140e9b92eSEd Tanous // SPDX-License-Identifier: Apache-2.0 240e9b92eSEd Tanous // SPDX-FileCopyrightText: Copyright OpenBMC Authors 340e9b92eSEd Tanous // SPDX-FileCopyrightText: Copyright 2018 Intel Corporation 4c5b2abe0SLewanczyk, Dawid #pragma once 5c5b2abe0SLewanczyk, Dawid 613451e39SWilly Tu #include "bmcweb_config.h" 713451e39SWilly Tu 83ccb3adbSEd Tanous #include "app.hpp" 9d7857201SEd Tanous #include "async_resp.hpp" 101e1e598dSJonathan Doman #include "dbus_singleton.hpp" 117a1dbc48SGeorge Liu #include "dbus_utility.hpp" 12d7857201SEd Tanous #include "error_messages.hpp" 13539d8c6bSEd Tanous #include "generated/enums/action_info.hpp" 148d69c668SEd Tanous #include "generated/enums/computer_system.hpp" 15539d8c6bSEd Tanous #include "generated/enums/open_bmc_computer_system.hpp" 1633e1f122SAndrew Geissler #include "generated/enums/resource.hpp" 17d7857201SEd Tanous #include "http_request.hpp" 18746b56f3SAsmitha Karunanithi #include "hypervisor_system.hpp" 191c8fba97SJames Feist #include "led.hpp" 20d7857201SEd Tanous #include "logging.hpp" 21f4c99e70SEd Tanous #include "query.hpp" 22c5d03ff4SJennifer Lee #include "redfish_util.hpp" 233ccb3adbSEd Tanous #include "registries/privilege_registry.hpp" 243ccb3adbSEd Tanous #include "utils/dbus_utils.hpp" 253ccb3adbSEd Tanous #include "utils/json_utils.hpp" 26472bd202SLakshmi Yadlapati #include "utils/pcie_util.hpp" 273ccb3adbSEd Tanous #include "utils/sw_utils.hpp" 28fc5ae94dSOliver Brewka #include "utils/systems_utils.hpp" 292b82937eSEd Tanous #include "utils/time_utils.hpp" 30c5d03ff4SJennifer Lee 31d7857201SEd Tanous #include <asm-generic/errno.h> 32d7857201SEd Tanous 33fc903b3dSAndrew Geissler #include <boost/asio/error.hpp> 34d7857201SEd Tanous #include <boost/beast/http/field.hpp> 35d7857201SEd Tanous #include <boost/beast/http/status.hpp> 36d7857201SEd Tanous #include <boost/beast/http/verb.hpp> 37e99073f5SGeorge Liu #include <boost/system/error_code.hpp> 3833e1f122SAndrew Geissler #include <boost/system/linux_error.hpp> 39ef4c65b7SEd Tanous #include <boost/url/format.hpp> 40d7857201SEd Tanous #include <nlohmann/json.hpp> 41d7857201SEd Tanous #include <sdbusplus/message/native_types.hpp> 42bc1d29deSKrzysztof Grobelny #include <sdbusplus/unpack_properties.hpp> 431214b7e7SGunnar Mills 447a1dbc48SGeorge Liu #include <array> 45d7857201SEd Tanous #include <chrono> 46d7857201SEd Tanous #include <cstddef> 47d7857201SEd Tanous #include <cstdint> 48d7857201SEd Tanous #include <functional> 4933e1f122SAndrew Geissler #include <memory> 50d7857201SEd Tanous #include <optional> 51d7857201SEd Tanous #include <ratio> 526b9ac4f2SChris Cain #include <string> 537a1dbc48SGeorge Liu #include <string_view> 54d7857201SEd Tanous #include <tuple> 5520fa6a2cSEd Tanous #include <utility> 566b9ac4f2SChris Cain #include <vector> 57c5b2abe0SLewanczyk, Dawid 581abe55efSEd Tanous namespace redfish 591abe55efSEd Tanous { 60c5b2abe0SLewanczyk, Dawid 615c3e9272SAbhishek Patel const static std::array<std::pair<std::string_view, std::string_view>, 2> 625c3e9272SAbhishek Patel protocolToDBusForSystems{ 635c3e9272SAbhishek Patel {{"SSH", "obmc-console-ssh"}, {"IPMI", "phosphor-ipmi-net"}}}; 645c3e9272SAbhishek Patel 659d3ae10eSAlpana Kumari /** 669d3ae10eSAlpana Kumari * @brief Updates the Functional State of DIMMs 679d3ae10eSAlpana Kumari * 68ac106bf6SEd Tanous * @param[in] asyncResp Shared pointer for completing asynchronous calls 699d3ae10eSAlpana Kumari * @param[in] dimmState Dimm's Functional state, true/false 709d3ae10eSAlpana Kumari * 719d3ae10eSAlpana Kumari * @return None. 729d3ae10eSAlpana Kumari */ 73bd79bce8SPatrick Williams inline void updateDimmProperties( 74bd79bce8SPatrick Williams const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, bool isDimmFunctional) 759d3ae10eSAlpana Kumari { 7662598e31SEd Tanous BMCWEB_LOG_DEBUG("Dimm Functional: {}", isDimmFunctional); 779d3ae10eSAlpana Kumari 789d3ae10eSAlpana Kumari // Set it as Enabled if at least one DIMM is functional 799d3ae10eSAlpana Kumari // Update STATE only if previous State was DISABLED and current Dimm is 809d3ae10eSAlpana Kumari // ENABLED. 8102cad96eSEd Tanous const nlohmann::json& prevMemSummary = 82ac106bf6SEd Tanous asyncResp->res.jsonValue["MemorySummary"]["Status"]["State"]; 839d3ae10eSAlpana Kumari if (prevMemSummary == "Disabled") 849d3ae10eSAlpana Kumari { 85e05aec50SEd Tanous if (isDimmFunctional) 869d3ae10eSAlpana Kumari { 87ac106bf6SEd Tanous asyncResp->res.jsonValue["MemorySummary"]["Status"]["State"] = 889d3ae10eSAlpana Kumari "Enabled"; 899d3ae10eSAlpana Kumari } 909d3ae10eSAlpana Kumari } 919d3ae10eSAlpana Kumari } 929d3ae10eSAlpana Kumari 9357e8c9beSAlpana Kumari /* 9457e8c9beSAlpana Kumari * @brief Update "ProcessorSummary" "Status" "State" based on 9557e8c9beSAlpana Kumari * CPU Functional State 9657e8c9beSAlpana Kumari * 97ac106bf6SEd Tanous * @param[in] asyncResp Shared pointer for completing asynchronous calls 9857e8c9beSAlpana Kumari * @param[in] cpuFunctionalState is CPU functional true/false 9957e8c9beSAlpana Kumari * 10057e8c9beSAlpana Kumari * @return None. 10157e8c9beSAlpana Kumari */ 102ac106bf6SEd Tanous inline void modifyCpuFunctionalState( 103ac106bf6SEd Tanous const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, bool isCpuFunctional) 10457e8c9beSAlpana Kumari { 10562598e31SEd Tanous BMCWEB_LOG_DEBUG("Cpu Functional: {}", isCpuFunctional); 10657e8c9beSAlpana Kumari 10702cad96eSEd Tanous const nlohmann::json& prevProcState = 108ac106bf6SEd Tanous asyncResp->res.jsonValue["ProcessorSummary"]["Status"]["State"]; 10957e8c9beSAlpana Kumari 11057e8c9beSAlpana Kumari // Set it as Enabled if at least one CPU is functional 11157e8c9beSAlpana Kumari // Update STATE only if previous State was Non_Functional and current CPU is 11257e8c9beSAlpana Kumari // Functional. 11357e8c9beSAlpana Kumari if (prevProcState == "Disabled") 11457e8c9beSAlpana Kumari { 115e05aec50SEd Tanous if (isCpuFunctional) 11657e8c9beSAlpana Kumari { 117ac106bf6SEd Tanous asyncResp->res.jsonValue["ProcessorSummary"]["Status"]["State"] = 11857e8c9beSAlpana Kumari "Enabled"; 11957e8c9beSAlpana Kumari } 12057e8c9beSAlpana Kumari } 12157e8c9beSAlpana Kumari } 12257e8c9beSAlpana Kumari 123cf0e004cSNinad Palsule /* 124cf0e004cSNinad Palsule * @brief Update "ProcessorSummary" "Count" based on Cpu PresenceState 125cf0e004cSNinad Palsule * 126ac106bf6SEd Tanous * @param[in] asyncResp Shared pointer for completing asynchronous calls 127cf0e004cSNinad Palsule * @param[in] cpuPresenceState CPU present or not 128cf0e004cSNinad Palsule * 129cf0e004cSNinad Palsule * @return None. 130cf0e004cSNinad Palsule */ 131bd79bce8SPatrick Williams inline void modifyCpuPresenceState( 132bd79bce8SPatrick Williams const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, bool isCpuPresent) 133cf0e004cSNinad Palsule { 13462598e31SEd Tanous BMCWEB_LOG_DEBUG("Cpu Present: {}", isCpuPresent); 135cf0e004cSNinad Palsule 136cf0e004cSNinad Palsule if (isCpuPresent) 137cf0e004cSNinad Palsule { 138cf0e004cSNinad Palsule nlohmann::json& procCount = 139ac106bf6SEd Tanous asyncResp->res.jsonValue["ProcessorSummary"]["Count"]; 140cf0e004cSNinad Palsule auto* procCountPtr = 141cf0e004cSNinad Palsule procCount.get_ptr<nlohmann::json::number_integer_t*>(); 142cf0e004cSNinad Palsule if (procCountPtr != nullptr) 143cf0e004cSNinad Palsule { 144cf0e004cSNinad Palsule // shouldn't be possible to be nullptr 145cf0e004cSNinad Palsule *procCountPtr += 1; 146cf0e004cSNinad Palsule } 147cf0e004cSNinad Palsule } 148cf0e004cSNinad Palsule } 149cf0e004cSNinad Palsule 150382d6475SAli Ahmed inline void getProcessorProperties( 151ac106bf6SEd Tanous const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 152382d6475SAli Ahmed const std::vector<std::pair<std::string, dbus::utility::DbusVariantType>>& 153382d6475SAli Ahmed properties) 15403fbed92SAli Ahmed { 15562598e31SEd Tanous BMCWEB_LOG_DEBUG("Got {} Cpu properties.", properties.size()); 15603fbed92SAli Ahmed 15703fbed92SAli Ahmed // TODO: Get Model 15803fbed92SAli Ahmed 159bc1d29deSKrzysztof Grobelny const uint16_t* coreCount = nullptr; 16003fbed92SAli Ahmed 161bc1d29deSKrzysztof Grobelny const bool success = sdbusplus::unpackPropertiesNoThrow( 162bc1d29deSKrzysztof Grobelny dbus_utils::UnpackErrorPrinter(), properties, "CoreCount", coreCount); 16303fbed92SAli Ahmed 164bc1d29deSKrzysztof Grobelny if (!success) 16503fbed92SAli Ahmed { 166ac106bf6SEd Tanous messages::internalError(asyncResp->res); 16703fbed92SAli Ahmed return; 16803fbed92SAli Ahmed } 16903fbed92SAli Ahmed 170bc1d29deSKrzysztof Grobelny if (coreCount != nullptr) 17103fbed92SAli Ahmed { 172bc1d29deSKrzysztof Grobelny nlohmann::json& coreCountJson = 173ac106bf6SEd Tanous asyncResp->res.jsonValue["ProcessorSummary"]["CoreCount"]; 174bc1d29deSKrzysztof Grobelny uint64_t* coreCountJsonPtr = coreCountJson.get_ptr<uint64_t*>(); 175bc1d29deSKrzysztof Grobelny 176bc1d29deSKrzysztof Grobelny if (coreCountJsonPtr == nullptr) 177bc1d29deSKrzysztof Grobelny { 178bc1d29deSKrzysztof Grobelny coreCountJson = *coreCount; 17903fbed92SAli Ahmed } 18003fbed92SAli Ahmed else 18103fbed92SAli Ahmed { 182bc1d29deSKrzysztof Grobelny *coreCountJsonPtr += *coreCount; 18303fbed92SAli Ahmed } 18403fbed92SAli Ahmed } 18503fbed92SAli Ahmed } 18603fbed92SAli Ahmed 18703fbed92SAli Ahmed /* 18803fbed92SAli Ahmed * @brief Get ProcessorSummary fields 18903fbed92SAli Ahmed * 190ac106bf6SEd Tanous * @param[in] asyncResp Shared pointer for completing asynchronous calls 19103fbed92SAli Ahmed * @param[in] service dbus service for Cpu Information 19203fbed92SAli Ahmed * @param[in] path dbus path for Cpu 19303fbed92SAli Ahmed * 19403fbed92SAli Ahmed * @return None. 19503fbed92SAli Ahmed */ 196504af5a0SPatrick Williams inline void getProcessorSummary( 197504af5a0SPatrick Williams const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 198ac106bf6SEd Tanous const std::string& service, const std::string& path) 19903fbed92SAli Ahmed { 200ac106bf6SEd Tanous auto getCpuPresenceState = [asyncResp](const boost::system::error_code& ec3, 201382d6475SAli Ahmed const bool cpuPresenceCheck) { 202382d6475SAli Ahmed if (ec3) 203382d6475SAli Ahmed { 20462598e31SEd Tanous BMCWEB_LOG_ERROR("DBUS response error {}", ec3); 205382d6475SAli Ahmed return; 206382d6475SAli Ahmed } 207ac106bf6SEd Tanous modifyCpuPresenceState(asyncResp, cpuPresenceCheck); 208382d6475SAli Ahmed }; 209382d6475SAli Ahmed 210cf0e004cSNinad Palsule // Get the Presence of CPU 211deae6a78SEd Tanous dbus::utility::getProperty<bool>(*crow::connections::systemBus, service, 212deae6a78SEd Tanous path, "xyz.openbmc_project.Inventory.Item", 213deae6a78SEd Tanous "Present", std::move(getCpuPresenceState)); 214cf0e004cSNinad Palsule 215deae6a78SEd Tanous dbus::utility::getAllProperties( 216deae6a78SEd Tanous service, path, "xyz.openbmc_project.Inventory.Item.Cpu", 217ac106bf6SEd Tanous [asyncResp, service, 2185e7e2dc5SEd Tanous path](const boost::system::error_code& ec2, 219b9d36b47SEd Tanous const dbus::utility::DBusPropertiesMap& properties) { 22003fbed92SAli Ahmed if (ec2) 22103fbed92SAli Ahmed { 22262598e31SEd Tanous BMCWEB_LOG_ERROR("DBUS response error {}", ec2); 223ac106bf6SEd Tanous messages::internalError(asyncResp->res); 22403fbed92SAli Ahmed return; 22503fbed92SAli Ahmed } 226ac106bf6SEd Tanous getProcessorProperties(asyncResp, properties); 227bc1d29deSKrzysztof Grobelny }); 22803fbed92SAli Ahmed } 22903fbed92SAli Ahmed 23057e8c9beSAlpana Kumari /* 231cf0e004cSNinad Palsule * @brief processMemoryProperties fields 232cf0e004cSNinad Palsule * 233ac106bf6SEd Tanous * @param[in] asyncResp Shared pointer for completing asynchronous calls 234cf0e004cSNinad Palsule * @param[in] DBUS properties for memory 235cf0e004cSNinad Palsule * 236cf0e004cSNinad Palsule * @return None. 237cf0e004cSNinad Palsule */ 238504af5a0SPatrick Williams inline void processMemoryProperties( 239504af5a0SPatrick Williams const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 240cf0e004cSNinad Palsule const dbus::utility::DBusPropertiesMap& properties) 241cf0e004cSNinad Palsule { 24262598e31SEd Tanous BMCWEB_LOG_DEBUG("Got {} Dimm properties.", properties.size()); 243cf0e004cSNinad Palsule 244cf0e004cSNinad Palsule if (properties.empty()) 245cf0e004cSNinad Palsule { 246cf0e004cSNinad Palsule return; 247cf0e004cSNinad Palsule } 248cf0e004cSNinad Palsule 249cf0e004cSNinad Palsule const size_t* memorySizeInKB = nullptr; 250cf0e004cSNinad Palsule 251cf0e004cSNinad Palsule const bool success = sdbusplus::unpackPropertiesNoThrow( 252cf0e004cSNinad Palsule dbus_utils::UnpackErrorPrinter(), properties, "MemorySizeInKB", 253cf0e004cSNinad Palsule memorySizeInKB); 254cf0e004cSNinad Palsule 255cf0e004cSNinad Palsule if (!success) 256cf0e004cSNinad Palsule { 257ac106bf6SEd Tanous messages::internalError(asyncResp->res); 258cf0e004cSNinad Palsule return; 259cf0e004cSNinad Palsule } 260cf0e004cSNinad Palsule 261cf0e004cSNinad Palsule if (memorySizeInKB != nullptr) 262cf0e004cSNinad Palsule { 263cf0e004cSNinad Palsule nlohmann::json& totalMemory = 264ac106bf6SEd Tanous asyncResp->res.jsonValue["MemorySummary"]["TotalSystemMemoryGiB"]; 265dfb2b408SPriyanga Ramasamy const double* preValue = totalMemory.get_ptr<const double*>(); 266cf0e004cSNinad Palsule if (preValue == nullptr) 267cf0e004cSNinad Palsule { 268ac106bf6SEd Tanous asyncResp->res.jsonValue["MemorySummary"]["TotalSystemMemoryGiB"] = 269dfb2b408SPriyanga Ramasamy static_cast<double>(*memorySizeInKB) / (1024 * 1024); 270cf0e004cSNinad Palsule } 271cf0e004cSNinad Palsule else 272cf0e004cSNinad Palsule { 273ac106bf6SEd Tanous asyncResp->res.jsonValue["MemorySummary"]["TotalSystemMemoryGiB"] = 274dfb2b408SPriyanga Ramasamy static_cast<double>(*memorySizeInKB) / (1024 * 1024) + 275dfb2b408SPriyanga Ramasamy *preValue; 276cf0e004cSNinad Palsule } 277cf0e004cSNinad Palsule } 278cf0e004cSNinad Palsule } 279cf0e004cSNinad Palsule 280cf0e004cSNinad Palsule /* 281cf0e004cSNinad Palsule * @brief Get getMemorySummary fields 282cf0e004cSNinad Palsule * 283ac106bf6SEd Tanous * @param[in] asyncResp Shared pointer for completing asynchronous calls 284cf0e004cSNinad Palsule * @param[in] service dbus service for memory Information 285cf0e004cSNinad Palsule * @param[in] path dbus path for memory 286cf0e004cSNinad Palsule * 287cf0e004cSNinad Palsule * @return None. 288cf0e004cSNinad Palsule */ 289504af5a0SPatrick Williams inline void getMemorySummary( 290504af5a0SPatrick Williams const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 291ac106bf6SEd Tanous const std::string& service, const std::string& path) 292cf0e004cSNinad Palsule { 293deae6a78SEd Tanous dbus::utility::getAllProperties( 294deae6a78SEd Tanous service, path, "xyz.openbmc_project.Inventory.Item.Dimm", 295ac106bf6SEd Tanous [asyncResp, service, 296cf0e004cSNinad Palsule path](const boost::system::error_code& ec2, 297cf0e004cSNinad Palsule const dbus::utility::DBusPropertiesMap& properties) { 298cf0e004cSNinad Palsule if (ec2) 299cf0e004cSNinad Palsule { 30062598e31SEd Tanous BMCWEB_LOG_ERROR("DBUS response error {}", ec2); 301ac106bf6SEd Tanous messages::internalError(asyncResp->res); 302cf0e004cSNinad Palsule return; 303cf0e004cSNinad Palsule } 30451bd2d8aSGunnar Mills processMemoryProperties(asyncResp, properties); 305cf0e004cSNinad Palsule }); 306cf0e004cSNinad Palsule } 307cf0e004cSNinad Palsule 308a974c132SLakshmi Yadlapati inline void afterGetUUID(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 309a974c132SLakshmi Yadlapati const boost::system::error_code& ec, 310a974c132SLakshmi Yadlapati const dbus::utility::DBusPropertiesMap& properties) 3111abe55efSEd Tanous { 312a974c132SLakshmi Yadlapati if (ec) 313a974c132SLakshmi Yadlapati { 314a974c132SLakshmi Yadlapati BMCWEB_LOG_ERROR("DBUS response error {}", ec); 315a974c132SLakshmi Yadlapati messages::internalError(asyncResp->res); 316a974c132SLakshmi Yadlapati return; 317a974c132SLakshmi Yadlapati } 318a974c132SLakshmi Yadlapati BMCWEB_LOG_DEBUG("Got {} UUID properties.", properties.size()); 319a974c132SLakshmi Yadlapati 320a974c132SLakshmi Yadlapati const std::string* uUID = nullptr; 321a974c132SLakshmi Yadlapati 322a974c132SLakshmi Yadlapati const bool success = sdbusplus::unpackPropertiesNoThrow( 323a974c132SLakshmi Yadlapati dbus_utils::UnpackErrorPrinter(), properties, "UUID", uUID); 324a974c132SLakshmi Yadlapati 325a974c132SLakshmi Yadlapati if (!success) 326a974c132SLakshmi Yadlapati { 327a974c132SLakshmi Yadlapati messages::internalError(asyncResp->res); 328a974c132SLakshmi Yadlapati return; 329a974c132SLakshmi Yadlapati } 330a974c132SLakshmi Yadlapati 331a974c132SLakshmi Yadlapati if (uUID != nullptr) 332a974c132SLakshmi Yadlapati { 333a974c132SLakshmi Yadlapati std::string valueStr = *uUID; 334a974c132SLakshmi Yadlapati if (valueStr.size() == 32) 335a974c132SLakshmi Yadlapati { 336a974c132SLakshmi Yadlapati valueStr.insert(8, 1, '-'); 337a974c132SLakshmi Yadlapati valueStr.insert(13, 1, '-'); 338a974c132SLakshmi Yadlapati valueStr.insert(18, 1, '-'); 339a974c132SLakshmi Yadlapati valueStr.insert(23, 1, '-'); 340a974c132SLakshmi Yadlapati } 341a974c132SLakshmi Yadlapati BMCWEB_LOG_DEBUG("UUID = {}", valueStr); 342a974c132SLakshmi Yadlapati asyncResp->res.jsonValue["UUID"] = valueStr; 343a974c132SLakshmi Yadlapati } 344a974c132SLakshmi Yadlapati } 345a974c132SLakshmi Yadlapati 346504af5a0SPatrick Williams inline void afterGetInventory( 347504af5a0SPatrick Williams const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 348a974c132SLakshmi Yadlapati const boost::system::error_code& ec, 349a974c132SLakshmi Yadlapati const dbus::utility::DBusPropertiesMap& propertiesList) 350a974c132SLakshmi Yadlapati { 351a974c132SLakshmi Yadlapati if (ec) 352a974c132SLakshmi Yadlapati { 353a974c132SLakshmi Yadlapati // doesn't have to include this 354a974c132SLakshmi Yadlapati // interface 355a974c132SLakshmi Yadlapati return; 356a974c132SLakshmi Yadlapati } 357a974c132SLakshmi Yadlapati BMCWEB_LOG_DEBUG("Got {} properties for system", propertiesList.size()); 358a974c132SLakshmi Yadlapati 359a974c132SLakshmi Yadlapati const std::string* partNumber = nullptr; 360a974c132SLakshmi Yadlapati const std::string* serialNumber = nullptr; 361a974c132SLakshmi Yadlapati const std::string* manufacturer = nullptr; 362a974c132SLakshmi Yadlapati const std::string* model = nullptr; 363a974c132SLakshmi Yadlapati const std::string* subModel = nullptr; 364a974c132SLakshmi Yadlapati 365a974c132SLakshmi Yadlapati const bool success = sdbusplus::unpackPropertiesNoThrow( 366a974c132SLakshmi Yadlapati dbus_utils::UnpackErrorPrinter(), propertiesList, "PartNumber", 367a974c132SLakshmi Yadlapati partNumber, "SerialNumber", serialNumber, "Manufacturer", manufacturer, 368a974c132SLakshmi Yadlapati "Model", model, "SubModel", subModel); 369a974c132SLakshmi Yadlapati 370a974c132SLakshmi Yadlapati if (!success) 371a974c132SLakshmi Yadlapati { 372a974c132SLakshmi Yadlapati messages::internalError(asyncResp->res); 373a974c132SLakshmi Yadlapati return; 374a974c132SLakshmi Yadlapati } 375a974c132SLakshmi Yadlapati 376a974c132SLakshmi Yadlapati if (partNumber != nullptr) 377a974c132SLakshmi Yadlapati { 378a974c132SLakshmi Yadlapati asyncResp->res.jsonValue["PartNumber"] = *partNumber; 379a974c132SLakshmi Yadlapati } 380a974c132SLakshmi Yadlapati 381a974c132SLakshmi Yadlapati if (serialNumber != nullptr) 382a974c132SLakshmi Yadlapati { 383a974c132SLakshmi Yadlapati asyncResp->res.jsonValue["SerialNumber"] = *serialNumber; 384a974c132SLakshmi Yadlapati } 385a974c132SLakshmi Yadlapati 386a974c132SLakshmi Yadlapati if (manufacturer != nullptr) 387a974c132SLakshmi Yadlapati { 388a974c132SLakshmi Yadlapati asyncResp->res.jsonValue["Manufacturer"] = *manufacturer; 389a974c132SLakshmi Yadlapati } 390a974c132SLakshmi Yadlapati 391a974c132SLakshmi Yadlapati if (model != nullptr) 392a974c132SLakshmi Yadlapati { 393a974c132SLakshmi Yadlapati asyncResp->res.jsonValue["Model"] = *model; 394a974c132SLakshmi Yadlapati } 395a974c132SLakshmi Yadlapati 396a974c132SLakshmi Yadlapati if (subModel != nullptr) 397a974c132SLakshmi Yadlapati { 398a974c132SLakshmi Yadlapati asyncResp->res.jsonValue["SubModel"] = *subModel; 399a974c132SLakshmi Yadlapati } 400a974c132SLakshmi Yadlapati 401a974c132SLakshmi Yadlapati // Grab the bios version 402a974c132SLakshmi Yadlapati sw_util::populateSoftwareInformation(asyncResp, sw_util::biosPurpose, 403a974c132SLakshmi Yadlapati "BiosVersion", false); 404a974c132SLakshmi Yadlapati } 405a974c132SLakshmi Yadlapati 406bd79bce8SPatrick Williams inline void afterGetAssetTag( 407bd79bce8SPatrick Williams const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 408bd79bce8SPatrick Williams const boost::system::error_code& ec, const std::string& value) 409a974c132SLakshmi Yadlapati { 410a974c132SLakshmi Yadlapati if (ec) 411a974c132SLakshmi Yadlapati { 412a974c132SLakshmi Yadlapati // doesn't have to include this 413a974c132SLakshmi Yadlapati // interface 414a974c132SLakshmi Yadlapati return; 415a974c132SLakshmi Yadlapati } 416a974c132SLakshmi Yadlapati 417a974c132SLakshmi Yadlapati asyncResp->res.jsonValue["AssetTag"] = value; 418a974c132SLakshmi Yadlapati } 419a974c132SLakshmi Yadlapati 420a974c132SLakshmi Yadlapati inline void afterSystemGetSubTree( 421a974c132SLakshmi Yadlapati const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 422a974c132SLakshmi Yadlapati const boost::system::error_code& ec, 423a974c132SLakshmi Yadlapati const dbus::utility::MapperGetSubTreeResponse& subtree) 424a974c132SLakshmi Yadlapati { 4251abe55efSEd Tanous if (ec) 4261abe55efSEd Tanous { 427b3e86cb0SGunnar Mills BMCWEB_LOG_ERROR("DBUS response error {}", ec); 428ac106bf6SEd Tanous messages::internalError(asyncResp->res); 429c5b2abe0SLewanczyk, Dawid return; 430c5b2abe0SLewanczyk, Dawid } 431c5b2abe0SLewanczyk, Dawid // Iterate over all retrieved ObjectPaths. 432002d39b4SEd Tanous for (const std::pair< 433002d39b4SEd Tanous std::string, 434002d39b4SEd Tanous std::vector<std::pair<std::string, std::vector<std::string>>>>& 4351214b7e7SGunnar Mills object : subtree) 4361abe55efSEd Tanous { 437c5b2abe0SLewanczyk, Dawid const std::string& path = object.first; 43862598e31SEd Tanous BMCWEB_LOG_DEBUG("Got path: {}", path); 439002d39b4SEd Tanous const std::vector<std::pair<std::string, std::vector<std::string>>>& 4401214b7e7SGunnar Mills connectionNames = object.second; 44126f6976fSEd Tanous if (connectionNames.empty()) 4421abe55efSEd Tanous { 443c5b2abe0SLewanczyk, Dawid continue; 444c5b2abe0SLewanczyk, Dawid } 445029573d4SEd Tanous 4466c34de48SEd Tanous // This is not system, so check if it's cpu, dimm, UUID or 4476c34de48SEd Tanous // BiosVer 44804a258f4SEd Tanous for (const auto& connection : connectionNames) 4491abe55efSEd Tanous { 45004a258f4SEd Tanous for (const auto& interfaceName : connection.second) 4511abe55efSEd Tanous { 452a974c132SLakshmi Yadlapati if (interfaceName == "xyz.openbmc_project.Inventory.Item.Dimm") 4531abe55efSEd Tanous { 45462598e31SEd Tanous BMCWEB_LOG_DEBUG("Found Dimm, now get its properties."); 4559d3ae10eSAlpana Kumari 456ac106bf6SEd Tanous getMemorySummary(asyncResp, connection.first, path); 4575fd0aafbSNinad Palsule } 45804a258f4SEd Tanous else if (interfaceName == 45904a258f4SEd Tanous "xyz.openbmc_project.Inventory.Item.Cpu") 4601abe55efSEd Tanous { 46162598e31SEd Tanous BMCWEB_LOG_DEBUG("Found Cpu, now get its properties."); 46257e8c9beSAlpana Kumari 463ac106bf6SEd Tanous getProcessorSummary(asyncResp, connection.first, path); 4645fd0aafbSNinad Palsule } 465002d39b4SEd Tanous else if (interfaceName == "xyz.openbmc_project.Common.UUID") 4661abe55efSEd Tanous { 46762598e31SEd Tanous BMCWEB_LOG_DEBUG("Found UUID, now get its properties."); 468bc1d29deSKrzysztof Grobelny 469deae6a78SEd Tanous dbus::utility::getAllProperties( 470a974c132SLakshmi Yadlapati *crow::connections::systemBus, connection.first, path, 471a974c132SLakshmi Yadlapati "xyz.openbmc_project.Common.UUID", 472ac106bf6SEd Tanous [asyncResp](const boost::system::error_code& ec3, 473b9d36b47SEd Tanous const dbus::utility::DBusPropertiesMap& 4741214b7e7SGunnar Mills properties) { 475a974c132SLakshmi Yadlapati afterGetUUID(asyncResp, ec3, properties); 476bc1d29deSKrzysztof Grobelny }); 477c5b2abe0SLewanczyk, Dawid } 478029573d4SEd Tanous else if (interfaceName == 479029573d4SEd Tanous "xyz.openbmc_project.Inventory.Item.System") 4801abe55efSEd Tanous { 481deae6a78SEd Tanous dbus::utility::getAllProperties( 482a974c132SLakshmi Yadlapati *crow::connections::systemBus, connection.first, path, 483bc1d29deSKrzysztof Grobelny "xyz.openbmc_project.Inventory.Decorator.Asset", 484a974c132SLakshmi Yadlapati [asyncResp](const boost::system::error_code& ec3, 485b9d36b47SEd Tanous const dbus::utility::DBusPropertiesMap& 486a974c132SLakshmi Yadlapati properties) { 487a974c132SLakshmi Yadlapati afterGetInventory(asyncResp, ec3, properties); 488bc1d29deSKrzysztof Grobelny }); 489e4a4b9a9SJames Feist 490deae6a78SEd Tanous dbus::utility::getProperty<std::string>( 491deae6a78SEd Tanous connection.first, path, 4921e1e598dSJonathan Doman "xyz.openbmc_project.Inventory.Decorator." 4931e1e598dSJonathan Doman "AssetTag", 4941e1e598dSJonathan Doman "AssetTag", 495a974c132SLakshmi Yadlapati std::bind_front(afterGetAssetTag, asyncResp)); 496a974c132SLakshmi Yadlapati } 497a974c132SLakshmi Yadlapati } 498a974c132SLakshmi Yadlapati } 499a974c132SLakshmi Yadlapati } 500a974c132SLakshmi Yadlapati } 501a974c132SLakshmi Yadlapati 502a974c132SLakshmi Yadlapati /* 503a974c132SLakshmi Yadlapati * @brief Retrieves computer system properties over dbus 504a974c132SLakshmi Yadlapati * 505a974c132SLakshmi Yadlapati * @param[in] asyncResp Shared pointer for completing asynchronous calls 506a974c132SLakshmi Yadlapati * 507a974c132SLakshmi Yadlapati * @return None. 508a974c132SLakshmi Yadlapati */ 509504af5a0SPatrick Williams inline void getComputerSystem( 510504af5a0SPatrick Williams const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) 511e4a4b9a9SJames Feist { 512a974c132SLakshmi Yadlapati BMCWEB_LOG_DEBUG("Get available system components."); 513a974c132SLakshmi Yadlapati constexpr std::array<std::string_view, 5> interfaces = { 514a974c132SLakshmi Yadlapati "xyz.openbmc_project.Inventory.Decorator.Asset", 515a974c132SLakshmi Yadlapati "xyz.openbmc_project.Inventory.Item.Cpu", 516a974c132SLakshmi Yadlapati "xyz.openbmc_project.Inventory.Item.Dimm", 517a974c132SLakshmi Yadlapati "xyz.openbmc_project.Inventory.Item.System", 518a974c132SLakshmi Yadlapati "xyz.openbmc_project.Common.UUID", 519a974c132SLakshmi Yadlapati }; 520a974c132SLakshmi Yadlapati dbus::utility::getSubTree( 521a974c132SLakshmi Yadlapati "/xyz/openbmc_project/inventory", 0, interfaces, 52251bd2d8aSGunnar Mills std::bind_front(afterSystemGetSubTree, asyncResp)); 523c5b2abe0SLewanczyk, Dawid } 524c5b2abe0SLewanczyk, Dawid 525c5b2abe0SLewanczyk, Dawid /** 526c5b2abe0SLewanczyk, Dawid * @brief Retrieves host state properties over dbus 527c5b2abe0SLewanczyk, Dawid * 528ac106bf6SEd Tanous * @param[in] asyncResp Shared pointer for completing asynchronous calls. 529*5e7c1f31SOliver Brewka * @param[in] computerSystemIndex Index associated with the requested system 530c5b2abe0SLewanczyk, Dawid * 531c5b2abe0SLewanczyk, Dawid * @return None. 532c5b2abe0SLewanczyk, Dawid */ 533*5e7c1f31SOliver Brewka inline void getHostState(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 534*5e7c1f31SOliver Brewka const uint64_t computerSystemIndex) 5351abe55efSEd Tanous { 53662598e31SEd Tanous BMCWEB_LOG_DEBUG("Get host information."); 537*5e7c1f31SOliver Brewka 538deae6a78SEd Tanous dbus::utility::getProperty<std::string>( 539*5e7c1f31SOliver Brewka getHostStateServiceName(computerSystemIndex), 540*5e7c1f31SOliver Brewka getHostStateObjectPath(computerSystemIndex), 541deae6a78SEd Tanous "xyz.openbmc_project.State.Host", "CurrentHostState", 542ac106bf6SEd Tanous [asyncResp](const boost::system::error_code& ec, 5431e1e598dSJonathan Doman const std::string& hostState) { 5441abe55efSEd Tanous if (ec) 5451abe55efSEd Tanous { 54622228c28SAndrew Geissler if (ec == boost::system::errc::host_unreachable) 54722228c28SAndrew Geissler { 54822228c28SAndrew Geissler // Service not available, no error, just don't return 54922228c28SAndrew Geissler // host state info 55062598e31SEd Tanous BMCWEB_LOG_DEBUG("Service not available {}", ec); 55122228c28SAndrew Geissler return; 55222228c28SAndrew Geissler } 55362598e31SEd Tanous BMCWEB_LOG_ERROR("DBUS response error {}", ec); 554ac106bf6SEd Tanous messages::internalError(asyncResp->res); 555c5b2abe0SLewanczyk, Dawid return; 556c5b2abe0SLewanczyk, Dawid } 5576617338dSEd Tanous 55862598e31SEd Tanous BMCWEB_LOG_DEBUG("Host state: {}", hostState); 559c5b2abe0SLewanczyk, Dawid // Verify Host State 5601e1e598dSJonathan Doman if (hostState == "xyz.openbmc_project.State.Host.HostState.Running") 5611abe55efSEd Tanous { 562bd79bce8SPatrick Williams asyncResp->res.jsonValue["PowerState"] = 563bd79bce8SPatrick Williams resource::PowerState::On; 564539d8c6bSEd Tanous asyncResp->res.jsonValue["Status"]["State"] = 565539d8c6bSEd Tanous resource::State::Enabled; 5661abe55efSEd Tanous } 5671e1e598dSJonathan Doman else if (hostState == 5680fda0f12SGeorge Liu "xyz.openbmc_project.State.Host.HostState.Quiesced") 5698c888608SGunnar Mills { 570bd79bce8SPatrick Williams asyncResp->res.jsonValue["PowerState"] = 571bd79bce8SPatrick Williams resource::PowerState::On; 572539d8c6bSEd Tanous asyncResp->res.jsonValue["Status"]["State"] = 573539d8c6bSEd Tanous resource::State::Quiesced; 5748c888608SGunnar Mills } 5751e1e598dSJonathan Doman else if (hostState == 5760fda0f12SGeorge Liu "xyz.openbmc_project.State.Host.HostState.DiagnosticMode") 57783935af9SAndrew Geissler { 578bd79bce8SPatrick Williams asyncResp->res.jsonValue["PowerState"] = 579bd79bce8SPatrick Williams resource::PowerState::On; 580539d8c6bSEd Tanous asyncResp->res.jsonValue["Status"]["State"] = 581539d8c6bSEd Tanous resource::State::InTest; 58283935af9SAndrew Geissler } 5830fda0f12SGeorge Liu else if ( 5841e1e598dSJonathan Doman hostState == 5850fda0f12SGeorge Liu "xyz.openbmc_project.State.Host.HostState.TransitioningToRunning") 5861a2a1437SAndrew Geissler { 587539d8c6bSEd Tanous asyncResp->res.jsonValue["PowerState"] = 588539d8c6bSEd Tanous resource::PowerState::PoweringOn; 589539d8c6bSEd Tanous asyncResp->res.jsonValue["Status"]["State"] = 590539d8c6bSEd Tanous resource::State::Starting; 5911a2a1437SAndrew Geissler } 592bd79bce8SPatrick Williams else if ( 593bd79bce8SPatrick Williams hostState == 5940fda0f12SGeorge Liu "xyz.openbmc_project.State.Host.HostState.TransitioningToOff") 5951a2a1437SAndrew Geissler { 596539d8c6bSEd Tanous asyncResp->res.jsonValue["PowerState"] = 597539d8c6bSEd Tanous resource::PowerState::PoweringOff; 598539d8c6bSEd Tanous asyncResp->res.jsonValue["Status"]["State"] = 599539d8c6bSEd Tanous resource::State::Disabled; 6001a2a1437SAndrew Geissler } 6011abe55efSEd Tanous else 6021abe55efSEd Tanous { 603bd79bce8SPatrick Williams asyncResp->res.jsonValue["PowerState"] = 604bd79bce8SPatrick Williams resource::PowerState::Off; 605539d8c6bSEd Tanous asyncResp->res.jsonValue["Status"]["State"] = 606539d8c6bSEd Tanous resource::State::Disabled; 607c5b2abe0SLewanczyk, Dawid } 6081e1e598dSJonathan Doman }); 609c5b2abe0SLewanczyk, Dawid } 610c5b2abe0SLewanczyk, Dawid 611c5b2abe0SLewanczyk, Dawid /** 612786d0f60SGunnar Mills * @brief Translates boot source DBUS property value to redfish. 613491d8ee7SSantosh Puranik * 614491d8ee7SSantosh Puranik * @param[in] dbusSource The boot source in DBUS speak. 615491d8ee7SSantosh Puranik * 616491d8ee7SSantosh Puranik * @return Returns as a string, the boot source in Redfish terms. If translation 617491d8ee7SSantosh Puranik * cannot be done, returns an empty string. 618491d8ee7SSantosh Puranik */ 61923a21a1cSEd Tanous inline std::string dbusToRfBootSource(const std::string& dbusSource) 620491d8ee7SSantosh Puranik { 621491d8ee7SSantosh Puranik if (dbusSource == "xyz.openbmc_project.Control.Boot.Source.Sources.Default") 622491d8ee7SSantosh Puranik { 623491d8ee7SSantosh Puranik return "None"; 624491d8ee7SSantosh Puranik } 6253174e4dfSEd Tanous if (dbusSource == "xyz.openbmc_project.Control.Boot.Source.Sources.Disk") 626491d8ee7SSantosh Puranik { 627491d8ee7SSantosh Puranik return "Hdd"; 628491d8ee7SSantosh Puranik } 6293174e4dfSEd Tanous if (dbusSource == 630a71dc0b7SSantosh Puranik "xyz.openbmc_project.Control.Boot.Source.Sources.ExternalMedia") 631491d8ee7SSantosh Puranik { 632491d8ee7SSantosh Puranik return "Cd"; 633491d8ee7SSantosh Puranik } 6343174e4dfSEd Tanous if (dbusSource == "xyz.openbmc_project.Control.Boot.Source.Sources.Network") 635491d8ee7SSantosh Puranik { 636491d8ee7SSantosh Puranik return "Pxe"; 637491d8ee7SSantosh Puranik } 6383174e4dfSEd Tanous if (dbusSource == 639944ffaf9SJohnathan Mantey "xyz.openbmc_project.Control.Boot.Source.Sources.RemovableMedia") 6409f16b2c1SJennifer Lee { 6419f16b2c1SJennifer Lee return "Usb"; 6429f16b2c1SJennifer Lee } 643491d8ee7SSantosh Puranik return ""; 644491d8ee7SSantosh Puranik } 645491d8ee7SSantosh Puranik 646491d8ee7SSantosh Puranik /** 647cd9a4666SKonstantin Aladyshev * @brief Translates boot type DBUS property value to redfish. 648cd9a4666SKonstantin Aladyshev * 649cd9a4666SKonstantin Aladyshev * @param[in] dbusType The boot type in DBUS speak. 650cd9a4666SKonstantin Aladyshev * 651cd9a4666SKonstantin Aladyshev * @return Returns as a string, the boot type in Redfish terms. If translation 652cd9a4666SKonstantin Aladyshev * cannot be done, returns an empty string. 653cd9a4666SKonstantin Aladyshev */ 654cd9a4666SKonstantin Aladyshev inline std::string dbusToRfBootType(const std::string& dbusType) 655cd9a4666SKonstantin Aladyshev { 656cd9a4666SKonstantin Aladyshev if (dbusType == "xyz.openbmc_project.Control.Boot.Type.Types.Legacy") 657cd9a4666SKonstantin Aladyshev { 658cd9a4666SKonstantin Aladyshev return "Legacy"; 659cd9a4666SKonstantin Aladyshev } 660cd9a4666SKonstantin Aladyshev if (dbusType == "xyz.openbmc_project.Control.Boot.Type.Types.EFI") 661cd9a4666SKonstantin Aladyshev { 662cd9a4666SKonstantin Aladyshev return "UEFI"; 663cd9a4666SKonstantin Aladyshev } 664cd9a4666SKonstantin Aladyshev return ""; 665cd9a4666SKonstantin Aladyshev } 666cd9a4666SKonstantin Aladyshev 667cd9a4666SKonstantin Aladyshev /** 668786d0f60SGunnar Mills * @brief Translates boot mode DBUS property value to redfish. 669491d8ee7SSantosh Puranik * 670491d8ee7SSantosh Puranik * @param[in] dbusMode The boot mode in DBUS speak. 671491d8ee7SSantosh Puranik * 672491d8ee7SSantosh Puranik * @return Returns as a string, the boot mode in Redfish terms. If translation 673491d8ee7SSantosh Puranik * cannot be done, returns an empty string. 674491d8ee7SSantosh Puranik */ 67523a21a1cSEd Tanous inline std::string dbusToRfBootMode(const std::string& dbusMode) 676491d8ee7SSantosh Puranik { 677491d8ee7SSantosh Puranik if (dbusMode == "xyz.openbmc_project.Control.Boot.Mode.Modes.Regular") 678491d8ee7SSantosh Puranik { 679491d8ee7SSantosh Puranik return "None"; 680491d8ee7SSantosh Puranik } 6813174e4dfSEd Tanous if (dbusMode == "xyz.openbmc_project.Control.Boot.Mode.Modes.Safe") 682491d8ee7SSantosh Puranik { 683491d8ee7SSantosh Puranik return "Diags"; 684491d8ee7SSantosh Puranik } 6853174e4dfSEd Tanous if (dbusMode == "xyz.openbmc_project.Control.Boot.Mode.Modes.Setup") 686491d8ee7SSantosh Puranik { 687491d8ee7SSantosh Puranik return "BiosSetup"; 688491d8ee7SSantosh Puranik } 689491d8ee7SSantosh Puranik return ""; 690491d8ee7SSantosh Puranik } 691491d8ee7SSantosh Puranik 692491d8ee7SSantosh Puranik /** 693e43914b3SAndrew Geissler * @brief Translates boot progress DBUS property value to redfish. 694e43914b3SAndrew Geissler * 695e43914b3SAndrew Geissler * @param[in] dbusBootProgress The boot progress in DBUS speak. 696e43914b3SAndrew Geissler * 697e43914b3SAndrew Geissler * @return Returns as a string, the boot progress in Redfish terms. If 698e43914b3SAndrew Geissler * translation cannot be done, returns "None". 699e43914b3SAndrew Geissler */ 700e43914b3SAndrew Geissler inline std::string dbusToRfBootProgress(const std::string& dbusBootProgress) 701e43914b3SAndrew Geissler { 702e43914b3SAndrew Geissler // Now convert the D-Bus BootProgress to the appropriate Redfish 703e43914b3SAndrew Geissler // enum 704e43914b3SAndrew Geissler std::string rfBpLastState = "None"; 705e43914b3SAndrew Geissler if (dbusBootProgress == "xyz.openbmc_project.State.Boot.Progress." 706e43914b3SAndrew Geissler "ProgressStages.Unspecified") 707e43914b3SAndrew Geissler { 708e43914b3SAndrew Geissler rfBpLastState = "None"; 709e43914b3SAndrew Geissler } 710e43914b3SAndrew Geissler else if (dbusBootProgress == 711e43914b3SAndrew Geissler "xyz.openbmc_project.State.Boot.Progress.ProgressStages." 712e43914b3SAndrew Geissler "PrimaryProcInit") 713e43914b3SAndrew Geissler { 714e43914b3SAndrew Geissler rfBpLastState = "PrimaryProcessorInitializationStarted"; 715e43914b3SAndrew Geissler } 716e43914b3SAndrew Geissler else if (dbusBootProgress == 717e43914b3SAndrew Geissler "xyz.openbmc_project.State.Boot.Progress.ProgressStages." 718e43914b3SAndrew Geissler "BusInit") 719e43914b3SAndrew Geissler { 720e43914b3SAndrew Geissler rfBpLastState = "BusInitializationStarted"; 721e43914b3SAndrew Geissler } 722e43914b3SAndrew Geissler else if (dbusBootProgress == 723e43914b3SAndrew Geissler "xyz.openbmc_project.State.Boot.Progress.ProgressStages." 724e43914b3SAndrew Geissler "MemoryInit") 725e43914b3SAndrew Geissler { 726e43914b3SAndrew Geissler rfBpLastState = "MemoryInitializationStarted"; 727e43914b3SAndrew Geissler } 728e43914b3SAndrew Geissler else if (dbusBootProgress == 729e43914b3SAndrew Geissler "xyz.openbmc_project.State.Boot.Progress.ProgressStages." 730e43914b3SAndrew Geissler "SecondaryProcInit") 731e43914b3SAndrew Geissler { 732e43914b3SAndrew Geissler rfBpLastState = "SecondaryProcessorInitializationStarted"; 733e43914b3SAndrew Geissler } 734e43914b3SAndrew Geissler else if (dbusBootProgress == 735e43914b3SAndrew Geissler "xyz.openbmc_project.State.Boot.Progress.ProgressStages." 736e43914b3SAndrew Geissler "PCIInit") 737e43914b3SAndrew Geissler { 738e43914b3SAndrew Geissler rfBpLastState = "PCIResourceConfigStarted"; 739e43914b3SAndrew Geissler } 740e43914b3SAndrew Geissler else if (dbusBootProgress == 741e43914b3SAndrew Geissler "xyz.openbmc_project.State.Boot.Progress.ProgressStages." 742e43914b3SAndrew Geissler "SystemSetup") 743e43914b3SAndrew Geissler { 744e43914b3SAndrew Geissler rfBpLastState = "SetupEntered"; 745e43914b3SAndrew Geissler } 746e43914b3SAndrew Geissler else if (dbusBootProgress == 747e43914b3SAndrew Geissler "xyz.openbmc_project.State.Boot.Progress.ProgressStages." 748e43914b3SAndrew Geissler "SystemInitComplete") 749e43914b3SAndrew Geissler { 750e43914b3SAndrew Geissler rfBpLastState = "SystemHardwareInitializationComplete"; 751e43914b3SAndrew Geissler } 752e43914b3SAndrew Geissler else if (dbusBootProgress == 753e43914b3SAndrew Geissler "xyz.openbmc_project.State.Boot.Progress.ProgressStages." 754e43914b3SAndrew Geissler "OSStart") 755e43914b3SAndrew Geissler { 756e43914b3SAndrew Geissler rfBpLastState = "OSBootStarted"; 757e43914b3SAndrew Geissler } 758e43914b3SAndrew Geissler else if (dbusBootProgress == 759e43914b3SAndrew Geissler "xyz.openbmc_project.State.Boot.Progress.ProgressStages." 760e43914b3SAndrew Geissler "OSRunning") 761e43914b3SAndrew Geissler { 762e43914b3SAndrew Geissler rfBpLastState = "OSRunning"; 763e43914b3SAndrew Geissler } 764e43914b3SAndrew Geissler else 765e43914b3SAndrew Geissler { 76662598e31SEd Tanous BMCWEB_LOG_DEBUG("Unsupported D-Bus BootProgress {}", dbusBootProgress); 767e43914b3SAndrew Geissler // Just return the default 768e43914b3SAndrew Geissler } 769e43914b3SAndrew Geissler return rfBpLastState; 770e43914b3SAndrew Geissler } 771e43914b3SAndrew Geissler 772e43914b3SAndrew Geissler /** 773786d0f60SGunnar Mills * @brief Translates boot source from Redfish to the DBus boot paths. 774491d8ee7SSantosh Puranik * 775491d8ee7SSantosh Puranik * @param[in] rfSource The boot source in Redfish. 776944ffaf9SJohnathan Mantey * @param[out] bootSource The DBus source 777944ffaf9SJohnathan Mantey * @param[out] bootMode the DBus boot mode 778491d8ee7SSantosh Puranik * 779944ffaf9SJohnathan Mantey * @return Integer error code. 780491d8ee7SSantosh Puranik */ 781bd79bce8SPatrick Williams inline int assignBootParameters( 782bd79bce8SPatrick Williams const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 783bd79bce8SPatrick Williams const std::string& rfSource, std::string& bootSource, std::string& bootMode) 784491d8ee7SSantosh Puranik { 785c21865c4SKonstantin Aladyshev bootSource = "xyz.openbmc_project.Control.Boot.Source.Sources.Default"; 786c21865c4SKonstantin Aladyshev bootMode = "xyz.openbmc_project.Control.Boot.Mode.Modes.Regular"; 787944ffaf9SJohnathan Mantey 788491d8ee7SSantosh Puranik if (rfSource == "None") 789491d8ee7SSantosh Puranik { 790944ffaf9SJohnathan Mantey return 0; 791491d8ee7SSantosh Puranik } 7923174e4dfSEd Tanous if (rfSource == "Pxe") 793491d8ee7SSantosh Puranik { 794944ffaf9SJohnathan Mantey bootSource = "xyz.openbmc_project.Control.Boot.Source.Sources.Network"; 795944ffaf9SJohnathan Mantey } 796944ffaf9SJohnathan Mantey else if (rfSource == "Hdd") 797944ffaf9SJohnathan Mantey { 798944ffaf9SJohnathan Mantey bootSource = "xyz.openbmc_project.Control.Boot.Source.Sources.Disk"; 799944ffaf9SJohnathan Mantey } 800944ffaf9SJohnathan Mantey else if (rfSource == "Diags") 801944ffaf9SJohnathan Mantey { 802944ffaf9SJohnathan Mantey bootMode = "xyz.openbmc_project.Control.Boot.Mode.Modes.Safe"; 803944ffaf9SJohnathan Mantey } 804944ffaf9SJohnathan Mantey else if (rfSource == "Cd") 805944ffaf9SJohnathan Mantey { 806944ffaf9SJohnathan Mantey bootSource = 807944ffaf9SJohnathan Mantey "xyz.openbmc_project.Control.Boot.Source.Sources.ExternalMedia"; 808944ffaf9SJohnathan Mantey } 809944ffaf9SJohnathan Mantey else if (rfSource == "BiosSetup") 810944ffaf9SJohnathan Mantey { 811944ffaf9SJohnathan Mantey bootMode = "xyz.openbmc_project.Control.Boot.Mode.Modes.Setup"; 812491d8ee7SSantosh Puranik } 8139f16b2c1SJennifer Lee else if (rfSource == "Usb") 8149f16b2c1SJennifer Lee { 815944ffaf9SJohnathan Mantey bootSource = 816944ffaf9SJohnathan Mantey "xyz.openbmc_project.Control.Boot.Source.Sources.RemovableMedia"; 8179f16b2c1SJennifer Lee } 818491d8ee7SSantosh Puranik else 819491d8ee7SSantosh Puranik { 82062598e31SEd Tanous BMCWEB_LOG_DEBUG( 82162598e31SEd Tanous "Invalid property value for BootSourceOverrideTarget: {}", 82262598e31SEd Tanous bootSource); 823ac106bf6SEd Tanous messages::propertyValueNotInList(asyncResp->res, rfSource, 824944ffaf9SJohnathan Mantey "BootSourceTargetOverride"); 825944ffaf9SJohnathan Mantey return -1; 826491d8ee7SSantosh Puranik } 827944ffaf9SJohnathan Mantey return 0; 828491d8ee7SSantosh Puranik } 8291981771bSAli Ahmed 830978b8803SAndrew Geissler /** 831978b8803SAndrew Geissler * @brief Retrieves boot progress of the system 832978b8803SAndrew Geissler * 833ac106bf6SEd Tanous * @param[in] asyncResp Shared pointer for generating response message. 834*5e7c1f31SOliver Brewka * @param[in] computerSystemIndex Index associated with the requested system 835978b8803SAndrew Geissler * 836978b8803SAndrew Geissler * @return None. 837978b8803SAndrew Geissler */ 838*5e7c1f31SOliver Brewka inline void getBootProgress(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 839*5e7c1f31SOliver Brewka const uint64_t computerSystemIndex) 840978b8803SAndrew Geissler { 841deae6a78SEd Tanous dbus::utility::getProperty<std::string>( 842*5e7c1f31SOliver Brewka getHostStateServiceName(computerSystemIndex), 843*5e7c1f31SOliver Brewka getHostStateObjectPath(computerSystemIndex), 8441e1e598dSJonathan Doman "xyz.openbmc_project.State.Boot.Progress", "BootProgress", 845ac106bf6SEd Tanous [asyncResp](const boost::system::error_code& ec, 8461e1e598dSJonathan Doman const std::string& bootProgressStr) { 847978b8803SAndrew Geissler if (ec) 848978b8803SAndrew Geissler { 849978b8803SAndrew Geissler // BootProgress is an optional object so just do nothing if 850978b8803SAndrew Geissler // not found 851978b8803SAndrew Geissler return; 852978b8803SAndrew Geissler } 853978b8803SAndrew Geissler 85462598e31SEd Tanous BMCWEB_LOG_DEBUG("Boot Progress: {}", bootProgressStr); 855978b8803SAndrew Geissler 856ac106bf6SEd Tanous asyncResp->res.jsonValue["BootProgress"]["LastState"] = 857e43914b3SAndrew Geissler dbusToRfBootProgress(bootProgressStr); 8581e1e598dSJonathan Doman }); 859978b8803SAndrew Geissler } 860491d8ee7SSantosh Puranik 861491d8ee7SSantosh Puranik /** 862b6d5d45cSHieu Huynh * @brief Retrieves boot progress Last Update of the system 863b6d5d45cSHieu Huynh * 864ac106bf6SEd Tanous * @param[in] asyncResp Shared pointer for generating response message. 865*5e7c1f31SOliver Brewka * @param[in] computerSystemIndex Index associated with the requested system 866b6d5d45cSHieu Huynh * 867b6d5d45cSHieu Huynh * @return None. 868b6d5d45cSHieu Huynh */ 869b6d5d45cSHieu Huynh inline void getBootProgressLastStateTime( 870*5e7c1f31SOliver Brewka const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 871*5e7c1f31SOliver Brewka const uint64_t computerSystemIndex) 872b6d5d45cSHieu Huynh { 873deae6a78SEd Tanous dbus::utility::getProperty<uint64_t>( 874*5e7c1f31SOliver Brewka getHostStateServiceName(computerSystemIndex), 875*5e7c1f31SOliver Brewka getHostStateObjectPath(computerSystemIndex), 876b6d5d45cSHieu Huynh "xyz.openbmc_project.State.Boot.Progress", "BootProgressLastUpdate", 877ac106bf6SEd Tanous [asyncResp](const boost::system::error_code& ec, 878b6d5d45cSHieu Huynh const uint64_t lastStateTime) { 879b6d5d45cSHieu Huynh if (ec) 880b6d5d45cSHieu Huynh { 88162598e31SEd Tanous BMCWEB_LOG_DEBUG("D-BUS response error {}", ec); 882b6d5d45cSHieu Huynh return; 883b6d5d45cSHieu Huynh } 884b6d5d45cSHieu Huynh 885b6d5d45cSHieu Huynh // BootProgressLastUpdate is the last time the BootProgress property 886b6d5d45cSHieu Huynh // was updated. The time is the Epoch time, number of microseconds 887b6d5d45cSHieu Huynh // since 1 Jan 1970 00::00::00 UTC." 888b6d5d45cSHieu Huynh // https://github.com/openbmc/phosphor-dbus-interfaces/blob/master/ 889b6d5d45cSHieu Huynh // yaml/xyz/openbmc_project/State/Boot/Progress.interface.yaml#L11 890b6d5d45cSHieu Huynh 891b6d5d45cSHieu Huynh // Convert to ISO 8601 standard 892ac106bf6SEd Tanous asyncResp->res.jsonValue["BootProgress"]["LastStateTime"] = 893b6d5d45cSHieu Huynh redfish::time_utils::getDateTimeUintUs(lastStateTime); 894b6d5d45cSHieu Huynh }); 895b6d5d45cSHieu Huynh } 896b6d5d45cSHieu Huynh 897b6d5d45cSHieu Huynh /** 898c21865c4SKonstantin Aladyshev * @brief Retrieves boot override type over DBUS and fills out the response 899cd9a4666SKonstantin Aladyshev * 900ac106bf6SEd Tanous * @param[in] asyncResp Shared pointer for generating response message. 901*5e7c1f31SOliver Brewka * @param[in] computerSystemIndex Index associated with the requested system 902cd9a4666SKonstantin Aladyshev * 903cd9a4666SKonstantin Aladyshev * @return None. 904cd9a4666SKonstantin Aladyshev */ 905504af5a0SPatrick Williams inline void getBootOverrideType( 906*5e7c1f31SOliver Brewka const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 907*5e7c1f31SOliver Brewka const uint64_t computerSystemIndex) 908cd9a4666SKonstantin Aladyshev { 909*5e7c1f31SOliver Brewka sdbusplus::message::object_path path("/xyz/openbmc_project/control/host" + 910*5e7c1f31SOliver Brewka std::to_string(computerSystemIndex)); 911*5e7c1f31SOliver Brewka path /= "boot"; 912*5e7c1f31SOliver Brewka 913deae6a78SEd Tanous dbus::utility::getProperty<std::string>( 914*5e7c1f31SOliver Brewka "xyz.openbmc_project.Settings", path, 9151e1e598dSJonathan Doman "xyz.openbmc_project.Control.Boot.Type", "BootType", 916ac106bf6SEd Tanous [asyncResp](const boost::system::error_code& ec, 9171e1e598dSJonathan Doman const std::string& bootType) { 918cd9a4666SKonstantin Aladyshev if (ec) 919cd9a4666SKonstantin Aladyshev { 920cd9a4666SKonstantin Aladyshev // not an error, don't have to have the interface 921cd9a4666SKonstantin Aladyshev return; 922cd9a4666SKonstantin Aladyshev } 923cd9a4666SKonstantin Aladyshev 92462598e31SEd Tanous BMCWEB_LOG_DEBUG("Boot type: {}", bootType); 925cd9a4666SKonstantin Aladyshev 926ac106bf6SEd Tanous asyncResp->res 927ac106bf6SEd Tanous .jsonValue["Boot"] 928002d39b4SEd Tanous ["BootSourceOverrideMode@Redfish.AllowableValues"] = 929613dabeaSEd Tanous nlohmann::json::array_t({"Legacy", "UEFI"}); 930cd9a4666SKonstantin Aladyshev 9311e1e598dSJonathan Doman auto rfType = dbusToRfBootType(bootType); 932cd9a4666SKonstantin Aladyshev if (rfType.empty()) 933cd9a4666SKonstantin Aladyshev { 934ac106bf6SEd Tanous messages::internalError(asyncResp->res); 935cd9a4666SKonstantin Aladyshev return; 936cd9a4666SKonstantin Aladyshev } 937cd9a4666SKonstantin Aladyshev 938ac106bf6SEd Tanous asyncResp->res.jsonValue["Boot"]["BootSourceOverrideMode"] = rfType; 9391e1e598dSJonathan Doman }); 940cd9a4666SKonstantin Aladyshev } 941cd9a4666SKonstantin Aladyshev 942cd9a4666SKonstantin Aladyshev /** 943c21865c4SKonstantin Aladyshev * @brief Retrieves boot override mode over DBUS and fills out the response 944491d8ee7SSantosh Puranik * 945ac106bf6SEd Tanous * @param[in] asyncResp Shared pointer for generating response message. 946*5e7c1f31SOliver Brewka * @param[in] computerSystemIndex Index associated with the requested system 947491d8ee7SSantosh Puranik * 948491d8ee7SSantosh Puranik * @return None. 949491d8ee7SSantosh Puranik */ 950504af5a0SPatrick Williams inline void getBootOverrideMode( 951*5e7c1f31SOliver Brewka const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 952*5e7c1f31SOliver Brewka const uint64_t computerSystemIndex) 953491d8ee7SSantosh Puranik { 954*5e7c1f31SOliver Brewka sdbusplus::message::object_path path("/xyz/openbmc_project/control/host" + 955*5e7c1f31SOliver Brewka std::to_string(computerSystemIndex)); 956*5e7c1f31SOliver Brewka path /= "boot"; 957deae6a78SEd Tanous dbus::utility::getProperty<std::string>( 958*5e7c1f31SOliver Brewka "xyz.openbmc_project.Settings", path, 9591e1e598dSJonathan Doman "xyz.openbmc_project.Control.Boot.Mode", "BootMode", 960ac106bf6SEd Tanous [asyncResp](const boost::system::error_code& ec, 9611e1e598dSJonathan Doman const std::string& bootModeStr) { 962491d8ee7SSantosh Puranik if (ec) 963491d8ee7SSantosh Puranik { 964b3e86cb0SGunnar Mills BMCWEB_LOG_ERROR("DBUS response error {}", ec); 965ac106bf6SEd Tanous messages::internalError(asyncResp->res); 966491d8ee7SSantosh Puranik return; 967491d8ee7SSantosh Puranik } 968491d8ee7SSantosh Puranik 96962598e31SEd Tanous BMCWEB_LOG_DEBUG("Boot mode: {}", bootModeStr); 970491d8ee7SSantosh Puranik 97120fa6a2cSEd Tanous nlohmann::json::array_t allowed; 97220fa6a2cSEd Tanous allowed.emplace_back("None"); 97320fa6a2cSEd Tanous allowed.emplace_back("Pxe"); 97420fa6a2cSEd Tanous allowed.emplace_back("Hdd"); 97520fa6a2cSEd Tanous allowed.emplace_back("Cd"); 97620fa6a2cSEd Tanous allowed.emplace_back("Diags"); 97720fa6a2cSEd Tanous allowed.emplace_back("BiosSetup"); 97820fa6a2cSEd Tanous allowed.emplace_back("Usb"); 97920fa6a2cSEd Tanous 980ac106bf6SEd Tanous asyncResp->res 9810fda0f12SGeorge Liu .jsonValue["Boot"] 98220fa6a2cSEd Tanous ["BootSourceOverrideTarget@Redfish.AllowableValues"] = 98320fa6a2cSEd Tanous std::move(allowed); 9841e1e598dSJonathan Doman if (bootModeStr != 985491d8ee7SSantosh Puranik "xyz.openbmc_project.Control.Boot.Mode.Modes.Regular") 986491d8ee7SSantosh Puranik { 9871e1e598dSJonathan Doman auto rfMode = dbusToRfBootMode(bootModeStr); 988491d8ee7SSantosh Puranik if (!rfMode.empty()) 989491d8ee7SSantosh Puranik { 990bd79bce8SPatrick Williams asyncResp->res 991bd79bce8SPatrick Williams .jsonValue["Boot"]["BootSourceOverrideTarget"] = rfMode; 992491d8ee7SSantosh Puranik } 993491d8ee7SSantosh Puranik } 9941e1e598dSJonathan Doman }); 995491d8ee7SSantosh Puranik } 996491d8ee7SSantosh Puranik 997491d8ee7SSantosh Puranik /** 998c21865c4SKonstantin Aladyshev * @brief Retrieves boot override source over DBUS 999491d8ee7SSantosh Puranik * 1000ac106bf6SEd Tanous * @param[in] asyncResp Shared pointer for generating response message. 1001*5e7c1f31SOliver Brewka * @param[in] computerSystemIndex Index associated with the requested system 1002491d8ee7SSantosh Puranik * 1003491d8ee7SSantosh Puranik * @return None. 1004491d8ee7SSantosh Puranik */ 1005504af5a0SPatrick Williams inline void getBootOverrideSource( 1006*5e7c1f31SOliver Brewka const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 1007*5e7c1f31SOliver Brewka const uint64_t computerSystemIndex) 1008491d8ee7SSantosh Puranik { 1009*5e7c1f31SOliver Brewka sdbusplus::message::object_path path("/xyz/openbmc_project/control/host" + 1010*5e7c1f31SOliver Brewka std::to_string(computerSystemIndex)); 1011*5e7c1f31SOliver Brewka path /= "boot"; 1012*5e7c1f31SOliver Brewka 1013deae6a78SEd Tanous dbus::utility::getProperty<std::string>( 1014*5e7c1f31SOliver Brewka "xyz.openbmc_project.Settings", path, 10151e1e598dSJonathan Doman "xyz.openbmc_project.Control.Boot.Source", "BootSource", 1016*5e7c1f31SOliver Brewka [asyncResp, computerSystemIndex](const boost::system::error_code& ec, 10171e1e598dSJonathan Doman const std::string& bootSourceStr) { 1018491d8ee7SSantosh Puranik if (ec) 1019491d8ee7SSantosh Puranik { 10208f1a35b9SAllen.Wang // Service not available, no error, just don't return 10218f1a35b9SAllen.Wang // Boot Override Source information 10228f1a35b9SAllen.Wang if (ec.value() != EBADR && 10238f1a35b9SAllen.Wang ec.value() != boost::asio::error::host_unreachable) 10245ef735c8SNan Zhou { 10258f1a35b9SAllen.Wang BMCWEB_LOG_ERROR("D-Bus response error: {}", ec); 1026ac106bf6SEd Tanous messages::internalError(asyncResp->res); 10278f1a35b9SAllen.Wang } 1028491d8ee7SSantosh Puranik return; 1029491d8ee7SSantosh Puranik } 1030491d8ee7SSantosh Puranik 103162598e31SEd Tanous BMCWEB_LOG_DEBUG("Boot source: {}", bootSourceStr); 1032491d8ee7SSantosh Puranik 10331e1e598dSJonathan Doman auto rfSource = dbusToRfBootSource(bootSourceStr); 1034491d8ee7SSantosh Puranik if (!rfSource.empty()) 1035491d8ee7SSantosh Puranik { 1036ac106bf6SEd Tanous asyncResp->res.jsonValue["Boot"]["BootSourceOverrideTarget"] = 1037ac106bf6SEd Tanous rfSource; 1038491d8ee7SSantosh Puranik } 1039cd9a4666SKonstantin Aladyshev 1040cd9a4666SKonstantin Aladyshev // Get BootMode as BootSourceOverrideTarget is constructed 1041cd9a4666SKonstantin Aladyshev // from both BootSource and BootMode 1042*5e7c1f31SOliver Brewka getBootOverrideMode(asyncResp, computerSystemIndex); 10431e1e598dSJonathan Doman }); 1044491d8ee7SSantosh Puranik } 1045491d8ee7SSantosh Puranik 1046491d8ee7SSantosh Puranik /** 1047c21865c4SKonstantin Aladyshev * @brief This functions abstracts all the logic behind getting a 1048c21865c4SKonstantin Aladyshev * "BootSourceOverrideEnabled" property from an overall boot override enable 1049c21865c4SKonstantin Aladyshev * state 1050491d8ee7SSantosh Puranik * 1051ac106bf6SEd Tanous * @param[in] asyncResp Shared pointer for generating response message. 1052*5e7c1f31SOliver Brewka * @param[in] computerSystemIndex Index associated with the requested system 1053*5e7c1f31SOliver Brewka * @param[in] bootOverrideEnableSetting 1054491d8ee7SSantosh Puranik * 1055491d8ee7SSantosh Puranik * @return None. 1056491d8ee7SSantosh Puranik */ 1057491d8ee7SSantosh Puranik 1058ac106bf6SEd Tanous inline void processBootOverrideEnable( 1059ac106bf6SEd Tanous const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 1060*5e7c1f31SOliver Brewka const uint64_t computerSystemIndex, const bool bootOverrideEnableSetting) 1061c21865c4SKonstantin Aladyshev { 1062c21865c4SKonstantin Aladyshev if (!bootOverrideEnableSetting) 1063c21865c4SKonstantin Aladyshev { 1064ac106bf6SEd Tanous asyncResp->res.jsonValue["Boot"]["BootSourceOverrideEnabled"] = 1065ac106bf6SEd Tanous "Disabled"; 1066c21865c4SKonstantin Aladyshev return; 1067c21865c4SKonstantin Aladyshev } 1068c21865c4SKonstantin Aladyshev 1069*5e7c1f31SOliver Brewka sdbusplus::message::object_path path("/xyz/openbmc_project/control/host" + 1070*5e7c1f31SOliver Brewka std::to_string(computerSystemIndex)); 1071*5e7c1f31SOliver Brewka path /= "boot"; 1072*5e7c1f31SOliver Brewka path /= "one_time"; 1073*5e7c1f31SOliver Brewka 1074c21865c4SKonstantin Aladyshev // If boot source override is enabled, we need to check 'one_time' 1075c21865c4SKonstantin Aladyshev // property to set a correct value for the "BootSourceOverrideEnabled" 1076deae6a78SEd Tanous dbus::utility::getProperty<bool>( 1077*5e7c1f31SOliver Brewka "xyz.openbmc_project.Settings", path, 10781e1e598dSJonathan Doman "xyz.openbmc_project.Object.Enable", "Enabled", 1079ac106bf6SEd Tanous [asyncResp](const boost::system::error_code& ec, bool oneTimeSetting) { 1080491d8ee7SSantosh Puranik if (ec) 1081491d8ee7SSantosh Puranik { 1082b3e86cb0SGunnar Mills BMCWEB_LOG_ERROR("DBUS response error {}", ec); 1083ac106bf6SEd Tanous messages::internalError(asyncResp->res); 1084491d8ee7SSantosh Puranik return; 1085491d8ee7SSantosh Puranik } 1086491d8ee7SSantosh Puranik 1087c21865c4SKonstantin Aladyshev if (oneTimeSetting) 1088c21865c4SKonstantin Aladyshev { 1089ac106bf6SEd Tanous asyncResp->res.jsonValue["Boot"]["BootSourceOverrideEnabled"] = 1090ac106bf6SEd Tanous "Once"; 1091c21865c4SKonstantin Aladyshev } 1092c21865c4SKonstantin Aladyshev else 1093c21865c4SKonstantin Aladyshev { 1094ac106bf6SEd Tanous asyncResp->res.jsonValue["Boot"]["BootSourceOverrideEnabled"] = 1095c21865c4SKonstantin Aladyshev "Continuous"; 1096c21865c4SKonstantin Aladyshev } 10971e1e598dSJonathan Doman }); 1098491d8ee7SSantosh Puranik } 1099491d8ee7SSantosh Puranik 1100491d8ee7SSantosh Puranik /** 1101c21865c4SKonstantin Aladyshev * @brief Retrieves boot override enable over DBUS 1102c21865c4SKonstantin Aladyshev * 1103ac106bf6SEd Tanous * @param[in] asyncResp Shared pointer for generating response message. 1104*5e7c1f31SOliver Brewka * @param[in] computerSystemIndex Index associated with the requested system 1105c21865c4SKonstantin Aladyshev * 1106c21865c4SKonstantin Aladyshev * @return None. 1107c21865c4SKonstantin Aladyshev */ 1108504af5a0SPatrick Williams inline void getBootOverrideEnable( 1109*5e7c1f31SOliver Brewka const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 1110*5e7c1f31SOliver Brewka const uint64_t computerSystemIndex) 1111c21865c4SKonstantin Aladyshev { 1112*5e7c1f31SOliver Brewka sdbusplus::message::object_path path("/xyz/openbmc_project/control/host" + 1113*5e7c1f31SOliver Brewka std::to_string(computerSystemIndex)); 1114*5e7c1f31SOliver Brewka path /= "boot"; 1115*5e7c1f31SOliver Brewka 1116deae6a78SEd Tanous dbus::utility::getProperty<bool>( 1117*5e7c1f31SOliver Brewka "xyz.openbmc_project.Settings", path, 11181e1e598dSJonathan Doman "xyz.openbmc_project.Object.Enable", "Enabled", 1119*5e7c1f31SOliver Brewka [asyncResp, computerSystemIndex](const boost::system::error_code& ec, 11201e1e598dSJonathan Doman const bool bootOverrideEnable) { 1121c21865c4SKonstantin Aladyshev if (ec) 1122c21865c4SKonstantin Aladyshev { 11238f1a35b9SAllen.Wang // Service not available, no error, just don't return 11248f1a35b9SAllen.Wang // Boot Override Enable information 11258f1a35b9SAllen.Wang if (ec.value() != EBADR && 11268f1a35b9SAllen.Wang ec.value() != boost::asio::error::host_unreachable) 11275ef735c8SNan Zhou { 11288f1a35b9SAllen.Wang BMCWEB_LOG_ERROR("D-Bus response error: {}", ec); 1129ac106bf6SEd Tanous messages::internalError(asyncResp->res); 11308f1a35b9SAllen.Wang } 1131c21865c4SKonstantin Aladyshev return; 1132c21865c4SKonstantin Aladyshev } 1133c21865c4SKonstantin Aladyshev 1134*5e7c1f31SOliver Brewka processBootOverrideEnable(asyncResp, computerSystemIndex, 1135*5e7c1f31SOliver Brewka bootOverrideEnable); 11361e1e598dSJonathan Doman }); 1137c21865c4SKonstantin Aladyshev } 1138c21865c4SKonstantin Aladyshev 1139c21865c4SKonstantin Aladyshev /** 1140c21865c4SKonstantin Aladyshev * @brief Retrieves boot source override properties 1141c21865c4SKonstantin Aladyshev * 1142ac106bf6SEd Tanous * @param[in] asyncResp Shared pointer for generating response message. 1143*5e7c1f31SOliver Brewka * @param[in] computerSystemIndex Index associated with the requested system 1144c21865c4SKonstantin Aladyshev * 1145c21865c4SKonstantin Aladyshev * @return None. 1146c21865c4SKonstantin Aladyshev */ 1147504af5a0SPatrick Williams inline void getBootProperties( 1148*5e7c1f31SOliver Brewka const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 1149*5e7c1f31SOliver Brewka const uint64_t computerSystemIndex) 1150c21865c4SKonstantin Aladyshev { 115162598e31SEd Tanous BMCWEB_LOG_DEBUG("Get boot information."); 1152c21865c4SKonstantin Aladyshev 1153*5e7c1f31SOliver Brewka getBootOverrideSource(asyncResp, computerSystemIndex); 1154*5e7c1f31SOliver Brewka getBootOverrideType(asyncResp, computerSystemIndex); 1155*5e7c1f31SOliver Brewka getBootOverrideEnable(asyncResp, computerSystemIndex); 1156c21865c4SKonstantin Aladyshev } 1157c21865c4SKonstantin Aladyshev 1158c21865c4SKonstantin Aladyshev /** 1159c0557e1aSGunnar Mills * @brief Retrieves the Last Reset Time 1160c0557e1aSGunnar Mills * 1161c0557e1aSGunnar Mills * "Reset" is an overloaded term in Redfish, "Reset" includes power on 1162c0557e1aSGunnar Mills * and power off. Even though this is the "system" Redfish object look at the 1163c0557e1aSGunnar Mills * chassis D-Bus interface for the LastStateChangeTime since this has the 1164c0557e1aSGunnar Mills * last power operation time. 1165c0557e1aSGunnar Mills * 1166ac106bf6SEd Tanous * @param[in] asyncResp Shared pointer for generating response message. 1167c0557e1aSGunnar Mills * 1168c0557e1aSGunnar Mills * @return None. 1169c0557e1aSGunnar Mills */ 1170504af5a0SPatrick Williams inline void getLastResetTime( 1171*5e7c1f31SOliver Brewka const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 1172*5e7c1f31SOliver Brewka const uint64_t computerSystemIndex) 1173c0557e1aSGunnar Mills { 117462598e31SEd Tanous BMCWEB_LOG_DEBUG("Getting System Last Reset Time"); 1175c0557e1aSGunnar Mills 1176deae6a78SEd Tanous dbus::utility::getProperty<uint64_t>( 1177*5e7c1f31SOliver Brewka getChassisStateServiceName(computerSystemIndex), 1178*5e7c1f31SOliver Brewka getChassisStateObjectPath(computerSystemIndex), 11791e1e598dSJonathan Doman "xyz.openbmc_project.State.Chassis", "LastStateChangeTime", 1180ac106bf6SEd Tanous [asyncResp](const boost::system::error_code& ec, 1181ac106bf6SEd Tanous uint64_t lastResetTime) { 1182c0557e1aSGunnar Mills if (ec) 1183c0557e1aSGunnar Mills { 118462598e31SEd Tanous BMCWEB_LOG_DEBUG("D-BUS response error {}", ec); 1185c0557e1aSGunnar Mills return; 1186c0557e1aSGunnar Mills } 1187c0557e1aSGunnar Mills 1188c0557e1aSGunnar Mills // LastStateChangeTime is epoch time, in milliseconds 1189c0557e1aSGunnar Mills // https://github.com/openbmc/phosphor-dbus-interfaces/blob/33e8e1dd64da53a66e888d33dc82001305cd0bf9/xyz/openbmc_project/State/Chassis.interface.yaml#L19 11901e1e598dSJonathan Doman uint64_t lastResetTimeStamp = lastResetTime / 1000; 1191c0557e1aSGunnar Mills 1192c0557e1aSGunnar Mills // Convert to ISO 8601 standard 1193ac106bf6SEd Tanous asyncResp->res.jsonValue["LastResetTime"] = 11942b82937eSEd Tanous redfish::time_utils::getDateTimeUint(lastResetTimeStamp); 11951e1e598dSJonathan Doman }); 1196c0557e1aSGunnar Mills } 1197c0557e1aSGunnar Mills 1198c0557e1aSGunnar Mills /** 1199797d5daeSCorey Hardesty * @brief Retrieves the number of automatic boot Retry attempts allowed/left. 1200797d5daeSCorey Hardesty * 1201797d5daeSCorey Hardesty * The total number of automatic reboot retries allowed "RetryAttempts" and its 1202797d5daeSCorey Hardesty * corresponding property "AttemptsLeft" that keeps track of the amount of 1203797d5daeSCorey Hardesty * automatic retry attempts left are hosted in phosphor-state-manager through 1204797d5daeSCorey Hardesty * dbus. 1205797d5daeSCorey Hardesty * 1206ac106bf6SEd Tanous * @param[in] asyncResp Shared pointer for generating response message. 1207*5e7c1f31SOliver Brewka * @param[in] computerSystemIndex Index associated with the requested system 1208797d5daeSCorey Hardesty * 1209797d5daeSCorey Hardesty * @return None. 1210797d5daeSCorey Hardesty */ 1211ac106bf6SEd Tanous inline void getAutomaticRebootAttempts( 1212*5e7c1f31SOliver Brewka const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 1213*5e7c1f31SOliver Brewka const uint64_t computerSystemIndex) 1214797d5daeSCorey Hardesty { 121562598e31SEd Tanous BMCWEB_LOG_DEBUG("Get Automatic Retry policy"); 1216797d5daeSCorey Hardesty 1217deae6a78SEd Tanous dbus::utility::getAllProperties( 1218*5e7c1f31SOliver Brewka getHostStateServiceName(computerSystemIndex), 1219*5e7c1f31SOliver Brewka getHostStateObjectPath(computerSystemIndex), 1220797d5daeSCorey Hardesty "xyz.openbmc_project.Control.Boot.RebootAttempts", 1221ac106bf6SEd Tanous [asyncResp{asyncResp}]( 1222ac106bf6SEd Tanous const boost::system::error_code& ec, 1223797d5daeSCorey Hardesty const dbus::utility::DBusPropertiesMap& propertiesList) { 1224797d5daeSCorey Hardesty if (ec) 1225797d5daeSCorey Hardesty { 1226d39a8c28SAishwary Joshi if (ec.value() != EBADR && 1227d39a8c28SAishwary Joshi ec.value() != boost::asio::error::host_unreachable) 1228797d5daeSCorey Hardesty { 1229d39a8c28SAishwary Joshi // Service not available, no error, just don't return 1230d39a8c28SAishwary Joshi // RebootAttempts information 123162598e31SEd Tanous BMCWEB_LOG_ERROR("D-Bus responses error: {}", ec); 1232ac106bf6SEd Tanous messages::internalError(asyncResp->res); 1233797d5daeSCorey Hardesty } 1234797d5daeSCorey Hardesty return; 1235797d5daeSCorey Hardesty } 1236797d5daeSCorey Hardesty 1237797d5daeSCorey Hardesty const uint32_t* attemptsLeft = nullptr; 1238797d5daeSCorey Hardesty const uint32_t* retryAttempts = nullptr; 1239797d5daeSCorey Hardesty 1240797d5daeSCorey Hardesty const bool success = sdbusplus::unpackPropertiesNoThrow( 1241bd79bce8SPatrick Williams dbus_utils::UnpackErrorPrinter(), propertiesList, 1242bd79bce8SPatrick Williams "AttemptsLeft", attemptsLeft, "RetryAttempts", retryAttempts); 1243797d5daeSCorey Hardesty 1244797d5daeSCorey Hardesty if (!success) 1245797d5daeSCorey Hardesty { 1246ac106bf6SEd Tanous messages::internalError(asyncResp->res); 1247797d5daeSCorey Hardesty return; 1248797d5daeSCorey Hardesty } 1249797d5daeSCorey Hardesty 1250797d5daeSCorey Hardesty if (attemptsLeft != nullptr) 1251797d5daeSCorey Hardesty { 1252ac106bf6SEd Tanous asyncResp->res 1253ac106bf6SEd Tanous .jsonValue["Boot"]["RemainingAutomaticRetryAttempts"] = 1254797d5daeSCorey Hardesty *attemptsLeft; 1255797d5daeSCorey Hardesty } 1256797d5daeSCorey Hardesty 1257797d5daeSCorey Hardesty if (retryAttempts != nullptr) 1258797d5daeSCorey Hardesty { 1259ac106bf6SEd Tanous asyncResp->res.jsonValue["Boot"]["AutomaticRetryAttempts"] = 1260797d5daeSCorey Hardesty *retryAttempts; 1261797d5daeSCorey Hardesty } 1262797d5daeSCorey Hardesty }); 1263797d5daeSCorey Hardesty } 1264797d5daeSCorey Hardesty 1265797d5daeSCorey Hardesty /** 12666bd5a8d2SGunnar Mills * @brief Retrieves Automatic Retry properties. Known on D-Bus as AutoReboot. 12676bd5a8d2SGunnar Mills * 1268ac106bf6SEd Tanous * @param[in] asyncResp Shared pointer for generating response message. 1269*5e7c1f31SOliver Brewka * @param[in] computerSystemIndex Index associated with the requested system 12706bd5a8d2SGunnar Mills * 12716bd5a8d2SGunnar Mills * @return None. 12726bd5a8d2SGunnar Mills */ 1273504af5a0SPatrick Williams inline void getAutomaticRetryPolicy( 1274*5e7c1f31SOliver Brewka const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 1275*5e7c1f31SOliver Brewka const uint64_t computerSystemIndex) 12766bd5a8d2SGunnar Mills { 127762598e31SEd Tanous BMCWEB_LOG_DEBUG("Get Automatic Retry policy"); 12786bd5a8d2SGunnar Mills 1279*5e7c1f31SOliver Brewka sdbusplus::message::object_path path("/xyz/openbmc_project/control/host" + 1280*5e7c1f31SOliver Brewka std::to_string(computerSystemIndex)); 1281*5e7c1f31SOliver Brewka path /= "auto_reboot"; 1282*5e7c1f31SOliver Brewka 1283deae6a78SEd Tanous dbus::utility::getProperty<bool>( 1284*5e7c1f31SOliver Brewka "xyz.openbmc_project.Settings", path, 12851e1e598dSJonathan Doman "xyz.openbmc_project.Control.Boot.RebootPolicy", "AutoReboot", 1286*5e7c1f31SOliver Brewka [asyncResp, computerSystemIndex](const boost::system::error_code& ec, 1287ac106bf6SEd Tanous bool autoRebootEnabled) { 12886bd5a8d2SGunnar Mills if (ec) 12896bd5a8d2SGunnar Mills { 1290d39a8c28SAishwary Joshi // Service not available, no error, just don't return 1291d39a8c28SAishwary Joshi // AutoReboot information 1292d39a8c28SAishwary Joshi if (ec.value() != EBADR && 1293d39a8c28SAishwary Joshi ec.value() != boost::asio::error::host_unreachable) 1294797d5daeSCorey Hardesty { 129562598e31SEd Tanous BMCWEB_LOG_ERROR("D-Bus responses error: {}", ec); 1296ac106bf6SEd Tanous messages::internalError(asyncResp->res); 1297797d5daeSCorey Hardesty } 12986bd5a8d2SGunnar Mills return; 12996bd5a8d2SGunnar Mills } 13006bd5a8d2SGunnar Mills 130162598e31SEd Tanous BMCWEB_LOG_DEBUG("Auto Reboot: {}", autoRebootEnabled); 1302e05aec50SEd Tanous if (autoRebootEnabled) 13036bd5a8d2SGunnar Mills { 1304ac106bf6SEd Tanous asyncResp->res.jsonValue["Boot"]["AutomaticRetryConfig"] = 13056bd5a8d2SGunnar Mills "RetryAttempts"; 13066bd5a8d2SGunnar Mills } 13076bd5a8d2SGunnar Mills else 13086bd5a8d2SGunnar Mills { 1309ac106bf6SEd Tanous asyncResp->res.jsonValue["Boot"]["AutomaticRetryConfig"] = 1310ac106bf6SEd Tanous "Disabled"; 13116bd5a8d2SGunnar Mills } 1312*5e7c1f31SOliver Brewka getAutomaticRebootAttempts(asyncResp, computerSystemIndex); 131369f35306SGunnar Mills 131469f35306SGunnar Mills // "AutomaticRetryConfig" can be 3 values, Disabled, RetryAlways, 131569f35306SGunnar Mills // and RetryAttempts. OpenBMC only supports Disabled and 131669f35306SGunnar Mills // RetryAttempts. 131720fa6a2cSEd Tanous nlohmann::json::array_t allowed; 131820fa6a2cSEd Tanous allowed.emplace_back("Disabled"); 131920fa6a2cSEd Tanous allowed.emplace_back("RetryAttempts"); 1320ac106bf6SEd Tanous asyncResp->res 1321bd79bce8SPatrick Williams .jsonValue["Boot"] 1322bd79bce8SPatrick Williams ["AutomaticRetryConfig@Redfish.AllowableValues"] = 132320fa6a2cSEd Tanous std::move(allowed); 13241e1e598dSJonathan Doman }); 13256bd5a8d2SGunnar Mills } 13266bd5a8d2SGunnar Mills 13276bd5a8d2SGunnar Mills /** 1328797d5daeSCorey Hardesty * @brief Sets RetryAttempts 1329797d5daeSCorey Hardesty * 1330ac106bf6SEd Tanous * @param[in] asyncResp Shared pointer for generating response message. 1331*5e7c1f31SOliver Brewka * @param[in] computerSystemIndex Index associated with the requested system 1332797d5daeSCorey Hardesty * @param[in] retryAttempts "AutomaticRetryAttempts" from request. 1333797d5daeSCorey Hardesty * 1334797d5daeSCorey Hardesty *@return None. 1335797d5daeSCorey Hardesty */ 1336797d5daeSCorey Hardesty 1337ac106bf6SEd Tanous inline void setAutomaticRetryAttempts( 1338ac106bf6SEd Tanous const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 1339797d5daeSCorey Hardesty const uint32_t retryAttempts) 1340797d5daeSCorey Hardesty { 134162598e31SEd Tanous BMCWEB_LOG_DEBUG("Set Automatic Retry Attempts."); 134287c44966SAsmitha Karunanithi setDbusProperty( 1343e93abac6SGinu George asyncResp, "Boot/AutomaticRetryAttempts", 1344e93abac6SGinu George "xyz.openbmc_project.State.Host", 134587c44966SAsmitha Karunanithi sdbusplus::message::object_path("/xyz/openbmc_project/state/host0"), 13469ae226faSGeorge Liu "xyz.openbmc_project.Control.Boot.RebootAttempts", "RetryAttempts", 1347e93abac6SGinu George retryAttempts); 1348797d5daeSCorey Hardesty } 1349797d5daeSCorey Hardesty 13508d69c668SEd Tanous inline computer_system::PowerRestorePolicyTypes 13518d69c668SEd Tanous redfishPowerRestorePolicyFromDbus(std::string_view value) 13528d69c668SEd Tanous { 13538d69c668SEd Tanous if (value == 13548d69c668SEd Tanous "xyz.openbmc_project.Control.Power.RestorePolicy.Policy.AlwaysOn") 13558d69c668SEd Tanous { 13568d69c668SEd Tanous return computer_system::PowerRestorePolicyTypes::AlwaysOn; 13578d69c668SEd Tanous } 13588d69c668SEd Tanous if (value == 13598d69c668SEd Tanous "xyz.openbmc_project.Control.Power.RestorePolicy.Policy.AlwaysOff") 13608d69c668SEd Tanous { 13618d69c668SEd Tanous return computer_system::PowerRestorePolicyTypes::AlwaysOff; 13628d69c668SEd Tanous } 13638d69c668SEd Tanous if (value == 13643a34b742SGunnar Mills "xyz.openbmc_project.Control.Power.RestorePolicy.Policy.Restore") 13658d69c668SEd Tanous { 13668d69c668SEd Tanous return computer_system::PowerRestorePolicyTypes::LastState; 13678d69c668SEd Tanous } 13688d69c668SEd Tanous if (value == "xyz.openbmc_project.Control.Power.RestorePolicy.Policy.None") 13698d69c668SEd Tanous { 13708d69c668SEd Tanous return computer_system::PowerRestorePolicyTypes::AlwaysOff; 13718d69c668SEd Tanous } 13728d69c668SEd Tanous return computer_system::PowerRestorePolicyTypes::Invalid; 13738d69c668SEd Tanous } 1374797d5daeSCorey Hardesty /** 1375c6a620f2SGeorge Liu * @brief Retrieves power restore policy over DBUS. 1376c6a620f2SGeorge Liu * 1377ac106bf6SEd Tanous * @param[in] asyncResp Shared pointer for generating response message. 1378c6a620f2SGeorge Liu * 1379c6a620f2SGeorge Liu * @return None. 1380c6a620f2SGeorge Liu */ 1381504af5a0SPatrick Williams inline void getPowerRestorePolicy( 1382*5e7c1f31SOliver Brewka const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 1383*5e7c1f31SOliver Brewka const uint64_t computerSystemIndex) 1384c6a620f2SGeorge Liu { 138562598e31SEd Tanous BMCWEB_LOG_DEBUG("Get power restore policy"); 1386c6a620f2SGeorge Liu 1387*5e7c1f31SOliver Brewka sdbusplus::message::object_path path("/xyz/openbmc_project/control/host" + 1388*5e7c1f31SOliver Brewka std::to_string(computerSystemIndex)); 1389*5e7c1f31SOliver Brewka path /= "power_restore_policy"; 1390*5e7c1f31SOliver Brewka 1391deae6a78SEd Tanous dbus::utility::getProperty<std::string>( 1392*5e7c1f31SOliver Brewka "xyz.openbmc_project.Settings", path, 13931e1e598dSJonathan Doman "xyz.openbmc_project.Control.Power.RestorePolicy", "PowerRestorePolicy", 1394ac106bf6SEd Tanous [asyncResp](const boost::system::error_code& ec, 13955e7e2dc5SEd Tanous const std::string& policy) { 1396c6a620f2SGeorge Liu if (ec) 1397c6a620f2SGeorge Liu { 139862598e31SEd Tanous BMCWEB_LOG_DEBUG("DBUS response error {}", ec); 1399c6a620f2SGeorge Liu return; 1400c6a620f2SGeorge Liu } 14018d69c668SEd Tanous computer_system::PowerRestorePolicyTypes restore = 14028d69c668SEd Tanous redfishPowerRestorePolicyFromDbus(policy); 14038d69c668SEd Tanous if (restore == computer_system::PowerRestorePolicyTypes::Invalid) 1404c6a620f2SGeorge Liu { 1405ac106bf6SEd Tanous messages::internalError(asyncResp->res); 1406c6a620f2SGeorge Liu return; 1407c6a620f2SGeorge Liu } 1408c6a620f2SGeorge Liu 14098d69c668SEd Tanous asyncResp->res.jsonValue["PowerRestorePolicy"] = restore; 14101e1e598dSJonathan Doman }); 1411c6a620f2SGeorge Liu } 1412c6a620f2SGeorge Liu 1413c6a620f2SGeorge Liu /** 14149dcfe8c1SAlbert Zhang * @brief Stop Boot On Fault over DBUS. 14159dcfe8c1SAlbert Zhang * 14169dcfe8c1SAlbert Zhang * @param[in] asyncResp Shared pointer for generating response message. 14179dcfe8c1SAlbert Zhang * 14189dcfe8c1SAlbert Zhang * @return None. 14199dcfe8c1SAlbert Zhang */ 1420504af5a0SPatrick Williams inline void getStopBootOnFault( 1421504af5a0SPatrick Williams const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) 14229dcfe8c1SAlbert Zhang { 142362598e31SEd Tanous BMCWEB_LOG_DEBUG("Get Stop Boot On Fault"); 14249dcfe8c1SAlbert Zhang 1425deae6a78SEd Tanous dbus::utility::getProperty<bool>( 1426deae6a78SEd Tanous "xyz.openbmc_project.Settings", "/xyz/openbmc_project/logging/settings", 14279dcfe8c1SAlbert Zhang "xyz.openbmc_project.Logging.Settings", "QuiesceOnHwError", 14289dcfe8c1SAlbert Zhang [asyncResp](const boost::system::error_code& ec, bool value) { 14299dcfe8c1SAlbert Zhang if (ec) 14309dcfe8c1SAlbert Zhang { 1431d39a8c28SAishwary Joshi // Service not available, no error, just don't return 1432d39a8c28SAishwary Joshi // StopBootOnFault information 1433d39a8c28SAishwary Joshi if (ec.value() != EBADR || 1434d39a8c28SAishwary Joshi ec.value() != boost::asio::error::host_unreachable) 14359dcfe8c1SAlbert Zhang { 1436b3e86cb0SGunnar Mills BMCWEB_LOG_ERROR("DBUS response error {}", ec); 14379dcfe8c1SAlbert Zhang messages::internalError(asyncResp->res); 14389dcfe8c1SAlbert Zhang } 14399dcfe8c1SAlbert Zhang return; 14409dcfe8c1SAlbert Zhang } 14419dcfe8c1SAlbert Zhang 14429dcfe8c1SAlbert Zhang if (value) 14439dcfe8c1SAlbert Zhang { 1444539d8c6bSEd Tanous asyncResp->res.jsonValue["Boot"]["StopBootOnFault"] = 1445539d8c6bSEd Tanous computer_system::StopBootOnFault::AnyFault; 14469dcfe8c1SAlbert Zhang } 14479dcfe8c1SAlbert Zhang else 14489dcfe8c1SAlbert Zhang { 1449539d8c6bSEd Tanous asyncResp->res.jsonValue["Boot"]["StopBootOnFault"] = 1450539d8c6bSEd Tanous computer_system::StopBootOnFault::Never; 14519dcfe8c1SAlbert Zhang } 14529dcfe8c1SAlbert Zhang }); 14539dcfe8c1SAlbert Zhang } 14549dcfe8c1SAlbert Zhang 1455*5e7c1f31SOliver Brewka inline void getTrustedModuleRequiredToBootCallback( 1456*5e7c1f31SOliver Brewka const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 1457*5e7c1f31SOliver Brewka const uint64_t computerSystemIndex, const boost::system::error_code& ec, 1458*5e7c1f31SOliver Brewka const dbus::utility::MapperGetSubTreeResponse& subtree) 14591981771bSAli Ahmed { 14601981771bSAli Ahmed if (ec) 14611981771bSAli Ahmed { 1462*5e7c1f31SOliver Brewka BMCWEB_LOG_DEBUG("DBUS response error on TPM.Policy GetSubTree{}", ec); 14631981771bSAli Ahmed // This is an optional D-Bus object so just return if 14641981771bSAli Ahmed // error occurs 14651981771bSAli Ahmed return; 14661981771bSAli Ahmed } 146726f6976fSEd Tanous if (subtree.empty()) 14681981771bSAli Ahmed { 14691981771bSAli Ahmed // As noted above, this is an optional interface so just return 14701981771bSAli Ahmed // if there is no instance found 14711981771bSAli Ahmed return; 14721981771bSAli Ahmed } 14731981771bSAli Ahmed 1474*5e7c1f31SOliver Brewka std::string path; 1475*5e7c1f31SOliver Brewka std::string service; 1476*5e7c1f31SOliver Brewka 1477*5e7c1f31SOliver Brewka if constexpr (BMCWEB_EXPERIMENTAL_REDFISH_MULTI_COMPUTER_SYSTEM) 14781981771bSAli Ahmed { 1479*5e7c1f31SOliver Brewka if (!indexMatchingSubTreeMapObjectPath(asyncResp, computerSystemIndex, 1480*5e7c1f31SOliver Brewka subtree, path, service)) 1481*5e7c1f31SOliver Brewka { 14821981771bSAli Ahmed return; 14831981771bSAli Ahmed } 1484*5e7c1f31SOliver Brewka } 1485*5e7c1f31SOliver Brewka else 1486*5e7c1f31SOliver Brewka { 14871981771bSAli Ahmed // Make sure the Dbus response map has a service and objectPath 14881981771bSAli Ahmed // field 14891981771bSAli Ahmed if (subtree[0].first.empty() || subtree[0].second.size() != 1) 14901981771bSAli Ahmed { 149162598e31SEd Tanous BMCWEB_LOG_DEBUG("TPM.Policy mapper error!"); 1492ac106bf6SEd Tanous messages::internalError(asyncResp->res); 14931981771bSAli Ahmed return; 14941981771bSAli Ahmed } 14951981771bSAli Ahmed 1496*5e7c1f31SOliver Brewka path = subtree[0].first; 1497*5e7c1f31SOliver Brewka service = subtree[0].second.begin()->first; 1498*5e7c1f31SOliver Brewka } 1499*5e7c1f31SOliver Brewka 1500*5e7c1f31SOliver Brewka BMCWEB_LOG_DEBUG("found tpm service {}", service); 1501*5e7c1f31SOliver Brewka BMCWEB_LOG_DEBUG("found tpm path {}", path); 15021981771bSAli Ahmed 15031981771bSAli Ahmed // Valid TPM Enable object found, now reading the current value 1504deae6a78SEd Tanous dbus::utility::getProperty<bool>( 1505*5e7c1f31SOliver Brewka service, path, "xyz.openbmc_project.Control.TPM.Policy", "TPMEnable", 1506*5e7c1f31SOliver Brewka [asyncResp](const boost::system::error_code& ec2, bool tpmRequired) { 15078a592810SEd Tanous if (ec2) 15081981771bSAli Ahmed { 1509*5e7c1f31SOliver Brewka BMCWEB_LOG_ERROR("D-BUS response error on TPM.Policy Get{}", 1510*5e7c1f31SOliver Brewka ec2); 1511ac106bf6SEd Tanous messages::internalError(asyncResp->res); 15121981771bSAli Ahmed return; 15131981771bSAli Ahmed } 15141981771bSAli Ahmed 15151e1e598dSJonathan Doman if (tpmRequired) 15161981771bSAli Ahmed { 1517ac106bf6SEd Tanous asyncResp->res 1518ac106bf6SEd Tanous .jsonValue["Boot"]["TrustedModuleRequiredToBoot"] = 15191981771bSAli Ahmed "Required"; 15201981771bSAli Ahmed } 15211981771bSAli Ahmed else 15221981771bSAli Ahmed { 1523ac106bf6SEd Tanous asyncResp->res 1524ac106bf6SEd Tanous .jsonValue["Boot"]["TrustedModuleRequiredToBoot"] = 15251981771bSAli Ahmed "Disabled"; 15261981771bSAli Ahmed } 15271e1e598dSJonathan Doman }); 1528*5e7c1f31SOliver Brewka } 1529*5e7c1f31SOliver Brewka 1530*5e7c1f31SOliver Brewka /** 1531*5e7c1f31SOliver Brewka * @brief Get TrustedModuleRequiredToBoot property. Determines whether or not 1532*5e7c1f31SOliver Brewka * TPM is required for booting the host. 1533*5e7c1f31SOliver Brewka * 1534*5e7c1f31SOliver Brewka * @param[in] asyncResp Shared pointer for generating response message. 1535*5e7c1f31SOliver Brewka * @param[in] computerSystemIndex Index associated with the requested system 1536*5e7c1f31SOliver Brewka * 1537*5e7c1f31SOliver Brewka * @return None. 1538*5e7c1f31SOliver Brewka */ 1539*5e7c1f31SOliver Brewka inline void getTrustedModuleRequiredToBoot( 1540*5e7c1f31SOliver Brewka const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 1541*5e7c1f31SOliver Brewka const uint64_t computerSystemIndex) 1542*5e7c1f31SOliver Brewka { 1543*5e7c1f31SOliver Brewka BMCWEB_LOG_DEBUG("Get TPM required to boot."); 1544*5e7c1f31SOliver Brewka constexpr std::array<std::string_view, 1> interfaces = { 1545*5e7c1f31SOliver Brewka "xyz.openbmc_project.Control.TPM.Policy"}; 1546*5e7c1f31SOliver Brewka dbus::utility::getSubTree( 1547*5e7c1f31SOliver Brewka "/", 0, interfaces, 1548*5e7c1f31SOliver Brewka std::bind_front(getTrustedModuleRequiredToBootCallback, asyncResp, 1549*5e7c1f31SOliver Brewka computerSystemIndex)); 15501981771bSAli Ahmed } 15511981771bSAli Ahmed 15521981771bSAli Ahmed /** 15531c05dae3SAli Ahmed * @brief Set TrustedModuleRequiredToBoot property. Determines whether or not 15541c05dae3SAli Ahmed * TPM is required for booting the host. 15551c05dae3SAli Ahmed * 1556ac106bf6SEd Tanous * @param[in] asyncResp Shared pointer for generating response message. 15571c05dae3SAli Ahmed * @param[in] tpmRequired Value to set TPM Required To Boot property to. 15581c05dae3SAli Ahmed * 15591c05dae3SAli Ahmed * @return None. 15601c05dae3SAli Ahmed */ 15611c05dae3SAli Ahmed inline void setTrustedModuleRequiredToBoot( 1562ac106bf6SEd Tanous const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, const bool tpmRequired) 15631c05dae3SAli Ahmed { 156462598e31SEd Tanous BMCWEB_LOG_DEBUG("Set TrustedModuleRequiredToBoot."); 1565e99073f5SGeorge Liu constexpr std::array<std::string_view, 1> interfaces = { 1566e99073f5SGeorge Liu "xyz.openbmc_project.Control.TPM.Policy"}; 1567e99073f5SGeorge Liu dbus::utility::getSubTree( 1568e99073f5SGeorge Liu "/", 0, interfaces, 1569ac106bf6SEd Tanous [asyncResp, 1570e99073f5SGeorge Liu tpmRequired](const boost::system::error_code& ec, 1571e99073f5SGeorge Liu const dbus::utility::MapperGetSubTreeResponse& subtree) { 15721c05dae3SAli Ahmed if (ec) 15731c05dae3SAli Ahmed { 1574bd79bce8SPatrick Williams BMCWEB_LOG_ERROR( 1575bd79bce8SPatrick Williams "DBUS response error on TPM.Policy GetSubTree{}", ec); 1576ac106bf6SEd Tanous messages::internalError(asyncResp->res); 15771c05dae3SAli Ahmed return; 15781c05dae3SAli Ahmed } 157926f6976fSEd Tanous if (subtree.empty()) 15801c05dae3SAli Ahmed { 1581bd79bce8SPatrick Williams messages::propertyValueNotInList(asyncResp->res, 1582bd79bce8SPatrick Williams "ComputerSystem", 15831c05dae3SAli Ahmed "TrustedModuleRequiredToBoot"); 15841c05dae3SAli Ahmed return; 15851c05dae3SAli Ahmed } 15861c05dae3SAli Ahmed 15871c05dae3SAli Ahmed /* When there is more than one TPMEnable object... */ 15881c05dae3SAli Ahmed if (subtree.size() > 1) 15891c05dae3SAli Ahmed { 159062598e31SEd Tanous BMCWEB_LOG_DEBUG( 159162598e31SEd Tanous "DBUS response has more than 1 TPM Enable object:{}", 159262598e31SEd Tanous subtree.size()); 15931c05dae3SAli Ahmed // Throw an internal Error and return 1594ac106bf6SEd Tanous messages::internalError(asyncResp->res); 15951c05dae3SAli Ahmed return; 15961c05dae3SAli Ahmed } 15971c05dae3SAli Ahmed 15981c05dae3SAli Ahmed // Make sure the Dbus response map has a service and objectPath 15991c05dae3SAli Ahmed // field 16001c05dae3SAli Ahmed if (subtree[0].first.empty() || subtree[0].second.size() != 1) 16011c05dae3SAli Ahmed { 160262598e31SEd Tanous BMCWEB_LOG_DEBUG("TPM.Policy mapper error!"); 1603ac106bf6SEd Tanous messages::internalError(asyncResp->res); 16041c05dae3SAli Ahmed return; 16051c05dae3SAli Ahmed } 16061c05dae3SAli Ahmed 16071c05dae3SAli Ahmed const std::string& path = subtree[0].first; 16081c05dae3SAli Ahmed const std::string& serv = subtree[0].second.begin()->first; 16091c05dae3SAli Ahmed 16101c05dae3SAli Ahmed if (serv.empty()) 16111c05dae3SAli Ahmed { 161262598e31SEd Tanous BMCWEB_LOG_DEBUG("TPM.Policy service mapper error!"); 1613ac106bf6SEd Tanous messages::internalError(asyncResp->res); 16141c05dae3SAli Ahmed return; 16151c05dae3SAli Ahmed } 16161c05dae3SAli Ahmed 16171c05dae3SAli Ahmed // Valid TPM Enable object found, now setting the value 1618e93abac6SGinu George setDbusProperty(asyncResp, "Boot/TrustedModuleRequiredToBoot", serv, 1619e93abac6SGinu George path, "xyz.openbmc_project.Control.TPM.Policy", 1620e93abac6SGinu George "TPMEnable", tpmRequired); 1621e99073f5SGeorge Liu }); 16221c05dae3SAli Ahmed } 16231c05dae3SAli Ahmed 16241c05dae3SAli Ahmed /** 1625491d8ee7SSantosh Puranik * @brief Sets boot properties into DBUS object(s). 1626491d8ee7SSantosh Puranik * 1627ac106bf6SEd Tanous * @param[in] asyncResp Shared pointer for generating response message. 1628cd9a4666SKonstantin Aladyshev * @param[in] bootType The boot type to set. 1629cd9a4666SKonstantin Aladyshev * @return Integer error code. 1630cd9a4666SKonstantin Aladyshev */ 1631ac106bf6SEd Tanous inline void setBootType(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 1632cd9a4666SKonstantin Aladyshev const std::optional<std::string>& bootType) 1633cd9a4666SKonstantin Aladyshev { 1634c21865c4SKonstantin Aladyshev std::string bootTypeStr; 1635cd9a4666SKonstantin Aladyshev 1636c21865c4SKonstantin Aladyshev if (!bootType) 1637cd9a4666SKonstantin Aladyshev { 1638c21865c4SKonstantin Aladyshev return; 1639c21865c4SKonstantin Aladyshev } 1640c21865c4SKonstantin Aladyshev 1641cd9a4666SKonstantin Aladyshev // Source target specified 164262598e31SEd Tanous BMCWEB_LOG_DEBUG("Boot type: {}", *bootType); 1643cd9a4666SKonstantin Aladyshev // Figure out which DBUS interface and property to use 1644cd9a4666SKonstantin Aladyshev if (*bootType == "Legacy") 1645cd9a4666SKonstantin Aladyshev { 1646cd9a4666SKonstantin Aladyshev bootTypeStr = "xyz.openbmc_project.Control.Boot.Type.Types.Legacy"; 1647cd9a4666SKonstantin Aladyshev } 1648cd9a4666SKonstantin Aladyshev else if (*bootType == "UEFI") 1649cd9a4666SKonstantin Aladyshev { 1650cd9a4666SKonstantin Aladyshev bootTypeStr = "xyz.openbmc_project.Control.Boot.Type.Types.EFI"; 1651cd9a4666SKonstantin Aladyshev } 1652cd9a4666SKonstantin Aladyshev else 1653cd9a4666SKonstantin Aladyshev { 165462598e31SEd Tanous BMCWEB_LOG_DEBUG("Invalid property value for " 165562598e31SEd Tanous "BootSourceOverrideMode: {}", 165662598e31SEd Tanous *bootType); 1657ac106bf6SEd Tanous messages::propertyValueNotInList(asyncResp->res, *bootType, 1658cd9a4666SKonstantin Aladyshev "BootSourceOverrideMode"); 1659cd9a4666SKonstantin Aladyshev return; 1660cd9a4666SKonstantin Aladyshev } 1661cd9a4666SKonstantin Aladyshev 1662cd9a4666SKonstantin Aladyshev // Act on validated parameters 166362598e31SEd Tanous BMCWEB_LOG_DEBUG("DBUS boot type: {}", bootTypeStr); 1664cd9a4666SKonstantin Aladyshev 1665e93abac6SGinu George setDbusProperty(asyncResp, "Boot/BootSourceOverrideMode", 1666e93abac6SGinu George "xyz.openbmc_project.Settings", 166787c44966SAsmitha Karunanithi sdbusplus::message::object_path( 166887c44966SAsmitha Karunanithi "/xyz/openbmc_project/control/host0/boot"), 166987c44966SAsmitha Karunanithi "xyz.openbmc_project.Control.Boot.Type", "BootType", 1670e93abac6SGinu George bootTypeStr); 1671cd9a4666SKonstantin Aladyshev } 1672cd9a4666SKonstantin Aladyshev 1673cd9a4666SKonstantin Aladyshev /** 1674cd9a4666SKonstantin Aladyshev * @brief Sets boot properties into DBUS object(s). 1675cd9a4666SKonstantin Aladyshev * 1676ac106bf6SEd Tanous * @param[in] asyncResp Shared pointer for generating response 1677ac106bf6SEd Tanous * message. 1678c21865c4SKonstantin Aladyshev * @param[in] bootType The boot type to set. 1679c21865c4SKonstantin Aladyshev * @return Integer error code. 1680c21865c4SKonstantin Aladyshev */ 1681ac106bf6SEd Tanous inline void setBootEnable(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 1682c21865c4SKonstantin Aladyshev const std::optional<std::string>& bootEnable) 1683c21865c4SKonstantin Aladyshev { 1684c21865c4SKonstantin Aladyshev if (!bootEnable) 1685c21865c4SKonstantin Aladyshev { 1686c21865c4SKonstantin Aladyshev return; 1687c21865c4SKonstantin Aladyshev } 1688c21865c4SKonstantin Aladyshev // Source target specified 168962598e31SEd Tanous BMCWEB_LOG_DEBUG("Boot enable: {}", *bootEnable); 1690c21865c4SKonstantin Aladyshev 1691c21865c4SKonstantin Aladyshev bool bootOverrideEnable = false; 1692c21865c4SKonstantin Aladyshev bool bootOverridePersistent = false; 1693c21865c4SKonstantin Aladyshev // Figure out which DBUS interface and property to use 1694c21865c4SKonstantin Aladyshev if (*bootEnable == "Disabled") 1695c21865c4SKonstantin Aladyshev { 1696c21865c4SKonstantin Aladyshev bootOverrideEnable = false; 1697c21865c4SKonstantin Aladyshev } 1698c21865c4SKonstantin Aladyshev else if (*bootEnable == "Once") 1699c21865c4SKonstantin Aladyshev { 1700c21865c4SKonstantin Aladyshev bootOverrideEnable = true; 1701c21865c4SKonstantin Aladyshev bootOverridePersistent = false; 1702c21865c4SKonstantin Aladyshev } 1703c21865c4SKonstantin Aladyshev else if (*bootEnable == "Continuous") 1704c21865c4SKonstantin Aladyshev { 1705c21865c4SKonstantin Aladyshev bootOverrideEnable = true; 1706c21865c4SKonstantin Aladyshev bootOverridePersistent = true; 1707c21865c4SKonstantin Aladyshev } 1708c21865c4SKonstantin Aladyshev else 1709c21865c4SKonstantin Aladyshev { 171062598e31SEd Tanous BMCWEB_LOG_DEBUG( 171162598e31SEd Tanous "Invalid property value for BootSourceOverrideEnabled: {}", 171262598e31SEd Tanous *bootEnable); 1713ac106bf6SEd Tanous messages::propertyValueNotInList(asyncResp->res, *bootEnable, 1714c21865c4SKonstantin Aladyshev "BootSourceOverrideEnabled"); 1715c21865c4SKonstantin Aladyshev return; 1716c21865c4SKonstantin Aladyshev } 1717c21865c4SKonstantin Aladyshev 1718c21865c4SKonstantin Aladyshev // Act on validated parameters 171962598e31SEd Tanous BMCWEB_LOG_DEBUG("DBUS boot override enable: {}", bootOverrideEnable); 1720c21865c4SKonstantin Aladyshev 1721e93abac6SGinu George setDbusProperty(asyncResp, "Boot/BootSourceOverrideEnabled", 1722e93abac6SGinu George "xyz.openbmc_project.Settings", 172387c44966SAsmitha Karunanithi sdbusplus::message::object_path( 172487c44966SAsmitha Karunanithi "/xyz/openbmc_project/control/host0/boot"), 172587c44966SAsmitha Karunanithi "xyz.openbmc_project.Object.Enable", "Enabled", 1726e93abac6SGinu George bootOverrideEnable); 1727c21865c4SKonstantin Aladyshev 1728c21865c4SKonstantin Aladyshev if (!bootOverrideEnable) 1729c21865c4SKonstantin Aladyshev { 1730c21865c4SKonstantin Aladyshev return; 1731c21865c4SKonstantin Aladyshev } 1732c21865c4SKonstantin Aladyshev 1733c21865c4SKonstantin Aladyshev // In case boot override is enabled we need to set correct value for the 1734c21865c4SKonstantin Aladyshev // 'one_time' enable DBus interface 173562598e31SEd Tanous BMCWEB_LOG_DEBUG("DBUS boot override persistent: {}", 173662598e31SEd Tanous bootOverridePersistent); 1737c21865c4SKonstantin Aladyshev 1738e93abac6SGinu George setDbusProperty(asyncResp, "Boot/BootSourceOverrideEnabled", 1739e93abac6SGinu George "xyz.openbmc_project.Settings", 174087c44966SAsmitha Karunanithi sdbusplus::message::object_path( 174187c44966SAsmitha Karunanithi "/xyz/openbmc_project/control/host0/boot/one_time"), 174287c44966SAsmitha Karunanithi "xyz.openbmc_project.Object.Enable", "Enabled", 1743e93abac6SGinu George !bootOverridePersistent); 1744c21865c4SKonstantin Aladyshev } 1745c21865c4SKonstantin Aladyshev 1746c21865c4SKonstantin Aladyshev /** 1747c21865c4SKonstantin Aladyshev * @brief Sets boot properties into DBUS object(s). 1748c21865c4SKonstantin Aladyshev * 1749ac106bf6SEd Tanous * @param[in] asyncResp Shared pointer for generating response message. 1750491d8ee7SSantosh Puranik * @param[in] bootSource The boot source to set. 1751491d8ee7SSantosh Puranik * 1752265c1602SJohnathan Mantey * @return Integer error code. 1753491d8ee7SSantosh Puranik */ 1754504af5a0SPatrick Williams inline void setBootModeOrSource( 1755504af5a0SPatrick Williams const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 1756cd9a4666SKonstantin Aladyshev const std::optional<std::string>& bootSource) 1757491d8ee7SSantosh Puranik { 1758c21865c4SKonstantin Aladyshev std::string bootSourceStr; 1759c21865c4SKonstantin Aladyshev std::string bootModeStr; 1760944ffaf9SJohnathan Mantey 1761c21865c4SKonstantin Aladyshev if (!bootSource) 1762491d8ee7SSantosh Puranik { 1763c21865c4SKonstantin Aladyshev return; 1764c21865c4SKonstantin Aladyshev } 1765c21865c4SKonstantin Aladyshev 1766491d8ee7SSantosh Puranik // Source target specified 176762598e31SEd Tanous BMCWEB_LOG_DEBUG("Boot source: {}", *bootSource); 1768491d8ee7SSantosh Puranik // Figure out which DBUS interface and property to use 1769ac106bf6SEd Tanous if (assignBootParameters(asyncResp, *bootSource, bootSourceStr, 1770ac106bf6SEd Tanous bootModeStr) != 0) 1771491d8ee7SSantosh Puranik { 177262598e31SEd Tanous BMCWEB_LOG_DEBUG( 177362598e31SEd Tanous "Invalid property value for BootSourceOverrideTarget: {}", 177462598e31SEd Tanous *bootSource); 1775ac106bf6SEd Tanous messages::propertyValueNotInList(asyncResp->res, *bootSource, 1776491d8ee7SSantosh Puranik "BootSourceTargetOverride"); 1777491d8ee7SSantosh Puranik return; 1778491d8ee7SSantosh Puranik } 1779491d8ee7SSantosh Puranik 1780944ffaf9SJohnathan Mantey // Act on validated parameters 178162598e31SEd Tanous BMCWEB_LOG_DEBUG("DBUS boot source: {}", bootSourceStr); 178262598e31SEd Tanous BMCWEB_LOG_DEBUG("DBUS boot mode: {}", bootModeStr); 1783944ffaf9SJohnathan Mantey 1784e93abac6SGinu George setDbusProperty(asyncResp, "Boot/BootSourceOverrideTarget", 1785e93abac6SGinu George "xyz.openbmc_project.Settings", 178687c44966SAsmitha Karunanithi sdbusplus::message::object_path( 178787c44966SAsmitha Karunanithi "/xyz/openbmc_project/control/host0/boot"), 178887c44966SAsmitha Karunanithi "xyz.openbmc_project.Control.Boot.Source", "BootSource", 1789e93abac6SGinu George bootSourceStr); 1790e93abac6SGinu George setDbusProperty(asyncResp, "Boot/BootSourceOverrideTarget", 1791e93abac6SGinu George "xyz.openbmc_project.Settings", 179287c44966SAsmitha Karunanithi sdbusplus::message::object_path( 179387c44966SAsmitha Karunanithi "/xyz/openbmc_project/control/host0/boot"), 179487c44966SAsmitha Karunanithi "xyz.openbmc_project.Control.Boot.Mode", "BootMode", 1795e93abac6SGinu George bootModeStr); 1796cd9a4666SKonstantin Aladyshev } 1797944ffaf9SJohnathan Mantey 1798cd9a4666SKonstantin Aladyshev /** 1799c21865c4SKonstantin Aladyshev * @brief Sets Boot source override properties. 1800491d8ee7SSantosh Puranik * 1801ac106bf6SEd Tanous * @param[in] asyncResp Shared pointer for generating response message. 1802491d8ee7SSantosh Puranik * @param[in] bootSource The boot source from incoming RF request. 1803cd9a4666SKonstantin Aladyshev * @param[in] bootType The boot type from incoming RF request. 1804491d8ee7SSantosh Puranik * @param[in] bootEnable The boot override enable from incoming RF request. 1805491d8ee7SSantosh Puranik * 1806265c1602SJohnathan Mantey * @return Integer error code. 1807491d8ee7SSantosh Puranik */ 1808c21865c4SKonstantin Aladyshev 1809504af5a0SPatrick Williams inline void setBootProperties( 1810504af5a0SPatrick Williams const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 1811c21865c4SKonstantin Aladyshev const std::optional<std::string>& bootSource, 1812c21865c4SKonstantin Aladyshev const std::optional<std::string>& bootType, 1813c21865c4SKonstantin Aladyshev const std::optional<std::string>& bootEnable) 1814491d8ee7SSantosh Puranik { 181562598e31SEd Tanous BMCWEB_LOG_DEBUG("Set boot information."); 1816491d8ee7SSantosh Puranik 1817ac106bf6SEd Tanous setBootModeOrSource(asyncResp, bootSource); 1818ac106bf6SEd Tanous setBootType(asyncResp, bootType); 1819ac106bf6SEd Tanous setBootEnable(asyncResp, bootEnable); 1820491d8ee7SSantosh Puranik } 1821491d8ee7SSantosh Puranik 1822c6a620f2SGeorge Liu /** 182398e386ecSGunnar Mills * @brief Sets AssetTag 182498e386ecSGunnar Mills * 1825ac106bf6SEd Tanous * @param[in] asyncResp Shared pointer for generating response message. 182698e386ecSGunnar Mills * @param[in] assetTag "AssetTag" from request. 182798e386ecSGunnar Mills * 182898e386ecSGunnar Mills * @return None. 182998e386ecSGunnar Mills */ 1830ac106bf6SEd Tanous inline void setAssetTag(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 183198e386ecSGunnar Mills const std::string& assetTag) 183298e386ecSGunnar Mills { 1833e99073f5SGeorge Liu constexpr std::array<std::string_view, 1> interfaces = { 1834e99073f5SGeorge Liu "xyz.openbmc_project.Inventory.Item.System"}; 1835e99073f5SGeorge Liu dbus::utility::getSubTree( 1836e99073f5SGeorge Liu "/xyz/openbmc_project/inventory", 0, interfaces, 1837ac106bf6SEd Tanous [asyncResp, 1838e99073f5SGeorge Liu assetTag](const boost::system::error_code& ec, 1839b9d36b47SEd Tanous const dbus::utility::MapperGetSubTreeResponse& subtree) { 184098e386ecSGunnar Mills if (ec) 184198e386ecSGunnar Mills { 184262598e31SEd Tanous BMCWEB_LOG_DEBUG("D-Bus response error on GetSubTree {}", ec); 1843ac106bf6SEd Tanous messages::internalError(asyncResp->res); 184498e386ecSGunnar Mills return; 184598e386ecSGunnar Mills } 184626f6976fSEd Tanous if (subtree.empty()) 184798e386ecSGunnar Mills { 184862598e31SEd Tanous BMCWEB_LOG_DEBUG("Can't find system D-Bus object!"); 1849ac106bf6SEd Tanous messages::internalError(asyncResp->res); 185098e386ecSGunnar Mills return; 185198e386ecSGunnar Mills } 185298e386ecSGunnar Mills // Assume only 1 system D-Bus object 185398e386ecSGunnar Mills // Throw an error if there is more than 1 185498e386ecSGunnar Mills if (subtree.size() > 1) 185598e386ecSGunnar Mills { 185662598e31SEd Tanous BMCWEB_LOG_DEBUG("Found more than 1 system D-Bus object!"); 1857ac106bf6SEd Tanous messages::internalError(asyncResp->res); 185898e386ecSGunnar Mills return; 185998e386ecSGunnar Mills } 186098e386ecSGunnar Mills if (subtree[0].first.empty() || subtree[0].second.size() != 1) 186198e386ecSGunnar Mills { 186262598e31SEd Tanous BMCWEB_LOG_DEBUG("Asset Tag Set mapper error!"); 1863ac106bf6SEd Tanous messages::internalError(asyncResp->res); 186498e386ecSGunnar Mills return; 186598e386ecSGunnar Mills } 186698e386ecSGunnar Mills 186798e386ecSGunnar Mills const std::string& path = subtree[0].first; 186898e386ecSGunnar Mills const std::string& service = subtree[0].second.begin()->first; 186998e386ecSGunnar Mills 187098e386ecSGunnar Mills if (service.empty()) 187198e386ecSGunnar Mills { 187262598e31SEd Tanous BMCWEB_LOG_DEBUG("Asset Tag Set service mapper error!"); 1873ac106bf6SEd Tanous messages::internalError(asyncResp->res); 187498e386ecSGunnar Mills return; 187598e386ecSGunnar Mills } 187698e386ecSGunnar Mills 1877e93abac6SGinu George setDbusProperty(asyncResp, "AssetTag", service, path, 187887c44966SAsmitha Karunanithi "xyz.openbmc_project.Inventory.Decorator.AssetTag", 1879e93abac6SGinu George "AssetTag", assetTag); 1880e99073f5SGeorge Liu }); 188198e386ecSGunnar Mills } 188298e386ecSGunnar Mills 188398e386ecSGunnar Mills /** 18849dcfe8c1SAlbert Zhang * @brief Validate the specified stopBootOnFault is valid and return the 18859dcfe8c1SAlbert Zhang * stopBootOnFault name associated with that string 18869dcfe8c1SAlbert Zhang * 18879dcfe8c1SAlbert Zhang * @param[in] stopBootOnFaultString String representing the desired 18889dcfe8c1SAlbert Zhang * stopBootOnFault 18899dcfe8c1SAlbert Zhang * 18909dcfe8c1SAlbert Zhang * @return stopBootOnFault value or empty if incoming value is not valid 18919dcfe8c1SAlbert Zhang */ 1892504af5a0SPatrick Williams inline std::optional<bool> validstopBootOnFault( 1893504af5a0SPatrick Williams const std::string& stopBootOnFaultString) 18949dcfe8c1SAlbert Zhang { 18959dcfe8c1SAlbert Zhang if (stopBootOnFaultString == "AnyFault") 18969dcfe8c1SAlbert Zhang { 18979dcfe8c1SAlbert Zhang return true; 18989dcfe8c1SAlbert Zhang } 18999dcfe8c1SAlbert Zhang 19009dcfe8c1SAlbert Zhang if (stopBootOnFaultString == "Never") 19019dcfe8c1SAlbert Zhang { 19029dcfe8c1SAlbert Zhang return false; 19039dcfe8c1SAlbert Zhang } 19049dcfe8c1SAlbert Zhang 19059dcfe8c1SAlbert Zhang return std::nullopt; 19069dcfe8c1SAlbert Zhang } 19079dcfe8c1SAlbert Zhang 19089dcfe8c1SAlbert Zhang /** 19099dcfe8c1SAlbert Zhang * @brief Sets stopBootOnFault 19109dcfe8c1SAlbert Zhang * 1911fc3edfddSEd Tanous * @param[in] asyncResp Shared pointer for generating response message. 19129dcfe8c1SAlbert Zhang * @param[in] stopBootOnFault "StopBootOnFault" from request. 19139dcfe8c1SAlbert Zhang * 19149dcfe8c1SAlbert Zhang * @return None. 19159dcfe8c1SAlbert Zhang */ 1916504af5a0SPatrick Williams inline void setStopBootOnFault( 1917504af5a0SPatrick Williams const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 19189dcfe8c1SAlbert Zhang const std::string& stopBootOnFault) 19199dcfe8c1SAlbert Zhang { 192062598e31SEd Tanous BMCWEB_LOG_DEBUG("Set Stop Boot On Fault."); 19219dcfe8c1SAlbert Zhang 19229dcfe8c1SAlbert Zhang std::optional<bool> stopBootEnabled = validstopBootOnFault(stopBootOnFault); 19239dcfe8c1SAlbert Zhang if (!stopBootEnabled) 19249dcfe8c1SAlbert Zhang { 192562598e31SEd Tanous BMCWEB_LOG_DEBUG("Invalid property value for StopBootOnFault: {}", 192662598e31SEd Tanous stopBootOnFault); 1927fc3edfddSEd Tanous messages::propertyValueNotInList(asyncResp->res, stopBootOnFault, 19289dcfe8c1SAlbert Zhang "StopBootOnFault"); 19299dcfe8c1SAlbert Zhang return; 19309dcfe8c1SAlbert Zhang } 19319dcfe8c1SAlbert Zhang 1932e93abac6SGinu George setDbusProperty(asyncResp, "Boot/StopBootOnFault", 1933e93abac6SGinu George "xyz.openbmc_project.Settings", 193487c44966SAsmitha Karunanithi sdbusplus::message::object_path( 193587c44966SAsmitha Karunanithi "/xyz/openbmc_project/logging/settings"), 1936fc3edfddSEd Tanous "xyz.openbmc_project.Logging.Settings", "QuiesceOnHwError", 1937e93abac6SGinu George *stopBootEnabled); 19389dcfe8c1SAlbert Zhang } 19399dcfe8c1SAlbert Zhang 19409dcfe8c1SAlbert Zhang /** 194169f35306SGunnar Mills * @brief Sets automaticRetry (Auto Reboot) 194269f35306SGunnar Mills * 1943ac106bf6SEd Tanous * @param[in] asyncResp Shared pointer for generating response message. 194469f35306SGunnar Mills * @param[in] automaticRetryConfig "AutomaticRetryConfig" from request. 194569f35306SGunnar Mills * 194669f35306SGunnar Mills * @return None. 194769f35306SGunnar Mills */ 1948504af5a0SPatrick Williams inline void setAutomaticRetry( 1949504af5a0SPatrick Williams const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 1950f23b7296SEd Tanous const std::string& automaticRetryConfig) 195169f35306SGunnar Mills { 195262598e31SEd Tanous BMCWEB_LOG_DEBUG("Set Automatic Retry."); 195369f35306SGunnar Mills 195469f35306SGunnar Mills // OpenBMC only supports "Disabled" and "RetryAttempts". 1955543f4400SEd Tanous bool autoRebootEnabled = false; 195669f35306SGunnar Mills 195769f35306SGunnar Mills if (automaticRetryConfig == "Disabled") 195869f35306SGunnar Mills { 195969f35306SGunnar Mills autoRebootEnabled = false; 196069f35306SGunnar Mills } 196169f35306SGunnar Mills else if (automaticRetryConfig == "RetryAttempts") 196269f35306SGunnar Mills { 196369f35306SGunnar Mills autoRebootEnabled = true; 196469f35306SGunnar Mills } 196569f35306SGunnar Mills else 196669f35306SGunnar Mills { 196762598e31SEd Tanous BMCWEB_LOG_DEBUG("Invalid property value for AutomaticRetryConfig: {}", 196862598e31SEd Tanous automaticRetryConfig); 1969ac106bf6SEd Tanous messages::propertyValueNotInList(asyncResp->res, automaticRetryConfig, 197069f35306SGunnar Mills "AutomaticRetryConfig"); 197169f35306SGunnar Mills return; 197269f35306SGunnar Mills } 197369f35306SGunnar Mills 1974e93abac6SGinu George setDbusProperty(asyncResp, "Boot/AutomaticRetryConfig", 1975e93abac6SGinu George "xyz.openbmc_project.Settings", 197687c44966SAsmitha Karunanithi sdbusplus::message::object_path( 197787c44966SAsmitha Karunanithi "/xyz/openbmc_project/control/host0/auto_reboot"), 197887c44966SAsmitha Karunanithi "xyz.openbmc_project.Control.Boot.RebootPolicy", 1979e93abac6SGinu George "AutoReboot", autoRebootEnabled); 198069f35306SGunnar Mills } 198169f35306SGunnar Mills 19828d69c668SEd Tanous inline std::string dbusPowerRestorePolicyFromRedfish(std::string_view policy) 19838d69c668SEd Tanous { 19848d69c668SEd Tanous if (policy == "AlwaysOn") 19858d69c668SEd Tanous { 19868d69c668SEd Tanous return "xyz.openbmc_project.Control.Power.RestorePolicy.Policy.AlwaysOn"; 19878d69c668SEd Tanous } 19888d69c668SEd Tanous if (policy == "AlwaysOff") 19898d69c668SEd Tanous { 19908d69c668SEd Tanous return "xyz.openbmc_project.Control.Power.RestorePolicy.Policy.AlwaysOff"; 19918d69c668SEd Tanous } 19928d69c668SEd Tanous if (policy == "LastState") 19938d69c668SEd Tanous { 19948d69c668SEd Tanous return "xyz.openbmc_project.Control.Power.RestorePolicy.Policy.Restore"; 19958d69c668SEd Tanous } 19968d69c668SEd Tanous return ""; 19978d69c668SEd Tanous } 19988d69c668SEd Tanous 199969f35306SGunnar Mills /** 2000c6a620f2SGeorge Liu * @brief Sets power restore policy properties. 2001c6a620f2SGeorge Liu * 2002ac106bf6SEd Tanous * @param[in] asyncResp Shared pointer for generating response message. 2003c6a620f2SGeorge Liu * @param[in] policy power restore policy properties from request. 2004c6a620f2SGeorge Liu * 2005c6a620f2SGeorge Liu * @return None. 2006c6a620f2SGeorge Liu */ 2007504af5a0SPatrick Williams inline void setPowerRestorePolicy( 2008504af5a0SPatrick Williams const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 20098d69c668SEd Tanous std::string_view policy) 2010c6a620f2SGeorge Liu { 201162598e31SEd Tanous BMCWEB_LOG_DEBUG("Set power restore policy."); 2012c6a620f2SGeorge Liu 20138d69c668SEd Tanous std::string powerRestorePolicy = dbusPowerRestorePolicyFromRedfish(policy); 2014c6a620f2SGeorge Liu 20158d69c668SEd Tanous if (powerRestorePolicy.empty()) 2016c6a620f2SGeorge Liu { 2017ac106bf6SEd Tanous messages::propertyValueNotInList(asyncResp->res, policy, 20184e69c904SGunnar Mills "PowerRestorePolicy"); 2019c6a620f2SGeorge Liu return; 2020c6a620f2SGeorge Liu } 2021c6a620f2SGeorge Liu 202287c44966SAsmitha Karunanithi setDbusProperty( 2023e93abac6SGinu George asyncResp, "PowerRestorePolicy", "xyz.openbmc_project.Settings", 202487c44966SAsmitha Karunanithi sdbusplus::message::object_path( 202587c44966SAsmitha Karunanithi "/xyz/openbmc_project/control/host0/power_restore_policy"), 20269ae226faSGeorge Liu "xyz.openbmc_project.Control.Power.RestorePolicy", "PowerRestorePolicy", 2027e93abac6SGinu George powerRestorePolicy); 2028c6a620f2SGeorge Liu } 2029c6a620f2SGeorge Liu 2030a6349918SAppaRao Puli /** 2031a6349918SAppaRao Puli * @brief Retrieves provisioning status 2032a6349918SAppaRao Puli * 203325b54dbaSEd Tanous * @param[in] asyncResp Shared pointer for completing asynchronous 203425b54dbaSEd Tanous * calls. 2035a6349918SAppaRao Puli * 2036a6349918SAppaRao Puli * @return None. 2037a6349918SAppaRao Puli */ 2038504af5a0SPatrick Williams inline void getProvisioningStatus( 2039504af5a0SPatrick Williams const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) 2040a6349918SAppaRao Puli { 204162598e31SEd Tanous BMCWEB_LOG_DEBUG("Get OEM information."); 2042deae6a78SEd Tanous dbus::utility::getAllProperties( 2043deae6a78SEd Tanous "xyz.openbmc_project.PFR.Manager", "/xyz/openbmc_project/pfr", 2044deae6a78SEd Tanous "xyz.openbmc_project.PFR.Attributes", 2045ac106bf6SEd Tanous [asyncResp](const boost::system::error_code& ec, 2046b9d36b47SEd Tanous const dbus::utility::DBusPropertiesMap& propertiesList) { 2047b99fb1a9SAppaRao Puli nlohmann::json& oemPFR = 2048bd79bce8SPatrick Williams asyncResp->res 2049bd79bce8SPatrick Williams .jsonValue["Oem"]["OpenBmc"]["FirmwareProvisioning"]; 2050ac106bf6SEd Tanous asyncResp->res.jsonValue["Oem"]["OpenBmc"]["@odata.type"] = 20511d834d49SEd Tanous "#OpenBMCComputerSystem.v1_0_0.OpenBmc"; 2052bd79bce8SPatrick Williams oemPFR["@odata.type"] = 2053bd79bce8SPatrick Williams "#OpenBMCComputerSystem.FirmwareProvisioning"; 205450626f4fSJames Feist 2055a6349918SAppaRao Puli if (ec) 2056a6349918SAppaRao Puli { 205762598e31SEd Tanous BMCWEB_LOG_DEBUG("DBUS response error {}", ec); 2058b99fb1a9SAppaRao Puli // not an error, don't have to have the interface 2059539d8c6bSEd Tanous oemPFR["ProvisioningStatus"] = open_bmc_computer_system:: 2060539d8c6bSEd Tanous FirmwareProvisioningStatus::NotProvisioned; 2061a6349918SAppaRao Puli return; 2062a6349918SAppaRao Puli } 2063a6349918SAppaRao Puli 2064a6349918SAppaRao Puli const bool* provState = nullptr; 2065a6349918SAppaRao Puli const bool* lockState = nullptr; 2066bc1d29deSKrzysztof Grobelny 2067bc1d29deSKrzysztof Grobelny const bool success = sdbusplus::unpackPropertiesNoThrow( 2068bd79bce8SPatrick Williams dbus_utils::UnpackErrorPrinter(), propertiesList, 2069bd79bce8SPatrick Williams "UfmProvisioned", provState, "UfmLocked", lockState); 2070bc1d29deSKrzysztof Grobelny 2071bc1d29deSKrzysztof Grobelny if (!success) 2072a6349918SAppaRao Puli { 2073ac106bf6SEd Tanous messages::internalError(asyncResp->res); 2074bc1d29deSKrzysztof Grobelny return; 2075a6349918SAppaRao Puli } 2076a6349918SAppaRao Puli 2077a6349918SAppaRao Puli if ((provState == nullptr) || (lockState == nullptr)) 2078a6349918SAppaRao Puli { 207962598e31SEd Tanous BMCWEB_LOG_DEBUG("Unable to get PFR attributes."); 2080ac106bf6SEd Tanous messages::internalError(asyncResp->res); 2081a6349918SAppaRao Puli return; 2082a6349918SAppaRao Puli } 2083a6349918SAppaRao Puli 208425b54dbaSEd Tanous if (*provState) 2085a6349918SAppaRao Puli { 208625b54dbaSEd Tanous if (*lockState) 2087a6349918SAppaRao Puli { 2088539d8c6bSEd Tanous oemPFR["ProvisioningStatus"] = open_bmc_computer_system:: 2089539d8c6bSEd Tanous FirmwareProvisioningStatus::ProvisionedAndLocked; 2090a6349918SAppaRao Puli } 2091a6349918SAppaRao Puli else 2092a6349918SAppaRao Puli { 2093539d8c6bSEd Tanous oemPFR["ProvisioningStatus"] = open_bmc_computer_system:: 2094539d8c6bSEd Tanous FirmwareProvisioningStatus::ProvisionedButNotLocked; 2095a6349918SAppaRao Puli } 2096a6349918SAppaRao Puli } 2097a6349918SAppaRao Puli else 2098a6349918SAppaRao Puli { 2099539d8c6bSEd Tanous oemPFR["ProvisioningStatus"] = open_bmc_computer_system:: 2100539d8c6bSEd Tanous FirmwareProvisioningStatus::NotProvisioned; 2101a6349918SAppaRao Puli } 2102bc1d29deSKrzysztof Grobelny }); 2103a6349918SAppaRao Puli } 2104a6349918SAppaRao Puli 2105491d8ee7SSantosh Puranik /** 21066b9ac4f2SChris Cain * @brief Translate the PowerMode string to enum value 21073a2d0424SChris Cain * 21086b9ac4f2SChris Cain * @param[in] modeString PowerMode string to be translated 21093a2d0424SChris Cain * 21106b9ac4f2SChris Cain * @return PowerMode enum 21113a2d0424SChris Cain */ 2112504af5a0SPatrick Williams inline computer_system::PowerMode translatePowerModeString( 2113504af5a0SPatrick Williams const std::string& modeString) 21143a2d0424SChris Cain { 2115b6655101SChris Cain using PowerMode = computer_system::PowerMode; 2116b6655101SChris Cain 21176b9ac4f2SChris Cain if (modeString == "xyz.openbmc_project.Control.Power.Mode.PowerMode.Static") 21183a2d0424SChris Cain { 21196b9ac4f2SChris Cain return PowerMode::Static; 21203a2d0424SChris Cain } 21216b9ac4f2SChris Cain if (modeString == 21220fda0f12SGeorge Liu "xyz.openbmc_project.Control.Power.Mode.PowerMode.MaximumPerformance") 21233a2d0424SChris Cain { 21246b9ac4f2SChris Cain return PowerMode::MaximumPerformance; 21253a2d0424SChris Cain } 21266b9ac4f2SChris Cain if (modeString == 21270fda0f12SGeorge Liu "xyz.openbmc_project.Control.Power.Mode.PowerMode.PowerSaving") 21283a2d0424SChris Cain { 21296b9ac4f2SChris Cain return PowerMode::PowerSaving; 2130b6655101SChris Cain } 21316b9ac4f2SChris Cain if (modeString == 2132b6655101SChris Cain "xyz.openbmc_project.Control.Power.Mode.PowerMode.BalancedPerformance") 2133b6655101SChris Cain { 21346b9ac4f2SChris Cain return PowerMode::BalancedPerformance; 2135b6655101SChris Cain } 21366b9ac4f2SChris Cain if (modeString == 2137b6655101SChris Cain "xyz.openbmc_project.Control.Power.Mode.PowerMode.EfficiencyFavorPerformance") 2138b6655101SChris Cain { 21396b9ac4f2SChris Cain return PowerMode::EfficiencyFavorPerformance; 2140b6655101SChris Cain } 21416b9ac4f2SChris Cain if (modeString == 2142b6655101SChris Cain "xyz.openbmc_project.Control.Power.Mode.PowerMode.EfficiencyFavorPower") 2143b6655101SChris Cain { 21446b9ac4f2SChris Cain return PowerMode::EfficiencyFavorPower; 21453a2d0424SChris Cain } 21466b9ac4f2SChris Cain if (modeString == "xyz.openbmc_project.Control.Power.Mode.PowerMode.OEM") 21473a2d0424SChris Cain { 21486b9ac4f2SChris Cain return PowerMode::OEM; 21496b9ac4f2SChris Cain } 21506b9ac4f2SChris Cain // Any other values would be invalid 21516b9ac4f2SChris Cain BMCWEB_LOG_ERROR("PowerMode value was not valid: {}", modeString); 21526b9ac4f2SChris Cain return PowerMode::Invalid; 21536b9ac4f2SChris Cain } 21546b9ac4f2SChris Cain 2155504af5a0SPatrick Williams inline void afterGetPowerMode( 2156504af5a0SPatrick Williams const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 21576b9ac4f2SChris Cain const boost::system::error_code& ec, 21586b9ac4f2SChris Cain const dbus::utility::DBusPropertiesMap& properties) 21596b9ac4f2SChris Cain { 21606b9ac4f2SChris Cain if (ec) 21616b9ac4f2SChris Cain { 21626b9ac4f2SChris Cain BMCWEB_LOG_ERROR("DBUS response error on PowerMode GetAll: {}", ec); 21636b9ac4f2SChris Cain messages::internalError(asyncResp->res); 21646b9ac4f2SChris Cain return; 21656b9ac4f2SChris Cain } 21666b9ac4f2SChris Cain 21676b9ac4f2SChris Cain std::string powerMode; 21686b9ac4f2SChris Cain const std::vector<std::string>* allowedModes = nullptr; 21696b9ac4f2SChris Cain const bool success = sdbusplus::unpackPropertiesNoThrow( 21706b9ac4f2SChris Cain dbus_utils::UnpackErrorPrinter(), properties, "PowerMode", powerMode, 21716b9ac4f2SChris Cain "AllowedPowerModes", allowedModes); 21726b9ac4f2SChris Cain 21736b9ac4f2SChris Cain if (!success) 21746b9ac4f2SChris Cain { 21756b9ac4f2SChris Cain messages::internalError(asyncResp->res); 21766b9ac4f2SChris Cain return; 21776b9ac4f2SChris Cain } 21786b9ac4f2SChris Cain 21796b9ac4f2SChris Cain nlohmann::json::array_t modeList; 21806b9ac4f2SChris Cain if (allowedModes == nullptr) 21816b9ac4f2SChris Cain { 21826b9ac4f2SChris Cain modeList.emplace_back("Static"); 21836b9ac4f2SChris Cain modeList.emplace_back("MaximumPerformance"); 21846b9ac4f2SChris Cain modeList.emplace_back("PowerSaving"); 21853a2d0424SChris Cain } 21863a2d0424SChris Cain else 21873a2d0424SChris Cain { 21886b9ac4f2SChris Cain for (const auto& aMode : *allowedModes) 21896b9ac4f2SChris Cain { 21906b9ac4f2SChris Cain computer_system::PowerMode modeValue = 21916b9ac4f2SChris Cain translatePowerModeString(aMode); 21926b9ac4f2SChris Cain if (modeValue == computer_system::PowerMode::Invalid) 21936b9ac4f2SChris Cain { 2194ac106bf6SEd Tanous messages::internalError(asyncResp->res); 21956b9ac4f2SChris Cain continue; 21966b9ac4f2SChris Cain } 21976b9ac4f2SChris Cain modeList.emplace_back(modeValue); 21983a2d0424SChris Cain } 21993a2d0424SChris Cain } 22006b9ac4f2SChris Cain asyncResp->res.jsonValue["PowerMode@Redfish.AllowableValues"] = modeList; 22013a2d0424SChris Cain 22026b9ac4f2SChris Cain BMCWEB_LOG_DEBUG("Current power mode: {}", powerMode); 22036b9ac4f2SChris Cain const computer_system::PowerMode modeValue = 22046b9ac4f2SChris Cain translatePowerModeString(powerMode); 22056b9ac4f2SChris Cain if (modeValue == computer_system::PowerMode::Invalid) 22066b9ac4f2SChris Cain { 22076b9ac4f2SChris Cain messages::internalError(asyncResp->res); 22086b9ac4f2SChris Cain return; 22096b9ac4f2SChris Cain } 22106b9ac4f2SChris Cain asyncResp->res.jsonValue["PowerMode"] = modeValue; 22116b9ac4f2SChris Cain } 22123a2d0424SChris Cain /** 22133a2d0424SChris Cain * @brief Retrieves system power mode 22143a2d0424SChris Cain * 2215ac106bf6SEd Tanous * @param[in] asyncResp Shared pointer for generating response message. 22163a2d0424SChris Cain * 22173a2d0424SChris Cain * @return None. 22183a2d0424SChris Cain */ 2219ac106bf6SEd Tanous inline void getPowerMode(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) 22203a2d0424SChris Cain { 222162598e31SEd Tanous BMCWEB_LOG_DEBUG("Get power mode."); 22223a2d0424SChris Cain 22233a2d0424SChris Cain // Get Power Mode object path: 2224e99073f5SGeorge Liu constexpr std::array<std::string_view, 1> interfaces = { 2225e99073f5SGeorge Liu "xyz.openbmc_project.Control.Power.Mode"}; 2226e99073f5SGeorge Liu dbus::utility::getSubTree( 2227e99073f5SGeorge Liu "/", 0, interfaces, 2228ac106bf6SEd Tanous [asyncResp](const boost::system::error_code& ec, 2229b9d36b47SEd Tanous const dbus::utility::MapperGetSubTreeResponse& subtree) { 22303a2d0424SChris Cain if (ec) 22313a2d0424SChris Cain { 2232bd79bce8SPatrick Williams BMCWEB_LOG_DEBUG( 2233bd79bce8SPatrick Williams "DBUS response error on Power.Mode GetSubTree {}", ec); 22343a2d0424SChris Cain // This is an optional D-Bus object so just return if 22353a2d0424SChris Cain // error occurs 22363a2d0424SChris Cain return; 22373a2d0424SChris Cain } 22383a2d0424SChris Cain if (subtree.empty()) 22393a2d0424SChris Cain { 22403a2d0424SChris Cain // As noted above, this is an optional interface so just return 22413a2d0424SChris Cain // if there is no instance found 22423a2d0424SChris Cain return; 22433a2d0424SChris Cain } 22443a2d0424SChris Cain if (subtree.size() > 1) 22453a2d0424SChris Cain { 22463a2d0424SChris Cain // More then one PowerMode object is not supported and is an 22473a2d0424SChris Cain // error 224862598e31SEd Tanous BMCWEB_LOG_DEBUG( 224962598e31SEd Tanous "Found more than 1 system D-Bus Power.Mode objects: {}", 225062598e31SEd Tanous subtree.size()); 2251ac106bf6SEd Tanous messages::internalError(asyncResp->res); 22523a2d0424SChris Cain return; 22533a2d0424SChris Cain } 22543a2d0424SChris Cain if ((subtree[0].first.empty()) || (subtree[0].second.size() != 1)) 22553a2d0424SChris Cain { 225662598e31SEd Tanous BMCWEB_LOG_DEBUG("Power.Mode mapper error!"); 2257ac106bf6SEd Tanous messages::internalError(asyncResp->res); 22583a2d0424SChris Cain return; 22593a2d0424SChris Cain } 22603a2d0424SChris Cain const std::string& path = subtree[0].first; 22613a2d0424SChris Cain const std::string& service = subtree[0].second.begin()->first; 22623a2d0424SChris Cain if (service.empty()) 22633a2d0424SChris Cain { 226462598e31SEd Tanous BMCWEB_LOG_DEBUG("Power.Mode service mapper error!"); 2265ac106bf6SEd Tanous messages::internalError(asyncResp->res); 22663a2d0424SChris Cain return; 22673a2d0424SChris Cain } 22686b9ac4f2SChris Cain 22696b9ac4f2SChris Cain // Valid Power Mode object found, now read the mode properties 2270deae6a78SEd Tanous dbus::utility::getAllProperties( 22711e1e598dSJonathan Doman *crow::connections::systemBus, service, path, 22726b9ac4f2SChris Cain "xyz.openbmc_project.Control.Power.Mode", 2273bd79bce8SPatrick Williams [asyncResp]( 2274bd79bce8SPatrick Williams const boost::system::error_code& ec2, 22756b9ac4f2SChris Cain const dbus::utility::DBusPropertiesMap& properties) { 22766b9ac4f2SChris Cain afterGetPowerMode(asyncResp, ec2, properties); 22771e1e598dSJonathan Doman }); 2278e99073f5SGeorge Liu }); 22793a2d0424SChris Cain } 22803a2d0424SChris Cain 22813a2d0424SChris Cain /** 22823a2d0424SChris Cain * @brief Validate the specified mode is valid and return the PowerMode 22833a2d0424SChris Cain * name associated with that string 22843a2d0424SChris Cain * 2285ac106bf6SEd Tanous * @param[in] asyncResp Shared pointer for generating response message. 2286b6655101SChris Cain * @param[in] modeValue String representing the desired PowerMode 22873a2d0424SChris Cain * 22883a2d0424SChris Cain * @return PowerMode value or empty string if mode is not valid 22893a2d0424SChris Cain */ 2290504af5a0SPatrick Williams inline std::string validatePowerMode( 2291504af5a0SPatrick Williams const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 2292b6655101SChris Cain const nlohmann::json& modeValue) 22933a2d0424SChris Cain { 2294b6655101SChris Cain using PowerMode = computer_system::PowerMode; 22953a2d0424SChris Cain std::string mode; 22963a2d0424SChris Cain 2297b6655101SChris Cain if (modeValue == PowerMode::Static) 22983a2d0424SChris Cain { 22993a2d0424SChris Cain mode = "xyz.openbmc_project.Control.Power.Mode.PowerMode.Static"; 23003a2d0424SChris Cain } 2301b6655101SChris Cain else if (modeValue == PowerMode::MaximumPerformance) 23023a2d0424SChris Cain { 23030fda0f12SGeorge Liu mode = 23040fda0f12SGeorge Liu "xyz.openbmc_project.Control.Power.Mode.PowerMode.MaximumPerformance"; 23053a2d0424SChris Cain } 2306b6655101SChris Cain else if (modeValue == PowerMode::PowerSaving) 23073a2d0424SChris Cain { 23083a2d0424SChris Cain mode = "xyz.openbmc_project.Control.Power.Mode.PowerMode.PowerSaving"; 23093a2d0424SChris Cain } 2310b6655101SChris Cain else if (modeValue == PowerMode::BalancedPerformance) 2311b6655101SChris Cain { 2312b6655101SChris Cain mode = 2313b6655101SChris Cain "xyz.openbmc_project.Control.Power.Mode.PowerMode.BalancedPerformance"; 2314b6655101SChris Cain } 2315b6655101SChris Cain else if (modeValue == PowerMode::EfficiencyFavorPerformance) 2316b6655101SChris Cain { 2317b6655101SChris Cain mode = 2318b6655101SChris Cain "xyz.openbmc_project.Control.Power.Mode.PowerMode.EfficiencyFavorPerformance"; 2319b6655101SChris Cain } 2320b6655101SChris Cain else if (modeValue == PowerMode::EfficiencyFavorPower) 2321b6655101SChris Cain { 2322b6655101SChris Cain mode = 2323b6655101SChris Cain "xyz.openbmc_project.Control.Power.Mode.PowerMode.EfficiencyFavorPower"; 2324b6655101SChris Cain } 23253a2d0424SChris Cain else 23263a2d0424SChris Cain { 2327b6655101SChris Cain messages::propertyValueNotInList(asyncResp->res, modeValue.dump(), 2328ac106bf6SEd Tanous "PowerMode"); 23293a2d0424SChris Cain } 23303a2d0424SChris Cain return mode; 23313a2d0424SChris Cain } 23323a2d0424SChris Cain 23333a2d0424SChris Cain /** 23343a2d0424SChris Cain * @brief Sets system power mode. 23353a2d0424SChris Cain * 2336ac106bf6SEd Tanous * @param[in] asyncResp Shared pointer for generating response message. 23373a2d0424SChris Cain * @param[in] pmode System power mode from request. 23383a2d0424SChris Cain * 23393a2d0424SChris Cain * @return None. 23403a2d0424SChris Cain */ 2341ac106bf6SEd Tanous inline void setPowerMode(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 23423a2d0424SChris Cain const std::string& pmode) 23433a2d0424SChris Cain { 234462598e31SEd Tanous BMCWEB_LOG_DEBUG("Set power mode."); 23453a2d0424SChris Cain 2346ac106bf6SEd Tanous std::string powerMode = validatePowerMode(asyncResp, pmode); 23473a2d0424SChris Cain if (powerMode.empty()) 23483a2d0424SChris Cain { 23493a2d0424SChris Cain return; 23503a2d0424SChris Cain } 23513a2d0424SChris Cain 23523a2d0424SChris Cain // Get Power Mode object path: 2353e99073f5SGeorge Liu constexpr std::array<std::string_view, 1> interfaces = { 2354e99073f5SGeorge Liu "xyz.openbmc_project.Control.Power.Mode"}; 2355e99073f5SGeorge Liu dbus::utility::getSubTree( 2356e99073f5SGeorge Liu "/", 0, interfaces, 2357ac106bf6SEd Tanous [asyncResp, 2358e99073f5SGeorge Liu powerMode](const boost::system::error_code& ec, 2359b9d36b47SEd Tanous const dbus::utility::MapperGetSubTreeResponse& subtree) { 23603a2d0424SChris Cain if (ec) 23613a2d0424SChris Cain { 2362bd79bce8SPatrick Williams BMCWEB_LOG_ERROR( 2363bd79bce8SPatrick Williams "DBUS response error on Power.Mode GetSubTree {}", ec); 23643a2d0424SChris Cain // This is an optional D-Bus object, but user attempted to patch 2365ac106bf6SEd Tanous messages::internalError(asyncResp->res); 23663a2d0424SChris Cain return; 23673a2d0424SChris Cain } 23683a2d0424SChris Cain if (subtree.empty()) 23693a2d0424SChris Cain { 23703a2d0424SChris Cain // This is an optional D-Bus object, but user attempted to patch 2371ac106bf6SEd Tanous messages::resourceNotFound(asyncResp->res, "ComputerSystem", 23723a2d0424SChris Cain "PowerMode"); 23733a2d0424SChris Cain return; 23743a2d0424SChris Cain } 23753a2d0424SChris Cain if (subtree.size() > 1) 23763a2d0424SChris Cain { 23773a2d0424SChris Cain // More then one PowerMode object is not supported and is an 23783a2d0424SChris Cain // error 237962598e31SEd Tanous BMCWEB_LOG_DEBUG( 238062598e31SEd Tanous "Found more than 1 system D-Bus Power.Mode objects: {}", 238162598e31SEd Tanous subtree.size()); 2382ac106bf6SEd Tanous messages::internalError(asyncResp->res); 23833a2d0424SChris Cain return; 23843a2d0424SChris Cain } 23853a2d0424SChris Cain if ((subtree[0].first.empty()) || (subtree[0].second.size() != 1)) 23863a2d0424SChris Cain { 238762598e31SEd Tanous BMCWEB_LOG_DEBUG("Power.Mode mapper error!"); 2388ac106bf6SEd Tanous messages::internalError(asyncResp->res); 23893a2d0424SChris Cain return; 23903a2d0424SChris Cain } 23913a2d0424SChris Cain const std::string& path = subtree[0].first; 23923a2d0424SChris Cain const std::string& service = subtree[0].second.begin()->first; 23933a2d0424SChris Cain if (service.empty()) 23943a2d0424SChris Cain { 239562598e31SEd Tanous BMCWEB_LOG_DEBUG("Power.Mode service mapper error!"); 2396ac106bf6SEd Tanous messages::internalError(asyncResp->res); 23973a2d0424SChris Cain return; 23983a2d0424SChris Cain } 23993a2d0424SChris Cain 240062598e31SEd Tanous BMCWEB_LOG_DEBUG("Setting power mode({}) -> {}", powerMode, path); 24013a2d0424SChris Cain 24023a2d0424SChris Cain // Set the Power Mode property 2403e93abac6SGinu George setDbusProperty(asyncResp, "PowerMode", service, path, 2404bd79bce8SPatrick Williams "xyz.openbmc_project.Control.Power.Mode", 2405bd79bce8SPatrick Williams "PowerMode", powerMode); 2406e99073f5SGeorge Liu }); 24073a2d0424SChris Cain } 24083a2d0424SChris Cain 24093a2d0424SChris Cain /** 241051709ffdSYong Li * @brief Translates watchdog timeout action DBUS property value to redfish. 241151709ffdSYong Li * 241251709ffdSYong Li * @param[in] dbusAction The watchdog timeout action in D-BUS. 241351709ffdSYong Li * 241451709ffdSYong Li * @return Returns as a string, the timeout action in Redfish terms. If 241551709ffdSYong Li * translation cannot be done, returns an empty string. 241651709ffdSYong Li */ 241723a21a1cSEd Tanous inline std::string dbusToRfWatchdogAction(const std::string& dbusAction) 241851709ffdSYong Li { 241951709ffdSYong Li if (dbusAction == "xyz.openbmc_project.State.Watchdog.Action.None") 242051709ffdSYong Li { 242151709ffdSYong Li return "None"; 242251709ffdSYong Li } 24233174e4dfSEd Tanous if (dbusAction == "xyz.openbmc_project.State.Watchdog.Action.HardReset") 242451709ffdSYong Li { 242551709ffdSYong Li return "ResetSystem"; 242651709ffdSYong Li } 24273174e4dfSEd Tanous if (dbusAction == "xyz.openbmc_project.State.Watchdog.Action.PowerOff") 242851709ffdSYong Li { 242951709ffdSYong Li return "PowerDown"; 243051709ffdSYong Li } 24313174e4dfSEd Tanous if (dbusAction == "xyz.openbmc_project.State.Watchdog.Action.PowerCycle") 243251709ffdSYong Li { 243351709ffdSYong Li return "PowerCycle"; 243451709ffdSYong Li } 243551709ffdSYong Li 243651709ffdSYong Li return ""; 243751709ffdSYong Li } 243851709ffdSYong Li 243951709ffdSYong Li /** 2440c45f0082SYong Li *@brief Translates timeout action from Redfish to DBUS property value. 2441c45f0082SYong Li * 2442c45f0082SYong Li *@param[in] rfAction The timeout action in Redfish. 2443c45f0082SYong Li * 2444c45f0082SYong Li *@return Returns as a string, the time_out action as expected by DBUS. 2445c45f0082SYong Li *If translation cannot be done, returns an empty string. 2446c45f0082SYong Li */ 2447c45f0082SYong Li 244823a21a1cSEd Tanous inline std::string rfToDbusWDTTimeOutAct(const std::string& rfAction) 2449c45f0082SYong Li { 2450c45f0082SYong Li if (rfAction == "None") 2451c45f0082SYong Li { 2452c45f0082SYong Li return "xyz.openbmc_project.State.Watchdog.Action.None"; 2453c45f0082SYong Li } 24543174e4dfSEd Tanous if (rfAction == "PowerCycle") 2455c45f0082SYong Li { 2456c45f0082SYong Li return "xyz.openbmc_project.State.Watchdog.Action.PowerCycle"; 2457c45f0082SYong Li } 24583174e4dfSEd Tanous if (rfAction == "PowerDown") 2459c45f0082SYong Li { 2460c45f0082SYong Li return "xyz.openbmc_project.State.Watchdog.Action.PowerOff"; 2461c45f0082SYong Li } 24623174e4dfSEd Tanous if (rfAction == "ResetSystem") 2463c45f0082SYong Li { 2464c45f0082SYong Li return "xyz.openbmc_project.State.Watchdog.Action.HardReset"; 2465c45f0082SYong Li } 2466c45f0082SYong Li 2467c45f0082SYong Li return ""; 2468c45f0082SYong Li } 2469c45f0082SYong Li 2470c45f0082SYong Li /** 247151709ffdSYong Li * @brief Retrieves host watchdog timer properties over DBUS 247251709ffdSYong Li * 2473ac106bf6SEd Tanous * @param[in] asyncResp Shared pointer for completing asynchronous calls. 247451709ffdSYong Li * 247551709ffdSYong Li * @return None. 247651709ffdSYong Li */ 2477504af5a0SPatrick Williams inline void getHostWatchdogTimer( 2478504af5a0SPatrick Williams const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) 247951709ffdSYong Li { 248062598e31SEd Tanous BMCWEB_LOG_DEBUG("Get host watchodg"); 2481deae6a78SEd Tanous dbus::utility::getAllProperties( 2482deae6a78SEd Tanous "xyz.openbmc_project.Watchdog", "/xyz/openbmc_project/watchdog/host0", 2483bc1d29deSKrzysztof Grobelny "xyz.openbmc_project.State.Watchdog", 2484ac106bf6SEd Tanous [asyncResp](const boost::system::error_code& ec, 2485b9d36b47SEd Tanous const dbus::utility::DBusPropertiesMap& properties) { 248651709ffdSYong Li if (ec) 248751709ffdSYong Li { 248851709ffdSYong Li // watchdog service is stopped 248962598e31SEd Tanous BMCWEB_LOG_DEBUG("DBUS response error {}", ec); 249051709ffdSYong Li return; 249151709ffdSYong Li } 249251709ffdSYong Li 249362598e31SEd Tanous BMCWEB_LOG_DEBUG("Got {} wdt prop.", properties.size()); 249451709ffdSYong Li 249551709ffdSYong Li nlohmann::json& hostWatchdogTimer = 2496ac106bf6SEd Tanous asyncResp->res.jsonValue["HostWatchdogTimer"]; 249751709ffdSYong Li 249851709ffdSYong Li // watchdog service is running/enabled 2499539d8c6bSEd Tanous hostWatchdogTimer["Status"]["State"] = resource::State::Enabled; 250051709ffdSYong Li 2501bc1d29deSKrzysztof Grobelny const bool* enabled = nullptr; 2502bc1d29deSKrzysztof Grobelny const std::string* expireAction = nullptr; 250351709ffdSYong Li 2504bc1d29deSKrzysztof Grobelny const bool success = sdbusplus::unpackPropertiesNoThrow( 2505bd79bce8SPatrick Williams dbus_utils::UnpackErrorPrinter(), properties, "Enabled", 2506bd79bce8SPatrick Williams enabled, "ExpireAction", expireAction); 2507bc1d29deSKrzysztof Grobelny 2508bc1d29deSKrzysztof Grobelny if (!success) 250951709ffdSYong Li { 2510ac106bf6SEd Tanous messages::internalError(asyncResp->res); 2511601af5edSChicago Duan return; 251251709ffdSYong Li } 251351709ffdSYong Li 2514bc1d29deSKrzysztof Grobelny if (enabled != nullptr) 251551709ffdSYong Li { 2516bc1d29deSKrzysztof Grobelny hostWatchdogTimer["FunctionEnabled"] = *enabled; 251751709ffdSYong Li } 251851709ffdSYong Li 2519bc1d29deSKrzysztof Grobelny if (expireAction != nullptr) 2520bc1d29deSKrzysztof Grobelny { 2521bc1d29deSKrzysztof Grobelny std::string action = dbusToRfWatchdogAction(*expireAction); 252251709ffdSYong Li if (action.empty()) 252351709ffdSYong Li { 2524ac106bf6SEd Tanous messages::internalError(asyncResp->res); 2525601af5edSChicago Duan return; 252651709ffdSYong Li } 252751709ffdSYong Li hostWatchdogTimer["TimeoutAction"] = action; 252851709ffdSYong Li } 2529bc1d29deSKrzysztof Grobelny }); 253051709ffdSYong Li } 253151709ffdSYong Li 253251709ffdSYong Li /** 2533c45f0082SYong Li * @brief Sets Host WatchDog Timer properties. 2534c45f0082SYong Li * 2535ac106bf6SEd Tanous * @param[in] asyncResp Shared pointer for generating response message. 2536c45f0082SYong Li * @param[in] wdtEnable The WDTimer Enable value (true/false) from incoming 2537c45f0082SYong Li * RF request. 2538c45f0082SYong Li * @param[in] wdtTimeOutAction The WDT Timeout action, from incoming RF request. 2539c45f0082SYong Li * 2540c45f0082SYong Li * @return None. 2541c45f0082SYong Li */ 2542504af5a0SPatrick Williams inline void setWDTProperties( 2543504af5a0SPatrick Williams const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 2544c45f0082SYong Li const std::optional<bool> wdtEnable, 2545c45f0082SYong Li const std::optional<std::string>& wdtTimeOutAction) 2546c45f0082SYong Li { 254762598e31SEd Tanous BMCWEB_LOG_DEBUG("Set host watchdog"); 2548c45f0082SYong Li 2549c45f0082SYong Li if (wdtTimeOutAction) 2550c45f0082SYong Li { 2551c45f0082SYong Li std::string wdtTimeOutActStr = rfToDbusWDTTimeOutAct(*wdtTimeOutAction); 2552c45f0082SYong Li // check if TimeOut Action is Valid 2553c45f0082SYong Li if (wdtTimeOutActStr.empty()) 2554c45f0082SYong Li { 255562598e31SEd Tanous BMCWEB_LOG_DEBUG("Unsupported value for TimeoutAction: {}", 255662598e31SEd Tanous *wdtTimeOutAction); 2557ac106bf6SEd Tanous messages::propertyValueNotInList(asyncResp->res, *wdtTimeOutAction, 2558c45f0082SYong Li "TimeoutAction"); 2559c45f0082SYong Li return; 2560c45f0082SYong Li } 2561c45f0082SYong Li 2562e93abac6SGinu George setDbusProperty(asyncResp, "HostWatchdogTimer/TimeoutAction", 2563e93abac6SGinu George "xyz.openbmc_project.Watchdog", 256487c44966SAsmitha Karunanithi sdbusplus::message::object_path( 256587c44966SAsmitha Karunanithi "/xyz/openbmc_project/watchdog/host0"), 25669ae226faSGeorge Liu "xyz.openbmc_project.State.Watchdog", "ExpireAction", 2567e93abac6SGinu George wdtTimeOutActStr); 2568c45f0082SYong Li } 2569c45f0082SYong Li 2570c45f0082SYong Li if (wdtEnable) 2571c45f0082SYong Li { 2572e93abac6SGinu George setDbusProperty(asyncResp, "HostWatchdogTimer/FunctionEnabled", 2573e93abac6SGinu George "xyz.openbmc_project.Watchdog", 257487c44966SAsmitha Karunanithi sdbusplus::message::object_path( 257587c44966SAsmitha Karunanithi "/xyz/openbmc_project/watchdog/host0"), 257687c44966SAsmitha Karunanithi "xyz.openbmc_project.State.Watchdog", "Enabled", 2577e93abac6SGinu George *wdtEnable); 2578c45f0082SYong Li } 2579c45f0082SYong Li } 2580c45f0082SYong Li 258137bbf98cSChris Cain /** 258237bbf98cSChris Cain * @brief Parse the Idle Power Saver properties into json 258337bbf98cSChris Cain * 2584ac106bf6SEd Tanous * @param[in] asyncResp Shared pointer for completing asynchronous calls. 258537bbf98cSChris Cain * @param[in] properties IPS property data from DBus. 258637bbf98cSChris Cain * 258737bbf98cSChris Cain * @return true if successful 258837bbf98cSChris Cain */ 2589504af5a0SPatrick Williams inline bool parseIpsProperties( 2590504af5a0SPatrick Williams const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 25911e5b7c88SJiaqing Zhao const dbus::utility::DBusPropertiesMap& properties) 259237bbf98cSChris Cain { 2593bc1d29deSKrzysztof Grobelny const bool* enabled = nullptr; 2594bc1d29deSKrzysztof Grobelny const uint8_t* enterUtilizationPercent = nullptr; 2595bc1d29deSKrzysztof Grobelny const uint64_t* enterDwellTime = nullptr; 2596bc1d29deSKrzysztof Grobelny const uint8_t* exitUtilizationPercent = nullptr; 2597bc1d29deSKrzysztof Grobelny const uint64_t* exitDwellTime = nullptr; 2598bc1d29deSKrzysztof Grobelny 2599bc1d29deSKrzysztof Grobelny const bool success = sdbusplus::unpackPropertiesNoThrow( 2600bc1d29deSKrzysztof Grobelny dbus_utils::UnpackErrorPrinter(), properties, "Enabled", enabled, 26012661b72cSChris Cain "EnterUtilizationPercent", enterUtilizationPercent, "EnterDwellTime", 26022661b72cSChris Cain enterDwellTime, "ExitUtilizationPercent", exitUtilizationPercent, 26032661b72cSChris Cain "ExitDwellTime", exitDwellTime); 2604bc1d29deSKrzysztof Grobelny 2605bc1d29deSKrzysztof Grobelny if (!success) 260637bbf98cSChris Cain { 260737bbf98cSChris Cain return false; 260837bbf98cSChris Cain } 2609bc1d29deSKrzysztof Grobelny 2610bc1d29deSKrzysztof Grobelny if (enabled != nullptr) 261137bbf98cSChris Cain { 2612ac106bf6SEd Tanous asyncResp->res.jsonValue["IdlePowerSaver"]["Enabled"] = *enabled; 261337bbf98cSChris Cain } 2614bc1d29deSKrzysztof Grobelny 2615bc1d29deSKrzysztof Grobelny if (enterUtilizationPercent != nullptr) 261637bbf98cSChris Cain { 2617ac106bf6SEd Tanous asyncResp->res.jsonValue["IdlePowerSaver"]["EnterUtilizationPercent"] = 2618bc1d29deSKrzysztof Grobelny *enterUtilizationPercent; 261937bbf98cSChris Cain } 2620bc1d29deSKrzysztof Grobelny 2621bc1d29deSKrzysztof Grobelny if (enterDwellTime != nullptr) 2622bc1d29deSKrzysztof Grobelny { 2623bc1d29deSKrzysztof Grobelny const std::chrono::duration<uint64_t, std::milli> ms(*enterDwellTime); 2624ac106bf6SEd Tanous asyncResp->res.jsonValue["IdlePowerSaver"]["EnterDwellTimeSeconds"] = 262537bbf98cSChris Cain std::chrono::duration_cast<std::chrono::duration<uint64_t>>(ms) 262637bbf98cSChris Cain .count(); 262737bbf98cSChris Cain } 2628bc1d29deSKrzysztof Grobelny 2629bc1d29deSKrzysztof Grobelny if (exitUtilizationPercent != nullptr) 263037bbf98cSChris Cain { 2631ac106bf6SEd Tanous asyncResp->res.jsonValue["IdlePowerSaver"]["ExitUtilizationPercent"] = 2632bc1d29deSKrzysztof Grobelny *exitUtilizationPercent; 263337bbf98cSChris Cain } 2634bc1d29deSKrzysztof Grobelny 2635bc1d29deSKrzysztof Grobelny if (exitDwellTime != nullptr) 263637bbf98cSChris Cain { 2637bc1d29deSKrzysztof Grobelny const std::chrono::duration<uint64_t, std::milli> ms(*exitDwellTime); 2638ac106bf6SEd Tanous asyncResp->res.jsonValue["IdlePowerSaver"]["ExitDwellTimeSeconds"] = 263937bbf98cSChris Cain std::chrono::duration_cast<std::chrono::duration<uint64_t>>(ms) 264037bbf98cSChris Cain .count(); 264137bbf98cSChris Cain } 264237bbf98cSChris Cain 264337bbf98cSChris Cain return true; 264437bbf98cSChris Cain } 264537bbf98cSChris Cain 264637bbf98cSChris Cain /** 2647*5e7c1f31SOliver Brewka * @brief Retrieves idle power saver properties over DBUS 264837bbf98cSChris Cain * 2649ac106bf6SEd Tanous * @param[in] asyncResp Shared pointer for completing asynchronous calls. 265037bbf98cSChris Cain * 265137bbf98cSChris Cain * @return None. 265237bbf98cSChris Cain */ 2653504af5a0SPatrick Williams inline void getIdlePowerSaver( 2654504af5a0SPatrick Williams const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) 265537bbf98cSChris Cain { 265662598e31SEd Tanous BMCWEB_LOG_DEBUG("Get idle power saver parameters"); 265737bbf98cSChris Cain 265837bbf98cSChris Cain // Get IdlePowerSaver object path: 2659e99073f5SGeorge Liu constexpr std::array<std::string_view, 1> interfaces = { 2660e99073f5SGeorge Liu "xyz.openbmc_project.Control.Power.IdlePowerSaver"}; 2661e99073f5SGeorge Liu dbus::utility::getSubTree( 2662e99073f5SGeorge Liu "/", 0, interfaces, 2663ac106bf6SEd Tanous [asyncResp](const boost::system::error_code& ec, 2664b9d36b47SEd Tanous const dbus::utility::MapperGetSubTreeResponse& subtree) { 266537bbf98cSChris Cain if (ec) 266637bbf98cSChris Cain { 2667b3e86cb0SGunnar Mills BMCWEB_LOG_ERROR( 266862598e31SEd Tanous "DBUS response error on Power.IdlePowerSaver GetSubTree {}", 266962598e31SEd Tanous ec); 2670ac106bf6SEd Tanous messages::internalError(asyncResp->res); 267137bbf98cSChris Cain return; 267237bbf98cSChris Cain } 267337bbf98cSChris Cain if (subtree.empty()) 267437bbf98cSChris Cain { 267537bbf98cSChris Cain // This is an optional interface so just return 267637bbf98cSChris Cain // if there is no instance found 267762598e31SEd Tanous BMCWEB_LOG_DEBUG("No instances found"); 267837bbf98cSChris Cain return; 267937bbf98cSChris Cain } 268037bbf98cSChris Cain if (subtree.size() > 1) 268137bbf98cSChris Cain { 268237bbf98cSChris Cain // More then one PowerIdlePowerSaver object is not supported and 268337bbf98cSChris Cain // is an error 2684*5e7c1f31SOliver Brewka BMCWEB_LOG_DEBUG( 2685*5e7c1f31SOliver Brewka "Found more than 1 system D-Bus Power.IdlePowerSaver objects: {}", 268662598e31SEd Tanous subtree.size()); 2687ac106bf6SEd Tanous messages::internalError(asyncResp->res); 268837bbf98cSChris Cain return; 268937bbf98cSChris Cain } 269037bbf98cSChris Cain if ((subtree[0].first.empty()) || (subtree[0].second.size() != 1)) 269137bbf98cSChris Cain { 269262598e31SEd Tanous BMCWEB_LOG_DEBUG("Power.IdlePowerSaver mapper error!"); 2693ac106bf6SEd Tanous messages::internalError(asyncResp->res); 269437bbf98cSChris Cain return; 269537bbf98cSChris Cain } 269637bbf98cSChris Cain const std::string& path = subtree[0].first; 269737bbf98cSChris Cain const std::string& service = subtree[0].second.begin()->first; 269837bbf98cSChris Cain if (service.empty()) 269937bbf98cSChris Cain { 270062598e31SEd Tanous BMCWEB_LOG_DEBUG("Power.IdlePowerSaver service mapper error!"); 2701ac106bf6SEd Tanous messages::internalError(asyncResp->res); 270237bbf98cSChris Cain return; 270337bbf98cSChris Cain } 270437bbf98cSChris Cain 270537bbf98cSChris Cain // Valid IdlePowerSaver object found, now read the current values 2706deae6a78SEd Tanous dbus::utility::getAllProperties( 2707bc1d29deSKrzysztof Grobelny *crow::connections::systemBus, service, path, 2708bc1d29deSKrzysztof Grobelny "xyz.openbmc_project.Control.Power.IdlePowerSaver", 2709bd79bce8SPatrick Williams [asyncResp]( 2710bd79bce8SPatrick Williams const boost::system::error_code& ec2, 27111e5b7c88SJiaqing Zhao const dbus::utility::DBusPropertiesMap& properties) { 27128a592810SEd Tanous if (ec2) 271337bbf98cSChris Cain { 271462598e31SEd Tanous BMCWEB_LOG_ERROR( 2715bd79bce8SPatrick Williams "DBUS response error on IdlePowerSaver GetAll: {}", 2716bd79bce8SPatrick Williams ec2); 2717ac106bf6SEd Tanous messages::internalError(asyncResp->res); 271837bbf98cSChris Cain return; 271937bbf98cSChris Cain } 272037bbf98cSChris Cain 2721ac106bf6SEd Tanous if (!parseIpsProperties(asyncResp, properties)) 272237bbf98cSChris Cain { 2723ac106bf6SEd Tanous messages::internalError(asyncResp->res); 272437bbf98cSChris Cain return; 272537bbf98cSChris Cain } 2726bc1d29deSKrzysztof Grobelny }); 2727e99073f5SGeorge Liu }); 272837bbf98cSChris Cain 272962598e31SEd Tanous BMCWEB_LOG_DEBUG("EXIT: Get idle power saver parameters"); 273037bbf98cSChris Cain } 273137bbf98cSChris Cain 273237bbf98cSChris Cain /** 273337bbf98cSChris Cain * @brief Sets Idle Power Saver properties. 273437bbf98cSChris Cain * 2735ac106bf6SEd Tanous * @param[in] asyncResp Shared pointer for generating response message. 273637bbf98cSChris Cain * @param[in] ipsEnable The IPS Enable value (true/false) from incoming 273737bbf98cSChris Cain * RF request. 273837bbf98cSChris Cain * @param[in] ipsEnterUtil The utilization limit to enter idle state. 273937bbf98cSChris Cain * @param[in] ipsEnterTime The time the utilization must be below ipsEnterUtil 274037bbf98cSChris Cain * before entering idle state. 274137bbf98cSChris Cain * @param[in] ipsExitUtil The utilization limit when exiting idle state. 274237bbf98cSChris Cain * @param[in] ipsExitTime The time the utilization must be above ipsExutUtil 274337bbf98cSChris Cain * before exiting idle state 274437bbf98cSChris Cain * 274537bbf98cSChris Cain * @return None. 274637bbf98cSChris Cain */ 2747bd79bce8SPatrick Williams inline void setIdlePowerSaver( 2748bd79bce8SPatrick Williams const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 274937bbf98cSChris Cain const std::optional<bool> ipsEnable, 275037bbf98cSChris Cain const std::optional<uint8_t> ipsEnterUtil, 275137bbf98cSChris Cain const std::optional<uint64_t> ipsEnterTime, 275237bbf98cSChris Cain const std::optional<uint8_t> ipsExitUtil, 275337bbf98cSChris Cain const std::optional<uint64_t> ipsExitTime) 275437bbf98cSChris Cain { 275562598e31SEd Tanous BMCWEB_LOG_DEBUG("Set idle power saver properties"); 275637bbf98cSChris Cain 275737bbf98cSChris Cain // Get IdlePowerSaver object path: 2758e99073f5SGeorge Liu constexpr std::array<std::string_view, 1> interfaces = { 2759e99073f5SGeorge Liu "xyz.openbmc_project.Control.Power.IdlePowerSaver"}; 2760e99073f5SGeorge Liu dbus::utility::getSubTree( 2761e99073f5SGeorge Liu "/", 0, interfaces, 2762ac106bf6SEd Tanous [asyncResp, ipsEnable, ipsEnterUtil, ipsEnterTime, ipsExitUtil, 2763e99073f5SGeorge Liu ipsExitTime](const boost::system::error_code& ec, 2764b9d36b47SEd Tanous const dbus::utility::MapperGetSubTreeResponse& subtree) { 276537bbf98cSChris Cain if (ec) 276637bbf98cSChris Cain { 2767b3e86cb0SGunnar Mills BMCWEB_LOG_ERROR( 276862598e31SEd Tanous "DBUS response error on Power.IdlePowerSaver GetSubTree {}", 276962598e31SEd Tanous ec); 2770ac106bf6SEd Tanous messages::internalError(asyncResp->res); 277137bbf98cSChris Cain return; 277237bbf98cSChris Cain } 277337bbf98cSChris Cain if (subtree.empty()) 277437bbf98cSChris Cain { 277537bbf98cSChris Cain // This is an optional D-Bus object, but user attempted to patch 2776ac106bf6SEd Tanous messages::resourceNotFound(asyncResp->res, "ComputerSystem", 277737bbf98cSChris Cain "IdlePowerSaver"); 277837bbf98cSChris Cain return; 277937bbf98cSChris Cain } 278037bbf98cSChris Cain if (subtree.size() > 1) 278137bbf98cSChris Cain { 278237bbf98cSChris Cain // More then one PowerIdlePowerSaver object is not supported and 278337bbf98cSChris Cain // is an error 278462598e31SEd Tanous BMCWEB_LOG_DEBUG( 278562598e31SEd Tanous "Found more than 1 system D-Bus Power.IdlePowerSaver objects: {}", 278662598e31SEd Tanous subtree.size()); 2787ac106bf6SEd Tanous messages::internalError(asyncResp->res); 278837bbf98cSChris Cain return; 278937bbf98cSChris Cain } 279037bbf98cSChris Cain if ((subtree[0].first.empty()) || (subtree[0].second.size() != 1)) 279137bbf98cSChris Cain { 279262598e31SEd Tanous BMCWEB_LOG_DEBUG("Power.IdlePowerSaver mapper error!"); 2793ac106bf6SEd Tanous messages::internalError(asyncResp->res); 279437bbf98cSChris Cain return; 279537bbf98cSChris Cain } 279637bbf98cSChris Cain const std::string& path = subtree[0].first; 279737bbf98cSChris Cain const std::string& service = subtree[0].second.begin()->first; 279837bbf98cSChris Cain if (service.empty()) 279937bbf98cSChris Cain { 280062598e31SEd Tanous BMCWEB_LOG_DEBUG("Power.IdlePowerSaver service mapper error!"); 2801ac106bf6SEd Tanous messages::internalError(asyncResp->res); 280237bbf98cSChris Cain return; 280337bbf98cSChris Cain } 280437bbf98cSChris Cain 280537bbf98cSChris Cain // Valid Power IdlePowerSaver object found, now set any values that 280637bbf98cSChris Cain // need to be updated 280737bbf98cSChris Cain 280837bbf98cSChris Cain if (ipsEnable) 280937bbf98cSChris Cain { 2810bd79bce8SPatrick Williams setDbusProperty( 2811bd79bce8SPatrick Williams asyncResp, "IdlePowerSaver/Enabled", service, path, 281287c44966SAsmitha Karunanithi "xyz.openbmc_project.Control.Power.IdlePowerSaver", 2813e93abac6SGinu George "Enabled", *ipsEnable); 281437bbf98cSChris Cain } 281537bbf98cSChris Cain if (ipsEnterUtil) 281637bbf98cSChris Cain { 2817bd79bce8SPatrick Williams setDbusProperty( 2818bd79bce8SPatrick Williams asyncResp, "IdlePowerSaver/EnterUtilizationPercent", 2819e93abac6SGinu George service, path, 28209ae226faSGeorge Liu "xyz.openbmc_project.Control.Power.IdlePowerSaver", 2821e93abac6SGinu George "EnterUtilizationPercent", *ipsEnterUtil); 282237bbf98cSChris Cain } 282337bbf98cSChris Cain if (ipsEnterTime) 282437bbf98cSChris Cain { 282537bbf98cSChris Cain // Convert from seconds into milliseconds for DBus 282637bbf98cSChris Cain const uint64_t timeMilliseconds = *ipsEnterTime * 1000; 2827bd79bce8SPatrick Williams setDbusProperty( 2828bd79bce8SPatrick Williams asyncResp, "IdlePowerSaver/EnterDwellTimeSeconds", service, 2829bd79bce8SPatrick Williams path, "xyz.openbmc_project.Control.Power.IdlePowerSaver", 2830e93abac6SGinu George "EnterDwellTime", timeMilliseconds); 283137bbf98cSChris Cain } 283237bbf98cSChris Cain if (ipsExitUtil) 283337bbf98cSChris Cain { 2834bd79bce8SPatrick Williams setDbusProperty( 2835bd79bce8SPatrick Williams asyncResp, "IdlePowerSaver/ExitUtilizationPercent", service, 2836bd79bce8SPatrick Williams path, "xyz.openbmc_project.Control.Power.IdlePowerSaver", 2837e93abac6SGinu George "ExitUtilizationPercent", *ipsExitUtil); 283837bbf98cSChris Cain } 283937bbf98cSChris Cain if (ipsExitTime) 284037bbf98cSChris Cain { 284137bbf98cSChris Cain // Convert from seconds into milliseconds for DBus 284237bbf98cSChris Cain const uint64_t timeMilliseconds = *ipsExitTime * 1000; 2843bd79bce8SPatrick Williams setDbusProperty( 2844bd79bce8SPatrick Williams asyncResp, "IdlePowerSaver/ExitDwellTimeSeconds", service, 2845bd79bce8SPatrick Williams path, "xyz.openbmc_project.Control.Power.IdlePowerSaver", 2846e93abac6SGinu George "ExitDwellTime", timeMilliseconds); 284737bbf98cSChris Cain } 2848e99073f5SGeorge Liu }); 284937bbf98cSChris Cain 285062598e31SEd Tanous BMCWEB_LOG_DEBUG("EXIT: Set idle power saver parameters"); 285137bbf98cSChris Cain } 285237bbf98cSChris Cain 2853c1e219d5SEd Tanous inline void handleComputerSystemCollectionHead( 2854dd60b9edSEd Tanous crow::App& app, const crow::Request& req, 2855dd60b9edSEd Tanous const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) 2856dd60b9edSEd Tanous { 2857dd60b9edSEd Tanous if (!redfish::setUpRedfishRoute(app, req, asyncResp)) 2858dd60b9edSEd Tanous { 2859dd60b9edSEd Tanous return; 2860dd60b9edSEd Tanous } 2861dd60b9edSEd Tanous asyncResp->res.addHeader( 2862dd60b9edSEd Tanous boost::beast::http::field::link, 2863dd60b9edSEd Tanous "</redfish/v1/JsonSchemas/ComputerSystemCollection/ComputerSystemCollection.json>; rel=describedby"); 2864dd60b9edSEd Tanous } 2865dd60b9edSEd Tanous 2866c1e219d5SEd Tanous inline void handleComputerSystemCollectionGet( 2867c1e219d5SEd Tanous crow::App& app, const crow::Request& req, 2868c1e219d5SEd Tanous const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) 28691abe55efSEd Tanous { 28703ba00073SCarson Labrado if (!redfish::setUpRedfishRoute(app, req, asyncResp)) 2871f4c99e70SEd Tanous { 2872f4c99e70SEd Tanous return; 2873f4c99e70SEd Tanous } 2874dd60b9edSEd Tanous 2875dd60b9edSEd Tanous asyncResp->res.addHeader( 2876dd60b9edSEd Tanous boost::beast::http::field::link, 2877dd60b9edSEd Tanous "</redfish/v1/JsonSchemas/ComputerSystemCollection.json>; rel=describedby"); 28788d1b46d7Szhanghch05 asyncResp->res.jsonValue["@odata.type"] = 28790f74e643SEd Tanous "#ComputerSystemCollection.ComputerSystemCollection"; 28808d1b46d7Szhanghch05 asyncResp->res.jsonValue["@odata.id"] = "/redfish/v1/Systems"; 28818d1b46d7Szhanghch05 asyncResp->res.jsonValue["Name"] = "Computer System Collection"; 2882462023adSSunitha Harish 2883fc5ae94dSOliver Brewka getSystemCollectionMembers(asyncResp); 2884c1e219d5SEd Tanous } 2885c1e219d5SEd Tanous 2886c1e219d5SEd Tanous /** 28877e860f15SJohn Edward Broadbent * Function transceives data with dbus directly. 28887e860f15SJohn Edward Broadbent */ 28894f48d5f6SEd Tanous inline void doNMI(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) 28907e860f15SJohn Edward Broadbent { 289189492a15SPatrick Williams constexpr const char* serviceName = "xyz.openbmc_project.Control.Host.NMI"; 289289492a15SPatrick Williams constexpr const char* objectPath = "/xyz/openbmc_project/control/host0/nmi"; 289389492a15SPatrick Williams constexpr const char* interfaceName = 28947e860f15SJohn Edward Broadbent "xyz.openbmc_project.Control.Host.NMI"; 289589492a15SPatrick Williams constexpr const char* method = "NMI"; 28967e860f15SJohn Edward Broadbent 2897177612aaSEd Tanous dbus::utility::async_method_call( 2898177612aaSEd Tanous asyncResp, 28995e7e2dc5SEd Tanous [asyncResp](const boost::system::error_code& ec) { 29007e860f15SJohn Edward Broadbent if (ec) 29017e860f15SJohn Edward Broadbent { 290262598e31SEd Tanous BMCWEB_LOG_ERROR(" Bad D-Bus request error: {}", ec); 29037e860f15SJohn Edward Broadbent messages::internalError(asyncResp->res); 29047e860f15SJohn Edward Broadbent return; 29057e860f15SJohn Edward Broadbent } 29067e860f15SJohn Edward Broadbent messages::success(asyncResp->res); 29077e860f15SJohn Edward Broadbent }, 29087e860f15SJohn Edward Broadbent serviceName, objectPath, interfaceName, method); 29097e860f15SJohn Edward Broadbent } 2910c5b2abe0SLewanczyk, Dawid 2911c1e219d5SEd Tanous inline void handleComputerSystemResetActionPost( 2912c1e219d5SEd Tanous crow::App& app, const crow::Request& req, 29137f3e84a1SEd Tanous const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 2914c1e219d5SEd Tanous const std::string& systemName) 2915c1e219d5SEd Tanous { 29163ba00073SCarson Labrado if (!redfish::setUpRedfishRoute(app, req, asyncResp)) 291745ca1b86SEd Tanous { 291845ca1b86SEd Tanous return; 291945ca1b86SEd Tanous } 2920dd7090e6SGunnar Mills 2921dd7090e6SGunnar Mills if constexpr (BMCWEB_HYPERVISOR_COMPUTER_SYSTEM) 2922dd7090e6SGunnar Mills { 2923dd7090e6SGunnar Mills if (systemName == "hypervisor") 2924dd7090e6SGunnar Mills { 2925dd7090e6SGunnar Mills handleHypervisorSystemResetPost(req, asyncResp); 2926dd7090e6SGunnar Mills return; 2927dd7090e6SGunnar Mills } 2928dd7090e6SGunnar Mills } 2929dd7090e6SGunnar Mills 2930253f11b8SEd Tanous if (systemName != BMCWEB_REDFISH_SYSTEM_URI_NAME) 2931c1e219d5SEd Tanous { 2932c1e219d5SEd Tanous messages::resourceNotFound(asyncResp->res, "ComputerSystem", 2933c1e219d5SEd Tanous systemName); 2934c1e219d5SEd Tanous return; 2935c1e219d5SEd Tanous } 293625b54dbaSEd Tanous if constexpr (BMCWEB_EXPERIMENTAL_REDFISH_MULTI_COMPUTER_SYSTEM) 29377f3e84a1SEd Tanous { 29387f3e84a1SEd Tanous // Option currently returns no systems. TBD 29397f3e84a1SEd Tanous messages::resourceNotFound(asyncResp->res, "ComputerSystem", 2940c1e219d5SEd Tanous systemName); 29417f3e84a1SEd Tanous return; 29427f3e84a1SEd Tanous } 29439712f8acSEd Tanous std::string resetType; 2944c1e219d5SEd Tanous if (!json_util::readJsonAction(req, asyncResp->res, "ResetType", resetType)) 2945cc340dd9SEd Tanous { 2946cc340dd9SEd Tanous return; 2947cc340dd9SEd Tanous } 2948cc340dd9SEd Tanous 2949d22c8396SJason M. Bills // Get the command and host vs. chassis 2950cc340dd9SEd Tanous std::string command; 2951543f4400SEd Tanous bool hostCommand = true; 2952d4d25793SEd Tanous if ((resetType == "On") || (resetType == "ForceOn")) 2953cc340dd9SEd Tanous { 2954cc340dd9SEd Tanous command = "xyz.openbmc_project.State.Host.Transition.On"; 2955d22c8396SJason M. Bills hostCommand = true; 2956d22c8396SJason M. Bills } 2957d22c8396SJason M. Bills else if (resetType == "ForceOff") 2958d22c8396SJason M. Bills { 2959d22c8396SJason M. Bills command = "xyz.openbmc_project.State.Chassis.Transition.Off"; 2960d22c8396SJason M. Bills hostCommand = false; 2961d22c8396SJason M. Bills } 2962d22c8396SJason M. Bills else if (resetType == "ForceRestart") 2963d22c8396SJason M. Bills { 2964c1e219d5SEd Tanous command = "xyz.openbmc_project.State.Host.Transition.ForceWarmReboot"; 296586a0851aSJason M. Bills hostCommand = true; 2966cc340dd9SEd Tanous } 29679712f8acSEd Tanous else if (resetType == "GracefulShutdown") 2968cc340dd9SEd Tanous { 2969cc340dd9SEd Tanous command = "xyz.openbmc_project.State.Host.Transition.Off"; 2970d22c8396SJason M. Bills hostCommand = true; 2971cc340dd9SEd Tanous } 29729712f8acSEd Tanous else if (resetType == "GracefulRestart") 2973cc340dd9SEd Tanous { 29740fda0f12SGeorge Liu command = 29750fda0f12SGeorge Liu "xyz.openbmc_project.State.Host.Transition.GracefulWarmReboot"; 2976d22c8396SJason M. Bills hostCommand = true; 2977d22c8396SJason M. Bills } 2978d22c8396SJason M. Bills else if (resetType == "PowerCycle") 2979d22c8396SJason M. Bills { 298086a0851aSJason M. Bills command = "xyz.openbmc_project.State.Host.Transition.Reboot"; 298186a0851aSJason M. Bills hostCommand = true; 2982cc340dd9SEd Tanous } 2983bfd5b826SLakshminarayana R. Kammath else if (resetType == "Nmi") 2984bfd5b826SLakshminarayana R. Kammath { 2985bfd5b826SLakshminarayana R. Kammath doNMI(asyncResp); 2986bfd5b826SLakshminarayana R. Kammath return; 2987bfd5b826SLakshminarayana R. Kammath } 2988cc340dd9SEd Tanous else 2989cc340dd9SEd Tanous { 2990c1e219d5SEd Tanous messages::actionParameterUnknown(asyncResp->res, "Reset", resetType); 2991cc340dd9SEd Tanous return; 2992cc340dd9SEd Tanous } 2993d02aad39SEd Tanous sdbusplus::message::object_path statePath("/xyz/openbmc_project/state"); 2994cc340dd9SEd Tanous 2995d22c8396SJason M. Bills if (hostCommand) 2996d22c8396SJason M. Bills { 2997e93abac6SGinu George setDbusProperty(asyncResp, "Reset", "xyz.openbmc_project.State.Host", 2998d02aad39SEd Tanous statePath / "host0", "xyz.openbmc_project.State.Host", 2999e93abac6SGinu George "RequestedHostTransition", command); 3000cc340dd9SEd Tanous } 3001d22c8396SJason M. Bills else 3002d22c8396SJason M. Bills { 3003e93abac6SGinu George setDbusProperty(asyncResp, "Reset", "xyz.openbmc_project.State.Chassis", 3004d02aad39SEd Tanous statePath / "chassis0", 3005d02aad39SEd Tanous "xyz.openbmc_project.State.Chassis", 3006e93abac6SGinu George "RequestedPowerTransition", command); 3007d22c8396SJason M. Bills } 3008d22c8396SJason M. Bills } 3009cc340dd9SEd Tanous 3010c1e219d5SEd Tanous inline void handleComputerSystemHead( 3011dd60b9edSEd Tanous App& app, const crow::Request& req, 30127f3e84a1SEd Tanous const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 30137f3e84a1SEd Tanous const std::string& /*systemName*/) 3014dd60b9edSEd Tanous { 3015dd60b9edSEd Tanous if (!redfish::setUpRedfishRoute(app, req, asyncResp)) 3016dd60b9edSEd Tanous { 3017dd60b9edSEd Tanous return; 3018dd60b9edSEd Tanous } 3019dd60b9edSEd Tanous 3020dd60b9edSEd Tanous asyncResp->res.addHeader( 3021dd60b9edSEd Tanous boost::beast::http::field::link, 3022dd60b9edSEd Tanous "</redfish/v1/JsonSchemas/ComputerSystem/ComputerSystem.json>; rel=describedby"); 3023dd60b9edSEd Tanous } 3024dd60b9edSEd Tanous 30255c3e9272SAbhishek Patel inline void afterPortRequest( 30265c3e9272SAbhishek Patel const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 30275c3e9272SAbhishek Patel const boost::system::error_code& ec, 30285c3e9272SAbhishek Patel const std::vector<std::tuple<std::string, std::string, bool>>& socketData) 30295c3e9272SAbhishek Patel { 30305c3e9272SAbhishek Patel if (ec) 30315c3e9272SAbhishek Patel { 3032b3e86cb0SGunnar Mills BMCWEB_LOG_ERROR("DBUS response error {}", ec); 30335c3e9272SAbhishek Patel messages::internalError(asyncResp->res); 30345c3e9272SAbhishek Patel return; 30355c3e9272SAbhishek Patel } 30365c3e9272SAbhishek Patel for (const auto& data : socketData) 30375c3e9272SAbhishek Patel { 30385c3e9272SAbhishek Patel const std::string& socketPath = get<0>(data); 30395c3e9272SAbhishek Patel const std::string& protocolName = get<1>(data); 30405c3e9272SAbhishek Patel bool isProtocolEnabled = get<2>(data); 30415c3e9272SAbhishek Patel nlohmann::json& dataJson = asyncResp->res.jsonValue["SerialConsole"]; 30425c3e9272SAbhishek Patel dataJson[protocolName]["ServiceEnabled"] = isProtocolEnabled; 30435c3e9272SAbhishek Patel // need to retrieve port number for 30445c3e9272SAbhishek Patel // obmc-console-ssh service 30455c3e9272SAbhishek Patel if (protocolName == "SSH") 30465c3e9272SAbhishek Patel { 30475c3e9272SAbhishek Patel getPortNumber(socketPath, [asyncResp, protocolName]( 304881c4e330SEd Tanous const boost::system::error_code& ec1, 30495c3e9272SAbhishek Patel int portNumber) { 30505c3e9272SAbhishek Patel if (ec1) 30515c3e9272SAbhishek Patel { 3052b3e86cb0SGunnar Mills BMCWEB_LOG_ERROR("DBUS response error {}", ec1); 30535c3e9272SAbhishek Patel messages::internalError(asyncResp->res); 30545c3e9272SAbhishek Patel return; 30555c3e9272SAbhishek Patel } 30565c3e9272SAbhishek Patel nlohmann::json& dataJson1 = 30575c3e9272SAbhishek Patel asyncResp->res.jsonValue["SerialConsole"]; 30585c3e9272SAbhishek Patel dataJson1[protocolName]["Port"] = portNumber; 30595c3e9272SAbhishek Patel }); 30605c3e9272SAbhishek Patel } 30615c3e9272SAbhishek Patel } 30625c3e9272SAbhishek Patel } 3063c1e219d5SEd Tanous 3064*5e7c1f31SOliver Brewka /** 3065*5e7c1f31SOliver Brewka * @brief process the GET request after getting the computerSystemIndex 3066*5e7c1f31SOliver Brewka * 3067*5e7c1f31SOliver Brewka * @param[in] asyncResp Shared pointer for completing asynchronous 3068*5e7c1f31SOliver Brewka * calls 3069*5e7c1f31SOliver Brewka * @param[in] systemName Name of the requested system 3070*5e7c1f31SOliver Brewka * @param[in] computerSystemIndex Index associated with the requested system 3071*5e7c1f31SOliver Brewka * 3072*5e7c1f31SOliver Brewka * @return None 3073*5e7c1f31SOliver Brewka */ 3074*5e7c1f31SOliver Brewka inline void processComputerSystemGet( 307522d268cbSEd Tanous const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 3076*5e7c1f31SOliver Brewka const std::string& systemName, const uint64_t computerSystemIndex) 3077c1e219d5SEd Tanous { 3078dd60b9edSEd Tanous asyncResp->res.addHeader( 3079dd60b9edSEd Tanous boost::beast::http::field::link, 3080dd60b9edSEd Tanous "</redfish/v1/JsonSchemas/ComputerSystem/ComputerSystem.json>; rel=describedby"); 30818d1b46d7Szhanghch05 asyncResp->res.jsonValue["@odata.type"] = 3082b6655101SChris Cain "#ComputerSystem.v1_22_0.ComputerSystem"; 3083*5e7c1f31SOliver Brewka asyncResp->res.jsonValue["Name"] = systemName; 3084*5e7c1f31SOliver Brewka asyncResp->res.jsonValue["Id"] = systemName; 3085539d8c6bSEd Tanous asyncResp->res.jsonValue["SystemType"] = 3086539d8c6bSEd Tanous computer_system::SystemType::Physical; 30878d1b46d7Szhanghch05 asyncResp->res.jsonValue["Description"] = "Computer System"; 30888d1b46d7Szhanghch05 asyncResp->res.jsonValue["ProcessorSummary"]["Count"] = 0; 3089cf0e004cSNinad Palsule asyncResp->res.jsonValue["MemorySummary"]["TotalSystemMemoryGiB"] = 3090dfb2b408SPriyanga Ramasamy double(0); 3091*5e7c1f31SOliver Brewka asyncResp->res.jsonValue["@odata.id"] = 3092*5e7c1f31SOliver Brewka boost::urls::format("/redfish/v1/Systems/{}", systemName); 309304a258f4SEd Tanous 3094*5e7c1f31SOliver Brewka // Currently not supported on multi-host. TBD 3095*5e7c1f31SOliver Brewka if constexpr (!BMCWEB_EXPERIMENTAL_REDFISH_MULTI_COMPUTER_SYSTEM) 3096*5e7c1f31SOliver Brewka { 3097*5e7c1f31SOliver Brewka asyncResp->res.jsonValue["Bios"]["@odata.id"] = 3098*5e7c1f31SOliver Brewka boost::urls::format("/redfish/v1/Systems/{}/Bios", systemName); 3099*5e7c1f31SOliver Brewka asyncResp->res.jsonValue["Processors"]["@odata.id"] = 3100*5e7c1f31SOliver Brewka boost::urls::format("/redfish/v1/Systems/{}/Processors", 3101*5e7c1f31SOliver Brewka systemName); 3102*5e7c1f31SOliver Brewka asyncResp->res.jsonValue["Memory"]["@odata.id"] = 3103*5e7c1f31SOliver Brewka boost::urls::format("/redfish/v1/Systems/{}/Memory", systemName); 3104*5e7c1f31SOliver Brewka asyncResp->res.jsonValue["Storage"]["@odata.id"] = 3105*5e7c1f31SOliver Brewka boost::urls::format("/redfish/v1/Systems/{}/Storage", systemName); 31063179105bSSunny Srivastava asyncResp->res.jsonValue["FabricAdapters"]["@odata.id"] = 3107253f11b8SEd Tanous boost::urls::format("/redfish/v1/Systems/{}/FabricAdapters", 3108*5e7c1f31SOliver Brewka systemName); 3109*5e7c1f31SOliver Brewka } 3110029573d4SEd Tanous 3111002d39b4SEd Tanous asyncResp->res.jsonValue["Actions"]["#ComputerSystem.Reset"]["target"] = 3112253f11b8SEd Tanous boost::urls::format( 3113*5e7c1f31SOliver Brewka "/redfish/v1/Systems/{}/Actions/ComputerSystem.Reset", systemName); 3114c1e219d5SEd Tanous asyncResp->res 3115c1e219d5SEd Tanous .jsonValue["Actions"]["#ComputerSystem.Reset"]["@Redfish.ActionInfo"] = 3116253f11b8SEd Tanous boost::urls::format("/redfish/v1/Systems/{}/ResetActionInfo", 3117*5e7c1f31SOliver Brewka systemName); 3118c5b2abe0SLewanczyk, Dawid 3119*5e7c1f31SOliver Brewka asyncResp->res.jsonValue["LogServices"]["@odata.id"] = 3120*5e7c1f31SOliver Brewka boost::urls::format("/redfish/v1/Systems/{}/LogServices", systemName); 3121c4bf6374SJason M. Bills 31221476687dSEd Tanous nlohmann::json::array_t managedBy; 31231476687dSEd Tanous nlohmann::json& manager = managedBy.emplace_back(); 3124253f11b8SEd Tanous manager["@odata.id"] = boost::urls::format("/redfish/v1/Managers/{}", 3125253f11b8SEd Tanous BMCWEB_REDFISH_MANAGER_URI_NAME); 3126002d39b4SEd Tanous asyncResp->res.jsonValue["Links"]["ManagedBy"] = std::move(managedBy); 3127539d8c6bSEd Tanous asyncResp->res.jsonValue["Status"]["Health"] = resource::Health::OK; 3128539d8c6bSEd Tanous asyncResp->res.jsonValue["Status"]["State"] = resource::State::Enabled; 31290e8ac5e7SGunnar Mills 31300e8ac5e7SGunnar Mills // Fill in SerialConsole info 3131002d39b4SEd Tanous asyncResp->res.jsonValue["SerialConsole"]["MaxConcurrentSessions"] = 15; 3132c1e219d5SEd Tanous asyncResp->res.jsonValue["SerialConsole"]["IPMI"]["ServiceEnabled"] = true; 31331476687dSEd Tanous 3134c1e219d5SEd Tanous asyncResp->res.jsonValue["SerialConsole"]["SSH"]["ServiceEnabled"] = true; 31351476687dSEd Tanous asyncResp->res.jsonValue["SerialConsole"]["SSH"]["Port"] = 2200; 3136c1e219d5SEd Tanous asyncResp->res.jsonValue["SerialConsole"]["SSH"]["HotKeySequenceDisplay"] = 31371476687dSEd Tanous "Press ~. to exit console"; 31385c3e9272SAbhishek Patel getPortStatusAndPath(std::span{protocolToDBusForSystems}, 31395c3e9272SAbhishek Patel std::bind_front(afterPortRequest, asyncResp)); 31400e8ac5e7SGunnar Mills 314125b54dbaSEd Tanous if constexpr (BMCWEB_KVM) 314225b54dbaSEd Tanous { 31430e8ac5e7SGunnar Mills // Fill in GraphicalConsole info 3144002d39b4SEd Tanous asyncResp->res.jsonValue["GraphicalConsole"]["ServiceEnabled"] = true; 314525b54dbaSEd Tanous asyncResp->res.jsonValue["GraphicalConsole"]["MaxConcurrentSessions"] = 314625b54dbaSEd Tanous 4; 3147613dabeaSEd Tanous asyncResp->res.jsonValue["GraphicalConsole"]["ConnectTypesSupported"] = 3148613dabeaSEd Tanous nlohmann::json::array_t({"KVMIP"}); 314925b54dbaSEd Tanous } 315013451e39SWilly Tu 31512eaa9279SJanet Adkins systems_utils::getValidSystemsPath( 31522eaa9279SJanet Adkins asyncResp, systemName, 31532eaa9279SJanet Adkins [asyncResp, 31542eaa9279SJanet Adkins systemName](const std::optional<std::string>& validSystemsPath) { 31552eaa9279SJanet Adkins if (validSystemsPath) 31562eaa9279SJanet Adkins { 31572eaa9279SJanet Adkins getLocationIndicatorActive(asyncResp, *validSystemsPath); 31582eaa9279SJanet Adkins } 31592eaa9279SJanet Adkins }); 31602eaa9279SJanet Adkins 3161f664fd8aSJanet Adkins if constexpr (BMCWEB_REDFISH_ALLOW_DEPRECATED_INDICATORLED) 3162f664fd8aSJanet Adkins { 3163a3002228SAppaRao Puli getIndicatorLedState(asyncResp); 3164f664fd8aSJanet Adkins } 3165f664fd8aSJanet Adkins 3166*5e7c1f31SOliver Brewka // Currently not supported on multi-host. 3167*5e7c1f31SOliver Brewka if constexpr (!BMCWEB_EXPERIMENTAL_REDFISH_MULTI_COMPUTER_SYSTEM) 3168*5e7c1f31SOliver Brewka { 316951bd2d8aSGunnar Mills getComputerSystem(asyncResp); 3170*5e7c1f31SOliver Brewka // Todo: chassis matching could be handled by patch 3171*5e7c1f31SOliver Brewka // https://gerrit.openbmc.org/c/openbmc/bmcweb/+/60793 3172*5e7c1f31SOliver Brewka getMainChassisId( 3173*5e7c1f31SOliver Brewka asyncResp, [](const std::string& chassisId, 3174*5e7c1f31SOliver Brewka const std::shared_ptr<bmcweb::AsyncResp>& aRsp) { 3175*5e7c1f31SOliver Brewka nlohmann::json::array_t chassisArray; 3176*5e7c1f31SOliver Brewka nlohmann::json& chassis = chassisArray.emplace_back(); 3177*5e7c1f31SOliver Brewka chassis["@odata.id"] = 3178*5e7c1f31SOliver Brewka boost::urls::format("/redfish/v1/Chassis/{}", chassisId); 3179*5e7c1f31SOliver Brewka aRsp->res.jsonValue["Links"]["Chassis"] = 3180*5e7c1f31SOliver Brewka std::move(chassisArray); 3181*5e7c1f31SOliver Brewka }); 3182*5e7c1f31SOliver Brewka 3183*5e7c1f31SOliver Brewka pcie_util::getPCIeDeviceList( 3184*5e7c1f31SOliver Brewka asyncResp, nlohmann::json::json_pointer("/PCIeDevices")); 3185*5e7c1f31SOliver Brewka } 3186*5e7c1f31SOliver Brewka getHostState(asyncResp, computerSystemIndex); 3187*5e7c1f31SOliver Brewka getBootProperties(asyncResp, computerSystemIndex); 3188*5e7c1f31SOliver Brewka getBootProgress(asyncResp, computerSystemIndex); 3189*5e7c1f31SOliver Brewka getBootProgressLastStateTime(asyncResp, computerSystemIndex); 319051709ffdSYong Li getHostWatchdogTimer(asyncResp); 3191*5e7c1f31SOliver Brewka getPowerRestorePolicy(asyncResp, computerSystemIndex); 31929dcfe8c1SAlbert Zhang getStopBootOnFault(asyncResp); 3193*5e7c1f31SOliver Brewka getAutomaticRetryPolicy(asyncResp, computerSystemIndex); 3194*5e7c1f31SOliver Brewka getLastResetTime(asyncResp, computerSystemIndex); 319525b54dbaSEd Tanous if constexpr (BMCWEB_REDFISH_PROVISIONING_FEATURE) 319625b54dbaSEd Tanous { 3197a6349918SAppaRao Puli getProvisioningStatus(asyncResp); 319825b54dbaSEd Tanous } 3199*5e7c1f31SOliver Brewka getTrustedModuleRequiredToBoot(asyncResp, computerSystemIndex); 32003a2d0424SChris Cain getPowerMode(asyncResp); 320137bbf98cSChris Cain getIdlePowerSaver(asyncResp); 3202c1e219d5SEd Tanous } 3203550a6bf8SJiaqing Zhao 3204*5e7c1f31SOliver Brewka inline void handleComputerSystemGet( 3205*5e7c1f31SOliver Brewka crow::App& app, const crow::Request& req, 3206*5e7c1f31SOliver Brewka const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 3207*5e7c1f31SOliver Brewka const std::string& systemName) 3208*5e7c1f31SOliver Brewka { 3209*5e7c1f31SOliver Brewka if (!redfish::setUpRedfishRoute(app, req, asyncResp)) 3210*5e7c1f31SOliver Brewka { 3211*5e7c1f31SOliver Brewka return; 3212*5e7c1f31SOliver Brewka } 3213*5e7c1f31SOliver Brewka 3214*5e7c1f31SOliver Brewka if constexpr (BMCWEB_HYPERVISOR_COMPUTER_SYSTEM) 3215*5e7c1f31SOliver Brewka { 3216*5e7c1f31SOliver Brewka if (systemName == "hypervisor") 3217*5e7c1f31SOliver Brewka { 3218*5e7c1f31SOliver Brewka handleHypervisorSystemGet(asyncResp); 3219*5e7c1f31SOliver Brewka return; 3220*5e7c1f31SOliver Brewka } 3221*5e7c1f31SOliver Brewka } 3222*5e7c1f31SOliver Brewka 3223*5e7c1f31SOliver Brewka if constexpr (!BMCWEB_EXPERIMENTAL_REDFISH_MULTI_COMPUTER_SYSTEM) 3224*5e7c1f31SOliver Brewka { 3225*5e7c1f31SOliver Brewka if (systemName != BMCWEB_REDFISH_SYSTEM_URI_NAME) 3226*5e7c1f31SOliver Brewka { 3227*5e7c1f31SOliver Brewka messages::resourceNotFound(asyncResp->res, "ComputerSystem", 3228*5e7c1f31SOliver Brewka systemName); 3229*5e7c1f31SOliver Brewka return; 3230*5e7c1f31SOliver Brewka } 3231*5e7c1f31SOliver Brewka } 3232*5e7c1f31SOliver Brewka 3233*5e7c1f31SOliver Brewka BMCWEB_LOG_DEBUG("requested system = {}", systemName); 3234*5e7c1f31SOliver Brewka getComputerSystemIndex( 3235*5e7c1f31SOliver Brewka asyncResp, systemName, 3236*5e7c1f31SOliver Brewka std::bind_front(processComputerSystemGet, asyncResp, systemName)); 3237*5e7c1f31SOliver Brewka } 3238*5e7c1f31SOliver Brewka 3239c1e219d5SEd Tanous inline void handleComputerSystemPatch( 3240c1e219d5SEd Tanous crow::App& app, const crow::Request& req, 324122d268cbSEd Tanous const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 3242c1e219d5SEd Tanous const std::string& systemName) 3243c1e219d5SEd Tanous { 32443ba00073SCarson Labrado if (!redfish::setUpRedfishRoute(app, req, asyncResp)) 324545ca1b86SEd Tanous { 324645ca1b86SEd Tanous return; 324745ca1b86SEd Tanous } 324825b54dbaSEd Tanous if constexpr (BMCWEB_EXPERIMENTAL_REDFISH_MULTI_COMPUTER_SYSTEM) 32497f3e84a1SEd Tanous { 32507f3e84a1SEd Tanous // Option currently returns no systems. TBD 32517f3e84a1SEd Tanous messages::resourceNotFound(asyncResp->res, "ComputerSystem", 32527f3e84a1SEd Tanous systemName); 32537f3e84a1SEd Tanous return; 32547f3e84a1SEd Tanous } 3255253f11b8SEd Tanous if (systemName != BMCWEB_REDFISH_SYSTEM_URI_NAME) 325622d268cbSEd Tanous { 325722d268cbSEd Tanous messages::resourceNotFound(asyncResp->res, "ComputerSystem", 325822d268cbSEd Tanous systemName); 325922d268cbSEd Tanous return; 326022d268cbSEd Tanous } 326122d268cbSEd Tanous 3262dd60b9edSEd Tanous asyncResp->res.addHeader( 3263dd60b9edSEd Tanous boost::beast::http::field::link, 3264dd60b9edSEd Tanous "</redfish/v1/JsonSchemas/ComputerSystem/ComputerSystem.json>; rel=describedby"); 3265dd60b9edSEd Tanous 32669f8bfa7cSGunnar Mills std::optional<bool> locationIndicatorActive; 3267cde19e5fSSantosh Puranik std::optional<std::string> indicatorLed; 326898e386ecSGunnar Mills std::optional<std::string> assetTag; 3269c6a620f2SGeorge Liu std::optional<std::string> powerRestorePolicy; 32703a2d0424SChris Cain std::optional<std::string> powerMode; 3271550a6bf8SJiaqing Zhao std::optional<bool> wdtEnable; 3272550a6bf8SJiaqing Zhao std::optional<std::string> wdtTimeOutAction; 3273550a6bf8SJiaqing Zhao std::optional<std::string> bootSource; 3274550a6bf8SJiaqing Zhao std::optional<std::string> bootType; 3275550a6bf8SJiaqing Zhao std::optional<std::string> bootEnable; 3276550a6bf8SJiaqing Zhao std::optional<std::string> bootAutomaticRetry; 3277797d5daeSCorey Hardesty std::optional<uint32_t> bootAutomaticRetryAttempts; 3278550a6bf8SJiaqing Zhao std::optional<bool> bootTrustedModuleRequired; 32799dcfe8c1SAlbert Zhang std::optional<std::string> stopBootOnFault; 3280550a6bf8SJiaqing Zhao std::optional<bool> ipsEnable; 3281550a6bf8SJiaqing Zhao std::optional<uint8_t> ipsEnterUtil; 3282550a6bf8SJiaqing Zhao std::optional<uint64_t> ipsEnterTime; 3283550a6bf8SJiaqing Zhao std::optional<uint8_t> ipsExitUtil; 3284550a6bf8SJiaqing Zhao std::optional<uint64_t> ipsExitTime; 3285550a6bf8SJiaqing Zhao 3286afc474aeSMyung Bae if (!json_util::readJsonPatch( // 3287afc474aeSMyung Bae req, asyncResp->res, // 3288afc474aeSMyung Bae "AssetTag", assetTag, // 3289afc474aeSMyung Bae "Boot/AutomaticRetryAttempts", bootAutomaticRetryAttempts, // 3290afc474aeSMyung Bae "Boot/AutomaticRetryConfig", bootAutomaticRetry, // 3291afc474aeSMyung Bae "Boot/BootSourceOverrideEnabled", bootEnable, // 3292afc474aeSMyung Bae "Boot/BootSourceOverrideMode", bootType, // 3293afc474aeSMyung Bae "Boot/BootSourceOverrideTarget", bootSource, // 3294afc474aeSMyung Bae "Boot/StopBootOnFault", stopBootOnFault, // 3295afc474aeSMyung Bae "Boot/TrustedModuleRequiredToBoot", bootTrustedModuleRequired, // 3296afc474aeSMyung Bae "HostWatchdogTimer/FunctionEnabled", wdtEnable, // 3297afc474aeSMyung Bae "HostWatchdogTimer/TimeoutAction", wdtTimeOutAction, // 3298afc474aeSMyung Bae "IdlePowerSaver/Enabled", ipsEnable, // 3299afc474aeSMyung Bae "IdlePowerSaver/EnterDwellTimeSeconds", ipsEnterTime, // 3300afc474aeSMyung Bae "IdlePowerSaver/EnterUtilizationPercent", ipsEnterUtil, // 3301afc474aeSMyung Bae "IdlePowerSaver/ExitDwellTimeSeconds", ipsExitTime, // 3302afc474aeSMyung Bae "IdlePowerSaver/ExitUtilizationPercent", ipsExitUtil, // 3303afc474aeSMyung Bae "IndicatorLED", indicatorLed, // 3304afc474aeSMyung Bae "LocationIndicatorActive", locationIndicatorActive, // 3305afc474aeSMyung Bae "PowerMode", powerMode, // 3306afc474aeSMyung Bae "PowerRestorePolicy", powerRestorePolicy // 3307afc474aeSMyung Bae )) 33086617338dSEd Tanous { 33096617338dSEd Tanous return; 33106617338dSEd Tanous } 3311491d8ee7SSantosh Puranik 3312f664fd8aSJanet Adkins if constexpr (!BMCWEB_REDFISH_ALLOW_DEPRECATED_INDICATORLED) 3313f664fd8aSJanet Adkins { 3314f664fd8aSJanet Adkins if (indicatorLed) 3315f664fd8aSJanet Adkins { 3316f664fd8aSJanet Adkins messages::propertyUnknown(asyncResp->res, "IndicatorLED"); 3317f664fd8aSJanet Adkins return; 3318f664fd8aSJanet Adkins } 3319f664fd8aSJanet Adkins } 3320f664fd8aSJanet Adkins 332198e386ecSGunnar Mills if (assetTag) 332298e386ecSGunnar Mills { 332398e386ecSGunnar Mills setAssetTag(asyncResp, *assetTag); 332498e386ecSGunnar Mills } 332598e386ecSGunnar Mills 3326550a6bf8SJiaqing Zhao if (wdtEnable || wdtTimeOutAction) 3327c45f0082SYong Li { 3328f23b7296SEd Tanous setWDTProperties(asyncResp, wdtEnable, wdtTimeOutAction); 3329c45f0082SYong Li } 3330c45f0082SYong Li 3331cd9a4666SKonstantin Aladyshev if (bootSource || bootType || bootEnable) 333269f35306SGunnar Mills { 3333002d39b4SEd Tanous setBootProperties(asyncResp, bootSource, bootType, bootEnable); 3334491d8ee7SSantosh Puranik } 3335550a6bf8SJiaqing Zhao if (bootAutomaticRetry) 333669f35306SGunnar Mills { 3337550a6bf8SJiaqing Zhao setAutomaticRetry(asyncResp, *bootAutomaticRetry); 333869f35306SGunnar Mills } 3339ac7e1e0bSAli Ahmed 3340797d5daeSCorey Hardesty if (bootAutomaticRetryAttempts) 3341797d5daeSCorey Hardesty { 3342797d5daeSCorey Hardesty setAutomaticRetryAttempts(asyncResp, 3343797d5daeSCorey Hardesty bootAutomaticRetryAttempts.value()); 3344797d5daeSCorey Hardesty } 3345797d5daeSCorey Hardesty 3346550a6bf8SJiaqing Zhao if (bootTrustedModuleRequired) 3347ac7e1e0bSAli Ahmed { 3348c1e219d5SEd Tanous setTrustedModuleRequiredToBoot(asyncResp, *bootTrustedModuleRequired); 334969f35306SGunnar Mills } 3350265c1602SJohnathan Mantey 33519dcfe8c1SAlbert Zhang if (stopBootOnFault) 33529dcfe8c1SAlbert Zhang { 33539dcfe8c1SAlbert Zhang setStopBootOnFault(asyncResp, *stopBootOnFault); 33549dcfe8c1SAlbert Zhang } 33559dcfe8c1SAlbert Zhang 33569f8bfa7cSGunnar Mills if (locationIndicatorActive) 33579f8bfa7cSGunnar Mills { 33582eaa9279SJanet Adkins systems_utils::getValidSystemsPath( 33592eaa9279SJanet Adkins asyncResp, systemName, 33602eaa9279SJanet Adkins [asyncResp, systemName, 33612eaa9279SJanet Adkins locationIndicatorActive{*locationIndicatorActive}]( 33622eaa9279SJanet Adkins const std::optional<std::string>& validSystemsPath) { 33632eaa9279SJanet Adkins if (!validSystemsPath) 33642eaa9279SJanet Adkins { 33652eaa9279SJanet Adkins messages::resourceNotFound(asyncResp->res, "Systems", 33662eaa9279SJanet Adkins systemName); 33672eaa9279SJanet Adkins return; 33682eaa9279SJanet Adkins } 33692eaa9279SJanet Adkins setLocationIndicatorActive(asyncResp, *validSystemsPath, 33702eaa9279SJanet Adkins locationIndicatorActive); 33712eaa9279SJanet Adkins }); 33729f8bfa7cSGunnar Mills } 33739f8bfa7cSGunnar Mills 3374f664fd8aSJanet Adkins if constexpr (BMCWEB_REDFISH_ALLOW_DEPRECATED_INDICATORLED) 3375f664fd8aSJanet Adkins { 33769712f8acSEd Tanous if (indicatorLed) 33776617338dSEd Tanous { 3378f23b7296SEd Tanous setIndicatorLedState(asyncResp, *indicatorLed); 3379002d39b4SEd Tanous asyncResp->res.addHeader(boost::beast::http::field::warning, 3380d6aa0093SGunnar Mills "299 - \"IndicatorLED is deprecated. Use " 3381d6aa0093SGunnar Mills "LocationIndicatorActive instead.\""); 33826617338dSEd Tanous } 3383f664fd8aSJanet Adkins } 3384c6a620f2SGeorge Liu 3385c6a620f2SGeorge Liu if (powerRestorePolicy) 3386c6a620f2SGeorge Liu { 33874e69c904SGunnar Mills setPowerRestorePolicy(asyncResp, *powerRestorePolicy); 3388c6a620f2SGeorge Liu } 33893a2d0424SChris Cain 33903a2d0424SChris Cain if (powerMode) 33913a2d0424SChris Cain { 33923a2d0424SChris Cain setPowerMode(asyncResp, *powerMode); 33933a2d0424SChris Cain } 339437bbf98cSChris Cain 3395c1e219d5SEd Tanous if (ipsEnable || ipsEnterUtil || ipsEnterTime || ipsExitUtil || ipsExitTime) 339637bbf98cSChris Cain { 3397002d39b4SEd Tanous setIdlePowerSaver(asyncResp, ipsEnable, ipsEnterUtil, ipsEnterTime, 3398002d39b4SEd Tanous ipsExitUtil, ipsExitTime); 339937bbf98cSChris Cain } 3400c1e219d5SEd Tanous } 34011cb1a9e6SAppaRao Puli 340238c8a6f2SEd Tanous inline void handleSystemCollectionResetActionHead( 3403dd60b9edSEd Tanous crow::App& app, const crow::Request& req, 34047f3e84a1SEd Tanous const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 3405c1e219d5SEd Tanous const std::string& /*systemName*/) 3406dd60b9edSEd Tanous { 3407dd60b9edSEd Tanous if (!redfish::setUpRedfishRoute(app, req, asyncResp)) 3408dd60b9edSEd Tanous { 3409dd60b9edSEd Tanous return; 3410dd60b9edSEd Tanous } 3411dd60b9edSEd Tanous asyncResp->res.addHeader( 3412dd60b9edSEd Tanous boost::beast::http::field::link, 3413dd60b9edSEd Tanous "</redfish/v1/JsonSchemas/ActionInfo/ActionInfo.json>; rel=describedby"); 3414dd60b9edSEd Tanous } 341533e1f122SAndrew Geissler 341633e1f122SAndrew Geissler /** 341733e1f122SAndrew Geissler * @brief Translates allowed host transitions to redfish string 341833e1f122SAndrew Geissler * 341933e1f122SAndrew Geissler * @param[in] dbusAllowedHostTran The allowed host transition on dbus 342033e1f122SAndrew Geissler * @param[out] allowableValues The translated host transition(s) 342133e1f122SAndrew Geissler * 3422efff2b5dSManojkiran Eda * @return Emplaces corresponding Redfish translated value(s) in 342333e1f122SAndrew Geissler * allowableValues. If translation not possible, does nothing to 342433e1f122SAndrew Geissler * allowableValues. 342533e1f122SAndrew Geissler */ 3426504af5a0SPatrick Williams inline void dbusToRfAllowedHostTransitions( 3427504af5a0SPatrick Williams const std::string& dbusAllowedHostTran, 342833e1f122SAndrew Geissler nlohmann::json::array_t& allowableValues) 342933e1f122SAndrew Geissler { 343033e1f122SAndrew Geissler if (dbusAllowedHostTran == "xyz.openbmc_project.State.Host.Transition.On") 343133e1f122SAndrew Geissler { 343233e1f122SAndrew Geissler allowableValues.emplace_back(resource::ResetType::On); 343333e1f122SAndrew Geissler allowableValues.emplace_back(resource::ResetType::ForceOn); 343433e1f122SAndrew Geissler } 343533e1f122SAndrew Geissler else if (dbusAllowedHostTran == 343633e1f122SAndrew Geissler "xyz.openbmc_project.State.Host.Transition.Off") 343733e1f122SAndrew Geissler { 343833e1f122SAndrew Geissler allowableValues.emplace_back(resource::ResetType::GracefulShutdown); 343933e1f122SAndrew Geissler } 344033e1f122SAndrew Geissler else if (dbusAllowedHostTran == 344133e1f122SAndrew Geissler "xyz.openbmc_project.State.Host.Transition.GracefulWarmReboot") 344233e1f122SAndrew Geissler { 344333e1f122SAndrew Geissler allowableValues.emplace_back(resource::ResetType::GracefulRestart); 344433e1f122SAndrew Geissler } 344533e1f122SAndrew Geissler else if (dbusAllowedHostTran == 344633e1f122SAndrew Geissler "xyz.openbmc_project.State.Host.Transition.ForceWarmReboot") 344733e1f122SAndrew Geissler { 344833e1f122SAndrew Geissler allowableValues.emplace_back(resource::ResetType::ForceRestart); 344933e1f122SAndrew Geissler } 345033e1f122SAndrew Geissler else 345133e1f122SAndrew Geissler { 345233e1f122SAndrew Geissler BMCWEB_LOG_WARNING("Unsupported host tran {}", dbusAllowedHostTran); 345333e1f122SAndrew Geissler } 345433e1f122SAndrew Geissler } 345533e1f122SAndrew Geissler 345633e1f122SAndrew Geissler inline void afterGetAllowedHostTransitions( 345733e1f122SAndrew Geissler const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 345833e1f122SAndrew Geissler const boost::system::error_code& ec, 345933e1f122SAndrew Geissler const std::vector<std::string>& allowedHostTransitions) 346033e1f122SAndrew Geissler { 346133e1f122SAndrew Geissler nlohmann::json::array_t allowableValues; 346233e1f122SAndrew Geissler 346333e1f122SAndrew Geissler // Supported on all systems currently 346433e1f122SAndrew Geissler allowableValues.emplace_back(resource::ResetType::ForceOff); 346533e1f122SAndrew Geissler allowableValues.emplace_back(resource::ResetType::PowerCycle); 346633e1f122SAndrew Geissler allowableValues.emplace_back(resource::ResetType::Nmi); 346733e1f122SAndrew Geissler 346833e1f122SAndrew Geissler if (ec) 346933e1f122SAndrew Geissler { 3470e715d14bSEd Tanous if ((ec.value() == 3471e715d14bSEd Tanous boost::system::linux_error::bad_request_descriptor) || 3472e715d14bSEd Tanous (ec.value() == boost::asio::error::basic_errors::host_unreachable)) 347333e1f122SAndrew Geissler { 347433e1f122SAndrew Geissler // Property not implemented so just return defaults 347533e1f122SAndrew Geissler BMCWEB_LOG_DEBUG("Property not available {}", ec); 347633e1f122SAndrew Geissler allowableValues.emplace_back(resource::ResetType::On); 347733e1f122SAndrew Geissler allowableValues.emplace_back(resource::ResetType::ForceOn); 347833e1f122SAndrew Geissler allowableValues.emplace_back(resource::ResetType::ForceRestart); 347933e1f122SAndrew Geissler allowableValues.emplace_back(resource::ResetType::GracefulRestart); 348033e1f122SAndrew Geissler allowableValues.emplace_back(resource::ResetType::GracefulShutdown); 348133e1f122SAndrew Geissler } 348233e1f122SAndrew Geissler else 348333e1f122SAndrew Geissler { 348433e1f122SAndrew Geissler BMCWEB_LOG_ERROR("DBUS response error {}", ec); 348533e1f122SAndrew Geissler messages::internalError(asyncResp->res); 348633e1f122SAndrew Geissler return; 348733e1f122SAndrew Geissler } 348833e1f122SAndrew Geissler } 348933e1f122SAndrew Geissler else 349033e1f122SAndrew Geissler { 349133e1f122SAndrew Geissler for (const std::string& transition : allowedHostTransitions) 349233e1f122SAndrew Geissler { 349333e1f122SAndrew Geissler BMCWEB_LOG_DEBUG("Found allowed host tran {}", transition); 349433e1f122SAndrew Geissler dbusToRfAllowedHostTransitions(transition, allowableValues); 349533e1f122SAndrew Geissler } 349633e1f122SAndrew Geissler } 349733e1f122SAndrew Geissler 349833e1f122SAndrew Geissler nlohmann::json::object_t parameter; 349933e1f122SAndrew Geissler parameter["Name"] = "ResetType"; 350033e1f122SAndrew Geissler parameter["Required"] = true; 3501539d8c6bSEd Tanous parameter["DataType"] = action_info::ParameterTypes::String; 350233e1f122SAndrew Geissler parameter["AllowableValues"] = std::move(allowableValues); 350333e1f122SAndrew Geissler nlohmann::json::array_t parameters; 350433e1f122SAndrew Geissler parameters.emplace_back(std::move(parameter)); 350533e1f122SAndrew Geissler asyncResp->res.jsonValue["Parameters"] = std::move(parameters); 350633e1f122SAndrew Geissler } 350733e1f122SAndrew Geissler 3508*5e7c1f31SOliver Brewka inline void getAllowedHostTransitions( 3509*5e7c1f31SOliver Brewka const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 3510*5e7c1f31SOliver Brewka const uint64_t computerSystemIndex) 3511*5e7c1f31SOliver Brewka { 3512*5e7c1f31SOliver Brewka dbus::utility::getProperty<std::vector<std::string>>( 3513*5e7c1f31SOliver Brewka getHostStateServiceName(computerSystemIndex), 3514*5e7c1f31SOliver Brewka getHostStateObjectPath(computerSystemIndex), 3515*5e7c1f31SOliver Brewka "xyz.openbmc_project.State.Host", "AllowedHostTransitions", 3516*5e7c1f31SOliver Brewka std::bind_front(afterGetAllowedHostTransitions, asyncResp)); 3517*5e7c1f31SOliver Brewka } 3518*5e7c1f31SOliver Brewka 3519c1e219d5SEd Tanous inline void handleSystemCollectionResetActionGet( 3520c1e219d5SEd Tanous crow::App& app, const crow::Request& req, 352122d268cbSEd Tanous const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 3522c1e219d5SEd Tanous const std::string& systemName) 3523c1e219d5SEd Tanous { 35243ba00073SCarson Labrado if (!redfish::setUpRedfishRoute(app, req, asyncResp)) 352545ca1b86SEd Tanous { 352645ca1b86SEd Tanous return; 352745ca1b86SEd Tanous } 3528746b56f3SAsmitha Karunanithi 352968896206SGunnar Mills if constexpr (BMCWEB_HYPERVISOR_COMPUTER_SYSTEM) 353068896206SGunnar Mills { 3531746b56f3SAsmitha Karunanithi if (systemName == "hypervisor") 3532746b56f3SAsmitha Karunanithi { 3533746b56f3SAsmitha Karunanithi handleHypervisorResetActionGet(asyncResp); 3534746b56f3SAsmitha Karunanithi return; 3535746b56f3SAsmitha Karunanithi } 353668896206SGunnar Mills } 3537746b56f3SAsmitha Karunanithi 3538*5e7c1f31SOliver Brewka if constexpr (!BMCWEB_EXPERIMENTAL_REDFISH_MULTI_COMPUTER_SYSTEM) 3539*5e7c1f31SOliver Brewka { 3540253f11b8SEd Tanous if (systemName != BMCWEB_REDFISH_SYSTEM_URI_NAME) 354122d268cbSEd Tanous { 354222d268cbSEd Tanous messages::resourceNotFound(asyncResp->res, "ComputerSystem", 354322d268cbSEd Tanous systemName); 354422d268cbSEd Tanous return; 354522d268cbSEd Tanous } 3546*5e7c1f31SOliver Brewka } 354722d268cbSEd Tanous 3548dd60b9edSEd Tanous asyncResp->res.addHeader( 3549dd60b9edSEd Tanous boost::beast::http::field::link, 3550dd60b9edSEd Tanous "</redfish/v1/JsonSchemas/ActionInfo/ActionInfo.json>; rel=describedby"); 35511476687dSEd Tanous 3552*5e7c1f31SOliver Brewka asyncResp->res.jsonValue["@odata.id"] = boost::urls::format( 3553*5e7c1f31SOliver Brewka "/redfish/v1/Systems/{}/ResetActionInfo", systemName); 3554c1e219d5SEd Tanous asyncResp->res.jsonValue["@odata.type"] = "#ActionInfo.v1_1_2.ActionInfo"; 35551476687dSEd Tanous asyncResp->res.jsonValue["Name"] = "Reset Action Info"; 35561476687dSEd Tanous asyncResp->res.jsonValue["Id"] = "ResetActionInfo"; 35573215e700SNan Zhou 355833e1f122SAndrew Geissler // Look to see if system defines AllowedHostTransitions 3559*5e7c1f31SOliver Brewka getComputerSystemIndex( 3560*5e7c1f31SOliver Brewka asyncResp, systemName, 3561*5e7c1f31SOliver Brewka std::bind_front(getAllowedHostTransitions, asyncResp)); 3562c1e219d5SEd Tanous } 3563*5e7c1f31SOliver Brewka 3564c1e219d5SEd Tanous /** 3565c1e219d5SEd Tanous * SystemResetActionInfo derived class for delivering Computer Systems 3566c1e219d5SEd Tanous * ResetType AllowableValues using ResetInfo schema. 3567c1e219d5SEd Tanous */ 3568100afe56SEd Tanous inline void requestRoutesSystems(App& app) 3569c1e219d5SEd Tanous { 3570100afe56SEd Tanous BMCWEB_ROUTE(app, "/redfish/v1/Systems/") 3571100afe56SEd Tanous .privileges(redfish::privileges::headComputerSystemCollection) 3572100afe56SEd Tanous .methods(boost::beast::http::verb::head)( 3573100afe56SEd Tanous std::bind_front(handleComputerSystemCollectionHead, std::ref(app))); 3574100afe56SEd Tanous 3575100afe56SEd Tanous BMCWEB_ROUTE(app, "/redfish/v1/Systems/") 3576100afe56SEd Tanous .privileges(redfish::privileges::getComputerSystemCollection) 3577100afe56SEd Tanous .methods(boost::beast::http::verb::get)( 3578100afe56SEd Tanous std::bind_front(handleComputerSystemCollectionGet, std::ref(app))); 3579100afe56SEd Tanous 3580100afe56SEd Tanous BMCWEB_ROUTE(app, "/redfish/v1/Systems/<str>/") 3581100afe56SEd Tanous .privileges(redfish::privileges::headComputerSystem) 3582100afe56SEd Tanous .methods(boost::beast::http::verb::head)( 3583100afe56SEd Tanous std::bind_front(handleComputerSystemHead, std::ref(app))); 3584100afe56SEd Tanous 3585100afe56SEd Tanous BMCWEB_ROUTE(app, "/redfish/v1/Systems/<str>/") 3586100afe56SEd Tanous .privileges(redfish::privileges::getComputerSystem) 3587100afe56SEd Tanous .methods(boost::beast::http::verb::get)( 3588100afe56SEd Tanous std::bind_front(handleComputerSystemGet, std::ref(app))); 3589100afe56SEd Tanous 3590100afe56SEd Tanous BMCWEB_ROUTE(app, "/redfish/v1/Systems/<str>/") 3591100afe56SEd Tanous .privileges(redfish::privileges::patchComputerSystem) 3592100afe56SEd Tanous .methods(boost::beast::http::verb::patch)( 3593100afe56SEd Tanous std::bind_front(handleComputerSystemPatch, std::ref(app))); 3594100afe56SEd Tanous 3595100afe56SEd Tanous BMCWEB_ROUTE(app, "/redfish/v1/Systems/<str>/Actions/ComputerSystem.Reset/") 3596100afe56SEd Tanous .privileges(redfish::privileges::postComputerSystem) 3597100afe56SEd Tanous .methods(boost::beast::http::verb::post)(std::bind_front( 3598100afe56SEd Tanous handleComputerSystemResetActionPost, std::ref(app))); 3599100afe56SEd Tanous 3600c1e219d5SEd Tanous BMCWEB_ROUTE(app, "/redfish/v1/Systems/<str>/ResetActionInfo/") 3601c1e219d5SEd Tanous .privileges(redfish::privileges::headActionInfo) 3602c1e219d5SEd Tanous .methods(boost::beast::http::verb::head)(std::bind_front( 3603c1e219d5SEd Tanous handleSystemCollectionResetActionHead, std::ref(app))); 3604c1e219d5SEd Tanous BMCWEB_ROUTE(app, "/redfish/v1/Systems/<str>/ResetActionInfo/") 3605c1e219d5SEd Tanous .privileges(redfish::privileges::getActionInfo) 3606c1e219d5SEd Tanous .methods(boost::beast::http::verb::get)(std::bind_front( 3607c1e219d5SEd Tanous handleSystemCollectionResetActionGet, std::ref(app))); 36081cb1a9e6SAppaRao Puli } 3609c5b2abe0SLewanczyk, Dawid } // namespace redfish 3610