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" 19f5c9f8bdSJason M. Bills #include "pcie.hpp" 20c5d03ff4SJennifer Lee #include "redfish_util.hpp" 21c5d03ff4SJennifer Lee 229712f8acSEd Tanous #include <boost/container/flat_map.hpp> 239712f8acSEd Tanous #include <node.hpp> 24cb7e1e7bSAndrew Geissler #include <utils/fw_utils.hpp> 25c5b2abe0SLewanczyk, Dawid #include <utils/json_utils.hpp> 26abf2add6SEd Tanous #include <variant> 27c5b2abe0SLewanczyk, Dawid 281abe55efSEd Tanous namespace redfish 291abe55efSEd Tanous { 30c5b2abe0SLewanczyk, Dawid 319d3ae10eSAlpana Kumari /** 329d3ae10eSAlpana Kumari * @brief Updates the Functional State of DIMMs 339d3ae10eSAlpana Kumari * 349d3ae10eSAlpana Kumari * @param[in] aResp Shared pointer for completing asynchronous calls 359d3ae10eSAlpana Kumari * @param[in] dimmState Dimm's Functional state, true/false 369d3ae10eSAlpana Kumari * 379d3ae10eSAlpana Kumari * @return None. 389d3ae10eSAlpana Kumari */ 399d3ae10eSAlpana Kumari void updateDimmProperties(std::shared_ptr<AsyncResp> aResp, 409d3ae10eSAlpana Kumari const std::variant<bool> &dimmState) 419d3ae10eSAlpana Kumari { 429d3ae10eSAlpana Kumari const bool *isDimmFunctional = std::get_if<bool>(&dimmState); 439d3ae10eSAlpana Kumari if (isDimmFunctional == nullptr) 449d3ae10eSAlpana Kumari { 459d3ae10eSAlpana Kumari messages::internalError(aResp->res); 469d3ae10eSAlpana Kumari return; 479d3ae10eSAlpana Kumari } 489d3ae10eSAlpana Kumari BMCWEB_LOG_DEBUG << "Dimm Functional: " << *isDimmFunctional; 499d3ae10eSAlpana Kumari 509d3ae10eSAlpana Kumari // Set it as Enabled if atleast one DIMM is functional 519d3ae10eSAlpana Kumari // Update STATE only if previous State was DISABLED and current Dimm is 529d3ae10eSAlpana Kumari // ENABLED. 539d3ae10eSAlpana Kumari nlohmann::json &prevMemSummary = 549d3ae10eSAlpana Kumari aResp->res.jsonValue["MemorySummary"]["Status"]["State"]; 559d3ae10eSAlpana Kumari if (prevMemSummary == "Disabled") 569d3ae10eSAlpana Kumari { 579d3ae10eSAlpana Kumari if (*isDimmFunctional == true) 589d3ae10eSAlpana Kumari { 599d3ae10eSAlpana Kumari aResp->res.jsonValue["MemorySummary"]["Status"]["State"] = 609d3ae10eSAlpana Kumari "Enabled"; 619d3ae10eSAlpana Kumari } 629d3ae10eSAlpana Kumari } 639d3ae10eSAlpana Kumari } 649d3ae10eSAlpana Kumari 6557e8c9beSAlpana Kumari /* 6657e8c9beSAlpana Kumari * @brief Update "ProcessorSummary" "Count" based on Cpu PresenceState 6757e8c9beSAlpana Kumari * 6857e8c9beSAlpana Kumari * @param[in] aResp Shared pointer for completing asynchronous calls 6957e8c9beSAlpana Kumari * @param[in] cpuPresenceState CPU present or not 7057e8c9beSAlpana Kumari * 7157e8c9beSAlpana Kumari * @return None. 7257e8c9beSAlpana Kumari */ 7357e8c9beSAlpana Kumari void modifyCpuPresenceState(std::shared_ptr<AsyncResp> aResp, 7457e8c9beSAlpana Kumari const std::variant<bool> &cpuPresenceState) 7557e8c9beSAlpana Kumari { 7657e8c9beSAlpana Kumari const bool *isCpuPresent = std::get_if<bool>(&cpuPresenceState); 7757e8c9beSAlpana Kumari 7857e8c9beSAlpana Kumari if (isCpuPresent == nullptr) 7957e8c9beSAlpana Kumari { 8057e8c9beSAlpana Kumari messages::internalError(aResp->res); 8157e8c9beSAlpana Kumari return; 8257e8c9beSAlpana Kumari } 8357e8c9beSAlpana Kumari BMCWEB_LOG_DEBUG << "Cpu Present: " << *isCpuPresent; 8457e8c9beSAlpana Kumari 8557e8c9beSAlpana Kumari if (*isCpuPresent == true) 8657e8c9beSAlpana Kumari { 87*b4b9595aSJames Feist nlohmann::json &procCount = 88*b4b9595aSJames Feist aResp->res.jsonValue["ProcessorSummary"]["Count"]; 89*b4b9595aSJames Feist auto procCountPtr = 90*b4b9595aSJames Feist procCount.get_ptr<nlohmann::json::number_integer_t *>(); 91*b4b9595aSJames Feist if (procCountPtr != nullptr) 92*b4b9595aSJames Feist { 93*b4b9595aSJames Feist // shouldn't be possible to be nullptr 94*b4b9595aSJames Feist *procCountPtr += 1; 9557e8c9beSAlpana Kumari } 96*b4b9595aSJames Feist } 9757e8c9beSAlpana Kumari } 9857e8c9beSAlpana Kumari 9957e8c9beSAlpana Kumari /* 10057e8c9beSAlpana Kumari * @brief Update "ProcessorSummary" "Status" "State" based on 10157e8c9beSAlpana Kumari * CPU Functional State 10257e8c9beSAlpana Kumari * 10357e8c9beSAlpana Kumari * @param[in] aResp Shared pointer for completing asynchronous calls 10457e8c9beSAlpana Kumari * @param[in] cpuFunctionalState is CPU functional true/false 10557e8c9beSAlpana Kumari * 10657e8c9beSAlpana Kumari * @return None. 10757e8c9beSAlpana Kumari */ 10857e8c9beSAlpana Kumari void modifyCpuFunctionalState(std::shared_ptr<AsyncResp> aResp, 10957e8c9beSAlpana Kumari const std::variant<bool> &cpuFunctionalState) 11057e8c9beSAlpana Kumari { 11157e8c9beSAlpana Kumari const bool *isCpuFunctional = std::get_if<bool>(&cpuFunctionalState); 11257e8c9beSAlpana Kumari 11357e8c9beSAlpana Kumari if (isCpuFunctional == nullptr) 11457e8c9beSAlpana Kumari { 11557e8c9beSAlpana Kumari messages::internalError(aResp->res); 11657e8c9beSAlpana Kumari return; 11757e8c9beSAlpana Kumari } 11857e8c9beSAlpana Kumari BMCWEB_LOG_DEBUG << "Cpu Functional: " << *isCpuFunctional; 11957e8c9beSAlpana Kumari 12057e8c9beSAlpana Kumari nlohmann::json &prevProcState = 12157e8c9beSAlpana Kumari aResp->res.jsonValue["ProcessorSummary"]["Status"]["State"]; 12257e8c9beSAlpana Kumari 12357e8c9beSAlpana Kumari // Set it as Enabled if atleast one CPU is functional 12457e8c9beSAlpana Kumari // Update STATE only if previous State was Non_Functional and current CPU is 12557e8c9beSAlpana Kumari // Functional. 12657e8c9beSAlpana Kumari if (prevProcState == "Disabled") 12757e8c9beSAlpana Kumari { 12857e8c9beSAlpana Kumari if (*isCpuFunctional == true) 12957e8c9beSAlpana Kumari { 13057e8c9beSAlpana Kumari aResp->res.jsonValue["ProcessorSummary"]["Status"]["State"] = 13157e8c9beSAlpana Kumari "Enabled"; 13257e8c9beSAlpana Kumari } 13357e8c9beSAlpana Kumari } 13457e8c9beSAlpana Kumari } 13557e8c9beSAlpana Kumari 13657e8c9beSAlpana Kumari /* 137c5b2abe0SLewanczyk, Dawid * @brief Retrieves computer system properties over dbus 138c5b2abe0SLewanczyk, Dawid * 139c5b2abe0SLewanczyk, Dawid * @param[in] aResp Shared pointer for completing asynchronous calls 140c5b2abe0SLewanczyk, Dawid * @param[in] name Computer system name from request 141c5b2abe0SLewanczyk, Dawid * 142c5b2abe0SLewanczyk, Dawid * @return None. 143c5b2abe0SLewanczyk, Dawid */ 1445bc2dc8eSJames Feist void getComputerSystem(std::shared_ptr<AsyncResp> aResp, 1455bc2dc8eSJames Feist std::shared_ptr<HealthPopulate> systemHealth) 1461abe55efSEd Tanous { 14755c7b7a2SEd Tanous BMCWEB_LOG_DEBUG << "Get available system components."; 1489d3ae10eSAlpana Kumari 14955c7b7a2SEd Tanous crow::connections::systemBus->async_method_call( 1505bc2dc8eSJames Feist [aResp, systemHealth]( 151c5b2abe0SLewanczyk, Dawid const boost::system::error_code ec, 152c5b2abe0SLewanczyk, Dawid const std::vector<std::pair< 1536c34de48SEd Tanous std::string, 1546c34de48SEd Tanous std::vector<std::pair<std::string, std::vector<std::string>>>>> 155c5b2abe0SLewanczyk, Dawid &subtree) { 1561abe55efSEd Tanous if (ec) 1571abe55efSEd Tanous { 15855c7b7a2SEd Tanous BMCWEB_LOG_DEBUG << "DBUS response error"; 159f12894f8SJason M. Bills messages::internalError(aResp->res); 160c5b2abe0SLewanczyk, Dawid return; 161c5b2abe0SLewanczyk, Dawid } 162c5b2abe0SLewanczyk, Dawid // Iterate over all retrieved ObjectPaths. 1636c34de48SEd Tanous for (const std::pair<std::string, 1646c34de48SEd Tanous std::vector<std::pair< 1656c34de48SEd Tanous std::string, std::vector<std::string>>>> 1661abe55efSEd Tanous &object : subtree) 1671abe55efSEd Tanous { 168c5b2abe0SLewanczyk, Dawid const std::string &path = object.first; 16955c7b7a2SEd Tanous BMCWEB_LOG_DEBUG << "Got path: " << path; 1701abe55efSEd Tanous const std::vector< 1711abe55efSEd Tanous std::pair<std::string, std::vector<std::string>>> 172c5b2abe0SLewanczyk, Dawid &connectionNames = object.second; 1731abe55efSEd Tanous if (connectionNames.size() < 1) 1741abe55efSEd Tanous { 175c5b2abe0SLewanczyk, Dawid continue; 176c5b2abe0SLewanczyk, Dawid } 177029573d4SEd Tanous 1785bc2dc8eSJames Feist auto memoryHealth = std::make_shared<HealthPopulate>( 1795bc2dc8eSJames Feist aResp, aResp->res.jsonValue["MemorySummary"]["Status"]); 1805bc2dc8eSJames Feist 1815bc2dc8eSJames Feist auto cpuHealth = std::make_shared<HealthPopulate>( 1825bc2dc8eSJames Feist aResp, aResp->res.jsonValue["ProcessorSummary"]["Status"]); 1835bc2dc8eSJames Feist 1845bc2dc8eSJames Feist systemHealth->children.emplace_back(memoryHealth); 1855bc2dc8eSJames Feist systemHealth->children.emplace_back(cpuHealth); 1865bc2dc8eSJames Feist 1876c34de48SEd Tanous // This is not system, so check if it's cpu, dimm, UUID or 1886c34de48SEd Tanous // BiosVer 18904a258f4SEd Tanous for (const auto &connection : connectionNames) 1901abe55efSEd Tanous { 19104a258f4SEd Tanous for (const auto &interfaceName : connection.second) 1921abe55efSEd Tanous { 19304a258f4SEd Tanous if (interfaceName == 19404a258f4SEd Tanous "xyz.openbmc_project.Inventory.Item.Dimm") 1951abe55efSEd Tanous { 1961abe55efSEd Tanous BMCWEB_LOG_DEBUG 19704a258f4SEd Tanous << "Found Dimm, now get its properties."; 1989d3ae10eSAlpana Kumari 19955c7b7a2SEd Tanous crow::connections::systemBus->async_method_call( 2009d3ae10eSAlpana Kumari [aResp, service{connection.first}, 2019d3ae10eSAlpana Kumari path(std::move(path))]( 2029d3ae10eSAlpana Kumari const boost::system::error_code ec, 2036c34de48SEd Tanous const std::vector< 2046c34de48SEd Tanous std::pair<std::string, VariantType>> 2051abe55efSEd Tanous &properties) { 2061abe55efSEd Tanous if (ec) 2071abe55efSEd Tanous { 2081abe55efSEd Tanous BMCWEB_LOG_ERROR 2096c34de48SEd Tanous << "DBUS response error " << ec; 210f12894f8SJason M. Bills messages::internalError(aResp->res); 211c5b2abe0SLewanczyk, Dawid return; 212c5b2abe0SLewanczyk, Dawid } 2136c34de48SEd Tanous BMCWEB_LOG_DEBUG << "Got " 2146c34de48SEd Tanous << properties.size() 215c5b2abe0SLewanczyk, Dawid << " Dimm properties."; 2169d3ae10eSAlpana Kumari 2179d3ae10eSAlpana Kumari if (properties.size() > 0) 2189d3ae10eSAlpana Kumari { 21904a258f4SEd Tanous for (const std::pair<std::string, 22004a258f4SEd Tanous VariantType> 22104a258f4SEd Tanous &property : properties) 2221abe55efSEd Tanous { 2235fd7ba65SCheng C Yang if (property.first != 2245fd7ba65SCheng C Yang "MemorySizeInKB") 2251abe55efSEd Tanous { 2265fd7ba65SCheng C Yang continue; 2275fd7ba65SCheng C Yang } 2285fd7ba65SCheng C Yang const uint32_t *value = 2295fd7ba65SCheng C Yang sdbusplus::message::variant_ns:: 2305fd7ba65SCheng C Yang get_if<uint32_t>( 2311b6b96c5SEd Tanous &property.second); 2325fd7ba65SCheng C Yang if (value == nullptr) 2331abe55efSEd Tanous { 2345fd7ba65SCheng C Yang BMCWEB_LOG_DEBUG 2355fd7ba65SCheng C Yang << "Find incorrect type of " 2365fd7ba65SCheng C Yang "MemorySize"; 2375fd7ba65SCheng C Yang continue; 2385fd7ba65SCheng C Yang } 2395fd7ba65SCheng C Yang nlohmann::json &totalMemory = 2405fd7ba65SCheng C Yang aResp->res 2415fd7ba65SCheng C Yang .jsonValue["MemorySummar" 2425fd7ba65SCheng C Yang "y"] 2435fd7ba65SCheng C Yang ["TotalSystemMe" 2445fd7ba65SCheng C Yang "moryGiB"]; 2455fd7ba65SCheng C Yang uint64_t *preValue = 2465fd7ba65SCheng C Yang totalMemory 2475fd7ba65SCheng C Yang .get_ptr<uint64_t *>(); 2485fd7ba65SCheng C Yang if (preValue == nullptr) 2495fd7ba65SCheng C Yang { 2505fd7ba65SCheng C Yang continue; 2515fd7ba65SCheng C Yang } 2525fd7ba65SCheng C Yang aResp->res 2535fd7ba65SCheng C Yang .jsonValue["MemorySummary"] 2546c34de48SEd Tanous ["TotalSystemMemoryGi" 2555fd7ba65SCheng C Yang "B"] = 2565fd7ba65SCheng C Yang *value / (1024 * 1024) + 2575fd7ba65SCheng C Yang *preValue; 2585fd7ba65SCheng C Yang aResp->res 2595fd7ba65SCheng C Yang .jsonValue["MemorySummary"] 2609d3ae10eSAlpana Kumari ["Status"]["State"] = 2611abe55efSEd Tanous "Enabled"; 262c5b2abe0SLewanczyk, Dawid } 263c5b2abe0SLewanczyk, Dawid } 2649d3ae10eSAlpana Kumari else 2659d3ae10eSAlpana Kumari { 2669d3ae10eSAlpana Kumari auto getDimmProperties = 2679d3ae10eSAlpana Kumari [aResp]( 2689d3ae10eSAlpana Kumari const boost::system::error_code 2699d3ae10eSAlpana Kumari ec, 2709d3ae10eSAlpana Kumari const std::variant<bool> 2719d3ae10eSAlpana Kumari &dimmState) { 2729d3ae10eSAlpana Kumari if (ec) 2739d3ae10eSAlpana Kumari { 2749d3ae10eSAlpana Kumari BMCWEB_LOG_ERROR 2759d3ae10eSAlpana Kumari << "DBUS response " 2769d3ae10eSAlpana Kumari "error " 2779d3ae10eSAlpana Kumari << ec; 2789d3ae10eSAlpana Kumari return; 2799d3ae10eSAlpana Kumari } 2809d3ae10eSAlpana Kumari updateDimmProperties(aResp, 2819d3ae10eSAlpana Kumari dimmState); 2829d3ae10eSAlpana Kumari }; 2839d3ae10eSAlpana Kumari crow::connections::systemBus 2849d3ae10eSAlpana Kumari ->async_method_call( 2859d3ae10eSAlpana Kumari std::move(getDimmProperties), 2869d3ae10eSAlpana Kumari service, path, 2879d3ae10eSAlpana Kumari "org.freedesktop.DBus." 2889d3ae10eSAlpana Kumari "Properties", 2899d3ae10eSAlpana Kumari "Get", 2909d3ae10eSAlpana Kumari "xyz.openbmc_project.State." 2919d3ae10eSAlpana Kumari "Decorator.OperationalStatus", 2929d3ae10eSAlpana Kumari "Functional"); 2939d3ae10eSAlpana Kumari } 294c5b2abe0SLewanczyk, Dawid }, 29504a258f4SEd Tanous connection.first, path, 2966c34de48SEd Tanous "org.freedesktop.DBus.Properties", "GetAll", 2976c34de48SEd Tanous "xyz.openbmc_project.Inventory.Item.Dimm"); 2985bc2dc8eSJames Feist 2995bc2dc8eSJames Feist memoryHealth->inventory.emplace_back(path); 3001abe55efSEd Tanous } 30104a258f4SEd Tanous else if (interfaceName == 30204a258f4SEd Tanous "xyz.openbmc_project.Inventory.Item.Cpu") 3031abe55efSEd Tanous { 3041abe55efSEd Tanous BMCWEB_LOG_DEBUG 30504a258f4SEd Tanous << "Found Cpu, now get its properties."; 30657e8c9beSAlpana Kumari 307a0803efaSEd Tanous crow::connections::systemBus->async_method_call( 30857e8c9beSAlpana Kumari [aResp, service{connection.first}, 30957e8c9beSAlpana Kumari path(std::move(path))]( 31057e8c9beSAlpana Kumari const boost::system::error_code ec, 3116c34de48SEd Tanous const std::vector< 3126c34de48SEd Tanous std::pair<std::string, VariantType>> 3131abe55efSEd Tanous &properties) { 3141abe55efSEd Tanous if (ec) 3151abe55efSEd Tanous { 3161abe55efSEd Tanous BMCWEB_LOG_ERROR 3176c34de48SEd Tanous << "DBUS response error " << ec; 318f12894f8SJason M. Bills messages::internalError(aResp->res); 319c5b2abe0SLewanczyk, Dawid return; 320c5b2abe0SLewanczyk, Dawid } 3216c34de48SEd Tanous BMCWEB_LOG_DEBUG << "Got " 3226c34de48SEd Tanous << properties.size() 323c5b2abe0SLewanczyk, Dawid << " Cpu properties."; 32457e8c9beSAlpana Kumari 32557e8c9beSAlpana Kumari if (properties.size() > 0) 32657e8c9beSAlpana Kumari { 32704a258f4SEd Tanous for (const auto &property : properties) 3281abe55efSEd Tanous { 32957e8c9beSAlpana Kumari if (property.first == 33057e8c9beSAlpana Kumari "ProcessorFamily") 3311abe55efSEd Tanous { 332a0803efaSEd Tanous const std::string *value = 33357e8c9beSAlpana Kumari sdbusplus::message:: 33457e8c9beSAlpana Kumari variant_ns::get_if< 33557e8c9beSAlpana Kumari std::string>( 3361b6b96c5SEd Tanous &property.second); 3371abe55efSEd Tanous if (value != nullptr) 3381abe55efSEd Tanous { 33957e8c9beSAlpana Kumari nlohmann::json 34057e8c9beSAlpana Kumari &procSummary = 3411abe55efSEd Tanous aResp->res.jsonValue 3426c34de48SEd Tanous ["ProcessorSumm" 34304a258f4SEd Tanous "ary"]; 34404a258f4SEd Tanous nlohmann::json &procCount = 34504a258f4SEd Tanous procSummary["Count"]; 346*b4b9595aSJames Feist 347*b4b9595aSJames Feist auto procCountPtr = 348*b4b9595aSJames Feist procCount.get_ptr< 349*b4b9595aSJames Feist nlohmann::json:: 350*b4b9595aSJames Feist number_integer_t 351*b4b9595aSJames Feist *>(); 352*b4b9595aSJames Feist if (procCountPtr != nullptr) 353*b4b9595aSJames Feist { 354*b4b9595aSJames Feist // shouldn't be possible 355*b4b9595aSJames Feist // to be nullptr 356*b4b9595aSJames Feist *procCountPtr += 1; 357*b4b9595aSJames Feist } 35857e8c9beSAlpana Kumari procSummary["Status"] 35957e8c9beSAlpana Kumari ["State"] = 360c5b2abe0SLewanczyk, Dawid "Enabled"; 36157e8c9beSAlpana Kumari procSummary["Model"] = 36257e8c9beSAlpana Kumari *value; 363c5b2abe0SLewanczyk, Dawid } 364c5b2abe0SLewanczyk, Dawid } 365c5b2abe0SLewanczyk, Dawid } 36657e8c9beSAlpana Kumari } 36757e8c9beSAlpana Kumari else 36857e8c9beSAlpana Kumari { 36957e8c9beSAlpana Kumari auto getCpuPresenceState = 37057e8c9beSAlpana Kumari [aResp]( 37157e8c9beSAlpana Kumari const boost::system::error_code 37257e8c9beSAlpana Kumari ec, 37357e8c9beSAlpana Kumari const std::variant<bool> 37457e8c9beSAlpana Kumari &cpuPresenceCheck) { 37557e8c9beSAlpana Kumari if (ec) 37657e8c9beSAlpana Kumari { 37757e8c9beSAlpana Kumari BMCWEB_LOG_ERROR 37857e8c9beSAlpana Kumari << "DBUS response " 37957e8c9beSAlpana Kumari "error " 38057e8c9beSAlpana Kumari << ec; 38157e8c9beSAlpana Kumari return; 38257e8c9beSAlpana Kumari } 38357e8c9beSAlpana Kumari modifyCpuPresenceState( 38457e8c9beSAlpana Kumari aResp, cpuPresenceCheck); 38557e8c9beSAlpana Kumari }; 38657e8c9beSAlpana Kumari 38757e8c9beSAlpana Kumari auto getCpuFunctionalState = 38857e8c9beSAlpana Kumari [aResp]( 38957e8c9beSAlpana Kumari const boost::system::error_code 39057e8c9beSAlpana Kumari ec, 39157e8c9beSAlpana Kumari const std::variant<bool> 39257e8c9beSAlpana Kumari &cpuFunctionalCheck) { 39357e8c9beSAlpana Kumari if (ec) 39457e8c9beSAlpana Kumari { 39557e8c9beSAlpana Kumari BMCWEB_LOG_ERROR 39657e8c9beSAlpana Kumari << "DBUS response " 39757e8c9beSAlpana Kumari "error " 39857e8c9beSAlpana Kumari << ec; 39957e8c9beSAlpana Kumari return; 40057e8c9beSAlpana Kumari } 40157e8c9beSAlpana Kumari modifyCpuFunctionalState( 40257e8c9beSAlpana Kumari aResp, cpuFunctionalCheck); 40357e8c9beSAlpana Kumari }; 40457e8c9beSAlpana Kumari // Get the Presence of CPU 40557e8c9beSAlpana Kumari crow::connections::systemBus 40657e8c9beSAlpana Kumari ->async_method_call( 40757e8c9beSAlpana Kumari std::move(getCpuPresenceState), 40857e8c9beSAlpana Kumari service, path, 40957e8c9beSAlpana Kumari "org.freedesktop.DBus." 41057e8c9beSAlpana Kumari "Properties", 41157e8c9beSAlpana Kumari "Get", 41257e8c9beSAlpana Kumari "xyz.openbmc_project.Inventory." 41357e8c9beSAlpana Kumari "Item", 41457e8c9beSAlpana Kumari "Present"); 41557e8c9beSAlpana Kumari 41657e8c9beSAlpana Kumari // Get the Functional State 41757e8c9beSAlpana Kumari crow::connections::systemBus 41857e8c9beSAlpana Kumari ->async_method_call( 41957e8c9beSAlpana Kumari std::move( 42057e8c9beSAlpana Kumari getCpuFunctionalState), 42157e8c9beSAlpana Kumari service, path, 42257e8c9beSAlpana Kumari "org.freedesktop.DBus." 42357e8c9beSAlpana Kumari "Properties", 42457e8c9beSAlpana Kumari "Get", 42557e8c9beSAlpana Kumari "xyz.openbmc_project.State." 42657e8c9beSAlpana Kumari "Decorator." 42757e8c9beSAlpana Kumari "OperationalStatus", 42857e8c9beSAlpana Kumari "Functional"); 42957e8c9beSAlpana Kumari 43057e8c9beSAlpana Kumari // Get the MODEL from 43157e8c9beSAlpana Kumari // xyz.openbmc_project.Inventory.Decorator.Asset 43257e8c9beSAlpana Kumari // support it later as Model is Empty 43357e8c9beSAlpana Kumari // currently. 43457e8c9beSAlpana Kumari } 435c5b2abe0SLewanczyk, Dawid }, 43604a258f4SEd Tanous connection.first, path, 4376c34de48SEd Tanous "org.freedesktop.DBus.Properties", "GetAll", 4386c34de48SEd Tanous "xyz.openbmc_project.Inventory.Item.Cpu"); 4395bc2dc8eSJames Feist 4405bc2dc8eSJames Feist cpuHealth->inventory.emplace_back(path); 4411abe55efSEd Tanous } 44204a258f4SEd Tanous else if (interfaceName == 44304a258f4SEd Tanous "xyz.openbmc_project.Common.UUID") 4441abe55efSEd Tanous { 4451abe55efSEd Tanous BMCWEB_LOG_DEBUG 44604a258f4SEd Tanous << "Found UUID, now get its properties."; 44755c7b7a2SEd Tanous crow::connections::systemBus->async_method_call( 448029573d4SEd Tanous [aResp](const boost::system::error_code ec, 4496c34de48SEd Tanous const std::vector< 4506c34de48SEd Tanous std::pair<std::string, VariantType>> 4511abe55efSEd Tanous &properties) { 4521abe55efSEd Tanous if (ec) 4531abe55efSEd Tanous { 4541abe55efSEd Tanous BMCWEB_LOG_DEBUG 4556c34de48SEd Tanous << "DBUS response error " << ec; 456f12894f8SJason M. Bills messages::internalError(aResp->res); 457c5b2abe0SLewanczyk, Dawid return; 458c5b2abe0SLewanczyk, Dawid } 4596c34de48SEd Tanous BMCWEB_LOG_DEBUG << "Got " 4606c34de48SEd Tanous << properties.size() 461c5b2abe0SLewanczyk, Dawid << " UUID properties."; 4621abe55efSEd Tanous for (const std::pair<std::string, 46304a258f4SEd Tanous VariantType> 46404a258f4SEd Tanous &property : properties) 4651abe55efSEd Tanous { 46604a258f4SEd Tanous if (property.first == "UUID") 4671abe55efSEd Tanous { 468c5b2abe0SLewanczyk, Dawid const std::string *value = 469029573d4SEd Tanous sdbusplus::message::variant_ns:: 470029573d4SEd Tanous get_if<std::string>( 4711b6b96c5SEd Tanous &property.second); 47204a258f4SEd Tanous 4731abe55efSEd Tanous if (value != nullptr) 4741abe55efSEd Tanous { 475029573d4SEd Tanous std::string valueStr = *value; 47604a258f4SEd Tanous if (valueStr.size() == 32) 4771abe55efSEd Tanous { 478029573d4SEd Tanous valueStr.insert(8, 1, '-'); 479029573d4SEd Tanous valueStr.insert(13, 1, '-'); 480029573d4SEd Tanous valueStr.insert(18, 1, '-'); 481029573d4SEd Tanous valueStr.insert(23, 1, '-'); 48204a258f4SEd Tanous } 483029573d4SEd Tanous BMCWEB_LOG_DEBUG << "UUID = " 48404a258f4SEd Tanous << valueStr; 485029573d4SEd Tanous aResp->res.jsonValue["UUID"] = 48604a258f4SEd Tanous valueStr; 487c5b2abe0SLewanczyk, Dawid } 488c5b2abe0SLewanczyk, Dawid } 489c5b2abe0SLewanczyk, Dawid } 490c5b2abe0SLewanczyk, Dawid }, 49104a258f4SEd Tanous connection.first, path, 4926c34de48SEd Tanous "org.freedesktop.DBus.Properties", "GetAll", 4931abe55efSEd Tanous "xyz.openbmc_project.Common.UUID"); 494c5b2abe0SLewanczyk, Dawid } 495029573d4SEd Tanous else if (interfaceName == 496029573d4SEd Tanous "xyz.openbmc_project.Inventory.Item.System") 4971abe55efSEd Tanous { 498029573d4SEd Tanous crow::connections::systemBus->async_method_call( 499029573d4SEd Tanous [aResp](const boost::system::error_code ec, 500029573d4SEd Tanous const std::vector< 501029573d4SEd Tanous std::pair<std::string, VariantType>> 502029573d4SEd Tanous &propertiesList) { 503029573d4SEd Tanous if (ec) 504029573d4SEd Tanous { 505e4a4b9a9SJames Feist // doesn't have to include this 506e4a4b9a9SJames Feist // interface 507029573d4SEd Tanous return; 508029573d4SEd Tanous } 509698654b6SGunnar Mills BMCWEB_LOG_DEBUG 510698654b6SGunnar Mills << "Got " << propertiesList.size() 511029573d4SEd Tanous << " properties for system"; 512029573d4SEd Tanous for (const std::pair<std::string, 513029573d4SEd Tanous VariantType> 514029573d4SEd Tanous &property : propertiesList) 515029573d4SEd Tanous { 516fc5afcf9Sbeccabroek const std::string &propertyName = 517fc5afcf9Sbeccabroek property.first; 518fc5afcf9Sbeccabroek if ((propertyName == "PartNumber") || 519fc5afcf9Sbeccabroek (propertyName == "SerialNumber") || 520fc5afcf9Sbeccabroek (propertyName == "Manufacturer") || 521fc5afcf9Sbeccabroek (propertyName == "Model")) 522fc5afcf9Sbeccabroek { 523029573d4SEd Tanous const std::string *value = 524fc5afcf9Sbeccabroek std::get_if<std::string>( 525029573d4SEd Tanous &property.second); 526029573d4SEd Tanous if (value != nullptr) 527029573d4SEd Tanous { 528029573d4SEd Tanous aResp->res 529fc5afcf9Sbeccabroek .jsonValue[propertyName] = 530029573d4SEd Tanous *value; 531029573d4SEd Tanous } 532029573d4SEd Tanous } 533fc5afcf9Sbeccabroek } 534029573d4SEd Tanous aResp->res.jsonValue["Name"] = "system"; 535029573d4SEd Tanous aResp->res.jsonValue["Id"] = 536029573d4SEd Tanous aResp->res.jsonValue["SerialNumber"]; 537cb7e1e7bSAndrew Geissler // Grab the bios version 538cb7e1e7bSAndrew Geissler fw_util::getActiveFwVersion( 539cb7e1e7bSAndrew Geissler aResp, fw_util::biosPurpose, 540cb7e1e7bSAndrew Geissler "BiosVersion"); 541029573d4SEd Tanous }, 542029573d4SEd Tanous connection.first, path, 543029573d4SEd Tanous "org.freedesktop.DBus.Properties", "GetAll", 544029573d4SEd Tanous "xyz.openbmc_project.Inventory.Decorator." 545029573d4SEd Tanous "Asset"); 546e4a4b9a9SJames Feist 547e4a4b9a9SJames Feist crow::connections::systemBus->async_method_call( 548e4a4b9a9SJames Feist [aResp]( 549e4a4b9a9SJames Feist const boost::system::error_code ec, 550e4a4b9a9SJames Feist const std::variant<std::string> &property) { 551e4a4b9a9SJames Feist if (ec) 552e4a4b9a9SJames Feist { 553e4a4b9a9SJames Feist // doesn't have to include this 554e4a4b9a9SJames Feist // interface 555e4a4b9a9SJames Feist return; 556e4a4b9a9SJames Feist } 557e4a4b9a9SJames Feist 558e4a4b9a9SJames Feist const std::string *value = 559e4a4b9a9SJames Feist std::get_if<std::string>(&property); 560e4a4b9a9SJames Feist if (value != nullptr) 561e4a4b9a9SJames Feist { 562e4a4b9a9SJames Feist aResp->res.jsonValue["AssetTag"] = 563e4a4b9a9SJames Feist *value; 564e4a4b9a9SJames Feist } 565e4a4b9a9SJames Feist }, 566e4a4b9a9SJames Feist connection.first, path, 567e4a4b9a9SJames Feist "org.freedesktop.DBus.Properties", "Get", 568e4a4b9a9SJames Feist "xyz.openbmc_project.Inventory.Decorator." 569e4a4b9a9SJames Feist "AssetTag", 570e4a4b9a9SJames Feist "AssetTag"); 571029573d4SEd Tanous } 572029573d4SEd Tanous } 573029573d4SEd Tanous } 574c5b2abe0SLewanczyk, Dawid } 575c5b2abe0SLewanczyk, Dawid }, 576c5b2abe0SLewanczyk, Dawid "xyz.openbmc_project.ObjectMapper", 577c5b2abe0SLewanczyk, Dawid "/xyz/openbmc_project/object_mapper", 578c5b2abe0SLewanczyk, Dawid "xyz.openbmc_project.ObjectMapper", "GetSubTree", 5796617338dSEd Tanous "/xyz/openbmc_project/inventory", int32_t(0), 5806617338dSEd Tanous std::array<const char *, 5>{ 5816617338dSEd Tanous "xyz.openbmc_project.Inventory.Decorator.Asset", 5826617338dSEd Tanous "xyz.openbmc_project.Inventory.Item.Cpu", 5836617338dSEd Tanous "xyz.openbmc_project.Inventory.Item.Dimm", 5846617338dSEd Tanous "xyz.openbmc_project.Inventory.Item.System", 5856617338dSEd Tanous "xyz.openbmc_project.Common.UUID", 5866617338dSEd Tanous }); 587c5b2abe0SLewanczyk, Dawid } 588c5b2abe0SLewanczyk, Dawid 589c5b2abe0SLewanczyk, Dawid /** 590c5b2abe0SLewanczyk, Dawid * @brief Retrieves identify led group properties over dbus 591c5b2abe0SLewanczyk, Dawid * 592491d8ee7SSantosh Puranik * @param[in] aResp Shared pointer for generating response message. 593c5b2abe0SLewanczyk, Dawid * 594c5b2abe0SLewanczyk, Dawid * @return None. 595c5b2abe0SLewanczyk, Dawid */ 596a3002228SAppaRao Puli void getIndicatorLedState(std::shared_ptr<AsyncResp> aResp) 5971abe55efSEd Tanous { 59855c7b7a2SEd Tanous BMCWEB_LOG_DEBUG << "Get led groups"; 59955c7b7a2SEd Tanous crow::connections::systemBus->async_method_call( 600a3002228SAppaRao Puli [aResp](const boost::system::error_code ec, 601a3002228SAppaRao Puli const std::variant<bool> asserted) { 602f847a198SAppaRao Puli // Some systems may not have enclosure_identify_blink object so 603f847a198SAppaRao Puli // proceed to get enclosure_identify state. 604f847a198SAppaRao Puli if (!ec) 6051abe55efSEd Tanous { 606a3002228SAppaRao Puli const bool *blinking = std::get_if<bool>(&asserted); 607a3002228SAppaRao Puli if (!blinking) 6081abe55efSEd Tanous { 609a3002228SAppaRao Puli BMCWEB_LOG_DEBUG << "Get identity blinking LED failed"; 610a3002228SAppaRao Puli messages::internalError(aResp->res); 611a3002228SAppaRao Puli return; 612a3002228SAppaRao Puli } 613a3002228SAppaRao Puli // Blinking ON, no need to check enclosure_identify assert. 614a3002228SAppaRao Puli if (*blinking) 6151abe55efSEd Tanous { 616a3002228SAppaRao Puli aResp->res.jsonValue["IndicatorLED"] = "Blinking"; 617a3002228SAppaRao Puli return; 618a3002228SAppaRao Puli } 619f847a198SAppaRao Puli } 620a3002228SAppaRao Puli crow::connections::systemBus->async_method_call( 621a3002228SAppaRao Puli [aResp](const boost::system::error_code ec, 622a3002228SAppaRao Puli const std::variant<bool> asserted) { 623f847a198SAppaRao Puli if (!ec) 6241abe55efSEd Tanous { 625a3002228SAppaRao Puli const bool *ledOn = std::get_if<bool>(&asserted); 626a3002228SAppaRao Puli if (!ledOn) 6271abe55efSEd Tanous { 628f847a198SAppaRao Puli BMCWEB_LOG_DEBUG 629f847a198SAppaRao Puli << "Get enclosure identity led failed"; 630a3002228SAppaRao Puli messages::internalError(aResp->res); 631a3002228SAppaRao Puli return; 632a3002228SAppaRao Puli } 633a3002228SAppaRao Puli 634a3002228SAppaRao Puli if (*ledOn) 6351abe55efSEd Tanous { 636a3002228SAppaRao Puli aResp->res.jsonValue["IndicatorLED"] = "Lit"; 6371abe55efSEd Tanous } 6381abe55efSEd Tanous else 6391abe55efSEd Tanous { 640a3002228SAppaRao Puli aResp->res.jsonValue["IndicatorLED"] = "Off"; 641c5b2abe0SLewanczyk, Dawid } 642f847a198SAppaRao Puli } 643a3002228SAppaRao Puli return; 644a3002228SAppaRao Puli }, 645a3002228SAppaRao Puli "xyz.openbmc_project.LED.GroupManager", 646a3002228SAppaRao Puli "/xyz/openbmc_project/led/groups/enclosure_identify", 647a3002228SAppaRao Puli "org.freedesktop.DBus.Properties", "Get", 648a3002228SAppaRao Puli "xyz.openbmc_project.Led.Group", "Asserted"); 649a3002228SAppaRao Puli }, 650a3002228SAppaRao Puli "xyz.openbmc_project.LED.GroupManager", 651a3002228SAppaRao Puli "/xyz/openbmc_project/led/groups/enclosure_identify_blink", 652a3002228SAppaRao Puli "org.freedesktop.DBus.Properties", "Get", 653a3002228SAppaRao Puli "xyz.openbmc_project.Led.Group", "Asserted"); 654c5b2abe0SLewanczyk, Dawid } 655a3002228SAppaRao Puli /** 656a3002228SAppaRao Puli * @brief Sets identify led group properties 657a3002228SAppaRao Puli * 658a3002228SAppaRao Puli * @param[in] aResp Shared pointer for generating response message. 659a3002228SAppaRao Puli * @param[in] ledState LED state passed from request 660a3002228SAppaRao Puli * 661a3002228SAppaRao Puli * @return None. 662a3002228SAppaRao Puli */ 663a3002228SAppaRao Puli void setIndicatorLedState(std::shared_ptr<AsyncResp> aResp, 664a3002228SAppaRao Puli const std::string &ledState) 665a3002228SAppaRao Puli { 666a3002228SAppaRao Puli BMCWEB_LOG_DEBUG << "Set led groups"; 667a3002228SAppaRao Puli bool ledOn = false; 668a3002228SAppaRao Puli bool ledBlinkng = false; 669a3002228SAppaRao Puli 670a3002228SAppaRao Puli if (ledState == "Lit") 671a3002228SAppaRao Puli { 672a3002228SAppaRao Puli ledOn = true; 673c5b2abe0SLewanczyk, Dawid } 674a3002228SAppaRao Puli else if (ledState == "Blinking") 675a3002228SAppaRao Puli { 676a3002228SAppaRao Puli ledBlinkng = true; 677c5b2abe0SLewanczyk, Dawid } 678a3002228SAppaRao Puli else if (ledState != "Off") 679a3002228SAppaRao Puli { 680a3002228SAppaRao Puli messages::propertyValueNotInList(aResp->res, ledState, "IndicatorLED"); 681a3002228SAppaRao Puli return; 682c5b2abe0SLewanczyk, Dawid } 683a3002228SAppaRao Puli 684a3002228SAppaRao Puli crow::connections::systemBus->async_method_call( 685f847a198SAppaRao Puli [aResp, ledOn, ledBlinkng](const boost::system::error_code ec, 686f847a198SAppaRao Puli const std::variant<bool> asserted) mutable { 687f847a198SAppaRao Puli if (ec) 688f847a198SAppaRao Puli { 689f847a198SAppaRao Puli // Some systems may not have enclosure_identify_blink object so 690f847a198SAppaRao Puli // Lets set enclosure_identify state to true if Blinking is 691f847a198SAppaRao Puli // true. 692f847a198SAppaRao Puli if (ledBlinkng) 693f847a198SAppaRao Puli { 694f847a198SAppaRao Puli ledOn = true; 695f847a198SAppaRao Puli } 696f847a198SAppaRao Puli } 697f847a198SAppaRao Puli crow::connections::systemBus->async_method_call( 698a3002228SAppaRao Puli [aResp](const boost::system::error_code ec, 699a3002228SAppaRao Puli const std::variant<bool> asserted) { 700a3002228SAppaRao Puli if (ec) 701a3002228SAppaRao Puli { 702a3002228SAppaRao Puli BMCWEB_LOG_DEBUG << "DBUS response error " << ec; 703a3002228SAppaRao Puli messages::internalError(aResp->res); 704a3002228SAppaRao Puli return; 705c5b2abe0SLewanczyk, Dawid } 706c5b2abe0SLewanczyk, Dawid }, 707c5b2abe0SLewanczyk, Dawid "xyz.openbmc_project.LED.GroupManager", 708a3002228SAppaRao Puli "/xyz/openbmc_project/led/groups/enclosure_identify", 709a3002228SAppaRao Puli "org.freedesktop.DBus.Properties", "Set", 710f847a198SAppaRao Puli "xyz.openbmc_project.Led.Group", "Asserted", 711f847a198SAppaRao Puli std::variant<bool>(ledOn)); 712a3002228SAppaRao Puli }, 713a3002228SAppaRao Puli "xyz.openbmc_project.LED.GroupManager", 714a3002228SAppaRao Puli "/xyz/openbmc_project/led/groups/enclosure_identify_blink", 715a3002228SAppaRao Puli "org.freedesktop.DBus.Properties", "Set", 716a3002228SAppaRao Puli "xyz.openbmc_project.Led.Group", "Asserted", 717a3002228SAppaRao Puli std::variant<bool>(ledBlinkng)); 718c5b2abe0SLewanczyk, Dawid } 719c5b2abe0SLewanczyk, Dawid 720c5b2abe0SLewanczyk, Dawid /** 721c5b2abe0SLewanczyk, Dawid * @brief Retrieves host state properties over dbus 722c5b2abe0SLewanczyk, Dawid * 723c5b2abe0SLewanczyk, Dawid * @param[in] aResp Shared pointer for completing asynchronous calls. 724c5b2abe0SLewanczyk, Dawid * 725c5b2abe0SLewanczyk, Dawid * @return None. 726c5b2abe0SLewanczyk, Dawid */ 727a0803efaSEd Tanous void getHostState(std::shared_ptr<AsyncResp> aResp) 7281abe55efSEd Tanous { 72955c7b7a2SEd Tanous BMCWEB_LOG_DEBUG << "Get host information."; 73055c7b7a2SEd Tanous crow::connections::systemBus->async_method_call( 731c5d03ff4SJennifer Lee [aResp](const boost::system::error_code ec, 732abf2add6SEd Tanous const std::variant<std::string> &hostState) { 7331abe55efSEd Tanous if (ec) 7341abe55efSEd Tanous { 73555c7b7a2SEd Tanous BMCWEB_LOG_DEBUG << "DBUS response error " << ec; 736f12894f8SJason M. Bills messages::internalError(aResp->res); 737c5b2abe0SLewanczyk, Dawid return; 738c5b2abe0SLewanczyk, Dawid } 7396617338dSEd Tanous 740abf2add6SEd Tanous const std::string *s = std::get_if<std::string>(&hostState); 74155c7b7a2SEd Tanous BMCWEB_LOG_DEBUG << "Host state: " << *s; 7426617338dSEd Tanous if (s != nullptr) 7431abe55efSEd Tanous { 744c5b2abe0SLewanczyk, Dawid // Verify Host State 74594732661SAndrew Geissler if (*s == "xyz.openbmc_project.State.Host.HostState.Running") 7461abe55efSEd Tanous { 74755c7b7a2SEd Tanous aResp->res.jsonValue["PowerState"] = "On"; 7486617338dSEd Tanous aResp->res.jsonValue["Status"]["State"] = "Enabled"; 7491abe55efSEd Tanous } 7501abe55efSEd Tanous else 7511abe55efSEd Tanous { 75255c7b7a2SEd Tanous aResp->res.jsonValue["PowerState"] = "Off"; 7536617338dSEd Tanous aResp->res.jsonValue["Status"]["State"] = "Disabled"; 754c5b2abe0SLewanczyk, Dawid } 755c5b2abe0SLewanczyk, Dawid } 756c5b2abe0SLewanczyk, Dawid }, 7576c34de48SEd Tanous "xyz.openbmc_project.State.Host", "/xyz/openbmc_project/state/host0", 7586617338dSEd Tanous "org.freedesktop.DBus.Properties", "Get", 7596617338dSEd Tanous "xyz.openbmc_project.State.Host", "CurrentHostState"); 760c5b2abe0SLewanczyk, Dawid } 761c5b2abe0SLewanczyk, Dawid 762c5b2abe0SLewanczyk, Dawid /** 763491d8ee7SSantosh Puranik * @brief Traslates boot source DBUS property value to redfish. 764491d8ee7SSantosh Puranik * 765491d8ee7SSantosh Puranik * @param[in] dbusSource The boot source in DBUS speak. 766491d8ee7SSantosh Puranik * 767491d8ee7SSantosh Puranik * @return Returns as a string, the boot source in Redfish terms. If translation 768491d8ee7SSantosh Puranik * cannot be done, returns an empty string. 769491d8ee7SSantosh Puranik */ 770491d8ee7SSantosh Puranik static std::string dbusToRfBootSource(const std::string &dbusSource) 771491d8ee7SSantosh Puranik { 772491d8ee7SSantosh Puranik if (dbusSource == "xyz.openbmc_project.Control.Boot.Source.Sources.Default") 773491d8ee7SSantosh Puranik { 774491d8ee7SSantosh Puranik return "None"; 775491d8ee7SSantosh Puranik } 776491d8ee7SSantosh Puranik else if (dbusSource == 777491d8ee7SSantosh Puranik "xyz.openbmc_project.Control.Boot.Source.Sources.Disk") 778491d8ee7SSantosh Puranik { 779491d8ee7SSantosh Puranik return "Hdd"; 780491d8ee7SSantosh Puranik } 781491d8ee7SSantosh Puranik else if (dbusSource == 782a71dc0b7SSantosh Puranik "xyz.openbmc_project.Control.Boot.Source.Sources.ExternalMedia") 783491d8ee7SSantosh Puranik { 784491d8ee7SSantosh Puranik return "Cd"; 785491d8ee7SSantosh Puranik } 786491d8ee7SSantosh Puranik else if (dbusSource == 787491d8ee7SSantosh Puranik "xyz.openbmc_project.Control.Boot.Source.Sources.Network") 788491d8ee7SSantosh Puranik { 789491d8ee7SSantosh Puranik return "Pxe"; 790491d8ee7SSantosh Puranik } 7919f16b2c1SJennifer Lee else if (dbusSource == 792944ffaf9SJohnathan Mantey "xyz.openbmc_project.Control.Boot.Source.Sources.RemovableMedia") 7939f16b2c1SJennifer Lee { 7949f16b2c1SJennifer Lee return "Usb"; 7959f16b2c1SJennifer Lee } 796491d8ee7SSantosh Puranik else 797491d8ee7SSantosh Puranik { 798491d8ee7SSantosh Puranik return ""; 799491d8ee7SSantosh Puranik } 800491d8ee7SSantosh Puranik } 801491d8ee7SSantosh Puranik 802491d8ee7SSantosh Puranik /** 803491d8ee7SSantosh Puranik * @brief Traslates boot mode DBUS property value to redfish. 804491d8ee7SSantosh Puranik * 805491d8ee7SSantosh Puranik * @param[in] dbusMode The boot mode in DBUS speak. 806491d8ee7SSantosh Puranik * 807491d8ee7SSantosh Puranik * @return Returns as a string, the boot mode in Redfish terms. If translation 808491d8ee7SSantosh Puranik * cannot be done, returns an empty string. 809491d8ee7SSantosh Puranik */ 810491d8ee7SSantosh Puranik static std::string dbusToRfBootMode(const std::string &dbusMode) 811491d8ee7SSantosh Puranik { 812491d8ee7SSantosh Puranik if (dbusMode == "xyz.openbmc_project.Control.Boot.Mode.Modes.Regular") 813491d8ee7SSantosh Puranik { 814491d8ee7SSantosh Puranik return "None"; 815491d8ee7SSantosh Puranik } 816491d8ee7SSantosh Puranik else if (dbusMode == "xyz.openbmc_project.Control.Boot.Mode.Modes.Safe") 817491d8ee7SSantosh Puranik { 818491d8ee7SSantosh Puranik return "Diags"; 819491d8ee7SSantosh Puranik } 820491d8ee7SSantosh Puranik else if (dbusMode == "xyz.openbmc_project.Control.Boot.Mode.Modes.Setup") 821491d8ee7SSantosh Puranik { 822491d8ee7SSantosh Puranik return "BiosSetup"; 823491d8ee7SSantosh Puranik } 824491d8ee7SSantosh Puranik else 825491d8ee7SSantosh Puranik { 826491d8ee7SSantosh Puranik return ""; 827491d8ee7SSantosh Puranik } 828491d8ee7SSantosh Puranik } 829491d8ee7SSantosh Puranik 830491d8ee7SSantosh Puranik /** 831944ffaf9SJohnathan Mantey * @brief Traslates boot source from Redfish to the DBus boot paths. 832491d8ee7SSantosh Puranik * 833491d8ee7SSantosh Puranik * @param[in] rfSource The boot source in Redfish. 834944ffaf9SJohnathan Mantey * @param[out] bootSource The DBus source 835944ffaf9SJohnathan Mantey * @param[out] bootMode the DBus boot mode 836491d8ee7SSantosh Puranik * 837944ffaf9SJohnathan Mantey * @return Integer error code. 838491d8ee7SSantosh Puranik */ 839944ffaf9SJohnathan Mantey static int assignBootParameters(std::shared_ptr<AsyncResp> aResp, 840944ffaf9SJohnathan Mantey const std::string &rfSource, 841944ffaf9SJohnathan Mantey std::string &bootSource, std::string &bootMode) 842491d8ee7SSantosh Puranik { 843944ffaf9SJohnathan Mantey // The caller has initialized the bootSource and bootMode to: 844944ffaf9SJohnathan Mantey // bootMode = "xyz.openbmc_project.Control.Boot.Mode.Modes.Regular"; 845944ffaf9SJohnathan Mantey // bootSource = "xyz.openbmc_project.Control.Boot.Source.Sources.Default"; 846944ffaf9SJohnathan Mantey // Only modify the bootSource/bootMode variable needed to achieve the 847944ffaf9SJohnathan Mantey // desired boot action. 848944ffaf9SJohnathan Mantey 849491d8ee7SSantosh Puranik if (rfSource == "None") 850491d8ee7SSantosh Puranik { 851944ffaf9SJohnathan Mantey return 0; 852491d8ee7SSantosh Puranik } 853491d8ee7SSantosh Puranik else if (rfSource == "Pxe") 854491d8ee7SSantosh Puranik { 855944ffaf9SJohnathan Mantey bootSource = "xyz.openbmc_project.Control.Boot.Source.Sources.Network"; 856944ffaf9SJohnathan Mantey } 857944ffaf9SJohnathan Mantey else if (rfSource == "Hdd") 858944ffaf9SJohnathan Mantey { 859944ffaf9SJohnathan Mantey bootSource = "xyz.openbmc_project.Control.Boot.Source.Sources.Disk"; 860944ffaf9SJohnathan Mantey } 861944ffaf9SJohnathan Mantey else if (rfSource == "Diags") 862944ffaf9SJohnathan Mantey { 863944ffaf9SJohnathan Mantey bootMode = "xyz.openbmc_project.Control.Boot.Mode.Modes.Safe"; 864944ffaf9SJohnathan Mantey } 865944ffaf9SJohnathan Mantey else if (rfSource == "Cd") 866944ffaf9SJohnathan Mantey { 867944ffaf9SJohnathan Mantey bootSource = 868944ffaf9SJohnathan Mantey "xyz.openbmc_project.Control.Boot.Source.Sources.ExternalMedia"; 869944ffaf9SJohnathan Mantey } 870944ffaf9SJohnathan Mantey else if (rfSource == "BiosSetup") 871944ffaf9SJohnathan Mantey { 872944ffaf9SJohnathan Mantey bootMode = "xyz.openbmc_project.Control.Boot.Mode.Modes.Setup"; 873491d8ee7SSantosh Puranik } 8749f16b2c1SJennifer Lee else if (rfSource == "Usb") 8759f16b2c1SJennifer Lee { 876944ffaf9SJohnathan Mantey bootSource = 877944ffaf9SJohnathan Mantey "xyz.openbmc_project.Control.Boot.Source.Sources.RemovableMedia"; 8789f16b2c1SJennifer Lee } 879491d8ee7SSantosh Puranik else 880491d8ee7SSantosh Puranik { 881944ffaf9SJohnathan Mantey BMCWEB_LOG_DEBUG << "Invalid property value for " 882944ffaf9SJohnathan Mantey "BootSourceOverrideTarget: " 883944ffaf9SJohnathan Mantey << bootSource; 884944ffaf9SJohnathan Mantey messages::propertyValueNotInList(aResp->res, rfSource, 885944ffaf9SJohnathan Mantey "BootSourceTargetOverride"); 886944ffaf9SJohnathan Mantey return -1; 887491d8ee7SSantosh Puranik } 888944ffaf9SJohnathan Mantey return 0; 889491d8ee7SSantosh Puranik } 890491d8ee7SSantosh Puranik 891491d8ee7SSantosh Puranik /** 892491d8ee7SSantosh Puranik * @brief Retrieves boot mode over DBUS and fills out the response 893491d8ee7SSantosh Puranik * 894491d8ee7SSantosh Puranik * @param[in] aResp Shared pointer for generating response message. 895491d8ee7SSantosh Puranik * @param[in] bootDbusObj The dbus object to query for boot properties. 896491d8ee7SSantosh Puranik * 897491d8ee7SSantosh Puranik * @return None. 898491d8ee7SSantosh Puranik */ 899491d8ee7SSantosh Puranik static void getBootMode(std::shared_ptr<AsyncResp> aResp, 900491d8ee7SSantosh Puranik std::string bootDbusObj) 901491d8ee7SSantosh Puranik { 902491d8ee7SSantosh Puranik crow::connections::systemBus->async_method_call( 903491d8ee7SSantosh Puranik [aResp](const boost::system::error_code ec, 904491d8ee7SSantosh Puranik const std::variant<std::string> &bootMode) { 905491d8ee7SSantosh Puranik if (ec) 906491d8ee7SSantosh Puranik { 907491d8ee7SSantosh Puranik BMCWEB_LOG_DEBUG << "DBUS response error " << ec; 908491d8ee7SSantosh Puranik messages::internalError(aResp->res); 909491d8ee7SSantosh Puranik return; 910491d8ee7SSantosh Puranik } 911491d8ee7SSantosh Puranik 912491d8ee7SSantosh Puranik const std::string *bootModeStr = 913491d8ee7SSantosh Puranik std::get_if<std::string>(&bootMode); 914491d8ee7SSantosh Puranik 915491d8ee7SSantosh Puranik if (!bootModeStr) 916491d8ee7SSantosh Puranik { 917491d8ee7SSantosh Puranik messages::internalError(aResp->res); 918491d8ee7SSantosh Puranik return; 919491d8ee7SSantosh Puranik } 920491d8ee7SSantosh Puranik 921491d8ee7SSantosh Puranik BMCWEB_LOG_DEBUG << "Boot mode: " << *bootModeStr; 922491d8ee7SSantosh Puranik 923491d8ee7SSantosh Puranik // TODO (Santosh): Do we need to support override mode? 924491d8ee7SSantosh Puranik aResp->res.jsonValue["Boot"]["BootSourceOverrideMode"] = "Legacy"; 925491d8ee7SSantosh Puranik aResp->res.jsonValue["Boot"]["BootSourceOverrideTarget@Redfish." 926491d8ee7SSantosh Puranik "AllowableValues"] = { 927944ffaf9SJohnathan Mantey "None", "Pxe", "Hdd", "Cd", "Diags", "BiosSetup", "Usb"}; 928491d8ee7SSantosh Puranik 929491d8ee7SSantosh Puranik if (*bootModeStr != 930491d8ee7SSantosh Puranik "xyz.openbmc_project.Control.Boot.Mode.Modes.Regular") 931491d8ee7SSantosh Puranik { 932491d8ee7SSantosh Puranik auto rfMode = dbusToRfBootMode(*bootModeStr); 933491d8ee7SSantosh Puranik if (!rfMode.empty()) 934491d8ee7SSantosh Puranik { 935491d8ee7SSantosh Puranik aResp->res.jsonValue["Boot"]["BootSourceOverrideTarget"] = 936491d8ee7SSantosh Puranik rfMode; 937491d8ee7SSantosh Puranik } 938491d8ee7SSantosh Puranik } 939491d8ee7SSantosh Puranik 940491d8ee7SSantosh Puranik // If the BootSourceOverrideTarget is still "None" at the end, 941491d8ee7SSantosh Puranik // reset the BootSourceOverrideEnabled to indicate that 942491d8ee7SSantosh Puranik // overrides are disabled 943491d8ee7SSantosh Puranik if (aResp->res.jsonValue["Boot"]["BootSourceOverrideTarget"] == 944491d8ee7SSantosh Puranik "None") 945491d8ee7SSantosh Puranik { 946491d8ee7SSantosh Puranik aResp->res.jsonValue["Boot"]["BootSourceOverrideEnabled"] = 947491d8ee7SSantosh Puranik "Disabled"; 948491d8ee7SSantosh Puranik } 949491d8ee7SSantosh Puranik }, 950491d8ee7SSantosh Puranik "xyz.openbmc_project.Settings", bootDbusObj, 951491d8ee7SSantosh Puranik "org.freedesktop.DBus.Properties", "Get", 952491d8ee7SSantosh Puranik "xyz.openbmc_project.Control.Boot.Mode", "BootMode"); 953491d8ee7SSantosh Puranik } 954491d8ee7SSantosh Puranik 955491d8ee7SSantosh Puranik /** 956491d8ee7SSantosh Puranik * @brief Retrieves boot source over DBUS 957491d8ee7SSantosh Puranik * 958491d8ee7SSantosh Puranik * @param[in] aResp Shared pointer for generating response message. 959491d8ee7SSantosh Puranik * @param[in] oneTimeEnable Boolean to indicate boot properties are one-time. 960491d8ee7SSantosh Puranik * 961491d8ee7SSantosh Puranik * @return None. 962491d8ee7SSantosh Puranik */ 963491d8ee7SSantosh Puranik static void getBootSource(std::shared_ptr<AsyncResp> aResp, bool oneTimeEnabled) 964491d8ee7SSantosh Puranik { 965491d8ee7SSantosh Puranik std::string bootDbusObj = 966491d8ee7SSantosh Puranik oneTimeEnabled ? "/xyz/openbmc_project/control/host0/boot/one_time" 967491d8ee7SSantosh Puranik : "/xyz/openbmc_project/control/host0/boot"; 968491d8ee7SSantosh Puranik 969491d8ee7SSantosh Puranik BMCWEB_LOG_DEBUG << "Is one time: " << oneTimeEnabled; 970491d8ee7SSantosh Puranik aResp->res.jsonValue["Boot"]["BootSourceOverrideEnabled"] = 971491d8ee7SSantosh Puranik (oneTimeEnabled) ? "Once" : "Continuous"; 972491d8ee7SSantosh Puranik 973491d8ee7SSantosh Puranik crow::connections::systemBus->async_method_call( 974491d8ee7SSantosh Puranik [aResp, bootDbusObj](const boost::system::error_code ec, 975491d8ee7SSantosh Puranik const std::variant<std::string> &bootSource) { 976491d8ee7SSantosh Puranik if (ec) 977491d8ee7SSantosh Puranik { 978491d8ee7SSantosh Puranik BMCWEB_LOG_DEBUG << "DBUS response error " << ec; 979491d8ee7SSantosh Puranik messages::internalError(aResp->res); 980491d8ee7SSantosh Puranik return; 981491d8ee7SSantosh Puranik } 982491d8ee7SSantosh Puranik 983491d8ee7SSantosh Puranik const std::string *bootSourceStr = 984491d8ee7SSantosh Puranik std::get_if<std::string>(&bootSource); 985491d8ee7SSantosh Puranik 986491d8ee7SSantosh Puranik if (!bootSourceStr) 987491d8ee7SSantosh Puranik { 988491d8ee7SSantosh Puranik messages::internalError(aResp->res); 989491d8ee7SSantosh Puranik return; 990491d8ee7SSantosh Puranik } 991491d8ee7SSantosh Puranik BMCWEB_LOG_DEBUG << "Boot source: " << *bootSourceStr; 992491d8ee7SSantosh Puranik 993491d8ee7SSantosh Puranik auto rfSource = dbusToRfBootSource(*bootSourceStr); 994491d8ee7SSantosh Puranik if (!rfSource.empty()) 995491d8ee7SSantosh Puranik { 996491d8ee7SSantosh Puranik aResp->res.jsonValue["Boot"]["BootSourceOverrideTarget"] = 997491d8ee7SSantosh Puranik rfSource; 998491d8ee7SSantosh Puranik } 999491d8ee7SSantosh Puranik }, 1000491d8ee7SSantosh Puranik "xyz.openbmc_project.Settings", bootDbusObj, 1001491d8ee7SSantosh Puranik "org.freedesktop.DBus.Properties", "Get", 1002491d8ee7SSantosh Puranik "xyz.openbmc_project.Control.Boot.Source", "BootSource"); 1003491d8ee7SSantosh Puranik getBootMode(std::move(aResp), std::move(bootDbusObj)); 1004491d8ee7SSantosh Puranik } 1005491d8ee7SSantosh Puranik 1006491d8ee7SSantosh Puranik /** 1007491d8ee7SSantosh Puranik * @brief Retrieves "One time" enabled setting over DBUS and calls function to 1008491d8ee7SSantosh Puranik * get boot source and boot mode. 1009491d8ee7SSantosh Puranik * 1010491d8ee7SSantosh Puranik * @param[in] aResp Shared pointer for generating response message. 1011491d8ee7SSantosh Puranik * 1012491d8ee7SSantosh Puranik * @return None. 1013491d8ee7SSantosh Puranik */ 1014491d8ee7SSantosh Puranik static void getBootProperties(std::shared_ptr<AsyncResp> aResp) 1015491d8ee7SSantosh Puranik { 1016491d8ee7SSantosh Puranik BMCWEB_LOG_DEBUG << "Get boot information."; 1017491d8ee7SSantosh Puranik 1018491d8ee7SSantosh Puranik crow::connections::systemBus->async_method_call( 1019c5d03ff4SJennifer Lee [aResp](const boost::system::error_code ec, 1020491d8ee7SSantosh Puranik const sdbusplus::message::variant<bool> &oneTime) { 1021491d8ee7SSantosh Puranik if (ec) 1022491d8ee7SSantosh Puranik { 1023491d8ee7SSantosh Puranik BMCWEB_LOG_DEBUG << "DBUS response error " << ec; 10242a833c77SJames Feist // not an error, don't have to have the interface 1025491d8ee7SSantosh Puranik return; 1026491d8ee7SSantosh Puranik } 1027491d8ee7SSantosh Puranik 1028491d8ee7SSantosh Puranik const bool *oneTimePtr = std::get_if<bool>(&oneTime); 1029491d8ee7SSantosh Puranik 1030491d8ee7SSantosh Puranik if (!oneTimePtr) 1031491d8ee7SSantosh Puranik { 1032491d8ee7SSantosh Puranik messages::internalError(aResp->res); 1033491d8ee7SSantosh Puranik return; 1034491d8ee7SSantosh Puranik } 1035491d8ee7SSantosh Puranik getBootSource(aResp, *oneTimePtr); 1036491d8ee7SSantosh Puranik }, 1037491d8ee7SSantosh Puranik "xyz.openbmc_project.Settings", 1038491d8ee7SSantosh Puranik "/xyz/openbmc_project/control/host0/boot/one_time", 1039491d8ee7SSantosh Puranik "org.freedesktop.DBus.Properties", "Get", 1040491d8ee7SSantosh Puranik "xyz.openbmc_project.Object.Enable", "Enabled"); 1041491d8ee7SSantosh Puranik } 1042491d8ee7SSantosh Puranik 1043491d8ee7SSantosh Puranik /** 1044491d8ee7SSantosh Puranik * @brief Sets boot properties into DBUS object(s). 1045491d8ee7SSantosh Puranik * 1046491d8ee7SSantosh Puranik * @param[in] aResp Shared pointer for generating response message. 1047491d8ee7SSantosh Puranik * @param[in] oneTimeEnabled Is "one-time" setting already enabled. 1048491d8ee7SSantosh Puranik * @param[in] bootSource The boot source to set. 1049491d8ee7SSantosh Puranik * @param[in] bootEnable The source override "enable" to set. 1050491d8ee7SSantosh Puranik * 1051265c1602SJohnathan Mantey * @return Integer error code. 1052491d8ee7SSantosh Puranik */ 1053491d8ee7SSantosh Puranik static void setBootModeOrSource(std::shared_ptr<AsyncResp> aResp, 1054491d8ee7SSantosh Puranik bool oneTimeEnabled, 1055491d8ee7SSantosh Puranik std::optional<std::string> bootSource, 1056491d8ee7SSantosh Puranik std::optional<std::string> bootEnable) 1057491d8ee7SSantosh Puranik { 1058944ffaf9SJohnathan Mantey std::string bootSourceStr = 1059944ffaf9SJohnathan Mantey "xyz.openbmc_project.Control.Boot.Source.Sources.Default"; 1060944ffaf9SJohnathan Mantey std::string bootModeStr = 1061944ffaf9SJohnathan Mantey "xyz.openbmc_project.Control.Boot.Mode.Modes.Regular"; 1062491d8ee7SSantosh Puranik bool oneTimeSetting = oneTimeEnabled; 1063944ffaf9SJohnathan Mantey bool useBootSource = true; 1064944ffaf9SJohnathan Mantey 1065491d8ee7SSantosh Puranik // Validate incoming parameters 1066491d8ee7SSantosh Puranik if (bootEnable) 1067491d8ee7SSantosh Puranik { 1068491d8ee7SSantosh Puranik if (*bootEnable == "Once") 1069491d8ee7SSantosh Puranik { 1070491d8ee7SSantosh Puranik oneTimeSetting = true; 1071491d8ee7SSantosh Puranik } 1072491d8ee7SSantosh Puranik else if (*bootEnable == "Continuous") 1073491d8ee7SSantosh Puranik { 1074491d8ee7SSantosh Puranik oneTimeSetting = false; 1075491d8ee7SSantosh Puranik } 1076491d8ee7SSantosh Puranik else if (*bootEnable == "Disabled") 1077491d8ee7SSantosh Puranik { 1078944ffaf9SJohnathan Mantey BMCWEB_LOG_DEBUG << "Boot source override will be disabled"; 1079491d8ee7SSantosh Puranik oneTimeSetting = false; 1080944ffaf9SJohnathan Mantey useBootSource = false; 1081491d8ee7SSantosh Puranik } 1082491d8ee7SSantosh Puranik else 1083491d8ee7SSantosh Puranik { 1084491d8ee7SSantosh Puranik BMCWEB_LOG_DEBUG << "Unsupported value for " 1085491d8ee7SSantosh Puranik "BootSourceOverrideEnabled: " 1086491d8ee7SSantosh Puranik << *bootEnable; 1087491d8ee7SSantosh Puranik messages::propertyValueNotInList(aResp->res, *bootEnable, 1088491d8ee7SSantosh Puranik "BootSourceOverrideEnabled"); 1089491d8ee7SSantosh Puranik return; 1090491d8ee7SSantosh Puranik } 1091491d8ee7SSantosh Puranik } 1092491d8ee7SSantosh Puranik 1093944ffaf9SJohnathan Mantey if (bootSource && useBootSource) 1094491d8ee7SSantosh Puranik { 1095491d8ee7SSantosh Puranik // Source target specified 1096491d8ee7SSantosh Puranik BMCWEB_LOG_DEBUG << "Boot source: " << *bootSource; 1097491d8ee7SSantosh Puranik // Figure out which DBUS interface and property to use 1098944ffaf9SJohnathan Mantey if (assignBootParameters(aResp, *bootSource, bootSourceStr, 1099944ffaf9SJohnathan Mantey bootModeStr)) 1100491d8ee7SSantosh Puranik { 1101944ffaf9SJohnathan Mantey BMCWEB_LOG_DEBUG 1102944ffaf9SJohnathan Mantey << "Invalid property value for BootSourceOverrideTarget: " 1103491d8ee7SSantosh Puranik << *bootSource; 1104491d8ee7SSantosh Puranik messages::propertyValueNotInList(aResp->res, *bootSource, 1105491d8ee7SSantosh Puranik "BootSourceTargetOverride"); 1106491d8ee7SSantosh Puranik return; 1107491d8ee7SSantosh Puranik } 1108944ffaf9SJohnathan Mantey } 1109491d8ee7SSantosh Puranik 1110944ffaf9SJohnathan Mantey // Act on validated parameters 1111944ffaf9SJohnathan Mantey BMCWEB_LOG_DEBUG << "DBUS boot source: " << bootSourceStr; 1112944ffaf9SJohnathan Mantey BMCWEB_LOG_DEBUG << "DBUS boot mode: " << bootModeStr; 1113944ffaf9SJohnathan Mantey const char *bootObj = 1114944ffaf9SJohnathan Mantey oneTimeSetting ? "/xyz/openbmc_project/control/host0/boot/one_time" 1115944ffaf9SJohnathan Mantey : "/xyz/openbmc_project/control/host0/boot"; 1116944ffaf9SJohnathan Mantey 1117491d8ee7SSantosh Puranik crow::connections::systemBus->async_method_call( 1118491d8ee7SSantosh Puranik [aResp](const boost::system::error_code ec) { 1119491d8ee7SSantosh Puranik if (ec) 1120491d8ee7SSantosh Puranik { 1121491d8ee7SSantosh Puranik BMCWEB_LOG_DEBUG << "DBUS response error " << ec; 1122491d8ee7SSantosh Puranik messages::internalError(aResp->res); 1123491d8ee7SSantosh Puranik return; 1124491d8ee7SSantosh Puranik } 1125491d8ee7SSantosh Puranik BMCWEB_LOG_DEBUG << "Boot source update done."; 1126491d8ee7SSantosh Puranik }, 1127491d8ee7SSantosh Puranik "xyz.openbmc_project.Settings", bootObj, 1128491d8ee7SSantosh Puranik "org.freedesktop.DBus.Properties", "Set", 1129491d8ee7SSantosh Puranik "xyz.openbmc_project.Control.Boot.Source", "BootSource", 1130491d8ee7SSantosh Puranik std::variant<std::string>(bootSourceStr)); 1131944ffaf9SJohnathan Mantey 1132491d8ee7SSantosh Puranik crow::connections::systemBus->async_method_call( 1133491d8ee7SSantosh Puranik [aResp](const boost::system::error_code ec) { 1134491d8ee7SSantosh Puranik if (ec) 1135491d8ee7SSantosh Puranik { 1136491d8ee7SSantosh Puranik BMCWEB_LOG_DEBUG << "DBUS response error " << ec; 1137491d8ee7SSantosh Puranik messages::internalError(aResp->res); 1138491d8ee7SSantosh Puranik return; 1139491d8ee7SSantosh Puranik } 1140491d8ee7SSantosh Puranik BMCWEB_LOG_DEBUG << "Boot mode update done."; 1141491d8ee7SSantosh Puranik }, 1142491d8ee7SSantosh Puranik "xyz.openbmc_project.Settings", bootObj, 1143491d8ee7SSantosh Puranik "org.freedesktop.DBus.Properties", "Set", 1144491d8ee7SSantosh Puranik "xyz.openbmc_project.Control.Boot.Mode", "BootMode", 1145491d8ee7SSantosh Puranik std::variant<std::string>(bootModeStr)); 1146944ffaf9SJohnathan Mantey 1147491d8ee7SSantosh Puranik crow::connections::systemBus->async_method_call( 1148491d8ee7SSantosh Puranik [aResp{std::move(aResp)}](const boost::system::error_code ec) { 1149491d8ee7SSantosh Puranik if (ec) 1150491d8ee7SSantosh Puranik { 1151491d8ee7SSantosh Puranik BMCWEB_LOG_DEBUG << "DBUS response error " << ec; 1152491d8ee7SSantosh Puranik messages::internalError(aResp->res); 1153491d8ee7SSantosh Puranik return; 1154491d8ee7SSantosh Puranik } 1155491d8ee7SSantosh Puranik BMCWEB_LOG_DEBUG << "Boot enable update done."; 1156491d8ee7SSantosh Puranik }, 1157491d8ee7SSantosh Puranik "xyz.openbmc_project.Settings", 1158491d8ee7SSantosh Puranik "/xyz/openbmc_project/control/host0/boot/one_time", 1159491d8ee7SSantosh Puranik "org.freedesktop.DBus.Properties", "Set", 1160491d8ee7SSantosh Puranik "xyz.openbmc_project.Object.Enable", "Enabled", 1161491d8ee7SSantosh Puranik std::variant<bool>(oneTimeSetting)); 1162491d8ee7SSantosh Puranik } 1163491d8ee7SSantosh Puranik 1164491d8ee7SSantosh Puranik /** 1165491d8ee7SSantosh Puranik * @brief Retrieves "One time" enabled setting over DBUS and calls function to 1166491d8ee7SSantosh Puranik * set boot source/boot mode properties. 1167491d8ee7SSantosh Puranik * 1168491d8ee7SSantosh Puranik * @param[in] aResp Shared pointer for generating response message. 1169491d8ee7SSantosh Puranik * @param[in] bootSource The boot source from incoming RF request. 1170491d8ee7SSantosh Puranik * @param[in] bootEnable The boot override enable from incoming RF request. 1171491d8ee7SSantosh Puranik * 1172265c1602SJohnathan Mantey * @return Integer error code. 1173491d8ee7SSantosh Puranik */ 1174491d8ee7SSantosh Puranik static void setBootProperties(std::shared_ptr<AsyncResp> aResp, 1175491d8ee7SSantosh Puranik std::optional<std::string> bootSource, 1176491d8ee7SSantosh Puranik std::optional<std::string> bootEnable) 1177491d8ee7SSantosh Puranik { 1178491d8ee7SSantosh Puranik BMCWEB_LOG_DEBUG << "Set boot information."; 1179491d8ee7SSantosh Puranik 1180491d8ee7SSantosh Puranik crow::connections::systemBus->async_method_call( 1181265c1602SJohnathan Mantey [aResp, bootSource{std::move(bootSource)}, 1182491d8ee7SSantosh Puranik bootEnable{std::move(bootEnable)}]( 1183491d8ee7SSantosh Puranik const boost::system::error_code ec, 1184491d8ee7SSantosh Puranik const sdbusplus::message::variant<bool> &oneTime) { 1185491d8ee7SSantosh Puranik if (ec) 1186491d8ee7SSantosh Puranik { 1187491d8ee7SSantosh Puranik BMCWEB_LOG_DEBUG << "DBUS response error " << ec; 1188491d8ee7SSantosh Puranik messages::internalError(aResp->res); 1189491d8ee7SSantosh Puranik return; 1190491d8ee7SSantosh Puranik } 1191491d8ee7SSantosh Puranik 1192491d8ee7SSantosh Puranik const bool *oneTimePtr = std::get_if<bool>(&oneTime); 1193491d8ee7SSantosh Puranik 1194491d8ee7SSantosh Puranik if (!oneTimePtr) 1195491d8ee7SSantosh Puranik { 1196491d8ee7SSantosh Puranik messages::internalError(aResp->res); 1197491d8ee7SSantosh Puranik return; 1198491d8ee7SSantosh Puranik } 1199491d8ee7SSantosh Puranik 1200491d8ee7SSantosh Puranik BMCWEB_LOG_DEBUG << "Got one time: " << *oneTimePtr; 1201491d8ee7SSantosh Puranik 1202491d8ee7SSantosh Puranik setBootModeOrSource(aResp, *oneTimePtr, std::move(bootSource), 1203491d8ee7SSantosh Puranik std::move(bootEnable)); 1204491d8ee7SSantosh Puranik }, 1205491d8ee7SSantosh Puranik "xyz.openbmc_project.Settings", 1206491d8ee7SSantosh Puranik "/xyz/openbmc_project/control/host0/boot/one_time", 1207491d8ee7SSantosh Puranik "org.freedesktop.DBus.Properties", "Get", 1208491d8ee7SSantosh Puranik "xyz.openbmc_project.Object.Enable", "Enabled"); 1209491d8ee7SSantosh Puranik } 1210491d8ee7SSantosh Puranik 1211a6349918SAppaRao Puli #ifdef BMCWEB_ENABLE_REDFISH_PROVISIONING_FEATURE 1212a6349918SAppaRao Puli /** 1213a6349918SAppaRao Puli * @brief Retrieves provisioning status 1214a6349918SAppaRao Puli * 1215a6349918SAppaRao Puli * @param[in] aResp Shared pointer for completing asynchronous calls. 1216a6349918SAppaRao Puli * 1217a6349918SAppaRao Puli * @return None. 1218a6349918SAppaRao Puli */ 1219a6349918SAppaRao Puli void getProvisioningStatus(std::shared_ptr<AsyncResp> aResp) 1220a6349918SAppaRao Puli { 1221a6349918SAppaRao Puli BMCWEB_LOG_DEBUG << "Get OEM information."; 1222a6349918SAppaRao Puli crow::connections::systemBus->async_method_call( 1223a6349918SAppaRao Puli [aResp](const boost::system::error_code ec, 1224a6349918SAppaRao Puli const std::vector<std::pair<std::string, VariantType>> 1225a6349918SAppaRao Puli &propertiesList) { 1226a6349918SAppaRao Puli if (ec) 1227a6349918SAppaRao Puli { 1228a6349918SAppaRao Puli BMCWEB_LOG_DEBUG << "DBUS response error " << ec; 1229a6349918SAppaRao Puli messages::internalError(aResp->res); 1230a6349918SAppaRao Puli return; 1231a6349918SAppaRao Puli } 1232a6349918SAppaRao Puli 1233a6349918SAppaRao Puli const bool *provState = nullptr; 1234a6349918SAppaRao Puli const bool *lockState = nullptr; 1235a6349918SAppaRao Puli for (const std::pair<std::string, VariantType> &property : 1236a6349918SAppaRao Puli propertiesList) 1237a6349918SAppaRao Puli { 1238a6349918SAppaRao Puli if (property.first == "UfmProvisioned") 1239a6349918SAppaRao Puli { 1240a6349918SAppaRao Puli provState = std::get_if<bool>(&property.second); 1241a6349918SAppaRao Puli } 1242a6349918SAppaRao Puli else if (property.first == "UfmLocked") 1243a6349918SAppaRao Puli { 1244a6349918SAppaRao Puli lockState = std::get_if<bool>(&property.second); 1245a6349918SAppaRao Puli } 1246a6349918SAppaRao Puli } 1247a6349918SAppaRao Puli 1248a6349918SAppaRao Puli if ((provState == nullptr) || (lockState == nullptr)) 1249a6349918SAppaRao Puli { 1250a6349918SAppaRao Puli BMCWEB_LOG_DEBUG << "Unable to get PFR attributes."; 1251a6349918SAppaRao Puli messages::internalError(aResp->res); 1252a6349918SAppaRao Puli return; 1253a6349918SAppaRao Puli } 1254a6349918SAppaRao Puli 1255a6349918SAppaRao Puli nlohmann::json &oemPFR = 1256a6349918SAppaRao Puli aResp->res.jsonValue["Oem"]["OpenBmc"]["FirmwareProvisioning"]; 1257a6349918SAppaRao Puli if (*provState == true) 1258a6349918SAppaRao Puli { 1259a6349918SAppaRao Puli if (*lockState == true) 1260a6349918SAppaRao Puli { 1261a6349918SAppaRao Puli oemPFR["ProvisioningStatus"] = "ProvisionedAndLocked"; 1262a6349918SAppaRao Puli } 1263a6349918SAppaRao Puli else 1264a6349918SAppaRao Puli { 1265a6349918SAppaRao Puli oemPFR["ProvisioningStatus"] = "ProvisionedButNotLocked"; 1266a6349918SAppaRao Puli } 1267a6349918SAppaRao Puli } 1268a6349918SAppaRao Puli else 1269a6349918SAppaRao Puli { 1270a6349918SAppaRao Puli oemPFR["ProvisioningStatus"] = "NotProvisioned"; 1271a6349918SAppaRao Puli } 1272a6349918SAppaRao Puli }, 1273a6349918SAppaRao Puli "xyz.openbmc_project.PFR.Manager", "/xyz/openbmc_project/pfr", 1274a6349918SAppaRao Puli "org.freedesktop.DBus.Properties", "GetAll", 1275a6349918SAppaRao Puli "xyz.openbmc_project.PFR.Attributes"); 1276a6349918SAppaRao Puli } 1277a6349918SAppaRao Puli #endif 1278a6349918SAppaRao Puli 1279491d8ee7SSantosh Puranik /** 128051709ffdSYong Li * @brief Translates watchdog timeout action DBUS property value to redfish. 128151709ffdSYong Li * 128251709ffdSYong Li * @param[in] dbusAction The watchdog timeout action in D-BUS. 128351709ffdSYong Li * 128451709ffdSYong Li * @return Returns as a string, the timeout action in Redfish terms. If 128551709ffdSYong Li * translation cannot be done, returns an empty string. 128651709ffdSYong Li */ 128751709ffdSYong Li static std::string dbusToRfWatchdogAction(const std::string &dbusAction) 128851709ffdSYong Li { 128951709ffdSYong Li if (dbusAction == "xyz.openbmc_project.State.Watchdog.Action.None") 129051709ffdSYong Li { 129151709ffdSYong Li return "None"; 129251709ffdSYong Li } 129351709ffdSYong Li else if (dbusAction == 129451709ffdSYong Li "xyz.openbmc_project.State.Watchdog.Action.HardReset") 129551709ffdSYong Li { 129651709ffdSYong Li return "ResetSystem"; 129751709ffdSYong Li } 129851709ffdSYong Li else if (dbusAction == "xyz.openbmc_project.State.Watchdog.Action.PowerOff") 129951709ffdSYong Li { 130051709ffdSYong Li return "PowerDown"; 130151709ffdSYong Li } 130251709ffdSYong Li else if (dbusAction == 130351709ffdSYong Li "xyz.openbmc_project.State.Watchdog.Action.PowerCycle") 130451709ffdSYong Li { 130551709ffdSYong Li return "PowerCycle"; 130651709ffdSYong Li } 130751709ffdSYong Li 130851709ffdSYong Li return ""; 130951709ffdSYong Li } 131051709ffdSYong Li 131151709ffdSYong Li /** 1312c45f0082SYong Li *@brief Translates timeout action from Redfish to DBUS property value. 1313c45f0082SYong Li * 1314c45f0082SYong Li *@param[in] rfAction The timeout action in Redfish. 1315c45f0082SYong Li * 1316c45f0082SYong Li *@return Returns as a string, the time_out action as expected by DBUS. 1317c45f0082SYong Li *If translation cannot be done, returns an empty string. 1318c45f0082SYong Li */ 1319c45f0082SYong Li 1320c45f0082SYong Li static std::string rfToDbusWDTTimeOutAct(const std::string &rfAction) 1321c45f0082SYong Li { 1322c45f0082SYong Li if (rfAction == "None") 1323c45f0082SYong Li { 1324c45f0082SYong Li return "xyz.openbmc_project.State.Watchdog.Action.None"; 1325c45f0082SYong Li } 1326c45f0082SYong Li else if (rfAction == "PowerCycle") 1327c45f0082SYong Li { 1328c45f0082SYong Li return "xyz.openbmc_project.State.Watchdog.Action.PowerCycle"; 1329c45f0082SYong Li } 1330c45f0082SYong Li else if (rfAction == "PowerDown") 1331c45f0082SYong Li { 1332c45f0082SYong Li return "xyz.openbmc_project.State.Watchdog.Action.PowerOff"; 1333c45f0082SYong Li } 1334c45f0082SYong Li else if (rfAction == "ResetSystem") 1335c45f0082SYong Li { 1336c45f0082SYong Li return "xyz.openbmc_project.State.Watchdog.Action.HardReset"; 1337c45f0082SYong Li } 1338c45f0082SYong Li 1339c45f0082SYong Li return ""; 1340c45f0082SYong Li } 1341c45f0082SYong Li 1342c45f0082SYong Li /** 134351709ffdSYong Li * @brief Retrieves host watchdog timer properties over DBUS 134451709ffdSYong Li * 134551709ffdSYong Li * @param[in] aResp Shared pointer for completing asynchronous calls. 134651709ffdSYong Li * 134751709ffdSYong Li * @return None. 134851709ffdSYong Li */ 134951709ffdSYong Li void getHostWatchdogTimer(std::shared_ptr<AsyncResp> aResp) 135051709ffdSYong Li { 135151709ffdSYong Li BMCWEB_LOG_DEBUG << "Get host watchodg"; 135251709ffdSYong Li crow::connections::systemBus->async_method_call( 135351709ffdSYong Li [aResp](const boost::system::error_code ec, 135451709ffdSYong Li PropertiesType &properties) { 135551709ffdSYong Li if (ec) 135651709ffdSYong Li { 135751709ffdSYong Li // watchdog service is stopped 135851709ffdSYong Li BMCWEB_LOG_DEBUG << "DBUS response error " << ec; 135951709ffdSYong Li return; 136051709ffdSYong Li } 136151709ffdSYong Li 136251709ffdSYong Li BMCWEB_LOG_DEBUG << "Got " << properties.size() << " wdt prop."; 136351709ffdSYong Li 136451709ffdSYong Li nlohmann::json &hostWatchdogTimer = 136551709ffdSYong Li aResp->res.jsonValue["HostWatchdogTimer"]; 136651709ffdSYong Li 136751709ffdSYong Li // watchdog service is running/enabled 136851709ffdSYong Li hostWatchdogTimer["Status"]["State"] = "Enabled"; 136951709ffdSYong Li 137051709ffdSYong Li for (const auto &property : properties) 137151709ffdSYong Li { 137251709ffdSYong Li BMCWEB_LOG_DEBUG << "prop=" << property.first; 137351709ffdSYong Li if (property.first == "Enabled") 137451709ffdSYong Li { 137551709ffdSYong Li const bool *state = std::get_if<bool>(&property.second); 137651709ffdSYong Li 137751709ffdSYong Li if (!state) 137851709ffdSYong Li { 137951709ffdSYong Li messages::internalError(aResp->res); 138051709ffdSYong Li continue; 138151709ffdSYong Li } 138251709ffdSYong Li 138351709ffdSYong Li hostWatchdogTimer["FunctionEnabled"] = *state; 138451709ffdSYong Li } 138551709ffdSYong Li else if (property.first == "ExpireAction") 138651709ffdSYong Li { 138751709ffdSYong Li const std::string *s = 138851709ffdSYong Li std::get_if<std::string>(&property.second); 138951709ffdSYong Li if (!s) 139051709ffdSYong Li { 139151709ffdSYong Li messages::internalError(aResp->res); 139251709ffdSYong Li continue; 139351709ffdSYong Li } 139451709ffdSYong Li 139551709ffdSYong Li std::string action = dbusToRfWatchdogAction(*s); 139651709ffdSYong Li if (action.empty()) 139751709ffdSYong Li { 139851709ffdSYong Li messages::internalError(aResp->res); 139951709ffdSYong Li continue; 140051709ffdSYong Li } 140151709ffdSYong Li hostWatchdogTimer["TimeoutAction"] = action; 140251709ffdSYong Li } 140351709ffdSYong Li } 140451709ffdSYong Li }, 140551709ffdSYong Li "xyz.openbmc_project.Watchdog", "/xyz/openbmc_project/watchdog/host0", 140651709ffdSYong Li "org.freedesktop.DBus.Properties", "GetAll", 140751709ffdSYong Li "xyz.openbmc_project.State.Watchdog"); 140851709ffdSYong Li } 140951709ffdSYong Li 141051709ffdSYong Li /** 1411c45f0082SYong Li * @brief Sets Host WatchDog Timer properties. 1412c45f0082SYong Li * 1413c45f0082SYong Li * @param[in] aResp Shared pointer for generating response message. 1414c45f0082SYong Li * @param[in] wdtEnable The WDTimer Enable value (true/false) from incoming 1415c45f0082SYong Li * RF request. 1416c45f0082SYong Li * @param[in] wdtTimeOutAction The WDT Timeout action, from incoming RF request. 1417c45f0082SYong Li * 1418c45f0082SYong Li * @return None. 1419c45f0082SYong Li */ 1420c45f0082SYong Li static void setWDTProperties(std::shared_ptr<AsyncResp> aResp, 1421c45f0082SYong Li const std::optional<bool> wdtEnable, 1422c45f0082SYong Li const std::optional<std::string> &wdtTimeOutAction) 1423c45f0082SYong Li { 1424c45f0082SYong Li BMCWEB_LOG_DEBUG << "Set host watchdog"; 1425c45f0082SYong Li 1426c45f0082SYong Li if (wdtTimeOutAction) 1427c45f0082SYong Li { 1428c45f0082SYong Li std::string wdtTimeOutActStr = rfToDbusWDTTimeOutAct(*wdtTimeOutAction); 1429c45f0082SYong Li // check if TimeOut Action is Valid 1430c45f0082SYong Li if (wdtTimeOutActStr.empty()) 1431c45f0082SYong Li { 1432c45f0082SYong Li BMCWEB_LOG_DEBUG << "Unsupported value for TimeoutAction: " 1433c45f0082SYong Li << *wdtTimeOutAction; 1434c45f0082SYong Li messages::propertyValueNotInList(aResp->res, *wdtTimeOutAction, 1435c45f0082SYong Li "TimeoutAction"); 1436c45f0082SYong Li return; 1437c45f0082SYong Li } 1438c45f0082SYong Li 1439c45f0082SYong Li crow::connections::systemBus->async_method_call( 1440c45f0082SYong Li [aResp](const boost::system::error_code ec) { 1441c45f0082SYong Li if (ec) 1442c45f0082SYong Li { 1443c45f0082SYong Li BMCWEB_LOG_DEBUG << "DBUS response error " << ec; 1444c45f0082SYong Li messages::internalError(aResp->res); 1445c45f0082SYong Li return; 1446c45f0082SYong Li } 1447c45f0082SYong Li }, 1448c45f0082SYong Li "xyz.openbmc_project.Watchdog", 1449c45f0082SYong Li "/xyz/openbmc_project/watchdog/host0", 1450c45f0082SYong Li "org.freedesktop.DBus.Properties", "Set", 1451c45f0082SYong Li "xyz.openbmc_project.State.Watchdog", "ExpireAction", 1452c45f0082SYong Li std::variant<std::string>(wdtTimeOutActStr)); 1453c45f0082SYong Li } 1454c45f0082SYong Li 1455c45f0082SYong Li if (wdtEnable) 1456c45f0082SYong Li { 1457c45f0082SYong Li crow::connections::systemBus->async_method_call( 1458c45f0082SYong Li [aResp](const boost::system::error_code ec) { 1459c45f0082SYong Li if (ec) 1460c45f0082SYong Li { 1461c45f0082SYong Li BMCWEB_LOG_DEBUG << "DBUS response error " << ec; 1462c45f0082SYong Li messages::internalError(aResp->res); 1463c45f0082SYong Li return; 1464c45f0082SYong Li } 1465c45f0082SYong Li }, 1466c45f0082SYong Li "xyz.openbmc_project.Watchdog", 1467c45f0082SYong Li "/xyz/openbmc_project/watchdog/host0", 1468c45f0082SYong Li "org.freedesktop.DBus.Properties", "Set", 1469c45f0082SYong Li "xyz.openbmc_project.State.Watchdog", "Enabled", 1470c45f0082SYong Li std::variant<bool>(*wdtEnable)); 1471c45f0082SYong Li } 1472c45f0082SYong Li } 1473c45f0082SYong Li 1474c45f0082SYong Li /** 1475c5b2abe0SLewanczyk, Dawid * SystemsCollection derived class for delivering ComputerSystems Collection 1476c5b2abe0SLewanczyk, Dawid * Schema 1477c5b2abe0SLewanczyk, Dawid */ 14781abe55efSEd Tanous class SystemsCollection : public Node 14791abe55efSEd Tanous { 1480c5b2abe0SLewanczyk, Dawid public: 14811abe55efSEd Tanous SystemsCollection(CrowApp &app) : Node(app, "/redfish/v1/Systems/") 14821abe55efSEd Tanous { 1483c5b2abe0SLewanczyk, Dawid entityPrivileges = { 1484c5b2abe0SLewanczyk, Dawid {boost::beast::http::verb::get, {{"Login"}}}, 1485c5b2abe0SLewanczyk, Dawid {boost::beast::http::verb::head, {{"Login"}}}, 1486c5b2abe0SLewanczyk, Dawid {boost::beast::http::verb::patch, {{"ConfigureComponents"}}}, 1487c5b2abe0SLewanczyk, Dawid {boost::beast::http::verb::put, {{"ConfigureComponents"}}}, 1488c5b2abe0SLewanczyk, Dawid {boost::beast::http::verb::delete_, {{"ConfigureComponents"}}}, 1489c5b2abe0SLewanczyk, Dawid {boost::beast::http::verb::post, {{"ConfigureComponents"}}}}; 1490c5b2abe0SLewanczyk, Dawid } 1491c5b2abe0SLewanczyk, Dawid 1492c5b2abe0SLewanczyk, Dawid private: 149355c7b7a2SEd Tanous void doGet(crow::Response &res, const crow::Request &req, 14941abe55efSEd Tanous const std::vector<std::string> ¶ms) override 14951abe55efSEd Tanous { 14960f74e643SEd Tanous res.jsonValue["@odata.type"] = 14970f74e643SEd Tanous "#ComputerSystemCollection.ComputerSystemCollection"; 14980f74e643SEd Tanous res.jsonValue["@odata.id"] = "/redfish/v1/Systems"; 14990f74e643SEd Tanous res.jsonValue["@odata.context"] = 15000f74e643SEd Tanous "/redfish/v1/" 15010f74e643SEd Tanous "$metadata#ComputerSystemCollection.ComputerSystemCollection"; 15020f74e643SEd Tanous res.jsonValue["Name"] = "Computer System Collection"; 1503029573d4SEd Tanous res.jsonValue["Members"] = { 1504029573d4SEd Tanous {{"@odata.id", "/redfish/v1/Systems/system"}}}; 1505029573d4SEd Tanous res.jsonValue["Members@odata.count"] = 1; 1506029573d4SEd Tanous res.end(); 1507c5b2abe0SLewanczyk, Dawid } 1508c5b2abe0SLewanczyk, Dawid }; 1509c5b2abe0SLewanczyk, Dawid 1510c5b2abe0SLewanczyk, Dawid /** 1511cc340dd9SEd Tanous * SystemActionsReset class supports handle POST method for Reset action. 1512cc340dd9SEd Tanous * The class retrieves and sends data directly to D-Bus. 1513cc340dd9SEd Tanous */ 1514cc340dd9SEd Tanous class SystemActionsReset : public Node 1515cc340dd9SEd Tanous { 1516cc340dd9SEd Tanous public: 1517cc340dd9SEd Tanous SystemActionsReset(CrowApp &app) : 1518029573d4SEd Tanous Node(app, "/redfish/v1/Systems/system/Actions/ComputerSystem.Reset/") 1519cc340dd9SEd Tanous { 1520cc340dd9SEd Tanous entityPrivileges = { 1521cc340dd9SEd Tanous {boost::beast::http::verb::post, {{"ConfigureComponents"}}}}; 1522cc340dd9SEd Tanous } 1523cc340dd9SEd Tanous 1524cc340dd9SEd Tanous private: 1525cc340dd9SEd Tanous /** 1526cc340dd9SEd Tanous * Function handles POST method request. 1527cc340dd9SEd Tanous * Analyzes POST body message before sends Reset request data to D-Bus. 1528cc340dd9SEd Tanous */ 1529cc340dd9SEd Tanous void doPost(crow::Response &res, const crow::Request &req, 1530cc340dd9SEd Tanous const std::vector<std::string> ¶ms) override 1531cc340dd9SEd Tanous { 1532cc340dd9SEd Tanous auto asyncResp = std::make_shared<AsyncResp>(res); 1533cc340dd9SEd Tanous 15349712f8acSEd Tanous std::string resetType; 15359712f8acSEd Tanous if (!json_util::readJson(req, res, "ResetType", resetType)) 1536cc340dd9SEd Tanous { 1537cc340dd9SEd Tanous return; 1538cc340dd9SEd Tanous } 1539cc340dd9SEd Tanous 1540d22c8396SJason M. Bills // Get the command and host vs. chassis 1541cc340dd9SEd Tanous std::string command; 1542d22c8396SJason M. Bills bool hostCommand; 15439712f8acSEd Tanous if (resetType == "On") 1544cc340dd9SEd Tanous { 1545cc340dd9SEd Tanous command = "xyz.openbmc_project.State.Host.Transition.On"; 1546d22c8396SJason M. Bills hostCommand = true; 1547d22c8396SJason M. Bills } 1548d22c8396SJason M. Bills else if (resetType == "ForceOff") 1549d22c8396SJason M. Bills { 1550d22c8396SJason M. Bills command = "xyz.openbmc_project.State.Chassis.Transition.Off"; 1551d22c8396SJason M. Bills hostCommand = false; 1552d22c8396SJason M. Bills } 1553d22c8396SJason M. Bills else if (resetType == "ForceOn") 1554d22c8396SJason M. Bills { 1555d22c8396SJason M. Bills command = "xyz.openbmc_project.State.Host.Transition.On"; 1556d22c8396SJason M. Bills hostCommand = true; 1557d22c8396SJason M. Bills } 1558d22c8396SJason M. Bills else if (resetType == "ForceRestart") 1559d22c8396SJason M. Bills { 1560d22c8396SJason M. Bills command = "xyz.openbmc_project.State.Chassis.Transition.Reset"; 1561d22c8396SJason M. Bills hostCommand = false; 1562cc340dd9SEd Tanous } 15639712f8acSEd Tanous else if (resetType == "GracefulShutdown") 1564cc340dd9SEd Tanous { 1565cc340dd9SEd Tanous command = "xyz.openbmc_project.State.Host.Transition.Off"; 1566d22c8396SJason M. Bills hostCommand = true; 1567cc340dd9SEd Tanous } 15689712f8acSEd Tanous else if (resetType == "GracefulRestart") 1569cc340dd9SEd Tanous { 15709712f8acSEd Tanous command = "xyz.openbmc_project.State.Host.Transition.Reboot"; 1571d22c8396SJason M. Bills hostCommand = true; 1572d22c8396SJason M. Bills } 1573d22c8396SJason M. Bills else if (resetType == "PowerCycle") 1574d22c8396SJason M. Bills { 1575d22c8396SJason M. Bills command = "xyz.openbmc_project.State.Chassis.Transition.PowerCycle"; 1576d22c8396SJason M. Bills hostCommand = false; 1577cc340dd9SEd Tanous } 1578bfd5b826SLakshminarayana R. Kammath else if (resetType == "Nmi") 1579bfd5b826SLakshminarayana R. Kammath { 1580bfd5b826SLakshminarayana R. Kammath doNMI(asyncResp); 1581bfd5b826SLakshminarayana R. Kammath return; 1582bfd5b826SLakshminarayana R. Kammath } 1583cc340dd9SEd Tanous else 1584cc340dd9SEd Tanous { 1585f12894f8SJason M. Bills messages::actionParameterUnknown(res, "Reset", resetType); 1586cc340dd9SEd Tanous return; 1587cc340dd9SEd Tanous } 1588cc340dd9SEd Tanous 1589d22c8396SJason M. Bills if (hostCommand) 1590d22c8396SJason M. Bills { 1591cc340dd9SEd Tanous crow::connections::systemBus->async_method_call( 1592d22c8396SJason M. Bills [asyncResp, resetType](const boost::system::error_code ec) { 1593cc340dd9SEd Tanous if (ec) 1594cc340dd9SEd Tanous { 1595cc340dd9SEd Tanous BMCWEB_LOG_ERROR << "D-Bus responses error: " << ec; 1596d22c8396SJason M. Bills if (ec.value() == boost::asio::error::invalid_argument) 1597d22c8396SJason M. Bills { 1598d22c8396SJason M. Bills messages::actionParameterNotSupported( 1599d22c8396SJason M. Bills asyncResp->res, resetType, "Reset"); 1600d22c8396SJason M. Bills } 1601d22c8396SJason M. Bills else 1602d22c8396SJason M. Bills { 1603f12894f8SJason M. Bills messages::internalError(asyncResp->res); 1604d22c8396SJason M. Bills } 1605cc340dd9SEd Tanous return; 1606cc340dd9SEd Tanous } 1607f12894f8SJason M. Bills messages::success(asyncResp->res); 1608cc340dd9SEd Tanous }, 1609cc340dd9SEd Tanous "xyz.openbmc_project.State.Host", 1610cc340dd9SEd Tanous "/xyz/openbmc_project/state/host0", 1611cc340dd9SEd Tanous "org.freedesktop.DBus.Properties", "Set", 16129712f8acSEd Tanous "xyz.openbmc_project.State.Host", "RequestedHostTransition", 1613abf2add6SEd Tanous std::variant<std::string>{command}); 1614cc340dd9SEd Tanous } 1615d22c8396SJason M. Bills else 1616d22c8396SJason M. Bills { 1617d22c8396SJason M. Bills crow::connections::systemBus->async_method_call( 1618d22c8396SJason M. Bills [asyncResp, resetType](const boost::system::error_code ec) { 1619d22c8396SJason M. Bills if (ec) 1620d22c8396SJason M. Bills { 1621d22c8396SJason M. Bills BMCWEB_LOG_ERROR << "D-Bus responses error: " << ec; 1622d22c8396SJason M. Bills if (ec.value() == boost::asio::error::invalid_argument) 1623d22c8396SJason M. Bills { 1624d22c8396SJason M. Bills messages::actionParameterNotSupported( 1625d22c8396SJason M. Bills asyncResp->res, resetType, "Reset"); 1626d22c8396SJason M. Bills } 1627d22c8396SJason M. Bills else 1628d22c8396SJason M. Bills { 1629d22c8396SJason M. Bills messages::internalError(asyncResp->res); 1630d22c8396SJason M. Bills } 1631d22c8396SJason M. Bills return; 1632d22c8396SJason M. Bills } 1633d22c8396SJason M. Bills messages::success(asyncResp->res); 1634d22c8396SJason M. Bills }, 1635d22c8396SJason M. Bills "xyz.openbmc_project.State.Chassis", 1636d22c8396SJason M. Bills "/xyz/openbmc_project/state/chassis0", 1637d22c8396SJason M. Bills "org.freedesktop.DBus.Properties", "Set", 1638d22c8396SJason M. Bills "xyz.openbmc_project.State.Chassis", "RequestedPowerTransition", 1639d22c8396SJason M. Bills std::variant<std::string>{command}); 1640d22c8396SJason M. Bills } 1641d22c8396SJason M. Bills } 1642bfd5b826SLakshminarayana R. Kammath /** 1643bfd5b826SLakshminarayana R. Kammath * Function transceives data with dbus directly. 1644bfd5b826SLakshminarayana R. Kammath */ 1645bfd5b826SLakshminarayana R. Kammath void doNMI(const std::shared_ptr<AsyncResp> &asyncResp) 1646bfd5b826SLakshminarayana R. Kammath { 1647bfd5b826SLakshminarayana R. Kammath constexpr char const *serviceName = 1648bfd5b826SLakshminarayana R. Kammath "xyz.openbmc_project.Control.Host.NMI"; 1649bfd5b826SLakshminarayana R. Kammath constexpr char const *objectPath = 1650bfd5b826SLakshminarayana R. Kammath "/xyz/openbmc_project/control/host0/nmi"; 1651bfd5b826SLakshminarayana R. Kammath constexpr char const *interfaceName = 1652bfd5b826SLakshminarayana R. Kammath "xyz.openbmc_project.Control.Host.NMI"; 1653bfd5b826SLakshminarayana R. Kammath constexpr char const *method = "NMI"; 1654bfd5b826SLakshminarayana R. Kammath 1655bfd5b826SLakshminarayana R. Kammath crow::connections::systemBus->async_method_call( 1656bfd5b826SLakshminarayana R. Kammath [asyncResp](const boost::system::error_code ec) { 1657bfd5b826SLakshminarayana R. Kammath if (ec) 1658bfd5b826SLakshminarayana R. Kammath { 1659bfd5b826SLakshminarayana R. Kammath BMCWEB_LOG_ERROR << " Bad D-Bus request error: " << ec; 1660bfd5b826SLakshminarayana R. Kammath messages::internalError(asyncResp->res); 1661bfd5b826SLakshminarayana R. Kammath return; 1662bfd5b826SLakshminarayana R. Kammath } 1663bfd5b826SLakshminarayana R. Kammath messages::success(asyncResp->res); 1664bfd5b826SLakshminarayana R. Kammath }, 1665bfd5b826SLakshminarayana R. Kammath serviceName, objectPath, interfaceName, method); 1666bfd5b826SLakshminarayana R. Kammath } 1667cc340dd9SEd Tanous }; 1668cc340dd9SEd Tanous 1669cc340dd9SEd Tanous /** 16706617338dSEd Tanous * Systems derived class for delivering Computer Systems Schema. 1671c5b2abe0SLewanczyk, Dawid */ 16721abe55efSEd Tanous class Systems : public Node 16731abe55efSEd Tanous { 1674c5b2abe0SLewanczyk, Dawid public: 1675c5b2abe0SLewanczyk, Dawid /* 1676c5b2abe0SLewanczyk, Dawid * Default Constructor 1677c5b2abe0SLewanczyk, Dawid */ 1678029573d4SEd Tanous Systems(CrowApp &app) : Node(app, "/redfish/v1/Systems/system/") 16791abe55efSEd Tanous { 1680c5b2abe0SLewanczyk, Dawid entityPrivileges = { 1681c5b2abe0SLewanczyk, Dawid {boost::beast::http::verb::get, {{"Login"}}}, 1682c5b2abe0SLewanczyk, Dawid {boost::beast::http::verb::head, {{"Login"}}}, 1683c5b2abe0SLewanczyk, Dawid {boost::beast::http::verb::patch, {{"ConfigureComponents"}}}, 1684c5b2abe0SLewanczyk, Dawid {boost::beast::http::verb::put, {{"ConfigureComponents"}}}, 1685c5b2abe0SLewanczyk, Dawid {boost::beast::http::verb::delete_, {{"ConfigureComponents"}}}, 1686c5b2abe0SLewanczyk, Dawid {boost::beast::http::verb::post, {{"ConfigureComponents"}}}}; 1687c5b2abe0SLewanczyk, Dawid } 1688c5b2abe0SLewanczyk, Dawid 1689c5b2abe0SLewanczyk, Dawid private: 1690c5b2abe0SLewanczyk, Dawid /** 1691c5b2abe0SLewanczyk, Dawid * Functions triggers appropriate requests on DBus 1692c5b2abe0SLewanczyk, Dawid */ 169355c7b7a2SEd Tanous void doGet(crow::Response &res, const crow::Request &req, 16941abe55efSEd Tanous const std::vector<std::string> ¶ms) override 16951abe55efSEd Tanous { 1696491d8ee7SSantosh Puranik res.jsonValue["@odata.type"] = "#ComputerSystem.v1_6_0.ComputerSystem"; 16970f74e643SEd Tanous res.jsonValue["@odata.context"] = 16980f74e643SEd Tanous "/redfish/v1/$metadata#ComputerSystem.ComputerSystem"; 1699029573d4SEd Tanous res.jsonValue["Name"] = "Computer System"; 1700029573d4SEd Tanous res.jsonValue["Id"] = "system"; 17010f74e643SEd Tanous res.jsonValue["SystemType"] = "Physical"; 17020f74e643SEd Tanous res.jsonValue["Description"] = "Computer System"; 17030f74e643SEd Tanous res.jsonValue["ProcessorSummary"]["Count"] = 0; 17040f74e643SEd Tanous res.jsonValue["ProcessorSummary"]["Status"]["State"] = "Disabled"; 17055fd7ba65SCheng C Yang res.jsonValue["MemorySummary"]["TotalSystemMemoryGiB"] = uint64_t(0); 17060f74e643SEd Tanous res.jsonValue["MemorySummary"]["Status"]["State"] = "Disabled"; 1707029573d4SEd Tanous res.jsonValue["@odata.id"] = "/redfish/v1/Systems/system"; 170804a258f4SEd Tanous 1709443c2934SRapkiewicz, Pawel res.jsonValue["Processors"] = { 1710029573d4SEd Tanous {"@odata.id", "/redfish/v1/Systems/system/Processors"}}; 1711443c2934SRapkiewicz, Pawel res.jsonValue["Memory"] = { 1712029573d4SEd Tanous {"@odata.id", "/redfish/v1/Systems/system/Memory"}}; 1713a25aeccfSNikhil Potade res.jsonValue["Storage"] = { 1714a25aeccfSNikhil Potade {"@odata.id", "/redfish/v1/Systems/system/Storage"}}; 1715029573d4SEd Tanous 1716cc340dd9SEd Tanous // TODO Need to support ForceRestart. 1717cc340dd9SEd Tanous res.jsonValue["Actions"]["#ComputerSystem.Reset"] = { 1718cc340dd9SEd Tanous {"target", 1719029573d4SEd Tanous "/redfish/v1/Systems/system/Actions/ComputerSystem.Reset"}, 1720cc340dd9SEd Tanous {"ResetType@Redfish.AllowableValues", 1721d22c8396SJason M. Bills {"On", "ForceOff", "ForceOn", "ForceRestart", "GracefulRestart", 1722bfd5b826SLakshminarayana R. Kammath "GracefulShutdown", "PowerCycle", "Nmi"}}}; 1723c5b2abe0SLewanczyk, Dawid 1724c4bf6374SJason M. Bills res.jsonValue["LogServices"] = { 1725029573d4SEd Tanous {"@odata.id", "/redfish/v1/Systems/system/LogServices"}}; 1726c4bf6374SJason M. Bills 1727d82a3acdSCarol Wang res.jsonValue["Bios"] = { 1728d82a3acdSCarol Wang {"@odata.id", "/redfish/v1/Systems/system/Bios"}}; 1729d82a3acdSCarol Wang 1730c5d03ff4SJennifer Lee res.jsonValue["Links"]["ManagedBy"] = { 1731c5d03ff4SJennifer Lee {{"@odata.id", "/redfish/v1/Managers/bmc"}}}; 1732c5d03ff4SJennifer Lee 1733c5d03ff4SJennifer Lee res.jsonValue["Status"] = { 1734c5d03ff4SJennifer Lee {"Health", "OK"}, 1735c5d03ff4SJennifer Lee {"State", "Enabled"}, 1736c5d03ff4SJennifer Lee }; 1737a0803efaSEd Tanous auto asyncResp = std::make_shared<AsyncResp>(res); 1738c5b2abe0SLewanczyk, Dawid 1739e284a7c1SJames Feist constexpr const std::array<const char *, 4> inventoryForSystems = { 1740b49ac873SJames Feist "xyz.openbmc_project.Inventory.Item.Dimm", 17412ad9c2f6SJames Feist "xyz.openbmc_project.Inventory.Item.Cpu", 1742e284a7c1SJames Feist "xyz.openbmc_project.Inventory.Item.Drive", 1743e284a7c1SJames Feist "xyz.openbmc_project.Inventory.Item.StorageController"}; 1744b49ac873SJames Feist 1745b49ac873SJames Feist auto health = std::make_shared<HealthPopulate>(asyncResp); 1746b49ac873SJames Feist crow::connections::systemBus->async_method_call( 1747b49ac873SJames Feist [health](const boost::system::error_code ec, 1748b49ac873SJames Feist std::vector<std::string> &resp) { 1749b49ac873SJames Feist if (ec) 1750b49ac873SJames Feist { 1751b49ac873SJames Feist // no inventory 1752b49ac873SJames Feist return; 1753b49ac873SJames Feist } 1754b49ac873SJames Feist 1755b49ac873SJames Feist health->inventory = std::move(resp); 1756b49ac873SJames Feist }, 1757b49ac873SJames Feist "xyz.openbmc_project.ObjectMapper", 1758b49ac873SJames Feist "/xyz/openbmc_project/object_mapper", 1759b49ac873SJames Feist "xyz.openbmc_project.ObjectMapper", "GetSubTreePaths", "/", 1760b49ac873SJames Feist int32_t(0), inventoryForSystems); 1761b49ac873SJames Feist 1762b49ac873SJames Feist health->populate(); 1763b49ac873SJames Feist 1764c5d03ff4SJennifer Lee getMainChassisId(asyncResp, [](const std::string &chassisId, 1765c5d03ff4SJennifer Lee std::shared_ptr<AsyncResp> aRsp) { 1766c5d03ff4SJennifer Lee aRsp->res.jsonValue["Links"]["Chassis"] = { 1767c5d03ff4SJennifer Lee {{"@odata.id", "/redfish/v1/Chassis/" + chassisId}}}; 1768c5d03ff4SJennifer Lee }); 1769a3002228SAppaRao Puli 1770a3002228SAppaRao Puli getIndicatorLedState(asyncResp); 17715bc2dc8eSJames Feist getComputerSystem(asyncResp, health); 17726c34de48SEd Tanous getHostState(asyncResp); 1773491d8ee7SSantosh Puranik getBootProperties(asyncResp); 1774adbe192aSJason M. Bills getPCIeDeviceList(asyncResp, "PCIeDevices"); 177551709ffdSYong Li getHostWatchdogTimer(asyncResp); 1776a6349918SAppaRao Puli #ifdef BMCWEB_ENABLE_REDFISH_PROVISIONING_FEATURE 1777a6349918SAppaRao Puli getProvisioningStatus(asyncResp); 1778a6349918SAppaRao Puli #endif 1779c5b2abe0SLewanczyk, Dawid } 1780c5b2abe0SLewanczyk, Dawid 178155c7b7a2SEd Tanous void doPatch(crow::Response &res, const crow::Request &req, 17821abe55efSEd Tanous const std::vector<std::string> ¶ms) override 17831abe55efSEd Tanous { 1784cde19e5fSSantosh Puranik std::optional<std::string> indicatorLed; 1785491d8ee7SSantosh Puranik std::optional<nlohmann::json> bootProps; 1786c45f0082SYong Li std::optional<nlohmann::json> wdtTimerProps; 178741352c24SSantosh Puranik auto asyncResp = std::make_shared<AsyncResp>(res); 178841352c24SSantosh Puranik 1789944ffaf9SJohnathan Mantey if (!json_util::readJson(req, res, "IndicatorLED", indicatorLed, "Boot", 1790c45f0082SYong Li bootProps, "WatchdogTimer", wdtTimerProps)) 17916617338dSEd Tanous { 17926617338dSEd Tanous return; 17936617338dSEd Tanous } 1794491d8ee7SSantosh Puranik 1795944ffaf9SJohnathan Mantey res.result(boost::beast::http::status::no_content); 1796c45f0082SYong Li 1797c45f0082SYong Li if (wdtTimerProps) 1798c45f0082SYong Li { 1799c45f0082SYong Li std::optional<bool> wdtEnable; 1800c45f0082SYong Li std::optional<std::string> wdtTimeOutAction; 1801c45f0082SYong Li 1802c45f0082SYong Li if (!json_util::readJson(*wdtTimerProps, asyncResp->res, 1803c45f0082SYong Li "FunctionEnabled", wdtEnable, 1804c45f0082SYong Li "TimeoutAction", wdtTimeOutAction)) 1805c45f0082SYong Li { 1806c45f0082SYong Li return; 1807c45f0082SYong Li } 1808c45f0082SYong Li setWDTProperties(asyncResp, std::move(wdtEnable), 1809c45f0082SYong Li std::move(wdtTimeOutAction)); 1810c45f0082SYong Li } 1811c45f0082SYong Li 1812491d8ee7SSantosh Puranik if (bootProps) 1813491d8ee7SSantosh Puranik { 1814491d8ee7SSantosh Puranik std::optional<std::string> bootSource; 1815491d8ee7SSantosh Puranik std::optional<std::string> bootEnable; 1816491d8ee7SSantosh Puranik 1817491d8ee7SSantosh Puranik if (!json_util::readJson(*bootProps, asyncResp->res, 1818491d8ee7SSantosh Puranik "BootSourceOverrideTarget", bootSource, 1819491d8ee7SSantosh Puranik "BootSourceOverrideEnabled", bootEnable)) 1820491d8ee7SSantosh Puranik { 1821491d8ee7SSantosh Puranik return; 1822491d8ee7SSantosh Puranik } 1823491d8ee7SSantosh Puranik setBootProperties(asyncResp, std::move(bootSource), 1824491d8ee7SSantosh Puranik std::move(bootEnable)); 1825491d8ee7SSantosh Puranik } 1826265c1602SJohnathan Mantey 18279712f8acSEd Tanous if (indicatorLed) 18286617338dSEd Tanous { 1829a3002228SAppaRao Puli setIndicatorLedState(asyncResp, std::move(*indicatorLed)); 18306617338dSEd Tanous } 1831c5b2abe0SLewanczyk, Dawid } 1832c5b2abe0SLewanczyk, Dawid }; 1833c5b2abe0SLewanczyk, Dawid } // namespace redfish 1834