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 143c5b2abe0SLewanczyk, Dawid * @param[in] name Computer system name from request 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}, 205*f23b7296SEd 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}, 311*f23b7296SEd 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") || 542fc5afcf9Sbeccabroek (propertyName == "Model")) 543fc5afcf9Sbeccabroek { 544029573d4SEd Tanous const std::string* value = 545fc5afcf9Sbeccabroek std::get_if<std::string>( 546029573d4SEd Tanous &property.second); 547029573d4SEd Tanous if (value != nullptr) 548029573d4SEd Tanous { 549029573d4SEd Tanous aResp->res 550fc5afcf9Sbeccabroek .jsonValue[propertyName] = 551029573d4SEd Tanous *value; 552029573d4SEd Tanous } 553029573d4SEd Tanous } 554fc5afcf9Sbeccabroek } 555c1e236a6SGunnar Mills 556cb7e1e7bSAndrew Geissler // Grab the bios version 557f97ddba7SGunnar Mills fw_util::populateFirmwareInformation( 558cb7e1e7bSAndrew Geissler aResp, fw_util::biosPurpose, 55972d566d9SGunnar Mills "BiosVersion", false); 560029573d4SEd Tanous }, 561029573d4SEd Tanous connection.first, path, 562029573d4SEd Tanous "org.freedesktop.DBus.Properties", "GetAll", 563029573d4SEd Tanous "xyz.openbmc_project.Inventory.Decorator." 564029573d4SEd Tanous "Asset"); 565e4a4b9a9SJames Feist 566e4a4b9a9SJames Feist crow::connections::systemBus->async_method_call( 567e4a4b9a9SJames Feist [aResp]( 568cb13a392SEd Tanous const boost::system::error_code ec2, 569e4a4b9a9SJames Feist const std::variant<std::string>& property) { 570cb13a392SEd Tanous if (ec2) 571e4a4b9a9SJames Feist { 572e4a4b9a9SJames Feist // doesn't have to include this 573e4a4b9a9SJames Feist // interface 574e4a4b9a9SJames Feist return; 575e4a4b9a9SJames Feist } 576e4a4b9a9SJames Feist 577e4a4b9a9SJames Feist const std::string* value = 578e4a4b9a9SJames Feist std::get_if<std::string>(&property); 579e4a4b9a9SJames Feist if (value != nullptr) 580e4a4b9a9SJames Feist { 581e4a4b9a9SJames Feist aResp->res.jsonValue["AssetTag"] = 582e4a4b9a9SJames Feist *value; 583e4a4b9a9SJames Feist } 584e4a4b9a9SJames Feist }, 585e4a4b9a9SJames Feist connection.first, path, 586e4a4b9a9SJames Feist "org.freedesktop.DBus.Properties", "Get", 587e4a4b9a9SJames Feist "xyz.openbmc_project.Inventory.Decorator." 588e4a4b9a9SJames Feist "AssetTag", 589e4a4b9a9SJames Feist "AssetTag"); 590029573d4SEd Tanous } 591029573d4SEd Tanous } 592029573d4SEd Tanous } 593c5b2abe0SLewanczyk, Dawid } 594c5b2abe0SLewanczyk, Dawid }, 595c5b2abe0SLewanczyk, Dawid "xyz.openbmc_project.ObjectMapper", 596c5b2abe0SLewanczyk, Dawid "/xyz/openbmc_project/object_mapper", 597c5b2abe0SLewanczyk, Dawid "xyz.openbmc_project.ObjectMapper", "GetSubTree", 5986617338dSEd Tanous "/xyz/openbmc_project/inventory", int32_t(0), 5996617338dSEd Tanous std::array<const char*, 5>{ 6006617338dSEd Tanous "xyz.openbmc_project.Inventory.Decorator.Asset", 6016617338dSEd Tanous "xyz.openbmc_project.Inventory.Item.Cpu", 6026617338dSEd Tanous "xyz.openbmc_project.Inventory.Item.Dimm", 6036617338dSEd Tanous "xyz.openbmc_project.Inventory.Item.System", 6046617338dSEd Tanous "xyz.openbmc_project.Common.UUID", 6056617338dSEd Tanous }); 606c5b2abe0SLewanczyk, Dawid } 607c5b2abe0SLewanczyk, Dawid 608c5b2abe0SLewanczyk, Dawid /** 609c5b2abe0SLewanczyk, Dawid * @brief Retrieves host state properties over dbus 610c5b2abe0SLewanczyk, Dawid * 611c5b2abe0SLewanczyk, Dawid * @param[in] aResp Shared pointer for completing asynchronous calls. 612c5b2abe0SLewanczyk, Dawid * 613c5b2abe0SLewanczyk, Dawid * @return None. 614c5b2abe0SLewanczyk, Dawid */ 615b5a76932SEd Tanous inline void getHostState(const std::shared_ptr<AsyncResp>& aResp) 6161abe55efSEd Tanous { 61755c7b7a2SEd Tanous BMCWEB_LOG_DEBUG << "Get host information."; 61855c7b7a2SEd Tanous crow::connections::systemBus->async_method_call( 619c5d03ff4SJennifer Lee [aResp](const boost::system::error_code ec, 620abf2add6SEd Tanous const std::variant<std::string>& hostState) { 6211abe55efSEd Tanous if (ec) 6221abe55efSEd Tanous { 62355c7b7a2SEd Tanous BMCWEB_LOG_DEBUG << "DBUS response error " << ec; 624f12894f8SJason M. Bills messages::internalError(aResp->res); 625c5b2abe0SLewanczyk, Dawid return; 626c5b2abe0SLewanczyk, Dawid } 6276617338dSEd Tanous 628abf2add6SEd Tanous const std::string* s = std::get_if<std::string>(&hostState); 62955c7b7a2SEd Tanous BMCWEB_LOG_DEBUG << "Host state: " << *s; 6306617338dSEd Tanous if (s != nullptr) 6311abe55efSEd Tanous { 632c5b2abe0SLewanczyk, Dawid // Verify Host State 63394732661SAndrew Geissler if (*s == "xyz.openbmc_project.State.Host.HostState.Running") 6341abe55efSEd Tanous { 63555c7b7a2SEd Tanous aResp->res.jsonValue["PowerState"] = "On"; 6366617338dSEd Tanous aResp->res.jsonValue["Status"]["State"] = "Enabled"; 6371abe55efSEd Tanous } 63883935af9SAndrew Geissler else if (*s == "xyz.openbmc_project.State.Host.HostState." 6398c888608SGunnar Mills "Quiesced") 6408c888608SGunnar Mills { 6418c888608SGunnar Mills aResp->res.jsonValue["PowerState"] = "On"; 6428c888608SGunnar Mills aResp->res.jsonValue["Status"]["State"] = "Quiesced"; 6438c888608SGunnar Mills } 6448c888608SGunnar Mills else if (*s == "xyz.openbmc_project.State.Host.HostState." 64583935af9SAndrew Geissler "DiagnosticMode") 64683935af9SAndrew Geissler { 64783935af9SAndrew Geissler aResp->res.jsonValue["PowerState"] = "On"; 64883935af9SAndrew Geissler aResp->res.jsonValue["Status"]["State"] = "InTest"; 64983935af9SAndrew Geissler } 6501abe55efSEd Tanous else 6511abe55efSEd Tanous { 65255c7b7a2SEd Tanous aResp->res.jsonValue["PowerState"] = "Off"; 6536617338dSEd Tanous aResp->res.jsonValue["Status"]["State"] = "Disabled"; 654c5b2abe0SLewanczyk, Dawid } 655c5b2abe0SLewanczyk, Dawid } 656c5b2abe0SLewanczyk, Dawid }, 6576c34de48SEd Tanous "xyz.openbmc_project.State.Host", "/xyz/openbmc_project/state/host0", 6586617338dSEd Tanous "org.freedesktop.DBus.Properties", "Get", 6596617338dSEd Tanous "xyz.openbmc_project.State.Host", "CurrentHostState"); 660c5b2abe0SLewanczyk, Dawid } 661c5b2abe0SLewanczyk, Dawid 662c5b2abe0SLewanczyk, Dawid /** 663786d0f60SGunnar Mills * @brief Translates boot source DBUS property value to redfish. 664491d8ee7SSantosh Puranik * 665491d8ee7SSantosh Puranik * @param[in] dbusSource The boot source in DBUS speak. 666491d8ee7SSantosh Puranik * 667491d8ee7SSantosh Puranik * @return Returns as a string, the boot source in Redfish terms. If translation 668491d8ee7SSantosh Puranik * cannot be done, returns an empty string. 669491d8ee7SSantosh Puranik */ 67023a21a1cSEd Tanous inline std::string dbusToRfBootSource(const std::string& dbusSource) 671491d8ee7SSantosh Puranik { 672491d8ee7SSantosh Puranik if (dbusSource == "xyz.openbmc_project.Control.Boot.Source.Sources.Default") 673491d8ee7SSantosh Puranik { 674491d8ee7SSantosh Puranik return "None"; 675491d8ee7SSantosh Puranik } 6763174e4dfSEd Tanous if (dbusSource == "xyz.openbmc_project.Control.Boot.Source.Sources.Disk") 677491d8ee7SSantosh Puranik { 678491d8ee7SSantosh Puranik return "Hdd"; 679491d8ee7SSantosh Puranik } 6803174e4dfSEd Tanous if (dbusSource == 681a71dc0b7SSantosh Puranik "xyz.openbmc_project.Control.Boot.Source.Sources.ExternalMedia") 682491d8ee7SSantosh Puranik { 683491d8ee7SSantosh Puranik return "Cd"; 684491d8ee7SSantosh Puranik } 6853174e4dfSEd Tanous if (dbusSource == "xyz.openbmc_project.Control.Boot.Source.Sources.Network") 686491d8ee7SSantosh Puranik { 687491d8ee7SSantosh Puranik return "Pxe"; 688491d8ee7SSantosh Puranik } 6893174e4dfSEd Tanous if (dbusSource == 690944ffaf9SJohnathan Mantey "xyz.openbmc_project.Control.Boot.Source.Sources.RemovableMedia") 6919f16b2c1SJennifer Lee { 6929f16b2c1SJennifer Lee return "Usb"; 6939f16b2c1SJennifer Lee } 694491d8ee7SSantosh Puranik return ""; 695491d8ee7SSantosh Puranik } 696491d8ee7SSantosh Puranik 697491d8ee7SSantosh Puranik /** 698786d0f60SGunnar Mills * @brief Translates boot mode DBUS property value to redfish. 699491d8ee7SSantosh Puranik * 700491d8ee7SSantosh Puranik * @param[in] dbusMode The boot mode in DBUS speak. 701491d8ee7SSantosh Puranik * 702491d8ee7SSantosh Puranik * @return Returns as a string, the boot mode in Redfish terms. If translation 703491d8ee7SSantosh Puranik * cannot be done, returns an empty string. 704491d8ee7SSantosh Puranik */ 70523a21a1cSEd Tanous inline std::string dbusToRfBootMode(const std::string& dbusMode) 706491d8ee7SSantosh Puranik { 707491d8ee7SSantosh Puranik if (dbusMode == "xyz.openbmc_project.Control.Boot.Mode.Modes.Regular") 708491d8ee7SSantosh Puranik { 709491d8ee7SSantosh Puranik return "None"; 710491d8ee7SSantosh Puranik } 7113174e4dfSEd Tanous if (dbusMode == "xyz.openbmc_project.Control.Boot.Mode.Modes.Safe") 712491d8ee7SSantosh Puranik { 713491d8ee7SSantosh Puranik return "Diags"; 714491d8ee7SSantosh Puranik } 7153174e4dfSEd Tanous if (dbusMode == "xyz.openbmc_project.Control.Boot.Mode.Modes.Setup") 716491d8ee7SSantosh Puranik { 717491d8ee7SSantosh Puranik return "BiosSetup"; 718491d8ee7SSantosh Puranik } 719491d8ee7SSantosh Puranik return ""; 720491d8ee7SSantosh Puranik } 721491d8ee7SSantosh Puranik 722491d8ee7SSantosh Puranik /** 723786d0f60SGunnar Mills * @brief Translates boot source from Redfish to the DBus boot paths. 724491d8ee7SSantosh Puranik * 725491d8ee7SSantosh Puranik * @param[in] rfSource The boot source in Redfish. 726944ffaf9SJohnathan Mantey * @param[out] bootSource The DBus source 727944ffaf9SJohnathan Mantey * @param[out] bootMode the DBus boot mode 728491d8ee7SSantosh Puranik * 729944ffaf9SJohnathan Mantey * @return Integer error code. 730491d8ee7SSantosh Puranik */ 731b5a76932SEd Tanous inline int assignBootParameters(const std::shared_ptr<AsyncResp>& aResp, 732944ffaf9SJohnathan Mantey const std::string& rfSource, 733944ffaf9SJohnathan Mantey std::string& bootSource, std::string& bootMode) 734491d8ee7SSantosh Puranik { 735944ffaf9SJohnathan Mantey // The caller has initialized the bootSource and bootMode to: 736944ffaf9SJohnathan Mantey // bootMode = "xyz.openbmc_project.Control.Boot.Mode.Modes.Regular"; 737944ffaf9SJohnathan Mantey // bootSource = "xyz.openbmc_project.Control.Boot.Source.Sources.Default"; 738944ffaf9SJohnathan Mantey // Only modify the bootSource/bootMode variable needed to achieve the 739944ffaf9SJohnathan Mantey // desired boot action. 740944ffaf9SJohnathan Mantey 741491d8ee7SSantosh Puranik if (rfSource == "None") 742491d8ee7SSantosh Puranik { 743944ffaf9SJohnathan Mantey return 0; 744491d8ee7SSantosh Puranik } 7453174e4dfSEd Tanous if (rfSource == "Pxe") 746491d8ee7SSantosh Puranik { 747944ffaf9SJohnathan Mantey bootSource = "xyz.openbmc_project.Control.Boot.Source.Sources.Network"; 748944ffaf9SJohnathan Mantey } 749944ffaf9SJohnathan Mantey else if (rfSource == "Hdd") 750944ffaf9SJohnathan Mantey { 751944ffaf9SJohnathan Mantey bootSource = "xyz.openbmc_project.Control.Boot.Source.Sources.Disk"; 752944ffaf9SJohnathan Mantey } 753944ffaf9SJohnathan Mantey else if (rfSource == "Diags") 754944ffaf9SJohnathan Mantey { 755944ffaf9SJohnathan Mantey bootMode = "xyz.openbmc_project.Control.Boot.Mode.Modes.Safe"; 756944ffaf9SJohnathan Mantey } 757944ffaf9SJohnathan Mantey else if (rfSource == "Cd") 758944ffaf9SJohnathan Mantey { 759944ffaf9SJohnathan Mantey bootSource = 760944ffaf9SJohnathan Mantey "xyz.openbmc_project.Control.Boot.Source.Sources.ExternalMedia"; 761944ffaf9SJohnathan Mantey } 762944ffaf9SJohnathan Mantey else if (rfSource == "BiosSetup") 763944ffaf9SJohnathan Mantey { 764944ffaf9SJohnathan Mantey bootMode = "xyz.openbmc_project.Control.Boot.Mode.Modes.Setup"; 765491d8ee7SSantosh Puranik } 7669f16b2c1SJennifer Lee else if (rfSource == "Usb") 7679f16b2c1SJennifer Lee { 768944ffaf9SJohnathan Mantey bootSource = 769944ffaf9SJohnathan Mantey "xyz.openbmc_project.Control.Boot.Source.Sources.RemovableMedia"; 7709f16b2c1SJennifer Lee } 771491d8ee7SSantosh Puranik else 772491d8ee7SSantosh Puranik { 773944ffaf9SJohnathan Mantey BMCWEB_LOG_DEBUG << "Invalid property value for " 774944ffaf9SJohnathan Mantey "BootSourceOverrideTarget: " 775944ffaf9SJohnathan Mantey << bootSource; 776944ffaf9SJohnathan Mantey messages::propertyValueNotInList(aResp->res, rfSource, 777944ffaf9SJohnathan Mantey "BootSourceTargetOverride"); 778944ffaf9SJohnathan Mantey return -1; 779491d8ee7SSantosh Puranik } 780944ffaf9SJohnathan Mantey return 0; 781491d8ee7SSantosh Puranik } 782491d8ee7SSantosh Puranik 783491d8ee7SSantosh Puranik /** 784491d8ee7SSantosh Puranik * @brief Retrieves boot mode over DBUS and fills out the response 785491d8ee7SSantosh Puranik * 786491d8ee7SSantosh Puranik * @param[in] aResp Shared pointer for generating response message. 787491d8ee7SSantosh Puranik * @param[in] bootDbusObj The dbus object to query for boot properties. 788491d8ee7SSantosh Puranik * 789491d8ee7SSantosh Puranik * @return None. 790491d8ee7SSantosh Puranik */ 791b5a76932SEd Tanous inline void getBootMode(const std::shared_ptr<AsyncResp>& aResp, 792b5a76932SEd Tanous const std::string& bootDbusObj) 793491d8ee7SSantosh Puranik { 794491d8ee7SSantosh Puranik crow::connections::systemBus->async_method_call( 795491d8ee7SSantosh Puranik [aResp](const boost::system::error_code ec, 796491d8ee7SSantosh Puranik const std::variant<std::string>& bootMode) { 797491d8ee7SSantosh Puranik if (ec) 798491d8ee7SSantosh Puranik { 799491d8ee7SSantosh Puranik BMCWEB_LOG_DEBUG << "DBUS response error " << ec; 800491d8ee7SSantosh Puranik messages::internalError(aResp->res); 801491d8ee7SSantosh Puranik return; 802491d8ee7SSantosh Puranik } 803491d8ee7SSantosh Puranik 804491d8ee7SSantosh Puranik const std::string* bootModeStr = 805491d8ee7SSantosh Puranik std::get_if<std::string>(&bootMode); 806491d8ee7SSantosh Puranik 807491d8ee7SSantosh Puranik if (!bootModeStr) 808491d8ee7SSantosh Puranik { 809491d8ee7SSantosh Puranik messages::internalError(aResp->res); 810491d8ee7SSantosh Puranik return; 811491d8ee7SSantosh Puranik } 812491d8ee7SSantosh Puranik 813491d8ee7SSantosh Puranik BMCWEB_LOG_DEBUG << "Boot mode: " << *bootModeStr; 814491d8ee7SSantosh Puranik 815491d8ee7SSantosh Puranik // TODO (Santosh): Do we need to support override mode? 816491d8ee7SSantosh Puranik aResp->res.jsonValue["Boot"]["BootSourceOverrideMode"] = "Legacy"; 817491d8ee7SSantosh Puranik aResp->res.jsonValue["Boot"]["BootSourceOverrideTarget@Redfish." 818491d8ee7SSantosh Puranik "AllowableValues"] = { 819944ffaf9SJohnathan Mantey "None", "Pxe", "Hdd", "Cd", "Diags", "BiosSetup", "Usb"}; 820491d8ee7SSantosh Puranik 821491d8ee7SSantosh Puranik if (*bootModeStr != 822491d8ee7SSantosh Puranik "xyz.openbmc_project.Control.Boot.Mode.Modes.Regular") 823491d8ee7SSantosh Puranik { 824491d8ee7SSantosh Puranik auto rfMode = dbusToRfBootMode(*bootModeStr); 825491d8ee7SSantosh Puranik if (!rfMode.empty()) 826491d8ee7SSantosh Puranik { 827491d8ee7SSantosh Puranik aResp->res.jsonValue["Boot"]["BootSourceOverrideTarget"] = 828491d8ee7SSantosh Puranik rfMode; 829491d8ee7SSantosh Puranik } 830491d8ee7SSantosh Puranik } 831491d8ee7SSantosh Puranik 832491d8ee7SSantosh Puranik // If the BootSourceOverrideTarget is still "None" at the end, 833491d8ee7SSantosh Puranik // reset the BootSourceOverrideEnabled to indicate that 834491d8ee7SSantosh Puranik // overrides are disabled 835491d8ee7SSantosh Puranik if (aResp->res.jsonValue["Boot"]["BootSourceOverrideTarget"] == 836491d8ee7SSantosh Puranik "None") 837491d8ee7SSantosh Puranik { 838491d8ee7SSantosh Puranik aResp->res.jsonValue["Boot"]["BootSourceOverrideEnabled"] = 839491d8ee7SSantosh Puranik "Disabled"; 840491d8ee7SSantosh Puranik } 841491d8ee7SSantosh Puranik }, 842491d8ee7SSantosh Puranik "xyz.openbmc_project.Settings", bootDbusObj, 843491d8ee7SSantosh Puranik "org.freedesktop.DBus.Properties", "Get", 844491d8ee7SSantosh Puranik "xyz.openbmc_project.Control.Boot.Mode", "BootMode"); 845491d8ee7SSantosh Puranik } 846491d8ee7SSantosh Puranik 847491d8ee7SSantosh Puranik /** 848491d8ee7SSantosh Puranik * @brief Retrieves boot source over DBUS 849491d8ee7SSantosh Puranik * 850491d8ee7SSantosh Puranik * @param[in] aResp Shared pointer for generating response message. 851491d8ee7SSantosh Puranik * @param[in] oneTimeEnable Boolean to indicate boot properties are one-time. 852491d8ee7SSantosh Puranik * 853491d8ee7SSantosh Puranik * @return None. 854491d8ee7SSantosh Puranik */ 855*f23b7296SEd Tanous inline void getBootSource(const std::shared_ptr<AsyncResp>& aResp, 856*f23b7296SEd Tanous bool oneTimeEnabled) 857491d8ee7SSantosh Puranik { 858491d8ee7SSantosh Puranik std::string bootDbusObj = 859491d8ee7SSantosh Puranik oneTimeEnabled ? "/xyz/openbmc_project/control/host0/boot/one_time" 860491d8ee7SSantosh Puranik : "/xyz/openbmc_project/control/host0/boot"; 861491d8ee7SSantosh Puranik 862491d8ee7SSantosh Puranik BMCWEB_LOG_DEBUG << "Is one time: " << oneTimeEnabled; 863491d8ee7SSantosh Puranik aResp->res.jsonValue["Boot"]["BootSourceOverrideEnabled"] = 864491d8ee7SSantosh Puranik (oneTimeEnabled) ? "Once" : "Continuous"; 865491d8ee7SSantosh Puranik 866491d8ee7SSantosh Puranik crow::connections::systemBus->async_method_call( 867491d8ee7SSantosh Puranik [aResp, bootDbusObj](const boost::system::error_code ec, 868491d8ee7SSantosh Puranik const std::variant<std::string>& bootSource) { 869491d8ee7SSantosh Puranik if (ec) 870491d8ee7SSantosh Puranik { 871491d8ee7SSantosh Puranik BMCWEB_LOG_DEBUG << "DBUS response error " << ec; 872491d8ee7SSantosh Puranik messages::internalError(aResp->res); 873491d8ee7SSantosh Puranik return; 874491d8ee7SSantosh Puranik } 875491d8ee7SSantosh Puranik 876491d8ee7SSantosh Puranik const std::string* bootSourceStr = 877491d8ee7SSantosh Puranik std::get_if<std::string>(&bootSource); 878491d8ee7SSantosh Puranik 879491d8ee7SSantosh Puranik if (!bootSourceStr) 880491d8ee7SSantosh Puranik { 881491d8ee7SSantosh Puranik messages::internalError(aResp->res); 882491d8ee7SSantosh Puranik return; 883491d8ee7SSantosh Puranik } 884491d8ee7SSantosh Puranik BMCWEB_LOG_DEBUG << "Boot source: " << *bootSourceStr; 885491d8ee7SSantosh Puranik 886491d8ee7SSantosh Puranik auto rfSource = dbusToRfBootSource(*bootSourceStr); 887491d8ee7SSantosh Puranik if (!rfSource.empty()) 888491d8ee7SSantosh Puranik { 889491d8ee7SSantosh Puranik aResp->res.jsonValue["Boot"]["BootSourceOverrideTarget"] = 890491d8ee7SSantosh Puranik rfSource; 891491d8ee7SSantosh Puranik } 892491d8ee7SSantosh Puranik }, 893491d8ee7SSantosh Puranik "xyz.openbmc_project.Settings", bootDbusObj, 894491d8ee7SSantosh Puranik "org.freedesktop.DBus.Properties", "Get", 895491d8ee7SSantosh Puranik "xyz.openbmc_project.Control.Boot.Source", "BootSource"); 896*f23b7296SEd Tanous getBootMode(aResp, bootDbusObj); 897491d8ee7SSantosh Puranik } 898491d8ee7SSantosh Puranik 899491d8ee7SSantosh Puranik /** 900491d8ee7SSantosh Puranik * @brief Retrieves "One time" enabled setting over DBUS and calls function to 901491d8ee7SSantosh Puranik * get boot source and boot mode. 902491d8ee7SSantosh Puranik * 903491d8ee7SSantosh Puranik * @param[in] aResp Shared pointer for generating response message. 904491d8ee7SSantosh Puranik * 905491d8ee7SSantosh Puranik * @return None. 906491d8ee7SSantosh Puranik */ 907b5a76932SEd Tanous inline void getBootProperties(const std::shared_ptr<AsyncResp>& aResp) 908491d8ee7SSantosh Puranik { 909491d8ee7SSantosh Puranik BMCWEB_LOG_DEBUG << "Get boot information."; 910491d8ee7SSantosh Puranik 911491d8ee7SSantosh Puranik crow::connections::systemBus->async_method_call( 912c5d03ff4SJennifer Lee [aResp](const boost::system::error_code ec, 91319bd78d9SPatrick Williams const std::variant<bool>& oneTime) { 914491d8ee7SSantosh Puranik if (ec) 915491d8ee7SSantosh Puranik { 916491d8ee7SSantosh Puranik BMCWEB_LOG_DEBUG << "DBUS response error " << ec; 9172a833c77SJames Feist // not an error, don't have to have the interface 918491d8ee7SSantosh Puranik return; 919491d8ee7SSantosh Puranik } 920491d8ee7SSantosh Puranik 921491d8ee7SSantosh Puranik const bool* oneTimePtr = std::get_if<bool>(&oneTime); 922491d8ee7SSantosh Puranik 923491d8ee7SSantosh Puranik if (!oneTimePtr) 924491d8ee7SSantosh Puranik { 925491d8ee7SSantosh Puranik messages::internalError(aResp->res); 926491d8ee7SSantosh Puranik return; 927491d8ee7SSantosh Puranik } 928491d8ee7SSantosh Puranik getBootSource(aResp, *oneTimePtr); 929491d8ee7SSantosh Puranik }, 930491d8ee7SSantosh Puranik "xyz.openbmc_project.Settings", 931491d8ee7SSantosh Puranik "/xyz/openbmc_project/control/host0/boot/one_time", 932491d8ee7SSantosh Puranik "org.freedesktop.DBus.Properties", "Get", 933491d8ee7SSantosh Puranik "xyz.openbmc_project.Object.Enable", "Enabled"); 934491d8ee7SSantosh Puranik } 935491d8ee7SSantosh Puranik 936491d8ee7SSantosh Puranik /** 937c0557e1aSGunnar Mills * @brief Retrieves the Last Reset Time 938c0557e1aSGunnar Mills * 939c0557e1aSGunnar Mills * "Reset" is an overloaded term in Redfish, "Reset" includes power on 940c0557e1aSGunnar Mills * and power off. Even though this is the "system" Redfish object look at the 941c0557e1aSGunnar Mills * chassis D-Bus interface for the LastStateChangeTime since this has the 942c0557e1aSGunnar Mills * last power operation time. 943c0557e1aSGunnar Mills * 944c0557e1aSGunnar Mills * @param[in] aResp Shared pointer for generating response message. 945c0557e1aSGunnar Mills * 946c0557e1aSGunnar Mills * @return None. 947c0557e1aSGunnar Mills */ 948b5a76932SEd Tanous inline void getLastResetTime(const std::shared_ptr<AsyncResp>& aResp) 949c0557e1aSGunnar Mills { 950c0557e1aSGunnar Mills BMCWEB_LOG_DEBUG << "Getting System Last Reset Time"; 951c0557e1aSGunnar Mills 952c0557e1aSGunnar Mills crow::connections::systemBus->async_method_call( 953c0557e1aSGunnar Mills [aResp](const boost::system::error_code ec, 954c0557e1aSGunnar Mills std::variant<uint64_t>& lastResetTime) { 955c0557e1aSGunnar Mills if (ec) 956c0557e1aSGunnar Mills { 957c0557e1aSGunnar Mills BMCWEB_LOG_DEBUG << "D-BUS response error " << ec; 958c0557e1aSGunnar Mills return; 959c0557e1aSGunnar Mills } 960c0557e1aSGunnar Mills 961c0557e1aSGunnar Mills const uint64_t* lastResetTimePtr = 962c0557e1aSGunnar Mills std::get_if<uint64_t>(&lastResetTime); 963c0557e1aSGunnar Mills 964c0557e1aSGunnar Mills if (!lastResetTimePtr) 965c0557e1aSGunnar Mills { 966c0557e1aSGunnar Mills messages::internalError(aResp->res); 967c0557e1aSGunnar Mills return; 968c0557e1aSGunnar Mills } 969c0557e1aSGunnar Mills // LastStateChangeTime is epoch time, in milliseconds 970c0557e1aSGunnar Mills // https://github.com/openbmc/phosphor-dbus-interfaces/blob/33e8e1dd64da53a66e888d33dc82001305cd0bf9/xyz/openbmc_project/State/Chassis.interface.yaml#L19 971c0557e1aSGunnar Mills time_t lastResetTimeStamp = 972c0557e1aSGunnar Mills static_cast<time_t>(*lastResetTimePtr / 1000); 973c0557e1aSGunnar Mills 974c0557e1aSGunnar Mills // Convert to ISO 8601 standard 975c0557e1aSGunnar Mills aResp->res.jsonValue["LastResetTime"] = 976c0557e1aSGunnar Mills crow::utility::getDateTime(lastResetTimeStamp); 977c0557e1aSGunnar Mills }, 978c0557e1aSGunnar Mills "xyz.openbmc_project.State.Chassis", 979c0557e1aSGunnar Mills "/xyz/openbmc_project/state/chassis0", 980c0557e1aSGunnar Mills "org.freedesktop.DBus.Properties", "Get", 981c0557e1aSGunnar Mills "xyz.openbmc_project.State.Chassis", "LastStateChangeTime"); 982c0557e1aSGunnar Mills } 983c0557e1aSGunnar Mills 984c0557e1aSGunnar Mills /** 9856bd5a8d2SGunnar Mills * @brief Retrieves Automatic Retry properties. Known on D-Bus as AutoReboot. 9866bd5a8d2SGunnar Mills * 9876bd5a8d2SGunnar Mills * @param[in] aResp Shared pointer for generating response message. 9886bd5a8d2SGunnar Mills * 9896bd5a8d2SGunnar Mills * @return None. 9906bd5a8d2SGunnar Mills */ 991b5a76932SEd Tanous inline void getAutomaticRetry(const std::shared_ptr<AsyncResp>& aResp) 9926bd5a8d2SGunnar Mills { 9936bd5a8d2SGunnar Mills BMCWEB_LOG_DEBUG << "Get Automatic Retry policy"; 9946bd5a8d2SGunnar Mills 9956bd5a8d2SGunnar Mills crow::connections::systemBus->async_method_call( 9966bd5a8d2SGunnar Mills [aResp](const boost::system::error_code ec, 9976bd5a8d2SGunnar Mills std::variant<bool>& autoRebootEnabled) { 9986bd5a8d2SGunnar Mills if (ec) 9996bd5a8d2SGunnar Mills { 10006bd5a8d2SGunnar Mills BMCWEB_LOG_DEBUG << "D-BUS response error " << ec; 10016bd5a8d2SGunnar Mills return; 10026bd5a8d2SGunnar Mills } 10036bd5a8d2SGunnar Mills 10046bd5a8d2SGunnar Mills const bool* autoRebootEnabledPtr = 10056bd5a8d2SGunnar Mills std::get_if<bool>(&autoRebootEnabled); 10066bd5a8d2SGunnar Mills 10076bd5a8d2SGunnar Mills if (!autoRebootEnabledPtr) 10086bd5a8d2SGunnar Mills { 10096bd5a8d2SGunnar Mills messages::internalError(aResp->res); 10106bd5a8d2SGunnar Mills return; 10116bd5a8d2SGunnar Mills } 10126bd5a8d2SGunnar Mills 10136bd5a8d2SGunnar Mills BMCWEB_LOG_DEBUG << "Auto Reboot: " << *autoRebootEnabledPtr; 10146bd5a8d2SGunnar Mills if (*autoRebootEnabledPtr == true) 10156bd5a8d2SGunnar Mills { 10166bd5a8d2SGunnar Mills aResp->res.jsonValue["Boot"]["AutomaticRetryConfig"] = 10176bd5a8d2SGunnar Mills "RetryAttempts"; 10186bd5a8d2SGunnar Mills // If AutomaticRetry (AutoReboot) is enabled see how many 10196bd5a8d2SGunnar Mills // attempts are left 10206bd5a8d2SGunnar Mills crow::connections::systemBus->async_method_call( 1021cb13a392SEd Tanous [aResp](const boost::system::error_code ec2, 10226bd5a8d2SGunnar Mills std::variant<uint32_t>& autoRebootAttemptsLeft) { 1023cb13a392SEd Tanous if (ec2) 10246bd5a8d2SGunnar Mills { 1025cb13a392SEd Tanous BMCWEB_LOG_DEBUG << "D-BUS response error " << ec2; 10266bd5a8d2SGunnar Mills return; 10276bd5a8d2SGunnar Mills } 10286bd5a8d2SGunnar Mills 10296bd5a8d2SGunnar Mills const uint32_t* autoRebootAttemptsLeftPtr = 10306bd5a8d2SGunnar Mills std::get_if<uint32_t>(&autoRebootAttemptsLeft); 10316bd5a8d2SGunnar Mills 10326bd5a8d2SGunnar Mills if (!autoRebootAttemptsLeftPtr) 10336bd5a8d2SGunnar Mills { 10346bd5a8d2SGunnar Mills messages::internalError(aResp->res); 10356bd5a8d2SGunnar Mills return; 10366bd5a8d2SGunnar Mills } 10376bd5a8d2SGunnar Mills 10386bd5a8d2SGunnar Mills BMCWEB_LOG_DEBUG << "Auto Reboot Attempts Left: " 10396bd5a8d2SGunnar Mills << *autoRebootAttemptsLeftPtr; 10406bd5a8d2SGunnar Mills 10416bd5a8d2SGunnar Mills aResp->res 10426bd5a8d2SGunnar Mills .jsonValue["Boot"] 10436bd5a8d2SGunnar Mills ["RemainingAutomaticRetryAttempts"] = 10446bd5a8d2SGunnar Mills *autoRebootAttemptsLeftPtr; 10456bd5a8d2SGunnar Mills }, 10466bd5a8d2SGunnar Mills "xyz.openbmc_project.State.Host", 10476bd5a8d2SGunnar Mills "/xyz/openbmc_project/state/host0", 10486bd5a8d2SGunnar Mills "org.freedesktop.DBus.Properties", "Get", 10496bd5a8d2SGunnar Mills "xyz.openbmc_project.Control.Boot.RebootAttempts", 10506bd5a8d2SGunnar Mills "AttemptsLeft"); 10516bd5a8d2SGunnar Mills } 10526bd5a8d2SGunnar Mills else 10536bd5a8d2SGunnar Mills { 10546bd5a8d2SGunnar Mills aResp->res.jsonValue["Boot"]["AutomaticRetryConfig"] = 10556bd5a8d2SGunnar Mills "Disabled"; 10566bd5a8d2SGunnar Mills } 10576bd5a8d2SGunnar Mills 10586bd5a8d2SGunnar Mills // Not on D-Bus. Hardcoded here: 10596bd5a8d2SGunnar Mills // https://github.com/openbmc/phosphor-state-manager/blob/1dbbef42675e94fb1f78edb87d6b11380260535a/meson_options.txt#L71 10606bd5a8d2SGunnar Mills aResp->res.jsonValue["Boot"]["AutomaticRetryAttempts"] = 3; 106169f35306SGunnar Mills 106269f35306SGunnar Mills // "AutomaticRetryConfig" can be 3 values, Disabled, RetryAlways, 106369f35306SGunnar Mills // and RetryAttempts. OpenBMC only supports Disabled and 106469f35306SGunnar Mills // RetryAttempts. 106569f35306SGunnar Mills aResp->res.jsonValue["Boot"]["AutomaticRetryConfig@Redfish." 106669f35306SGunnar Mills "AllowableValues"] = {"Disabled", 106769f35306SGunnar Mills "RetryAttempts"}; 10686bd5a8d2SGunnar Mills }, 10696bd5a8d2SGunnar Mills "xyz.openbmc_project.Settings", 10706bd5a8d2SGunnar Mills "/xyz/openbmc_project/control/host0/auto_reboot", 10716bd5a8d2SGunnar Mills "org.freedesktop.DBus.Properties", "Get", 10726bd5a8d2SGunnar Mills "xyz.openbmc_project.Control.Boot.RebootPolicy", "AutoReboot"); 10736bd5a8d2SGunnar Mills } 10746bd5a8d2SGunnar Mills 10756bd5a8d2SGunnar Mills /** 1076c6a620f2SGeorge Liu * @brief Retrieves power restore policy over DBUS. 1077c6a620f2SGeorge Liu * 1078c6a620f2SGeorge Liu * @param[in] aResp Shared pointer for generating response message. 1079c6a620f2SGeorge Liu * 1080c6a620f2SGeorge Liu * @return None. 1081c6a620f2SGeorge Liu */ 1082b5a76932SEd Tanous inline void getPowerRestorePolicy(const std::shared_ptr<AsyncResp>& aResp) 1083c6a620f2SGeorge Liu { 1084c6a620f2SGeorge Liu BMCWEB_LOG_DEBUG << "Get power restore policy"; 1085c6a620f2SGeorge Liu 1086c6a620f2SGeorge Liu crow::connections::systemBus->async_method_call( 1087c6a620f2SGeorge Liu [aResp](const boost::system::error_code ec, 108819bd78d9SPatrick Williams std::variant<std::string>& policy) { 1089c6a620f2SGeorge Liu if (ec) 1090c6a620f2SGeorge Liu { 1091c6a620f2SGeorge Liu BMCWEB_LOG_DEBUG << "DBUS response error " << ec; 1092c6a620f2SGeorge Liu return; 1093c6a620f2SGeorge Liu } 1094c6a620f2SGeorge Liu 1095c6a620f2SGeorge Liu const boost::container::flat_map<std::string, std::string> 1096c6a620f2SGeorge Liu policyMaps = { 1097c6a620f2SGeorge Liu {"xyz.openbmc_project.Control.Power.RestorePolicy.Policy." 1098c6a620f2SGeorge Liu "AlwaysOn", 1099c6a620f2SGeorge Liu "AlwaysOn"}, 1100c6a620f2SGeorge Liu {"xyz.openbmc_project.Control.Power.RestorePolicy.Policy." 1101c6a620f2SGeorge Liu "AlwaysOff", 1102c6a620f2SGeorge Liu "AlwaysOff"}, 1103c6a620f2SGeorge Liu {"xyz.openbmc_project.Control.Power.RestorePolicy.Policy." 1104c6a620f2SGeorge Liu "LastState", 1105c6a620f2SGeorge Liu "LastState"}}; 1106c6a620f2SGeorge Liu 1107c6a620f2SGeorge Liu const std::string* policyPtr = std::get_if<std::string>(&policy); 1108c6a620f2SGeorge Liu 1109c6a620f2SGeorge Liu if (!policyPtr) 1110c6a620f2SGeorge Liu { 1111c6a620f2SGeorge Liu messages::internalError(aResp->res); 1112c6a620f2SGeorge Liu return; 1113c6a620f2SGeorge Liu } 1114c6a620f2SGeorge Liu 1115c6a620f2SGeorge Liu auto policyMapsIt = policyMaps.find(*policyPtr); 1116c6a620f2SGeorge Liu if (policyMapsIt == policyMaps.end()) 1117c6a620f2SGeorge Liu { 1118c6a620f2SGeorge Liu messages::internalError(aResp->res); 1119c6a620f2SGeorge Liu return; 1120c6a620f2SGeorge Liu } 1121c6a620f2SGeorge Liu 1122c6a620f2SGeorge Liu aResp->res.jsonValue["PowerRestorePolicy"] = policyMapsIt->second; 1123c6a620f2SGeorge Liu }, 1124c6a620f2SGeorge Liu "xyz.openbmc_project.Settings", 1125c6a620f2SGeorge Liu "/xyz/openbmc_project/control/host0/power_restore_policy", 1126c6a620f2SGeorge Liu "org.freedesktop.DBus.Properties", "Get", 1127c6a620f2SGeorge Liu "xyz.openbmc_project.Control.Power.RestorePolicy", 1128c6a620f2SGeorge Liu "PowerRestorePolicy"); 1129c6a620f2SGeorge Liu } 1130c6a620f2SGeorge Liu 1131c6a620f2SGeorge Liu /** 1132491d8ee7SSantosh Puranik * @brief Sets boot properties into DBUS object(s). 1133491d8ee7SSantosh Puranik * 1134491d8ee7SSantosh Puranik * @param[in] aResp Shared pointer for generating response message. 1135491d8ee7SSantosh Puranik * @param[in] oneTimeEnabled Is "one-time" setting already enabled. 1136491d8ee7SSantosh Puranik * @param[in] bootSource The boot source to set. 1137491d8ee7SSantosh Puranik * @param[in] bootEnable The source override "enable" to set. 1138491d8ee7SSantosh Puranik * 1139265c1602SJohnathan Mantey * @return Integer error code. 1140491d8ee7SSantosh Puranik */ 114123a21a1cSEd Tanous inline void setBootModeOrSource(std::shared_ptr<AsyncResp> aResp, 1142491d8ee7SSantosh Puranik bool oneTimeEnabled, 1143*f23b7296SEd Tanous const std::optional<std::string>& bootSource, 1144*f23b7296SEd Tanous const std::optional<std::string>& bootEnable) 1145491d8ee7SSantosh Puranik { 1146944ffaf9SJohnathan Mantey std::string bootSourceStr = 1147944ffaf9SJohnathan Mantey "xyz.openbmc_project.Control.Boot.Source.Sources.Default"; 1148944ffaf9SJohnathan Mantey std::string bootModeStr = 1149944ffaf9SJohnathan Mantey "xyz.openbmc_project.Control.Boot.Mode.Modes.Regular"; 1150491d8ee7SSantosh Puranik bool oneTimeSetting = oneTimeEnabled; 1151944ffaf9SJohnathan Mantey bool useBootSource = true; 1152944ffaf9SJohnathan Mantey 1153491d8ee7SSantosh Puranik // Validate incoming parameters 1154491d8ee7SSantosh Puranik if (bootEnable) 1155491d8ee7SSantosh Puranik { 1156491d8ee7SSantosh Puranik if (*bootEnable == "Once") 1157491d8ee7SSantosh Puranik { 1158491d8ee7SSantosh Puranik oneTimeSetting = true; 1159491d8ee7SSantosh Puranik } 1160491d8ee7SSantosh Puranik else if (*bootEnable == "Continuous") 1161491d8ee7SSantosh Puranik { 1162491d8ee7SSantosh Puranik oneTimeSetting = false; 1163491d8ee7SSantosh Puranik } 1164491d8ee7SSantosh Puranik else if (*bootEnable == "Disabled") 1165491d8ee7SSantosh Puranik { 1166944ffaf9SJohnathan Mantey BMCWEB_LOG_DEBUG << "Boot source override will be disabled"; 1167491d8ee7SSantosh Puranik oneTimeSetting = false; 1168944ffaf9SJohnathan Mantey useBootSource = false; 1169491d8ee7SSantosh Puranik } 1170491d8ee7SSantosh Puranik else 1171491d8ee7SSantosh Puranik { 1172491d8ee7SSantosh Puranik BMCWEB_LOG_DEBUG << "Unsupported value for " 1173491d8ee7SSantosh Puranik "BootSourceOverrideEnabled: " 1174491d8ee7SSantosh Puranik << *bootEnable; 1175491d8ee7SSantosh Puranik messages::propertyValueNotInList(aResp->res, *bootEnable, 1176491d8ee7SSantosh Puranik "BootSourceOverrideEnabled"); 1177491d8ee7SSantosh Puranik return; 1178491d8ee7SSantosh Puranik } 1179491d8ee7SSantosh Puranik } 1180491d8ee7SSantosh Puranik 1181944ffaf9SJohnathan Mantey if (bootSource && useBootSource) 1182491d8ee7SSantosh Puranik { 1183491d8ee7SSantosh Puranik // Source target specified 1184491d8ee7SSantosh Puranik BMCWEB_LOG_DEBUG << "Boot source: " << *bootSource; 1185491d8ee7SSantosh Puranik // Figure out which DBUS interface and property to use 1186944ffaf9SJohnathan Mantey if (assignBootParameters(aResp, *bootSource, bootSourceStr, 1187944ffaf9SJohnathan Mantey bootModeStr)) 1188491d8ee7SSantosh Puranik { 1189944ffaf9SJohnathan Mantey BMCWEB_LOG_DEBUG 1190944ffaf9SJohnathan Mantey << "Invalid property value for BootSourceOverrideTarget: " 1191491d8ee7SSantosh Puranik << *bootSource; 1192491d8ee7SSantosh Puranik messages::propertyValueNotInList(aResp->res, *bootSource, 1193491d8ee7SSantosh Puranik "BootSourceTargetOverride"); 1194491d8ee7SSantosh Puranik return; 1195491d8ee7SSantosh Puranik } 1196944ffaf9SJohnathan Mantey } 1197491d8ee7SSantosh Puranik 1198944ffaf9SJohnathan Mantey // Act on validated parameters 1199944ffaf9SJohnathan Mantey BMCWEB_LOG_DEBUG << "DBUS boot source: " << bootSourceStr; 1200944ffaf9SJohnathan Mantey BMCWEB_LOG_DEBUG << "DBUS boot mode: " << bootModeStr; 1201944ffaf9SJohnathan Mantey const char* bootObj = 1202944ffaf9SJohnathan Mantey oneTimeSetting ? "/xyz/openbmc_project/control/host0/boot/one_time" 1203944ffaf9SJohnathan Mantey : "/xyz/openbmc_project/control/host0/boot"; 1204944ffaf9SJohnathan Mantey 1205491d8ee7SSantosh Puranik crow::connections::systemBus->async_method_call( 1206491d8ee7SSantosh Puranik [aResp](const boost::system::error_code ec) { 1207491d8ee7SSantosh Puranik if (ec) 1208491d8ee7SSantosh Puranik { 1209491d8ee7SSantosh Puranik BMCWEB_LOG_DEBUG << "DBUS response error " << ec; 1210491d8ee7SSantosh Puranik messages::internalError(aResp->res); 1211491d8ee7SSantosh Puranik return; 1212491d8ee7SSantosh Puranik } 1213491d8ee7SSantosh Puranik BMCWEB_LOG_DEBUG << "Boot source update done."; 1214491d8ee7SSantosh Puranik }, 1215491d8ee7SSantosh Puranik "xyz.openbmc_project.Settings", bootObj, 1216491d8ee7SSantosh Puranik "org.freedesktop.DBus.Properties", "Set", 1217491d8ee7SSantosh Puranik "xyz.openbmc_project.Control.Boot.Source", "BootSource", 1218491d8ee7SSantosh Puranik std::variant<std::string>(bootSourceStr)); 1219944ffaf9SJohnathan Mantey 1220491d8ee7SSantosh Puranik crow::connections::systemBus->async_method_call( 1221491d8ee7SSantosh Puranik [aResp](const boost::system::error_code ec) { 1222491d8ee7SSantosh Puranik if (ec) 1223491d8ee7SSantosh Puranik { 1224491d8ee7SSantosh Puranik BMCWEB_LOG_DEBUG << "DBUS response error " << ec; 1225491d8ee7SSantosh Puranik messages::internalError(aResp->res); 1226491d8ee7SSantosh Puranik return; 1227491d8ee7SSantosh Puranik } 1228491d8ee7SSantosh Puranik BMCWEB_LOG_DEBUG << "Boot mode update done."; 1229491d8ee7SSantosh Puranik }, 1230491d8ee7SSantosh Puranik "xyz.openbmc_project.Settings", bootObj, 1231491d8ee7SSantosh Puranik "org.freedesktop.DBus.Properties", "Set", 1232491d8ee7SSantosh Puranik "xyz.openbmc_project.Control.Boot.Mode", "BootMode", 1233491d8ee7SSantosh Puranik std::variant<std::string>(bootModeStr)); 1234944ffaf9SJohnathan Mantey 1235491d8ee7SSantosh Puranik crow::connections::systemBus->async_method_call( 1236491d8ee7SSantosh Puranik [aResp{std::move(aResp)}](const boost::system::error_code ec) { 1237491d8ee7SSantosh Puranik if (ec) 1238491d8ee7SSantosh Puranik { 1239491d8ee7SSantosh Puranik BMCWEB_LOG_DEBUG << "DBUS response error " << ec; 1240491d8ee7SSantosh Puranik messages::internalError(aResp->res); 1241491d8ee7SSantosh Puranik return; 1242491d8ee7SSantosh Puranik } 1243491d8ee7SSantosh Puranik BMCWEB_LOG_DEBUG << "Boot enable update done."; 1244491d8ee7SSantosh Puranik }, 1245491d8ee7SSantosh Puranik "xyz.openbmc_project.Settings", 1246491d8ee7SSantosh Puranik "/xyz/openbmc_project/control/host0/boot/one_time", 1247491d8ee7SSantosh Puranik "org.freedesktop.DBus.Properties", "Set", 1248491d8ee7SSantosh Puranik "xyz.openbmc_project.Object.Enable", "Enabled", 1249491d8ee7SSantosh Puranik std::variant<bool>(oneTimeSetting)); 1250491d8ee7SSantosh Puranik } 1251491d8ee7SSantosh Puranik 1252491d8ee7SSantosh Puranik /** 1253491d8ee7SSantosh Puranik * @brief Retrieves "One time" enabled setting over DBUS and calls function to 1254491d8ee7SSantosh Puranik * set boot source/boot mode properties. 1255491d8ee7SSantosh Puranik * 1256491d8ee7SSantosh Puranik * @param[in] aResp Shared pointer for generating response message. 1257491d8ee7SSantosh Puranik * @param[in] bootSource The boot source from incoming RF request. 1258491d8ee7SSantosh Puranik * @param[in] bootEnable The boot override enable from incoming RF request. 1259491d8ee7SSantosh Puranik * 1260265c1602SJohnathan Mantey * @return Integer error code. 1261491d8ee7SSantosh Puranik */ 1262b5a76932SEd Tanous inline void setBootSourceProperties(const std::shared_ptr<AsyncResp>& aResp, 1263491d8ee7SSantosh Puranik std::optional<std::string> bootSource, 1264491d8ee7SSantosh Puranik std::optional<std::string> bootEnable) 1265491d8ee7SSantosh Puranik { 1266491d8ee7SSantosh Puranik BMCWEB_LOG_DEBUG << "Set boot information."; 1267491d8ee7SSantosh Puranik 1268491d8ee7SSantosh Puranik crow::connections::systemBus->async_method_call( 1269265c1602SJohnathan Mantey [aResp, bootSource{std::move(bootSource)}, 127019bd78d9SPatrick Williams bootEnable{std::move(bootEnable)}](const boost::system::error_code ec, 127119bd78d9SPatrick Williams const std::variant<bool>& oneTime) { 1272491d8ee7SSantosh Puranik if (ec) 1273491d8ee7SSantosh Puranik { 1274491d8ee7SSantosh Puranik BMCWEB_LOG_DEBUG << "DBUS response error " << ec; 1275491d8ee7SSantosh Puranik messages::internalError(aResp->res); 1276491d8ee7SSantosh Puranik return; 1277491d8ee7SSantosh Puranik } 1278491d8ee7SSantosh Puranik 1279491d8ee7SSantosh Puranik const bool* oneTimePtr = std::get_if<bool>(&oneTime); 1280491d8ee7SSantosh Puranik 1281491d8ee7SSantosh Puranik if (!oneTimePtr) 1282491d8ee7SSantosh Puranik { 1283491d8ee7SSantosh Puranik messages::internalError(aResp->res); 1284491d8ee7SSantosh Puranik return; 1285491d8ee7SSantosh Puranik } 1286491d8ee7SSantosh Puranik 1287491d8ee7SSantosh Puranik BMCWEB_LOG_DEBUG << "Got one time: " << *oneTimePtr; 1288491d8ee7SSantosh Puranik 1289*f23b7296SEd Tanous setBootModeOrSource(aResp, *oneTimePtr, bootSource, bootEnable); 1290491d8ee7SSantosh Puranik }, 1291491d8ee7SSantosh Puranik "xyz.openbmc_project.Settings", 1292491d8ee7SSantosh Puranik "/xyz/openbmc_project/control/host0/boot/one_time", 1293491d8ee7SSantosh Puranik "org.freedesktop.DBus.Properties", "Get", 1294491d8ee7SSantosh Puranik "xyz.openbmc_project.Object.Enable", "Enabled"); 1295491d8ee7SSantosh Puranik } 1296491d8ee7SSantosh Puranik 1297c6a620f2SGeorge Liu /** 129869f35306SGunnar Mills * @brief Sets automaticRetry (Auto Reboot) 129969f35306SGunnar Mills * 130069f35306SGunnar Mills * @param[in] aResp Shared pointer for generating response message. 130169f35306SGunnar Mills * @param[in] automaticRetryConfig "AutomaticRetryConfig" from request. 130269f35306SGunnar Mills * 130369f35306SGunnar Mills * @return None. 130469f35306SGunnar Mills */ 1305b5a76932SEd Tanous inline void setAutomaticRetry(const std::shared_ptr<AsyncResp>& aResp, 1306*f23b7296SEd Tanous const std::string& automaticRetryConfig) 130769f35306SGunnar Mills { 130869f35306SGunnar Mills BMCWEB_LOG_DEBUG << "Set Automatic Retry."; 130969f35306SGunnar Mills 131069f35306SGunnar Mills // OpenBMC only supports "Disabled" and "RetryAttempts". 131169f35306SGunnar Mills bool autoRebootEnabled; 131269f35306SGunnar Mills 131369f35306SGunnar Mills if (automaticRetryConfig == "Disabled") 131469f35306SGunnar Mills { 131569f35306SGunnar Mills autoRebootEnabled = false; 131669f35306SGunnar Mills } 131769f35306SGunnar Mills else if (automaticRetryConfig == "RetryAttempts") 131869f35306SGunnar Mills { 131969f35306SGunnar Mills autoRebootEnabled = true; 132069f35306SGunnar Mills } 132169f35306SGunnar Mills else 132269f35306SGunnar Mills { 132369f35306SGunnar Mills BMCWEB_LOG_DEBUG << "Invalid property value for " 132469f35306SGunnar Mills "AutomaticRetryConfig: " 132569f35306SGunnar Mills << automaticRetryConfig; 132669f35306SGunnar Mills messages::propertyValueNotInList(aResp->res, automaticRetryConfig, 132769f35306SGunnar Mills "AutomaticRetryConfig"); 132869f35306SGunnar Mills return; 132969f35306SGunnar Mills } 133069f35306SGunnar Mills 133169f35306SGunnar Mills crow::connections::systemBus->async_method_call( 133269f35306SGunnar Mills [aResp](const boost::system::error_code ec) { 133369f35306SGunnar Mills if (ec) 133469f35306SGunnar Mills { 133569f35306SGunnar Mills messages::internalError(aResp->res); 133669f35306SGunnar Mills return; 133769f35306SGunnar Mills } 133869f35306SGunnar Mills }, 133969f35306SGunnar Mills "xyz.openbmc_project.Settings", 134069f35306SGunnar Mills "/xyz/openbmc_project/control/host0/auto_reboot", 134169f35306SGunnar Mills "org.freedesktop.DBus.Properties", "Set", 134269f35306SGunnar Mills "xyz.openbmc_project.Control.Boot.RebootPolicy", "AutoReboot", 134369f35306SGunnar Mills std::variant<bool>(autoRebootEnabled)); 134469f35306SGunnar Mills } 134569f35306SGunnar Mills 134669f35306SGunnar Mills /** 1347c6a620f2SGeorge Liu * @brief Sets power restore policy properties. 1348c6a620f2SGeorge Liu * 1349c6a620f2SGeorge Liu * @param[in] aResp Shared pointer for generating response message. 1350c6a620f2SGeorge Liu * @param[in] policy power restore policy properties from request. 1351c6a620f2SGeorge Liu * 1352c6a620f2SGeorge Liu * @return None. 1353c6a620f2SGeorge Liu */ 1354b5a76932SEd Tanous inline void setPowerRestorePolicy(const std::shared_ptr<AsyncResp>& aResp, 1355c6a620f2SGeorge Liu std::optional<std::string> policy) 1356c6a620f2SGeorge Liu { 1357c6a620f2SGeorge Liu BMCWEB_LOG_DEBUG << "Set power restore policy."; 1358c6a620f2SGeorge Liu 1359c6a620f2SGeorge Liu const boost::container::flat_map<std::string, std::string> policyMaps = { 1360c6a620f2SGeorge Liu {"AlwaysOn", "xyz.openbmc_project.Control.Power.RestorePolicy.Policy." 1361c6a620f2SGeorge Liu "AlwaysOn"}, 1362c6a620f2SGeorge Liu {"AlwaysOff", "xyz.openbmc_project.Control.Power.RestorePolicy.Policy." 1363c6a620f2SGeorge Liu "AlwaysOff"}, 1364c6a620f2SGeorge Liu {"LastState", "xyz.openbmc_project.Control.Power.RestorePolicy.Policy." 1365c6a620f2SGeorge Liu "LastState"}}; 1366c6a620f2SGeorge Liu 1367c6a620f2SGeorge Liu std::string powerRestorPolicy; 1368c6a620f2SGeorge Liu 1369c6a620f2SGeorge Liu auto policyMapsIt = policyMaps.find(*policy); 1370c6a620f2SGeorge Liu if (policyMapsIt == policyMaps.end()) 1371c6a620f2SGeorge Liu { 1372c6a620f2SGeorge Liu messages::internalError(aResp->res); 1373c6a620f2SGeorge Liu return; 1374c6a620f2SGeorge Liu } 1375c6a620f2SGeorge Liu 1376c6a620f2SGeorge Liu powerRestorPolicy = policyMapsIt->second; 1377c6a620f2SGeorge Liu 1378c6a620f2SGeorge Liu crow::connections::systemBus->async_method_call( 1379c6a620f2SGeorge Liu [aResp](const boost::system::error_code ec) { 1380c6a620f2SGeorge Liu if (ec) 1381c6a620f2SGeorge Liu { 1382c6a620f2SGeorge Liu messages::internalError(aResp->res); 1383c6a620f2SGeorge Liu return; 1384c6a620f2SGeorge Liu } 1385c6a620f2SGeorge Liu }, 1386c6a620f2SGeorge Liu "xyz.openbmc_project.Settings", 1387c6a620f2SGeorge Liu "/xyz/openbmc_project/control/host0/power_restore_policy", 1388c6a620f2SGeorge Liu "org.freedesktop.DBus.Properties", "Set", 1389c6a620f2SGeorge Liu "xyz.openbmc_project.Control.Power.RestorePolicy", "PowerRestorePolicy", 1390c6a620f2SGeorge Liu std::variant<std::string>(powerRestorPolicy)); 1391c6a620f2SGeorge Liu } 1392c6a620f2SGeorge Liu 1393a6349918SAppaRao Puli #ifdef BMCWEB_ENABLE_REDFISH_PROVISIONING_FEATURE 1394a6349918SAppaRao Puli /** 1395a6349918SAppaRao Puli * @brief Retrieves provisioning status 1396a6349918SAppaRao Puli * 1397a6349918SAppaRao Puli * @param[in] aResp Shared pointer for completing asynchronous calls. 1398a6349918SAppaRao Puli * 1399a6349918SAppaRao Puli * @return None. 1400a6349918SAppaRao Puli */ 140123a21a1cSEd Tanous inline void getProvisioningStatus(std::shared_ptr<AsyncResp> aResp) 1402a6349918SAppaRao Puli { 1403a6349918SAppaRao Puli BMCWEB_LOG_DEBUG << "Get OEM information."; 1404a6349918SAppaRao Puli crow::connections::systemBus->async_method_call( 1405a6349918SAppaRao Puli [aResp](const boost::system::error_code ec, 14061214b7e7SGunnar Mills const std::vector<std::pair<std::string, VariantType>>& 14071214b7e7SGunnar Mills propertiesList) { 1408b99fb1a9SAppaRao Puli nlohmann::json& oemPFR = 1409b99fb1a9SAppaRao Puli aResp->res.jsonValue["Oem"]["OpenBmc"]["FirmwareProvisioning"]; 141050626f4fSJames Feist aResp->res.jsonValue["Oem"]["OpenBmc"]["@odata.type"] = 141150626f4fSJames Feist "#OemComputerSystem.OpenBmc"; 141250626f4fSJames Feist oemPFR["@odata.type"] = "#OemComputerSystem.FirmwareProvisioning"; 141350626f4fSJames Feist 1414a6349918SAppaRao Puli if (ec) 1415a6349918SAppaRao Puli { 1416a6349918SAppaRao Puli BMCWEB_LOG_DEBUG << "DBUS response error " << ec; 1417b99fb1a9SAppaRao Puli // not an error, don't have to have the interface 1418b99fb1a9SAppaRao Puli oemPFR["ProvisioningStatus"] = "NotProvisioned"; 1419a6349918SAppaRao Puli return; 1420a6349918SAppaRao Puli } 1421a6349918SAppaRao Puli 1422a6349918SAppaRao Puli const bool* provState = nullptr; 1423a6349918SAppaRao Puli const bool* lockState = nullptr; 1424a6349918SAppaRao Puli for (const std::pair<std::string, VariantType>& property : 1425a6349918SAppaRao Puli propertiesList) 1426a6349918SAppaRao Puli { 1427a6349918SAppaRao Puli if (property.first == "UfmProvisioned") 1428a6349918SAppaRao Puli { 1429a6349918SAppaRao Puli provState = std::get_if<bool>(&property.second); 1430a6349918SAppaRao Puli } 1431a6349918SAppaRao Puli else if (property.first == "UfmLocked") 1432a6349918SAppaRao Puli { 1433a6349918SAppaRao Puli lockState = std::get_if<bool>(&property.second); 1434a6349918SAppaRao Puli } 1435a6349918SAppaRao Puli } 1436a6349918SAppaRao Puli 1437a6349918SAppaRao Puli if ((provState == nullptr) || (lockState == nullptr)) 1438a6349918SAppaRao Puli { 1439a6349918SAppaRao Puli BMCWEB_LOG_DEBUG << "Unable to get PFR attributes."; 1440a6349918SAppaRao Puli messages::internalError(aResp->res); 1441a6349918SAppaRao Puli return; 1442a6349918SAppaRao Puli } 1443a6349918SAppaRao Puli 1444a6349918SAppaRao Puli if (*provState == true) 1445a6349918SAppaRao Puli { 1446a6349918SAppaRao Puli if (*lockState == true) 1447a6349918SAppaRao Puli { 1448a6349918SAppaRao Puli oemPFR["ProvisioningStatus"] = "ProvisionedAndLocked"; 1449a6349918SAppaRao Puli } 1450a6349918SAppaRao Puli else 1451a6349918SAppaRao Puli { 1452a6349918SAppaRao Puli oemPFR["ProvisioningStatus"] = "ProvisionedButNotLocked"; 1453a6349918SAppaRao Puli } 1454a6349918SAppaRao Puli } 1455a6349918SAppaRao Puli else 1456a6349918SAppaRao Puli { 1457a6349918SAppaRao Puli oemPFR["ProvisioningStatus"] = "NotProvisioned"; 1458a6349918SAppaRao Puli } 1459a6349918SAppaRao Puli }, 1460a6349918SAppaRao Puli "xyz.openbmc_project.PFR.Manager", "/xyz/openbmc_project/pfr", 1461a6349918SAppaRao Puli "org.freedesktop.DBus.Properties", "GetAll", 1462a6349918SAppaRao Puli "xyz.openbmc_project.PFR.Attributes"); 1463a6349918SAppaRao Puli } 1464a6349918SAppaRao Puli #endif 1465a6349918SAppaRao Puli 1466491d8ee7SSantosh Puranik /** 146751709ffdSYong Li * @brief Translates watchdog timeout action DBUS property value to redfish. 146851709ffdSYong Li * 146951709ffdSYong Li * @param[in] dbusAction The watchdog timeout action in D-BUS. 147051709ffdSYong Li * 147151709ffdSYong Li * @return Returns as a string, the timeout action in Redfish terms. If 147251709ffdSYong Li * translation cannot be done, returns an empty string. 147351709ffdSYong Li */ 147423a21a1cSEd Tanous inline std::string dbusToRfWatchdogAction(const std::string& dbusAction) 147551709ffdSYong Li { 147651709ffdSYong Li if (dbusAction == "xyz.openbmc_project.State.Watchdog.Action.None") 147751709ffdSYong Li { 147851709ffdSYong Li return "None"; 147951709ffdSYong Li } 14803174e4dfSEd Tanous if (dbusAction == "xyz.openbmc_project.State.Watchdog.Action.HardReset") 148151709ffdSYong Li { 148251709ffdSYong Li return "ResetSystem"; 148351709ffdSYong Li } 14843174e4dfSEd Tanous if (dbusAction == "xyz.openbmc_project.State.Watchdog.Action.PowerOff") 148551709ffdSYong Li { 148651709ffdSYong Li return "PowerDown"; 148751709ffdSYong Li } 14883174e4dfSEd Tanous if (dbusAction == "xyz.openbmc_project.State.Watchdog.Action.PowerCycle") 148951709ffdSYong Li { 149051709ffdSYong Li return "PowerCycle"; 149151709ffdSYong Li } 149251709ffdSYong Li 149351709ffdSYong Li return ""; 149451709ffdSYong Li } 149551709ffdSYong Li 149651709ffdSYong Li /** 1497c45f0082SYong Li *@brief Translates timeout action from Redfish to DBUS property value. 1498c45f0082SYong Li * 1499c45f0082SYong Li *@param[in] rfAction The timeout action in Redfish. 1500c45f0082SYong Li * 1501c45f0082SYong Li *@return Returns as a string, the time_out action as expected by DBUS. 1502c45f0082SYong Li *If translation cannot be done, returns an empty string. 1503c45f0082SYong Li */ 1504c45f0082SYong Li 150523a21a1cSEd Tanous inline std::string rfToDbusWDTTimeOutAct(const std::string& rfAction) 1506c45f0082SYong Li { 1507c45f0082SYong Li if (rfAction == "None") 1508c45f0082SYong Li { 1509c45f0082SYong Li return "xyz.openbmc_project.State.Watchdog.Action.None"; 1510c45f0082SYong Li } 15113174e4dfSEd Tanous if (rfAction == "PowerCycle") 1512c45f0082SYong Li { 1513c45f0082SYong Li return "xyz.openbmc_project.State.Watchdog.Action.PowerCycle"; 1514c45f0082SYong Li } 15153174e4dfSEd Tanous if (rfAction == "PowerDown") 1516c45f0082SYong Li { 1517c45f0082SYong Li return "xyz.openbmc_project.State.Watchdog.Action.PowerOff"; 1518c45f0082SYong Li } 15193174e4dfSEd Tanous if (rfAction == "ResetSystem") 1520c45f0082SYong Li { 1521c45f0082SYong Li return "xyz.openbmc_project.State.Watchdog.Action.HardReset"; 1522c45f0082SYong Li } 1523c45f0082SYong Li 1524c45f0082SYong Li return ""; 1525c45f0082SYong Li } 1526c45f0082SYong Li 1527c45f0082SYong Li /** 152851709ffdSYong Li * @brief Retrieves host watchdog timer properties over DBUS 152951709ffdSYong Li * 153051709ffdSYong Li * @param[in] aResp Shared pointer for completing asynchronous calls. 153151709ffdSYong Li * 153251709ffdSYong Li * @return None. 153351709ffdSYong Li */ 1534b5a76932SEd Tanous inline void getHostWatchdogTimer(const std::shared_ptr<AsyncResp>& aResp) 153551709ffdSYong Li { 153651709ffdSYong Li BMCWEB_LOG_DEBUG << "Get host watchodg"; 153751709ffdSYong Li crow::connections::systemBus->async_method_call( 153851709ffdSYong Li [aResp](const boost::system::error_code ec, 153951709ffdSYong Li PropertiesType& properties) { 154051709ffdSYong Li if (ec) 154151709ffdSYong Li { 154251709ffdSYong Li // watchdog service is stopped 154351709ffdSYong Li BMCWEB_LOG_DEBUG << "DBUS response error " << ec; 154451709ffdSYong Li return; 154551709ffdSYong Li } 154651709ffdSYong Li 154751709ffdSYong Li BMCWEB_LOG_DEBUG << "Got " << properties.size() << " wdt prop."; 154851709ffdSYong Li 154951709ffdSYong Li nlohmann::json& hostWatchdogTimer = 155051709ffdSYong Li aResp->res.jsonValue["HostWatchdogTimer"]; 155151709ffdSYong Li 155251709ffdSYong Li // watchdog service is running/enabled 155351709ffdSYong Li hostWatchdogTimer["Status"]["State"] = "Enabled"; 155451709ffdSYong Li 155551709ffdSYong Li for (const auto& property : properties) 155651709ffdSYong Li { 155751709ffdSYong Li BMCWEB_LOG_DEBUG << "prop=" << property.first; 155851709ffdSYong Li if (property.first == "Enabled") 155951709ffdSYong Li { 156051709ffdSYong Li const bool* state = std::get_if<bool>(&property.second); 156151709ffdSYong Li 156251709ffdSYong Li if (!state) 156351709ffdSYong Li { 156451709ffdSYong Li messages::internalError(aResp->res); 156551709ffdSYong Li continue; 156651709ffdSYong Li } 156751709ffdSYong Li 156851709ffdSYong Li hostWatchdogTimer["FunctionEnabled"] = *state; 156951709ffdSYong Li } 157051709ffdSYong Li else if (property.first == "ExpireAction") 157151709ffdSYong Li { 157251709ffdSYong Li const std::string* s = 157351709ffdSYong Li std::get_if<std::string>(&property.second); 157451709ffdSYong Li if (!s) 157551709ffdSYong Li { 157651709ffdSYong Li messages::internalError(aResp->res); 157751709ffdSYong Li continue; 157851709ffdSYong Li } 157951709ffdSYong Li 158051709ffdSYong Li std::string action = dbusToRfWatchdogAction(*s); 158151709ffdSYong Li if (action.empty()) 158251709ffdSYong Li { 158351709ffdSYong Li messages::internalError(aResp->res); 158451709ffdSYong Li continue; 158551709ffdSYong Li } 158651709ffdSYong Li hostWatchdogTimer["TimeoutAction"] = action; 158751709ffdSYong Li } 158851709ffdSYong Li } 158951709ffdSYong Li }, 159051709ffdSYong Li "xyz.openbmc_project.Watchdog", "/xyz/openbmc_project/watchdog/host0", 159151709ffdSYong Li "org.freedesktop.DBus.Properties", "GetAll", 159251709ffdSYong Li "xyz.openbmc_project.State.Watchdog"); 159351709ffdSYong Li } 159451709ffdSYong Li 159551709ffdSYong Li /** 1596c45f0082SYong Li * @brief Sets Host WatchDog Timer properties. 1597c45f0082SYong Li * 1598c45f0082SYong Li * @param[in] aResp Shared pointer for generating response message. 1599c45f0082SYong Li * @param[in] wdtEnable The WDTimer Enable value (true/false) from incoming 1600c45f0082SYong Li * RF request. 1601c45f0082SYong Li * @param[in] wdtTimeOutAction The WDT Timeout action, from incoming RF request. 1602c45f0082SYong Li * 1603c45f0082SYong Li * @return None. 1604c45f0082SYong Li */ 1605b5a76932SEd Tanous inline void setWDTProperties(const std::shared_ptr<AsyncResp>& aResp, 1606c45f0082SYong Li const std::optional<bool> wdtEnable, 1607c45f0082SYong Li const std::optional<std::string>& wdtTimeOutAction) 1608c45f0082SYong Li { 1609c45f0082SYong Li BMCWEB_LOG_DEBUG << "Set host watchdog"; 1610c45f0082SYong Li 1611c45f0082SYong Li if (wdtTimeOutAction) 1612c45f0082SYong Li { 1613c45f0082SYong Li std::string wdtTimeOutActStr = rfToDbusWDTTimeOutAct(*wdtTimeOutAction); 1614c45f0082SYong Li // check if TimeOut Action is Valid 1615c45f0082SYong Li if (wdtTimeOutActStr.empty()) 1616c45f0082SYong Li { 1617c45f0082SYong Li BMCWEB_LOG_DEBUG << "Unsupported value for TimeoutAction: " 1618c45f0082SYong Li << *wdtTimeOutAction; 1619c45f0082SYong Li messages::propertyValueNotInList(aResp->res, *wdtTimeOutAction, 1620c45f0082SYong Li "TimeoutAction"); 1621c45f0082SYong Li return; 1622c45f0082SYong Li } 1623c45f0082SYong Li 1624c45f0082SYong Li crow::connections::systemBus->async_method_call( 1625c45f0082SYong Li [aResp](const boost::system::error_code ec) { 1626c45f0082SYong Li if (ec) 1627c45f0082SYong Li { 1628c45f0082SYong Li BMCWEB_LOG_DEBUG << "DBUS response error " << ec; 1629c45f0082SYong Li messages::internalError(aResp->res); 1630c45f0082SYong Li return; 1631c45f0082SYong Li } 1632c45f0082SYong Li }, 1633c45f0082SYong Li "xyz.openbmc_project.Watchdog", 1634c45f0082SYong Li "/xyz/openbmc_project/watchdog/host0", 1635c45f0082SYong Li "org.freedesktop.DBus.Properties", "Set", 1636c45f0082SYong Li "xyz.openbmc_project.State.Watchdog", "ExpireAction", 1637c45f0082SYong Li std::variant<std::string>(wdtTimeOutActStr)); 1638c45f0082SYong Li } 1639c45f0082SYong Li 1640c45f0082SYong Li if (wdtEnable) 1641c45f0082SYong Li { 1642c45f0082SYong Li crow::connections::systemBus->async_method_call( 1643c45f0082SYong Li [aResp](const boost::system::error_code ec) { 1644c45f0082SYong Li if (ec) 1645c45f0082SYong Li { 1646c45f0082SYong Li BMCWEB_LOG_DEBUG << "DBUS response error " << ec; 1647c45f0082SYong Li messages::internalError(aResp->res); 1648c45f0082SYong Li return; 1649c45f0082SYong Li } 1650c45f0082SYong Li }, 1651c45f0082SYong Li "xyz.openbmc_project.Watchdog", 1652c45f0082SYong Li "/xyz/openbmc_project/watchdog/host0", 1653c45f0082SYong Li "org.freedesktop.DBus.Properties", "Set", 1654c45f0082SYong Li "xyz.openbmc_project.State.Watchdog", "Enabled", 1655c45f0082SYong Li std::variant<bool>(*wdtEnable)); 1656c45f0082SYong Li } 1657c45f0082SYong Li } 1658c45f0082SYong Li 1659c45f0082SYong Li /** 1660c5b2abe0SLewanczyk, Dawid * SystemsCollection derived class for delivering ComputerSystems Collection 1661c5b2abe0SLewanczyk, Dawid * Schema 1662c5b2abe0SLewanczyk, Dawid */ 16631abe55efSEd Tanous class SystemsCollection : public Node 16641abe55efSEd Tanous { 1665c5b2abe0SLewanczyk, Dawid public: 166652cc112dSEd Tanous SystemsCollection(App& app) : Node(app, "/redfish/v1/Systems/") 16671abe55efSEd Tanous { 1668c5b2abe0SLewanczyk, Dawid entityPrivileges = { 1669c5b2abe0SLewanczyk, Dawid {boost::beast::http::verb::get, {{"Login"}}}, 1670c5b2abe0SLewanczyk, Dawid {boost::beast::http::verb::head, {{"Login"}}}, 1671c5b2abe0SLewanczyk, Dawid {boost::beast::http::verb::patch, {{"ConfigureComponents"}}}, 1672c5b2abe0SLewanczyk, Dawid {boost::beast::http::verb::put, {{"ConfigureComponents"}}}, 1673c5b2abe0SLewanczyk, Dawid {boost::beast::http::verb::delete_, {{"ConfigureComponents"}}}, 1674c5b2abe0SLewanczyk, Dawid {boost::beast::http::verb::post, {{"ConfigureComponents"}}}}; 1675c5b2abe0SLewanczyk, Dawid } 1676c5b2abe0SLewanczyk, Dawid 1677c5b2abe0SLewanczyk, Dawid private: 1678cb13a392SEd Tanous void doGet(crow::Response& res, const crow::Request&, 1679cb13a392SEd Tanous const std::vector<std::string>&) override 16801abe55efSEd Tanous { 1681462023adSSunitha Harish std::shared_ptr<AsyncResp> asyncResp = std::make_shared<AsyncResp>(res); 16820f74e643SEd Tanous res.jsonValue["@odata.type"] = 16830f74e643SEd Tanous "#ComputerSystemCollection.ComputerSystemCollection"; 16840f74e643SEd Tanous res.jsonValue["@odata.id"] = "/redfish/v1/Systems"; 16850f74e643SEd Tanous res.jsonValue["Name"] = "Computer System Collection"; 1686462023adSSunitha Harish 1687462023adSSunitha Harish crow::connections::systemBus->async_method_call( 1688462023adSSunitha Harish [asyncResp](const boost::system::error_code ec, 1689cb13a392SEd Tanous const std::variant<std::string>& /*hostName*/) { 16902c70f800SEd Tanous nlohmann::json& ifaceArray = 1691462023adSSunitha Harish asyncResp->res.jsonValue["Members"]; 16922c70f800SEd Tanous ifaceArray = nlohmann::json::array(); 1693462023adSSunitha Harish auto& count = asyncResp->res.jsonValue["Members@odata.count"]; 1694462023adSSunitha Harish count = 0; 16952c70f800SEd Tanous ifaceArray.push_back( 1696cb13a392SEd Tanous {{"@odata.id", "/redfish/v1/Systems/system"}}); 1697cb13a392SEd Tanous if (!ec) 1698462023adSSunitha Harish { 1699462023adSSunitha Harish BMCWEB_LOG_DEBUG << "Hypervisor is available"; 17002c70f800SEd Tanous ifaceArray.push_back( 1701462023adSSunitha Harish {{"@odata.id", "/redfish/v1/Systems/hypervisor"}}); 17022c70f800SEd Tanous count = ifaceArray.size(); 1703cb13a392SEd Tanous return; 1704cb13a392SEd Tanous } 1705462023adSSunitha Harish }, 17068e651fbfSSunitha Harish "xyz.openbmc_project.Settings", 17078e651fbfSSunitha Harish "/xyz/openbmc_project/network/hypervisor", 1708462023adSSunitha Harish "org.freedesktop.DBus.Properties", "Get", 1709462023adSSunitha Harish "xyz.openbmc_project.Network.SystemConfiguration", "HostName"); 1710c5b2abe0SLewanczyk, Dawid } 1711c5b2abe0SLewanczyk, Dawid }; 1712c5b2abe0SLewanczyk, Dawid 1713c5b2abe0SLewanczyk, Dawid /** 1714cc340dd9SEd Tanous * SystemActionsReset class supports handle POST method for Reset action. 1715cc340dd9SEd Tanous * The class retrieves and sends data directly to D-Bus. 1716cc340dd9SEd Tanous */ 1717cc340dd9SEd Tanous class SystemActionsReset : public Node 1718cc340dd9SEd Tanous { 1719cc340dd9SEd Tanous public: 172052cc112dSEd Tanous SystemActionsReset(App& app) : 1721029573d4SEd Tanous Node(app, "/redfish/v1/Systems/system/Actions/ComputerSystem.Reset/") 1722cc340dd9SEd Tanous { 1723cc340dd9SEd Tanous entityPrivileges = { 1724cc340dd9SEd Tanous {boost::beast::http::verb::post, {{"ConfigureComponents"}}}}; 1725cc340dd9SEd Tanous } 1726cc340dd9SEd Tanous 1727cc340dd9SEd Tanous private: 1728cc340dd9SEd Tanous /** 1729cc340dd9SEd Tanous * Function handles POST method request. 1730cc340dd9SEd Tanous * Analyzes POST body message before sends Reset request data to D-Bus. 1731cc340dd9SEd Tanous */ 1732cc340dd9SEd Tanous void doPost(crow::Response& res, const crow::Request& req, 1733cb13a392SEd Tanous const std::vector<std::string>&) override 1734cc340dd9SEd Tanous { 1735cc340dd9SEd Tanous auto asyncResp = std::make_shared<AsyncResp>(res); 1736cc340dd9SEd Tanous 17379712f8acSEd Tanous std::string resetType; 17389712f8acSEd Tanous if (!json_util::readJson(req, res, "ResetType", resetType)) 1739cc340dd9SEd Tanous { 1740cc340dd9SEd Tanous return; 1741cc340dd9SEd Tanous } 1742cc340dd9SEd Tanous 1743d22c8396SJason M. Bills // Get the command and host vs. chassis 1744cc340dd9SEd Tanous std::string command; 1745d22c8396SJason M. Bills bool hostCommand; 1746d4d25793SEd Tanous if ((resetType == "On") || (resetType == "ForceOn")) 1747cc340dd9SEd Tanous { 1748cc340dd9SEd Tanous command = "xyz.openbmc_project.State.Host.Transition.On"; 1749d22c8396SJason M. Bills hostCommand = true; 1750d22c8396SJason M. Bills } 1751d22c8396SJason M. Bills else if (resetType == "ForceOff") 1752d22c8396SJason M. Bills { 1753d22c8396SJason M. Bills command = "xyz.openbmc_project.State.Chassis.Transition.Off"; 1754d22c8396SJason M. Bills hostCommand = false; 1755d22c8396SJason M. Bills } 1756d22c8396SJason M. Bills else if (resetType == "ForceRestart") 1757d22c8396SJason M. Bills { 175886a0851aSJason M. Bills command = 175986a0851aSJason M. Bills "xyz.openbmc_project.State.Host.Transition.ForceWarmReboot"; 176086a0851aSJason M. Bills hostCommand = true; 1761cc340dd9SEd Tanous } 17629712f8acSEd Tanous else if (resetType == "GracefulShutdown") 1763cc340dd9SEd Tanous { 1764cc340dd9SEd Tanous command = "xyz.openbmc_project.State.Host.Transition.Off"; 1765d22c8396SJason M. Bills hostCommand = true; 1766cc340dd9SEd Tanous } 17679712f8acSEd Tanous else if (resetType == "GracefulRestart") 1768cc340dd9SEd Tanous { 176986a0851aSJason M. Bills command = 177086a0851aSJason M. Bills "xyz.openbmc_project.State.Host.Transition.GracefulWarmReboot"; 1771d22c8396SJason M. Bills hostCommand = true; 1772d22c8396SJason M. Bills } 1773d22c8396SJason M. Bills else if (resetType == "PowerCycle") 1774d22c8396SJason M. Bills { 177586a0851aSJason M. Bills command = "xyz.openbmc_project.State.Host.Transition.Reboot"; 177686a0851aSJason M. Bills hostCommand = true; 1777cc340dd9SEd Tanous } 1778bfd5b826SLakshminarayana R. Kammath else if (resetType == "Nmi") 1779bfd5b826SLakshminarayana R. Kammath { 1780bfd5b826SLakshminarayana R. Kammath doNMI(asyncResp); 1781bfd5b826SLakshminarayana R. Kammath return; 1782bfd5b826SLakshminarayana R. Kammath } 1783cc340dd9SEd Tanous else 1784cc340dd9SEd Tanous { 1785f12894f8SJason M. Bills messages::actionParameterUnknown(res, "Reset", resetType); 1786cc340dd9SEd Tanous return; 1787cc340dd9SEd Tanous } 1788cc340dd9SEd Tanous 1789d22c8396SJason M. Bills if (hostCommand) 1790d22c8396SJason M. Bills { 1791cc340dd9SEd Tanous crow::connections::systemBus->async_method_call( 1792d22c8396SJason M. Bills [asyncResp, resetType](const boost::system::error_code ec) { 1793cc340dd9SEd Tanous if (ec) 1794cc340dd9SEd Tanous { 1795cc340dd9SEd Tanous BMCWEB_LOG_ERROR << "D-Bus responses error: " << ec; 1796d22c8396SJason M. Bills if (ec.value() == boost::asio::error::invalid_argument) 1797d22c8396SJason M. Bills { 1798d22c8396SJason M. Bills messages::actionParameterNotSupported( 1799d22c8396SJason M. Bills asyncResp->res, resetType, "Reset"); 1800d22c8396SJason M. Bills } 1801d22c8396SJason M. Bills else 1802d22c8396SJason M. Bills { 1803f12894f8SJason M. Bills messages::internalError(asyncResp->res); 1804d22c8396SJason M. Bills } 1805cc340dd9SEd Tanous return; 1806cc340dd9SEd Tanous } 1807f12894f8SJason M. Bills messages::success(asyncResp->res); 1808cc340dd9SEd Tanous }, 1809cc340dd9SEd Tanous "xyz.openbmc_project.State.Host", 1810cc340dd9SEd Tanous "/xyz/openbmc_project/state/host0", 1811cc340dd9SEd Tanous "org.freedesktop.DBus.Properties", "Set", 18129712f8acSEd Tanous "xyz.openbmc_project.State.Host", "RequestedHostTransition", 1813abf2add6SEd Tanous std::variant<std::string>{command}); 1814cc340dd9SEd Tanous } 1815d22c8396SJason M. Bills else 1816d22c8396SJason M. Bills { 1817d22c8396SJason M. Bills crow::connections::systemBus->async_method_call( 1818d22c8396SJason M. Bills [asyncResp, resetType](const boost::system::error_code ec) { 1819d22c8396SJason M. Bills if (ec) 1820d22c8396SJason M. Bills { 1821d22c8396SJason M. Bills BMCWEB_LOG_ERROR << "D-Bus responses error: " << ec; 1822d22c8396SJason M. Bills if (ec.value() == boost::asio::error::invalid_argument) 1823d22c8396SJason M. Bills { 1824d22c8396SJason M. Bills messages::actionParameterNotSupported( 1825d22c8396SJason M. Bills asyncResp->res, resetType, "Reset"); 1826d22c8396SJason M. Bills } 1827d22c8396SJason M. Bills else 1828d22c8396SJason M. Bills { 1829d22c8396SJason M. Bills messages::internalError(asyncResp->res); 1830d22c8396SJason M. Bills } 1831d22c8396SJason M. Bills return; 1832d22c8396SJason M. Bills } 1833d22c8396SJason M. Bills messages::success(asyncResp->res); 1834d22c8396SJason M. Bills }, 1835d22c8396SJason M. Bills "xyz.openbmc_project.State.Chassis", 1836d22c8396SJason M. Bills "/xyz/openbmc_project/state/chassis0", 1837d22c8396SJason M. Bills "org.freedesktop.DBus.Properties", "Set", 1838d22c8396SJason M. Bills "xyz.openbmc_project.State.Chassis", "RequestedPowerTransition", 1839d22c8396SJason M. Bills std::variant<std::string>{command}); 1840d22c8396SJason M. Bills } 1841d22c8396SJason M. Bills } 1842bfd5b826SLakshminarayana R. Kammath /** 1843bfd5b826SLakshminarayana R. Kammath * Function transceives data with dbus directly. 1844bfd5b826SLakshminarayana R. Kammath */ 1845bfd5b826SLakshminarayana R. Kammath void doNMI(const std::shared_ptr<AsyncResp>& asyncResp) 1846bfd5b826SLakshminarayana R. Kammath { 1847bfd5b826SLakshminarayana R. Kammath constexpr char const* serviceName = 1848bfd5b826SLakshminarayana R. Kammath "xyz.openbmc_project.Control.Host.NMI"; 1849bfd5b826SLakshminarayana R. Kammath constexpr char const* objectPath = 1850bfd5b826SLakshminarayana R. Kammath "/xyz/openbmc_project/control/host0/nmi"; 1851bfd5b826SLakshminarayana R. Kammath constexpr char const* interfaceName = 1852bfd5b826SLakshminarayana R. Kammath "xyz.openbmc_project.Control.Host.NMI"; 1853bfd5b826SLakshminarayana R. Kammath constexpr char const* method = "NMI"; 1854bfd5b826SLakshminarayana R. Kammath 1855bfd5b826SLakshminarayana R. Kammath crow::connections::systemBus->async_method_call( 1856bfd5b826SLakshminarayana R. Kammath [asyncResp](const boost::system::error_code ec) { 1857bfd5b826SLakshminarayana R. Kammath if (ec) 1858bfd5b826SLakshminarayana R. Kammath { 1859bfd5b826SLakshminarayana R. Kammath BMCWEB_LOG_ERROR << " Bad D-Bus request error: " << ec; 1860bfd5b826SLakshminarayana R. Kammath messages::internalError(asyncResp->res); 1861bfd5b826SLakshminarayana R. Kammath return; 1862bfd5b826SLakshminarayana R. Kammath } 1863bfd5b826SLakshminarayana R. Kammath messages::success(asyncResp->res); 1864bfd5b826SLakshminarayana R. Kammath }, 1865bfd5b826SLakshminarayana R. Kammath serviceName, objectPath, interfaceName, method); 1866bfd5b826SLakshminarayana R. Kammath } 1867cc340dd9SEd Tanous }; 1868cc340dd9SEd Tanous 1869cc340dd9SEd Tanous /** 18706617338dSEd Tanous * Systems derived class for delivering Computer Systems Schema. 1871c5b2abe0SLewanczyk, Dawid */ 18721abe55efSEd Tanous class Systems : public Node 18731abe55efSEd Tanous { 1874c5b2abe0SLewanczyk, Dawid public: 1875c5b2abe0SLewanczyk, Dawid /* 1876c5b2abe0SLewanczyk, Dawid * Default Constructor 1877c5b2abe0SLewanczyk, Dawid */ 187852cc112dSEd Tanous Systems(App& app) : Node(app, "/redfish/v1/Systems/system/") 18791abe55efSEd Tanous { 1880c5b2abe0SLewanczyk, Dawid entityPrivileges = { 1881c5b2abe0SLewanczyk, Dawid {boost::beast::http::verb::get, {{"Login"}}}, 1882c5b2abe0SLewanczyk, Dawid {boost::beast::http::verb::head, {{"Login"}}}, 1883c5b2abe0SLewanczyk, Dawid {boost::beast::http::verb::patch, {{"ConfigureComponents"}}}, 1884c5b2abe0SLewanczyk, Dawid {boost::beast::http::verb::put, {{"ConfigureComponents"}}}, 1885c5b2abe0SLewanczyk, Dawid {boost::beast::http::verb::delete_, {{"ConfigureComponents"}}}, 1886c5b2abe0SLewanczyk, Dawid {boost::beast::http::verb::post, {{"ConfigureComponents"}}}}; 1887c5b2abe0SLewanczyk, Dawid } 1888c5b2abe0SLewanczyk, Dawid 1889c5b2abe0SLewanczyk, Dawid private: 1890c5b2abe0SLewanczyk, Dawid /** 1891c5b2abe0SLewanczyk, Dawid * Functions triggers appropriate requests on DBus 1892c5b2abe0SLewanczyk, Dawid */ 1893cb13a392SEd Tanous void doGet(crow::Response& res, const crow::Request&, 1894cb13a392SEd Tanous const std::vector<std::string>&) override 18951abe55efSEd Tanous { 1896c0557e1aSGunnar Mills res.jsonValue["@odata.type"] = "#ComputerSystem.v1_12_0.ComputerSystem"; 1897450a25cbSGunnar Mills res.jsonValue["Name"] = "system"; 1898029573d4SEd Tanous res.jsonValue["Id"] = "system"; 18990f74e643SEd Tanous res.jsonValue["SystemType"] = "Physical"; 19000f74e643SEd Tanous res.jsonValue["Description"] = "Computer System"; 19010f74e643SEd Tanous res.jsonValue["ProcessorSummary"]["Count"] = 0; 19020f74e643SEd Tanous res.jsonValue["ProcessorSummary"]["Status"]["State"] = "Disabled"; 19035fd7ba65SCheng C Yang res.jsonValue["MemorySummary"]["TotalSystemMemoryGiB"] = uint64_t(0); 19040f74e643SEd Tanous res.jsonValue["MemorySummary"]["Status"]["State"] = "Disabled"; 1905029573d4SEd Tanous res.jsonValue["@odata.id"] = "/redfish/v1/Systems/system"; 190604a258f4SEd Tanous 1907443c2934SRapkiewicz, Pawel res.jsonValue["Processors"] = { 1908029573d4SEd Tanous {"@odata.id", "/redfish/v1/Systems/system/Processors"}}; 1909443c2934SRapkiewicz, Pawel res.jsonValue["Memory"] = { 1910029573d4SEd Tanous {"@odata.id", "/redfish/v1/Systems/system/Memory"}}; 1911a25aeccfSNikhil Potade res.jsonValue["Storage"] = { 1912a25aeccfSNikhil Potade {"@odata.id", "/redfish/v1/Systems/system/Storage"}}; 1913029573d4SEd Tanous 1914cc340dd9SEd Tanous res.jsonValue["Actions"]["#ComputerSystem.Reset"] = { 1915cc340dd9SEd Tanous {"target", 1916029573d4SEd Tanous "/redfish/v1/Systems/system/Actions/ComputerSystem.Reset"}, 19171cb1a9e6SAppaRao Puli {"@Redfish.ActionInfo", 19181cb1a9e6SAppaRao Puli "/redfish/v1/Systems/system/ResetActionInfo"}}; 1919c5b2abe0SLewanczyk, Dawid 1920c4bf6374SJason M. Bills res.jsonValue["LogServices"] = { 1921029573d4SEd Tanous {"@odata.id", "/redfish/v1/Systems/system/LogServices"}}; 1922c4bf6374SJason M. Bills 1923d82a3acdSCarol Wang res.jsonValue["Bios"] = { 1924d82a3acdSCarol Wang {"@odata.id", "/redfish/v1/Systems/system/Bios"}}; 1925d82a3acdSCarol Wang 1926c5d03ff4SJennifer Lee res.jsonValue["Links"]["ManagedBy"] = { 1927c5d03ff4SJennifer Lee {{"@odata.id", "/redfish/v1/Managers/bmc"}}}; 1928c5d03ff4SJennifer Lee 1929c5d03ff4SJennifer Lee res.jsonValue["Status"] = { 1930c5d03ff4SJennifer Lee {"Health", "OK"}, 1931c5d03ff4SJennifer Lee {"State", "Enabled"}, 1932c5d03ff4SJennifer Lee }; 1933a0803efaSEd Tanous auto asyncResp = std::make_shared<AsyncResp>(res); 1934c5b2abe0SLewanczyk, Dawid 1935e284a7c1SJames Feist constexpr const std::array<const char*, 4> inventoryForSystems = { 1936b49ac873SJames Feist "xyz.openbmc_project.Inventory.Item.Dimm", 19372ad9c2f6SJames Feist "xyz.openbmc_project.Inventory.Item.Cpu", 1938e284a7c1SJames Feist "xyz.openbmc_project.Inventory.Item.Drive", 1939e284a7c1SJames Feist "xyz.openbmc_project.Inventory.Item.StorageController"}; 1940b49ac873SJames Feist 1941b49ac873SJames Feist auto health = std::make_shared<HealthPopulate>(asyncResp); 1942b49ac873SJames Feist crow::connections::systemBus->async_method_call( 1943b49ac873SJames Feist [health](const boost::system::error_code ec, 1944b49ac873SJames Feist std::vector<std::string>& resp) { 1945b49ac873SJames Feist if (ec) 1946b49ac873SJames Feist { 1947b49ac873SJames Feist // no inventory 1948b49ac873SJames Feist return; 1949b49ac873SJames Feist } 1950b49ac873SJames Feist 1951b49ac873SJames Feist health->inventory = std::move(resp); 1952b49ac873SJames Feist }, 1953b49ac873SJames Feist "xyz.openbmc_project.ObjectMapper", 1954b49ac873SJames Feist "/xyz/openbmc_project/object_mapper", 1955b49ac873SJames Feist "xyz.openbmc_project.ObjectMapper", "GetSubTreePaths", "/", 1956b49ac873SJames Feist int32_t(0), inventoryForSystems); 1957b49ac873SJames Feist 1958b49ac873SJames Feist health->populate(); 1959b49ac873SJames Feist 1960c5d03ff4SJennifer Lee getMainChassisId(asyncResp, [](const std::string& chassisId, 1961b5a76932SEd Tanous const std::shared_ptr<AsyncResp>& aRsp) { 1962c5d03ff4SJennifer Lee aRsp->res.jsonValue["Links"]["Chassis"] = { 1963c5d03ff4SJennifer Lee {{"@odata.id", "/redfish/v1/Chassis/" + chassisId}}}; 1964c5d03ff4SJennifer Lee }); 1965a3002228SAppaRao Puli 1966a3002228SAppaRao Puli getIndicatorLedState(asyncResp); 19675bc2dc8eSJames Feist getComputerSystem(asyncResp, health); 19686c34de48SEd Tanous getHostState(asyncResp); 1969491d8ee7SSantosh Puranik getBootProperties(asyncResp); 1970adbe192aSJason M. Bills getPCIeDeviceList(asyncResp, "PCIeDevices"); 197151709ffdSYong Li getHostWatchdogTimer(asyncResp); 1972c6a620f2SGeorge Liu getPowerRestorePolicy(asyncResp); 19736bd5a8d2SGunnar Mills getAutomaticRetry(asyncResp); 1974c0557e1aSGunnar Mills getLastResetTime(asyncResp); 1975a6349918SAppaRao Puli #ifdef BMCWEB_ENABLE_REDFISH_PROVISIONING_FEATURE 1976a6349918SAppaRao Puli getProvisioningStatus(asyncResp); 1977a6349918SAppaRao Puli #endif 1978c5b2abe0SLewanczyk, Dawid } 1979c5b2abe0SLewanczyk, Dawid 198055c7b7a2SEd Tanous void doPatch(crow::Response& res, const crow::Request& req, 1981cb13a392SEd Tanous const std::vector<std::string>&) override 19821abe55efSEd Tanous { 1983cde19e5fSSantosh Puranik std::optional<std::string> indicatorLed; 1984491d8ee7SSantosh Puranik std::optional<nlohmann::json> bootProps; 1985c45f0082SYong Li std::optional<nlohmann::json> wdtTimerProps; 1986c6a620f2SGeorge Liu std::optional<std::string> powerRestorePolicy; 198741352c24SSantosh Puranik auto asyncResp = std::make_shared<AsyncResp>(res); 198841352c24SSantosh Puranik 1989944ffaf9SJohnathan Mantey if (!json_util::readJson(req, res, "IndicatorLED", indicatorLed, "Boot", 1990c6a620f2SGeorge Liu bootProps, "WatchdogTimer", wdtTimerProps, 1991c6a620f2SGeorge Liu "PowerRestorePolicy", powerRestorePolicy)) 19926617338dSEd Tanous { 19936617338dSEd Tanous return; 19946617338dSEd Tanous } 1995491d8ee7SSantosh Puranik 1996944ffaf9SJohnathan Mantey res.result(boost::beast::http::status::no_content); 1997c45f0082SYong Li 1998c45f0082SYong Li if (wdtTimerProps) 1999c45f0082SYong Li { 2000c45f0082SYong Li std::optional<bool> wdtEnable; 2001c45f0082SYong Li std::optional<std::string> wdtTimeOutAction; 2002c45f0082SYong Li 2003c45f0082SYong Li if (!json_util::readJson(*wdtTimerProps, asyncResp->res, 2004c45f0082SYong Li "FunctionEnabled", wdtEnable, 2005c45f0082SYong Li "TimeoutAction", wdtTimeOutAction)) 2006c45f0082SYong Li { 2007c45f0082SYong Li return; 2008c45f0082SYong Li } 2009*f23b7296SEd Tanous setWDTProperties(asyncResp, wdtEnable, wdtTimeOutAction); 2010c45f0082SYong Li } 2011c45f0082SYong Li 2012491d8ee7SSantosh Puranik if (bootProps) 2013491d8ee7SSantosh Puranik { 2014491d8ee7SSantosh Puranik std::optional<std::string> bootSource; 2015491d8ee7SSantosh Puranik std::optional<std::string> bootEnable; 201669f35306SGunnar Mills std::optional<std::string> automaticRetryConfig; 2017491d8ee7SSantosh Puranik 201869f35306SGunnar Mills if (!json_util::readJson( 201969f35306SGunnar Mills *bootProps, asyncResp->res, "BootSourceOverrideTarget", 202069f35306SGunnar Mills bootSource, "BootSourceOverrideEnabled", bootEnable, 202169f35306SGunnar Mills "AutomaticRetryConfig", automaticRetryConfig)) 2022491d8ee7SSantosh Puranik { 2023491d8ee7SSantosh Puranik return; 2024491d8ee7SSantosh Puranik } 202569f35306SGunnar Mills if (bootSource || bootEnable) 202669f35306SGunnar Mills { 202769f35306SGunnar Mills setBootSourceProperties(asyncResp, std::move(bootSource), 2028491d8ee7SSantosh Puranik std::move(bootEnable)); 2029491d8ee7SSantosh Puranik } 203069f35306SGunnar Mills if (automaticRetryConfig) 203169f35306SGunnar Mills { 2032*f23b7296SEd Tanous setAutomaticRetry(asyncResp, *automaticRetryConfig); 203369f35306SGunnar Mills } 203469f35306SGunnar Mills } 2035265c1602SJohnathan Mantey 20369712f8acSEd Tanous if (indicatorLed) 20376617338dSEd Tanous { 2038*f23b7296SEd Tanous setIndicatorLedState(asyncResp, *indicatorLed); 20396617338dSEd Tanous } 2040c6a620f2SGeorge Liu 2041c6a620f2SGeorge Liu if (powerRestorePolicy) 2042c6a620f2SGeorge Liu { 2043c6a620f2SGeorge Liu setPowerRestorePolicy(asyncResp, std::move(*powerRestorePolicy)); 2044c6a620f2SGeorge Liu } 2045c5b2abe0SLewanczyk, Dawid } 2046c5b2abe0SLewanczyk, Dawid }; 20471cb1a9e6SAppaRao Puli 20481cb1a9e6SAppaRao Puli /** 20491cb1a9e6SAppaRao Puli * SystemResetActionInfo derived class for delivering Computer Systems 20501cb1a9e6SAppaRao Puli * ResetType AllowableValues using ResetInfo schema. 20511cb1a9e6SAppaRao Puli */ 20521cb1a9e6SAppaRao Puli class SystemResetActionInfo : public Node 20531cb1a9e6SAppaRao Puli { 20541cb1a9e6SAppaRao Puli public: 20551cb1a9e6SAppaRao Puli /* 20561cb1a9e6SAppaRao Puli * Default Constructor 20571cb1a9e6SAppaRao Puli */ 205852cc112dSEd Tanous SystemResetActionInfo(App& app) : 20591cb1a9e6SAppaRao Puli Node(app, "/redfish/v1/Systems/system/ResetActionInfo/") 20601cb1a9e6SAppaRao Puli { 20611cb1a9e6SAppaRao Puli entityPrivileges = { 20621cb1a9e6SAppaRao Puli {boost::beast::http::verb::get, {{"Login"}}}, 20631cb1a9e6SAppaRao Puli {boost::beast::http::verb::head, {{"Login"}}}, 20641cb1a9e6SAppaRao Puli {boost::beast::http::verb::patch, {{"ConfigureComponents"}}}, 20651cb1a9e6SAppaRao Puli {boost::beast::http::verb::put, {{"ConfigureComponents"}}}, 20661cb1a9e6SAppaRao Puli {boost::beast::http::verb::delete_, {{"ConfigureComponents"}}}, 20671cb1a9e6SAppaRao Puli {boost::beast::http::verb::post, {{"ConfigureComponents"}}}}; 20681cb1a9e6SAppaRao Puli } 20691cb1a9e6SAppaRao Puli 20701cb1a9e6SAppaRao Puli private: 20711cb1a9e6SAppaRao Puli /** 20721cb1a9e6SAppaRao Puli * Functions triggers appropriate requests on DBus 20731cb1a9e6SAppaRao Puli */ 2074cb13a392SEd Tanous void doGet(crow::Response& res, const crow::Request&, 2075cb13a392SEd Tanous const std::vector<std::string>&) override 20761cb1a9e6SAppaRao Puli { 20771cb1a9e6SAppaRao Puli res.jsonValue = { 20781cb1a9e6SAppaRao Puli {"@odata.type", "#ActionInfo.v1_1_2.ActionInfo"}, 20791cb1a9e6SAppaRao Puli {"@odata.id", "/redfish/v1/Systems/system/ResetActionInfo"}, 20801cb1a9e6SAppaRao Puli {"Name", "Reset Action Info"}, 20811cb1a9e6SAppaRao Puli {"Id", "ResetActionInfo"}, 20821cb1a9e6SAppaRao Puli {"Parameters", 20831cb1a9e6SAppaRao Puli {{{"Name", "ResetType"}, 20841cb1a9e6SAppaRao Puli {"Required", true}, 20851cb1a9e6SAppaRao Puli {"DataType", "String"}, 20861cb1a9e6SAppaRao Puli {"AllowableValues", 20871cb1a9e6SAppaRao Puli {"On", "ForceOff", "ForceOn", "ForceRestart", "GracefulRestart", 20881cb1a9e6SAppaRao Puli "GracefulShutdown", "PowerCycle", "Nmi"}}}}}}; 20891cb1a9e6SAppaRao Puli res.end(); 20901cb1a9e6SAppaRao Puli } 20911cb1a9e6SAppaRao Puli }; 2092c5b2abe0SLewanczyk, Dawid } // namespace redfish 2093