1c5b2abe0SLewanczyk, Dawid /* 2c5b2abe0SLewanczyk, Dawid // Copyright (c) 2018 Intel Corporation 3c5b2abe0SLewanczyk, Dawid // 4c5b2abe0SLewanczyk, Dawid // Licensed under the Apache License, Version 2.0 (the "License"); 5c5b2abe0SLewanczyk, Dawid // you may not use this file except in compliance with the License. 6c5b2abe0SLewanczyk, Dawid // You may obtain a copy of the License at 7c5b2abe0SLewanczyk, Dawid // 8c5b2abe0SLewanczyk, Dawid // http://www.apache.org/licenses/LICENSE-2.0 9c5b2abe0SLewanczyk, Dawid // 10c5b2abe0SLewanczyk, Dawid // Unless required by applicable law or agreed to in writing, software 11c5b2abe0SLewanczyk, Dawid // distributed under the License is distributed on an "AS IS" BASIS, 12c5b2abe0SLewanczyk, Dawid // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13c5b2abe0SLewanczyk, Dawid // See the License for the specific language governing permissions and 14c5b2abe0SLewanczyk, Dawid // limitations under the License. 15c5b2abe0SLewanczyk, Dawid */ 16c5b2abe0SLewanczyk, Dawid #pragma once 17c5b2abe0SLewanczyk, Dawid 18b49ac873SJames Feist #include "health.hpp" 191c8fba97SJames Feist #include "led.hpp" 20f5c9f8bdSJason M. Bills #include "pcie.hpp" 21c5d03ff4SJennifer Lee #include "redfish_util.hpp" 22c5d03ff4SJennifer Lee 239712f8acSEd Tanous #include <boost/container/flat_map.hpp> 249712f8acSEd Tanous #include <node.hpp> 25cb7e1e7bSAndrew Geissler #include <utils/fw_utils.hpp> 26c5b2abe0SLewanczyk, Dawid #include <utils/json_utils.hpp> 271214b7e7SGunnar Mills 28abf2add6SEd Tanous #include <variant> 29c5b2abe0SLewanczyk, Dawid 301abe55efSEd Tanous namespace redfish 311abe55efSEd Tanous { 32c5b2abe0SLewanczyk, Dawid 339d3ae10eSAlpana Kumari /** 349d3ae10eSAlpana Kumari * @brief Updates the Functional State of DIMMs 359d3ae10eSAlpana Kumari * 369d3ae10eSAlpana Kumari * @param[in] aResp Shared pointer for completing asynchronous calls 379d3ae10eSAlpana Kumari * @param[in] dimmState Dimm's Functional state, true/false 389d3ae10eSAlpana Kumari * 399d3ae10eSAlpana Kumari * @return None. 409d3ae10eSAlpana Kumari */ 41b5a76932SEd Tanous inline void updateDimmProperties(const std::shared_ptr<AsyncResp>& aResp, 429d3ae10eSAlpana Kumari const std::variant<bool>& dimmState) 439d3ae10eSAlpana Kumari { 449d3ae10eSAlpana Kumari const bool* isDimmFunctional = std::get_if<bool>(&dimmState); 459d3ae10eSAlpana Kumari if (isDimmFunctional == nullptr) 469d3ae10eSAlpana Kumari { 479d3ae10eSAlpana Kumari messages::internalError(aResp->res); 489d3ae10eSAlpana Kumari return; 499d3ae10eSAlpana Kumari } 509d3ae10eSAlpana Kumari BMCWEB_LOG_DEBUG << "Dimm Functional: " << *isDimmFunctional; 519d3ae10eSAlpana Kumari 529d3ae10eSAlpana Kumari // Set it as Enabled if at least one DIMM is functional 539d3ae10eSAlpana Kumari // Update STATE only if previous State was DISABLED and current Dimm is 549d3ae10eSAlpana Kumari // ENABLED. 559d3ae10eSAlpana Kumari nlohmann::json& prevMemSummary = 569d3ae10eSAlpana Kumari aResp->res.jsonValue["MemorySummary"]["Status"]["State"]; 579d3ae10eSAlpana Kumari if (prevMemSummary == "Disabled") 589d3ae10eSAlpana Kumari { 599d3ae10eSAlpana Kumari if (*isDimmFunctional == true) 609d3ae10eSAlpana Kumari { 619d3ae10eSAlpana Kumari aResp->res.jsonValue["MemorySummary"]["Status"]["State"] = 629d3ae10eSAlpana Kumari "Enabled"; 639d3ae10eSAlpana Kumari } 649d3ae10eSAlpana Kumari } 659d3ae10eSAlpana Kumari } 669d3ae10eSAlpana Kumari 6757e8c9beSAlpana Kumari /* 6857e8c9beSAlpana Kumari * @brief Update "ProcessorSummary" "Count" based on Cpu PresenceState 6957e8c9beSAlpana Kumari * 7057e8c9beSAlpana Kumari * @param[in] aResp Shared pointer for completing asynchronous calls 7157e8c9beSAlpana Kumari * @param[in] cpuPresenceState CPU present or not 7257e8c9beSAlpana Kumari * 7357e8c9beSAlpana Kumari * @return None. 7457e8c9beSAlpana Kumari */ 75b5a76932SEd Tanous inline void modifyCpuPresenceState(const std::shared_ptr<AsyncResp>& aResp, 7657e8c9beSAlpana Kumari const std::variant<bool>& cpuPresenceState) 7757e8c9beSAlpana Kumari { 7857e8c9beSAlpana Kumari const bool* isCpuPresent = std::get_if<bool>(&cpuPresenceState); 7957e8c9beSAlpana Kumari 8057e8c9beSAlpana Kumari if (isCpuPresent == nullptr) 8157e8c9beSAlpana Kumari { 8257e8c9beSAlpana Kumari messages::internalError(aResp->res); 8357e8c9beSAlpana Kumari return; 8457e8c9beSAlpana Kumari } 8557e8c9beSAlpana Kumari BMCWEB_LOG_DEBUG << "Cpu Present: " << *isCpuPresent; 8657e8c9beSAlpana Kumari 8757e8c9beSAlpana Kumari if (*isCpuPresent == true) 8857e8c9beSAlpana Kumari { 89b4b9595aSJames Feist nlohmann::json& procCount = 90b4b9595aSJames Feist aResp->res.jsonValue["ProcessorSummary"]["Count"]; 91b4b9595aSJames Feist auto procCountPtr = 92b4b9595aSJames Feist procCount.get_ptr<nlohmann::json::number_integer_t*>(); 93b4b9595aSJames Feist if (procCountPtr != nullptr) 94b4b9595aSJames Feist { 95b4b9595aSJames Feist // shouldn't be possible to be nullptr 96b4b9595aSJames Feist *procCountPtr += 1; 9757e8c9beSAlpana Kumari } 98b4b9595aSJames Feist } 9957e8c9beSAlpana Kumari } 10057e8c9beSAlpana Kumari 10157e8c9beSAlpana Kumari /* 10257e8c9beSAlpana Kumari * @brief Update "ProcessorSummary" "Status" "State" based on 10357e8c9beSAlpana Kumari * CPU Functional State 10457e8c9beSAlpana Kumari * 10557e8c9beSAlpana Kumari * @param[in] aResp Shared pointer for completing asynchronous calls 10657e8c9beSAlpana Kumari * @param[in] cpuFunctionalState is CPU functional true/false 10757e8c9beSAlpana Kumari * 10857e8c9beSAlpana Kumari * @return None. 10957e8c9beSAlpana Kumari */ 11023a21a1cSEd Tanous inline void 111b5a76932SEd Tanous modifyCpuFunctionalState(const std::shared_ptr<AsyncResp>& aResp, 11257e8c9beSAlpana Kumari const std::variant<bool>& cpuFunctionalState) 11357e8c9beSAlpana Kumari { 11457e8c9beSAlpana Kumari const bool* isCpuFunctional = std::get_if<bool>(&cpuFunctionalState); 11557e8c9beSAlpana Kumari 11657e8c9beSAlpana Kumari if (isCpuFunctional == nullptr) 11757e8c9beSAlpana Kumari { 11857e8c9beSAlpana Kumari messages::internalError(aResp->res); 11957e8c9beSAlpana Kumari return; 12057e8c9beSAlpana Kumari } 12157e8c9beSAlpana Kumari BMCWEB_LOG_DEBUG << "Cpu Functional: " << *isCpuFunctional; 12257e8c9beSAlpana Kumari 12357e8c9beSAlpana Kumari nlohmann::json& prevProcState = 12457e8c9beSAlpana Kumari aResp->res.jsonValue["ProcessorSummary"]["Status"]["State"]; 12557e8c9beSAlpana Kumari 12657e8c9beSAlpana Kumari // Set it as Enabled if at least one CPU is functional 12757e8c9beSAlpana Kumari // Update STATE only if previous State was Non_Functional and current CPU is 12857e8c9beSAlpana Kumari // Functional. 12957e8c9beSAlpana Kumari if (prevProcState == "Disabled") 13057e8c9beSAlpana Kumari { 13157e8c9beSAlpana Kumari if (*isCpuFunctional == true) 13257e8c9beSAlpana Kumari { 13357e8c9beSAlpana Kumari aResp->res.jsonValue["ProcessorSummary"]["Status"]["State"] = 13457e8c9beSAlpana Kumari "Enabled"; 13557e8c9beSAlpana Kumari } 13657e8c9beSAlpana Kumari } 13757e8c9beSAlpana Kumari } 13857e8c9beSAlpana Kumari 13957e8c9beSAlpana Kumari /* 140c5b2abe0SLewanczyk, Dawid * @brief Retrieves computer system properties over dbus 141c5b2abe0SLewanczyk, Dawid * 142c5b2abe0SLewanczyk, Dawid * @param[in] aResp Shared pointer for completing asynchronous calls 1438f9ee3cdSGunnar Mills * @param[in] systemHealth Shared HealthPopulate pointer 144c5b2abe0SLewanczyk, Dawid * 145c5b2abe0SLewanczyk, Dawid * @return None. 146c5b2abe0SLewanczyk, Dawid */ 147b5a76932SEd Tanous inline void 148b5a76932SEd Tanous getComputerSystem(const std::shared_ptr<AsyncResp>& aResp, 149b5a76932SEd Tanous const std::shared_ptr<HealthPopulate>& systemHealth) 1501abe55efSEd Tanous { 15155c7b7a2SEd Tanous BMCWEB_LOG_DEBUG << "Get available system components."; 1529d3ae10eSAlpana Kumari 15355c7b7a2SEd Tanous crow::connections::systemBus->async_method_call( 1545bc2dc8eSJames Feist [aResp, systemHealth]( 155c5b2abe0SLewanczyk, Dawid const boost::system::error_code ec, 156c5b2abe0SLewanczyk, Dawid const std::vector<std::pair< 1576c34de48SEd Tanous std::string, 1581214b7e7SGunnar Mills std::vector<std::pair<std::string, std::vector<std::string>>>>>& 1591214b7e7SGunnar Mills subtree) { 1601abe55efSEd Tanous if (ec) 1611abe55efSEd Tanous { 16255c7b7a2SEd Tanous BMCWEB_LOG_DEBUG << "DBUS response error"; 163f12894f8SJason M. Bills messages::internalError(aResp->res); 164c5b2abe0SLewanczyk, Dawid return; 165c5b2abe0SLewanczyk, Dawid } 166c5b2abe0SLewanczyk, Dawid // Iterate over all retrieved ObjectPaths. 1676c34de48SEd Tanous for (const std::pair<std::string, 1686c34de48SEd Tanous std::vector<std::pair< 1691214b7e7SGunnar Mills std::string, std::vector<std::string>>>>& 1701214b7e7SGunnar Mills object : subtree) 1711abe55efSEd Tanous { 172c5b2abe0SLewanczyk, Dawid const std::string& path = object.first; 17355c7b7a2SEd Tanous BMCWEB_LOG_DEBUG << "Got path: " << path; 1741abe55efSEd Tanous const std::vector< 1751214b7e7SGunnar Mills std::pair<std::string, std::vector<std::string>>>& 1761214b7e7SGunnar Mills connectionNames = object.second; 1771abe55efSEd Tanous if (connectionNames.size() < 1) 1781abe55efSEd Tanous { 179c5b2abe0SLewanczyk, Dawid continue; 180c5b2abe0SLewanczyk, Dawid } 181029573d4SEd Tanous 1825bc2dc8eSJames Feist auto memoryHealth = std::make_shared<HealthPopulate>( 1835bc2dc8eSJames Feist aResp, aResp->res.jsonValue["MemorySummary"]["Status"]); 1845bc2dc8eSJames Feist 1855bc2dc8eSJames Feist auto cpuHealth = std::make_shared<HealthPopulate>( 1865bc2dc8eSJames Feist aResp, aResp->res.jsonValue["ProcessorSummary"]["Status"]); 1875bc2dc8eSJames Feist 1885bc2dc8eSJames Feist systemHealth->children.emplace_back(memoryHealth); 1895bc2dc8eSJames Feist systemHealth->children.emplace_back(cpuHealth); 1905bc2dc8eSJames Feist 1916c34de48SEd Tanous // This is not system, so check if it's cpu, dimm, UUID or 1926c34de48SEd Tanous // BiosVer 19304a258f4SEd Tanous for (const auto& connection : connectionNames) 1941abe55efSEd Tanous { 19504a258f4SEd Tanous for (const auto& interfaceName : connection.second) 1961abe55efSEd Tanous { 19704a258f4SEd Tanous if (interfaceName == 19804a258f4SEd Tanous "xyz.openbmc_project.Inventory.Item.Dimm") 1991abe55efSEd Tanous { 2001abe55efSEd Tanous BMCWEB_LOG_DEBUG 20104a258f4SEd Tanous << "Found Dimm, now get its properties."; 2029d3ae10eSAlpana Kumari 20355c7b7a2SEd Tanous crow::connections::systemBus->async_method_call( 2049d3ae10eSAlpana Kumari [aResp, service{connection.first}, 205f23b7296SEd Tanous path](const boost::system::error_code ec2, 2066c34de48SEd Tanous const std::vector< 2071214b7e7SGunnar Mills std::pair<std::string, VariantType>>& 2081214b7e7SGunnar Mills properties) { 209cb13a392SEd Tanous if (ec2) 2101abe55efSEd Tanous { 2111abe55efSEd Tanous BMCWEB_LOG_ERROR 212cb13a392SEd Tanous << "DBUS response error " << ec2; 213f12894f8SJason M. Bills messages::internalError(aResp->res); 214c5b2abe0SLewanczyk, Dawid return; 215c5b2abe0SLewanczyk, Dawid } 2166c34de48SEd Tanous BMCWEB_LOG_DEBUG << "Got " 2176c34de48SEd Tanous << properties.size() 218c5b2abe0SLewanczyk, Dawid << " Dimm properties."; 2199d3ae10eSAlpana Kumari 2209d3ae10eSAlpana Kumari if (properties.size() > 0) 2219d3ae10eSAlpana Kumari { 22204a258f4SEd Tanous for (const std::pair<std::string, 2231214b7e7SGunnar Mills VariantType>& 2241214b7e7SGunnar Mills property : properties) 2251abe55efSEd Tanous { 2265fd7ba65SCheng C Yang if (property.first != 2275fd7ba65SCheng C Yang "MemorySizeInKB") 2281abe55efSEd Tanous { 2295fd7ba65SCheng C Yang continue; 2305fd7ba65SCheng C Yang } 2315fd7ba65SCheng C Yang const uint32_t* value = 2328d78b7a9SPatrick Williams std::get_if<uint32_t>( 2331b6b96c5SEd Tanous &property.second); 2345fd7ba65SCheng C Yang if (value == nullptr) 2351abe55efSEd Tanous { 2365fd7ba65SCheng C Yang BMCWEB_LOG_DEBUG 2375fd7ba65SCheng C Yang << "Find incorrect type of " 2385fd7ba65SCheng C Yang "MemorySize"; 2395fd7ba65SCheng C Yang continue; 2405fd7ba65SCheng C Yang } 2415fd7ba65SCheng C Yang nlohmann::json& totalMemory = 2425fd7ba65SCheng C Yang aResp->res 2435fd7ba65SCheng C Yang .jsonValue["MemorySummar" 2445fd7ba65SCheng C Yang "y"] 2455fd7ba65SCheng C Yang ["TotalSystemMe" 2465fd7ba65SCheng C Yang "moryGiB"]; 2475fd7ba65SCheng C Yang uint64_t* preValue = 2485fd7ba65SCheng C Yang totalMemory 2495fd7ba65SCheng C Yang .get_ptr<uint64_t*>(); 2505fd7ba65SCheng C Yang if (preValue == nullptr) 2515fd7ba65SCheng C Yang { 2525fd7ba65SCheng C Yang continue; 2535fd7ba65SCheng C Yang } 2545fd7ba65SCheng C Yang aResp->res 2555fd7ba65SCheng C Yang .jsonValue["MemorySummary"] 2566c34de48SEd Tanous ["TotalSystemMemoryGi" 2575fd7ba65SCheng C Yang "B"] = 2585fd7ba65SCheng C Yang *value / (1024 * 1024) + 2595fd7ba65SCheng C Yang *preValue; 2605fd7ba65SCheng C Yang aResp->res 2615fd7ba65SCheng C Yang .jsonValue["MemorySummary"] 2629d3ae10eSAlpana Kumari ["Status"]["State"] = 2631abe55efSEd Tanous "Enabled"; 264c5b2abe0SLewanczyk, Dawid } 265c5b2abe0SLewanczyk, Dawid } 2669d3ae10eSAlpana Kumari else 2679d3ae10eSAlpana Kumari { 2689d3ae10eSAlpana Kumari auto getDimmProperties = 2699d3ae10eSAlpana Kumari [aResp]( 2709d3ae10eSAlpana Kumari const boost::system::error_code 271cb13a392SEd Tanous ec3, 2721214b7e7SGunnar Mills const std::variant<bool>& 2731214b7e7SGunnar Mills dimmState) { 274cb13a392SEd Tanous if (ec3) 2759d3ae10eSAlpana Kumari { 2769d3ae10eSAlpana Kumari BMCWEB_LOG_ERROR 2779d3ae10eSAlpana Kumari << "DBUS response " 2789d3ae10eSAlpana Kumari "error " 279cb13a392SEd Tanous << ec3; 2809d3ae10eSAlpana Kumari return; 2819d3ae10eSAlpana Kumari } 2829d3ae10eSAlpana Kumari updateDimmProperties(aResp, 2839d3ae10eSAlpana Kumari dimmState); 2849d3ae10eSAlpana Kumari }; 2859d3ae10eSAlpana Kumari crow::connections::systemBus 2869d3ae10eSAlpana Kumari ->async_method_call( 2879d3ae10eSAlpana Kumari std::move(getDimmProperties), 2889d3ae10eSAlpana Kumari service, path, 2899d3ae10eSAlpana Kumari "org.freedesktop.DBus." 2909d3ae10eSAlpana Kumari "Properties", 2919d3ae10eSAlpana Kumari "Get", 2929d3ae10eSAlpana Kumari "xyz.openbmc_project.State." 2939d3ae10eSAlpana Kumari "Decorator.OperationalStatus", 2949d3ae10eSAlpana Kumari "Functional"); 2959d3ae10eSAlpana Kumari } 296c5b2abe0SLewanczyk, Dawid }, 29704a258f4SEd Tanous connection.first, path, 2986c34de48SEd Tanous "org.freedesktop.DBus.Properties", "GetAll", 2996c34de48SEd Tanous "xyz.openbmc_project.Inventory.Item.Dimm"); 3005bc2dc8eSJames Feist 3015bc2dc8eSJames Feist memoryHealth->inventory.emplace_back(path); 3021abe55efSEd Tanous } 30304a258f4SEd Tanous else if (interfaceName == 30404a258f4SEd Tanous "xyz.openbmc_project.Inventory.Item.Cpu") 3051abe55efSEd Tanous { 3061abe55efSEd Tanous BMCWEB_LOG_DEBUG 30704a258f4SEd Tanous << "Found Cpu, now get its properties."; 30857e8c9beSAlpana Kumari 309a0803efaSEd Tanous crow::connections::systemBus->async_method_call( 31057e8c9beSAlpana Kumari [aResp, service{connection.first}, 311f23b7296SEd Tanous path](const boost::system::error_code ec2, 3126c34de48SEd Tanous const std::vector< 3131214b7e7SGunnar Mills std::pair<std::string, VariantType>>& 3141214b7e7SGunnar Mills properties) { 315cb13a392SEd Tanous if (ec2) 3161abe55efSEd Tanous { 3171abe55efSEd Tanous BMCWEB_LOG_ERROR 318cb13a392SEd Tanous << "DBUS response error " << ec2; 319f12894f8SJason M. Bills messages::internalError(aResp->res); 320c5b2abe0SLewanczyk, Dawid return; 321c5b2abe0SLewanczyk, Dawid } 3226c34de48SEd Tanous BMCWEB_LOG_DEBUG << "Got " 3236c34de48SEd Tanous << properties.size() 324c5b2abe0SLewanczyk, Dawid << " Cpu properties."; 32557e8c9beSAlpana Kumari 32657e8c9beSAlpana Kumari if (properties.size() > 0) 32757e8c9beSAlpana Kumari { 3289cf21522SZhikui Ren const uint64_t* processorId = nullptr; 329029cc1f4SZhikui Ren const std::string* procFamily = nullptr; 330029cc1f4SZhikui Ren nlohmann::json& procSummary = 331029cc1f4SZhikui Ren aResp->res.jsonValue["ProcessorSumm" 33204a258f4SEd Tanous "ary"]; 33304a258f4SEd Tanous nlohmann::json& procCount = 33404a258f4SEd Tanous procSummary["Count"]; 335b4b9595aSJames Feist 336029cc1f4SZhikui Ren auto procCountPtr = procCount.get_ptr< 337b4b9595aSJames Feist nlohmann::json:: 3381214b7e7SGunnar Mills number_integer_t*>(); 339029cc1f4SZhikui Ren if (procCountPtr == nullptr) 340b4b9595aSJames Feist { 341029cc1f4SZhikui Ren messages::internalError(aResp->res); 342029cc1f4SZhikui Ren return; 343029cc1f4SZhikui Ren } 344029cc1f4SZhikui Ren for (const auto& property : properties) 345029cc1f4SZhikui Ren { 346029cc1f4SZhikui Ren 3479cf21522SZhikui Ren if (property.first == "Id") 348029cc1f4SZhikui Ren { 349029cc1f4SZhikui Ren processorId = 3509cf21522SZhikui Ren std::get_if<uint64_t>( 351029cc1f4SZhikui Ren &property.second); 352029cc1f4SZhikui Ren if (nullptr != procFamily) 3533174e4dfSEd Tanous { 354029cc1f4SZhikui Ren break; 3553174e4dfSEd Tanous } 356029cc1f4SZhikui Ren continue; 357029cc1f4SZhikui Ren } 358029cc1f4SZhikui Ren 3599cf21522SZhikui Ren if (property.first == "Family") 360029cc1f4SZhikui Ren { 361029cc1f4SZhikui Ren procFamily = 362029cc1f4SZhikui Ren std::get_if<std::string>( 363029cc1f4SZhikui Ren &property.second); 364029cc1f4SZhikui Ren if (nullptr != processorId) 3653174e4dfSEd Tanous { 366029cc1f4SZhikui Ren break; 3673174e4dfSEd Tanous } 368029cc1f4SZhikui Ren continue; 369029cc1f4SZhikui Ren } 370029cc1f4SZhikui Ren } 371029cc1f4SZhikui Ren 372029cc1f4SZhikui Ren if (procFamily != nullptr && 373029cc1f4SZhikui Ren processorId != nullptr) 374029cc1f4SZhikui Ren { 375029cc1f4SZhikui Ren if (procCountPtr != nullptr && 376029cc1f4SZhikui Ren *processorId != 0) 377029cc1f4SZhikui Ren { 378b4b9595aSJames Feist *procCountPtr += 1; 379029cc1f4SZhikui Ren procSummary["Status"]["State"] = 380c5b2abe0SLewanczyk, Dawid "Enabled"; 381029cc1f4SZhikui Ren 38257e8c9beSAlpana Kumari procSummary["Model"] = 383029cc1f4SZhikui Ren *procFamily; 384c5b2abe0SLewanczyk, Dawid } 385c5b2abe0SLewanczyk, Dawid } 38657e8c9beSAlpana Kumari } 38757e8c9beSAlpana Kumari else 38857e8c9beSAlpana Kumari { 38957e8c9beSAlpana Kumari auto getCpuPresenceState = 39057e8c9beSAlpana Kumari [aResp]( 39157e8c9beSAlpana Kumari const boost::system::error_code 392cb13a392SEd Tanous ec3, 3931214b7e7SGunnar Mills const std::variant<bool>& 3941214b7e7SGunnar Mills cpuPresenceCheck) { 395cb13a392SEd Tanous if (ec3) 39657e8c9beSAlpana Kumari { 39757e8c9beSAlpana Kumari BMCWEB_LOG_ERROR 39857e8c9beSAlpana Kumari << "DBUS response " 39957e8c9beSAlpana Kumari "error " 400cb13a392SEd Tanous << ec3; 40157e8c9beSAlpana Kumari return; 40257e8c9beSAlpana Kumari } 40357e8c9beSAlpana Kumari modifyCpuPresenceState( 40457e8c9beSAlpana Kumari aResp, cpuPresenceCheck); 40557e8c9beSAlpana Kumari }; 40657e8c9beSAlpana Kumari 40757e8c9beSAlpana Kumari auto getCpuFunctionalState = 40857e8c9beSAlpana Kumari [aResp]( 40957e8c9beSAlpana Kumari const boost::system::error_code 410cb13a392SEd Tanous ec3, 4111214b7e7SGunnar Mills const std::variant<bool>& 4121214b7e7SGunnar Mills cpuFunctionalCheck) { 413cb13a392SEd Tanous if (ec3) 41457e8c9beSAlpana Kumari { 41557e8c9beSAlpana Kumari BMCWEB_LOG_ERROR 41657e8c9beSAlpana Kumari << "DBUS response " 41757e8c9beSAlpana Kumari "error " 418cb13a392SEd Tanous << ec3; 41957e8c9beSAlpana Kumari return; 42057e8c9beSAlpana Kumari } 42157e8c9beSAlpana Kumari modifyCpuFunctionalState( 42257e8c9beSAlpana Kumari aResp, cpuFunctionalCheck); 42357e8c9beSAlpana Kumari }; 42457e8c9beSAlpana Kumari // Get the Presence of CPU 42557e8c9beSAlpana Kumari crow::connections::systemBus 42657e8c9beSAlpana Kumari ->async_method_call( 42757e8c9beSAlpana Kumari std::move(getCpuPresenceState), 42857e8c9beSAlpana Kumari service, path, 42957e8c9beSAlpana Kumari "org.freedesktop.DBus." 43057e8c9beSAlpana Kumari "Properties", 43157e8c9beSAlpana Kumari "Get", 43257e8c9beSAlpana Kumari "xyz.openbmc_project.Inventory." 43357e8c9beSAlpana Kumari "Item", 43457e8c9beSAlpana Kumari "Present"); 43557e8c9beSAlpana Kumari 43657e8c9beSAlpana Kumari // Get the Functional State 43757e8c9beSAlpana Kumari crow::connections::systemBus 43857e8c9beSAlpana Kumari ->async_method_call( 43957e8c9beSAlpana Kumari std::move( 44057e8c9beSAlpana Kumari getCpuFunctionalState), 44157e8c9beSAlpana Kumari service, path, 44257e8c9beSAlpana Kumari "org.freedesktop.DBus." 44357e8c9beSAlpana Kumari "Properties", 44457e8c9beSAlpana Kumari "Get", 44557e8c9beSAlpana Kumari "xyz.openbmc_project.State." 44657e8c9beSAlpana Kumari "Decorator." 44757e8c9beSAlpana Kumari "OperationalStatus", 44857e8c9beSAlpana Kumari "Functional"); 44957e8c9beSAlpana Kumari 45057e8c9beSAlpana Kumari // Get the MODEL from 45157e8c9beSAlpana Kumari // xyz.openbmc_project.Inventory.Decorator.Asset 45257e8c9beSAlpana Kumari // support it later as Model is Empty 45357e8c9beSAlpana Kumari // currently. 45457e8c9beSAlpana Kumari } 455c5b2abe0SLewanczyk, Dawid }, 45604a258f4SEd Tanous connection.first, path, 4576c34de48SEd Tanous "org.freedesktop.DBus.Properties", "GetAll", 4586c34de48SEd Tanous "xyz.openbmc_project.Inventory.Item.Cpu"); 4595bc2dc8eSJames Feist 4605bc2dc8eSJames Feist cpuHealth->inventory.emplace_back(path); 4611abe55efSEd Tanous } 46204a258f4SEd Tanous else if (interfaceName == 46304a258f4SEd Tanous "xyz.openbmc_project.Common.UUID") 4641abe55efSEd Tanous { 4651abe55efSEd Tanous BMCWEB_LOG_DEBUG 46604a258f4SEd Tanous << "Found UUID, now get its properties."; 46755c7b7a2SEd Tanous crow::connections::systemBus->async_method_call( 4681214b7e7SGunnar Mills [aResp]( 469cb13a392SEd Tanous const boost::system::error_code ec3, 4706c34de48SEd Tanous const std::vector< 4711214b7e7SGunnar Mills std::pair<std::string, VariantType>>& 4721214b7e7SGunnar Mills properties) { 473cb13a392SEd Tanous if (ec3) 4741abe55efSEd Tanous { 4751abe55efSEd Tanous BMCWEB_LOG_DEBUG 476cb13a392SEd Tanous << "DBUS response error " << ec3; 477f12894f8SJason M. Bills messages::internalError(aResp->res); 478c5b2abe0SLewanczyk, Dawid return; 479c5b2abe0SLewanczyk, Dawid } 4806c34de48SEd Tanous BMCWEB_LOG_DEBUG << "Got " 4816c34de48SEd Tanous << properties.size() 482c5b2abe0SLewanczyk, Dawid << " UUID properties."; 4831abe55efSEd Tanous for (const std::pair<std::string, 4841214b7e7SGunnar Mills VariantType>& 4851214b7e7SGunnar Mills property : properties) 4861abe55efSEd Tanous { 48704a258f4SEd Tanous if (property.first == "UUID") 4881abe55efSEd Tanous { 489c5b2abe0SLewanczyk, Dawid const std::string* value = 4908d78b7a9SPatrick Williams std::get_if<std::string>( 4911b6b96c5SEd Tanous &property.second); 49204a258f4SEd Tanous 4931abe55efSEd Tanous if (value != nullptr) 4941abe55efSEd Tanous { 495029573d4SEd Tanous std::string valueStr = *value; 49604a258f4SEd Tanous if (valueStr.size() == 32) 4971abe55efSEd Tanous { 498029573d4SEd Tanous valueStr.insert(8, 1, '-'); 499029573d4SEd Tanous valueStr.insert(13, 1, '-'); 500029573d4SEd Tanous valueStr.insert(18, 1, '-'); 501029573d4SEd Tanous valueStr.insert(23, 1, '-'); 50204a258f4SEd Tanous } 503029573d4SEd Tanous BMCWEB_LOG_DEBUG << "UUID = " 50404a258f4SEd Tanous << valueStr; 505029573d4SEd Tanous aResp->res.jsonValue["UUID"] = 50604a258f4SEd Tanous valueStr; 507c5b2abe0SLewanczyk, Dawid } 508c5b2abe0SLewanczyk, Dawid } 509c5b2abe0SLewanczyk, Dawid } 510c5b2abe0SLewanczyk, Dawid }, 51104a258f4SEd Tanous connection.first, path, 5126c34de48SEd Tanous "org.freedesktop.DBus.Properties", "GetAll", 5131abe55efSEd Tanous "xyz.openbmc_project.Common.UUID"); 514c5b2abe0SLewanczyk, Dawid } 515029573d4SEd Tanous else if (interfaceName == 516029573d4SEd Tanous "xyz.openbmc_project.Inventory.Item.System") 5171abe55efSEd Tanous { 518029573d4SEd Tanous crow::connections::systemBus->async_method_call( 5191214b7e7SGunnar Mills [aResp]( 520cb13a392SEd Tanous const boost::system::error_code ec2, 521029573d4SEd Tanous const std::vector< 5221214b7e7SGunnar Mills std::pair<std::string, VariantType>>& 5231214b7e7SGunnar Mills propertiesList) { 524cb13a392SEd Tanous if (ec2) 525029573d4SEd Tanous { 526e4a4b9a9SJames Feist // doesn't have to include this 527e4a4b9a9SJames Feist // interface 528029573d4SEd Tanous return; 529029573d4SEd Tanous } 530698654b6SGunnar Mills BMCWEB_LOG_DEBUG 531698654b6SGunnar Mills << "Got " << propertiesList.size() 532029573d4SEd Tanous << " properties for system"; 533029573d4SEd Tanous for (const std::pair<std::string, 5341214b7e7SGunnar Mills VariantType>& 5351214b7e7SGunnar Mills property : propertiesList) 536029573d4SEd Tanous { 537fc5afcf9Sbeccabroek const std::string& propertyName = 538fc5afcf9Sbeccabroek property.first; 539fc5afcf9Sbeccabroek if ((propertyName == "PartNumber") || 540fc5afcf9Sbeccabroek (propertyName == "SerialNumber") || 541fc5afcf9Sbeccabroek (propertyName == "Manufacturer") || 5425235d964SSunnySrivastava1984 (propertyName == "Model") || 5435235d964SSunnySrivastava1984 (propertyName == "SubModel")) 544fc5afcf9Sbeccabroek { 545029573d4SEd Tanous const std::string* value = 546fc5afcf9Sbeccabroek std::get_if<std::string>( 547029573d4SEd Tanous &property.second); 548029573d4SEd Tanous if (value != nullptr) 549029573d4SEd Tanous { 550029573d4SEd Tanous aResp->res 551fc5afcf9Sbeccabroek .jsonValue[propertyName] = 552029573d4SEd Tanous *value; 553029573d4SEd Tanous } 554029573d4SEd Tanous } 555fc5afcf9Sbeccabroek } 556c1e236a6SGunnar Mills 557cb7e1e7bSAndrew Geissler // Grab the bios version 558f97ddba7SGunnar Mills fw_util::populateFirmwareInformation( 559cb7e1e7bSAndrew Geissler aResp, fw_util::biosPurpose, 56072d566d9SGunnar Mills "BiosVersion", false); 561029573d4SEd Tanous }, 562029573d4SEd Tanous connection.first, path, 563029573d4SEd Tanous "org.freedesktop.DBus.Properties", "GetAll", 564029573d4SEd Tanous "xyz.openbmc_project.Inventory.Decorator." 565029573d4SEd Tanous "Asset"); 566e4a4b9a9SJames Feist 567e4a4b9a9SJames Feist crow::connections::systemBus->async_method_call( 568e4a4b9a9SJames Feist [aResp]( 569cb13a392SEd Tanous const boost::system::error_code ec2, 570e4a4b9a9SJames Feist const std::variant<std::string>& property) { 571cb13a392SEd Tanous if (ec2) 572e4a4b9a9SJames Feist { 573e4a4b9a9SJames Feist // doesn't have to include this 574e4a4b9a9SJames Feist // interface 575e4a4b9a9SJames Feist return; 576e4a4b9a9SJames Feist } 577e4a4b9a9SJames Feist 578e4a4b9a9SJames Feist const std::string* value = 579e4a4b9a9SJames Feist std::get_if<std::string>(&property); 580e4a4b9a9SJames Feist if (value != nullptr) 581e4a4b9a9SJames Feist { 582e4a4b9a9SJames Feist aResp->res.jsonValue["AssetTag"] = 583e4a4b9a9SJames Feist *value; 584e4a4b9a9SJames Feist } 585e4a4b9a9SJames Feist }, 586e4a4b9a9SJames Feist connection.first, path, 587e4a4b9a9SJames Feist "org.freedesktop.DBus.Properties", "Get", 588e4a4b9a9SJames Feist "xyz.openbmc_project.Inventory.Decorator." 589e4a4b9a9SJames Feist "AssetTag", 590e4a4b9a9SJames Feist "AssetTag"); 591029573d4SEd Tanous } 592029573d4SEd Tanous } 593029573d4SEd Tanous } 594c5b2abe0SLewanczyk, Dawid } 595c5b2abe0SLewanczyk, Dawid }, 596c5b2abe0SLewanczyk, Dawid "xyz.openbmc_project.ObjectMapper", 597c5b2abe0SLewanczyk, Dawid "/xyz/openbmc_project/object_mapper", 598c5b2abe0SLewanczyk, Dawid "xyz.openbmc_project.ObjectMapper", "GetSubTree", 5996617338dSEd Tanous "/xyz/openbmc_project/inventory", int32_t(0), 6006617338dSEd Tanous std::array<const char*, 5>{ 6016617338dSEd Tanous "xyz.openbmc_project.Inventory.Decorator.Asset", 6026617338dSEd Tanous "xyz.openbmc_project.Inventory.Item.Cpu", 6036617338dSEd Tanous "xyz.openbmc_project.Inventory.Item.Dimm", 6046617338dSEd Tanous "xyz.openbmc_project.Inventory.Item.System", 6056617338dSEd Tanous "xyz.openbmc_project.Common.UUID", 6066617338dSEd Tanous }); 607c5b2abe0SLewanczyk, Dawid } 608c5b2abe0SLewanczyk, Dawid 609c5b2abe0SLewanczyk, Dawid /** 610c5b2abe0SLewanczyk, Dawid * @brief Retrieves host state properties over dbus 611c5b2abe0SLewanczyk, Dawid * 612c5b2abe0SLewanczyk, Dawid * @param[in] aResp Shared pointer for completing asynchronous calls. 613c5b2abe0SLewanczyk, Dawid * 614c5b2abe0SLewanczyk, Dawid * @return None. 615c5b2abe0SLewanczyk, Dawid */ 616b5a76932SEd Tanous inline void getHostState(const std::shared_ptr<AsyncResp>& aResp) 6171abe55efSEd Tanous { 61855c7b7a2SEd Tanous BMCWEB_LOG_DEBUG << "Get host information."; 61955c7b7a2SEd Tanous crow::connections::systemBus->async_method_call( 620c5d03ff4SJennifer Lee [aResp](const boost::system::error_code ec, 621abf2add6SEd Tanous const std::variant<std::string>& hostState) { 6221abe55efSEd Tanous if (ec) 6231abe55efSEd Tanous { 62455c7b7a2SEd Tanous BMCWEB_LOG_DEBUG << "DBUS response error " << ec; 625f12894f8SJason M. Bills messages::internalError(aResp->res); 626c5b2abe0SLewanczyk, Dawid return; 627c5b2abe0SLewanczyk, Dawid } 6286617338dSEd Tanous 629abf2add6SEd Tanous const std::string* s = std::get_if<std::string>(&hostState); 63055c7b7a2SEd Tanous BMCWEB_LOG_DEBUG << "Host state: " << *s; 6316617338dSEd Tanous if (s != nullptr) 6321abe55efSEd Tanous { 633c5b2abe0SLewanczyk, Dawid // Verify Host State 63494732661SAndrew Geissler if (*s == "xyz.openbmc_project.State.Host.HostState.Running") 6351abe55efSEd Tanous { 63655c7b7a2SEd Tanous aResp->res.jsonValue["PowerState"] = "On"; 6376617338dSEd Tanous aResp->res.jsonValue["Status"]["State"] = "Enabled"; 6381abe55efSEd Tanous } 63983935af9SAndrew Geissler else if (*s == "xyz.openbmc_project.State.Host.HostState." 6408c888608SGunnar Mills "Quiesced") 6418c888608SGunnar Mills { 6428c888608SGunnar Mills aResp->res.jsonValue["PowerState"] = "On"; 6438c888608SGunnar Mills aResp->res.jsonValue["Status"]["State"] = "Quiesced"; 6448c888608SGunnar Mills } 6458c888608SGunnar Mills else if (*s == "xyz.openbmc_project.State.Host.HostState." 64683935af9SAndrew Geissler "DiagnosticMode") 64783935af9SAndrew Geissler { 64883935af9SAndrew Geissler aResp->res.jsonValue["PowerState"] = "On"; 64983935af9SAndrew Geissler aResp->res.jsonValue["Status"]["State"] = "InTest"; 65083935af9SAndrew Geissler } 6511a2a1437SAndrew Geissler else if (*s == "xyz.openbmc_project.State.Host.HostState." 6521a2a1437SAndrew Geissler "TransitioningToRunning") 6531a2a1437SAndrew Geissler { 6541a2a1437SAndrew Geissler aResp->res.jsonValue["PowerState"] = "PoweringOn"; 6551a2a1437SAndrew Geissler aResp->res.jsonValue["Status"]["State"] = "Disabled"; 6561a2a1437SAndrew Geissler } 6571a2a1437SAndrew Geissler else if (*s == "xyz.openbmc_project.State.Host.HostState." 6581a2a1437SAndrew Geissler "TransitioningToOff") 6591a2a1437SAndrew Geissler { 6601a2a1437SAndrew Geissler aResp->res.jsonValue["PowerState"] = "PoweringOff"; 6611a2a1437SAndrew Geissler aResp->res.jsonValue["Status"]["State"] = "Disabled"; 6621a2a1437SAndrew Geissler } 6631abe55efSEd Tanous else 6641abe55efSEd Tanous { 66555c7b7a2SEd Tanous aResp->res.jsonValue["PowerState"] = "Off"; 6666617338dSEd Tanous aResp->res.jsonValue["Status"]["State"] = "Disabled"; 667c5b2abe0SLewanczyk, Dawid } 668c5b2abe0SLewanczyk, Dawid } 669c5b2abe0SLewanczyk, Dawid }, 6706c34de48SEd Tanous "xyz.openbmc_project.State.Host", "/xyz/openbmc_project/state/host0", 6716617338dSEd Tanous "org.freedesktop.DBus.Properties", "Get", 6726617338dSEd Tanous "xyz.openbmc_project.State.Host", "CurrentHostState"); 673c5b2abe0SLewanczyk, Dawid } 674c5b2abe0SLewanczyk, Dawid 675c5b2abe0SLewanczyk, Dawid /** 676786d0f60SGunnar Mills * @brief Translates boot source DBUS property value to redfish. 677491d8ee7SSantosh Puranik * 678491d8ee7SSantosh Puranik * @param[in] dbusSource The boot source in DBUS speak. 679491d8ee7SSantosh Puranik * 680491d8ee7SSantosh Puranik * @return Returns as a string, the boot source in Redfish terms. If translation 681491d8ee7SSantosh Puranik * cannot be done, returns an empty string. 682491d8ee7SSantosh Puranik */ 68323a21a1cSEd Tanous inline std::string dbusToRfBootSource(const std::string& dbusSource) 684491d8ee7SSantosh Puranik { 685491d8ee7SSantosh Puranik if (dbusSource == "xyz.openbmc_project.Control.Boot.Source.Sources.Default") 686491d8ee7SSantosh Puranik { 687491d8ee7SSantosh Puranik return "None"; 688491d8ee7SSantosh Puranik } 6893174e4dfSEd Tanous if (dbusSource == "xyz.openbmc_project.Control.Boot.Source.Sources.Disk") 690491d8ee7SSantosh Puranik { 691491d8ee7SSantosh Puranik return "Hdd"; 692491d8ee7SSantosh Puranik } 6933174e4dfSEd Tanous if (dbusSource == 694a71dc0b7SSantosh Puranik "xyz.openbmc_project.Control.Boot.Source.Sources.ExternalMedia") 695491d8ee7SSantosh Puranik { 696491d8ee7SSantosh Puranik return "Cd"; 697491d8ee7SSantosh Puranik } 6983174e4dfSEd Tanous if (dbusSource == "xyz.openbmc_project.Control.Boot.Source.Sources.Network") 699491d8ee7SSantosh Puranik { 700491d8ee7SSantosh Puranik return "Pxe"; 701491d8ee7SSantosh Puranik } 7023174e4dfSEd Tanous if (dbusSource == 703944ffaf9SJohnathan Mantey "xyz.openbmc_project.Control.Boot.Source.Sources.RemovableMedia") 7049f16b2c1SJennifer Lee { 7059f16b2c1SJennifer Lee return "Usb"; 7069f16b2c1SJennifer Lee } 707491d8ee7SSantosh Puranik return ""; 708491d8ee7SSantosh Puranik } 709491d8ee7SSantosh Puranik 710491d8ee7SSantosh Puranik /** 711786d0f60SGunnar Mills * @brief Translates boot mode DBUS property value to redfish. 712491d8ee7SSantosh Puranik * 713491d8ee7SSantosh Puranik * @param[in] dbusMode The boot mode in DBUS speak. 714491d8ee7SSantosh Puranik * 715491d8ee7SSantosh Puranik * @return Returns as a string, the boot mode in Redfish terms. If translation 716491d8ee7SSantosh Puranik * cannot be done, returns an empty string. 717491d8ee7SSantosh Puranik */ 71823a21a1cSEd Tanous inline std::string dbusToRfBootMode(const std::string& dbusMode) 719491d8ee7SSantosh Puranik { 720491d8ee7SSantosh Puranik if (dbusMode == "xyz.openbmc_project.Control.Boot.Mode.Modes.Regular") 721491d8ee7SSantosh Puranik { 722491d8ee7SSantosh Puranik return "None"; 723491d8ee7SSantosh Puranik } 7243174e4dfSEd Tanous if (dbusMode == "xyz.openbmc_project.Control.Boot.Mode.Modes.Safe") 725491d8ee7SSantosh Puranik { 726491d8ee7SSantosh Puranik return "Diags"; 727491d8ee7SSantosh Puranik } 7283174e4dfSEd Tanous if (dbusMode == "xyz.openbmc_project.Control.Boot.Mode.Modes.Setup") 729491d8ee7SSantosh Puranik { 730491d8ee7SSantosh Puranik return "BiosSetup"; 731491d8ee7SSantosh Puranik } 732491d8ee7SSantosh Puranik return ""; 733491d8ee7SSantosh Puranik } 734491d8ee7SSantosh Puranik 735491d8ee7SSantosh Puranik /** 736786d0f60SGunnar Mills * @brief Translates boot source from Redfish to the DBus boot paths. 737491d8ee7SSantosh Puranik * 738491d8ee7SSantosh Puranik * @param[in] rfSource The boot source in Redfish. 739944ffaf9SJohnathan Mantey * @param[out] bootSource The DBus source 740944ffaf9SJohnathan Mantey * @param[out] bootMode the DBus boot mode 741491d8ee7SSantosh Puranik * 742944ffaf9SJohnathan Mantey * @return Integer error code. 743491d8ee7SSantosh Puranik */ 744b5a76932SEd Tanous inline int assignBootParameters(const std::shared_ptr<AsyncResp>& aResp, 745944ffaf9SJohnathan Mantey const std::string& rfSource, 746944ffaf9SJohnathan Mantey std::string& bootSource, std::string& bootMode) 747491d8ee7SSantosh Puranik { 748944ffaf9SJohnathan Mantey // The caller has initialized the bootSource and bootMode to: 749944ffaf9SJohnathan Mantey // bootMode = "xyz.openbmc_project.Control.Boot.Mode.Modes.Regular"; 750944ffaf9SJohnathan Mantey // bootSource = "xyz.openbmc_project.Control.Boot.Source.Sources.Default"; 751944ffaf9SJohnathan Mantey // Only modify the bootSource/bootMode variable needed to achieve the 752944ffaf9SJohnathan Mantey // desired boot action. 753944ffaf9SJohnathan Mantey 754491d8ee7SSantosh Puranik if (rfSource == "None") 755491d8ee7SSantosh Puranik { 756944ffaf9SJohnathan Mantey return 0; 757491d8ee7SSantosh Puranik } 7583174e4dfSEd Tanous if (rfSource == "Pxe") 759491d8ee7SSantosh Puranik { 760944ffaf9SJohnathan Mantey bootSource = "xyz.openbmc_project.Control.Boot.Source.Sources.Network"; 761944ffaf9SJohnathan Mantey } 762944ffaf9SJohnathan Mantey else if (rfSource == "Hdd") 763944ffaf9SJohnathan Mantey { 764944ffaf9SJohnathan Mantey bootSource = "xyz.openbmc_project.Control.Boot.Source.Sources.Disk"; 765944ffaf9SJohnathan Mantey } 766944ffaf9SJohnathan Mantey else if (rfSource == "Diags") 767944ffaf9SJohnathan Mantey { 768944ffaf9SJohnathan Mantey bootMode = "xyz.openbmc_project.Control.Boot.Mode.Modes.Safe"; 769944ffaf9SJohnathan Mantey } 770944ffaf9SJohnathan Mantey else if (rfSource == "Cd") 771944ffaf9SJohnathan Mantey { 772944ffaf9SJohnathan Mantey bootSource = 773944ffaf9SJohnathan Mantey "xyz.openbmc_project.Control.Boot.Source.Sources.ExternalMedia"; 774944ffaf9SJohnathan Mantey } 775944ffaf9SJohnathan Mantey else if (rfSource == "BiosSetup") 776944ffaf9SJohnathan Mantey { 777944ffaf9SJohnathan Mantey bootMode = "xyz.openbmc_project.Control.Boot.Mode.Modes.Setup"; 778491d8ee7SSantosh Puranik } 7799f16b2c1SJennifer Lee else if (rfSource == "Usb") 7809f16b2c1SJennifer Lee { 781944ffaf9SJohnathan Mantey bootSource = 782944ffaf9SJohnathan Mantey "xyz.openbmc_project.Control.Boot.Source.Sources.RemovableMedia"; 7839f16b2c1SJennifer Lee } 784491d8ee7SSantosh Puranik else 785491d8ee7SSantosh Puranik { 786944ffaf9SJohnathan Mantey BMCWEB_LOG_DEBUG << "Invalid property value for " 787944ffaf9SJohnathan Mantey "BootSourceOverrideTarget: " 788944ffaf9SJohnathan Mantey << bootSource; 789944ffaf9SJohnathan Mantey messages::propertyValueNotInList(aResp->res, rfSource, 790944ffaf9SJohnathan Mantey "BootSourceTargetOverride"); 791944ffaf9SJohnathan Mantey return -1; 792491d8ee7SSantosh Puranik } 793944ffaf9SJohnathan Mantey return 0; 794491d8ee7SSantosh Puranik } 795978b8803SAndrew Geissler /** 796978b8803SAndrew Geissler * @brief Retrieves boot progress of the system 797978b8803SAndrew Geissler * 798978b8803SAndrew Geissler * @param[in] aResp Shared pointer for generating response message. 799978b8803SAndrew Geissler * 800978b8803SAndrew Geissler * @return None. 801978b8803SAndrew Geissler */ 802978b8803SAndrew Geissler inline void getBootProgress(const std::shared_ptr<AsyncResp>& aResp) 803978b8803SAndrew Geissler { 804978b8803SAndrew Geissler crow::connections::systemBus->async_method_call( 805978b8803SAndrew Geissler [aResp](const boost::system::error_code ec, 806978b8803SAndrew Geissler const std::variant<std::string>& bootProgress) { 807978b8803SAndrew Geissler if (ec) 808978b8803SAndrew Geissler { 809978b8803SAndrew Geissler // BootProgress is an optional object so just do nothing if 810978b8803SAndrew Geissler // not found 811978b8803SAndrew Geissler return; 812978b8803SAndrew Geissler } 813978b8803SAndrew Geissler 814978b8803SAndrew Geissler const std::string* bootProgressStr = 815978b8803SAndrew Geissler std::get_if<std::string>(&bootProgress); 816978b8803SAndrew Geissler 817978b8803SAndrew Geissler if (!bootProgressStr) 818978b8803SAndrew Geissler { 819978b8803SAndrew Geissler // Interface implemented but property not found, return error 820978b8803SAndrew Geissler // for that 821978b8803SAndrew Geissler messages::internalError(aResp->res); 822978b8803SAndrew Geissler return; 823978b8803SAndrew Geissler } 824978b8803SAndrew Geissler 825978b8803SAndrew Geissler BMCWEB_LOG_DEBUG << "Boot Progress: " << *bootProgressStr; 826978b8803SAndrew Geissler 827978b8803SAndrew Geissler // Now convert the D-Bus BootProgress to the appropriate Redfish 828978b8803SAndrew Geissler // enum 829978b8803SAndrew Geissler std::string rfBpLastState = "None"; 830978b8803SAndrew Geissler if (*bootProgressStr == "xyz.openbmc_project.State.Boot.Progress." 831978b8803SAndrew Geissler "ProgressStages.Unspecified") 832978b8803SAndrew Geissler { 833978b8803SAndrew Geissler rfBpLastState = "None"; 834978b8803SAndrew Geissler } 835978b8803SAndrew Geissler else if (*bootProgressStr == 836978b8803SAndrew Geissler "xyz.openbmc_project.State.Boot.Progress.ProgressStages." 837978b8803SAndrew Geissler "PrimaryProcInit") 838978b8803SAndrew Geissler { 839978b8803SAndrew Geissler rfBpLastState = "PrimaryProcessorInitializationStarted"; 840978b8803SAndrew Geissler } 841978b8803SAndrew Geissler else if (*bootProgressStr == 842978b8803SAndrew Geissler "xyz.openbmc_project.State.Boot.Progress.ProgressStages." 843978b8803SAndrew Geissler "BusInit") 844978b8803SAndrew Geissler { 845978b8803SAndrew Geissler rfBpLastState = "BusInitializationStarted"; 846978b8803SAndrew Geissler } 847978b8803SAndrew Geissler else if (*bootProgressStr == 848978b8803SAndrew Geissler "xyz.openbmc_project.State.Boot.Progress.ProgressStages." 849978b8803SAndrew Geissler "MemoryInit") 850978b8803SAndrew Geissler { 851978b8803SAndrew Geissler rfBpLastState = "MemoryInitializationStarted"; 852978b8803SAndrew Geissler } 853978b8803SAndrew Geissler else if (*bootProgressStr == 854978b8803SAndrew Geissler "xyz.openbmc_project.State.Boot.Progress.ProgressStages." 855978b8803SAndrew Geissler "SecondaryProcInit") 856978b8803SAndrew Geissler { 857978b8803SAndrew Geissler rfBpLastState = "SecondaryProcessorInitializationStarted"; 858978b8803SAndrew Geissler } 859978b8803SAndrew Geissler else if (*bootProgressStr == 860978b8803SAndrew Geissler "xyz.openbmc_project.State.Boot.Progress.ProgressStages." 861978b8803SAndrew Geissler "PCIInit") 862978b8803SAndrew Geissler { 863978b8803SAndrew Geissler rfBpLastState = "PCIResourceConfigStarted"; 864978b8803SAndrew Geissler } 865978b8803SAndrew Geissler else if (*bootProgressStr == 866978b8803SAndrew Geissler "xyz.openbmc_project.State.Boot.Progress.ProgressStages." 867978b8803SAndrew Geissler "SystemInitComplete") 868978b8803SAndrew Geissler { 869978b8803SAndrew Geissler rfBpLastState = "SystemHardwareInitializationComplete"; 870978b8803SAndrew Geissler } 871978b8803SAndrew Geissler else if (*bootProgressStr == 872978b8803SAndrew Geissler "xyz.openbmc_project.State.Boot.Progress.ProgressStages." 873978b8803SAndrew Geissler "OSStart") 874978b8803SAndrew Geissler { 875978b8803SAndrew Geissler rfBpLastState = "OSBootStarted"; 876978b8803SAndrew Geissler } 877978b8803SAndrew Geissler else if (*bootProgressStr == 878978b8803SAndrew Geissler "xyz.openbmc_project.State.Boot.Progress.ProgressStages." 879978b8803SAndrew Geissler "OSRunning") 880978b8803SAndrew Geissler { 881978b8803SAndrew Geissler rfBpLastState = "OSRunning"; 882978b8803SAndrew Geissler } 883978b8803SAndrew Geissler else 884978b8803SAndrew Geissler { 885978b8803SAndrew Geissler BMCWEB_LOG_DEBUG << "Unsupported D-Bus BootProgress " 886978b8803SAndrew Geissler << *bootProgressStr; 887978b8803SAndrew Geissler // Just return the default 888978b8803SAndrew Geissler } 889978b8803SAndrew Geissler 890978b8803SAndrew Geissler aResp->res.jsonValue["BootProgress"]["LastState"] = rfBpLastState; 891978b8803SAndrew Geissler }, 892978b8803SAndrew Geissler "xyz.openbmc_project.State.Host", "/xyz/openbmc_project/state/host0", 893978b8803SAndrew Geissler "org.freedesktop.DBus.Properties", "Get", 894978b8803SAndrew Geissler "xyz.openbmc_project.State.Boot.Progress", "BootProgress"); 895978b8803SAndrew Geissler } 896491d8ee7SSantosh Puranik 897491d8ee7SSantosh Puranik /** 898491d8ee7SSantosh Puranik * @brief Retrieves boot mode over DBUS and fills out the response 899491d8ee7SSantosh Puranik * 900491d8ee7SSantosh Puranik * @param[in] aResp Shared pointer for generating response message. 901491d8ee7SSantosh Puranik * @param[in] bootDbusObj The dbus object to query for boot properties. 902491d8ee7SSantosh Puranik * 903491d8ee7SSantosh Puranik * @return None. 904491d8ee7SSantosh Puranik */ 905b5a76932SEd Tanous inline void getBootMode(const std::shared_ptr<AsyncResp>& aResp, 906b5a76932SEd Tanous const std::string& bootDbusObj) 907491d8ee7SSantosh Puranik { 908491d8ee7SSantosh Puranik crow::connections::systemBus->async_method_call( 909491d8ee7SSantosh Puranik [aResp](const boost::system::error_code ec, 910491d8ee7SSantosh Puranik const std::variant<std::string>& bootMode) { 911491d8ee7SSantosh Puranik if (ec) 912491d8ee7SSantosh Puranik { 913491d8ee7SSantosh Puranik BMCWEB_LOG_DEBUG << "DBUS response error " << ec; 914491d8ee7SSantosh Puranik messages::internalError(aResp->res); 915491d8ee7SSantosh Puranik return; 916491d8ee7SSantosh Puranik } 917491d8ee7SSantosh Puranik 918491d8ee7SSantosh Puranik const std::string* bootModeStr = 919491d8ee7SSantosh Puranik std::get_if<std::string>(&bootMode); 920491d8ee7SSantosh Puranik 921491d8ee7SSantosh Puranik if (!bootModeStr) 922491d8ee7SSantosh Puranik { 923491d8ee7SSantosh Puranik messages::internalError(aResp->res); 924491d8ee7SSantosh Puranik return; 925491d8ee7SSantosh Puranik } 926491d8ee7SSantosh Puranik 927491d8ee7SSantosh Puranik BMCWEB_LOG_DEBUG << "Boot mode: " << *bootModeStr; 928491d8ee7SSantosh Puranik 929491d8ee7SSantosh Puranik // TODO (Santosh): Do we need to support override mode? 930491d8ee7SSantosh Puranik aResp->res.jsonValue["Boot"]["BootSourceOverrideMode"] = "Legacy"; 931491d8ee7SSantosh Puranik aResp->res.jsonValue["Boot"]["BootSourceOverrideTarget@Redfish." 932491d8ee7SSantosh Puranik "AllowableValues"] = { 933944ffaf9SJohnathan Mantey "None", "Pxe", "Hdd", "Cd", "Diags", "BiosSetup", "Usb"}; 934491d8ee7SSantosh Puranik 935491d8ee7SSantosh Puranik if (*bootModeStr != 936491d8ee7SSantosh Puranik "xyz.openbmc_project.Control.Boot.Mode.Modes.Regular") 937491d8ee7SSantosh Puranik { 938491d8ee7SSantosh Puranik auto rfMode = dbusToRfBootMode(*bootModeStr); 939491d8ee7SSantosh Puranik if (!rfMode.empty()) 940491d8ee7SSantosh Puranik { 941491d8ee7SSantosh Puranik aResp->res.jsonValue["Boot"]["BootSourceOverrideTarget"] = 942491d8ee7SSantosh Puranik rfMode; 943491d8ee7SSantosh Puranik } 944491d8ee7SSantosh Puranik } 945491d8ee7SSantosh Puranik 946491d8ee7SSantosh Puranik // If the BootSourceOverrideTarget is still "None" at the end, 947491d8ee7SSantosh Puranik // reset the BootSourceOverrideEnabled to indicate that 948491d8ee7SSantosh Puranik // overrides are disabled 949491d8ee7SSantosh Puranik if (aResp->res.jsonValue["Boot"]["BootSourceOverrideTarget"] == 950491d8ee7SSantosh Puranik "None") 951491d8ee7SSantosh Puranik { 952491d8ee7SSantosh Puranik aResp->res.jsonValue["Boot"]["BootSourceOverrideEnabled"] = 953491d8ee7SSantosh Puranik "Disabled"; 954491d8ee7SSantosh Puranik } 955491d8ee7SSantosh Puranik }, 956491d8ee7SSantosh Puranik "xyz.openbmc_project.Settings", bootDbusObj, 957491d8ee7SSantosh Puranik "org.freedesktop.DBus.Properties", "Get", 958491d8ee7SSantosh Puranik "xyz.openbmc_project.Control.Boot.Mode", "BootMode"); 959491d8ee7SSantosh Puranik } 960491d8ee7SSantosh Puranik 961491d8ee7SSantosh Puranik /** 962491d8ee7SSantosh Puranik * @brief Retrieves boot source over DBUS 963491d8ee7SSantosh Puranik * 964491d8ee7SSantosh Puranik * @param[in] aResp Shared pointer for generating response message. 965491d8ee7SSantosh Puranik * @param[in] oneTimeEnable Boolean to indicate boot properties are one-time. 966491d8ee7SSantosh Puranik * 967491d8ee7SSantosh Puranik * @return None. 968491d8ee7SSantosh Puranik */ 969f23b7296SEd Tanous inline void getBootSource(const std::shared_ptr<AsyncResp>& aResp, 970f23b7296SEd Tanous bool oneTimeEnabled) 971491d8ee7SSantosh Puranik { 972491d8ee7SSantosh Puranik std::string bootDbusObj = 973491d8ee7SSantosh Puranik oneTimeEnabled ? "/xyz/openbmc_project/control/host0/boot/one_time" 974491d8ee7SSantosh Puranik : "/xyz/openbmc_project/control/host0/boot"; 975491d8ee7SSantosh Puranik 976491d8ee7SSantosh Puranik BMCWEB_LOG_DEBUG << "Is one time: " << oneTimeEnabled; 977491d8ee7SSantosh Puranik aResp->res.jsonValue["Boot"]["BootSourceOverrideEnabled"] = 978491d8ee7SSantosh Puranik (oneTimeEnabled) ? "Once" : "Continuous"; 979491d8ee7SSantosh Puranik 980491d8ee7SSantosh Puranik crow::connections::systemBus->async_method_call( 981491d8ee7SSantosh Puranik [aResp, bootDbusObj](const boost::system::error_code ec, 982491d8ee7SSantosh Puranik const std::variant<std::string>& bootSource) { 983491d8ee7SSantosh Puranik if (ec) 984491d8ee7SSantosh Puranik { 985491d8ee7SSantosh Puranik BMCWEB_LOG_DEBUG << "DBUS response error " << ec; 986491d8ee7SSantosh Puranik messages::internalError(aResp->res); 987491d8ee7SSantosh Puranik return; 988491d8ee7SSantosh Puranik } 989491d8ee7SSantosh Puranik 990491d8ee7SSantosh Puranik const std::string* bootSourceStr = 991491d8ee7SSantosh Puranik std::get_if<std::string>(&bootSource); 992491d8ee7SSantosh Puranik 993491d8ee7SSantosh Puranik if (!bootSourceStr) 994491d8ee7SSantosh Puranik { 995491d8ee7SSantosh Puranik messages::internalError(aResp->res); 996491d8ee7SSantosh Puranik return; 997491d8ee7SSantosh Puranik } 998491d8ee7SSantosh Puranik BMCWEB_LOG_DEBUG << "Boot source: " << *bootSourceStr; 999491d8ee7SSantosh Puranik 1000491d8ee7SSantosh Puranik auto rfSource = dbusToRfBootSource(*bootSourceStr); 1001491d8ee7SSantosh Puranik if (!rfSource.empty()) 1002491d8ee7SSantosh Puranik { 1003491d8ee7SSantosh Puranik aResp->res.jsonValue["Boot"]["BootSourceOverrideTarget"] = 1004491d8ee7SSantosh Puranik rfSource; 1005491d8ee7SSantosh Puranik } 1006491d8ee7SSantosh Puranik }, 1007491d8ee7SSantosh Puranik "xyz.openbmc_project.Settings", bootDbusObj, 1008491d8ee7SSantosh Puranik "org.freedesktop.DBus.Properties", "Get", 1009491d8ee7SSantosh Puranik "xyz.openbmc_project.Control.Boot.Source", "BootSource"); 1010f23b7296SEd Tanous getBootMode(aResp, bootDbusObj); 1011491d8ee7SSantosh Puranik } 1012491d8ee7SSantosh Puranik 1013491d8ee7SSantosh Puranik /** 1014491d8ee7SSantosh Puranik * @brief Retrieves "One time" enabled setting over DBUS and calls function to 1015491d8ee7SSantosh Puranik * get boot source and boot mode. 1016491d8ee7SSantosh Puranik * 1017491d8ee7SSantosh Puranik * @param[in] aResp Shared pointer for generating response message. 1018491d8ee7SSantosh Puranik * 1019491d8ee7SSantosh Puranik * @return None. 1020491d8ee7SSantosh Puranik */ 1021b5a76932SEd Tanous inline void getBootProperties(const std::shared_ptr<AsyncResp>& aResp) 1022491d8ee7SSantosh Puranik { 1023491d8ee7SSantosh Puranik BMCWEB_LOG_DEBUG << "Get boot information."; 1024491d8ee7SSantosh Puranik 1025491d8ee7SSantosh Puranik crow::connections::systemBus->async_method_call( 1026c5d03ff4SJennifer Lee [aResp](const boost::system::error_code ec, 102719bd78d9SPatrick Williams const std::variant<bool>& oneTime) { 1028491d8ee7SSantosh Puranik if (ec) 1029491d8ee7SSantosh Puranik { 1030491d8ee7SSantosh Puranik BMCWEB_LOG_DEBUG << "DBUS response error " << ec; 10312a833c77SJames Feist // not an error, don't have to have the interface 1032491d8ee7SSantosh Puranik return; 1033491d8ee7SSantosh Puranik } 1034491d8ee7SSantosh Puranik 1035491d8ee7SSantosh Puranik const bool* oneTimePtr = std::get_if<bool>(&oneTime); 1036491d8ee7SSantosh Puranik 1037491d8ee7SSantosh Puranik if (!oneTimePtr) 1038491d8ee7SSantosh Puranik { 1039491d8ee7SSantosh Puranik messages::internalError(aResp->res); 1040491d8ee7SSantosh Puranik return; 1041491d8ee7SSantosh Puranik } 1042491d8ee7SSantosh Puranik getBootSource(aResp, *oneTimePtr); 1043491d8ee7SSantosh Puranik }, 1044491d8ee7SSantosh Puranik "xyz.openbmc_project.Settings", 1045491d8ee7SSantosh Puranik "/xyz/openbmc_project/control/host0/boot/one_time", 1046491d8ee7SSantosh Puranik "org.freedesktop.DBus.Properties", "Get", 1047491d8ee7SSantosh Puranik "xyz.openbmc_project.Object.Enable", "Enabled"); 1048491d8ee7SSantosh Puranik } 1049491d8ee7SSantosh Puranik 1050491d8ee7SSantosh Puranik /** 1051c0557e1aSGunnar Mills * @brief Retrieves the Last Reset Time 1052c0557e1aSGunnar Mills * 1053c0557e1aSGunnar Mills * "Reset" is an overloaded term in Redfish, "Reset" includes power on 1054c0557e1aSGunnar Mills * and power off. Even though this is the "system" Redfish object look at the 1055c0557e1aSGunnar Mills * chassis D-Bus interface for the LastStateChangeTime since this has the 1056c0557e1aSGunnar Mills * last power operation time. 1057c0557e1aSGunnar Mills * 1058c0557e1aSGunnar Mills * @param[in] aResp Shared pointer for generating response message. 1059c0557e1aSGunnar Mills * 1060c0557e1aSGunnar Mills * @return None. 1061c0557e1aSGunnar Mills */ 1062b5a76932SEd Tanous inline void getLastResetTime(const std::shared_ptr<AsyncResp>& aResp) 1063c0557e1aSGunnar Mills { 1064c0557e1aSGunnar Mills BMCWEB_LOG_DEBUG << "Getting System Last Reset Time"; 1065c0557e1aSGunnar Mills 1066c0557e1aSGunnar Mills crow::connections::systemBus->async_method_call( 1067c0557e1aSGunnar Mills [aResp](const boost::system::error_code ec, 1068c0557e1aSGunnar Mills std::variant<uint64_t>& lastResetTime) { 1069c0557e1aSGunnar Mills if (ec) 1070c0557e1aSGunnar Mills { 1071c0557e1aSGunnar Mills BMCWEB_LOG_DEBUG << "D-BUS response error " << ec; 1072c0557e1aSGunnar Mills return; 1073c0557e1aSGunnar Mills } 1074c0557e1aSGunnar Mills 1075c0557e1aSGunnar Mills const uint64_t* lastResetTimePtr = 1076c0557e1aSGunnar Mills std::get_if<uint64_t>(&lastResetTime); 1077c0557e1aSGunnar Mills 1078c0557e1aSGunnar Mills if (!lastResetTimePtr) 1079c0557e1aSGunnar Mills { 1080c0557e1aSGunnar Mills messages::internalError(aResp->res); 1081c0557e1aSGunnar Mills return; 1082c0557e1aSGunnar Mills } 1083c0557e1aSGunnar Mills // LastStateChangeTime is epoch time, in milliseconds 1084c0557e1aSGunnar Mills // https://github.com/openbmc/phosphor-dbus-interfaces/blob/33e8e1dd64da53a66e888d33dc82001305cd0bf9/xyz/openbmc_project/State/Chassis.interface.yaml#L19 1085c0557e1aSGunnar Mills time_t lastResetTimeStamp = 1086c0557e1aSGunnar Mills static_cast<time_t>(*lastResetTimePtr / 1000); 1087c0557e1aSGunnar Mills 1088c0557e1aSGunnar Mills // Convert to ISO 8601 standard 1089c0557e1aSGunnar Mills aResp->res.jsonValue["LastResetTime"] = 1090c0557e1aSGunnar Mills crow::utility::getDateTime(lastResetTimeStamp); 1091c0557e1aSGunnar Mills }, 1092c0557e1aSGunnar Mills "xyz.openbmc_project.State.Chassis", 1093c0557e1aSGunnar Mills "/xyz/openbmc_project/state/chassis0", 1094c0557e1aSGunnar Mills "org.freedesktop.DBus.Properties", "Get", 1095c0557e1aSGunnar Mills "xyz.openbmc_project.State.Chassis", "LastStateChangeTime"); 1096c0557e1aSGunnar Mills } 1097c0557e1aSGunnar Mills 1098c0557e1aSGunnar Mills /** 10996bd5a8d2SGunnar Mills * @brief Retrieves Automatic Retry properties. Known on D-Bus as AutoReboot. 11006bd5a8d2SGunnar Mills * 11016bd5a8d2SGunnar Mills * @param[in] aResp Shared pointer for generating response message. 11026bd5a8d2SGunnar Mills * 11036bd5a8d2SGunnar Mills * @return None. 11046bd5a8d2SGunnar Mills */ 1105b5a76932SEd Tanous inline void getAutomaticRetry(const std::shared_ptr<AsyncResp>& aResp) 11066bd5a8d2SGunnar Mills { 11076bd5a8d2SGunnar Mills BMCWEB_LOG_DEBUG << "Get Automatic Retry policy"; 11086bd5a8d2SGunnar Mills 11096bd5a8d2SGunnar Mills crow::connections::systemBus->async_method_call( 11106bd5a8d2SGunnar Mills [aResp](const boost::system::error_code ec, 11116bd5a8d2SGunnar Mills std::variant<bool>& autoRebootEnabled) { 11126bd5a8d2SGunnar Mills if (ec) 11136bd5a8d2SGunnar Mills { 11146bd5a8d2SGunnar Mills BMCWEB_LOG_DEBUG << "D-BUS response error " << ec; 11156bd5a8d2SGunnar Mills return; 11166bd5a8d2SGunnar Mills } 11176bd5a8d2SGunnar Mills 11186bd5a8d2SGunnar Mills const bool* autoRebootEnabledPtr = 11196bd5a8d2SGunnar Mills std::get_if<bool>(&autoRebootEnabled); 11206bd5a8d2SGunnar Mills 11216bd5a8d2SGunnar Mills if (!autoRebootEnabledPtr) 11226bd5a8d2SGunnar Mills { 11236bd5a8d2SGunnar Mills messages::internalError(aResp->res); 11246bd5a8d2SGunnar Mills return; 11256bd5a8d2SGunnar Mills } 11266bd5a8d2SGunnar Mills 11276bd5a8d2SGunnar Mills BMCWEB_LOG_DEBUG << "Auto Reboot: " << *autoRebootEnabledPtr; 11286bd5a8d2SGunnar Mills if (*autoRebootEnabledPtr == true) 11296bd5a8d2SGunnar Mills { 11306bd5a8d2SGunnar Mills aResp->res.jsonValue["Boot"]["AutomaticRetryConfig"] = 11316bd5a8d2SGunnar Mills "RetryAttempts"; 11326bd5a8d2SGunnar Mills // If AutomaticRetry (AutoReboot) is enabled see how many 11336bd5a8d2SGunnar Mills // attempts are left 11346bd5a8d2SGunnar Mills crow::connections::systemBus->async_method_call( 1135cb13a392SEd Tanous [aResp](const boost::system::error_code ec2, 11366bd5a8d2SGunnar Mills std::variant<uint32_t>& autoRebootAttemptsLeft) { 1137cb13a392SEd Tanous if (ec2) 11386bd5a8d2SGunnar Mills { 1139cb13a392SEd Tanous BMCWEB_LOG_DEBUG << "D-BUS response error " << ec2; 11406bd5a8d2SGunnar Mills return; 11416bd5a8d2SGunnar Mills } 11426bd5a8d2SGunnar Mills 11436bd5a8d2SGunnar Mills const uint32_t* autoRebootAttemptsLeftPtr = 11446bd5a8d2SGunnar Mills std::get_if<uint32_t>(&autoRebootAttemptsLeft); 11456bd5a8d2SGunnar Mills 11466bd5a8d2SGunnar Mills if (!autoRebootAttemptsLeftPtr) 11476bd5a8d2SGunnar Mills { 11486bd5a8d2SGunnar Mills messages::internalError(aResp->res); 11496bd5a8d2SGunnar Mills return; 11506bd5a8d2SGunnar Mills } 11516bd5a8d2SGunnar Mills 11526bd5a8d2SGunnar Mills BMCWEB_LOG_DEBUG << "Auto Reboot Attempts Left: " 11536bd5a8d2SGunnar Mills << *autoRebootAttemptsLeftPtr; 11546bd5a8d2SGunnar Mills 11556bd5a8d2SGunnar Mills aResp->res 11566bd5a8d2SGunnar Mills .jsonValue["Boot"] 11576bd5a8d2SGunnar Mills ["RemainingAutomaticRetryAttempts"] = 11586bd5a8d2SGunnar Mills *autoRebootAttemptsLeftPtr; 11596bd5a8d2SGunnar Mills }, 11606bd5a8d2SGunnar Mills "xyz.openbmc_project.State.Host", 11616bd5a8d2SGunnar Mills "/xyz/openbmc_project/state/host0", 11626bd5a8d2SGunnar Mills "org.freedesktop.DBus.Properties", "Get", 11636bd5a8d2SGunnar Mills "xyz.openbmc_project.Control.Boot.RebootAttempts", 11646bd5a8d2SGunnar Mills "AttemptsLeft"); 11656bd5a8d2SGunnar Mills } 11666bd5a8d2SGunnar Mills else 11676bd5a8d2SGunnar Mills { 11686bd5a8d2SGunnar Mills aResp->res.jsonValue["Boot"]["AutomaticRetryConfig"] = 11696bd5a8d2SGunnar Mills "Disabled"; 11706bd5a8d2SGunnar Mills } 11716bd5a8d2SGunnar Mills 11726bd5a8d2SGunnar Mills // Not on D-Bus. Hardcoded here: 11736bd5a8d2SGunnar Mills // https://github.com/openbmc/phosphor-state-manager/blob/1dbbef42675e94fb1f78edb87d6b11380260535a/meson_options.txt#L71 11746bd5a8d2SGunnar Mills aResp->res.jsonValue["Boot"]["AutomaticRetryAttempts"] = 3; 117569f35306SGunnar Mills 117669f35306SGunnar Mills // "AutomaticRetryConfig" can be 3 values, Disabled, RetryAlways, 117769f35306SGunnar Mills // and RetryAttempts. OpenBMC only supports Disabled and 117869f35306SGunnar Mills // RetryAttempts. 117969f35306SGunnar Mills aResp->res.jsonValue["Boot"]["AutomaticRetryConfig@Redfish." 118069f35306SGunnar Mills "AllowableValues"] = {"Disabled", 118169f35306SGunnar Mills "RetryAttempts"}; 11826bd5a8d2SGunnar Mills }, 11836bd5a8d2SGunnar Mills "xyz.openbmc_project.Settings", 11846bd5a8d2SGunnar Mills "/xyz/openbmc_project/control/host0/auto_reboot", 11856bd5a8d2SGunnar Mills "org.freedesktop.DBus.Properties", "Get", 11866bd5a8d2SGunnar Mills "xyz.openbmc_project.Control.Boot.RebootPolicy", "AutoReboot"); 11876bd5a8d2SGunnar Mills } 11886bd5a8d2SGunnar Mills 11896bd5a8d2SGunnar Mills /** 1190c6a620f2SGeorge Liu * @brief Retrieves power restore policy over DBUS. 1191c6a620f2SGeorge Liu * 1192c6a620f2SGeorge Liu * @param[in] aResp Shared pointer for generating response message. 1193c6a620f2SGeorge Liu * 1194c6a620f2SGeorge Liu * @return None. 1195c6a620f2SGeorge Liu */ 1196b5a76932SEd Tanous inline void getPowerRestorePolicy(const std::shared_ptr<AsyncResp>& aResp) 1197c6a620f2SGeorge Liu { 1198c6a620f2SGeorge Liu BMCWEB_LOG_DEBUG << "Get power restore policy"; 1199c6a620f2SGeorge Liu 1200c6a620f2SGeorge Liu crow::connections::systemBus->async_method_call( 1201c6a620f2SGeorge Liu [aResp](const boost::system::error_code ec, 120219bd78d9SPatrick Williams std::variant<std::string>& policy) { 1203c6a620f2SGeorge Liu if (ec) 1204c6a620f2SGeorge Liu { 1205c6a620f2SGeorge Liu BMCWEB_LOG_DEBUG << "DBUS response error " << ec; 1206c6a620f2SGeorge Liu return; 1207c6a620f2SGeorge Liu } 1208c6a620f2SGeorge Liu 1209c6a620f2SGeorge Liu const boost::container::flat_map<std::string, std::string> 1210c6a620f2SGeorge Liu policyMaps = { 1211c6a620f2SGeorge Liu {"xyz.openbmc_project.Control.Power.RestorePolicy.Policy." 1212c6a620f2SGeorge Liu "AlwaysOn", 1213c6a620f2SGeorge Liu "AlwaysOn"}, 1214c6a620f2SGeorge Liu {"xyz.openbmc_project.Control.Power.RestorePolicy.Policy." 1215c6a620f2SGeorge Liu "AlwaysOff", 1216c6a620f2SGeorge Liu "AlwaysOff"}, 1217c6a620f2SGeorge Liu {"xyz.openbmc_project.Control.Power.RestorePolicy.Policy." 121837ec9072SGunnar Mills "Restore", 1219c6a620f2SGeorge Liu "LastState"}}; 1220c6a620f2SGeorge Liu 1221c6a620f2SGeorge Liu const std::string* policyPtr = std::get_if<std::string>(&policy); 1222c6a620f2SGeorge Liu 1223c6a620f2SGeorge Liu if (!policyPtr) 1224c6a620f2SGeorge Liu { 1225c6a620f2SGeorge Liu messages::internalError(aResp->res); 1226c6a620f2SGeorge Liu return; 1227c6a620f2SGeorge Liu } 1228c6a620f2SGeorge Liu 1229c6a620f2SGeorge Liu auto policyMapsIt = policyMaps.find(*policyPtr); 1230c6a620f2SGeorge Liu if (policyMapsIt == policyMaps.end()) 1231c6a620f2SGeorge Liu { 1232c6a620f2SGeorge Liu messages::internalError(aResp->res); 1233c6a620f2SGeorge Liu return; 1234c6a620f2SGeorge Liu } 1235c6a620f2SGeorge Liu 1236c6a620f2SGeorge Liu aResp->res.jsonValue["PowerRestorePolicy"] = policyMapsIt->second; 1237c6a620f2SGeorge Liu }, 1238c6a620f2SGeorge Liu "xyz.openbmc_project.Settings", 1239c6a620f2SGeorge Liu "/xyz/openbmc_project/control/host0/power_restore_policy", 1240c6a620f2SGeorge Liu "org.freedesktop.DBus.Properties", "Get", 1241c6a620f2SGeorge Liu "xyz.openbmc_project.Control.Power.RestorePolicy", 1242c6a620f2SGeorge Liu "PowerRestorePolicy"); 1243c6a620f2SGeorge Liu } 1244c6a620f2SGeorge Liu 1245c6a620f2SGeorge Liu /** 1246491d8ee7SSantosh Puranik * @brief Sets boot properties into DBUS object(s). 1247491d8ee7SSantosh Puranik * 1248491d8ee7SSantosh Puranik * @param[in] aResp Shared pointer for generating response message. 1249491d8ee7SSantosh Puranik * @param[in] oneTimeEnabled Is "one-time" setting already enabled. 1250491d8ee7SSantosh Puranik * @param[in] bootSource The boot source to set. 1251491d8ee7SSantosh Puranik * @param[in] bootEnable The source override "enable" to set. 1252491d8ee7SSantosh Puranik * 1253265c1602SJohnathan Mantey * @return Integer error code. 1254491d8ee7SSantosh Puranik */ 125523a21a1cSEd Tanous inline void setBootModeOrSource(std::shared_ptr<AsyncResp> aResp, 1256491d8ee7SSantosh Puranik bool oneTimeEnabled, 1257f23b7296SEd Tanous const std::optional<std::string>& bootSource, 1258f23b7296SEd Tanous const std::optional<std::string>& bootEnable) 1259491d8ee7SSantosh Puranik { 1260944ffaf9SJohnathan Mantey std::string bootSourceStr = 1261944ffaf9SJohnathan Mantey "xyz.openbmc_project.Control.Boot.Source.Sources.Default"; 1262944ffaf9SJohnathan Mantey std::string bootModeStr = 1263944ffaf9SJohnathan Mantey "xyz.openbmc_project.Control.Boot.Mode.Modes.Regular"; 1264491d8ee7SSantosh Puranik bool oneTimeSetting = oneTimeEnabled; 1265944ffaf9SJohnathan Mantey bool useBootSource = true; 1266944ffaf9SJohnathan Mantey 1267491d8ee7SSantosh Puranik // Validate incoming parameters 1268491d8ee7SSantosh Puranik if (bootEnable) 1269491d8ee7SSantosh Puranik { 1270491d8ee7SSantosh Puranik if (*bootEnable == "Once") 1271491d8ee7SSantosh Puranik { 1272491d8ee7SSantosh Puranik oneTimeSetting = true; 1273491d8ee7SSantosh Puranik } 1274491d8ee7SSantosh Puranik else if (*bootEnable == "Continuous") 1275491d8ee7SSantosh Puranik { 1276491d8ee7SSantosh Puranik oneTimeSetting = false; 1277491d8ee7SSantosh Puranik } 1278491d8ee7SSantosh Puranik else if (*bootEnable == "Disabled") 1279491d8ee7SSantosh Puranik { 1280944ffaf9SJohnathan Mantey BMCWEB_LOG_DEBUG << "Boot source override will be disabled"; 1281491d8ee7SSantosh Puranik oneTimeSetting = false; 1282944ffaf9SJohnathan Mantey useBootSource = false; 1283491d8ee7SSantosh Puranik } 1284491d8ee7SSantosh Puranik else 1285491d8ee7SSantosh Puranik { 1286491d8ee7SSantosh Puranik BMCWEB_LOG_DEBUG << "Unsupported value for " 1287491d8ee7SSantosh Puranik "BootSourceOverrideEnabled: " 1288491d8ee7SSantosh Puranik << *bootEnable; 1289491d8ee7SSantosh Puranik messages::propertyValueNotInList(aResp->res, *bootEnable, 1290491d8ee7SSantosh Puranik "BootSourceOverrideEnabled"); 1291491d8ee7SSantosh Puranik return; 1292491d8ee7SSantosh Puranik } 1293491d8ee7SSantosh Puranik } 1294491d8ee7SSantosh Puranik 1295944ffaf9SJohnathan Mantey if (bootSource && useBootSource) 1296491d8ee7SSantosh Puranik { 1297491d8ee7SSantosh Puranik // Source target specified 1298491d8ee7SSantosh Puranik BMCWEB_LOG_DEBUG << "Boot source: " << *bootSource; 1299491d8ee7SSantosh Puranik // Figure out which DBUS interface and property to use 1300944ffaf9SJohnathan Mantey if (assignBootParameters(aResp, *bootSource, bootSourceStr, 1301944ffaf9SJohnathan Mantey bootModeStr)) 1302491d8ee7SSantosh Puranik { 1303944ffaf9SJohnathan Mantey BMCWEB_LOG_DEBUG 1304944ffaf9SJohnathan Mantey << "Invalid property value for BootSourceOverrideTarget: " 1305491d8ee7SSantosh Puranik << *bootSource; 1306491d8ee7SSantosh Puranik messages::propertyValueNotInList(aResp->res, *bootSource, 1307491d8ee7SSantosh Puranik "BootSourceTargetOverride"); 1308491d8ee7SSantosh Puranik return; 1309491d8ee7SSantosh Puranik } 1310944ffaf9SJohnathan Mantey } 1311491d8ee7SSantosh Puranik 1312944ffaf9SJohnathan Mantey // Act on validated parameters 1313944ffaf9SJohnathan Mantey BMCWEB_LOG_DEBUG << "DBUS boot source: " << bootSourceStr; 1314944ffaf9SJohnathan Mantey BMCWEB_LOG_DEBUG << "DBUS boot mode: " << bootModeStr; 1315944ffaf9SJohnathan Mantey const char* bootObj = 1316944ffaf9SJohnathan Mantey oneTimeSetting ? "/xyz/openbmc_project/control/host0/boot/one_time" 1317944ffaf9SJohnathan Mantey : "/xyz/openbmc_project/control/host0/boot"; 1318944ffaf9SJohnathan Mantey 1319491d8ee7SSantosh Puranik crow::connections::systemBus->async_method_call( 1320491d8ee7SSantosh Puranik [aResp](const boost::system::error_code ec) { 1321491d8ee7SSantosh Puranik if (ec) 1322491d8ee7SSantosh Puranik { 1323491d8ee7SSantosh Puranik BMCWEB_LOG_DEBUG << "DBUS response error " << ec; 1324491d8ee7SSantosh Puranik messages::internalError(aResp->res); 1325491d8ee7SSantosh Puranik return; 1326491d8ee7SSantosh Puranik } 1327491d8ee7SSantosh Puranik BMCWEB_LOG_DEBUG << "Boot source update done."; 1328491d8ee7SSantosh Puranik }, 1329491d8ee7SSantosh Puranik "xyz.openbmc_project.Settings", bootObj, 1330491d8ee7SSantosh Puranik "org.freedesktop.DBus.Properties", "Set", 1331491d8ee7SSantosh Puranik "xyz.openbmc_project.Control.Boot.Source", "BootSource", 1332491d8ee7SSantosh Puranik std::variant<std::string>(bootSourceStr)); 1333944ffaf9SJohnathan Mantey 1334491d8ee7SSantosh Puranik crow::connections::systemBus->async_method_call( 1335491d8ee7SSantosh Puranik [aResp](const boost::system::error_code ec) { 1336491d8ee7SSantosh Puranik if (ec) 1337491d8ee7SSantosh Puranik { 1338491d8ee7SSantosh Puranik BMCWEB_LOG_DEBUG << "DBUS response error " << ec; 1339491d8ee7SSantosh Puranik messages::internalError(aResp->res); 1340491d8ee7SSantosh Puranik return; 1341491d8ee7SSantosh Puranik } 1342491d8ee7SSantosh Puranik BMCWEB_LOG_DEBUG << "Boot mode update done."; 1343491d8ee7SSantosh Puranik }, 1344491d8ee7SSantosh Puranik "xyz.openbmc_project.Settings", bootObj, 1345491d8ee7SSantosh Puranik "org.freedesktop.DBus.Properties", "Set", 1346491d8ee7SSantosh Puranik "xyz.openbmc_project.Control.Boot.Mode", "BootMode", 1347491d8ee7SSantosh Puranik std::variant<std::string>(bootModeStr)); 1348944ffaf9SJohnathan Mantey 1349491d8ee7SSantosh Puranik crow::connections::systemBus->async_method_call( 1350491d8ee7SSantosh Puranik [aResp{std::move(aResp)}](const boost::system::error_code ec) { 1351491d8ee7SSantosh Puranik if (ec) 1352491d8ee7SSantosh Puranik { 1353491d8ee7SSantosh Puranik BMCWEB_LOG_DEBUG << "DBUS response error " << ec; 1354491d8ee7SSantosh Puranik messages::internalError(aResp->res); 1355491d8ee7SSantosh Puranik return; 1356491d8ee7SSantosh Puranik } 1357491d8ee7SSantosh Puranik BMCWEB_LOG_DEBUG << "Boot enable update done."; 1358491d8ee7SSantosh Puranik }, 1359491d8ee7SSantosh Puranik "xyz.openbmc_project.Settings", 1360491d8ee7SSantosh Puranik "/xyz/openbmc_project/control/host0/boot/one_time", 1361491d8ee7SSantosh Puranik "org.freedesktop.DBus.Properties", "Set", 1362491d8ee7SSantosh Puranik "xyz.openbmc_project.Object.Enable", "Enabled", 1363491d8ee7SSantosh Puranik std::variant<bool>(oneTimeSetting)); 1364491d8ee7SSantosh Puranik } 1365491d8ee7SSantosh Puranik 1366491d8ee7SSantosh Puranik /** 1367491d8ee7SSantosh Puranik * @brief Retrieves "One time" enabled setting over DBUS and calls function to 1368491d8ee7SSantosh Puranik * set boot source/boot mode properties. 1369491d8ee7SSantosh Puranik * 1370491d8ee7SSantosh Puranik * @param[in] aResp Shared pointer for generating response message. 1371491d8ee7SSantosh Puranik * @param[in] bootSource The boot source from incoming RF request. 1372491d8ee7SSantosh Puranik * @param[in] bootEnable The boot override enable from incoming RF request. 1373491d8ee7SSantosh Puranik * 1374265c1602SJohnathan Mantey * @return Integer error code. 1375491d8ee7SSantosh Puranik */ 1376b5a76932SEd Tanous inline void setBootSourceProperties(const std::shared_ptr<AsyncResp>& aResp, 1377491d8ee7SSantosh Puranik std::optional<std::string> bootSource, 1378491d8ee7SSantosh Puranik std::optional<std::string> bootEnable) 1379491d8ee7SSantosh Puranik { 1380491d8ee7SSantosh Puranik BMCWEB_LOG_DEBUG << "Set boot information."; 1381491d8ee7SSantosh Puranik 1382491d8ee7SSantosh Puranik crow::connections::systemBus->async_method_call( 1383265c1602SJohnathan Mantey [aResp, bootSource{std::move(bootSource)}, 138419bd78d9SPatrick Williams bootEnable{std::move(bootEnable)}](const boost::system::error_code ec, 138519bd78d9SPatrick Williams const std::variant<bool>& oneTime) { 1386491d8ee7SSantosh Puranik if (ec) 1387491d8ee7SSantosh Puranik { 1388491d8ee7SSantosh Puranik BMCWEB_LOG_DEBUG << "DBUS response error " << ec; 1389491d8ee7SSantosh Puranik messages::internalError(aResp->res); 1390491d8ee7SSantosh Puranik return; 1391491d8ee7SSantosh Puranik } 1392491d8ee7SSantosh Puranik 1393491d8ee7SSantosh Puranik const bool* oneTimePtr = std::get_if<bool>(&oneTime); 1394491d8ee7SSantosh Puranik 1395491d8ee7SSantosh Puranik if (!oneTimePtr) 1396491d8ee7SSantosh Puranik { 1397491d8ee7SSantosh Puranik messages::internalError(aResp->res); 1398491d8ee7SSantosh Puranik return; 1399491d8ee7SSantosh Puranik } 1400491d8ee7SSantosh Puranik 1401491d8ee7SSantosh Puranik BMCWEB_LOG_DEBUG << "Got one time: " << *oneTimePtr; 1402491d8ee7SSantosh Puranik 1403f23b7296SEd Tanous setBootModeOrSource(aResp, *oneTimePtr, bootSource, bootEnable); 1404491d8ee7SSantosh Puranik }, 1405491d8ee7SSantosh Puranik "xyz.openbmc_project.Settings", 1406491d8ee7SSantosh Puranik "/xyz/openbmc_project/control/host0/boot/one_time", 1407491d8ee7SSantosh Puranik "org.freedesktop.DBus.Properties", "Get", 1408491d8ee7SSantosh Puranik "xyz.openbmc_project.Object.Enable", "Enabled"); 1409491d8ee7SSantosh Puranik } 1410491d8ee7SSantosh Puranik 1411c6a620f2SGeorge Liu /** 141298e386ecSGunnar Mills * @brief Sets AssetTag 141398e386ecSGunnar Mills * 141498e386ecSGunnar Mills * @param[in] aResp Shared pointer for generating response message. 141598e386ecSGunnar Mills * @param[in] assetTag "AssetTag" from request. 141698e386ecSGunnar Mills * 141798e386ecSGunnar Mills * @return None. 141898e386ecSGunnar Mills */ 141998e386ecSGunnar Mills inline void setAssetTag(const std::shared_ptr<AsyncResp>& aResp, 142098e386ecSGunnar Mills const std::string& assetTag) 142198e386ecSGunnar Mills { 142298e386ecSGunnar Mills crow::connections::systemBus->async_method_call( 142398e386ecSGunnar Mills [aResp, assetTag]( 142498e386ecSGunnar Mills const boost::system::error_code ec, 142598e386ecSGunnar Mills const std::vector<std::pair< 142698e386ecSGunnar Mills std::string, 142798e386ecSGunnar Mills std::vector<std::pair<std::string, std::vector<std::string>>>>>& 142898e386ecSGunnar Mills subtree) { 142998e386ecSGunnar Mills if (ec) 143098e386ecSGunnar Mills { 143198e386ecSGunnar Mills BMCWEB_LOG_DEBUG << "D-Bus response error on GetSubTree " << ec; 143298e386ecSGunnar Mills messages::internalError(aResp->res); 143398e386ecSGunnar Mills return; 143498e386ecSGunnar Mills } 143598e386ecSGunnar Mills if (subtree.size() == 0) 143698e386ecSGunnar Mills { 143798e386ecSGunnar Mills BMCWEB_LOG_DEBUG << "Can't find system D-Bus object!"; 143898e386ecSGunnar Mills messages::internalError(aResp->res); 143998e386ecSGunnar Mills return; 144098e386ecSGunnar Mills } 144198e386ecSGunnar Mills // Assume only 1 system D-Bus object 144298e386ecSGunnar Mills // Throw an error if there is more than 1 144398e386ecSGunnar Mills if (subtree.size() > 1) 144498e386ecSGunnar Mills { 144598e386ecSGunnar Mills BMCWEB_LOG_DEBUG << "Found more than 1 system D-Bus object!"; 144698e386ecSGunnar Mills messages::internalError(aResp->res); 144798e386ecSGunnar Mills return; 144898e386ecSGunnar Mills } 144998e386ecSGunnar Mills if (subtree[0].first.empty() || subtree[0].second.size() != 1) 145098e386ecSGunnar Mills { 145198e386ecSGunnar Mills BMCWEB_LOG_DEBUG << "Asset Tag Set mapper error!"; 145298e386ecSGunnar Mills messages::internalError(aResp->res); 145398e386ecSGunnar Mills return; 145498e386ecSGunnar Mills } 145598e386ecSGunnar Mills 145698e386ecSGunnar Mills const std::string& path = subtree[0].first; 145798e386ecSGunnar Mills const std::string& service = subtree[0].second.begin()->first; 145898e386ecSGunnar Mills 145998e386ecSGunnar Mills if (service.empty()) 146098e386ecSGunnar Mills { 146198e386ecSGunnar Mills BMCWEB_LOG_DEBUG << "Asset Tag Set service mapper error!"; 146298e386ecSGunnar Mills messages::internalError(aResp->res); 146398e386ecSGunnar Mills return; 146498e386ecSGunnar Mills } 146598e386ecSGunnar Mills 146698e386ecSGunnar Mills crow::connections::systemBus->async_method_call( 146798e386ecSGunnar Mills [aResp](const boost::system::error_code ec2) { 146898e386ecSGunnar Mills if (ec2) 146998e386ecSGunnar Mills { 147098e386ecSGunnar Mills BMCWEB_LOG_DEBUG 147198e386ecSGunnar Mills << "D-Bus response error on AssetTag Set " << ec2; 147298e386ecSGunnar Mills messages::internalError(aResp->res); 147398e386ecSGunnar Mills return; 147498e386ecSGunnar Mills } 147598e386ecSGunnar Mills }, 147698e386ecSGunnar Mills service, path, "org.freedesktop.DBus.Properties", "Set", 147798e386ecSGunnar Mills "xyz.openbmc_project.Inventory.Decorator.AssetTag", "AssetTag", 147898e386ecSGunnar Mills std::variant<std::string>(assetTag)); 147998e386ecSGunnar Mills }, 148098e386ecSGunnar Mills "xyz.openbmc_project.ObjectMapper", 148198e386ecSGunnar Mills "/xyz/openbmc_project/object_mapper", 148298e386ecSGunnar Mills "xyz.openbmc_project.ObjectMapper", "GetSubTree", 148398e386ecSGunnar Mills "/xyz/openbmc_project/inventory", int32_t(0), 148498e386ecSGunnar Mills std::array<const char*, 1>{ 148598e386ecSGunnar Mills "xyz.openbmc_project.Inventory.Item.System"}); 148698e386ecSGunnar Mills } 148798e386ecSGunnar Mills 148898e386ecSGunnar Mills /** 148969f35306SGunnar Mills * @brief Sets automaticRetry (Auto Reboot) 149069f35306SGunnar Mills * 149169f35306SGunnar Mills * @param[in] aResp Shared pointer for generating response message. 149269f35306SGunnar Mills * @param[in] automaticRetryConfig "AutomaticRetryConfig" from request. 149369f35306SGunnar Mills * 149469f35306SGunnar Mills * @return None. 149569f35306SGunnar Mills */ 1496b5a76932SEd Tanous inline void setAutomaticRetry(const std::shared_ptr<AsyncResp>& aResp, 1497f23b7296SEd Tanous const std::string& automaticRetryConfig) 149869f35306SGunnar Mills { 149969f35306SGunnar Mills BMCWEB_LOG_DEBUG << "Set Automatic Retry."; 150069f35306SGunnar Mills 150169f35306SGunnar Mills // OpenBMC only supports "Disabled" and "RetryAttempts". 150269f35306SGunnar Mills bool autoRebootEnabled; 150369f35306SGunnar Mills 150469f35306SGunnar Mills if (automaticRetryConfig == "Disabled") 150569f35306SGunnar Mills { 150669f35306SGunnar Mills autoRebootEnabled = false; 150769f35306SGunnar Mills } 150869f35306SGunnar Mills else if (automaticRetryConfig == "RetryAttempts") 150969f35306SGunnar Mills { 151069f35306SGunnar Mills autoRebootEnabled = true; 151169f35306SGunnar Mills } 151269f35306SGunnar Mills else 151369f35306SGunnar Mills { 151469f35306SGunnar Mills BMCWEB_LOG_DEBUG << "Invalid property value for " 151569f35306SGunnar Mills "AutomaticRetryConfig: " 151669f35306SGunnar Mills << automaticRetryConfig; 151769f35306SGunnar Mills messages::propertyValueNotInList(aResp->res, automaticRetryConfig, 151869f35306SGunnar Mills "AutomaticRetryConfig"); 151969f35306SGunnar Mills return; 152069f35306SGunnar Mills } 152169f35306SGunnar Mills 152269f35306SGunnar Mills crow::connections::systemBus->async_method_call( 152369f35306SGunnar Mills [aResp](const boost::system::error_code ec) { 152469f35306SGunnar Mills if (ec) 152569f35306SGunnar Mills { 152669f35306SGunnar Mills messages::internalError(aResp->res); 152769f35306SGunnar Mills return; 152869f35306SGunnar Mills } 152969f35306SGunnar Mills }, 153069f35306SGunnar Mills "xyz.openbmc_project.Settings", 153169f35306SGunnar Mills "/xyz/openbmc_project/control/host0/auto_reboot", 153269f35306SGunnar Mills "org.freedesktop.DBus.Properties", "Set", 153369f35306SGunnar Mills "xyz.openbmc_project.Control.Boot.RebootPolicy", "AutoReboot", 153469f35306SGunnar Mills std::variant<bool>(autoRebootEnabled)); 153569f35306SGunnar Mills } 153669f35306SGunnar Mills 153769f35306SGunnar Mills /** 1538c6a620f2SGeorge Liu * @brief Sets power restore policy properties. 1539c6a620f2SGeorge Liu * 1540c6a620f2SGeorge Liu * @param[in] aResp Shared pointer for generating response message. 1541c6a620f2SGeorge Liu * @param[in] policy power restore policy properties from request. 1542c6a620f2SGeorge Liu * 1543c6a620f2SGeorge Liu * @return None. 1544c6a620f2SGeorge Liu */ 1545b5a76932SEd Tanous inline void setPowerRestorePolicy(const std::shared_ptr<AsyncResp>& aResp, 1546*4e69c904SGunnar Mills const std::string& policy) 1547c6a620f2SGeorge Liu { 1548c6a620f2SGeorge Liu BMCWEB_LOG_DEBUG << "Set power restore policy."; 1549c6a620f2SGeorge Liu 1550c6a620f2SGeorge Liu const boost::container::flat_map<std::string, std::string> policyMaps = { 1551c6a620f2SGeorge Liu {"AlwaysOn", "xyz.openbmc_project.Control.Power.RestorePolicy.Policy." 1552c6a620f2SGeorge Liu "AlwaysOn"}, 1553c6a620f2SGeorge Liu {"AlwaysOff", "xyz.openbmc_project.Control.Power.RestorePolicy.Policy." 1554c6a620f2SGeorge Liu "AlwaysOff"}, 1555c6a620f2SGeorge Liu {"LastState", "xyz.openbmc_project.Control.Power.RestorePolicy.Policy." 155637ec9072SGunnar Mills "Restore"}}; 1557c6a620f2SGeorge Liu 1558c6a620f2SGeorge Liu std::string powerRestorPolicy; 1559c6a620f2SGeorge Liu 1560*4e69c904SGunnar Mills auto policyMapsIt = policyMaps.find(policy); 1561c6a620f2SGeorge Liu if (policyMapsIt == policyMaps.end()) 1562c6a620f2SGeorge Liu { 1563*4e69c904SGunnar Mills messages::propertyValueNotInList(aResp->res, policy, 1564*4e69c904SGunnar Mills "PowerRestorePolicy"); 1565c6a620f2SGeorge Liu return; 1566c6a620f2SGeorge Liu } 1567c6a620f2SGeorge Liu 1568c6a620f2SGeorge Liu powerRestorPolicy = policyMapsIt->second; 1569c6a620f2SGeorge Liu 1570c6a620f2SGeorge Liu crow::connections::systemBus->async_method_call( 1571c6a620f2SGeorge Liu [aResp](const boost::system::error_code ec) { 1572c6a620f2SGeorge Liu if (ec) 1573c6a620f2SGeorge Liu { 1574c6a620f2SGeorge Liu messages::internalError(aResp->res); 1575c6a620f2SGeorge Liu return; 1576c6a620f2SGeorge Liu } 1577c6a620f2SGeorge Liu }, 1578c6a620f2SGeorge Liu "xyz.openbmc_project.Settings", 1579c6a620f2SGeorge Liu "/xyz/openbmc_project/control/host0/power_restore_policy", 1580c6a620f2SGeorge Liu "org.freedesktop.DBus.Properties", "Set", 1581c6a620f2SGeorge Liu "xyz.openbmc_project.Control.Power.RestorePolicy", "PowerRestorePolicy", 1582c6a620f2SGeorge Liu std::variant<std::string>(powerRestorPolicy)); 1583c6a620f2SGeorge Liu } 1584c6a620f2SGeorge Liu 1585a6349918SAppaRao Puli #ifdef BMCWEB_ENABLE_REDFISH_PROVISIONING_FEATURE 1586a6349918SAppaRao Puli /** 1587a6349918SAppaRao Puli * @brief Retrieves provisioning status 1588a6349918SAppaRao Puli * 1589a6349918SAppaRao Puli * @param[in] aResp Shared pointer for completing asynchronous calls. 1590a6349918SAppaRao Puli * 1591a6349918SAppaRao Puli * @return None. 1592a6349918SAppaRao Puli */ 159323a21a1cSEd Tanous inline void getProvisioningStatus(std::shared_ptr<AsyncResp> aResp) 1594a6349918SAppaRao Puli { 1595a6349918SAppaRao Puli BMCWEB_LOG_DEBUG << "Get OEM information."; 1596a6349918SAppaRao Puli crow::connections::systemBus->async_method_call( 1597a6349918SAppaRao Puli [aResp](const boost::system::error_code ec, 15981214b7e7SGunnar Mills const std::vector<std::pair<std::string, VariantType>>& 15991214b7e7SGunnar Mills propertiesList) { 1600b99fb1a9SAppaRao Puli nlohmann::json& oemPFR = 1601b99fb1a9SAppaRao Puli aResp->res.jsonValue["Oem"]["OpenBmc"]["FirmwareProvisioning"]; 160250626f4fSJames Feist aResp->res.jsonValue["Oem"]["OpenBmc"]["@odata.type"] = 160350626f4fSJames Feist "#OemComputerSystem.OpenBmc"; 160450626f4fSJames Feist oemPFR["@odata.type"] = "#OemComputerSystem.FirmwareProvisioning"; 160550626f4fSJames Feist 1606a6349918SAppaRao Puli if (ec) 1607a6349918SAppaRao Puli { 1608a6349918SAppaRao Puli BMCWEB_LOG_DEBUG << "DBUS response error " << ec; 1609b99fb1a9SAppaRao Puli // not an error, don't have to have the interface 1610b99fb1a9SAppaRao Puli oemPFR["ProvisioningStatus"] = "NotProvisioned"; 1611a6349918SAppaRao Puli return; 1612a6349918SAppaRao Puli } 1613a6349918SAppaRao Puli 1614a6349918SAppaRao Puli const bool* provState = nullptr; 1615a6349918SAppaRao Puli const bool* lockState = nullptr; 1616a6349918SAppaRao Puli for (const std::pair<std::string, VariantType>& property : 1617a6349918SAppaRao Puli propertiesList) 1618a6349918SAppaRao Puli { 1619a6349918SAppaRao Puli if (property.first == "UfmProvisioned") 1620a6349918SAppaRao Puli { 1621a6349918SAppaRao Puli provState = std::get_if<bool>(&property.second); 1622a6349918SAppaRao Puli } 1623a6349918SAppaRao Puli else if (property.first == "UfmLocked") 1624a6349918SAppaRao Puli { 1625a6349918SAppaRao Puli lockState = std::get_if<bool>(&property.second); 1626a6349918SAppaRao Puli } 1627a6349918SAppaRao Puli } 1628a6349918SAppaRao Puli 1629a6349918SAppaRao Puli if ((provState == nullptr) || (lockState == nullptr)) 1630a6349918SAppaRao Puli { 1631a6349918SAppaRao Puli BMCWEB_LOG_DEBUG << "Unable to get PFR attributes."; 1632a6349918SAppaRao Puli messages::internalError(aResp->res); 1633a6349918SAppaRao Puli return; 1634a6349918SAppaRao Puli } 1635a6349918SAppaRao Puli 1636a6349918SAppaRao Puli if (*provState == true) 1637a6349918SAppaRao Puli { 1638a6349918SAppaRao Puli if (*lockState == true) 1639a6349918SAppaRao Puli { 1640a6349918SAppaRao Puli oemPFR["ProvisioningStatus"] = "ProvisionedAndLocked"; 1641a6349918SAppaRao Puli } 1642a6349918SAppaRao Puli else 1643a6349918SAppaRao Puli { 1644a6349918SAppaRao Puli oemPFR["ProvisioningStatus"] = "ProvisionedButNotLocked"; 1645a6349918SAppaRao Puli } 1646a6349918SAppaRao Puli } 1647a6349918SAppaRao Puli else 1648a6349918SAppaRao Puli { 1649a6349918SAppaRao Puli oemPFR["ProvisioningStatus"] = "NotProvisioned"; 1650a6349918SAppaRao Puli } 1651a6349918SAppaRao Puli }, 1652a6349918SAppaRao Puli "xyz.openbmc_project.PFR.Manager", "/xyz/openbmc_project/pfr", 1653a6349918SAppaRao Puli "org.freedesktop.DBus.Properties", "GetAll", 1654a6349918SAppaRao Puli "xyz.openbmc_project.PFR.Attributes"); 1655a6349918SAppaRao Puli } 1656a6349918SAppaRao Puli #endif 1657a6349918SAppaRao Puli 1658491d8ee7SSantosh Puranik /** 165951709ffdSYong Li * @brief Translates watchdog timeout action DBUS property value to redfish. 166051709ffdSYong Li * 166151709ffdSYong Li * @param[in] dbusAction The watchdog timeout action in D-BUS. 166251709ffdSYong Li * 166351709ffdSYong Li * @return Returns as a string, the timeout action in Redfish terms. If 166451709ffdSYong Li * translation cannot be done, returns an empty string. 166551709ffdSYong Li */ 166623a21a1cSEd Tanous inline std::string dbusToRfWatchdogAction(const std::string& dbusAction) 166751709ffdSYong Li { 166851709ffdSYong Li if (dbusAction == "xyz.openbmc_project.State.Watchdog.Action.None") 166951709ffdSYong Li { 167051709ffdSYong Li return "None"; 167151709ffdSYong Li } 16723174e4dfSEd Tanous if (dbusAction == "xyz.openbmc_project.State.Watchdog.Action.HardReset") 167351709ffdSYong Li { 167451709ffdSYong Li return "ResetSystem"; 167551709ffdSYong Li } 16763174e4dfSEd Tanous if (dbusAction == "xyz.openbmc_project.State.Watchdog.Action.PowerOff") 167751709ffdSYong Li { 167851709ffdSYong Li return "PowerDown"; 167951709ffdSYong Li } 16803174e4dfSEd Tanous if (dbusAction == "xyz.openbmc_project.State.Watchdog.Action.PowerCycle") 168151709ffdSYong Li { 168251709ffdSYong Li return "PowerCycle"; 168351709ffdSYong Li } 168451709ffdSYong Li 168551709ffdSYong Li return ""; 168651709ffdSYong Li } 168751709ffdSYong Li 168851709ffdSYong Li /** 1689c45f0082SYong Li *@brief Translates timeout action from Redfish to DBUS property value. 1690c45f0082SYong Li * 1691c45f0082SYong Li *@param[in] rfAction The timeout action in Redfish. 1692c45f0082SYong Li * 1693c45f0082SYong Li *@return Returns as a string, the time_out action as expected by DBUS. 1694c45f0082SYong Li *If translation cannot be done, returns an empty string. 1695c45f0082SYong Li */ 1696c45f0082SYong Li 169723a21a1cSEd Tanous inline std::string rfToDbusWDTTimeOutAct(const std::string& rfAction) 1698c45f0082SYong Li { 1699c45f0082SYong Li if (rfAction == "None") 1700c45f0082SYong Li { 1701c45f0082SYong Li return "xyz.openbmc_project.State.Watchdog.Action.None"; 1702c45f0082SYong Li } 17033174e4dfSEd Tanous if (rfAction == "PowerCycle") 1704c45f0082SYong Li { 1705c45f0082SYong Li return "xyz.openbmc_project.State.Watchdog.Action.PowerCycle"; 1706c45f0082SYong Li } 17073174e4dfSEd Tanous if (rfAction == "PowerDown") 1708c45f0082SYong Li { 1709c45f0082SYong Li return "xyz.openbmc_project.State.Watchdog.Action.PowerOff"; 1710c45f0082SYong Li } 17113174e4dfSEd Tanous if (rfAction == "ResetSystem") 1712c45f0082SYong Li { 1713c45f0082SYong Li return "xyz.openbmc_project.State.Watchdog.Action.HardReset"; 1714c45f0082SYong Li } 1715c45f0082SYong Li 1716c45f0082SYong Li return ""; 1717c45f0082SYong Li } 1718c45f0082SYong Li 1719c45f0082SYong Li /** 172051709ffdSYong Li * @brief Retrieves host watchdog timer properties over DBUS 172151709ffdSYong Li * 172251709ffdSYong Li * @param[in] aResp Shared pointer for completing asynchronous calls. 172351709ffdSYong Li * 172451709ffdSYong Li * @return None. 172551709ffdSYong Li */ 1726b5a76932SEd Tanous inline void getHostWatchdogTimer(const std::shared_ptr<AsyncResp>& aResp) 172751709ffdSYong Li { 172851709ffdSYong Li BMCWEB_LOG_DEBUG << "Get host watchodg"; 172951709ffdSYong Li crow::connections::systemBus->async_method_call( 173051709ffdSYong Li [aResp](const boost::system::error_code ec, 173151709ffdSYong Li PropertiesType& properties) { 173251709ffdSYong Li if (ec) 173351709ffdSYong Li { 173451709ffdSYong Li // watchdog service is stopped 173551709ffdSYong Li BMCWEB_LOG_DEBUG << "DBUS response error " << ec; 173651709ffdSYong Li return; 173751709ffdSYong Li } 173851709ffdSYong Li 173951709ffdSYong Li BMCWEB_LOG_DEBUG << "Got " << properties.size() << " wdt prop."; 174051709ffdSYong Li 174151709ffdSYong Li nlohmann::json& hostWatchdogTimer = 174251709ffdSYong Li aResp->res.jsonValue["HostWatchdogTimer"]; 174351709ffdSYong Li 174451709ffdSYong Li // watchdog service is running/enabled 174551709ffdSYong Li hostWatchdogTimer["Status"]["State"] = "Enabled"; 174651709ffdSYong Li 174751709ffdSYong Li for (const auto& property : properties) 174851709ffdSYong Li { 174951709ffdSYong Li BMCWEB_LOG_DEBUG << "prop=" << property.first; 175051709ffdSYong Li if (property.first == "Enabled") 175151709ffdSYong Li { 175251709ffdSYong Li const bool* state = std::get_if<bool>(&property.second); 175351709ffdSYong Li 175451709ffdSYong Li if (!state) 175551709ffdSYong Li { 175651709ffdSYong Li messages::internalError(aResp->res); 175751709ffdSYong Li continue; 175851709ffdSYong Li } 175951709ffdSYong Li 176051709ffdSYong Li hostWatchdogTimer["FunctionEnabled"] = *state; 176151709ffdSYong Li } 176251709ffdSYong Li else if (property.first == "ExpireAction") 176351709ffdSYong Li { 176451709ffdSYong Li const std::string* s = 176551709ffdSYong Li std::get_if<std::string>(&property.second); 176651709ffdSYong Li if (!s) 176751709ffdSYong Li { 176851709ffdSYong Li messages::internalError(aResp->res); 176951709ffdSYong Li continue; 177051709ffdSYong Li } 177151709ffdSYong Li 177251709ffdSYong Li std::string action = dbusToRfWatchdogAction(*s); 177351709ffdSYong Li if (action.empty()) 177451709ffdSYong Li { 177551709ffdSYong Li messages::internalError(aResp->res); 177651709ffdSYong Li continue; 177751709ffdSYong Li } 177851709ffdSYong Li hostWatchdogTimer["TimeoutAction"] = action; 177951709ffdSYong Li } 178051709ffdSYong Li } 178151709ffdSYong Li }, 178251709ffdSYong Li "xyz.openbmc_project.Watchdog", "/xyz/openbmc_project/watchdog/host0", 178351709ffdSYong Li "org.freedesktop.DBus.Properties", "GetAll", 178451709ffdSYong Li "xyz.openbmc_project.State.Watchdog"); 178551709ffdSYong Li } 178651709ffdSYong Li 178751709ffdSYong Li /** 1788c45f0082SYong Li * @brief Sets Host WatchDog Timer properties. 1789c45f0082SYong Li * 1790c45f0082SYong Li * @param[in] aResp Shared pointer for generating response message. 1791c45f0082SYong Li * @param[in] wdtEnable The WDTimer Enable value (true/false) from incoming 1792c45f0082SYong Li * RF request. 1793c45f0082SYong Li * @param[in] wdtTimeOutAction The WDT Timeout action, from incoming RF request. 1794c45f0082SYong Li * 1795c45f0082SYong Li * @return None. 1796c45f0082SYong Li */ 1797b5a76932SEd Tanous inline void setWDTProperties(const std::shared_ptr<AsyncResp>& aResp, 1798c45f0082SYong Li const std::optional<bool> wdtEnable, 1799c45f0082SYong Li const std::optional<std::string>& wdtTimeOutAction) 1800c45f0082SYong Li { 1801c45f0082SYong Li BMCWEB_LOG_DEBUG << "Set host watchdog"; 1802c45f0082SYong Li 1803c45f0082SYong Li if (wdtTimeOutAction) 1804c45f0082SYong Li { 1805c45f0082SYong Li std::string wdtTimeOutActStr = rfToDbusWDTTimeOutAct(*wdtTimeOutAction); 1806c45f0082SYong Li // check if TimeOut Action is Valid 1807c45f0082SYong Li if (wdtTimeOutActStr.empty()) 1808c45f0082SYong Li { 1809c45f0082SYong Li BMCWEB_LOG_DEBUG << "Unsupported value for TimeoutAction: " 1810c45f0082SYong Li << *wdtTimeOutAction; 1811c45f0082SYong Li messages::propertyValueNotInList(aResp->res, *wdtTimeOutAction, 1812c45f0082SYong Li "TimeoutAction"); 1813c45f0082SYong Li return; 1814c45f0082SYong Li } 1815c45f0082SYong Li 1816c45f0082SYong Li crow::connections::systemBus->async_method_call( 1817c45f0082SYong Li [aResp](const boost::system::error_code ec) { 1818c45f0082SYong Li if (ec) 1819c45f0082SYong Li { 1820c45f0082SYong Li BMCWEB_LOG_DEBUG << "DBUS response error " << ec; 1821c45f0082SYong Li messages::internalError(aResp->res); 1822c45f0082SYong Li return; 1823c45f0082SYong Li } 1824c45f0082SYong Li }, 1825c45f0082SYong Li "xyz.openbmc_project.Watchdog", 1826c45f0082SYong Li "/xyz/openbmc_project/watchdog/host0", 1827c45f0082SYong Li "org.freedesktop.DBus.Properties", "Set", 1828c45f0082SYong Li "xyz.openbmc_project.State.Watchdog", "ExpireAction", 1829c45f0082SYong Li std::variant<std::string>(wdtTimeOutActStr)); 1830c45f0082SYong Li } 1831c45f0082SYong Li 1832c45f0082SYong Li if (wdtEnable) 1833c45f0082SYong Li { 1834c45f0082SYong Li crow::connections::systemBus->async_method_call( 1835c45f0082SYong Li [aResp](const boost::system::error_code ec) { 1836c45f0082SYong Li if (ec) 1837c45f0082SYong Li { 1838c45f0082SYong Li BMCWEB_LOG_DEBUG << "DBUS response error " << ec; 1839c45f0082SYong Li messages::internalError(aResp->res); 1840c45f0082SYong Li return; 1841c45f0082SYong Li } 1842c45f0082SYong Li }, 1843c45f0082SYong Li "xyz.openbmc_project.Watchdog", 1844c45f0082SYong Li "/xyz/openbmc_project/watchdog/host0", 1845c45f0082SYong Li "org.freedesktop.DBus.Properties", "Set", 1846c45f0082SYong Li "xyz.openbmc_project.State.Watchdog", "Enabled", 1847c45f0082SYong Li std::variant<bool>(*wdtEnable)); 1848c45f0082SYong Li } 1849c45f0082SYong Li } 1850c45f0082SYong Li 1851c45f0082SYong Li /** 1852c5b2abe0SLewanczyk, Dawid * SystemsCollection derived class for delivering ComputerSystems Collection 1853c5b2abe0SLewanczyk, Dawid * Schema 1854c5b2abe0SLewanczyk, Dawid */ 18551abe55efSEd Tanous class SystemsCollection : public Node 18561abe55efSEd Tanous { 1857c5b2abe0SLewanczyk, Dawid public: 185852cc112dSEd Tanous SystemsCollection(App& app) : Node(app, "/redfish/v1/Systems/") 18591abe55efSEd Tanous { 1860c5b2abe0SLewanczyk, Dawid entityPrivileges = { 1861c5b2abe0SLewanczyk, Dawid {boost::beast::http::verb::get, {{"Login"}}}, 1862c5b2abe0SLewanczyk, Dawid {boost::beast::http::verb::head, {{"Login"}}}, 1863c5b2abe0SLewanczyk, Dawid {boost::beast::http::verb::patch, {{"ConfigureComponents"}}}, 1864c5b2abe0SLewanczyk, Dawid {boost::beast::http::verb::put, {{"ConfigureComponents"}}}, 1865c5b2abe0SLewanczyk, Dawid {boost::beast::http::verb::delete_, {{"ConfigureComponents"}}}, 1866c5b2abe0SLewanczyk, Dawid {boost::beast::http::verb::post, {{"ConfigureComponents"}}}}; 1867c5b2abe0SLewanczyk, Dawid } 1868c5b2abe0SLewanczyk, Dawid 1869c5b2abe0SLewanczyk, Dawid private: 1870cb13a392SEd Tanous void doGet(crow::Response& res, const crow::Request&, 1871cb13a392SEd Tanous const std::vector<std::string>&) override 18721abe55efSEd Tanous { 1873462023adSSunitha Harish std::shared_ptr<AsyncResp> asyncResp = std::make_shared<AsyncResp>(res); 18740f74e643SEd Tanous res.jsonValue["@odata.type"] = 18750f74e643SEd Tanous "#ComputerSystemCollection.ComputerSystemCollection"; 18760f74e643SEd Tanous res.jsonValue["@odata.id"] = "/redfish/v1/Systems"; 18770f74e643SEd Tanous res.jsonValue["Name"] = "Computer System Collection"; 1878462023adSSunitha Harish 1879462023adSSunitha Harish crow::connections::systemBus->async_method_call( 1880462023adSSunitha Harish [asyncResp](const boost::system::error_code ec, 1881cb13a392SEd Tanous const std::variant<std::string>& /*hostName*/) { 18822c70f800SEd Tanous nlohmann::json& ifaceArray = 1883462023adSSunitha Harish asyncResp->res.jsonValue["Members"]; 18842c70f800SEd Tanous ifaceArray = nlohmann::json::array(); 1885462023adSSunitha Harish auto& count = asyncResp->res.jsonValue["Members@odata.count"]; 18862c70f800SEd Tanous ifaceArray.push_back( 1887cb13a392SEd Tanous {{"@odata.id", "/redfish/v1/Systems/system"}}); 188894bda602STim Lee count = ifaceArray.size(); 1889cb13a392SEd Tanous if (!ec) 1890462023adSSunitha Harish { 1891462023adSSunitha Harish BMCWEB_LOG_DEBUG << "Hypervisor is available"; 18922c70f800SEd Tanous ifaceArray.push_back( 1893462023adSSunitha Harish {{"@odata.id", "/redfish/v1/Systems/hypervisor"}}); 18942c70f800SEd Tanous count = ifaceArray.size(); 1895cb13a392SEd Tanous return; 1896cb13a392SEd Tanous } 1897462023adSSunitha Harish }, 18988e651fbfSSunitha Harish "xyz.openbmc_project.Settings", 18998e651fbfSSunitha Harish "/xyz/openbmc_project/network/hypervisor", 1900462023adSSunitha Harish "org.freedesktop.DBus.Properties", "Get", 1901462023adSSunitha Harish "xyz.openbmc_project.Network.SystemConfiguration", "HostName"); 1902c5b2abe0SLewanczyk, Dawid } 1903c5b2abe0SLewanczyk, Dawid }; 1904c5b2abe0SLewanczyk, Dawid 1905c5b2abe0SLewanczyk, Dawid /** 1906cc340dd9SEd Tanous * SystemActionsReset class supports handle POST method for Reset action. 1907cc340dd9SEd Tanous * The class retrieves and sends data directly to D-Bus. 1908cc340dd9SEd Tanous */ 1909cc340dd9SEd Tanous class SystemActionsReset : public Node 1910cc340dd9SEd Tanous { 1911cc340dd9SEd Tanous public: 191252cc112dSEd Tanous SystemActionsReset(App& app) : 1913029573d4SEd Tanous Node(app, "/redfish/v1/Systems/system/Actions/ComputerSystem.Reset/") 1914cc340dd9SEd Tanous { 1915cc340dd9SEd Tanous entityPrivileges = { 1916cc340dd9SEd Tanous {boost::beast::http::verb::post, {{"ConfigureComponents"}}}}; 1917cc340dd9SEd Tanous } 1918cc340dd9SEd Tanous 1919cc340dd9SEd Tanous private: 1920cc340dd9SEd Tanous /** 1921cc340dd9SEd Tanous * Function handles POST method request. 1922cc340dd9SEd Tanous * Analyzes POST body message before sends Reset request data to D-Bus. 1923cc340dd9SEd Tanous */ 1924cc340dd9SEd Tanous void doPost(crow::Response& res, const crow::Request& req, 1925cb13a392SEd Tanous const std::vector<std::string>&) override 1926cc340dd9SEd Tanous { 1927cc340dd9SEd Tanous auto asyncResp = std::make_shared<AsyncResp>(res); 1928cc340dd9SEd Tanous 19299712f8acSEd Tanous std::string resetType; 19309712f8acSEd Tanous if (!json_util::readJson(req, res, "ResetType", resetType)) 1931cc340dd9SEd Tanous { 1932cc340dd9SEd Tanous return; 1933cc340dd9SEd Tanous } 1934cc340dd9SEd Tanous 1935d22c8396SJason M. Bills // Get the command and host vs. chassis 1936cc340dd9SEd Tanous std::string command; 1937d22c8396SJason M. Bills bool hostCommand; 1938d4d25793SEd Tanous if ((resetType == "On") || (resetType == "ForceOn")) 1939cc340dd9SEd Tanous { 1940cc340dd9SEd Tanous command = "xyz.openbmc_project.State.Host.Transition.On"; 1941d22c8396SJason M. Bills hostCommand = true; 1942d22c8396SJason M. Bills } 1943d22c8396SJason M. Bills else if (resetType == "ForceOff") 1944d22c8396SJason M. Bills { 1945d22c8396SJason M. Bills command = "xyz.openbmc_project.State.Chassis.Transition.Off"; 1946d22c8396SJason M. Bills hostCommand = false; 1947d22c8396SJason M. Bills } 1948d22c8396SJason M. Bills else if (resetType == "ForceRestart") 1949d22c8396SJason M. Bills { 195086a0851aSJason M. Bills command = 195186a0851aSJason M. Bills "xyz.openbmc_project.State.Host.Transition.ForceWarmReboot"; 195286a0851aSJason M. Bills hostCommand = true; 1953cc340dd9SEd Tanous } 19549712f8acSEd Tanous else if (resetType == "GracefulShutdown") 1955cc340dd9SEd Tanous { 1956cc340dd9SEd Tanous command = "xyz.openbmc_project.State.Host.Transition.Off"; 1957d22c8396SJason M. Bills hostCommand = true; 1958cc340dd9SEd Tanous } 19599712f8acSEd Tanous else if (resetType == "GracefulRestart") 1960cc340dd9SEd Tanous { 196186a0851aSJason M. Bills command = 196286a0851aSJason M. Bills "xyz.openbmc_project.State.Host.Transition.GracefulWarmReboot"; 1963d22c8396SJason M. Bills hostCommand = true; 1964d22c8396SJason M. Bills } 1965d22c8396SJason M. Bills else if (resetType == "PowerCycle") 1966d22c8396SJason M. Bills { 196786a0851aSJason M. Bills command = "xyz.openbmc_project.State.Host.Transition.Reboot"; 196886a0851aSJason M. Bills hostCommand = true; 1969cc340dd9SEd Tanous } 1970bfd5b826SLakshminarayana R. Kammath else if (resetType == "Nmi") 1971bfd5b826SLakshminarayana R. Kammath { 1972bfd5b826SLakshminarayana R. Kammath doNMI(asyncResp); 1973bfd5b826SLakshminarayana R. Kammath return; 1974bfd5b826SLakshminarayana R. Kammath } 1975cc340dd9SEd Tanous else 1976cc340dd9SEd Tanous { 1977f12894f8SJason M. Bills messages::actionParameterUnknown(res, "Reset", resetType); 1978cc340dd9SEd Tanous return; 1979cc340dd9SEd Tanous } 1980cc340dd9SEd Tanous 1981d22c8396SJason M. Bills if (hostCommand) 1982d22c8396SJason M. Bills { 1983cc340dd9SEd Tanous crow::connections::systemBus->async_method_call( 1984d22c8396SJason M. Bills [asyncResp, resetType](const boost::system::error_code ec) { 1985cc340dd9SEd Tanous if (ec) 1986cc340dd9SEd Tanous { 1987cc340dd9SEd Tanous BMCWEB_LOG_ERROR << "D-Bus responses error: " << ec; 1988d22c8396SJason M. Bills if (ec.value() == boost::asio::error::invalid_argument) 1989d22c8396SJason M. Bills { 1990d22c8396SJason M. Bills messages::actionParameterNotSupported( 1991d22c8396SJason M. Bills asyncResp->res, resetType, "Reset"); 1992d22c8396SJason M. Bills } 1993d22c8396SJason M. Bills else 1994d22c8396SJason M. Bills { 1995f12894f8SJason M. Bills messages::internalError(asyncResp->res); 1996d22c8396SJason M. Bills } 1997cc340dd9SEd Tanous return; 1998cc340dd9SEd Tanous } 1999f12894f8SJason M. Bills messages::success(asyncResp->res); 2000cc340dd9SEd Tanous }, 2001cc340dd9SEd Tanous "xyz.openbmc_project.State.Host", 2002cc340dd9SEd Tanous "/xyz/openbmc_project/state/host0", 2003cc340dd9SEd Tanous "org.freedesktop.DBus.Properties", "Set", 20049712f8acSEd Tanous "xyz.openbmc_project.State.Host", "RequestedHostTransition", 2005abf2add6SEd Tanous std::variant<std::string>{command}); 2006cc340dd9SEd Tanous } 2007d22c8396SJason M. Bills else 2008d22c8396SJason M. Bills { 2009d22c8396SJason M. Bills crow::connections::systemBus->async_method_call( 2010d22c8396SJason M. Bills [asyncResp, resetType](const boost::system::error_code ec) { 2011d22c8396SJason M. Bills if (ec) 2012d22c8396SJason M. Bills { 2013d22c8396SJason M. Bills BMCWEB_LOG_ERROR << "D-Bus responses error: " << ec; 2014d22c8396SJason M. Bills if (ec.value() == boost::asio::error::invalid_argument) 2015d22c8396SJason M. Bills { 2016d22c8396SJason M. Bills messages::actionParameterNotSupported( 2017d22c8396SJason M. Bills asyncResp->res, resetType, "Reset"); 2018d22c8396SJason M. Bills } 2019d22c8396SJason M. Bills else 2020d22c8396SJason M. Bills { 2021d22c8396SJason M. Bills messages::internalError(asyncResp->res); 2022d22c8396SJason M. Bills } 2023d22c8396SJason M. Bills return; 2024d22c8396SJason M. Bills } 2025d22c8396SJason M. Bills messages::success(asyncResp->res); 2026d22c8396SJason M. Bills }, 2027d22c8396SJason M. Bills "xyz.openbmc_project.State.Chassis", 2028d22c8396SJason M. Bills "/xyz/openbmc_project/state/chassis0", 2029d22c8396SJason M. Bills "org.freedesktop.DBus.Properties", "Set", 2030d22c8396SJason M. Bills "xyz.openbmc_project.State.Chassis", "RequestedPowerTransition", 2031d22c8396SJason M. Bills std::variant<std::string>{command}); 2032d22c8396SJason M. Bills } 2033d22c8396SJason M. Bills } 2034bfd5b826SLakshminarayana R. Kammath /** 2035bfd5b826SLakshminarayana R. Kammath * Function transceives data with dbus directly. 2036bfd5b826SLakshminarayana R. Kammath */ 2037bfd5b826SLakshminarayana R. Kammath void doNMI(const std::shared_ptr<AsyncResp>& asyncResp) 2038bfd5b826SLakshminarayana R. Kammath { 2039bfd5b826SLakshminarayana R. Kammath constexpr char const* serviceName = 2040bfd5b826SLakshminarayana R. Kammath "xyz.openbmc_project.Control.Host.NMI"; 2041bfd5b826SLakshminarayana R. Kammath constexpr char const* objectPath = 2042bfd5b826SLakshminarayana R. Kammath "/xyz/openbmc_project/control/host0/nmi"; 2043bfd5b826SLakshminarayana R. Kammath constexpr char const* interfaceName = 2044bfd5b826SLakshminarayana R. Kammath "xyz.openbmc_project.Control.Host.NMI"; 2045bfd5b826SLakshminarayana R. Kammath constexpr char const* method = "NMI"; 2046bfd5b826SLakshminarayana R. Kammath 2047bfd5b826SLakshminarayana R. Kammath crow::connections::systemBus->async_method_call( 2048bfd5b826SLakshminarayana R. Kammath [asyncResp](const boost::system::error_code ec) { 2049bfd5b826SLakshminarayana R. Kammath if (ec) 2050bfd5b826SLakshminarayana R. Kammath { 2051bfd5b826SLakshminarayana R. Kammath BMCWEB_LOG_ERROR << " Bad D-Bus request error: " << ec; 2052bfd5b826SLakshminarayana R. Kammath messages::internalError(asyncResp->res); 2053bfd5b826SLakshminarayana R. Kammath return; 2054bfd5b826SLakshminarayana R. Kammath } 2055bfd5b826SLakshminarayana R. Kammath messages::success(asyncResp->res); 2056bfd5b826SLakshminarayana R. Kammath }, 2057bfd5b826SLakshminarayana R. Kammath serviceName, objectPath, interfaceName, method); 2058bfd5b826SLakshminarayana R. Kammath } 2059cc340dd9SEd Tanous }; 2060cc340dd9SEd Tanous 2061cc340dd9SEd Tanous /** 20626617338dSEd Tanous * Systems derived class for delivering Computer Systems Schema. 2063c5b2abe0SLewanczyk, Dawid */ 20641abe55efSEd Tanous class Systems : public Node 20651abe55efSEd Tanous { 2066c5b2abe0SLewanczyk, Dawid public: 2067c5b2abe0SLewanczyk, Dawid /* 2068c5b2abe0SLewanczyk, Dawid * Default Constructor 2069c5b2abe0SLewanczyk, Dawid */ 207052cc112dSEd Tanous Systems(App& app) : Node(app, "/redfish/v1/Systems/system/") 20711abe55efSEd Tanous { 2072c5b2abe0SLewanczyk, Dawid entityPrivileges = { 2073c5b2abe0SLewanczyk, Dawid {boost::beast::http::verb::get, {{"Login"}}}, 2074c5b2abe0SLewanczyk, Dawid {boost::beast::http::verb::head, {{"Login"}}}, 2075c5b2abe0SLewanczyk, Dawid {boost::beast::http::verb::patch, {{"ConfigureComponents"}}}, 2076c5b2abe0SLewanczyk, Dawid {boost::beast::http::verb::put, {{"ConfigureComponents"}}}, 2077c5b2abe0SLewanczyk, Dawid {boost::beast::http::verb::delete_, {{"ConfigureComponents"}}}, 2078c5b2abe0SLewanczyk, Dawid {boost::beast::http::verb::post, {{"ConfigureComponents"}}}}; 2079c5b2abe0SLewanczyk, Dawid } 2080c5b2abe0SLewanczyk, Dawid 2081c5b2abe0SLewanczyk, Dawid private: 2082c5b2abe0SLewanczyk, Dawid /** 2083c5b2abe0SLewanczyk, Dawid * Functions triggers appropriate requests on DBus 2084c5b2abe0SLewanczyk, Dawid */ 2085cb13a392SEd Tanous void doGet(crow::Response& res, const crow::Request&, 2086cb13a392SEd Tanous const std::vector<std::string>&) override 20871abe55efSEd Tanous { 20889f8bfa7cSGunnar Mills res.jsonValue["@odata.type"] = "#ComputerSystem.v1_13_0.ComputerSystem"; 2089450a25cbSGunnar Mills res.jsonValue["Name"] = "system"; 2090029573d4SEd Tanous res.jsonValue["Id"] = "system"; 20910f74e643SEd Tanous res.jsonValue["SystemType"] = "Physical"; 20920f74e643SEd Tanous res.jsonValue["Description"] = "Computer System"; 20930f74e643SEd Tanous res.jsonValue["ProcessorSummary"]["Count"] = 0; 20940f74e643SEd Tanous res.jsonValue["ProcessorSummary"]["Status"]["State"] = "Disabled"; 20955fd7ba65SCheng C Yang res.jsonValue["MemorySummary"]["TotalSystemMemoryGiB"] = uint64_t(0); 20960f74e643SEd Tanous res.jsonValue["MemorySummary"]["Status"]["State"] = "Disabled"; 2097029573d4SEd Tanous res.jsonValue["@odata.id"] = "/redfish/v1/Systems/system"; 209804a258f4SEd Tanous 2099443c2934SRapkiewicz, Pawel res.jsonValue["Processors"] = { 2100029573d4SEd Tanous {"@odata.id", "/redfish/v1/Systems/system/Processors"}}; 2101443c2934SRapkiewicz, Pawel res.jsonValue["Memory"] = { 2102029573d4SEd Tanous {"@odata.id", "/redfish/v1/Systems/system/Memory"}}; 2103a25aeccfSNikhil Potade res.jsonValue["Storage"] = { 2104a25aeccfSNikhil Potade {"@odata.id", "/redfish/v1/Systems/system/Storage"}}; 2105029573d4SEd Tanous 2106cc340dd9SEd Tanous res.jsonValue["Actions"]["#ComputerSystem.Reset"] = { 2107cc340dd9SEd Tanous {"target", 2108029573d4SEd Tanous "/redfish/v1/Systems/system/Actions/ComputerSystem.Reset"}, 21091cb1a9e6SAppaRao Puli {"@Redfish.ActionInfo", 21101cb1a9e6SAppaRao Puli "/redfish/v1/Systems/system/ResetActionInfo"}}; 2111c5b2abe0SLewanczyk, Dawid 2112c4bf6374SJason M. Bills res.jsonValue["LogServices"] = { 2113029573d4SEd Tanous {"@odata.id", "/redfish/v1/Systems/system/LogServices"}}; 2114c4bf6374SJason M. Bills 2115d82a3acdSCarol Wang res.jsonValue["Bios"] = { 2116d82a3acdSCarol Wang {"@odata.id", "/redfish/v1/Systems/system/Bios"}}; 2117d82a3acdSCarol Wang 2118c5d03ff4SJennifer Lee res.jsonValue["Links"]["ManagedBy"] = { 2119c5d03ff4SJennifer Lee {{"@odata.id", "/redfish/v1/Managers/bmc"}}}; 2120c5d03ff4SJennifer Lee 2121c5d03ff4SJennifer Lee res.jsonValue["Status"] = { 2122c5d03ff4SJennifer Lee {"Health", "OK"}, 2123c5d03ff4SJennifer Lee {"State", "Enabled"}, 2124c5d03ff4SJennifer Lee }; 2125a0803efaSEd Tanous auto asyncResp = std::make_shared<AsyncResp>(res); 2126c5b2abe0SLewanczyk, Dawid 2127e284a7c1SJames Feist constexpr const std::array<const char*, 4> inventoryForSystems = { 2128b49ac873SJames Feist "xyz.openbmc_project.Inventory.Item.Dimm", 21292ad9c2f6SJames Feist "xyz.openbmc_project.Inventory.Item.Cpu", 2130e284a7c1SJames Feist "xyz.openbmc_project.Inventory.Item.Drive", 2131e284a7c1SJames Feist "xyz.openbmc_project.Inventory.Item.StorageController"}; 2132b49ac873SJames Feist 2133b49ac873SJames Feist auto health = std::make_shared<HealthPopulate>(asyncResp); 2134b49ac873SJames Feist crow::connections::systemBus->async_method_call( 2135b49ac873SJames Feist [health](const boost::system::error_code ec, 2136b49ac873SJames Feist std::vector<std::string>& resp) { 2137b49ac873SJames Feist if (ec) 2138b49ac873SJames Feist { 2139b49ac873SJames Feist // no inventory 2140b49ac873SJames Feist return; 2141b49ac873SJames Feist } 2142b49ac873SJames Feist 2143b49ac873SJames Feist health->inventory = std::move(resp); 2144b49ac873SJames Feist }, 2145b49ac873SJames Feist "xyz.openbmc_project.ObjectMapper", 2146b49ac873SJames Feist "/xyz/openbmc_project/object_mapper", 2147b49ac873SJames Feist "xyz.openbmc_project.ObjectMapper", "GetSubTreePaths", "/", 2148b49ac873SJames Feist int32_t(0), inventoryForSystems); 2149b49ac873SJames Feist 2150b49ac873SJames Feist health->populate(); 2151b49ac873SJames Feist 2152c5d03ff4SJennifer Lee getMainChassisId(asyncResp, [](const std::string& chassisId, 2153b5a76932SEd Tanous const std::shared_ptr<AsyncResp>& aRsp) { 2154c5d03ff4SJennifer Lee aRsp->res.jsonValue["Links"]["Chassis"] = { 2155c5d03ff4SJennifer Lee {{"@odata.id", "/redfish/v1/Chassis/" + chassisId}}}; 2156c5d03ff4SJennifer Lee }); 2157a3002228SAppaRao Puli 21589f8bfa7cSGunnar Mills getLocationIndicatorActive(asyncResp); 21599f8bfa7cSGunnar Mills // TODO (Gunnar): Remove IndicatorLED after enough time has passed 2160a3002228SAppaRao Puli getIndicatorLedState(asyncResp); 21615bc2dc8eSJames Feist getComputerSystem(asyncResp, health); 21626c34de48SEd Tanous getHostState(asyncResp); 2163491d8ee7SSantosh Puranik getBootProperties(asyncResp); 2164978b8803SAndrew Geissler getBootProgress(asyncResp); 2165adbe192aSJason M. Bills getPCIeDeviceList(asyncResp, "PCIeDevices"); 216651709ffdSYong Li getHostWatchdogTimer(asyncResp); 2167c6a620f2SGeorge Liu getPowerRestorePolicy(asyncResp); 21686bd5a8d2SGunnar Mills getAutomaticRetry(asyncResp); 2169c0557e1aSGunnar Mills getLastResetTime(asyncResp); 2170a6349918SAppaRao Puli #ifdef BMCWEB_ENABLE_REDFISH_PROVISIONING_FEATURE 2171a6349918SAppaRao Puli getProvisioningStatus(asyncResp); 2172a6349918SAppaRao Puli #endif 2173c5b2abe0SLewanczyk, Dawid } 2174c5b2abe0SLewanczyk, Dawid 217555c7b7a2SEd Tanous void doPatch(crow::Response& res, const crow::Request& req, 2176cb13a392SEd Tanous const std::vector<std::string>&) override 21771abe55efSEd Tanous { 21789f8bfa7cSGunnar Mills std::optional<bool> locationIndicatorActive; 2179cde19e5fSSantosh Puranik std::optional<std::string> indicatorLed; 2180491d8ee7SSantosh Puranik std::optional<nlohmann::json> bootProps; 2181c45f0082SYong Li std::optional<nlohmann::json> wdtTimerProps; 218298e386ecSGunnar Mills std::optional<std::string> assetTag; 2183c6a620f2SGeorge Liu std::optional<std::string> powerRestorePolicy; 218441352c24SSantosh Puranik auto asyncResp = std::make_shared<AsyncResp>(res); 218541352c24SSantosh Puranik 21869f8bfa7cSGunnar Mills if (!json_util::readJson( 21879f8bfa7cSGunnar Mills req, res, "IndicatorLED", indicatorLed, 21889f8bfa7cSGunnar Mills "LocationIndicatorActive", locationIndicatorActive, "Boot", 21899f8bfa7cSGunnar Mills bootProps, "WatchdogTimer", wdtTimerProps, "PowerRestorePolicy", 21909f8bfa7cSGunnar Mills powerRestorePolicy, "AssetTag", assetTag)) 21916617338dSEd Tanous { 21926617338dSEd Tanous return; 21936617338dSEd Tanous } 2194491d8ee7SSantosh Puranik 2195944ffaf9SJohnathan Mantey res.result(boost::beast::http::status::no_content); 2196c45f0082SYong Li 219798e386ecSGunnar Mills if (assetTag) 219898e386ecSGunnar Mills { 219998e386ecSGunnar Mills setAssetTag(asyncResp, *assetTag); 220098e386ecSGunnar Mills } 220198e386ecSGunnar Mills 2202c45f0082SYong Li if (wdtTimerProps) 2203c45f0082SYong Li { 2204c45f0082SYong Li std::optional<bool> wdtEnable; 2205c45f0082SYong Li std::optional<std::string> wdtTimeOutAction; 2206c45f0082SYong Li 2207c45f0082SYong Li if (!json_util::readJson(*wdtTimerProps, asyncResp->res, 2208c45f0082SYong Li "FunctionEnabled", wdtEnable, 2209c45f0082SYong Li "TimeoutAction", wdtTimeOutAction)) 2210c45f0082SYong Li { 2211c45f0082SYong Li return; 2212c45f0082SYong Li } 2213f23b7296SEd Tanous setWDTProperties(asyncResp, wdtEnable, wdtTimeOutAction); 2214c45f0082SYong Li } 2215c45f0082SYong Li 2216491d8ee7SSantosh Puranik if (bootProps) 2217491d8ee7SSantosh Puranik { 2218491d8ee7SSantosh Puranik std::optional<std::string> bootSource; 2219491d8ee7SSantosh Puranik std::optional<std::string> bootEnable; 222069f35306SGunnar Mills std::optional<std::string> automaticRetryConfig; 2221491d8ee7SSantosh Puranik 222269f35306SGunnar Mills if (!json_util::readJson( 222369f35306SGunnar Mills *bootProps, asyncResp->res, "BootSourceOverrideTarget", 222469f35306SGunnar Mills bootSource, "BootSourceOverrideEnabled", bootEnable, 222569f35306SGunnar Mills "AutomaticRetryConfig", automaticRetryConfig)) 2226491d8ee7SSantosh Puranik { 2227491d8ee7SSantosh Puranik return; 2228491d8ee7SSantosh Puranik } 222969f35306SGunnar Mills if (bootSource || bootEnable) 223069f35306SGunnar Mills { 223169f35306SGunnar Mills setBootSourceProperties(asyncResp, std::move(bootSource), 2232491d8ee7SSantosh Puranik std::move(bootEnable)); 2233491d8ee7SSantosh Puranik } 223469f35306SGunnar Mills if (automaticRetryConfig) 223569f35306SGunnar Mills { 2236f23b7296SEd Tanous setAutomaticRetry(asyncResp, *automaticRetryConfig); 223769f35306SGunnar Mills } 223869f35306SGunnar Mills } 2239265c1602SJohnathan Mantey 22409f8bfa7cSGunnar Mills if (locationIndicatorActive) 22419f8bfa7cSGunnar Mills { 22429f8bfa7cSGunnar Mills setLocationIndicatorActive(asyncResp, *locationIndicatorActive); 22439f8bfa7cSGunnar Mills } 22449f8bfa7cSGunnar Mills 22459f8bfa7cSGunnar Mills // TODO (Gunnar): Remove IndicatorLED after enough time has passed 22469712f8acSEd Tanous if (indicatorLed) 22476617338dSEd Tanous { 2248f23b7296SEd Tanous setIndicatorLedState(asyncResp, *indicatorLed); 2249d6aa0093SGunnar Mills res.addHeader(boost::beast::http::field::warning, 2250d6aa0093SGunnar Mills "299 - \"IndicatorLED is deprecated. Use " 2251d6aa0093SGunnar Mills "LocationIndicatorActive instead.\""); 22526617338dSEd Tanous } 2253c6a620f2SGeorge Liu 2254c6a620f2SGeorge Liu if (powerRestorePolicy) 2255c6a620f2SGeorge Liu { 2256*4e69c904SGunnar Mills setPowerRestorePolicy(asyncResp, *powerRestorePolicy); 2257c6a620f2SGeorge Liu } 2258c5b2abe0SLewanczyk, Dawid } 2259c5b2abe0SLewanczyk, Dawid }; 22601cb1a9e6SAppaRao Puli 22611cb1a9e6SAppaRao Puli /** 22621cb1a9e6SAppaRao Puli * SystemResetActionInfo derived class for delivering Computer Systems 22631cb1a9e6SAppaRao Puli * ResetType AllowableValues using ResetInfo schema. 22641cb1a9e6SAppaRao Puli */ 22651cb1a9e6SAppaRao Puli class SystemResetActionInfo : public Node 22661cb1a9e6SAppaRao Puli { 22671cb1a9e6SAppaRao Puli public: 22681cb1a9e6SAppaRao Puli /* 22691cb1a9e6SAppaRao Puli * Default Constructor 22701cb1a9e6SAppaRao Puli */ 227152cc112dSEd Tanous SystemResetActionInfo(App& app) : 22721cb1a9e6SAppaRao Puli Node(app, "/redfish/v1/Systems/system/ResetActionInfo/") 22731cb1a9e6SAppaRao Puli { 22741cb1a9e6SAppaRao Puli entityPrivileges = { 22751cb1a9e6SAppaRao Puli {boost::beast::http::verb::get, {{"Login"}}}, 22761cb1a9e6SAppaRao Puli {boost::beast::http::verb::head, {{"Login"}}}, 22771cb1a9e6SAppaRao Puli {boost::beast::http::verb::patch, {{"ConfigureComponents"}}}, 22781cb1a9e6SAppaRao Puli {boost::beast::http::verb::put, {{"ConfigureComponents"}}}, 22791cb1a9e6SAppaRao Puli {boost::beast::http::verb::delete_, {{"ConfigureComponents"}}}, 22801cb1a9e6SAppaRao Puli {boost::beast::http::verb::post, {{"ConfigureComponents"}}}}; 22811cb1a9e6SAppaRao Puli } 22821cb1a9e6SAppaRao Puli 22831cb1a9e6SAppaRao Puli private: 22841cb1a9e6SAppaRao Puli /** 22851cb1a9e6SAppaRao Puli * Functions triggers appropriate requests on DBus 22861cb1a9e6SAppaRao Puli */ 2287cb13a392SEd Tanous void doGet(crow::Response& res, const crow::Request&, 2288cb13a392SEd Tanous const std::vector<std::string>&) override 22891cb1a9e6SAppaRao Puli { 22901cb1a9e6SAppaRao Puli res.jsonValue = { 22911cb1a9e6SAppaRao Puli {"@odata.type", "#ActionInfo.v1_1_2.ActionInfo"}, 22921cb1a9e6SAppaRao Puli {"@odata.id", "/redfish/v1/Systems/system/ResetActionInfo"}, 22931cb1a9e6SAppaRao Puli {"Name", "Reset Action Info"}, 22941cb1a9e6SAppaRao Puli {"Id", "ResetActionInfo"}, 22951cb1a9e6SAppaRao Puli {"Parameters", 22961cb1a9e6SAppaRao Puli {{{"Name", "ResetType"}, 22971cb1a9e6SAppaRao Puli {"Required", true}, 22981cb1a9e6SAppaRao Puli {"DataType", "String"}, 22991cb1a9e6SAppaRao Puli {"AllowableValues", 23001cb1a9e6SAppaRao Puli {"On", "ForceOff", "ForceOn", "ForceRestart", "GracefulRestart", 23011cb1a9e6SAppaRao Puli "GracefulShutdown", "PowerCycle", "Nmi"}}}}}}; 23021cb1a9e6SAppaRao Puli res.end(); 23031cb1a9e6SAppaRao Puli } 23041cb1a9e6SAppaRao Puli }; 2305c5b2abe0SLewanczyk, Dawid } // namespace redfish 2306