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 181e1e598dSJonathan Doman #include "dbus_singleton.hpp" 19b49ac873SJames Feist #include "health.hpp" 201c8fba97SJames Feist #include "led.hpp" 21f5c9f8bdSJason M. Bills #include "pcie.hpp" 22f4c99e70SEd Tanous #include "query.hpp" 23c5d03ff4SJennifer Lee #include "redfish_util.hpp" 242b82937eSEd Tanous #include "utils/time_utils.hpp" 25c5d03ff4SJennifer Lee 267e860f15SJohn Edward Broadbent #include <app.hpp> 279712f8acSEd Tanous #include <boost/container/flat_map.hpp> 28168e20c1SEd Tanous #include <dbus_utility.hpp> 29ed398213SEd Tanous #include <registries/privilege_registry.hpp> 301e1e598dSJonathan Doman #include <sdbusplus/asio/property.hpp> 31bc1d29deSKrzysztof Grobelny #include <sdbusplus/unpack_properties.hpp> 32bc1d29deSKrzysztof Grobelny #include <utils/dbus_utils.hpp> 33c5b2abe0SLewanczyk, Dawid #include <utils/json_utils.hpp> 34eee0013eSWilly Tu #include <utils/sw_utils.hpp> 351214b7e7SGunnar Mills 36abf2add6SEd Tanous #include <variant> 37c5b2abe0SLewanczyk, Dawid 381abe55efSEd Tanous namespace redfish 391abe55efSEd Tanous { 40c5b2abe0SLewanczyk, Dawid 419d3ae10eSAlpana Kumari /** 429d3ae10eSAlpana Kumari * @brief Updates the Functional State of DIMMs 439d3ae10eSAlpana Kumari * 449d3ae10eSAlpana Kumari * @param[in] aResp Shared pointer for completing asynchronous calls 459d3ae10eSAlpana Kumari * @param[in] dimmState Dimm's Functional state, true/false 469d3ae10eSAlpana Kumari * 479d3ae10eSAlpana Kumari * @return None. 489d3ae10eSAlpana Kumari */ 498d1b46d7Szhanghch05 inline void 508d1b46d7Szhanghch05 updateDimmProperties(const std::shared_ptr<bmcweb::AsyncResp>& aResp, 511e1e598dSJonathan Doman bool isDimmFunctional) 529d3ae10eSAlpana Kumari { 531e1e598dSJonathan Doman BMCWEB_LOG_DEBUG << "Dimm Functional: " << isDimmFunctional; 549d3ae10eSAlpana Kumari 559d3ae10eSAlpana Kumari // Set it as Enabled if at least one DIMM is functional 569d3ae10eSAlpana Kumari // Update STATE only if previous State was DISABLED and current Dimm is 579d3ae10eSAlpana Kumari // ENABLED. 5802cad96eSEd Tanous const nlohmann::json& prevMemSummary = 599d3ae10eSAlpana Kumari aResp->res.jsonValue["MemorySummary"]["Status"]["State"]; 609d3ae10eSAlpana Kumari if (prevMemSummary == "Disabled") 619d3ae10eSAlpana Kumari { 62e05aec50SEd Tanous if (isDimmFunctional) 639d3ae10eSAlpana Kumari { 649d3ae10eSAlpana Kumari aResp->res.jsonValue["MemorySummary"]["Status"]["State"] = 659d3ae10eSAlpana Kumari "Enabled"; 669d3ae10eSAlpana Kumari } 679d3ae10eSAlpana Kumari } 689d3ae10eSAlpana Kumari } 699d3ae10eSAlpana Kumari 7057e8c9beSAlpana Kumari /* 7157e8c9beSAlpana Kumari * @brief Update "ProcessorSummary" "Count" based on Cpu PresenceState 7257e8c9beSAlpana Kumari * 7357e8c9beSAlpana Kumari * @param[in] aResp Shared pointer for completing asynchronous calls 7457e8c9beSAlpana Kumari * @param[in] cpuPresenceState CPU present or not 7557e8c9beSAlpana Kumari * 7657e8c9beSAlpana Kumari * @return None. 7757e8c9beSAlpana Kumari */ 781e1e598dSJonathan Doman inline void 791e1e598dSJonathan Doman modifyCpuPresenceState(const std::shared_ptr<bmcweb::AsyncResp>& aResp, 801e1e598dSJonathan Doman bool isCpuPresent) 8157e8c9beSAlpana Kumari { 821e1e598dSJonathan Doman BMCWEB_LOG_DEBUG << "Cpu Present: " << isCpuPresent; 8357e8c9beSAlpana Kumari 8455f79e6fSEd Tanous if (isCpuPresent) 8557e8c9beSAlpana Kumari { 86b4b9595aSJames Feist nlohmann::json& procCount = 87b4b9595aSJames Feist aResp->res.jsonValue["ProcessorSummary"]["Count"]; 8855f79e6fSEd Tanous auto* procCountPtr = 89b4b9595aSJames Feist procCount.get_ptr<nlohmann::json::number_integer_t*>(); 90b4b9595aSJames Feist if (procCountPtr != nullptr) 91b4b9595aSJames Feist { 92b4b9595aSJames Feist // shouldn't be possible to be nullptr 93b4b9595aSJames Feist *procCountPtr += 1; 9457e8c9beSAlpana Kumari } 95b4b9595aSJames Feist } 9657e8c9beSAlpana Kumari } 9757e8c9beSAlpana Kumari 9857e8c9beSAlpana Kumari /* 9957e8c9beSAlpana Kumari * @brief Update "ProcessorSummary" "Status" "State" based on 10057e8c9beSAlpana Kumari * CPU Functional State 10157e8c9beSAlpana Kumari * 10257e8c9beSAlpana Kumari * @param[in] aResp Shared pointer for completing asynchronous calls 10357e8c9beSAlpana Kumari * @param[in] cpuFunctionalState is CPU functional true/false 10457e8c9beSAlpana Kumari * 10557e8c9beSAlpana Kumari * @return None. 10657e8c9beSAlpana Kumari */ 1071e1e598dSJonathan Doman inline void 1081e1e598dSJonathan Doman modifyCpuFunctionalState(const std::shared_ptr<bmcweb::AsyncResp>& aResp, 1091e1e598dSJonathan Doman bool isCpuFunctional) 11057e8c9beSAlpana Kumari { 1111e1e598dSJonathan Doman BMCWEB_LOG_DEBUG << "Cpu Functional: " << isCpuFunctional; 11257e8c9beSAlpana Kumari 11302cad96eSEd Tanous const nlohmann::json& prevProcState = 11457e8c9beSAlpana Kumari aResp->res.jsonValue["ProcessorSummary"]["Status"]["State"]; 11557e8c9beSAlpana Kumari 11657e8c9beSAlpana Kumari // Set it as Enabled if at least one CPU is functional 11757e8c9beSAlpana Kumari // Update STATE only if previous State was Non_Functional and current CPU is 11857e8c9beSAlpana Kumari // Functional. 11957e8c9beSAlpana Kumari if (prevProcState == "Disabled") 12057e8c9beSAlpana Kumari { 121e05aec50SEd Tanous if (isCpuFunctional) 12257e8c9beSAlpana Kumari { 12357e8c9beSAlpana Kumari aResp->res.jsonValue["ProcessorSummary"]["Status"]["State"] = 12457e8c9beSAlpana Kumari "Enabled"; 12557e8c9beSAlpana Kumari } 12657e8c9beSAlpana Kumari } 12757e8c9beSAlpana Kumari } 12857e8c9beSAlpana Kumari 129382d6475SAli Ahmed inline void getProcessorProperties( 130382d6475SAli Ahmed const std::shared_ptr<bmcweb::AsyncResp>& aResp, 131382d6475SAli Ahmed const std::vector<std::pair<std::string, dbus::utility::DbusVariantType>>& 132382d6475SAli Ahmed properties) 13303fbed92SAli Ahmed { 13403fbed92SAli Ahmed 13503fbed92SAli Ahmed BMCWEB_LOG_DEBUG << "Got " << properties.size() << " Cpu properties."; 13603fbed92SAli Ahmed 13703fbed92SAli Ahmed // TODO: Get Model 13803fbed92SAli Ahmed 139bc1d29deSKrzysztof Grobelny const uint16_t* coreCount = nullptr; 14003fbed92SAli Ahmed 141bc1d29deSKrzysztof Grobelny const bool success = sdbusplus::unpackPropertiesNoThrow( 142bc1d29deSKrzysztof Grobelny dbus_utils::UnpackErrorPrinter(), properties, "CoreCount", coreCount); 14303fbed92SAli Ahmed 144bc1d29deSKrzysztof Grobelny if (!success) 14503fbed92SAli Ahmed { 14603fbed92SAli Ahmed messages::internalError(aResp->res); 14703fbed92SAli Ahmed return; 14803fbed92SAli Ahmed } 14903fbed92SAli Ahmed 150bc1d29deSKrzysztof Grobelny if (coreCount != nullptr) 15103fbed92SAli Ahmed { 152bc1d29deSKrzysztof Grobelny nlohmann::json& coreCountJson = 153bc1d29deSKrzysztof Grobelny aResp->res.jsonValue["ProcessorSummary"]["CoreCount"]; 154bc1d29deSKrzysztof Grobelny uint64_t* coreCountJsonPtr = coreCountJson.get_ptr<uint64_t*>(); 155bc1d29deSKrzysztof Grobelny 156bc1d29deSKrzysztof Grobelny if (coreCountJsonPtr == nullptr) 157bc1d29deSKrzysztof Grobelny { 158bc1d29deSKrzysztof Grobelny coreCountJson = *coreCount; 15903fbed92SAli Ahmed } 16003fbed92SAli Ahmed else 16103fbed92SAli Ahmed { 162bc1d29deSKrzysztof Grobelny *coreCountJsonPtr += *coreCount; 16303fbed92SAli Ahmed } 16403fbed92SAli Ahmed } 16503fbed92SAli Ahmed } 16603fbed92SAli Ahmed 16703fbed92SAli Ahmed /* 16803fbed92SAli Ahmed * @brief Get ProcessorSummary fields 16903fbed92SAli Ahmed * 17003fbed92SAli Ahmed * @param[in] aResp Shared pointer for completing asynchronous calls 17103fbed92SAli Ahmed * @param[in] service dbus service for Cpu Information 17203fbed92SAli Ahmed * @param[in] path dbus path for Cpu 17303fbed92SAli Ahmed * 17403fbed92SAli Ahmed * @return None. 17503fbed92SAli Ahmed */ 17603fbed92SAli Ahmed inline void getProcessorSummary(const std::shared_ptr<bmcweb::AsyncResp>& aResp, 17703fbed92SAli Ahmed const std::string& service, 17803fbed92SAli Ahmed const std::string& path) 17903fbed92SAli Ahmed { 18003fbed92SAli Ahmed 181382d6475SAli Ahmed auto getCpuPresenceState = [aResp](const boost::system::error_code ec3, 182382d6475SAli Ahmed const bool cpuPresenceCheck) { 183382d6475SAli Ahmed if (ec3) 184382d6475SAli Ahmed { 185382d6475SAli Ahmed BMCWEB_LOG_ERROR << "DBUS response error " << ec3; 186382d6475SAli Ahmed return; 187382d6475SAli Ahmed } 188382d6475SAli Ahmed modifyCpuPresenceState(aResp, cpuPresenceCheck); 189382d6475SAli Ahmed }; 190382d6475SAli Ahmed 191382d6475SAli Ahmed auto getCpuFunctionalState = [aResp](const boost::system::error_code ec3, 192382d6475SAli Ahmed const bool cpuFunctionalCheck) { 193382d6475SAli Ahmed if (ec3) 194382d6475SAli Ahmed { 195382d6475SAli Ahmed BMCWEB_LOG_ERROR << "DBUS response error " << ec3; 196382d6475SAli Ahmed return; 197382d6475SAli Ahmed } 198382d6475SAli Ahmed modifyCpuFunctionalState(aResp, cpuFunctionalCheck); 199382d6475SAli Ahmed }; 200382d6475SAli Ahmed 201382d6475SAli Ahmed // Get the Presence of CPU 202382d6475SAli Ahmed sdbusplus::asio::getProperty<bool>( 203382d6475SAli Ahmed *crow::connections::systemBus, service, path, 204382d6475SAli Ahmed "xyz.openbmc_project.Inventory.Item", "Present", 205382d6475SAli Ahmed std::move(getCpuPresenceState)); 206382d6475SAli Ahmed 207382d6475SAli Ahmed // Get the Functional State 208382d6475SAli Ahmed sdbusplus::asio::getProperty<bool>( 209382d6475SAli Ahmed *crow::connections::systemBus, service, path, 210382d6475SAli Ahmed "xyz.openbmc_project.State.Decorator.OperationalStatus", "Functional", 211382d6475SAli Ahmed std::move(getCpuFunctionalState)); 212382d6475SAli Ahmed 213bc1d29deSKrzysztof Grobelny sdbusplus::asio::getAllProperties( 214bc1d29deSKrzysztof Grobelny *crow::connections::systemBus, service, path, 215bc1d29deSKrzysztof Grobelny "xyz.openbmc_project.Inventory.Item.Cpu", 21603fbed92SAli Ahmed [aResp, service, 21703fbed92SAli Ahmed path](const boost::system::error_code ec2, 218b9d36b47SEd Tanous const dbus::utility::DBusPropertiesMap& properties) { 21903fbed92SAli Ahmed if (ec2) 22003fbed92SAli Ahmed { 22103fbed92SAli Ahmed BMCWEB_LOG_ERROR << "DBUS response error " << ec2; 22203fbed92SAli Ahmed messages::internalError(aResp->res); 22303fbed92SAli Ahmed return; 22403fbed92SAli Ahmed } 225382d6475SAli Ahmed getProcessorProperties(aResp, properties); 226bc1d29deSKrzysztof Grobelny }); 22703fbed92SAli Ahmed } 22803fbed92SAli Ahmed 22957e8c9beSAlpana Kumari /* 230c5b2abe0SLewanczyk, Dawid * @brief Retrieves computer system properties over dbus 231c5b2abe0SLewanczyk, Dawid * 232c5b2abe0SLewanczyk, Dawid * @param[in] aResp Shared pointer for completing asynchronous calls 2338f9ee3cdSGunnar Mills * @param[in] systemHealth Shared HealthPopulate pointer 234c5b2abe0SLewanczyk, Dawid * 235c5b2abe0SLewanczyk, Dawid * @return None. 236c5b2abe0SLewanczyk, Dawid */ 237b5a76932SEd Tanous inline void 2388d1b46d7Szhanghch05 getComputerSystem(const std::shared_ptr<bmcweb::AsyncResp>& aResp, 239b5a76932SEd Tanous const std::shared_ptr<HealthPopulate>& systemHealth) 2401abe55efSEd Tanous { 24155c7b7a2SEd Tanous BMCWEB_LOG_DEBUG << "Get available system components."; 2429d3ae10eSAlpana Kumari 24355c7b7a2SEd Tanous crow::connections::systemBus->async_method_call( 244b9d36b47SEd Tanous [aResp, 245b9d36b47SEd Tanous systemHealth](const boost::system::error_code ec, 246b9d36b47SEd Tanous const dbus::utility::MapperGetSubTreeResponse& subtree) { 2471abe55efSEd Tanous if (ec) 2481abe55efSEd Tanous { 24955c7b7a2SEd Tanous BMCWEB_LOG_DEBUG << "DBUS response error"; 250f12894f8SJason M. Bills messages::internalError(aResp->res); 251c5b2abe0SLewanczyk, Dawid return; 252c5b2abe0SLewanczyk, Dawid } 253c5b2abe0SLewanczyk, Dawid // Iterate over all retrieved ObjectPaths. 254002d39b4SEd Tanous for (const std::pair< 255002d39b4SEd Tanous std::string, 256002d39b4SEd Tanous std::vector<std::pair<std::string, std::vector<std::string>>>>& 2571214b7e7SGunnar Mills object : subtree) 2581abe55efSEd Tanous { 259c5b2abe0SLewanczyk, Dawid const std::string& path = object.first; 26055c7b7a2SEd Tanous BMCWEB_LOG_DEBUG << "Got path: " << path; 261002d39b4SEd Tanous const std::vector<std::pair<std::string, std::vector<std::string>>>& 2621214b7e7SGunnar Mills connectionNames = object.second; 26326f6976fSEd Tanous if (connectionNames.empty()) 2641abe55efSEd Tanous { 265c5b2abe0SLewanczyk, Dawid continue; 266c5b2abe0SLewanczyk, Dawid } 267029573d4SEd Tanous 2685bc2dc8eSJames Feist auto memoryHealth = std::make_shared<HealthPopulate>( 269dfababfcSNan Zhou aResp, "/MemorySummary/Status"_json_pointer); 2705bc2dc8eSJames Feist 2715bc2dc8eSJames Feist auto cpuHealth = std::make_shared<HealthPopulate>( 272dfababfcSNan Zhou aResp, "/ProcessorSummary/Status"_json_pointer); 2735bc2dc8eSJames Feist 2745bc2dc8eSJames Feist systemHealth->children.emplace_back(memoryHealth); 2755bc2dc8eSJames Feist systemHealth->children.emplace_back(cpuHealth); 2765bc2dc8eSJames Feist 2776c34de48SEd Tanous // This is not system, so check if it's cpu, dimm, UUID or 2786c34de48SEd Tanous // BiosVer 27904a258f4SEd Tanous for (const auto& connection : connectionNames) 2801abe55efSEd Tanous { 28104a258f4SEd Tanous for (const auto& interfaceName : connection.second) 2821abe55efSEd Tanous { 28304a258f4SEd Tanous if (interfaceName == 28404a258f4SEd Tanous "xyz.openbmc_project.Inventory.Item.Dimm") 2851abe55efSEd Tanous { 2861abe55efSEd Tanous BMCWEB_LOG_DEBUG 28704a258f4SEd Tanous << "Found Dimm, now get its properties."; 2889d3ae10eSAlpana Kumari 289bc1d29deSKrzysztof Grobelny sdbusplus::asio::getAllProperties( 290bc1d29deSKrzysztof Grobelny *crow::connections::systemBus, connection.first, 291bc1d29deSKrzysztof Grobelny path, "xyz.openbmc_project.Inventory.Item.Dimm", 2929d3ae10eSAlpana Kumari [aResp, service{connection.first}, 293f23b7296SEd Tanous path](const boost::system::error_code ec2, 294b9d36b47SEd Tanous const dbus::utility::DBusPropertiesMap& 2951214b7e7SGunnar Mills properties) { 296cb13a392SEd Tanous if (ec2) 2971abe55efSEd Tanous { 298002d39b4SEd Tanous BMCWEB_LOG_ERROR << "DBUS response error " 299002d39b4SEd Tanous << ec2; 300f12894f8SJason M. Bills messages::internalError(aResp->res); 301c5b2abe0SLewanczyk, Dawid return; 302c5b2abe0SLewanczyk, Dawid } 303002d39b4SEd Tanous BMCWEB_LOG_DEBUG << "Got " << properties.size() 304c5b2abe0SLewanczyk, Dawid << " Dimm properties."; 3059d3ae10eSAlpana Kumari 306bc1d29deSKrzysztof Grobelny if (properties.empty()) 3079d3ae10eSAlpana Kumari { 3081e1e598dSJonathan Doman sdbusplus::asio::getProperty<bool>( 309002d39b4SEd Tanous *crow::connections::systemBus, service, 310002d39b4SEd Tanous path, 3111e1e598dSJonathan Doman "xyz.openbmc_project.State." 3121e1e598dSJonathan Doman "Decorator.OperationalStatus", 3131e1e598dSJonathan Doman "Functional", 314002d39b4SEd Tanous [aResp](const boost::system::error_code ec3, 3151e1e598dSJonathan Doman bool dimmState) { 316cb13a392SEd Tanous if (ec3) 3179d3ae10eSAlpana Kumari { 3189d3ae10eSAlpana Kumari BMCWEB_LOG_ERROR 319002d39b4SEd Tanous << "DBUS response error " << ec3; 3209d3ae10eSAlpana Kumari return; 3219d3ae10eSAlpana Kumari } 322002d39b4SEd Tanous updateDimmProperties(aResp, dimmState); 3231e1e598dSJonathan Doman }); 324bc1d29deSKrzysztof Grobelny return; 3259d3ae10eSAlpana Kumari } 326bc1d29deSKrzysztof Grobelny 327bc1d29deSKrzysztof Grobelny const uint32_t* memorySizeInKB = nullptr; 328bc1d29deSKrzysztof Grobelny 329bc1d29deSKrzysztof Grobelny const bool success = 330bc1d29deSKrzysztof Grobelny sdbusplus::unpackPropertiesNoThrow( 331bc1d29deSKrzysztof Grobelny dbus_utils::UnpackErrorPrinter(), 332bc1d29deSKrzysztof Grobelny properties, "MemorySizeInKB", 333bc1d29deSKrzysztof Grobelny memorySizeInKB); 334bc1d29deSKrzysztof Grobelny 335bc1d29deSKrzysztof Grobelny if (!success) 336bc1d29deSKrzysztof Grobelny { 337bc1d29deSKrzysztof Grobelny messages::internalError(aResp->res); 338bc1d29deSKrzysztof Grobelny return; 339bc1d29deSKrzysztof Grobelny } 340bc1d29deSKrzysztof Grobelny 341bc1d29deSKrzysztof Grobelny if (memorySizeInKB != nullptr) 342bc1d29deSKrzysztof Grobelny { 343bc1d29deSKrzysztof Grobelny nlohmann::json& totalMemory = 344bc1d29deSKrzysztof Grobelny aResp->res 345bc1d29deSKrzysztof Grobelny .jsonValue["MemorySummary"] 346bc1d29deSKrzysztof Grobelny ["TotalSystemMemoryGiB"]; 347bc1d29deSKrzysztof Grobelny const uint64_t* preValue = 348bc1d29deSKrzysztof Grobelny totalMemory.get_ptr<const uint64_t*>(); 349bc1d29deSKrzysztof Grobelny if (preValue == nullptr) 350bc1d29deSKrzysztof Grobelny { 351bc1d29deSKrzysztof Grobelny aResp->res 352bc1d29deSKrzysztof Grobelny .jsonValue["MemorySummary"] 353bc1d29deSKrzysztof Grobelny ["TotalSystemMemoryGiB"] = 354bc1d29deSKrzysztof Grobelny *memorySizeInKB / (1024 * 1024); 355bc1d29deSKrzysztof Grobelny } 356bc1d29deSKrzysztof Grobelny else 357bc1d29deSKrzysztof Grobelny { 358bc1d29deSKrzysztof Grobelny aResp->res 359bc1d29deSKrzysztof Grobelny .jsonValue["MemorySummary"] 360bc1d29deSKrzysztof Grobelny ["TotalSystemMemoryGiB"] = 361bc1d29deSKrzysztof Grobelny *memorySizeInKB / (1024 * 1024) + 362bc1d29deSKrzysztof Grobelny *preValue; 363bc1d29deSKrzysztof Grobelny } 364bc1d29deSKrzysztof Grobelny aResp->res.jsonValue["MemorySummary"]["Status"] 365bc1d29deSKrzysztof Grobelny ["State"] = "Enabled"; 366bc1d29deSKrzysztof Grobelny } 367bc1d29deSKrzysztof Grobelny }); 3685bc2dc8eSJames Feist 3695bc2dc8eSJames Feist memoryHealth->inventory.emplace_back(path); 3701abe55efSEd Tanous } 37104a258f4SEd Tanous else if (interfaceName == 37204a258f4SEd Tanous "xyz.openbmc_project.Inventory.Item.Cpu") 3731abe55efSEd Tanous { 3741abe55efSEd Tanous BMCWEB_LOG_DEBUG 37504a258f4SEd Tanous << "Found Cpu, now get its properties."; 37657e8c9beSAlpana Kumari 37703fbed92SAli Ahmed getProcessorSummary(aResp, connection.first, path); 3785bc2dc8eSJames Feist 3795bc2dc8eSJames Feist cpuHealth->inventory.emplace_back(path); 3801abe55efSEd Tanous } 381002d39b4SEd Tanous else if (interfaceName == "xyz.openbmc_project.Common.UUID") 3821abe55efSEd Tanous { 3831abe55efSEd Tanous BMCWEB_LOG_DEBUG 38404a258f4SEd Tanous << "Found UUID, now get its properties."; 385bc1d29deSKrzysztof Grobelny 386bc1d29deSKrzysztof Grobelny sdbusplus::asio::getAllProperties( 387bc1d29deSKrzysztof Grobelny *crow::connections::systemBus, connection.first, 388bc1d29deSKrzysztof Grobelny path, "xyz.openbmc_project.Common.UUID", 389168e20c1SEd Tanous [aResp](const boost::system::error_code ec3, 390b9d36b47SEd Tanous const dbus::utility::DBusPropertiesMap& 3911214b7e7SGunnar Mills properties) { 392cb13a392SEd Tanous if (ec3) 3931abe55efSEd Tanous { 394002d39b4SEd Tanous BMCWEB_LOG_DEBUG << "DBUS response error " 395002d39b4SEd Tanous << ec3; 396f12894f8SJason M. Bills messages::internalError(aResp->res); 397c5b2abe0SLewanczyk, Dawid return; 398c5b2abe0SLewanczyk, Dawid } 399002d39b4SEd Tanous BMCWEB_LOG_DEBUG << "Got " << properties.size() 400c5b2abe0SLewanczyk, Dawid << " UUID properties."; 40104a258f4SEd Tanous 402bc1d29deSKrzysztof Grobelny const std::string* uUID = nullptr; 403bc1d29deSKrzysztof Grobelny 404bc1d29deSKrzysztof Grobelny const bool success = 405bc1d29deSKrzysztof Grobelny sdbusplus::unpackPropertiesNoThrow( 406bc1d29deSKrzysztof Grobelny dbus_utils::UnpackErrorPrinter(), 407bc1d29deSKrzysztof Grobelny properties, "UUID", uUID); 408bc1d29deSKrzysztof Grobelny 409bc1d29deSKrzysztof Grobelny if (!success) 4101abe55efSEd Tanous { 411bc1d29deSKrzysztof Grobelny messages::internalError(aResp->res); 412bc1d29deSKrzysztof Grobelny return; 413bc1d29deSKrzysztof Grobelny } 414bc1d29deSKrzysztof Grobelny 415bc1d29deSKrzysztof Grobelny if (uUID != nullptr) 416bc1d29deSKrzysztof Grobelny { 417bc1d29deSKrzysztof Grobelny std::string valueStr = *uUID; 41804a258f4SEd Tanous if (valueStr.size() == 32) 4191abe55efSEd Tanous { 420029573d4SEd Tanous valueStr.insert(8, 1, '-'); 421029573d4SEd Tanous valueStr.insert(13, 1, '-'); 422029573d4SEd Tanous valueStr.insert(18, 1, '-'); 423029573d4SEd Tanous valueStr.insert(23, 1, '-'); 42404a258f4SEd Tanous } 425bc1d29deSKrzysztof Grobelny BMCWEB_LOG_DEBUG << "UUID = " << valueStr; 426002d39b4SEd Tanous aResp->res.jsonValue["UUID"] = valueStr; 427c5b2abe0SLewanczyk, Dawid } 428bc1d29deSKrzysztof Grobelny }); 429c5b2abe0SLewanczyk, Dawid } 430029573d4SEd Tanous else if (interfaceName == 431029573d4SEd Tanous "xyz.openbmc_project.Inventory.Item.System") 4321abe55efSEd Tanous { 433bc1d29deSKrzysztof Grobelny sdbusplus::asio::getAllProperties( 434bc1d29deSKrzysztof Grobelny *crow::connections::systemBus, connection.first, 435bc1d29deSKrzysztof Grobelny path, 436bc1d29deSKrzysztof Grobelny "xyz.openbmc_project.Inventory.Decorator.Asset", 437168e20c1SEd Tanous [aResp](const boost::system::error_code ec2, 438b9d36b47SEd Tanous const dbus::utility::DBusPropertiesMap& 4391214b7e7SGunnar Mills propertiesList) { 440cb13a392SEd Tanous if (ec2) 441029573d4SEd Tanous { 442e4a4b9a9SJames Feist // doesn't have to include this 443e4a4b9a9SJames Feist // interface 444029573d4SEd Tanous return; 445029573d4SEd Tanous } 446002d39b4SEd Tanous BMCWEB_LOG_DEBUG << "Got " << propertiesList.size() 447029573d4SEd Tanous << " properties for system"; 448bc1d29deSKrzysztof Grobelny 449bc1d29deSKrzysztof Grobelny const std::string* partNumber = nullptr; 450bc1d29deSKrzysztof Grobelny const std::string* serialNumber = nullptr; 451bc1d29deSKrzysztof Grobelny const std::string* manufacturer = nullptr; 452bc1d29deSKrzysztof Grobelny const std::string* model = nullptr; 453bc1d29deSKrzysztof Grobelny const std::string* subModel = nullptr; 454bc1d29deSKrzysztof Grobelny 455bc1d29deSKrzysztof Grobelny const bool success = 456bc1d29deSKrzysztof Grobelny sdbusplus::unpackPropertiesNoThrow( 457bc1d29deSKrzysztof Grobelny dbus_utils::UnpackErrorPrinter(), 458bc1d29deSKrzysztof Grobelny propertiesList, "PartNumber", partNumber, 459bc1d29deSKrzysztof Grobelny "SerialNumber", serialNumber, 460bc1d29deSKrzysztof Grobelny "Manufacturer", manufacturer, "Model", 461bc1d29deSKrzysztof Grobelny model, "SubModel", subModel); 462bc1d29deSKrzysztof Grobelny 463bc1d29deSKrzysztof Grobelny if (!success) 464029573d4SEd Tanous { 465bc1d29deSKrzysztof Grobelny messages::internalError(aResp->res); 466bc1d29deSKrzysztof Grobelny return; 467029573d4SEd Tanous } 468bc1d29deSKrzysztof Grobelny 469bc1d29deSKrzysztof Grobelny if (partNumber != nullptr) 470bc1d29deSKrzysztof Grobelny { 471bc1d29deSKrzysztof Grobelny aResp->res.jsonValue["PartNumber"] = 472bc1d29deSKrzysztof Grobelny *partNumber; 473029573d4SEd Tanous } 474bc1d29deSKrzysztof Grobelny 475bc1d29deSKrzysztof Grobelny if (serialNumber != nullptr) 476bc1d29deSKrzysztof Grobelny { 477bc1d29deSKrzysztof Grobelny aResp->res.jsonValue["SerialNumber"] = 478bc1d29deSKrzysztof Grobelny *serialNumber; 479bc1d29deSKrzysztof Grobelny } 480bc1d29deSKrzysztof Grobelny 481bc1d29deSKrzysztof Grobelny if (manufacturer != nullptr) 482bc1d29deSKrzysztof Grobelny { 483bc1d29deSKrzysztof Grobelny aResp->res.jsonValue["Manufacturer"] = 484bc1d29deSKrzysztof Grobelny *manufacturer; 485bc1d29deSKrzysztof Grobelny } 486bc1d29deSKrzysztof Grobelny 487bc1d29deSKrzysztof Grobelny if (model != nullptr) 488bc1d29deSKrzysztof Grobelny { 489bc1d29deSKrzysztof Grobelny aResp->res.jsonValue["Model"] = *model; 490bc1d29deSKrzysztof Grobelny } 491bc1d29deSKrzysztof Grobelny 492bc1d29deSKrzysztof Grobelny if (subModel != nullptr) 493bc1d29deSKrzysztof Grobelny { 494bc1d29deSKrzysztof Grobelny aResp->res.jsonValue["SubModel"] = *subModel; 495fc5afcf9Sbeccabroek } 496c1e236a6SGunnar Mills 497cb7e1e7bSAndrew Geissler // Grab the bios version 498eee0013eSWilly Tu sw_util::populateSoftwareInformation( 499eee0013eSWilly Tu aResp, sw_util::biosPurpose, "BiosVersion", 500002d39b4SEd Tanous false); 501bc1d29deSKrzysztof Grobelny }); 502e4a4b9a9SJames Feist 5031e1e598dSJonathan Doman sdbusplus::asio::getProperty<std::string>( 5041e1e598dSJonathan Doman *crow::connections::systemBus, connection.first, 5051e1e598dSJonathan Doman path, 5061e1e598dSJonathan Doman "xyz.openbmc_project.Inventory.Decorator." 5071e1e598dSJonathan Doman "AssetTag", 5081e1e598dSJonathan Doman "AssetTag", 509168e20c1SEd Tanous [aResp](const boost::system::error_code ec2, 5101e1e598dSJonathan Doman const std::string& value) { 511cb13a392SEd Tanous if (ec2) 512e4a4b9a9SJames Feist { 513e4a4b9a9SJames Feist // doesn't have to include this 514e4a4b9a9SJames Feist // interface 515e4a4b9a9SJames Feist return; 516e4a4b9a9SJames Feist } 517e4a4b9a9SJames Feist 5181e1e598dSJonathan Doman aResp->res.jsonValue["AssetTag"] = value; 5191e1e598dSJonathan Doman }); 520029573d4SEd Tanous } 521029573d4SEd Tanous } 522bc1d29deSKrzysztof Grobelny break; 523029573d4SEd Tanous } 524c5b2abe0SLewanczyk, Dawid } 525c5b2abe0SLewanczyk, Dawid }, 526c5b2abe0SLewanczyk, Dawid "xyz.openbmc_project.ObjectMapper", 527c5b2abe0SLewanczyk, Dawid "/xyz/openbmc_project/object_mapper", 528c5b2abe0SLewanczyk, Dawid "xyz.openbmc_project.ObjectMapper", "GetSubTree", 5296617338dSEd Tanous "/xyz/openbmc_project/inventory", int32_t(0), 5306617338dSEd Tanous std::array<const char*, 5>{ 5316617338dSEd Tanous "xyz.openbmc_project.Inventory.Decorator.Asset", 5326617338dSEd Tanous "xyz.openbmc_project.Inventory.Item.Cpu", 5336617338dSEd Tanous "xyz.openbmc_project.Inventory.Item.Dimm", 5346617338dSEd Tanous "xyz.openbmc_project.Inventory.Item.System", 5356617338dSEd Tanous "xyz.openbmc_project.Common.UUID", 5366617338dSEd Tanous }); 537c5b2abe0SLewanczyk, Dawid } 538c5b2abe0SLewanczyk, Dawid 539c5b2abe0SLewanczyk, Dawid /** 540c5b2abe0SLewanczyk, Dawid * @brief Retrieves host state properties over dbus 541c5b2abe0SLewanczyk, Dawid * 542c5b2abe0SLewanczyk, Dawid * @param[in] aResp Shared pointer for completing asynchronous calls. 543c5b2abe0SLewanczyk, Dawid * 544c5b2abe0SLewanczyk, Dawid * @return None. 545c5b2abe0SLewanczyk, Dawid */ 5468d1b46d7Szhanghch05 inline void getHostState(const std::shared_ptr<bmcweb::AsyncResp>& aResp) 5471abe55efSEd Tanous { 54855c7b7a2SEd Tanous BMCWEB_LOG_DEBUG << "Get host information."; 5491e1e598dSJonathan Doman sdbusplus::asio::getProperty<std::string>( 5501e1e598dSJonathan Doman *crow::connections::systemBus, "xyz.openbmc_project.State.Host", 5511e1e598dSJonathan Doman "/xyz/openbmc_project/state/host0", "xyz.openbmc_project.State.Host", 5521e1e598dSJonathan Doman "CurrentHostState", 553c5d03ff4SJennifer Lee [aResp](const boost::system::error_code ec, 5541e1e598dSJonathan Doman const std::string& hostState) { 5551abe55efSEd Tanous if (ec) 5561abe55efSEd Tanous { 55722228c28SAndrew Geissler if (ec == boost::system::errc::host_unreachable) 55822228c28SAndrew Geissler { 55922228c28SAndrew Geissler // Service not available, no error, just don't return 56022228c28SAndrew Geissler // host state info 56122228c28SAndrew Geissler BMCWEB_LOG_DEBUG << "Service not available " << ec; 56222228c28SAndrew Geissler return; 56322228c28SAndrew Geissler } 56422228c28SAndrew Geissler BMCWEB_LOG_ERROR << "DBUS response error " << ec; 565f12894f8SJason M. Bills messages::internalError(aResp->res); 566c5b2abe0SLewanczyk, Dawid return; 567c5b2abe0SLewanczyk, Dawid } 5686617338dSEd Tanous 5691e1e598dSJonathan Doman BMCWEB_LOG_DEBUG << "Host state: " << hostState; 570c5b2abe0SLewanczyk, Dawid // Verify Host State 5711e1e598dSJonathan Doman if (hostState == "xyz.openbmc_project.State.Host.HostState.Running") 5721abe55efSEd Tanous { 57355c7b7a2SEd Tanous aResp->res.jsonValue["PowerState"] = "On"; 5746617338dSEd Tanous aResp->res.jsonValue["Status"]["State"] = "Enabled"; 5751abe55efSEd Tanous } 5761e1e598dSJonathan Doman else if (hostState == 5770fda0f12SGeorge Liu "xyz.openbmc_project.State.Host.HostState.Quiesced") 5788c888608SGunnar Mills { 5798c888608SGunnar Mills aResp->res.jsonValue["PowerState"] = "On"; 5808c888608SGunnar Mills aResp->res.jsonValue["Status"]["State"] = "Quiesced"; 5818c888608SGunnar Mills } 5821e1e598dSJonathan Doman else if (hostState == 5830fda0f12SGeorge Liu "xyz.openbmc_project.State.Host.HostState.DiagnosticMode") 58483935af9SAndrew Geissler { 58583935af9SAndrew Geissler aResp->res.jsonValue["PowerState"] = "On"; 58683935af9SAndrew Geissler aResp->res.jsonValue["Status"]["State"] = "InTest"; 58783935af9SAndrew Geissler } 5880fda0f12SGeorge Liu else if ( 5891e1e598dSJonathan Doman hostState == 5900fda0f12SGeorge Liu "xyz.openbmc_project.State.Host.HostState.TransitioningToRunning") 5911a2a1437SAndrew Geissler { 5921a2a1437SAndrew Geissler aResp->res.jsonValue["PowerState"] = "PoweringOn"; 59315c27bf8SNoah Brewer aResp->res.jsonValue["Status"]["State"] = "Starting"; 5941a2a1437SAndrew Geissler } 595002d39b4SEd Tanous else if (hostState == 5960fda0f12SGeorge Liu "xyz.openbmc_project.State.Host.HostState.TransitioningToOff") 5971a2a1437SAndrew Geissler { 5981a2a1437SAndrew Geissler aResp->res.jsonValue["PowerState"] = "PoweringOff"; 5991a2a1437SAndrew Geissler aResp->res.jsonValue["Status"]["State"] = "Disabled"; 6001a2a1437SAndrew Geissler } 6011abe55efSEd Tanous else 6021abe55efSEd Tanous { 60355c7b7a2SEd Tanous aResp->res.jsonValue["PowerState"] = "Off"; 6046617338dSEd Tanous aResp->res.jsonValue["Status"]["State"] = "Disabled"; 605c5b2abe0SLewanczyk, Dawid } 6061e1e598dSJonathan Doman }); 607c5b2abe0SLewanczyk, Dawid } 608c5b2abe0SLewanczyk, Dawid 609c5b2abe0SLewanczyk, Dawid /** 610786d0f60SGunnar Mills * @brief Translates boot source DBUS property value to redfish. 611491d8ee7SSantosh Puranik * 612491d8ee7SSantosh Puranik * @param[in] dbusSource The boot source in DBUS speak. 613491d8ee7SSantosh Puranik * 614491d8ee7SSantosh Puranik * @return Returns as a string, the boot source in Redfish terms. If translation 615491d8ee7SSantosh Puranik * cannot be done, returns an empty string. 616491d8ee7SSantosh Puranik */ 61723a21a1cSEd Tanous inline std::string dbusToRfBootSource(const std::string& dbusSource) 618491d8ee7SSantosh Puranik { 619491d8ee7SSantosh Puranik if (dbusSource == "xyz.openbmc_project.Control.Boot.Source.Sources.Default") 620491d8ee7SSantosh Puranik { 621491d8ee7SSantosh Puranik return "None"; 622491d8ee7SSantosh Puranik } 6233174e4dfSEd Tanous if (dbusSource == "xyz.openbmc_project.Control.Boot.Source.Sources.Disk") 624491d8ee7SSantosh Puranik { 625491d8ee7SSantosh Puranik return "Hdd"; 626491d8ee7SSantosh Puranik } 6273174e4dfSEd Tanous if (dbusSource == 628a71dc0b7SSantosh Puranik "xyz.openbmc_project.Control.Boot.Source.Sources.ExternalMedia") 629491d8ee7SSantosh Puranik { 630491d8ee7SSantosh Puranik return "Cd"; 631491d8ee7SSantosh Puranik } 6323174e4dfSEd Tanous if (dbusSource == "xyz.openbmc_project.Control.Boot.Source.Sources.Network") 633491d8ee7SSantosh Puranik { 634491d8ee7SSantosh Puranik return "Pxe"; 635491d8ee7SSantosh Puranik } 6363174e4dfSEd Tanous if (dbusSource == 637944ffaf9SJohnathan Mantey "xyz.openbmc_project.Control.Boot.Source.Sources.RemovableMedia") 6389f16b2c1SJennifer Lee { 6399f16b2c1SJennifer Lee return "Usb"; 6409f16b2c1SJennifer Lee } 641491d8ee7SSantosh Puranik return ""; 642491d8ee7SSantosh Puranik } 643491d8ee7SSantosh Puranik 644491d8ee7SSantosh Puranik /** 645cd9a4666SKonstantin Aladyshev * @brief Translates boot type DBUS property value to redfish. 646cd9a4666SKonstantin Aladyshev * 647cd9a4666SKonstantin Aladyshev * @param[in] dbusType The boot type in DBUS speak. 648cd9a4666SKonstantin Aladyshev * 649cd9a4666SKonstantin Aladyshev * @return Returns as a string, the boot type in Redfish terms. If translation 650cd9a4666SKonstantin Aladyshev * cannot be done, returns an empty string. 651cd9a4666SKonstantin Aladyshev */ 652cd9a4666SKonstantin Aladyshev inline std::string dbusToRfBootType(const std::string& dbusType) 653cd9a4666SKonstantin Aladyshev { 654cd9a4666SKonstantin Aladyshev if (dbusType == "xyz.openbmc_project.Control.Boot.Type.Types.Legacy") 655cd9a4666SKonstantin Aladyshev { 656cd9a4666SKonstantin Aladyshev return "Legacy"; 657cd9a4666SKonstantin Aladyshev } 658cd9a4666SKonstantin Aladyshev if (dbusType == "xyz.openbmc_project.Control.Boot.Type.Types.EFI") 659cd9a4666SKonstantin Aladyshev { 660cd9a4666SKonstantin Aladyshev return "UEFI"; 661cd9a4666SKonstantin Aladyshev } 662cd9a4666SKonstantin Aladyshev return ""; 663cd9a4666SKonstantin Aladyshev } 664cd9a4666SKonstantin Aladyshev 665cd9a4666SKonstantin Aladyshev /** 666786d0f60SGunnar Mills * @brief Translates boot mode DBUS property value to redfish. 667491d8ee7SSantosh Puranik * 668491d8ee7SSantosh Puranik * @param[in] dbusMode The boot mode in DBUS speak. 669491d8ee7SSantosh Puranik * 670491d8ee7SSantosh Puranik * @return Returns as a string, the boot mode in Redfish terms. If translation 671491d8ee7SSantosh Puranik * cannot be done, returns an empty string. 672491d8ee7SSantosh Puranik */ 67323a21a1cSEd Tanous inline std::string dbusToRfBootMode(const std::string& dbusMode) 674491d8ee7SSantosh Puranik { 675491d8ee7SSantosh Puranik if (dbusMode == "xyz.openbmc_project.Control.Boot.Mode.Modes.Regular") 676491d8ee7SSantosh Puranik { 677491d8ee7SSantosh Puranik return "None"; 678491d8ee7SSantosh Puranik } 6793174e4dfSEd Tanous if (dbusMode == "xyz.openbmc_project.Control.Boot.Mode.Modes.Safe") 680491d8ee7SSantosh Puranik { 681491d8ee7SSantosh Puranik return "Diags"; 682491d8ee7SSantosh Puranik } 6833174e4dfSEd Tanous if (dbusMode == "xyz.openbmc_project.Control.Boot.Mode.Modes.Setup") 684491d8ee7SSantosh Puranik { 685491d8ee7SSantosh Puranik return "BiosSetup"; 686491d8ee7SSantosh Puranik } 687491d8ee7SSantosh Puranik return ""; 688491d8ee7SSantosh Puranik } 689491d8ee7SSantosh Puranik 690491d8ee7SSantosh Puranik /** 691e43914b3SAndrew Geissler * @brief Translates boot progress DBUS property value to redfish. 692e43914b3SAndrew Geissler * 693e43914b3SAndrew Geissler * @param[in] dbusBootProgress The boot progress in DBUS speak. 694e43914b3SAndrew Geissler * 695e43914b3SAndrew Geissler * @return Returns as a string, the boot progress in Redfish terms. If 696e43914b3SAndrew Geissler * translation cannot be done, returns "None". 697e43914b3SAndrew Geissler */ 698e43914b3SAndrew Geissler inline std::string dbusToRfBootProgress(const std::string& dbusBootProgress) 699e43914b3SAndrew Geissler { 700e43914b3SAndrew Geissler // Now convert the D-Bus BootProgress to the appropriate Redfish 701e43914b3SAndrew Geissler // enum 702e43914b3SAndrew Geissler std::string rfBpLastState = "None"; 703e43914b3SAndrew Geissler if (dbusBootProgress == "xyz.openbmc_project.State.Boot.Progress." 704e43914b3SAndrew Geissler "ProgressStages.Unspecified") 705e43914b3SAndrew Geissler { 706e43914b3SAndrew Geissler rfBpLastState = "None"; 707e43914b3SAndrew Geissler } 708e43914b3SAndrew Geissler else if (dbusBootProgress == 709e43914b3SAndrew Geissler "xyz.openbmc_project.State.Boot.Progress.ProgressStages." 710e43914b3SAndrew Geissler "PrimaryProcInit") 711e43914b3SAndrew Geissler { 712e43914b3SAndrew Geissler rfBpLastState = "PrimaryProcessorInitializationStarted"; 713e43914b3SAndrew Geissler } 714e43914b3SAndrew Geissler else if (dbusBootProgress == 715e43914b3SAndrew Geissler "xyz.openbmc_project.State.Boot.Progress.ProgressStages." 716e43914b3SAndrew Geissler "BusInit") 717e43914b3SAndrew Geissler { 718e43914b3SAndrew Geissler rfBpLastState = "BusInitializationStarted"; 719e43914b3SAndrew Geissler } 720e43914b3SAndrew Geissler else if (dbusBootProgress == 721e43914b3SAndrew Geissler "xyz.openbmc_project.State.Boot.Progress.ProgressStages." 722e43914b3SAndrew Geissler "MemoryInit") 723e43914b3SAndrew Geissler { 724e43914b3SAndrew Geissler rfBpLastState = "MemoryInitializationStarted"; 725e43914b3SAndrew Geissler } 726e43914b3SAndrew Geissler else if (dbusBootProgress == 727e43914b3SAndrew Geissler "xyz.openbmc_project.State.Boot.Progress.ProgressStages." 728e43914b3SAndrew Geissler "SecondaryProcInit") 729e43914b3SAndrew Geissler { 730e43914b3SAndrew Geissler rfBpLastState = "SecondaryProcessorInitializationStarted"; 731e43914b3SAndrew Geissler } 732e43914b3SAndrew Geissler else if (dbusBootProgress == 733e43914b3SAndrew Geissler "xyz.openbmc_project.State.Boot.Progress.ProgressStages." 734e43914b3SAndrew Geissler "PCIInit") 735e43914b3SAndrew Geissler { 736e43914b3SAndrew Geissler rfBpLastState = "PCIResourceConfigStarted"; 737e43914b3SAndrew Geissler } 738e43914b3SAndrew Geissler else if (dbusBootProgress == 739e43914b3SAndrew Geissler "xyz.openbmc_project.State.Boot.Progress.ProgressStages." 740e43914b3SAndrew Geissler "SystemSetup") 741e43914b3SAndrew Geissler { 742e43914b3SAndrew Geissler rfBpLastState = "SetupEntered"; 743e43914b3SAndrew Geissler } 744e43914b3SAndrew Geissler else if (dbusBootProgress == 745e43914b3SAndrew Geissler "xyz.openbmc_project.State.Boot.Progress.ProgressStages." 746e43914b3SAndrew Geissler "SystemInitComplete") 747e43914b3SAndrew Geissler { 748e43914b3SAndrew Geissler rfBpLastState = "SystemHardwareInitializationComplete"; 749e43914b3SAndrew Geissler } 750e43914b3SAndrew Geissler else if (dbusBootProgress == 751e43914b3SAndrew Geissler "xyz.openbmc_project.State.Boot.Progress.ProgressStages." 752e43914b3SAndrew Geissler "OSStart") 753e43914b3SAndrew Geissler { 754e43914b3SAndrew Geissler rfBpLastState = "OSBootStarted"; 755e43914b3SAndrew Geissler } 756e43914b3SAndrew Geissler else if (dbusBootProgress == 757e43914b3SAndrew Geissler "xyz.openbmc_project.State.Boot.Progress.ProgressStages." 758e43914b3SAndrew Geissler "OSRunning") 759e43914b3SAndrew Geissler { 760e43914b3SAndrew Geissler rfBpLastState = "OSRunning"; 761e43914b3SAndrew Geissler } 762e43914b3SAndrew Geissler else 763e43914b3SAndrew Geissler { 764e43914b3SAndrew Geissler BMCWEB_LOG_DEBUG << "Unsupported D-Bus BootProgress " 765e43914b3SAndrew Geissler << dbusBootProgress; 766e43914b3SAndrew Geissler // Just return the default 767e43914b3SAndrew Geissler } 768e43914b3SAndrew Geissler return rfBpLastState; 769e43914b3SAndrew Geissler } 770e43914b3SAndrew Geissler 771e43914b3SAndrew Geissler /** 772786d0f60SGunnar Mills * @brief Translates boot source from Redfish to the DBus boot paths. 773491d8ee7SSantosh Puranik * 774491d8ee7SSantosh Puranik * @param[in] rfSource The boot source in Redfish. 775944ffaf9SJohnathan Mantey * @param[out] bootSource The DBus source 776944ffaf9SJohnathan Mantey * @param[out] bootMode the DBus boot mode 777491d8ee7SSantosh Puranik * 778944ffaf9SJohnathan Mantey * @return Integer error code. 779491d8ee7SSantosh Puranik */ 7808d1b46d7Szhanghch05 inline int assignBootParameters(const std::shared_ptr<bmcweb::AsyncResp>& aResp, 781944ffaf9SJohnathan Mantey const std::string& rfSource, 782944ffaf9SJohnathan Mantey std::string& bootSource, std::string& bootMode) 783491d8ee7SSantosh Puranik { 784c21865c4SKonstantin Aladyshev bootSource = "xyz.openbmc_project.Control.Boot.Source.Sources.Default"; 785c21865c4SKonstantin Aladyshev bootMode = "xyz.openbmc_project.Control.Boot.Mode.Modes.Regular"; 786944ffaf9SJohnathan Mantey 787491d8ee7SSantosh Puranik if (rfSource == "None") 788491d8ee7SSantosh Puranik { 789944ffaf9SJohnathan Mantey return 0; 790491d8ee7SSantosh Puranik } 7913174e4dfSEd Tanous if (rfSource == "Pxe") 792491d8ee7SSantosh Puranik { 793944ffaf9SJohnathan Mantey bootSource = "xyz.openbmc_project.Control.Boot.Source.Sources.Network"; 794944ffaf9SJohnathan Mantey } 795944ffaf9SJohnathan Mantey else if (rfSource == "Hdd") 796944ffaf9SJohnathan Mantey { 797944ffaf9SJohnathan Mantey bootSource = "xyz.openbmc_project.Control.Boot.Source.Sources.Disk"; 798944ffaf9SJohnathan Mantey } 799944ffaf9SJohnathan Mantey else if (rfSource == "Diags") 800944ffaf9SJohnathan Mantey { 801944ffaf9SJohnathan Mantey bootMode = "xyz.openbmc_project.Control.Boot.Mode.Modes.Safe"; 802944ffaf9SJohnathan Mantey } 803944ffaf9SJohnathan Mantey else if (rfSource == "Cd") 804944ffaf9SJohnathan Mantey { 805944ffaf9SJohnathan Mantey bootSource = 806944ffaf9SJohnathan Mantey "xyz.openbmc_project.Control.Boot.Source.Sources.ExternalMedia"; 807944ffaf9SJohnathan Mantey } 808944ffaf9SJohnathan Mantey else if (rfSource == "BiosSetup") 809944ffaf9SJohnathan Mantey { 810944ffaf9SJohnathan Mantey bootMode = "xyz.openbmc_project.Control.Boot.Mode.Modes.Setup"; 811491d8ee7SSantosh Puranik } 8129f16b2c1SJennifer Lee else if (rfSource == "Usb") 8139f16b2c1SJennifer Lee { 814944ffaf9SJohnathan Mantey bootSource = 815944ffaf9SJohnathan Mantey "xyz.openbmc_project.Control.Boot.Source.Sources.RemovableMedia"; 8169f16b2c1SJennifer Lee } 817491d8ee7SSantosh Puranik else 818491d8ee7SSantosh Puranik { 8190fda0f12SGeorge Liu BMCWEB_LOG_DEBUG 8200fda0f12SGeorge Liu << "Invalid property value for BootSourceOverrideTarget: " 821944ffaf9SJohnathan Mantey << bootSource; 822944ffaf9SJohnathan Mantey messages::propertyValueNotInList(aResp->res, rfSource, 823944ffaf9SJohnathan Mantey "BootSourceTargetOverride"); 824944ffaf9SJohnathan Mantey return -1; 825491d8ee7SSantosh Puranik } 826944ffaf9SJohnathan Mantey return 0; 827491d8ee7SSantosh Puranik } 8281981771bSAli Ahmed 829978b8803SAndrew Geissler /** 830978b8803SAndrew Geissler * @brief Retrieves boot progress of the system 831978b8803SAndrew Geissler * 832978b8803SAndrew Geissler * @param[in] aResp Shared pointer for generating response message. 833978b8803SAndrew Geissler * 834978b8803SAndrew Geissler * @return None. 835978b8803SAndrew Geissler */ 8368d1b46d7Szhanghch05 inline void getBootProgress(const std::shared_ptr<bmcweb::AsyncResp>& aResp) 837978b8803SAndrew Geissler { 8381e1e598dSJonathan Doman sdbusplus::asio::getProperty<std::string>( 8391e1e598dSJonathan Doman *crow::connections::systemBus, "xyz.openbmc_project.State.Host", 8401e1e598dSJonathan Doman "/xyz/openbmc_project/state/host0", 8411e1e598dSJonathan Doman "xyz.openbmc_project.State.Boot.Progress", "BootProgress", 842978b8803SAndrew Geissler [aResp](const boost::system::error_code ec, 8431e1e598dSJonathan Doman const std::string& bootProgressStr) { 844978b8803SAndrew Geissler if (ec) 845978b8803SAndrew Geissler { 846978b8803SAndrew Geissler // BootProgress is an optional object so just do nothing if 847978b8803SAndrew Geissler // not found 848978b8803SAndrew Geissler return; 849978b8803SAndrew Geissler } 850978b8803SAndrew Geissler 8511e1e598dSJonathan Doman BMCWEB_LOG_DEBUG << "Boot Progress: " << bootProgressStr; 852978b8803SAndrew Geissler 853e43914b3SAndrew Geissler aResp->res.jsonValue["BootProgress"]["LastState"] = 854e43914b3SAndrew Geissler dbusToRfBootProgress(bootProgressStr); 8551e1e598dSJonathan Doman }); 856978b8803SAndrew Geissler } 857491d8ee7SSantosh Puranik 858491d8ee7SSantosh Puranik /** 859*b6d5d45cSHieu Huynh * @brief Retrieves boot progress Last Update of the system 860*b6d5d45cSHieu Huynh * 861*b6d5d45cSHieu Huynh * @param[in] aResp Shared pointer for generating response message. 862*b6d5d45cSHieu Huynh * 863*b6d5d45cSHieu Huynh * @return None. 864*b6d5d45cSHieu Huynh */ 865*b6d5d45cSHieu Huynh inline void getBootProgressLastStateTime( 866*b6d5d45cSHieu Huynh const std::shared_ptr<bmcweb::AsyncResp>& aResp) 867*b6d5d45cSHieu Huynh { 868*b6d5d45cSHieu Huynh sdbusplus::asio::getProperty<uint64_t>( 869*b6d5d45cSHieu Huynh *crow::connections::systemBus, "xyz.openbmc_project.State.Host", 870*b6d5d45cSHieu Huynh "/xyz/openbmc_project/state/host0", 871*b6d5d45cSHieu Huynh "xyz.openbmc_project.State.Boot.Progress", "BootProgressLastUpdate", 872*b6d5d45cSHieu Huynh [aResp](const boost::system::error_code ec, 873*b6d5d45cSHieu Huynh const uint64_t lastStateTime) { 874*b6d5d45cSHieu Huynh if (ec) 875*b6d5d45cSHieu Huynh { 876*b6d5d45cSHieu Huynh BMCWEB_LOG_DEBUG << "D-BUS response error " << ec; 877*b6d5d45cSHieu Huynh return; 878*b6d5d45cSHieu Huynh } 879*b6d5d45cSHieu Huynh 880*b6d5d45cSHieu Huynh // BootProgressLastUpdate is the last time the BootProgress property 881*b6d5d45cSHieu Huynh // was updated. The time is the Epoch time, number of microseconds 882*b6d5d45cSHieu Huynh // since 1 Jan 1970 00::00::00 UTC." 883*b6d5d45cSHieu Huynh // https://github.com/openbmc/phosphor-dbus-interfaces/blob/master/ 884*b6d5d45cSHieu Huynh // yaml/xyz/openbmc_project/State/Boot/Progress.interface.yaml#L11 885*b6d5d45cSHieu Huynh 886*b6d5d45cSHieu Huynh // Convert to ISO 8601 standard 887*b6d5d45cSHieu Huynh aResp->res.jsonValue["BootProgress"]["LastStateTime"] = 888*b6d5d45cSHieu Huynh redfish::time_utils::getDateTimeUintUs(lastStateTime); 889*b6d5d45cSHieu Huynh }); 890*b6d5d45cSHieu Huynh } 891*b6d5d45cSHieu Huynh 892*b6d5d45cSHieu Huynh /** 893c21865c4SKonstantin Aladyshev * @brief Retrieves boot override type over DBUS and fills out the response 894cd9a4666SKonstantin Aladyshev * 895cd9a4666SKonstantin Aladyshev * @param[in] aResp Shared pointer for generating response message. 896cd9a4666SKonstantin Aladyshev * 897cd9a4666SKonstantin Aladyshev * @return None. 898cd9a4666SKonstantin Aladyshev */ 899cd9a4666SKonstantin Aladyshev 900c21865c4SKonstantin Aladyshev inline void getBootOverrideType(const std::shared_ptr<bmcweb::AsyncResp>& aResp) 901cd9a4666SKonstantin Aladyshev { 9021e1e598dSJonathan Doman sdbusplus::asio::getProperty<std::string>( 9031e1e598dSJonathan Doman *crow::connections::systemBus, "xyz.openbmc_project.Settings", 9041e1e598dSJonathan Doman "/xyz/openbmc_project/control/host0/boot", 9051e1e598dSJonathan Doman "xyz.openbmc_project.Control.Boot.Type", "BootType", 906cd9a4666SKonstantin Aladyshev [aResp](const boost::system::error_code ec, 9071e1e598dSJonathan Doman const std::string& bootType) { 908cd9a4666SKonstantin Aladyshev if (ec) 909cd9a4666SKonstantin Aladyshev { 910cd9a4666SKonstantin Aladyshev // not an error, don't have to have the interface 911cd9a4666SKonstantin Aladyshev return; 912cd9a4666SKonstantin Aladyshev } 913cd9a4666SKonstantin Aladyshev 9141e1e598dSJonathan Doman BMCWEB_LOG_DEBUG << "Boot type: " << bootType; 915cd9a4666SKonstantin Aladyshev 916002d39b4SEd Tanous aResp->res.jsonValue["Boot"] 917002d39b4SEd Tanous ["BootSourceOverrideMode@Redfish.AllowableValues"] = 918613dabeaSEd Tanous nlohmann::json::array_t({"Legacy", "UEFI"}); 919cd9a4666SKonstantin Aladyshev 9201e1e598dSJonathan Doman auto rfType = dbusToRfBootType(bootType); 921cd9a4666SKonstantin Aladyshev if (rfType.empty()) 922cd9a4666SKonstantin Aladyshev { 923cd9a4666SKonstantin Aladyshev messages::internalError(aResp->res); 924cd9a4666SKonstantin Aladyshev return; 925cd9a4666SKonstantin Aladyshev } 926cd9a4666SKonstantin Aladyshev 927cd9a4666SKonstantin Aladyshev aResp->res.jsonValue["Boot"]["BootSourceOverrideMode"] = rfType; 9281e1e598dSJonathan Doman }); 929cd9a4666SKonstantin Aladyshev } 930cd9a4666SKonstantin Aladyshev 931cd9a4666SKonstantin Aladyshev /** 932c21865c4SKonstantin Aladyshev * @brief Retrieves boot override mode over DBUS and fills out the response 933491d8ee7SSantosh Puranik * 934491d8ee7SSantosh Puranik * @param[in] aResp Shared pointer for generating response message. 935491d8ee7SSantosh Puranik * 936491d8ee7SSantosh Puranik * @return None. 937491d8ee7SSantosh Puranik */ 938c21865c4SKonstantin Aladyshev 939c21865c4SKonstantin Aladyshev inline void getBootOverrideMode(const std::shared_ptr<bmcweb::AsyncResp>& aResp) 940491d8ee7SSantosh Puranik { 9411e1e598dSJonathan Doman sdbusplus::asio::getProperty<std::string>( 9421e1e598dSJonathan Doman *crow::connections::systemBus, "xyz.openbmc_project.Settings", 9431e1e598dSJonathan Doman "/xyz/openbmc_project/control/host0/boot", 9441e1e598dSJonathan Doman "xyz.openbmc_project.Control.Boot.Mode", "BootMode", 945c21865c4SKonstantin Aladyshev [aResp](const boost::system::error_code ec, 9461e1e598dSJonathan Doman const std::string& bootModeStr) { 947491d8ee7SSantosh Puranik if (ec) 948491d8ee7SSantosh Puranik { 949491d8ee7SSantosh Puranik BMCWEB_LOG_DEBUG << "DBUS response error " << ec; 950491d8ee7SSantosh Puranik messages::internalError(aResp->res); 951491d8ee7SSantosh Puranik return; 952491d8ee7SSantosh Puranik } 953491d8ee7SSantosh Puranik 9541e1e598dSJonathan Doman BMCWEB_LOG_DEBUG << "Boot mode: " << bootModeStr; 955491d8ee7SSantosh Puranik 9560fda0f12SGeorge Liu aResp->res 9570fda0f12SGeorge Liu .jsonValue["Boot"] 958002d39b4SEd Tanous ["BootSourceOverrideTarget@Redfish.AllowableValues"] = { 959002d39b4SEd Tanous "None", "Pxe", "Hdd", "Cd", "Diags", "BiosSetup", "Usb"}; 960491d8ee7SSantosh Puranik 9611e1e598dSJonathan Doman if (bootModeStr != 962491d8ee7SSantosh Puranik "xyz.openbmc_project.Control.Boot.Mode.Modes.Regular") 963491d8ee7SSantosh Puranik { 9641e1e598dSJonathan Doman auto rfMode = dbusToRfBootMode(bootModeStr); 965491d8ee7SSantosh Puranik if (!rfMode.empty()) 966491d8ee7SSantosh Puranik { 967491d8ee7SSantosh Puranik aResp->res.jsonValue["Boot"]["BootSourceOverrideTarget"] = 968491d8ee7SSantosh Puranik rfMode; 969491d8ee7SSantosh Puranik } 970491d8ee7SSantosh Puranik } 9711e1e598dSJonathan Doman }); 972491d8ee7SSantosh Puranik } 973491d8ee7SSantosh Puranik 974491d8ee7SSantosh Puranik /** 975c21865c4SKonstantin Aladyshev * @brief Retrieves boot override source over DBUS 976491d8ee7SSantosh Puranik * 977491d8ee7SSantosh Puranik * @param[in] aResp Shared pointer for generating response message. 978491d8ee7SSantosh Puranik * 979491d8ee7SSantosh Puranik * @return None. 980491d8ee7SSantosh Puranik */ 981c21865c4SKonstantin Aladyshev 982c21865c4SKonstantin Aladyshev inline void 983c21865c4SKonstantin Aladyshev getBootOverrideSource(const std::shared_ptr<bmcweb::AsyncResp>& aResp) 984491d8ee7SSantosh Puranik { 9851e1e598dSJonathan Doman sdbusplus::asio::getProperty<std::string>( 9861e1e598dSJonathan Doman *crow::connections::systemBus, "xyz.openbmc_project.Settings", 9871e1e598dSJonathan Doman "/xyz/openbmc_project/control/host0/boot", 9881e1e598dSJonathan Doman "xyz.openbmc_project.Control.Boot.Source", "BootSource", 989c21865c4SKonstantin Aladyshev [aResp](const boost::system::error_code ec, 9901e1e598dSJonathan Doman const std::string& bootSourceStr) { 991491d8ee7SSantosh Puranik if (ec) 992491d8ee7SSantosh Puranik { 993491d8ee7SSantosh Puranik BMCWEB_LOG_DEBUG << "DBUS response error " << ec; 9945ef735c8SNan Zhou if (ec.value() == boost::asio::error::host_unreachable) 9955ef735c8SNan Zhou { 9965ef735c8SNan Zhou return; 9975ef735c8SNan Zhou } 998491d8ee7SSantosh Puranik messages::internalError(aResp->res); 999491d8ee7SSantosh Puranik return; 1000491d8ee7SSantosh Puranik } 1001491d8ee7SSantosh Puranik 10021e1e598dSJonathan Doman BMCWEB_LOG_DEBUG << "Boot source: " << bootSourceStr; 1003491d8ee7SSantosh Puranik 10041e1e598dSJonathan Doman auto rfSource = dbusToRfBootSource(bootSourceStr); 1005491d8ee7SSantosh Puranik if (!rfSource.empty()) 1006491d8ee7SSantosh Puranik { 1007002d39b4SEd Tanous aResp->res.jsonValue["Boot"]["BootSourceOverrideTarget"] = rfSource; 1008491d8ee7SSantosh Puranik } 1009cd9a4666SKonstantin Aladyshev 1010cd9a4666SKonstantin Aladyshev // Get BootMode as BootSourceOverrideTarget is constructed 1011cd9a4666SKonstantin Aladyshev // from both BootSource and BootMode 1012c21865c4SKonstantin Aladyshev getBootOverrideMode(aResp); 10131e1e598dSJonathan Doman }); 1014491d8ee7SSantosh Puranik } 1015491d8ee7SSantosh Puranik 1016491d8ee7SSantosh Puranik /** 1017c21865c4SKonstantin Aladyshev * @brief This functions abstracts all the logic behind getting a 1018c21865c4SKonstantin Aladyshev * "BootSourceOverrideEnabled" property from an overall boot override enable 1019c21865c4SKonstantin Aladyshev * state 1020491d8ee7SSantosh Puranik * 1021491d8ee7SSantosh Puranik * @param[in] aResp Shared pointer for generating response message. 1022491d8ee7SSantosh Puranik * 1023491d8ee7SSantosh Puranik * @return None. 1024491d8ee7SSantosh Puranik */ 1025491d8ee7SSantosh Puranik 1026c21865c4SKonstantin Aladyshev inline void 1027c21865c4SKonstantin Aladyshev processBootOverrideEnable(const std::shared_ptr<bmcweb::AsyncResp>& aResp, 1028c21865c4SKonstantin Aladyshev const bool bootOverrideEnableSetting) 1029c21865c4SKonstantin Aladyshev { 1030c21865c4SKonstantin Aladyshev if (!bootOverrideEnableSetting) 1031c21865c4SKonstantin Aladyshev { 1032c21865c4SKonstantin Aladyshev aResp->res.jsonValue["Boot"]["BootSourceOverrideEnabled"] = "Disabled"; 1033c21865c4SKonstantin Aladyshev return; 1034c21865c4SKonstantin Aladyshev } 1035c21865c4SKonstantin Aladyshev 1036c21865c4SKonstantin Aladyshev // If boot source override is enabled, we need to check 'one_time' 1037c21865c4SKonstantin Aladyshev // property to set a correct value for the "BootSourceOverrideEnabled" 10381e1e598dSJonathan Doman sdbusplus::asio::getProperty<bool>( 10391e1e598dSJonathan Doman *crow::connections::systemBus, "xyz.openbmc_project.Settings", 10401e1e598dSJonathan Doman "/xyz/openbmc_project/control/host0/boot/one_time", 10411e1e598dSJonathan Doman "xyz.openbmc_project.Object.Enable", "Enabled", 10421e1e598dSJonathan Doman [aResp](const boost::system::error_code ec, bool oneTimeSetting) { 1043491d8ee7SSantosh Puranik if (ec) 1044491d8ee7SSantosh Puranik { 1045491d8ee7SSantosh Puranik BMCWEB_LOG_DEBUG << "DBUS response error " << ec; 1046c21865c4SKonstantin Aladyshev messages::internalError(aResp->res); 1047491d8ee7SSantosh Puranik return; 1048491d8ee7SSantosh Puranik } 1049491d8ee7SSantosh Puranik 1050c21865c4SKonstantin Aladyshev if (oneTimeSetting) 1051c21865c4SKonstantin Aladyshev { 1052002d39b4SEd Tanous aResp->res.jsonValue["Boot"]["BootSourceOverrideEnabled"] = "Once"; 1053c21865c4SKonstantin Aladyshev } 1054c21865c4SKonstantin Aladyshev else 1055c21865c4SKonstantin Aladyshev { 1056c21865c4SKonstantin Aladyshev aResp->res.jsonValue["Boot"]["BootSourceOverrideEnabled"] = 1057c21865c4SKonstantin Aladyshev "Continuous"; 1058c21865c4SKonstantin Aladyshev } 10591e1e598dSJonathan Doman }); 1060491d8ee7SSantosh Puranik } 1061491d8ee7SSantosh Puranik 1062491d8ee7SSantosh Puranik /** 1063c21865c4SKonstantin Aladyshev * @brief Retrieves boot override enable over DBUS 1064c21865c4SKonstantin Aladyshev * 1065c21865c4SKonstantin Aladyshev * @param[in] aResp Shared pointer for generating response message. 1066c21865c4SKonstantin Aladyshev * 1067c21865c4SKonstantin Aladyshev * @return None. 1068c21865c4SKonstantin Aladyshev */ 1069c21865c4SKonstantin Aladyshev 1070c21865c4SKonstantin Aladyshev inline void 1071c21865c4SKonstantin Aladyshev getBootOverrideEnable(const std::shared_ptr<bmcweb::AsyncResp>& aResp) 1072c21865c4SKonstantin Aladyshev { 10731e1e598dSJonathan Doman sdbusplus::asio::getProperty<bool>( 10741e1e598dSJonathan Doman *crow::connections::systemBus, "xyz.openbmc_project.Settings", 10751e1e598dSJonathan Doman "/xyz/openbmc_project/control/host0/boot", 10761e1e598dSJonathan Doman "xyz.openbmc_project.Object.Enable", "Enabled", 1077c21865c4SKonstantin Aladyshev [aResp](const boost::system::error_code ec, 10781e1e598dSJonathan Doman const bool bootOverrideEnable) { 1079c21865c4SKonstantin Aladyshev if (ec) 1080c21865c4SKonstantin Aladyshev { 1081c21865c4SKonstantin Aladyshev BMCWEB_LOG_DEBUG << "DBUS response error " << ec; 10825ef735c8SNan Zhou if (ec.value() == boost::asio::error::host_unreachable) 10835ef735c8SNan Zhou { 10845ef735c8SNan Zhou return; 10855ef735c8SNan Zhou } 1086c21865c4SKonstantin Aladyshev messages::internalError(aResp->res); 1087c21865c4SKonstantin Aladyshev return; 1088c21865c4SKonstantin Aladyshev } 1089c21865c4SKonstantin Aladyshev 10901e1e598dSJonathan Doman processBootOverrideEnable(aResp, bootOverrideEnable); 10911e1e598dSJonathan Doman }); 1092c21865c4SKonstantin Aladyshev } 1093c21865c4SKonstantin Aladyshev 1094c21865c4SKonstantin Aladyshev /** 1095c21865c4SKonstantin Aladyshev * @brief Retrieves boot source override properties 1096c21865c4SKonstantin Aladyshev * 1097c21865c4SKonstantin Aladyshev * @param[in] aResp Shared pointer for generating response message. 1098c21865c4SKonstantin Aladyshev * 1099c21865c4SKonstantin Aladyshev * @return None. 1100c21865c4SKonstantin Aladyshev */ 1101c21865c4SKonstantin Aladyshev inline void getBootProperties(const std::shared_ptr<bmcweb::AsyncResp>& aResp) 1102c21865c4SKonstantin Aladyshev { 1103c21865c4SKonstantin Aladyshev BMCWEB_LOG_DEBUG << "Get boot information."; 1104c21865c4SKonstantin Aladyshev 1105c21865c4SKonstantin Aladyshev getBootOverrideSource(aResp); 1106c21865c4SKonstantin Aladyshev getBootOverrideType(aResp); 1107c21865c4SKonstantin Aladyshev getBootOverrideEnable(aResp); 1108c21865c4SKonstantin Aladyshev } 1109c21865c4SKonstantin Aladyshev 1110c21865c4SKonstantin Aladyshev /** 1111c0557e1aSGunnar Mills * @brief Retrieves the Last Reset Time 1112c0557e1aSGunnar Mills * 1113c0557e1aSGunnar Mills * "Reset" is an overloaded term in Redfish, "Reset" includes power on 1114c0557e1aSGunnar Mills * and power off. Even though this is the "system" Redfish object look at the 1115c0557e1aSGunnar Mills * chassis D-Bus interface for the LastStateChangeTime since this has the 1116c0557e1aSGunnar Mills * last power operation time. 1117c0557e1aSGunnar Mills * 1118c0557e1aSGunnar Mills * @param[in] aResp Shared pointer for generating response message. 1119c0557e1aSGunnar Mills * 1120c0557e1aSGunnar Mills * @return None. 1121c0557e1aSGunnar Mills */ 11228d1b46d7Szhanghch05 inline void getLastResetTime(const std::shared_ptr<bmcweb::AsyncResp>& aResp) 1123c0557e1aSGunnar Mills { 1124c0557e1aSGunnar Mills BMCWEB_LOG_DEBUG << "Getting System Last Reset Time"; 1125c0557e1aSGunnar Mills 11261e1e598dSJonathan Doman sdbusplus::asio::getProperty<uint64_t>( 11271e1e598dSJonathan Doman *crow::connections::systemBus, "xyz.openbmc_project.State.Chassis", 11281e1e598dSJonathan Doman "/xyz/openbmc_project/state/chassis0", 11291e1e598dSJonathan Doman "xyz.openbmc_project.State.Chassis", "LastStateChangeTime", 11301e1e598dSJonathan Doman [aResp](const boost::system::error_code ec, uint64_t lastResetTime) { 1131c0557e1aSGunnar Mills if (ec) 1132c0557e1aSGunnar Mills { 1133c0557e1aSGunnar Mills BMCWEB_LOG_DEBUG << "D-BUS response error " << ec; 1134c0557e1aSGunnar Mills return; 1135c0557e1aSGunnar Mills } 1136c0557e1aSGunnar Mills 1137c0557e1aSGunnar Mills // LastStateChangeTime is epoch time, in milliseconds 1138c0557e1aSGunnar Mills // https://github.com/openbmc/phosphor-dbus-interfaces/blob/33e8e1dd64da53a66e888d33dc82001305cd0bf9/xyz/openbmc_project/State/Chassis.interface.yaml#L19 11391e1e598dSJonathan Doman uint64_t lastResetTimeStamp = lastResetTime / 1000; 1140c0557e1aSGunnar Mills 1141c0557e1aSGunnar Mills // Convert to ISO 8601 standard 1142c0557e1aSGunnar Mills aResp->res.jsonValue["LastResetTime"] = 11432b82937eSEd Tanous redfish::time_utils::getDateTimeUint(lastResetTimeStamp); 11441e1e598dSJonathan Doman }); 1145c0557e1aSGunnar Mills } 1146c0557e1aSGunnar Mills 1147c0557e1aSGunnar Mills /** 11486bd5a8d2SGunnar Mills * @brief Retrieves Automatic Retry properties. Known on D-Bus as AutoReboot. 11496bd5a8d2SGunnar Mills * 11506bd5a8d2SGunnar Mills * @param[in] aResp Shared pointer for generating response message. 11516bd5a8d2SGunnar Mills * 11526bd5a8d2SGunnar Mills * @return None. 11536bd5a8d2SGunnar Mills */ 11548d1b46d7Szhanghch05 inline void getAutomaticRetry(const std::shared_ptr<bmcweb::AsyncResp>& aResp) 11556bd5a8d2SGunnar Mills { 11566bd5a8d2SGunnar Mills BMCWEB_LOG_DEBUG << "Get Automatic Retry policy"; 11576bd5a8d2SGunnar Mills 11581e1e598dSJonathan Doman sdbusplus::asio::getProperty<bool>( 11591e1e598dSJonathan Doman *crow::connections::systemBus, "xyz.openbmc_project.Settings", 11601e1e598dSJonathan Doman "/xyz/openbmc_project/control/host0/auto_reboot", 11611e1e598dSJonathan Doman "xyz.openbmc_project.Control.Boot.RebootPolicy", "AutoReboot", 11621e1e598dSJonathan Doman [aResp](const boost::system::error_code ec, bool autoRebootEnabled) { 11636bd5a8d2SGunnar Mills if (ec) 11646bd5a8d2SGunnar Mills { 11656bd5a8d2SGunnar Mills BMCWEB_LOG_DEBUG << "D-BUS response error " << ec; 11666bd5a8d2SGunnar Mills return; 11676bd5a8d2SGunnar Mills } 11686bd5a8d2SGunnar Mills 11691e1e598dSJonathan Doman BMCWEB_LOG_DEBUG << "Auto Reboot: " << autoRebootEnabled; 1170e05aec50SEd Tanous if (autoRebootEnabled) 11716bd5a8d2SGunnar Mills { 11726bd5a8d2SGunnar Mills aResp->res.jsonValue["Boot"]["AutomaticRetryConfig"] = 11736bd5a8d2SGunnar Mills "RetryAttempts"; 11746bd5a8d2SGunnar Mills // If AutomaticRetry (AutoReboot) is enabled see how many 11756bd5a8d2SGunnar Mills // attempts are left 11761e1e598dSJonathan Doman sdbusplus::asio::getProperty<uint32_t>( 1177002d39b4SEd Tanous *crow::connections::systemBus, "xyz.openbmc_project.State.Host", 11781e1e598dSJonathan Doman "/xyz/openbmc_project/state/host0", 11791e1e598dSJonathan Doman "xyz.openbmc_project.Control.Boot.RebootAttempts", 11801e1e598dSJonathan Doman "AttemptsLeft", 1181cb13a392SEd Tanous [aResp](const boost::system::error_code ec2, 1182914e2d5dSEd Tanous const uint32_t autoRebootAttemptsLeft) { 1183cb13a392SEd Tanous if (ec2) 11846bd5a8d2SGunnar Mills { 1185cb13a392SEd Tanous BMCWEB_LOG_DEBUG << "D-BUS response error " << ec2; 11866bd5a8d2SGunnar Mills return; 11876bd5a8d2SGunnar Mills } 11886bd5a8d2SGunnar Mills 11896bd5a8d2SGunnar Mills BMCWEB_LOG_DEBUG << "Auto Reboot Attempts Left: " 11901e1e598dSJonathan Doman << autoRebootAttemptsLeft; 11916bd5a8d2SGunnar Mills 11926bd5a8d2SGunnar Mills aResp->res 1193002d39b4SEd Tanous .jsonValue["Boot"]["RemainingAutomaticRetryAttempts"] = 11941e1e598dSJonathan Doman autoRebootAttemptsLeft; 11951e1e598dSJonathan Doman }); 11966bd5a8d2SGunnar Mills } 11976bd5a8d2SGunnar Mills else 11986bd5a8d2SGunnar Mills { 1199002d39b4SEd Tanous aResp->res.jsonValue["Boot"]["AutomaticRetryConfig"] = "Disabled"; 12006bd5a8d2SGunnar Mills } 12016bd5a8d2SGunnar Mills 12026bd5a8d2SGunnar Mills // Not on D-Bus. Hardcoded here: 12036bd5a8d2SGunnar Mills // https://github.com/openbmc/phosphor-state-manager/blob/1dbbef42675e94fb1f78edb87d6b11380260535a/meson_options.txt#L71 12046bd5a8d2SGunnar Mills aResp->res.jsonValue["Boot"]["AutomaticRetryAttempts"] = 3; 120569f35306SGunnar Mills 120669f35306SGunnar Mills // "AutomaticRetryConfig" can be 3 values, Disabled, RetryAlways, 120769f35306SGunnar Mills // and RetryAttempts. OpenBMC only supports Disabled and 120869f35306SGunnar Mills // RetryAttempts. 1209002d39b4SEd Tanous aResp->res.jsonValue["Boot"] 12100fda0f12SGeorge Liu ["AutomaticRetryConfig@Redfish.AllowableValues"] = { 12110fda0f12SGeorge Liu "Disabled", "RetryAttempts"}; 12121e1e598dSJonathan Doman }); 12136bd5a8d2SGunnar Mills } 12146bd5a8d2SGunnar Mills 12156bd5a8d2SGunnar Mills /** 1216c6a620f2SGeorge Liu * @brief Retrieves power restore policy over DBUS. 1217c6a620f2SGeorge Liu * 1218c6a620f2SGeorge Liu * @param[in] aResp Shared pointer for generating response message. 1219c6a620f2SGeorge Liu * 1220c6a620f2SGeorge Liu * @return None. 1221c6a620f2SGeorge Liu */ 12228d1b46d7Szhanghch05 inline void 12238d1b46d7Szhanghch05 getPowerRestorePolicy(const std::shared_ptr<bmcweb::AsyncResp>& aResp) 1224c6a620f2SGeorge Liu { 1225c6a620f2SGeorge Liu BMCWEB_LOG_DEBUG << "Get power restore policy"; 1226c6a620f2SGeorge Liu 12271e1e598dSJonathan Doman sdbusplus::asio::getProperty<std::string>( 12281e1e598dSJonathan Doman *crow::connections::systemBus, "xyz.openbmc_project.Settings", 12291e1e598dSJonathan Doman "/xyz/openbmc_project/control/host0/power_restore_policy", 12301e1e598dSJonathan Doman "xyz.openbmc_project.Control.Power.RestorePolicy", "PowerRestorePolicy", 12311e1e598dSJonathan Doman [aResp](const boost::system::error_code ec, const std::string& policy) { 1232c6a620f2SGeorge Liu if (ec) 1233c6a620f2SGeorge Liu { 1234c6a620f2SGeorge Liu BMCWEB_LOG_DEBUG << "DBUS response error " << ec; 1235c6a620f2SGeorge Liu return; 1236c6a620f2SGeorge Liu } 1237c6a620f2SGeorge Liu 12380fda0f12SGeorge Liu const boost::container::flat_map<std::string, std::string> policyMaps = { 12390fda0f12SGeorge Liu {"xyz.openbmc_project.Control.Power.RestorePolicy.Policy.AlwaysOn", 1240c6a620f2SGeorge Liu "AlwaysOn"}, 12410fda0f12SGeorge Liu {"xyz.openbmc_project.Control.Power.RestorePolicy.Policy.AlwaysOff", 1242c6a620f2SGeorge Liu "AlwaysOff"}, 12430fda0f12SGeorge Liu {"xyz.openbmc_project.Control.Power.RestorePolicy.Policy.Restore", 12444ed47cb8SMatthew Barth "LastState"}, 12454ed47cb8SMatthew Barth // Return `AlwaysOff` when power restore policy set to "None" 12464ed47cb8SMatthew Barth {"xyz.openbmc_project.Control.Power.RestorePolicy.Policy.None", 12474ed47cb8SMatthew Barth "AlwaysOff"}}; 1248c6a620f2SGeorge Liu 12491e1e598dSJonathan Doman auto policyMapsIt = policyMaps.find(policy); 1250c6a620f2SGeorge Liu if (policyMapsIt == policyMaps.end()) 1251c6a620f2SGeorge Liu { 1252c6a620f2SGeorge Liu messages::internalError(aResp->res); 1253c6a620f2SGeorge Liu return; 1254c6a620f2SGeorge Liu } 1255c6a620f2SGeorge Liu 1256c6a620f2SGeorge Liu aResp->res.jsonValue["PowerRestorePolicy"] = policyMapsIt->second; 12571e1e598dSJonathan Doman }); 1258c6a620f2SGeorge Liu } 1259c6a620f2SGeorge Liu 1260c6a620f2SGeorge Liu /** 12611981771bSAli Ahmed * @brief Get TrustedModuleRequiredToBoot property. Determines whether or not 12621981771bSAli Ahmed * TPM is required for booting the host. 12631981771bSAli Ahmed * 12641981771bSAli Ahmed * @param[in] aResp Shared pointer for generating response message. 12651981771bSAli Ahmed * 12661981771bSAli Ahmed * @return None. 12671981771bSAli Ahmed */ 12681981771bSAli Ahmed inline void getTrustedModuleRequiredToBoot( 12691981771bSAli Ahmed const std::shared_ptr<bmcweb::AsyncResp>& aResp) 12701981771bSAli Ahmed { 12711981771bSAli Ahmed BMCWEB_LOG_DEBUG << "Get TPM required to boot."; 12721981771bSAli Ahmed 12731981771bSAli Ahmed crow::connections::systemBus->async_method_call( 1274b9d36b47SEd Tanous [aResp](const boost::system::error_code ec, 1275b9d36b47SEd Tanous const dbus::utility::MapperGetSubTreeResponse& subtree) { 12761981771bSAli Ahmed if (ec) 12771981771bSAli Ahmed { 1278002d39b4SEd Tanous BMCWEB_LOG_DEBUG << "DBUS response error on TPM.Policy GetSubTree" 1279002d39b4SEd Tanous << ec; 12801981771bSAli Ahmed // This is an optional D-Bus object so just return if 12811981771bSAli Ahmed // error occurs 12821981771bSAli Ahmed return; 12831981771bSAli Ahmed } 128426f6976fSEd Tanous if (subtree.empty()) 12851981771bSAli Ahmed { 12861981771bSAli Ahmed // As noted above, this is an optional interface so just return 12871981771bSAli Ahmed // if there is no instance found 12881981771bSAli Ahmed return; 12891981771bSAli Ahmed } 12901981771bSAli Ahmed 12911981771bSAli Ahmed /* When there is more than one TPMEnable object... */ 12921981771bSAli Ahmed if (subtree.size() > 1) 12931981771bSAli Ahmed { 12941981771bSAli Ahmed BMCWEB_LOG_DEBUG 12951981771bSAli Ahmed << "DBUS response has more than 1 TPM Enable object:" 12961981771bSAli Ahmed << subtree.size(); 12971981771bSAli Ahmed // Throw an internal Error and return 12981981771bSAli Ahmed messages::internalError(aResp->res); 12991981771bSAli Ahmed return; 13001981771bSAli Ahmed } 13011981771bSAli Ahmed 13021981771bSAli Ahmed // Make sure the Dbus response map has a service and objectPath 13031981771bSAli Ahmed // field 13041981771bSAli Ahmed if (subtree[0].first.empty() || subtree[0].second.size() != 1) 13051981771bSAli Ahmed { 13061981771bSAli Ahmed BMCWEB_LOG_DEBUG << "TPM.Policy mapper error!"; 13071981771bSAli Ahmed messages::internalError(aResp->res); 13081981771bSAli Ahmed return; 13091981771bSAli Ahmed } 13101981771bSAli Ahmed 13111981771bSAli Ahmed const std::string& path = subtree[0].first; 13121981771bSAli Ahmed const std::string& serv = subtree[0].second.begin()->first; 13131981771bSAli Ahmed 13141981771bSAli Ahmed // Valid TPM Enable object found, now reading the current value 13151e1e598dSJonathan Doman sdbusplus::asio::getProperty<bool>( 13161e1e598dSJonathan Doman *crow::connections::systemBus, serv, path, 13171e1e598dSJonathan Doman "xyz.openbmc_project.Control.TPM.Policy", "TPMEnable", 13188a592810SEd Tanous [aResp](const boost::system::error_code ec2, bool tpmRequired) { 13198a592810SEd Tanous if (ec2) 13201981771bSAli Ahmed { 1321002d39b4SEd Tanous BMCWEB_LOG_DEBUG << "D-BUS response error on TPM.Policy Get" 13228a592810SEd Tanous << ec2; 13231981771bSAli Ahmed messages::internalError(aResp->res); 13241981771bSAli Ahmed return; 13251981771bSAli Ahmed } 13261981771bSAli Ahmed 13271e1e598dSJonathan Doman if (tpmRequired) 13281981771bSAli Ahmed { 1329002d39b4SEd Tanous aResp->res.jsonValue["Boot"]["TrustedModuleRequiredToBoot"] = 13301981771bSAli Ahmed "Required"; 13311981771bSAli Ahmed } 13321981771bSAli Ahmed else 13331981771bSAli Ahmed { 1334002d39b4SEd Tanous aResp->res.jsonValue["Boot"]["TrustedModuleRequiredToBoot"] = 13351981771bSAli Ahmed "Disabled"; 13361981771bSAli Ahmed } 13371e1e598dSJonathan Doman }); 13381981771bSAli Ahmed }, 13391981771bSAli Ahmed "xyz.openbmc_project.ObjectMapper", 13401981771bSAli Ahmed "/xyz/openbmc_project/object_mapper", 13411981771bSAli Ahmed "xyz.openbmc_project.ObjectMapper", "GetSubTree", "/", int32_t(0), 13421981771bSAli Ahmed std::array<const char*, 1>{"xyz.openbmc_project.Control.TPM.Policy"}); 13431981771bSAli Ahmed } 13441981771bSAli Ahmed 13451981771bSAli Ahmed /** 13461c05dae3SAli Ahmed * @brief Set TrustedModuleRequiredToBoot property. Determines whether or not 13471c05dae3SAli Ahmed * TPM is required for booting the host. 13481c05dae3SAli Ahmed * 13491c05dae3SAli Ahmed * @param[in] aResp Shared pointer for generating response message. 13501c05dae3SAli Ahmed * @param[in] tpmRequired Value to set TPM Required To Boot property to. 13511c05dae3SAli Ahmed * 13521c05dae3SAli Ahmed * @return None. 13531c05dae3SAli Ahmed */ 13541c05dae3SAli Ahmed inline void setTrustedModuleRequiredToBoot( 13551c05dae3SAli Ahmed const std::shared_ptr<bmcweb::AsyncResp>& aResp, const bool tpmRequired) 13561c05dae3SAli Ahmed { 13571c05dae3SAli Ahmed BMCWEB_LOG_DEBUG << "Set TrustedModuleRequiredToBoot."; 13581c05dae3SAli Ahmed 13591c05dae3SAli Ahmed crow::connections::systemBus->async_method_call( 1360b9d36b47SEd Tanous [aResp, tpmRequired](const boost::system::error_code ec, 1361b9d36b47SEd Tanous dbus::utility::MapperGetSubTreeResponse& subtree) { 13621c05dae3SAli Ahmed if (ec) 13631c05dae3SAli Ahmed { 1364002d39b4SEd Tanous BMCWEB_LOG_DEBUG << "DBUS response error on TPM.Policy GetSubTree" 1365002d39b4SEd Tanous << ec; 13661c05dae3SAli Ahmed messages::internalError(aResp->res); 13671c05dae3SAli Ahmed return; 13681c05dae3SAli Ahmed } 136926f6976fSEd Tanous if (subtree.empty()) 13701c05dae3SAli Ahmed { 13711c05dae3SAli Ahmed messages::propertyValueNotInList(aResp->res, "ComputerSystem", 13721c05dae3SAli Ahmed "TrustedModuleRequiredToBoot"); 13731c05dae3SAli Ahmed return; 13741c05dae3SAli Ahmed } 13751c05dae3SAli Ahmed 13761c05dae3SAli Ahmed /* When there is more than one TPMEnable object... */ 13771c05dae3SAli Ahmed if (subtree.size() > 1) 13781c05dae3SAli Ahmed { 13791c05dae3SAli Ahmed BMCWEB_LOG_DEBUG 13801c05dae3SAli Ahmed << "DBUS response has more than 1 TPM Enable object:" 13811c05dae3SAli Ahmed << subtree.size(); 13821c05dae3SAli Ahmed // Throw an internal Error and return 13831c05dae3SAli Ahmed messages::internalError(aResp->res); 13841c05dae3SAli Ahmed return; 13851c05dae3SAli Ahmed } 13861c05dae3SAli Ahmed 13871c05dae3SAli Ahmed // Make sure the Dbus response map has a service and objectPath 13881c05dae3SAli Ahmed // field 13891c05dae3SAli Ahmed if (subtree[0].first.empty() || subtree[0].second.size() != 1) 13901c05dae3SAli Ahmed { 13911c05dae3SAli Ahmed BMCWEB_LOG_DEBUG << "TPM.Policy mapper error!"; 13921c05dae3SAli Ahmed messages::internalError(aResp->res); 13931c05dae3SAli Ahmed return; 13941c05dae3SAli Ahmed } 13951c05dae3SAli Ahmed 13961c05dae3SAli Ahmed const std::string& path = subtree[0].first; 13971c05dae3SAli Ahmed const std::string& serv = subtree[0].second.begin()->first; 13981c05dae3SAli Ahmed 13991c05dae3SAli Ahmed if (serv.empty()) 14001c05dae3SAli Ahmed { 14011c05dae3SAli Ahmed BMCWEB_LOG_DEBUG << "TPM.Policy service mapper error!"; 14021c05dae3SAli Ahmed messages::internalError(aResp->res); 14031c05dae3SAli Ahmed return; 14041c05dae3SAli Ahmed } 14051c05dae3SAli Ahmed 14061c05dae3SAli Ahmed // Valid TPM Enable object found, now setting the value 14071c05dae3SAli Ahmed crow::connections::systemBus->async_method_call( 14088a592810SEd Tanous [aResp](const boost::system::error_code ec2) { 14098a592810SEd Tanous if (ec2) 14101c05dae3SAli Ahmed { 14110fda0f12SGeorge Liu BMCWEB_LOG_DEBUG 14120fda0f12SGeorge Liu << "DBUS response error: Set TrustedModuleRequiredToBoot" 14138a592810SEd Tanous << ec2; 14141c05dae3SAli Ahmed messages::internalError(aResp->res); 14151c05dae3SAli Ahmed return; 14161c05dae3SAli Ahmed } 14171c05dae3SAli Ahmed BMCWEB_LOG_DEBUG << "Set TrustedModuleRequiredToBoot done."; 14181c05dae3SAli Ahmed }, 14191c05dae3SAli Ahmed serv, path, "org.freedesktop.DBus.Properties", "Set", 14201c05dae3SAli Ahmed "xyz.openbmc_project.Control.TPM.Policy", "TPMEnable", 1421168e20c1SEd Tanous dbus::utility::DbusVariantType(tpmRequired)); 14221c05dae3SAli Ahmed }, 14231c05dae3SAli Ahmed "xyz.openbmc_project.ObjectMapper", 14241c05dae3SAli Ahmed "/xyz/openbmc_project/object_mapper", 14251c05dae3SAli Ahmed "xyz.openbmc_project.ObjectMapper", "GetSubTree", "/", int32_t(0), 14261c05dae3SAli Ahmed std::array<const char*, 1>{"xyz.openbmc_project.Control.TPM.Policy"}); 14271c05dae3SAli Ahmed } 14281c05dae3SAli Ahmed 14291c05dae3SAli Ahmed /** 1430491d8ee7SSantosh Puranik * @brief Sets boot properties into DBUS object(s). 1431491d8ee7SSantosh Puranik * 1432491d8ee7SSantosh Puranik * @param[in] aResp Shared pointer for generating response message. 1433cd9a4666SKonstantin Aladyshev * @param[in] bootType The boot type to set. 1434cd9a4666SKonstantin Aladyshev * @return Integer error code. 1435cd9a4666SKonstantin Aladyshev */ 1436cd9a4666SKonstantin Aladyshev inline void setBootType(const std::shared_ptr<bmcweb::AsyncResp>& aResp, 1437cd9a4666SKonstantin Aladyshev const std::optional<std::string>& bootType) 1438cd9a4666SKonstantin Aladyshev { 1439c21865c4SKonstantin Aladyshev std::string bootTypeStr; 1440cd9a4666SKonstantin Aladyshev 1441c21865c4SKonstantin Aladyshev if (!bootType) 1442cd9a4666SKonstantin Aladyshev { 1443c21865c4SKonstantin Aladyshev return; 1444c21865c4SKonstantin Aladyshev } 1445c21865c4SKonstantin Aladyshev 1446cd9a4666SKonstantin Aladyshev // Source target specified 1447cd9a4666SKonstantin Aladyshev BMCWEB_LOG_DEBUG << "Boot type: " << *bootType; 1448cd9a4666SKonstantin Aladyshev // Figure out which DBUS interface and property to use 1449cd9a4666SKonstantin Aladyshev if (*bootType == "Legacy") 1450cd9a4666SKonstantin Aladyshev { 1451cd9a4666SKonstantin Aladyshev bootTypeStr = "xyz.openbmc_project.Control.Boot.Type.Types.Legacy"; 1452cd9a4666SKonstantin Aladyshev } 1453cd9a4666SKonstantin Aladyshev else if (*bootType == "UEFI") 1454cd9a4666SKonstantin Aladyshev { 1455cd9a4666SKonstantin Aladyshev bootTypeStr = "xyz.openbmc_project.Control.Boot.Type.Types.EFI"; 1456cd9a4666SKonstantin Aladyshev } 1457cd9a4666SKonstantin Aladyshev else 1458cd9a4666SKonstantin Aladyshev { 1459cd9a4666SKonstantin Aladyshev BMCWEB_LOG_DEBUG << "Invalid property value for " 1460cd9a4666SKonstantin Aladyshev "BootSourceOverrideMode: " 1461cd9a4666SKonstantin Aladyshev << *bootType; 1462cd9a4666SKonstantin Aladyshev messages::propertyValueNotInList(aResp->res, *bootType, 1463cd9a4666SKonstantin Aladyshev "BootSourceOverrideMode"); 1464cd9a4666SKonstantin Aladyshev return; 1465cd9a4666SKonstantin Aladyshev } 1466cd9a4666SKonstantin Aladyshev 1467cd9a4666SKonstantin Aladyshev // Act on validated parameters 1468cd9a4666SKonstantin Aladyshev BMCWEB_LOG_DEBUG << "DBUS boot type: " << bootTypeStr; 1469cd9a4666SKonstantin Aladyshev 1470cd9a4666SKonstantin Aladyshev crow::connections::systemBus->async_method_call( 1471c21865c4SKonstantin Aladyshev [aResp](const boost::system::error_code ec) { 1472cd9a4666SKonstantin Aladyshev if (ec) 1473cd9a4666SKonstantin Aladyshev { 1474cd9a4666SKonstantin Aladyshev BMCWEB_LOG_DEBUG << "DBUS response error " << ec; 1475cd9a4666SKonstantin Aladyshev if (ec.value() == boost::asio::error::host_unreachable) 1476cd9a4666SKonstantin Aladyshev { 1477cd9a4666SKonstantin Aladyshev messages::resourceNotFound(aResp->res, "Set", "BootType"); 1478cd9a4666SKonstantin Aladyshev return; 1479cd9a4666SKonstantin Aladyshev } 1480cd9a4666SKonstantin Aladyshev messages::internalError(aResp->res); 1481cd9a4666SKonstantin Aladyshev return; 1482cd9a4666SKonstantin Aladyshev } 1483cd9a4666SKonstantin Aladyshev BMCWEB_LOG_DEBUG << "Boot type update done."; 1484cd9a4666SKonstantin Aladyshev }, 1485c21865c4SKonstantin Aladyshev "xyz.openbmc_project.Settings", 1486c21865c4SKonstantin Aladyshev "/xyz/openbmc_project/control/host0/boot", 1487cd9a4666SKonstantin Aladyshev "org.freedesktop.DBus.Properties", "Set", 1488cd9a4666SKonstantin Aladyshev "xyz.openbmc_project.Control.Boot.Type", "BootType", 1489168e20c1SEd Tanous dbus::utility::DbusVariantType(bootTypeStr)); 1490cd9a4666SKonstantin Aladyshev } 1491cd9a4666SKonstantin Aladyshev 1492cd9a4666SKonstantin Aladyshev /** 1493cd9a4666SKonstantin Aladyshev * @brief Sets boot properties into DBUS object(s). 1494cd9a4666SKonstantin Aladyshev * 1495cd9a4666SKonstantin Aladyshev * @param[in] aResp Shared pointer for generating response message. 1496c21865c4SKonstantin Aladyshev * @param[in] bootType The boot type to set. 1497c21865c4SKonstantin Aladyshev * @return Integer error code. 1498c21865c4SKonstantin Aladyshev */ 1499c21865c4SKonstantin Aladyshev inline void setBootEnable(const std::shared_ptr<bmcweb::AsyncResp>& aResp, 1500c21865c4SKonstantin Aladyshev const std::optional<std::string>& bootEnable) 1501c21865c4SKonstantin Aladyshev { 1502c21865c4SKonstantin Aladyshev if (!bootEnable) 1503c21865c4SKonstantin Aladyshev { 1504c21865c4SKonstantin Aladyshev return; 1505c21865c4SKonstantin Aladyshev } 1506c21865c4SKonstantin Aladyshev // Source target specified 1507c21865c4SKonstantin Aladyshev BMCWEB_LOG_DEBUG << "Boot enable: " << *bootEnable; 1508c21865c4SKonstantin Aladyshev 1509c21865c4SKonstantin Aladyshev bool bootOverrideEnable = false; 1510c21865c4SKonstantin Aladyshev bool bootOverridePersistent = false; 1511c21865c4SKonstantin Aladyshev // Figure out which DBUS interface and property to use 1512c21865c4SKonstantin Aladyshev if (*bootEnable == "Disabled") 1513c21865c4SKonstantin Aladyshev { 1514c21865c4SKonstantin Aladyshev bootOverrideEnable = false; 1515c21865c4SKonstantin Aladyshev } 1516c21865c4SKonstantin Aladyshev else if (*bootEnable == "Once") 1517c21865c4SKonstantin Aladyshev { 1518c21865c4SKonstantin Aladyshev bootOverrideEnable = true; 1519c21865c4SKonstantin Aladyshev bootOverridePersistent = false; 1520c21865c4SKonstantin Aladyshev } 1521c21865c4SKonstantin Aladyshev else if (*bootEnable == "Continuous") 1522c21865c4SKonstantin Aladyshev { 1523c21865c4SKonstantin Aladyshev bootOverrideEnable = true; 1524c21865c4SKonstantin Aladyshev bootOverridePersistent = true; 1525c21865c4SKonstantin Aladyshev } 1526c21865c4SKonstantin Aladyshev else 1527c21865c4SKonstantin Aladyshev { 15280fda0f12SGeorge Liu BMCWEB_LOG_DEBUG 15290fda0f12SGeorge Liu << "Invalid property value for BootSourceOverrideEnabled: " 1530c21865c4SKonstantin Aladyshev << *bootEnable; 1531c21865c4SKonstantin Aladyshev messages::propertyValueNotInList(aResp->res, *bootEnable, 1532c21865c4SKonstantin Aladyshev "BootSourceOverrideEnabled"); 1533c21865c4SKonstantin Aladyshev return; 1534c21865c4SKonstantin Aladyshev } 1535c21865c4SKonstantin Aladyshev 1536c21865c4SKonstantin Aladyshev // Act on validated parameters 1537c21865c4SKonstantin Aladyshev BMCWEB_LOG_DEBUG << "DBUS boot override enable: " << bootOverrideEnable; 1538c21865c4SKonstantin Aladyshev 1539c21865c4SKonstantin Aladyshev crow::connections::systemBus->async_method_call( 15408a592810SEd Tanous [aResp](const boost::system::error_code ec2) { 15418a592810SEd Tanous if (ec2) 1542c21865c4SKonstantin Aladyshev { 15438a592810SEd Tanous BMCWEB_LOG_DEBUG << "DBUS response error " << ec2; 1544c21865c4SKonstantin Aladyshev messages::internalError(aResp->res); 1545c21865c4SKonstantin Aladyshev return; 1546c21865c4SKonstantin Aladyshev } 1547c21865c4SKonstantin Aladyshev BMCWEB_LOG_DEBUG << "Boot override enable update done."; 1548c21865c4SKonstantin Aladyshev }, 1549c21865c4SKonstantin Aladyshev "xyz.openbmc_project.Settings", 1550c21865c4SKonstantin Aladyshev "/xyz/openbmc_project/control/host0/boot", 1551c21865c4SKonstantin Aladyshev "org.freedesktop.DBus.Properties", "Set", 1552c21865c4SKonstantin Aladyshev "xyz.openbmc_project.Object.Enable", "Enabled", 1553168e20c1SEd Tanous dbus::utility::DbusVariantType(bootOverrideEnable)); 1554c21865c4SKonstantin Aladyshev 1555c21865c4SKonstantin Aladyshev if (!bootOverrideEnable) 1556c21865c4SKonstantin Aladyshev { 1557c21865c4SKonstantin Aladyshev return; 1558c21865c4SKonstantin Aladyshev } 1559c21865c4SKonstantin Aladyshev 1560c21865c4SKonstantin Aladyshev // In case boot override is enabled we need to set correct value for the 1561c21865c4SKonstantin Aladyshev // 'one_time' enable DBus interface 1562c21865c4SKonstantin Aladyshev BMCWEB_LOG_DEBUG << "DBUS boot override persistent: " 1563c21865c4SKonstantin Aladyshev << bootOverridePersistent; 1564c21865c4SKonstantin Aladyshev 1565c21865c4SKonstantin Aladyshev crow::connections::systemBus->async_method_call( 1566c21865c4SKonstantin Aladyshev [aResp](const boost::system::error_code ec) { 1567c21865c4SKonstantin Aladyshev if (ec) 1568c21865c4SKonstantin Aladyshev { 1569c21865c4SKonstantin Aladyshev BMCWEB_LOG_DEBUG << "DBUS response error " << ec; 1570c21865c4SKonstantin Aladyshev messages::internalError(aResp->res); 1571c21865c4SKonstantin Aladyshev return; 1572c21865c4SKonstantin Aladyshev } 1573c21865c4SKonstantin Aladyshev BMCWEB_LOG_DEBUG << "Boot one_time update done."; 1574c21865c4SKonstantin Aladyshev }, 1575c21865c4SKonstantin Aladyshev "xyz.openbmc_project.Settings", 1576c21865c4SKonstantin Aladyshev "/xyz/openbmc_project/control/host0/boot/one_time", 1577c21865c4SKonstantin Aladyshev "org.freedesktop.DBus.Properties", "Set", 1578c21865c4SKonstantin Aladyshev "xyz.openbmc_project.Object.Enable", "Enabled", 1579168e20c1SEd Tanous dbus::utility::DbusVariantType(!bootOverridePersistent)); 1580c21865c4SKonstantin Aladyshev } 1581c21865c4SKonstantin Aladyshev 1582c21865c4SKonstantin Aladyshev /** 1583c21865c4SKonstantin Aladyshev * @brief Sets boot properties into DBUS object(s). 1584c21865c4SKonstantin Aladyshev * 1585c21865c4SKonstantin Aladyshev * @param[in] aResp Shared pointer for generating response message. 1586491d8ee7SSantosh Puranik * @param[in] bootSource The boot source to set. 1587491d8ee7SSantosh Puranik * 1588265c1602SJohnathan Mantey * @return Integer error code. 1589491d8ee7SSantosh Puranik */ 1590cd9a4666SKonstantin Aladyshev inline void setBootModeOrSource(const std::shared_ptr<bmcweb::AsyncResp>& aResp, 1591cd9a4666SKonstantin Aladyshev const std::optional<std::string>& bootSource) 1592491d8ee7SSantosh Puranik { 1593c21865c4SKonstantin Aladyshev std::string bootSourceStr; 1594c21865c4SKonstantin Aladyshev std::string bootModeStr; 1595944ffaf9SJohnathan Mantey 1596c21865c4SKonstantin Aladyshev if (!bootSource) 1597491d8ee7SSantosh Puranik { 1598c21865c4SKonstantin Aladyshev return; 1599c21865c4SKonstantin Aladyshev } 1600c21865c4SKonstantin Aladyshev 1601491d8ee7SSantosh Puranik // Source target specified 1602491d8ee7SSantosh Puranik BMCWEB_LOG_DEBUG << "Boot source: " << *bootSource; 1603491d8ee7SSantosh Puranik // Figure out which DBUS interface and property to use 1604e662eae8SEd Tanous if (assignBootParameters(aResp, *bootSource, bootSourceStr, bootModeStr) != 1605e662eae8SEd Tanous 0) 1606491d8ee7SSantosh Puranik { 1607944ffaf9SJohnathan Mantey BMCWEB_LOG_DEBUG 1608944ffaf9SJohnathan Mantey << "Invalid property value for BootSourceOverrideTarget: " 1609491d8ee7SSantosh Puranik << *bootSource; 1610491d8ee7SSantosh Puranik messages::propertyValueNotInList(aResp->res, *bootSource, 1611491d8ee7SSantosh Puranik "BootSourceTargetOverride"); 1612491d8ee7SSantosh Puranik return; 1613491d8ee7SSantosh Puranik } 1614491d8ee7SSantosh Puranik 1615944ffaf9SJohnathan Mantey // Act on validated parameters 1616944ffaf9SJohnathan Mantey BMCWEB_LOG_DEBUG << "DBUS boot source: " << bootSourceStr; 1617944ffaf9SJohnathan Mantey BMCWEB_LOG_DEBUG << "DBUS boot mode: " << bootModeStr; 1618944ffaf9SJohnathan Mantey 1619491d8ee7SSantosh Puranik crow::connections::systemBus->async_method_call( 1620491d8ee7SSantosh Puranik [aResp](const boost::system::error_code ec) { 1621491d8ee7SSantosh Puranik if (ec) 1622491d8ee7SSantosh Puranik { 1623491d8ee7SSantosh Puranik BMCWEB_LOG_DEBUG << "DBUS response error " << ec; 1624491d8ee7SSantosh Puranik messages::internalError(aResp->res); 1625491d8ee7SSantosh Puranik return; 1626491d8ee7SSantosh Puranik } 1627491d8ee7SSantosh Puranik BMCWEB_LOG_DEBUG << "Boot source update done."; 1628491d8ee7SSantosh Puranik }, 1629c21865c4SKonstantin Aladyshev "xyz.openbmc_project.Settings", 1630c21865c4SKonstantin Aladyshev "/xyz/openbmc_project/control/host0/boot", 1631491d8ee7SSantosh Puranik "org.freedesktop.DBus.Properties", "Set", 1632491d8ee7SSantosh Puranik "xyz.openbmc_project.Control.Boot.Source", "BootSource", 1633168e20c1SEd Tanous dbus::utility::DbusVariantType(bootSourceStr)); 1634944ffaf9SJohnathan Mantey 1635491d8ee7SSantosh Puranik crow::connections::systemBus->async_method_call( 1636491d8ee7SSantosh Puranik [aResp](const boost::system::error_code ec) { 1637491d8ee7SSantosh Puranik if (ec) 1638491d8ee7SSantosh Puranik { 1639491d8ee7SSantosh Puranik BMCWEB_LOG_DEBUG << "DBUS response error " << ec; 1640491d8ee7SSantosh Puranik messages::internalError(aResp->res); 1641491d8ee7SSantosh Puranik return; 1642491d8ee7SSantosh Puranik } 1643491d8ee7SSantosh Puranik BMCWEB_LOG_DEBUG << "Boot mode update done."; 1644491d8ee7SSantosh Puranik }, 1645c21865c4SKonstantin Aladyshev "xyz.openbmc_project.Settings", 1646c21865c4SKonstantin Aladyshev "/xyz/openbmc_project/control/host0/boot", 1647491d8ee7SSantosh Puranik "org.freedesktop.DBus.Properties", "Set", 1648491d8ee7SSantosh Puranik "xyz.openbmc_project.Control.Boot.Mode", "BootMode", 1649168e20c1SEd Tanous dbus::utility::DbusVariantType(bootModeStr)); 1650cd9a4666SKonstantin Aladyshev } 1651944ffaf9SJohnathan Mantey 1652cd9a4666SKonstantin Aladyshev /** 1653c21865c4SKonstantin Aladyshev * @brief Sets Boot source override properties. 1654491d8ee7SSantosh Puranik * 1655491d8ee7SSantosh Puranik * @param[in] aResp Shared pointer for generating response message. 1656491d8ee7SSantosh Puranik * @param[in] bootSource The boot source from incoming RF request. 1657cd9a4666SKonstantin Aladyshev * @param[in] bootType The boot type from incoming RF request. 1658491d8ee7SSantosh Puranik * @param[in] bootEnable The boot override enable from incoming RF request. 1659491d8ee7SSantosh Puranik * 1660265c1602SJohnathan Mantey * @return Integer error code. 1661491d8ee7SSantosh Puranik */ 1662c21865c4SKonstantin Aladyshev 1663c21865c4SKonstantin Aladyshev inline void setBootProperties(const std::shared_ptr<bmcweb::AsyncResp>& aResp, 1664c21865c4SKonstantin Aladyshev const std::optional<std::string>& bootSource, 1665c21865c4SKonstantin Aladyshev const std::optional<std::string>& bootType, 1666c21865c4SKonstantin Aladyshev const std::optional<std::string>& bootEnable) 1667491d8ee7SSantosh Puranik { 1668491d8ee7SSantosh Puranik BMCWEB_LOG_DEBUG << "Set boot information."; 1669491d8ee7SSantosh Puranik 1670c21865c4SKonstantin Aladyshev setBootModeOrSource(aResp, bootSource); 1671c21865c4SKonstantin Aladyshev setBootType(aResp, bootType); 1672c21865c4SKonstantin Aladyshev setBootEnable(aResp, bootEnable); 1673491d8ee7SSantosh Puranik } 1674491d8ee7SSantosh Puranik 1675c6a620f2SGeorge Liu /** 167698e386ecSGunnar Mills * @brief Sets AssetTag 167798e386ecSGunnar Mills * 167898e386ecSGunnar Mills * @param[in] aResp Shared pointer for generating response message. 167998e386ecSGunnar Mills * @param[in] assetTag "AssetTag" from request. 168098e386ecSGunnar Mills * 168198e386ecSGunnar Mills * @return None. 168298e386ecSGunnar Mills */ 16838d1b46d7Szhanghch05 inline void setAssetTag(const std::shared_ptr<bmcweb::AsyncResp>& aResp, 168498e386ecSGunnar Mills const std::string& assetTag) 168598e386ecSGunnar Mills { 168698e386ecSGunnar Mills crow::connections::systemBus->async_method_call( 1687b9d36b47SEd Tanous [aResp, 1688b9d36b47SEd Tanous assetTag](const boost::system::error_code ec, 1689b9d36b47SEd Tanous const dbus::utility::MapperGetSubTreeResponse& subtree) { 169098e386ecSGunnar Mills if (ec) 169198e386ecSGunnar Mills { 169298e386ecSGunnar Mills BMCWEB_LOG_DEBUG << "D-Bus response error on GetSubTree " << ec; 169398e386ecSGunnar Mills messages::internalError(aResp->res); 169498e386ecSGunnar Mills return; 169598e386ecSGunnar Mills } 169626f6976fSEd Tanous if (subtree.empty()) 169798e386ecSGunnar Mills { 169898e386ecSGunnar Mills BMCWEB_LOG_DEBUG << "Can't find system D-Bus object!"; 169998e386ecSGunnar Mills messages::internalError(aResp->res); 170098e386ecSGunnar Mills return; 170198e386ecSGunnar Mills } 170298e386ecSGunnar Mills // Assume only 1 system D-Bus object 170398e386ecSGunnar Mills // Throw an error if there is more than 1 170498e386ecSGunnar Mills if (subtree.size() > 1) 170598e386ecSGunnar Mills { 170698e386ecSGunnar Mills BMCWEB_LOG_DEBUG << "Found more than 1 system D-Bus object!"; 170798e386ecSGunnar Mills messages::internalError(aResp->res); 170898e386ecSGunnar Mills return; 170998e386ecSGunnar Mills } 171098e386ecSGunnar Mills if (subtree[0].first.empty() || subtree[0].second.size() != 1) 171198e386ecSGunnar Mills { 171298e386ecSGunnar Mills BMCWEB_LOG_DEBUG << "Asset Tag Set mapper error!"; 171398e386ecSGunnar Mills messages::internalError(aResp->res); 171498e386ecSGunnar Mills return; 171598e386ecSGunnar Mills } 171698e386ecSGunnar Mills 171798e386ecSGunnar Mills const std::string& path = subtree[0].first; 171898e386ecSGunnar Mills const std::string& service = subtree[0].second.begin()->first; 171998e386ecSGunnar Mills 172098e386ecSGunnar Mills if (service.empty()) 172198e386ecSGunnar Mills { 172298e386ecSGunnar Mills BMCWEB_LOG_DEBUG << "Asset Tag Set service mapper error!"; 172398e386ecSGunnar Mills messages::internalError(aResp->res); 172498e386ecSGunnar Mills return; 172598e386ecSGunnar Mills } 172698e386ecSGunnar Mills 172798e386ecSGunnar Mills crow::connections::systemBus->async_method_call( 172898e386ecSGunnar Mills [aResp](const boost::system::error_code ec2) { 172998e386ecSGunnar Mills if (ec2) 173098e386ecSGunnar Mills { 1731002d39b4SEd Tanous BMCWEB_LOG_DEBUG << "D-Bus response error on AssetTag Set " 1732002d39b4SEd Tanous << ec2; 173398e386ecSGunnar Mills messages::internalError(aResp->res); 173498e386ecSGunnar Mills return; 173598e386ecSGunnar Mills } 173698e386ecSGunnar Mills }, 173798e386ecSGunnar Mills service, path, "org.freedesktop.DBus.Properties", "Set", 173898e386ecSGunnar Mills "xyz.openbmc_project.Inventory.Decorator.AssetTag", "AssetTag", 1739168e20c1SEd Tanous dbus::utility::DbusVariantType(assetTag)); 174098e386ecSGunnar Mills }, 174198e386ecSGunnar Mills "xyz.openbmc_project.ObjectMapper", 174298e386ecSGunnar Mills "/xyz/openbmc_project/object_mapper", 174398e386ecSGunnar Mills "xyz.openbmc_project.ObjectMapper", "GetSubTree", 174498e386ecSGunnar Mills "/xyz/openbmc_project/inventory", int32_t(0), 174598e386ecSGunnar Mills std::array<const char*, 1>{ 174698e386ecSGunnar Mills "xyz.openbmc_project.Inventory.Item.System"}); 174798e386ecSGunnar Mills } 174898e386ecSGunnar Mills 174998e386ecSGunnar Mills /** 175069f35306SGunnar Mills * @brief Sets automaticRetry (Auto Reboot) 175169f35306SGunnar Mills * 175269f35306SGunnar Mills * @param[in] aResp Shared pointer for generating response message. 175369f35306SGunnar Mills * @param[in] automaticRetryConfig "AutomaticRetryConfig" from request. 175469f35306SGunnar Mills * 175569f35306SGunnar Mills * @return None. 175669f35306SGunnar Mills */ 17578d1b46d7Szhanghch05 inline void setAutomaticRetry(const std::shared_ptr<bmcweb::AsyncResp>& aResp, 1758f23b7296SEd Tanous const std::string& automaticRetryConfig) 175969f35306SGunnar Mills { 176069f35306SGunnar Mills BMCWEB_LOG_DEBUG << "Set Automatic Retry."; 176169f35306SGunnar Mills 176269f35306SGunnar Mills // OpenBMC only supports "Disabled" and "RetryAttempts". 1763543f4400SEd Tanous bool autoRebootEnabled = false; 176469f35306SGunnar Mills 176569f35306SGunnar Mills if (automaticRetryConfig == "Disabled") 176669f35306SGunnar Mills { 176769f35306SGunnar Mills autoRebootEnabled = false; 176869f35306SGunnar Mills } 176969f35306SGunnar Mills else if (automaticRetryConfig == "RetryAttempts") 177069f35306SGunnar Mills { 177169f35306SGunnar Mills autoRebootEnabled = true; 177269f35306SGunnar Mills } 177369f35306SGunnar Mills else 177469f35306SGunnar Mills { 17750fda0f12SGeorge Liu BMCWEB_LOG_DEBUG << "Invalid property value for AutomaticRetryConfig: " 177669f35306SGunnar Mills << automaticRetryConfig; 177769f35306SGunnar Mills messages::propertyValueNotInList(aResp->res, automaticRetryConfig, 177869f35306SGunnar Mills "AutomaticRetryConfig"); 177969f35306SGunnar Mills return; 178069f35306SGunnar Mills } 178169f35306SGunnar Mills 178269f35306SGunnar Mills crow::connections::systemBus->async_method_call( 178369f35306SGunnar Mills [aResp](const boost::system::error_code ec) { 178469f35306SGunnar Mills if (ec) 178569f35306SGunnar Mills { 178669f35306SGunnar Mills messages::internalError(aResp->res); 178769f35306SGunnar Mills return; 178869f35306SGunnar Mills } 178969f35306SGunnar Mills }, 179069f35306SGunnar Mills "xyz.openbmc_project.Settings", 179169f35306SGunnar Mills "/xyz/openbmc_project/control/host0/auto_reboot", 179269f35306SGunnar Mills "org.freedesktop.DBus.Properties", "Set", 179369f35306SGunnar Mills "xyz.openbmc_project.Control.Boot.RebootPolicy", "AutoReboot", 1794168e20c1SEd Tanous dbus::utility::DbusVariantType(autoRebootEnabled)); 179569f35306SGunnar Mills } 179669f35306SGunnar Mills 179769f35306SGunnar Mills /** 1798c6a620f2SGeorge Liu * @brief Sets power restore policy properties. 1799c6a620f2SGeorge Liu * 1800c6a620f2SGeorge Liu * @param[in] aResp Shared pointer for generating response message. 1801c6a620f2SGeorge Liu * @param[in] policy power restore policy properties from request. 1802c6a620f2SGeorge Liu * 1803c6a620f2SGeorge Liu * @return None. 1804c6a620f2SGeorge Liu */ 18058d1b46d7Szhanghch05 inline void 18068d1b46d7Szhanghch05 setPowerRestorePolicy(const std::shared_ptr<bmcweb::AsyncResp>& aResp, 18074e69c904SGunnar Mills const std::string& policy) 1808c6a620f2SGeorge Liu { 1809c6a620f2SGeorge Liu BMCWEB_LOG_DEBUG << "Set power restore policy."; 1810c6a620f2SGeorge Liu 1811c6a620f2SGeorge Liu const boost::container::flat_map<std::string, std::string> policyMaps = { 18120fda0f12SGeorge Liu {"AlwaysOn", 18130fda0f12SGeorge Liu "xyz.openbmc_project.Control.Power.RestorePolicy.Policy.AlwaysOn"}, 18140fda0f12SGeorge Liu {"AlwaysOff", 18150fda0f12SGeorge Liu "xyz.openbmc_project.Control.Power.RestorePolicy.Policy.AlwaysOff"}, 18160fda0f12SGeorge Liu {"LastState", 18170fda0f12SGeorge Liu "xyz.openbmc_project.Control.Power.RestorePolicy.Policy.Restore"}}; 1818c6a620f2SGeorge Liu 1819c6a620f2SGeorge Liu std::string powerRestorPolicy; 1820c6a620f2SGeorge Liu 18214e69c904SGunnar Mills auto policyMapsIt = policyMaps.find(policy); 1822c6a620f2SGeorge Liu if (policyMapsIt == policyMaps.end()) 1823c6a620f2SGeorge Liu { 18244e69c904SGunnar Mills messages::propertyValueNotInList(aResp->res, policy, 18254e69c904SGunnar Mills "PowerRestorePolicy"); 1826c6a620f2SGeorge Liu return; 1827c6a620f2SGeorge Liu } 1828c6a620f2SGeorge Liu 1829c6a620f2SGeorge Liu powerRestorPolicy = policyMapsIt->second; 1830c6a620f2SGeorge Liu 1831c6a620f2SGeorge Liu crow::connections::systemBus->async_method_call( 1832c6a620f2SGeorge Liu [aResp](const boost::system::error_code ec) { 1833c6a620f2SGeorge Liu if (ec) 1834c6a620f2SGeorge Liu { 1835c6a620f2SGeorge Liu messages::internalError(aResp->res); 1836c6a620f2SGeorge Liu return; 1837c6a620f2SGeorge Liu } 1838c6a620f2SGeorge Liu }, 1839c6a620f2SGeorge Liu "xyz.openbmc_project.Settings", 1840c6a620f2SGeorge Liu "/xyz/openbmc_project/control/host0/power_restore_policy", 1841c6a620f2SGeorge Liu "org.freedesktop.DBus.Properties", "Set", 1842c6a620f2SGeorge Liu "xyz.openbmc_project.Control.Power.RestorePolicy", "PowerRestorePolicy", 1843168e20c1SEd Tanous dbus::utility::DbusVariantType(powerRestorPolicy)); 1844c6a620f2SGeorge Liu } 1845c6a620f2SGeorge Liu 1846a6349918SAppaRao Puli #ifdef BMCWEB_ENABLE_REDFISH_PROVISIONING_FEATURE 1847a6349918SAppaRao Puli /** 1848a6349918SAppaRao Puli * @brief Retrieves provisioning status 1849a6349918SAppaRao Puli * 1850a6349918SAppaRao Puli * @param[in] aResp Shared pointer for completing asynchronous calls. 1851a6349918SAppaRao Puli * 1852a6349918SAppaRao Puli * @return None. 1853a6349918SAppaRao Puli */ 18548d1b46d7Szhanghch05 inline void getProvisioningStatus(std::shared_ptr<bmcweb::AsyncResp> aResp) 1855a6349918SAppaRao Puli { 1856a6349918SAppaRao Puli BMCWEB_LOG_DEBUG << "Get OEM information."; 1857bc1d29deSKrzysztof Grobelny sdbusplus::asio::getAllProperties( 1858bc1d29deSKrzysztof Grobelny *crow::connections::systemBus, "xyz.openbmc_project.PFR.Manager", 1859bc1d29deSKrzysztof Grobelny "/xyz/openbmc_project/pfr", "xyz.openbmc_project.PFR.Attributes", 1860a6349918SAppaRao Puli [aResp](const boost::system::error_code ec, 1861b9d36b47SEd Tanous const dbus::utility::DBusPropertiesMap& propertiesList) { 1862b99fb1a9SAppaRao Puli nlohmann::json& oemPFR = 1863b99fb1a9SAppaRao Puli aResp->res.jsonValue["Oem"]["OpenBmc"]["FirmwareProvisioning"]; 186450626f4fSJames Feist aResp->res.jsonValue["Oem"]["OpenBmc"]["@odata.type"] = 186550626f4fSJames Feist "#OemComputerSystem.OpenBmc"; 186650626f4fSJames Feist oemPFR["@odata.type"] = "#OemComputerSystem.FirmwareProvisioning"; 186750626f4fSJames Feist 1868a6349918SAppaRao Puli if (ec) 1869a6349918SAppaRao Puli { 1870a6349918SAppaRao Puli BMCWEB_LOG_DEBUG << "DBUS response error " << ec; 1871b99fb1a9SAppaRao Puli // not an error, don't have to have the interface 1872b99fb1a9SAppaRao Puli oemPFR["ProvisioningStatus"] = "NotProvisioned"; 1873a6349918SAppaRao Puli return; 1874a6349918SAppaRao Puli } 1875a6349918SAppaRao Puli 1876a6349918SAppaRao Puli const bool* provState = nullptr; 1877a6349918SAppaRao Puli const bool* lockState = nullptr; 1878bc1d29deSKrzysztof Grobelny 1879bc1d29deSKrzysztof Grobelny const bool success = sdbusplus::unpackPropertiesNoThrow( 18800d4befa8SJiaqing Zhao dbus_utils::UnpackErrorPrinter(), propertiesList, "UfmProvisioned", 18810d4befa8SJiaqing Zhao provState, "UfmLocked", lockState); 1882bc1d29deSKrzysztof Grobelny 1883bc1d29deSKrzysztof Grobelny if (!success) 1884a6349918SAppaRao Puli { 1885bc1d29deSKrzysztof Grobelny messages::internalError(aResp->res); 1886bc1d29deSKrzysztof Grobelny return; 1887a6349918SAppaRao Puli } 1888a6349918SAppaRao Puli 1889a6349918SAppaRao Puli if ((provState == nullptr) || (lockState == nullptr)) 1890a6349918SAppaRao Puli { 1891a6349918SAppaRao Puli BMCWEB_LOG_DEBUG << "Unable to get PFR attributes."; 1892a6349918SAppaRao Puli messages::internalError(aResp->res); 1893a6349918SAppaRao Puli return; 1894a6349918SAppaRao Puli } 1895a6349918SAppaRao Puli 1896a6349918SAppaRao Puli if (*provState == true) 1897a6349918SAppaRao Puli { 1898a6349918SAppaRao Puli if (*lockState == true) 1899a6349918SAppaRao Puli { 1900a6349918SAppaRao Puli oemPFR["ProvisioningStatus"] = "ProvisionedAndLocked"; 1901a6349918SAppaRao Puli } 1902a6349918SAppaRao Puli else 1903a6349918SAppaRao Puli { 1904a6349918SAppaRao Puli oemPFR["ProvisioningStatus"] = "ProvisionedButNotLocked"; 1905a6349918SAppaRao Puli } 1906a6349918SAppaRao Puli } 1907a6349918SAppaRao Puli else 1908a6349918SAppaRao Puli { 1909a6349918SAppaRao Puli oemPFR["ProvisioningStatus"] = "NotProvisioned"; 1910a6349918SAppaRao Puli } 1911bc1d29deSKrzysztof Grobelny }); 1912a6349918SAppaRao Puli } 1913a6349918SAppaRao Puli #endif 1914a6349918SAppaRao Puli 1915491d8ee7SSantosh Puranik /** 19163a2d0424SChris Cain * @brief Translate the PowerMode to a response message. 19173a2d0424SChris Cain * 19183a2d0424SChris Cain * @param[in] aResp Shared pointer for generating response message. 19193a2d0424SChris Cain * @param[in] modeValue PowerMode value to be translated 19203a2d0424SChris Cain * 19213a2d0424SChris Cain * @return None. 19223a2d0424SChris Cain */ 19233a2d0424SChris Cain inline void translatePowerMode(const std::shared_ptr<bmcweb::AsyncResp>& aResp, 19243a2d0424SChris Cain const std::string& modeValue) 19253a2d0424SChris Cain { 19260fda0f12SGeorge Liu if (modeValue == "xyz.openbmc_project.Control.Power.Mode.PowerMode.Static") 19273a2d0424SChris Cain { 19283a2d0424SChris Cain aResp->res.jsonValue["PowerMode"] = "Static"; 19293a2d0424SChris Cain } 19300fda0f12SGeorge Liu else if ( 19310fda0f12SGeorge Liu modeValue == 19320fda0f12SGeorge Liu "xyz.openbmc_project.Control.Power.Mode.PowerMode.MaximumPerformance") 19333a2d0424SChris Cain { 19343a2d0424SChris Cain aResp->res.jsonValue["PowerMode"] = "MaximumPerformance"; 19353a2d0424SChris Cain } 19360fda0f12SGeorge Liu else if (modeValue == 19370fda0f12SGeorge Liu "xyz.openbmc_project.Control.Power.Mode.PowerMode.PowerSaving") 19383a2d0424SChris Cain { 19393a2d0424SChris Cain aResp->res.jsonValue["PowerMode"] = "PowerSaving"; 19403a2d0424SChris Cain } 19410fda0f12SGeorge Liu else if (modeValue == 19420fda0f12SGeorge Liu "xyz.openbmc_project.Control.Power.Mode.PowerMode.OEM") 19433a2d0424SChris Cain { 19443a2d0424SChris Cain aResp->res.jsonValue["PowerMode"] = "OEM"; 19453a2d0424SChris Cain } 19463a2d0424SChris Cain else 19473a2d0424SChris Cain { 19483a2d0424SChris Cain // Any other values would be invalid 19493a2d0424SChris Cain BMCWEB_LOG_DEBUG << "PowerMode value was not valid: " << modeValue; 19503a2d0424SChris Cain messages::internalError(aResp->res); 19513a2d0424SChris Cain } 19523a2d0424SChris Cain } 19533a2d0424SChris Cain 19543a2d0424SChris Cain /** 19553a2d0424SChris Cain * @brief Retrieves system power mode 19563a2d0424SChris Cain * 19573a2d0424SChris Cain * @param[in] aResp Shared pointer for generating response message. 19583a2d0424SChris Cain * 19593a2d0424SChris Cain * @return None. 19603a2d0424SChris Cain */ 19613a2d0424SChris Cain inline void getPowerMode(const std::shared_ptr<bmcweb::AsyncResp>& aResp) 19623a2d0424SChris Cain { 19633a2d0424SChris Cain BMCWEB_LOG_DEBUG << "Get power mode."; 19643a2d0424SChris Cain 19653a2d0424SChris Cain // Get Power Mode object path: 19663a2d0424SChris Cain crow::connections::systemBus->async_method_call( 1967b9d36b47SEd Tanous [aResp](const boost::system::error_code ec, 1968b9d36b47SEd Tanous const dbus::utility::MapperGetSubTreeResponse& subtree) { 19693a2d0424SChris Cain if (ec) 19703a2d0424SChris Cain { 1971002d39b4SEd Tanous BMCWEB_LOG_DEBUG << "DBUS response error on Power.Mode GetSubTree " 1972002d39b4SEd Tanous << ec; 19733a2d0424SChris Cain // This is an optional D-Bus object so just return if 19743a2d0424SChris Cain // error occurs 19753a2d0424SChris Cain return; 19763a2d0424SChris Cain } 19773a2d0424SChris Cain if (subtree.empty()) 19783a2d0424SChris Cain { 19793a2d0424SChris Cain // As noted above, this is an optional interface so just return 19803a2d0424SChris Cain // if there is no instance found 19813a2d0424SChris Cain return; 19823a2d0424SChris Cain } 19833a2d0424SChris Cain if (subtree.size() > 1) 19843a2d0424SChris Cain { 19853a2d0424SChris Cain // More then one PowerMode object is not supported and is an 19863a2d0424SChris Cain // error 19873a2d0424SChris Cain BMCWEB_LOG_DEBUG 19883a2d0424SChris Cain << "Found more than 1 system D-Bus Power.Mode objects: " 19893a2d0424SChris Cain << subtree.size(); 19903a2d0424SChris Cain messages::internalError(aResp->res); 19913a2d0424SChris Cain return; 19923a2d0424SChris Cain } 19933a2d0424SChris Cain if ((subtree[0].first.empty()) || (subtree[0].second.size() != 1)) 19943a2d0424SChris Cain { 19953a2d0424SChris Cain BMCWEB_LOG_DEBUG << "Power.Mode mapper error!"; 19963a2d0424SChris Cain messages::internalError(aResp->res); 19973a2d0424SChris Cain return; 19983a2d0424SChris Cain } 19993a2d0424SChris Cain const std::string& path = subtree[0].first; 20003a2d0424SChris Cain const std::string& service = subtree[0].second.begin()->first; 20013a2d0424SChris Cain if (service.empty()) 20023a2d0424SChris Cain { 20033a2d0424SChris Cain BMCWEB_LOG_DEBUG << "Power.Mode service mapper error!"; 20043a2d0424SChris Cain messages::internalError(aResp->res); 20053a2d0424SChris Cain return; 20063a2d0424SChris Cain } 20073a2d0424SChris Cain // Valid Power Mode object found, now read the current value 20081e1e598dSJonathan Doman sdbusplus::asio::getProperty<std::string>( 20091e1e598dSJonathan Doman *crow::connections::systemBus, service, path, 20101e1e598dSJonathan Doman "xyz.openbmc_project.Control.Power.Mode", "PowerMode", 20118a592810SEd Tanous [aResp](const boost::system::error_code ec2, 20121e1e598dSJonathan Doman const std::string& pmode) { 20138a592810SEd Tanous if (ec2) 20143a2d0424SChris Cain { 2015002d39b4SEd Tanous BMCWEB_LOG_DEBUG << "DBUS response error on PowerMode Get: " 20168a592810SEd Tanous << ec2; 20173a2d0424SChris Cain messages::internalError(aResp->res); 20183a2d0424SChris Cain return; 20193a2d0424SChris Cain } 20203a2d0424SChris Cain 2021002d39b4SEd Tanous aResp->res.jsonValue["PowerMode@Redfish.AllowableValues"] = { 2022002d39b4SEd Tanous "Static", "MaximumPerformance", "PowerSaving"}; 20233a2d0424SChris Cain 20241e1e598dSJonathan Doman BMCWEB_LOG_DEBUG << "Current power mode: " << pmode; 20251e1e598dSJonathan Doman translatePowerMode(aResp, pmode); 20261e1e598dSJonathan Doman }); 20273a2d0424SChris Cain }, 20283a2d0424SChris Cain "xyz.openbmc_project.ObjectMapper", 20293a2d0424SChris Cain "/xyz/openbmc_project/object_mapper", 20303a2d0424SChris Cain "xyz.openbmc_project.ObjectMapper", "GetSubTree", "/", int32_t(0), 20313a2d0424SChris Cain std::array<const char*, 1>{"xyz.openbmc_project.Control.Power.Mode"}); 20323a2d0424SChris Cain } 20333a2d0424SChris Cain 20343a2d0424SChris Cain /** 20353a2d0424SChris Cain * @brief Validate the specified mode is valid and return the PowerMode 20363a2d0424SChris Cain * name associated with that string 20373a2d0424SChris Cain * 20383a2d0424SChris Cain * @param[in] aResp Shared pointer for generating response message. 20393a2d0424SChris Cain * @param[in] modeString String representing the desired PowerMode 20403a2d0424SChris Cain * 20413a2d0424SChris Cain * @return PowerMode value or empty string if mode is not valid 20423a2d0424SChris Cain */ 20433a2d0424SChris Cain inline std::string 20443a2d0424SChris Cain validatePowerMode(const std::shared_ptr<bmcweb::AsyncResp>& aResp, 20453a2d0424SChris Cain const std::string& modeString) 20463a2d0424SChris Cain { 20473a2d0424SChris Cain std::string mode; 20483a2d0424SChris Cain 20493a2d0424SChris Cain if (modeString == "Static") 20503a2d0424SChris Cain { 20513a2d0424SChris Cain mode = "xyz.openbmc_project.Control.Power.Mode.PowerMode.Static"; 20523a2d0424SChris Cain } 20533a2d0424SChris Cain else if (modeString == "MaximumPerformance") 20543a2d0424SChris Cain { 20550fda0f12SGeorge Liu mode = 20560fda0f12SGeorge Liu "xyz.openbmc_project.Control.Power.Mode.PowerMode.MaximumPerformance"; 20573a2d0424SChris Cain } 20583a2d0424SChris Cain else if (modeString == "PowerSaving") 20593a2d0424SChris Cain { 20603a2d0424SChris Cain mode = "xyz.openbmc_project.Control.Power.Mode.PowerMode.PowerSaving"; 20613a2d0424SChris Cain } 20623a2d0424SChris Cain else 20633a2d0424SChris Cain { 20643a2d0424SChris Cain messages::propertyValueNotInList(aResp->res, modeString, "PowerMode"); 20653a2d0424SChris Cain } 20663a2d0424SChris Cain return mode; 20673a2d0424SChris Cain } 20683a2d0424SChris Cain 20693a2d0424SChris Cain /** 20703a2d0424SChris Cain * @brief Sets system power mode. 20713a2d0424SChris Cain * 20723a2d0424SChris Cain * @param[in] aResp Shared pointer for generating response message. 20733a2d0424SChris Cain * @param[in] pmode System power mode from request. 20743a2d0424SChris Cain * 20753a2d0424SChris Cain * @return None. 20763a2d0424SChris Cain */ 20773a2d0424SChris Cain inline void setPowerMode(const std::shared_ptr<bmcweb::AsyncResp>& aResp, 20783a2d0424SChris Cain const std::string& pmode) 20793a2d0424SChris Cain { 20803a2d0424SChris Cain BMCWEB_LOG_DEBUG << "Set power mode."; 20813a2d0424SChris Cain 20823a2d0424SChris Cain std::string powerMode = validatePowerMode(aResp, pmode); 20833a2d0424SChris Cain if (powerMode.empty()) 20843a2d0424SChris Cain { 20853a2d0424SChris Cain return; 20863a2d0424SChris Cain } 20873a2d0424SChris Cain 20883a2d0424SChris Cain // Get Power Mode object path: 20893a2d0424SChris Cain crow::connections::systemBus->async_method_call( 2090b9d36b47SEd Tanous [aResp, 2091b9d36b47SEd Tanous powerMode](const boost::system::error_code ec, 2092b9d36b47SEd Tanous const dbus::utility::MapperGetSubTreeResponse& subtree) { 20933a2d0424SChris Cain if (ec) 20943a2d0424SChris Cain { 2095002d39b4SEd Tanous BMCWEB_LOG_DEBUG << "DBUS response error on Power.Mode GetSubTree " 2096002d39b4SEd Tanous << ec; 20973a2d0424SChris Cain // This is an optional D-Bus object, but user attempted to patch 20983a2d0424SChris Cain messages::internalError(aResp->res); 20993a2d0424SChris Cain return; 21003a2d0424SChris Cain } 21013a2d0424SChris Cain if (subtree.empty()) 21023a2d0424SChris Cain { 21033a2d0424SChris Cain // This is an optional D-Bus object, but user attempted to patch 21043a2d0424SChris Cain messages::resourceNotFound(aResp->res, "ComputerSystem", 21053a2d0424SChris Cain "PowerMode"); 21063a2d0424SChris Cain return; 21073a2d0424SChris Cain } 21083a2d0424SChris Cain if (subtree.size() > 1) 21093a2d0424SChris Cain { 21103a2d0424SChris Cain // More then one PowerMode object is not supported and is an 21113a2d0424SChris Cain // error 21123a2d0424SChris Cain BMCWEB_LOG_DEBUG 21133a2d0424SChris Cain << "Found more than 1 system D-Bus Power.Mode objects: " 21143a2d0424SChris Cain << subtree.size(); 21153a2d0424SChris Cain messages::internalError(aResp->res); 21163a2d0424SChris Cain return; 21173a2d0424SChris Cain } 21183a2d0424SChris Cain if ((subtree[0].first.empty()) || (subtree[0].second.size() != 1)) 21193a2d0424SChris Cain { 21203a2d0424SChris Cain BMCWEB_LOG_DEBUG << "Power.Mode mapper error!"; 21213a2d0424SChris Cain messages::internalError(aResp->res); 21223a2d0424SChris Cain return; 21233a2d0424SChris Cain } 21243a2d0424SChris Cain const std::string& path = subtree[0].first; 21253a2d0424SChris Cain const std::string& service = subtree[0].second.begin()->first; 21263a2d0424SChris Cain if (service.empty()) 21273a2d0424SChris Cain { 21283a2d0424SChris Cain BMCWEB_LOG_DEBUG << "Power.Mode service mapper error!"; 21293a2d0424SChris Cain messages::internalError(aResp->res); 21303a2d0424SChris Cain return; 21313a2d0424SChris Cain } 21323a2d0424SChris Cain 21333a2d0424SChris Cain BMCWEB_LOG_DEBUG << "Setting power mode(" << powerMode << ") -> " 21343a2d0424SChris Cain << path; 21353a2d0424SChris Cain 21363a2d0424SChris Cain // Set the Power Mode property 21373a2d0424SChris Cain crow::connections::systemBus->async_method_call( 21388a592810SEd Tanous [aResp](const boost::system::error_code ec2) { 21398a592810SEd Tanous if (ec2) 21403a2d0424SChris Cain { 21413a2d0424SChris Cain messages::internalError(aResp->res); 21423a2d0424SChris Cain return; 21433a2d0424SChris Cain } 21443a2d0424SChris Cain }, 21453a2d0424SChris Cain service, path, "org.freedesktop.DBus.Properties", "Set", 21463a2d0424SChris Cain "xyz.openbmc_project.Control.Power.Mode", "PowerMode", 2147168e20c1SEd Tanous dbus::utility::DbusVariantType(powerMode)); 21483a2d0424SChris Cain }, 21493a2d0424SChris Cain "xyz.openbmc_project.ObjectMapper", 21503a2d0424SChris Cain "/xyz/openbmc_project/object_mapper", 21513a2d0424SChris Cain "xyz.openbmc_project.ObjectMapper", "GetSubTree", "/", int32_t(0), 21523a2d0424SChris Cain std::array<const char*, 1>{"xyz.openbmc_project.Control.Power.Mode"}); 21533a2d0424SChris Cain } 21543a2d0424SChris Cain 21553a2d0424SChris Cain /** 215651709ffdSYong Li * @brief Translates watchdog timeout action DBUS property value to redfish. 215751709ffdSYong Li * 215851709ffdSYong Li * @param[in] dbusAction The watchdog timeout action in D-BUS. 215951709ffdSYong Li * 216051709ffdSYong Li * @return Returns as a string, the timeout action in Redfish terms. If 216151709ffdSYong Li * translation cannot be done, returns an empty string. 216251709ffdSYong Li */ 216323a21a1cSEd Tanous inline std::string dbusToRfWatchdogAction(const std::string& dbusAction) 216451709ffdSYong Li { 216551709ffdSYong Li if (dbusAction == "xyz.openbmc_project.State.Watchdog.Action.None") 216651709ffdSYong Li { 216751709ffdSYong Li return "None"; 216851709ffdSYong Li } 21693174e4dfSEd Tanous if (dbusAction == "xyz.openbmc_project.State.Watchdog.Action.HardReset") 217051709ffdSYong Li { 217151709ffdSYong Li return "ResetSystem"; 217251709ffdSYong Li } 21733174e4dfSEd Tanous if (dbusAction == "xyz.openbmc_project.State.Watchdog.Action.PowerOff") 217451709ffdSYong Li { 217551709ffdSYong Li return "PowerDown"; 217651709ffdSYong Li } 21773174e4dfSEd Tanous if (dbusAction == "xyz.openbmc_project.State.Watchdog.Action.PowerCycle") 217851709ffdSYong Li { 217951709ffdSYong Li return "PowerCycle"; 218051709ffdSYong Li } 218151709ffdSYong Li 218251709ffdSYong Li return ""; 218351709ffdSYong Li } 218451709ffdSYong Li 218551709ffdSYong Li /** 2186c45f0082SYong Li *@brief Translates timeout action from Redfish to DBUS property value. 2187c45f0082SYong Li * 2188c45f0082SYong Li *@param[in] rfAction The timeout action in Redfish. 2189c45f0082SYong Li * 2190c45f0082SYong Li *@return Returns as a string, the time_out action as expected by DBUS. 2191c45f0082SYong Li *If translation cannot be done, returns an empty string. 2192c45f0082SYong Li */ 2193c45f0082SYong Li 219423a21a1cSEd Tanous inline std::string rfToDbusWDTTimeOutAct(const std::string& rfAction) 2195c45f0082SYong Li { 2196c45f0082SYong Li if (rfAction == "None") 2197c45f0082SYong Li { 2198c45f0082SYong Li return "xyz.openbmc_project.State.Watchdog.Action.None"; 2199c45f0082SYong Li } 22003174e4dfSEd Tanous if (rfAction == "PowerCycle") 2201c45f0082SYong Li { 2202c45f0082SYong Li return "xyz.openbmc_project.State.Watchdog.Action.PowerCycle"; 2203c45f0082SYong Li } 22043174e4dfSEd Tanous if (rfAction == "PowerDown") 2205c45f0082SYong Li { 2206c45f0082SYong Li return "xyz.openbmc_project.State.Watchdog.Action.PowerOff"; 2207c45f0082SYong Li } 22083174e4dfSEd Tanous if (rfAction == "ResetSystem") 2209c45f0082SYong Li { 2210c45f0082SYong Li return "xyz.openbmc_project.State.Watchdog.Action.HardReset"; 2211c45f0082SYong Li } 2212c45f0082SYong Li 2213c45f0082SYong Li return ""; 2214c45f0082SYong Li } 2215c45f0082SYong Li 2216c45f0082SYong Li /** 221751709ffdSYong Li * @brief Retrieves host watchdog timer properties over DBUS 221851709ffdSYong Li * 221951709ffdSYong Li * @param[in] aResp Shared pointer for completing asynchronous calls. 222051709ffdSYong Li * 222151709ffdSYong Li * @return None. 222251709ffdSYong Li */ 22238d1b46d7Szhanghch05 inline void 22248d1b46d7Szhanghch05 getHostWatchdogTimer(const std::shared_ptr<bmcweb::AsyncResp>& aResp) 222551709ffdSYong Li { 222651709ffdSYong Li BMCWEB_LOG_DEBUG << "Get host watchodg"; 2227bc1d29deSKrzysztof Grobelny sdbusplus::asio::getAllProperties( 2228bc1d29deSKrzysztof Grobelny *crow::connections::systemBus, "xyz.openbmc_project.Watchdog", 2229bc1d29deSKrzysztof Grobelny "/xyz/openbmc_project/watchdog/host0", 2230bc1d29deSKrzysztof Grobelny "xyz.openbmc_project.State.Watchdog", 223151709ffdSYong Li [aResp](const boost::system::error_code ec, 2232b9d36b47SEd Tanous const dbus::utility::DBusPropertiesMap& properties) { 223351709ffdSYong Li if (ec) 223451709ffdSYong Li { 223551709ffdSYong Li // watchdog service is stopped 223651709ffdSYong Li BMCWEB_LOG_DEBUG << "DBUS response error " << ec; 223751709ffdSYong Li return; 223851709ffdSYong Li } 223951709ffdSYong Li 224051709ffdSYong Li BMCWEB_LOG_DEBUG << "Got " << properties.size() << " wdt prop."; 224151709ffdSYong Li 224251709ffdSYong Li nlohmann::json& hostWatchdogTimer = 224351709ffdSYong Li aResp->res.jsonValue["HostWatchdogTimer"]; 224451709ffdSYong Li 224551709ffdSYong Li // watchdog service is running/enabled 224651709ffdSYong Li hostWatchdogTimer["Status"]["State"] = "Enabled"; 224751709ffdSYong Li 2248bc1d29deSKrzysztof Grobelny const bool* enabled = nullptr; 2249bc1d29deSKrzysztof Grobelny const std::string* expireAction = nullptr; 225051709ffdSYong Li 2251bc1d29deSKrzysztof Grobelny const bool success = sdbusplus::unpackPropertiesNoThrow( 2252bc1d29deSKrzysztof Grobelny dbus_utils::UnpackErrorPrinter(), properties, "Enabled", enabled, 2253bc1d29deSKrzysztof Grobelny "ExpireAction", expireAction); 2254bc1d29deSKrzysztof Grobelny 2255bc1d29deSKrzysztof Grobelny if (!success) 225651709ffdSYong Li { 225751709ffdSYong Li messages::internalError(aResp->res); 2258601af5edSChicago Duan return; 225951709ffdSYong Li } 226051709ffdSYong Li 2261bc1d29deSKrzysztof Grobelny if (enabled != nullptr) 226251709ffdSYong Li { 2263bc1d29deSKrzysztof Grobelny hostWatchdogTimer["FunctionEnabled"] = *enabled; 226451709ffdSYong Li } 226551709ffdSYong Li 2266bc1d29deSKrzysztof Grobelny if (expireAction != nullptr) 2267bc1d29deSKrzysztof Grobelny { 2268bc1d29deSKrzysztof Grobelny std::string action = dbusToRfWatchdogAction(*expireAction); 226951709ffdSYong Li if (action.empty()) 227051709ffdSYong Li { 227151709ffdSYong Li messages::internalError(aResp->res); 2272601af5edSChicago Duan return; 227351709ffdSYong Li } 227451709ffdSYong Li hostWatchdogTimer["TimeoutAction"] = action; 227551709ffdSYong Li } 2276bc1d29deSKrzysztof Grobelny }); 227751709ffdSYong Li } 227851709ffdSYong Li 227951709ffdSYong Li /** 2280c45f0082SYong Li * @brief Sets Host WatchDog Timer properties. 2281c45f0082SYong Li * 2282c45f0082SYong Li * @param[in] aResp Shared pointer for generating response message. 2283c45f0082SYong Li * @param[in] wdtEnable The WDTimer Enable value (true/false) from incoming 2284c45f0082SYong Li * RF request. 2285c45f0082SYong Li * @param[in] wdtTimeOutAction The WDT Timeout action, from incoming RF request. 2286c45f0082SYong Li * 2287c45f0082SYong Li * @return None. 2288c45f0082SYong Li */ 22898d1b46d7Szhanghch05 inline void setWDTProperties(const std::shared_ptr<bmcweb::AsyncResp>& aResp, 2290c45f0082SYong Li const std::optional<bool> wdtEnable, 2291c45f0082SYong Li const std::optional<std::string>& wdtTimeOutAction) 2292c45f0082SYong Li { 2293c45f0082SYong Li BMCWEB_LOG_DEBUG << "Set host watchdog"; 2294c45f0082SYong Li 2295c45f0082SYong Li if (wdtTimeOutAction) 2296c45f0082SYong Li { 2297c45f0082SYong Li std::string wdtTimeOutActStr = rfToDbusWDTTimeOutAct(*wdtTimeOutAction); 2298c45f0082SYong Li // check if TimeOut Action is Valid 2299c45f0082SYong Li if (wdtTimeOutActStr.empty()) 2300c45f0082SYong Li { 2301c45f0082SYong Li BMCWEB_LOG_DEBUG << "Unsupported value for TimeoutAction: " 2302c45f0082SYong Li << *wdtTimeOutAction; 2303c45f0082SYong Li messages::propertyValueNotInList(aResp->res, *wdtTimeOutAction, 2304c45f0082SYong Li "TimeoutAction"); 2305c45f0082SYong Li return; 2306c45f0082SYong Li } 2307c45f0082SYong Li 2308c45f0082SYong Li crow::connections::systemBus->async_method_call( 2309c45f0082SYong Li [aResp](const boost::system::error_code ec) { 2310c45f0082SYong Li if (ec) 2311c45f0082SYong Li { 2312c45f0082SYong Li BMCWEB_LOG_DEBUG << "DBUS response error " << ec; 2313c45f0082SYong Li messages::internalError(aResp->res); 2314c45f0082SYong Li return; 2315c45f0082SYong Li } 2316c45f0082SYong Li }, 2317c45f0082SYong Li "xyz.openbmc_project.Watchdog", 2318c45f0082SYong Li "/xyz/openbmc_project/watchdog/host0", 2319c45f0082SYong Li "org.freedesktop.DBus.Properties", "Set", 2320c45f0082SYong Li "xyz.openbmc_project.State.Watchdog", "ExpireAction", 2321168e20c1SEd Tanous dbus::utility::DbusVariantType(wdtTimeOutActStr)); 2322c45f0082SYong Li } 2323c45f0082SYong Li 2324c45f0082SYong Li if (wdtEnable) 2325c45f0082SYong Li { 2326c45f0082SYong Li crow::connections::systemBus->async_method_call( 2327c45f0082SYong Li [aResp](const boost::system::error_code ec) { 2328c45f0082SYong Li if (ec) 2329c45f0082SYong Li { 2330c45f0082SYong Li BMCWEB_LOG_DEBUG << "DBUS response error " << ec; 2331c45f0082SYong Li messages::internalError(aResp->res); 2332c45f0082SYong Li return; 2333c45f0082SYong Li } 2334c45f0082SYong Li }, 2335c45f0082SYong Li "xyz.openbmc_project.Watchdog", 2336c45f0082SYong Li "/xyz/openbmc_project/watchdog/host0", 2337c45f0082SYong Li "org.freedesktop.DBus.Properties", "Set", 2338c45f0082SYong Li "xyz.openbmc_project.State.Watchdog", "Enabled", 2339168e20c1SEd Tanous dbus::utility::DbusVariantType(*wdtEnable)); 2340c45f0082SYong Li } 2341c45f0082SYong Li } 2342c45f0082SYong Li 234337bbf98cSChris Cain /** 234437bbf98cSChris Cain * @brief Parse the Idle Power Saver properties into json 234537bbf98cSChris Cain * 234637bbf98cSChris Cain * @param[in] aResp Shared pointer for completing asynchronous calls. 234737bbf98cSChris Cain * @param[in] properties IPS property data from DBus. 234837bbf98cSChris Cain * 234937bbf98cSChris Cain * @return true if successful 235037bbf98cSChris Cain */ 23511e5b7c88SJiaqing Zhao inline bool 23521e5b7c88SJiaqing Zhao parseIpsProperties(const std::shared_ptr<bmcweb::AsyncResp>& aResp, 23531e5b7c88SJiaqing Zhao const dbus::utility::DBusPropertiesMap& properties) 235437bbf98cSChris Cain { 2355bc1d29deSKrzysztof Grobelny const bool* enabled = nullptr; 2356bc1d29deSKrzysztof Grobelny const uint8_t* enterUtilizationPercent = nullptr; 2357bc1d29deSKrzysztof Grobelny const uint64_t* enterDwellTime = nullptr; 2358bc1d29deSKrzysztof Grobelny const uint8_t* exitUtilizationPercent = nullptr; 2359bc1d29deSKrzysztof Grobelny const uint64_t* exitDwellTime = nullptr; 2360bc1d29deSKrzysztof Grobelny 2361bc1d29deSKrzysztof Grobelny const bool success = sdbusplus::unpackPropertiesNoThrow( 2362bc1d29deSKrzysztof Grobelny dbus_utils::UnpackErrorPrinter(), properties, "Enabled", enabled, 2363bc1d29deSKrzysztof Grobelny "EnterUtilizationPercent", enterUtilizationPercent, 2364bc1d29deSKrzysztof Grobelny "ExitUtilizationPercent", exitUtilizationPercent, "ExitDwellTime", 2365bc1d29deSKrzysztof Grobelny exitDwellTime); 2366bc1d29deSKrzysztof Grobelny 2367bc1d29deSKrzysztof Grobelny if (!success) 236837bbf98cSChris Cain { 236937bbf98cSChris Cain return false; 237037bbf98cSChris Cain } 2371bc1d29deSKrzysztof Grobelny 2372bc1d29deSKrzysztof Grobelny if (enabled != nullptr) 237337bbf98cSChris Cain { 2374bc1d29deSKrzysztof Grobelny aResp->res.jsonValue["IdlePowerSaver"]["Enabled"] = *enabled; 237537bbf98cSChris Cain } 2376bc1d29deSKrzysztof Grobelny 2377bc1d29deSKrzysztof Grobelny if (enterUtilizationPercent != nullptr) 237837bbf98cSChris Cain { 2379bc1d29deSKrzysztof Grobelny aResp->res.jsonValue["IdlePowerSaver"]["EnterUtilizationPercent"] = 2380bc1d29deSKrzysztof Grobelny *enterUtilizationPercent; 238137bbf98cSChris Cain } 2382bc1d29deSKrzysztof Grobelny 2383bc1d29deSKrzysztof Grobelny if (enterDwellTime != nullptr) 2384bc1d29deSKrzysztof Grobelny { 2385bc1d29deSKrzysztof Grobelny const std::chrono::duration<uint64_t, std::milli> ms(*enterDwellTime); 238637bbf98cSChris Cain aResp->res.jsonValue["IdlePowerSaver"]["EnterDwellTimeSeconds"] = 238737bbf98cSChris Cain std::chrono::duration_cast<std::chrono::duration<uint64_t>>(ms) 238837bbf98cSChris Cain .count(); 238937bbf98cSChris Cain } 2390bc1d29deSKrzysztof Grobelny 2391bc1d29deSKrzysztof Grobelny if (exitUtilizationPercent != nullptr) 239237bbf98cSChris Cain { 2393bc1d29deSKrzysztof Grobelny aResp->res.jsonValue["IdlePowerSaver"]["ExitUtilizationPercent"] = 2394bc1d29deSKrzysztof Grobelny *exitUtilizationPercent; 239537bbf98cSChris Cain } 2396bc1d29deSKrzysztof Grobelny 2397bc1d29deSKrzysztof Grobelny if (exitDwellTime != nullptr) 239837bbf98cSChris Cain { 2399bc1d29deSKrzysztof Grobelny const std::chrono::duration<uint64_t, std::milli> ms(*exitDwellTime); 240037bbf98cSChris Cain aResp->res.jsonValue["IdlePowerSaver"]["ExitDwellTimeSeconds"] = 240137bbf98cSChris Cain std::chrono::duration_cast<std::chrono::duration<uint64_t>>(ms) 240237bbf98cSChris Cain .count(); 240337bbf98cSChris Cain } 240437bbf98cSChris Cain 240537bbf98cSChris Cain return true; 240637bbf98cSChris Cain } 240737bbf98cSChris Cain 240837bbf98cSChris Cain /** 240937bbf98cSChris Cain * @brief Retrieves host watchdog timer properties over DBUS 241037bbf98cSChris Cain * 241137bbf98cSChris Cain * @param[in] aResp Shared pointer for completing asynchronous calls. 241237bbf98cSChris Cain * 241337bbf98cSChris Cain * @return None. 241437bbf98cSChris Cain */ 241537bbf98cSChris Cain inline void getIdlePowerSaver(const std::shared_ptr<bmcweb::AsyncResp>& aResp) 241637bbf98cSChris Cain { 241737bbf98cSChris Cain BMCWEB_LOG_DEBUG << "Get idle power saver parameters"; 241837bbf98cSChris Cain 241937bbf98cSChris Cain // Get IdlePowerSaver object path: 242037bbf98cSChris Cain crow::connections::systemBus->async_method_call( 2421b9d36b47SEd Tanous [aResp](const boost::system::error_code ec, 2422b9d36b47SEd Tanous const dbus::utility::MapperGetSubTreeResponse& subtree) { 242337bbf98cSChris Cain if (ec) 242437bbf98cSChris Cain { 242537bbf98cSChris Cain BMCWEB_LOG_DEBUG 242637bbf98cSChris Cain << "DBUS response error on Power.IdlePowerSaver GetSubTree " 242737bbf98cSChris Cain << ec; 242837bbf98cSChris Cain messages::internalError(aResp->res); 242937bbf98cSChris Cain return; 243037bbf98cSChris Cain } 243137bbf98cSChris Cain if (subtree.empty()) 243237bbf98cSChris Cain { 243337bbf98cSChris Cain // This is an optional interface so just return 243437bbf98cSChris Cain // if there is no instance found 243537bbf98cSChris Cain BMCWEB_LOG_DEBUG << "No instances found"; 243637bbf98cSChris Cain return; 243737bbf98cSChris Cain } 243837bbf98cSChris Cain if (subtree.size() > 1) 243937bbf98cSChris Cain { 244037bbf98cSChris Cain // More then one PowerIdlePowerSaver object is not supported and 244137bbf98cSChris Cain // is an error 244237bbf98cSChris Cain BMCWEB_LOG_DEBUG << "Found more than 1 system D-Bus " 244337bbf98cSChris Cain "Power.IdlePowerSaver objects: " 244437bbf98cSChris Cain << subtree.size(); 244537bbf98cSChris Cain messages::internalError(aResp->res); 244637bbf98cSChris Cain return; 244737bbf98cSChris Cain } 244837bbf98cSChris Cain if ((subtree[0].first.empty()) || (subtree[0].second.size() != 1)) 244937bbf98cSChris Cain { 245037bbf98cSChris Cain BMCWEB_LOG_DEBUG << "Power.IdlePowerSaver mapper error!"; 245137bbf98cSChris Cain messages::internalError(aResp->res); 245237bbf98cSChris Cain return; 245337bbf98cSChris Cain } 245437bbf98cSChris Cain const std::string& path = subtree[0].first; 245537bbf98cSChris Cain const std::string& service = subtree[0].second.begin()->first; 245637bbf98cSChris Cain if (service.empty()) 245737bbf98cSChris Cain { 2458002d39b4SEd Tanous BMCWEB_LOG_DEBUG << "Power.IdlePowerSaver service mapper error!"; 245937bbf98cSChris Cain messages::internalError(aResp->res); 246037bbf98cSChris Cain return; 246137bbf98cSChris Cain } 246237bbf98cSChris Cain 246337bbf98cSChris Cain // Valid IdlePowerSaver object found, now read the current values 2464bc1d29deSKrzysztof Grobelny sdbusplus::asio::getAllProperties( 2465bc1d29deSKrzysztof Grobelny *crow::connections::systemBus, service, path, 2466bc1d29deSKrzysztof Grobelny "xyz.openbmc_project.Control.Power.IdlePowerSaver", 24678a592810SEd Tanous [aResp](const boost::system::error_code ec2, 24681e5b7c88SJiaqing Zhao const dbus::utility::DBusPropertiesMap& properties) { 24698a592810SEd Tanous if (ec2) 247037bbf98cSChris Cain { 247137bbf98cSChris Cain BMCWEB_LOG_ERROR 24728a592810SEd Tanous << "DBUS response error on IdlePowerSaver GetAll: " << ec2; 247337bbf98cSChris Cain messages::internalError(aResp->res); 247437bbf98cSChris Cain return; 247537bbf98cSChris Cain } 247637bbf98cSChris Cain 2477e05aec50SEd Tanous if (!parseIpsProperties(aResp, properties)) 247837bbf98cSChris Cain { 247937bbf98cSChris Cain messages::internalError(aResp->res); 248037bbf98cSChris Cain return; 248137bbf98cSChris Cain } 2482bc1d29deSKrzysztof Grobelny }); 248337bbf98cSChris Cain }, 248437bbf98cSChris Cain "xyz.openbmc_project.ObjectMapper", 248537bbf98cSChris Cain "/xyz/openbmc_project/object_mapper", 248637bbf98cSChris Cain "xyz.openbmc_project.ObjectMapper", "GetSubTree", "/", int32_t(0), 248737bbf98cSChris Cain std::array<const char*, 1>{ 248837bbf98cSChris Cain "xyz.openbmc_project.Control.Power.IdlePowerSaver"}); 248937bbf98cSChris Cain 249037bbf98cSChris Cain BMCWEB_LOG_DEBUG << "EXIT: Get idle power saver parameters"; 249137bbf98cSChris Cain } 249237bbf98cSChris Cain 249337bbf98cSChris Cain /** 249437bbf98cSChris Cain * @brief Sets Idle Power Saver properties. 249537bbf98cSChris Cain * 249637bbf98cSChris Cain * @param[in] aResp Shared pointer for generating response message. 249737bbf98cSChris Cain * @param[in] ipsEnable The IPS Enable value (true/false) from incoming 249837bbf98cSChris Cain * RF request. 249937bbf98cSChris Cain * @param[in] ipsEnterUtil The utilization limit to enter idle state. 250037bbf98cSChris Cain * @param[in] ipsEnterTime The time the utilization must be below ipsEnterUtil 250137bbf98cSChris Cain * before entering idle state. 250237bbf98cSChris Cain * @param[in] ipsExitUtil The utilization limit when exiting idle state. 250337bbf98cSChris Cain * @param[in] ipsExitTime The time the utilization must be above ipsExutUtil 250437bbf98cSChris Cain * before exiting idle state 250537bbf98cSChris Cain * 250637bbf98cSChris Cain * @return None. 250737bbf98cSChris Cain */ 250837bbf98cSChris Cain inline void setIdlePowerSaver(const std::shared_ptr<bmcweb::AsyncResp>& aResp, 250937bbf98cSChris Cain const std::optional<bool> ipsEnable, 251037bbf98cSChris Cain const std::optional<uint8_t> ipsEnterUtil, 251137bbf98cSChris Cain const std::optional<uint64_t> ipsEnterTime, 251237bbf98cSChris Cain const std::optional<uint8_t> ipsExitUtil, 251337bbf98cSChris Cain const std::optional<uint64_t> ipsExitTime) 251437bbf98cSChris Cain { 251537bbf98cSChris Cain BMCWEB_LOG_DEBUG << "Set idle power saver properties"; 251637bbf98cSChris Cain 251737bbf98cSChris Cain // Get IdlePowerSaver object path: 251837bbf98cSChris Cain crow::connections::systemBus->async_method_call( 251937bbf98cSChris Cain [aResp, ipsEnable, ipsEnterUtil, ipsEnterTime, ipsExitUtil, 2520b9d36b47SEd Tanous ipsExitTime](const boost::system::error_code ec, 2521b9d36b47SEd Tanous const dbus::utility::MapperGetSubTreeResponse& subtree) { 252237bbf98cSChris Cain if (ec) 252337bbf98cSChris Cain { 252437bbf98cSChris Cain BMCWEB_LOG_DEBUG 252537bbf98cSChris Cain << "DBUS response error on Power.IdlePowerSaver GetSubTree " 252637bbf98cSChris Cain << ec; 252737bbf98cSChris Cain messages::internalError(aResp->res); 252837bbf98cSChris Cain return; 252937bbf98cSChris Cain } 253037bbf98cSChris Cain if (subtree.empty()) 253137bbf98cSChris Cain { 253237bbf98cSChris Cain // This is an optional D-Bus object, but user attempted to patch 253337bbf98cSChris Cain messages::resourceNotFound(aResp->res, "ComputerSystem", 253437bbf98cSChris Cain "IdlePowerSaver"); 253537bbf98cSChris Cain return; 253637bbf98cSChris Cain } 253737bbf98cSChris Cain if (subtree.size() > 1) 253837bbf98cSChris Cain { 253937bbf98cSChris Cain // More then one PowerIdlePowerSaver object is not supported and 254037bbf98cSChris Cain // is an error 25410fda0f12SGeorge Liu BMCWEB_LOG_DEBUG 25420fda0f12SGeorge Liu << "Found more than 1 system D-Bus Power.IdlePowerSaver objects: " 254337bbf98cSChris Cain << subtree.size(); 254437bbf98cSChris Cain messages::internalError(aResp->res); 254537bbf98cSChris Cain return; 254637bbf98cSChris Cain } 254737bbf98cSChris Cain if ((subtree[0].first.empty()) || (subtree[0].second.size() != 1)) 254837bbf98cSChris Cain { 254937bbf98cSChris Cain BMCWEB_LOG_DEBUG << "Power.IdlePowerSaver mapper error!"; 255037bbf98cSChris Cain messages::internalError(aResp->res); 255137bbf98cSChris Cain return; 255237bbf98cSChris Cain } 255337bbf98cSChris Cain const std::string& path = subtree[0].first; 255437bbf98cSChris Cain const std::string& service = subtree[0].second.begin()->first; 255537bbf98cSChris Cain if (service.empty()) 255637bbf98cSChris Cain { 2557002d39b4SEd Tanous BMCWEB_LOG_DEBUG << "Power.IdlePowerSaver service mapper error!"; 255837bbf98cSChris Cain messages::internalError(aResp->res); 255937bbf98cSChris Cain return; 256037bbf98cSChris Cain } 256137bbf98cSChris Cain 256237bbf98cSChris Cain // Valid Power IdlePowerSaver object found, now set any values that 256337bbf98cSChris Cain // need to be updated 256437bbf98cSChris Cain 256537bbf98cSChris Cain if (ipsEnable) 256637bbf98cSChris Cain { 256737bbf98cSChris Cain crow::connections::systemBus->async_method_call( 25688a592810SEd Tanous [aResp](const boost::system::error_code ec2) { 25698a592810SEd Tanous if (ec2) 257037bbf98cSChris Cain { 25718a592810SEd Tanous BMCWEB_LOG_DEBUG << "DBUS response error " << ec2; 257237bbf98cSChris Cain messages::internalError(aResp->res); 257337bbf98cSChris Cain return; 257437bbf98cSChris Cain } 257537bbf98cSChris Cain }, 257637bbf98cSChris Cain service, path, "org.freedesktop.DBus.Properties", "Set", 2577002d39b4SEd Tanous "xyz.openbmc_project.Control.Power.IdlePowerSaver", "Enabled", 2578002d39b4SEd Tanous dbus::utility::DbusVariantType(*ipsEnable)); 257937bbf98cSChris Cain } 258037bbf98cSChris Cain if (ipsEnterUtil) 258137bbf98cSChris Cain { 258237bbf98cSChris Cain crow::connections::systemBus->async_method_call( 25838a592810SEd Tanous [aResp](const boost::system::error_code ec2) { 25848a592810SEd Tanous if (ec2) 258537bbf98cSChris Cain { 25868a592810SEd Tanous BMCWEB_LOG_DEBUG << "DBUS response error " << ec2; 258737bbf98cSChris Cain messages::internalError(aResp->res); 258837bbf98cSChris Cain return; 258937bbf98cSChris Cain } 259037bbf98cSChris Cain }, 259137bbf98cSChris Cain service, path, "org.freedesktop.DBus.Properties", "Set", 259237bbf98cSChris Cain "xyz.openbmc_project.Control.Power.IdlePowerSaver", 259337bbf98cSChris Cain "EnterUtilizationPercent", 2594168e20c1SEd Tanous dbus::utility::DbusVariantType(*ipsEnterUtil)); 259537bbf98cSChris Cain } 259637bbf98cSChris Cain if (ipsEnterTime) 259737bbf98cSChris Cain { 259837bbf98cSChris Cain // Convert from seconds into milliseconds for DBus 259937bbf98cSChris Cain const uint64_t timeMilliseconds = *ipsEnterTime * 1000; 260037bbf98cSChris Cain crow::connections::systemBus->async_method_call( 26018a592810SEd Tanous [aResp](const boost::system::error_code ec2) { 26028a592810SEd Tanous if (ec2) 260337bbf98cSChris Cain { 26048a592810SEd Tanous BMCWEB_LOG_DEBUG << "DBUS response error " << ec2; 260537bbf98cSChris Cain messages::internalError(aResp->res); 260637bbf98cSChris Cain return; 260737bbf98cSChris Cain } 260837bbf98cSChris Cain }, 260937bbf98cSChris Cain service, path, "org.freedesktop.DBus.Properties", "Set", 261037bbf98cSChris Cain "xyz.openbmc_project.Control.Power.IdlePowerSaver", 2611168e20c1SEd Tanous "EnterDwellTime", 2612168e20c1SEd Tanous dbus::utility::DbusVariantType(timeMilliseconds)); 261337bbf98cSChris Cain } 261437bbf98cSChris Cain if (ipsExitUtil) 261537bbf98cSChris Cain { 261637bbf98cSChris Cain crow::connections::systemBus->async_method_call( 26178a592810SEd Tanous [aResp](const boost::system::error_code ec2) { 26188a592810SEd Tanous if (ec2) 261937bbf98cSChris Cain { 26208a592810SEd Tanous BMCWEB_LOG_DEBUG << "DBUS response error " << ec2; 262137bbf98cSChris Cain messages::internalError(aResp->res); 262237bbf98cSChris Cain return; 262337bbf98cSChris Cain } 262437bbf98cSChris Cain }, 262537bbf98cSChris Cain service, path, "org.freedesktop.DBus.Properties", "Set", 262637bbf98cSChris Cain "xyz.openbmc_project.Control.Power.IdlePowerSaver", 262737bbf98cSChris Cain "ExitUtilizationPercent", 2628168e20c1SEd Tanous dbus::utility::DbusVariantType(*ipsExitUtil)); 262937bbf98cSChris Cain } 263037bbf98cSChris Cain if (ipsExitTime) 263137bbf98cSChris Cain { 263237bbf98cSChris Cain // Convert from seconds into milliseconds for DBus 263337bbf98cSChris Cain const uint64_t timeMilliseconds = *ipsExitTime * 1000; 263437bbf98cSChris Cain crow::connections::systemBus->async_method_call( 26358a592810SEd Tanous [aResp](const boost::system::error_code ec2) { 26368a592810SEd Tanous if (ec2) 263737bbf98cSChris Cain { 26388a592810SEd Tanous BMCWEB_LOG_DEBUG << "DBUS response error " << ec2; 263937bbf98cSChris Cain messages::internalError(aResp->res); 264037bbf98cSChris Cain return; 264137bbf98cSChris Cain } 264237bbf98cSChris Cain }, 264337bbf98cSChris Cain service, path, "org.freedesktop.DBus.Properties", "Set", 264437bbf98cSChris Cain "xyz.openbmc_project.Control.Power.IdlePowerSaver", 2645168e20c1SEd Tanous "ExitDwellTime", 2646168e20c1SEd Tanous dbus::utility::DbusVariantType(timeMilliseconds)); 264737bbf98cSChris Cain } 264837bbf98cSChris Cain }, 264937bbf98cSChris Cain "xyz.openbmc_project.ObjectMapper", 265037bbf98cSChris Cain "/xyz/openbmc_project/object_mapper", 265137bbf98cSChris Cain "xyz.openbmc_project.ObjectMapper", "GetSubTree", "/", int32_t(0), 265237bbf98cSChris Cain std::array<const char*, 1>{ 265337bbf98cSChris Cain "xyz.openbmc_project.Control.Power.IdlePowerSaver"}); 265437bbf98cSChris Cain 265537bbf98cSChris Cain BMCWEB_LOG_DEBUG << "EXIT: Set idle power saver parameters"; 265637bbf98cSChris Cain } 265737bbf98cSChris Cain 2658dd60b9edSEd Tanous inline void handleComputerSystemHead( 2659dd60b9edSEd Tanous crow::App& app, const crow::Request& req, 2660dd60b9edSEd Tanous const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) 2661dd60b9edSEd Tanous { 2662dd60b9edSEd Tanous if (!redfish::setUpRedfishRoute(app, req, asyncResp)) 2663dd60b9edSEd Tanous { 2664dd60b9edSEd Tanous return; 2665dd60b9edSEd Tanous } 2666dd60b9edSEd Tanous asyncResp->res.addHeader( 2667dd60b9edSEd Tanous boost::beast::http::field::link, 2668dd60b9edSEd Tanous "</redfish/v1/JsonSchemas/ComputerSystemCollection/ComputerSystemCollection.json>; rel=describedby"); 2669dd60b9edSEd Tanous } 2670dd60b9edSEd Tanous 2671c45f0082SYong Li /** 2672c5b2abe0SLewanczyk, Dawid * SystemsCollection derived class for delivering ComputerSystems Collection 2673c5b2abe0SLewanczyk, Dawid * Schema 2674c5b2abe0SLewanczyk, Dawid */ 26757e860f15SJohn Edward Broadbent inline void requestRoutesSystemsCollection(App& app) 26761abe55efSEd Tanous { 26777e860f15SJohn Edward Broadbent BMCWEB_ROUTE(app, "/redfish/v1/Systems/") 2678dd60b9edSEd Tanous .privileges(redfish::privileges::headComputerSystemCollection) 2679dd60b9edSEd Tanous .methods(boost::beast::http::verb::head)( 2680dd60b9edSEd Tanous std::bind_front(handleComputerSystemHead, std::ref(app))); 2681dd60b9edSEd Tanous 2682dd60b9edSEd Tanous BMCWEB_ROUTE(app, "/redfish/v1/Systems/") 2683ed398213SEd Tanous .privileges(redfish::privileges::getComputerSystemCollection) 26847e860f15SJohn Edward Broadbent .methods(boost::beast::http::verb::get)( 2685f4c99e70SEd Tanous [&app](const crow::Request& req, 26867e860f15SJohn Edward Broadbent const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) { 26873ba00073SCarson Labrado if (!redfish::setUpRedfishRoute(app, req, asyncResp)) 2688f4c99e70SEd Tanous { 2689f4c99e70SEd Tanous return; 2690f4c99e70SEd Tanous } 2691dd60b9edSEd Tanous 2692dd60b9edSEd Tanous asyncResp->res.addHeader( 2693dd60b9edSEd Tanous boost::beast::http::field::link, 2694dd60b9edSEd Tanous "</redfish/v1/JsonSchemas/ComputerSystemCollection.json>; rel=describedby"); 26958d1b46d7Szhanghch05 asyncResp->res.jsonValue["@odata.type"] = 26960f74e643SEd Tanous "#ComputerSystemCollection.ComputerSystemCollection"; 26978d1b46d7Szhanghch05 asyncResp->res.jsonValue["@odata.id"] = "/redfish/v1/Systems"; 26988d1b46d7Szhanghch05 asyncResp->res.jsonValue["Name"] = "Computer System Collection"; 2699462023adSSunitha Harish 27001e1e598dSJonathan Doman sdbusplus::asio::getProperty<std::string>( 2701002d39b4SEd Tanous *crow::connections::systemBus, "xyz.openbmc_project.Settings", 27021e1e598dSJonathan Doman "/xyz/openbmc_project/network/hypervisor", 2703002d39b4SEd Tanous "xyz.openbmc_project.Network.SystemConfiguration", "HostName", 27048a592810SEd Tanous [asyncResp](const boost::system::error_code ec2, 27051e1e598dSJonathan Doman const std::string& /*hostName*/) { 2706002d39b4SEd Tanous nlohmann::json& ifaceArray = asyncResp->res.jsonValue["Members"]; 27072c70f800SEd Tanous ifaceArray = nlohmann::json::array(); 2708002d39b4SEd Tanous auto& count = asyncResp->res.jsonValue["Members@odata.count"]; 27091476687dSEd Tanous 27101476687dSEd Tanous nlohmann::json::object_t system; 27111476687dSEd Tanous system["@odata.id"] = "/redfish/v1/Systems/system"; 27121476687dSEd Tanous ifaceArray.push_back(std::move(system)); 271394bda602STim Lee count = ifaceArray.size(); 27148a592810SEd Tanous if (!ec2) 2715462023adSSunitha Harish { 2716462023adSSunitha Harish BMCWEB_LOG_DEBUG << "Hypervisor is available"; 27171476687dSEd Tanous nlohmann::json::object_t hypervisor; 2718002d39b4SEd Tanous hypervisor["@odata.id"] = "/redfish/v1/Systems/hypervisor"; 27191476687dSEd Tanous ifaceArray.push_back(std::move(hypervisor)); 27202c70f800SEd Tanous count = ifaceArray.size(); 2721cb13a392SEd Tanous } 27221e1e598dSJonathan Doman }); 27237e860f15SJohn Edward Broadbent }); 2724c5b2abe0SLewanczyk, Dawid } 27257e860f15SJohn Edward Broadbent 27267e860f15SJohn Edward Broadbent /** 27277e860f15SJohn Edward Broadbent * Function transceives data with dbus directly. 27287e860f15SJohn Edward Broadbent */ 27294f48d5f6SEd Tanous inline void doNMI(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) 27307e860f15SJohn Edward Broadbent { 27317e860f15SJohn Edward Broadbent constexpr char const* serviceName = "xyz.openbmc_project.Control.Host.NMI"; 27327e860f15SJohn Edward Broadbent constexpr char const* objectPath = "/xyz/openbmc_project/control/host0/nmi"; 27337e860f15SJohn Edward Broadbent constexpr char const* interfaceName = 27347e860f15SJohn Edward Broadbent "xyz.openbmc_project.Control.Host.NMI"; 27357e860f15SJohn Edward Broadbent constexpr char const* method = "NMI"; 27367e860f15SJohn Edward Broadbent 27377e860f15SJohn Edward Broadbent crow::connections::systemBus->async_method_call( 27387e860f15SJohn Edward Broadbent [asyncResp](const boost::system::error_code ec) { 27397e860f15SJohn Edward Broadbent if (ec) 27407e860f15SJohn Edward Broadbent { 27417e860f15SJohn Edward Broadbent BMCWEB_LOG_ERROR << " Bad D-Bus request error: " << ec; 27427e860f15SJohn Edward Broadbent messages::internalError(asyncResp->res); 27437e860f15SJohn Edward Broadbent return; 27447e860f15SJohn Edward Broadbent } 27457e860f15SJohn Edward Broadbent messages::success(asyncResp->res); 27467e860f15SJohn Edward Broadbent }, 27477e860f15SJohn Edward Broadbent serviceName, objectPath, interfaceName, method); 27487e860f15SJohn Edward Broadbent } 2749c5b2abe0SLewanczyk, Dawid 2750c5b2abe0SLewanczyk, Dawid /** 2751cc340dd9SEd Tanous * SystemActionsReset class supports handle POST method for Reset action. 2752cc340dd9SEd Tanous * The class retrieves and sends data directly to D-Bus. 2753cc340dd9SEd Tanous */ 27547e860f15SJohn Edward Broadbent inline void requestRoutesSystemActionsReset(App& app) 2755cc340dd9SEd Tanous { 2756cc340dd9SEd Tanous /** 2757cc340dd9SEd Tanous * Function handles POST method request. 2758cc340dd9SEd Tanous * Analyzes POST body message before sends Reset request data to D-Bus. 2759cc340dd9SEd Tanous */ 27607e860f15SJohn Edward Broadbent BMCWEB_ROUTE(app, 27617e860f15SJohn Edward Broadbent "/redfish/v1/Systems/system/Actions/ComputerSystem.Reset/") 2762ed398213SEd Tanous .privileges(redfish::privileges::postComputerSystem) 2763002d39b4SEd Tanous .methods(boost::beast::http::verb::post)( 2764002d39b4SEd Tanous [&app](const crow::Request& req, 27657e860f15SJohn Edward Broadbent const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) { 27663ba00073SCarson Labrado if (!redfish::setUpRedfishRoute(app, req, asyncResp)) 276745ca1b86SEd Tanous { 276845ca1b86SEd Tanous return; 276945ca1b86SEd Tanous } 27709712f8acSEd Tanous std::string resetType; 277115ed6780SWilly Tu if (!json_util::readJsonAction(req, asyncResp->res, "ResetType", 27727e860f15SJohn Edward Broadbent resetType)) 2773cc340dd9SEd Tanous { 2774cc340dd9SEd Tanous return; 2775cc340dd9SEd Tanous } 2776cc340dd9SEd Tanous 2777d22c8396SJason M. Bills // Get the command and host vs. chassis 2778cc340dd9SEd Tanous std::string command; 2779543f4400SEd Tanous bool hostCommand = true; 2780d4d25793SEd Tanous if ((resetType == "On") || (resetType == "ForceOn")) 2781cc340dd9SEd Tanous { 2782cc340dd9SEd Tanous command = "xyz.openbmc_project.State.Host.Transition.On"; 2783d22c8396SJason M. Bills hostCommand = true; 2784d22c8396SJason M. Bills } 2785d22c8396SJason M. Bills else if (resetType == "ForceOff") 2786d22c8396SJason M. Bills { 2787d22c8396SJason M. Bills command = "xyz.openbmc_project.State.Chassis.Transition.Off"; 2788d22c8396SJason M. Bills hostCommand = false; 2789d22c8396SJason M. Bills } 2790d22c8396SJason M. Bills else if (resetType == "ForceRestart") 2791d22c8396SJason M. Bills { 279286a0851aSJason M. Bills command = 279386a0851aSJason M. Bills "xyz.openbmc_project.State.Host.Transition.ForceWarmReboot"; 279486a0851aSJason M. Bills hostCommand = true; 2795cc340dd9SEd Tanous } 27969712f8acSEd Tanous else if (resetType == "GracefulShutdown") 2797cc340dd9SEd Tanous { 2798cc340dd9SEd Tanous command = "xyz.openbmc_project.State.Host.Transition.Off"; 2799d22c8396SJason M. Bills hostCommand = true; 2800cc340dd9SEd Tanous } 28019712f8acSEd Tanous else if (resetType == "GracefulRestart") 2802cc340dd9SEd Tanous { 28030fda0f12SGeorge Liu command = 28040fda0f12SGeorge Liu "xyz.openbmc_project.State.Host.Transition.GracefulWarmReboot"; 2805d22c8396SJason M. Bills hostCommand = true; 2806d22c8396SJason M. Bills } 2807d22c8396SJason M. Bills else if (resetType == "PowerCycle") 2808d22c8396SJason M. Bills { 280986a0851aSJason M. Bills command = "xyz.openbmc_project.State.Host.Transition.Reboot"; 281086a0851aSJason M. Bills hostCommand = true; 2811cc340dd9SEd Tanous } 2812bfd5b826SLakshminarayana R. Kammath else if (resetType == "Nmi") 2813bfd5b826SLakshminarayana R. Kammath { 2814bfd5b826SLakshminarayana R. Kammath doNMI(asyncResp); 2815bfd5b826SLakshminarayana R. Kammath return; 2816bfd5b826SLakshminarayana R. Kammath } 2817cc340dd9SEd Tanous else 2818cc340dd9SEd Tanous { 28198d1b46d7Szhanghch05 messages::actionParameterUnknown(asyncResp->res, "Reset", 28208d1b46d7Szhanghch05 resetType); 2821cc340dd9SEd Tanous return; 2822cc340dd9SEd Tanous } 2823cc340dd9SEd Tanous 2824d22c8396SJason M. Bills if (hostCommand) 2825d22c8396SJason M. Bills { 2826cc340dd9SEd Tanous crow::connections::systemBus->async_method_call( 2827d22c8396SJason M. Bills [asyncResp, resetType](const boost::system::error_code ec) { 2828cc340dd9SEd Tanous if (ec) 2829cc340dd9SEd Tanous { 2830cc340dd9SEd Tanous BMCWEB_LOG_ERROR << "D-Bus responses error: " << ec; 2831002d39b4SEd Tanous if (ec.value() == boost::asio::error::invalid_argument) 2832d22c8396SJason M. Bills { 2833d22c8396SJason M. Bills messages::actionParameterNotSupported( 2834d22c8396SJason M. Bills asyncResp->res, resetType, "Reset"); 2835d22c8396SJason M. Bills } 2836d22c8396SJason M. Bills else 2837d22c8396SJason M. Bills { 2838f12894f8SJason M. Bills messages::internalError(asyncResp->res); 2839d22c8396SJason M. Bills } 2840cc340dd9SEd Tanous return; 2841cc340dd9SEd Tanous } 2842f12894f8SJason M. Bills messages::success(asyncResp->res); 2843cc340dd9SEd Tanous }, 2844cc340dd9SEd Tanous "xyz.openbmc_project.State.Host", 2845cc340dd9SEd Tanous "/xyz/openbmc_project/state/host0", 2846cc340dd9SEd Tanous "org.freedesktop.DBus.Properties", "Set", 28479712f8acSEd Tanous "xyz.openbmc_project.State.Host", "RequestedHostTransition", 2848168e20c1SEd Tanous dbus::utility::DbusVariantType{command}); 2849cc340dd9SEd Tanous } 2850d22c8396SJason M. Bills else 2851d22c8396SJason M. Bills { 2852d22c8396SJason M. Bills crow::connections::systemBus->async_method_call( 2853d22c8396SJason M. Bills [asyncResp, resetType](const boost::system::error_code ec) { 2854d22c8396SJason M. Bills if (ec) 2855d22c8396SJason M. Bills { 2856d22c8396SJason M. Bills BMCWEB_LOG_ERROR << "D-Bus responses error: " << ec; 2857002d39b4SEd Tanous if (ec.value() == boost::asio::error::invalid_argument) 2858d22c8396SJason M. Bills { 2859d22c8396SJason M. Bills messages::actionParameterNotSupported( 2860d22c8396SJason M. Bills asyncResp->res, resetType, "Reset"); 2861d22c8396SJason M. Bills } 2862d22c8396SJason M. Bills else 2863d22c8396SJason M. Bills { 2864d22c8396SJason M. Bills messages::internalError(asyncResp->res); 2865d22c8396SJason M. Bills } 2866d22c8396SJason M. Bills return; 2867d22c8396SJason M. Bills } 2868d22c8396SJason M. Bills messages::success(asyncResp->res); 2869d22c8396SJason M. Bills }, 2870d22c8396SJason M. Bills "xyz.openbmc_project.State.Chassis", 2871d22c8396SJason M. Bills "/xyz/openbmc_project/state/chassis0", 2872d22c8396SJason M. Bills "org.freedesktop.DBus.Properties", "Set", 2873002d39b4SEd Tanous "xyz.openbmc_project.State.Chassis", "RequestedPowerTransition", 2874168e20c1SEd Tanous dbus::utility::DbusVariantType{command}); 2875d22c8396SJason M. Bills } 28767e860f15SJohn Edward Broadbent }); 2877d22c8396SJason M. Bills } 2878cc340dd9SEd Tanous 287938c8a6f2SEd Tanous inline void handleComputerSystemCollectionHead( 2880dd60b9edSEd Tanous App& app, const crow::Request& req, 2881dd60b9edSEd Tanous const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) 2882dd60b9edSEd Tanous { 2883dd60b9edSEd Tanous if (!redfish::setUpRedfishRoute(app, req, asyncResp)) 2884dd60b9edSEd Tanous { 2885dd60b9edSEd Tanous return; 2886dd60b9edSEd Tanous } 2887dd60b9edSEd Tanous 2888dd60b9edSEd Tanous asyncResp->res.addHeader( 2889dd60b9edSEd Tanous boost::beast::http::field::link, 2890dd60b9edSEd Tanous "</redfish/v1/JsonSchemas/ComputerSystem/ComputerSystem.json>; rel=describedby"); 2891dd60b9edSEd Tanous } 2892dd60b9edSEd Tanous 2893cc340dd9SEd Tanous /** 28946617338dSEd Tanous * Systems derived class for delivering Computer Systems Schema. 2895c5b2abe0SLewanczyk, Dawid */ 28967e860f15SJohn Edward Broadbent inline void requestRoutesSystems(App& app) 28971abe55efSEd Tanous { 2898c5b2abe0SLewanczyk, Dawid 2899dd60b9edSEd Tanous BMCWEB_ROUTE(app, "/redfish/v1/Systems/system/") 2900dd60b9edSEd Tanous .privileges(redfish::privileges::headComputerSystem) 2901dd60b9edSEd Tanous .methods(boost::beast::http::verb::head)( 2902dd60b9edSEd Tanous std::bind_front(handleComputerSystemCollectionHead, std::ref(app))); 2903c5b2abe0SLewanczyk, Dawid /** 2904c5b2abe0SLewanczyk, Dawid * Functions triggers appropriate requests on DBus 2905c5b2abe0SLewanczyk, Dawid */ 290622d268cbSEd Tanous BMCWEB_ROUTE(app, "/redfish/v1/Systems/<str>/") 2907ed398213SEd Tanous .privileges(redfish::privileges::getComputerSystem) 2908002d39b4SEd Tanous .methods(boost::beast::http::verb::get)( 2909002d39b4SEd Tanous [&app](const crow::Request& req, 291022d268cbSEd Tanous const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 291122d268cbSEd Tanous const std::string& systemName) { 29123ba00073SCarson Labrado if (!redfish::setUpRedfishRoute(app, req, asyncResp)) 291345ca1b86SEd Tanous { 291445ca1b86SEd Tanous return; 291545ca1b86SEd Tanous } 291622d268cbSEd Tanous if (systemName != "system") 291722d268cbSEd Tanous { 291822d268cbSEd Tanous messages::resourceNotFound(asyncResp->res, "ComputerSystem", 291922d268cbSEd Tanous systemName); 292022d268cbSEd Tanous return; 292122d268cbSEd Tanous } 2922dd60b9edSEd Tanous asyncResp->res.addHeader( 2923dd60b9edSEd Tanous boost::beast::http::field::link, 2924dd60b9edSEd Tanous "</redfish/v1/JsonSchemas/ComputerSystem/ComputerSystem.json>; rel=describedby"); 29258d1b46d7Szhanghch05 asyncResp->res.jsonValue["@odata.type"] = 292637bbf98cSChris Cain "#ComputerSystem.v1_16_0.ComputerSystem"; 29278d1b46d7Szhanghch05 asyncResp->res.jsonValue["Name"] = "system"; 29288d1b46d7Szhanghch05 asyncResp->res.jsonValue["Id"] = "system"; 29298d1b46d7Szhanghch05 asyncResp->res.jsonValue["SystemType"] = "Physical"; 29308d1b46d7Szhanghch05 asyncResp->res.jsonValue["Description"] = "Computer System"; 29318d1b46d7Szhanghch05 asyncResp->res.jsonValue["ProcessorSummary"]["Count"] = 0; 29328d1b46d7Szhanghch05 asyncResp->res.jsonValue["ProcessorSummary"]["Status"]["State"] = 29338d1b46d7Szhanghch05 "Disabled"; 29348d1b46d7Szhanghch05 asyncResp->res.jsonValue["MemorySummary"]["TotalSystemMemoryGiB"] = 29358d1b46d7Szhanghch05 uint64_t(0); 29368d1b46d7Szhanghch05 asyncResp->res.jsonValue["MemorySummary"]["Status"]["State"] = 29378d1b46d7Szhanghch05 "Disabled"; 2938002d39b4SEd Tanous asyncResp->res.jsonValue["@odata.id"] = "/redfish/v1/Systems/system"; 293904a258f4SEd Tanous 29401476687dSEd Tanous asyncResp->res.jsonValue["Processors"]["@odata.id"] = 29411476687dSEd Tanous "/redfish/v1/Systems/system/Processors"; 29421476687dSEd Tanous asyncResp->res.jsonValue["Memory"]["@odata.id"] = 29431476687dSEd Tanous "/redfish/v1/Systems/system/Memory"; 29441476687dSEd Tanous asyncResp->res.jsonValue["Storage"]["@odata.id"] = 29451476687dSEd Tanous "/redfish/v1/Systems/system/Storage"; 2946029573d4SEd Tanous 2947002d39b4SEd Tanous asyncResp->res.jsonValue["Actions"]["#ComputerSystem.Reset"]["target"] = 29481476687dSEd Tanous "/redfish/v1/Systems/system/Actions/ComputerSystem.Reset"; 29491476687dSEd Tanous asyncResp->res.jsonValue["Actions"]["#ComputerSystem.Reset"] 29501476687dSEd Tanous ["@Redfish.ActionInfo"] = 29511476687dSEd Tanous "/redfish/v1/Systems/system/ResetActionInfo"; 2952c5b2abe0SLewanczyk, Dawid 29531476687dSEd Tanous asyncResp->res.jsonValue["LogServices"]["@odata.id"] = 29541476687dSEd Tanous "/redfish/v1/Systems/system/LogServices"; 29551476687dSEd Tanous asyncResp->res.jsonValue["Bios"]["@odata.id"] = 29561476687dSEd Tanous "/redfish/v1/Systems/system/Bios"; 2957c4bf6374SJason M. Bills 29581476687dSEd Tanous nlohmann::json::array_t managedBy; 29591476687dSEd Tanous nlohmann::json& manager = managedBy.emplace_back(); 29601476687dSEd Tanous manager["@odata.id"] = "/redfish/v1/Managers/bmc"; 2961002d39b4SEd Tanous asyncResp->res.jsonValue["Links"]["ManagedBy"] = std::move(managedBy); 29621476687dSEd Tanous asyncResp->res.jsonValue["Status"]["Health"] = "OK"; 29631476687dSEd Tanous asyncResp->res.jsonValue["Status"]["State"] = "Enabled"; 29640e8ac5e7SGunnar Mills 29650e8ac5e7SGunnar Mills // Fill in SerialConsole info 2966002d39b4SEd Tanous asyncResp->res.jsonValue["SerialConsole"]["MaxConcurrentSessions"] = 15; 2967002d39b4SEd Tanous asyncResp->res.jsonValue["SerialConsole"]["IPMI"]["ServiceEnabled"] = 2968002d39b4SEd Tanous true; 29691476687dSEd Tanous 29700e8ac5e7SGunnar Mills // TODO (Gunnar): Should look for obmc-console-ssh@2200.service 29711476687dSEd Tanous asyncResp->res.jsonValue["SerialConsole"]["SSH"]["ServiceEnabled"] = 29721476687dSEd Tanous true; 29731476687dSEd Tanous asyncResp->res.jsonValue["SerialConsole"]["SSH"]["Port"] = 2200; 29741476687dSEd Tanous asyncResp->res 29751476687dSEd Tanous .jsonValue["SerialConsole"]["SSH"]["HotKeySequenceDisplay"] = 29761476687dSEd Tanous "Press ~. to exit console"; 29770e8ac5e7SGunnar Mills 29780e8ac5e7SGunnar Mills #ifdef BMCWEB_ENABLE_KVM 29790e8ac5e7SGunnar Mills // Fill in GraphicalConsole info 2980002d39b4SEd Tanous asyncResp->res.jsonValue["GraphicalConsole"]["ServiceEnabled"] = true; 2981002d39b4SEd Tanous asyncResp->res.jsonValue["GraphicalConsole"]["MaxConcurrentSessions"] = 2982002d39b4SEd Tanous 4; 2983613dabeaSEd Tanous asyncResp->res.jsonValue["GraphicalConsole"]["ConnectTypesSupported"] = 2984613dabeaSEd Tanous nlohmann::json::array_t({"KVMIP"}); 29851476687dSEd Tanous 29860e8ac5e7SGunnar Mills #endif // BMCWEB_ENABLE_KVM 2987e284a7c1SJames Feist constexpr const std::array<const char*, 4> inventoryForSystems = { 2988b49ac873SJames Feist "xyz.openbmc_project.Inventory.Item.Dimm", 29892ad9c2f6SJames Feist "xyz.openbmc_project.Inventory.Item.Cpu", 2990e284a7c1SJames Feist "xyz.openbmc_project.Inventory.Item.Drive", 2991e284a7c1SJames Feist "xyz.openbmc_project.Inventory.Item.StorageController"}; 2992b49ac873SJames Feist 2993b49ac873SJames Feist auto health = std::make_shared<HealthPopulate>(asyncResp); 2994b49ac873SJames Feist crow::connections::systemBus->async_method_call( 2995b49ac873SJames Feist [health](const boost::system::error_code ec, 2996914e2d5dSEd Tanous const std::vector<std::string>& resp) { 2997b49ac873SJames Feist if (ec) 2998b49ac873SJames Feist { 2999b49ac873SJames Feist // no inventory 3000b49ac873SJames Feist return; 3001b49ac873SJames Feist } 3002b49ac873SJames Feist 3003914e2d5dSEd Tanous health->inventory = resp; 3004b49ac873SJames Feist }, 3005b49ac873SJames Feist "xyz.openbmc_project.ObjectMapper", 3006b49ac873SJames Feist "/xyz/openbmc_project/object_mapper", 3007b49ac873SJames Feist "xyz.openbmc_project.ObjectMapper", "GetSubTreePaths", "/", 3008b49ac873SJames Feist int32_t(0), inventoryForSystems); 3009b49ac873SJames Feist 3010b49ac873SJames Feist health->populate(); 3011b49ac873SJames Feist 3012002d39b4SEd Tanous getMainChassisId(asyncResp, 3013002d39b4SEd Tanous [](const std::string& chassisId, 30148d1b46d7Szhanghch05 const std::shared_ptr<bmcweb::AsyncResp>& aRsp) { 3015b2c7e208SEd Tanous nlohmann::json::array_t chassisArray; 3016b2c7e208SEd Tanous nlohmann::json& chassis = chassisArray.emplace_back(); 3017b2c7e208SEd Tanous chassis["@odata.id"] = "/redfish/v1/Chassis/" + chassisId; 3018002d39b4SEd Tanous aRsp->res.jsonValue["Links"]["Chassis"] = std::move(chassisArray); 3019c5d03ff4SJennifer Lee }); 3020a3002228SAppaRao Puli 30219f8bfa7cSGunnar Mills getLocationIndicatorActive(asyncResp); 30229f8bfa7cSGunnar Mills // TODO (Gunnar): Remove IndicatorLED after enough time has passed 3023a3002228SAppaRao Puli getIndicatorLedState(asyncResp); 30245bc2dc8eSJames Feist getComputerSystem(asyncResp, health); 30256c34de48SEd Tanous getHostState(asyncResp); 3026491d8ee7SSantosh Puranik getBootProperties(asyncResp); 3027978b8803SAndrew Geissler getBootProgress(asyncResp); 3028*b6d5d45cSHieu Huynh getBootProgressLastStateTime(asyncResp); 3029adbe192aSJason M. Bills getPCIeDeviceList(asyncResp, "PCIeDevices"); 303051709ffdSYong Li getHostWatchdogTimer(asyncResp); 3031c6a620f2SGeorge Liu getPowerRestorePolicy(asyncResp); 30326bd5a8d2SGunnar Mills getAutomaticRetry(asyncResp); 3033c0557e1aSGunnar Mills getLastResetTime(asyncResp); 3034a6349918SAppaRao Puli #ifdef BMCWEB_ENABLE_REDFISH_PROVISIONING_FEATURE 3035a6349918SAppaRao Puli getProvisioningStatus(asyncResp); 3036a6349918SAppaRao Puli #endif 30371981771bSAli Ahmed getTrustedModuleRequiredToBoot(asyncResp); 30383a2d0424SChris Cain getPowerMode(asyncResp); 303937bbf98cSChris Cain getIdlePowerSaver(asyncResp); 30407e860f15SJohn Edward Broadbent }); 3041550a6bf8SJiaqing Zhao 304222d268cbSEd Tanous BMCWEB_ROUTE(app, "/redfish/v1/Systems/<str>/") 3043ed398213SEd Tanous .privileges(redfish::privileges::patchComputerSystem) 30447e860f15SJohn Edward Broadbent .methods(boost::beast::http::verb::patch)( 304545ca1b86SEd Tanous [&app](const crow::Request& req, 304622d268cbSEd Tanous const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 304722d268cbSEd Tanous const std::string& systemName) { 30483ba00073SCarson Labrado if (!redfish::setUpRedfishRoute(app, req, asyncResp)) 304945ca1b86SEd Tanous { 305045ca1b86SEd Tanous return; 305145ca1b86SEd Tanous } 305222d268cbSEd Tanous if (systemName != "system") 305322d268cbSEd Tanous { 305422d268cbSEd Tanous messages::resourceNotFound(asyncResp->res, "ComputerSystem", 305522d268cbSEd Tanous systemName); 305622d268cbSEd Tanous return; 305722d268cbSEd Tanous } 305822d268cbSEd Tanous 3059dd60b9edSEd Tanous asyncResp->res.addHeader( 3060dd60b9edSEd Tanous boost::beast::http::field::link, 3061dd60b9edSEd Tanous "</redfish/v1/JsonSchemas/ComputerSystem/ComputerSystem.json>; rel=describedby"); 3062dd60b9edSEd Tanous 30639f8bfa7cSGunnar Mills std::optional<bool> locationIndicatorActive; 3064cde19e5fSSantosh Puranik std::optional<std::string> indicatorLed; 306598e386ecSGunnar Mills std::optional<std::string> assetTag; 3066c6a620f2SGeorge Liu std::optional<std::string> powerRestorePolicy; 30673a2d0424SChris Cain std::optional<std::string> powerMode; 3068550a6bf8SJiaqing Zhao std::optional<bool> wdtEnable; 3069550a6bf8SJiaqing Zhao std::optional<std::string> wdtTimeOutAction; 3070550a6bf8SJiaqing Zhao std::optional<std::string> bootSource; 3071550a6bf8SJiaqing Zhao std::optional<std::string> bootType; 3072550a6bf8SJiaqing Zhao std::optional<std::string> bootEnable; 3073550a6bf8SJiaqing Zhao std::optional<std::string> bootAutomaticRetry; 3074550a6bf8SJiaqing Zhao std::optional<bool> bootTrustedModuleRequired; 3075550a6bf8SJiaqing Zhao std::optional<bool> ipsEnable; 3076550a6bf8SJiaqing Zhao std::optional<uint8_t> ipsEnterUtil; 3077550a6bf8SJiaqing Zhao std::optional<uint64_t> ipsEnterTime; 3078550a6bf8SJiaqing Zhao std::optional<uint8_t> ipsExitUtil; 3079550a6bf8SJiaqing Zhao std::optional<uint64_t> ipsExitTime; 3080550a6bf8SJiaqing Zhao 3081550a6bf8SJiaqing Zhao // clang-format off 308215ed6780SWilly Tu if (!json_util::readJsonPatch( 3083550a6bf8SJiaqing Zhao req, asyncResp->res, 3084550a6bf8SJiaqing Zhao "IndicatorLED", indicatorLed, 30857e860f15SJohn Edward Broadbent "LocationIndicatorActive", locationIndicatorActive, 3086550a6bf8SJiaqing Zhao "AssetTag", assetTag, 3087550a6bf8SJiaqing Zhao "PowerRestorePolicy", powerRestorePolicy, 3088550a6bf8SJiaqing Zhao "PowerMode", powerMode, 3089550a6bf8SJiaqing Zhao "HostWatchdogTimer/FunctionEnabled", wdtEnable, 3090550a6bf8SJiaqing Zhao "HostWatchdogTimer/TimeoutAction", wdtTimeOutAction, 3091550a6bf8SJiaqing Zhao "Boot/BootSourceOverrideTarget", bootSource, 3092550a6bf8SJiaqing Zhao "Boot/BootSourceOverrideMode", bootType, 3093550a6bf8SJiaqing Zhao "Boot/BootSourceOverrideEnabled", bootEnable, 3094550a6bf8SJiaqing Zhao "Boot/AutomaticRetryConfig", bootAutomaticRetry, 3095550a6bf8SJiaqing Zhao "Boot/TrustedModuleRequiredToBoot", bootTrustedModuleRequired, 3096550a6bf8SJiaqing Zhao "IdlePowerSaver/Enabled", ipsEnable, 3097550a6bf8SJiaqing Zhao "IdlePowerSaver/EnterUtilizationPercent", ipsEnterUtil, 3098550a6bf8SJiaqing Zhao "IdlePowerSaver/EnterDwellTimeSeconds", ipsEnterTime, 3099550a6bf8SJiaqing Zhao "IdlePowerSaver/ExitUtilizationPercent", ipsExitUtil, 3100550a6bf8SJiaqing Zhao "IdlePowerSaver/ExitDwellTimeSeconds", ipsExitTime)) 31016617338dSEd Tanous { 31026617338dSEd Tanous return; 31036617338dSEd Tanous } 3104550a6bf8SJiaqing Zhao // clang-format on 3105491d8ee7SSantosh Puranik 31068d1b46d7Szhanghch05 asyncResp->res.result(boost::beast::http::status::no_content); 3107c45f0082SYong Li 310898e386ecSGunnar Mills if (assetTag) 310998e386ecSGunnar Mills { 311098e386ecSGunnar Mills setAssetTag(asyncResp, *assetTag); 311198e386ecSGunnar Mills } 311298e386ecSGunnar Mills 3113550a6bf8SJiaqing Zhao if (wdtEnable || wdtTimeOutAction) 3114c45f0082SYong Li { 3115f23b7296SEd Tanous setWDTProperties(asyncResp, wdtEnable, wdtTimeOutAction); 3116c45f0082SYong Li } 3117c45f0082SYong Li 3118cd9a4666SKonstantin Aladyshev if (bootSource || bootType || bootEnable) 311969f35306SGunnar Mills { 3120002d39b4SEd Tanous setBootProperties(asyncResp, bootSource, bootType, bootEnable); 3121491d8ee7SSantosh Puranik } 3122550a6bf8SJiaqing Zhao if (bootAutomaticRetry) 312369f35306SGunnar Mills { 3124550a6bf8SJiaqing Zhao setAutomaticRetry(asyncResp, *bootAutomaticRetry); 312569f35306SGunnar Mills } 3126ac7e1e0bSAli Ahmed 3127550a6bf8SJiaqing Zhao if (bootTrustedModuleRequired) 3128ac7e1e0bSAli Ahmed { 3129550a6bf8SJiaqing Zhao setTrustedModuleRequiredToBoot(asyncResp, 3130550a6bf8SJiaqing Zhao *bootTrustedModuleRequired); 313169f35306SGunnar Mills } 3132265c1602SJohnathan Mantey 31339f8bfa7cSGunnar Mills if (locationIndicatorActive) 31349f8bfa7cSGunnar Mills { 3135002d39b4SEd Tanous setLocationIndicatorActive(asyncResp, *locationIndicatorActive); 31369f8bfa7cSGunnar Mills } 31379f8bfa7cSGunnar Mills 31387e860f15SJohn Edward Broadbent // TODO (Gunnar): Remove IndicatorLED after enough time has 31397e860f15SJohn Edward Broadbent // passed 31409712f8acSEd Tanous if (indicatorLed) 31416617338dSEd Tanous { 3142f23b7296SEd Tanous setIndicatorLedState(asyncResp, *indicatorLed); 3143002d39b4SEd Tanous asyncResp->res.addHeader(boost::beast::http::field::warning, 3144d6aa0093SGunnar Mills "299 - \"IndicatorLED is deprecated. Use " 3145d6aa0093SGunnar Mills "LocationIndicatorActive instead.\""); 31466617338dSEd Tanous } 3147c6a620f2SGeorge Liu 3148c6a620f2SGeorge Liu if (powerRestorePolicy) 3149c6a620f2SGeorge Liu { 31504e69c904SGunnar Mills setPowerRestorePolicy(asyncResp, *powerRestorePolicy); 3151c6a620f2SGeorge Liu } 31523a2d0424SChris Cain 31533a2d0424SChris Cain if (powerMode) 31543a2d0424SChris Cain { 31553a2d0424SChris Cain setPowerMode(asyncResp, *powerMode); 31563a2d0424SChris Cain } 315737bbf98cSChris Cain 3158550a6bf8SJiaqing Zhao if (ipsEnable || ipsEnterUtil || ipsEnterTime || ipsExitUtil || 3159550a6bf8SJiaqing Zhao ipsExitTime) 316037bbf98cSChris Cain { 3161002d39b4SEd Tanous setIdlePowerSaver(asyncResp, ipsEnable, ipsEnterUtil, ipsEnterTime, 3162002d39b4SEd Tanous ipsExitUtil, ipsExitTime); 316337bbf98cSChris Cain } 31647e860f15SJohn Edward Broadbent }); 3165c5b2abe0SLewanczyk, Dawid } 31661cb1a9e6SAppaRao Puli 316738c8a6f2SEd Tanous inline void handleSystemCollectionResetActionHead( 3168dd60b9edSEd Tanous crow::App& app, const crow::Request& req, 3169dd60b9edSEd Tanous const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) 3170dd60b9edSEd Tanous { 3171dd60b9edSEd Tanous if (!redfish::setUpRedfishRoute(app, req, asyncResp)) 3172dd60b9edSEd Tanous { 3173dd60b9edSEd Tanous return; 3174dd60b9edSEd Tanous } 3175dd60b9edSEd Tanous asyncResp->res.addHeader( 3176dd60b9edSEd Tanous boost::beast::http::field::link, 3177dd60b9edSEd Tanous "</redfish/v1/JsonSchemas/ActionInfo/ActionInfo.json>; rel=describedby"); 3178dd60b9edSEd Tanous } 3179dd60b9edSEd Tanous 31801cb1a9e6SAppaRao Puli /** 31811cb1a9e6SAppaRao Puli * SystemResetActionInfo derived class for delivering Computer Systems 31821cb1a9e6SAppaRao Puli * ResetType AllowableValues using ResetInfo schema. 31831cb1a9e6SAppaRao Puli */ 31847e860f15SJohn Edward Broadbent inline void requestRoutesSystemResetActionInfo(App& app) 31851cb1a9e6SAppaRao Puli { 3186dd60b9edSEd Tanous BMCWEB_ROUTE(app, "/redfish/v1/Systems/system/ResetActionInfo/") 3187dd60b9edSEd Tanous .privileges(redfish::privileges::headActionInfo) 3188dd60b9edSEd Tanous .methods(boost::beast::http::verb::head)(std::bind_front( 3189dd60b9edSEd Tanous handleSystemCollectionResetActionHead, std::ref(app))); 31901cb1a9e6SAppaRao Puli /** 31911cb1a9e6SAppaRao Puli * Functions triggers appropriate requests on DBus 31921cb1a9e6SAppaRao Puli */ 319322d268cbSEd Tanous BMCWEB_ROUTE(app, "/redfish/v1/Systems/<str>/ResetActionInfo/") 3194ed398213SEd Tanous .privileges(redfish::privileges::getActionInfo) 31957e860f15SJohn Edward Broadbent .methods(boost::beast::http::verb::get)( 319645ca1b86SEd Tanous [&app](const crow::Request& req, 319722d268cbSEd Tanous const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 319822d268cbSEd Tanous const std::string& systemName) { 31993ba00073SCarson Labrado if (!redfish::setUpRedfishRoute(app, req, asyncResp)) 320045ca1b86SEd Tanous { 320145ca1b86SEd Tanous return; 320245ca1b86SEd Tanous } 320322d268cbSEd Tanous if (systemName != "system") 320422d268cbSEd Tanous { 320522d268cbSEd Tanous messages::resourceNotFound(asyncResp->res, "ComputerSystem", 320622d268cbSEd Tanous systemName); 320722d268cbSEd Tanous return; 320822d268cbSEd Tanous } 320922d268cbSEd Tanous 3210dd60b9edSEd Tanous asyncResp->res.addHeader( 3211dd60b9edSEd Tanous boost::beast::http::field::link, 3212dd60b9edSEd Tanous "</redfish/v1/JsonSchemas/ActionInfo/ActionInfo.json>; rel=describedby"); 32131476687dSEd Tanous 32141476687dSEd Tanous asyncResp->res.jsonValue["@odata.id"] = 32151476687dSEd Tanous "/redfish/v1/Systems/system/ResetActionInfo"; 32161476687dSEd Tanous asyncResp->res.jsonValue["@odata.type"] = 32171476687dSEd Tanous "#ActionInfo.v1_1_2.ActionInfo"; 32181476687dSEd Tanous asyncResp->res.jsonValue["Name"] = "Reset Action Info"; 32191476687dSEd Tanous asyncResp->res.jsonValue["Id"] = "ResetActionInfo"; 32203215e700SNan Zhou 32213215e700SNan Zhou nlohmann::json::array_t parameters; 32223215e700SNan Zhou nlohmann::json::object_t parameter; 32233215e700SNan Zhou 32243215e700SNan Zhou parameter["Name"] = "ResetType"; 32253215e700SNan Zhou parameter["Required"] = true; 32263215e700SNan Zhou parameter["DataType"] = "String"; 32273215e700SNan Zhou nlohmann::json::array_t allowableValues; 32283215e700SNan Zhou allowableValues.emplace_back("On"); 32293215e700SNan Zhou allowableValues.emplace_back("ForceOff"); 32303215e700SNan Zhou allowableValues.emplace_back("ForceOn"); 32313215e700SNan Zhou allowableValues.emplace_back("ForceRestart"); 32323215e700SNan Zhou allowableValues.emplace_back("GracefulRestart"); 32333215e700SNan Zhou allowableValues.emplace_back("GracefulShutdown"); 32343215e700SNan Zhou allowableValues.emplace_back("PowerCycle"); 32353215e700SNan Zhou allowableValues.emplace_back("Nmi"); 32363215e700SNan Zhou parameter["AllowableValues"] = std::move(allowableValues); 32373215e700SNan Zhou parameters.emplace_back(std::move(parameter)); 32383215e700SNan Zhou 32393215e700SNan Zhou asyncResp->res.jsonValue["Parameters"] = std::move(parameters); 32407e860f15SJohn Edward Broadbent }); 32411cb1a9e6SAppaRao Puli } 3242c5b2abe0SLewanczyk, Dawid } // namespace redfish 3243