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 nlohmann::json &procCount = 8657e8c9beSAlpana Kumari aResp->res.jsonValue["ProcessorSummary"]["Count"]; 8757e8c9beSAlpana Kumari if (*isCpuPresent == true) 8857e8c9beSAlpana Kumari { 8957e8c9beSAlpana Kumari procCount = procCount.get<int>() + 1; 9057e8c9beSAlpana Kumari } 9157e8c9beSAlpana Kumari aResp->res.jsonValue["ProcessorSummary"]["Count"] = procCount; 9257e8c9beSAlpana Kumari } 9357e8c9beSAlpana Kumari 9457e8c9beSAlpana Kumari /* 9557e8c9beSAlpana Kumari * @brief Update "ProcessorSummary" "Status" "State" based on 9657e8c9beSAlpana Kumari * CPU Functional State 9757e8c9beSAlpana Kumari * 9857e8c9beSAlpana Kumari * @param[in] aResp Shared pointer for completing asynchronous calls 9957e8c9beSAlpana Kumari * @param[in] cpuFunctionalState is CPU functional true/false 10057e8c9beSAlpana Kumari * 10157e8c9beSAlpana Kumari * @return None. 10257e8c9beSAlpana Kumari */ 10357e8c9beSAlpana Kumari void modifyCpuFunctionalState(std::shared_ptr<AsyncResp> aResp, 10457e8c9beSAlpana Kumari const std::variant<bool> &cpuFunctionalState) 10557e8c9beSAlpana Kumari { 10657e8c9beSAlpana Kumari const bool *isCpuFunctional = std::get_if<bool>(&cpuFunctionalState); 10757e8c9beSAlpana Kumari 10857e8c9beSAlpana Kumari if (isCpuFunctional == nullptr) 10957e8c9beSAlpana Kumari { 11057e8c9beSAlpana Kumari messages::internalError(aResp->res); 11157e8c9beSAlpana Kumari return; 11257e8c9beSAlpana Kumari } 11357e8c9beSAlpana Kumari BMCWEB_LOG_DEBUG << "Cpu Functional: " << *isCpuFunctional; 11457e8c9beSAlpana Kumari 11557e8c9beSAlpana Kumari nlohmann::json &prevProcState = 11657e8c9beSAlpana Kumari aResp->res.jsonValue["ProcessorSummary"]["Status"]["State"]; 11757e8c9beSAlpana Kumari 11857e8c9beSAlpana Kumari // Set it as Enabled if atleast one CPU is functional 11957e8c9beSAlpana Kumari // Update STATE only if previous State was Non_Functional and current CPU is 12057e8c9beSAlpana Kumari // Functional. 12157e8c9beSAlpana Kumari if (prevProcState == "Disabled") 12257e8c9beSAlpana Kumari { 12357e8c9beSAlpana Kumari if (*isCpuFunctional == true) 12457e8c9beSAlpana Kumari { 12557e8c9beSAlpana Kumari aResp->res.jsonValue["ProcessorSummary"]["Status"]["State"] = 12657e8c9beSAlpana Kumari "Enabled"; 12757e8c9beSAlpana Kumari } 12857e8c9beSAlpana Kumari } 12957e8c9beSAlpana Kumari } 13057e8c9beSAlpana Kumari 13157e8c9beSAlpana Kumari /* 132c5b2abe0SLewanczyk, Dawid * @brief Retrieves computer system properties over dbus 133c5b2abe0SLewanczyk, Dawid * 134c5b2abe0SLewanczyk, Dawid * @param[in] aResp Shared pointer for completing asynchronous calls 135c5b2abe0SLewanczyk, Dawid * @param[in] name Computer system name from request 136c5b2abe0SLewanczyk, Dawid * 137c5b2abe0SLewanczyk, Dawid * @return None. 138c5b2abe0SLewanczyk, Dawid */ 1395bc2dc8eSJames Feist void getComputerSystem(std::shared_ptr<AsyncResp> aResp, 1405bc2dc8eSJames Feist std::shared_ptr<HealthPopulate> systemHealth) 1411abe55efSEd Tanous { 14255c7b7a2SEd Tanous BMCWEB_LOG_DEBUG << "Get available system components."; 1439d3ae10eSAlpana Kumari 14455c7b7a2SEd Tanous crow::connections::systemBus->async_method_call( 1455bc2dc8eSJames Feist [aResp, systemHealth]( 146c5b2abe0SLewanczyk, Dawid const boost::system::error_code ec, 147c5b2abe0SLewanczyk, Dawid const std::vector<std::pair< 1486c34de48SEd Tanous std::string, 1496c34de48SEd Tanous std::vector<std::pair<std::string, std::vector<std::string>>>>> 150c5b2abe0SLewanczyk, Dawid &subtree) { 1511abe55efSEd Tanous if (ec) 1521abe55efSEd Tanous { 15355c7b7a2SEd Tanous BMCWEB_LOG_DEBUG << "DBUS response error"; 154f12894f8SJason M. Bills messages::internalError(aResp->res); 155c5b2abe0SLewanczyk, Dawid return; 156c5b2abe0SLewanczyk, Dawid } 157c5b2abe0SLewanczyk, Dawid // Iterate over all retrieved ObjectPaths. 1586c34de48SEd Tanous for (const std::pair<std::string, 1596c34de48SEd Tanous std::vector<std::pair< 1606c34de48SEd Tanous std::string, std::vector<std::string>>>> 1611abe55efSEd Tanous &object : subtree) 1621abe55efSEd Tanous { 163c5b2abe0SLewanczyk, Dawid const std::string &path = object.first; 16455c7b7a2SEd Tanous BMCWEB_LOG_DEBUG << "Got path: " << path; 1651abe55efSEd Tanous const std::vector< 1661abe55efSEd Tanous std::pair<std::string, std::vector<std::string>>> 167c5b2abe0SLewanczyk, Dawid &connectionNames = object.second; 1681abe55efSEd Tanous if (connectionNames.size() < 1) 1691abe55efSEd Tanous { 170c5b2abe0SLewanczyk, Dawid continue; 171c5b2abe0SLewanczyk, Dawid } 172029573d4SEd Tanous 1735bc2dc8eSJames Feist auto memoryHealth = std::make_shared<HealthPopulate>( 1745bc2dc8eSJames Feist aResp, aResp->res.jsonValue["MemorySummary"]["Status"]); 1755bc2dc8eSJames Feist 1765bc2dc8eSJames Feist auto cpuHealth = std::make_shared<HealthPopulate>( 1775bc2dc8eSJames Feist aResp, aResp->res.jsonValue["ProcessorSummary"]["Status"]); 1785bc2dc8eSJames Feist 1795bc2dc8eSJames Feist systemHealth->children.emplace_back(memoryHealth); 1805bc2dc8eSJames Feist systemHealth->children.emplace_back(cpuHealth); 1815bc2dc8eSJames Feist 1826c34de48SEd Tanous // This is not system, so check if it's cpu, dimm, UUID or 1836c34de48SEd Tanous // BiosVer 18404a258f4SEd Tanous for (const auto &connection : connectionNames) 1851abe55efSEd Tanous { 18604a258f4SEd Tanous for (const auto &interfaceName : connection.second) 1871abe55efSEd Tanous { 18804a258f4SEd Tanous if (interfaceName == 18904a258f4SEd Tanous "xyz.openbmc_project.Inventory.Item.Dimm") 1901abe55efSEd Tanous { 1911abe55efSEd Tanous BMCWEB_LOG_DEBUG 19204a258f4SEd Tanous << "Found Dimm, now get its properties."; 1939d3ae10eSAlpana Kumari 19455c7b7a2SEd Tanous crow::connections::systemBus->async_method_call( 1959d3ae10eSAlpana Kumari [aResp, service{connection.first}, 1969d3ae10eSAlpana Kumari path(std::move(path))]( 1979d3ae10eSAlpana Kumari const boost::system::error_code ec, 1986c34de48SEd Tanous const std::vector< 1996c34de48SEd Tanous std::pair<std::string, VariantType>> 2001abe55efSEd Tanous &properties) { 2011abe55efSEd Tanous if (ec) 2021abe55efSEd Tanous { 2031abe55efSEd Tanous BMCWEB_LOG_ERROR 2046c34de48SEd Tanous << "DBUS response error " << ec; 205f12894f8SJason M. Bills messages::internalError(aResp->res); 206c5b2abe0SLewanczyk, Dawid return; 207c5b2abe0SLewanczyk, Dawid } 2086c34de48SEd Tanous BMCWEB_LOG_DEBUG << "Got " 2096c34de48SEd Tanous << properties.size() 210c5b2abe0SLewanczyk, Dawid << " Dimm properties."; 2119d3ae10eSAlpana Kumari 2129d3ae10eSAlpana Kumari if (properties.size() > 0) 2139d3ae10eSAlpana Kumari { 21404a258f4SEd Tanous for (const std::pair<std::string, 21504a258f4SEd Tanous VariantType> 21604a258f4SEd Tanous &property : properties) 2171abe55efSEd Tanous { 218*5fd7ba65SCheng C Yang if (property.first != 219*5fd7ba65SCheng C Yang "MemorySizeInKB") 2201abe55efSEd Tanous { 221*5fd7ba65SCheng C Yang continue; 222*5fd7ba65SCheng C Yang } 223*5fd7ba65SCheng C Yang const uint32_t *value = 224*5fd7ba65SCheng C Yang sdbusplus::message::variant_ns:: 225*5fd7ba65SCheng C Yang get_if<uint32_t>( 2261b6b96c5SEd Tanous &property.second); 227*5fd7ba65SCheng C Yang if (value == nullptr) 2281abe55efSEd Tanous { 229*5fd7ba65SCheng C Yang BMCWEB_LOG_DEBUG 230*5fd7ba65SCheng C Yang << "Find incorrect type of " 231*5fd7ba65SCheng C Yang "MemorySize"; 232*5fd7ba65SCheng C Yang continue; 233*5fd7ba65SCheng C Yang } 234*5fd7ba65SCheng C Yang nlohmann::json &totalMemory = 235*5fd7ba65SCheng C Yang aResp->res 236*5fd7ba65SCheng C Yang .jsonValue["MemorySummar" 237*5fd7ba65SCheng C Yang "y"] 238*5fd7ba65SCheng C Yang ["TotalSystemMe" 239*5fd7ba65SCheng C Yang "moryGiB"]; 240*5fd7ba65SCheng C Yang uint64_t *preValue = 241*5fd7ba65SCheng C Yang totalMemory 242*5fd7ba65SCheng C Yang .get_ptr<uint64_t *>(); 243*5fd7ba65SCheng C Yang if (preValue == nullptr) 244*5fd7ba65SCheng C Yang { 245*5fd7ba65SCheng C Yang continue; 246*5fd7ba65SCheng C Yang } 247*5fd7ba65SCheng C Yang aResp->res 248*5fd7ba65SCheng C Yang .jsonValue["MemorySummary"] 2496c34de48SEd Tanous ["TotalSystemMemoryGi" 250*5fd7ba65SCheng C Yang "B"] = 251*5fd7ba65SCheng C Yang *value / (1024 * 1024) + 252*5fd7ba65SCheng C Yang *preValue; 253*5fd7ba65SCheng C Yang aResp->res 254*5fd7ba65SCheng C Yang .jsonValue["MemorySummary"] 2559d3ae10eSAlpana Kumari ["Status"]["State"] = 2561abe55efSEd Tanous "Enabled"; 257c5b2abe0SLewanczyk, Dawid } 258c5b2abe0SLewanczyk, Dawid } 2599d3ae10eSAlpana Kumari else 2609d3ae10eSAlpana Kumari { 2619d3ae10eSAlpana Kumari auto getDimmProperties = 2629d3ae10eSAlpana Kumari [aResp]( 2639d3ae10eSAlpana Kumari const boost::system::error_code 2649d3ae10eSAlpana Kumari ec, 2659d3ae10eSAlpana Kumari const std::variant<bool> 2669d3ae10eSAlpana Kumari &dimmState) { 2679d3ae10eSAlpana Kumari if (ec) 2689d3ae10eSAlpana Kumari { 2699d3ae10eSAlpana Kumari BMCWEB_LOG_ERROR 2709d3ae10eSAlpana Kumari << "DBUS response " 2719d3ae10eSAlpana Kumari "error " 2729d3ae10eSAlpana Kumari << ec; 2739d3ae10eSAlpana Kumari return; 2749d3ae10eSAlpana Kumari } 2759d3ae10eSAlpana Kumari updateDimmProperties(aResp, 2769d3ae10eSAlpana Kumari dimmState); 2779d3ae10eSAlpana Kumari }; 2789d3ae10eSAlpana Kumari crow::connections::systemBus 2799d3ae10eSAlpana Kumari ->async_method_call( 2809d3ae10eSAlpana Kumari std::move(getDimmProperties), 2819d3ae10eSAlpana Kumari service, path, 2829d3ae10eSAlpana Kumari "org.freedesktop.DBus." 2839d3ae10eSAlpana Kumari "Properties", 2849d3ae10eSAlpana Kumari "Get", 2859d3ae10eSAlpana Kumari "xyz.openbmc_project.State." 2869d3ae10eSAlpana Kumari "Decorator.OperationalStatus", 2879d3ae10eSAlpana Kumari "Functional"); 2889d3ae10eSAlpana Kumari } 289c5b2abe0SLewanczyk, Dawid }, 29004a258f4SEd Tanous connection.first, path, 2916c34de48SEd Tanous "org.freedesktop.DBus.Properties", "GetAll", 2926c34de48SEd Tanous "xyz.openbmc_project.Inventory.Item.Dimm"); 2935bc2dc8eSJames Feist 2945bc2dc8eSJames Feist memoryHealth->inventory.emplace_back(path); 2951abe55efSEd Tanous } 29604a258f4SEd Tanous else if (interfaceName == 29704a258f4SEd Tanous "xyz.openbmc_project.Inventory.Item.Cpu") 2981abe55efSEd Tanous { 2991abe55efSEd Tanous BMCWEB_LOG_DEBUG 30004a258f4SEd Tanous << "Found Cpu, now get its properties."; 30157e8c9beSAlpana Kumari 302a0803efaSEd Tanous crow::connections::systemBus->async_method_call( 30357e8c9beSAlpana Kumari [aResp, service{connection.first}, 30457e8c9beSAlpana Kumari path(std::move(path))]( 30557e8c9beSAlpana Kumari const boost::system::error_code ec, 3066c34de48SEd Tanous const std::vector< 3076c34de48SEd Tanous std::pair<std::string, VariantType>> 3081abe55efSEd Tanous &properties) { 3091abe55efSEd Tanous if (ec) 3101abe55efSEd Tanous { 3111abe55efSEd Tanous BMCWEB_LOG_ERROR 3126c34de48SEd Tanous << "DBUS response error " << ec; 313f12894f8SJason M. Bills messages::internalError(aResp->res); 314c5b2abe0SLewanczyk, Dawid return; 315c5b2abe0SLewanczyk, Dawid } 3166c34de48SEd Tanous BMCWEB_LOG_DEBUG << "Got " 3176c34de48SEd Tanous << properties.size() 318c5b2abe0SLewanczyk, Dawid << " Cpu properties."; 31957e8c9beSAlpana Kumari 32057e8c9beSAlpana Kumari if (properties.size() > 0) 32157e8c9beSAlpana Kumari { 32204a258f4SEd Tanous for (const auto &property : properties) 3231abe55efSEd Tanous { 32457e8c9beSAlpana Kumari if (property.first == 32557e8c9beSAlpana Kumari "ProcessorFamily") 3261abe55efSEd Tanous { 327a0803efaSEd Tanous const std::string *value = 32857e8c9beSAlpana Kumari sdbusplus::message:: 32957e8c9beSAlpana Kumari variant_ns::get_if< 33057e8c9beSAlpana Kumari std::string>( 3311b6b96c5SEd Tanous &property.second); 3321abe55efSEd Tanous if (value != nullptr) 3331abe55efSEd Tanous { 33457e8c9beSAlpana Kumari nlohmann::json 33557e8c9beSAlpana Kumari &procSummary = 3361abe55efSEd Tanous aResp->res.jsonValue 3376c34de48SEd Tanous ["ProcessorSumm" 33804a258f4SEd Tanous "ary"]; 33904a258f4SEd Tanous nlohmann::json &procCount = 34004a258f4SEd Tanous procSummary["Count"]; 34104a258f4SEd Tanous procCount = 34257e8c9beSAlpana Kumari procCount.get<int>() + 34357e8c9beSAlpana Kumari 1; 34457e8c9beSAlpana Kumari procSummary["Status"] 34557e8c9beSAlpana Kumari ["State"] = 346c5b2abe0SLewanczyk, Dawid "Enabled"; 34757e8c9beSAlpana Kumari procSummary["Model"] = 34857e8c9beSAlpana Kumari *value; 349c5b2abe0SLewanczyk, Dawid } 350c5b2abe0SLewanczyk, Dawid } 351c5b2abe0SLewanczyk, Dawid } 35257e8c9beSAlpana Kumari } 35357e8c9beSAlpana Kumari else 35457e8c9beSAlpana Kumari { 35557e8c9beSAlpana Kumari auto getCpuPresenceState = 35657e8c9beSAlpana Kumari [aResp]( 35757e8c9beSAlpana Kumari const boost::system::error_code 35857e8c9beSAlpana Kumari ec, 35957e8c9beSAlpana Kumari const std::variant<bool> 36057e8c9beSAlpana Kumari &cpuPresenceCheck) { 36157e8c9beSAlpana Kumari if (ec) 36257e8c9beSAlpana Kumari { 36357e8c9beSAlpana Kumari BMCWEB_LOG_ERROR 36457e8c9beSAlpana Kumari << "DBUS response " 36557e8c9beSAlpana Kumari "error " 36657e8c9beSAlpana Kumari << ec; 36757e8c9beSAlpana Kumari return; 36857e8c9beSAlpana Kumari } 36957e8c9beSAlpana Kumari modifyCpuPresenceState( 37057e8c9beSAlpana Kumari aResp, cpuPresenceCheck); 37157e8c9beSAlpana Kumari }; 37257e8c9beSAlpana Kumari 37357e8c9beSAlpana Kumari auto getCpuFunctionalState = 37457e8c9beSAlpana Kumari [aResp]( 37557e8c9beSAlpana Kumari const boost::system::error_code 37657e8c9beSAlpana Kumari ec, 37757e8c9beSAlpana Kumari const std::variant<bool> 37857e8c9beSAlpana Kumari &cpuFunctionalCheck) { 37957e8c9beSAlpana Kumari if (ec) 38057e8c9beSAlpana Kumari { 38157e8c9beSAlpana Kumari BMCWEB_LOG_ERROR 38257e8c9beSAlpana Kumari << "DBUS response " 38357e8c9beSAlpana Kumari "error " 38457e8c9beSAlpana Kumari << ec; 38557e8c9beSAlpana Kumari return; 38657e8c9beSAlpana Kumari } 38757e8c9beSAlpana Kumari modifyCpuFunctionalState( 38857e8c9beSAlpana Kumari aResp, cpuFunctionalCheck); 38957e8c9beSAlpana Kumari }; 39057e8c9beSAlpana Kumari // Get the Presence of CPU 39157e8c9beSAlpana Kumari crow::connections::systemBus 39257e8c9beSAlpana Kumari ->async_method_call( 39357e8c9beSAlpana Kumari std::move(getCpuPresenceState), 39457e8c9beSAlpana Kumari service, path, 39557e8c9beSAlpana Kumari "org.freedesktop.DBus." 39657e8c9beSAlpana Kumari "Properties", 39757e8c9beSAlpana Kumari "Get", 39857e8c9beSAlpana Kumari "xyz.openbmc_project.Inventory." 39957e8c9beSAlpana Kumari "Item", 40057e8c9beSAlpana Kumari "Present"); 40157e8c9beSAlpana Kumari 40257e8c9beSAlpana Kumari // Get the Functional State 40357e8c9beSAlpana Kumari crow::connections::systemBus 40457e8c9beSAlpana Kumari ->async_method_call( 40557e8c9beSAlpana Kumari std::move( 40657e8c9beSAlpana Kumari getCpuFunctionalState), 40757e8c9beSAlpana Kumari service, path, 40857e8c9beSAlpana Kumari "org.freedesktop.DBus." 40957e8c9beSAlpana Kumari "Properties", 41057e8c9beSAlpana Kumari "Get", 41157e8c9beSAlpana Kumari "xyz.openbmc_project.State." 41257e8c9beSAlpana Kumari "Decorator." 41357e8c9beSAlpana Kumari "OperationalStatus", 41457e8c9beSAlpana Kumari "Functional"); 41557e8c9beSAlpana Kumari 41657e8c9beSAlpana Kumari // Get the MODEL from 41757e8c9beSAlpana Kumari // xyz.openbmc_project.Inventory.Decorator.Asset 41857e8c9beSAlpana Kumari // support it later as Model is Empty 41957e8c9beSAlpana Kumari // currently. 42057e8c9beSAlpana Kumari } 421c5b2abe0SLewanczyk, Dawid }, 42204a258f4SEd Tanous connection.first, path, 4236c34de48SEd Tanous "org.freedesktop.DBus.Properties", "GetAll", 4246c34de48SEd Tanous "xyz.openbmc_project.Inventory.Item.Cpu"); 4255bc2dc8eSJames Feist 4265bc2dc8eSJames Feist cpuHealth->inventory.emplace_back(path); 4271abe55efSEd Tanous } 42804a258f4SEd Tanous else if (interfaceName == 42904a258f4SEd Tanous "xyz.openbmc_project.Common.UUID") 4301abe55efSEd Tanous { 4311abe55efSEd Tanous BMCWEB_LOG_DEBUG 43204a258f4SEd Tanous << "Found UUID, now get its properties."; 43355c7b7a2SEd Tanous crow::connections::systemBus->async_method_call( 434029573d4SEd Tanous [aResp](const boost::system::error_code ec, 4356c34de48SEd Tanous const std::vector< 4366c34de48SEd Tanous std::pair<std::string, VariantType>> 4371abe55efSEd Tanous &properties) { 4381abe55efSEd Tanous if (ec) 4391abe55efSEd Tanous { 4401abe55efSEd Tanous BMCWEB_LOG_DEBUG 4416c34de48SEd Tanous << "DBUS response error " << ec; 442f12894f8SJason M. Bills messages::internalError(aResp->res); 443c5b2abe0SLewanczyk, Dawid return; 444c5b2abe0SLewanczyk, Dawid } 4456c34de48SEd Tanous BMCWEB_LOG_DEBUG << "Got " 4466c34de48SEd Tanous << properties.size() 447c5b2abe0SLewanczyk, Dawid << " UUID properties."; 4481abe55efSEd Tanous for (const std::pair<std::string, 44904a258f4SEd Tanous VariantType> 45004a258f4SEd Tanous &property : properties) 4511abe55efSEd Tanous { 45204a258f4SEd Tanous if (property.first == "UUID") 4531abe55efSEd Tanous { 454c5b2abe0SLewanczyk, Dawid const std::string *value = 455029573d4SEd Tanous sdbusplus::message::variant_ns:: 456029573d4SEd Tanous get_if<std::string>( 4571b6b96c5SEd Tanous &property.second); 45804a258f4SEd Tanous 4591abe55efSEd Tanous if (value != nullptr) 4601abe55efSEd Tanous { 461029573d4SEd Tanous std::string valueStr = *value; 46204a258f4SEd Tanous if (valueStr.size() == 32) 4631abe55efSEd Tanous { 464029573d4SEd Tanous valueStr.insert(8, 1, '-'); 465029573d4SEd Tanous valueStr.insert(13, 1, '-'); 466029573d4SEd Tanous valueStr.insert(18, 1, '-'); 467029573d4SEd Tanous valueStr.insert(23, 1, '-'); 46804a258f4SEd Tanous } 469029573d4SEd Tanous BMCWEB_LOG_DEBUG << "UUID = " 47004a258f4SEd Tanous << valueStr; 471029573d4SEd Tanous aResp->res.jsonValue["UUID"] = 47204a258f4SEd Tanous valueStr; 473c5b2abe0SLewanczyk, Dawid } 474c5b2abe0SLewanczyk, Dawid } 475c5b2abe0SLewanczyk, Dawid } 476c5b2abe0SLewanczyk, Dawid }, 47704a258f4SEd Tanous connection.first, path, 4786c34de48SEd Tanous "org.freedesktop.DBus.Properties", "GetAll", 4791abe55efSEd Tanous "xyz.openbmc_project.Common.UUID"); 480c5b2abe0SLewanczyk, Dawid } 481029573d4SEd Tanous else if (interfaceName == 482029573d4SEd Tanous "xyz.openbmc_project.Inventory.Item.System") 4831abe55efSEd Tanous { 484029573d4SEd Tanous crow::connections::systemBus->async_method_call( 485029573d4SEd Tanous [aResp](const boost::system::error_code ec, 486029573d4SEd Tanous const std::vector< 487029573d4SEd Tanous std::pair<std::string, VariantType>> 488029573d4SEd Tanous &propertiesList) { 489029573d4SEd Tanous if (ec) 490029573d4SEd Tanous { 491e4a4b9a9SJames Feist // doesn't have to include this 492e4a4b9a9SJames Feist // interface 493029573d4SEd Tanous return; 494029573d4SEd Tanous } 495698654b6SGunnar Mills BMCWEB_LOG_DEBUG 496698654b6SGunnar Mills << "Got " << propertiesList.size() 497029573d4SEd Tanous << " properties for system"; 498029573d4SEd Tanous for (const std::pair<std::string, 499029573d4SEd Tanous VariantType> 500029573d4SEd Tanous &property : propertiesList) 501029573d4SEd Tanous { 502fc5afcf9Sbeccabroek const std::string &propertyName = 503fc5afcf9Sbeccabroek property.first; 504fc5afcf9Sbeccabroek if ((propertyName == "PartNumber") || 505fc5afcf9Sbeccabroek (propertyName == "SerialNumber") || 506fc5afcf9Sbeccabroek (propertyName == "Manufacturer") || 507fc5afcf9Sbeccabroek (propertyName == "Model")) 508fc5afcf9Sbeccabroek { 509029573d4SEd Tanous const std::string *value = 510fc5afcf9Sbeccabroek std::get_if<std::string>( 511029573d4SEd Tanous &property.second); 512029573d4SEd Tanous if (value != nullptr) 513029573d4SEd Tanous { 514029573d4SEd Tanous aResp->res 515fc5afcf9Sbeccabroek .jsonValue[propertyName] = 516029573d4SEd Tanous *value; 517029573d4SEd Tanous } 518029573d4SEd Tanous } 519fc5afcf9Sbeccabroek } 520029573d4SEd Tanous aResp->res.jsonValue["Name"] = "system"; 521029573d4SEd Tanous aResp->res.jsonValue["Id"] = 522029573d4SEd Tanous aResp->res.jsonValue["SerialNumber"]; 523cb7e1e7bSAndrew Geissler // Grab the bios version 524cb7e1e7bSAndrew Geissler fw_util::getActiveFwVersion( 525cb7e1e7bSAndrew Geissler aResp, fw_util::biosPurpose, 526cb7e1e7bSAndrew Geissler "BiosVersion"); 527029573d4SEd Tanous }, 528029573d4SEd Tanous connection.first, path, 529029573d4SEd Tanous "org.freedesktop.DBus.Properties", "GetAll", 530029573d4SEd Tanous "xyz.openbmc_project.Inventory.Decorator." 531029573d4SEd Tanous "Asset"); 532e4a4b9a9SJames Feist 533e4a4b9a9SJames Feist crow::connections::systemBus->async_method_call( 534e4a4b9a9SJames Feist [aResp]( 535e4a4b9a9SJames Feist const boost::system::error_code ec, 536e4a4b9a9SJames Feist const std::variant<std::string> &property) { 537e4a4b9a9SJames Feist if (ec) 538e4a4b9a9SJames Feist { 539e4a4b9a9SJames Feist // doesn't have to include this 540e4a4b9a9SJames Feist // interface 541e4a4b9a9SJames Feist return; 542e4a4b9a9SJames Feist } 543e4a4b9a9SJames Feist 544e4a4b9a9SJames Feist const std::string *value = 545e4a4b9a9SJames Feist std::get_if<std::string>(&property); 546e4a4b9a9SJames Feist if (value != nullptr) 547e4a4b9a9SJames Feist { 548e4a4b9a9SJames Feist aResp->res.jsonValue["AssetTag"] = 549e4a4b9a9SJames Feist *value; 550e4a4b9a9SJames Feist } 551e4a4b9a9SJames Feist }, 552e4a4b9a9SJames Feist connection.first, path, 553e4a4b9a9SJames Feist "org.freedesktop.DBus.Properties", "Get", 554e4a4b9a9SJames Feist "xyz.openbmc_project.Inventory.Decorator." 555e4a4b9a9SJames Feist "AssetTag", 556e4a4b9a9SJames Feist "AssetTag"); 557029573d4SEd Tanous } 558029573d4SEd Tanous } 559029573d4SEd Tanous } 560c5b2abe0SLewanczyk, Dawid } 561c5b2abe0SLewanczyk, Dawid }, 562c5b2abe0SLewanczyk, Dawid "xyz.openbmc_project.ObjectMapper", 563c5b2abe0SLewanczyk, Dawid "/xyz/openbmc_project/object_mapper", 564c5b2abe0SLewanczyk, Dawid "xyz.openbmc_project.ObjectMapper", "GetSubTree", 5656617338dSEd Tanous "/xyz/openbmc_project/inventory", int32_t(0), 5666617338dSEd Tanous std::array<const char *, 5>{ 5676617338dSEd Tanous "xyz.openbmc_project.Inventory.Decorator.Asset", 5686617338dSEd Tanous "xyz.openbmc_project.Inventory.Item.Cpu", 5696617338dSEd Tanous "xyz.openbmc_project.Inventory.Item.Dimm", 5706617338dSEd Tanous "xyz.openbmc_project.Inventory.Item.System", 5716617338dSEd Tanous "xyz.openbmc_project.Common.UUID", 5726617338dSEd Tanous }); 573c5b2abe0SLewanczyk, Dawid } 574c5b2abe0SLewanczyk, Dawid 575c5b2abe0SLewanczyk, Dawid /** 576c5b2abe0SLewanczyk, Dawid * @brief Retrieves identify led group properties over dbus 577c5b2abe0SLewanczyk, Dawid * 578491d8ee7SSantosh Puranik * @param[in] aResp Shared pointer for generating response message. 579c5b2abe0SLewanczyk, Dawid * 580c5b2abe0SLewanczyk, Dawid * @return None. 581c5b2abe0SLewanczyk, Dawid */ 582a3002228SAppaRao Puli void getIndicatorLedState(std::shared_ptr<AsyncResp> aResp) 5831abe55efSEd Tanous { 58455c7b7a2SEd Tanous BMCWEB_LOG_DEBUG << "Get led groups"; 58555c7b7a2SEd Tanous crow::connections::systemBus->async_method_call( 586a3002228SAppaRao Puli [aResp](const boost::system::error_code ec, 587a3002228SAppaRao Puli const std::variant<bool> asserted) { 588f847a198SAppaRao Puli // Some systems may not have enclosure_identify_blink object so 589f847a198SAppaRao Puli // proceed to get enclosure_identify state. 590f847a198SAppaRao Puli if (!ec) 5911abe55efSEd Tanous { 592a3002228SAppaRao Puli const bool *blinking = std::get_if<bool>(&asserted); 593a3002228SAppaRao Puli if (!blinking) 5941abe55efSEd Tanous { 595a3002228SAppaRao Puli BMCWEB_LOG_DEBUG << "Get identity blinking LED failed"; 596a3002228SAppaRao Puli messages::internalError(aResp->res); 597a3002228SAppaRao Puli return; 598a3002228SAppaRao Puli } 599a3002228SAppaRao Puli // Blinking ON, no need to check enclosure_identify assert. 600a3002228SAppaRao Puli if (*blinking) 6011abe55efSEd Tanous { 602a3002228SAppaRao Puli aResp->res.jsonValue["IndicatorLED"] = "Blinking"; 603a3002228SAppaRao Puli return; 604a3002228SAppaRao Puli } 605f847a198SAppaRao Puli } 606a3002228SAppaRao Puli crow::connections::systemBus->async_method_call( 607a3002228SAppaRao Puli [aResp](const boost::system::error_code ec, 608a3002228SAppaRao Puli const std::variant<bool> asserted) { 609f847a198SAppaRao Puli if (!ec) 6101abe55efSEd Tanous { 611a3002228SAppaRao Puli const bool *ledOn = std::get_if<bool>(&asserted); 612a3002228SAppaRao Puli if (!ledOn) 6131abe55efSEd Tanous { 614f847a198SAppaRao Puli BMCWEB_LOG_DEBUG 615f847a198SAppaRao Puli << "Get enclosure identity led failed"; 616a3002228SAppaRao Puli messages::internalError(aResp->res); 617a3002228SAppaRao Puli return; 618a3002228SAppaRao Puli } 619a3002228SAppaRao Puli 620a3002228SAppaRao Puli if (*ledOn) 6211abe55efSEd Tanous { 622a3002228SAppaRao Puli aResp->res.jsonValue["IndicatorLED"] = "Lit"; 6231abe55efSEd Tanous } 6241abe55efSEd Tanous else 6251abe55efSEd Tanous { 626a3002228SAppaRao Puli aResp->res.jsonValue["IndicatorLED"] = "Off"; 627c5b2abe0SLewanczyk, Dawid } 628f847a198SAppaRao Puli } 629a3002228SAppaRao Puli return; 630a3002228SAppaRao Puli }, 631a3002228SAppaRao Puli "xyz.openbmc_project.LED.GroupManager", 632a3002228SAppaRao Puli "/xyz/openbmc_project/led/groups/enclosure_identify", 633a3002228SAppaRao Puli "org.freedesktop.DBus.Properties", "Get", 634a3002228SAppaRao Puli "xyz.openbmc_project.Led.Group", "Asserted"); 635a3002228SAppaRao Puli }, 636a3002228SAppaRao Puli "xyz.openbmc_project.LED.GroupManager", 637a3002228SAppaRao Puli "/xyz/openbmc_project/led/groups/enclosure_identify_blink", 638a3002228SAppaRao Puli "org.freedesktop.DBus.Properties", "Get", 639a3002228SAppaRao Puli "xyz.openbmc_project.Led.Group", "Asserted"); 640c5b2abe0SLewanczyk, Dawid } 641a3002228SAppaRao Puli /** 642a3002228SAppaRao Puli * @brief Sets identify led group properties 643a3002228SAppaRao Puli * 644a3002228SAppaRao Puli * @param[in] aResp Shared pointer for generating response message. 645a3002228SAppaRao Puli * @param[in] ledState LED state passed from request 646a3002228SAppaRao Puli * 647a3002228SAppaRao Puli * @return None. 648a3002228SAppaRao Puli */ 649a3002228SAppaRao Puli void setIndicatorLedState(std::shared_ptr<AsyncResp> aResp, 650a3002228SAppaRao Puli const std::string &ledState) 651a3002228SAppaRao Puli { 652a3002228SAppaRao Puli BMCWEB_LOG_DEBUG << "Set led groups"; 653a3002228SAppaRao Puli bool ledOn = false; 654a3002228SAppaRao Puli bool ledBlinkng = false; 655a3002228SAppaRao Puli 656a3002228SAppaRao Puli if (ledState == "Lit") 657a3002228SAppaRao Puli { 658a3002228SAppaRao Puli ledOn = true; 659c5b2abe0SLewanczyk, Dawid } 660a3002228SAppaRao Puli else if (ledState == "Blinking") 661a3002228SAppaRao Puli { 662a3002228SAppaRao Puli ledBlinkng = true; 663c5b2abe0SLewanczyk, Dawid } 664a3002228SAppaRao Puli else if (ledState != "Off") 665a3002228SAppaRao Puli { 666a3002228SAppaRao Puli messages::propertyValueNotInList(aResp->res, ledState, "IndicatorLED"); 667a3002228SAppaRao Puli return; 668c5b2abe0SLewanczyk, Dawid } 669a3002228SAppaRao Puli 670a3002228SAppaRao Puli crow::connections::systemBus->async_method_call( 671f847a198SAppaRao Puli [aResp, ledOn, ledBlinkng](const boost::system::error_code ec, 672f847a198SAppaRao Puli const std::variant<bool> asserted) mutable { 673f847a198SAppaRao Puli if (ec) 674f847a198SAppaRao Puli { 675f847a198SAppaRao Puli // Some systems may not have enclosure_identify_blink object so 676f847a198SAppaRao Puli // Lets set enclosure_identify state to true if Blinking is 677f847a198SAppaRao Puli // true. 678f847a198SAppaRao Puli if (ledBlinkng) 679f847a198SAppaRao Puli { 680f847a198SAppaRao Puli ledOn = true; 681f847a198SAppaRao Puli } 682f847a198SAppaRao Puli } 683f847a198SAppaRao Puli crow::connections::systemBus->async_method_call( 684a3002228SAppaRao Puli [aResp](const boost::system::error_code ec, 685a3002228SAppaRao Puli const std::variant<bool> asserted) { 686a3002228SAppaRao Puli if (ec) 687a3002228SAppaRao Puli { 688a3002228SAppaRao Puli BMCWEB_LOG_DEBUG << "DBUS response error " << ec; 689a3002228SAppaRao Puli messages::internalError(aResp->res); 690a3002228SAppaRao Puli return; 691c5b2abe0SLewanczyk, Dawid } 692c5b2abe0SLewanczyk, Dawid }, 693c5b2abe0SLewanczyk, Dawid "xyz.openbmc_project.LED.GroupManager", 694a3002228SAppaRao Puli "/xyz/openbmc_project/led/groups/enclosure_identify", 695a3002228SAppaRao Puli "org.freedesktop.DBus.Properties", "Set", 696f847a198SAppaRao Puli "xyz.openbmc_project.Led.Group", "Asserted", 697f847a198SAppaRao Puli std::variant<bool>(ledOn)); 698a3002228SAppaRao Puli }, 699a3002228SAppaRao Puli "xyz.openbmc_project.LED.GroupManager", 700a3002228SAppaRao Puli "/xyz/openbmc_project/led/groups/enclosure_identify_blink", 701a3002228SAppaRao Puli "org.freedesktop.DBus.Properties", "Set", 702a3002228SAppaRao Puli "xyz.openbmc_project.Led.Group", "Asserted", 703a3002228SAppaRao Puli std::variant<bool>(ledBlinkng)); 704c5b2abe0SLewanczyk, Dawid } 705c5b2abe0SLewanczyk, Dawid 706c5b2abe0SLewanczyk, Dawid /** 707c5b2abe0SLewanczyk, Dawid * @brief Retrieves host state properties over dbus 708c5b2abe0SLewanczyk, Dawid * 709c5b2abe0SLewanczyk, Dawid * @param[in] aResp Shared pointer for completing asynchronous calls. 710c5b2abe0SLewanczyk, Dawid * 711c5b2abe0SLewanczyk, Dawid * @return None. 712c5b2abe0SLewanczyk, Dawid */ 713a0803efaSEd Tanous void getHostState(std::shared_ptr<AsyncResp> aResp) 7141abe55efSEd Tanous { 71555c7b7a2SEd Tanous BMCWEB_LOG_DEBUG << "Get host information."; 71655c7b7a2SEd Tanous crow::connections::systemBus->async_method_call( 717c5d03ff4SJennifer Lee [aResp](const boost::system::error_code ec, 718abf2add6SEd Tanous const std::variant<std::string> &hostState) { 7191abe55efSEd Tanous if (ec) 7201abe55efSEd Tanous { 72155c7b7a2SEd Tanous BMCWEB_LOG_DEBUG << "DBUS response error " << ec; 722f12894f8SJason M. Bills messages::internalError(aResp->res); 723c5b2abe0SLewanczyk, Dawid return; 724c5b2abe0SLewanczyk, Dawid } 7256617338dSEd Tanous 726abf2add6SEd Tanous const std::string *s = std::get_if<std::string>(&hostState); 72755c7b7a2SEd Tanous BMCWEB_LOG_DEBUG << "Host state: " << *s; 7286617338dSEd Tanous if (s != nullptr) 7291abe55efSEd Tanous { 730c5b2abe0SLewanczyk, Dawid // Verify Host State 73194732661SAndrew Geissler if (*s == "xyz.openbmc_project.State.Host.HostState.Running") 7321abe55efSEd Tanous { 73355c7b7a2SEd Tanous aResp->res.jsonValue["PowerState"] = "On"; 7346617338dSEd Tanous aResp->res.jsonValue["Status"]["State"] = "Enabled"; 7351abe55efSEd Tanous } 7361abe55efSEd Tanous else 7371abe55efSEd Tanous { 73855c7b7a2SEd Tanous aResp->res.jsonValue["PowerState"] = "Off"; 7396617338dSEd Tanous aResp->res.jsonValue["Status"]["State"] = "Disabled"; 740c5b2abe0SLewanczyk, Dawid } 741c5b2abe0SLewanczyk, Dawid } 742c5b2abe0SLewanczyk, Dawid }, 7436c34de48SEd Tanous "xyz.openbmc_project.State.Host", "/xyz/openbmc_project/state/host0", 7446617338dSEd Tanous "org.freedesktop.DBus.Properties", "Get", 7456617338dSEd Tanous "xyz.openbmc_project.State.Host", "CurrentHostState"); 746c5b2abe0SLewanczyk, Dawid } 747c5b2abe0SLewanczyk, Dawid 748c5b2abe0SLewanczyk, Dawid /** 749491d8ee7SSantosh Puranik * @brief Traslates boot source DBUS property value to redfish. 750491d8ee7SSantosh Puranik * 751491d8ee7SSantosh Puranik * @param[in] dbusSource The boot source in DBUS speak. 752491d8ee7SSantosh Puranik * 753491d8ee7SSantosh Puranik * @return Returns as a string, the boot source in Redfish terms. If translation 754491d8ee7SSantosh Puranik * cannot be done, returns an empty string. 755491d8ee7SSantosh Puranik */ 756491d8ee7SSantosh Puranik static std::string dbusToRfBootSource(const std::string &dbusSource) 757491d8ee7SSantosh Puranik { 758491d8ee7SSantosh Puranik if (dbusSource == "xyz.openbmc_project.Control.Boot.Source.Sources.Default") 759491d8ee7SSantosh Puranik { 760491d8ee7SSantosh Puranik return "None"; 761491d8ee7SSantosh Puranik } 762491d8ee7SSantosh Puranik else if (dbusSource == 763491d8ee7SSantosh Puranik "xyz.openbmc_project.Control.Boot.Source.Sources.Disk") 764491d8ee7SSantosh Puranik { 765491d8ee7SSantosh Puranik return "Hdd"; 766491d8ee7SSantosh Puranik } 767491d8ee7SSantosh Puranik else if (dbusSource == 768a71dc0b7SSantosh Puranik "xyz.openbmc_project.Control.Boot.Source.Sources.ExternalMedia") 769491d8ee7SSantosh Puranik { 770491d8ee7SSantosh Puranik return "Cd"; 771491d8ee7SSantosh Puranik } 772491d8ee7SSantosh Puranik else if (dbusSource == 773491d8ee7SSantosh Puranik "xyz.openbmc_project.Control.Boot.Source.Sources.Network") 774491d8ee7SSantosh Puranik { 775491d8ee7SSantosh Puranik return "Pxe"; 776491d8ee7SSantosh Puranik } 7779f16b2c1SJennifer Lee else if (dbusSource == 778944ffaf9SJohnathan Mantey "xyz.openbmc_project.Control.Boot.Source.Sources.RemovableMedia") 7799f16b2c1SJennifer Lee { 7809f16b2c1SJennifer Lee return "Usb"; 7819f16b2c1SJennifer Lee } 782491d8ee7SSantosh Puranik else 783491d8ee7SSantosh Puranik { 784491d8ee7SSantosh Puranik return ""; 785491d8ee7SSantosh Puranik } 786491d8ee7SSantosh Puranik } 787491d8ee7SSantosh Puranik 788491d8ee7SSantosh Puranik /** 789491d8ee7SSantosh Puranik * @brief Traslates boot mode DBUS property value to redfish. 790491d8ee7SSantosh Puranik * 791491d8ee7SSantosh Puranik * @param[in] dbusMode The boot mode in DBUS speak. 792491d8ee7SSantosh Puranik * 793491d8ee7SSantosh Puranik * @return Returns as a string, the boot mode in Redfish terms. If translation 794491d8ee7SSantosh Puranik * cannot be done, returns an empty string. 795491d8ee7SSantosh Puranik */ 796491d8ee7SSantosh Puranik static std::string dbusToRfBootMode(const std::string &dbusMode) 797491d8ee7SSantosh Puranik { 798491d8ee7SSantosh Puranik if (dbusMode == "xyz.openbmc_project.Control.Boot.Mode.Modes.Regular") 799491d8ee7SSantosh Puranik { 800491d8ee7SSantosh Puranik return "None"; 801491d8ee7SSantosh Puranik } 802491d8ee7SSantosh Puranik else if (dbusMode == "xyz.openbmc_project.Control.Boot.Mode.Modes.Safe") 803491d8ee7SSantosh Puranik { 804491d8ee7SSantosh Puranik return "Diags"; 805491d8ee7SSantosh Puranik } 806491d8ee7SSantosh Puranik else if (dbusMode == "xyz.openbmc_project.Control.Boot.Mode.Modes.Setup") 807491d8ee7SSantosh Puranik { 808491d8ee7SSantosh Puranik return "BiosSetup"; 809491d8ee7SSantosh Puranik } 810491d8ee7SSantosh Puranik else 811491d8ee7SSantosh Puranik { 812491d8ee7SSantosh Puranik return ""; 813491d8ee7SSantosh Puranik } 814491d8ee7SSantosh Puranik } 815491d8ee7SSantosh Puranik 816491d8ee7SSantosh Puranik /** 817944ffaf9SJohnathan Mantey * @brief Traslates boot source from Redfish to the DBus boot paths. 818491d8ee7SSantosh Puranik * 819491d8ee7SSantosh Puranik * @param[in] rfSource The boot source in Redfish. 820944ffaf9SJohnathan Mantey * @param[out] bootSource The DBus source 821944ffaf9SJohnathan Mantey * @param[out] bootMode the DBus boot mode 822491d8ee7SSantosh Puranik * 823944ffaf9SJohnathan Mantey * @return Integer error code. 824491d8ee7SSantosh Puranik */ 825944ffaf9SJohnathan Mantey static int assignBootParameters(std::shared_ptr<AsyncResp> aResp, 826944ffaf9SJohnathan Mantey const std::string &rfSource, 827944ffaf9SJohnathan Mantey std::string &bootSource, std::string &bootMode) 828491d8ee7SSantosh Puranik { 829944ffaf9SJohnathan Mantey // The caller has initialized the bootSource and bootMode to: 830944ffaf9SJohnathan Mantey // bootMode = "xyz.openbmc_project.Control.Boot.Mode.Modes.Regular"; 831944ffaf9SJohnathan Mantey // bootSource = "xyz.openbmc_project.Control.Boot.Source.Sources.Default"; 832944ffaf9SJohnathan Mantey // Only modify the bootSource/bootMode variable needed to achieve the 833944ffaf9SJohnathan Mantey // desired boot action. 834944ffaf9SJohnathan Mantey 835491d8ee7SSantosh Puranik if (rfSource == "None") 836491d8ee7SSantosh Puranik { 837944ffaf9SJohnathan Mantey return 0; 838491d8ee7SSantosh Puranik } 839491d8ee7SSantosh Puranik else if (rfSource == "Pxe") 840491d8ee7SSantosh Puranik { 841944ffaf9SJohnathan Mantey bootSource = "xyz.openbmc_project.Control.Boot.Source.Sources.Network"; 842944ffaf9SJohnathan Mantey } 843944ffaf9SJohnathan Mantey else if (rfSource == "Hdd") 844944ffaf9SJohnathan Mantey { 845944ffaf9SJohnathan Mantey bootSource = "xyz.openbmc_project.Control.Boot.Source.Sources.Disk"; 846944ffaf9SJohnathan Mantey } 847944ffaf9SJohnathan Mantey else if (rfSource == "Diags") 848944ffaf9SJohnathan Mantey { 849944ffaf9SJohnathan Mantey bootMode = "xyz.openbmc_project.Control.Boot.Mode.Modes.Safe"; 850944ffaf9SJohnathan Mantey } 851944ffaf9SJohnathan Mantey else if (rfSource == "Cd") 852944ffaf9SJohnathan Mantey { 853944ffaf9SJohnathan Mantey bootSource = 854944ffaf9SJohnathan Mantey "xyz.openbmc_project.Control.Boot.Source.Sources.ExternalMedia"; 855944ffaf9SJohnathan Mantey } 856944ffaf9SJohnathan Mantey else if (rfSource == "BiosSetup") 857944ffaf9SJohnathan Mantey { 858944ffaf9SJohnathan Mantey bootMode = "xyz.openbmc_project.Control.Boot.Mode.Modes.Setup"; 859491d8ee7SSantosh Puranik } 8609f16b2c1SJennifer Lee else if (rfSource == "Usb") 8619f16b2c1SJennifer Lee { 862944ffaf9SJohnathan Mantey bootSource = 863944ffaf9SJohnathan Mantey "xyz.openbmc_project.Control.Boot.Source.Sources.RemovableMedia"; 8649f16b2c1SJennifer Lee } 865491d8ee7SSantosh Puranik else 866491d8ee7SSantosh Puranik { 867944ffaf9SJohnathan Mantey BMCWEB_LOG_DEBUG << "Invalid property value for " 868944ffaf9SJohnathan Mantey "BootSourceOverrideTarget: " 869944ffaf9SJohnathan Mantey << bootSource; 870944ffaf9SJohnathan Mantey messages::propertyValueNotInList(aResp->res, rfSource, 871944ffaf9SJohnathan Mantey "BootSourceTargetOverride"); 872944ffaf9SJohnathan Mantey return -1; 873491d8ee7SSantosh Puranik } 874944ffaf9SJohnathan Mantey return 0; 875491d8ee7SSantosh Puranik } 876491d8ee7SSantosh Puranik 877491d8ee7SSantosh Puranik /** 878491d8ee7SSantosh Puranik * @brief Retrieves boot mode over DBUS and fills out the response 879491d8ee7SSantosh Puranik * 880491d8ee7SSantosh Puranik * @param[in] aResp Shared pointer for generating response message. 881491d8ee7SSantosh Puranik * @param[in] bootDbusObj The dbus object to query for boot properties. 882491d8ee7SSantosh Puranik * 883491d8ee7SSantosh Puranik * @return None. 884491d8ee7SSantosh Puranik */ 885491d8ee7SSantosh Puranik static void getBootMode(std::shared_ptr<AsyncResp> aResp, 886491d8ee7SSantosh Puranik std::string bootDbusObj) 887491d8ee7SSantosh Puranik { 888491d8ee7SSantosh Puranik crow::connections::systemBus->async_method_call( 889491d8ee7SSantosh Puranik [aResp](const boost::system::error_code ec, 890491d8ee7SSantosh Puranik const std::variant<std::string> &bootMode) { 891491d8ee7SSantosh Puranik if (ec) 892491d8ee7SSantosh Puranik { 893491d8ee7SSantosh Puranik BMCWEB_LOG_DEBUG << "DBUS response error " << ec; 894491d8ee7SSantosh Puranik messages::internalError(aResp->res); 895491d8ee7SSantosh Puranik return; 896491d8ee7SSantosh Puranik } 897491d8ee7SSantosh Puranik 898491d8ee7SSantosh Puranik const std::string *bootModeStr = 899491d8ee7SSantosh Puranik std::get_if<std::string>(&bootMode); 900491d8ee7SSantosh Puranik 901491d8ee7SSantosh Puranik if (!bootModeStr) 902491d8ee7SSantosh Puranik { 903491d8ee7SSantosh Puranik messages::internalError(aResp->res); 904491d8ee7SSantosh Puranik return; 905491d8ee7SSantosh Puranik } 906491d8ee7SSantosh Puranik 907491d8ee7SSantosh Puranik BMCWEB_LOG_DEBUG << "Boot mode: " << *bootModeStr; 908491d8ee7SSantosh Puranik 909491d8ee7SSantosh Puranik // TODO (Santosh): Do we need to support override mode? 910491d8ee7SSantosh Puranik aResp->res.jsonValue["Boot"]["BootSourceOverrideMode"] = "Legacy"; 911491d8ee7SSantosh Puranik aResp->res.jsonValue["Boot"]["BootSourceOverrideTarget@Redfish." 912491d8ee7SSantosh Puranik "AllowableValues"] = { 913944ffaf9SJohnathan Mantey "None", "Pxe", "Hdd", "Cd", "Diags", "BiosSetup", "Usb"}; 914491d8ee7SSantosh Puranik 915491d8ee7SSantosh Puranik if (*bootModeStr != 916491d8ee7SSantosh Puranik "xyz.openbmc_project.Control.Boot.Mode.Modes.Regular") 917491d8ee7SSantosh Puranik { 918491d8ee7SSantosh Puranik auto rfMode = dbusToRfBootMode(*bootModeStr); 919491d8ee7SSantosh Puranik if (!rfMode.empty()) 920491d8ee7SSantosh Puranik { 921491d8ee7SSantosh Puranik aResp->res.jsonValue["Boot"]["BootSourceOverrideTarget"] = 922491d8ee7SSantosh Puranik rfMode; 923491d8ee7SSantosh Puranik } 924491d8ee7SSantosh Puranik } 925491d8ee7SSantosh Puranik 926491d8ee7SSantosh Puranik // If the BootSourceOverrideTarget is still "None" at the end, 927491d8ee7SSantosh Puranik // reset the BootSourceOverrideEnabled to indicate that 928491d8ee7SSantosh Puranik // overrides are disabled 929491d8ee7SSantosh Puranik if (aResp->res.jsonValue["Boot"]["BootSourceOverrideTarget"] == 930491d8ee7SSantosh Puranik "None") 931491d8ee7SSantosh Puranik { 932491d8ee7SSantosh Puranik aResp->res.jsonValue["Boot"]["BootSourceOverrideEnabled"] = 933491d8ee7SSantosh Puranik "Disabled"; 934491d8ee7SSantosh Puranik } 935491d8ee7SSantosh Puranik }, 936491d8ee7SSantosh Puranik "xyz.openbmc_project.Settings", bootDbusObj, 937491d8ee7SSantosh Puranik "org.freedesktop.DBus.Properties", "Get", 938491d8ee7SSantosh Puranik "xyz.openbmc_project.Control.Boot.Mode", "BootMode"); 939491d8ee7SSantosh Puranik } 940491d8ee7SSantosh Puranik 941491d8ee7SSantosh Puranik /** 942491d8ee7SSantosh Puranik * @brief Retrieves boot source over DBUS 943491d8ee7SSantosh Puranik * 944491d8ee7SSantosh Puranik * @param[in] aResp Shared pointer for generating response message. 945491d8ee7SSantosh Puranik * @param[in] oneTimeEnable Boolean to indicate boot properties are one-time. 946491d8ee7SSantosh Puranik * 947491d8ee7SSantosh Puranik * @return None. 948491d8ee7SSantosh Puranik */ 949491d8ee7SSantosh Puranik static void getBootSource(std::shared_ptr<AsyncResp> aResp, bool oneTimeEnabled) 950491d8ee7SSantosh Puranik { 951491d8ee7SSantosh Puranik std::string bootDbusObj = 952491d8ee7SSantosh Puranik oneTimeEnabled ? "/xyz/openbmc_project/control/host0/boot/one_time" 953491d8ee7SSantosh Puranik : "/xyz/openbmc_project/control/host0/boot"; 954491d8ee7SSantosh Puranik 955491d8ee7SSantosh Puranik BMCWEB_LOG_DEBUG << "Is one time: " << oneTimeEnabled; 956491d8ee7SSantosh Puranik aResp->res.jsonValue["Boot"]["BootSourceOverrideEnabled"] = 957491d8ee7SSantosh Puranik (oneTimeEnabled) ? "Once" : "Continuous"; 958491d8ee7SSantosh Puranik 959491d8ee7SSantosh Puranik crow::connections::systemBus->async_method_call( 960491d8ee7SSantosh Puranik [aResp, bootDbusObj](const boost::system::error_code ec, 961491d8ee7SSantosh Puranik const std::variant<std::string> &bootSource) { 962491d8ee7SSantosh Puranik if (ec) 963491d8ee7SSantosh Puranik { 964491d8ee7SSantosh Puranik BMCWEB_LOG_DEBUG << "DBUS response error " << ec; 965491d8ee7SSantosh Puranik messages::internalError(aResp->res); 966491d8ee7SSantosh Puranik return; 967491d8ee7SSantosh Puranik } 968491d8ee7SSantosh Puranik 969491d8ee7SSantosh Puranik const std::string *bootSourceStr = 970491d8ee7SSantosh Puranik std::get_if<std::string>(&bootSource); 971491d8ee7SSantosh Puranik 972491d8ee7SSantosh Puranik if (!bootSourceStr) 973491d8ee7SSantosh Puranik { 974491d8ee7SSantosh Puranik messages::internalError(aResp->res); 975491d8ee7SSantosh Puranik return; 976491d8ee7SSantosh Puranik } 977491d8ee7SSantosh Puranik BMCWEB_LOG_DEBUG << "Boot source: " << *bootSourceStr; 978491d8ee7SSantosh Puranik 979491d8ee7SSantosh Puranik auto rfSource = dbusToRfBootSource(*bootSourceStr); 980491d8ee7SSantosh Puranik if (!rfSource.empty()) 981491d8ee7SSantosh Puranik { 982491d8ee7SSantosh Puranik aResp->res.jsonValue["Boot"]["BootSourceOverrideTarget"] = 983491d8ee7SSantosh Puranik rfSource; 984491d8ee7SSantosh Puranik } 985491d8ee7SSantosh Puranik }, 986491d8ee7SSantosh Puranik "xyz.openbmc_project.Settings", bootDbusObj, 987491d8ee7SSantosh Puranik "org.freedesktop.DBus.Properties", "Get", 988491d8ee7SSantosh Puranik "xyz.openbmc_project.Control.Boot.Source", "BootSource"); 989491d8ee7SSantosh Puranik getBootMode(std::move(aResp), std::move(bootDbusObj)); 990491d8ee7SSantosh Puranik } 991491d8ee7SSantosh Puranik 992491d8ee7SSantosh Puranik /** 993491d8ee7SSantosh Puranik * @brief Retrieves "One time" enabled setting over DBUS and calls function to 994491d8ee7SSantosh Puranik * get boot source and boot mode. 995491d8ee7SSantosh Puranik * 996491d8ee7SSantosh Puranik * @param[in] aResp Shared pointer for generating response message. 997491d8ee7SSantosh Puranik * 998491d8ee7SSantosh Puranik * @return None. 999491d8ee7SSantosh Puranik */ 1000491d8ee7SSantosh Puranik static void getBootProperties(std::shared_ptr<AsyncResp> aResp) 1001491d8ee7SSantosh Puranik { 1002491d8ee7SSantosh Puranik BMCWEB_LOG_DEBUG << "Get boot information."; 1003491d8ee7SSantosh Puranik 1004491d8ee7SSantosh Puranik crow::connections::systemBus->async_method_call( 1005c5d03ff4SJennifer Lee [aResp](const boost::system::error_code ec, 1006491d8ee7SSantosh Puranik const sdbusplus::message::variant<bool> &oneTime) { 1007491d8ee7SSantosh Puranik if (ec) 1008491d8ee7SSantosh Puranik { 1009491d8ee7SSantosh Puranik BMCWEB_LOG_DEBUG << "DBUS response error " << ec; 10102a833c77SJames Feist // not an error, don't have to have the interface 1011491d8ee7SSantosh Puranik return; 1012491d8ee7SSantosh Puranik } 1013491d8ee7SSantosh Puranik 1014491d8ee7SSantosh Puranik const bool *oneTimePtr = std::get_if<bool>(&oneTime); 1015491d8ee7SSantosh Puranik 1016491d8ee7SSantosh Puranik if (!oneTimePtr) 1017491d8ee7SSantosh Puranik { 1018491d8ee7SSantosh Puranik messages::internalError(aResp->res); 1019491d8ee7SSantosh Puranik return; 1020491d8ee7SSantosh Puranik } 1021491d8ee7SSantosh Puranik getBootSource(aResp, *oneTimePtr); 1022491d8ee7SSantosh Puranik }, 1023491d8ee7SSantosh Puranik "xyz.openbmc_project.Settings", 1024491d8ee7SSantosh Puranik "/xyz/openbmc_project/control/host0/boot/one_time", 1025491d8ee7SSantosh Puranik "org.freedesktop.DBus.Properties", "Get", 1026491d8ee7SSantosh Puranik "xyz.openbmc_project.Object.Enable", "Enabled"); 1027491d8ee7SSantosh Puranik } 1028491d8ee7SSantosh Puranik 1029491d8ee7SSantosh Puranik /** 1030491d8ee7SSantosh Puranik * @brief Sets boot properties into DBUS object(s). 1031491d8ee7SSantosh Puranik * 1032491d8ee7SSantosh Puranik * @param[in] aResp Shared pointer for generating response message. 1033491d8ee7SSantosh Puranik * @param[in] oneTimeEnabled Is "one-time" setting already enabled. 1034491d8ee7SSantosh Puranik * @param[in] bootSource The boot source to set. 1035491d8ee7SSantosh Puranik * @param[in] bootEnable The source override "enable" to set. 1036491d8ee7SSantosh Puranik * 1037265c1602SJohnathan Mantey * @return Integer error code. 1038491d8ee7SSantosh Puranik */ 1039491d8ee7SSantosh Puranik static void setBootModeOrSource(std::shared_ptr<AsyncResp> aResp, 1040491d8ee7SSantosh Puranik bool oneTimeEnabled, 1041491d8ee7SSantosh Puranik std::optional<std::string> bootSource, 1042491d8ee7SSantosh Puranik std::optional<std::string> bootEnable) 1043491d8ee7SSantosh Puranik { 1044944ffaf9SJohnathan Mantey std::string bootSourceStr = 1045944ffaf9SJohnathan Mantey "xyz.openbmc_project.Control.Boot.Source.Sources.Default"; 1046944ffaf9SJohnathan Mantey std::string bootModeStr = 1047944ffaf9SJohnathan Mantey "xyz.openbmc_project.Control.Boot.Mode.Modes.Regular"; 1048491d8ee7SSantosh Puranik bool oneTimeSetting = oneTimeEnabled; 1049944ffaf9SJohnathan Mantey bool useBootSource = true; 1050944ffaf9SJohnathan Mantey 1051491d8ee7SSantosh Puranik // Validate incoming parameters 1052491d8ee7SSantosh Puranik if (bootEnable) 1053491d8ee7SSantosh Puranik { 1054491d8ee7SSantosh Puranik if (*bootEnable == "Once") 1055491d8ee7SSantosh Puranik { 1056491d8ee7SSantosh Puranik oneTimeSetting = true; 1057491d8ee7SSantosh Puranik } 1058491d8ee7SSantosh Puranik else if (*bootEnable == "Continuous") 1059491d8ee7SSantosh Puranik { 1060491d8ee7SSantosh Puranik oneTimeSetting = false; 1061491d8ee7SSantosh Puranik } 1062491d8ee7SSantosh Puranik else if (*bootEnable == "Disabled") 1063491d8ee7SSantosh Puranik { 1064944ffaf9SJohnathan Mantey BMCWEB_LOG_DEBUG << "Boot source override will be disabled"; 1065491d8ee7SSantosh Puranik oneTimeSetting = false; 1066944ffaf9SJohnathan Mantey useBootSource = false; 1067491d8ee7SSantosh Puranik } 1068491d8ee7SSantosh Puranik else 1069491d8ee7SSantosh Puranik { 1070491d8ee7SSantosh Puranik BMCWEB_LOG_DEBUG << "Unsupported value for " 1071491d8ee7SSantosh Puranik "BootSourceOverrideEnabled: " 1072491d8ee7SSantosh Puranik << *bootEnable; 1073491d8ee7SSantosh Puranik messages::propertyValueNotInList(aResp->res, *bootEnable, 1074491d8ee7SSantosh Puranik "BootSourceOverrideEnabled"); 1075491d8ee7SSantosh Puranik return; 1076491d8ee7SSantosh Puranik } 1077491d8ee7SSantosh Puranik } 1078491d8ee7SSantosh Puranik 1079944ffaf9SJohnathan Mantey if (bootSource && useBootSource) 1080491d8ee7SSantosh Puranik { 1081491d8ee7SSantosh Puranik // Source target specified 1082491d8ee7SSantosh Puranik BMCWEB_LOG_DEBUG << "Boot source: " << *bootSource; 1083491d8ee7SSantosh Puranik // Figure out which DBUS interface and property to use 1084944ffaf9SJohnathan Mantey if (assignBootParameters(aResp, *bootSource, bootSourceStr, 1085944ffaf9SJohnathan Mantey bootModeStr)) 1086491d8ee7SSantosh Puranik { 1087944ffaf9SJohnathan Mantey BMCWEB_LOG_DEBUG 1088944ffaf9SJohnathan Mantey << "Invalid property value for BootSourceOverrideTarget: " 1089491d8ee7SSantosh Puranik << *bootSource; 1090491d8ee7SSantosh Puranik messages::propertyValueNotInList(aResp->res, *bootSource, 1091491d8ee7SSantosh Puranik "BootSourceTargetOverride"); 1092491d8ee7SSantosh Puranik return; 1093491d8ee7SSantosh Puranik } 1094944ffaf9SJohnathan Mantey } 1095491d8ee7SSantosh Puranik 1096944ffaf9SJohnathan Mantey // Act on validated parameters 1097944ffaf9SJohnathan Mantey BMCWEB_LOG_DEBUG << "DBUS boot source: " << bootSourceStr; 1098944ffaf9SJohnathan Mantey BMCWEB_LOG_DEBUG << "DBUS boot mode: " << bootModeStr; 1099944ffaf9SJohnathan Mantey const char *bootObj = 1100944ffaf9SJohnathan Mantey oneTimeSetting ? "/xyz/openbmc_project/control/host0/boot/one_time" 1101944ffaf9SJohnathan Mantey : "/xyz/openbmc_project/control/host0/boot"; 1102944ffaf9SJohnathan Mantey 1103491d8ee7SSantosh Puranik crow::connections::systemBus->async_method_call( 1104491d8ee7SSantosh Puranik [aResp](const boost::system::error_code ec) { 1105491d8ee7SSantosh Puranik if (ec) 1106491d8ee7SSantosh Puranik { 1107491d8ee7SSantosh Puranik BMCWEB_LOG_DEBUG << "DBUS response error " << ec; 1108491d8ee7SSantosh Puranik messages::internalError(aResp->res); 1109491d8ee7SSantosh Puranik return; 1110491d8ee7SSantosh Puranik } 1111491d8ee7SSantosh Puranik BMCWEB_LOG_DEBUG << "Boot source update done."; 1112491d8ee7SSantosh Puranik }, 1113491d8ee7SSantosh Puranik "xyz.openbmc_project.Settings", bootObj, 1114491d8ee7SSantosh Puranik "org.freedesktop.DBus.Properties", "Set", 1115491d8ee7SSantosh Puranik "xyz.openbmc_project.Control.Boot.Source", "BootSource", 1116491d8ee7SSantosh Puranik std::variant<std::string>(bootSourceStr)); 1117944ffaf9SJohnathan Mantey 1118491d8ee7SSantosh Puranik crow::connections::systemBus->async_method_call( 1119491d8ee7SSantosh Puranik [aResp](const boost::system::error_code ec) { 1120491d8ee7SSantosh Puranik if (ec) 1121491d8ee7SSantosh Puranik { 1122491d8ee7SSantosh Puranik BMCWEB_LOG_DEBUG << "DBUS response error " << ec; 1123491d8ee7SSantosh Puranik messages::internalError(aResp->res); 1124491d8ee7SSantosh Puranik return; 1125491d8ee7SSantosh Puranik } 1126491d8ee7SSantosh Puranik BMCWEB_LOG_DEBUG << "Boot mode update done."; 1127491d8ee7SSantosh Puranik }, 1128491d8ee7SSantosh Puranik "xyz.openbmc_project.Settings", bootObj, 1129491d8ee7SSantosh Puranik "org.freedesktop.DBus.Properties", "Set", 1130491d8ee7SSantosh Puranik "xyz.openbmc_project.Control.Boot.Mode", "BootMode", 1131491d8ee7SSantosh Puranik std::variant<std::string>(bootModeStr)); 1132944ffaf9SJohnathan Mantey 1133491d8ee7SSantosh Puranik crow::connections::systemBus->async_method_call( 1134491d8ee7SSantosh Puranik [aResp{std::move(aResp)}](const boost::system::error_code ec) { 1135491d8ee7SSantosh Puranik if (ec) 1136491d8ee7SSantosh Puranik { 1137491d8ee7SSantosh Puranik BMCWEB_LOG_DEBUG << "DBUS response error " << ec; 1138491d8ee7SSantosh Puranik messages::internalError(aResp->res); 1139491d8ee7SSantosh Puranik return; 1140491d8ee7SSantosh Puranik } 1141491d8ee7SSantosh Puranik BMCWEB_LOG_DEBUG << "Boot enable update done."; 1142491d8ee7SSantosh Puranik }, 1143491d8ee7SSantosh Puranik "xyz.openbmc_project.Settings", 1144491d8ee7SSantosh Puranik "/xyz/openbmc_project/control/host0/boot/one_time", 1145491d8ee7SSantosh Puranik "org.freedesktop.DBus.Properties", "Set", 1146491d8ee7SSantosh Puranik "xyz.openbmc_project.Object.Enable", "Enabled", 1147491d8ee7SSantosh Puranik std::variant<bool>(oneTimeSetting)); 1148491d8ee7SSantosh Puranik } 1149491d8ee7SSantosh Puranik 1150491d8ee7SSantosh Puranik /** 1151491d8ee7SSantosh Puranik * @brief Retrieves "One time" enabled setting over DBUS and calls function to 1152491d8ee7SSantosh Puranik * set boot source/boot mode properties. 1153491d8ee7SSantosh Puranik * 1154491d8ee7SSantosh Puranik * @param[in] aResp Shared pointer for generating response message. 1155491d8ee7SSantosh Puranik * @param[in] bootSource The boot source from incoming RF request. 1156491d8ee7SSantosh Puranik * @param[in] bootEnable The boot override enable from incoming RF request. 1157491d8ee7SSantosh Puranik * 1158265c1602SJohnathan Mantey * @return Integer error code. 1159491d8ee7SSantosh Puranik */ 1160491d8ee7SSantosh Puranik static void setBootProperties(std::shared_ptr<AsyncResp> aResp, 1161491d8ee7SSantosh Puranik std::optional<std::string> bootSource, 1162491d8ee7SSantosh Puranik std::optional<std::string> bootEnable) 1163491d8ee7SSantosh Puranik { 1164491d8ee7SSantosh Puranik BMCWEB_LOG_DEBUG << "Set boot information."; 1165491d8ee7SSantosh Puranik 1166491d8ee7SSantosh Puranik crow::connections::systemBus->async_method_call( 1167265c1602SJohnathan Mantey [aResp, bootSource{std::move(bootSource)}, 1168491d8ee7SSantosh Puranik bootEnable{std::move(bootEnable)}]( 1169491d8ee7SSantosh Puranik const boost::system::error_code ec, 1170491d8ee7SSantosh Puranik const sdbusplus::message::variant<bool> &oneTime) { 1171491d8ee7SSantosh Puranik if (ec) 1172491d8ee7SSantosh Puranik { 1173491d8ee7SSantosh Puranik BMCWEB_LOG_DEBUG << "DBUS response error " << ec; 1174491d8ee7SSantosh Puranik messages::internalError(aResp->res); 1175491d8ee7SSantosh Puranik return; 1176491d8ee7SSantosh Puranik } 1177491d8ee7SSantosh Puranik 1178491d8ee7SSantosh Puranik const bool *oneTimePtr = std::get_if<bool>(&oneTime); 1179491d8ee7SSantosh Puranik 1180491d8ee7SSantosh Puranik if (!oneTimePtr) 1181491d8ee7SSantosh Puranik { 1182491d8ee7SSantosh Puranik messages::internalError(aResp->res); 1183491d8ee7SSantosh Puranik return; 1184491d8ee7SSantosh Puranik } 1185491d8ee7SSantosh Puranik 1186491d8ee7SSantosh Puranik BMCWEB_LOG_DEBUG << "Got one time: " << *oneTimePtr; 1187491d8ee7SSantosh Puranik 1188491d8ee7SSantosh Puranik setBootModeOrSource(aResp, *oneTimePtr, std::move(bootSource), 1189491d8ee7SSantosh Puranik std::move(bootEnable)); 1190491d8ee7SSantosh Puranik }, 1191491d8ee7SSantosh Puranik "xyz.openbmc_project.Settings", 1192491d8ee7SSantosh Puranik "/xyz/openbmc_project/control/host0/boot/one_time", 1193491d8ee7SSantosh Puranik "org.freedesktop.DBus.Properties", "Get", 1194491d8ee7SSantosh Puranik "xyz.openbmc_project.Object.Enable", "Enabled"); 1195491d8ee7SSantosh Puranik } 1196491d8ee7SSantosh Puranik 1197a6349918SAppaRao Puli #ifdef BMCWEB_ENABLE_REDFISH_PROVISIONING_FEATURE 1198a6349918SAppaRao Puli /** 1199a6349918SAppaRao Puli * @brief Retrieves provisioning status 1200a6349918SAppaRao Puli * 1201a6349918SAppaRao Puli * @param[in] aResp Shared pointer for completing asynchronous calls. 1202a6349918SAppaRao Puli * 1203a6349918SAppaRao Puli * @return None. 1204a6349918SAppaRao Puli */ 1205a6349918SAppaRao Puli void getProvisioningStatus(std::shared_ptr<AsyncResp> aResp) 1206a6349918SAppaRao Puli { 1207a6349918SAppaRao Puli BMCWEB_LOG_DEBUG << "Get OEM information."; 1208a6349918SAppaRao Puli crow::connections::systemBus->async_method_call( 1209a6349918SAppaRao Puli [aResp](const boost::system::error_code ec, 1210a6349918SAppaRao Puli const std::vector<std::pair<std::string, VariantType>> 1211a6349918SAppaRao Puli &propertiesList) { 1212a6349918SAppaRao Puli if (ec) 1213a6349918SAppaRao Puli { 1214a6349918SAppaRao Puli BMCWEB_LOG_DEBUG << "DBUS response error " << ec; 1215a6349918SAppaRao Puli messages::internalError(aResp->res); 1216a6349918SAppaRao Puli return; 1217a6349918SAppaRao Puli } 1218a6349918SAppaRao Puli 1219a6349918SAppaRao Puli const bool *provState = nullptr; 1220a6349918SAppaRao Puli const bool *lockState = nullptr; 1221a6349918SAppaRao Puli for (const std::pair<std::string, VariantType> &property : 1222a6349918SAppaRao Puli propertiesList) 1223a6349918SAppaRao Puli { 1224a6349918SAppaRao Puli if (property.first == "UfmProvisioned") 1225a6349918SAppaRao Puli { 1226a6349918SAppaRao Puli provState = std::get_if<bool>(&property.second); 1227a6349918SAppaRao Puli } 1228a6349918SAppaRao Puli else if (property.first == "UfmLocked") 1229a6349918SAppaRao Puli { 1230a6349918SAppaRao Puli lockState = std::get_if<bool>(&property.second); 1231a6349918SAppaRao Puli } 1232a6349918SAppaRao Puli } 1233a6349918SAppaRao Puli 1234a6349918SAppaRao Puli if ((provState == nullptr) || (lockState == nullptr)) 1235a6349918SAppaRao Puli { 1236a6349918SAppaRao Puli BMCWEB_LOG_DEBUG << "Unable to get PFR attributes."; 1237a6349918SAppaRao Puli messages::internalError(aResp->res); 1238a6349918SAppaRao Puli return; 1239a6349918SAppaRao Puli } 1240a6349918SAppaRao Puli 1241a6349918SAppaRao Puli nlohmann::json &oemPFR = 1242a6349918SAppaRao Puli aResp->res.jsonValue["Oem"]["OpenBmc"]["FirmwareProvisioning"]; 1243a6349918SAppaRao Puli if (*provState == true) 1244a6349918SAppaRao Puli { 1245a6349918SAppaRao Puli if (*lockState == true) 1246a6349918SAppaRao Puli { 1247a6349918SAppaRao Puli oemPFR["ProvisioningStatus"] = "ProvisionedAndLocked"; 1248a6349918SAppaRao Puli } 1249a6349918SAppaRao Puli else 1250a6349918SAppaRao Puli { 1251a6349918SAppaRao Puli oemPFR["ProvisioningStatus"] = "ProvisionedButNotLocked"; 1252a6349918SAppaRao Puli } 1253a6349918SAppaRao Puli } 1254a6349918SAppaRao Puli else 1255a6349918SAppaRao Puli { 1256a6349918SAppaRao Puli oemPFR["ProvisioningStatus"] = "NotProvisioned"; 1257a6349918SAppaRao Puli } 1258a6349918SAppaRao Puli }, 1259a6349918SAppaRao Puli "xyz.openbmc_project.PFR.Manager", "/xyz/openbmc_project/pfr", 1260a6349918SAppaRao Puli "org.freedesktop.DBus.Properties", "GetAll", 1261a6349918SAppaRao Puli "xyz.openbmc_project.PFR.Attributes"); 1262a6349918SAppaRao Puli } 1263a6349918SAppaRao Puli #endif 1264a6349918SAppaRao Puli 1265491d8ee7SSantosh Puranik /** 126651709ffdSYong Li * @brief Translates watchdog timeout action DBUS property value to redfish. 126751709ffdSYong Li * 126851709ffdSYong Li * @param[in] dbusAction The watchdog timeout action in D-BUS. 126951709ffdSYong Li * 127051709ffdSYong Li * @return Returns as a string, the timeout action in Redfish terms. If 127151709ffdSYong Li * translation cannot be done, returns an empty string. 127251709ffdSYong Li */ 127351709ffdSYong Li static std::string dbusToRfWatchdogAction(const std::string &dbusAction) 127451709ffdSYong Li { 127551709ffdSYong Li if (dbusAction == "xyz.openbmc_project.State.Watchdog.Action.None") 127651709ffdSYong Li { 127751709ffdSYong Li return "None"; 127851709ffdSYong Li } 127951709ffdSYong Li else if (dbusAction == 128051709ffdSYong Li "xyz.openbmc_project.State.Watchdog.Action.HardReset") 128151709ffdSYong Li { 128251709ffdSYong Li return "ResetSystem"; 128351709ffdSYong Li } 128451709ffdSYong Li else if (dbusAction == "xyz.openbmc_project.State.Watchdog.Action.PowerOff") 128551709ffdSYong Li { 128651709ffdSYong Li return "PowerDown"; 128751709ffdSYong Li } 128851709ffdSYong Li else if (dbusAction == 128951709ffdSYong Li "xyz.openbmc_project.State.Watchdog.Action.PowerCycle") 129051709ffdSYong Li { 129151709ffdSYong Li return "PowerCycle"; 129251709ffdSYong Li } 129351709ffdSYong Li 129451709ffdSYong Li return ""; 129551709ffdSYong Li } 129651709ffdSYong Li 129751709ffdSYong Li /** 1298c45f0082SYong Li *@brief Translates timeout action from Redfish to DBUS property value. 1299c45f0082SYong Li * 1300c45f0082SYong Li *@param[in] rfAction The timeout action in Redfish. 1301c45f0082SYong Li * 1302c45f0082SYong Li *@return Returns as a string, the time_out action as expected by DBUS. 1303c45f0082SYong Li *If translation cannot be done, returns an empty string. 1304c45f0082SYong Li */ 1305c45f0082SYong Li 1306c45f0082SYong Li static std::string rfToDbusWDTTimeOutAct(const std::string &rfAction) 1307c45f0082SYong Li { 1308c45f0082SYong Li if (rfAction == "None") 1309c45f0082SYong Li { 1310c45f0082SYong Li return "xyz.openbmc_project.State.Watchdog.Action.None"; 1311c45f0082SYong Li } 1312c45f0082SYong Li else if (rfAction == "PowerCycle") 1313c45f0082SYong Li { 1314c45f0082SYong Li return "xyz.openbmc_project.State.Watchdog.Action.PowerCycle"; 1315c45f0082SYong Li } 1316c45f0082SYong Li else if (rfAction == "PowerDown") 1317c45f0082SYong Li { 1318c45f0082SYong Li return "xyz.openbmc_project.State.Watchdog.Action.PowerOff"; 1319c45f0082SYong Li } 1320c45f0082SYong Li else if (rfAction == "ResetSystem") 1321c45f0082SYong Li { 1322c45f0082SYong Li return "xyz.openbmc_project.State.Watchdog.Action.HardReset"; 1323c45f0082SYong Li } 1324c45f0082SYong Li 1325c45f0082SYong Li return ""; 1326c45f0082SYong Li } 1327c45f0082SYong Li 1328c45f0082SYong Li /** 132951709ffdSYong Li * @brief Retrieves host watchdog timer properties over DBUS 133051709ffdSYong Li * 133151709ffdSYong Li * @param[in] aResp Shared pointer for completing asynchronous calls. 133251709ffdSYong Li * 133351709ffdSYong Li * @return None. 133451709ffdSYong Li */ 133551709ffdSYong Li void getHostWatchdogTimer(std::shared_ptr<AsyncResp> aResp) 133651709ffdSYong Li { 133751709ffdSYong Li BMCWEB_LOG_DEBUG << "Get host watchodg"; 133851709ffdSYong Li crow::connections::systemBus->async_method_call( 133951709ffdSYong Li [aResp](const boost::system::error_code ec, 134051709ffdSYong Li PropertiesType &properties) { 134151709ffdSYong Li if (ec) 134251709ffdSYong Li { 134351709ffdSYong Li // watchdog service is stopped 134451709ffdSYong Li BMCWEB_LOG_DEBUG << "DBUS response error " << ec; 134551709ffdSYong Li return; 134651709ffdSYong Li } 134751709ffdSYong Li 134851709ffdSYong Li BMCWEB_LOG_DEBUG << "Got " << properties.size() << " wdt prop."; 134951709ffdSYong Li 135051709ffdSYong Li nlohmann::json &hostWatchdogTimer = 135151709ffdSYong Li aResp->res.jsonValue["HostWatchdogTimer"]; 135251709ffdSYong Li 135351709ffdSYong Li // watchdog service is running/enabled 135451709ffdSYong Li hostWatchdogTimer["Status"]["State"] = "Enabled"; 135551709ffdSYong Li 135651709ffdSYong Li for (const auto &property : properties) 135751709ffdSYong Li { 135851709ffdSYong Li BMCWEB_LOG_DEBUG << "prop=" << property.first; 135951709ffdSYong Li if (property.first == "Enabled") 136051709ffdSYong Li { 136151709ffdSYong Li const bool *state = std::get_if<bool>(&property.second); 136251709ffdSYong Li 136351709ffdSYong Li if (!state) 136451709ffdSYong Li { 136551709ffdSYong Li messages::internalError(aResp->res); 136651709ffdSYong Li continue; 136751709ffdSYong Li } 136851709ffdSYong Li 136951709ffdSYong Li hostWatchdogTimer["FunctionEnabled"] = *state; 137051709ffdSYong Li } 137151709ffdSYong Li else if (property.first == "ExpireAction") 137251709ffdSYong Li { 137351709ffdSYong Li const std::string *s = 137451709ffdSYong Li std::get_if<std::string>(&property.second); 137551709ffdSYong Li if (!s) 137651709ffdSYong Li { 137751709ffdSYong Li messages::internalError(aResp->res); 137851709ffdSYong Li continue; 137951709ffdSYong Li } 138051709ffdSYong Li 138151709ffdSYong Li std::string action = dbusToRfWatchdogAction(*s); 138251709ffdSYong Li if (action.empty()) 138351709ffdSYong Li { 138451709ffdSYong Li messages::internalError(aResp->res); 138551709ffdSYong Li continue; 138651709ffdSYong Li } 138751709ffdSYong Li hostWatchdogTimer["TimeoutAction"] = action; 138851709ffdSYong Li } 138951709ffdSYong Li } 139051709ffdSYong Li }, 139151709ffdSYong Li "xyz.openbmc_project.Watchdog", "/xyz/openbmc_project/watchdog/host0", 139251709ffdSYong Li "org.freedesktop.DBus.Properties", "GetAll", 139351709ffdSYong Li "xyz.openbmc_project.State.Watchdog"); 139451709ffdSYong Li } 139551709ffdSYong Li 139651709ffdSYong Li /** 1397c45f0082SYong Li * @brief Sets Host WatchDog Timer properties. 1398c45f0082SYong Li * 1399c45f0082SYong Li * @param[in] aResp Shared pointer for generating response message. 1400c45f0082SYong Li * @param[in] wdtEnable The WDTimer Enable value (true/false) from incoming 1401c45f0082SYong Li * RF request. 1402c45f0082SYong Li * @param[in] wdtTimeOutAction The WDT Timeout action, from incoming RF request. 1403c45f0082SYong Li * 1404c45f0082SYong Li * @return None. 1405c45f0082SYong Li */ 1406c45f0082SYong Li static void setWDTProperties(std::shared_ptr<AsyncResp> aResp, 1407c45f0082SYong Li const std::optional<bool> wdtEnable, 1408c45f0082SYong Li const std::optional<std::string> &wdtTimeOutAction) 1409c45f0082SYong Li { 1410c45f0082SYong Li BMCWEB_LOG_DEBUG << "Set host watchdog"; 1411c45f0082SYong Li 1412c45f0082SYong Li if (wdtTimeOutAction) 1413c45f0082SYong Li { 1414c45f0082SYong Li std::string wdtTimeOutActStr = rfToDbusWDTTimeOutAct(*wdtTimeOutAction); 1415c45f0082SYong Li // check if TimeOut Action is Valid 1416c45f0082SYong Li if (wdtTimeOutActStr.empty()) 1417c45f0082SYong Li { 1418c45f0082SYong Li BMCWEB_LOG_DEBUG << "Unsupported value for TimeoutAction: " 1419c45f0082SYong Li << *wdtTimeOutAction; 1420c45f0082SYong Li messages::propertyValueNotInList(aResp->res, *wdtTimeOutAction, 1421c45f0082SYong Li "TimeoutAction"); 1422c45f0082SYong Li return; 1423c45f0082SYong Li } 1424c45f0082SYong Li 1425c45f0082SYong Li crow::connections::systemBus->async_method_call( 1426c45f0082SYong Li [aResp](const boost::system::error_code ec) { 1427c45f0082SYong Li if (ec) 1428c45f0082SYong Li { 1429c45f0082SYong Li BMCWEB_LOG_DEBUG << "DBUS response error " << ec; 1430c45f0082SYong Li messages::internalError(aResp->res); 1431c45f0082SYong Li return; 1432c45f0082SYong Li } 1433c45f0082SYong Li }, 1434c45f0082SYong Li "xyz.openbmc_project.Watchdog", 1435c45f0082SYong Li "/xyz/openbmc_project/watchdog/host0", 1436c45f0082SYong Li "org.freedesktop.DBus.Properties", "Set", 1437c45f0082SYong Li "xyz.openbmc_project.State.Watchdog", "ExpireAction", 1438c45f0082SYong Li std::variant<std::string>(wdtTimeOutActStr)); 1439c45f0082SYong Li } 1440c45f0082SYong Li 1441c45f0082SYong Li if (wdtEnable) 1442c45f0082SYong Li { 1443c45f0082SYong Li crow::connections::systemBus->async_method_call( 1444c45f0082SYong Li [aResp](const boost::system::error_code ec) { 1445c45f0082SYong Li if (ec) 1446c45f0082SYong Li { 1447c45f0082SYong Li BMCWEB_LOG_DEBUG << "DBUS response error " << ec; 1448c45f0082SYong Li messages::internalError(aResp->res); 1449c45f0082SYong Li return; 1450c45f0082SYong Li } 1451c45f0082SYong Li }, 1452c45f0082SYong Li "xyz.openbmc_project.Watchdog", 1453c45f0082SYong Li "/xyz/openbmc_project/watchdog/host0", 1454c45f0082SYong Li "org.freedesktop.DBus.Properties", "Set", 1455c45f0082SYong Li "xyz.openbmc_project.State.Watchdog", "Enabled", 1456c45f0082SYong Li std::variant<bool>(*wdtEnable)); 1457c45f0082SYong Li } 1458c45f0082SYong Li } 1459c45f0082SYong Li 1460c45f0082SYong Li /** 1461c5b2abe0SLewanczyk, Dawid * SystemsCollection derived class for delivering ComputerSystems Collection 1462c5b2abe0SLewanczyk, Dawid * Schema 1463c5b2abe0SLewanczyk, Dawid */ 14641abe55efSEd Tanous class SystemsCollection : public Node 14651abe55efSEd Tanous { 1466c5b2abe0SLewanczyk, Dawid public: 14671abe55efSEd Tanous SystemsCollection(CrowApp &app) : Node(app, "/redfish/v1/Systems/") 14681abe55efSEd Tanous { 1469c5b2abe0SLewanczyk, Dawid entityPrivileges = { 1470c5b2abe0SLewanczyk, Dawid {boost::beast::http::verb::get, {{"Login"}}}, 1471c5b2abe0SLewanczyk, Dawid {boost::beast::http::verb::head, {{"Login"}}}, 1472c5b2abe0SLewanczyk, Dawid {boost::beast::http::verb::patch, {{"ConfigureComponents"}}}, 1473c5b2abe0SLewanczyk, Dawid {boost::beast::http::verb::put, {{"ConfigureComponents"}}}, 1474c5b2abe0SLewanczyk, Dawid {boost::beast::http::verb::delete_, {{"ConfigureComponents"}}}, 1475c5b2abe0SLewanczyk, Dawid {boost::beast::http::verb::post, {{"ConfigureComponents"}}}}; 1476c5b2abe0SLewanczyk, Dawid } 1477c5b2abe0SLewanczyk, Dawid 1478c5b2abe0SLewanczyk, Dawid private: 147955c7b7a2SEd Tanous void doGet(crow::Response &res, const crow::Request &req, 14801abe55efSEd Tanous const std::vector<std::string> ¶ms) override 14811abe55efSEd Tanous { 14820f74e643SEd Tanous res.jsonValue["@odata.type"] = 14830f74e643SEd Tanous "#ComputerSystemCollection.ComputerSystemCollection"; 14840f74e643SEd Tanous res.jsonValue["@odata.id"] = "/redfish/v1/Systems"; 14850f74e643SEd Tanous res.jsonValue["@odata.context"] = 14860f74e643SEd Tanous "/redfish/v1/" 14870f74e643SEd Tanous "$metadata#ComputerSystemCollection.ComputerSystemCollection"; 14880f74e643SEd Tanous res.jsonValue["Name"] = "Computer System Collection"; 1489029573d4SEd Tanous res.jsonValue["Members"] = { 1490029573d4SEd Tanous {{"@odata.id", "/redfish/v1/Systems/system"}}}; 1491029573d4SEd Tanous res.jsonValue["Members@odata.count"] = 1; 1492029573d4SEd Tanous res.end(); 1493c5b2abe0SLewanczyk, Dawid } 1494c5b2abe0SLewanczyk, Dawid }; 1495c5b2abe0SLewanczyk, Dawid 1496c5b2abe0SLewanczyk, Dawid /** 1497cc340dd9SEd Tanous * SystemActionsReset class supports handle POST method for Reset action. 1498cc340dd9SEd Tanous * The class retrieves and sends data directly to D-Bus. 1499cc340dd9SEd Tanous */ 1500cc340dd9SEd Tanous class SystemActionsReset : public Node 1501cc340dd9SEd Tanous { 1502cc340dd9SEd Tanous public: 1503cc340dd9SEd Tanous SystemActionsReset(CrowApp &app) : 1504029573d4SEd Tanous Node(app, "/redfish/v1/Systems/system/Actions/ComputerSystem.Reset/") 1505cc340dd9SEd Tanous { 1506cc340dd9SEd Tanous entityPrivileges = { 1507cc340dd9SEd Tanous {boost::beast::http::verb::post, {{"ConfigureComponents"}}}}; 1508cc340dd9SEd Tanous } 1509cc340dd9SEd Tanous 1510cc340dd9SEd Tanous private: 1511cc340dd9SEd Tanous /** 1512cc340dd9SEd Tanous * Function handles POST method request. 1513cc340dd9SEd Tanous * Analyzes POST body message before sends Reset request data to D-Bus. 1514cc340dd9SEd Tanous */ 1515cc340dd9SEd Tanous void doPost(crow::Response &res, const crow::Request &req, 1516cc340dd9SEd Tanous const std::vector<std::string> ¶ms) override 1517cc340dd9SEd Tanous { 1518cc340dd9SEd Tanous auto asyncResp = std::make_shared<AsyncResp>(res); 1519cc340dd9SEd Tanous 15209712f8acSEd Tanous std::string resetType; 15219712f8acSEd Tanous if (!json_util::readJson(req, res, "ResetType", resetType)) 1522cc340dd9SEd Tanous { 1523cc340dd9SEd Tanous return; 1524cc340dd9SEd Tanous } 1525cc340dd9SEd Tanous 1526d22c8396SJason M. Bills // Get the command and host vs. chassis 1527cc340dd9SEd Tanous std::string command; 1528d22c8396SJason M. Bills bool hostCommand; 15299712f8acSEd Tanous if (resetType == "On") 1530cc340dd9SEd Tanous { 1531cc340dd9SEd Tanous command = "xyz.openbmc_project.State.Host.Transition.On"; 1532d22c8396SJason M. Bills hostCommand = true; 1533d22c8396SJason M. Bills } 1534d22c8396SJason M. Bills else if (resetType == "ForceOff") 1535d22c8396SJason M. Bills { 1536d22c8396SJason M. Bills command = "xyz.openbmc_project.State.Chassis.Transition.Off"; 1537d22c8396SJason M. Bills hostCommand = false; 1538d22c8396SJason M. Bills } 1539d22c8396SJason M. Bills else if (resetType == "ForceOn") 1540d22c8396SJason M. Bills { 1541d22c8396SJason M. Bills command = "xyz.openbmc_project.State.Host.Transition.On"; 1542d22c8396SJason M. Bills hostCommand = true; 1543d22c8396SJason M. Bills } 1544d22c8396SJason M. Bills else if (resetType == "ForceRestart") 1545d22c8396SJason M. Bills { 1546d22c8396SJason M. Bills command = "xyz.openbmc_project.State.Chassis.Transition.Reset"; 1547d22c8396SJason M. Bills hostCommand = false; 1548cc340dd9SEd Tanous } 15499712f8acSEd Tanous else if (resetType == "GracefulShutdown") 1550cc340dd9SEd Tanous { 1551cc340dd9SEd Tanous command = "xyz.openbmc_project.State.Host.Transition.Off"; 1552d22c8396SJason M. Bills hostCommand = true; 1553cc340dd9SEd Tanous } 15549712f8acSEd Tanous else if (resetType == "GracefulRestart") 1555cc340dd9SEd Tanous { 15569712f8acSEd Tanous command = "xyz.openbmc_project.State.Host.Transition.Reboot"; 1557d22c8396SJason M. Bills hostCommand = true; 1558d22c8396SJason M. Bills } 1559d22c8396SJason M. Bills else if (resetType == "PowerCycle") 1560d22c8396SJason M. Bills { 1561d22c8396SJason M. Bills command = "xyz.openbmc_project.State.Chassis.Transition.PowerCycle"; 1562d22c8396SJason M. Bills hostCommand = false; 1563cc340dd9SEd Tanous } 1564bfd5b826SLakshminarayana R. Kammath else if (resetType == "Nmi") 1565bfd5b826SLakshminarayana R. Kammath { 1566bfd5b826SLakshminarayana R. Kammath doNMI(asyncResp); 1567bfd5b826SLakshminarayana R. Kammath return; 1568bfd5b826SLakshminarayana R. Kammath } 1569cc340dd9SEd Tanous else 1570cc340dd9SEd Tanous { 1571f12894f8SJason M. Bills messages::actionParameterUnknown(res, "Reset", resetType); 1572cc340dd9SEd Tanous return; 1573cc340dd9SEd Tanous } 1574cc340dd9SEd Tanous 1575d22c8396SJason M. Bills if (hostCommand) 1576d22c8396SJason M. Bills { 1577cc340dd9SEd Tanous crow::connections::systemBus->async_method_call( 1578d22c8396SJason M. Bills [asyncResp, resetType](const boost::system::error_code ec) { 1579cc340dd9SEd Tanous if (ec) 1580cc340dd9SEd Tanous { 1581cc340dd9SEd Tanous BMCWEB_LOG_ERROR << "D-Bus responses error: " << ec; 1582d22c8396SJason M. Bills if (ec.value() == boost::asio::error::invalid_argument) 1583d22c8396SJason M. Bills { 1584d22c8396SJason M. Bills messages::actionParameterNotSupported( 1585d22c8396SJason M. Bills asyncResp->res, resetType, "Reset"); 1586d22c8396SJason M. Bills } 1587d22c8396SJason M. Bills else 1588d22c8396SJason M. Bills { 1589f12894f8SJason M. Bills messages::internalError(asyncResp->res); 1590d22c8396SJason M. Bills } 1591cc340dd9SEd Tanous return; 1592cc340dd9SEd Tanous } 1593f12894f8SJason M. Bills messages::success(asyncResp->res); 1594cc340dd9SEd Tanous }, 1595cc340dd9SEd Tanous "xyz.openbmc_project.State.Host", 1596cc340dd9SEd Tanous "/xyz/openbmc_project/state/host0", 1597cc340dd9SEd Tanous "org.freedesktop.DBus.Properties", "Set", 15989712f8acSEd Tanous "xyz.openbmc_project.State.Host", "RequestedHostTransition", 1599abf2add6SEd Tanous std::variant<std::string>{command}); 1600cc340dd9SEd Tanous } 1601d22c8396SJason M. Bills else 1602d22c8396SJason M. Bills { 1603d22c8396SJason M. Bills crow::connections::systemBus->async_method_call( 1604d22c8396SJason M. Bills [asyncResp, resetType](const boost::system::error_code ec) { 1605d22c8396SJason M. Bills if (ec) 1606d22c8396SJason M. Bills { 1607d22c8396SJason M. Bills BMCWEB_LOG_ERROR << "D-Bus responses error: " << ec; 1608d22c8396SJason M. Bills if (ec.value() == boost::asio::error::invalid_argument) 1609d22c8396SJason M. Bills { 1610d22c8396SJason M. Bills messages::actionParameterNotSupported( 1611d22c8396SJason M. Bills asyncResp->res, resetType, "Reset"); 1612d22c8396SJason M. Bills } 1613d22c8396SJason M. Bills else 1614d22c8396SJason M. Bills { 1615d22c8396SJason M. Bills messages::internalError(asyncResp->res); 1616d22c8396SJason M. Bills } 1617d22c8396SJason M. Bills return; 1618d22c8396SJason M. Bills } 1619d22c8396SJason M. Bills messages::success(asyncResp->res); 1620d22c8396SJason M. Bills }, 1621d22c8396SJason M. Bills "xyz.openbmc_project.State.Chassis", 1622d22c8396SJason M. Bills "/xyz/openbmc_project/state/chassis0", 1623d22c8396SJason M. Bills "org.freedesktop.DBus.Properties", "Set", 1624d22c8396SJason M. Bills "xyz.openbmc_project.State.Chassis", "RequestedPowerTransition", 1625d22c8396SJason M. Bills std::variant<std::string>{command}); 1626d22c8396SJason M. Bills } 1627d22c8396SJason M. Bills } 1628bfd5b826SLakshminarayana R. Kammath /** 1629bfd5b826SLakshminarayana R. Kammath * Function transceives data with dbus directly. 1630bfd5b826SLakshminarayana R. Kammath */ 1631bfd5b826SLakshminarayana R. Kammath void doNMI(const std::shared_ptr<AsyncResp> &asyncResp) 1632bfd5b826SLakshminarayana R. Kammath { 1633bfd5b826SLakshminarayana R. Kammath constexpr char const *serviceName = 1634bfd5b826SLakshminarayana R. Kammath "xyz.openbmc_project.Control.Host.NMI"; 1635bfd5b826SLakshminarayana R. Kammath constexpr char const *objectPath = 1636bfd5b826SLakshminarayana R. Kammath "/xyz/openbmc_project/control/host0/nmi"; 1637bfd5b826SLakshminarayana R. Kammath constexpr char const *interfaceName = 1638bfd5b826SLakshminarayana R. Kammath "xyz.openbmc_project.Control.Host.NMI"; 1639bfd5b826SLakshminarayana R. Kammath constexpr char const *method = "NMI"; 1640bfd5b826SLakshminarayana R. Kammath 1641bfd5b826SLakshminarayana R. Kammath crow::connections::systemBus->async_method_call( 1642bfd5b826SLakshminarayana R. Kammath [asyncResp](const boost::system::error_code ec) { 1643bfd5b826SLakshminarayana R. Kammath if (ec) 1644bfd5b826SLakshminarayana R. Kammath { 1645bfd5b826SLakshminarayana R. Kammath BMCWEB_LOG_ERROR << " Bad D-Bus request error: " << ec; 1646bfd5b826SLakshminarayana R. Kammath messages::internalError(asyncResp->res); 1647bfd5b826SLakshminarayana R. Kammath return; 1648bfd5b826SLakshminarayana R. Kammath } 1649bfd5b826SLakshminarayana R. Kammath messages::success(asyncResp->res); 1650bfd5b826SLakshminarayana R. Kammath }, 1651bfd5b826SLakshminarayana R. Kammath serviceName, objectPath, interfaceName, method); 1652bfd5b826SLakshminarayana R. Kammath } 1653cc340dd9SEd Tanous }; 1654cc340dd9SEd Tanous 1655cc340dd9SEd Tanous /** 16566617338dSEd Tanous * Systems derived class for delivering Computer Systems Schema. 1657c5b2abe0SLewanczyk, Dawid */ 16581abe55efSEd Tanous class Systems : public Node 16591abe55efSEd Tanous { 1660c5b2abe0SLewanczyk, Dawid public: 1661c5b2abe0SLewanczyk, Dawid /* 1662c5b2abe0SLewanczyk, Dawid * Default Constructor 1663c5b2abe0SLewanczyk, Dawid */ 1664029573d4SEd Tanous Systems(CrowApp &app) : Node(app, "/redfish/v1/Systems/system/") 16651abe55efSEd Tanous { 1666c5b2abe0SLewanczyk, Dawid entityPrivileges = { 1667c5b2abe0SLewanczyk, Dawid {boost::beast::http::verb::get, {{"Login"}}}, 1668c5b2abe0SLewanczyk, Dawid {boost::beast::http::verb::head, {{"Login"}}}, 1669c5b2abe0SLewanczyk, Dawid {boost::beast::http::verb::patch, {{"ConfigureComponents"}}}, 1670c5b2abe0SLewanczyk, Dawid {boost::beast::http::verb::put, {{"ConfigureComponents"}}}, 1671c5b2abe0SLewanczyk, Dawid {boost::beast::http::verb::delete_, {{"ConfigureComponents"}}}, 1672c5b2abe0SLewanczyk, Dawid {boost::beast::http::verb::post, {{"ConfigureComponents"}}}}; 1673c5b2abe0SLewanczyk, Dawid } 1674c5b2abe0SLewanczyk, Dawid 1675c5b2abe0SLewanczyk, Dawid private: 1676c5b2abe0SLewanczyk, Dawid /** 1677c5b2abe0SLewanczyk, Dawid * Functions triggers appropriate requests on DBus 1678c5b2abe0SLewanczyk, Dawid */ 167955c7b7a2SEd Tanous void doGet(crow::Response &res, const crow::Request &req, 16801abe55efSEd Tanous const std::vector<std::string> ¶ms) override 16811abe55efSEd Tanous { 1682491d8ee7SSantosh Puranik res.jsonValue["@odata.type"] = "#ComputerSystem.v1_6_0.ComputerSystem"; 16830f74e643SEd Tanous res.jsonValue["@odata.context"] = 16840f74e643SEd Tanous "/redfish/v1/$metadata#ComputerSystem.ComputerSystem"; 1685029573d4SEd Tanous res.jsonValue["Name"] = "Computer System"; 1686029573d4SEd Tanous res.jsonValue["Id"] = "system"; 16870f74e643SEd Tanous res.jsonValue["SystemType"] = "Physical"; 16880f74e643SEd Tanous res.jsonValue["Description"] = "Computer System"; 16890f74e643SEd Tanous res.jsonValue["ProcessorSummary"]["Count"] = 0; 16900f74e643SEd Tanous res.jsonValue["ProcessorSummary"]["Status"]["State"] = "Disabled"; 1691*5fd7ba65SCheng C Yang res.jsonValue["MemorySummary"]["TotalSystemMemoryGiB"] = uint64_t(0); 16920f74e643SEd Tanous res.jsonValue["MemorySummary"]["Status"]["State"] = "Disabled"; 1693029573d4SEd Tanous res.jsonValue["@odata.id"] = "/redfish/v1/Systems/system"; 169404a258f4SEd Tanous 1695443c2934SRapkiewicz, Pawel res.jsonValue["Processors"] = { 1696029573d4SEd Tanous {"@odata.id", "/redfish/v1/Systems/system/Processors"}}; 1697443c2934SRapkiewicz, Pawel res.jsonValue["Memory"] = { 1698029573d4SEd Tanous {"@odata.id", "/redfish/v1/Systems/system/Memory"}}; 1699a25aeccfSNikhil Potade res.jsonValue["Storage"] = { 1700a25aeccfSNikhil Potade {"@odata.id", "/redfish/v1/Systems/system/Storage"}}; 1701029573d4SEd Tanous 1702cc340dd9SEd Tanous // TODO Need to support ForceRestart. 1703cc340dd9SEd Tanous res.jsonValue["Actions"]["#ComputerSystem.Reset"] = { 1704cc340dd9SEd Tanous {"target", 1705029573d4SEd Tanous "/redfish/v1/Systems/system/Actions/ComputerSystem.Reset"}, 1706cc340dd9SEd Tanous {"ResetType@Redfish.AllowableValues", 1707d22c8396SJason M. Bills {"On", "ForceOff", "ForceOn", "ForceRestart", "GracefulRestart", 1708bfd5b826SLakshminarayana R. Kammath "GracefulShutdown", "PowerCycle", "Nmi"}}}; 1709c5b2abe0SLewanczyk, Dawid 1710c4bf6374SJason M. Bills res.jsonValue["LogServices"] = { 1711029573d4SEd Tanous {"@odata.id", "/redfish/v1/Systems/system/LogServices"}}; 1712c4bf6374SJason M. Bills 1713c5d03ff4SJennifer Lee res.jsonValue["Links"]["ManagedBy"] = { 1714c5d03ff4SJennifer Lee {{"@odata.id", "/redfish/v1/Managers/bmc"}}}; 1715c5d03ff4SJennifer Lee 1716c5d03ff4SJennifer Lee res.jsonValue["Status"] = { 1717c5d03ff4SJennifer Lee {"Health", "OK"}, 1718c5d03ff4SJennifer Lee {"State", "Enabled"}, 1719c5d03ff4SJennifer Lee }; 1720a0803efaSEd Tanous auto asyncResp = std::make_shared<AsyncResp>(res); 1721c5b2abe0SLewanczyk, Dawid 1722e284a7c1SJames Feist constexpr const std::array<const char *, 4> inventoryForSystems = { 1723b49ac873SJames Feist "xyz.openbmc_project.Inventory.Item.Dimm", 17242ad9c2f6SJames Feist "xyz.openbmc_project.Inventory.Item.Cpu", 1725e284a7c1SJames Feist "xyz.openbmc_project.Inventory.Item.Drive", 1726e284a7c1SJames Feist "xyz.openbmc_project.Inventory.Item.StorageController"}; 1727b49ac873SJames Feist 1728b49ac873SJames Feist auto health = std::make_shared<HealthPopulate>(asyncResp); 1729b49ac873SJames Feist crow::connections::systemBus->async_method_call( 1730b49ac873SJames Feist [health](const boost::system::error_code ec, 1731b49ac873SJames Feist std::vector<std::string> &resp) { 1732b49ac873SJames Feist if (ec) 1733b49ac873SJames Feist { 1734b49ac873SJames Feist // no inventory 1735b49ac873SJames Feist return; 1736b49ac873SJames Feist } 1737b49ac873SJames Feist 1738b49ac873SJames Feist health->inventory = std::move(resp); 1739b49ac873SJames Feist }, 1740b49ac873SJames Feist "xyz.openbmc_project.ObjectMapper", 1741b49ac873SJames Feist "/xyz/openbmc_project/object_mapper", 1742b49ac873SJames Feist "xyz.openbmc_project.ObjectMapper", "GetSubTreePaths", "/", 1743b49ac873SJames Feist int32_t(0), inventoryForSystems); 1744b49ac873SJames Feist 1745b49ac873SJames Feist health->populate(); 1746b49ac873SJames Feist 1747c5d03ff4SJennifer Lee getMainChassisId(asyncResp, [](const std::string &chassisId, 1748c5d03ff4SJennifer Lee std::shared_ptr<AsyncResp> aRsp) { 1749c5d03ff4SJennifer Lee aRsp->res.jsonValue["Links"]["Chassis"] = { 1750c5d03ff4SJennifer Lee {{"@odata.id", "/redfish/v1/Chassis/" + chassisId}}}; 1751c5d03ff4SJennifer Lee }); 1752a3002228SAppaRao Puli 1753a3002228SAppaRao Puli getIndicatorLedState(asyncResp); 17545bc2dc8eSJames Feist getComputerSystem(asyncResp, health); 17556c34de48SEd Tanous getHostState(asyncResp); 1756491d8ee7SSantosh Puranik getBootProperties(asyncResp); 1757adbe192aSJason M. Bills getPCIeDeviceList(asyncResp, "PCIeDevices"); 175851709ffdSYong Li getHostWatchdogTimer(asyncResp); 1759a6349918SAppaRao Puli #ifdef BMCWEB_ENABLE_REDFISH_PROVISIONING_FEATURE 1760a6349918SAppaRao Puli getProvisioningStatus(asyncResp); 1761a6349918SAppaRao Puli #endif 1762c5b2abe0SLewanczyk, Dawid } 1763c5b2abe0SLewanczyk, Dawid 176455c7b7a2SEd Tanous void doPatch(crow::Response &res, const crow::Request &req, 17651abe55efSEd Tanous const std::vector<std::string> ¶ms) override 17661abe55efSEd Tanous { 1767cde19e5fSSantosh Puranik std::optional<std::string> indicatorLed; 1768491d8ee7SSantosh Puranik std::optional<nlohmann::json> bootProps; 1769c45f0082SYong Li std::optional<nlohmann::json> wdtTimerProps; 177041352c24SSantosh Puranik auto asyncResp = std::make_shared<AsyncResp>(res); 177141352c24SSantosh Puranik 1772944ffaf9SJohnathan Mantey if (!json_util::readJson(req, res, "IndicatorLED", indicatorLed, "Boot", 1773c45f0082SYong Li bootProps, "WatchdogTimer", wdtTimerProps)) 17746617338dSEd Tanous { 17756617338dSEd Tanous return; 17766617338dSEd Tanous } 1777491d8ee7SSantosh Puranik 1778944ffaf9SJohnathan Mantey res.result(boost::beast::http::status::no_content); 1779c45f0082SYong Li 1780c45f0082SYong Li if (wdtTimerProps) 1781c45f0082SYong Li { 1782c45f0082SYong Li std::optional<bool> wdtEnable; 1783c45f0082SYong Li std::optional<std::string> wdtTimeOutAction; 1784c45f0082SYong Li 1785c45f0082SYong Li if (!json_util::readJson(*wdtTimerProps, asyncResp->res, 1786c45f0082SYong Li "FunctionEnabled", wdtEnable, 1787c45f0082SYong Li "TimeoutAction", wdtTimeOutAction)) 1788c45f0082SYong Li { 1789c45f0082SYong Li return; 1790c45f0082SYong Li } 1791c45f0082SYong Li setWDTProperties(asyncResp, std::move(wdtEnable), 1792c45f0082SYong Li std::move(wdtTimeOutAction)); 1793c45f0082SYong Li } 1794c45f0082SYong Li 1795491d8ee7SSantosh Puranik if (bootProps) 1796491d8ee7SSantosh Puranik { 1797491d8ee7SSantosh Puranik std::optional<std::string> bootSource; 1798491d8ee7SSantosh Puranik std::optional<std::string> bootEnable; 1799491d8ee7SSantosh Puranik 1800491d8ee7SSantosh Puranik if (!json_util::readJson(*bootProps, asyncResp->res, 1801491d8ee7SSantosh Puranik "BootSourceOverrideTarget", bootSource, 1802491d8ee7SSantosh Puranik "BootSourceOverrideEnabled", bootEnable)) 1803491d8ee7SSantosh Puranik { 1804491d8ee7SSantosh Puranik return; 1805491d8ee7SSantosh Puranik } 1806491d8ee7SSantosh Puranik setBootProperties(asyncResp, std::move(bootSource), 1807491d8ee7SSantosh Puranik std::move(bootEnable)); 1808491d8ee7SSantosh Puranik } 1809265c1602SJohnathan Mantey 18109712f8acSEd Tanous if (indicatorLed) 18116617338dSEd Tanous { 1812a3002228SAppaRao Puli setIndicatorLedState(asyncResp, std::move(*indicatorLed)); 18136617338dSEd Tanous } 1814c5b2abe0SLewanczyk, Dawid } 1815c5b2abe0SLewanczyk, Dawid }; 1816c5b2abe0SLewanczyk, Dawid } // namespace redfish 1817