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 { 2189d3ae10eSAlpana Kumari if (property.first == 2199d3ae10eSAlpana Kumari "MemorySizeInKb") 2201abe55efSEd Tanous { 22104a258f4SEd Tanous const uint64_t *value = 2229d3ae10eSAlpana Kumari sdbusplus::message:: 2239d3ae10eSAlpana Kumari variant_ns::get_if< 2249d3ae10eSAlpana Kumari uint64_t>( 2251b6b96c5SEd Tanous &property.second); 22604a258f4SEd Tanous if (value != nullptr) 2271abe55efSEd Tanous { 2281abe55efSEd Tanous aResp->res.jsonValue 2296c34de48SEd Tanous ["TotalSystemMemoryGi" 2306c34de48SEd Tanous "B"] += 23104a258f4SEd Tanous *value / (1024 * 1024); 2329d3ae10eSAlpana Kumari aResp->res.jsonValue 2339d3ae10eSAlpana Kumari ["MemorySummary"] 2349d3ae10eSAlpana Kumari ["Status"]["State"] = 2351abe55efSEd Tanous "Enabled"; 236c5b2abe0SLewanczyk, Dawid } 237c5b2abe0SLewanczyk, Dawid } 238c5b2abe0SLewanczyk, Dawid } 2399d3ae10eSAlpana Kumari } 2409d3ae10eSAlpana Kumari else 2419d3ae10eSAlpana Kumari { 2429d3ae10eSAlpana Kumari auto getDimmProperties = 2439d3ae10eSAlpana Kumari [aResp]( 2449d3ae10eSAlpana Kumari const boost::system::error_code 2459d3ae10eSAlpana Kumari ec, 2469d3ae10eSAlpana Kumari const std::variant<bool> 2479d3ae10eSAlpana Kumari &dimmState) { 2489d3ae10eSAlpana Kumari if (ec) 2499d3ae10eSAlpana Kumari { 2509d3ae10eSAlpana Kumari BMCWEB_LOG_ERROR 2519d3ae10eSAlpana Kumari << "DBUS response " 2529d3ae10eSAlpana Kumari "error " 2539d3ae10eSAlpana Kumari << ec; 2549d3ae10eSAlpana Kumari return; 2559d3ae10eSAlpana Kumari } 2569d3ae10eSAlpana Kumari updateDimmProperties(aResp, 2579d3ae10eSAlpana Kumari dimmState); 2589d3ae10eSAlpana Kumari }; 2599d3ae10eSAlpana Kumari crow::connections::systemBus 2609d3ae10eSAlpana Kumari ->async_method_call( 2619d3ae10eSAlpana Kumari std::move(getDimmProperties), 2629d3ae10eSAlpana Kumari service, path, 2639d3ae10eSAlpana Kumari "org.freedesktop.DBus." 2649d3ae10eSAlpana Kumari "Properties", 2659d3ae10eSAlpana Kumari "Get", 2669d3ae10eSAlpana Kumari "xyz.openbmc_project.State." 2679d3ae10eSAlpana Kumari "Decorator.OperationalStatus", 2689d3ae10eSAlpana Kumari "Functional"); 2699d3ae10eSAlpana Kumari } 270c5b2abe0SLewanczyk, Dawid }, 27104a258f4SEd Tanous connection.first, path, 2726c34de48SEd Tanous "org.freedesktop.DBus.Properties", "GetAll", 2736c34de48SEd Tanous "xyz.openbmc_project.Inventory.Item.Dimm"); 2745bc2dc8eSJames Feist 2755bc2dc8eSJames Feist memoryHealth->inventory.emplace_back(path); 2761abe55efSEd Tanous } 27704a258f4SEd Tanous else if (interfaceName == 27804a258f4SEd Tanous "xyz.openbmc_project.Inventory.Item.Cpu") 2791abe55efSEd Tanous { 2801abe55efSEd Tanous BMCWEB_LOG_DEBUG 28104a258f4SEd Tanous << "Found Cpu, now get its properties."; 28257e8c9beSAlpana Kumari 283a0803efaSEd Tanous crow::connections::systemBus->async_method_call( 28457e8c9beSAlpana Kumari [aResp, service{connection.first}, 28557e8c9beSAlpana Kumari path(std::move(path))]( 28657e8c9beSAlpana Kumari const boost::system::error_code ec, 2876c34de48SEd Tanous const std::vector< 2886c34de48SEd Tanous std::pair<std::string, VariantType>> 2891abe55efSEd Tanous &properties) { 2901abe55efSEd Tanous if (ec) 2911abe55efSEd Tanous { 2921abe55efSEd Tanous BMCWEB_LOG_ERROR 2936c34de48SEd Tanous << "DBUS response error " << ec; 294f12894f8SJason M. Bills messages::internalError(aResp->res); 295c5b2abe0SLewanczyk, Dawid return; 296c5b2abe0SLewanczyk, Dawid } 2976c34de48SEd Tanous BMCWEB_LOG_DEBUG << "Got " 2986c34de48SEd Tanous << properties.size() 299c5b2abe0SLewanczyk, Dawid << " Cpu properties."; 30057e8c9beSAlpana Kumari 30157e8c9beSAlpana Kumari if (properties.size() > 0) 30257e8c9beSAlpana Kumari { 30304a258f4SEd Tanous for (const auto &property : properties) 3041abe55efSEd Tanous { 30557e8c9beSAlpana Kumari if (property.first == 30657e8c9beSAlpana Kumari "ProcessorFamily") 3071abe55efSEd Tanous { 308a0803efaSEd Tanous const std::string *value = 30957e8c9beSAlpana Kumari sdbusplus::message:: 31057e8c9beSAlpana Kumari variant_ns::get_if< 31157e8c9beSAlpana Kumari std::string>( 3121b6b96c5SEd Tanous &property.second); 3131abe55efSEd Tanous if (value != nullptr) 3141abe55efSEd Tanous { 31557e8c9beSAlpana Kumari nlohmann::json 31657e8c9beSAlpana Kumari &procSummary = 3171abe55efSEd Tanous aResp->res.jsonValue 3186c34de48SEd Tanous ["ProcessorSumm" 31904a258f4SEd Tanous "ary"]; 32004a258f4SEd Tanous nlohmann::json &procCount = 32104a258f4SEd Tanous procSummary["Count"]; 32204a258f4SEd Tanous procCount = 32357e8c9beSAlpana Kumari procCount.get<int>() + 32457e8c9beSAlpana Kumari 1; 32557e8c9beSAlpana Kumari procSummary["Status"] 32657e8c9beSAlpana Kumari ["State"] = 327c5b2abe0SLewanczyk, Dawid "Enabled"; 32857e8c9beSAlpana Kumari procSummary["Model"] = 32957e8c9beSAlpana Kumari *value; 330c5b2abe0SLewanczyk, Dawid } 331c5b2abe0SLewanczyk, Dawid } 332c5b2abe0SLewanczyk, Dawid } 33357e8c9beSAlpana Kumari } 33457e8c9beSAlpana Kumari else 33557e8c9beSAlpana Kumari { 33657e8c9beSAlpana Kumari auto getCpuPresenceState = 33757e8c9beSAlpana Kumari [aResp]( 33857e8c9beSAlpana Kumari const boost::system::error_code 33957e8c9beSAlpana Kumari ec, 34057e8c9beSAlpana Kumari const std::variant<bool> 34157e8c9beSAlpana Kumari &cpuPresenceCheck) { 34257e8c9beSAlpana Kumari if (ec) 34357e8c9beSAlpana Kumari { 34457e8c9beSAlpana Kumari BMCWEB_LOG_ERROR 34557e8c9beSAlpana Kumari << "DBUS response " 34657e8c9beSAlpana Kumari "error " 34757e8c9beSAlpana Kumari << ec; 34857e8c9beSAlpana Kumari return; 34957e8c9beSAlpana Kumari } 35057e8c9beSAlpana Kumari modifyCpuPresenceState( 35157e8c9beSAlpana Kumari aResp, cpuPresenceCheck); 35257e8c9beSAlpana Kumari }; 35357e8c9beSAlpana Kumari 35457e8c9beSAlpana Kumari auto getCpuFunctionalState = 35557e8c9beSAlpana Kumari [aResp]( 35657e8c9beSAlpana Kumari const boost::system::error_code 35757e8c9beSAlpana Kumari ec, 35857e8c9beSAlpana Kumari const std::variant<bool> 35957e8c9beSAlpana Kumari &cpuFunctionalCheck) { 36057e8c9beSAlpana Kumari if (ec) 36157e8c9beSAlpana Kumari { 36257e8c9beSAlpana Kumari BMCWEB_LOG_ERROR 36357e8c9beSAlpana Kumari << "DBUS response " 36457e8c9beSAlpana Kumari "error " 36557e8c9beSAlpana Kumari << ec; 36657e8c9beSAlpana Kumari return; 36757e8c9beSAlpana Kumari } 36857e8c9beSAlpana Kumari modifyCpuFunctionalState( 36957e8c9beSAlpana Kumari aResp, cpuFunctionalCheck); 37057e8c9beSAlpana Kumari }; 37157e8c9beSAlpana Kumari // Get the Presence of CPU 37257e8c9beSAlpana Kumari crow::connections::systemBus 37357e8c9beSAlpana Kumari ->async_method_call( 37457e8c9beSAlpana Kumari std::move(getCpuPresenceState), 37557e8c9beSAlpana Kumari service, path, 37657e8c9beSAlpana Kumari "org.freedesktop.DBus." 37757e8c9beSAlpana Kumari "Properties", 37857e8c9beSAlpana Kumari "Get", 37957e8c9beSAlpana Kumari "xyz.openbmc_project.Inventory." 38057e8c9beSAlpana Kumari "Item", 38157e8c9beSAlpana Kumari "Present"); 38257e8c9beSAlpana Kumari 38357e8c9beSAlpana Kumari // Get the Functional State 38457e8c9beSAlpana Kumari crow::connections::systemBus 38557e8c9beSAlpana Kumari ->async_method_call( 38657e8c9beSAlpana Kumari std::move( 38757e8c9beSAlpana Kumari getCpuFunctionalState), 38857e8c9beSAlpana Kumari service, path, 38957e8c9beSAlpana Kumari "org.freedesktop.DBus." 39057e8c9beSAlpana Kumari "Properties", 39157e8c9beSAlpana Kumari "Get", 39257e8c9beSAlpana Kumari "xyz.openbmc_project.State." 39357e8c9beSAlpana Kumari "Decorator." 39457e8c9beSAlpana Kumari "OperationalStatus", 39557e8c9beSAlpana Kumari "Functional"); 39657e8c9beSAlpana Kumari 39757e8c9beSAlpana Kumari // Get the MODEL from 39857e8c9beSAlpana Kumari // xyz.openbmc_project.Inventory.Decorator.Asset 39957e8c9beSAlpana Kumari // support it later as Model is Empty 40057e8c9beSAlpana Kumari // currently. 40157e8c9beSAlpana Kumari } 402c5b2abe0SLewanczyk, Dawid }, 40304a258f4SEd Tanous connection.first, path, 4046c34de48SEd Tanous "org.freedesktop.DBus.Properties", "GetAll", 4056c34de48SEd Tanous "xyz.openbmc_project.Inventory.Item.Cpu"); 4065bc2dc8eSJames Feist 4075bc2dc8eSJames Feist cpuHealth->inventory.emplace_back(path); 4081abe55efSEd Tanous } 40904a258f4SEd Tanous else if (interfaceName == 41004a258f4SEd Tanous "xyz.openbmc_project.Common.UUID") 4111abe55efSEd Tanous { 4121abe55efSEd Tanous BMCWEB_LOG_DEBUG 41304a258f4SEd Tanous << "Found UUID, now get its properties."; 41455c7b7a2SEd Tanous crow::connections::systemBus->async_method_call( 415029573d4SEd Tanous [aResp](const boost::system::error_code ec, 4166c34de48SEd Tanous const std::vector< 4176c34de48SEd Tanous std::pair<std::string, VariantType>> 4181abe55efSEd Tanous &properties) { 4191abe55efSEd Tanous if (ec) 4201abe55efSEd Tanous { 4211abe55efSEd Tanous BMCWEB_LOG_DEBUG 4226c34de48SEd Tanous << "DBUS response error " << ec; 423f12894f8SJason M. Bills messages::internalError(aResp->res); 424c5b2abe0SLewanczyk, Dawid return; 425c5b2abe0SLewanczyk, Dawid } 4266c34de48SEd Tanous BMCWEB_LOG_DEBUG << "Got " 4276c34de48SEd Tanous << properties.size() 428c5b2abe0SLewanczyk, Dawid << " UUID properties."; 4291abe55efSEd Tanous for (const std::pair<std::string, 43004a258f4SEd Tanous VariantType> 43104a258f4SEd Tanous &property : properties) 4321abe55efSEd Tanous { 43304a258f4SEd Tanous if (property.first == "UUID") 4341abe55efSEd Tanous { 435c5b2abe0SLewanczyk, Dawid const std::string *value = 436029573d4SEd Tanous sdbusplus::message::variant_ns:: 437029573d4SEd Tanous get_if<std::string>( 4381b6b96c5SEd Tanous &property.second); 43904a258f4SEd Tanous 4401abe55efSEd Tanous if (value != nullptr) 4411abe55efSEd Tanous { 442029573d4SEd Tanous std::string valueStr = *value; 44304a258f4SEd Tanous if (valueStr.size() == 32) 4441abe55efSEd Tanous { 445029573d4SEd Tanous valueStr.insert(8, 1, '-'); 446029573d4SEd Tanous valueStr.insert(13, 1, '-'); 447029573d4SEd Tanous valueStr.insert(18, 1, '-'); 448029573d4SEd Tanous valueStr.insert(23, 1, '-'); 44904a258f4SEd Tanous } 450029573d4SEd Tanous BMCWEB_LOG_DEBUG << "UUID = " 45104a258f4SEd Tanous << valueStr; 452029573d4SEd Tanous aResp->res.jsonValue["UUID"] = 45304a258f4SEd Tanous valueStr; 454c5b2abe0SLewanczyk, Dawid } 455c5b2abe0SLewanczyk, Dawid } 456c5b2abe0SLewanczyk, Dawid } 457c5b2abe0SLewanczyk, Dawid }, 45804a258f4SEd Tanous connection.first, path, 4596c34de48SEd Tanous "org.freedesktop.DBus.Properties", "GetAll", 4601abe55efSEd Tanous "xyz.openbmc_project.Common.UUID"); 461c5b2abe0SLewanczyk, Dawid } 462029573d4SEd Tanous else if (interfaceName == 463029573d4SEd Tanous "xyz.openbmc_project.Inventory.Item.System") 4641abe55efSEd Tanous { 465029573d4SEd Tanous crow::connections::systemBus->async_method_call( 466029573d4SEd Tanous [aResp](const boost::system::error_code ec, 467029573d4SEd Tanous const std::vector< 468029573d4SEd Tanous std::pair<std::string, VariantType>> 469029573d4SEd Tanous &propertiesList) { 470029573d4SEd Tanous if (ec) 471029573d4SEd Tanous { 472e4a4b9a9SJames Feist // doesn't have to include this 473e4a4b9a9SJames Feist // interface 474029573d4SEd Tanous return; 475029573d4SEd Tanous } 476698654b6SGunnar Mills BMCWEB_LOG_DEBUG 477698654b6SGunnar Mills << "Got " << propertiesList.size() 478029573d4SEd Tanous << " properties for system"; 479029573d4SEd Tanous for (const std::pair<std::string, 480029573d4SEd Tanous VariantType> 481029573d4SEd Tanous &property : propertiesList) 482029573d4SEd Tanous { 483fc5afcf9Sbeccabroek const std::string &propertyName = 484fc5afcf9Sbeccabroek property.first; 485fc5afcf9Sbeccabroek if ((propertyName == "PartNumber") || 486fc5afcf9Sbeccabroek (propertyName == "SerialNumber") || 487fc5afcf9Sbeccabroek (propertyName == "Manufacturer") || 488fc5afcf9Sbeccabroek (propertyName == "Model")) 489fc5afcf9Sbeccabroek { 490029573d4SEd Tanous const std::string *value = 491fc5afcf9Sbeccabroek std::get_if<std::string>( 492029573d4SEd Tanous &property.second); 493029573d4SEd Tanous if (value != nullptr) 494029573d4SEd Tanous { 495029573d4SEd Tanous aResp->res 496fc5afcf9Sbeccabroek .jsonValue[propertyName] = 497029573d4SEd Tanous *value; 498029573d4SEd Tanous } 499029573d4SEd Tanous } 500fc5afcf9Sbeccabroek } 501029573d4SEd Tanous aResp->res.jsonValue["Name"] = "system"; 502029573d4SEd Tanous aResp->res.jsonValue["Id"] = 503029573d4SEd Tanous aResp->res.jsonValue["SerialNumber"]; 504cb7e1e7bSAndrew Geissler // Grab the bios version 505cb7e1e7bSAndrew Geissler fw_util::getActiveFwVersion( 506cb7e1e7bSAndrew Geissler aResp, fw_util::biosPurpose, 507cb7e1e7bSAndrew Geissler "BiosVersion"); 508029573d4SEd Tanous }, 509029573d4SEd Tanous connection.first, path, 510029573d4SEd Tanous "org.freedesktop.DBus.Properties", "GetAll", 511029573d4SEd Tanous "xyz.openbmc_project.Inventory.Decorator." 512029573d4SEd Tanous "Asset"); 513e4a4b9a9SJames Feist 514e4a4b9a9SJames Feist crow::connections::systemBus->async_method_call( 515e4a4b9a9SJames Feist [aResp]( 516e4a4b9a9SJames Feist const boost::system::error_code ec, 517e4a4b9a9SJames Feist const std::variant<std::string> &property) { 518e4a4b9a9SJames Feist if (ec) 519e4a4b9a9SJames Feist { 520e4a4b9a9SJames Feist // doesn't have to include this 521e4a4b9a9SJames Feist // interface 522e4a4b9a9SJames Feist return; 523e4a4b9a9SJames Feist } 524e4a4b9a9SJames Feist 525e4a4b9a9SJames Feist const std::string *value = 526e4a4b9a9SJames Feist std::get_if<std::string>(&property); 527e4a4b9a9SJames Feist if (value != nullptr) 528e4a4b9a9SJames Feist { 529e4a4b9a9SJames Feist aResp->res.jsonValue["AssetTag"] = 530e4a4b9a9SJames Feist *value; 531e4a4b9a9SJames Feist } 532e4a4b9a9SJames Feist }, 533e4a4b9a9SJames Feist connection.first, path, 534e4a4b9a9SJames Feist "org.freedesktop.DBus.Properties", "Get", 535e4a4b9a9SJames Feist "xyz.openbmc_project.Inventory.Decorator." 536e4a4b9a9SJames Feist "AssetTag", 537e4a4b9a9SJames Feist "AssetTag"); 538029573d4SEd Tanous } 539029573d4SEd Tanous } 540029573d4SEd Tanous } 541c5b2abe0SLewanczyk, Dawid } 542c5b2abe0SLewanczyk, Dawid }, 543c5b2abe0SLewanczyk, Dawid "xyz.openbmc_project.ObjectMapper", 544c5b2abe0SLewanczyk, Dawid "/xyz/openbmc_project/object_mapper", 545c5b2abe0SLewanczyk, Dawid "xyz.openbmc_project.ObjectMapper", "GetSubTree", 5466617338dSEd Tanous "/xyz/openbmc_project/inventory", int32_t(0), 5476617338dSEd Tanous std::array<const char *, 5>{ 5486617338dSEd Tanous "xyz.openbmc_project.Inventory.Decorator.Asset", 5496617338dSEd Tanous "xyz.openbmc_project.Inventory.Item.Cpu", 5506617338dSEd Tanous "xyz.openbmc_project.Inventory.Item.Dimm", 5516617338dSEd Tanous "xyz.openbmc_project.Inventory.Item.System", 5526617338dSEd Tanous "xyz.openbmc_project.Common.UUID", 5536617338dSEd Tanous }); 554c5b2abe0SLewanczyk, Dawid } 555c5b2abe0SLewanczyk, Dawid 556c5b2abe0SLewanczyk, Dawid /** 557c5b2abe0SLewanczyk, Dawid * @brief Retrieves identify led group properties over dbus 558c5b2abe0SLewanczyk, Dawid * 559491d8ee7SSantosh Puranik * @param[in] aResp Shared pointer for generating response message. 560c5b2abe0SLewanczyk, Dawid * @param[in] callback Callback for process retrieved data. 561c5b2abe0SLewanczyk, Dawid * 562c5b2abe0SLewanczyk, Dawid * @return None. 563c5b2abe0SLewanczyk, Dawid */ 564c5b2abe0SLewanczyk, Dawid template <typename CallbackFunc> 565a0803efaSEd Tanous void getLedGroupIdentify(std::shared_ptr<AsyncResp> aResp, 5661abe55efSEd Tanous CallbackFunc &&callback) 5671abe55efSEd Tanous { 56855c7b7a2SEd Tanous BMCWEB_LOG_DEBUG << "Get led groups"; 56955c7b7a2SEd Tanous crow::connections::systemBus->async_method_call( 570c5d03ff4SJennifer Lee [aResp, 5716617338dSEd Tanous callback{std::move(callback)}](const boost::system::error_code &ec, 5721abe55efSEd Tanous const ManagedObjectsType &resp) { 5731abe55efSEd Tanous if (ec) 5741abe55efSEd Tanous { 57555c7b7a2SEd Tanous BMCWEB_LOG_DEBUG << "DBUS response error " << ec; 576f12894f8SJason M. Bills messages::internalError(aResp->res); 577c5b2abe0SLewanczyk, Dawid return; 578c5b2abe0SLewanczyk, Dawid } 5796c34de48SEd Tanous BMCWEB_LOG_DEBUG << "Got " << resp.size() << " led group objects."; 5801abe55efSEd Tanous for (const auto &objPath : resp) 5811abe55efSEd Tanous { 582c5b2abe0SLewanczyk, Dawid const std::string &path = objPath.first; 5831abe55efSEd Tanous if (path.rfind("enclosure_identify") != std::string::npos) 5841abe55efSEd Tanous { 5851abe55efSEd Tanous for (const auto &interface : objPath.second) 5861abe55efSEd Tanous { 5876c34de48SEd Tanous if (interface.first == "xyz.openbmc_project.Led.Group") 5881abe55efSEd Tanous { 5891abe55efSEd Tanous for (const auto &property : interface.second) 5901abe55efSEd Tanous { 5911abe55efSEd Tanous if (property.first == "Asserted") 5921abe55efSEd Tanous { 593c5b2abe0SLewanczyk, Dawid const bool *asserted = 594abf2add6SEd Tanous std::get_if<bool>(&property.second); 5951abe55efSEd Tanous if (nullptr != asserted) 5961abe55efSEd Tanous { 597c5b2abe0SLewanczyk, Dawid callback(*asserted, aResp); 5981abe55efSEd Tanous } 5991abe55efSEd Tanous else 6001abe55efSEd Tanous { 601c5b2abe0SLewanczyk, Dawid callback(false, aResp); 602c5b2abe0SLewanczyk, Dawid } 603c5b2abe0SLewanczyk, Dawid } 604c5b2abe0SLewanczyk, Dawid } 605c5b2abe0SLewanczyk, Dawid } 606c5b2abe0SLewanczyk, Dawid } 607c5b2abe0SLewanczyk, Dawid } 608c5b2abe0SLewanczyk, Dawid } 609c5b2abe0SLewanczyk, Dawid }, 610c5b2abe0SLewanczyk, Dawid "xyz.openbmc_project.LED.GroupManager", 6116c34de48SEd Tanous "/xyz/openbmc_project/led/groups", "org.freedesktop.DBus.ObjectManager", 6126c34de48SEd Tanous "GetManagedObjects"); 613c5b2abe0SLewanczyk, Dawid } 614c5b2abe0SLewanczyk, Dawid 615c5b2abe0SLewanczyk, Dawid template <typename CallbackFunc> 6166c34de48SEd Tanous void getLedIdentify(std::shared_ptr<AsyncResp> aResp, CallbackFunc &&callback) 6171abe55efSEd Tanous { 61855c7b7a2SEd Tanous BMCWEB_LOG_DEBUG << "Get identify led properties"; 61955c7b7a2SEd Tanous crow::connections::systemBus->async_method_call( 6206617338dSEd Tanous [aResp, 6216617338dSEd Tanous callback{std::move(callback)}](const boost::system::error_code ec, 622c5b2abe0SLewanczyk, Dawid const PropertiesType &properties) { 6231abe55efSEd Tanous if (ec) 6241abe55efSEd Tanous { 62555c7b7a2SEd Tanous BMCWEB_LOG_DEBUG << "DBUS response error " << ec; 626f12894f8SJason M. Bills messages::internalError(aResp->res); 627c5b2abe0SLewanczyk, Dawid return; 628c5b2abe0SLewanczyk, Dawid } 6291abe55efSEd Tanous BMCWEB_LOG_DEBUG << "Got " << properties.size() 6301abe55efSEd Tanous << " led properties."; 631c5b2abe0SLewanczyk, Dawid std::string output; 6321abe55efSEd Tanous for (const auto &property : properties) 6331abe55efSEd Tanous { 6341abe55efSEd Tanous if (property.first == "State") 6351abe55efSEd Tanous { 636c5b2abe0SLewanczyk, Dawid const std::string *s = 637abf2add6SEd Tanous std::get_if<std::string>(&property.second); 6381abe55efSEd Tanous if (nullptr != s) 6391abe55efSEd Tanous { 64055c7b7a2SEd Tanous BMCWEB_LOG_DEBUG << "Identify Led State: " << *s; 641c5b2abe0SLewanczyk, Dawid const auto pos = s->rfind('.'); 6421abe55efSEd Tanous if (pos != std::string::npos) 6431abe55efSEd Tanous { 644c5b2abe0SLewanczyk, Dawid auto led = s->substr(pos + 1); 6451abe55efSEd Tanous for (const std::pair<const char *, const char *> 6461abe55efSEd Tanous &p : 6471abe55efSEd Tanous std::array< 6486c34de48SEd Tanous std::pair<const char *, const char *>, 3>{ 6496c34de48SEd Tanous {{"On", "Lit"}, 650c5b2abe0SLewanczyk, Dawid {"Blink", "Blinking"}, 6511abe55efSEd Tanous {"Off", "Off"}}}) 6521abe55efSEd Tanous { 6531abe55efSEd Tanous if (led == p.first) 6541abe55efSEd Tanous { 655c5b2abe0SLewanczyk, Dawid output = p.second; 656c5b2abe0SLewanczyk, Dawid } 657c5b2abe0SLewanczyk, Dawid } 658c5b2abe0SLewanczyk, Dawid } 659c5b2abe0SLewanczyk, Dawid } 660c5b2abe0SLewanczyk, Dawid } 661c5b2abe0SLewanczyk, Dawid } 662c5b2abe0SLewanczyk, Dawid callback(output, aResp); 663c5b2abe0SLewanczyk, Dawid }, 664c5b2abe0SLewanczyk, Dawid "xyz.openbmc_project.LED.Controller.identify", 665c5b2abe0SLewanczyk, Dawid "/xyz/openbmc_project/led/physical/identify", 666c5b2abe0SLewanczyk, Dawid "org.freedesktop.DBus.Properties", "GetAll", 667c5b2abe0SLewanczyk, Dawid "xyz.openbmc_project.Led.Physical"); 668c5b2abe0SLewanczyk, Dawid } 669c5b2abe0SLewanczyk, Dawid /** 670c5b2abe0SLewanczyk, Dawid * @brief Retrieves host state properties over dbus 671c5b2abe0SLewanczyk, Dawid * 672c5b2abe0SLewanczyk, Dawid * @param[in] aResp Shared pointer for completing asynchronous calls. 673c5b2abe0SLewanczyk, Dawid * 674c5b2abe0SLewanczyk, Dawid * @return None. 675c5b2abe0SLewanczyk, Dawid */ 676a0803efaSEd Tanous void getHostState(std::shared_ptr<AsyncResp> aResp) 6771abe55efSEd Tanous { 67855c7b7a2SEd Tanous BMCWEB_LOG_DEBUG << "Get host information."; 67955c7b7a2SEd Tanous crow::connections::systemBus->async_method_call( 680c5d03ff4SJennifer Lee [aResp](const boost::system::error_code ec, 681abf2add6SEd Tanous const std::variant<std::string> &hostState) { 6821abe55efSEd Tanous if (ec) 6831abe55efSEd Tanous { 68455c7b7a2SEd Tanous BMCWEB_LOG_DEBUG << "DBUS response error " << ec; 685f12894f8SJason M. Bills messages::internalError(aResp->res); 686c5b2abe0SLewanczyk, Dawid return; 687c5b2abe0SLewanczyk, Dawid } 6886617338dSEd Tanous 689abf2add6SEd Tanous const std::string *s = std::get_if<std::string>(&hostState); 69055c7b7a2SEd Tanous BMCWEB_LOG_DEBUG << "Host state: " << *s; 6916617338dSEd Tanous if (s != nullptr) 6921abe55efSEd Tanous { 693c5b2abe0SLewanczyk, Dawid // Verify Host State 69494732661SAndrew Geissler if (*s == "xyz.openbmc_project.State.Host.HostState.Running") 6951abe55efSEd Tanous { 69655c7b7a2SEd Tanous aResp->res.jsonValue["PowerState"] = "On"; 6976617338dSEd Tanous aResp->res.jsonValue["Status"]["State"] = "Enabled"; 6981abe55efSEd Tanous } 6991abe55efSEd Tanous else 7001abe55efSEd Tanous { 70155c7b7a2SEd Tanous aResp->res.jsonValue["PowerState"] = "Off"; 7026617338dSEd Tanous aResp->res.jsonValue["Status"]["State"] = "Disabled"; 703c5b2abe0SLewanczyk, Dawid } 704c5b2abe0SLewanczyk, Dawid } 705c5b2abe0SLewanczyk, Dawid }, 7066c34de48SEd Tanous "xyz.openbmc_project.State.Host", "/xyz/openbmc_project/state/host0", 7076617338dSEd Tanous "org.freedesktop.DBus.Properties", "Get", 7086617338dSEd Tanous "xyz.openbmc_project.State.Host", "CurrentHostState"); 709c5b2abe0SLewanczyk, Dawid } 710c5b2abe0SLewanczyk, Dawid 711c5b2abe0SLewanczyk, Dawid /** 712491d8ee7SSantosh Puranik * @brief Traslates boot source DBUS property value to redfish. 713491d8ee7SSantosh Puranik * 714491d8ee7SSantosh Puranik * @param[in] dbusSource The boot source in DBUS speak. 715491d8ee7SSantosh Puranik * 716491d8ee7SSantosh Puranik * @return Returns as a string, the boot source in Redfish terms. If translation 717491d8ee7SSantosh Puranik * cannot be done, returns an empty string. 718491d8ee7SSantosh Puranik */ 719491d8ee7SSantosh Puranik static std::string dbusToRfBootSource(const std::string &dbusSource) 720491d8ee7SSantosh Puranik { 721491d8ee7SSantosh Puranik if (dbusSource == "xyz.openbmc_project.Control.Boot.Source.Sources.Default") 722491d8ee7SSantosh Puranik { 723491d8ee7SSantosh Puranik return "None"; 724491d8ee7SSantosh Puranik } 725491d8ee7SSantosh Puranik else if (dbusSource == 726491d8ee7SSantosh Puranik "xyz.openbmc_project.Control.Boot.Source.Sources.Disk") 727491d8ee7SSantosh Puranik { 728491d8ee7SSantosh Puranik return "Hdd"; 729491d8ee7SSantosh Puranik } 730491d8ee7SSantosh Puranik else if (dbusSource == 731a71dc0b7SSantosh Puranik "xyz.openbmc_project.Control.Boot.Source.Sources.ExternalMedia") 732491d8ee7SSantosh Puranik { 733491d8ee7SSantosh Puranik return "Cd"; 734491d8ee7SSantosh Puranik } 735491d8ee7SSantosh Puranik else if (dbusSource == 736491d8ee7SSantosh Puranik "xyz.openbmc_project.Control.Boot.Source.Sources.Network") 737491d8ee7SSantosh Puranik { 738491d8ee7SSantosh Puranik return "Pxe"; 739491d8ee7SSantosh Puranik } 7409f16b2c1SJennifer Lee else if (dbusSource == 741944ffaf9SJohnathan Mantey "xyz.openbmc_project.Control.Boot.Source.Sources.RemovableMedia") 7429f16b2c1SJennifer Lee { 7439f16b2c1SJennifer Lee return "Usb"; 7449f16b2c1SJennifer Lee } 745491d8ee7SSantosh Puranik else 746491d8ee7SSantosh Puranik { 747491d8ee7SSantosh Puranik return ""; 748491d8ee7SSantosh Puranik } 749491d8ee7SSantosh Puranik } 750491d8ee7SSantosh Puranik 751491d8ee7SSantosh Puranik /** 752491d8ee7SSantosh Puranik * @brief Traslates boot mode DBUS property value to redfish. 753491d8ee7SSantosh Puranik * 754491d8ee7SSantosh Puranik * @param[in] dbusMode The boot mode in DBUS speak. 755491d8ee7SSantosh Puranik * 756491d8ee7SSantosh Puranik * @return Returns as a string, the boot mode in Redfish terms. If translation 757491d8ee7SSantosh Puranik * cannot be done, returns an empty string. 758491d8ee7SSantosh Puranik */ 759491d8ee7SSantosh Puranik static std::string dbusToRfBootMode(const std::string &dbusMode) 760491d8ee7SSantosh Puranik { 761491d8ee7SSantosh Puranik if (dbusMode == "xyz.openbmc_project.Control.Boot.Mode.Modes.Regular") 762491d8ee7SSantosh Puranik { 763491d8ee7SSantosh Puranik return "None"; 764491d8ee7SSantosh Puranik } 765491d8ee7SSantosh Puranik else if (dbusMode == "xyz.openbmc_project.Control.Boot.Mode.Modes.Safe") 766491d8ee7SSantosh Puranik { 767491d8ee7SSantosh Puranik return "Diags"; 768491d8ee7SSantosh Puranik } 769491d8ee7SSantosh Puranik else if (dbusMode == "xyz.openbmc_project.Control.Boot.Mode.Modes.Setup") 770491d8ee7SSantosh Puranik { 771491d8ee7SSantosh Puranik return "BiosSetup"; 772491d8ee7SSantosh Puranik } 773491d8ee7SSantosh Puranik else 774491d8ee7SSantosh Puranik { 775491d8ee7SSantosh Puranik return ""; 776491d8ee7SSantosh Puranik } 777491d8ee7SSantosh Puranik } 778491d8ee7SSantosh Puranik 779491d8ee7SSantosh Puranik /** 780944ffaf9SJohnathan Mantey * @brief Traslates boot source from Redfish to the DBus boot paths. 781491d8ee7SSantosh Puranik * 782491d8ee7SSantosh Puranik * @param[in] rfSource The boot source in Redfish. 783944ffaf9SJohnathan Mantey * @param[out] bootSource The DBus source 784944ffaf9SJohnathan Mantey * @param[out] bootMode the DBus boot mode 785491d8ee7SSantosh Puranik * 786944ffaf9SJohnathan Mantey * @return Integer error code. 787491d8ee7SSantosh Puranik */ 788944ffaf9SJohnathan Mantey static int assignBootParameters(std::shared_ptr<AsyncResp> aResp, 789944ffaf9SJohnathan Mantey const std::string &rfSource, 790944ffaf9SJohnathan Mantey std::string &bootSource, std::string &bootMode) 791491d8ee7SSantosh Puranik { 792944ffaf9SJohnathan Mantey // The caller has initialized the bootSource and bootMode to: 793944ffaf9SJohnathan Mantey // bootMode = "xyz.openbmc_project.Control.Boot.Mode.Modes.Regular"; 794944ffaf9SJohnathan Mantey // bootSource = "xyz.openbmc_project.Control.Boot.Source.Sources.Default"; 795944ffaf9SJohnathan Mantey // Only modify the bootSource/bootMode variable needed to achieve the 796944ffaf9SJohnathan Mantey // desired boot action. 797944ffaf9SJohnathan Mantey 798491d8ee7SSantosh Puranik if (rfSource == "None") 799491d8ee7SSantosh Puranik { 800944ffaf9SJohnathan Mantey return 0; 801491d8ee7SSantosh Puranik } 802491d8ee7SSantosh Puranik else if (rfSource == "Pxe") 803491d8ee7SSantosh Puranik { 804944ffaf9SJohnathan Mantey bootSource = "xyz.openbmc_project.Control.Boot.Source.Sources.Network"; 805944ffaf9SJohnathan Mantey } 806944ffaf9SJohnathan Mantey else if (rfSource == "Hdd") 807944ffaf9SJohnathan Mantey { 808944ffaf9SJohnathan Mantey bootSource = "xyz.openbmc_project.Control.Boot.Source.Sources.Disk"; 809944ffaf9SJohnathan Mantey } 810944ffaf9SJohnathan Mantey else if (rfSource == "Diags") 811944ffaf9SJohnathan Mantey { 812944ffaf9SJohnathan Mantey bootMode = "xyz.openbmc_project.Control.Boot.Mode.Modes.Safe"; 813944ffaf9SJohnathan Mantey } 814944ffaf9SJohnathan Mantey else if (rfSource == "Cd") 815944ffaf9SJohnathan Mantey { 816944ffaf9SJohnathan Mantey bootSource = 817944ffaf9SJohnathan Mantey "xyz.openbmc_project.Control.Boot.Source.Sources.ExternalMedia"; 818944ffaf9SJohnathan Mantey } 819944ffaf9SJohnathan Mantey else if (rfSource == "BiosSetup") 820944ffaf9SJohnathan Mantey { 821944ffaf9SJohnathan Mantey bootMode = "xyz.openbmc_project.Control.Boot.Mode.Modes.Setup"; 822491d8ee7SSantosh Puranik } 8239f16b2c1SJennifer Lee else if (rfSource == "Usb") 8249f16b2c1SJennifer Lee { 825944ffaf9SJohnathan Mantey bootSource = 826944ffaf9SJohnathan Mantey "xyz.openbmc_project.Control.Boot.Source.Sources.RemovableMedia"; 8279f16b2c1SJennifer Lee } 828491d8ee7SSantosh Puranik else 829491d8ee7SSantosh Puranik { 830944ffaf9SJohnathan Mantey BMCWEB_LOG_DEBUG << "Invalid property value for " 831944ffaf9SJohnathan Mantey "BootSourceOverrideTarget: " 832944ffaf9SJohnathan Mantey << bootSource; 833944ffaf9SJohnathan Mantey messages::propertyValueNotInList(aResp->res, rfSource, 834944ffaf9SJohnathan Mantey "BootSourceTargetOverride"); 835944ffaf9SJohnathan Mantey return -1; 836491d8ee7SSantosh Puranik } 837944ffaf9SJohnathan Mantey return 0; 838491d8ee7SSantosh Puranik } 839491d8ee7SSantosh Puranik 840491d8ee7SSantosh Puranik /** 841491d8ee7SSantosh Puranik * @brief Retrieves boot mode over DBUS and fills out the response 842491d8ee7SSantosh Puranik * 843491d8ee7SSantosh Puranik * @param[in] aResp Shared pointer for generating response message. 844491d8ee7SSantosh Puranik * @param[in] bootDbusObj The dbus object to query for boot properties. 845491d8ee7SSantosh Puranik * 846491d8ee7SSantosh Puranik * @return None. 847491d8ee7SSantosh Puranik */ 848491d8ee7SSantosh Puranik static void getBootMode(std::shared_ptr<AsyncResp> aResp, 849491d8ee7SSantosh Puranik std::string bootDbusObj) 850491d8ee7SSantosh Puranik { 851491d8ee7SSantosh Puranik crow::connections::systemBus->async_method_call( 852491d8ee7SSantosh Puranik [aResp](const boost::system::error_code ec, 853491d8ee7SSantosh Puranik const std::variant<std::string> &bootMode) { 854491d8ee7SSantosh Puranik if (ec) 855491d8ee7SSantosh Puranik { 856491d8ee7SSantosh Puranik BMCWEB_LOG_DEBUG << "DBUS response error " << ec; 857491d8ee7SSantosh Puranik messages::internalError(aResp->res); 858491d8ee7SSantosh Puranik return; 859491d8ee7SSantosh Puranik } 860491d8ee7SSantosh Puranik 861491d8ee7SSantosh Puranik const std::string *bootModeStr = 862491d8ee7SSantosh Puranik std::get_if<std::string>(&bootMode); 863491d8ee7SSantosh Puranik 864491d8ee7SSantosh Puranik if (!bootModeStr) 865491d8ee7SSantosh Puranik { 866491d8ee7SSantosh Puranik messages::internalError(aResp->res); 867491d8ee7SSantosh Puranik return; 868491d8ee7SSantosh Puranik } 869491d8ee7SSantosh Puranik 870491d8ee7SSantosh Puranik BMCWEB_LOG_DEBUG << "Boot mode: " << *bootModeStr; 871491d8ee7SSantosh Puranik 872491d8ee7SSantosh Puranik // TODO (Santosh): Do we need to support override mode? 873491d8ee7SSantosh Puranik aResp->res.jsonValue["Boot"]["BootSourceOverrideMode"] = "Legacy"; 874491d8ee7SSantosh Puranik aResp->res.jsonValue["Boot"]["BootSourceOverrideTarget@Redfish." 875491d8ee7SSantosh Puranik "AllowableValues"] = { 876944ffaf9SJohnathan Mantey "None", "Pxe", "Hdd", "Cd", "Diags", "BiosSetup", "Usb"}; 877491d8ee7SSantosh Puranik 878491d8ee7SSantosh Puranik if (*bootModeStr != 879491d8ee7SSantosh Puranik "xyz.openbmc_project.Control.Boot.Mode.Modes.Regular") 880491d8ee7SSantosh Puranik { 881491d8ee7SSantosh Puranik auto rfMode = dbusToRfBootMode(*bootModeStr); 882491d8ee7SSantosh Puranik if (!rfMode.empty()) 883491d8ee7SSantosh Puranik { 884491d8ee7SSantosh Puranik aResp->res.jsonValue["Boot"]["BootSourceOverrideTarget"] = 885491d8ee7SSantosh Puranik rfMode; 886491d8ee7SSantosh Puranik } 887491d8ee7SSantosh Puranik } 888491d8ee7SSantosh Puranik 889491d8ee7SSantosh Puranik // If the BootSourceOverrideTarget is still "None" at the end, 890491d8ee7SSantosh Puranik // reset the BootSourceOverrideEnabled to indicate that 891491d8ee7SSantosh Puranik // overrides are disabled 892491d8ee7SSantosh Puranik if (aResp->res.jsonValue["Boot"]["BootSourceOverrideTarget"] == 893491d8ee7SSantosh Puranik "None") 894491d8ee7SSantosh Puranik { 895491d8ee7SSantosh Puranik aResp->res.jsonValue["Boot"]["BootSourceOverrideEnabled"] = 896491d8ee7SSantosh Puranik "Disabled"; 897491d8ee7SSantosh Puranik } 898491d8ee7SSantosh Puranik }, 899491d8ee7SSantosh Puranik "xyz.openbmc_project.Settings", bootDbusObj, 900491d8ee7SSantosh Puranik "org.freedesktop.DBus.Properties", "Get", 901491d8ee7SSantosh Puranik "xyz.openbmc_project.Control.Boot.Mode", "BootMode"); 902491d8ee7SSantosh Puranik } 903491d8ee7SSantosh Puranik 904491d8ee7SSantosh Puranik /** 905491d8ee7SSantosh Puranik * @brief Retrieves boot source over DBUS 906491d8ee7SSantosh Puranik * 907491d8ee7SSantosh Puranik * @param[in] aResp Shared pointer for generating response message. 908491d8ee7SSantosh Puranik * @param[in] oneTimeEnable Boolean to indicate boot properties are one-time. 909491d8ee7SSantosh Puranik * 910491d8ee7SSantosh Puranik * @return None. 911491d8ee7SSantosh Puranik */ 912491d8ee7SSantosh Puranik static void getBootSource(std::shared_ptr<AsyncResp> aResp, bool oneTimeEnabled) 913491d8ee7SSantosh Puranik { 914491d8ee7SSantosh Puranik std::string bootDbusObj = 915491d8ee7SSantosh Puranik oneTimeEnabled ? "/xyz/openbmc_project/control/host0/boot/one_time" 916491d8ee7SSantosh Puranik : "/xyz/openbmc_project/control/host0/boot"; 917491d8ee7SSantosh Puranik 918491d8ee7SSantosh Puranik BMCWEB_LOG_DEBUG << "Is one time: " << oneTimeEnabled; 919491d8ee7SSantosh Puranik aResp->res.jsonValue["Boot"]["BootSourceOverrideEnabled"] = 920491d8ee7SSantosh Puranik (oneTimeEnabled) ? "Once" : "Continuous"; 921491d8ee7SSantosh Puranik 922491d8ee7SSantosh Puranik crow::connections::systemBus->async_method_call( 923491d8ee7SSantosh Puranik [aResp, bootDbusObj](const boost::system::error_code ec, 924491d8ee7SSantosh Puranik const std::variant<std::string> &bootSource) { 925491d8ee7SSantosh Puranik if (ec) 926491d8ee7SSantosh Puranik { 927491d8ee7SSantosh Puranik BMCWEB_LOG_DEBUG << "DBUS response error " << ec; 928491d8ee7SSantosh Puranik messages::internalError(aResp->res); 929491d8ee7SSantosh Puranik return; 930491d8ee7SSantosh Puranik } 931491d8ee7SSantosh Puranik 932491d8ee7SSantosh Puranik const std::string *bootSourceStr = 933491d8ee7SSantosh Puranik std::get_if<std::string>(&bootSource); 934491d8ee7SSantosh Puranik 935491d8ee7SSantosh Puranik if (!bootSourceStr) 936491d8ee7SSantosh Puranik { 937491d8ee7SSantosh Puranik messages::internalError(aResp->res); 938491d8ee7SSantosh Puranik return; 939491d8ee7SSantosh Puranik } 940491d8ee7SSantosh Puranik BMCWEB_LOG_DEBUG << "Boot source: " << *bootSourceStr; 941491d8ee7SSantosh Puranik 942491d8ee7SSantosh Puranik auto rfSource = dbusToRfBootSource(*bootSourceStr); 943491d8ee7SSantosh Puranik if (!rfSource.empty()) 944491d8ee7SSantosh Puranik { 945491d8ee7SSantosh Puranik aResp->res.jsonValue["Boot"]["BootSourceOverrideTarget"] = 946491d8ee7SSantosh Puranik rfSource; 947491d8ee7SSantosh Puranik } 948491d8ee7SSantosh Puranik }, 949491d8ee7SSantosh Puranik "xyz.openbmc_project.Settings", bootDbusObj, 950491d8ee7SSantosh Puranik "org.freedesktop.DBus.Properties", "Get", 951491d8ee7SSantosh Puranik "xyz.openbmc_project.Control.Boot.Source", "BootSource"); 952491d8ee7SSantosh Puranik getBootMode(std::move(aResp), std::move(bootDbusObj)); 953491d8ee7SSantosh Puranik } 954491d8ee7SSantosh Puranik 955491d8ee7SSantosh Puranik /** 956491d8ee7SSantosh Puranik * @brief Retrieves "One time" enabled setting over DBUS and calls function to 957491d8ee7SSantosh Puranik * get boot source and boot mode. 958491d8ee7SSantosh Puranik * 959491d8ee7SSantosh Puranik * @param[in] aResp Shared pointer for generating response message. 960491d8ee7SSantosh Puranik * 961491d8ee7SSantosh Puranik * @return None. 962491d8ee7SSantosh Puranik */ 963491d8ee7SSantosh Puranik static void getBootProperties(std::shared_ptr<AsyncResp> aResp) 964491d8ee7SSantosh Puranik { 965491d8ee7SSantosh Puranik BMCWEB_LOG_DEBUG << "Get boot information."; 966491d8ee7SSantosh Puranik 967491d8ee7SSantosh Puranik crow::connections::systemBus->async_method_call( 968c5d03ff4SJennifer Lee [aResp](const boost::system::error_code ec, 969491d8ee7SSantosh Puranik const sdbusplus::message::variant<bool> &oneTime) { 970491d8ee7SSantosh Puranik if (ec) 971491d8ee7SSantosh Puranik { 972491d8ee7SSantosh Puranik BMCWEB_LOG_DEBUG << "DBUS response error " << ec; 9732a833c77SJames Feist // not an error, don't have to have the interface 974491d8ee7SSantosh Puranik return; 975491d8ee7SSantosh Puranik } 976491d8ee7SSantosh Puranik 977491d8ee7SSantosh Puranik const bool *oneTimePtr = std::get_if<bool>(&oneTime); 978491d8ee7SSantosh Puranik 979491d8ee7SSantosh Puranik if (!oneTimePtr) 980491d8ee7SSantosh Puranik { 981491d8ee7SSantosh Puranik messages::internalError(aResp->res); 982491d8ee7SSantosh Puranik return; 983491d8ee7SSantosh Puranik } 984491d8ee7SSantosh Puranik getBootSource(aResp, *oneTimePtr); 985491d8ee7SSantosh Puranik }, 986491d8ee7SSantosh Puranik "xyz.openbmc_project.Settings", 987491d8ee7SSantosh Puranik "/xyz/openbmc_project/control/host0/boot/one_time", 988491d8ee7SSantosh Puranik "org.freedesktop.DBus.Properties", "Get", 989491d8ee7SSantosh Puranik "xyz.openbmc_project.Object.Enable", "Enabled"); 990491d8ee7SSantosh Puranik } 991491d8ee7SSantosh Puranik 992491d8ee7SSantosh Puranik /** 993491d8ee7SSantosh Puranik * @brief Sets boot properties into DBUS object(s). 994491d8ee7SSantosh Puranik * 995491d8ee7SSantosh Puranik * @param[in] aResp Shared pointer for generating response message. 996491d8ee7SSantosh Puranik * @param[in] oneTimeEnabled Is "one-time" setting already enabled. 997491d8ee7SSantosh Puranik * @param[in] bootSource The boot source to set. 998491d8ee7SSantosh Puranik * @param[in] bootEnable The source override "enable" to set. 999491d8ee7SSantosh Puranik * 1000265c1602SJohnathan Mantey * @return Integer error code. 1001491d8ee7SSantosh Puranik */ 1002491d8ee7SSantosh Puranik static void setBootModeOrSource(std::shared_ptr<AsyncResp> aResp, 1003491d8ee7SSantosh Puranik bool oneTimeEnabled, 1004491d8ee7SSantosh Puranik std::optional<std::string> bootSource, 1005491d8ee7SSantosh Puranik std::optional<std::string> bootEnable) 1006491d8ee7SSantosh Puranik { 1007944ffaf9SJohnathan Mantey std::string bootSourceStr = 1008944ffaf9SJohnathan Mantey "xyz.openbmc_project.Control.Boot.Source.Sources.Default"; 1009944ffaf9SJohnathan Mantey std::string bootModeStr = 1010944ffaf9SJohnathan Mantey "xyz.openbmc_project.Control.Boot.Mode.Modes.Regular"; 1011491d8ee7SSantosh Puranik bool oneTimeSetting = oneTimeEnabled; 1012944ffaf9SJohnathan Mantey bool useBootSource = true; 1013944ffaf9SJohnathan Mantey 1014491d8ee7SSantosh Puranik // Validate incoming parameters 1015491d8ee7SSantosh Puranik if (bootEnable) 1016491d8ee7SSantosh Puranik { 1017491d8ee7SSantosh Puranik if (*bootEnable == "Once") 1018491d8ee7SSantosh Puranik { 1019491d8ee7SSantosh Puranik oneTimeSetting = true; 1020491d8ee7SSantosh Puranik } 1021491d8ee7SSantosh Puranik else if (*bootEnable == "Continuous") 1022491d8ee7SSantosh Puranik { 1023491d8ee7SSantosh Puranik oneTimeSetting = false; 1024491d8ee7SSantosh Puranik } 1025491d8ee7SSantosh Puranik else if (*bootEnable == "Disabled") 1026491d8ee7SSantosh Puranik { 1027944ffaf9SJohnathan Mantey BMCWEB_LOG_DEBUG << "Boot source override will be disabled"; 1028491d8ee7SSantosh Puranik oneTimeSetting = false; 1029944ffaf9SJohnathan Mantey useBootSource = false; 1030491d8ee7SSantosh Puranik } 1031491d8ee7SSantosh Puranik else 1032491d8ee7SSantosh Puranik { 1033491d8ee7SSantosh Puranik BMCWEB_LOG_DEBUG << "Unsupported value for " 1034491d8ee7SSantosh Puranik "BootSourceOverrideEnabled: " 1035491d8ee7SSantosh Puranik << *bootEnable; 1036491d8ee7SSantosh Puranik messages::propertyValueNotInList(aResp->res, *bootEnable, 1037491d8ee7SSantosh Puranik "BootSourceOverrideEnabled"); 1038491d8ee7SSantosh Puranik return; 1039491d8ee7SSantosh Puranik } 1040491d8ee7SSantosh Puranik } 1041491d8ee7SSantosh Puranik 1042944ffaf9SJohnathan Mantey if (bootSource && useBootSource) 1043491d8ee7SSantosh Puranik { 1044491d8ee7SSantosh Puranik // Source target specified 1045491d8ee7SSantosh Puranik BMCWEB_LOG_DEBUG << "Boot source: " << *bootSource; 1046491d8ee7SSantosh Puranik // Figure out which DBUS interface and property to use 1047944ffaf9SJohnathan Mantey if (assignBootParameters(aResp, *bootSource, bootSourceStr, 1048944ffaf9SJohnathan Mantey bootModeStr)) 1049491d8ee7SSantosh Puranik { 1050944ffaf9SJohnathan Mantey BMCWEB_LOG_DEBUG 1051944ffaf9SJohnathan Mantey << "Invalid property value for BootSourceOverrideTarget: " 1052491d8ee7SSantosh Puranik << *bootSource; 1053491d8ee7SSantosh Puranik messages::propertyValueNotInList(aResp->res, *bootSource, 1054491d8ee7SSantosh Puranik "BootSourceTargetOverride"); 1055491d8ee7SSantosh Puranik return; 1056491d8ee7SSantosh Puranik } 1057944ffaf9SJohnathan Mantey } 1058491d8ee7SSantosh Puranik 1059944ffaf9SJohnathan Mantey // Act on validated parameters 1060944ffaf9SJohnathan Mantey BMCWEB_LOG_DEBUG << "DBUS boot source: " << bootSourceStr; 1061944ffaf9SJohnathan Mantey BMCWEB_LOG_DEBUG << "DBUS boot mode: " << bootModeStr; 1062944ffaf9SJohnathan Mantey const char *bootObj = 1063944ffaf9SJohnathan Mantey oneTimeSetting ? "/xyz/openbmc_project/control/host0/boot/one_time" 1064944ffaf9SJohnathan Mantey : "/xyz/openbmc_project/control/host0/boot"; 1065944ffaf9SJohnathan Mantey 1066491d8ee7SSantosh Puranik crow::connections::systemBus->async_method_call( 1067491d8ee7SSantosh Puranik [aResp](const boost::system::error_code ec) { 1068491d8ee7SSantosh Puranik if (ec) 1069491d8ee7SSantosh Puranik { 1070491d8ee7SSantosh Puranik BMCWEB_LOG_DEBUG << "DBUS response error " << ec; 1071491d8ee7SSantosh Puranik messages::internalError(aResp->res); 1072491d8ee7SSantosh Puranik return; 1073491d8ee7SSantosh Puranik } 1074491d8ee7SSantosh Puranik BMCWEB_LOG_DEBUG << "Boot source update done."; 1075491d8ee7SSantosh Puranik }, 1076491d8ee7SSantosh Puranik "xyz.openbmc_project.Settings", bootObj, 1077491d8ee7SSantosh Puranik "org.freedesktop.DBus.Properties", "Set", 1078491d8ee7SSantosh Puranik "xyz.openbmc_project.Control.Boot.Source", "BootSource", 1079491d8ee7SSantosh Puranik std::variant<std::string>(bootSourceStr)); 1080944ffaf9SJohnathan Mantey 1081491d8ee7SSantosh Puranik crow::connections::systemBus->async_method_call( 1082491d8ee7SSantosh Puranik [aResp](const boost::system::error_code ec) { 1083491d8ee7SSantosh Puranik if (ec) 1084491d8ee7SSantosh Puranik { 1085491d8ee7SSantosh Puranik BMCWEB_LOG_DEBUG << "DBUS response error " << ec; 1086491d8ee7SSantosh Puranik messages::internalError(aResp->res); 1087491d8ee7SSantosh Puranik return; 1088491d8ee7SSantosh Puranik } 1089491d8ee7SSantosh Puranik BMCWEB_LOG_DEBUG << "Boot mode update done."; 1090491d8ee7SSantosh Puranik }, 1091491d8ee7SSantosh Puranik "xyz.openbmc_project.Settings", bootObj, 1092491d8ee7SSantosh Puranik "org.freedesktop.DBus.Properties", "Set", 1093491d8ee7SSantosh Puranik "xyz.openbmc_project.Control.Boot.Mode", "BootMode", 1094491d8ee7SSantosh Puranik std::variant<std::string>(bootModeStr)); 1095944ffaf9SJohnathan Mantey 1096491d8ee7SSantosh Puranik crow::connections::systemBus->async_method_call( 1097491d8ee7SSantosh Puranik [aResp{std::move(aResp)}](const boost::system::error_code ec) { 1098491d8ee7SSantosh Puranik if (ec) 1099491d8ee7SSantosh Puranik { 1100491d8ee7SSantosh Puranik BMCWEB_LOG_DEBUG << "DBUS response error " << ec; 1101491d8ee7SSantosh Puranik messages::internalError(aResp->res); 1102491d8ee7SSantosh Puranik return; 1103491d8ee7SSantosh Puranik } 1104491d8ee7SSantosh Puranik BMCWEB_LOG_DEBUG << "Boot enable update done."; 1105491d8ee7SSantosh Puranik }, 1106491d8ee7SSantosh Puranik "xyz.openbmc_project.Settings", 1107491d8ee7SSantosh Puranik "/xyz/openbmc_project/control/host0/boot/one_time", 1108491d8ee7SSantosh Puranik "org.freedesktop.DBus.Properties", "Set", 1109491d8ee7SSantosh Puranik "xyz.openbmc_project.Object.Enable", "Enabled", 1110491d8ee7SSantosh Puranik std::variant<bool>(oneTimeSetting)); 1111491d8ee7SSantosh Puranik } 1112491d8ee7SSantosh Puranik 1113491d8ee7SSantosh Puranik /** 1114491d8ee7SSantosh Puranik * @brief Retrieves "One time" enabled setting over DBUS and calls function to 1115491d8ee7SSantosh Puranik * set boot source/boot mode properties. 1116491d8ee7SSantosh Puranik * 1117491d8ee7SSantosh Puranik * @param[in] aResp Shared pointer for generating response message. 1118491d8ee7SSantosh Puranik * @param[in] bootSource The boot source from incoming RF request. 1119491d8ee7SSantosh Puranik * @param[in] bootEnable The boot override enable from incoming RF request. 1120491d8ee7SSantosh Puranik * 1121265c1602SJohnathan Mantey * @return Integer error code. 1122491d8ee7SSantosh Puranik */ 1123491d8ee7SSantosh Puranik static void setBootProperties(std::shared_ptr<AsyncResp> aResp, 1124491d8ee7SSantosh Puranik std::optional<std::string> bootSource, 1125491d8ee7SSantosh Puranik std::optional<std::string> bootEnable) 1126491d8ee7SSantosh Puranik { 1127491d8ee7SSantosh Puranik BMCWEB_LOG_DEBUG << "Set boot information."; 1128491d8ee7SSantosh Puranik 1129491d8ee7SSantosh Puranik crow::connections::systemBus->async_method_call( 1130265c1602SJohnathan Mantey [aResp, bootSource{std::move(bootSource)}, 1131491d8ee7SSantosh Puranik bootEnable{std::move(bootEnable)}]( 1132491d8ee7SSantosh Puranik const boost::system::error_code ec, 1133491d8ee7SSantosh Puranik const sdbusplus::message::variant<bool> &oneTime) { 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 1141491d8ee7SSantosh Puranik const bool *oneTimePtr = std::get_if<bool>(&oneTime); 1142491d8ee7SSantosh Puranik 1143491d8ee7SSantosh Puranik if (!oneTimePtr) 1144491d8ee7SSantosh Puranik { 1145491d8ee7SSantosh Puranik messages::internalError(aResp->res); 1146491d8ee7SSantosh Puranik return; 1147491d8ee7SSantosh Puranik } 1148491d8ee7SSantosh Puranik 1149491d8ee7SSantosh Puranik BMCWEB_LOG_DEBUG << "Got one time: " << *oneTimePtr; 1150491d8ee7SSantosh Puranik 1151491d8ee7SSantosh Puranik setBootModeOrSource(aResp, *oneTimePtr, std::move(bootSource), 1152491d8ee7SSantosh Puranik std::move(bootEnable)); 1153491d8ee7SSantosh Puranik }, 1154491d8ee7SSantosh Puranik "xyz.openbmc_project.Settings", 1155491d8ee7SSantosh Puranik "/xyz/openbmc_project/control/host0/boot/one_time", 1156491d8ee7SSantosh Puranik "org.freedesktop.DBus.Properties", "Get", 1157491d8ee7SSantosh Puranik "xyz.openbmc_project.Object.Enable", "Enabled"); 1158491d8ee7SSantosh Puranik } 1159491d8ee7SSantosh Puranik 1160491d8ee7SSantosh Puranik /** 116151709ffdSYong Li * @brief Translates watchdog timeout action DBUS property value to redfish. 116251709ffdSYong Li * 116351709ffdSYong Li * @param[in] dbusAction The watchdog timeout action in D-BUS. 116451709ffdSYong Li * 116551709ffdSYong Li * @return Returns as a string, the timeout action in Redfish terms. If 116651709ffdSYong Li * translation cannot be done, returns an empty string. 116751709ffdSYong Li */ 116851709ffdSYong Li static std::string dbusToRfWatchdogAction(const std::string &dbusAction) 116951709ffdSYong Li { 117051709ffdSYong Li if (dbusAction == "xyz.openbmc_project.State.Watchdog.Action.None") 117151709ffdSYong Li { 117251709ffdSYong Li return "None"; 117351709ffdSYong Li } 117451709ffdSYong Li else if (dbusAction == 117551709ffdSYong Li "xyz.openbmc_project.State.Watchdog.Action.HardReset") 117651709ffdSYong Li { 117751709ffdSYong Li return "ResetSystem"; 117851709ffdSYong Li } 117951709ffdSYong Li else if (dbusAction == "xyz.openbmc_project.State.Watchdog.Action.PowerOff") 118051709ffdSYong Li { 118151709ffdSYong Li return "PowerDown"; 118251709ffdSYong Li } 118351709ffdSYong Li else if (dbusAction == 118451709ffdSYong Li "xyz.openbmc_project.State.Watchdog.Action.PowerCycle") 118551709ffdSYong Li { 118651709ffdSYong Li return "PowerCycle"; 118751709ffdSYong Li } 118851709ffdSYong Li 118951709ffdSYong Li return ""; 119051709ffdSYong Li } 119151709ffdSYong Li 119251709ffdSYong Li /** 1193*c45f0082SYong Li *@brief Translates timeout action from Redfish to DBUS property value. 1194*c45f0082SYong Li * 1195*c45f0082SYong Li *@param[in] rfAction The timeout action in Redfish. 1196*c45f0082SYong Li * 1197*c45f0082SYong Li *@return Returns as a string, the time_out action as expected by DBUS. 1198*c45f0082SYong Li *If translation cannot be done, returns an empty string. 1199*c45f0082SYong Li */ 1200*c45f0082SYong Li 1201*c45f0082SYong Li static std::string rfToDbusWDTTimeOutAct(const std::string &rfAction) 1202*c45f0082SYong Li { 1203*c45f0082SYong Li if (rfAction == "None") 1204*c45f0082SYong Li { 1205*c45f0082SYong Li return "xyz.openbmc_project.State.Watchdog.Action.None"; 1206*c45f0082SYong Li } 1207*c45f0082SYong Li else if (rfAction == "PowerCycle") 1208*c45f0082SYong Li { 1209*c45f0082SYong Li return "xyz.openbmc_project.State.Watchdog.Action.PowerCycle"; 1210*c45f0082SYong Li } 1211*c45f0082SYong Li else if (rfAction == "PowerDown") 1212*c45f0082SYong Li { 1213*c45f0082SYong Li return "xyz.openbmc_project.State.Watchdog.Action.PowerOff"; 1214*c45f0082SYong Li } 1215*c45f0082SYong Li else if (rfAction == "ResetSystem") 1216*c45f0082SYong Li { 1217*c45f0082SYong Li return "xyz.openbmc_project.State.Watchdog.Action.HardReset"; 1218*c45f0082SYong Li } 1219*c45f0082SYong Li 1220*c45f0082SYong Li return ""; 1221*c45f0082SYong Li } 1222*c45f0082SYong Li 1223*c45f0082SYong Li /** 122451709ffdSYong Li * @brief Retrieves host watchdog timer properties over DBUS 122551709ffdSYong Li * 122651709ffdSYong Li * @param[in] aResp Shared pointer for completing asynchronous calls. 122751709ffdSYong Li * 122851709ffdSYong Li * @return None. 122951709ffdSYong Li */ 123051709ffdSYong Li void getHostWatchdogTimer(std::shared_ptr<AsyncResp> aResp) 123151709ffdSYong Li { 123251709ffdSYong Li BMCWEB_LOG_DEBUG << "Get host watchodg"; 123351709ffdSYong Li crow::connections::systemBus->async_method_call( 123451709ffdSYong Li [aResp](const boost::system::error_code ec, 123551709ffdSYong Li PropertiesType &properties) { 123651709ffdSYong Li if (ec) 123751709ffdSYong Li { 123851709ffdSYong Li // watchdog service is stopped 123951709ffdSYong Li BMCWEB_LOG_DEBUG << "DBUS response error " << ec; 124051709ffdSYong Li return; 124151709ffdSYong Li } 124251709ffdSYong Li 124351709ffdSYong Li BMCWEB_LOG_DEBUG << "Got " << properties.size() << " wdt prop."; 124451709ffdSYong Li 124551709ffdSYong Li nlohmann::json &hostWatchdogTimer = 124651709ffdSYong Li aResp->res.jsonValue["HostWatchdogTimer"]; 124751709ffdSYong Li 124851709ffdSYong Li // watchdog service is running/enabled 124951709ffdSYong Li hostWatchdogTimer["Status"]["State"] = "Enabled"; 125051709ffdSYong Li 125151709ffdSYong Li for (const auto &property : properties) 125251709ffdSYong Li { 125351709ffdSYong Li BMCWEB_LOG_DEBUG << "prop=" << property.first; 125451709ffdSYong Li if (property.first == "Enabled") 125551709ffdSYong Li { 125651709ffdSYong Li const bool *state = std::get_if<bool>(&property.second); 125751709ffdSYong Li 125851709ffdSYong Li if (!state) 125951709ffdSYong Li { 126051709ffdSYong Li messages::internalError(aResp->res); 126151709ffdSYong Li continue; 126251709ffdSYong Li } 126351709ffdSYong Li 126451709ffdSYong Li hostWatchdogTimer["FunctionEnabled"] = *state; 126551709ffdSYong Li } 126651709ffdSYong Li else if (property.first == "ExpireAction") 126751709ffdSYong Li { 126851709ffdSYong Li const std::string *s = 126951709ffdSYong Li std::get_if<std::string>(&property.second); 127051709ffdSYong Li if (!s) 127151709ffdSYong Li { 127251709ffdSYong Li messages::internalError(aResp->res); 127351709ffdSYong Li continue; 127451709ffdSYong Li } 127551709ffdSYong Li 127651709ffdSYong Li std::string action = dbusToRfWatchdogAction(*s); 127751709ffdSYong Li if (action.empty()) 127851709ffdSYong Li { 127951709ffdSYong Li messages::internalError(aResp->res); 128051709ffdSYong Li continue; 128151709ffdSYong Li } 128251709ffdSYong Li hostWatchdogTimer["TimeoutAction"] = action; 128351709ffdSYong Li } 128451709ffdSYong Li } 128551709ffdSYong Li }, 128651709ffdSYong Li "xyz.openbmc_project.Watchdog", "/xyz/openbmc_project/watchdog/host0", 128751709ffdSYong Li "org.freedesktop.DBus.Properties", "GetAll", 128851709ffdSYong Li "xyz.openbmc_project.State.Watchdog"); 128951709ffdSYong Li } 129051709ffdSYong Li 129151709ffdSYong Li /** 1292*c45f0082SYong Li * @brief Sets Host WatchDog Timer properties. 1293*c45f0082SYong Li * 1294*c45f0082SYong Li * @param[in] aResp Shared pointer for generating response message. 1295*c45f0082SYong Li * @param[in] wdtEnable The WDTimer Enable value (true/false) from incoming 1296*c45f0082SYong Li * RF request. 1297*c45f0082SYong Li * @param[in] wdtTimeOutAction The WDT Timeout action, from incoming RF request. 1298*c45f0082SYong Li * 1299*c45f0082SYong Li * @return None. 1300*c45f0082SYong Li */ 1301*c45f0082SYong Li static void setWDTProperties(std::shared_ptr<AsyncResp> aResp, 1302*c45f0082SYong Li const std::optional<bool> wdtEnable, 1303*c45f0082SYong Li const std::optional<std::string> &wdtTimeOutAction) 1304*c45f0082SYong Li { 1305*c45f0082SYong Li BMCWEB_LOG_DEBUG << "Set host watchdog"; 1306*c45f0082SYong Li 1307*c45f0082SYong Li if (wdtTimeOutAction) 1308*c45f0082SYong Li { 1309*c45f0082SYong Li std::string wdtTimeOutActStr = rfToDbusWDTTimeOutAct(*wdtTimeOutAction); 1310*c45f0082SYong Li // check if TimeOut Action is Valid 1311*c45f0082SYong Li if (wdtTimeOutActStr.empty()) 1312*c45f0082SYong Li { 1313*c45f0082SYong Li BMCWEB_LOG_DEBUG << "Unsupported value for TimeoutAction: " 1314*c45f0082SYong Li << *wdtTimeOutAction; 1315*c45f0082SYong Li messages::propertyValueNotInList(aResp->res, *wdtTimeOutAction, 1316*c45f0082SYong Li "TimeoutAction"); 1317*c45f0082SYong Li return; 1318*c45f0082SYong Li } 1319*c45f0082SYong Li 1320*c45f0082SYong Li crow::connections::systemBus->async_method_call( 1321*c45f0082SYong Li [aResp](const boost::system::error_code ec) { 1322*c45f0082SYong Li if (ec) 1323*c45f0082SYong Li { 1324*c45f0082SYong Li BMCWEB_LOG_DEBUG << "DBUS response error " << ec; 1325*c45f0082SYong Li messages::internalError(aResp->res); 1326*c45f0082SYong Li return; 1327*c45f0082SYong Li } 1328*c45f0082SYong Li }, 1329*c45f0082SYong Li "xyz.openbmc_project.Watchdog", 1330*c45f0082SYong Li "/xyz/openbmc_project/watchdog/host0", 1331*c45f0082SYong Li "org.freedesktop.DBus.Properties", "Set", 1332*c45f0082SYong Li "xyz.openbmc_project.State.Watchdog", "ExpireAction", 1333*c45f0082SYong Li std::variant<std::string>(wdtTimeOutActStr)); 1334*c45f0082SYong Li } 1335*c45f0082SYong Li 1336*c45f0082SYong Li if (wdtEnable) 1337*c45f0082SYong Li { 1338*c45f0082SYong Li crow::connections::systemBus->async_method_call( 1339*c45f0082SYong Li [aResp](const boost::system::error_code ec) { 1340*c45f0082SYong Li if (ec) 1341*c45f0082SYong Li { 1342*c45f0082SYong Li BMCWEB_LOG_DEBUG << "DBUS response error " << ec; 1343*c45f0082SYong Li messages::internalError(aResp->res); 1344*c45f0082SYong Li return; 1345*c45f0082SYong Li } 1346*c45f0082SYong Li }, 1347*c45f0082SYong Li "xyz.openbmc_project.Watchdog", 1348*c45f0082SYong Li "/xyz/openbmc_project/watchdog/host0", 1349*c45f0082SYong Li "org.freedesktop.DBus.Properties", "Set", 1350*c45f0082SYong Li "xyz.openbmc_project.State.Watchdog", "Enabled", 1351*c45f0082SYong Li std::variant<bool>(*wdtEnable)); 1352*c45f0082SYong Li } 1353*c45f0082SYong Li } 1354*c45f0082SYong Li 1355*c45f0082SYong Li /** 1356c5b2abe0SLewanczyk, Dawid * SystemsCollection derived class for delivering ComputerSystems Collection 1357c5b2abe0SLewanczyk, Dawid * Schema 1358c5b2abe0SLewanczyk, Dawid */ 13591abe55efSEd Tanous class SystemsCollection : public Node 13601abe55efSEd Tanous { 1361c5b2abe0SLewanczyk, Dawid public: 13621abe55efSEd Tanous SystemsCollection(CrowApp &app) : Node(app, "/redfish/v1/Systems/") 13631abe55efSEd Tanous { 1364c5b2abe0SLewanczyk, Dawid entityPrivileges = { 1365c5b2abe0SLewanczyk, Dawid {boost::beast::http::verb::get, {{"Login"}}}, 1366c5b2abe0SLewanczyk, Dawid {boost::beast::http::verb::head, {{"Login"}}}, 1367c5b2abe0SLewanczyk, Dawid {boost::beast::http::verb::patch, {{"ConfigureComponents"}}}, 1368c5b2abe0SLewanczyk, Dawid {boost::beast::http::verb::put, {{"ConfigureComponents"}}}, 1369c5b2abe0SLewanczyk, Dawid {boost::beast::http::verb::delete_, {{"ConfigureComponents"}}}, 1370c5b2abe0SLewanczyk, Dawid {boost::beast::http::verb::post, {{"ConfigureComponents"}}}}; 1371c5b2abe0SLewanczyk, Dawid } 1372c5b2abe0SLewanczyk, Dawid 1373c5b2abe0SLewanczyk, Dawid private: 137455c7b7a2SEd Tanous void doGet(crow::Response &res, const crow::Request &req, 13751abe55efSEd Tanous const std::vector<std::string> ¶ms) override 13761abe55efSEd Tanous { 13770f74e643SEd Tanous res.jsonValue["@odata.type"] = 13780f74e643SEd Tanous "#ComputerSystemCollection.ComputerSystemCollection"; 13790f74e643SEd Tanous res.jsonValue["@odata.id"] = "/redfish/v1/Systems"; 13800f74e643SEd Tanous res.jsonValue["@odata.context"] = 13810f74e643SEd Tanous "/redfish/v1/" 13820f74e643SEd Tanous "$metadata#ComputerSystemCollection.ComputerSystemCollection"; 13830f74e643SEd Tanous res.jsonValue["Name"] = "Computer System Collection"; 1384029573d4SEd Tanous res.jsonValue["Members"] = { 1385029573d4SEd Tanous {{"@odata.id", "/redfish/v1/Systems/system"}}}; 1386029573d4SEd Tanous res.jsonValue["Members@odata.count"] = 1; 1387029573d4SEd Tanous res.end(); 1388c5b2abe0SLewanczyk, Dawid } 1389c5b2abe0SLewanczyk, Dawid }; 1390c5b2abe0SLewanczyk, Dawid 1391c5b2abe0SLewanczyk, Dawid /** 1392cc340dd9SEd Tanous * SystemActionsReset class supports handle POST method for Reset action. 1393cc340dd9SEd Tanous * The class retrieves and sends data directly to D-Bus. 1394cc340dd9SEd Tanous */ 1395cc340dd9SEd Tanous class SystemActionsReset : public Node 1396cc340dd9SEd Tanous { 1397cc340dd9SEd Tanous public: 1398cc340dd9SEd Tanous SystemActionsReset(CrowApp &app) : 1399029573d4SEd Tanous Node(app, "/redfish/v1/Systems/system/Actions/ComputerSystem.Reset/") 1400cc340dd9SEd Tanous { 1401cc340dd9SEd Tanous entityPrivileges = { 1402cc340dd9SEd Tanous {boost::beast::http::verb::post, {{"ConfigureComponents"}}}}; 1403cc340dd9SEd Tanous } 1404cc340dd9SEd Tanous 1405cc340dd9SEd Tanous private: 1406cc340dd9SEd Tanous /** 1407cc340dd9SEd Tanous * Function handles POST method request. 1408cc340dd9SEd Tanous * Analyzes POST body message before sends Reset request data to D-Bus. 1409cc340dd9SEd Tanous */ 1410cc340dd9SEd Tanous void doPost(crow::Response &res, const crow::Request &req, 1411cc340dd9SEd Tanous const std::vector<std::string> ¶ms) override 1412cc340dd9SEd Tanous { 1413cc340dd9SEd Tanous auto asyncResp = std::make_shared<AsyncResp>(res); 1414cc340dd9SEd Tanous 14159712f8acSEd Tanous std::string resetType; 14169712f8acSEd Tanous if (!json_util::readJson(req, res, "ResetType", resetType)) 1417cc340dd9SEd Tanous { 1418cc340dd9SEd Tanous return; 1419cc340dd9SEd Tanous } 1420cc340dd9SEd Tanous 1421d22c8396SJason M. Bills // Get the command and host vs. chassis 1422cc340dd9SEd Tanous std::string command; 1423d22c8396SJason M. Bills bool hostCommand; 14249712f8acSEd Tanous if (resetType == "On") 1425cc340dd9SEd Tanous { 1426cc340dd9SEd Tanous command = "xyz.openbmc_project.State.Host.Transition.On"; 1427d22c8396SJason M. Bills hostCommand = true; 1428d22c8396SJason M. Bills } 1429d22c8396SJason M. Bills else if (resetType == "ForceOff") 1430d22c8396SJason M. Bills { 1431d22c8396SJason M. Bills command = "xyz.openbmc_project.State.Chassis.Transition.Off"; 1432d22c8396SJason M. Bills hostCommand = false; 1433d22c8396SJason M. Bills } 1434d22c8396SJason M. Bills else if (resetType == "ForceOn") 1435d22c8396SJason M. Bills { 1436d22c8396SJason M. Bills command = "xyz.openbmc_project.State.Host.Transition.On"; 1437d22c8396SJason M. Bills hostCommand = true; 1438d22c8396SJason M. Bills } 1439d22c8396SJason M. Bills else if (resetType == "ForceRestart") 1440d22c8396SJason M. Bills { 1441d22c8396SJason M. Bills command = "xyz.openbmc_project.State.Chassis.Transition.Reset"; 1442d22c8396SJason M. Bills hostCommand = false; 1443cc340dd9SEd Tanous } 14449712f8acSEd Tanous else if (resetType == "GracefulShutdown") 1445cc340dd9SEd Tanous { 1446cc340dd9SEd Tanous command = "xyz.openbmc_project.State.Host.Transition.Off"; 1447d22c8396SJason M. Bills hostCommand = true; 1448cc340dd9SEd Tanous } 14499712f8acSEd Tanous else if (resetType == "GracefulRestart") 1450cc340dd9SEd Tanous { 14519712f8acSEd Tanous command = "xyz.openbmc_project.State.Host.Transition.Reboot"; 1452d22c8396SJason M. Bills hostCommand = true; 1453d22c8396SJason M. Bills } 1454d22c8396SJason M. Bills else if (resetType == "PowerCycle") 1455d22c8396SJason M. Bills { 1456d22c8396SJason M. Bills command = "xyz.openbmc_project.State.Chassis.Transition.PowerCycle"; 1457d22c8396SJason M. Bills hostCommand = false; 1458cc340dd9SEd Tanous } 1459bfd5b826SLakshminarayana R. Kammath else if (resetType == "Nmi") 1460bfd5b826SLakshminarayana R. Kammath { 1461bfd5b826SLakshminarayana R. Kammath doNMI(asyncResp); 1462bfd5b826SLakshminarayana R. Kammath return; 1463bfd5b826SLakshminarayana R. Kammath } 1464cc340dd9SEd Tanous else 1465cc340dd9SEd Tanous { 1466f12894f8SJason M. Bills messages::actionParameterUnknown(res, "Reset", resetType); 1467cc340dd9SEd Tanous return; 1468cc340dd9SEd Tanous } 1469cc340dd9SEd Tanous 1470d22c8396SJason M. Bills if (hostCommand) 1471d22c8396SJason M. Bills { 1472cc340dd9SEd Tanous crow::connections::systemBus->async_method_call( 1473d22c8396SJason M. Bills [asyncResp, resetType](const boost::system::error_code ec) { 1474cc340dd9SEd Tanous if (ec) 1475cc340dd9SEd Tanous { 1476cc340dd9SEd Tanous BMCWEB_LOG_ERROR << "D-Bus responses error: " << ec; 1477d22c8396SJason M. Bills if (ec.value() == boost::asio::error::invalid_argument) 1478d22c8396SJason M. Bills { 1479d22c8396SJason M. Bills messages::actionParameterNotSupported( 1480d22c8396SJason M. Bills asyncResp->res, resetType, "Reset"); 1481d22c8396SJason M. Bills } 1482d22c8396SJason M. Bills else 1483d22c8396SJason M. Bills { 1484f12894f8SJason M. Bills messages::internalError(asyncResp->res); 1485d22c8396SJason M. Bills } 1486cc340dd9SEd Tanous return; 1487cc340dd9SEd Tanous } 1488f12894f8SJason M. Bills messages::success(asyncResp->res); 1489cc340dd9SEd Tanous }, 1490cc340dd9SEd Tanous "xyz.openbmc_project.State.Host", 1491cc340dd9SEd Tanous "/xyz/openbmc_project/state/host0", 1492cc340dd9SEd Tanous "org.freedesktop.DBus.Properties", "Set", 14939712f8acSEd Tanous "xyz.openbmc_project.State.Host", "RequestedHostTransition", 1494abf2add6SEd Tanous std::variant<std::string>{command}); 1495cc340dd9SEd Tanous } 1496d22c8396SJason M. Bills else 1497d22c8396SJason M. Bills { 1498d22c8396SJason M. Bills crow::connections::systemBus->async_method_call( 1499d22c8396SJason M. Bills [asyncResp, resetType](const boost::system::error_code ec) { 1500d22c8396SJason M. Bills if (ec) 1501d22c8396SJason M. Bills { 1502d22c8396SJason M. Bills BMCWEB_LOG_ERROR << "D-Bus responses error: " << ec; 1503d22c8396SJason M. Bills if (ec.value() == boost::asio::error::invalid_argument) 1504d22c8396SJason M. Bills { 1505d22c8396SJason M. Bills messages::actionParameterNotSupported( 1506d22c8396SJason M. Bills asyncResp->res, resetType, "Reset"); 1507d22c8396SJason M. Bills } 1508d22c8396SJason M. Bills else 1509d22c8396SJason M. Bills { 1510d22c8396SJason M. Bills messages::internalError(asyncResp->res); 1511d22c8396SJason M. Bills } 1512d22c8396SJason M. Bills return; 1513d22c8396SJason M. Bills } 1514d22c8396SJason M. Bills messages::success(asyncResp->res); 1515d22c8396SJason M. Bills }, 1516d22c8396SJason M. Bills "xyz.openbmc_project.State.Chassis", 1517d22c8396SJason M. Bills "/xyz/openbmc_project/state/chassis0", 1518d22c8396SJason M. Bills "org.freedesktop.DBus.Properties", "Set", 1519d22c8396SJason M. Bills "xyz.openbmc_project.State.Chassis", "RequestedPowerTransition", 1520d22c8396SJason M. Bills std::variant<std::string>{command}); 1521d22c8396SJason M. Bills } 1522d22c8396SJason M. Bills } 1523bfd5b826SLakshminarayana R. Kammath /** 1524bfd5b826SLakshminarayana R. Kammath * Function transceives data with dbus directly. 1525bfd5b826SLakshminarayana R. Kammath */ 1526bfd5b826SLakshminarayana R. Kammath void doNMI(const std::shared_ptr<AsyncResp> &asyncResp) 1527bfd5b826SLakshminarayana R. Kammath { 1528bfd5b826SLakshminarayana R. Kammath constexpr char const *serviceName = 1529bfd5b826SLakshminarayana R. Kammath "xyz.openbmc_project.Control.Host.NMI"; 1530bfd5b826SLakshminarayana R. Kammath constexpr char const *objectPath = 1531bfd5b826SLakshminarayana R. Kammath "/xyz/openbmc_project/control/host0/nmi"; 1532bfd5b826SLakshminarayana R. Kammath constexpr char const *interfaceName = 1533bfd5b826SLakshminarayana R. Kammath "xyz.openbmc_project.Control.Host.NMI"; 1534bfd5b826SLakshminarayana R. Kammath constexpr char const *method = "NMI"; 1535bfd5b826SLakshminarayana R. Kammath 1536bfd5b826SLakshminarayana R. Kammath crow::connections::systemBus->async_method_call( 1537bfd5b826SLakshminarayana R. Kammath [asyncResp](const boost::system::error_code ec) { 1538bfd5b826SLakshminarayana R. Kammath if (ec) 1539bfd5b826SLakshminarayana R. Kammath { 1540bfd5b826SLakshminarayana R. Kammath BMCWEB_LOG_ERROR << " Bad D-Bus request error: " << ec; 1541bfd5b826SLakshminarayana R. Kammath messages::internalError(asyncResp->res); 1542bfd5b826SLakshminarayana R. Kammath return; 1543bfd5b826SLakshminarayana R. Kammath } 1544bfd5b826SLakshminarayana R. Kammath messages::success(asyncResp->res); 1545bfd5b826SLakshminarayana R. Kammath }, 1546bfd5b826SLakshminarayana R. Kammath serviceName, objectPath, interfaceName, method); 1547bfd5b826SLakshminarayana R. Kammath } 1548cc340dd9SEd Tanous }; 1549cc340dd9SEd Tanous 1550cc340dd9SEd Tanous /** 15516617338dSEd Tanous * Systems derived class for delivering Computer Systems Schema. 1552c5b2abe0SLewanczyk, Dawid */ 15531abe55efSEd Tanous class Systems : public Node 15541abe55efSEd Tanous { 1555c5b2abe0SLewanczyk, Dawid public: 1556c5b2abe0SLewanczyk, Dawid /* 1557c5b2abe0SLewanczyk, Dawid * Default Constructor 1558c5b2abe0SLewanczyk, Dawid */ 1559029573d4SEd Tanous Systems(CrowApp &app) : Node(app, "/redfish/v1/Systems/system/") 15601abe55efSEd Tanous { 1561c5b2abe0SLewanczyk, Dawid entityPrivileges = { 1562c5b2abe0SLewanczyk, Dawid {boost::beast::http::verb::get, {{"Login"}}}, 1563c5b2abe0SLewanczyk, Dawid {boost::beast::http::verb::head, {{"Login"}}}, 1564c5b2abe0SLewanczyk, Dawid {boost::beast::http::verb::patch, {{"ConfigureComponents"}}}, 1565c5b2abe0SLewanczyk, Dawid {boost::beast::http::verb::put, {{"ConfigureComponents"}}}, 1566c5b2abe0SLewanczyk, Dawid {boost::beast::http::verb::delete_, {{"ConfigureComponents"}}}, 1567c5b2abe0SLewanczyk, Dawid {boost::beast::http::verb::post, {{"ConfigureComponents"}}}}; 1568c5b2abe0SLewanczyk, Dawid } 1569c5b2abe0SLewanczyk, Dawid 1570c5b2abe0SLewanczyk, Dawid private: 1571c5b2abe0SLewanczyk, Dawid /** 1572c5b2abe0SLewanczyk, Dawid * Functions triggers appropriate requests on DBus 1573c5b2abe0SLewanczyk, Dawid */ 157455c7b7a2SEd Tanous void doGet(crow::Response &res, const crow::Request &req, 15751abe55efSEd Tanous const std::vector<std::string> ¶ms) override 15761abe55efSEd Tanous { 1577491d8ee7SSantosh Puranik res.jsonValue["@odata.type"] = "#ComputerSystem.v1_6_0.ComputerSystem"; 15780f74e643SEd Tanous res.jsonValue["@odata.context"] = 15790f74e643SEd Tanous "/redfish/v1/$metadata#ComputerSystem.ComputerSystem"; 1580029573d4SEd Tanous res.jsonValue["Name"] = "Computer System"; 1581029573d4SEd Tanous res.jsonValue["Id"] = "system"; 15820f74e643SEd Tanous res.jsonValue["SystemType"] = "Physical"; 15830f74e643SEd Tanous res.jsonValue["Description"] = "Computer System"; 15840f74e643SEd Tanous res.jsonValue["ProcessorSummary"]["Count"] = 0; 15850f74e643SEd Tanous res.jsonValue["ProcessorSummary"]["Status"]["State"] = "Disabled"; 15860f74e643SEd Tanous res.jsonValue["MemorySummary"]["TotalSystemMemoryGiB"] = int(0); 15870f74e643SEd Tanous res.jsonValue["MemorySummary"]["Status"]["State"] = "Disabled"; 1588029573d4SEd Tanous res.jsonValue["@odata.id"] = "/redfish/v1/Systems/system"; 158904a258f4SEd Tanous 1590443c2934SRapkiewicz, Pawel res.jsonValue["Processors"] = { 1591029573d4SEd Tanous {"@odata.id", "/redfish/v1/Systems/system/Processors"}}; 1592443c2934SRapkiewicz, Pawel res.jsonValue["Memory"] = { 1593029573d4SEd Tanous {"@odata.id", "/redfish/v1/Systems/system/Memory"}}; 1594a25aeccfSNikhil Potade res.jsonValue["Storage"] = { 1595a25aeccfSNikhil Potade {"@odata.id", "/redfish/v1/Systems/system/Storage"}}; 1596029573d4SEd Tanous 1597cc340dd9SEd Tanous // TODO Need to support ForceRestart. 1598cc340dd9SEd Tanous res.jsonValue["Actions"]["#ComputerSystem.Reset"] = { 1599cc340dd9SEd Tanous {"target", 1600029573d4SEd Tanous "/redfish/v1/Systems/system/Actions/ComputerSystem.Reset"}, 1601cc340dd9SEd Tanous {"ResetType@Redfish.AllowableValues", 1602d22c8396SJason M. Bills {"On", "ForceOff", "ForceOn", "ForceRestart", "GracefulRestart", 1603bfd5b826SLakshminarayana R. Kammath "GracefulShutdown", "PowerCycle", "Nmi"}}}; 1604c5b2abe0SLewanczyk, Dawid 1605c4bf6374SJason M. Bills res.jsonValue["LogServices"] = { 1606029573d4SEd Tanous {"@odata.id", "/redfish/v1/Systems/system/LogServices"}}; 1607c4bf6374SJason M. Bills 1608c5d03ff4SJennifer Lee res.jsonValue["Links"]["ManagedBy"] = { 1609c5d03ff4SJennifer Lee {{"@odata.id", "/redfish/v1/Managers/bmc"}}}; 1610c5d03ff4SJennifer Lee 1611c5d03ff4SJennifer Lee res.jsonValue["Status"] = { 1612c5d03ff4SJennifer Lee {"Health", "OK"}, 1613c5d03ff4SJennifer Lee {"State", "Enabled"}, 1614c5d03ff4SJennifer Lee }; 1615a0803efaSEd Tanous auto asyncResp = std::make_shared<AsyncResp>(res); 1616c5b2abe0SLewanczyk, Dawid 1617b49ac873SJames Feist constexpr const std::array<const char *, 2> inventoryForSystems = { 1618b49ac873SJames Feist "xyz.openbmc_project.Inventory.Item.Dimm", 1619b49ac873SJames Feist "xyz.openbmc_project.Inventory.Item.Cpu"}; 1620b49ac873SJames Feist 1621b49ac873SJames Feist auto health = std::make_shared<HealthPopulate>(asyncResp); 1622b49ac873SJames Feist crow::connections::systemBus->async_method_call( 1623b49ac873SJames Feist [health](const boost::system::error_code ec, 1624b49ac873SJames Feist std::vector<std::string> &resp) { 1625b49ac873SJames Feist if (ec) 1626b49ac873SJames Feist { 1627b49ac873SJames Feist // no inventory 1628b49ac873SJames Feist return; 1629b49ac873SJames Feist } 1630b49ac873SJames Feist 1631b49ac873SJames Feist health->inventory = std::move(resp); 1632b49ac873SJames Feist }, 1633b49ac873SJames Feist "xyz.openbmc_project.ObjectMapper", 1634b49ac873SJames Feist "/xyz/openbmc_project/object_mapper", 1635b49ac873SJames Feist "xyz.openbmc_project.ObjectMapper", "GetSubTreePaths", "/", 1636b49ac873SJames Feist int32_t(0), inventoryForSystems); 1637b49ac873SJames Feist 1638b49ac873SJames Feist health->populate(); 1639b49ac873SJames Feist 1640c5d03ff4SJennifer Lee getMainChassisId(asyncResp, [](const std::string &chassisId, 1641c5d03ff4SJennifer Lee std::shared_ptr<AsyncResp> aRsp) { 1642c5d03ff4SJennifer Lee aRsp->res.jsonValue["Links"]["Chassis"] = { 1643c5d03ff4SJennifer Lee {{"@odata.id", "/redfish/v1/Chassis/" + chassisId}}}; 1644c5d03ff4SJennifer Lee }); 16456c34de48SEd Tanous getLedGroupIdentify( 1646a0803efaSEd Tanous asyncResp, 1647c5d03ff4SJennifer Lee [](const bool &asserted, const std::shared_ptr<AsyncResp> aRsp) { 16481abe55efSEd Tanous if (asserted) 16491abe55efSEd Tanous { 1650c5b2abe0SLewanczyk, Dawid // If led group is asserted, then another call is needed to 1651c5b2abe0SLewanczyk, Dawid // get led status 16526c34de48SEd Tanous getLedIdentify( 1653c5d03ff4SJennifer Lee aRsp, [](const std::string &ledStatus, 1654c5d03ff4SJennifer Lee const std::shared_ptr<AsyncResp> aRsp) { 16551abe55efSEd Tanous if (!ledStatus.empty()) 16561abe55efSEd Tanous { 1657c5d03ff4SJennifer Lee aRsp->res.jsonValue["IndicatorLED"] = ledStatus; 1658c5b2abe0SLewanczyk, Dawid } 1659c5b2abe0SLewanczyk, Dawid }); 16601abe55efSEd Tanous } 16611abe55efSEd Tanous else 16621abe55efSEd Tanous { 1663c5d03ff4SJennifer Lee aRsp->res.jsonValue["IndicatorLED"] = "Off"; 1664c5b2abe0SLewanczyk, Dawid } 1665c5b2abe0SLewanczyk, Dawid }); 16665bc2dc8eSJames Feist getComputerSystem(asyncResp, health); 16676c34de48SEd Tanous getHostState(asyncResp); 1668491d8ee7SSantosh Puranik getBootProperties(asyncResp); 1669f5c9f8bdSJason M. Bills getPCIeDeviceList(asyncResp); 167051709ffdSYong Li getHostWatchdogTimer(asyncResp); 1671c5b2abe0SLewanczyk, Dawid } 1672c5b2abe0SLewanczyk, Dawid 167355c7b7a2SEd Tanous void doPatch(crow::Response &res, const crow::Request &req, 16741abe55efSEd Tanous const std::vector<std::string> ¶ms) override 16751abe55efSEd Tanous { 1676cde19e5fSSantosh Puranik std::optional<std::string> indicatorLed; 1677491d8ee7SSantosh Puranik std::optional<nlohmann::json> bootProps; 1678*c45f0082SYong Li std::optional<nlohmann::json> wdtTimerProps; 167941352c24SSantosh Puranik auto asyncResp = std::make_shared<AsyncResp>(res); 168041352c24SSantosh Puranik 1681944ffaf9SJohnathan Mantey if (!json_util::readJson(req, res, "IndicatorLED", indicatorLed, "Boot", 1682*c45f0082SYong Li bootProps, "WatchdogTimer", wdtTimerProps)) 16836617338dSEd Tanous { 16846617338dSEd Tanous return; 16856617338dSEd Tanous } 1686491d8ee7SSantosh Puranik 1687944ffaf9SJohnathan Mantey res.result(boost::beast::http::status::no_content); 1688*c45f0082SYong Li 1689*c45f0082SYong Li if (wdtTimerProps) 1690*c45f0082SYong Li { 1691*c45f0082SYong Li std::optional<bool> wdtEnable; 1692*c45f0082SYong Li std::optional<std::string> wdtTimeOutAction; 1693*c45f0082SYong Li 1694*c45f0082SYong Li if (!json_util::readJson(*wdtTimerProps, asyncResp->res, 1695*c45f0082SYong Li "FunctionEnabled", wdtEnable, 1696*c45f0082SYong Li "TimeoutAction", wdtTimeOutAction)) 1697*c45f0082SYong Li { 1698*c45f0082SYong Li return; 1699*c45f0082SYong Li } 1700*c45f0082SYong Li setWDTProperties(asyncResp, std::move(wdtEnable), 1701*c45f0082SYong Li std::move(wdtTimeOutAction)); 1702*c45f0082SYong Li } 1703*c45f0082SYong Li 1704491d8ee7SSantosh Puranik if (bootProps) 1705491d8ee7SSantosh Puranik { 1706491d8ee7SSantosh Puranik std::optional<std::string> bootSource; 1707491d8ee7SSantosh Puranik std::optional<std::string> bootEnable; 1708491d8ee7SSantosh Puranik 1709491d8ee7SSantosh Puranik if (!json_util::readJson(*bootProps, asyncResp->res, 1710491d8ee7SSantosh Puranik "BootSourceOverrideTarget", bootSource, 1711491d8ee7SSantosh Puranik "BootSourceOverrideEnabled", bootEnable)) 1712491d8ee7SSantosh Puranik { 1713491d8ee7SSantosh Puranik return; 1714491d8ee7SSantosh Puranik } 1715491d8ee7SSantosh Puranik setBootProperties(asyncResp, std::move(bootSource), 1716491d8ee7SSantosh Puranik std::move(bootEnable)); 1717491d8ee7SSantosh Puranik } 1718265c1602SJohnathan Mantey 17199712f8acSEd Tanous if (indicatorLed) 17206617338dSEd Tanous { 17219712f8acSEd Tanous std::string dbusLedState; 1722d573bb2aSJennifer Lee if (*indicatorLed == "Lit") 17239712f8acSEd Tanous { 1724d573bb2aSJennifer Lee dbusLedState = "xyz.openbmc_project.Led.Physical.Action.On"; 17256617338dSEd Tanous } 17265c6221acSGunnar Mills else if (*indicatorLed == "Blinking") 17276617338dSEd Tanous { 17285c6221acSGunnar Mills dbusLedState = "xyz.openbmc_project.Led.Physical.Action.Blink"; 17296617338dSEd Tanous } 17309712f8acSEd Tanous else if (*indicatorLed == "Off") 17316617338dSEd Tanous { 17329712f8acSEd Tanous dbusLedState = "xyz.openbmc_project.Led.Physical.Action.Off"; 17336617338dSEd Tanous } 17346617338dSEd Tanous else 17356617338dSEd Tanous { 1736a08b46ccSJason M. Bills messages::propertyValueNotInList(res, *indicatorLed, 1737a08b46ccSJason M. Bills "IndicatorLED"); 17386617338dSEd Tanous return; 17396617338dSEd Tanous } 17406617338dSEd Tanous 1741c5b2abe0SLewanczyk, Dawid // Update led group 174255c7b7a2SEd Tanous BMCWEB_LOG_DEBUG << "Update led group."; 174355c7b7a2SEd Tanous crow::connections::systemBus->async_method_call( 1744cde19e5fSSantosh Puranik [asyncResp](const boost::system::error_code ec) { 17451abe55efSEd Tanous if (ec) 17461abe55efSEd Tanous { 174755c7b7a2SEd Tanous BMCWEB_LOG_DEBUG << "DBUS response error " << ec; 1748f12894f8SJason M. Bills messages::internalError(asyncResp->res); 1749c5b2abe0SLewanczyk, Dawid return; 1750c5b2abe0SLewanczyk, Dawid } 175155c7b7a2SEd Tanous BMCWEB_LOG_DEBUG << "Led group update done."; 1752c5b2abe0SLewanczyk, Dawid }, 1753c5b2abe0SLewanczyk, Dawid "xyz.openbmc_project.LED.GroupManager", 1754c5b2abe0SLewanczyk, Dawid "/xyz/openbmc_project/led/groups/enclosure_identify", 1755c5b2abe0SLewanczyk, Dawid "org.freedesktop.DBus.Properties", "Set", 1756c5b2abe0SLewanczyk, Dawid "xyz.openbmc_project.Led.Group", "Asserted", 1757abf2add6SEd Tanous std::variant<bool>( 1758265c1602SJohnathan Mantey (dbusLedState != 1759265c1602SJohnathan Mantey "xyz.openbmc_project.Led.Physical.Action.Off"))); 1760265c1602SJohnathan Mantey 1761c5b2abe0SLewanczyk, Dawid // Update identify led status 176255c7b7a2SEd Tanous BMCWEB_LOG_DEBUG << "Update led SoftwareInventoryCollection."; 176355c7b7a2SEd Tanous crow::connections::systemBus->async_method_call( 1764265c1602SJohnathan Mantey [asyncResp](const boost::system::error_code ec) { 17651abe55efSEd Tanous if (ec) 17661abe55efSEd Tanous { 176755c7b7a2SEd Tanous BMCWEB_LOG_DEBUG << "DBUS response error " << ec; 1768f12894f8SJason M. Bills messages::internalError(asyncResp->res); 1769c5b2abe0SLewanczyk, Dawid return; 1770c5b2abe0SLewanczyk, Dawid } 177155c7b7a2SEd Tanous BMCWEB_LOG_DEBUG << "Led state update done."; 1772c5b2abe0SLewanczyk, Dawid }, 1773c5b2abe0SLewanczyk, Dawid "xyz.openbmc_project.LED.Controller.identify", 1774c5b2abe0SLewanczyk, Dawid "/xyz/openbmc_project/led/physical/identify", 1775c5b2abe0SLewanczyk, Dawid "org.freedesktop.DBus.Properties", "Set", 1776c5b2abe0SLewanczyk, Dawid "xyz.openbmc_project.Led.Physical", "State", 1777abf2add6SEd Tanous std::variant<std::string>(dbusLedState)); 17786617338dSEd Tanous } 1779c5b2abe0SLewanczyk, Dawid } 1780c5b2abe0SLewanczyk, Dawid }; 1781c5b2abe0SLewanczyk, Dawid } // namespace redfish 1782