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> 25ed398213SEd 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 /** 714*cd9a4666SKonstantin Aladyshev * @brief Translates boot type DBUS property value to redfish. 715*cd9a4666SKonstantin Aladyshev * 716*cd9a4666SKonstantin Aladyshev * @param[in] dbusType The boot type in DBUS speak. 717*cd9a4666SKonstantin Aladyshev * 718*cd9a4666SKonstantin Aladyshev * @return Returns as a string, the boot type in Redfish terms. If translation 719*cd9a4666SKonstantin Aladyshev * cannot be done, returns an empty string. 720*cd9a4666SKonstantin Aladyshev */ 721*cd9a4666SKonstantin Aladyshev inline std::string dbusToRfBootType(const std::string& dbusType) 722*cd9a4666SKonstantin Aladyshev { 723*cd9a4666SKonstantin Aladyshev if (dbusType == "xyz.openbmc_project.Control.Boot.Type.Types.Legacy") 724*cd9a4666SKonstantin Aladyshev { 725*cd9a4666SKonstantin Aladyshev return "Legacy"; 726*cd9a4666SKonstantin Aladyshev } 727*cd9a4666SKonstantin Aladyshev if (dbusType == "xyz.openbmc_project.Control.Boot.Type.Types.EFI") 728*cd9a4666SKonstantin Aladyshev { 729*cd9a4666SKonstantin Aladyshev return "UEFI"; 730*cd9a4666SKonstantin Aladyshev } 731*cd9a4666SKonstantin Aladyshev return ""; 732*cd9a4666SKonstantin Aladyshev } 733*cd9a4666SKonstantin Aladyshev 734*cd9a4666SKonstantin Aladyshev /** 735786d0f60SGunnar Mills * @brief Translates boot mode DBUS property value to redfish. 736491d8ee7SSantosh Puranik * 737491d8ee7SSantosh Puranik * @param[in] dbusMode The boot mode in DBUS speak. 738491d8ee7SSantosh Puranik * 739491d8ee7SSantosh Puranik * @return Returns as a string, the boot mode in Redfish terms. If translation 740491d8ee7SSantosh Puranik * cannot be done, returns an empty string. 741491d8ee7SSantosh Puranik */ 74223a21a1cSEd Tanous inline std::string dbusToRfBootMode(const std::string& dbusMode) 743491d8ee7SSantosh Puranik { 744491d8ee7SSantosh Puranik if (dbusMode == "xyz.openbmc_project.Control.Boot.Mode.Modes.Regular") 745491d8ee7SSantosh Puranik { 746491d8ee7SSantosh Puranik return "None"; 747491d8ee7SSantosh Puranik } 7483174e4dfSEd Tanous if (dbusMode == "xyz.openbmc_project.Control.Boot.Mode.Modes.Safe") 749491d8ee7SSantosh Puranik { 750491d8ee7SSantosh Puranik return "Diags"; 751491d8ee7SSantosh Puranik } 7523174e4dfSEd Tanous if (dbusMode == "xyz.openbmc_project.Control.Boot.Mode.Modes.Setup") 753491d8ee7SSantosh Puranik { 754491d8ee7SSantosh Puranik return "BiosSetup"; 755491d8ee7SSantosh Puranik } 756491d8ee7SSantosh Puranik return ""; 757491d8ee7SSantosh Puranik } 758491d8ee7SSantosh Puranik 759491d8ee7SSantosh Puranik /** 760786d0f60SGunnar Mills * @brief Translates boot source from Redfish to the DBus boot paths. 761491d8ee7SSantosh Puranik * 762491d8ee7SSantosh Puranik * @param[in] rfSource The boot source in Redfish. 763944ffaf9SJohnathan Mantey * @param[out] bootSource The DBus source 764944ffaf9SJohnathan Mantey * @param[out] bootMode the DBus boot mode 765491d8ee7SSantosh Puranik * 766944ffaf9SJohnathan Mantey * @return Integer error code. 767491d8ee7SSantosh Puranik */ 7688d1b46d7Szhanghch05 inline int assignBootParameters(const std::shared_ptr<bmcweb::AsyncResp>& aResp, 769944ffaf9SJohnathan Mantey const std::string& rfSource, 770944ffaf9SJohnathan Mantey std::string& bootSource, std::string& bootMode) 771491d8ee7SSantosh Puranik { 772944ffaf9SJohnathan Mantey // The caller has initialized the bootSource and bootMode to: 773944ffaf9SJohnathan Mantey // bootMode = "xyz.openbmc_project.Control.Boot.Mode.Modes.Regular"; 774944ffaf9SJohnathan Mantey // bootSource = "xyz.openbmc_project.Control.Boot.Source.Sources.Default"; 775944ffaf9SJohnathan Mantey // Only modify the bootSource/bootMode variable needed to achieve the 776944ffaf9SJohnathan Mantey // desired boot action. 777944ffaf9SJohnathan Mantey 778491d8ee7SSantosh Puranik if (rfSource == "None") 779491d8ee7SSantosh Puranik { 780944ffaf9SJohnathan Mantey return 0; 781491d8ee7SSantosh Puranik } 7823174e4dfSEd Tanous if (rfSource == "Pxe") 783491d8ee7SSantosh Puranik { 784944ffaf9SJohnathan Mantey bootSource = "xyz.openbmc_project.Control.Boot.Source.Sources.Network"; 785944ffaf9SJohnathan Mantey } 786944ffaf9SJohnathan Mantey else if (rfSource == "Hdd") 787944ffaf9SJohnathan Mantey { 788944ffaf9SJohnathan Mantey bootSource = "xyz.openbmc_project.Control.Boot.Source.Sources.Disk"; 789944ffaf9SJohnathan Mantey } 790944ffaf9SJohnathan Mantey else if (rfSource == "Diags") 791944ffaf9SJohnathan Mantey { 792944ffaf9SJohnathan Mantey bootMode = "xyz.openbmc_project.Control.Boot.Mode.Modes.Safe"; 793944ffaf9SJohnathan Mantey } 794944ffaf9SJohnathan Mantey else if (rfSource == "Cd") 795944ffaf9SJohnathan Mantey { 796944ffaf9SJohnathan Mantey bootSource = 797944ffaf9SJohnathan Mantey "xyz.openbmc_project.Control.Boot.Source.Sources.ExternalMedia"; 798944ffaf9SJohnathan Mantey } 799944ffaf9SJohnathan Mantey else if (rfSource == "BiosSetup") 800944ffaf9SJohnathan Mantey { 801944ffaf9SJohnathan Mantey bootMode = "xyz.openbmc_project.Control.Boot.Mode.Modes.Setup"; 802491d8ee7SSantosh Puranik } 8039f16b2c1SJennifer Lee else if (rfSource == "Usb") 8049f16b2c1SJennifer Lee { 805944ffaf9SJohnathan Mantey bootSource = 806944ffaf9SJohnathan Mantey "xyz.openbmc_project.Control.Boot.Source.Sources.RemovableMedia"; 8079f16b2c1SJennifer Lee } 808491d8ee7SSantosh Puranik else 809491d8ee7SSantosh Puranik { 810944ffaf9SJohnathan Mantey BMCWEB_LOG_DEBUG << "Invalid property value for " 811944ffaf9SJohnathan Mantey "BootSourceOverrideTarget: " 812944ffaf9SJohnathan Mantey << bootSource; 813944ffaf9SJohnathan Mantey messages::propertyValueNotInList(aResp->res, rfSource, 814944ffaf9SJohnathan Mantey "BootSourceTargetOverride"); 815944ffaf9SJohnathan Mantey return -1; 816491d8ee7SSantosh Puranik } 817944ffaf9SJohnathan Mantey return 0; 818491d8ee7SSantosh Puranik } 8191981771bSAli Ahmed 820978b8803SAndrew Geissler /** 821978b8803SAndrew Geissler * @brief Retrieves boot progress of the system 822978b8803SAndrew Geissler * 823978b8803SAndrew Geissler * @param[in] aResp Shared pointer for generating response message. 824978b8803SAndrew Geissler * 825978b8803SAndrew Geissler * @return None. 826978b8803SAndrew Geissler */ 8278d1b46d7Szhanghch05 inline void getBootProgress(const std::shared_ptr<bmcweb::AsyncResp>& aResp) 828978b8803SAndrew Geissler { 829978b8803SAndrew Geissler crow::connections::systemBus->async_method_call( 830978b8803SAndrew Geissler [aResp](const boost::system::error_code ec, 831978b8803SAndrew Geissler const std::variant<std::string>& bootProgress) { 832978b8803SAndrew Geissler if (ec) 833978b8803SAndrew Geissler { 834978b8803SAndrew Geissler // BootProgress is an optional object so just do nothing if 835978b8803SAndrew Geissler // not found 836978b8803SAndrew Geissler return; 837978b8803SAndrew Geissler } 838978b8803SAndrew Geissler 839978b8803SAndrew Geissler const std::string* bootProgressStr = 840978b8803SAndrew Geissler std::get_if<std::string>(&bootProgress); 841978b8803SAndrew Geissler 842978b8803SAndrew Geissler if (!bootProgressStr) 843978b8803SAndrew Geissler { 844978b8803SAndrew Geissler // Interface implemented but property not found, return error 845978b8803SAndrew Geissler // for that 846978b8803SAndrew Geissler messages::internalError(aResp->res); 847978b8803SAndrew Geissler return; 848978b8803SAndrew Geissler } 849978b8803SAndrew Geissler 850978b8803SAndrew Geissler BMCWEB_LOG_DEBUG << "Boot Progress: " << *bootProgressStr; 851978b8803SAndrew Geissler 852978b8803SAndrew Geissler // Now convert the D-Bus BootProgress to the appropriate Redfish 853978b8803SAndrew Geissler // enum 854978b8803SAndrew Geissler std::string rfBpLastState = "None"; 855978b8803SAndrew Geissler if (*bootProgressStr == "xyz.openbmc_project.State.Boot.Progress." 856978b8803SAndrew Geissler "ProgressStages.Unspecified") 857978b8803SAndrew Geissler { 858978b8803SAndrew Geissler rfBpLastState = "None"; 859978b8803SAndrew Geissler } 860978b8803SAndrew Geissler else if (*bootProgressStr == 861978b8803SAndrew Geissler "xyz.openbmc_project.State.Boot.Progress.ProgressStages." 862978b8803SAndrew Geissler "PrimaryProcInit") 863978b8803SAndrew Geissler { 864978b8803SAndrew Geissler rfBpLastState = "PrimaryProcessorInitializationStarted"; 865978b8803SAndrew Geissler } 866978b8803SAndrew Geissler else if (*bootProgressStr == 867978b8803SAndrew Geissler "xyz.openbmc_project.State.Boot.Progress.ProgressStages." 868978b8803SAndrew Geissler "BusInit") 869978b8803SAndrew Geissler { 870978b8803SAndrew Geissler rfBpLastState = "BusInitializationStarted"; 871978b8803SAndrew Geissler } 872978b8803SAndrew Geissler else if (*bootProgressStr == 873978b8803SAndrew Geissler "xyz.openbmc_project.State.Boot.Progress.ProgressStages." 874978b8803SAndrew Geissler "MemoryInit") 875978b8803SAndrew Geissler { 876978b8803SAndrew Geissler rfBpLastState = "MemoryInitializationStarted"; 877978b8803SAndrew Geissler } 878978b8803SAndrew Geissler else if (*bootProgressStr == 879978b8803SAndrew Geissler "xyz.openbmc_project.State.Boot.Progress.ProgressStages." 880978b8803SAndrew Geissler "SecondaryProcInit") 881978b8803SAndrew Geissler { 882978b8803SAndrew Geissler rfBpLastState = "SecondaryProcessorInitializationStarted"; 883978b8803SAndrew Geissler } 884978b8803SAndrew Geissler else if (*bootProgressStr == 885978b8803SAndrew Geissler "xyz.openbmc_project.State.Boot.Progress.ProgressStages." 886978b8803SAndrew Geissler "PCIInit") 887978b8803SAndrew Geissler { 888978b8803SAndrew Geissler rfBpLastState = "PCIResourceConfigStarted"; 889978b8803SAndrew Geissler } 890978b8803SAndrew Geissler else if (*bootProgressStr == 891978b8803SAndrew Geissler "xyz.openbmc_project.State.Boot.Progress.ProgressStages." 892978b8803SAndrew Geissler "SystemInitComplete") 893978b8803SAndrew Geissler { 894978b8803SAndrew Geissler rfBpLastState = "SystemHardwareInitializationComplete"; 895978b8803SAndrew Geissler } 896978b8803SAndrew Geissler else if (*bootProgressStr == 897978b8803SAndrew Geissler "xyz.openbmc_project.State.Boot.Progress.ProgressStages." 898978b8803SAndrew Geissler "OSStart") 899978b8803SAndrew Geissler { 900978b8803SAndrew Geissler rfBpLastState = "OSBootStarted"; 901978b8803SAndrew Geissler } 902978b8803SAndrew Geissler else if (*bootProgressStr == 903978b8803SAndrew Geissler "xyz.openbmc_project.State.Boot.Progress.ProgressStages." 904978b8803SAndrew Geissler "OSRunning") 905978b8803SAndrew Geissler { 906978b8803SAndrew Geissler rfBpLastState = "OSRunning"; 907978b8803SAndrew Geissler } 908978b8803SAndrew Geissler else 909978b8803SAndrew Geissler { 910978b8803SAndrew Geissler BMCWEB_LOG_DEBUG << "Unsupported D-Bus BootProgress " 911978b8803SAndrew Geissler << *bootProgressStr; 912978b8803SAndrew Geissler // Just return the default 913978b8803SAndrew Geissler } 914978b8803SAndrew Geissler 915978b8803SAndrew Geissler aResp->res.jsonValue["BootProgress"]["LastState"] = rfBpLastState; 916978b8803SAndrew Geissler }, 917978b8803SAndrew Geissler "xyz.openbmc_project.State.Host", "/xyz/openbmc_project/state/host0", 918978b8803SAndrew Geissler "org.freedesktop.DBus.Properties", "Get", 919978b8803SAndrew Geissler "xyz.openbmc_project.State.Boot.Progress", "BootProgress"); 920978b8803SAndrew Geissler } 921491d8ee7SSantosh Puranik 922491d8ee7SSantosh Puranik /** 923*cd9a4666SKonstantin Aladyshev * @brief Checks if the current boot override state can be considered as 924*cd9a4666SKonstantin Aladyshev * Disabled 925*cd9a4666SKonstantin Aladyshev * 926*cd9a4666SKonstantin Aladyshev * @param[in] aResp Shared pointer for generating response message. 927*cd9a4666SKonstantin Aladyshev * 928*cd9a4666SKonstantin Aladyshev * @return None. 929*cd9a4666SKonstantin Aladyshev */ 930*cd9a4666SKonstantin Aladyshev inline void 931*cd9a4666SKonstantin Aladyshev checkIfOverrideIsDisabled(const std::shared_ptr<bmcweb::AsyncResp>& aResp) 932*cd9a4666SKonstantin Aladyshev { 933*cd9a4666SKonstantin Aladyshev // If the BootSourceOverrideTarget is still "None" at the end, 934*cd9a4666SKonstantin Aladyshev // reset the BootSourceOverrideEnabled to indicate that 935*cd9a4666SKonstantin Aladyshev // overrides are disabled 936*cd9a4666SKonstantin Aladyshev if (aResp->res.jsonValue["Boot"]["BootSourceOverrideTarget"] == "None") 937*cd9a4666SKonstantin Aladyshev { 938*cd9a4666SKonstantin Aladyshev // If the BootSourceOverrideMode is supported we should 939*cd9a4666SKonstantin Aladyshev // check if it is still "UEFI" too 940*cd9a4666SKonstantin Aladyshev if (aResp->res.jsonValue["Boot"].contains("BootSourceOverrideMode")) 941*cd9a4666SKonstantin Aladyshev { 942*cd9a4666SKonstantin Aladyshev if (aResp->res.jsonValue["Boot"]["BootSourceOverrideMode"] != 943*cd9a4666SKonstantin Aladyshev "UEFI") 944*cd9a4666SKonstantin Aladyshev { 945*cd9a4666SKonstantin Aladyshev return; 946*cd9a4666SKonstantin Aladyshev } 947*cd9a4666SKonstantin Aladyshev } 948*cd9a4666SKonstantin Aladyshev aResp->res.jsonValue["Boot"]["BootSourceOverrideEnabled"] = "Disabled"; 949*cd9a4666SKonstantin Aladyshev } 950*cd9a4666SKonstantin Aladyshev } 951*cd9a4666SKonstantin Aladyshev 952*cd9a4666SKonstantin Aladyshev /** 953*cd9a4666SKonstantin Aladyshev * @brief Retrieves boot type over DBUS and fills out the response 954*cd9a4666SKonstantin Aladyshev * 955*cd9a4666SKonstantin Aladyshev * @param[in] aResp Shared pointer for generating response message. 956*cd9a4666SKonstantin Aladyshev * @param[in] bootDbusObj The dbus object to query for boot properties. 957*cd9a4666SKonstantin Aladyshev * 958*cd9a4666SKonstantin Aladyshev * @return None. 959*cd9a4666SKonstantin Aladyshev */ 960*cd9a4666SKonstantin Aladyshev inline void getBootType(const std::shared_ptr<bmcweb::AsyncResp>& aResp, 961*cd9a4666SKonstantin Aladyshev const std::string& bootDbusObj) 962*cd9a4666SKonstantin Aladyshev { 963*cd9a4666SKonstantin Aladyshev crow::connections::systemBus->async_method_call( 964*cd9a4666SKonstantin Aladyshev [aResp](const boost::system::error_code ec, 965*cd9a4666SKonstantin Aladyshev const std::variant<std::string>& bootType) { 966*cd9a4666SKonstantin Aladyshev if (ec) 967*cd9a4666SKonstantin Aladyshev { 968*cd9a4666SKonstantin Aladyshev // not an error, don't have to have the interface 969*cd9a4666SKonstantin Aladyshev 970*cd9a4666SKonstantin Aladyshev // Support Disabled override state in a way: 971*cd9a4666SKonstantin Aladyshev // "BootSourceOverrideEnabled=Disabled" = 972*cd9a4666SKonstantin Aladyshev // "BootSourceOverrideMode=UEFI" + 973*cd9a4666SKonstantin Aladyshev // "BootSourceOverrideTarget=None" 974*cd9a4666SKonstantin Aladyshev checkIfOverrideIsDisabled(aResp); 975*cd9a4666SKonstantin Aladyshev return; 976*cd9a4666SKonstantin Aladyshev } 977*cd9a4666SKonstantin Aladyshev 978*cd9a4666SKonstantin Aladyshev const std::string* bootTypeStr = 979*cd9a4666SKonstantin Aladyshev std::get_if<std::string>(&bootType); 980*cd9a4666SKonstantin Aladyshev 981*cd9a4666SKonstantin Aladyshev if (!bootTypeStr) 982*cd9a4666SKonstantin Aladyshev { 983*cd9a4666SKonstantin Aladyshev messages::internalError(aResp->res); 984*cd9a4666SKonstantin Aladyshev return; 985*cd9a4666SKonstantin Aladyshev } 986*cd9a4666SKonstantin Aladyshev 987*cd9a4666SKonstantin Aladyshev BMCWEB_LOG_DEBUG << "Boot type: " << *bootTypeStr; 988*cd9a4666SKonstantin Aladyshev 989*cd9a4666SKonstantin Aladyshev aResp->res.jsonValue["Boot"]["BootSourceOverrideMode@Redfish." 990*cd9a4666SKonstantin Aladyshev "AllowableValues"] = {"Legacy", 991*cd9a4666SKonstantin Aladyshev "UEFI"}; 992*cd9a4666SKonstantin Aladyshev 993*cd9a4666SKonstantin Aladyshev auto rfType = dbusToRfBootType(*bootTypeStr); 994*cd9a4666SKonstantin Aladyshev if (rfType.empty()) 995*cd9a4666SKonstantin Aladyshev { 996*cd9a4666SKonstantin Aladyshev messages::internalError(aResp->res); 997*cd9a4666SKonstantin Aladyshev return; 998*cd9a4666SKonstantin Aladyshev } 999*cd9a4666SKonstantin Aladyshev 1000*cd9a4666SKonstantin Aladyshev aResp->res.jsonValue["Boot"]["BootSourceOverrideMode"] = rfType; 1001*cd9a4666SKonstantin Aladyshev 1002*cd9a4666SKonstantin Aladyshev // Support Disabled override state in a way: 1003*cd9a4666SKonstantin Aladyshev // "BootSourceOverrideEnabled=Disabled" = 1004*cd9a4666SKonstantin Aladyshev // "BootSourceOverrideMode=UEFI" + "BootSourceOverrideTarget=None" 1005*cd9a4666SKonstantin Aladyshev checkIfOverrideIsDisabled(aResp); 1006*cd9a4666SKonstantin Aladyshev }, 1007*cd9a4666SKonstantin Aladyshev "xyz.openbmc_project.Settings", bootDbusObj, 1008*cd9a4666SKonstantin Aladyshev "org.freedesktop.DBus.Properties", "Get", 1009*cd9a4666SKonstantin Aladyshev "xyz.openbmc_project.Control.Boot.Type", "BootType"); 1010*cd9a4666SKonstantin Aladyshev } 1011*cd9a4666SKonstantin Aladyshev 1012*cd9a4666SKonstantin Aladyshev /** 1013491d8ee7SSantosh Puranik * @brief Retrieves boot mode over DBUS and fills out the response 1014491d8ee7SSantosh Puranik * 1015491d8ee7SSantosh Puranik * @param[in] aResp Shared pointer for generating response message. 1016491d8ee7SSantosh Puranik * @param[in] bootDbusObj The dbus object to query for boot properties. 1017491d8ee7SSantosh Puranik * 1018491d8ee7SSantosh Puranik * @return None. 1019491d8ee7SSantosh Puranik */ 10208d1b46d7Szhanghch05 inline void getBootMode(const std::shared_ptr<bmcweb::AsyncResp>& aResp, 1021b5a76932SEd Tanous const std::string& bootDbusObj) 1022491d8ee7SSantosh Puranik { 1023491d8ee7SSantosh Puranik crow::connections::systemBus->async_method_call( 1024*cd9a4666SKonstantin Aladyshev [aResp, bootDbusObj](const boost::system::error_code ec, 1025491d8ee7SSantosh Puranik const std::variant<std::string>& bootMode) { 1026491d8ee7SSantosh Puranik if (ec) 1027491d8ee7SSantosh Puranik { 1028491d8ee7SSantosh Puranik BMCWEB_LOG_DEBUG << "DBUS response error " << ec; 1029491d8ee7SSantosh Puranik messages::internalError(aResp->res); 1030491d8ee7SSantosh Puranik return; 1031491d8ee7SSantosh Puranik } 1032491d8ee7SSantosh Puranik 1033491d8ee7SSantosh Puranik const std::string* bootModeStr = 1034491d8ee7SSantosh Puranik std::get_if<std::string>(&bootMode); 1035491d8ee7SSantosh Puranik 1036491d8ee7SSantosh Puranik if (!bootModeStr) 1037491d8ee7SSantosh Puranik { 1038491d8ee7SSantosh Puranik messages::internalError(aResp->res); 1039491d8ee7SSantosh Puranik return; 1040491d8ee7SSantosh Puranik } 1041491d8ee7SSantosh Puranik 1042491d8ee7SSantosh Puranik BMCWEB_LOG_DEBUG << "Boot mode: " << *bootModeStr; 1043491d8ee7SSantosh Puranik 1044491d8ee7SSantosh Puranik aResp->res.jsonValue["Boot"]["BootSourceOverrideTarget@Redfish." 1045491d8ee7SSantosh Puranik "AllowableValues"] = { 1046944ffaf9SJohnathan Mantey "None", "Pxe", "Hdd", "Cd", "Diags", "BiosSetup", "Usb"}; 1047491d8ee7SSantosh Puranik 1048491d8ee7SSantosh Puranik if (*bootModeStr != 1049491d8ee7SSantosh Puranik "xyz.openbmc_project.Control.Boot.Mode.Modes.Regular") 1050491d8ee7SSantosh Puranik { 1051491d8ee7SSantosh Puranik auto rfMode = dbusToRfBootMode(*bootModeStr); 1052491d8ee7SSantosh Puranik if (!rfMode.empty()) 1053491d8ee7SSantosh Puranik { 1054491d8ee7SSantosh Puranik aResp->res.jsonValue["Boot"]["BootSourceOverrideTarget"] = 1055491d8ee7SSantosh Puranik rfMode; 1056491d8ee7SSantosh Puranik } 1057491d8ee7SSantosh Puranik } 1058491d8ee7SSantosh Puranik 1059*cd9a4666SKonstantin Aladyshev // Get BootType inside this async call as we need all of the 1060*cd9a4666SKonstantin Aladyshev // BootSource/BootMode/BootType to support 1061*cd9a4666SKonstantin Aladyshev // "BootSourceOverrideEnabled"="Disabled" state. 1062*cd9a4666SKonstantin Aladyshev getBootType(aResp, bootDbusObj); 1063491d8ee7SSantosh Puranik }, 1064491d8ee7SSantosh Puranik "xyz.openbmc_project.Settings", bootDbusObj, 1065491d8ee7SSantosh Puranik "org.freedesktop.DBus.Properties", "Get", 1066491d8ee7SSantosh Puranik "xyz.openbmc_project.Control.Boot.Mode", "BootMode"); 1067491d8ee7SSantosh Puranik } 1068491d8ee7SSantosh Puranik 1069491d8ee7SSantosh Puranik /** 1070491d8ee7SSantosh Puranik * @brief Retrieves boot source over DBUS 1071491d8ee7SSantosh Puranik * 1072491d8ee7SSantosh Puranik * @param[in] aResp Shared pointer for generating response message. 1073491d8ee7SSantosh Puranik * @param[in] oneTimeEnable Boolean to indicate boot properties are one-time. 1074491d8ee7SSantosh Puranik * 1075491d8ee7SSantosh Puranik * @return None. 1076491d8ee7SSantosh Puranik */ 10778d1b46d7Szhanghch05 inline void getBootSource(const std::shared_ptr<bmcweb::AsyncResp>& aResp, 1078f23b7296SEd Tanous bool oneTimeEnabled) 1079491d8ee7SSantosh Puranik { 1080491d8ee7SSantosh Puranik std::string bootDbusObj = 1081491d8ee7SSantosh Puranik oneTimeEnabled ? "/xyz/openbmc_project/control/host0/boot/one_time" 1082491d8ee7SSantosh Puranik : "/xyz/openbmc_project/control/host0/boot"; 1083491d8ee7SSantosh Puranik 1084491d8ee7SSantosh Puranik BMCWEB_LOG_DEBUG << "Is one time: " << oneTimeEnabled; 1085491d8ee7SSantosh Puranik aResp->res.jsonValue["Boot"]["BootSourceOverrideEnabled"] = 1086491d8ee7SSantosh Puranik (oneTimeEnabled) ? "Once" : "Continuous"; 1087491d8ee7SSantosh Puranik 1088491d8ee7SSantosh Puranik crow::connections::systemBus->async_method_call( 1089491d8ee7SSantosh Puranik [aResp, bootDbusObj](const boost::system::error_code ec, 1090491d8ee7SSantosh Puranik const std::variant<std::string>& bootSource) { 1091491d8ee7SSantosh Puranik if (ec) 1092491d8ee7SSantosh Puranik { 1093491d8ee7SSantosh Puranik BMCWEB_LOG_DEBUG << "DBUS response error " << ec; 1094491d8ee7SSantosh Puranik messages::internalError(aResp->res); 1095491d8ee7SSantosh Puranik return; 1096491d8ee7SSantosh Puranik } 1097491d8ee7SSantosh Puranik 1098491d8ee7SSantosh Puranik const std::string* bootSourceStr = 1099491d8ee7SSantosh Puranik std::get_if<std::string>(&bootSource); 1100491d8ee7SSantosh Puranik 1101491d8ee7SSantosh Puranik if (!bootSourceStr) 1102491d8ee7SSantosh Puranik { 1103491d8ee7SSantosh Puranik messages::internalError(aResp->res); 1104491d8ee7SSantosh Puranik return; 1105491d8ee7SSantosh Puranik } 1106491d8ee7SSantosh Puranik BMCWEB_LOG_DEBUG << "Boot source: " << *bootSourceStr; 1107491d8ee7SSantosh Puranik 1108491d8ee7SSantosh Puranik auto rfSource = dbusToRfBootSource(*bootSourceStr); 1109491d8ee7SSantosh Puranik if (!rfSource.empty()) 1110491d8ee7SSantosh Puranik { 1111491d8ee7SSantosh Puranik aResp->res.jsonValue["Boot"]["BootSourceOverrideTarget"] = 1112491d8ee7SSantosh Puranik rfSource; 1113491d8ee7SSantosh Puranik } 1114*cd9a4666SKonstantin Aladyshev 1115*cd9a4666SKonstantin Aladyshev // Get BootMode as BootSourceOverrideTarget is constructed 1116*cd9a4666SKonstantin Aladyshev // from both BootSource and BootMode 1117*cd9a4666SKonstantin Aladyshev getBootMode(aResp, bootDbusObj); 1118491d8ee7SSantosh Puranik }, 1119491d8ee7SSantosh Puranik "xyz.openbmc_project.Settings", bootDbusObj, 1120491d8ee7SSantosh Puranik "org.freedesktop.DBus.Properties", "Get", 1121491d8ee7SSantosh Puranik "xyz.openbmc_project.Control.Boot.Source", "BootSource"); 1122491d8ee7SSantosh Puranik } 1123491d8ee7SSantosh Puranik 1124491d8ee7SSantosh Puranik /** 1125491d8ee7SSantosh Puranik * @brief Retrieves "One time" enabled setting over DBUS and calls function to 1126491d8ee7SSantosh Puranik * get boot source and boot mode. 1127491d8ee7SSantosh Puranik * 1128491d8ee7SSantosh Puranik * @param[in] aResp Shared pointer for generating response message. 1129491d8ee7SSantosh Puranik * 1130491d8ee7SSantosh Puranik * @return None. 1131491d8ee7SSantosh Puranik */ 11328d1b46d7Szhanghch05 inline void getBootProperties(const std::shared_ptr<bmcweb::AsyncResp>& aResp) 1133491d8ee7SSantosh Puranik { 1134491d8ee7SSantosh Puranik BMCWEB_LOG_DEBUG << "Get boot information."; 1135491d8ee7SSantosh Puranik 1136491d8ee7SSantosh Puranik crow::connections::systemBus->async_method_call( 1137c5d03ff4SJennifer Lee [aResp](const boost::system::error_code ec, 113819bd78d9SPatrick Williams const std::variant<bool>& oneTime) { 1139491d8ee7SSantosh Puranik if (ec) 1140491d8ee7SSantosh Puranik { 1141491d8ee7SSantosh Puranik BMCWEB_LOG_DEBUG << "DBUS response error " << ec; 11422a833c77SJames Feist // not an error, don't have to have the interface 1143491d8ee7SSantosh Puranik return; 1144491d8ee7SSantosh Puranik } 1145491d8ee7SSantosh Puranik 1146491d8ee7SSantosh Puranik const bool* oneTimePtr = std::get_if<bool>(&oneTime); 1147491d8ee7SSantosh Puranik 1148491d8ee7SSantosh Puranik if (!oneTimePtr) 1149491d8ee7SSantosh Puranik { 1150491d8ee7SSantosh Puranik messages::internalError(aResp->res); 1151491d8ee7SSantosh Puranik return; 1152491d8ee7SSantosh Puranik } 1153491d8ee7SSantosh Puranik getBootSource(aResp, *oneTimePtr); 1154491d8ee7SSantosh Puranik }, 1155491d8ee7SSantosh Puranik "xyz.openbmc_project.Settings", 1156491d8ee7SSantosh Puranik "/xyz/openbmc_project/control/host0/boot/one_time", 1157491d8ee7SSantosh Puranik "org.freedesktop.DBus.Properties", "Get", 1158491d8ee7SSantosh Puranik "xyz.openbmc_project.Object.Enable", "Enabled"); 1159491d8ee7SSantosh Puranik } 1160491d8ee7SSantosh Puranik 1161491d8ee7SSantosh Puranik /** 1162c0557e1aSGunnar Mills * @brief Retrieves the Last Reset Time 1163c0557e1aSGunnar Mills * 1164c0557e1aSGunnar Mills * "Reset" is an overloaded term in Redfish, "Reset" includes power on 1165c0557e1aSGunnar Mills * and power off. Even though this is the "system" Redfish object look at the 1166c0557e1aSGunnar Mills * chassis D-Bus interface for the LastStateChangeTime since this has the 1167c0557e1aSGunnar Mills * last power operation time. 1168c0557e1aSGunnar Mills * 1169c0557e1aSGunnar Mills * @param[in] aResp Shared pointer for generating response message. 1170c0557e1aSGunnar Mills * 1171c0557e1aSGunnar Mills * @return None. 1172c0557e1aSGunnar Mills */ 11738d1b46d7Szhanghch05 inline void getLastResetTime(const std::shared_ptr<bmcweb::AsyncResp>& aResp) 1174c0557e1aSGunnar Mills { 1175c0557e1aSGunnar Mills BMCWEB_LOG_DEBUG << "Getting System Last Reset Time"; 1176c0557e1aSGunnar Mills 1177c0557e1aSGunnar Mills crow::connections::systemBus->async_method_call( 1178c0557e1aSGunnar Mills [aResp](const boost::system::error_code ec, 1179c0557e1aSGunnar Mills std::variant<uint64_t>& lastResetTime) { 1180c0557e1aSGunnar Mills if (ec) 1181c0557e1aSGunnar Mills { 1182c0557e1aSGunnar Mills BMCWEB_LOG_DEBUG << "D-BUS response error " << ec; 1183c0557e1aSGunnar Mills return; 1184c0557e1aSGunnar Mills } 1185c0557e1aSGunnar Mills 1186c0557e1aSGunnar Mills const uint64_t* lastResetTimePtr = 1187c0557e1aSGunnar Mills std::get_if<uint64_t>(&lastResetTime); 1188c0557e1aSGunnar Mills 1189c0557e1aSGunnar Mills if (!lastResetTimePtr) 1190c0557e1aSGunnar Mills { 1191c0557e1aSGunnar Mills messages::internalError(aResp->res); 1192c0557e1aSGunnar Mills return; 1193c0557e1aSGunnar Mills } 1194c0557e1aSGunnar Mills // LastStateChangeTime is epoch time, in milliseconds 1195c0557e1aSGunnar Mills // https://github.com/openbmc/phosphor-dbus-interfaces/blob/33e8e1dd64da53a66e888d33dc82001305cd0bf9/xyz/openbmc_project/State/Chassis.interface.yaml#L19 1196c0557e1aSGunnar Mills time_t lastResetTimeStamp = 1197c0557e1aSGunnar Mills static_cast<time_t>(*lastResetTimePtr / 1000); 1198c0557e1aSGunnar Mills 1199c0557e1aSGunnar Mills // Convert to ISO 8601 standard 1200c0557e1aSGunnar Mills aResp->res.jsonValue["LastResetTime"] = 1201c0557e1aSGunnar Mills crow::utility::getDateTime(lastResetTimeStamp); 1202c0557e1aSGunnar Mills }, 1203c0557e1aSGunnar Mills "xyz.openbmc_project.State.Chassis", 1204c0557e1aSGunnar Mills "/xyz/openbmc_project/state/chassis0", 1205c0557e1aSGunnar Mills "org.freedesktop.DBus.Properties", "Get", 1206c0557e1aSGunnar Mills "xyz.openbmc_project.State.Chassis", "LastStateChangeTime"); 1207c0557e1aSGunnar Mills } 1208c0557e1aSGunnar Mills 1209c0557e1aSGunnar Mills /** 12106bd5a8d2SGunnar Mills * @brief Retrieves Automatic Retry properties. Known on D-Bus as AutoReboot. 12116bd5a8d2SGunnar Mills * 12126bd5a8d2SGunnar Mills * @param[in] aResp Shared pointer for generating response message. 12136bd5a8d2SGunnar Mills * 12146bd5a8d2SGunnar Mills * @return None. 12156bd5a8d2SGunnar Mills */ 12168d1b46d7Szhanghch05 inline void getAutomaticRetry(const std::shared_ptr<bmcweb::AsyncResp>& aResp) 12176bd5a8d2SGunnar Mills { 12186bd5a8d2SGunnar Mills BMCWEB_LOG_DEBUG << "Get Automatic Retry policy"; 12196bd5a8d2SGunnar Mills 12206bd5a8d2SGunnar Mills crow::connections::systemBus->async_method_call( 12216bd5a8d2SGunnar Mills [aResp](const boost::system::error_code ec, 12226bd5a8d2SGunnar Mills std::variant<bool>& autoRebootEnabled) { 12236bd5a8d2SGunnar Mills if (ec) 12246bd5a8d2SGunnar Mills { 12256bd5a8d2SGunnar Mills BMCWEB_LOG_DEBUG << "D-BUS response error " << ec; 12266bd5a8d2SGunnar Mills return; 12276bd5a8d2SGunnar Mills } 12286bd5a8d2SGunnar Mills 12296bd5a8d2SGunnar Mills const bool* autoRebootEnabledPtr = 12306bd5a8d2SGunnar Mills std::get_if<bool>(&autoRebootEnabled); 12316bd5a8d2SGunnar Mills 12326bd5a8d2SGunnar Mills if (!autoRebootEnabledPtr) 12336bd5a8d2SGunnar Mills { 12346bd5a8d2SGunnar Mills messages::internalError(aResp->res); 12356bd5a8d2SGunnar Mills return; 12366bd5a8d2SGunnar Mills } 12376bd5a8d2SGunnar Mills 12386bd5a8d2SGunnar Mills BMCWEB_LOG_DEBUG << "Auto Reboot: " << *autoRebootEnabledPtr; 12396bd5a8d2SGunnar Mills if (*autoRebootEnabledPtr == true) 12406bd5a8d2SGunnar Mills { 12416bd5a8d2SGunnar Mills aResp->res.jsonValue["Boot"]["AutomaticRetryConfig"] = 12426bd5a8d2SGunnar Mills "RetryAttempts"; 12436bd5a8d2SGunnar Mills // If AutomaticRetry (AutoReboot) is enabled see how many 12446bd5a8d2SGunnar Mills // attempts are left 12456bd5a8d2SGunnar Mills crow::connections::systemBus->async_method_call( 1246cb13a392SEd Tanous [aResp](const boost::system::error_code ec2, 12476bd5a8d2SGunnar Mills std::variant<uint32_t>& autoRebootAttemptsLeft) { 1248cb13a392SEd Tanous if (ec2) 12496bd5a8d2SGunnar Mills { 1250cb13a392SEd Tanous BMCWEB_LOG_DEBUG << "D-BUS response error " << ec2; 12516bd5a8d2SGunnar Mills return; 12526bd5a8d2SGunnar Mills } 12536bd5a8d2SGunnar Mills 12546bd5a8d2SGunnar Mills const uint32_t* autoRebootAttemptsLeftPtr = 12556bd5a8d2SGunnar Mills std::get_if<uint32_t>(&autoRebootAttemptsLeft); 12566bd5a8d2SGunnar Mills 12576bd5a8d2SGunnar Mills if (!autoRebootAttemptsLeftPtr) 12586bd5a8d2SGunnar Mills { 12596bd5a8d2SGunnar Mills messages::internalError(aResp->res); 12606bd5a8d2SGunnar Mills return; 12616bd5a8d2SGunnar Mills } 12626bd5a8d2SGunnar Mills 12636bd5a8d2SGunnar Mills BMCWEB_LOG_DEBUG << "Auto Reboot Attempts Left: " 12646bd5a8d2SGunnar Mills << *autoRebootAttemptsLeftPtr; 12656bd5a8d2SGunnar Mills 12666bd5a8d2SGunnar Mills aResp->res 12676bd5a8d2SGunnar Mills .jsonValue["Boot"] 12686bd5a8d2SGunnar Mills ["RemainingAutomaticRetryAttempts"] = 12696bd5a8d2SGunnar Mills *autoRebootAttemptsLeftPtr; 12706bd5a8d2SGunnar Mills }, 12716bd5a8d2SGunnar Mills "xyz.openbmc_project.State.Host", 12726bd5a8d2SGunnar Mills "/xyz/openbmc_project/state/host0", 12736bd5a8d2SGunnar Mills "org.freedesktop.DBus.Properties", "Get", 12746bd5a8d2SGunnar Mills "xyz.openbmc_project.Control.Boot.RebootAttempts", 12756bd5a8d2SGunnar Mills "AttemptsLeft"); 12766bd5a8d2SGunnar Mills } 12776bd5a8d2SGunnar Mills else 12786bd5a8d2SGunnar Mills { 12796bd5a8d2SGunnar Mills aResp->res.jsonValue["Boot"]["AutomaticRetryConfig"] = 12806bd5a8d2SGunnar Mills "Disabled"; 12816bd5a8d2SGunnar Mills } 12826bd5a8d2SGunnar Mills 12836bd5a8d2SGunnar Mills // Not on D-Bus. Hardcoded here: 12846bd5a8d2SGunnar Mills // https://github.com/openbmc/phosphor-state-manager/blob/1dbbef42675e94fb1f78edb87d6b11380260535a/meson_options.txt#L71 12856bd5a8d2SGunnar Mills aResp->res.jsonValue["Boot"]["AutomaticRetryAttempts"] = 3; 128669f35306SGunnar Mills 128769f35306SGunnar Mills // "AutomaticRetryConfig" can be 3 values, Disabled, RetryAlways, 128869f35306SGunnar Mills // and RetryAttempts. OpenBMC only supports Disabled and 128969f35306SGunnar Mills // RetryAttempts. 129069f35306SGunnar Mills aResp->res.jsonValue["Boot"]["AutomaticRetryConfig@Redfish." 129169f35306SGunnar Mills "AllowableValues"] = {"Disabled", 129269f35306SGunnar Mills "RetryAttempts"}; 12936bd5a8d2SGunnar Mills }, 12946bd5a8d2SGunnar Mills "xyz.openbmc_project.Settings", 12956bd5a8d2SGunnar Mills "/xyz/openbmc_project/control/host0/auto_reboot", 12966bd5a8d2SGunnar Mills "org.freedesktop.DBus.Properties", "Get", 12976bd5a8d2SGunnar Mills "xyz.openbmc_project.Control.Boot.RebootPolicy", "AutoReboot"); 12986bd5a8d2SGunnar Mills } 12996bd5a8d2SGunnar Mills 13006bd5a8d2SGunnar Mills /** 1301c6a620f2SGeorge Liu * @brief Retrieves power restore policy over DBUS. 1302c6a620f2SGeorge Liu * 1303c6a620f2SGeorge Liu * @param[in] aResp Shared pointer for generating response message. 1304c6a620f2SGeorge Liu * 1305c6a620f2SGeorge Liu * @return None. 1306c6a620f2SGeorge Liu */ 13078d1b46d7Szhanghch05 inline void 13088d1b46d7Szhanghch05 getPowerRestorePolicy(const std::shared_ptr<bmcweb::AsyncResp>& aResp) 1309c6a620f2SGeorge Liu { 1310c6a620f2SGeorge Liu BMCWEB_LOG_DEBUG << "Get power restore policy"; 1311c6a620f2SGeorge Liu 1312c6a620f2SGeorge Liu crow::connections::systemBus->async_method_call( 1313c6a620f2SGeorge Liu [aResp](const boost::system::error_code ec, 131419bd78d9SPatrick Williams std::variant<std::string>& policy) { 1315c6a620f2SGeorge Liu if (ec) 1316c6a620f2SGeorge Liu { 1317c6a620f2SGeorge Liu BMCWEB_LOG_DEBUG << "DBUS response error " << ec; 1318c6a620f2SGeorge Liu return; 1319c6a620f2SGeorge Liu } 1320c6a620f2SGeorge Liu 1321c6a620f2SGeorge Liu const boost::container::flat_map<std::string, std::string> 1322c6a620f2SGeorge Liu policyMaps = { 1323c6a620f2SGeorge Liu {"xyz.openbmc_project.Control.Power.RestorePolicy.Policy." 1324c6a620f2SGeorge Liu "AlwaysOn", 1325c6a620f2SGeorge Liu "AlwaysOn"}, 1326c6a620f2SGeorge Liu {"xyz.openbmc_project.Control.Power.RestorePolicy.Policy." 1327c6a620f2SGeorge Liu "AlwaysOff", 1328c6a620f2SGeorge Liu "AlwaysOff"}, 1329c6a620f2SGeorge Liu {"xyz.openbmc_project.Control.Power.RestorePolicy.Policy." 133037ec9072SGunnar Mills "Restore", 1331c6a620f2SGeorge Liu "LastState"}}; 1332c6a620f2SGeorge Liu 1333c6a620f2SGeorge Liu const std::string* policyPtr = std::get_if<std::string>(&policy); 1334c6a620f2SGeorge Liu 1335c6a620f2SGeorge Liu if (!policyPtr) 1336c6a620f2SGeorge Liu { 1337c6a620f2SGeorge Liu messages::internalError(aResp->res); 1338c6a620f2SGeorge Liu return; 1339c6a620f2SGeorge Liu } 1340c6a620f2SGeorge Liu 1341c6a620f2SGeorge Liu auto policyMapsIt = policyMaps.find(*policyPtr); 1342c6a620f2SGeorge Liu if (policyMapsIt == policyMaps.end()) 1343c6a620f2SGeorge Liu { 1344c6a620f2SGeorge Liu messages::internalError(aResp->res); 1345c6a620f2SGeorge Liu return; 1346c6a620f2SGeorge Liu } 1347c6a620f2SGeorge Liu 1348c6a620f2SGeorge Liu aResp->res.jsonValue["PowerRestorePolicy"] = policyMapsIt->second; 1349c6a620f2SGeorge Liu }, 1350c6a620f2SGeorge Liu "xyz.openbmc_project.Settings", 1351c6a620f2SGeorge Liu "/xyz/openbmc_project/control/host0/power_restore_policy", 1352c6a620f2SGeorge Liu "org.freedesktop.DBus.Properties", "Get", 1353c6a620f2SGeorge Liu "xyz.openbmc_project.Control.Power.RestorePolicy", 1354c6a620f2SGeorge Liu "PowerRestorePolicy"); 1355c6a620f2SGeorge Liu } 1356c6a620f2SGeorge Liu 1357c6a620f2SGeorge Liu /** 13581981771bSAli Ahmed * @brief Get TrustedModuleRequiredToBoot property. Determines whether or not 13591981771bSAli Ahmed * TPM is required for booting the host. 13601981771bSAli Ahmed * 13611981771bSAli Ahmed * @param[in] aResp Shared pointer for generating response message. 13621981771bSAli Ahmed * 13631981771bSAli Ahmed * @return None. 13641981771bSAli Ahmed */ 13651981771bSAli Ahmed inline void getTrustedModuleRequiredToBoot( 13661981771bSAli Ahmed const std::shared_ptr<bmcweb::AsyncResp>& aResp) 13671981771bSAli Ahmed { 13681981771bSAli Ahmed BMCWEB_LOG_DEBUG << "Get TPM required to boot."; 13691981771bSAli Ahmed 13701981771bSAli Ahmed crow::connections::systemBus->async_method_call( 13711981771bSAli Ahmed [aResp]( 13721981771bSAli Ahmed const boost::system::error_code ec, 13731981771bSAli Ahmed std::vector<std::pair< 13741981771bSAli Ahmed std::string, 13751981771bSAli Ahmed std::vector<std::pair<std::string, std::vector<std::string>>>>>& 13761981771bSAli Ahmed subtree) { 13771981771bSAli Ahmed if (ec) 13781981771bSAli Ahmed { 13791981771bSAli Ahmed BMCWEB_LOG_DEBUG 13801981771bSAli Ahmed << "DBUS response error on TPM.Policy GetSubTree" << ec; 13811981771bSAli Ahmed // This is an optional D-Bus object so just return if 13821981771bSAli Ahmed // error occurs 13831981771bSAli Ahmed return; 13841981771bSAli Ahmed } 13851981771bSAli Ahmed if (subtree.size() == 0) 13861981771bSAli Ahmed { 13871981771bSAli Ahmed // As noted above, this is an optional interface so just return 13881981771bSAli Ahmed // if there is no instance found 13891981771bSAli Ahmed return; 13901981771bSAli Ahmed } 13911981771bSAli Ahmed 13921981771bSAli Ahmed /* When there is more than one TPMEnable object... */ 13931981771bSAli Ahmed if (subtree.size() > 1) 13941981771bSAli Ahmed { 13951981771bSAli Ahmed BMCWEB_LOG_DEBUG 13961981771bSAli Ahmed << "DBUS response has more than 1 TPM Enable object:" 13971981771bSAli Ahmed << subtree.size(); 13981981771bSAli Ahmed // Throw an internal Error and return 13991981771bSAli Ahmed messages::internalError(aResp->res); 14001981771bSAli Ahmed return; 14011981771bSAli Ahmed } 14021981771bSAli Ahmed 14031981771bSAli Ahmed // Make sure the Dbus response map has a service and objectPath 14041981771bSAli Ahmed // field 14051981771bSAli Ahmed if (subtree[0].first.empty() || subtree[0].second.size() != 1) 14061981771bSAli Ahmed { 14071981771bSAli Ahmed BMCWEB_LOG_DEBUG << "TPM.Policy mapper error!"; 14081981771bSAli Ahmed messages::internalError(aResp->res); 14091981771bSAli Ahmed return; 14101981771bSAli Ahmed } 14111981771bSAli Ahmed 14121981771bSAli Ahmed const std::string& path = subtree[0].first; 14131981771bSAli Ahmed const std::string& serv = subtree[0].second.begin()->first; 14141981771bSAli Ahmed 14151981771bSAli Ahmed // Valid TPM Enable object found, now reading the current value 14161981771bSAli Ahmed crow::connections::systemBus->async_method_call( 14171981771bSAli Ahmed [aResp](const boost::system::error_code ec, 14181981771bSAli Ahmed std::variant<bool>& tpmRequired) { 14191981771bSAli Ahmed if (ec) 14201981771bSAli Ahmed { 14211981771bSAli Ahmed BMCWEB_LOG_DEBUG 14221981771bSAli Ahmed << "D-BUS response error on TPM.Policy Get" << ec; 14231981771bSAli Ahmed messages::internalError(aResp->res); 14241981771bSAli Ahmed return; 14251981771bSAli Ahmed } 14261981771bSAli Ahmed 14271981771bSAli Ahmed const bool* tpmRequiredVal = 14281981771bSAli Ahmed std::get_if<bool>(&tpmRequired); 14291981771bSAli Ahmed 14301981771bSAli Ahmed if (!tpmRequiredVal) 14311981771bSAli Ahmed { 14321981771bSAli Ahmed messages::internalError(aResp->res); 14331981771bSAli Ahmed return; 14341981771bSAli Ahmed } 14351981771bSAli Ahmed 14361981771bSAli Ahmed if (*tpmRequiredVal == true) 14371981771bSAli Ahmed { 14381981771bSAli Ahmed aResp->res 14391981771bSAli Ahmed .jsonValue["Boot"]["TrustedModuleRequiredToBoot"] = 14401981771bSAli Ahmed "Required"; 14411981771bSAli Ahmed } 14421981771bSAli Ahmed else 14431981771bSAli Ahmed { 14441981771bSAli Ahmed aResp->res 14451981771bSAli Ahmed .jsonValue["Boot"]["TrustedModuleRequiredToBoot"] = 14461981771bSAli Ahmed "Disabled"; 14471981771bSAli Ahmed } 14481981771bSAli Ahmed }, 14491981771bSAli Ahmed serv, path, "org.freedesktop.DBus.Properties", "Get", 14501981771bSAli Ahmed "xyz.openbmc_project.Control.TPM.Policy", "TPMEnable"); 14511981771bSAli Ahmed }, 14521981771bSAli Ahmed "xyz.openbmc_project.ObjectMapper", 14531981771bSAli Ahmed "/xyz/openbmc_project/object_mapper", 14541981771bSAli Ahmed "xyz.openbmc_project.ObjectMapper", "GetSubTree", "/", int32_t(0), 14551981771bSAli Ahmed std::array<const char*, 1>{"xyz.openbmc_project.Control.TPM.Policy"}); 14561981771bSAli Ahmed } 14571981771bSAli Ahmed 14581981771bSAli Ahmed /** 1459491d8ee7SSantosh Puranik * @brief Sets boot properties into DBUS object(s). 1460491d8ee7SSantosh Puranik * 1461491d8ee7SSantosh Puranik * @param[in] aResp Shared pointer for generating response message. 1462*cd9a4666SKonstantin Aladyshev * @param[in] overrideEnabled The source override "enable". 1463*cd9a4666SKonstantin Aladyshev * @param[in] bootObj Path to the DBUS object. 1464*cd9a4666SKonstantin Aladyshev * @param[in] bootType The boot type to set. 1465*cd9a4666SKonstantin Aladyshev * @return Integer error code. 1466*cd9a4666SKonstantin Aladyshev */ 1467*cd9a4666SKonstantin Aladyshev inline void setBootType(const std::shared_ptr<bmcweb::AsyncResp>& aResp, 1468*cd9a4666SKonstantin Aladyshev const bool overrideEnabled, const std::string& bootObj, 1469*cd9a4666SKonstantin Aladyshev const std::optional<std::string>& bootType) 1470*cd9a4666SKonstantin Aladyshev { 1471*cd9a4666SKonstantin Aladyshev std::string bootTypeStr = "xyz.openbmc_project.Control.Boot.Type.Types.EFI"; 1472*cd9a4666SKonstantin Aladyshev 1473*cd9a4666SKonstantin Aladyshev if (bootType && overrideEnabled) 1474*cd9a4666SKonstantin Aladyshev { 1475*cd9a4666SKonstantin Aladyshev // Source target specified 1476*cd9a4666SKonstantin Aladyshev BMCWEB_LOG_DEBUG << "Boot type: " << *bootType; 1477*cd9a4666SKonstantin Aladyshev // Figure out which DBUS interface and property to use 1478*cd9a4666SKonstantin Aladyshev if (*bootType == "Legacy") 1479*cd9a4666SKonstantin Aladyshev { 1480*cd9a4666SKonstantin Aladyshev bootTypeStr = "xyz.openbmc_project.Control.Boot.Type.Types.Legacy"; 1481*cd9a4666SKonstantin Aladyshev } 1482*cd9a4666SKonstantin Aladyshev else if (*bootType == "UEFI") 1483*cd9a4666SKonstantin Aladyshev { 1484*cd9a4666SKonstantin Aladyshev bootTypeStr = "xyz.openbmc_project.Control.Boot.Type.Types.EFI"; 1485*cd9a4666SKonstantin Aladyshev } 1486*cd9a4666SKonstantin Aladyshev else 1487*cd9a4666SKonstantin Aladyshev { 1488*cd9a4666SKonstantin Aladyshev BMCWEB_LOG_DEBUG << "Invalid property value for " 1489*cd9a4666SKonstantin Aladyshev "BootSourceOverrideMode: " 1490*cd9a4666SKonstantin Aladyshev << *bootType; 1491*cd9a4666SKonstantin Aladyshev messages::propertyValueNotInList(aResp->res, *bootType, 1492*cd9a4666SKonstantin Aladyshev "BootSourceOverrideMode"); 1493*cd9a4666SKonstantin Aladyshev return; 1494*cd9a4666SKonstantin Aladyshev } 1495*cd9a4666SKonstantin Aladyshev } 1496*cd9a4666SKonstantin Aladyshev 1497*cd9a4666SKonstantin Aladyshev // Act on validated parameters 1498*cd9a4666SKonstantin Aladyshev BMCWEB_LOG_DEBUG << "DBUS boot type: " << bootTypeStr; 1499*cd9a4666SKonstantin Aladyshev 1500*cd9a4666SKonstantin Aladyshev crow::connections::systemBus->async_method_call( 1501*cd9a4666SKonstantin Aladyshev [aResp, bootType](const boost::system::error_code ec) { 1502*cd9a4666SKonstantin Aladyshev if (ec) 1503*cd9a4666SKonstantin Aladyshev { 1504*cd9a4666SKonstantin Aladyshev if (!bootType) 1505*cd9a4666SKonstantin Aladyshev { 1506*cd9a4666SKonstantin Aladyshev // If bootType wasn't explicitly present in the incoming 1507*cd9a4666SKonstantin Aladyshev // message don't output error. The error could come from a 1508*cd9a4666SKonstantin Aladyshev // fact that the BootType interface may be not present in 1509*cd9a4666SKonstantin Aladyshev // the settings object. It could happen because this 1510*cd9a4666SKonstantin Aladyshev // interface is not relevant for some Host architectures 1511*cd9a4666SKonstantin Aladyshev // (for example POWER). 1512*cd9a4666SKonstantin Aladyshev return; 1513*cd9a4666SKonstantin Aladyshev } 1514*cd9a4666SKonstantin Aladyshev 1515*cd9a4666SKonstantin Aladyshev BMCWEB_LOG_DEBUG << "DBUS response error " << ec; 1516*cd9a4666SKonstantin Aladyshev if (ec.value() == boost::asio::error::host_unreachable) 1517*cd9a4666SKonstantin Aladyshev { 1518*cd9a4666SKonstantin Aladyshev messages::resourceNotFound(aResp->res, "Set", "BootType"); 1519*cd9a4666SKonstantin Aladyshev return; 1520*cd9a4666SKonstantin Aladyshev } 1521*cd9a4666SKonstantin Aladyshev messages::internalError(aResp->res); 1522*cd9a4666SKonstantin Aladyshev return; 1523*cd9a4666SKonstantin Aladyshev } 1524*cd9a4666SKonstantin Aladyshev BMCWEB_LOG_DEBUG << "Boot type update done."; 1525*cd9a4666SKonstantin Aladyshev }, 1526*cd9a4666SKonstantin Aladyshev "xyz.openbmc_project.Settings", bootObj, 1527*cd9a4666SKonstantin Aladyshev "org.freedesktop.DBus.Properties", "Set", 1528*cd9a4666SKonstantin Aladyshev "xyz.openbmc_project.Control.Boot.Type", "BootType", 1529*cd9a4666SKonstantin Aladyshev std::variant<std::string>(bootTypeStr)); 1530*cd9a4666SKonstantin Aladyshev } 1531*cd9a4666SKonstantin Aladyshev 1532*cd9a4666SKonstantin Aladyshev /** 1533*cd9a4666SKonstantin Aladyshev * @brief Sets boot properties into DBUS object(s). 1534*cd9a4666SKonstantin Aladyshev * 1535*cd9a4666SKonstantin Aladyshev * @param[in] aResp Shared pointer for generating response message. 1536*cd9a4666SKonstantin Aladyshev * @param[in] overrideEnabled The source override "enable". 1537*cd9a4666SKonstantin Aladyshev * @param[in] bootObj Path to the DBUS object. 1538491d8ee7SSantosh Puranik * @param[in] bootSource The boot source to set. 1539491d8ee7SSantosh Puranik * 1540265c1602SJohnathan Mantey * @return Integer error code. 1541491d8ee7SSantosh Puranik */ 1542*cd9a4666SKonstantin Aladyshev inline void setBootModeOrSource(const std::shared_ptr<bmcweb::AsyncResp>& aResp, 1543*cd9a4666SKonstantin Aladyshev const bool overrideEnabled, 1544*cd9a4666SKonstantin Aladyshev const std::string& bootObj, 1545*cd9a4666SKonstantin Aladyshev const std::optional<std::string>& bootSource) 1546491d8ee7SSantosh Puranik { 1547944ffaf9SJohnathan Mantey std::string bootSourceStr = 1548944ffaf9SJohnathan Mantey "xyz.openbmc_project.Control.Boot.Source.Sources.Default"; 1549944ffaf9SJohnathan Mantey std::string bootModeStr = 1550944ffaf9SJohnathan Mantey "xyz.openbmc_project.Control.Boot.Mode.Modes.Regular"; 1551944ffaf9SJohnathan Mantey 1552*cd9a4666SKonstantin Aladyshev if (bootSource && overrideEnabled) 1553491d8ee7SSantosh Puranik { 1554491d8ee7SSantosh Puranik // Source target specified 1555491d8ee7SSantosh Puranik BMCWEB_LOG_DEBUG << "Boot source: " << *bootSource; 1556491d8ee7SSantosh Puranik // Figure out which DBUS interface and property to use 1557944ffaf9SJohnathan Mantey if (assignBootParameters(aResp, *bootSource, bootSourceStr, 1558944ffaf9SJohnathan Mantey bootModeStr)) 1559491d8ee7SSantosh Puranik { 1560944ffaf9SJohnathan Mantey BMCWEB_LOG_DEBUG 1561944ffaf9SJohnathan Mantey << "Invalid property value for BootSourceOverrideTarget: " 1562491d8ee7SSantosh Puranik << *bootSource; 1563491d8ee7SSantosh Puranik messages::propertyValueNotInList(aResp->res, *bootSource, 1564491d8ee7SSantosh Puranik "BootSourceTargetOverride"); 1565491d8ee7SSantosh Puranik return; 1566491d8ee7SSantosh Puranik } 1567944ffaf9SJohnathan Mantey } 1568491d8ee7SSantosh Puranik 1569944ffaf9SJohnathan Mantey // Act on validated parameters 1570944ffaf9SJohnathan Mantey BMCWEB_LOG_DEBUG << "DBUS boot source: " << bootSourceStr; 1571944ffaf9SJohnathan Mantey BMCWEB_LOG_DEBUG << "DBUS boot mode: " << bootModeStr; 1572944ffaf9SJohnathan Mantey 1573491d8ee7SSantosh Puranik crow::connections::systemBus->async_method_call( 1574491d8ee7SSantosh Puranik [aResp](const boost::system::error_code ec) { 1575491d8ee7SSantosh Puranik if (ec) 1576491d8ee7SSantosh Puranik { 1577491d8ee7SSantosh Puranik BMCWEB_LOG_DEBUG << "DBUS response error " << ec; 1578491d8ee7SSantosh Puranik messages::internalError(aResp->res); 1579491d8ee7SSantosh Puranik return; 1580491d8ee7SSantosh Puranik } 1581491d8ee7SSantosh Puranik BMCWEB_LOG_DEBUG << "Boot source update done."; 1582491d8ee7SSantosh Puranik }, 1583491d8ee7SSantosh Puranik "xyz.openbmc_project.Settings", bootObj, 1584491d8ee7SSantosh Puranik "org.freedesktop.DBus.Properties", "Set", 1585491d8ee7SSantosh Puranik "xyz.openbmc_project.Control.Boot.Source", "BootSource", 1586491d8ee7SSantosh Puranik std::variant<std::string>(bootSourceStr)); 1587944ffaf9SJohnathan Mantey 1588491d8ee7SSantosh Puranik crow::connections::systemBus->async_method_call( 1589491d8ee7SSantosh Puranik [aResp](const boost::system::error_code ec) { 1590491d8ee7SSantosh Puranik if (ec) 1591491d8ee7SSantosh Puranik { 1592491d8ee7SSantosh Puranik BMCWEB_LOG_DEBUG << "DBUS response error " << ec; 1593491d8ee7SSantosh Puranik messages::internalError(aResp->res); 1594491d8ee7SSantosh Puranik return; 1595491d8ee7SSantosh Puranik } 1596491d8ee7SSantosh Puranik BMCWEB_LOG_DEBUG << "Boot mode update done."; 1597491d8ee7SSantosh Puranik }, 1598491d8ee7SSantosh Puranik "xyz.openbmc_project.Settings", bootObj, 1599491d8ee7SSantosh Puranik "org.freedesktop.DBus.Properties", "Set", 1600491d8ee7SSantosh Puranik "xyz.openbmc_project.Control.Boot.Mode", "BootMode", 1601491d8ee7SSantosh Puranik std::variant<std::string>(bootModeStr)); 1602*cd9a4666SKonstantin Aladyshev } 1603944ffaf9SJohnathan Mantey 1604*cd9a4666SKonstantin Aladyshev /** 1605*cd9a4666SKonstantin Aladyshev * @brief Sets "One time" enabled setting into DBUS object 1606*cd9a4666SKonstantin Aladyshev * 1607*cd9a4666SKonstantin Aladyshev * @param[in] aResp Shared pointer for generating response message. 1608*cd9a4666SKonstantin Aladyshev * @param[in] oneTime Enable property for one-time object 1609*cd9a4666SKonstantin Aladyshev * 1610*cd9a4666SKonstantin Aladyshev * @return Integer error code. 1611*cd9a4666SKonstantin Aladyshev */ 1612*cd9a4666SKonstantin Aladyshev inline void setOneTime(const std::shared_ptr<bmcweb::AsyncResp>& aResp, 1613*cd9a4666SKonstantin Aladyshev bool oneTime) 1614*cd9a4666SKonstantin Aladyshev { 1615491d8ee7SSantosh Puranik crow::connections::systemBus->async_method_call( 1616*cd9a4666SKonstantin Aladyshev [aResp{aResp}](const boost::system::error_code ec) { 1617491d8ee7SSantosh Puranik if (ec) 1618491d8ee7SSantosh Puranik { 1619491d8ee7SSantosh Puranik BMCWEB_LOG_DEBUG << "DBUS response error " << ec; 1620491d8ee7SSantosh Puranik messages::internalError(aResp->res); 1621491d8ee7SSantosh Puranik return; 1622491d8ee7SSantosh Puranik } 1623491d8ee7SSantosh Puranik BMCWEB_LOG_DEBUG << "Boot enable update done."; 1624491d8ee7SSantosh Puranik }, 1625491d8ee7SSantosh Puranik "xyz.openbmc_project.Settings", 1626491d8ee7SSantosh Puranik "/xyz/openbmc_project/control/host0/boot/one_time", 1627491d8ee7SSantosh Puranik "org.freedesktop.DBus.Properties", "Set", 1628491d8ee7SSantosh Puranik "xyz.openbmc_project.Object.Enable", "Enabled", 1629*cd9a4666SKonstantin Aladyshev std::variant<bool>(oneTime)); 1630491d8ee7SSantosh Puranik } 1631491d8ee7SSantosh Puranik 1632491d8ee7SSantosh Puranik /** 1633491d8ee7SSantosh Puranik * @brief Retrieves "One time" enabled setting over DBUS and calls function to 1634491d8ee7SSantosh Puranik * set boot source/boot mode properties. 1635491d8ee7SSantosh Puranik * 1636491d8ee7SSantosh Puranik * @param[in] aResp Shared pointer for generating response message. 1637491d8ee7SSantosh Puranik * @param[in] bootSource The boot source from incoming RF request. 1638*cd9a4666SKonstantin Aladyshev * @param[in] bootType The boot type from incoming RF request. 1639491d8ee7SSantosh Puranik * @param[in] bootEnable The boot override enable from incoming RF request. 1640491d8ee7SSantosh Puranik * 1641265c1602SJohnathan Mantey * @return Integer error code. 1642491d8ee7SSantosh Puranik */ 16438d1b46d7Szhanghch05 inline void 16448d1b46d7Szhanghch05 setBootSourceProperties(const std::shared_ptr<bmcweb::AsyncResp>& aResp, 1645491d8ee7SSantosh Puranik std::optional<std::string> bootSource, 1646*cd9a4666SKonstantin Aladyshev std::optional<std::string> bootType, 1647491d8ee7SSantosh Puranik std::optional<std::string> bootEnable) 1648491d8ee7SSantosh Puranik { 1649491d8ee7SSantosh Puranik BMCWEB_LOG_DEBUG << "Set boot information."; 1650491d8ee7SSantosh Puranik 1651491d8ee7SSantosh Puranik crow::connections::systemBus->async_method_call( 1652265c1602SJohnathan Mantey [aResp, bootSource{std::move(bootSource)}, 1653*cd9a4666SKonstantin Aladyshev bootType{std::move(bootType)}, 165419bd78d9SPatrick Williams bootEnable{std::move(bootEnable)}](const boost::system::error_code ec, 165519bd78d9SPatrick Williams const std::variant<bool>& oneTime) { 1656491d8ee7SSantosh Puranik if (ec) 1657491d8ee7SSantosh Puranik { 1658491d8ee7SSantosh Puranik BMCWEB_LOG_DEBUG << "DBUS response error " << ec; 1659491d8ee7SSantosh Puranik messages::internalError(aResp->res); 1660491d8ee7SSantosh Puranik return; 1661491d8ee7SSantosh Puranik } 1662491d8ee7SSantosh Puranik 1663491d8ee7SSantosh Puranik const bool* oneTimePtr = std::get_if<bool>(&oneTime); 1664491d8ee7SSantosh Puranik 1665491d8ee7SSantosh Puranik if (!oneTimePtr) 1666491d8ee7SSantosh Puranik { 1667491d8ee7SSantosh Puranik messages::internalError(aResp->res); 1668491d8ee7SSantosh Puranik return; 1669491d8ee7SSantosh Puranik } 1670491d8ee7SSantosh Puranik 1671491d8ee7SSantosh Puranik BMCWEB_LOG_DEBUG << "Got one time: " << *oneTimePtr; 1672491d8ee7SSantosh Puranik 1673*cd9a4666SKonstantin Aladyshev bool oneTimeSetting = *oneTimePtr; 1674*cd9a4666SKonstantin Aladyshev bool overrideEnabled = true; 1675*cd9a4666SKonstantin Aladyshev 1676*cd9a4666SKonstantin Aladyshev // Validate incoming parameters 1677*cd9a4666SKonstantin Aladyshev if (bootEnable) 1678*cd9a4666SKonstantin Aladyshev { 1679*cd9a4666SKonstantin Aladyshev if (*bootEnable == "Once") 1680*cd9a4666SKonstantin Aladyshev { 1681*cd9a4666SKonstantin Aladyshev oneTimeSetting = true; 1682*cd9a4666SKonstantin Aladyshev } 1683*cd9a4666SKonstantin Aladyshev else if (*bootEnable == "Continuous") 1684*cd9a4666SKonstantin Aladyshev { 1685*cd9a4666SKonstantin Aladyshev oneTimeSetting = false; 1686*cd9a4666SKonstantin Aladyshev } 1687*cd9a4666SKonstantin Aladyshev else if (*bootEnable == "Disabled") 1688*cd9a4666SKonstantin Aladyshev { 1689*cd9a4666SKonstantin Aladyshev BMCWEB_LOG_DEBUG << "Boot source override will be disabled"; 1690*cd9a4666SKonstantin Aladyshev oneTimeSetting = false; 1691*cd9a4666SKonstantin Aladyshev overrideEnabled = false; 1692*cd9a4666SKonstantin Aladyshev } 1693*cd9a4666SKonstantin Aladyshev else 1694*cd9a4666SKonstantin Aladyshev { 1695*cd9a4666SKonstantin Aladyshev BMCWEB_LOG_DEBUG << "Unsupported value for " 1696*cd9a4666SKonstantin Aladyshev "BootSourceOverrideEnabled: " 1697*cd9a4666SKonstantin Aladyshev << *bootEnable; 1698*cd9a4666SKonstantin Aladyshev messages::propertyValueNotInList( 1699*cd9a4666SKonstantin Aladyshev aResp->res, *bootEnable, "BootSourceOverrideEnabled"); 1700*cd9a4666SKonstantin Aladyshev return; 1701*cd9a4666SKonstantin Aladyshev } 1702*cd9a4666SKonstantin Aladyshev } 1703*cd9a4666SKonstantin Aladyshev 1704*cd9a4666SKonstantin Aladyshev std::string bootObj = "/xyz/openbmc_project/control/host0/boot"; 1705*cd9a4666SKonstantin Aladyshev if (oneTimeSetting) 1706*cd9a4666SKonstantin Aladyshev { 1707*cd9a4666SKonstantin Aladyshev bootObj += "/one_time"; 1708*cd9a4666SKonstantin Aladyshev } 1709*cd9a4666SKonstantin Aladyshev 1710*cd9a4666SKonstantin Aladyshev setBootModeOrSource(aResp, overrideEnabled, bootObj, bootSource); 1711*cd9a4666SKonstantin Aladyshev setBootType(aResp, overrideEnabled, bootObj, bootType); 1712*cd9a4666SKonstantin Aladyshev setOneTime(aResp, oneTimeSetting); 1713491d8ee7SSantosh Puranik }, 1714491d8ee7SSantosh Puranik "xyz.openbmc_project.Settings", 1715491d8ee7SSantosh Puranik "/xyz/openbmc_project/control/host0/boot/one_time", 1716491d8ee7SSantosh Puranik "org.freedesktop.DBus.Properties", "Get", 1717491d8ee7SSantosh Puranik "xyz.openbmc_project.Object.Enable", "Enabled"); 1718491d8ee7SSantosh Puranik } 1719491d8ee7SSantosh Puranik 1720c6a620f2SGeorge Liu /** 172198e386ecSGunnar Mills * @brief Sets AssetTag 172298e386ecSGunnar Mills * 172398e386ecSGunnar Mills * @param[in] aResp Shared pointer for generating response message. 172498e386ecSGunnar Mills * @param[in] assetTag "AssetTag" from request. 172598e386ecSGunnar Mills * 172698e386ecSGunnar Mills * @return None. 172798e386ecSGunnar Mills */ 17288d1b46d7Szhanghch05 inline void setAssetTag(const std::shared_ptr<bmcweb::AsyncResp>& aResp, 172998e386ecSGunnar Mills const std::string& assetTag) 173098e386ecSGunnar Mills { 173198e386ecSGunnar Mills crow::connections::systemBus->async_method_call( 173298e386ecSGunnar Mills [aResp, assetTag]( 173398e386ecSGunnar Mills const boost::system::error_code ec, 173498e386ecSGunnar Mills const std::vector<std::pair< 173598e386ecSGunnar Mills std::string, 173698e386ecSGunnar Mills std::vector<std::pair<std::string, std::vector<std::string>>>>>& 173798e386ecSGunnar Mills subtree) { 173898e386ecSGunnar Mills if (ec) 173998e386ecSGunnar Mills { 174098e386ecSGunnar Mills BMCWEB_LOG_DEBUG << "D-Bus response error on GetSubTree " << ec; 174198e386ecSGunnar Mills messages::internalError(aResp->res); 174298e386ecSGunnar Mills return; 174398e386ecSGunnar Mills } 174498e386ecSGunnar Mills if (subtree.size() == 0) 174598e386ecSGunnar Mills { 174698e386ecSGunnar Mills BMCWEB_LOG_DEBUG << "Can't find system D-Bus object!"; 174798e386ecSGunnar Mills messages::internalError(aResp->res); 174898e386ecSGunnar Mills return; 174998e386ecSGunnar Mills } 175098e386ecSGunnar Mills // Assume only 1 system D-Bus object 175198e386ecSGunnar Mills // Throw an error if there is more than 1 175298e386ecSGunnar Mills if (subtree.size() > 1) 175398e386ecSGunnar Mills { 175498e386ecSGunnar Mills BMCWEB_LOG_DEBUG << "Found more than 1 system D-Bus object!"; 175598e386ecSGunnar Mills messages::internalError(aResp->res); 175698e386ecSGunnar Mills return; 175798e386ecSGunnar Mills } 175898e386ecSGunnar Mills if (subtree[0].first.empty() || subtree[0].second.size() != 1) 175998e386ecSGunnar Mills { 176098e386ecSGunnar Mills BMCWEB_LOG_DEBUG << "Asset Tag Set mapper error!"; 176198e386ecSGunnar Mills messages::internalError(aResp->res); 176298e386ecSGunnar Mills return; 176398e386ecSGunnar Mills } 176498e386ecSGunnar Mills 176598e386ecSGunnar Mills const std::string& path = subtree[0].first; 176698e386ecSGunnar Mills const std::string& service = subtree[0].second.begin()->first; 176798e386ecSGunnar Mills 176898e386ecSGunnar Mills if (service.empty()) 176998e386ecSGunnar Mills { 177098e386ecSGunnar Mills BMCWEB_LOG_DEBUG << "Asset Tag Set service mapper error!"; 177198e386ecSGunnar Mills messages::internalError(aResp->res); 177298e386ecSGunnar Mills return; 177398e386ecSGunnar Mills } 177498e386ecSGunnar Mills 177598e386ecSGunnar Mills crow::connections::systemBus->async_method_call( 177698e386ecSGunnar Mills [aResp](const boost::system::error_code ec2) { 177798e386ecSGunnar Mills if (ec2) 177898e386ecSGunnar Mills { 177998e386ecSGunnar Mills BMCWEB_LOG_DEBUG 178098e386ecSGunnar Mills << "D-Bus response error on AssetTag Set " << ec2; 178198e386ecSGunnar Mills messages::internalError(aResp->res); 178298e386ecSGunnar Mills return; 178398e386ecSGunnar Mills } 178498e386ecSGunnar Mills }, 178598e386ecSGunnar Mills service, path, "org.freedesktop.DBus.Properties", "Set", 178698e386ecSGunnar Mills "xyz.openbmc_project.Inventory.Decorator.AssetTag", "AssetTag", 178798e386ecSGunnar Mills std::variant<std::string>(assetTag)); 178898e386ecSGunnar Mills }, 178998e386ecSGunnar Mills "xyz.openbmc_project.ObjectMapper", 179098e386ecSGunnar Mills "/xyz/openbmc_project/object_mapper", 179198e386ecSGunnar Mills "xyz.openbmc_project.ObjectMapper", "GetSubTree", 179298e386ecSGunnar Mills "/xyz/openbmc_project/inventory", int32_t(0), 179398e386ecSGunnar Mills std::array<const char*, 1>{ 179498e386ecSGunnar Mills "xyz.openbmc_project.Inventory.Item.System"}); 179598e386ecSGunnar Mills } 179698e386ecSGunnar Mills 179798e386ecSGunnar Mills /** 179869f35306SGunnar Mills * @brief Sets automaticRetry (Auto Reboot) 179969f35306SGunnar Mills * 180069f35306SGunnar Mills * @param[in] aResp Shared pointer for generating response message. 180169f35306SGunnar Mills * @param[in] automaticRetryConfig "AutomaticRetryConfig" from request. 180269f35306SGunnar Mills * 180369f35306SGunnar Mills * @return None. 180469f35306SGunnar Mills */ 18058d1b46d7Szhanghch05 inline void setAutomaticRetry(const std::shared_ptr<bmcweb::AsyncResp>& aResp, 1806f23b7296SEd Tanous const std::string& automaticRetryConfig) 180769f35306SGunnar Mills { 180869f35306SGunnar Mills BMCWEB_LOG_DEBUG << "Set Automatic Retry."; 180969f35306SGunnar Mills 181069f35306SGunnar Mills // OpenBMC only supports "Disabled" and "RetryAttempts". 181169f35306SGunnar Mills bool autoRebootEnabled; 181269f35306SGunnar Mills 181369f35306SGunnar Mills if (automaticRetryConfig == "Disabled") 181469f35306SGunnar Mills { 181569f35306SGunnar Mills autoRebootEnabled = false; 181669f35306SGunnar Mills } 181769f35306SGunnar Mills else if (automaticRetryConfig == "RetryAttempts") 181869f35306SGunnar Mills { 181969f35306SGunnar Mills autoRebootEnabled = true; 182069f35306SGunnar Mills } 182169f35306SGunnar Mills else 182269f35306SGunnar Mills { 182369f35306SGunnar Mills BMCWEB_LOG_DEBUG << "Invalid property value for " 182469f35306SGunnar Mills "AutomaticRetryConfig: " 182569f35306SGunnar Mills << automaticRetryConfig; 182669f35306SGunnar Mills messages::propertyValueNotInList(aResp->res, automaticRetryConfig, 182769f35306SGunnar Mills "AutomaticRetryConfig"); 182869f35306SGunnar Mills return; 182969f35306SGunnar Mills } 183069f35306SGunnar Mills 183169f35306SGunnar Mills crow::connections::systemBus->async_method_call( 183269f35306SGunnar Mills [aResp](const boost::system::error_code ec) { 183369f35306SGunnar Mills if (ec) 183469f35306SGunnar Mills { 183569f35306SGunnar Mills messages::internalError(aResp->res); 183669f35306SGunnar Mills return; 183769f35306SGunnar Mills } 183869f35306SGunnar Mills }, 183969f35306SGunnar Mills "xyz.openbmc_project.Settings", 184069f35306SGunnar Mills "/xyz/openbmc_project/control/host0/auto_reboot", 184169f35306SGunnar Mills "org.freedesktop.DBus.Properties", "Set", 184269f35306SGunnar Mills "xyz.openbmc_project.Control.Boot.RebootPolicy", "AutoReboot", 184369f35306SGunnar Mills std::variant<bool>(autoRebootEnabled)); 184469f35306SGunnar Mills } 184569f35306SGunnar Mills 184669f35306SGunnar Mills /** 1847c6a620f2SGeorge Liu * @brief Sets power restore policy properties. 1848c6a620f2SGeorge Liu * 1849c6a620f2SGeorge Liu * @param[in] aResp Shared pointer for generating response message. 1850c6a620f2SGeorge Liu * @param[in] policy power restore policy properties from request. 1851c6a620f2SGeorge Liu * 1852c6a620f2SGeorge Liu * @return None. 1853c6a620f2SGeorge Liu */ 18548d1b46d7Szhanghch05 inline void 18558d1b46d7Szhanghch05 setPowerRestorePolicy(const std::shared_ptr<bmcweb::AsyncResp>& aResp, 18564e69c904SGunnar Mills const std::string& policy) 1857c6a620f2SGeorge Liu { 1858c6a620f2SGeorge Liu BMCWEB_LOG_DEBUG << "Set power restore policy."; 1859c6a620f2SGeorge Liu 1860c6a620f2SGeorge Liu const boost::container::flat_map<std::string, std::string> policyMaps = { 1861c6a620f2SGeorge Liu {"AlwaysOn", "xyz.openbmc_project.Control.Power.RestorePolicy.Policy." 1862c6a620f2SGeorge Liu "AlwaysOn"}, 1863c6a620f2SGeorge Liu {"AlwaysOff", "xyz.openbmc_project.Control.Power.RestorePolicy.Policy." 1864c6a620f2SGeorge Liu "AlwaysOff"}, 1865c6a620f2SGeorge Liu {"LastState", "xyz.openbmc_project.Control.Power.RestorePolicy.Policy." 186637ec9072SGunnar Mills "Restore"}}; 1867c6a620f2SGeorge Liu 1868c6a620f2SGeorge Liu std::string powerRestorPolicy; 1869c6a620f2SGeorge Liu 18704e69c904SGunnar Mills auto policyMapsIt = policyMaps.find(policy); 1871c6a620f2SGeorge Liu if (policyMapsIt == policyMaps.end()) 1872c6a620f2SGeorge Liu { 18734e69c904SGunnar Mills messages::propertyValueNotInList(aResp->res, policy, 18744e69c904SGunnar Mills "PowerRestorePolicy"); 1875c6a620f2SGeorge Liu return; 1876c6a620f2SGeorge Liu } 1877c6a620f2SGeorge Liu 1878c6a620f2SGeorge Liu powerRestorPolicy = policyMapsIt->second; 1879c6a620f2SGeorge Liu 1880c6a620f2SGeorge Liu crow::connections::systemBus->async_method_call( 1881c6a620f2SGeorge Liu [aResp](const boost::system::error_code ec) { 1882c6a620f2SGeorge Liu if (ec) 1883c6a620f2SGeorge Liu { 1884c6a620f2SGeorge Liu messages::internalError(aResp->res); 1885c6a620f2SGeorge Liu return; 1886c6a620f2SGeorge Liu } 1887c6a620f2SGeorge Liu }, 1888c6a620f2SGeorge Liu "xyz.openbmc_project.Settings", 1889c6a620f2SGeorge Liu "/xyz/openbmc_project/control/host0/power_restore_policy", 1890c6a620f2SGeorge Liu "org.freedesktop.DBus.Properties", "Set", 1891c6a620f2SGeorge Liu "xyz.openbmc_project.Control.Power.RestorePolicy", "PowerRestorePolicy", 1892c6a620f2SGeorge Liu std::variant<std::string>(powerRestorPolicy)); 1893c6a620f2SGeorge Liu } 1894c6a620f2SGeorge Liu 1895a6349918SAppaRao Puli #ifdef BMCWEB_ENABLE_REDFISH_PROVISIONING_FEATURE 1896a6349918SAppaRao Puli /** 1897a6349918SAppaRao Puli * @brief Retrieves provisioning status 1898a6349918SAppaRao Puli * 1899a6349918SAppaRao Puli * @param[in] aResp Shared pointer for completing asynchronous calls. 1900a6349918SAppaRao Puli * 1901a6349918SAppaRao Puli * @return None. 1902a6349918SAppaRao Puli */ 19038d1b46d7Szhanghch05 inline void getProvisioningStatus(std::shared_ptr<bmcweb::AsyncResp> aResp) 1904a6349918SAppaRao Puli { 1905a6349918SAppaRao Puli BMCWEB_LOG_DEBUG << "Get OEM information."; 1906a6349918SAppaRao Puli crow::connections::systemBus->async_method_call( 1907a6349918SAppaRao Puli [aResp](const boost::system::error_code ec, 19081214b7e7SGunnar Mills const std::vector<std::pair<std::string, VariantType>>& 19091214b7e7SGunnar Mills propertiesList) { 1910b99fb1a9SAppaRao Puli nlohmann::json& oemPFR = 1911b99fb1a9SAppaRao Puli aResp->res.jsonValue["Oem"]["OpenBmc"]["FirmwareProvisioning"]; 191250626f4fSJames Feist aResp->res.jsonValue["Oem"]["OpenBmc"]["@odata.type"] = 191350626f4fSJames Feist "#OemComputerSystem.OpenBmc"; 191450626f4fSJames Feist oemPFR["@odata.type"] = "#OemComputerSystem.FirmwareProvisioning"; 191550626f4fSJames Feist 1916a6349918SAppaRao Puli if (ec) 1917a6349918SAppaRao Puli { 1918a6349918SAppaRao Puli BMCWEB_LOG_DEBUG << "DBUS response error " << ec; 1919b99fb1a9SAppaRao Puli // not an error, don't have to have the interface 1920b99fb1a9SAppaRao Puli oemPFR["ProvisioningStatus"] = "NotProvisioned"; 1921a6349918SAppaRao Puli return; 1922a6349918SAppaRao Puli } 1923a6349918SAppaRao Puli 1924a6349918SAppaRao Puli const bool* provState = nullptr; 1925a6349918SAppaRao Puli const bool* lockState = nullptr; 1926a6349918SAppaRao Puli for (const std::pair<std::string, VariantType>& property : 1927a6349918SAppaRao Puli propertiesList) 1928a6349918SAppaRao Puli { 1929a6349918SAppaRao Puli if (property.first == "UfmProvisioned") 1930a6349918SAppaRao Puli { 1931a6349918SAppaRao Puli provState = std::get_if<bool>(&property.second); 1932a6349918SAppaRao Puli } 1933a6349918SAppaRao Puli else if (property.first == "UfmLocked") 1934a6349918SAppaRao Puli { 1935a6349918SAppaRao Puli lockState = std::get_if<bool>(&property.second); 1936a6349918SAppaRao Puli } 1937a6349918SAppaRao Puli } 1938a6349918SAppaRao Puli 1939a6349918SAppaRao Puli if ((provState == nullptr) || (lockState == nullptr)) 1940a6349918SAppaRao Puli { 1941a6349918SAppaRao Puli BMCWEB_LOG_DEBUG << "Unable to get PFR attributes."; 1942a6349918SAppaRao Puli messages::internalError(aResp->res); 1943a6349918SAppaRao Puli return; 1944a6349918SAppaRao Puli } 1945a6349918SAppaRao Puli 1946a6349918SAppaRao Puli if (*provState == true) 1947a6349918SAppaRao Puli { 1948a6349918SAppaRao Puli if (*lockState == true) 1949a6349918SAppaRao Puli { 1950a6349918SAppaRao Puli oemPFR["ProvisioningStatus"] = "ProvisionedAndLocked"; 1951a6349918SAppaRao Puli } 1952a6349918SAppaRao Puli else 1953a6349918SAppaRao Puli { 1954a6349918SAppaRao Puli oemPFR["ProvisioningStatus"] = "ProvisionedButNotLocked"; 1955a6349918SAppaRao Puli } 1956a6349918SAppaRao Puli } 1957a6349918SAppaRao Puli else 1958a6349918SAppaRao Puli { 1959a6349918SAppaRao Puli oemPFR["ProvisioningStatus"] = "NotProvisioned"; 1960a6349918SAppaRao Puli } 1961a6349918SAppaRao Puli }, 1962a6349918SAppaRao Puli "xyz.openbmc_project.PFR.Manager", "/xyz/openbmc_project/pfr", 1963a6349918SAppaRao Puli "org.freedesktop.DBus.Properties", "GetAll", 1964a6349918SAppaRao Puli "xyz.openbmc_project.PFR.Attributes"); 1965a6349918SAppaRao Puli } 1966a6349918SAppaRao Puli #endif 1967a6349918SAppaRao Puli 1968491d8ee7SSantosh Puranik /** 19693a2d0424SChris Cain * @brief Translate the PowerMode to a response message. 19703a2d0424SChris Cain * 19713a2d0424SChris Cain * @param[in] aResp Shared pointer for generating response message. 19723a2d0424SChris Cain * @param[in] modeValue PowerMode value to be translated 19733a2d0424SChris Cain * 19743a2d0424SChris Cain * @return None. 19753a2d0424SChris Cain */ 19763a2d0424SChris Cain inline void translatePowerMode(const std::shared_ptr<bmcweb::AsyncResp>& aResp, 19773a2d0424SChris Cain const std::string& modeValue) 19783a2d0424SChris Cain { 19793a2d0424SChris Cain std::string modeString; 19803a2d0424SChris Cain 19813a2d0424SChris Cain if (modeValue == "xyz.openbmc_project.Control.Power.Mode." 19823a2d0424SChris Cain "PowerMode.Static") 19833a2d0424SChris Cain { 19843a2d0424SChris Cain aResp->res.jsonValue["PowerMode"] = "Static"; 19853a2d0424SChris Cain } 19863a2d0424SChris Cain else if (modeValue == "xyz.openbmc_project.Control.Power.Mode." 19873a2d0424SChris Cain "PowerMode.MaximumPerformance") 19883a2d0424SChris Cain { 19893a2d0424SChris Cain aResp->res.jsonValue["PowerMode"] = "MaximumPerformance"; 19903a2d0424SChris Cain } 19913a2d0424SChris Cain else if (modeValue == "xyz.openbmc_project.Control.Power.Mode." 19923a2d0424SChris Cain "PowerMode.PowerSaving") 19933a2d0424SChris Cain { 19943a2d0424SChris Cain aResp->res.jsonValue["PowerMode"] = "PowerSaving"; 19953a2d0424SChris Cain } 19963a2d0424SChris Cain else if (modeValue == "xyz.openbmc_project.Control.Power.Mode." 19973a2d0424SChris Cain "PowerMode.OEM") 19983a2d0424SChris Cain { 19993a2d0424SChris Cain aResp->res.jsonValue["PowerMode"] = "OEM"; 20003a2d0424SChris Cain } 20013a2d0424SChris Cain else 20023a2d0424SChris Cain { 20033a2d0424SChris Cain // Any other values would be invalid 20043a2d0424SChris Cain BMCWEB_LOG_DEBUG << "PowerMode value was not valid: " << modeValue; 20053a2d0424SChris Cain messages::internalError(aResp->res); 20063a2d0424SChris Cain } 20073a2d0424SChris Cain } 20083a2d0424SChris Cain 20093a2d0424SChris Cain /** 20103a2d0424SChris Cain * @brief Retrieves system power mode 20113a2d0424SChris Cain * 20123a2d0424SChris Cain * @param[in] aResp Shared pointer for generating response message. 20133a2d0424SChris Cain * 20143a2d0424SChris Cain * @return None. 20153a2d0424SChris Cain */ 20163a2d0424SChris Cain inline void getPowerMode(const std::shared_ptr<bmcweb::AsyncResp>& aResp) 20173a2d0424SChris Cain { 20183a2d0424SChris Cain BMCWEB_LOG_DEBUG << "Get power mode."; 20193a2d0424SChris Cain 20203a2d0424SChris Cain // Get Power Mode object path: 20213a2d0424SChris Cain crow::connections::systemBus->async_method_call( 20223a2d0424SChris Cain [aResp]( 20233a2d0424SChris Cain const boost::system::error_code ec, 20243a2d0424SChris Cain const std::vector<std::pair< 20253a2d0424SChris Cain std::string, 20263a2d0424SChris Cain std::vector<std::pair<std::string, std::vector<std::string>>>>>& 20273a2d0424SChris Cain subtree) { 20283a2d0424SChris Cain if (ec) 20293a2d0424SChris Cain { 20303a2d0424SChris Cain BMCWEB_LOG_DEBUG 20313a2d0424SChris Cain << "DBUS response error on Power.Mode GetSubTree " << ec; 20323a2d0424SChris Cain // This is an optional D-Bus object so just return if 20333a2d0424SChris Cain // error occurs 20343a2d0424SChris Cain return; 20353a2d0424SChris Cain } 20363a2d0424SChris Cain if (subtree.empty()) 20373a2d0424SChris Cain { 20383a2d0424SChris Cain // As noted above, this is an optional interface so just return 20393a2d0424SChris Cain // if there is no instance found 20403a2d0424SChris Cain return; 20413a2d0424SChris Cain } 20423a2d0424SChris Cain if (subtree.size() > 1) 20433a2d0424SChris Cain { 20443a2d0424SChris Cain // More then one PowerMode object is not supported and is an 20453a2d0424SChris Cain // error 20463a2d0424SChris Cain BMCWEB_LOG_DEBUG 20473a2d0424SChris Cain << "Found more than 1 system D-Bus Power.Mode objects: " 20483a2d0424SChris Cain << subtree.size(); 20493a2d0424SChris Cain messages::internalError(aResp->res); 20503a2d0424SChris Cain return; 20513a2d0424SChris Cain } 20523a2d0424SChris Cain if ((subtree[0].first.empty()) || (subtree[0].second.size() != 1)) 20533a2d0424SChris Cain { 20543a2d0424SChris Cain BMCWEB_LOG_DEBUG << "Power.Mode mapper error!"; 20553a2d0424SChris Cain messages::internalError(aResp->res); 20563a2d0424SChris Cain return; 20573a2d0424SChris Cain } 20583a2d0424SChris Cain const std::string& path = subtree[0].first; 20593a2d0424SChris Cain const std::string& service = subtree[0].second.begin()->first; 20603a2d0424SChris Cain if (service.empty()) 20613a2d0424SChris Cain { 20623a2d0424SChris Cain BMCWEB_LOG_DEBUG << "Power.Mode service mapper error!"; 20633a2d0424SChris Cain messages::internalError(aResp->res); 20643a2d0424SChris Cain return; 20653a2d0424SChris Cain } 20663a2d0424SChris Cain // Valid Power Mode object found, now read the current value 20673a2d0424SChris Cain crow::connections::systemBus->async_method_call( 20683a2d0424SChris Cain [aResp](const boost::system::error_code ec, 20693a2d0424SChris Cain const std::variant<std::string>& pmode) { 20703a2d0424SChris Cain if (ec) 20713a2d0424SChris Cain { 20723a2d0424SChris Cain BMCWEB_LOG_DEBUG 20733a2d0424SChris Cain << "DBUS response error on PowerMode Get: " << ec; 20743a2d0424SChris Cain messages::internalError(aResp->res); 20753a2d0424SChris Cain return; 20763a2d0424SChris Cain } 20773a2d0424SChris Cain 20783a2d0424SChris Cain const std::string* s = std::get_if<std::string>(&pmode); 20793a2d0424SChris Cain if (s == nullptr) 20803a2d0424SChris Cain { 20813a2d0424SChris Cain BMCWEB_LOG_DEBUG << "Unable to get PowerMode value"; 20823a2d0424SChris Cain messages::internalError(aResp->res); 20833a2d0424SChris Cain return; 20843a2d0424SChris Cain } 20853a2d0424SChris Cain 20863a2d0424SChris Cain aResp->res.jsonValue["PowerMode@Redfish.AllowableValues"] = 20873a2d0424SChris Cain {"Static", "MaximumPerformance", "PowerSaving"}; 20883a2d0424SChris Cain 20893a2d0424SChris Cain BMCWEB_LOG_DEBUG << "Current power mode: " << *s; 20903a2d0424SChris Cain translatePowerMode(aResp, *s); 20913a2d0424SChris Cain }, 20923a2d0424SChris Cain service, path, "org.freedesktop.DBus.Properties", "Get", 20933a2d0424SChris Cain "xyz.openbmc_project.Control.Power.Mode", "PowerMode"); 20943a2d0424SChris Cain }, 20953a2d0424SChris Cain "xyz.openbmc_project.ObjectMapper", 20963a2d0424SChris Cain "/xyz/openbmc_project/object_mapper", 20973a2d0424SChris Cain "xyz.openbmc_project.ObjectMapper", "GetSubTree", "/", int32_t(0), 20983a2d0424SChris Cain std::array<const char*, 1>{"xyz.openbmc_project.Control.Power.Mode"}); 20993a2d0424SChris Cain } 21003a2d0424SChris Cain 21013a2d0424SChris Cain /** 21023a2d0424SChris Cain * @brief Validate the specified mode is valid and return the PowerMode 21033a2d0424SChris Cain * name associated with that string 21043a2d0424SChris Cain * 21053a2d0424SChris Cain * @param[in] aResp Shared pointer for generating response message. 21063a2d0424SChris Cain * @param[in] modeString String representing the desired PowerMode 21073a2d0424SChris Cain * 21083a2d0424SChris Cain * @return PowerMode value or empty string if mode is not valid 21093a2d0424SChris Cain */ 21103a2d0424SChris Cain inline std::string 21113a2d0424SChris Cain validatePowerMode(const std::shared_ptr<bmcweb::AsyncResp>& aResp, 21123a2d0424SChris Cain const std::string& modeString) 21133a2d0424SChris Cain { 21143a2d0424SChris Cain std::string mode; 21153a2d0424SChris Cain 21163a2d0424SChris Cain if (modeString == "Static") 21173a2d0424SChris Cain { 21183a2d0424SChris Cain mode = "xyz.openbmc_project.Control.Power.Mode.PowerMode.Static"; 21193a2d0424SChris Cain } 21203a2d0424SChris Cain else if (modeString == "MaximumPerformance") 21213a2d0424SChris Cain { 21223a2d0424SChris Cain mode = "xyz.openbmc_project.Control.Power.Mode.PowerMode." 21233a2d0424SChris Cain "MaximumPerformance"; 21243a2d0424SChris Cain } 21253a2d0424SChris Cain else if (modeString == "PowerSaving") 21263a2d0424SChris Cain { 21273a2d0424SChris Cain mode = "xyz.openbmc_project.Control.Power.Mode.PowerMode.PowerSaving"; 21283a2d0424SChris Cain } 21293a2d0424SChris Cain else 21303a2d0424SChris Cain { 21313a2d0424SChris Cain messages::propertyValueNotInList(aResp->res, modeString, "PowerMode"); 21323a2d0424SChris Cain } 21333a2d0424SChris Cain return mode; 21343a2d0424SChris Cain } 21353a2d0424SChris Cain 21363a2d0424SChris Cain /** 21373a2d0424SChris Cain * @brief Sets system power mode. 21383a2d0424SChris Cain * 21393a2d0424SChris Cain * @param[in] aResp Shared pointer for generating response message. 21403a2d0424SChris Cain * @param[in] pmode System power mode from request. 21413a2d0424SChris Cain * 21423a2d0424SChris Cain * @return None. 21433a2d0424SChris Cain */ 21443a2d0424SChris Cain inline void setPowerMode(const std::shared_ptr<bmcweb::AsyncResp>& aResp, 21453a2d0424SChris Cain const std::string& pmode) 21463a2d0424SChris Cain { 21473a2d0424SChris Cain BMCWEB_LOG_DEBUG << "Set power mode."; 21483a2d0424SChris Cain 21493a2d0424SChris Cain std::string powerMode = validatePowerMode(aResp, pmode); 21503a2d0424SChris Cain if (powerMode.empty()) 21513a2d0424SChris Cain { 21523a2d0424SChris Cain return; 21533a2d0424SChris Cain } 21543a2d0424SChris Cain 21553a2d0424SChris Cain // Get Power Mode object path: 21563a2d0424SChris Cain crow::connections::systemBus->async_method_call( 21573a2d0424SChris Cain [aResp, powerMode]( 21583a2d0424SChris Cain const boost::system::error_code ec, 21593a2d0424SChris Cain const std::vector<std::pair< 21603a2d0424SChris Cain std::string, 21613a2d0424SChris Cain std::vector<std::pair<std::string, std::vector<std::string>>>>>& 21623a2d0424SChris Cain subtree) { 21633a2d0424SChris Cain if (ec) 21643a2d0424SChris Cain { 21653a2d0424SChris Cain BMCWEB_LOG_DEBUG 21663a2d0424SChris Cain << "DBUS response error on Power.Mode GetSubTree " << ec; 21673a2d0424SChris Cain // This is an optional D-Bus object, but user attempted to patch 21683a2d0424SChris Cain messages::internalError(aResp->res); 21693a2d0424SChris Cain return; 21703a2d0424SChris Cain } 21713a2d0424SChris Cain if (subtree.empty()) 21723a2d0424SChris Cain { 21733a2d0424SChris Cain // This is an optional D-Bus object, but user attempted to patch 21743a2d0424SChris Cain messages::resourceNotFound(aResp->res, "ComputerSystem", 21753a2d0424SChris Cain "PowerMode"); 21763a2d0424SChris Cain return; 21773a2d0424SChris Cain } 21783a2d0424SChris Cain if (subtree.size() > 1) 21793a2d0424SChris Cain { 21803a2d0424SChris Cain // More then one PowerMode object is not supported and is an 21813a2d0424SChris Cain // error 21823a2d0424SChris Cain BMCWEB_LOG_DEBUG 21833a2d0424SChris Cain << "Found more than 1 system D-Bus Power.Mode objects: " 21843a2d0424SChris Cain << subtree.size(); 21853a2d0424SChris Cain messages::internalError(aResp->res); 21863a2d0424SChris Cain return; 21873a2d0424SChris Cain } 21883a2d0424SChris Cain if ((subtree[0].first.empty()) || (subtree[0].second.size() != 1)) 21893a2d0424SChris Cain { 21903a2d0424SChris Cain BMCWEB_LOG_DEBUG << "Power.Mode mapper error!"; 21913a2d0424SChris Cain messages::internalError(aResp->res); 21923a2d0424SChris Cain return; 21933a2d0424SChris Cain } 21943a2d0424SChris Cain const std::string& path = subtree[0].first; 21953a2d0424SChris Cain const std::string& service = subtree[0].second.begin()->first; 21963a2d0424SChris Cain if (service.empty()) 21973a2d0424SChris Cain { 21983a2d0424SChris Cain BMCWEB_LOG_DEBUG << "Power.Mode service mapper error!"; 21993a2d0424SChris Cain messages::internalError(aResp->res); 22003a2d0424SChris Cain return; 22013a2d0424SChris Cain } 22023a2d0424SChris Cain 22033a2d0424SChris Cain BMCWEB_LOG_DEBUG << "Setting power mode(" << powerMode << ") -> " 22043a2d0424SChris Cain << path; 22053a2d0424SChris Cain 22063a2d0424SChris Cain // Set the Power Mode property 22073a2d0424SChris Cain crow::connections::systemBus->async_method_call( 22083a2d0424SChris Cain [aResp](const boost::system::error_code ec) { 22093a2d0424SChris Cain if (ec) 22103a2d0424SChris Cain { 22113a2d0424SChris Cain messages::internalError(aResp->res); 22123a2d0424SChris Cain return; 22133a2d0424SChris Cain } 22143a2d0424SChris Cain }, 22153a2d0424SChris Cain service, path, "org.freedesktop.DBus.Properties", "Set", 22163a2d0424SChris Cain "xyz.openbmc_project.Control.Power.Mode", "PowerMode", 22173a2d0424SChris Cain std::variant<std::string>(powerMode)); 22183a2d0424SChris Cain }, 22193a2d0424SChris Cain "xyz.openbmc_project.ObjectMapper", 22203a2d0424SChris Cain "/xyz/openbmc_project/object_mapper", 22213a2d0424SChris Cain "xyz.openbmc_project.ObjectMapper", "GetSubTree", "/", int32_t(0), 22223a2d0424SChris Cain std::array<const char*, 1>{"xyz.openbmc_project.Control.Power.Mode"}); 22233a2d0424SChris Cain } 22243a2d0424SChris Cain 22253a2d0424SChris Cain /** 222651709ffdSYong Li * @brief Translates watchdog timeout action DBUS property value to redfish. 222751709ffdSYong Li * 222851709ffdSYong Li * @param[in] dbusAction The watchdog timeout action in D-BUS. 222951709ffdSYong Li * 223051709ffdSYong Li * @return Returns as a string, the timeout action in Redfish terms. If 223151709ffdSYong Li * translation cannot be done, returns an empty string. 223251709ffdSYong Li */ 223323a21a1cSEd Tanous inline std::string dbusToRfWatchdogAction(const std::string& dbusAction) 223451709ffdSYong Li { 223551709ffdSYong Li if (dbusAction == "xyz.openbmc_project.State.Watchdog.Action.None") 223651709ffdSYong Li { 223751709ffdSYong Li return "None"; 223851709ffdSYong Li } 22393174e4dfSEd Tanous if (dbusAction == "xyz.openbmc_project.State.Watchdog.Action.HardReset") 224051709ffdSYong Li { 224151709ffdSYong Li return "ResetSystem"; 224251709ffdSYong Li } 22433174e4dfSEd Tanous if (dbusAction == "xyz.openbmc_project.State.Watchdog.Action.PowerOff") 224451709ffdSYong Li { 224551709ffdSYong Li return "PowerDown"; 224651709ffdSYong Li } 22473174e4dfSEd Tanous if (dbusAction == "xyz.openbmc_project.State.Watchdog.Action.PowerCycle") 224851709ffdSYong Li { 224951709ffdSYong Li return "PowerCycle"; 225051709ffdSYong Li } 225151709ffdSYong Li 225251709ffdSYong Li return ""; 225351709ffdSYong Li } 225451709ffdSYong Li 225551709ffdSYong Li /** 2256c45f0082SYong Li *@brief Translates timeout action from Redfish to DBUS property value. 2257c45f0082SYong Li * 2258c45f0082SYong Li *@param[in] rfAction The timeout action in Redfish. 2259c45f0082SYong Li * 2260c45f0082SYong Li *@return Returns as a string, the time_out action as expected by DBUS. 2261c45f0082SYong Li *If translation cannot be done, returns an empty string. 2262c45f0082SYong Li */ 2263c45f0082SYong Li 226423a21a1cSEd Tanous inline std::string rfToDbusWDTTimeOutAct(const std::string& rfAction) 2265c45f0082SYong Li { 2266c45f0082SYong Li if (rfAction == "None") 2267c45f0082SYong Li { 2268c45f0082SYong Li return "xyz.openbmc_project.State.Watchdog.Action.None"; 2269c45f0082SYong Li } 22703174e4dfSEd Tanous if (rfAction == "PowerCycle") 2271c45f0082SYong Li { 2272c45f0082SYong Li return "xyz.openbmc_project.State.Watchdog.Action.PowerCycle"; 2273c45f0082SYong Li } 22743174e4dfSEd Tanous if (rfAction == "PowerDown") 2275c45f0082SYong Li { 2276c45f0082SYong Li return "xyz.openbmc_project.State.Watchdog.Action.PowerOff"; 2277c45f0082SYong Li } 22783174e4dfSEd Tanous if (rfAction == "ResetSystem") 2279c45f0082SYong Li { 2280c45f0082SYong Li return "xyz.openbmc_project.State.Watchdog.Action.HardReset"; 2281c45f0082SYong Li } 2282c45f0082SYong Li 2283c45f0082SYong Li return ""; 2284c45f0082SYong Li } 2285c45f0082SYong Li 2286c45f0082SYong Li /** 228751709ffdSYong Li * @brief Retrieves host watchdog timer properties over DBUS 228851709ffdSYong Li * 228951709ffdSYong Li * @param[in] aResp Shared pointer for completing asynchronous calls. 229051709ffdSYong Li * 229151709ffdSYong Li * @return None. 229251709ffdSYong Li */ 22938d1b46d7Szhanghch05 inline void 22948d1b46d7Szhanghch05 getHostWatchdogTimer(const std::shared_ptr<bmcweb::AsyncResp>& aResp) 229551709ffdSYong Li { 229651709ffdSYong Li BMCWEB_LOG_DEBUG << "Get host watchodg"; 229751709ffdSYong Li crow::connections::systemBus->async_method_call( 229851709ffdSYong Li [aResp](const boost::system::error_code ec, 229951709ffdSYong Li PropertiesType& properties) { 230051709ffdSYong Li if (ec) 230151709ffdSYong Li { 230251709ffdSYong Li // watchdog service is stopped 230351709ffdSYong Li BMCWEB_LOG_DEBUG << "DBUS response error " << ec; 230451709ffdSYong Li return; 230551709ffdSYong Li } 230651709ffdSYong Li 230751709ffdSYong Li BMCWEB_LOG_DEBUG << "Got " << properties.size() << " wdt prop."; 230851709ffdSYong Li 230951709ffdSYong Li nlohmann::json& hostWatchdogTimer = 231051709ffdSYong Li aResp->res.jsonValue["HostWatchdogTimer"]; 231151709ffdSYong Li 231251709ffdSYong Li // watchdog service is running/enabled 231351709ffdSYong Li hostWatchdogTimer["Status"]["State"] = "Enabled"; 231451709ffdSYong Li 231551709ffdSYong Li for (const auto& property : properties) 231651709ffdSYong Li { 231751709ffdSYong Li BMCWEB_LOG_DEBUG << "prop=" << property.first; 231851709ffdSYong Li if (property.first == "Enabled") 231951709ffdSYong Li { 232051709ffdSYong Li const bool* state = std::get_if<bool>(&property.second); 232151709ffdSYong Li 232251709ffdSYong Li if (!state) 232351709ffdSYong Li { 232451709ffdSYong Li messages::internalError(aResp->res); 2325601af5edSChicago Duan return; 232651709ffdSYong Li } 232751709ffdSYong Li 232851709ffdSYong Li hostWatchdogTimer["FunctionEnabled"] = *state; 232951709ffdSYong Li } 233051709ffdSYong Li else if (property.first == "ExpireAction") 233151709ffdSYong Li { 233251709ffdSYong Li const std::string* s = 233351709ffdSYong Li std::get_if<std::string>(&property.second); 233451709ffdSYong Li if (!s) 233551709ffdSYong Li { 233651709ffdSYong Li messages::internalError(aResp->res); 2337601af5edSChicago Duan return; 233851709ffdSYong Li } 233951709ffdSYong Li 234051709ffdSYong Li std::string action = dbusToRfWatchdogAction(*s); 234151709ffdSYong Li if (action.empty()) 234251709ffdSYong Li { 234351709ffdSYong Li messages::internalError(aResp->res); 2344601af5edSChicago Duan return; 234551709ffdSYong Li } 234651709ffdSYong Li hostWatchdogTimer["TimeoutAction"] = action; 234751709ffdSYong Li } 234851709ffdSYong Li } 234951709ffdSYong Li }, 235051709ffdSYong Li "xyz.openbmc_project.Watchdog", "/xyz/openbmc_project/watchdog/host0", 235151709ffdSYong Li "org.freedesktop.DBus.Properties", "GetAll", 235251709ffdSYong Li "xyz.openbmc_project.State.Watchdog"); 235351709ffdSYong Li } 235451709ffdSYong Li 235551709ffdSYong Li /** 2356c45f0082SYong Li * @brief Sets Host WatchDog Timer properties. 2357c45f0082SYong Li * 2358c45f0082SYong Li * @param[in] aResp Shared pointer for generating response message. 2359c45f0082SYong Li * @param[in] wdtEnable The WDTimer Enable value (true/false) from incoming 2360c45f0082SYong Li * RF request. 2361c45f0082SYong Li * @param[in] wdtTimeOutAction The WDT Timeout action, from incoming RF request. 2362c45f0082SYong Li * 2363c45f0082SYong Li * @return None. 2364c45f0082SYong Li */ 23658d1b46d7Szhanghch05 inline void setWDTProperties(const std::shared_ptr<bmcweb::AsyncResp>& aResp, 2366c45f0082SYong Li const std::optional<bool> wdtEnable, 2367c45f0082SYong Li const std::optional<std::string>& wdtTimeOutAction) 2368c45f0082SYong Li { 2369c45f0082SYong Li BMCWEB_LOG_DEBUG << "Set host watchdog"; 2370c45f0082SYong Li 2371c45f0082SYong Li if (wdtTimeOutAction) 2372c45f0082SYong Li { 2373c45f0082SYong Li std::string wdtTimeOutActStr = rfToDbusWDTTimeOutAct(*wdtTimeOutAction); 2374c45f0082SYong Li // check if TimeOut Action is Valid 2375c45f0082SYong Li if (wdtTimeOutActStr.empty()) 2376c45f0082SYong Li { 2377c45f0082SYong Li BMCWEB_LOG_DEBUG << "Unsupported value for TimeoutAction: " 2378c45f0082SYong Li << *wdtTimeOutAction; 2379c45f0082SYong Li messages::propertyValueNotInList(aResp->res, *wdtTimeOutAction, 2380c45f0082SYong Li "TimeoutAction"); 2381c45f0082SYong Li return; 2382c45f0082SYong Li } 2383c45f0082SYong Li 2384c45f0082SYong Li crow::connections::systemBus->async_method_call( 2385c45f0082SYong Li [aResp](const boost::system::error_code ec) { 2386c45f0082SYong Li if (ec) 2387c45f0082SYong Li { 2388c45f0082SYong Li BMCWEB_LOG_DEBUG << "DBUS response error " << ec; 2389c45f0082SYong Li messages::internalError(aResp->res); 2390c45f0082SYong Li return; 2391c45f0082SYong Li } 2392c45f0082SYong Li }, 2393c45f0082SYong Li "xyz.openbmc_project.Watchdog", 2394c45f0082SYong Li "/xyz/openbmc_project/watchdog/host0", 2395c45f0082SYong Li "org.freedesktop.DBus.Properties", "Set", 2396c45f0082SYong Li "xyz.openbmc_project.State.Watchdog", "ExpireAction", 2397c45f0082SYong Li std::variant<std::string>(wdtTimeOutActStr)); 2398c45f0082SYong Li } 2399c45f0082SYong Li 2400c45f0082SYong Li if (wdtEnable) 2401c45f0082SYong Li { 2402c45f0082SYong Li crow::connections::systemBus->async_method_call( 2403c45f0082SYong Li [aResp](const boost::system::error_code ec) { 2404c45f0082SYong Li if (ec) 2405c45f0082SYong Li { 2406c45f0082SYong Li BMCWEB_LOG_DEBUG << "DBUS response error " << ec; 2407c45f0082SYong Li messages::internalError(aResp->res); 2408c45f0082SYong Li return; 2409c45f0082SYong Li } 2410c45f0082SYong Li }, 2411c45f0082SYong Li "xyz.openbmc_project.Watchdog", 2412c45f0082SYong Li "/xyz/openbmc_project/watchdog/host0", 2413c45f0082SYong Li "org.freedesktop.DBus.Properties", "Set", 2414c45f0082SYong Li "xyz.openbmc_project.State.Watchdog", "Enabled", 2415c45f0082SYong Li std::variant<bool>(*wdtEnable)); 2416c45f0082SYong Li } 2417c45f0082SYong Li } 2418c45f0082SYong Li 2419c45f0082SYong Li /** 2420c5b2abe0SLewanczyk, Dawid * SystemsCollection derived class for delivering ComputerSystems Collection 2421c5b2abe0SLewanczyk, Dawid * Schema 2422c5b2abe0SLewanczyk, Dawid */ 24237e860f15SJohn Edward Broadbent inline void requestRoutesSystemsCollection(App& app) 24241abe55efSEd Tanous { 24257e860f15SJohn Edward Broadbent BMCWEB_ROUTE(app, "/redfish/v1/Systems/") 2426ed398213SEd Tanous .privileges(redfish::privileges::getComputerSystemCollection) 24277e860f15SJohn Edward Broadbent .methods(boost::beast::http::verb::get)( 24284f48d5f6SEd Tanous [](const crow::Request& /*req*/, 24297e860f15SJohn Edward Broadbent const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) { 24308d1b46d7Szhanghch05 asyncResp->res.jsonValue["@odata.type"] = 24310f74e643SEd Tanous "#ComputerSystemCollection.ComputerSystemCollection"; 24328d1b46d7Szhanghch05 asyncResp->res.jsonValue["@odata.id"] = "/redfish/v1/Systems"; 24338d1b46d7Szhanghch05 asyncResp->res.jsonValue["Name"] = "Computer System Collection"; 2434462023adSSunitha Harish 2435462023adSSunitha Harish crow::connections::systemBus->async_method_call( 24364f48d5f6SEd Tanous [asyncResp](const boost::system::error_code ec, 2437cb13a392SEd Tanous const std::variant<std::string>& /*hostName*/) { 24382c70f800SEd Tanous nlohmann::json& ifaceArray = 2439462023adSSunitha Harish asyncResp->res.jsonValue["Members"]; 24402c70f800SEd Tanous ifaceArray = nlohmann::json::array(); 24417e860f15SJohn Edward Broadbent auto& count = 24427e860f15SJohn Edward Broadbent asyncResp->res.jsonValue["Members@odata.count"]; 24432c70f800SEd Tanous ifaceArray.push_back( 2444cb13a392SEd Tanous {{"@odata.id", "/redfish/v1/Systems/system"}}); 244594bda602STim Lee count = ifaceArray.size(); 2446cb13a392SEd Tanous if (!ec) 2447462023adSSunitha Harish { 2448462023adSSunitha Harish BMCWEB_LOG_DEBUG << "Hypervisor is available"; 24492c70f800SEd Tanous ifaceArray.push_back( 24507e860f15SJohn Edward Broadbent {{"@odata.id", 24517e860f15SJohn Edward Broadbent "/redfish/v1/Systems/hypervisor"}}); 24522c70f800SEd Tanous count = ifaceArray.size(); 2453cb13a392SEd Tanous } 2454462023adSSunitha Harish }, 24558e651fbfSSunitha Harish "xyz.openbmc_project.Settings", 24568e651fbfSSunitha Harish "/xyz/openbmc_project/network/hypervisor", 2457462023adSSunitha Harish "org.freedesktop.DBus.Properties", "Get", 24587e860f15SJohn Edward Broadbent "xyz.openbmc_project.Network.SystemConfiguration", 24597e860f15SJohn Edward Broadbent "HostName"); 24607e860f15SJohn Edward Broadbent }); 2461c5b2abe0SLewanczyk, Dawid } 24627e860f15SJohn Edward Broadbent 24637e860f15SJohn Edward Broadbent /** 24647e860f15SJohn Edward Broadbent * Function transceives data with dbus directly. 24657e860f15SJohn Edward Broadbent */ 24664f48d5f6SEd Tanous inline void doNMI(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) 24677e860f15SJohn Edward Broadbent { 24687e860f15SJohn Edward Broadbent constexpr char const* serviceName = "xyz.openbmc_project.Control.Host.NMI"; 24697e860f15SJohn Edward Broadbent constexpr char const* objectPath = "/xyz/openbmc_project/control/host0/nmi"; 24707e860f15SJohn Edward Broadbent constexpr char const* interfaceName = 24717e860f15SJohn Edward Broadbent "xyz.openbmc_project.Control.Host.NMI"; 24727e860f15SJohn Edward Broadbent constexpr char const* method = "NMI"; 24737e860f15SJohn Edward Broadbent 24747e860f15SJohn Edward Broadbent crow::connections::systemBus->async_method_call( 24757e860f15SJohn Edward Broadbent [asyncResp](const boost::system::error_code ec) { 24767e860f15SJohn Edward Broadbent if (ec) 24777e860f15SJohn Edward Broadbent { 24787e860f15SJohn Edward Broadbent BMCWEB_LOG_ERROR << " Bad D-Bus request error: " << ec; 24797e860f15SJohn Edward Broadbent messages::internalError(asyncResp->res); 24807e860f15SJohn Edward Broadbent return; 24817e860f15SJohn Edward Broadbent } 24827e860f15SJohn Edward Broadbent messages::success(asyncResp->res); 24837e860f15SJohn Edward Broadbent }, 24847e860f15SJohn Edward Broadbent serviceName, objectPath, interfaceName, method); 24857e860f15SJohn Edward Broadbent } 2486c5b2abe0SLewanczyk, Dawid 2487c5b2abe0SLewanczyk, Dawid /** 2488cc340dd9SEd Tanous * SystemActionsReset class supports handle POST method for Reset action. 2489cc340dd9SEd Tanous * The class retrieves and sends data directly to D-Bus. 2490cc340dd9SEd Tanous */ 24917e860f15SJohn Edward Broadbent inline void requestRoutesSystemActionsReset(App& app) 2492cc340dd9SEd Tanous { 2493cc340dd9SEd Tanous /** 2494cc340dd9SEd Tanous * Function handles POST method request. 2495cc340dd9SEd Tanous * Analyzes POST body message before sends Reset request data to D-Bus. 2496cc340dd9SEd Tanous */ 24977e860f15SJohn Edward Broadbent BMCWEB_ROUTE(app, 24987e860f15SJohn Edward Broadbent "/redfish/v1/Systems/system/Actions/ComputerSystem.Reset/") 2499ed398213SEd Tanous .privileges(redfish::privileges::postComputerSystem) 25007e860f15SJohn Edward Broadbent .methods( 25017e860f15SJohn Edward Broadbent boost::beast::http::verb:: 25027e860f15SJohn Edward Broadbent post)([](const crow::Request& req, 25037e860f15SJohn Edward Broadbent const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) { 25049712f8acSEd Tanous std::string resetType; 25057e860f15SJohn Edward Broadbent if (!json_util::readJson(req, asyncResp->res, "ResetType", 25067e860f15SJohn Edward Broadbent resetType)) 2507cc340dd9SEd Tanous { 2508cc340dd9SEd Tanous return; 2509cc340dd9SEd Tanous } 2510cc340dd9SEd Tanous 2511d22c8396SJason M. Bills // Get the command and host vs. chassis 2512cc340dd9SEd Tanous std::string command; 2513d22c8396SJason M. Bills bool hostCommand; 2514d4d25793SEd Tanous if ((resetType == "On") || (resetType == "ForceOn")) 2515cc340dd9SEd Tanous { 2516cc340dd9SEd Tanous command = "xyz.openbmc_project.State.Host.Transition.On"; 2517d22c8396SJason M. Bills hostCommand = true; 2518d22c8396SJason M. Bills } 2519d22c8396SJason M. Bills else if (resetType == "ForceOff") 2520d22c8396SJason M. Bills { 2521d22c8396SJason M. Bills command = "xyz.openbmc_project.State.Chassis.Transition.Off"; 2522d22c8396SJason M. Bills hostCommand = false; 2523d22c8396SJason M. Bills } 2524d22c8396SJason M. Bills else if (resetType == "ForceRestart") 2525d22c8396SJason M. Bills { 252686a0851aSJason M. Bills command = 252786a0851aSJason M. Bills "xyz.openbmc_project.State.Host.Transition.ForceWarmReboot"; 252886a0851aSJason M. Bills hostCommand = true; 2529cc340dd9SEd Tanous } 25309712f8acSEd Tanous else if (resetType == "GracefulShutdown") 2531cc340dd9SEd Tanous { 2532cc340dd9SEd Tanous command = "xyz.openbmc_project.State.Host.Transition.Off"; 2533d22c8396SJason M. Bills hostCommand = true; 2534cc340dd9SEd Tanous } 25359712f8acSEd Tanous else if (resetType == "GracefulRestart") 2536cc340dd9SEd Tanous { 25377e860f15SJohn Edward Broadbent command = "xyz.openbmc_project.State.Host.Transition." 25387e860f15SJohn Edward Broadbent "GracefulWarmReboot"; 2539d22c8396SJason M. Bills hostCommand = true; 2540d22c8396SJason M. Bills } 2541d22c8396SJason M. Bills else if (resetType == "PowerCycle") 2542d22c8396SJason M. Bills { 254386a0851aSJason M. Bills command = "xyz.openbmc_project.State.Host.Transition.Reboot"; 254486a0851aSJason M. Bills hostCommand = true; 2545cc340dd9SEd Tanous } 2546bfd5b826SLakshminarayana R. Kammath else if (resetType == "Nmi") 2547bfd5b826SLakshminarayana R. Kammath { 2548bfd5b826SLakshminarayana R. Kammath doNMI(asyncResp); 2549bfd5b826SLakshminarayana R. Kammath return; 2550bfd5b826SLakshminarayana R. Kammath } 2551cc340dd9SEd Tanous else 2552cc340dd9SEd Tanous { 25538d1b46d7Szhanghch05 messages::actionParameterUnknown(asyncResp->res, "Reset", 25548d1b46d7Szhanghch05 resetType); 2555cc340dd9SEd Tanous return; 2556cc340dd9SEd Tanous } 2557cc340dd9SEd Tanous 2558d22c8396SJason M. Bills if (hostCommand) 2559d22c8396SJason M. Bills { 2560cc340dd9SEd Tanous crow::connections::systemBus->async_method_call( 2561d22c8396SJason M. Bills [asyncResp, resetType](const boost::system::error_code ec) { 2562cc340dd9SEd Tanous if (ec) 2563cc340dd9SEd Tanous { 2564cc340dd9SEd Tanous BMCWEB_LOG_ERROR << "D-Bus responses error: " << ec; 25657e860f15SJohn Edward Broadbent if (ec.value() == 25667e860f15SJohn Edward Broadbent boost::asio::error::invalid_argument) 2567d22c8396SJason M. Bills { 2568d22c8396SJason M. Bills messages::actionParameterNotSupported( 2569d22c8396SJason M. Bills asyncResp->res, resetType, "Reset"); 2570d22c8396SJason M. Bills } 2571d22c8396SJason M. Bills else 2572d22c8396SJason M. Bills { 2573f12894f8SJason M. Bills messages::internalError(asyncResp->res); 2574d22c8396SJason M. Bills } 2575cc340dd9SEd Tanous return; 2576cc340dd9SEd Tanous } 2577f12894f8SJason M. Bills messages::success(asyncResp->res); 2578cc340dd9SEd Tanous }, 2579cc340dd9SEd Tanous "xyz.openbmc_project.State.Host", 2580cc340dd9SEd Tanous "/xyz/openbmc_project/state/host0", 2581cc340dd9SEd Tanous "org.freedesktop.DBus.Properties", "Set", 25829712f8acSEd Tanous "xyz.openbmc_project.State.Host", "RequestedHostTransition", 2583abf2add6SEd Tanous std::variant<std::string>{command}); 2584cc340dd9SEd Tanous } 2585d22c8396SJason M. Bills else 2586d22c8396SJason M. Bills { 2587d22c8396SJason M. Bills crow::connections::systemBus->async_method_call( 2588d22c8396SJason M. Bills [asyncResp, resetType](const boost::system::error_code ec) { 2589d22c8396SJason M. Bills if (ec) 2590d22c8396SJason M. Bills { 2591d22c8396SJason M. Bills BMCWEB_LOG_ERROR << "D-Bus responses error: " << ec; 25927e860f15SJohn Edward Broadbent if (ec.value() == 25937e860f15SJohn Edward Broadbent boost::asio::error::invalid_argument) 2594d22c8396SJason M. Bills { 2595d22c8396SJason M. Bills messages::actionParameterNotSupported( 2596d22c8396SJason M. Bills asyncResp->res, resetType, "Reset"); 2597d22c8396SJason M. Bills } 2598d22c8396SJason M. Bills else 2599d22c8396SJason M. Bills { 2600d22c8396SJason M. Bills messages::internalError(asyncResp->res); 2601d22c8396SJason M. Bills } 2602d22c8396SJason M. Bills return; 2603d22c8396SJason M. Bills } 2604d22c8396SJason M. Bills messages::success(asyncResp->res); 2605d22c8396SJason M. Bills }, 2606d22c8396SJason M. Bills "xyz.openbmc_project.State.Chassis", 2607d22c8396SJason M. Bills "/xyz/openbmc_project/state/chassis0", 2608d22c8396SJason M. Bills "org.freedesktop.DBus.Properties", "Set", 26097e860f15SJohn Edward Broadbent "xyz.openbmc_project.State.Chassis", 26107e860f15SJohn Edward Broadbent "RequestedPowerTransition", 2611d22c8396SJason M. Bills std::variant<std::string>{command}); 2612d22c8396SJason M. Bills } 26137e860f15SJohn Edward Broadbent }); 2614d22c8396SJason M. Bills } 2615cc340dd9SEd Tanous 2616cc340dd9SEd Tanous /** 26176617338dSEd Tanous * Systems derived class for delivering Computer Systems Schema. 2618c5b2abe0SLewanczyk, Dawid */ 26197e860f15SJohn Edward Broadbent inline void requestRoutesSystems(App& app) 26201abe55efSEd Tanous { 2621c5b2abe0SLewanczyk, Dawid 2622c5b2abe0SLewanczyk, Dawid /** 2623c5b2abe0SLewanczyk, Dawid * Functions triggers appropriate requests on DBus 2624c5b2abe0SLewanczyk, Dawid */ 26257e860f15SJohn Edward Broadbent BMCWEB_ROUTE(app, "/redfish/v1/Systems/system/") 2626ed398213SEd Tanous .privileges(redfish::privileges::getComputerSystem) 26277e860f15SJohn Edward Broadbent .methods( 26287e860f15SJohn Edward Broadbent boost::beast::http::verb:: 26297e860f15SJohn Edward Broadbent get)([](const crow::Request&, 26307e860f15SJohn Edward Broadbent const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) { 26318d1b46d7Szhanghch05 asyncResp->res.jsonValue["@odata.type"] = 26323a2d0424SChris Cain "#ComputerSystem.v1_15_0.ComputerSystem"; 26338d1b46d7Szhanghch05 asyncResp->res.jsonValue["Name"] = "system"; 26348d1b46d7Szhanghch05 asyncResp->res.jsonValue["Id"] = "system"; 26358d1b46d7Szhanghch05 asyncResp->res.jsonValue["SystemType"] = "Physical"; 26368d1b46d7Szhanghch05 asyncResp->res.jsonValue["Description"] = "Computer System"; 26378d1b46d7Szhanghch05 asyncResp->res.jsonValue["ProcessorSummary"]["Count"] = 0; 26388d1b46d7Szhanghch05 asyncResp->res.jsonValue["ProcessorSummary"]["Status"]["State"] = 26398d1b46d7Szhanghch05 "Disabled"; 26408d1b46d7Szhanghch05 asyncResp->res.jsonValue["MemorySummary"]["TotalSystemMemoryGiB"] = 26418d1b46d7Szhanghch05 uint64_t(0); 26428d1b46d7Szhanghch05 asyncResp->res.jsonValue["MemorySummary"]["Status"]["State"] = 26438d1b46d7Szhanghch05 "Disabled"; 26447e860f15SJohn Edward Broadbent asyncResp->res.jsonValue["@odata.id"] = 26457e860f15SJohn Edward Broadbent "/redfish/v1/Systems/system"; 264604a258f4SEd Tanous 26478d1b46d7Szhanghch05 asyncResp->res.jsonValue["Processors"] = { 2648029573d4SEd Tanous {"@odata.id", "/redfish/v1/Systems/system/Processors"}}; 26498d1b46d7Szhanghch05 asyncResp->res.jsonValue["Memory"] = { 2650029573d4SEd Tanous {"@odata.id", "/redfish/v1/Systems/system/Memory"}}; 26518d1b46d7Szhanghch05 asyncResp->res.jsonValue["Storage"] = { 2652a25aeccfSNikhil Potade {"@odata.id", "/redfish/v1/Systems/system/Storage"}}; 2653029573d4SEd Tanous 26548d1b46d7Szhanghch05 asyncResp->res.jsonValue["Actions"]["#ComputerSystem.Reset"] = { 2655cc340dd9SEd Tanous {"target", 2656029573d4SEd Tanous "/redfish/v1/Systems/system/Actions/ComputerSystem.Reset"}, 26571cb1a9e6SAppaRao Puli {"@Redfish.ActionInfo", 26581cb1a9e6SAppaRao Puli "/redfish/v1/Systems/system/ResetActionInfo"}}; 2659c5b2abe0SLewanczyk, Dawid 26608d1b46d7Szhanghch05 asyncResp->res.jsonValue["LogServices"] = { 2661029573d4SEd Tanous {"@odata.id", "/redfish/v1/Systems/system/LogServices"}}; 2662c4bf6374SJason M. Bills 26638d1b46d7Szhanghch05 asyncResp->res.jsonValue["Bios"] = { 2664d82a3acdSCarol Wang {"@odata.id", "/redfish/v1/Systems/system/Bios"}}; 2665d82a3acdSCarol Wang 26668d1b46d7Szhanghch05 asyncResp->res.jsonValue["Links"]["ManagedBy"] = { 2667c5d03ff4SJennifer Lee {{"@odata.id", "/redfish/v1/Managers/bmc"}}}; 2668c5d03ff4SJennifer Lee 26698d1b46d7Szhanghch05 asyncResp->res.jsonValue["Status"] = { 2670c5d03ff4SJennifer Lee {"Health", "OK"}, 2671c5d03ff4SJennifer Lee {"State", "Enabled"}, 2672c5d03ff4SJennifer Lee }; 26730e8ac5e7SGunnar Mills 26740e8ac5e7SGunnar Mills // Fill in SerialConsole info 26750e8ac5e7SGunnar Mills asyncResp->res.jsonValue["SerialConsole"]["MaxConcurrentSessions"] = 26760e8ac5e7SGunnar Mills 15; 26770e8ac5e7SGunnar Mills asyncResp->res.jsonValue["SerialConsole"]["IPMI"] = { 26780e8ac5e7SGunnar Mills {"ServiceEnabled", true}, 26790e8ac5e7SGunnar Mills }; 26800e8ac5e7SGunnar Mills // TODO (Gunnar): Should look for obmc-console-ssh@2200.service 26810e8ac5e7SGunnar Mills asyncResp->res.jsonValue["SerialConsole"]["SSH"] = { 26820e8ac5e7SGunnar Mills {"ServiceEnabled", true}, 26830e8ac5e7SGunnar Mills {"Port", 2200}, 26840e8ac5e7SGunnar Mills // https://github.com/openbmc/docs/blob/master/console.md 26850e8ac5e7SGunnar Mills {"HotKeySequenceDisplay", "Press ~. to exit console"}, 26860e8ac5e7SGunnar Mills }; 26870e8ac5e7SGunnar Mills 26880e8ac5e7SGunnar Mills #ifdef BMCWEB_ENABLE_KVM 26890e8ac5e7SGunnar Mills // Fill in GraphicalConsole info 26900e8ac5e7SGunnar Mills asyncResp->res.jsonValue["GraphicalConsole"] = { 26910e8ac5e7SGunnar Mills {"ServiceEnabled", true}, 26920e8ac5e7SGunnar Mills {"MaxConcurrentSessions", 4}, 26930e8ac5e7SGunnar Mills {"ConnectTypesSupported", {"KVMIP"}}, 26940e8ac5e7SGunnar Mills }; 26950e8ac5e7SGunnar Mills #endif // BMCWEB_ENABLE_KVM 2696e284a7c1SJames Feist constexpr const std::array<const char*, 4> inventoryForSystems = { 2697b49ac873SJames Feist "xyz.openbmc_project.Inventory.Item.Dimm", 26982ad9c2f6SJames Feist "xyz.openbmc_project.Inventory.Item.Cpu", 2699e284a7c1SJames Feist "xyz.openbmc_project.Inventory.Item.Drive", 2700e284a7c1SJames Feist "xyz.openbmc_project.Inventory.Item.StorageController"}; 2701b49ac873SJames Feist 2702b49ac873SJames Feist auto health = std::make_shared<HealthPopulate>(asyncResp); 2703b49ac873SJames Feist crow::connections::systemBus->async_method_call( 2704b49ac873SJames Feist [health](const boost::system::error_code ec, 2705b49ac873SJames Feist std::vector<std::string>& resp) { 2706b49ac873SJames Feist if (ec) 2707b49ac873SJames Feist { 2708b49ac873SJames Feist // no inventory 2709b49ac873SJames Feist return; 2710b49ac873SJames Feist } 2711b49ac873SJames Feist 2712b49ac873SJames Feist health->inventory = std::move(resp); 2713b49ac873SJames Feist }, 2714b49ac873SJames Feist "xyz.openbmc_project.ObjectMapper", 2715b49ac873SJames Feist "/xyz/openbmc_project/object_mapper", 2716b49ac873SJames Feist "xyz.openbmc_project.ObjectMapper", "GetSubTreePaths", "/", 2717b49ac873SJames Feist int32_t(0), inventoryForSystems); 2718b49ac873SJames Feist 2719b49ac873SJames Feist health->populate(); 2720b49ac873SJames Feist 27218d1b46d7Szhanghch05 getMainChassisId( 27228d1b46d7Szhanghch05 asyncResp, [](const std::string& chassisId, 27238d1b46d7Szhanghch05 const std::shared_ptr<bmcweb::AsyncResp>& aRsp) { 2724c5d03ff4SJennifer Lee aRsp->res.jsonValue["Links"]["Chassis"] = { 2725c5d03ff4SJennifer Lee {{"@odata.id", "/redfish/v1/Chassis/" + chassisId}}}; 2726c5d03ff4SJennifer Lee }); 2727a3002228SAppaRao Puli 27289f8bfa7cSGunnar Mills getLocationIndicatorActive(asyncResp); 27299f8bfa7cSGunnar Mills // TODO (Gunnar): Remove IndicatorLED after enough time has passed 2730a3002228SAppaRao Puli getIndicatorLedState(asyncResp); 27315bc2dc8eSJames Feist getComputerSystem(asyncResp, health); 27326c34de48SEd Tanous getHostState(asyncResp); 2733491d8ee7SSantosh Puranik getBootProperties(asyncResp); 2734978b8803SAndrew Geissler getBootProgress(asyncResp); 2735adbe192aSJason M. Bills getPCIeDeviceList(asyncResp, "PCIeDevices"); 273651709ffdSYong Li getHostWatchdogTimer(asyncResp); 2737c6a620f2SGeorge Liu getPowerRestorePolicy(asyncResp); 27386bd5a8d2SGunnar Mills getAutomaticRetry(asyncResp); 2739c0557e1aSGunnar Mills getLastResetTime(asyncResp); 2740a6349918SAppaRao Puli #ifdef BMCWEB_ENABLE_REDFISH_PROVISIONING_FEATURE 2741a6349918SAppaRao Puli getProvisioningStatus(asyncResp); 2742a6349918SAppaRao Puli #endif 27431981771bSAli Ahmed getTrustedModuleRequiredToBoot(asyncResp); 27443a2d0424SChris Cain getPowerMode(asyncResp); 27457e860f15SJohn Edward Broadbent }); 27467e860f15SJohn Edward Broadbent BMCWEB_ROUTE(app, "/redfish/v1/Systems/system/") 2747ed398213SEd Tanous .privileges(redfish::privileges::patchComputerSystem) 27487e860f15SJohn Edward Broadbent .methods(boost::beast::http::verb::patch)( 27497e860f15SJohn Edward Broadbent [](const crow::Request& req, 27507e860f15SJohn Edward Broadbent const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) { 27519f8bfa7cSGunnar Mills std::optional<bool> locationIndicatorActive; 2752cde19e5fSSantosh Puranik std::optional<std::string> indicatorLed; 2753491d8ee7SSantosh Puranik std::optional<nlohmann::json> bootProps; 2754c45f0082SYong Li std::optional<nlohmann::json> wdtTimerProps; 275598e386ecSGunnar Mills std::optional<std::string> assetTag; 2756c6a620f2SGeorge Liu std::optional<std::string> powerRestorePolicy; 27573a2d0424SChris Cain std::optional<std::string> powerMode; 275841352c24SSantosh Puranik 27599f8bfa7cSGunnar Mills if (!json_util::readJson( 27608d1b46d7Szhanghch05 req, asyncResp->res, "IndicatorLED", indicatorLed, 27617e860f15SJohn Edward Broadbent "LocationIndicatorActive", locationIndicatorActive, 27627e860f15SJohn Edward Broadbent "Boot", bootProps, "WatchdogTimer", wdtTimerProps, 27637e860f15SJohn Edward Broadbent "PowerRestorePolicy", powerRestorePolicy, "AssetTag", 27643a2d0424SChris Cain assetTag, "PowerMode", powerMode)) 27656617338dSEd Tanous { 27666617338dSEd Tanous return; 27676617338dSEd Tanous } 2768491d8ee7SSantosh Puranik 27698d1b46d7Szhanghch05 asyncResp->res.result(boost::beast::http::status::no_content); 2770c45f0082SYong Li 277198e386ecSGunnar Mills if (assetTag) 277298e386ecSGunnar Mills { 277398e386ecSGunnar Mills setAssetTag(asyncResp, *assetTag); 277498e386ecSGunnar Mills } 277598e386ecSGunnar Mills 2776c45f0082SYong Li if (wdtTimerProps) 2777c45f0082SYong Li { 2778c45f0082SYong Li std::optional<bool> wdtEnable; 2779c45f0082SYong Li std::optional<std::string> wdtTimeOutAction; 2780c45f0082SYong Li 2781c45f0082SYong Li if (!json_util::readJson(*wdtTimerProps, asyncResp->res, 2782c45f0082SYong Li "FunctionEnabled", wdtEnable, 2783c45f0082SYong Li "TimeoutAction", wdtTimeOutAction)) 2784c45f0082SYong Li { 2785c45f0082SYong Li return; 2786c45f0082SYong Li } 2787f23b7296SEd Tanous setWDTProperties(asyncResp, wdtEnable, wdtTimeOutAction); 2788c45f0082SYong Li } 2789c45f0082SYong Li 2790491d8ee7SSantosh Puranik if (bootProps) 2791491d8ee7SSantosh Puranik { 2792491d8ee7SSantosh Puranik std::optional<std::string> bootSource; 2793*cd9a4666SKonstantin Aladyshev std::optional<std::string> bootType; 2794491d8ee7SSantosh Puranik std::optional<std::string> bootEnable; 279569f35306SGunnar Mills std::optional<std::string> automaticRetryConfig; 2796491d8ee7SSantosh Puranik 279769f35306SGunnar Mills if (!json_util::readJson( 27987e860f15SJohn Edward Broadbent *bootProps, asyncResp->res, 27997e860f15SJohn Edward Broadbent "BootSourceOverrideTarget", bootSource, 2800*cd9a4666SKonstantin Aladyshev "BootSourceOverrideMode", bootType, 28017e860f15SJohn Edward Broadbent "BootSourceOverrideEnabled", bootEnable, 280269f35306SGunnar Mills "AutomaticRetryConfig", automaticRetryConfig)) 2803491d8ee7SSantosh Puranik { 2804491d8ee7SSantosh Puranik return; 2805491d8ee7SSantosh Puranik } 2806*cd9a4666SKonstantin Aladyshev if (bootSource || bootType || bootEnable) 280769f35306SGunnar Mills { 2808*cd9a4666SKonstantin Aladyshev setBootSourceProperties( 2809*cd9a4666SKonstantin Aladyshev asyncResp, std::move(bootSource), 2810*cd9a4666SKonstantin Aladyshev std::move(bootType), std::move(bootEnable)); 2811491d8ee7SSantosh Puranik } 281269f35306SGunnar Mills if (automaticRetryConfig) 281369f35306SGunnar Mills { 2814f23b7296SEd Tanous setAutomaticRetry(asyncResp, *automaticRetryConfig); 281569f35306SGunnar Mills } 281669f35306SGunnar Mills } 2817265c1602SJohnathan Mantey 28189f8bfa7cSGunnar Mills if (locationIndicatorActive) 28199f8bfa7cSGunnar Mills { 28207e860f15SJohn Edward Broadbent setLocationIndicatorActive(asyncResp, 28217e860f15SJohn Edward Broadbent *locationIndicatorActive); 28229f8bfa7cSGunnar Mills } 28239f8bfa7cSGunnar Mills 28247e860f15SJohn Edward Broadbent // TODO (Gunnar): Remove IndicatorLED after enough time has 28257e860f15SJohn Edward Broadbent // passed 28269712f8acSEd Tanous if (indicatorLed) 28276617338dSEd Tanous { 2828f23b7296SEd Tanous setIndicatorLedState(asyncResp, *indicatorLed); 28297e860f15SJohn Edward Broadbent asyncResp->res.addHeader( 28307e860f15SJohn Edward Broadbent boost::beast::http::field::warning, 2831d6aa0093SGunnar Mills "299 - \"IndicatorLED is deprecated. Use " 2832d6aa0093SGunnar Mills "LocationIndicatorActive instead.\""); 28336617338dSEd Tanous } 2834c6a620f2SGeorge Liu 2835c6a620f2SGeorge Liu if (powerRestorePolicy) 2836c6a620f2SGeorge Liu { 28374e69c904SGunnar Mills setPowerRestorePolicy(asyncResp, *powerRestorePolicy); 2838c6a620f2SGeorge Liu } 28393a2d0424SChris Cain 28403a2d0424SChris Cain if (powerMode) 28413a2d0424SChris Cain { 28423a2d0424SChris Cain setPowerMode(asyncResp, *powerMode); 28433a2d0424SChris Cain } 28447e860f15SJohn Edward Broadbent }); 2845c5b2abe0SLewanczyk, Dawid } 28461cb1a9e6SAppaRao Puli 28471cb1a9e6SAppaRao Puli /** 28481cb1a9e6SAppaRao Puli * SystemResetActionInfo derived class for delivering Computer Systems 28491cb1a9e6SAppaRao Puli * ResetType AllowableValues using ResetInfo schema. 28501cb1a9e6SAppaRao Puli */ 28517e860f15SJohn Edward Broadbent inline void requestRoutesSystemResetActionInfo(App& app) 28521cb1a9e6SAppaRao Puli { 28531cb1a9e6SAppaRao Puli 28541cb1a9e6SAppaRao Puli /** 28551cb1a9e6SAppaRao Puli * Functions triggers appropriate requests on DBus 28561cb1a9e6SAppaRao Puli */ 28577e860f15SJohn Edward Broadbent BMCWEB_ROUTE(app, "/redfish/v1/Systems/system/ResetActionInfo/") 2858ed398213SEd Tanous .privileges(redfish::privileges::getActionInfo) 28597e860f15SJohn Edward Broadbent .methods(boost::beast::http::verb::get)( 28607e860f15SJohn Edward Broadbent [](const crow::Request&, 28617e860f15SJohn Edward Broadbent const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) { 28628d1b46d7Szhanghch05 asyncResp->res.jsonValue = { 28631cb1a9e6SAppaRao Puli {"@odata.type", "#ActionInfo.v1_1_2.ActionInfo"}, 28641cb1a9e6SAppaRao Puli {"@odata.id", "/redfish/v1/Systems/system/ResetActionInfo"}, 28651cb1a9e6SAppaRao Puli {"Name", "Reset Action Info"}, 28661cb1a9e6SAppaRao Puli {"Id", "ResetActionInfo"}, 28671cb1a9e6SAppaRao Puli {"Parameters", 28681cb1a9e6SAppaRao Puli {{{"Name", "ResetType"}, 28691cb1a9e6SAppaRao Puli {"Required", true}, 28701cb1a9e6SAppaRao Puli {"DataType", "String"}, 28711cb1a9e6SAppaRao Puli {"AllowableValues", 28727e860f15SJohn Edward Broadbent {"On", "ForceOff", "ForceOn", "ForceRestart", 28737e860f15SJohn Edward Broadbent "GracefulRestart", "GracefulShutdown", "PowerCycle", 28747e860f15SJohn Edward Broadbent "Nmi"}}}}}}; 28757e860f15SJohn Edward Broadbent }); 28761cb1a9e6SAppaRao Puli } 2877c5b2abe0SLewanczyk, Dawid } // namespace redfish 2878