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> 25*ed398213SEd Tanous #include <registries/privilege_registry.hpp> 26cb7e1e7bSAndrew Geissler #include <utils/fw_utils.hpp> 27c5b2abe0SLewanczyk, Dawid #include <utils/json_utils.hpp> 281214b7e7SGunnar Mills 29abf2add6SEd Tanous #include <variant> 30c5b2abe0SLewanczyk, Dawid 311abe55efSEd Tanous namespace redfish 321abe55efSEd Tanous { 33c5b2abe0SLewanczyk, Dawid 349d3ae10eSAlpana Kumari /** 359d3ae10eSAlpana Kumari * @brief Updates the Functional State of DIMMs 369d3ae10eSAlpana Kumari * 379d3ae10eSAlpana Kumari * @param[in] aResp Shared pointer for completing asynchronous calls 389d3ae10eSAlpana Kumari * @param[in] dimmState Dimm's Functional state, true/false 399d3ae10eSAlpana Kumari * 409d3ae10eSAlpana Kumari * @return None. 419d3ae10eSAlpana Kumari */ 428d1b46d7Szhanghch05 inline void 438d1b46d7Szhanghch05 updateDimmProperties(const std::shared_ptr<bmcweb::AsyncResp>& aResp, 449d3ae10eSAlpana Kumari const std::variant<bool>& dimmState) 459d3ae10eSAlpana Kumari { 469d3ae10eSAlpana Kumari const bool* isDimmFunctional = std::get_if<bool>(&dimmState); 479d3ae10eSAlpana Kumari if (isDimmFunctional == nullptr) 489d3ae10eSAlpana Kumari { 499d3ae10eSAlpana Kumari messages::internalError(aResp->res); 509d3ae10eSAlpana Kumari return; 519d3ae10eSAlpana Kumari } 529d3ae10eSAlpana Kumari BMCWEB_LOG_DEBUG << "Dimm Functional: " << *isDimmFunctional; 539d3ae10eSAlpana Kumari 549d3ae10eSAlpana Kumari // Set it as Enabled if at least one DIMM is functional 559d3ae10eSAlpana Kumari // Update STATE only if previous State was DISABLED and current Dimm is 569d3ae10eSAlpana Kumari // ENABLED. 579d3ae10eSAlpana Kumari nlohmann::json& prevMemSummary = 589d3ae10eSAlpana Kumari aResp->res.jsonValue["MemorySummary"]["Status"]["State"]; 599d3ae10eSAlpana Kumari if (prevMemSummary == "Disabled") 609d3ae10eSAlpana Kumari { 619d3ae10eSAlpana Kumari if (*isDimmFunctional == true) 629d3ae10eSAlpana Kumari { 639d3ae10eSAlpana Kumari aResp->res.jsonValue["MemorySummary"]["Status"]["State"] = 649d3ae10eSAlpana Kumari "Enabled"; 659d3ae10eSAlpana Kumari } 669d3ae10eSAlpana Kumari } 679d3ae10eSAlpana Kumari } 689d3ae10eSAlpana Kumari 6957e8c9beSAlpana Kumari /* 7057e8c9beSAlpana Kumari * @brief Update "ProcessorSummary" "Count" based on Cpu PresenceState 7157e8c9beSAlpana Kumari * 7257e8c9beSAlpana Kumari * @param[in] aResp Shared pointer for completing asynchronous calls 7357e8c9beSAlpana Kumari * @param[in] cpuPresenceState CPU present or not 7457e8c9beSAlpana Kumari * 7557e8c9beSAlpana Kumari * @return None. 7657e8c9beSAlpana Kumari */ 778d1b46d7Szhanghch05 inline void 788d1b46d7Szhanghch05 modifyCpuPresenceState(const std::shared_ptr<bmcweb::AsyncResp>& aResp, 7957e8c9beSAlpana Kumari const std::variant<bool>& cpuPresenceState) 8057e8c9beSAlpana Kumari { 8157e8c9beSAlpana Kumari const bool* isCpuPresent = std::get_if<bool>(&cpuPresenceState); 8257e8c9beSAlpana Kumari 8357e8c9beSAlpana Kumari if (isCpuPresent == nullptr) 8457e8c9beSAlpana Kumari { 8557e8c9beSAlpana Kumari messages::internalError(aResp->res); 8657e8c9beSAlpana Kumari return; 8757e8c9beSAlpana Kumari } 8857e8c9beSAlpana Kumari BMCWEB_LOG_DEBUG << "Cpu Present: " << *isCpuPresent; 8957e8c9beSAlpana Kumari 9057e8c9beSAlpana Kumari if (*isCpuPresent == true) 9157e8c9beSAlpana Kumari { 92b4b9595aSJames Feist nlohmann::json& procCount = 93b4b9595aSJames Feist aResp->res.jsonValue["ProcessorSummary"]["Count"]; 94b4b9595aSJames Feist auto procCountPtr = 95b4b9595aSJames Feist procCount.get_ptr<nlohmann::json::number_integer_t*>(); 96b4b9595aSJames Feist if (procCountPtr != nullptr) 97b4b9595aSJames Feist { 98b4b9595aSJames Feist // shouldn't be possible to be nullptr 99b4b9595aSJames Feist *procCountPtr += 1; 10057e8c9beSAlpana Kumari } 101b4b9595aSJames Feist } 10257e8c9beSAlpana Kumari } 10357e8c9beSAlpana Kumari 10457e8c9beSAlpana Kumari /* 10557e8c9beSAlpana Kumari * @brief Update "ProcessorSummary" "Status" "State" based on 10657e8c9beSAlpana Kumari * CPU Functional State 10757e8c9beSAlpana Kumari * 10857e8c9beSAlpana Kumari * @param[in] aResp Shared pointer for completing asynchronous calls 10957e8c9beSAlpana Kumari * @param[in] cpuFunctionalState is CPU functional true/false 11057e8c9beSAlpana Kumari * 11157e8c9beSAlpana Kumari * @return None. 11257e8c9beSAlpana Kumari */ 11323a21a1cSEd Tanous inline void 1148d1b46d7Szhanghch05 modifyCpuFunctionalState(const std::shared_ptr<bmcweb::AsyncResp>& aResp, 11557e8c9beSAlpana Kumari const std::variant<bool>& cpuFunctionalState) 11657e8c9beSAlpana Kumari { 11757e8c9beSAlpana Kumari const bool* isCpuFunctional = std::get_if<bool>(&cpuFunctionalState); 11857e8c9beSAlpana Kumari 11957e8c9beSAlpana Kumari if (isCpuFunctional == nullptr) 12057e8c9beSAlpana Kumari { 12157e8c9beSAlpana Kumari messages::internalError(aResp->res); 12257e8c9beSAlpana Kumari return; 12357e8c9beSAlpana Kumari } 12457e8c9beSAlpana Kumari BMCWEB_LOG_DEBUG << "Cpu Functional: " << *isCpuFunctional; 12557e8c9beSAlpana Kumari 12657e8c9beSAlpana Kumari nlohmann::json& prevProcState = 12757e8c9beSAlpana Kumari aResp->res.jsonValue["ProcessorSummary"]["Status"]["State"]; 12857e8c9beSAlpana Kumari 12957e8c9beSAlpana Kumari // Set it as Enabled if at least one CPU is functional 13057e8c9beSAlpana Kumari // Update STATE only if previous State was Non_Functional and current CPU is 13157e8c9beSAlpana Kumari // Functional. 13257e8c9beSAlpana Kumari if (prevProcState == "Disabled") 13357e8c9beSAlpana Kumari { 13457e8c9beSAlpana Kumari if (*isCpuFunctional == true) 13557e8c9beSAlpana Kumari { 13657e8c9beSAlpana Kumari aResp->res.jsonValue["ProcessorSummary"]["Status"]["State"] = 13757e8c9beSAlpana Kumari "Enabled"; 13857e8c9beSAlpana Kumari } 13957e8c9beSAlpana Kumari } 14057e8c9beSAlpana Kumari } 14157e8c9beSAlpana Kumari 14257e8c9beSAlpana Kumari /* 143c5b2abe0SLewanczyk, Dawid * @brief Retrieves computer system properties over dbus 144c5b2abe0SLewanczyk, Dawid * 145c5b2abe0SLewanczyk, Dawid * @param[in] aResp Shared pointer for completing asynchronous calls 1468f9ee3cdSGunnar Mills * @param[in] systemHealth Shared HealthPopulate pointer 147c5b2abe0SLewanczyk, Dawid * 148c5b2abe0SLewanczyk, Dawid * @return None. 149c5b2abe0SLewanczyk, Dawid */ 150b5a76932SEd Tanous inline void 1518d1b46d7Szhanghch05 getComputerSystem(const std::shared_ptr<bmcweb::AsyncResp>& aResp, 152b5a76932SEd Tanous const std::shared_ptr<HealthPopulate>& systemHealth) 1531abe55efSEd Tanous { 15455c7b7a2SEd Tanous BMCWEB_LOG_DEBUG << "Get available system components."; 1559d3ae10eSAlpana Kumari 15655c7b7a2SEd Tanous crow::connections::systemBus->async_method_call( 1575bc2dc8eSJames Feist [aResp, systemHealth]( 158c5b2abe0SLewanczyk, Dawid const boost::system::error_code ec, 159c5b2abe0SLewanczyk, Dawid const std::vector<std::pair< 1606c34de48SEd Tanous std::string, 1611214b7e7SGunnar Mills std::vector<std::pair<std::string, std::vector<std::string>>>>>& 1621214b7e7SGunnar Mills subtree) { 1631abe55efSEd Tanous if (ec) 1641abe55efSEd Tanous { 16555c7b7a2SEd Tanous BMCWEB_LOG_DEBUG << "DBUS response error"; 166f12894f8SJason M. Bills messages::internalError(aResp->res); 167c5b2abe0SLewanczyk, Dawid return; 168c5b2abe0SLewanczyk, Dawid } 169c5b2abe0SLewanczyk, Dawid // Iterate over all retrieved ObjectPaths. 1706c34de48SEd Tanous for (const std::pair<std::string, 1716c34de48SEd Tanous std::vector<std::pair< 1721214b7e7SGunnar Mills std::string, std::vector<std::string>>>>& 1731214b7e7SGunnar Mills object : subtree) 1741abe55efSEd Tanous { 175c5b2abe0SLewanczyk, Dawid const std::string& path = object.first; 17655c7b7a2SEd Tanous BMCWEB_LOG_DEBUG << "Got path: " << path; 1771abe55efSEd Tanous const std::vector< 1781214b7e7SGunnar Mills std::pair<std::string, std::vector<std::string>>>& 1791214b7e7SGunnar Mills connectionNames = object.second; 1801abe55efSEd Tanous if (connectionNames.size() < 1) 1811abe55efSEd Tanous { 182c5b2abe0SLewanczyk, Dawid continue; 183c5b2abe0SLewanczyk, Dawid } 184029573d4SEd Tanous 1855bc2dc8eSJames Feist auto memoryHealth = std::make_shared<HealthPopulate>( 1865bc2dc8eSJames Feist aResp, aResp->res.jsonValue["MemorySummary"]["Status"]); 1875bc2dc8eSJames Feist 1885bc2dc8eSJames Feist auto cpuHealth = std::make_shared<HealthPopulate>( 1895bc2dc8eSJames Feist aResp, aResp->res.jsonValue["ProcessorSummary"]["Status"]); 1905bc2dc8eSJames Feist 1915bc2dc8eSJames Feist systemHealth->children.emplace_back(memoryHealth); 1925bc2dc8eSJames Feist systemHealth->children.emplace_back(cpuHealth); 1935bc2dc8eSJames Feist 1946c34de48SEd Tanous // This is not system, so check if it's cpu, dimm, UUID or 1956c34de48SEd Tanous // BiosVer 19604a258f4SEd Tanous for (const auto& connection : connectionNames) 1971abe55efSEd Tanous { 19804a258f4SEd Tanous for (const auto& interfaceName : connection.second) 1991abe55efSEd Tanous { 20004a258f4SEd Tanous if (interfaceName == 20104a258f4SEd Tanous "xyz.openbmc_project.Inventory.Item.Dimm") 2021abe55efSEd Tanous { 2031abe55efSEd Tanous BMCWEB_LOG_DEBUG 20404a258f4SEd Tanous << "Found Dimm, now get its properties."; 2059d3ae10eSAlpana Kumari 20655c7b7a2SEd Tanous crow::connections::systemBus->async_method_call( 2079d3ae10eSAlpana Kumari [aResp, service{connection.first}, 208f23b7296SEd Tanous path](const boost::system::error_code ec2, 2096c34de48SEd Tanous const std::vector< 2101214b7e7SGunnar Mills std::pair<std::string, VariantType>>& 2111214b7e7SGunnar Mills properties) { 212cb13a392SEd Tanous if (ec2) 2131abe55efSEd Tanous { 2141abe55efSEd Tanous BMCWEB_LOG_ERROR 215cb13a392SEd Tanous << "DBUS response error " << ec2; 216f12894f8SJason M. Bills messages::internalError(aResp->res); 217c5b2abe0SLewanczyk, Dawid return; 218c5b2abe0SLewanczyk, Dawid } 2196c34de48SEd Tanous BMCWEB_LOG_DEBUG << "Got " 2206c34de48SEd Tanous << properties.size() 221c5b2abe0SLewanczyk, Dawid << " Dimm properties."; 2229d3ae10eSAlpana Kumari 2239d3ae10eSAlpana Kumari if (properties.size() > 0) 2249d3ae10eSAlpana Kumari { 22504a258f4SEd Tanous for (const std::pair<std::string, 2261214b7e7SGunnar Mills VariantType>& 2271214b7e7SGunnar Mills property : properties) 2281abe55efSEd Tanous { 2295fd7ba65SCheng C Yang if (property.first != 2305fd7ba65SCheng C Yang "MemorySizeInKB") 2311abe55efSEd Tanous { 2325fd7ba65SCheng C Yang continue; 2335fd7ba65SCheng C Yang } 2345fd7ba65SCheng C Yang const uint32_t* value = 2358d78b7a9SPatrick Williams std::get_if<uint32_t>( 2361b6b96c5SEd Tanous &property.second); 2375fd7ba65SCheng C Yang if (value == nullptr) 2381abe55efSEd Tanous { 2395fd7ba65SCheng C Yang BMCWEB_LOG_DEBUG 2405fd7ba65SCheng C Yang << "Find incorrect type of " 2415fd7ba65SCheng C Yang "MemorySize"; 2425fd7ba65SCheng C Yang continue; 2435fd7ba65SCheng C Yang } 2445fd7ba65SCheng C Yang nlohmann::json& totalMemory = 2455fd7ba65SCheng C Yang aResp->res 2465fd7ba65SCheng C Yang .jsonValue["MemorySummar" 2475fd7ba65SCheng C Yang "y"] 2485fd7ba65SCheng C Yang ["TotalSystemMe" 2495fd7ba65SCheng C Yang "moryGiB"]; 2505fd7ba65SCheng C Yang uint64_t* preValue = 2515fd7ba65SCheng C Yang totalMemory 2525fd7ba65SCheng C Yang .get_ptr<uint64_t*>(); 2535fd7ba65SCheng C Yang if (preValue == nullptr) 2545fd7ba65SCheng C Yang { 2555fd7ba65SCheng C Yang continue; 2565fd7ba65SCheng C Yang } 2575fd7ba65SCheng C Yang aResp->res 2585fd7ba65SCheng C Yang .jsonValue["MemorySummary"] 2596c34de48SEd Tanous ["TotalSystemMemoryGi" 2605fd7ba65SCheng C Yang "B"] = 2615fd7ba65SCheng C Yang *value / (1024 * 1024) + 2625fd7ba65SCheng C Yang *preValue; 2635fd7ba65SCheng C Yang aResp->res 2645fd7ba65SCheng C Yang .jsonValue["MemorySummary"] 2659d3ae10eSAlpana Kumari ["Status"]["State"] = 2661abe55efSEd Tanous "Enabled"; 267c5b2abe0SLewanczyk, Dawid } 268c5b2abe0SLewanczyk, Dawid } 2699d3ae10eSAlpana Kumari else 2709d3ae10eSAlpana Kumari { 2719d3ae10eSAlpana Kumari auto getDimmProperties = 2729d3ae10eSAlpana Kumari [aResp]( 2739d3ae10eSAlpana Kumari const boost::system::error_code 274cb13a392SEd Tanous ec3, 2751214b7e7SGunnar Mills const std::variant<bool>& 2761214b7e7SGunnar Mills dimmState) { 277cb13a392SEd Tanous if (ec3) 2789d3ae10eSAlpana Kumari { 2799d3ae10eSAlpana Kumari BMCWEB_LOG_ERROR 2809d3ae10eSAlpana Kumari << "DBUS response " 2819d3ae10eSAlpana Kumari "error " 282cb13a392SEd Tanous << ec3; 2839d3ae10eSAlpana Kumari return; 2849d3ae10eSAlpana Kumari } 2859d3ae10eSAlpana Kumari updateDimmProperties(aResp, 2869d3ae10eSAlpana Kumari dimmState); 2879d3ae10eSAlpana Kumari }; 2889d3ae10eSAlpana Kumari crow::connections::systemBus 2899d3ae10eSAlpana Kumari ->async_method_call( 2909d3ae10eSAlpana Kumari std::move(getDimmProperties), 2919d3ae10eSAlpana Kumari service, path, 2929d3ae10eSAlpana Kumari "org.freedesktop.DBus." 2939d3ae10eSAlpana Kumari "Properties", 2949d3ae10eSAlpana Kumari "Get", 2959d3ae10eSAlpana Kumari "xyz.openbmc_project.State." 2969d3ae10eSAlpana Kumari "Decorator.OperationalStatus", 2979d3ae10eSAlpana Kumari "Functional"); 2989d3ae10eSAlpana Kumari } 299c5b2abe0SLewanczyk, Dawid }, 30004a258f4SEd Tanous connection.first, path, 3016c34de48SEd Tanous "org.freedesktop.DBus.Properties", "GetAll", 3026c34de48SEd Tanous "xyz.openbmc_project.Inventory.Item.Dimm"); 3035bc2dc8eSJames Feist 3045bc2dc8eSJames Feist memoryHealth->inventory.emplace_back(path); 3051abe55efSEd Tanous } 30604a258f4SEd Tanous else if (interfaceName == 30704a258f4SEd Tanous "xyz.openbmc_project.Inventory.Item.Cpu") 3081abe55efSEd Tanous { 3091abe55efSEd Tanous BMCWEB_LOG_DEBUG 31004a258f4SEd Tanous << "Found Cpu, now get its properties."; 31157e8c9beSAlpana Kumari 312a0803efaSEd Tanous crow::connections::systemBus->async_method_call( 31357e8c9beSAlpana Kumari [aResp, service{connection.first}, 314f23b7296SEd Tanous path](const boost::system::error_code ec2, 3156c34de48SEd Tanous const std::vector< 3161214b7e7SGunnar Mills std::pair<std::string, VariantType>>& 3171214b7e7SGunnar Mills properties) { 318cb13a392SEd Tanous if (ec2) 3191abe55efSEd Tanous { 3201abe55efSEd Tanous BMCWEB_LOG_ERROR 321cb13a392SEd Tanous << "DBUS response error " << ec2; 322f12894f8SJason M. Bills messages::internalError(aResp->res); 323c5b2abe0SLewanczyk, Dawid return; 324c5b2abe0SLewanczyk, Dawid } 3256c34de48SEd Tanous BMCWEB_LOG_DEBUG << "Got " 3266c34de48SEd Tanous << properties.size() 327c5b2abe0SLewanczyk, Dawid << " Cpu properties."; 32857e8c9beSAlpana Kumari 32957e8c9beSAlpana Kumari if (properties.size() > 0) 33057e8c9beSAlpana Kumari { 3319cf21522SZhikui Ren const uint64_t* processorId = nullptr; 332029cc1f4SZhikui Ren const std::string* procFamily = nullptr; 333029cc1f4SZhikui Ren nlohmann::json& procSummary = 334029cc1f4SZhikui Ren aResp->res.jsonValue["ProcessorSumm" 33504a258f4SEd Tanous "ary"]; 33604a258f4SEd Tanous nlohmann::json& procCount = 33704a258f4SEd Tanous procSummary["Count"]; 338b4b9595aSJames Feist 339029cc1f4SZhikui Ren auto procCountPtr = procCount.get_ptr< 340b4b9595aSJames Feist nlohmann::json:: 3411214b7e7SGunnar Mills number_integer_t*>(); 342029cc1f4SZhikui Ren if (procCountPtr == nullptr) 343b4b9595aSJames Feist { 344029cc1f4SZhikui Ren messages::internalError(aResp->res); 345029cc1f4SZhikui Ren return; 346029cc1f4SZhikui Ren } 347029cc1f4SZhikui Ren for (const auto& property : properties) 348029cc1f4SZhikui Ren { 349029cc1f4SZhikui Ren 3509cf21522SZhikui Ren if (property.first == "Id") 351029cc1f4SZhikui Ren { 352029cc1f4SZhikui Ren processorId = 3539cf21522SZhikui Ren std::get_if<uint64_t>( 354029cc1f4SZhikui Ren &property.second); 355029cc1f4SZhikui Ren if (nullptr != procFamily) 3563174e4dfSEd Tanous { 357029cc1f4SZhikui Ren break; 3583174e4dfSEd Tanous } 359029cc1f4SZhikui Ren continue; 360029cc1f4SZhikui Ren } 361029cc1f4SZhikui Ren 3629cf21522SZhikui Ren if (property.first == "Family") 363029cc1f4SZhikui Ren { 364029cc1f4SZhikui Ren procFamily = 365029cc1f4SZhikui Ren std::get_if<std::string>( 366029cc1f4SZhikui Ren &property.second); 367029cc1f4SZhikui Ren if (nullptr != processorId) 3683174e4dfSEd Tanous { 369029cc1f4SZhikui Ren break; 3703174e4dfSEd Tanous } 371029cc1f4SZhikui Ren continue; 372029cc1f4SZhikui Ren } 373029cc1f4SZhikui Ren } 374029cc1f4SZhikui Ren 375029cc1f4SZhikui Ren if (procFamily != nullptr && 376029cc1f4SZhikui Ren processorId != nullptr) 377029cc1f4SZhikui Ren { 378029cc1f4SZhikui Ren if (procCountPtr != nullptr && 379029cc1f4SZhikui Ren *processorId != 0) 380029cc1f4SZhikui Ren { 381b4b9595aSJames Feist *procCountPtr += 1; 382029cc1f4SZhikui Ren procSummary["Status"]["State"] = 383c5b2abe0SLewanczyk, Dawid "Enabled"; 384029cc1f4SZhikui Ren 38557e8c9beSAlpana Kumari procSummary["Model"] = 386029cc1f4SZhikui Ren *procFamily; 387c5b2abe0SLewanczyk, Dawid } 388c5b2abe0SLewanczyk, Dawid } 38957e8c9beSAlpana Kumari } 39057e8c9beSAlpana Kumari else 39157e8c9beSAlpana Kumari { 39257e8c9beSAlpana Kumari auto getCpuPresenceState = 39357e8c9beSAlpana Kumari [aResp]( 39457e8c9beSAlpana Kumari const boost::system::error_code 395cb13a392SEd Tanous ec3, 3961214b7e7SGunnar Mills const std::variant<bool>& 3971214b7e7SGunnar Mills cpuPresenceCheck) { 398cb13a392SEd Tanous if (ec3) 39957e8c9beSAlpana Kumari { 40057e8c9beSAlpana Kumari BMCWEB_LOG_ERROR 40157e8c9beSAlpana Kumari << "DBUS response " 40257e8c9beSAlpana Kumari "error " 403cb13a392SEd Tanous << ec3; 40457e8c9beSAlpana Kumari return; 40557e8c9beSAlpana Kumari } 40657e8c9beSAlpana Kumari modifyCpuPresenceState( 40757e8c9beSAlpana Kumari aResp, cpuPresenceCheck); 40857e8c9beSAlpana Kumari }; 40957e8c9beSAlpana Kumari 41057e8c9beSAlpana Kumari auto getCpuFunctionalState = 41157e8c9beSAlpana Kumari [aResp]( 41257e8c9beSAlpana Kumari const boost::system::error_code 413cb13a392SEd Tanous ec3, 4141214b7e7SGunnar Mills const std::variant<bool>& 4151214b7e7SGunnar Mills cpuFunctionalCheck) { 416cb13a392SEd Tanous if (ec3) 41757e8c9beSAlpana Kumari { 41857e8c9beSAlpana Kumari BMCWEB_LOG_ERROR 41957e8c9beSAlpana Kumari << "DBUS response " 42057e8c9beSAlpana Kumari "error " 421cb13a392SEd Tanous << ec3; 42257e8c9beSAlpana Kumari return; 42357e8c9beSAlpana Kumari } 42457e8c9beSAlpana Kumari modifyCpuFunctionalState( 42557e8c9beSAlpana Kumari aResp, cpuFunctionalCheck); 42657e8c9beSAlpana Kumari }; 42757e8c9beSAlpana Kumari // Get the Presence of CPU 42857e8c9beSAlpana Kumari crow::connections::systemBus 42957e8c9beSAlpana Kumari ->async_method_call( 43057e8c9beSAlpana Kumari std::move(getCpuPresenceState), 43157e8c9beSAlpana Kumari service, path, 43257e8c9beSAlpana Kumari "org.freedesktop.DBus." 43357e8c9beSAlpana Kumari "Properties", 43457e8c9beSAlpana Kumari "Get", 43557e8c9beSAlpana Kumari "xyz.openbmc_project.Inventory." 43657e8c9beSAlpana Kumari "Item", 43757e8c9beSAlpana Kumari "Present"); 43857e8c9beSAlpana Kumari 43957e8c9beSAlpana Kumari // Get the Functional State 44057e8c9beSAlpana Kumari crow::connections::systemBus 44157e8c9beSAlpana Kumari ->async_method_call( 44257e8c9beSAlpana Kumari std::move( 44357e8c9beSAlpana Kumari getCpuFunctionalState), 44457e8c9beSAlpana Kumari service, path, 44557e8c9beSAlpana Kumari "org.freedesktop.DBus." 44657e8c9beSAlpana Kumari "Properties", 44757e8c9beSAlpana Kumari "Get", 44857e8c9beSAlpana Kumari "xyz.openbmc_project.State." 44957e8c9beSAlpana Kumari "Decorator." 45057e8c9beSAlpana Kumari "OperationalStatus", 45157e8c9beSAlpana Kumari "Functional"); 45257e8c9beSAlpana Kumari 45357e8c9beSAlpana Kumari // Get the MODEL from 45457e8c9beSAlpana Kumari // xyz.openbmc_project.Inventory.Decorator.Asset 45557e8c9beSAlpana Kumari // support it later as Model is Empty 45657e8c9beSAlpana Kumari // currently. 45757e8c9beSAlpana Kumari } 458c5b2abe0SLewanczyk, Dawid }, 45904a258f4SEd Tanous connection.first, path, 4606c34de48SEd Tanous "org.freedesktop.DBus.Properties", "GetAll", 4616c34de48SEd Tanous "xyz.openbmc_project.Inventory.Item.Cpu"); 4625bc2dc8eSJames Feist 4635bc2dc8eSJames Feist cpuHealth->inventory.emplace_back(path); 4641abe55efSEd Tanous } 46504a258f4SEd Tanous else if (interfaceName == 46604a258f4SEd Tanous "xyz.openbmc_project.Common.UUID") 4671abe55efSEd Tanous { 4681abe55efSEd Tanous BMCWEB_LOG_DEBUG 46904a258f4SEd Tanous << "Found UUID, now get its properties."; 47055c7b7a2SEd Tanous crow::connections::systemBus->async_method_call( 4711214b7e7SGunnar Mills [aResp]( 472cb13a392SEd Tanous const boost::system::error_code ec3, 4736c34de48SEd Tanous const std::vector< 4741214b7e7SGunnar Mills std::pair<std::string, VariantType>>& 4751214b7e7SGunnar Mills properties) { 476cb13a392SEd Tanous if (ec3) 4771abe55efSEd Tanous { 4781abe55efSEd Tanous BMCWEB_LOG_DEBUG 479cb13a392SEd Tanous << "DBUS response error " << ec3; 480f12894f8SJason M. Bills messages::internalError(aResp->res); 481c5b2abe0SLewanczyk, Dawid return; 482c5b2abe0SLewanczyk, Dawid } 4836c34de48SEd Tanous BMCWEB_LOG_DEBUG << "Got " 4846c34de48SEd Tanous << properties.size() 485c5b2abe0SLewanczyk, Dawid << " UUID properties."; 4861abe55efSEd Tanous for (const std::pair<std::string, 4871214b7e7SGunnar Mills VariantType>& 4881214b7e7SGunnar Mills property : properties) 4891abe55efSEd Tanous { 49004a258f4SEd Tanous if (property.first == "UUID") 4911abe55efSEd Tanous { 492c5b2abe0SLewanczyk, Dawid const std::string* value = 4938d78b7a9SPatrick Williams std::get_if<std::string>( 4941b6b96c5SEd Tanous &property.second); 49504a258f4SEd Tanous 4961abe55efSEd Tanous if (value != nullptr) 4971abe55efSEd Tanous { 498029573d4SEd Tanous std::string valueStr = *value; 49904a258f4SEd Tanous if (valueStr.size() == 32) 5001abe55efSEd Tanous { 501029573d4SEd Tanous valueStr.insert(8, 1, '-'); 502029573d4SEd Tanous valueStr.insert(13, 1, '-'); 503029573d4SEd Tanous valueStr.insert(18, 1, '-'); 504029573d4SEd Tanous valueStr.insert(23, 1, '-'); 50504a258f4SEd Tanous } 506029573d4SEd Tanous BMCWEB_LOG_DEBUG << "UUID = " 50704a258f4SEd Tanous << valueStr; 508029573d4SEd Tanous aResp->res.jsonValue["UUID"] = 50904a258f4SEd Tanous valueStr; 510c5b2abe0SLewanczyk, Dawid } 511c5b2abe0SLewanczyk, Dawid } 512c5b2abe0SLewanczyk, Dawid } 513c5b2abe0SLewanczyk, Dawid }, 51404a258f4SEd Tanous connection.first, path, 5156c34de48SEd Tanous "org.freedesktop.DBus.Properties", "GetAll", 5161abe55efSEd Tanous "xyz.openbmc_project.Common.UUID"); 517c5b2abe0SLewanczyk, Dawid } 518029573d4SEd Tanous else if (interfaceName == 519029573d4SEd Tanous "xyz.openbmc_project.Inventory.Item.System") 5201abe55efSEd Tanous { 521029573d4SEd Tanous crow::connections::systemBus->async_method_call( 5221214b7e7SGunnar Mills [aResp]( 523cb13a392SEd Tanous const boost::system::error_code ec2, 524029573d4SEd Tanous const std::vector< 5251214b7e7SGunnar Mills std::pair<std::string, VariantType>>& 5261214b7e7SGunnar Mills propertiesList) { 527cb13a392SEd Tanous if (ec2) 528029573d4SEd Tanous { 529e4a4b9a9SJames Feist // doesn't have to include this 530e4a4b9a9SJames Feist // interface 531029573d4SEd Tanous return; 532029573d4SEd Tanous } 533698654b6SGunnar Mills BMCWEB_LOG_DEBUG 534698654b6SGunnar Mills << "Got " << propertiesList.size() 535029573d4SEd Tanous << " properties for system"; 536029573d4SEd Tanous for (const std::pair<std::string, 5371214b7e7SGunnar Mills VariantType>& 5381214b7e7SGunnar Mills property : propertiesList) 539029573d4SEd Tanous { 540fc5afcf9Sbeccabroek const std::string& propertyName = 541fc5afcf9Sbeccabroek property.first; 542fc5afcf9Sbeccabroek if ((propertyName == "PartNumber") || 543fc5afcf9Sbeccabroek (propertyName == "SerialNumber") || 544fc5afcf9Sbeccabroek (propertyName == "Manufacturer") || 5455235d964SSunnySrivastava1984 (propertyName == "Model") || 5465235d964SSunnySrivastava1984 (propertyName == "SubModel")) 547fc5afcf9Sbeccabroek { 548029573d4SEd Tanous const std::string* value = 549fc5afcf9Sbeccabroek std::get_if<std::string>( 550029573d4SEd Tanous &property.second); 551029573d4SEd Tanous if (value != nullptr) 552029573d4SEd Tanous { 553029573d4SEd Tanous aResp->res 554fc5afcf9Sbeccabroek .jsonValue[propertyName] = 555029573d4SEd Tanous *value; 556029573d4SEd Tanous } 557029573d4SEd Tanous } 558fc5afcf9Sbeccabroek } 559c1e236a6SGunnar Mills 560cb7e1e7bSAndrew Geissler // Grab the bios version 561f97ddba7SGunnar Mills fw_util::populateFirmwareInformation( 562cb7e1e7bSAndrew Geissler aResp, fw_util::biosPurpose, 56372d566d9SGunnar Mills "BiosVersion", false); 564029573d4SEd Tanous }, 565029573d4SEd Tanous connection.first, path, 566029573d4SEd Tanous "org.freedesktop.DBus.Properties", "GetAll", 567029573d4SEd Tanous "xyz.openbmc_project.Inventory.Decorator." 568029573d4SEd Tanous "Asset"); 569e4a4b9a9SJames Feist 570e4a4b9a9SJames Feist crow::connections::systemBus->async_method_call( 571e4a4b9a9SJames Feist [aResp]( 572cb13a392SEd Tanous const boost::system::error_code ec2, 573e4a4b9a9SJames Feist const std::variant<std::string>& property) { 574cb13a392SEd Tanous if (ec2) 575e4a4b9a9SJames Feist { 576e4a4b9a9SJames Feist // doesn't have to include this 577e4a4b9a9SJames Feist // interface 578e4a4b9a9SJames Feist return; 579e4a4b9a9SJames Feist } 580e4a4b9a9SJames Feist 581e4a4b9a9SJames Feist const std::string* value = 582e4a4b9a9SJames Feist std::get_if<std::string>(&property); 583e4a4b9a9SJames Feist if (value != nullptr) 584e4a4b9a9SJames Feist { 585e4a4b9a9SJames Feist aResp->res.jsonValue["AssetTag"] = 586e4a4b9a9SJames Feist *value; 587e4a4b9a9SJames Feist } 588e4a4b9a9SJames Feist }, 589e4a4b9a9SJames Feist connection.first, path, 590e4a4b9a9SJames Feist "org.freedesktop.DBus.Properties", "Get", 591e4a4b9a9SJames Feist "xyz.openbmc_project.Inventory.Decorator." 592e4a4b9a9SJames Feist "AssetTag", 593e4a4b9a9SJames Feist "AssetTag"); 594029573d4SEd Tanous } 595029573d4SEd Tanous } 596029573d4SEd Tanous } 597c5b2abe0SLewanczyk, Dawid } 598c5b2abe0SLewanczyk, Dawid }, 599c5b2abe0SLewanczyk, Dawid "xyz.openbmc_project.ObjectMapper", 600c5b2abe0SLewanczyk, Dawid "/xyz/openbmc_project/object_mapper", 601c5b2abe0SLewanczyk, Dawid "xyz.openbmc_project.ObjectMapper", "GetSubTree", 6026617338dSEd Tanous "/xyz/openbmc_project/inventory", int32_t(0), 6036617338dSEd Tanous std::array<const char*, 5>{ 6046617338dSEd Tanous "xyz.openbmc_project.Inventory.Decorator.Asset", 6056617338dSEd Tanous "xyz.openbmc_project.Inventory.Item.Cpu", 6066617338dSEd Tanous "xyz.openbmc_project.Inventory.Item.Dimm", 6076617338dSEd Tanous "xyz.openbmc_project.Inventory.Item.System", 6086617338dSEd Tanous "xyz.openbmc_project.Common.UUID", 6096617338dSEd Tanous }); 610c5b2abe0SLewanczyk, Dawid } 611c5b2abe0SLewanczyk, Dawid 612c5b2abe0SLewanczyk, Dawid /** 613c5b2abe0SLewanczyk, Dawid * @brief Retrieves host state properties over dbus 614c5b2abe0SLewanczyk, Dawid * 615c5b2abe0SLewanczyk, Dawid * @param[in] aResp Shared pointer for completing asynchronous calls. 616c5b2abe0SLewanczyk, Dawid * 617c5b2abe0SLewanczyk, Dawid * @return None. 618c5b2abe0SLewanczyk, Dawid */ 6198d1b46d7Szhanghch05 inline void getHostState(const std::shared_ptr<bmcweb::AsyncResp>& aResp) 6201abe55efSEd Tanous { 62155c7b7a2SEd Tanous BMCWEB_LOG_DEBUG << "Get host information."; 62255c7b7a2SEd Tanous crow::connections::systemBus->async_method_call( 623c5d03ff4SJennifer Lee [aResp](const boost::system::error_code ec, 624abf2add6SEd Tanous const std::variant<std::string>& hostState) { 6251abe55efSEd Tanous if (ec) 6261abe55efSEd Tanous { 62755c7b7a2SEd Tanous BMCWEB_LOG_DEBUG << "DBUS response error " << ec; 628f12894f8SJason M. Bills messages::internalError(aResp->res); 629c5b2abe0SLewanczyk, Dawid return; 630c5b2abe0SLewanczyk, Dawid } 6316617338dSEd Tanous 632abf2add6SEd Tanous const std::string* s = std::get_if<std::string>(&hostState); 63355c7b7a2SEd Tanous BMCWEB_LOG_DEBUG << "Host state: " << *s; 6346617338dSEd Tanous if (s != nullptr) 6351abe55efSEd Tanous { 636c5b2abe0SLewanczyk, Dawid // Verify Host State 63794732661SAndrew Geissler if (*s == "xyz.openbmc_project.State.Host.HostState.Running") 6381abe55efSEd Tanous { 63955c7b7a2SEd Tanous aResp->res.jsonValue["PowerState"] = "On"; 6406617338dSEd Tanous aResp->res.jsonValue["Status"]["State"] = "Enabled"; 6411abe55efSEd Tanous } 64283935af9SAndrew Geissler else if (*s == "xyz.openbmc_project.State.Host.HostState." 6438c888608SGunnar Mills "Quiesced") 6448c888608SGunnar Mills { 6458c888608SGunnar Mills aResp->res.jsonValue["PowerState"] = "On"; 6468c888608SGunnar Mills aResp->res.jsonValue["Status"]["State"] = "Quiesced"; 6478c888608SGunnar Mills } 6488c888608SGunnar Mills else if (*s == "xyz.openbmc_project.State.Host.HostState." 64983935af9SAndrew Geissler "DiagnosticMode") 65083935af9SAndrew Geissler { 65183935af9SAndrew Geissler aResp->res.jsonValue["PowerState"] = "On"; 65283935af9SAndrew Geissler aResp->res.jsonValue["Status"]["State"] = "InTest"; 65383935af9SAndrew Geissler } 6541a2a1437SAndrew Geissler else if (*s == "xyz.openbmc_project.State.Host.HostState." 6551a2a1437SAndrew Geissler "TransitioningToRunning") 6561a2a1437SAndrew Geissler { 6571a2a1437SAndrew Geissler aResp->res.jsonValue["PowerState"] = "PoweringOn"; 65815c27bf8SNoah Brewer aResp->res.jsonValue["Status"]["State"] = "Starting"; 6591a2a1437SAndrew Geissler } 6601a2a1437SAndrew Geissler else if (*s == "xyz.openbmc_project.State.Host.HostState." 6611a2a1437SAndrew Geissler "TransitioningToOff") 6621a2a1437SAndrew Geissler { 6631a2a1437SAndrew Geissler aResp->res.jsonValue["PowerState"] = "PoweringOff"; 6641a2a1437SAndrew Geissler aResp->res.jsonValue["Status"]["State"] = "Disabled"; 6651a2a1437SAndrew Geissler } 6661abe55efSEd Tanous else 6671abe55efSEd Tanous { 66855c7b7a2SEd Tanous aResp->res.jsonValue["PowerState"] = "Off"; 6696617338dSEd Tanous aResp->res.jsonValue["Status"]["State"] = "Disabled"; 670c5b2abe0SLewanczyk, Dawid } 671c5b2abe0SLewanczyk, Dawid } 672c5b2abe0SLewanczyk, Dawid }, 6736c34de48SEd Tanous "xyz.openbmc_project.State.Host", "/xyz/openbmc_project/state/host0", 6746617338dSEd Tanous "org.freedesktop.DBus.Properties", "Get", 6756617338dSEd Tanous "xyz.openbmc_project.State.Host", "CurrentHostState"); 676c5b2abe0SLewanczyk, Dawid } 677c5b2abe0SLewanczyk, Dawid 678c5b2abe0SLewanczyk, Dawid /** 679786d0f60SGunnar Mills * @brief Translates boot source DBUS property value to redfish. 680491d8ee7SSantosh Puranik * 681491d8ee7SSantosh Puranik * @param[in] dbusSource The boot source in DBUS speak. 682491d8ee7SSantosh Puranik * 683491d8ee7SSantosh Puranik * @return Returns as a string, the boot source in Redfish terms. If translation 684491d8ee7SSantosh Puranik * cannot be done, returns an empty string. 685491d8ee7SSantosh Puranik */ 68623a21a1cSEd Tanous inline std::string dbusToRfBootSource(const std::string& dbusSource) 687491d8ee7SSantosh Puranik { 688491d8ee7SSantosh Puranik if (dbusSource == "xyz.openbmc_project.Control.Boot.Source.Sources.Default") 689491d8ee7SSantosh Puranik { 690491d8ee7SSantosh Puranik return "None"; 691491d8ee7SSantosh Puranik } 6923174e4dfSEd Tanous if (dbusSource == "xyz.openbmc_project.Control.Boot.Source.Sources.Disk") 693491d8ee7SSantosh Puranik { 694491d8ee7SSantosh Puranik return "Hdd"; 695491d8ee7SSantosh Puranik } 6963174e4dfSEd Tanous if (dbusSource == 697a71dc0b7SSantosh Puranik "xyz.openbmc_project.Control.Boot.Source.Sources.ExternalMedia") 698491d8ee7SSantosh Puranik { 699491d8ee7SSantosh Puranik return "Cd"; 700491d8ee7SSantosh Puranik } 7013174e4dfSEd Tanous if (dbusSource == "xyz.openbmc_project.Control.Boot.Source.Sources.Network") 702491d8ee7SSantosh Puranik { 703491d8ee7SSantosh Puranik return "Pxe"; 704491d8ee7SSantosh Puranik } 7053174e4dfSEd Tanous if (dbusSource == 706944ffaf9SJohnathan Mantey "xyz.openbmc_project.Control.Boot.Source.Sources.RemovableMedia") 7079f16b2c1SJennifer Lee { 7089f16b2c1SJennifer Lee return "Usb"; 7099f16b2c1SJennifer Lee } 710491d8ee7SSantosh Puranik return ""; 711491d8ee7SSantosh Puranik } 712491d8ee7SSantosh Puranik 713491d8ee7SSantosh Puranik /** 714786d0f60SGunnar Mills * @brief Translates boot mode DBUS property value to redfish. 715491d8ee7SSantosh Puranik * 716491d8ee7SSantosh Puranik * @param[in] dbusMode The boot mode in DBUS speak. 717491d8ee7SSantosh Puranik * 718491d8ee7SSantosh Puranik * @return Returns as a string, the boot mode in Redfish terms. If translation 719491d8ee7SSantosh Puranik * cannot be done, returns an empty string. 720491d8ee7SSantosh Puranik */ 72123a21a1cSEd Tanous inline std::string dbusToRfBootMode(const std::string& dbusMode) 722491d8ee7SSantosh Puranik { 723491d8ee7SSantosh Puranik if (dbusMode == "xyz.openbmc_project.Control.Boot.Mode.Modes.Regular") 724491d8ee7SSantosh Puranik { 725491d8ee7SSantosh Puranik return "None"; 726491d8ee7SSantosh Puranik } 7273174e4dfSEd Tanous if (dbusMode == "xyz.openbmc_project.Control.Boot.Mode.Modes.Safe") 728491d8ee7SSantosh Puranik { 729491d8ee7SSantosh Puranik return "Diags"; 730491d8ee7SSantosh Puranik } 7313174e4dfSEd Tanous if (dbusMode == "xyz.openbmc_project.Control.Boot.Mode.Modes.Setup") 732491d8ee7SSantosh Puranik { 733491d8ee7SSantosh Puranik return "BiosSetup"; 734491d8ee7SSantosh Puranik } 735491d8ee7SSantosh Puranik return ""; 736491d8ee7SSantosh Puranik } 737491d8ee7SSantosh Puranik 738491d8ee7SSantosh Puranik /** 739786d0f60SGunnar Mills * @brief Translates boot source from Redfish to the DBus boot paths. 740491d8ee7SSantosh Puranik * 741491d8ee7SSantosh Puranik * @param[in] rfSource The boot source in Redfish. 742944ffaf9SJohnathan Mantey * @param[out] bootSource The DBus source 743944ffaf9SJohnathan Mantey * @param[out] bootMode the DBus boot mode 744491d8ee7SSantosh Puranik * 745944ffaf9SJohnathan Mantey * @return Integer error code. 746491d8ee7SSantosh Puranik */ 7478d1b46d7Szhanghch05 inline int assignBootParameters(const std::shared_ptr<bmcweb::AsyncResp>& aResp, 748944ffaf9SJohnathan Mantey const std::string& rfSource, 749944ffaf9SJohnathan Mantey std::string& bootSource, std::string& bootMode) 750491d8ee7SSantosh Puranik { 751944ffaf9SJohnathan Mantey // The caller has initialized the bootSource and bootMode to: 752944ffaf9SJohnathan Mantey // bootMode = "xyz.openbmc_project.Control.Boot.Mode.Modes.Regular"; 753944ffaf9SJohnathan Mantey // bootSource = "xyz.openbmc_project.Control.Boot.Source.Sources.Default"; 754944ffaf9SJohnathan Mantey // Only modify the bootSource/bootMode variable needed to achieve the 755944ffaf9SJohnathan Mantey // desired boot action. 756944ffaf9SJohnathan Mantey 757491d8ee7SSantosh Puranik if (rfSource == "None") 758491d8ee7SSantosh Puranik { 759944ffaf9SJohnathan Mantey return 0; 760491d8ee7SSantosh Puranik } 7613174e4dfSEd Tanous if (rfSource == "Pxe") 762491d8ee7SSantosh Puranik { 763944ffaf9SJohnathan Mantey bootSource = "xyz.openbmc_project.Control.Boot.Source.Sources.Network"; 764944ffaf9SJohnathan Mantey } 765944ffaf9SJohnathan Mantey else if (rfSource == "Hdd") 766944ffaf9SJohnathan Mantey { 767944ffaf9SJohnathan Mantey bootSource = "xyz.openbmc_project.Control.Boot.Source.Sources.Disk"; 768944ffaf9SJohnathan Mantey } 769944ffaf9SJohnathan Mantey else if (rfSource == "Diags") 770944ffaf9SJohnathan Mantey { 771944ffaf9SJohnathan Mantey bootMode = "xyz.openbmc_project.Control.Boot.Mode.Modes.Safe"; 772944ffaf9SJohnathan Mantey } 773944ffaf9SJohnathan Mantey else if (rfSource == "Cd") 774944ffaf9SJohnathan Mantey { 775944ffaf9SJohnathan Mantey bootSource = 776944ffaf9SJohnathan Mantey "xyz.openbmc_project.Control.Boot.Source.Sources.ExternalMedia"; 777944ffaf9SJohnathan Mantey } 778944ffaf9SJohnathan Mantey else if (rfSource == "BiosSetup") 779944ffaf9SJohnathan Mantey { 780944ffaf9SJohnathan Mantey bootMode = "xyz.openbmc_project.Control.Boot.Mode.Modes.Setup"; 781491d8ee7SSantosh Puranik } 7829f16b2c1SJennifer Lee else if (rfSource == "Usb") 7839f16b2c1SJennifer Lee { 784944ffaf9SJohnathan Mantey bootSource = 785944ffaf9SJohnathan Mantey "xyz.openbmc_project.Control.Boot.Source.Sources.RemovableMedia"; 7869f16b2c1SJennifer Lee } 787491d8ee7SSantosh Puranik else 788491d8ee7SSantosh Puranik { 789944ffaf9SJohnathan Mantey BMCWEB_LOG_DEBUG << "Invalid property value for " 790944ffaf9SJohnathan Mantey "BootSourceOverrideTarget: " 791944ffaf9SJohnathan Mantey << bootSource; 792944ffaf9SJohnathan Mantey messages::propertyValueNotInList(aResp->res, rfSource, 793944ffaf9SJohnathan Mantey "BootSourceTargetOverride"); 794944ffaf9SJohnathan Mantey return -1; 795491d8ee7SSantosh Puranik } 796944ffaf9SJohnathan Mantey return 0; 797491d8ee7SSantosh Puranik } 7981981771bSAli Ahmed 799978b8803SAndrew Geissler /** 800978b8803SAndrew Geissler * @brief Retrieves boot progress of the system 801978b8803SAndrew Geissler * 802978b8803SAndrew Geissler * @param[in] aResp Shared pointer for generating response message. 803978b8803SAndrew Geissler * 804978b8803SAndrew Geissler * @return None. 805978b8803SAndrew Geissler */ 8068d1b46d7Szhanghch05 inline void getBootProgress(const std::shared_ptr<bmcweb::AsyncResp>& aResp) 807978b8803SAndrew Geissler { 808978b8803SAndrew Geissler crow::connections::systemBus->async_method_call( 809978b8803SAndrew Geissler [aResp](const boost::system::error_code ec, 810978b8803SAndrew Geissler const std::variant<std::string>& bootProgress) { 811978b8803SAndrew Geissler if (ec) 812978b8803SAndrew Geissler { 813978b8803SAndrew Geissler // BootProgress is an optional object so just do nothing if 814978b8803SAndrew Geissler // not found 815978b8803SAndrew Geissler return; 816978b8803SAndrew Geissler } 817978b8803SAndrew Geissler 818978b8803SAndrew Geissler const std::string* bootProgressStr = 819978b8803SAndrew Geissler std::get_if<std::string>(&bootProgress); 820978b8803SAndrew Geissler 821978b8803SAndrew Geissler if (!bootProgressStr) 822978b8803SAndrew Geissler { 823978b8803SAndrew Geissler // Interface implemented but property not found, return error 824978b8803SAndrew Geissler // for that 825978b8803SAndrew Geissler messages::internalError(aResp->res); 826978b8803SAndrew Geissler return; 827978b8803SAndrew Geissler } 828978b8803SAndrew Geissler 829978b8803SAndrew Geissler BMCWEB_LOG_DEBUG << "Boot Progress: " << *bootProgressStr; 830978b8803SAndrew Geissler 831978b8803SAndrew Geissler // Now convert the D-Bus BootProgress to the appropriate Redfish 832978b8803SAndrew Geissler // enum 833978b8803SAndrew Geissler std::string rfBpLastState = "None"; 834978b8803SAndrew Geissler if (*bootProgressStr == "xyz.openbmc_project.State.Boot.Progress." 835978b8803SAndrew Geissler "ProgressStages.Unspecified") 836978b8803SAndrew Geissler { 837978b8803SAndrew Geissler rfBpLastState = "None"; 838978b8803SAndrew Geissler } 839978b8803SAndrew Geissler else if (*bootProgressStr == 840978b8803SAndrew Geissler "xyz.openbmc_project.State.Boot.Progress.ProgressStages." 841978b8803SAndrew Geissler "PrimaryProcInit") 842978b8803SAndrew Geissler { 843978b8803SAndrew Geissler rfBpLastState = "PrimaryProcessorInitializationStarted"; 844978b8803SAndrew Geissler } 845978b8803SAndrew Geissler else if (*bootProgressStr == 846978b8803SAndrew Geissler "xyz.openbmc_project.State.Boot.Progress.ProgressStages." 847978b8803SAndrew Geissler "BusInit") 848978b8803SAndrew Geissler { 849978b8803SAndrew Geissler rfBpLastState = "BusInitializationStarted"; 850978b8803SAndrew Geissler } 851978b8803SAndrew Geissler else if (*bootProgressStr == 852978b8803SAndrew Geissler "xyz.openbmc_project.State.Boot.Progress.ProgressStages." 853978b8803SAndrew Geissler "MemoryInit") 854978b8803SAndrew Geissler { 855978b8803SAndrew Geissler rfBpLastState = "MemoryInitializationStarted"; 856978b8803SAndrew Geissler } 857978b8803SAndrew Geissler else if (*bootProgressStr == 858978b8803SAndrew Geissler "xyz.openbmc_project.State.Boot.Progress.ProgressStages." 859978b8803SAndrew Geissler "SecondaryProcInit") 860978b8803SAndrew Geissler { 861978b8803SAndrew Geissler rfBpLastState = "SecondaryProcessorInitializationStarted"; 862978b8803SAndrew Geissler } 863978b8803SAndrew Geissler else if (*bootProgressStr == 864978b8803SAndrew Geissler "xyz.openbmc_project.State.Boot.Progress.ProgressStages." 865978b8803SAndrew Geissler "PCIInit") 866978b8803SAndrew Geissler { 867978b8803SAndrew Geissler rfBpLastState = "PCIResourceConfigStarted"; 868978b8803SAndrew Geissler } 869978b8803SAndrew Geissler else if (*bootProgressStr == 870978b8803SAndrew Geissler "xyz.openbmc_project.State.Boot.Progress.ProgressStages." 871978b8803SAndrew Geissler "SystemInitComplete") 872978b8803SAndrew Geissler { 873978b8803SAndrew Geissler rfBpLastState = "SystemHardwareInitializationComplete"; 874978b8803SAndrew Geissler } 875978b8803SAndrew Geissler else if (*bootProgressStr == 876978b8803SAndrew Geissler "xyz.openbmc_project.State.Boot.Progress.ProgressStages." 877978b8803SAndrew Geissler "OSStart") 878978b8803SAndrew Geissler { 879978b8803SAndrew Geissler rfBpLastState = "OSBootStarted"; 880978b8803SAndrew Geissler } 881978b8803SAndrew Geissler else if (*bootProgressStr == 882978b8803SAndrew Geissler "xyz.openbmc_project.State.Boot.Progress.ProgressStages." 883978b8803SAndrew Geissler "OSRunning") 884978b8803SAndrew Geissler { 885978b8803SAndrew Geissler rfBpLastState = "OSRunning"; 886978b8803SAndrew Geissler } 887978b8803SAndrew Geissler else 888978b8803SAndrew Geissler { 889978b8803SAndrew Geissler BMCWEB_LOG_DEBUG << "Unsupported D-Bus BootProgress " 890978b8803SAndrew Geissler << *bootProgressStr; 891978b8803SAndrew Geissler // Just return the default 892978b8803SAndrew Geissler } 893978b8803SAndrew Geissler 894978b8803SAndrew Geissler aResp->res.jsonValue["BootProgress"]["LastState"] = rfBpLastState; 895978b8803SAndrew Geissler }, 896978b8803SAndrew Geissler "xyz.openbmc_project.State.Host", "/xyz/openbmc_project/state/host0", 897978b8803SAndrew Geissler "org.freedesktop.DBus.Properties", "Get", 898978b8803SAndrew Geissler "xyz.openbmc_project.State.Boot.Progress", "BootProgress"); 899978b8803SAndrew Geissler } 900491d8ee7SSantosh Puranik 901491d8ee7SSantosh Puranik /** 902491d8ee7SSantosh Puranik * @brief Retrieves boot mode over DBUS and fills out the response 903491d8ee7SSantosh Puranik * 904491d8ee7SSantosh Puranik * @param[in] aResp Shared pointer for generating response message. 905491d8ee7SSantosh Puranik * @param[in] bootDbusObj The dbus object to query for boot properties. 906491d8ee7SSantosh Puranik * 907491d8ee7SSantosh Puranik * @return None. 908491d8ee7SSantosh Puranik */ 9098d1b46d7Szhanghch05 inline void getBootMode(const std::shared_ptr<bmcweb::AsyncResp>& aResp, 910b5a76932SEd Tanous const std::string& bootDbusObj) 911491d8ee7SSantosh Puranik { 912491d8ee7SSantosh Puranik crow::connections::systemBus->async_method_call( 913491d8ee7SSantosh Puranik [aResp](const boost::system::error_code ec, 914491d8ee7SSantosh Puranik const std::variant<std::string>& bootMode) { 915491d8ee7SSantosh Puranik if (ec) 916491d8ee7SSantosh Puranik { 917491d8ee7SSantosh Puranik BMCWEB_LOG_DEBUG << "DBUS response error " << ec; 918491d8ee7SSantosh Puranik messages::internalError(aResp->res); 919491d8ee7SSantosh Puranik return; 920491d8ee7SSantosh Puranik } 921491d8ee7SSantosh Puranik 922491d8ee7SSantosh Puranik const std::string* bootModeStr = 923491d8ee7SSantosh Puranik std::get_if<std::string>(&bootMode); 924491d8ee7SSantosh Puranik 925491d8ee7SSantosh Puranik if (!bootModeStr) 926491d8ee7SSantosh Puranik { 927491d8ee7SSantosh Puranik messages::internalError(aResp->res); 928491d8ee7SSantosh Puranik return; 929491d8ee7SSantosh Puranik } 930491d8ee7SSantosh Puranik 931491d8ee7SSantosh Puranik BMCWEB_LOG_DEBUG << "Boot mode: " << *bootModeStr; 932491d8ee7SSantosh Puranik 933491d8ee7SSantosh Puranik // TODO (Santosh): Do we need to support override mode? 934491d8ee7SSantosh Puranik aResp->res.jsonValue["Boot"]["BootSourceOverrideMode"] = "Legacy"; 935491d8ee7SSantosh Puranik aResp->res.jsonValue["Boot"]["BootSourceOverrideTarget@Redfish." 936491d8ee7SSantosh Puranik "AllowableValues"] = { 937944ffaf9SJohnathan Mantey "None", "Pxe", "Hdd", "Cd", "Diags", "BiosSetup", "Usb"}; 938491d8ee7SSantosh Puranik 939491d8ee7SSantosh Puranik if (*bootModeStr != 940491d8ee7SSantosh Puranik "xyz.openbmc_project.Control.Boot.Mode.Modes.Regular") 941491d8ee7SSantosh Puranik { 942491d8ee7SSantosh Puranik auto rfMode = dbusToRfBootMode(*bootModeStr); 943491d8ee7SSantosh Puranik if (!rfMode.empty()) 944491d8ee7SSantosh Puranik { 945491d8ee7SSantosh Puranik aResp->res.jsonValue["Boot"]["BootSourceOverrideTarget"] = 946491d8ee7SSantosh Puranik rfMode; 947491d8ee7SSantosh Puranik } 948491d8ee7SSantosh Puranik } 949491d8ee7SSantosh Puranik 950491d8ee7SSantosh Puranik // If the BootSourceOverrideTarget is still "None" at the end, 951491d8ee7SSantosh Puranik // reset the BootSourceOverrideEnabled to indicate that 952491d8ee7SSantosh Puranik // overrides are disabled 953491d8ee7SSantosh Puranik if (aResp->res.jsonValue["Boot"]["BootSourceOverrideTarget"] == 954491d8ee7SSantosh Puranik "None") 955491d8ee7SSantosh Puranik { 956491d8ee7SSantosh Puranik aResp->res.jsonValue["Boot"]["BootSourceOverrideEnabled"] = 957491d8ee7SSantosh Puranik "Disabled"; 958491d8ee7SSantosh Puranik } 959491d8ee7SSantosh Puranik }, 960491d8ee7SSantosh Puranik "xyz.openbmc_project.Settings", bootDbusObj, 961491d8ee7SSantosh Puranik "org.freedesktop.DBus.Properties", "Get", 962491d8ee7SSantosh Puranik "xyz.openbmc_project.Control.Boot.Mode", "BootMode"); 963491d8ee7SSantosh Puranik } 964491d8ee7SSantosh Puranik 965491d8ee7SSantosh Puranik /** 966491d8ee7SSantosh Puranik * @brief Retrieves boot source over DBUS 967491d8ee7SSantosh Puranik * 968491d8ee7SSantosh Puranik * @param[in] aResp Shared pointer for generating response message. 969491d8ee7SSantosh Puranik * @param[in] oneTimeEnable Boolean to indicate boot properties are one-time. 970491d8ee7SSantosh Puranik * 971491d8ee7SSantosh Puranik * @return None. 972491d8ee7SSantosh Puranik */ 9738d1b46d7Szhanghch05 inline void getBootSource(const std::shared_ptr<bmcweb::AsyncResp>& aResp, 974f23b7296SEd Tanous bool oneTimeEnabled) 975491d8ee7SSantosh Puranik { 976491d8ee7SSantosh Puranik std::string bootDbusObj = 977491d8ee7SSantosh Puranik oneTimeEnabled ? "/xyz/openbmc_project/control/host0/boot/one_time" 978491d8ee7SSantosh Puranik : "/xyz/openbmc_project/control/host0/boot"; 979491d8ee7SSantosh Puranik 980491d8ee7SSantosh Puranik BMCWEB_LOG_DEBUG << "Is one time: " << oneTimeEnabled; 981491d8ee7SSantosh Puranik aResp->res.jsonValue["Boot"]["BootSourceOverrideEnabled"] = 982491d8ee7SSantosh Puranik (oneTimeEnabled) ? "Once" : "Continuous"; 983491d8ee7SSantosh Puranik 984491d8ee7SSantosh Puranik crow::connections::systemBus->async_method_call( 985491d8ee7SSantosh Puranik [aResp, bootDbusObj](const boost::system::error_code ec, 986491d8ee7SSantosh Puranik const std::variant<std::string>& bootSource) { 987491d8ee7SSantosh Puranik if (ec) 988491d8ee7SSantosh Puranik { 989491d8ee7SSantosh Puranik BMCWEB_LOG_DEBUG << "DBUS response error " << ec; 990491d8ee7SSantosh Puranik messages::internalError(aResp->res); 991491d8ee7SSantosh Puranik return; 992491d8ee7SSantosh Puranik } 993491d8ee7SSantosh Puranik 994491d8ee7SSantosh Puranik const std::string* bootSourceStr = 995491d8ee7SSantosh Puranik std::get_if<std::string>(&bootSource); 996491d8ee7SSantosh Puranik 997491d8ee7SSantosh Puranik if (!bootSourceStr) 998491d8ee7SSantosh Puranik { 999491d8ee7SSantosh Puranik messages::internalError(aResp->res); 1000491d8ee7SSantosh Puranik return; 1001491d8ee7SSantosh Puranik } 1002491d8ee7SSantosh Puranik BMCWEB_LOG_DEBUG << "Boot source: " << *bootSourceStr; 1003491d8ee7SSantosh Puranik 1004491d8ee7SSantosh Puranik auto rfSource = dbusToRfBootSource(*bootSourceStr); 1005491d8ee7SSantosh Puranik if (!rfSource.empty()) 1006491d8ee7SSantosh Puranik { 1007491d8ee7SSantosh Puranik aResp->res.jsonValue["Boot"]["BootSourceOverrideTarget"] = 1008491d8ee7SSantosh Puranik rfSource; 1009491d8ee7SSantosh Puranik } 1010491d8ee7SSantosh Puranik }, 1011491d8ee7SSantosh Puranik "xyz.openbmc_project.Settings", bootDbusObj, 1012491d8ee7SSantosh Puranik "org.freedesktop.DBus.Properties", "Get", 1013491d8ee7SSantosh Puranik "xyz.openbmc_project.Control.Boot.Source", "BootSource"); 1014f23b7296SEd Tanous getBootMode(aResp, bootDbusObj); 1015491d8ee7SSantosh Puranik } 1016491d8ee7SSantosh Puranik 1017491d8ee7SSantosh Puranik /** 1018491d8ee7SSantosh Puranik * @brief Retrieves "One time" enabled setting over DBUS and calls function to 1019491d8ee7SSantosh Puranik * get boot source and boot mode. 1020491d8ee7SSantosh Puranik * 1021491d8ee7SSantosh Puranik * @param[in] aResp Shared pointer for generating response message. 1022491d8ee7SSantosh Puranik * 1023491d8ee7SSantosh Puranik * @return None. 1024491d8ee7SSantosh Puranik */ 10258d1b46d7Szhanghch05 inline void getBootProperties(const std::shared_ptr<bmcweb::AsyncResp>& aResp) 1026491d8ee7SSantosh Puranik { 1027491d8ee7SSantosh Puranik BMCWEB_LOG_DEBUG << "Get boot information."; 1028491d8ee7SSantosh Puranik 1029491d8ee7SSantosh Puranik crow::connections::systemBus->async_method_call( 1030c5d03ff4SJennifer Lee [aResp](const boost::system::error_code ec, 103119bd78d9SPatrick Williams const std::variant<bool>& oneTime) { 1032491d8ee7SSantosh Puranik if (ec) 1033491d8ee7SSantosh Puranik { 1034491d8ee7SSantosh Puranik BMCWEB_LOG_DEBUG << "DBUS response error " << ec; 10352a833c77SJames Feist // not an error, don't have to have the interface 1036491d8ee7SSantosh Puranik return; 1037491d8ee7SSantosh Puranik } 1038491d8ee7SSantosh Puranik 1039491d8ee7SSantosh Puranik const bool* oneTimePtr = std::get_if<bool>(&oneTime); 1040491d8ee7SSantosh Puranik 1041491d8ee7SSantosh Puranik if (!oneTimePtr) 1042491d8ee7SSantosh Puranik { 1043491d8ee7SSantosh Puranik messages::internalError(aResp->res); 1044491d8ee7SSantosh Puranik return; 1045491d8ee7SSantosh Puranik } 1046491d8ee7SSantosh Puranik getBootSource(aResp, *oneTimePtr); 1047491d8ee7SSantosh Puranik }, 1048491d8ee7SSantosh Puranik "xyz.openbmc_project.Settings", 1049491d8ee7SSantosh Puranik "/xyz/openbmc_project/control/host0/boot/one_time", 1050491d8ee7SSantosh Puranik "org.freedesktop.DBus.Properties", "Get", 1051491d8ee7SSantosh Puranik "xyz.openbmc_project.Object.Enable", "Enabled"); 1052491d8ee7SSantosh Puranik } 1053491d8ee7SSantosh Puranik 1054491d8ee7SSantosh Puranik /** 1055c0557e1aSGunnar Mills * @brief Retrieves the Last Reset Time 1056c0557e1aSGunnar Mills * 1057c0557e1aSGunnar Mills * "Reset" is an overloaded term in Redfish, "Reset" includes power on 1058c0557e1aSGunnar Mills * and power off. Even though this is the "system" Redfish object look at the 1059c0557e1aSGunnar Mills * chassis D-Bus interface for the LastStateChangeTime since this has the 1060c0557e1aSGunnar Mills * last power operation time. 1061c0557e1aSGunnar Mills * 1062c0557e1aSGunnar Mills * @param[in] aResp Shared pointer for generating response message. 1063c0557e1aSGunnar Mills * 1064c0557e1aSGunnar Mills * @return None. 1065c0557e1aSGunnar Mills */ 10668d1b46d7Szhanghch05 inline void getLastResetTime(const std::shared_ptr<bmcweb::AsyncResp>& aResp) 1067c0557e1aSGunnar Mills { 1068c0557e1aSGunnar Mills BMCWEB_LOG_DEBUG << "Getting System Last Reset Time"; 1069c0557e1aSGunnar Mills 1070c0557e1aSGunnar Mills crow::connections::systemBus->async_method_call( 1071c0557e1aSGunnar Mills [aResp](const boost::system::error_code ec, 1072c0557e1aSGunnar Mills std::variant<uint64_t>& lastResetTime) { 1073c0557e1aSGunnar Mills if (ec) 1074c0557e1aSGunnar Mills { 1075c0557e1aSGunnar Mills BMCWEB_LOG_DEBUG << "D-BUS response error " << ec; 1076c0557e1aSGunnar Mills return; 1077c0557e1aSGunnar Mills } 1078c0557e1aSGunnar Mills 1079c0557e1aSGunnar Mills const uint64_t* lastResetTimePtr = 1080c0557e1aSGunnar Mills std::get_if<uint64_t>(&lastResetTime); 1081c0557e1aSGunnar Mills 1082c0557e1aSGunnar Mills if (!lastResetTimePtr) 1083c0557e1aSGunnar Mills { 1084c0557e1aSGunnar Mills messages::internalError(aResp->res); 1085c0557e1aSGunnar Mills return; 1086c0557e1aSGunnar Mills } 1087c0557e1aSGunnar Mills // LastStateChangeTime is epoch time, in milliseconds 1088c0557e1aSGunnar Mills // https://github.com/openbmc/phosphor-dbus-interfaces/blob/33e8e1dd64da53a66e888d33dc82001305cd0bf9/xyz/openbmc_project/State/Chassis.interface.yaml#L19 1089c0557e1aSGunnar Mills time_t lastResetTimeStamp = 1090c0557e1aSGunnar Mills static_cast<time_t>(*lastResetTimePtr / 1000); 1091c0557e1aSGunnar Mills 1092c0557e1aSGunnar Mills // Convert to ISO 8601 standard 1093c0557e1aSGunnar Mills aResp->res.jsonValue["LastResetTime"] = 1094c0557e1aSGunnar Mills crow::utility::getDateTime(lastResetTimeStamp); 1095c0557e1aSGunnar Mills }, 1096c0557e1aSGunnar Mills "xyz.openbmc_project.State.Chassis", 1097c0557e1aSGunnar Mills "/xyz/openbmc_project/state/chassis0", 1098c0557e1aSGunnar Mills "org.freedesktop.DBus.Properties", "Get", 1099c0557e1aSGunnar Mills "xyz.openbmc_project.State.Chassis", "LastStateChangeTime"); 1100c0557e1aSGunnar Mills } 1101c0557e1aSGunnar Mills 1102c0557e1aSGunnar Mills /** 11036bd5a8d2SGunnar Mills * @brief Retrieves Automatic Retry properties. Known on D-Bus as AutoReboot. 11046bd5a8d2SGunnar Mills * 11056bd5a8d2SGunnar Mills * @param[in] aResp Shared pointer for generating response message. 11066bd5a8d2SGunnar Mills * 11076bd5a8d2SGunnar Mills * @return None. 11086bd5a8d2SGunnar Mills */ 11098d1b46d7Szhanghch05 inline void getAutomaticRetry(const std::shared_ptr<bmcweb::AsyncResp>& aResp) 11106bd5a8d2SGunnar Mills { 11116bd5a8d2SGunnar Mills BMCWEB_LOG_DEBUG << "Get Automatic Retry policy"; 11126bd5a8d2SGunnar Mills 11136bd5a8d2SGunnar Mills crow::connections::systemBus->async_method_call( 11146bd5a8d2SGunnar Mills [aResp](const boost::system::error_code ec, 11156bd5a8d2SGunnar Mills std::variant<bool>& autoRebootEnabled) { 11166bd5a8d2SGunnar Mills if (ec) 11176bd5a8d2SGunnar Mills { 11186bd5a8d2SGunnar Mills BMCWEB_LOG_DEBUG << "D-BUS response error " << ec; 11196bd5a8d2SGunnar Mills return; 11206bd5a8d2SGunnar Mills } 11216bd5a8d2SGunnar Mills 11226bd5a8d2SGunnar Mills const bool* autoRebootEnabledPtr = 11236bd5a8d2SGunnar Mills std::get_if<bool>(&autoRebootEnabled); 11246bd5a8d2SGunnar Mills 11256bd5a8d2SGunnar Mills if (!autoRebootEnabledPtr) 11266bd5a8d2SGunnar Mills { 11276bd5a8d2SGunnar Mills messages::internalError(aResp->res); 11286bd5a8d2SGunnar Mills return; 11296bd5a8d2SGunnar Mills } 11306bd5a8d2SGunnar Mills 11316bd5a8d2SGunnar Mills BMCWEB_LOG_DEBUG << "Auto Reboot: " << *autoRebootEnabledPtr; 11326bd5a8d2SGunnar Mills if (*autoRebootEnabledPtr == true) 11336bd5a8d2SGunnar Mills { 11346bd5a8d2SGunnar Mills aResp->res.jsonValue["Boot"]["AutomaticRetryConfig"] = 11356bd5a8d2SGunnar Mills "RetryAttempts"; 11366bd5a8d2SGunnar Mills // If AutomaticRetry (AutoReboot) is enabled see how many 11376bd5a8d2SGunnar Mills // attempts are left 11386bd5a8d2SGunnar Mills crow::connections::systemBus->async_method_call( 1139cb13a392SEd Tanous [aResp](const boost::system::error_code ec2, 11406bd5a8d2SGunnar Mills std::variant<uint32_t>& autoRebootAttemptsLeft) { 1141cb13a392SEd Tanous if (ec2) 11426bd5a8d2SGunnar Mills { 1143cb13a392SEd Tanous BMCWEB_LOG_DEBUG << "D-BUS response error " << ec2; 11446bd5a8d2SGunnar Mills return; 11456bd5a8d2SGunnar Mills } 11466bd5a8d2SGunnar Mills 11476bd5a8d2SGunnar Mills const uint32_t* autoRebootAttemptsLeftPtr = 11486bd5a8d2SGunnar Mills std::get_if<uint32_t>(&autoRebootAttemptsLeft); 11496bd5a8d2SGunnar Mills 11506bd5a8d2SGunnar Mills if (!autoRebootAttemptsLeftPtr) 11516bd5a8d2SGunnar Mills { 11526bd5a8d2SGunnar Mills messages::internalError(aResp->res); 11536bd5a8d2SGunnar Mills return; 11546bd5a8d2SGunnar Mills } 11556bd5a8d2SGunnar Mills 11566bd5a8d2SGunnar Mills BMCWEB_LOG_DEBUG << "Auto Reboot Attempts Left: " 11576bd5a8d2SGunnar Mills << *autoRebootAttemptsLeftPtr; 11586bd5a8d2SGunnar Mills 11596bd5a8d2SGunnar Mills aResp->res 11606bd5a8d2SGunnar Mills .jsonValue["Boot"] 11616bd5a8d2SGunnar Mills ["RemainingAutomaticRetryAttempts"] = 11626bd5a8d2SGunnar Mills *autoRebootAttemptsLeftPtr; 11636bd5a8d2SGunnar Mills }, 11646bd5a8d2SGunnar Mills "xyz.openbmc_project.State.Host", 11656bd5a8d2SGunnar Mills "/xyz/openbmc_project/state/host0", 11666bd5a8d2SGunnar Mills "org.freedesktop.DBus.Properties", "Get", 11676bd5a8d2SGunnar Mills "xyz.openbmc_project.Control.Boot.RebootAttempts", 11686bd5a8d2SGunnar Mills "AttemptsLeft"); 11696bd5a8d2SGunnar Mills } 11706bd5a8d2SGunnar Mills else 11716bd5a8d2SGunnar Mills { 11726bd5a8d2SGunnar Mills aResp->res.jsonValue["Boot"]["AutomaticRetryConfig"] = 11736bd5a8d2SGunnar Mills "Disabled"; 11746bd5a8d2SGunnar Mills } 11756bd5a8d2SGunnar Mills 11766bd5a8d2SGunnar Mills // Not on D-Bus. Hardcoded here: 11776bd5a8d2SGunnar Mills // https://github.com/openbmc/phosphor-state-manager/blob/1dbbef42675e94fb1f78edb87d6b11380260535a/meson_options.txt#L71 11786bd5a8d2SGunnar Mills aResp->res.jsonValue["Boot"]["AutomaticRetryAttempts"] = 3; 117969f35306SGunnar Mills 118069f35306SGunnar Mills // "AutomaticRetryConfig" can be 3 values, Disabled, RetryAlways, 118169f35306SGunnar Mills // and RetryAttempts. OpenBMC only supports Disabled and 118269f35306SGunnar Mills // RetryAttempts. 118369f35306SGunnar Mills aResp->res.jsonValue["Boot"]["AutomaticRetryConfig@Redfish." 118469f35306SGunnar Mills "AllowableValues"] = {"Disabled", 118569f35306SGunnar Mills "RetryAttempts"}; 11866bd5a8d2SGunnar Mills }, 11876bd5a8d2SGunnar Mills "xyz.openbmc_project.Settings", 11886bd5a8d2SGunnar Mills "/xyz/openbmc_project/control/host0/auto_reboot", 11896bd5a8d2SGunnar Mills "org.freedesktop.DBus.Properties", "Get", 11906bd5a8d2SGunnar Mills "xyz.openbmc_project.Control.Boot.RebootPolicy", "AutoReboot"); 11916bd5a8d2SGunnar Mills } 11926bd5a8d2SGunnar Mills 11936bd5a8d2SGunnar Mills /** 1194c6a620f2SGeorge Liu * @brief Retrieves power restore policy over DBUS. 1195c6a620f2SGeorge Liu * 1196c6a620f2SGeorge Liu * @param[in] aResp Shared pointer for generating response message. 1197c6a620f2SGeorge Liu * 1198c6a620f2SGeorge Liu * @return None. 1199c6a620f2SGeorge Liu */ 12008d1b46d7Szhanghch05 inline void 12018d1b46d7Szhanghch05 getPowerRestorePolicy(const std::shared_ptr<bmcweb::AsyncResp>& aResp) 1202c6a620f2SGeorge Liu { 1203c6a620f2SGeorge Liu BMCWEB_LOG_DEBUG << "Get power restore policy"; 1204c6a620f2SGeorge Liu 1205c6a620f2SGeorge Liu crow::connections::systemBus->async_method_call( 1206c6a620f2SGeorge Liu [aResp](const boost::system::error_code ec, 120719bd78d9SPatrick Williams std::variant<std::string>& policy) { 1208c6a620f2SGeorge Liu if (ec) 1209c6a620f2SGeorge Liu { 1210c6a620f2SGeorge Liu BMCWEB_LOG_DEBUG << "DBUS response error " << ec; 1211c6a620f2SGeorge Liu return; 1212c6a620f2SGeorge Liu } 1213c6a620f2SGeorge Liu 1214c6a620f2SGeorge Liu const boost::container::flat_map<std::string, std::string> 1215c6a620f2SGeorge Liu policyMaps = { 1216c6a620f2SGeorge Liu {"xyz.openbmc_project.Control.Power.RestorePolicy.Policy." 1217c6a620f2SGeorge Liu "AlwaysOn", 1218c6a620f2SGeorge Liu "AlwaysOn"}, 1219c6a620f2SGeorge Liu {"xyz.openbmc_project.Control.Power.RestorePolicy.Policy." 1220c6a620f2SGeorge Liu "AlwaysOff", 1221c6a620f2SGeorge Liu "AlwaysOff"}, 1222c6a620f2SGeorge Liu {"xyz.openbmc_project.Control.Power.RestorePolicy.Policy." 122337ec9072SGunnar Mills "Restore", 1224c6a620f2SGeorge Liu "LastState"}}; 1225c6a620f2SGeorge Liu 1226c6a620f2SGeorge Liu const std::string* policyPtr = std::get_if<std::string>(&policy); 1227c6a620f2SGeorge Liu 1228c6a620f2SGeorge Liu if (!policyPtr) 1229c6a620f2SGeorge Liu { 1230c6a620f2SGeorge Liu messages::internalError(aResp->res); 1231c6a620f2SGeorge Liu return; 1232c6a620f2SGeorge Liu } 1233c6a620f2SGeorge Liu 1234c6a620f2SGeorge Liu auto policyMapsIt = policyMaps.find(*policyPtr); 1235c6a620f2SGeorge Liu if (policyMapsIt == policyMaps.end()) 1236c6a620f2SGeorge Liu { 1237c6a620f2SGeorge Liu messages::internalError(aResp->res); 1238c6a620f2SGeorge Liu return; 1239c6a620f2SGeorge Liu } 1240c6a620f2SGeorge Liu 1241c6a620f2SGeorge Liu aResp->res.jsonValue["PowerRestorePolicy"] = policyMapsIt->second; 1242c6a620f2SGeorge Liu }, 1243c6a620f2SGeorge Liu "xyz.openbmc_project.Settings", 1244c6a620f2SGeorge Liu "/xyz/openbmc_project/control/host0/power_restore_policy", 1245c6a620f2SGeorge Liu "org.freedesktop.DBus.Properties", "Get", 1246c6a620f2SGeorge Liu "xyz.openbmc_project.Control.Power.RestorePolicy", 1247c6a620f2SGeorge Liu "PowerRestorePolicy"); 1248c6a620f2SGeorge Liu } 1249c6a620f2SGeorge Liu 1250c6a620f2SGeorge Liu /** 12511981771bSAli Ahmed * @brief Get TrustedModuleRequiredToBoot property. Determines whether or not 12521981771bSAli Ahmed * TPM is required for booting the host. 12531981771bSAli Ahmed * 12541981771bSAli Ahmed * @param[in] aResp Shared pointer for generating response message. 12551981771bSAli Ahmed * 12561981771bSAli Ahmed * @return None. 12571981771bSAli Ahmed */ 12581981771bSAli Ahmed inline void getTrustedModuleRequiredToBoot( 12591981771bSAli Ahmed const std::shared_ptr<bmcweb::AsyncResp>& aResp) 12601981771bSAli Ahmed { 12611981771bSAli Ahmed BMCWEB_LOG_DEBUG << "Get TPM required to boot."; 12621981771bSAli Ahmed 12631981771bSAli Ahmed crow::connections::systemBus->async_method_call( 12641981771bSAli Ahmed [aResp]( 12651981771bSAli Ahmed const boost::system::error_code ec, 12661981771bSAli Ahmed std::vector<std::pair< 12671981771bSAli Ahmed std::string, 12681981771bSAli Ahmed std::vector<std::pair<std::string, std::vector<std::string>>>>>& 12691981771bSAli Ahmed subtree) { 12701981771bSAli Ahmed if (ec) 12711981771bSAli Ahmed { 12721981771bSAli Ahmed BMCWEB_LOG_DEBUG 12731981771bSAli Ahmed << "DBUS response error on TPM.Policy GetSubTree" << ec; 12741981771bSAli Ahmed // This is an optional D-Bus object so just return if 12751981771bSAli Ahmed // error occurs 12761981771bSAli Ahmed return; 12771981771bSAli Ahmed } 12781981771bSAli Ahmed if (subtree.size() == 0) 12791981771bSAli Ahmed { 12801981771bSAli Ahmed // As noted above, this is an optional interface so just return 12811981771bSAli Ahmed // if there is no instance found 12821981771bSAli Ahmed return; 12831981771bSAli Ahmed } 12841981771bSAli Ahmed 12851981771bSAli Ahmed /* When there is more than one TPMEnable object... */ 12861981771bSAli Ahmed if (subtree.size() > 1) 12871981771bSAli Ahmed { 12881981771bSAli Ahmed BMCWEB_LOG_DEBUG 12891981771bSAli Ahmed << "DBUS response has more than 1 TPM Enable object:" 12901981771bSAli Ahmed << subtree.size(); 12911981771bSAli Ahmed // Throw an internal Error and return 12921981771bSAli Ahmed messages::internalError(aResp->res); 12931981771bSAli Ahmed return; 12941981771bSAli Ahmed } 12951981771bSAli Ahmed 12961981771bSAli Ahmed // Make sure the Dbus response map has a service and objectPath 12971981771bSAli Ahmed // field 12981981771bSAli Ahmed if (subtree[0].first.empty() || subtree[0].second.size() != 1) 12991981771bSAli Ahmed { 13001981771bSAli Ahmed BMCWEB_LOG_DEBUG << "TPM.Policy mapper error!"; 13011981771bSAli Ahmed messages::internalError(aResp->res); 13021981771bSAli Ahmed return; 13031981771bSAli Ahmed } 13041981771bSAli Ahmed 13051981771bSAli Ahmed const std::string& path = subtree[0].first; 13061981771bSAli Ahmed const std::string& serv = subtree[0].second.begin()->first; 13071981771bSAli Ahmed 13081981771bSAli Ahmed // Valid TPM Enable object found, now reading the current value 13091981771bSAli Ahmed crow::connections::systemBus->async_method_call( 13101981771bSAli Ahmed [aResp](const boost::system::error_code ec, 13111981771bSAli Ahmed std::variant<bool>& tpmRequired) { 13121981771bSAli Ahmed if (ec) 13131981771bSAli Ahmed { 13141981771bSAli Ahmed BMCWEB_LOG_DEBUG 13151981771bSAli Ahmed << "D-BUS response error on TPM.Policy Get" << ec; 13161981771bSAli Ahmed messages::internalError(aResp->res); 13171981771bSAli Ahmed return; 13181981771bSAli Ahmed } 13191981771bSAli Ahmed 13201981771bSAli Ahmed const bool* tpmRequiredVal = 13211981771bSAli Ahmed std::get_if<bool>(&tpmRequired); 13221981771bSAli Ahmed 13231981771bSAli Ahmed if (!tpmRequiredVal) 13241981771bSAli Ahmed { 13251981771bSAli Ahmed messages::internalError(aResp->res); 13261981771bSAli Ahmed return; 13271981771bSAli Ahmed } 13281981771bSAli Ahmed 13291981771bSAli Ahmed if (*tpmRequiredVal == true) 13301981771bSAli Ahmed { 13311981771bSAli Ahmed aResp->res 13321981771bSAli Ahmed .jsonValue["Boot"]["TrustedModuleRequiredToBoot"] = 13331981771bSAli Ahmed "Required"; 13341981771bSAli Ahmed } 13351981771bSAli Ahmed else 13361981771bSAli Ahmed { 13371981771bSAli Ahmed aResp->res 13381981771bSAli Ahmed .jsonValue["Boot"]["TrustedModuleRequiredToBoot"] = 13391981771bSAli Ahmed "Disabled"; 13401981771bSAli Ahmed } 13411981771bSAli Ahmed }, 13421981771bSAli Ahmed serv, path, "org.freedesktop.DBus.Properties", "Get", 13431981771bSAli Ahmed "xyz.openbmc_project.Control.TPM.Policy", "TPMEnable"); 13441981771bSAli Ahmed }, 13451981771bSAli Ahmed "xyz.openbmc_project.ObjectMapper", 13461981771bSAli Ahmed "/xyz/openbmc_project/object_mapper", 13471981771bSAli Ahmed "xyz.openbmc_project.ObjectMapper", "GetSubTree", "/", int32_t(0), 13481981771bSAli Ahmed std::array<const char*, 1>{"xyz.openbmc_project.Control.TPM.Policy"}); 13491981771bSAli Ahmed } 13501981771bSAli Ahmed 13511981771bSAli Ahmed /** 1352491d8ee7SSantosh Puranik * @brief Sets boot properties into DBUS object(s). 1353491d8ee7SSantosh Puranik * 1354491d8ee7SSantosh Puranik * @param[in] aResp Shared pointer for generating response message. 1355491d8ee7SSantosh Puranik * @param[in] oneTimeEnabled Is "one-time" setting already enabled. 1356491d8ee7SSantosh Puranik * @param[in] bootSource The boot source to set. 1357491d8ee7SSantosh Puranik * @param[in] bootEnable The source override "enable" to set. 1358491d8ee7SSantosh Puranik * 1359265c1602SJohnathan Mantey * @return Integer error code. 1360491d8ee7SSantosh Puranik */ 13618d1b46d7Szhanghch05 inline void setBootModeOrSource(std::shared_ptr<bmcweb::AsyncResp> aResp, 1362491d8ee7SSantosh Puranik bool oneTimeEnabled, 1363f23b7296SEd Tanous const std::optional<std::string>& bootSource, 1364f23b7296SEd Tanous const std::optional<std::string>& bootEnable) 1365491d8ee7SSantosh Puranik { 1366944ffaf9SJohnathan Mantey std::string bootSourceStr = 1367944ffaf9SJohnathan Mantey "xyz.openbmc_project.Control.Boot.Source.Sources.Default"; 1368944ffaf9SJohnathan Mantey std::string bootModeStr = 1369944ffaf9SJohnathan Mantey "xyz.openbmc_project.Control.Boot.Mode.Modes.Regular"; 1370491d8ee7SSantosh Puranik bool oneTimeSetting = oneTimeEnabled; 1371944ffaf9SJohnathan Mantey bool useBootSource = true; 1372944ffaf9SJohnathan Mantey 1373491d8ee7SSantosh Puranik // Validate incoming parameters 1374491d8ee7SSantosh Puranik if (bootEnable) 1375491d8ee7SSantosh Puranik { 1376491d8ee7SSantosh Puranik if (*bootEnable == "Once") 1377491d8ee7SSantosh Puranik { 1378491d8ee7SSantosh Puranik oneTimeSetting = true; 1379491d8ee7SSantosh Puranik } 1380491d8ee7SSantosh Puranik else if (*bootEnable == "Continuous") 1381491d8ee7SSantosh Puranik { 1382491d8ee7SSantosh Puranik oneTimeSetting = false; 1383491d8ee7SSantosh Puranik } 1384491d8ee7SSantosh Puranik else if (*bootEnable == "Disabled") 1385491d8ee7SSantosh Puranik { 1386944ffaf9SJohnathan Mantey BMCWEB_LOG_DEBUG << "Boot source override will be disabled"; 1387491d8ee7SSantosh Puranik oneTimeSetting = false; 1388944ffaf9SJohnathan Mantey useBootSource = false; 1389491d8ee7SSantosh Puranik } 1390491d8ee7SSantosh Puranik else 1391491d8ee7SSantosh Puranik { 1392491d8ee7SSantosh Puranik BMCWEB_LOG_DEBUG << "Unsupported value for " 1393491d8ee7SSantosh Puranik "BootSourceOverrideEnabled: " 1394491d8ee7SSantosh Puranik << *bootEnable; 1395491d8ee7SSantosh Puranik messages::propertyValueNotInList(aResp->res, *bootEnable, 1396491d8ee7SSantosh Puranik "BootSourceOverrideEnabled"); 1397491d8ee7SSantosh Puranik return; 1398491d8ee7SSantosh Puranik } 1399491d8ee7SSantosh Puranik } 1400491d8ee7SSantosh Puranik 1401944ffaf9SJohnathan Mantey if (bootSource && useBootSource) 1402491d8ee7SSantosh Puranik { 1403491d8ee7SSantosh Puranik // Source target specified 1404491d8ee7SSantosh Puranik BMCWEB_LOG_DEBUG << "Boot source: " << *bootSource; 1405491d8ee7SSantosh Puranik // Figure out which DBUS interface and property to use 1406944ffaf9SJohnathan Mantey if (assignBootParameters(aResp, *bootSource, bootSourceStr, 1407944ffaf9SJohnathan Mantey bootModeStr)) 1408491d8ee7SSantosh Puranik { 1409944ffaf9SJohnathan Mantey BMCWEB_LOG_DEBUG 1410944ffaf9SJohnathan Mantey << "Invalid property value for BootSourceOverrideTarget: " 1411491d8ee7SSantosh Puranik << *bootSource; 1412491d8ee7SSantosh Puranik messages::propertyValueNotInList(aResp->res, *bootSource, 1413491d8ee7SSantosh Puranik "BootSourceTargetOverride"); 1414491d8ee7SSantosh Puranik return; 1415491d8ee7SSantosh Puranik } 1416944ffaf9SJohnathan Mantey } 1417491d8ee7SSantosh Puranik 1418944ffaf9SJohnathan Mantey // Act on validated parameters 1419944ffaf9SJohnathan Mantey BMCWEB_LOG_DEBUG << "DBUS boot source: " << bootSourceStr; 1420944ffaf9SJohnathan Mantey BMCWEB_LOG_DEBUG << "DBUS boot mode: " << bootModeStr; 1421944ffaf9SJohnathan Mantey const char* bootObj = 1422944ffaf9SJohnathan Mantey oneTimeSetting ? "/xyz/openbmc_project/control/host0/boot/one_time" 1423944ffaf9SJohnathan Mantey : "/xyz/openbmc_project/control/host0/boot"; 1424944ffaf9SJohnathan Mantey 1425491d8ee7SSantosh Puranik crow::connections::systemBus->async_method_call( 1426491d8ee7SSantosh Puranik [aResp](const boost::system::error_code ec) { 1427491d8ee7SSantosh Puranik if (ec) 1428491d8ee7SSantosh Puranik { 1429491d8ee7SSantosh Puranik BMCWEB_LOG_DEBUG << "DBUS response error " << ec; 1430491d8ee7SSantosh Puranik messages::internalError(aResp->res); 1431491d8ee7SSantosh Puranik return; 1432491d8ee7SSantosh Puranik } 1433491d8ee7SSantosh Puranik BMCWEB_LOG_DEBUG << "Boot source update done."; 1434491d8ee7SSantosh Puranik }, 1435491d8ee7SSantosh Puranik "xyz.openbmc_project.Settings", bootObj, 1436491d8ee7SSantosh Puranik "org.freedesktop.DBus.Properties", "Set", 1437491d8ee7SSantosh Puranik "xyz.openbmc_project.Control.Boot.Source", "BootSource", 1438491d8ee7SSantosh Puranik std::variant<std::string>(bootSourceStr)); 1439944ffaf9SJohnathan Mantey 1440491d8ee7SSantosh Puranik crow::connections::systemBus->async_method_call( 1441491d8ee7SSantosh Puranik [aResp](const boost::system::error_code ec) { 1442491d8ee7SSantosh Puranik if (ec) 1443491d8ee7SSantosh Puranik { 1444491d8ee7SSantosh Puranik BMCWEB_LOG_DEBUG << "DBUS response error " << ec; 1445491d8ee7SSantosh Puranik messages::internalError(aResp->res); 1446491d8ee7SSantosh Puranik return; 1447491d8ee7SSantosh Puranik } 1448491d8ee7SSantosh Puranik BMCWEB_LOG_DEBUG << "Boot mode update done."; 1449491d8ee7SSantosh Puranik }, 1450491d8ee7SSantosh Puranik "xyz.openbmc_project.Settings", bootObj, 1451491d8ee7SSantosh Puranik "org.freedesktop.DBus.Properties", "Set", 1452491d8ee7SSantosh Puranik "xyz.openbmc_project.Control.Boot.Mode", "BootMode", 1453491d8ee7SSantosh Puranik std::variant<std::string>(bootModeStr)); 1454944ffaf9SJohnathan Mantey 1455491d8ee7SSantosh Puranik crow::connections::systemBus->async_method_call( 1456491d8ee7SSantosh Puranik [aResp{std::move(aResp)}](const boost::system::error_code ec) { 1457491d8ee7SSantosh Puranik if (ec) 1458491d8ee7SSantosh Puranik { 1459491d8ee7SSantosh Puranik BMCWEB_LOG_DEBUG << "DBUS response error " << ec; 1460491d8ee7SSantosh Puranik messages::internalError(aResp->res); 1461491d8ee7SSantosh Puranik return; 1462491d8ee7SSantosh Puranik } 1463491d8ee7SSantosh Puranik BMCWEB_LOG_DEBUG << "Boot enable update done."; 1464491d8ee7SSantosh Puranik }, 1465491d8ee7SSantosh Puranik "xyz.openbmc_project.Settings", 1466491d8ee7SSantosh Puranik "/xyz/openbmc_project/control/host0/boot/one_time", 1467491d8ee7SSantosh Puranik "org.freedesktop.DBus.Properties", "Set", 1468491d8ee7SSantosh Puranik "xyz.openbmc_project.Object.Enable", "Enabled", 1469491d8ee7SSantosh Puranik std::variant<bool>(oneTimeSetting)); 1470491d8ee7SSantosh Puranik } 1471491d8ee7SSantosh Puranik 1472491d8ee7SSantosh Puranik /** 1473491d8ee7SSantosh Puranik * @brief Retrieves "One time" enabled setting over DBUS and calls function to 1474491d8ee7SSantosh Puranik * set boot source/boot mode properties. 1475491d8ee7SSantosh Puranik * 1476491d8ee7SSantosh Puranik * @param[in] aResp Shared pointer for generating response message. 1477491d8ee7SSantosh Puranik * @param[in] bootSource The boot source from incoming RF request. 1478491d8ee7SSantosh Puranik * @param[in] bootEnable The boot override enable from incoming RF request. 1479491d8ee7SSantosh Puranik * 1480265c1602SJohnathan Mantey * @return Integer error code. 1481491d8ee7SSantosh Puranik */ 14828d1b46d7Szhanghch05 inline void 14838d1b46d7Szhanghch05 setBootSourceProperties(const std::shared_ptr<bmcweb::AsyncResp>& aResp, 1484491d8ee7SSantosh Puranik std::optional<std::string> bootSource, 1485491d8ee7SSantosh Puranik std::optional<std::string> bootEnable) 1486491d8ee7SSantosh Puranik { 1487491d8ee7SSantosh Puranik BMCWEB_LOG_DEBUG << "Set boot information."; 1488491d8ee7SSantosh Puranik 1489491d8ee7SSantosh Puranik crow::connections::systemBus->async_method_call( 1490265c1602SJohnathan Mantey [aResp, bootSource{std::move(bootSource)}, 149119bd78d9SPatrick Williams bootEnable{std::move(bootEnable)}](const boost::system::error_code ec, 149219bd78d9SPatrick Williams const std::variant<bool>& oneTime) { 1493491d8ee7SSantosh Puranik if (ec) 1494491d8ee7SSantosh Puranik { 1495491d8ee7SSantosh Puranik BMCWEB_LOG_DEBUG << "DBUS response error " << ec; 1496491d8ee7SSantosh Puranik messages::internalError(aResp->res); 1497491d8ee7SSantosh Puranik return; 1498491d8ee7SSantosh Puranik } 1499491d8ee7SSantosh Puranik 1500491d8ee7SSantosh Puranik const bool* oneTimePtr = std::get_if<bool>(&oneTime); 1501491d8ee7SSantosh Puranik 1502491d8ee7SSantosh Puranik if (!oneTimePtr) 1503491d8ee7SSantosh Puranik { 1504491d8ee7SSantosh Puranik messages::internalError(aResp->res); 1505491d8ee7SSantosh Puranik return; 1506491d8ee7SSantosh Puranik } 1507491d8ee7SSantosh Puranik 1508491d8ee7SSantosh Puranik BMCWEB_LOG_DEBUG << "Got one time: " << *oneTimePtr; 1509491d8ee7SSantosh Puranik 1510f23b7296SEd Tanous setBootModeOrSource(aResp, *oneTimePtr, bootSource, bootEnable); 1511491d8ee7SSantosh Puranik }, 1512491d8ee7SSantosh Puranik "xyz.openbmc_project.Settings", 1513491d8ee7SSantosh Puranik "/xyz/openbmc_project/control/host0/boot/one_time", 1514491d8ee7SSantosh Puranik "org.freedesktop.DBus.Properties", "Get", 1515491d8ee7SSantosh Puranik "xyz.openbmc_project.Object.Enable", "Enabled"); 1516491d8ee7SSantosh Puranik } 1517491d8ee7SSantosh Puranik 1518c6a620f2SGeorge Liu /** 151998e386ecSGunnar Mills * @brief Sets AssetTag 152098e386ecSGunnar Mills * 152198e386ecSGunnar Mills * @param[in] aResp Shared pointer for generating response message. 152298e386ecSGunnar Mills * @param[in] assetTag "AssetTag" from request. 152398e386ecSGunnar Mills * 152498e386ecSGunnar Mills * @return None. 152598e386ecSGunnar Mills */ 15268d1b46d7Szhanghch05 inline void setAssetTag(const std::shared_ptr<bmcweb::AsyncResp>& aResp, 152798e386ecSGunnar Mills const std::string& assetTag) 152898e386ecSGunnar Mills { 152998e386ecSGunnar Mills crow::connections::systemBus->async_method_call( 153098e386ecSGunnar Mills [aResp, assetTag]( 153198e386ecSGunnar Mills const boost::system::error_code ec, 153298e386ecSGunnar Mills const std::vector<std::pair< 153398e386ecSGunnar Mills std::string, 153498e386ecSGunnar Mills std::vector<std::pair<std::string, std::vector<std::string>>>>>& 153598e386ecSGunnar Mills subtree) { 153698e386ecSGunnar Mills if (ec) 153798e386ecSGunnar Mills { 153898e386ecSGunnar Mills BMCWEB_LOG_DEBUG << "D-Bus response error on GetSubTree " << ec; 153998e386ecSGunnar Mills messages::internalError(aResp->res); 154098e386ecSGunnar Mills return; 154198e386ecSGunnar Mills } 154298e386ecSGunnar Mills if (subtree.size() == 0) 154398e386ecSGunnar Mills { 154498e386ecSGunnar Mills BMCWEB_LOG_DEBUG << "Can't find system D-Bus object!"; 154598e386ecSGunnar Mills messages::internalError(aResp->res); 154698e386ecSGunnar Mills return; 154798e386ecSGunnar Mills } 154898e386ecSGunnar Mills // Assume only 1 system D-Bus object 154998e386ecSGunnar Mills // Throw an error if there is more than 1 155098e386ecSGunnar Mills if (subtree.size() > 1) 155198e386ecSGunnar Mills { 155298e386ecSGunnar Mills BMCWEB_LOG_DEBUG << "Found more than 1 system D-Bus object!"; 155398e386ecSGunnar Mills messages::internalError(aResp->res); 155498e386ecSGunnar Mills return; 155598e386ecSGunnar Mills } 155698e386ecSGunnar Mills if (subtree[0].first.empty() || subtree[0].second.size() != 1) 155798e386ecSGunnar Mills { 155898e386ecSGunnar Mills BMCWEB_LOG_DEBUG << "Asset Tag Set mapper error!"; 155998e386ecSGunnar Mills messages::internalError(aResp->res); 156098e386ecSGunnar Mills return; 156198e386ecSGunnar Mills } 156298e386ecSGunnar Mills 156398e386ecSGunnar Mills const std::string& path = subtree[0].first; 156498e386ecSGunnar Mills const std::string& service = subtree[0].second.begin()->first; 156598e386ecSGunnar Mills 156698e386ecSGunnar Mills if (service.empty()) 156798e386ecSGunnar Mills { 156898e386ecSGunnar Mills BMCWEB_LOG_DEBUG << "Asset Tag Set service mapper error!"; 156998e386ecSGunnar Mills messages::internalError(aResp->res); 157098e386ecSGunnar Mills return; 157198e386ecSGunnar Mills } 157298e386ecSGunnar Mills 157398e386ecSGunnar Mills crow::connections::systemBus->async_method_call( 157498e386ecSGunnar Mills [aResp](const boost::system::error_code ec2) { 157598e386ecSGunnar Mills if (ec2) 157698e386ecSGunnar Mills { 157798e386ecSGunnar Mills BMCWEB_LOG_DEBUG 157898e386ecSGunnar Mills << "D-Bus response error on AssetTag Set " << ec2; 157998e386ecSGunnar Mills messages::internalError(aResp->res); 158098e386ecSGunnar Mills return; 158198e386ecSGunnar Mills } 158298e386ecSGunnar Mills }, 158398e386ecSGunnar Mills service, path, "org.freedesktop.DBus.Properties", "Set", 158498e386ecSGunnar Mills "xyz.openbmc_project.Inventory.Decorator.AssetTag", "AssetTag", 158598e386ecSGunnar Mills std::variant<std::string>(assetTag)); 158698e386ecSGunnar Mills }, 158798e386ecSGunnar Mills "xyz.openbmc_project.ObjectMapper", 158898e386ecSGunnar Mills "/xyz/openbmc_project/object_mapper", 158998e386ecSGunnar Mills "xyz.openbmc_project.ObjectMapper", "GetSubTree", 159098e386ecSGunnar Mills "/xyz/openbmc_project/inventory", int32_t(0), 159198e386ecSGunnar Mills std::array<const char*, 1>{ 159298e386ecSGunnar Mills "xyz.openbmc_project.Inventory.Item.System"}); 159398e386ecSGunnar Mills } 159498e386ecSGunnar Mills 159598e386ecSGunnar Mills /** 159669f35306SGunnar Mills * @brief Sets automaticRetry (Auto Reboot) 159769f35306SGunnar Mills * 159869f35306SGunnar Mills * @param[in] aResp Shared pointer for generating response message. 159969f35306SGunnar Mills * @param[in] automaticRetryConfig "AutomaticRetryConfig" from request. 160069f35306SGunnar Mills * 160169f35306SGunnar Mills * @return None. 160269f35306SGunnar Mills */ 16038d1b46d7Szhanghch05 inline void setAutomaticRetry(const std::shared_ptr<bmcweb::AsyncResp>& aResp, 1604f23b7296SEd Tanous const std::string& automaticRetryConfig) 160569f35306SGunnar Mills { 160669f35306SGunnar Mills BMCWEB_LOG_DEBUG << "Set Automatic Retry."; 160769f35306SGunnar Mills 160869f35306SGunnar Mills // OpenBMC only supports "Disabled" and "RetryAttempts". 160969f35306SGunnar Mills bool autoRebootEnabled; 161069f35306SGunnar Mills 161169f35306SGunnar Mills if (automaticRetryConfig == "Disabled") 161269f35306SGunnar Mills { 161369f35306SGunnar Mills autoRebootEnabled = false; 161469f35306SGunnar Mills } 161569f35306SGunnar Mills else if (automaticRetryConfig == "RetryAttempts") 161669f35306SGunnar Mills { 161769f35306SGunnar Mills autoRebootEnabled = true; 161869f35306SGunnar Mills } 161969f35306SGunnar Mills else 162069f35306SGunnar Mills { 162169f35306SGunnar Mills BMCWEB_LOG_DEBUG << "Invalid property value for " 162269f35306SGunnar Mills "AutomaticRetryConfig: " 162369f35306SGunnar Mills << automaticRetryConfig; 162469f35306SGunnar Mills messages::propertyValueNotInList(aResp->res, automaticRetryConfig, 162569f35306SGunnar Mills "AutomaticRetryConfig"); 162669f35306SGunnar Mills return; 162769f35306SGunnar Mills } 162869f35306SGunnar Mills 162969f35306SGunnar Mills crow::connections::systemBus->async_method_call( 163069f35306SGunnar Mills [aResp](const boost::system::error_code ec) { 163169f35306SGunnar Mills if (ec) 163269f35306SGunnar Mills { 163369f35306SGunnar Mills messages::internalError(aResp->res); 163469f35306SGunnar Mills return; 163569f35306SGunnar Mills } 163669f35306SGunnar Mills }, 163769f35306SGunnar Mills "xyz.openbmc_project.Settings", 163869f35306SGunnar Mills "/xyz/openbmc_project/control/host0/auto_reboot", 163969f35306SGunnar Mills "org.freedesktop.DBus.Properties", "Set", 164069f35306SGunnar Mills "xyz.openbmc_project.Control.Boot.RebootPolicy", "AutoReboot", 164169f35306SGunnar Mills std::variant<bool>(autoRebootEnabled)); 164269f35306SGunnar Mills } 164369f35306SGunnar Mills 164469f35306SGunnar Mills /** 1645c6a620f2SGeorge Liu * @brief Sets power restore policy properties. 1646c6a620f2SGeorge Liu * 1647c6a620f2SGeorge Liu * @param[in] aResp Shared pointer for generating response message. 1648c6a620f2SGeorge Liu * @param[in] policy power restore policy properties from request. 1649c6a620f2SGeorge Liu * 1650c6a620f2SGeorge Liu * @return None. 1651c6a620f2SGeorge Liu */ 16528d1b46d7Szhanghch05 inline void 16538d1b46d7Szhanghch05 setPowerRestorePolicy(const std::shared_ptr<bmcweb::AsyncResp>& aResp, 16544e69c904SGunnar Mills const std::string& policy) 1655c6a620f2SGeorge Liu { 1656c6a620f2SGeorge Liu BMCWEB_LOG_DEBUG << "Set power restore policy."; 1657c6a620f2SGeorge Liu 1658c6a620f2SGeorge Liu const boost::container::flat_map<std::string, std::string> policyMaps = { 1659c6a620f2SGeorge Liu {"AlwaysOn", "xyz.openbmc_project.Control.Power.RestorePolicy.Policy." 1660c6a620f2SGeorge Liu "AlwaysOn"}, 1661c6a620f2SGeorge Liu {"AlwaysOff", "xyz.openbmc_project.Control.Power.RestorePolicy.Policy." 1662c6a620f2SGeorge Liu "AlwaysOff"}, 1663c6a620f2SGeorge Liu {"LastState", "xyz.openbmc_project.Control.Power.RestorePolicy.Policy." 166437ec9072SGunnar Mills "Restore"}}; 1665c6a620f2SGeorge Liu 1666c6a620f2SGeorge Liu std::string powerRestorPolicy; 1667c6a620f2SGeorge Liu 16684e69c904SGunnar Mills auto policyMapsIt = policyMaps.find(policy); 1669c6a620f2SGeorge Liu if (policyMapsIt == policyMaps.end()) 1670c6a620f2SGeorge Liu { 16714e69c904SGunnar Mills messages::propertyValueNotInList(aResp->res, policy, 16724e69c904SGunnar Mills "PowerRestorePolicy"); 1673c6a620f2SGeorge Liu return; 1674c6a620f2SGeorge Liu } 1675c6a620f2SGeorge Liu 1676c6a620f2SGeorge Liu powerRestorPolicy = policyMapsIt->second; 1677c6a620f2SGeorge Liu 1678c6a620f2SGeorge Liu crow::connections::systemBus->async_method_call( 1679c6a620f2SGeorge Liu [aResp](const boost::system::error_code ec) { 1680c6a620f2SGeorge Liu if (ec) 1681c6a620f2SGeorge Liu { 1682c6a620f2SGeorge Liu messages::internalError(aResp->res); 1683c6a620f2SGeorge Liu return; 1684c6a620f2SGeorge Liu } 1685c6a620f2SGeorge Liu }, 1686c6a620f2SGeorge Liu "xyz.openbmc_project.Settings", 1687c6a620f2SGeorge Liu "/xyz/openbmc_project/control/host0/power_restore_policy", 1688c6a620f2SGeorge Liu "org.freedesktop.DBus.Properties", "Set", 1689c6a620f2SGeorge Liu "xyz.openbmc_project.Control.Power.RestorePolicy", "PowerRestorePolicy", 1690c6a620f2SGeorge Liu std::variant<std::string>(powerRestorPolicy)); 1691c6a620f2SGeorge Liu } 1692c6a620f2SGeorge Liu 1693a6349918SAppaRao Puli #ifdef BMCWEB_ENABLE_REDFISH_PROVISIONING_FEATURE 1694a6349918SAppaRao Puli /** 1695a6349918SAppaRao Puli * @brief Retrieves provisioning status 1696a6349918SAppaRao Puli * 1697a6349918SAppaRao Puli * @param[in] aResp Shared pointer for completing asynchronous calls. 1698a6349918SAppaRao Puli * 1699a6349918SAppaRao Puli * @return None. 1700a6349918SAppaRao Puli */ 17018d1b46d7Szhanghch05 inline void getProvisioningStatus(std::shared_ptr<bmcweb::AsyncResp> aResp) 1702a6349918SAppaRao Puli { 1703a6349918SAppaRao Puli BMCWEB_LOG_DEBUG << "Get OEM information."; 1704a6349918SAppaRao Puli crow::connections::systemBus->async_method_call( 1705a6349918SAppaRao Puli [aResp](const boost::system::error_code ec, 17061214b7e7SGunnar Mills const std::vector<std::pair<std::string, VariantType>>& 17071214b7e7SGunnar Mills propertiesList) { 1708b99fb1a9SAppaRao Puli nlohmann::json& oemPFR = 1709b99fb1a9SAppaRao Puli aResp->res.jsonValue["Oem"]["OpenBmc"]["FirmwareProvisioning"]; 171050626f4fSJames Feist aResp->res.jsonValue["Oem"]["OpenBmc"]["@odata.type"] = 171150626f4fSJames Feist "#OemComputerSystem.OpenBmc"; 171250626f4fSJames Feist oemPFR["@odata.type"] = "#OemComputerSystem.FirmwareProvisioning"; 171350626f4fSJames Feist 1714a6349918SAppaRao Puli if (ec) 1715a6349918SAppaRao Puli { 1716a6349918SAppaRao Puli BMCWEB_LOG_DEBUG << "DBUS response error " << ec; 1717b99fb1a9SAppaRao Puli // not an error, don't have to have the interface 1718b99fb1a9SAppaRao Puli oemPFR["ProvisioningStatus"] = "NotProvisioned"; 1719a6349918SAppaRao Puli return; 1720a6349918SAppaRao Puli } 1721a6349918SAppaRao Puli 1722a6349918SAppaRao Puli const bool* provState = nullptr; 1723a6349918SAppaRao Puli const bool* lockState = nullptr; 1724a6349918SAppaRao Puli for (const std::pair<std::string, VariantType>& property : 1725a6349918SAppaRao Puli propertiesList) 1726a6349918SAppaRao Puli { 1727a6349918SAppaRao Puli if (property.first == "UfmProvisioned") 1728a6349918SAppaRao Puli { 1729a6349918SAppaRao Puli provState = std::get_if<bool>(&property.second); 1730a6349918SAppaRao Puli } 1731a6349918SAppaRao Puli else if (property.first == "UfmLocked") 1732a6349918SAppaRao Puli { 1733a6349918SAppaRao Puli lockState = std::get_if<bool>(&property.second); 1734a6349918SAppaRao Puli } 1735a6349918SAppaRao Puli } 1736a6349918SAppaRao Puli 1737a6349918SAppaRao Puli if ((provState == nullptr) || (lockState == nullptr)) 1738a6349918SAppaRao Puli { 1739a6349918SAppaRao Puli BMCWEB_LOG_DEBUG << "Unable to get PFR attributes."; 1740a6349918SAppaRao Puli messages::internalError(aResp->res); 1741a6349918SAppaRao Puli return; 1742a6349918SAppaRao Puli } 1743a6349918SAppaRao Puli 1744a6349918SAppaRao Puli if (*provState == true) 1745a6349918SAppaRao Puli { 1746a6349918SAppaRao Puli if (*lockState == true) 1747a6349918SAppaRao Puli { 1748a6349918SAppaRao Puli oemPFR["ProvisioningStatus"] = "ProvisionedAndLocked"; 1749a6349918SAppaRao Puli } 1750a6349918SAppaRao Puli else 1751a6349918SAppaRao Puli { 1752a6349918SAppaRao Puli oemPFR["ProvisioningStatus"] = "ProvisionedButNotLocked"; 1753a6349918SAppaRao Puli } 1754a6349918SAppaRao Puli } 1755a6349918SAppaRao Puli else 1756a6349918SAppaRao Puli { 1757a6349918SAppaRao Puli oemPFR["ProvisioningStatus"] = "NotProvisioned"; 1758a6349918SAppaRao Puli } 1759a6349918SAppaRao Puli }, 1760a6349918SAppaRao Puli "xyz.openbmc_project.PFR.Manager", "/xyz/openbmc_project/pfr", 1761a6349918SAppaRao Puli "org.freedesktop.DBus.Properties", "GetAll", 1762a6349918SAppaRao Puli "xyz.openbmc_project.PFR.Attributes"); 1763a6349918SAppaRao Puli } 1764a6349918SAppaRao Puli #endif 1765a6349918SAppaRao Puli 1766491d8ee7SSantosh Puranik /** 17673a2d0424SChris Cain * @brief Translate the PowerMode to a response message. 17683a2d0424SChris Cain * 17693a2d0424SChris Cain * @param[in] aResp Shared pointer for generating response message. 17703a2d0424SChris Cain * @param[in] modeValue PowerMode value to be translated 17713a2d0424SChris Cain * 17723a2d0424SChris Cain * @return None. 17733a2d0424SChris Cain */ 17743a2d0424SChris Cain inline void translatePowerMode(const std::shared_ptr<bmcweb::AsyncResp>& aResp, 17753a2d0424SChris Cain const std::string& modeValue) 17763a2d0424SChris Cain { 17773a2d0424SChris Cain std::string modeString; 17783a2d0424SChris Cain 17793a2d0424SChris Cain if (modeValue == "xyz.openbmc_project.Control.Power.Mode." 17803a2d0424SChris Cain "PowerMode.Static") 17813a2d0424SChris Cain { 17823a2d0424SChris Cain aResp->res.jsonValue["PowerMode"] = "Static"; 17833a2d0424SChris Cain } 17843a2d0424SChris Cain else if (modeValue == "xyz.openbmc_project.Control.Power.Mode." 17853a2d0424SChris Cain "PowerMode.MaximumPerformance") 17863a2d0424SChris Cain { 17873a2d0424SChris Cain aResp->res.jsonValue["PowerMode"] = "MaximumPerformance"; 17883a2d0424SChris Cain } 17893a2d0424SChris Cain else if (modeValue == "xyz.openbmc_project.Control.Power.Mode." 17903a2d0424SChris Cain "PowerMode.PowerSaving") 17913a2d0424SChris Cain { 17923a2d0424SChris Cain aResp->res.jsonValue["PowerMode"] = "PowerSaving"; 17933a2d0424SChris Cain } 17943a2d0424SChris Cain else if (modeValue == "xyz.openbmc_project.Control.Power.Mode." 17953a2d0424SChris Cain "PowerMode.OEM") 17963a2d0424SChris Cain { 17973a2d0424SChris Cain aResp->res.jsonValue["PowerMode"] = "OEM"; 17983a2d0424SChris Cain } 17993a2d0424SChris Cain else 18003a2d0424SChris Cain { 18013a2d0424SChris Cain // Any other values would be invalid 18023a2d0424SChris Cain BMCWEB_LOG_DEBUG << "PowerMode value was not valid: " << modeValue; 18033a2d0424SChris Cain messages::internalError(aResp->res); 18043a2d0424SChris Cain } 18053a2d0424SChris Cain } 18063a2d0424SChris Cain 18073a2d0424SChris Cain /** 18083a2d0424SChris Cain * @brief Retrieves system power mode 18093a2d0424SChris Cain * 18103a2d0424SChris Cain * @param[in] aResp Shared pointer for generating response message. 18113a2d0424SChris Cain * 18123a2d0424SChris Cain * @return None. 18133a2d0424SChris Cain */ 18143a2d0424SChris Cain inline void getPowerMode(const std::shared_ptr<bmcweb::AsyncResp>& aResp) 18153a2d0424SChris Cain { 18163a2d0424SChris Cain BMCWEB_LOG_DEBUG << "Get power mode."; 18173a2d0424SChris Cain 18183a2d0424SChris Cain // Get Power Mode object path: 18193a2d0424SChris Cain crow::connections::systemBus->async_method_call( 18203a2d0424SChris Cain [aResp]( 18213a2d0424SChris Cain const boost::system::error_code ec, 18223a2d0424SChris Cain const std::vector<std::pair< 18233a2d0424SChris Cain std::string, 18243a2d0424SChris Cain std::vector<std::pair<std::string, std::vector<std::string>>>>>& 18253a2d0424SChris Cain subtree) { 18263a2d0424SChris Cain if (ec) 18273a2d0424SChris Cain { 18283a2d0424SChris Cain BMCWEB_LOG_DEBUG 18293a2d0424SChris Cain << "DBUS response error on Power.Mode GetSubTree " << ec; 18303a2d0424SChris Cain // This is an optional D-Bus object so just return if 18313a2d0424SChris Cain // error occurs 18323a2d0424SChris Cain return; 18333a2d0424SChris Cain } 18343a2d0424SChris Cain if (subtree.empty()) 18353a2d0424SChris Cain { 18363a2d0424SChris Cain // As noted above, this is an optional interface so just return 18373a2d0424SChris Cain // if there is no instance found 18383a2d0424SChris Cain return; 18393a2d0424SChris Cain } 18403a2d0424SChris Cain if (subtree.size() > 1) 18413a2d0424SChris Cain { 18423a2d0424SChris Cain // More then one PowerMode object is not supported and is an 18433a2d0424SChris Cain // error 18443a2d0424SChris Cain BMCWEB_LOG_DEBUG 18453a2d0424SChris Cain << "Found more than 1 system D-Bus Power.Mode objects: " 18463a2d0424SChris Cain << subtree.size(); 18473a2d0424SChris Cain messages::internalError(aResp->res); 18483a2d0424SChris Cain return; 18493a2d0424SChris Cain } 18503a2d0424SChris Cain if ((subtree[0].first.empty()) || (subtree[0].second.size() != 1)) 18513a2d0424SChris Cain { 18523a2d0424SChris Cain BMCWEB_LOG_DEBUG << "Power.Mode mapper error!"; 18533a2d0424SChris Cain messages::internalError(aResp->res); 18543a2d0424SChris Cain return; 18553a2d0424SChris Cain } 18563a2d0424SChris Cain const std::string& path = subtree[0].first; 18573a2d0424SChris Cain const std::string& service = subtree[0].second.begin()->first; 18583a2d0424SChris Cain if (service.empty()) 18593a2d0424SChris Cain { 18603a2d0424SChris Cain BMCWEB_LOG_DEBUG << "Power.Mode service mapper error!"; 18613a2d0424SChris Cain messages::internalError(aResp->res); 18623a2d0424SChris Cain return; 18633a2d0424SChris Cain } 18643a2d0424SChris Cain // Valid Power Mode object found, now read the current value 18653a2d0424SChris Cain crow::connections::systemBus->async_method_call( 18663a2d0424SChris Cain [aResp](const boost::system::error_code ec, 18673a2d0424SChris Cain const std::variant<std::string>& pmode) { 18683a2d0424SChris Cain if (ec) 18693a2d0424SChris Cain { 18703a2d0424SChris Cain BMCWEB_LOG_DEBUG 18713a2d0424SChris Cain << "DBUS response error on PowerMode Get: " << ec; 18723a2d0424SChris Cain messages::internalError(aResp->res); 18733a2d0424SChris Cain return; 18743a2d0424SChris Cain } 18753a2d0424SChris Cain 18763a2d0424SChris Cain const std::string* s = std::get_if<std::string>(&pmode); 18773a2d0424SChris Cain if (s == nullptr) 18783a2d0424SChris Cain { 18793a2d0424SChris Cain BMCWEB_LOG_DEBUG << "Unable to get PowerMode value"; 18803a2d0424SChris Cain messages::internalError(aResp->res); 18813a2d0424SChris Cain return; 18823a2d0424SChris Cain } 18833a2d0424SChris Cain 18843a2d0424SChris Cain aResp->res.jsonValue["PowerMode@Redfish.AllowableValues"] = 18853a2d0424SChris Cain {"Static", "MaximumPerformance", "PowerSaving"}; 18863a2d0424SChris Cain 18873a2d0424SChris Cain BMCWEB_LOG_DEBUG << "Current power mode: " << *s; 18883a2d0424SChris Cain translatePowerMode(aResp, *s); 18893a2d0424SChris Cain }, 18903a2d0424SChris Cain service, path, "org.freedesktop.DBus.Properties", "Get", 18913a2d0424SChris Cain "xyz.openbmc_project.Control.Power.Mode", "PowerMode"); 18923a2d0424SChris Cain }, 18933a2d0424SChris Cain "xyz.openbmc_project.ObjectMapper", 18943a2d0424SChris Cain "/xyz/openbmc_project/object_mapper", 18953a2d0424SChris Cain "xyz.openbmc_project.ObjectMapper", "GetSubTree", "/", int32_t(0), 18963a2d0424SChris Cain std::array<const char*, 1>{"xyz.openbmc_project.Control.Power.Mode"}); 18973a2d0424SChris Cain } 18983a2d0424SChris Cain 18993a2d0424SChris Cain /** 19003a2d0424SChris Cain * @brief Validate the specified mode is valid and return the PowerMode 19013a2d0424SChris Cain * name associated with that string 19023a2d0424SChris Cain * 19033a2d0424SChris Cain * @param[in] aResp Shared pointer for generating response message. 19043a2d0424SChris Cain * @param[in] modeString String representing the desired PowerMode 19053a2d0424SChris Cain * 19063a2d0424SChris Cain * @return PowerMode value or empty string if mode is not valid 19073a2d0424SChris Cain */ 19083a2d0424SChris Cain inline std::string 19093a2d0424SChris Cain validatePowerMode(const std::shared_ptr<bmcweb::AsyncResp>& aResp, 19103a2d0424SChris Cain const std::string& modeString) 19113a2d0424SChris Cain { 19123a2d0424SChris Cain std::string mode; 19133a2d0424SChris Cain 19143a2d0424SChris Cain if (modeString == "Static") 19153a2d0424SChris Cain { 19163a2d0424SChris Cain mode = "xyz.openbmc_project.Control.Power.Mode.PowerMode.Static"; 19173a2d0424SChris Cain } 19183a2d0424SChris Cain else if (modeString == "MaximumPerformance") 19193a2d0424SChris Cain { 19203a2d0424SChris Cain mode = "xyz.openbmc_project.Control.Power.Mode.PowerMode." 19213a2d0424SChris Cain "MaximumPerformance"; 19223a2d0424SChris Cain } 19233a2d0424SChris Cain else if (modeString == "PowerSaving") 19243a2d0424SChris Cain { 19253a2d0424SChris Cain mode = "xyz.openbmc_project.Control.Power.Mode.PowerMode.PowerSaving"; 19263a2d0424SChris Cain } 19273a2d0424SChris Cain else 19283a2d0424SChris Cain { 19293a2d0424SChris Cain messages::propertyValueNotInList(aResp->res, modeString, "PowerMode"); 19303a2d0424SChris Cain } 19313a2d0424SChris Cain return mode; 19323a2d0424SChris Cain } 19333a2d0424SChris Cain 19343a2d0424SChris Cain /** 19353a2d0424SChris Cain * @brief Sets system power mode. 19363a2d0424SChris Cain * 19373a2d0424SChris Cain * @param[in] aResp Shared pointer for generating response message. 19383a2d0424SChris Cain * @param[in] pmode System power mode from request. 19393a2d0424SChris Cain * 19403a2d0424SChris Cain * @return None. 19413a2d0424SChris Cain */ 19423a2d0424SChris Cain inline void setPowerMode(const std::shared_ptr<bmcweb::AsyncResp>& aResp, 19433a2d0424SChris Cain const std::string& pmode) 19443a2d0424SChris Cain { 19453a2d0424SChris Cain BMCWEB_LOG_DEBUG << "Set power mode."; 19463a2d0424SChris Cain 19473a2d0424SChris Cain std::string powerMode = validatePowerMode(aResp, pmode); 19483a2d0424SChris Cain if (powerMode.empty()) 19493a2d0424SChris Cain { 19503a2d0424SChris Cain return; 19513a2d0424SChris Cain } 19523a2d0424SChris Cain 19533a2d0424SChris Cain // Get Power Mode object path: 19543a2d0424SChris Cain crow::connections::systemBus->async_method_call( 19553a2d0424SChris Cain [aResp, powerMode]( 19563a2d0424SChris Cain const boost::system::error_code ec, 19573a2d0424SChris Cain const std::vector<std::pair< 19583a2d0424SChris Cain std::string, 19593a2d0424SChris Cain std::vector<std::pair<std::string, std::vector<std::string>>>>>& 19603a2d0424SChris Cain subtree) { 19613a2d0424SChris Cain if (ec) 19623a2d0424SChris Cain { 19633a2d0424SChris Cain BMCWEB_LOG_DEBUG 19643a2d0424SChris Cain << "DBUS response error on Power.Mode GetSubTree " << ec; 19653a2d0424SChris Cain // This is an optional D-Bus object, but user attempted to patch 19663a2d0424SChris Cain messages::internalError(aResp->res); 19673a2d0424SChris Cain return; 19683a2d0424SChris Cain } 19693a2d0424SChris Cain if (subtree.empty()) 19703a2d0424SChris Cain { 19713a2d0424SChris Cain // This is an optional D-Bus object, but user attempted to patch 19723a2d0424SChris Cain messages::resourceNotFound(aResp->res, "ComputerSystem", 19733a2d0424SChris Cain "PowerMode"); 19743a2d0424SChris Cain return; 19753a2d0424SChris Cain } 19763a2d0424SChris Cain if (subtree.size() > 1) 19773a2d0424SChris Cain { 19783a2d0424SChris Cain // More then one PowerMode object is not supported and is an 19793a2d0424SChris Cain // error 19803a2d0424SChris Cain BMCWEB_LOG_DEBUG 19813a2d0424SChris Cain << "Found more than 1 system D-Bus Power.Mode objects: " 19823a2d0424SChris Cain << subtree.size(); 19833a2d0424SChris Cain messages::internalError(aResp->res); 19843a2d0424SChris Cain return; 19853a2d0424SChris Cain } 19863a2d0424SChris Cain if ((subtree[0].first.empty()) || (subtree[0].second.size() != 1)) 19873a2d0424SChris Cain { 19883a2d0424SChris Cain BMCWEB_LOG_DEBUG << "Power.Mode mapper error!"; 19893a2d0424SChris Cain messages::internalError(aResp->res); 19903a2d0424SChris Cain return; 19913a2d0424SChris Cain } 19923a2d0424SChris Cain const std::string& path = subtree[0].first; 19933a2d0424SChris Cain const std::string& service = subtree[0].second.begin()->first; 19943a2d0424SChris Cain if (service.empty()) 19953a2d0424SChris Cain { 19963a2d0424SChris Cain BMCWEB_LOG_DEBUG << "Power.Mode service mapper error!"; 19973a2d0424SChris Cain messages::internalError(aResp->res); 19983a2d0424SChris Cain return; 19993a2d0424SChris Cain } 20003a2d0424SChris Cain 20013a2d0424SChris Cain BMCWEB_LOG_DEBUG << "Setting power mode(" << powerMode << ") -> " 20023a2d0424SChris Cain << path; 20033a2d0424SChris Cain 20043a2d0424SChris Cain // Set the Power Mode property 20053a2d0424SChris Cain crow::connections::systemBus->async_method_call( 20063a2d0424SChris Cain [aResp](const boost::system::error_code ec) { 20073a2d0424SChris Cain if (ec) 20083a2d0424SChris Cain { 20093a2d0424SChris Cain messages::internalError(aResp->res); 20103a2d0424SChris Cain return; 20113a2d0424SChris Cain } 20123a2d0424SChris Cain }, 20133a2d0424SChris Cain service, path, "org.freedesktop.DBus.Properties", "Set", 20143a2d0424SChris Cain "xyz.openbmc_project.Control.Power.Mode", "PowerMode", 20153a2d0424SChris Cain std::variant<std::string>(powerMode)); 20163a2d0424SChris Cain }, 20173a2d0424SChris Cain "xyz.openbmc_project.ObjectMapper", 20183a2d0424SChris Cain "/xyz/openbmc_project/object_mapper", 20193a2d0424SChris Cain "xyz.openbmc_project.ObjectMapper", "GetSubTree", "/", int32_t(0), 20203a2d0424SChris Cain std::array<const char*, 1>{"xyz.openbmc_project.Control.Power.Mode"}); 20213a2d0424SChris Cain } 20223a2d0424SChris Cain 20233a2d0424SChris Cain /** 202451709ffdSYong Li * @brief Translates watchdog timeout action DBUS property value to redfish. 202551709ffdSYong Li * 202651709ffdSYong Li * @param[in] dbusAction The watchdog timeout action in D-BUS. 202751709ffdSYong Li * 202851709ffdSYong Li * @return Returns as a string, the timeout action in Redfish terms. If 202951709ffdSYong Li * translation cannot be done, returns an empty string. 203051709ffdSYong Li */ 203123a21a1cSEd Tanous inline std::string dbusToRfWatchdogAction(const std::string& dbusAction) 203251709ffdSYong Li { 203351709ffdSYong Li if (dbusAction == "xyz.openbmc_project.State.Watchdog.Action.None") 203451709ffdSYong Li { 203551709ffdSYong Li return "None"; 203651709ffdSYong Li } 20373174e4dfSEd Tanous if (dbusAction == "xyz.openbmc_project.State.Watchdog.Action.HardReset") 203851709ffdSYong Li { 203951709ffdSYong Li return "ResetSystem"; 204051709ffdSYong Li } 20413174e4dfSEd Tanous if (dbusAction == "xyz.openbmc_project.State.Watchdog.Action.PowerOff") 204251709ffdSYong Li { 204351709ffdSYong Li return "PowerDown"; 204451709ffdSYong Li } 20453174e4dfSEd Tanous if (dbusAction == "xyz.openbmc_project.State.Watchdog.Action.PowerCycle") 204651709ffdSYong Li { 204751709ffdSYong Li return "PowerCycle"; 204851709ffdSYong Li } 204951709ffdSYong Li 205051709ffdSYong Li return ""; 205151709ffdSYong Li } 205251709ffdSYong Li 205351709ffdSYong Li /** 2054c45f0082SYong Li *@brief Translates timeout action from Redfish to DBUS property value. 2055c45f0082SYong Li * 2056c45f0082SYong Li *@param[in] rfAction The timeout action in Redfish. 2057c45f0082SYong Li * 2058c45f0082SYong Li *@return Returns as a string, the time_out action as expected by DBUS. 2059c45f0082SYong Li *If translation cannot be done, returns an empty string. 2060c45f0082SYong Li */ 2061c45f0082SYong Li 206223a21a1cSEd Tanous inline std::string rfToDbusWDTTimeOutAct(const std::string& rfAction) 2063c45f0082SYong Li { 2064c45f0082SYong Li if (rfAction == "None") 2065c45f0082SYong Li { 2066c45f0082SYong Li return "xyz.openbmc_project.State.Watchdog.Action.None"; 2067c45f0082SYong Li } 20683174e4dfSEd Tanous if (rfAction == "PowerCycle") 2069c45f0082SYong Li { 2070c45f0082SYong Li return "xyz.openbmc_project.State.Watchdog.Action.PowerCycle"; 2071c45f0082SYong Li } 20723174e4dfSEd Tanous if (rfAction == "PowerDown") 2073c45f0082SYong Li { 2074c45f0082SYong Li return "xyz.openbmc_project.State.Watchdog.Action.PowerOff"; 2075c45f0082SYong Li } 20763174e4dfSEd Tanous if (rfAction == "ResetSystem") 2077c45f0082SYong Li { 2078c45f0082SYong Li return "xyz.openbmc_project.State.Watchdog.Action.HardReset"; 2079c45f0082SYong Li } 2080c45f0082SYong Li 2081c45f0082SYong Li return ""; 2082c45f0082SYong Li } 2083c45f0082SYong Li 2084c45f0082SYong Li /** 208551709ffdSYong Li * @brief Retrieves host watchdog timer properties over DBUS 208651709ffdSYong Li * 208751709ffdSYong Li * @param[in] aResp Shared pointer for completing asynchronous calls. 208851709ffdSYong Li * 208951709ffdSYong Li * @return None. 209051709ffdSYong Li */ 20918d1b46d7Szhanghch05 inline void 20928d1b46d7Szhanghch05 getHostWatchdogTimer(const std::shared_ptr<bmcweb::AsyncResp>& aResp) 209351709ffdSYong Li { 209451709ffdSYong Li BMCWEB_LOG_DEBUG << "Get host watchodg"; 209551709ffdSYong Li crow::connections::systemBus->async_method_call( 209651709ffdSYong Li [aResp](const boost::system::error_code ec, 209751709ffdSYong Li PropertiesType& properties) { 209851709ffdSYong Li if (ec) 209951709ffdSYong Li { 210051709ffdSYong Li // watchdog service is stopped 210151709ffdSYong Li BMCWEB_LOG_DEBUG << "DBUS response error " << ec; 210251709ffdSYong Li return; 210351709ffdSYong Li } 210451709ffdSYong Li 210551709ffdSYong Li BMCWEB_LOG_DEBUG << "Got " << properties.size() << " wdt prop."; 210651709ffdSYong Li 210751709ffdSYong Li nlohmann::json& hostWatchdogTimer = 210851709ffdSYong Li aResp->res.jsonValue["HostWatchdogTimer"]; 210951709ffdSYong Li 211051709ffdSYong Li // watchdog service is running/enabled 211151709ffdSYong Li hostWatchdogTimer["Status"]["State"] = "Enabled"; 211251709ffdSYong Li 211351709ffdSYong Li for (const auto& property : properties) 211451709ffdSYong Li { 211551709ffdSYong Li BMCWEB_LOG_DEBUG << "prop=" << property.first; 211651709ffdSYong Li if (property.first == "Enabled") 211751709ffdSYong Li { 211851709ffdSYong Li const bool* state = std::get_if<bool>(&property.second); 211951709ffdSYong Li 212051709ffdSYong Li if (!state) 212151709ffdSYong Li { 212251709ffdSYong Li messages::internalError(aResp->res); 2123601af5edSChicago Duan return; 212451709ffdSYong Li } 212551709ffdSYong Li 212651709ffdSYong Li hostWatchdogTimer["FunctionEnabled"] = *state; 212751709ffdSYong Li } 212851709ffdSYong Li else if (property.first == "ExpireAction") 212951709ffdSYong Li { 213051709ffdSYong Li const std::string* s = 213151709ffdSYong Li std::get_if<std::string>(&property.second); 213251709ffdSYong Li if (!s) 213351709ffdSYong Li { 213451709ffdSYong Li messages::internalError(aResp->res); 2135601af5edSChicago Duan return; 213651709ffdSYong Li } 213751709ffdSYong Li 213851709ffdSYong Li std::string action = dbusToRfWatchdogAction(*s); 213951709ffdSYong Li if (action.empty()) 214051709ffdSYong Li { 214151709ffdSYong Li messages::internalError(aResp->res); 2142601af5edSChicago Duan return; 214351709ffdSYong Li } 214451709ffdSYong Li hostWatchdogTimer["TimeoutAction"] = action; 214551709ffdSYong Li } 214651709ffdSYong Li } 214751709ffdSYong Li }, 214851709ffdSYong Li "xyz.openbmc_project.Watchdog", "/xyz/openbmc_project/watchdog/host0", 214951709ffdSYong Li "org.freedesktop.DBus.Properties", "GetAll", 215051709ffdSYong Li "xyz.openbmc_project.State.Watchdog"); 215151709ffdSYong Li } 215251709ffdSYong Li 215351709ffdSYong Li /** 2154c45f0082SYong Li * @brief Sets Host WatchDog Timer properties. 2155c45f0082SYong Li * 2156c45f0082SYong Li * @param[in] aResp Shared pointer for generating response message. 2157c45f0082SYong Li * @param[in] wdtEnable The WDTimer Enable value (true/false) from incoming 2158c45f0082SYong Li * RF request. 2159c45f0082SYong Li * @param[in] wdtTimeOutAction The WDT Timeout action, from incoming RF request. 2160c45f0082SYong Li * 2161c45f0082SYong Li * @return None. 2162c45f0082SYong Li */ 21638d1b46d7Szhanghch05 inline void setWDTProperties(const std::shared_ptr<bmcweb::AsyncResp>& aResp, 2164c45f0082SYong Li const std::optional<bool> wdtEnable, 2165c45f0082SYong Li const std::optional<std::string>& wdtTimeOutAction) 2166c45f0082SYong Li { 2167c45f0082SYong Li BMCWEB_LOG_DEBUG << "Set host watchdog"; 2168c45f0082SYong Li 2169c45f0082SYong Li if (wdtTimeOutAction) 2170c45f0082SYong Li { 2171c45f0082SYong Li std::string wdtTimeOutActStr = rfToDbusWDTTimeOutAct(*wdtTimeOutAction); 2172c45f0082SYong Li // check if TimeOut Action is Valid 2173c45f0082SYong Li if (wdtTimeOutActStr.empty()) 2174c45f0082SYong Li { 2175c45f0082SYong Li BMCWEB_LOG_DEBUG << "Unsupported value for TimeoutAction: " 2176c45f0082SYong Li << *wdtTimeOutAction; 2177c45f0082SYong Li messages::propertyValueNotInList(aResp->res, *wdtTimeOutAction, 2178c45f0082SYong Li "TimeoutAction"); 2179c45f0082SYong Li return; 2180c45f0082SYong Li } 2181c45f0082SYong Li 2182c45f0082SYong Li crow::connections::systemBus->async_method_call( 2183c45f0082SYong Li [aResp](const boost::system::error_code ec) { 2184c45f0082SYong Li if (ec) 2185c45f0082SYong Li { 2186c45f0082SYong Li BMCWEB_LOG_DEBUG << "DBUS response error " << ec; 2187c45f0082SYong Li messages::internalError(aResp->res); 2188c45f0082SYong Li return; 2189c45f0082SYong Li } 2190c45f0082SYong Li }, 2191c45f0082SYong Li "xyz.openbmc_project.Watchdog", 2192c45f0082SYong Li "/xyz/openbmc_project/watchdog/host0", 2193c45f0082SYong Li "org.freedesktop.DBus.Properties", "Set", 2194c45f0082SYong Li "xyz.openbmc_project.State.Watchdog", "ExpireAction", 2195c45f0082SYong Li std::variant<std::string>(wdtTimeOutActStr)); 2196c45f0082SYong Li } 2197c45f0082SYong Li 2198c45f0082SYong Li if (wdtEnable) 2199c45f0082SYong Li { 2200c45f0082SYong Li crow::connections::systemBus->async_method_call( 2201c45f0082SYong Li [aResp](const boost::system::error_code ec) { 2202c45f0082SYong Li if (ec) 2203c45f0082SYong Li { 2204c45f0082SYong Li BMCWEB_LOG_DEBUG << "DBUS response error " << ec; 2205c45f0082SYong Li messages::internalError(aResp->res); 2206c45f0082SYong Li return; 2207c45f0082SYong Li } 2208c45f0082SYong Li }, 2209c45f0082SYong Li "xyz.openbmc_project.Watchdog", 2210c45f0082SYong Li "/xyz/openbmc_project/watchdog/host0", 2211c45f0082SYong Li "org.freedesktop.DBus.Properties", "Set", 2212c45f0082SYong Li "xyz.openbmc_project.State.Watchdog", "Enabled", 2213c45f0082SYong Li std::variant<bool>(*wdtEnable)); 2214c45f0082SYong Li } 2215c45f0082SYong Li } 2216c45f0082SYong Li 2217c45f0082SYong Li /** 2218c5b2abe0SLewanczyk, Dawid * SystemsCollection derived class for delivering ComputerSystems Collection 2219c5b2abe0SLewanczyk, Dawid * Schema 2220c5b2abe0SLewanczyk, Dawid */ 22217e860f15SJohn Edward Broadbent inline void requestRoutesSystemsCollection(App& app) 22221abe55efSEd Tanous { 22237e860f15SJohn Edward Broadbent BMCWEB_ROUTE(app, "/redfish/v1/Systems/") 2224*ed398213SEd Tanous .privileges(redfish::privileges::getComputerSystemCollection) 22257e860f15SJohn Edward Broadbent .methods(boost::beast::http::verb::get)( 22267e860f15SJohn Edward Broadbent [](const crow::Request& req, 22277e860f15SJohn Edward Broadbent const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) { 22288d1b46d7Szhanghch05 asyncResp->res.jsonValue["@odata.type"] = 22290f74e643SEd Tanous "#ComputerSystemCollection.ComputerSystemCollection"; 22308d1b46d7Szhanghch05 asyncResp->res.jsonValue["@odata.id"] = "/redfish/v1/Systems"; 22318d1b46d7Szhanghch05 asyncResp->res.jsonValue["Name"] = "Computer System Collection"; 2232462023adSSunitha Harish 2233462023adSSunitha Harish crow::connections::systemBus->async_method_call( 22347e860f15SJohn Edward Broadbent [asyncResp, 22357e860f15SJohn Edward Broadbent &req](const boost::system::error_code ec, 2236cb13a392SEd Tanous const std::variant<std::string>& /*hostName*/) { 22372c70f800SEd Tanous nlohmann::json& ifaceArray = 2238462023adSSunitha Harish asyncResp->res.jsonValue["Members"]; 22392c70f800SEd Tanous ifaceArray = nlohmann::json::array(); 22407e860f15SJohn Edward Broadbent auto& count = 22417e860f15SJohn Edward Broadbent asyncResp->res.jsonValue["Members@odata.count"]; 22422c70f800SEd Tanous ifaceArray.push_back( 2243cb13a392SEd Tanous {{"@odata.id", "/redfish/v1/Systems/system"}}); 224494bda602STim Lee count = ifaceArray.size(); 2245cb13a392SEd Tanous if (!ec) 2246462023adSSunitha Harish { 2247462023adSSunitha Harish BMCWEB_LOG_DEBUG << "Hypervisor is available"; 22482c70f800SEd Tanous ifaceArray.push_back( 22497e860f15SJohn Edward Broadbent {{"@odata.id", 22507e860f15SJohn Edward Broadbent "/redfish/v1/Systems/hypervisor"}}); 22512c70f800SEd Tanous count = ifaceArray.size(); 2252cb13a392SEd Tanous } 2253462023adSSunitha Harish }, 22548e651fbfSSunitha Harish "xyz.openbmc_project.Settings", 22558e651fbfSSunitha Harish "/xyz/openbmc_project/network/hypervisor", 2256462023adSSunitha Harish "org.freedesktop.DBus.Properties", "Get", 22577e860f15SJohn Edward Broadbent "xyz.openbmc_project.Network.SystemConfiguration", 22587e860f15SJohn Edward Broadbent "HostName"); 22597e860f15SJohn Edward Broadbent }); 2260c5b2abe0SLewanczyk, Dawid } 22617e860f15SJohn Edward Broadbent 22627e860f15SJohn Edward Broadbent /** 22637e860f15SJohn Edward Broadbent * Function transceives data with dbus directly. 22647e860f15SJohn Edward Broadbent */ 22657e860f15SJohn Edward Broadbent void doNMI(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) 22667e860f15SJohn Edward Broadbent { 22677e860f15SJohn Edward Broadbent constexpr char const* serviceName = "xyz.openbmc_project.Control.Host.NMI"; 22687e860f15SJohn Edward Broadbent constexpr char const* objectPath = "/xyz/openbmc_project/control/host0/nmi"; 22697e860f15SJohn Edward Broadbent constexpr char const* interfaceName = 22707e860f15SJohn Edward Broadbent "xyz.openbmc_project.Control.Host.NMI"; 22717e860f15SJohn Edward Broadbent constexpr char const* method = "NMI"; 22727e860f15SJohn Edward Broadbent 22737e860f15SJohn Edward Broadbent crow::connections::systemBus->async_method_call( 22747e860f15SJohn Edward Broadbent [asyncResp](const boost::system::error_code ec) { 22757e860f15SJohn Edward Broadbent if (ec) 22767e860f15SJohn Edward Broadbent { 22777e860f15SJohn Edward Broadbent BMCWEB_LOG_ERROR << " Bad D-Bus request error: " << ec; 22787e860f15SJohn Edward Broadbent messages::internalError(asyncResp->res); 22797e860f15SJohn Edward Broadbent return; 22807e860f15SJohn Edward Broadbent } 22817e860f15SJohn Edward Broadbent messages::success(asyncResp->res); 22827e860f15SJohn Edward Broadbent }, 22837e860f15SJohn Edward Broadbent serviceName, objectPath, interfaceName, method); 22847e860f15SJohn Edward Broadbent } 2285c5b2abe0SLewanczyk, Dawid 2286c5b2abe0SLewanczyk, Dawid /** 2287cc340dd9SEd Tanous * SystemActionsReset class supports handle POST method for Reset action. 2288cc340dd9SEd Tanous * The class retrieves and sends data directly to D-Bus. 2289cc340dd9SEd Tanous */ 22907e860f15SJohn Edward Broadbent inline void requestRoutesSystemActionsReset(App& app) 2291cc340dd9SEd Tanous { 2292cc340dd9SEd Tanous /** 2293cc340dd9SEd Tanous * Function handles POST method request. 2294cc340dd9SEd Tanous * Analyzes POST body message before sends Reset request data to D-Bus. 2295cc340dd9SEd Tanous */ 22967e860f15SJohn Edward Broadbent BMCWEB_ROUTE(app, 22977e860f15SJohn Edward Broadbent "/redfish/v1/Systems/system/Actions/ComputerSystem.Reset/") 2298*ed398213SEd Tanous .privileges(redfish::privileges::postComputerSystem) 22997e860f15SJohn Edward Broadbent .methods( 23007e860f15SJohn Edward Broadbent boost::beast::http::verb:: 23017e860f15SJohn Edward Broadbent post)([](const crow::Request& req, 23027e860f15SJohn Edward Broadbent const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) { 23039712f8acSEd Tanous std::string resetType; 23047e860f15SJohn Edward Broadbent if (!json_util::readJson(req, asyncResp->res, "ResetType", 23057e860f15SJohn Edward Broadbent resetType)) 2306cc340dd9SEd Tanous { 2307cc340dd9SEd Tanous return; 2308cc340dd9SEd Tanous } 2309cc340dd9SEd Tanous 2310d22c8396SJason M. Bills // Get the command and host vs. chassis 2311cc340dd9SEd Tanous std::string command; 2312d22c8396SJason M. Bills bool hostCommand; 2313d4d25793SEd Tanous if ((resetType == "On") || (resetType == "ForceOn")) 2314cc340dd9SEd Tanous { 2315cc340dd9SEd Tanous command = "xyz.openbmc_project.State.Host.Transition.On"; 2316d22c8396SJason M. Bills hostCommand = true; 2317d22c8396SJason M. Bills } 2318d22c8396SJason M. Bills else if (resetType == "ForceOff") 2319d22c8396SJason M. Bills { 2320d22c8396SJason M. Bills command = "xyz.openbmc_project.State.Chassis.Transition.Off"; 2321d22c8396SJason M. Bills hostCommand = false; 2322d22c8396SJason M. Bills } 2323d22c8396SJason M. Bills else if (resetType == "ForceRestart") 2324d22c8396SJason M. Bills { 232586a0851aSJason M. Bills command = 232686a0851aSJason M. Bills "xyz.openbmc_project.State.Host.Transition.ForceWarmReboot"; 232786a0851aSJason M. Bills hostCommand = true; 2328cc340dd9SEd Tanous } 23299712f8acSEd Tanous else if (resetType == "GracefulShutdown") 2330cc340dd9SEd Tanous { 2331cc340dd9SEd Tanous command = "xyz.openbmc_project.State.Host.Transition.Off"; 2332d22c8396SJason M. Bills hostCommand = true; 2333cc340dd9SEd Tanous } 23349712f8acSEd Tanous else if (resetType == "GracefulRestart") 2335cc340dd9SEd Tanous { 23367e860f15SJohn Edward Broadbent command = "xyz.openbmc_project.State.Host.Transition." 23377e860f15SJohn Edward Broadbent "GracefulWarmReboot"; 2338d22c8396SJason M. Bills hostCommand = true; 2339d22c8396SJason M. Bills } 2340d22c8396SJason M. Bills else if (resetType == "PowerCycle") 2341d22c8396SJason M. Bills { 234286a0851aSJason M. Bills command = "xyz.openbmc_project.State.Host.Transition.Reboot"; 234386a0851aSJason M. Bills hostCommand = true; 2344cc340dd9SEd Tanous } 2345bfd5b826SLakshminarayana R. Kammath else if (resetType == "Nmi") 2346bfd5b826SLakshminarayana R. Kammath { 2347bfd5b826SLakshminarayana R. Kammath doNMI(asyncResp); 2348bfd5b826SLakshminarayana R. Kammath return; 2349bfd5b826SLakshminarayana R. Kammath } 2350cc340dd9SEd Tanous else 2351cc340dd9SEd Tanous { 23528d1b46d7Szhanghch05 messages::actionParameterUnknown(asyncResp->res, "Reset", 23538d1b46d7Szhanghch05 resetType); 2354cc340dd9SEd Tanous return; 2355cc340dd9SEd Tanous } 2356cc340dd9SEd Tanous 2357d22c8396SJason M. Bills if (hostCommand) 2358d22c8396SJason M. Bills { 2359cc340dd9SEd Tanous crow::connections::systemBus->async_method_call( 2360d22c8396SJason M. Bills [asyncResp, resetType](const boost::system::error_code ec) { 2361cc340dd9SEd Tanous if (ec) 2362cc340dd9SEd Tanous { 2363cc340dd9SEd Tanous BMCWEB_LOG_ERROR << "D-Bus responses error: " << ec; 23647e860f15SJohn Edward Broadbent if (ec.value() == 23657e860f15SJohn Edward Broadbent boost::asio::error::invalid_argument) 2366d22c8396SJason M. Bills { 2367d22c8396SJason M. Bills messages::actionParameterNotSupported( 2368d22c8396SJason M. Bills asyncResp->res, resetType, "Reset"); 2369d22c8396SJason M. Bills } 2370d22c8396SJason M. Bills else 2371d22c8396SJason M. Bills { 2372f12894f8SJason M. Bills messages::internalError(asyncResp->res); 2373d22c8396SJason M. Bills } 2374cc340dd9SEd Tanous return; 2375cc340dd9SEd Tanous } 2376f12894f8SJason M. Bills messages::success(asyncResp->res); 2377cc340dd9SEd Tanous }, 2378cc340dd9SEd Tanous "xyz.openbmc_project.State.Host", 2379cc340dd9SEd Tanous "/xyz/openbmc_project/state/host0", 2380cc340dd9SEd Tanous "org.freedesktop.DBus.Properties", "Set", 23819712f8acSEd Tanous "xyz.openbmc_project.State.Host", "RequestedHostTransition", 2382abf2add6SEd Tanous std::variant<std::string>{command}); 2383cc340dd9SEd Tanous } 2384d22c8396SJason M. Bills else 2385d22c8396SJason M. Bills { 2386d22c8396SJason M. Bills crow::connections::systemBus->async_method_call( 2387d22c8396SJason M. Bills [asyncResp, resetType](const boost::system::error_code ec) { 2388d22c8396SJason M. Bills if (ec) 2389d22c8396SJason M. Bills { 2390d22c8396SJason M. Bills BMCWEB_LOG_ERROR << "D-Bus responses error: " << ec; 23917e860f15SJohn Edward Broadbent if (ec.value() == 23927e860f15SJohn Edward Broadbent boost::asio::error::invalid_argument) 2393d22c8396SJason M. Bills { 2394d22c8396SJason M. Bills messages::actionParameterNotSupported( 2395d22c8396SJason M. Bills asyncResp->res, resetType, "Reset"); 2396d22c8396SJason M. Bills } 2397d22c8396SJason M. Bills else 2398d22c8396SJason M. Bills { 2399d22c8396SJason M. Bills messages::internalError(asyncResp->res); 2400d22c8396SJason M. Bills } 2401d22c8396SJason M. Bills return; 2402d22c8396SJason M. Bills } 2403d22c8396SJason M. Bills messages::success(asyncResp->res); 2404d22c8396SJason M. Bills }, 2405d22c8396SJason M. Bills "xyz.openbmc_project.State.Chassis", 2406d22c8396SJason M. Bills "/xyz/openbmc_project/state/chassis0", 2407d22c8396SJason M. Bills "org.freedesktop.DBus.Properties", "Set", 24087e860f15SJohn Edward Broadbent "xyz.openbmc_project.State.Chassis", 24097e860f15SJohn Edward Broadbent "RequestedPowerTransition", 2410d22c8396SJason M. Bills std::variant<std::string>{command}); 2411d22c8396SJason M. Bills } 24127e860f15SJohn Edward Broadbent }); 2413d22c8396SJason M. Bills } 2414cc340dd9SEd Tanous 2415cc340dd9SEd Tanous /** 24166617338dSEd Tanous * Systems derived class for delivering Computer Systems Schema. 2417c5b2abe0SLewanczyk, Dawid */ 24187e860f15SJohn Edward Broadbent inline void requestRoutesSystems(App& app) 24191abe55efSEd Tanous { 2420c5b2abe0SLewanczyk, Dawid 2421c5b2abe0SLewanczyk, Dawid /** 2422c5b2abe0SLewanczyk, Dawid * Functions triggers appropriate requests on DBus 2423c5b2abe0SLewanczyk, Dawid */ 24247e860f15SJohn Edward Broadbent BMCWEB_ROUTE(app, "/redfish/v1/Systems/system/") 2425*ed398213SEd Tanous .privileges(redfish::privileges::getComputerSystem) 24267e860f15SJohn Edward Broadbent .methods( 24277e860f15SJohn Edward Broadbent boost::beast::http::verb:: 24287e860f15SJohn Edward Broadbent get)([](const crow::Request&, 24297e860f15SJohn Edward Broadbent const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) { 24308d1b46d7Szhanghch05 asyncResp->res.jsonValue["@odata.type"] = 24313a2d0424SChris Cain "#ComputerSystem.v1_15_0.ComputerSystem"; 24328d1b46d7Szhanghch05 asyncResp->res.jsonValue["Name"] = "system"; 24338d1b46d7Szhanghch05 asyncResp->res.jsonValue["Id"] = "system"; 24348d1b46d7Szhanghch05 asyncResp->res.jsonValue["SystemType"] = "Physical"; 24358d1b46d7Szhanghch05 asyncResp->res.jsonValue["Description"] = "Computer System"; 24368d1b46d7Szhanghch05 asyncResp->res.jsonValue["ProcessorSummary"]["Count"] = 0; 24378d1b46d7Szhanghch05 asyncResp->res.jsonValue["ProcessorSummary"]["Status"]["State"] = 24388d1b46d7Szhanghch05 "Disabled"; 24398d1b46d7Szhanghch05 asyncResp->res.jsonValue["MemorySummary"]["TotalSystemMemoryGiB"] = 24408d1b46d7Szhanghch05 uint64_t(0); 24418d1b46d7Szhanghch05 asyncResp->res.jsonValue["MemorySummary"]["Status"]["State"] = 24428d1b46d7Szhanghch05 "Disabled"; 24437e860f15SJohn Edward Broadbent asyncResp->res.jsonValue["@odata.id"] = 24447e860f15SJohn Edward Broadbent "/redfish/v1/Systems/system"; 244504a258f4SEd Tanous 24468d1b46d7Szhanghch05 asyncResp->res.jsonValue["Processors"] = { 2447029573d4SEd Tanous {"@odata.id", "/redfish/v1/Systems/system/Processors"}}; 24488d1b46d7Szhanghch05 asyncResp->res.jsonValue["Memory"] = { 2449029573d4SEd Tanous {"@odata.id", "/redfish/v1/Systems/system/Memory"}}; 24508d1b46d7Szhanghch05 asyncResp->res.jsonValue["Storage"] = { 2451a25aeccfSNikhil Potade {"@odata.id", "/redfish/v1/Systems/system/Storage"}}; 2452029573d4SEd Tanous 24538d1b46d7Szhanghch05 asyncResp->res.jsonValue["Actions"]["#ComputerSystem.Reset"] = { 2454cc340dd9SEd Tanous {"target", 2455029573d4SEd Tanous "/redfish/v1/Systems/system/Actions/ComputerSystem.Reset"}, 24561cb1a9e6SAppaRao Puli {"@Redfish.ActionInfo", 24571cb1a9e6SAppaRao Puli "/redfish/v1/Systems/system/ResetActionInfo"}}; 2458c5b2abe0SLewanczyk, Dawid 24598d1b46d7Szhanghch05 asyncResp->res.jsonValue["LogServices"] = { 2460029573d4SEd Tanous {"@odata.id", "/redfish/v1/Systems/system/LogServices"}}; 2461c4bf6374SJason M. Bills 24628d1b46d7Szhanghch05 asyncResp->res.jsonValue["Bios"] = { 2463d82a3acdSCarol Wang {"@odata.id", "/redfish/v1/Systems/system/Bios"}}; 2464d82a3acdSCarol Wang 24658d1b46d7Szhanghch05 asyncResp->res.jsonValue["Links"]["ManagedBy"] = { 2466c5d03ff4SJennifer Lee {{"@odata.id", "/redfish/v1/Managers/bmc"}}}; 2467c5d03ff4SJennifer Lee 24688d1b46d7Szhanghch05 asyncResp->res.jsonValue["Status"] = { 2469c5d03ff4SJennifer Lee {"Health", "OK"}, 2470c5d03ff4SJennifer Lee {"State", "Enabled"}, 2471c5d03ff4SJennifer Lee }; 24720e8ac5e7SGunnar Mills 24730e8ac5e7SGunnar Mills // Fill in SerialConsole info 24740e8ac5e7SGunnar Mills asyncResp->res.jsonValue["SerialConsole"]["MaxConcurrentSessions"] = 24750e8ac5e7SGunnar Mills 15; 24760e8ac5e7SGunnar Mills asyncResp->res.jsonValue["SerialConsole"]["IPMI"] = { 24770e8ac5e7SGunnar Mills {"ServiceEnabled", true}, 24780e8ac5e7SGunnar Mills }; 24790e8ac5e7SGunnar Mills // TODO (Gunnar): Should look for obmc-console-ssh@2200.service 24800e8ac5e7SGunnar Mills asyncResp->res.jsonValue["SerialConsole"]["SSH"] = { 24810e8ac5e7SGunnar Mills {"ServiceEnabled", true}, 24820e8ac5e7SGunnar Mills {"Port", 2200}, 24830e8ac5e7SGunnar Mills // https://github.com/openbmc/docs/blob/master/console.md 24840e8ac5e7SGunnar Mills {"HotKeySequenceDisplay", "Press ~. to exit console"}, 24850e8ac5e7SGunnar Mills }; 24860e8ac5e7SGunnar Mills 24870e8ac5e7SGunnar Mills #ifdef BMCWEB_ENABLE_KVM 24880e8ac5e7SGunnar Mills // Fill in GraphicalConsole info 24890e8ac5e7SGunnar Mills asyncResp->res.jsonValue["GraphicalConsole"] = { 24900e8ac5e7SGunnar Mills {"ServiceEnabled", true}, 24910e8ac5e7SGunnar Mills {"MaxConcurrentSessions", 4}, 24920e8ac5e7SGunnar Mills {"ConnectTypesSupported", {"KVMIP"}}, 24930e8ac5e7SGunnar Mills }; 24940e8ac5e7SGunnar Mills #endif // BMCWEB_ENABLE_KVM 2495e284a7c1SJames Feist constexpr const std::array<const char*, 4> inventoryForSystems = { 2496b49ac873SJames Feist "xyz.openbmc_project.Inventory.Item.Dimm", 24972ad9c2f6SJames Feist "xyz.openbmc_project.Inventory.Item.Cpu", 2498e284a7c1SJames Feist "xyz.openbmc_project.Inventory.Item.Drive", 2499e284a7c1SJames Feist "xyz.openbmc_project.Inventory.Item.StorageController"}; 2500b49ac873SJames Feist 2501b49ac873SJames Feist auto health = std::make_shared<HealthPopulate>(asyncResp); 2502b49ac873SJames Feist crow::connections::systemBus->async_method_call( 2503b49ac873SJames Feist [health](const boost::system::error_code ec, 2504b49ac873SJames Feist std::vector<std::string>& resp) { 2505b49ac873SJames Feist if (ec) 2506b49ac873SJames Feist { 2507b49ac873SJames Feist // no inventory 2508b49ac873SJames Feist return; 2509b49ac873SJames Feist } 2510b49ac873SJames Feist 2511b49ac873SJames Feist health->inventory = std::move(resp); 2512b49ac873SJames Feist }, 2513b49ac873SJames Feist "xyz.openbmc_project.ObjectMapper", 2514b49ac873SJames Feist "/xyz/openbmc_project/object_mapper", 2515b49ac873SJames Feist "xyz.openbmc_project.ObjectMapper", "GetSubTreePaths", "/", 2516b49ac873SJames Feist int32_t(0), inventoryForSystems); 2517b49ac873SJames Feist 2518b49ac873SJames Feist health->populate(); 2519b49ac873SJames Feist 25208d1b46d7Szhanghch05 getMainChassisId( 25218d1b46d7Szhanghch05 asyncResp, [](const std::string& chassisId, 25228d1b46d7Szhanghch05 const std::shared_ptr<bmcweb::AsyncResp>& aRsp) { 2523c5d03ff4SJennifer Lee aRsp->res.jsonValue["Links"]["Chassis"] = { 2524c5d03ff4SJennifer Lee {{"@odata.id", "/redfish/v1/Chassis/" + chassisId}}}; 2525c5d03ff4SJennifer Lee }); 2526a3002228SAppaRao Puli 25279f8bfa7cSGunnar Mills getLocationIndicatorActive(asyncResp); 25289f8bfa7cSGunnar Mills // TODO (Gunnar): Remove IndicatorLED after enough time has passed 2529a3002228SAppaRao Puli getIndicatorLedState(asyncResp); 25305bc2dc8eSJames Feist getComputerSystem(asyncResp, health); 25316c34de48SEd Tanous getHostState(asyncResp); 2532491d8ee7SSantosh Puranik getBootProperties(asyncResp); 2533978b8803SAndrew Geissler getBootProgress(asyncResp); 2534adbe192aSJason M. Bills getPCIeDeviceList(asyncResp, "PCIeDevices"); 253551709ffdSYong Li getHostWatchdogTimer(asyncResp); 2536c6a620f2SGeorge Liu getPowerRestorePolicy(asyncResp); 25376bd5a8d2SGunnar Mills getAutomaticRetry(asyncResp); 2538c0557e1aSGunnar Mills getLastResetTime(asyncResp); 2539a6349918SAppaRao Puli #ifdef BMCWEB_ENABLE_REDFISH_PROVISIONING_FEATURE 2540a6349918SAppaRao Puli getProvisioningStatus(asyncResp); 2541a6349918SAppaRao Puli #endif 25421981771bSAli Ahmed getTrustedModuleRequiredToBoot(asyncResp); 25433a2d0424SChris Cain getPowerMode(asyncResp); 25447e860f15SJohn Edward Broadbent }); 25457e860f15SJohn Edward Broadbent BMCWEB_ROUTE(app, "/redfish/v1/Systems/system/") 2546*ed398213SEd Tanous .privileges(redfish::privileges::patchComputerSystem) 25477e860f15SJohn Edward Broadbent .methods(boost::beast::http::verb::patch)( 25487e860f15SJohn Edward Broadbent [](const crow::Request& req, 25497e860f15SJohn Edward Broadbent const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) { 25509f8bfa7cSGunnar Mills std::optional<bool> locationIndicatorActive; 2551cde19e5fSSantosh Puranik std::optional<std::string> indicatorLed; 2552491d8ee7SSantosh Puranik std::optional<nlohmann::json> bootProps; 2553c45f0082SYong Li std::optional<nlohmann::json> wdtTimerProps; 255498e386ecSGunnar Mills std::optional<std::string> assetTag; 2555c6a620f2SGeorge Liu std::optional<std::string> powerRestorePolicy; 25563a2d0424SChris Cain std::optional<std::string> powerMode; 255741352c24SSantosh Puranik 25589f8bfa7cSGunnar Mills if (!json_util::readJson( 25598d1b46d7Szhanghch05 req, asyncResp->res, "IndicatorLED", indicatorLed, 25607e860f15SJohn Edward Broadbent "LocationIndicatorActive", locationIndicatorActive, 25617e860f15SJohn Edward Broadbent "Boot", bootProps, "WatchdogTimer", wdtTimerProps, 25627e860f15SJohn Edward Broadbent "PowerRestorePolicy", powerRestorePolicy, "AssetTag", 25633a2d0424SChris Cain assetTag, "PowerMode", powerMode)) 25646617338dSEd Tanous { 25656617338dSEd Tanous return; 25666617338dSEd Tanous } 2567491d8ee7SSantosh Puranik 25688d1b46d7Szhanghch05 asyncResp->res.result(boost::beast::http::status::no_content); 2569c45f0082SYong Li 257098e386ecSGunnar Mills if (assetTag) 257198e386ecSGunnar Mills { 257298e386ecSGunnar Mills setAssetTag(asyncResp, *assetTag); 257398e386ecSGunnar Mills } 257498e386ecSGunnar Mills 2575c45f0082SYong Li if (wdtTimerProps) 2576c45f0082SYong Li { 2577c45f0082SYong Li std::optional<bool> wdtEnable; 2578c45f0082SYong Li std::optional<std::string> wdtTimeOutAction; 2579c45f0082SYong Li 2580c45f0082SYong Li if (!json_util::readJson(*wdtTimerProps, asyncResp->res, 2581c45f0082SYong Li "FunctionEnabled", wdtEnable, 2582c45f0082SYong Li "TimeoutAction", wdtTimeOutAction)) 2583c45f0082SYong Li { 2584c45f0082SYong Li return; 2585c45f0082SYong Li } 2586f23b7296SEd Tanous setWDTProperties(asyncResp, wdtEnable, wdtTimeOutAction); 2587c45f0082SYong Li } 2588c45f0082SYong Li 2589491d8ee7SSantosh Puranik if (bootProps) 2590491d8ee7SSantosh Puranik { 2591491d8ee7SSantosh Puranik std::optional<std::string> bootSource; 2592491d8ee7SSantosh Puranik std::optional<std::string> bootEnable; 259369f35306SGunnar Mills std::optional<std::string> automaticRetryConfig; 2594491d8ee7SSantosh Puranik 259569f35306SGunnar Mills if (!json_util::readJson( 25967e860f15SJohn Edward Broadbent *bootProps, asyncResp->res, 25977e860f15SJohn Edward Broadbent "BootSourceOverrideTarget", bootSource, 25987e860f15SJohn Edward Broadbent "BootSourceOverrideEnabled", bootEnable, 259969f35306SGunnar Mills "AutomaticRetryConfig", automaticRetryConfig)) 2600491d8ee7SSantosh Puranik { 2601491d8ee7SSantosh Puranik return; 2602491d8ee7SSantosh Puranik } 260369f35306SGunnar Mills if (bootSource || bootEnable) 260469f35306SGunnar Mills { 26057e860f15SJohn Edward Broadbent setBootSourceProperties(asyncResp, 26067e860f15SJohn Edward Broadbent std::move(bootSource), 2607491d8ee7SSantosh Puranik std::move(bootEnable)); 2608491d8ee7SSantosh Puranik } 260969f35306SGunnar Mills if (automaticRetryConfig) 261069f35306SGunnar Mills { 2611f23b7296SEd Tanous setAutomaticRetry(asyncResp, *automaticRetryConfig); 261269f35306SGunnar Mills } 261369f35306SGunnar Mills } 2614265c1602SJohnathan Mantey 26159f8bfa7cSGunnar Mills if (locationIndicatorActive) 26169f8bfa7cSGunnar Mills { 26177e860f15SJohn Edward Broadbent setLocationIndicatorActive(asyncResp, 26187e860f15SJohn Edward Broadbent *locationIndicatorActive); 26199f8bfa7cSGunnar Mills } 26209f8bfa7cSGunnar Mills 26217e860f15SJohn Edward Broadbent // TODO (Gunnar): Remove IndicatorLED after enough time has 26227e860f15SJohn Edward Broadbent // passed 26239712f8acSEd Tanous if (indicatorLed) 26246617338dSEd Tanous { 2625f23b7296SEd Tanous setIndicatorLedState(asyncResp, *indicatorLed); 26267e860f15SJohn Edward Broadbent asyncResp->res.addHeader( 26277e860f15SJohn Edward Broadbent boost::beast::http::field::warning, 2628d6aa0093SGunnar Mills "299 - \"IndicatorLED is deprecated. Use " 2629d6aa0093SGunnar Mills "LocationIndicatorActive instead.\""); 26306617338dSEd Tanous } 2631c6a620f2SGeorge Liu 2632c6a620f2SGeorge Liu if (powerRestorePolicy) 2633c6a620f2SGeorge Liu { 26344e69c904SGunnar Mills setPowerRestorePolicy(asyncResp, *powerRestorePolicy); 2635c6a620f2SGeorge Liu } 26363a2d0424SChris Cain 26373a2d0424SChris Cain if (powerMode) 26383a2d0424SChris Cain { 26393a2d0424SChris Cain setPowerMode(asyncResp, *powerMode); 26403a2d0424SChris Cain } 26417e860f15SJohn Edward Broadbent }); 2642c5b2abe0SLewanczyk, Dawid } 26431cb1a9e6SAppaRao Puli 26441cb1a9e6SAppaRao Puli /** 26451cb1a9e6SAppaRao Puli * SystemResetActionInfo derived class for delivering Computer Systems 26461cb1a9e6SAppaRao Puli * ResetType AllowableValues using ResetInfo schema. 26471cb1a9e6SAppaRao Puli */ 26487e860f15SJohn Edward Broadbent inline void requestRoutesSystemResetActionInfo(App& app) 26491cb1a9e6SAppaRao Puli { 26501cb1a9e6SAppaRao Puli 26511cb1a9e6SAppaRao Puli /** 26521cb1a9e6SAppaRao Puli * Functions triggers appropriate requests on DBus 26531cb1a9e6SAppaRao Puli */ 26547e860f15SJohn Edward Broadbent BMCWEB_ROUTE(app, "/redfish/v1/Systems/system/ResetActionInfo/") 2655*ed398213SEd Tanous .privileges(redfish::privileges::getActionInfo) 26567e860f15SJohn Edward Broadbent .methods(boost::beast::http::verb::get)( 26577e860f15SJohn Edward Broadbent [](const crow::Request&, 26587e860f15SJohn Edward Broadbent const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) { 26598d1b46d7Szhanghch05 asyncResp->res.jsonValue = { 26601cb1a9e6SAppaRao Puli {"@odata.type", "#ActionInfo.v1_1_2.ActionInfo"}, 26611cb1a9e6SAppaRao Puli {"@odata.id", "/redfish/v1/Systems/system/ResetActionInfo"}, 26621cb1a9e6SAppaRao Puli {"Name", "Reset Action Info"}, 26631cb1a9e6SAppaRao Puli {"Id", "ResetActionInfo"}, 26641cb1a9e6SAppaRao Puli {"Parameters", 26651cb1a9e6SAppaRao Puli {{{"Name", "ResetType"}, 26661cb1a9e6SAppaRao Puli {"Required", true}, 26671cb1a9e6SAppaRao Puli {"DataType", "String"}, 26681cb1a9e6SAppaRao Puli {"AllowableValues", 26697e860f15SJohn Edward Broadbent {"On", "ForceOff", "ForceOn", "ForceRestart", 26707e860f15SJohn Edward Broadbent "GracefulRestart", "GracefulShutdown", "PowerCycle", 26717e860f15SJohn Edward Broadbent "Nmi"}}}}}}; 26727e860f15SJohn Edward Broadbent }); 26731cb1a9e6SAppaRao Puli } 2674c5b2abe0SLewanczyk, Dawid } // namespace redfish 2675