1c5b2abe0SLewanczyk, Dawid /* 2c5b2abe0SLewanczyk, Dawid // Copyright (c) 2018 Intel Corporation 3c5b2abe0SLewanczyk, Dawid // 4c5b2abe0SLewanczyk, Dawid // Licensed under the Apache License, Version 2.0 (the "License"); 5c5b2abe0SLewanczyk, Dawid // you may not use this file except in compliance with the License. 6c5b2abe0SLewanczyk, Dawid // You may obtain a copy of the License at 7c5b2abe0SLewanczyk, Dawid // 8c5b2abe0SLewanczyk, Dawid // http://www.apache.org/licenses/LICENSE-2.0 9c5b2abe0SLewanczyk, Dawid // 10c5b2abe0SLewanczyk, Dawid // Unless required by applicable law or agreed to in writing, software 11c5b2abe0SLewanczyk, Dawid // distributed under the License is distributed on an "AS IS" BASIS, 12c5b2abe0SLewanczyk, Dawid // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13c5b2abe0SLewanczyk, Dawid // See the License for the specific language governing permissions and 14c5b2abe0SLewanczyk, Dawid // limitations under the License. 15c5b2abe0SLewanczyk, Dawid */ 16c5b2abe0SLewanczyk, Dawid #pragma once 17c5b2abe0SLewanczyk, Dawid 1813451e39SWilly Tu #include "bmcweb_config.h" 1913451e39SWilly Tu 203ccb3adbSEd Tanous #include "app.hpp" 211e1e598dSJonathan Doman #include "dbus_singleton.hpp" 227a1dbc48SGeorge Liu #include "dbus_utility.hpp" 238d69c668SEd Tanous #include "generated/enums/computer_system.hpp" 2433e1f122SAndrew Geissler #include "generated/enums/resource.hpp" 25746b56f3SAsmitha Karunanithi #include "hypervisor_system.hpp" 261c8fba97SJames Feist #include "led.hpp" 27f4c99e70SEd Tanous #include "query.hpp" 28c5d03ff4SJennifer Lee #include "redfish_util.hpp" 293ccb3adbSEd Tanous #include "registries/privilege_registry.hpp" 303ccb3adbSEd Tanous #include "utils/dbus_utils.hpp" 313ccb3adbSEd Tanous #include "utils/json_utils.hpp" 32472bd202SLakshmi Yadlapati #include "utils/pcie_util.hpp" 333ccb3adbSEd Tanous #include "utils/sw_utils.hpp" 342b82937eSEd Tanous #include "utils/time_utils.hpp" 35c5d03ff4SJennifer Lee 36fc903b3dSAndrew Geissler #include <boost/asio/error.hpp> 379712f8acSEd Tanous #include <boost/container/flat_map.hpp> 38e99073f5SGeorge Liu #include <boost/system/error_code.hpp> 3933e1f122SAndrew Geissler #include <boost/system/linux_error.hpp> 40ef4c65b7SEd Tanous #include <boost/url/format.hpp> 411e1e598dSJonathan Doman #include <sdbusplus/asio/property.hpp> 42fc903b3dSAndrew Geissler #include <sdbusplus/message.hpp> 43bc1d29deSKrzysztof Grobelny #include <sdbusplus/unpack_properties.hpp> 441214b7e7SGunnar Mills 457a1dbc48SGeorge Liu #include <array> 4633e1f122SAndrew Geissler #include <memory> 476b9ac4f2SChris Cain #include <string> 487a1dbc48SGeorge Liu #include <string_view> 4920fa6a2cSEd Tanous #include <utility> 50abf2add6SEd Tanous #include <variant> 516b9ac4f2SChris Cain #include <vector> 52c5b2abe0SLewanczyk, Dawid 531abe55efSEd Tanous namespace redfish 541abe55efSEd Tanous { 55c5b2abe0SLewanczyk, Dawid 565c3e9272SAbhishek Patel const static std::array<std::pair<std::string_view, std::string_view>, 2> 575c3e9272SAbhishek Patel protocolToDBusForSystems{ 585c3e9272SAbhishek Patel {{"SSH", "obmc-console-ssh"}, {"IPMI", "phosphor-ipmi-net"}}}; 595c3e9272SAbhishek Patel 609d3ae10eSAlpana Kumari /** 619d3ae10eSAlpana Kumari * @brief Updates the Functional State of DIMMs 629d3ae10eSAlpana Kumari * 63ac106bf6SEd Tanous * @param[in] asyncResp Shared pointer for completing asynchronous calls 649d3ae10eSAlpana Kumari * @param[in] dimmState Dimm's Functional state, true/false 659d3ae10eSAlpana Kumari * 669d3ae10eSAlpana Kumari * @return None. 679d3ae10eSAlpana Kumari */ 688d1b46d7Szhanghch05 inline void 69ac106bf6SEd Tanous updateDimmProperties(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 701e1e598dSJonathan Doman bool isDimmFunctional) 719d3ae10eSAlpana Kumari { 7262598e31SEd Tanous BMCWEB_LOG_DEBUG("Dimm Functional: {}", isDimmFunctional); 739d3ae10eSAlpana Kumari 749d3ae10eSAlpana Kumari // Set it as Enabled if at least one DIMM is functional 759d3ae10eSAlpana Kumari // Update STATE only if previous State was DISABLED and current Dimm is 769d3ae10eSAlpana Kumari // ENABLED. 7702cad96eSEd Tanous const nlohmann::json& prevMemSummary = 78ac106bf6SEd Tanous asyncResp->res.jsonValue["MemorySummary"]["Status"]["State"]; 799d3ae10eSAlpana Kumari if (prevMemSummary == "Disabled") 809d3ae10eSAlpana Kumari { 81e05aec50SEd Tanous if (isDimmFunctional) 829d3ae10eSAlpana Kumari { 83ac106bf6SEd Tanous asyncResp->res.jsonValue["MemorySummary"]["Status"]["State"] = 849d3ae10eSAlpana Kumari "Enabled"; 859d3ae10eSAlpana Kumari } 869d3ae10eSAlpana Kumari } 879d3ae10eSAlpana Kumari } 889d3ae10eSAlpana Kumari 8957e8c9beSAlpana Kumari /* 9057e8c9beSAlpana Kumari * @brief Update "ProcessorSummary" "Status" "State" based on 9157e8c9beSAlpana Kumari * CPU Functional State 9257e8c9beSAlpana Kumari * 93ac106bf6SEd Tanous * @param[in] asyncResp Shared pointer for completing asynchronous calls 9457e8c9beSAlpana Kumari * @param[in] cpuFunctionalState is CPU functional true/false 9557e8c9beSAlpana Kumari * 9657e8c9beSAlpana Kumari * @return None. 9757e8c9beSAlpana Kumari */ 98ac106bf6SEd Tanous inline void modifyCpuFunctionalState( 99ac106bf6SEd Tanous const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, bool isCpuFunctional) 10057e8c9beSAlpana Kumari { 10162598e31SEd Tanous BMCWEB_LOG_DEBUG("Cpu Functional: {}", isCpuFunctional); 10257e8c9beSAlpana Kumari 10302cad96eSEd Tanous const nlohmann::json& prevProcState = 104ac106bf6SEd Tanous asyncResp->res.jsonValue["ProcessorSummary"]["Status"]["State"]; 10557e8c9beSAlpana Kumari 10657e8c9beSAlpana Kumari // Set it as Enabled if at least one CPU is functional 10757e8c9beSAlpana Kumari // Update STATE only if previous State was Non_Functional and current CPU is 10857e8c9beSAlpana Kumari // Functional. 10957e8c9beSAlpana Kumari if (prevProcState == "Disabled") 11057e8c9beSAlpana Kumari { 111e05aec50SEd Tanous if (isCpuFunctional) 11257e8c9beSAlpana Kumari { 113ac106bf6SEd Tanous asyncResp->res.jsonValue["ProcessorSummary"]["Status"]["State"] = 11457e8c9beSAlpana Kumari "Enabled"; 11557e8c9beSAlpana Kumari } 11657e8c9beSAlpana Kumari } 11757e8c9beSAlpana Kumari } 11857e8c9beSAlpana Kumari 119cf0e004cSNinad Palsule /* 120cf0e004cSNinad Palsule * @brief Update "ProcessorSummary" "Count" based on Cpu PresenceState 121cf0e004cSNinad Palsule * 122ac106bf6SEd Tanous * @param[in] asyncResp Shared pointer for completing asynchronous calls 123cf0e004cSNinad Palsule * @param[in] cpuPresenceState CPU present or not 124cf0e004cSNinad Palsule * 125cf0e004cSNinad Palsule * @return None. 126cf0e004cSNinad Palsule */ 127cf0e004cSNinad Palsule inline void 128ac106bf6SEd Tanous modifyCpuPresenceState(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 129cf0e004cSNinad Palsule bool isCpuPresent) 130cf0e004cSNinad Palsule { 13162598e31SEd Tanous BMCWEB_LOG_DEBUG("Cpu Present: {}", isCpuPresent); 132cf0e004cSNinad Palsule 133cf0e004cSNinad Palsule if (isCpuPresent) 134cf0e004cSNinad Palsule { 135cf0e004cSNinad Palsule nlohmann::json& procCount = 136ac106bf6SEd Tanous asyncResp->res.jsonValue["ProcessorSummary"]["Count"]; 137cf0e004cSNinad Palsule auto* procCountPtr = 138cf0e004cSNinad Palsule procCount.get_ptr<nlohmann::json::number_integer_t*>(); 139cf0e004cSNinad Palsule if (procCountPtr != nullptr) 140cf0e004cSNinad Palsule { 141cf0e004cSNinad Palsule // shouldn't be possible to be nullptr 142cf0e004cSNinad Palsule *procCountPtr += 1; 143cf0e004cSNinad Palsule } 144cf0e004cSNinad Palsule } 145cf0e004cSNinad Palsule } 146cf0e004cSNinad Palsule 147382d6475SAli Ahmed inline void getProcessorProperties( 148ac106bf6SEd Tanous const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 149382d6475SAli Ahmed const std::vector<std::pair<std::string, dbus::utility::DbusVariantType>>& 150382d6475SAli Ahmed properties) 15103fbed92SAli Ahmed { 15262598e31SEd Tanous BMCWEB_LOG_DEBUG("Got {} Cpu properties.", properties.size()); 15303fbed92SAli Ahmed 15403fbed92SAli Ahmed // TODO: Get Model 15503fbed92SAli Ahmed 156bc1d29deSKrzysztof Grobelny const uint16_t* coreCount = nullptr; 15703fbed92SAli Ahmed 158bc1d29deSKrzysztof Grobelny const bool success = sdbusplus::unpackPropertiesNoThrow( 159bc1d29deSKrzysztof Grobelny dbus_utils::UnpackErrorPrinter(), properties, "CoreCount", coreCount); 16003fbed92SAli Ahmed 161bc1d29deSKrzysztof Grobelny if (!success) 16203fbed92SAli Ahmed { 163ac106bf6SEd Tanous messages::internalError(asyncResp->res); 16403fbed92SAli Ahmed return; 16503fbed92SAli Ahmed } 16603fbed92SAli Ahmed 167bc1d29deSKrzysztof Grobelny if (coreCount != nullptr) 16803fbed92SAli Ahmed { 169bc1d29deSKrzysztof Grobelny nlohmann::json& coreCountJson = 170ac106bf6SEd Tanous asyncResp->res.jsonValue["ProcessorSummary"]["CoreCount"]; 171bc1d29deSKrzysztof Grobelny uint64_t* coreCountJsonPtr = coreCountJson.get_ptr<uint64_t*>(); 172bc1d29deSKrzysztof Grobelny 173bc1d29deSKrzysztof Grobelny if (coreCountJsonPtr == nullptr) 174bc1d29deSKrzysztof Grobelny { 175bc1d29deSKrzysztof Grobelny coreCountJson = *coreCount; 17603fbed92SAli Ahmed } 17703fbed92SAli Ahmed else 17803fbed92SAli Ahmed { 179bc1d29deSKrzysztof Grobelny *coreCountJsonPtr += *coreCount; 18003fbed92SAli Ahmed } 18103fbed92SAli Ahmed } 18203fbed92SAli Ahmed } 18303fbed92SAli Ahmed 18403fbed92SAli Ahmed /* 18503fbed92SAli Ahmed * @brief Get ProcessorSummary fields 18603fbed92SAli Ahmed * 187ac106bf6SEd Tanous * @param[in] asyncResp Shared pointer for completing asynchronous calls 18803fbed92SAli Ahmed * @param[in] service dbus service for Cpu Information 18903fbed92SAli Ahmed * @param[in] path dbus path for Cpu 19003fbed92SAli Ahmed * 19103fbed92SAli Ahmed * @return None. 19203fbed92SAli Ahmed */ 193ac106bf6SEd Tanous inline void 194ac106bf6SEd Tanous getProcessorSummary(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 195ac106bf6SEd Tanous const std::string& service, const std::string& path) 19603fbed92SAli Ahmed { 197ac106bf6SEd Tanous auto getCpuPresenceState = [asyncResp](const boost::system::error_code& ec3, 198382d6475SAli Ahmed const bool cpuPresenceCheck) { 199382d6475SAli Ahmed if (ec3) 200382d6475SAli Ahmed { 20162598e31SEd Tanous BMCWEB_LOG_ERROR("DBUS response error {}", ec3); 202382d6475SAli Ahmed return; 203382d6475SAli Ahmed } 204ac106bf6SEd Tanous modifyCpuPresenceState(asyncResp, cpuPresenceCheck); 205382d6475SAli Ahmed }; 206382d6475SAli Ahmed 207cf0e004cSNinad Palsule // Get the Presence of CPU 208cf0e004cSNinad Palsule sdbusplus::asio::getProperty<bool>( 209cf0e004cSNinad Palsule *crow::connections::systemBus, service, path, 210cf0e004cSNinad Palsule "xyz.openbmc_project.Inventory.Item", "Present", 211cf0e004cSNinad Palsule std::move(getCpuPresenceState)); 212cf0e004cSNinad Palsule 213bc1d29deSKrzysztof Grobelny sdbusplus::asio::getAllProperties( 214bc1d29deSKrzysztof Grobelny *crow::connections::systemBus, service, path, 215bc1d29deSKrzysztof Grobelny "xyz.openbmc_project.Inventory.Item.Cpu", 216ac106bf6SEd Tanous [asyncResp, service, 2175e7e2dc5SEd Tanous path](const boost::system::error_code& ec2, 218b9d36b47SEd Tanous const dbus::utility::DBusPropertiesMap& properties) { 21903fbed92SAli Ahmed if (ec2) 22003fbed92SAli Ahmed { 22162598e31SEd Tanous BMCWEB_LOG_ERROR("DBUS response error {}", ec2); 222ac106bf6SEd Tanous messages::internalError(asyncResp->res); 22303fbed92SAli Ahmed return; 22403fbed92SAli Ahmed } 225ac106bf6SEd Tanous getProcessorProperties(asyncResp, properties); 226bc1d29deSKrzysztof Grobelny }); 22703fbed92SAli Ahmed } 22803fbed92SAli Ahmed 22957e8c9beSAlpana Kumari /* 230cf0e004cSNinad Palsule * @brief processMemoryProperties fields 231cf0e004cSNinad Palsule * 232ac106bf6SEd Tanous * @param[in] asyncResp Shared pointer for completing asynchronous calls 233cf0e004cSNinad Palsule * @param[in] DBUS properties for memory 234cf0e004cSNinad Palsule * 235cf0e004cSNinad Palsule * @return None. 236cf0e004cSNinad Palsule */ 237cf0e004cSNinad Palsule inline void 238ac106bf6SEd Tanous processMemoryProperties(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 239cf0e004cSNinad Palsule const dbus::utility::DBusPropertiesMap& properties) 240cf0e004cSNinad Palsule { 24162598e31SEd Tanous BMCWEB_LOG_DEBUG("Got {} Dimm properties.", properties.size()); 242cf0e004cSNinad Palsule 243cf0e004cSNinad Palsule if (properties.empty()) 244cf0e004cSNinad Palsule { 245cf0e004cSNinad Palsule return; 246cf0e004cSNinad Palsule } 247cf0e004cSNinad Palsule 248cf0e004cSNinad Palsule const size_t* memorySizeInKB = nullptr; 249cf0e004cSNinad Palsule 250cf0e004cSNinad Palsule const bool success = sdbusplus::unpackPropertiesNoThrow( 251cf0e004cSNinad Palsule dbus_utils::UnpackErrorPrinter(), properties, "MemorySizeInKB", 252cf0e004cSNinad Palsule memorySizeInKB); 253cf0e004cSNinad Palsule 254cf0e004cSNinad Palsule if (!success) 255cf0e004cSNinad Palsule { 256ac106bf6SEd Tanous messages::internalError(asyncResp->res); 257cf0e004cSNinad Palsule return; 258cf0e004cSNinad Palsule } 259cf0e004cSNinad Palsule 260cf0e004cSNinad Palsule if (memorySizeInKB != nullptr) 261cf0e004cSNinad Palsule { 262cf0e004cSNinad Palsule nlohmann::json& totalMemory = 263ac106bf6SEd Tanous asyncResp->res.jsonValue["MemorySummary"]["TotalSystemMemoryGiB"]; 264dfb2b408SPriyanga Ramasamy const double* preValue = totalMemory.get_ptr<const double*>(); 265cf0e004cSNinad Palsule if (preValue == nullptr) 266cf0e004cSNinad Palsule { 267ac106bf6SEd Tanous asyncResp->res.jsonValue["MemorySummary"]["TotalSystemMemoryGiB"] = 268dfb2b408SPriyanga Ramasamy static_cast<double>(*memorySizeInKB) / (1024 * 1024); 269cf0e004cSNinad Palsule } 270cf0e004cSNinad Palsule else 271cf0e004cSNinad Palsule { 272ac106bf6SEd Tanous asyncResp->res.jsonValue["MemorySummary"]["TotalSystemMemoryGiB"] = 273dfb2b408SPriyanga Ramasamy static_cast<double>(*memorySizeInKB) / (1024 * 1024) + 274dfb2b408SPriyanga Ramasamy *preValue; 275cf0e004cSNinad Palsule } 276cf0e004cSNinad Palsule } 277cf0e004cSNinad Palsule } 278cf0e004cSNinad Palsule 279cf0e004cSNinad Palsule /* 280cf0e004cSNinad Palsule * @brief Get getMemorySummary fields 281cf0e004cSNinad Palsule * 282ac106bf6SEd Tanous * @param[in] asyncResp Shared pointer for completing asynchronous calls 283cf0e004cSNinad Palsule * @param[in] service dbus service for memory Information 284cf0e004cSNinad Palsule * @param[in] path dbus path for memory 285cf0e004cSNinad Palsule * 286cf0e004cSNinad Palsule * @return None. 287cf0e004cSNinad Palsule */ 288ac106bf6SEd Tanous inline void 289ac106bf6SEd Tanous getMemorySummary(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 290ac106bf6SEd Tanous const std::string& service, const std::string& path) 291cf0e004cSNinad Palsule { 292cf0e004cSNinad Palsule sdbusplus::asio::getAllProperties( 293cf0e004cSNinad Palsule *crow::connections::systemBus, service, path, 294cf0e004cSNinad Palsule "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 346a974c132SLakshmi Yadlapati inline void 347a974c132SLakshmi Yadlapati afterGetInventory(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 406a974c132SLakshmi Yadlapati inline void 407a974c132SLakshmi Yadlapati afterGetAssetTag(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 408a974c132SLakshmi Yadlapati const boost::system::error_code& ec, 409a974c132SLakshmi Yadlapati const std::string& value) 410a974c132SLakshmi Yadlapati { 411a974c132SLakshmi Yadlapati if (ec) 412a974c132SLakshmi Yadlapati { 413a974c132SLakshmi Yadlapati // doesn't have to include this 414a974c132SLakshmi Yadlapati // interface 415a974c132SLakshmi Yadlapati return; 416a974c132SLakshmi Yadlapati } 417a974c132SLakshmi Yadlapati 418a974c132SLakshmi Yadlapati asyncResp->res.jsonValue["AssetTag"] = value; 419a974c132SLakshmi Yadlapati } 420a974c132SLakshmi Yadlapati 421a974c132SLakshmi Yadlapati inline void afterSystemGetSubTree( 422a974c132SLakshmi Yadlapati const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 423a974c132SLakshmi Yadlapati const boost::system::error_code& ec, 424a974c132SLakshmi Yadlapati const dbus::utility::MapperGetSubTreeResponse& subtree) 425a974c132SLakshmi Yadlapati { 4261abe55efSEd Tanous if (ec) 4271abe55efSEd Tanous { 428b3e86cb0SGunnar Mills BMCWEB_LOG_ERROR("DBUS response error {}", ec); 429ac106bf6SEd Tanous messages::internalError(asyncResp->res); 430c5b2abe0SLewanczyk, Dawid return; 431c5b2abe0SLewanczyk, Dawid } 432c5b2abe0SLewanczyk, Dawid // Iterate over all retrieved ObjectPaths. 433002d39b4SEd Tanous for (const std::pair< 434002d39b4SEd Tanous std::string, 435002d39b4SEd Tanous std::vector<std::pair<std::string, std::vector<std::string>>>>& 4361214b7e7SGunnar Mills object : subtree) 4371abe55efSEd Tanous { 438c5b2abe0SLewanczyk, Dawid const std::string& path = object.first; 43962598e31SEd Tanous BMCWEB_LOG_DEBUG("Got path: {}", path); 440002d39b4SEd Tanous const std::vector<std::pair<std::string, std::vector<std::string>>>& 4411214b7e7SGunnar Mills connectionNames = object.second; 44226f6976fSEd Tanous if (connectionNames.empty()) 4431abe55efSEd Tanous { 444c5b2abe0SLewanczyk, Dawid continue; 445c5b2abe0SLewanczyk, Dawid } 446029573d4SEd Tanous 4476c34de48SEd Tanous // This is not system, so check if it's cpu, dimm, UUID or 4486c34de48SEd Tanous // BiosVer 44904a258f4SEd Tanous for (const auto& connection : connectionNames) 4501abe55efSEd Tanous { 45104a258f4SEd Tanous for (const auto& interfaceName : connection.second) 4521abe55efSEd Tanous { 453a974c132SLakshmi Yadlapati if (interfaceName == "xyz.openbmc_project.Inventory.Item.Dimm") 4541abe55efSEd Tanous { 45562598e31SEd Tanous BMCWEB_LOG_DEBUG("Found Dimm, now get its properties."); 4569d3ae10eSAlpana Kumari 457ac106bf6SEd Tanous getMemorySummary(asyncResp, connection.first, path); 4585fd0aafbSNinad Palsule } 45904a258f4SEd Tanous else if (interfaceName == 46004a258f4SEd Tanous "xyz.openbmc_project.Inventory.Item.Cpu") 4611abe55efSEd Tanous { 46262598e31SEd Tanous BMCWEB_LOG_DEBUG("Found Cpu, now get its properties."); 46357e8c9beSAlpana Kumari 464ac106bf6SEd Tanous getProcessorSummary(asyncResp, connection.first, path); 4655fd0aafbSNinad Palsule } 466002d39b4SEd Tanous else if (interfaceName == "xyz.openbmc_project.Common.UUID") 4671abe55efSEd Tanous { 46862598e31SEd Tanous BMCWEB_LOG_DEBUG("Found UUID, now get its properties."); 469bc1d29deSKrzysztof Grobelny 470bc1d29deSKrzysztof Grobelny sdbusplus::asio::getAllProperties( 471a974c132SLakshmi Yadlapati *crow::connections::systemBus, connection.first, path, 472a974c132SLakshmi Yadlapati "xyz.openbmc_project.Common.UUID", 473ac106bf6SEd Tanous [asyncResp](const boost::system::error_code& ec3, 474b9d36b47SEd Tanous const dbus::utility::DBusPropertiesMap& 4751214b7e7SGunnar Mills properties) { 476a974c132SLakshmi Yadlapati afterGetUUID(asyncResp, ec3, properties); 477bc1d29deSKrzysztof Grobelny }); 478c5b2abe0SLewanczyk, Dawid } 479029573d4SEd Tanous else if (interfaceName == 480029573d4SEd Tanous "xyz.openbmc_project.Inventory.Item.System") 4811abe55efSEd Tanous { 482bc1d29deSKrzysztof Grobelny sdbusplus::asio::getAllProperties( 483a974c132SLakshmi Yadlapati *crow::connections::systemBus, connection.first, path, 484bc1d29deSKrzysztof Grobelny "xyz.openbmc_project.Inventory.Decorator.Asset", 485a974c132SLakshmi Yadlapati [asyncResp](const boost::system::error_code& ec3, 486b9d36b47SEd Tanous const dbus::utility::DBusPropertiesMap& 487a974c132SLakshmi Yadlapati properties) { 488a974c132SLakshmi Yadlapati afterGetInventory(asyncResp, ec3, properties); 489bc1d29deSKrzysztof Grobelny }); 490e4a4b9a9SJames Feist 4911e1e598dSJonathan Doman sdbusplus::asio::getProperty<std::string>( 492a974c132SLakshmi Yadlapati *crow::connections::systemBus, connection.first, path, 4931e1e598dSJonathan Doman "xyz.openbmc_project.Inventory.Decorator." 4941e1e598dSJonathan Doman "AssetTag", 4951e1e598dSJonathan Doman "AssetTag", 496a974c132SLakshmi Yadlapati std::bind_front(afterGetAssetTag, asyncResp)); 497a974c132SLakshmi Yadlapati } 498a974c132SLakshmi Yadlapati } 499a974c132SLakshmi Yadlapati } 500a974c132SLakshmi Yadlapati } 501a974c132SLakshmi Yadlapati } 502a974c132SLakshmi Yadlapati 503a974c132SLakshmi Yadlapati /* 504a974c132SLakshmi Yadlapati * @brief Retrieves computer system properties over dbus 505a974c132SLakshmi Yadlapati * 506a974c132SLakshmi Yadlapati * @param[in] asyncResp Shared pointer for completing asynchronous calls 507a974c132SLakshmi Yadlapati * 508a974c132SLakshmi Yadlapati * @return None. 509a974c132SLakshmi Yadlapati */ 510a974c132SLakshmi Yadlapati inline void 51151bd2d8aSGunnar Mills getComputerSystem(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) 512e4a4b9a9SJames Feist { 513a974c132SLakshmi Yadlapati BMCWEB_LOG_DEBUG("Get available system components."); 514a974c132SLakshmi Yadlapati constexpr std::array<std::string_view, 5> interfaces = { 515a974c132SLakshmi Yadlapati "xyz.openbmc_project.Inventory.Decorator.Asset", 516a974c132SLakshmi Yadlapati "xyz.openbmc_project.Inventory.Item.Cpu", 517a974c132SLakshmi Yadlapati "xyz.openbmc_project.Inventory.Item.Dimm", 518a974c132SLakshmi Yadlapati "xyz.openbmc_project.Inventory.Item.System", 519a974c132SLakshmi Yadlapati "xyz.openbmc_project.Common.UUID", 520a974c132SLakshmi Yadlapati }; 521a974c132SLakshmi Yadlapati dbus::utility::getSubTree( 522a974c132SLakshmi Yadlapati "/xyz/openbmc_project/inventory", 0, interfaces, 52351bd2d8aSGunnar Mills std::bind_front(afterSystemGetSubTree, asyncResp)); 524c5b2abe0SLewanczyk, Dawid } 525c5b2abe0SLewanczyk, Dawid 526c5b2abe0SLewanczyk, Dawid /** 527c5b2abe0SLewanczyk, Dawid * @brief Retrieves host state properties over dbus 528c5b2abe0SLewanczyk, Dawid * 529ac106bf6SEd Tanous * @param[in] asyncResp Shared pointer for completing asynchronous calls. 530c5b2abe0SLewanczyk, Dawid * 531c5b2abe0SLewanczyk, Dawid * @return None. 532c5b2abe0SLewanczyk, Dawid */ 533ac106bf6SEd Tanous inline void getHostState(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) 5341abe55efSEd Tanous { 53562598e31SEd Tanous BMCWEB_LOG_DEBUG("Get host information."); 5361e1e598dSJonathan Doman sdbusplus::asio::getProperty<std::string>( 5371e1e598dSJonathan Doman *crow::connections::systemBus, "xyz.openbmc_project.State.Host", 5381e1e598dSJonathan Doman "/xyz/openbmc_project/state/host0", "xyz.openbmc_project.State.Host", 5391e1e598dSJonathan Doman "CurrentHostState", 540ac106bf6SEd Tanous [asyncResp](const boost::system::error_code& ec, 5411e1e598dSJonathan Doman const std::string& hostState) { 5421abe55efSEd Tanous if (ec) 5431abe55efSEd Tanous { 54422228c28SAndrew Geissler if (ec == boost::system::errc::host_unreachable) 54522228c28SAndrew Geissler { 54622228c28SAndrew Geissler // Service not available, no error, just don't return 54722228c28SAndrew Geissler // host state info 54862598e31SEd Tanous BMCWEB_LOG_DEBUG("Service not available {}", ec); 54922228c28SAndrew Geissler return; 55022228c28SAndrew Geissler } 55162598e31SEd Tanous BMCWEB_LOG_ERROR("DBUS response error {}", ec); 552ac106bf6SEd Tanous messages::internalError(asyncResp->res); 553c5b2abe0SLewanczyk, Dawid return; 554c5b2abe0SLewanczyk, Dawid } 5556617338dSEd Tanous 55662598e31SEd Tanous BMCWEB_LOG_DEBUG("Host state: {}", hostState); 557c5b2abe0SLewanczyk, Dawid // Verify Host State 5581e1e598dSJonathan Doman if (hostState == "xyz.openbmc_project.State.Host.HostState.Running") 5591abe55efSEd Tanous { 560ac106bf6SEd Tanous asyncResp->res.jsonValue["PowerState"] = "On"; 561ac106bf6SEd Tanous asyncResp->res.jsonValue["Status"]["State"] = "Enabled"; 5621abe55efSEd Tanous } 5631e1e598dSJonathan Doman else if (hostState == 5640fda0f12SGeorge Liu "xyz.openbmc_project.State.Host.HostState.Quiesced") 5658c888608SGunnar Mills { 566ac106bf6SEd Tanous asyncResp->res.jsonValue["PowerState"] = "On"; 567ac106bf6SEd Tanous asyncResp->res.jsonValue["Status"]["State"] = "Quiesced"; 5688c888608SGunnar Mills } 5691e1e598dSJonathan Doman else if (hostState == 5700fda0f12SGeorge Liu "xyz.openbmc_project.State.Host.HostState.DiagnosticMode") 57183935af9SAndrew Geissler { 572ac106bf6SEd Tanous asyncResp->res.jsonValue["PowerState"] = "On"; 573ac106bf6SEd Tanous asyncResp->res.jsonValue["Status"]["State"] = "InTest"; 57483935af9SAndrew Geissler } 5750fda0f12SGeorge Liu else if ( 5761e1e598dSJonathan Doman hostState == 5770fda0f12SGeorge Liu "xyz.openbmc_project.State.Host.HostState.TransitioningToRunning") 5781a2a1437SAndrew Geissler { 579ac106bf6SEd Tanous asyncResp->res.jsonValue["PowerState"] = "PoweringOn"; 580ac106bf6SEd Tanous asyncResp->res.jsonValue["Status"]["State"] = "Starting"; 5811a2a1437SAndrew Geissler } 582002d39b4SEd Tanous else if (hostState == 5830fda0f12SGeorge Liu "xyz.openbmc_project.State.Host.HostState.TransitioningToOff") 5841a2a1437SAndrew Geissler { 585ac106bf6SEd Tanous asyncResp->res.jsonValue["PowerState"] = "PoweringOff"; 586ac106bf6SEd Tanous asyncResp->res.jsonValue["Status"]["State"] = "Disabled"; 5871a2a1437SAndrew Geissler } 5881abe55efSEd Tanous else 5891abe55efSEd Tanous { 590ac106bf6SEd Tanous asyncResp->res.jsonValue["PowerState"] = "Off"; 591ac106bf6SEd Tanous asyncResp->res.jsonValue["Status"]["State"] = "Disabled"; 592c5b2abe0SLewanczyk, Dawid } 5931e1e598dSJonathan Doman }); 594c5b2abe0SLewanczyk, Dawid } 595c5b2abe0SLewanczyk, Dawid 596c5b2abe0SLewanczyk, Dawid /** 597786d0f60SGunnar Mills * @brief Translates boot source DBUS property value to redfish. 598491d8ee7SSantosh Puranik * 599491d8ee7SSantosh Puranik * @param[in] dbusSource The boot source in DBUS speak. 600491d8ee7SSantosh Puranik * 601491d8ee7SSantosh Puranik * @return Returns as a string, the boot source in Redfish terms. If translation 602491d8ee7SSantosh Puranik * cannot be done, returns an empty string. 603491d8ee7SSantosh Puranik */ 60423a21a1cSEd Tanous inline std::string dbusToRfBootSource(const std::string& dbusSource) 605491d8ee7SSantosh Puranik { 606491d8ee7SSantosh Puranik if (dbusSource == "xyz.openbmc_project.Control.Boot.Source.Sources.Default") 607491d8ee7SSantosh Puranik { 608491d8ee7SSantosh Puranik return "None"; 609491d8ee7SSantosh Puranik } 6103174e4dfSEd Tanous if (dbusSource == "xyz.openbmc_project.Control.Boot.Source.Sources.Disk") 611491d8ee7SSantosh Puranik { 612491d8ee7SSantosh Puranik return "Hdd"; 613491d8ee7SSantosh Puranik } 6143174e4dfSEd Tanous if (dbusSource == 615a71dc0b7SSantosh Puranik "xyz.openbmc_project.Control.Boot.Source.Sources.ExternalMedia") 616491d8ee7SSantosh Puranik { 617491d8ee7SSantosh Puranik return "Cd"; 618491d8ee7SSantosh Puranik } 6193174e4dfSEd Tanous if (dbusSource == "xyz.openbmc_project.Control.Boot.Source.Sources.Network") 620491d8ee7SSantosh Puranik { 621491d8ee7SSantosh Puranik return "Pxe"; 622491d8ee7SSantosh Puranik } 6233174e4dfSEd Tanous if (dbusSource == 624944ffaf9SJohnathan Mantey "xyz.openbmc_project.Control.Boot.Source.Sources.RemovableMedia") 6259f16b2c1SJennifer Lee { 6269f16b2c1SJennifer Lee return "Usb"; 6279f16b2c1SJennifer Lee } 628491d8ee7SSantosh Puranik return ""; 629491d8ee7SSantosh Puranik } 630491d8ee7SSantosh Puranik 631491d8ee7SSantosh Puranik /** 632cd9a4666SKonstantin Aladyshev * @brief Translates boot type DBUS property value to redfish. 633cd9a4666SKonstantin Aladyshev * 634cd9a4666SKonstantin Aladyshev * @param[in] dbusType The boot type in DBUS speak. 635cd9a4666SKonstantin Aladyshev * 636cd9a4666SKonstantin Aladyshev * @return Returns as a string, the boot type in Redfish terms. If translation 637cd9a4666SKonstantin Aladyshev * cannot be done, returns an empty string. 638cd9a4666SKonstantin Aladyshev */ 639cd9a4666SKonstantin Aladyshev inline std::string dbusToRfBootType(const std::string& dbusType) 640cd9a4666SKonstantin Aladyshev { 641cd9a4666SKonstantin Aladyshev if (dbusType == "xyz.openbmc_project.Control.Boot.Type.Types.Legacy") 642cd9a4666SKonstantin Aladyshev { 643cd9a4666SKonstantin Aladyshev return "Legacy"; 644cd9a4666SKonstantin Aladyshev } 645cd9a4666SKonstantin Aladyshev if (dbusType == "xyz.openbmc_project.Control.Boot.Type.Types.EFI") 646cd9a4666SKonstantin Aladyshev { 647cd9a4666SKonstantin Aladyshev return "UEFI"; 648cd9a4666SKonstantin Aladyshev } 649cd9a4666SKonstantin Aladyshev return ""; 650cd9a4666SKonstantin Aladyshev } 651cd9a4666SKonstantin Aladyshev 652cd9a4666SKonstantin Aladyshev /** 653786d0f60SGunnar Mills * @brief Translates boot mode DBUS property value to redfish. 654491d8ee7SSantosh Puranik * 655491d8ee7SSantosh Puranik * @param[in] dbusMode The boot mode in DBUS speak. 656491d8ee7SSantosh Puranik * 657491d8ee7SSantosh Puranik * @return Returns as a string, the boot mode in Redfish terms. If translation 658491d8ee7SSantosh Puranik * cannot be done, returns an empty string. 659491d8ee7SSantosh Puranik */ 66023a21a1cSEd Tanous inline std::string dbusToRfBootMode(const std::string& dbusMode) 661491d8ee7SSantosh Puranik { 662491d8ee7SSantosh Puranik if (dbusMode == "xyz.openbmc_project.Control.Boot.Mode.Modes.Regular") 663491d8ee7SSantosh Puranik { 664491d8ee7SSantosh Puranik return "None"; 665491d8ee7SSantosh Puranik } 6663174e4dfSEd Tanous if (dbusMode == "xyz.openbmc_project.Control.Boot.Mode.Modes.Safe") 667491d8ee7SSantosh Puranik { 668491d8ee7SSantosh Puranik return "Diags"; 669491d8ee7SSantosh Puranik } 6703174e4dfSEd Tanous if (dbusMode == "xyz.openbmc_project.Control.Boot.Mode.Modes.Setup") 671491d8ee7SSantosh Puranik { 672491d8ee7SSantosh Puranik return "BiosSetup"; 673491d8ee7SSantosh Puranik } 674491d8ee7SSantosh Puranik return ""; 675491d8ee7SSantosh Puranik } 676491d8ee7SSantosh Puranik 677491d8ee7SSantosh Puranik /** 678e43914b3SAndrew Geissler * @brief Translates boot progress DBUS property value to redfish. 679e43914b3SAndrew Geissler * 680e43914b3SAndrew Geissler * @param[in] dbusBootProgress The boot progress in DBUS speak. 681e43914b3SAndrew Geissler * 682e43914b3SAndrew Geissler * @return Returns as a string, the boot progress in Redfish terms. If 683e43914b3SAndrew Geissler * translation cannot be done, returns "None". 684e43914b3SAndrew Geissler */ 685e43914b3SAndrew Geissler inline std::string dbusToRfBootProgress(const std::string& dbusBootProgress) 686e43914b3SAndrew Geissler { 687e43914b3SAndrew Geissler // Now convert the D-Bus BootProgress to the appropriate Redfish 688e43914b3SAndrew Geissler // enum 689e43914b3SAndrew Geissler std::string rfBpLastState = "None"; 690e43914b3SAndrew Geissler if (dbusBootProgress == "xyz.openbmc_project.State.Boot.Progress." 691e43914b3SAndrew Geissler "ProgressStages.Unspecified") 692e43914b3SAndrew Geissler { 693e43914b3SAndrew Geissler rfBpLastState = "None"; 694e43914b3SAndrew Geissler } 695e43914b3SAndrew Geissler else if (dbusBootProgress == 696e43914b3SAndrew Geissler "xyz.openbmc_project.State.Boot.Progress.ProgressStages." 697e43914b3SAndrew Geissler "PrimaryProcInit") 698e43914b3SAndrew Geissler { 699e43914b3SAndrew Geissler rfBpLastState = "PrimaryProcessorInitializationStarted"; 700e43914b3SAndrew Geissler } 701e43914b3SAndrew Geissler else if (dbusBootProgress == 702e43914b3SAndrew Geissler "xyz.openbmc_project.State.Boot.Progress.ProgressStages." 703e43914b3SAndrew Geissler "BusInit") 704e43914b3SAndrew Geissler { 705e43914b3SAndrew Geissler rfBpLastState = "BusInitializationStarted"; 706e43914b3SAndrew Geissler } 707e43914b3SAndrew Geissler else if (dbusBootProgress == 708e43914b3SAndrew Geissler "xyz.openbmc_project.State.Boot.Progress.ProgressStages." 709e43914b3SAndrew Geissler "MemoryInit") 710e43914b3SAndrew Geissler { 711e43914b3SAndrew Geissler rfBpLastState = "MemoryInitializationStarted"; 712e43914b3SAndrew Geissler } 713e43914b3SAndrew Geissler else if (dbusBootProgress == 714e43914b3SAndrew Geissler "xyz.openbmc_project.State.Boot.Progress.ProgressStages." 715e43914b3SAndrew Geissler "SecondaryProcInit") 716e43914b3SAndrew Geissler { 717e43914b3SAndrew Geissler rfBpLastState = "SecondaryProcessorInitializationStarted"; 718e43914b3SAndrew Geissler } 719e43914b3SAndrew Geissler else if (dbusBootProgress == 720e43914b3SAndrew Geissler "xyz.openbmc_project.State.Boot.Progress.ProgressStages." 721e43914b3SAndrew Geissler "PCIInit") 722e43914b3SAndrew Geissler { 723e43914b3SAndrew Geissler rfBpLastState = "PCIResourceConfigStarted"; 724e43914b3SAndrew Geissler } 725e43914b3SAndrew Geissler else if (dbusBootProgress == 726e43914b3SAndrew Geissler "xyz.openbmc_project.State.Boot.Progress.ProgressStages." 727e43914b3SAndrew Geissler "SystemSetup") 728e43914b3SAndrew Geissler { 729e43914b3SAndrew Geissler rfBpLastState = "SetupEntered"; 730e43914b3SAndrew Geissler } 731e43914b3SAndrew Geissler else if (dbusBootProgress == 732e43914b3SAndrew Geissler "xyz.openbmc_project.State.Boot.Progress.ProgressStages." 733e43914b3SAndrew Geissler "SystemInitComplete") 734e43914b3SAndrew Geissler { 735e43914b3SAndrew Geissler rfBpLastState = "SystemHardwareInitializationComplete"; 736e43914b3SAndrew Geissler } 737e43914b3SAndrew Geissler else if (dbusBootProgress == 738e43914b3SAndrew Geissler "xyz.openbmc_project.State.Boot.Progress.ProgressStages." 739e43914b3SAndrew Geissler "OSStart") 740e43914b3SAndrew Geissler { 741e43914b3SAndrew Geissler rfBpLastState = "OSBootStarted"; 742e43914b3SAndrew Geissler } 743e43914b3SAndrew Geissler else if (dbusBootProgress == 744e43914b3SAndrew Geissler "xyz.openbmc_project.State.Boot.Progress.ProgressStages." 745e43914b3SAndrew Geissler "OSRunning") 746e43914b3SAndrew Geissler { 747e43914b3SAndrew Geissler rfBpLastState = "OSRunning"; 748e43914b3SAndrew Geissler } 749e43914b3SAndrew Geissler else 750e43914b3SAndrew Geissler { 75162598e31SEd Tanous BMCWEB_LOG_DEBUG("Unsupported D-Bus BootProgress {}", dbusBootProgress); 752e43914b3SAndrew Geissler // Just return the default 753e43914b3SAndrew Geissler } 754e43914b3SAndrew Geissler return rfBpLastState; 755e43914b3SAndrew Geissler } 756e43914b3SAndrew Geissler 757e43914b3SAndrew Geissler /** 758786d0f60SGunnar Mills * @brief Translates boot source from Redfish to the DBus boot paths. 759491d8ee7SSantosh Puranik * 760491d8ee7SSantosh Puranik * @param[in] rfSource The boot source in Redfish. 761944ffaf9SJohnathan Mantey * @param[out] bootSource The DBus source 762944ffaf9SJohnathan Mantey * @param[out] bootMode the DBus boot mode 763491d8ee7SSantosh Puranik * 764944ffaf9SJohnathan Mantey * @return Integer error code. 765491d8ee7SSantosh Puranik */ 766ac106bf6SEd Tanous inline int 767ac106bf6SEd Tanous assignBootParameters(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 768ac106bf6SEd Tanous const std::string& rfSource, std::string& bootSource, 769ac106bf6SEd Tanous std::string& bootMode) 770491d8ee7SSantosh Puranik { 771c21865c4SKonstantin Aladyshev bootSource = "xyz.openbmc_project.Control.Boot.Source.Sources.Default"; 772c21865c4SKonstantin Aladyshev bootMode = "xyz.openbmc_project.Control.Boot.Mode.Modes.Regular"; 773944ffaf9SJohnathan Mantey 774491d8ee7SSantosh Puranik if (rfSource == "None") 775491d8ee7SSantosh Puranik { 776944ffaf9SJohnathan Mantey return 0; 777491d8ee7SSantosh Puranik } 7783174e4dfSEd Tanous if (rfSource == "Pxe") 779491d8ee7SSantosh Puranik { 780944ffaf9SJohnathan Mantey bootSource = "xyz.openbmc_project.Control.Boot.Source.Sources.Network"; 781944ffaf9SJohnathan Mantey } 782944ffaf9SJohnathan Mantey else if (rfSource == "Hdd") 783944ffaf9SJohnathan Mantey { 784944ffaf9SJohnathan Mantey bootSource = "xyz.openbmc_project.Control.Boot.Source.Sources.Disk"; 785944ffaf9SJohnathan Mantey } 786944ffaf9SJohnathan Mantey else if (rfSource == "Diags") 787944ffaf9SJohnathan Mantey { 788944ffaf9SJohnathan Mantey bootMode = "xyz.openbmc_project.Control.Boot.Mode.Modes.Safe"; 789944ffaf9SJohnathan Mantey } 790944ffaf9SJohnathan Mantey else if (rfSource == "Cd") 791944ffaf9SJohnathan Mantey { 792944ffaf9SJohnathan Mantey bootSource = 793944ffaf9SJohnathan Mantey "xyz.openbmc_project.Control.Boot.Source.Sources.ExternalMedia"; 794944ffaf9SJohnathan Mantey } 795944ffaf9SJohnathan Mantey else if (rfSource == "BiosSetup") 796944ffaf9SJohnathan Mantey { 797944ffaf9SJohnathan Mantey bootMode = "xyz.openbmc_project.Control.Boot.Mode.Modes.Setup"; 798491d8ee7SSantosh Puranik } 7999f16b2c1SJennifer Lee else if (rfSource == "Usb") 8009f16b2c1SJennifer Lee { 801944ffaf9SJohnathan Mantey bootSource = 802944ffaf9SJohnathan Mantey "xyz.openbmc_project.Control.Boot.Source.Sources.RemovableMedia"; 8039f16b2c1SJennifer Lee } 804491d8ee7SSantosh Puranik else 805491d8ee7SSantosh Puranik { 80662598e31SEd Tanous BMCWEB_LOG_DEBUG( 80762598e31SEd Tanous "Invalid property value for BootSourceOverrideTarget: {}", 80862598e31SEd Tanous bootSource); 809ac106bf6SEd Tanous messages::propertyValueNotInList(asyncResp->res, rfSource, 810944ffaf9SJohnathan Mantey "BootSourceTargetOverride"); 811944ffaf9SJohnathan Mantey return -1; 812491d8ee7SSantosh Puranik } 813944ffaf9SJohnathan Mantey return 0; 814491d8ee7SSantosh Puranik } 8151981771bSAli Ahmed 816978b8803SAndrew Geissler /** 817978b8803SAndrew Geissler * @brief Retrieves boot progress of the system 818978b8803SAndrew Geissler * 819ac106bf6SEd Tanous * @param[in] asyncResp Shared pointer for generating response message. 820978b8803SAndrew Geissler * 821978b8803SAndrew Geissler * @return None. 822978b8803SAndrew Geissler */ 823ac106bf6SEd Tanous inline void getBootProgress(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) 824978b8803SAndrew Geissler { 8251e1e598dSJonathan Doman sdbusplus::asio::getProperty<std::string>( 8261e1e598dSJonathan Doman *crow::connections::systemBus, "xyz.openbmc_project.State.Host", 8271e1e598dSJonathan Doman "/xyz/openbmc_project/state/host0", 8281e1e598dSJonathan Doman "xyz.openbmc_project.State.Boot.Progress", "BootProgress", 829ac106bf6SEd Tanous [asyncResp](const boost::system::error_code& ec, 8301e1e598dSJonathan Doman const std::string& bootProgressStr) { 831978b8803SAndrew Geissler if (ec) 832978b8803SAndrew Geissler { 833978b8803SAndrew Geissler // BootProgress is an optional object so just do nothing if 834978b8803SAndrew Geissler // not found 835978b8803SAndrew Geissler return; 836978b8803SAndrew Geissler } 837978b8803SAndrew Geissler 83862598e31SEd Tanous BMCWEB_LOG_DEBUG("Boot Progress: {}", bootProgressStr); 839978b8803SAndrew Geissler 840ac106bf6SEd Tanous asyncResp->res.jsonValue["BootProgress"]["LastState"] = 841e43914b3SAndrew Geissler dbusToRfBootProgress(bootProgressStr); 8421e1e598dSJonathan Doman }); 843978b8803SAndrew Geissler } 844491d8ee7SSantosh Puranik 845491d8ee7SSantosh Puranik /** 846b6d5d45cSHieu Huynh * @brief Retrieves boot progress Last Update of the system 847b6d5d45cSHieu Huynh * 848ac106bf6SEd Tanous * @param[in] asyncResp Shared pointer for generating response message. 849b6d5d45cSHieu Huynh * 850b6d5d45cSHieu Huynh * @return None. 851b6d5d45cSHieu Huynh */ 852b6d5d45cSHieu Huynh inline void getBootProgressLastStateTime( 853ac106bf6SEd Tanous const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) 854b6d5d45cSHieu Huynh { 855b6d5d45cSHieu Huynh sdbusplus::asio::getProperty<uint64_t>( 856b6d5d45cSHieu Huynh *crow::connections::systemBus, "xyz.openbmc_project.State.Host", 857b6d5d45cSHieu Huynh "/xyz/openbmc_project/state/host0", 858b6d5d45cSHieu Huynh "xyz.openbmc_project.State.Boot.Progress", "BootProgressLastUpdate", 859ac106bf6SEd Tanous [asyncResp](const boost::system::error_code& ec, 860b6d5d45cSHieu Huynh const uint64_t lastStateTime) { 861b6d5d45cSHieu Huynh if (ec) 862b6d5d45cSHieu Huynh { 86362598e31SEd Tanous BMCWEB_LOG_DEBUG("D-BUS response error {}", ec); 864b6d5d45cSHieu Huynh return; 865b6d5d45cSHieu Huynh } 866b6d5d45cSHieu Huynh 867b6d5d45cSHieu Huynh // BootProgressLastUpdate is the last time the BootProgress property 868b6d5d45cSHieu Huynh // was updated. The time is the Epoch time, number of microseconds 869b6d5d45cSHieu Huynh // since 1 Jan 1970 00::00::00 UTC." 870b6d5d45cSHieu Huynh // https://github.com/openbmc/phosphor-dbus-interfaces/blob/master/ 871b6d5d45cSHieu Huynh // yaml/xyz/openbmc_project/State/Boot/Progress.interface.yaml#L11 872b6d5d45cSHieu Huynh 873b6d5d45cSHieu Huynh // Convert to ISO 8601 standard 874ac106bf6SEd Tanous asyncResp->res.jsonValue["BootProgress"]["LastStateTime"] = 875b6d5d45cSHieu Huynh redfish::time_utils::getDateTimeUintUs(lastStateTime); 876b6d5d45cSHieu Huynh }); 877b6d5d45cSHieu Huynh } 878b6d5d45cSHieu Huynh 879b6d5d45cSHieu Huynh /** 880c21865c4SKonstantin Aladyshev * @brief Retrieves boot override type over DBUS and fills out the response 881cd9a4666SKonstantin Aladyshev * 882ac106bf6SEd Tanous * @param[in] asyncResp Shared pointer for generating response message. 883cd9a4666SKonstantin Aladyshev * 884cd9a4666SKonstantin Aladyshev * @return None. 885cd9a4666SKonstantin Aladyshev */ 886cd9a4666SKonstantin Aladyshev 887ac106bf6SEd Tanous inline void 888ac106bf6SEd Tanous getBootOverrideType(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) 889cd9a4666SKonstantin Aladyshev { 8901e1e598dSJonathan Doman sdbusplus::asio::getProperty<std::string>( 8911e1e598dSJonathan Doman *crow::connections::systemBus, "xyz.openbmc_project.Settings", 8921e1e598dSJonathan Doman "/xyz/openbmc_project/control/host0/boot", 8931e1e598dSJonathan Doman "xyz.openbmc_project.Control.Boot.Type", "BootType", 894ac106bf6SEd Tanous [asyncResp](const boost::system::error_code& ec, 8951e1e598dSJonathan Doman const std::string& bootType) { 896cd9a4666SKonstantin Aladyshev if (ec) 897cd9a4666SKonstantin Aladyshev { 898cd9a4666SKonstantin Aladyshev // not an error, don't have to have the interface 899cd9a4666SKonstantin Aladyshev return; 900cd9a4666SKonstantin Aladyshev } 901cd9a4666SKonstantin Aladyshev 90262598e31SEd Tanous BMCWEB_LOG_DEBUG("Boot type: {}", bootType); 903cd9a4666SKonstantin Aladyshev 904ac106bf6SEd Tanous asyncResp->res 905ac106bf6SEd Tanous .jsonValue["Boot"] 906002d39b4SEd Tanous ["BootSourceOverrideMode@Redfish.AllowableValues"] = 907613dabeaSEd Tanous nlohmann::json::array_t({"Legacy", "UEFI"}); 908cd9a4666SKonstantin Aladyshev 9091e1e598dSJonathan Doman auto rfType = dbusToRfBootType(bootType); 910cd9a4666SKonstantin Aladyshev if (rfType.empty()) 911cd9a4666SKonstantin Aladyshev { 912ac106bf6SEd Tanous messages::internalError(asyncResp->res); 913cd9a4666SKonstantin Aladyshev return; 914cd9a4666SKonstantin Aladyshev } 915cd9a4666SKonstantin Aladyshev 916ac106bf6SEd Tanous asyncResp->res.jsonValue["Boot"]["BootSourceOverrideMode"] = rfType; 9171e1e598dSJonathan Doman }); 918cd9a4666SKonstantin Aladyshev } 919cd9a4666SKonstantin Aladyshev 920cd9a4666SKonstantin Aladyshev /** 921c21865c4SKonstantin Aladyshev * @brief Retrieves boot override mode over DBUS and fills out the response 922491d8ee7SSantosh Puranik * 923ac106bf6SEd Tanous * @param[in] asyncResp Shared pointer for generating response message. 924491d8ee7SSantosh Puranik * 925491d8ee7SSantosh Puranik * @return None. 926491d8ee7SSantosh Puranik */ 927c21865c4SKonstantin Aladyshev 928ac106bf6SEd Tanous inline void 929ac106bf6SEd Tanous getBootOverrideMode(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) 930491d8ee7SSantosh Puranik { 9311e1e598dSJonathan Doman sdbusplus::asio::getProperty<std::string>( 9321e1e598dSJonathan Doman *crow::connections::systemBus, "xyz.openbmc_project.Settings", 9331e1e598dSJonathan Doman "/xyz/openbmc_project/control/host0/boot", 9341e1e598dSJonathan Doman "xyz.openbmc_project.Control.Boot.Mode", "BootMode", 935ac106bf6SEd Tanous [asyncResp](const boost::system::error_code& ec, 9361e1e598dSJonathan Doman const std::string& bootModeStr) { 937491d8ee7SSantosh Puranik if (ec) 938491d8ee7SSantosh Puranik { 939b3e86cb0SGunnar Mills BMCWEB_LOG_ERROR("DBUS response error {}", ec); 940ac106bf6SEd Tanous messages::internalError(asyncResp->res); 941491d8ee7SSantosh Puranik return; 942491d8ee7SSantosh Puranik } 943491d8ee7SSantosh Puranik 94462598e31SEd Tanous BMCWEB_LOG_DEBUG("Boot mode: {}", bootModeStr); 945491d8ee7SSantosh Puranik 94620fa6a2cSEd Tanous nlohmann::json::array_t allowed; 94720fa6a2cSEd Tanous allowed.emplace_back("None"); 94820fa6a2cSEd Tanous allowed.emplace_back("Pxe"); 94920fa6a2cSEd Tanous allowed.emplace_back("Hdd"); 95020fa6a2cSEd Tanous allowed.emplace_back("Cd"); 95120fa6a2cSEd Tanous allowed.emplace_back("Diags"); 95220fa6a2cSEd Tanous allowed.emplace_back("BiosSetup"); 95320fa6a2cSEd Tanous allowed.emplace_back("Usb"); 95420fa6a2cSEd Tanous 955ac106bf6SEd Tanous asyncResp->res 9560fda0f12SGeorge Liu .jsonValue["Boot"] 95720fa6a2cSEd Tanous ["BootSourceOverrideTarget@Redfish.AllowableValues"] = 95820fa6a2cSEd Tanous std::move(allowed); 9591e1e598dSJonathan Doman if (bootModeStr != 960491d8ee7SSantosh Puranik "xyz.openbmc_project.Control.Boot.Mode.Modes.Regular") 961491d8ee7SSantosh Puranik { 9621e1e598dSJonathan Doman auto rfMode = dbusToRfBootMode(bootModeStr); 963491d8ee7SSantosh Puranik if (!rfMode.empty()) 964491d8ee7SSantosh Puranik { 965ac106bf6SEd Tanous asyncResp->res.jsonValue["Boot"]["BootSourceOverrideTarget"] = 966491d8ee7SSantosh Puranik rfMode; 967491d8ee7SSantosh Puranik } 968491d8ee7SSantosh Puranik } 9691e1e598dSJonathan Doman }); 970491d8ee7SSantosh Puranik } 971491d8ee7SSantosh Puranik 972491d8ee7SSantosh Puranik /** 973c21865c4SKonstantin Aladyshev * @brief Retrieves boot override source over DBUS 974491d8ee7SSantosh Puranik * 975ac106bf6SEd Tanous * @param[in] asyncResp Shared pointer for generating response message. 976491d8ee7SSantosh Puranik * 977491d8ee7SSantosh Puranik * @return None. 978491d8ee7SSantosh Puranik */ 979c21865c4SKonstantin Aladyshev 980c21865c4SKonstantin Aladyshev inline void 981ac106bf6SEd Tanous getBootOverrideSource(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) 982491d8ee7SSantosh Puranik { 9831e1e598dSJonathan Doman sdbusplus::asio::getProperty<std::string>( 9841e1e598dSJonathan Doman *crow::connections::systemBus, "xyz.openbmc_project.Settings", 9851e1e598dSJonathan Doman "/xyz/openbmc_project/control/host0/boot", 9861e1e598dSJonathan Doman "xyz.openbmc_project.Control.Boot.Source", "BootSource", 987ac106bf6SEd Tanous [asyncResp](const boost::system::error_code& ec, 9881e1e598dSJonathan Doman const std::string& bootSourceStr) { 989491d8ee7SSantosh Puranik if (ec) 990491d8ee7SSantosh Puranik { 9915ef735c8SNan Zhou if (ec.value() == boost::asio::error::host_unreachable) 9925ef735c8SNan Zhou { 9935ef735c8SNan Zhou return; 9945ef735c8SNan Zhou } 995b3e86cb0SGunnar Mills BMCWEB_LOG_ERROR("DBUS response error {}", ec); 996ac106bf6SEd Tanous messages::internalError(asyncResp->res); 997491d8ee7SSantosh Puranik return; 998491d8ee7SSantosh Puranik } 999491d8ee7SSantosh Puranik 100062598e31SEd Tanous BMCWEB_LOG_DEBUG("Boot source: {}", bootSourceStr); 1001491d8ee7SSantosh Puranik 10021e1e598dSJonathan Doman auto rfSource = dbusToRfBootSource(bootSourceStr); 1003491d8ee7SSantosh Puranik if (!rfSource.empty()) 1004491d8ee7SSantosh Puranik { 1005ac106bf6SEd Tanous asyncResp->res.jsonValue["Boot"]["BootSourceOverrideTarget"] = 1006ac106bf6SEd Tanous rfSource; 1007491d8ee7SSantosh Puranik } 1008cd9a4666SKonstantin Aladyshev 1009cd9a4666SKonstantin Aladyshev // Get BootMode as BootSourceOverrideTarget is constructed 1010cd9a4666SKonstantin Aladyshev // from both BootSource and BootMode 1011ac106bf6SEd Tanous getBootOverrideMode(asyncResp); 10121e1e598dSJonathan Doman }); 1013491d8ee7SSantosh Puranik } 1014491d8ee7SSantosh Puranik 1015491d8ee7SSantosh Puranik /** 1016c21865c4SKonstantin Aladyshev * @brief This functions abstracts all the logic behind getting a 1017c21865c4SKonstantin Aladyshev * "BootSourceOverrideEnabled" property from an overall boot override enable 1018c21865c4SKonstantin Aladyshev * state 1019491d8ee7SSantosh Puranik * 1020ac106bf6SEd Tanous * @param[in] asyncResp Shared pointer for generating response message. 1021491d8ee7SSantosh Puranik * 1022491d8ee7SSantosh Puranik * @return None. 1023491d8ee7SSantosh Puranik */ 1024491d8ee7SSantosh Puranik 1025ac106bf6SEd Tanous inline void processBootOverrideEnable( 1026ac106bf6SEd Tanous const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 1027c21865c4SKonstantin Aladyshev const bool bootOverrideEnableSetting) 1028c21865c4SKonstantin Aladyshev { 1029c21865c4SKonstantin Aladyshev if (!bootOverrideEnableSetting) 1030c21865c4SKonstantin Aladyshev { 1031ac106bf6SEd Tanous asyncResp->res.jsonValue["Boot"]["BootSourceOverrideEnabled"] = 1032ac106bf6SEd Tanous "Disabled"; 1033c21865c4SKonstantin Aladyshev return; 1034c21865c4SKonstantin Aladyshev } 1035c21865c4SKonstantin Aladyshev 1036c21865c4SKonstantin Aladyshev // If boot source override is enabled, we need to check 'one_time' 1037c21865c4SKonstantin Aladyshev // property to set a correct value for the "BootSourceOverrideEnabled" 10381e1e598dSJonathan Doman sdbusplus::asio::getProperty<bool>( 10391e1e598dSJonathan Doman *crow::connections::systemBus, "xyz.openbmc_project.Settings", 10401e1e598dSJonathan Doman "/xyz/openbmc_project/control/host0/boot/one_time", 10411e1e598dSJonathan Doman "xyz.openbmc_project.Object.Enable", "Enabled", 1042ac106bf6SEd Tanous [asyncResp](const boost::system::error_code& ec, bool oneTimeSetting) { 1043491d8ee7SSantosh Puranik if (ec) 1044491d8ee7SSantosh Puranik { 1045b3e86cb0SGunnar Mills BMCWEB_LOG_ERROR("DBUS response error {}", ec); 1046ac106bf6SEd Tanous messages::internalError(asyncResp->res); 1047491d8ee7SSantosh Puranik return; 1048491d8ee7SSantosh Puranik } 1049491d8ee7SSantosh Puranik 1050c21865c4SKonstantin Aladyshev if (oneTimeSetting) 1051c21865c4SKonstantin Aladyshev { 1052ac106bf6SEd Tanous asyncResp->res.jsonValue["Boot"]["BootSourceOverrideEnabled"] = 1053ac106bf6SEd Tanous "Once"; 1054c21865c4SKonstantin Aladyshev } 1055c21865c4SKonstantin Aladyshev else 1056c21865c4SKonstantin Aladyshev { 1057ac106bf6SEd Tanous asyncResp->res.jsonValue["Boot"]["BootSourceOverrideEnabled"] = 1058c21865c4SKonstantin Aladyshev "Continuous"; 1059c21865c4SKonstantin Aladyshev } 10601e1e598dSJonathan Doman }); 1061491d8ee7SSantosh Puranik } 1062491d8ee7SSantosh Puranik 1063491d8ee7SSantosh Puranik /** 1064c21865c4SKonstantin Aladyshev * @brief Retrieves boot override enable over DBUS 1065c21865c4SKonstantin Aladyshev * 1066ac106bf6SEd Tanous * @param[in] asyncResp Shared pointer for generating response message. 1067c21865c4SKonstantin Aladyshev * 1068c21865c4SKonstantin Aladyshev * @return None. 1069c21865c4SKonstantin Aladyshev */ 1070c21865c4SKonstantin Aladyshev 1071c21865c4SKonstantin Aladyshev inline void 1072ac106bf6SEd Tanous getBootOverrideEnable(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) 1073c21865c4SKonstantin Aladyshev { 10741e1e598dSJonathan Doman sdbusplus::asio::getProperty<bool>( 10751e1e598dSJonathan Doman *crow::connections::systemBus, "xyz.openbmc_project.Settings", 10761e1e598dSJonathan Doman "/xyz/openbmc_project/control/host0/boot", 10771e1e598dSJonathan Doman "xyz.openbmc_project.Object.Enable", "Enabled", 1078ac106bf6SEd Tanous [asyncResp](const boost::system::error_code& ec, 10791e1e598dSJonathan Doman const bool bootOverrideEnable) { 1080c21865c4SKonstantin Aladyshev if (ec) 1081c21865c4SKonstantin Aladyshev { 10825ef735c8SNan Zhou if (ec.value() == boost::asio::error::host_unreachable) 10835ef735c8SNan Zhou { 10845ef735c8SNan Zhou return; 10855ef735c8SNan Zhou } 1086b3e86cb0SGunnar Mills BMCWEB_LOG_ERROR("DBUS response error {}", ec); 1087ac106bf6SEd Tanous messages::internalError(asyncResp->res); 1088c21865c4SKonstantin Aladyshev return; 1089c21865c4SKonstantin Aladyshev } 1090c21865c4SKonstantin Aladyshev 1091ac106bf6SEd Tanous processBootOverrideEnable(asyncResp, bootOverrideEnable); 10921e1e598dSJonathan Doman }); 1093c21865c4SKonstantin Aladyshev } 1094c21865c4SKonstantin Aladyshev 1095c21865c4SKonstantin Aladyshev /** 1096c21865c4SKonstantin Aladyshev * @brief Retrieves boot source override properties 1097c21865c4SKonstantin Aladyshev * 1098ac106bf6SEd Tanous * @param[in] asyncResp Shared pointer for generating response message. 1099c21865c4SKonstantin Aladyshev * 1100c21865c4SKonstantin Aladyshev * @return None. 1101c21865c4SKonstantin Aladyshev */ 1102ac106bf6SEd Tanous inline void 1103ac106bf6SEd Tanous getBootProperties(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) 1104c21865c4SKonstantin Aladyshev { 110562598e31SEd Tanous BMCWEB_LOG_DEBUG("Get boot information."); 1106c21865c4SKonstantin Aladyshev 1107ac106bf6SEd Tanous getBootOverrideSource(asyncResp); 1108ac106bf6SEd Tanous getBootOverrideType(asyncResp); 1109ac106bf6SEd Tanous getBootOverrideEnable(asyncResp); 1110c21865c4SKonstantin Aladyshev } 1111c21865c4SKonstantin Aladyshev 1112c21865c4SKonstantin Aladyshev /** 1113c0557e1aSGunnar Mills * @brief Retrieves the Last Reset Time 1114c0557e1aSGunnar Mills * 1115c0557e1aSGunnar Mills * "Reset" is an overloaded term in Redfish, "Reset" includes power on 1116c0557e1aSGunnar Mills * and power off. Even though this is the "system" Redfish object look at the 1117c0557e1aSGunnar Mills * chassis D-Bus interface for the LastStateChangeTime since this has the 1118c0557e1aSGunnar Mills * last power operation time. 1119c0557e1aSGunnar Mills * 1120ac106bf6SEd Tanous * @param[in] asyncResp Shared pointer for generating response message. 1121c0557e1aSGunnar Mills * 1122c0557e1aSGunnar Mills * @return None. 1123c0557e1aSGunnar Mills */ 1124ac106bf6SEd Tanous inline void 1125ac106bf6SEd Tanous getLastResetTime(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) 1126c0557e1aSGunnar Mills { 112762598e31SEd Tanous BMCWEB_LOG_DEBUG("Getting System Last Reset Time"); 1128c0557e1aSGunnar Mills 11291e1e598dSJonathan Doman sdbusplus::asio::getProperty<uint64_t>( 11301e1e598dSJonathan Doman *crow::connections::systemBus, "xyz.openbmc_project.State.Chassis", 11311e1e598dSJonathan Doman "/xyz/openbmc_project/state/chassis0", 11321e1e598dSJonathan Doman "xyz.openbmc_project.State.Chassis", "LastStateChangeTime", 1133ac106bf6SEd Tanous [asyncResp](const boost::system::error_code& ec, 1134ac106bf6SEd Tanous uint64_t lastResetTime) { 1135c0557e1aSGunnar Mills if (ec) 1136c0557e1aSGunnar Mills { 113762598e31SEd Tanous BMCWEB_LOG_DEBUG("D-BUS response error {}", ec); 1138c0557e1aSGunnar Mills return; 1139c0557e1aSGunnar Mills } 1140c0557e1aSGunnar Mills 1141c0557e1aSGunnar Mills // LastStateChangeTime is epoch time, in milliseconds 1142c0557e1aSGunnar Mills // https://github.com/openbmc/phosphor-dbus-interfaces/blob/33e8e1dd64da53a66e888d33dc82001305cd0bf9/xyz/openbmc_project/State/Chassis.interface.yaml#L19 11431e1e598dSJonathan Doman uint64_t lastResetTimeStamp = lastResetTime / 1000; 1144c0557e1aSGunnar Mills 1145c0557e1aSGunnar Mills // Convert to ISO 8601 standard 1146ac106bf6SEd Tanous asyncResp->res.jsonValue["LastResetTime"] = 11472b82937eSEd Tanous redfish::time_utils::getDateTimeUint(lastResetTimeStamp); 11481e1e598dSJonathan Doman }); 1149c0557e1aSGunnar Mills } 1150c0557e1aSGunnar Mills 1151c0557e1aSGunnar Mills /** 1152797d5daeSCorey Hardesty * @brief Retrieves the number of automatic boot Retry attempts allowed/left. 1153797d5daeSCorey Hardesty * 1154797d5daeSCorey Hardesty * The total number of automatic reboot retries allowed "RetryAttempts" and its 1155797d5daeSCorey Hardesty * corresponding property "AttemptsLeft" that keeps track of the amount of 1156797d5daeSCorey Hardesty * automatic retry attempts left are hosted in phosphor-state-manager through 1157797d5daeSCorey Hardesty * dbus. 1158797d5daeSCorey Hardesty * 1159ac106bf6SEd Tanous * @param[in] asyncResp Shared pointer for generating response message. 1160797d5daeSCorey Hardesty * 1161797d5daeSCorey Hardesty * @return None. 1162797d5daeSCorey Hardesty */ 1163ac106bf6SEd Tanous inline void getAutomaticRebootAttempts( 1164ac106bf6SEd Tanous const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) 1165797d5daeSCorey Hardesty { 116662598e31SEd Tanous BMCWEB_LOG_DEBUG("Get Automatic Retry policy"); 1167797d5daeSCorey Hardesty 1168797d5daeSCorey Hardesty sdbusplus::asio::getAllProperties( 1169797d5daeSCorey Hardesty *crow::connections::systemBus, "xyz.openbmc_project.State.Host", 1170797d5daeSCorey Hardesty "/xyz/openbmc_project/state/host0", 1171797d5daeSCorey Hardesty "xyz.openbmc_project.Control.Boot.RebootAttempts", 1172ac106bf6SEd Tanous [asyncResp{asyncResp}]( 1173ac106bf6SEd Tanous const boost::system::error_code& ec, 1174797d5daeSCorey Hardesty const dbus::utility::DBusPropertiesMap& propertiesList) { 1175797d5daeSCorey Hardesty if (ec) 1176797d5daeSCorey Hardesty { 1177797d5daeSCorey Hardesty if (ec.value() != EBADR) 1178797d5daeSCorey Hardesty { 117962598e31SEd Tanous BMCWEB_LOG_ERROR("D-Bus responses error: {}", ec); 1180ac106bf6SEd Tanous messages::internalError(asyncResp->res); 1181797d5daeSCorey Hardesty } 1182797d5daeSCorey Hardesty return; 1183797d5daeSCorey Hardesty } 1184797d5daeSCorey Hardesty 1185797d5daeSCorey Hardesty const uint32_t* attemptsLeft = nullptr; 1186797d5daeSCorey Hardesty const uint32_t* retryAttempts = nullptr; 1187797d5daeSCorey Hardesty 1188797d5daeSCorey Hardesty const bool success = sdbusplus::unpackPropertiesNoThrow( 1189797d5daeSCorey Hardesty dbus_utils::UnpackErrorPrinter(), propertiesList, "AttemptsLeft", 1190797d5daeSCorey Hardesty attemptsLeft, "RetryAttempts", retryAttempts); 1191797d5daeSCorey Hardesty 1192797d5daeSCorey Hardesty if (!success) 1193797d5daeSCorey Hardesty { 1194ac106bf6SEd Tanous messages::internalError(asyncResp->res); 1195797d5daeSCorey Hardesty return; 1196797d5daeSCorey Hardesty } 1197797d5daeSCorey Hardesty 1198797d5daeSCorey Hardesty if (attemptsLeft != nullptr) 1199797d5daeSCorey Hardesty { 1200ac106bf6SEd Tanous asyncResp->res 1201ac106bf6SEd Tanous .jsonValue["Boot"]["RemainingAutomaticRetryAttempts"] = 1202797d5daeSCorey Hardesty *attemptsLeft; 1203797d5daeSCorey Hardesty } 1204797d5daeSCorey Hardesty 1205797d5daeSCorey Hardesty if (retryAttempts != nullptr) 1206797d5daeSCorey Hardesty { 1207ac106bf6SEd Tanous asyncResp->res.jsonValue["Boot"]["AutomaticRetryAttempts"] = 1208797d5daeSCorey Hardesty *retryAttempts; 1209797d5daeSCorey Hardesty } 1210797d5daeSCorey Hardesty }); 1211797d5daeSCorey Hardesty } 1212797d5daeSCorey Hardesty 1213797d5daeSCorey Hardesty /** 12146bd5a8d2SGunnar Mills * @brief Retrieves Automatic Retry properties. Known on D-Bus as AutoReboot. 12156bd5a8d2SGunnar Mills * 1216ac106bf6SEd Tanous * @param[in] asyncResp Shared pointer for generating response message. 12176bd5a8d2SGunnar Mills * 12186bd5a8d2SGunnar Mills * @return None. 12196bd5a8d2SGunnar Mills */ 1220797d5daeSCorey Hardesty inline void 1221ac106bf6SEd Tanous getAutomaticRetryPolicy(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) 12226bd5a8d2SGunnar Mills { 122362598e31SEd Tanous BMCWEB_LOG_DEBUG("Get Automatic Retry policy"); 12246bd5a8d2SGunnar Mills 12251e1e598dSJonathan Doman sdbusplus::asio::getProperty<bool>( 12261e1e598dSJonathan Doman *crow::connections::systemBus, "xyz.openbmc_project.Settings", 12271e1e598dSJonathan Doman "/xyz/openbmc_project/control/host0/auto_reboot", 12281e1e598dSJonathan Doman "xyz.openbmc_project.Control.Boot.RebootPolicy", "AutoReboot", 1229ac106bf6SEd Tanous [asyncResp](const boost::system::error_code& ec, 1230ac106bf6SEd Tanous bool autoRebootEnabled) { 12316bd5a8d2SGunnar Mills if (ec) 12326bd5a8d2SGunnar Mills { 1233797d5daeSCorey Hardesty if (ec.value() != EBADR) 1234797d5daeSCorey Hardesty { 123562598e31SEd Tanous BMCWEB_LOG_ERROR("D-Bus responses error: {}", ec); 1236ac106bf6SEd Tanous messages::internalError(asyncResp->res); 1237797d5daeSCorey Hardesty } 12386bd5a8d2SGunnar Mills return; 12396bd5a8d2SGunnar Mills } 12406bd5a8d2SGunnar Mills 124162598e31SEd Tanous BMCWEB_LOG_DEBUG("Auto Reboot: {}", autoRebootEnabled); 1242e05aec50SEd Tanous if (autoRebootEnabled) 12436bd5a8d2SGunnar Mills { 1244ac106bf6SEd Tanous asyncResp->res.jsonValue["Boot"]["AutomaticRetryConfig"] = 12456bd5a8d2SGunnar Mills "RetryAttempts"; 12466bd5a8d2SGunnar Mills } 12476bd5a8d2SGunnar Mills else 12486bd5a8d2SGunnar Mills { 1249ac106bf6SEd Tanous asyncResp->res.jsonValue["Boot"]["AutomaticRetryConfig"] = 1250ac106bf6SEd Tanous "Disabled"; 12516bd5a8d2SGunnar Mills } 1252ac106bf6SEd Tanous getAutomaticRebootAttempts(asyncResp); 125369f35306SGunnar Mills 125469f35306SGunnar Mills // "AutomaticRetryConfig" can be 3 values, Disabled, RetryAlways, 125569f35306SGunnar Mills // and RetryAttempts. OpenBMC only supports Disabled and 125669f35306SGunnar Mills // RetryAttempts. 125720fa6a2cSEd Tanous nlohmann::json::array_t allowed; 125820fa6a2cSEd Tanous allowed.emplace_back("Disabled"); 125920fa6a2cSEd Tanous allowed.emplace_back("RetryAttempts"); 1260ac106bf6SEd Tanous asyncResp->res 1261ac106bf6SEd Tanous .jsonValue["Boot"]["AutomaticRetryConfig@Redfish.AllowableValues"] = 126220fa6a2cSEd Tanous std::move(allowed); 12631e1e598dSJonathan Doman }); 12646bd5a8d2SGunnar Mills } 12656bd5a8d2SGunnar Mills 12666bd5a8d2SGunnar Mills /** 1267797d5daeSCorey Hardesty * @brief Sets RetryAttempts 1268797d5daeSCorey Hardesty * 1269ac106bf6SEd Tanous * @param[in] asyncResp Shared pointer for generating response message. 1270797d5daeSCorey Hardesty * @param[in] retryAttempts "AutomaticRetryAttempts" from request. 1271797d5daeSCorey Hardesty * 1272797d5daeSCorey Hardesty *@return None. 1273797d5daeSCorey Hardesty */ 1274797d5daeSCorey Hardesty 1275ac106bf6SEd Tanous inline void setAutomaticRetryAttempts( 1276ac106bf6SEd Tanous const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 1277797d5daeSCorey Hardesty const uint32_t retryAttempts) 1278797d5daeSCorey Hardesty { 127962598e31SEd Tanous BMCWEB_LOG_DEBUG("Set Automatic Retry Attempts."); 128087c44966SAsmitha Karunanithi setDbusProperty( 1281*e93abac6SGinu George asyncResp, "Boot/AutomaticRetryAttempts", 1282*e93abac6SGinu George "xyz.openbmc_project.State.Host", 128387c44966SAsmitha Karunanithi sdbusplus::message::object_path("/xyz/openbmc_project/state/host0"), 12849ae226faSGeorge Liu "xyz.openbmc_project.Control.Boot.RebootAttempts", "RetryAttempts", 1285*e93abac6SGinu George retryAttempts); 1286797d5daeSCorey Hardesty } 1287797d5daeSCorey Hardesty 12888d69c668SEd Tanous inline computer_system::PowerRestorePolicyTypes 12898d69c668SEd Tanous redfishPowerRestorePolicyFromDbus(std::string_view value) 12908d69c668SEd Tanous { 12918d69c668SEd Tanous if (value == 12928d69c668SEd Tanous "xyz.openbmc_project.Control.Power.RestorePolicy.Policy.AlwaysOn") 12938d69c668SEd Tanous { 12948d69c668SEd Tanous return computer_system::PowerRestorePolicyTypes::AlwaysOn; 12958d69c668SEd Tanous } 12968d69c668SEd Tanous if (value == 12978d69c668SEd Tanous "xyz.openbmc_project.Control.Power.RestorePolicy.Policy.AlwaysOff") 12988d69c668SEd Tanous { 12998d69c668SEd Tanous return computer_system::PowerRestorePolicyTypes::AlwaysOff; 13008d69c668SEd Tanous } 13018d69c668SEd Tanous if (value == 13023a34b742SGunnar Mills "xyz.openbmc_project.Control.Power.RestorePolicy.Policy.Restore") 13038d69c668SEd Tanous { 13048d69c668SEd Tanous return computer_system::PowerRestorePolicyTypes::LastState; 13058d69c668SEd Tanous } 13068d69c668SEd Tanous if (value == "xyz.openbmc_project.Control.Power.RestorePolicy.Policy.None") 13078d69c668SEd Tanous { 13088d69c668SEd Tanous return computer_system::PowerRestorePolicyTypes::AlwaysOff; 13098d69c668SEd Tanous } 13108d69c668SEd Tanous return computer_system::PowerRestorePolicyTypes::Invalid; 13118d69c668SEd Tanous } 1312797d5daeSCorey Hardesty /** 1313c6a620f2SGeorge Liu * @brief Retrieves power restore policy over DBUS. 1314c6a620f2SGeorge Liu * 1315ac106bf6SEd Tanous * @param[in] asyncResp Shared pointer for generating response message. 1316c6a620f2SGeorge Liu * 1317c6a620f2SGeorge Liu * @return None. 1318c6a620f2SGeorge Liu */ 13198d1b46d7Szhanghch05 inline void 1320ac106bf6SEd Tanous getPowerRestorePolicy(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) 1321c6a620f2SGeorge Liu { 132262598e31SEd Tanous BMCWEB_LOG_DEBUG("Get power restore policy"); 1323c6a620f2SGeorge Liu 13241e1e598dSJonathan Doman sdbusplus::asio::getProperty<std::string>( 13251e1e598dSJonathan Doman *crow::connections::systemBus, "xyz.openbmc_project.Settings", 13261e1e598dSJonathan Doman "/xyz/openbmc_project/control/host0/power_restore_policy", 13271e1e598dSJonathan Doman "xyz.openbmc_project.Control.Power.RestorePolicy", "PowerRestorePolicy", 1328ac106bf6SEd Tanous [asyncResp](const boost::system::error_code& ec, 13295e7e2dc5SEd Tanous const std::string& policy) { 1330c6a620f2SGeorge Liu if (ec) 1331c6a620f2SGeorge Liu { 133262598e31SEd Tanous BMCWEB_LOG_DEBUG("DBUS response error {}", ec); 1333c6a620f2SGeorge Liu return; 1334c6a620f2SGeorge Liu } 13358d69c668SEd Tanous computer_system::PowerRestorePolicyTypes restore = 13368d69c668SEd Tanous redfishPowerRestorePolicyFromDbus(policy); 13378d69c668SEd Tanous if (restore == computer_system::PowerRestorePolicyTypes::Invalid) 1338c6a620f2SGeorge Liu { 1339ac106bf6SEd Tanous messages::internalError(asyncResp->res); 1340c6a620f2SGeorge Liu return; 1341c6a620f2SGeorge Liu } 1342c6a620f2SGeorge Liu 13438d69c668SEd Tanous asyncResp->res.jsonValue["PowerRestorePolicy"] = restore; 13441e1e598dSJonathan Doman }); 1345c6a620f2SGeorge Liu } 1346c6a620f2SGeorge Liu 1347c6a620f2SGeorge Liu /** 13489dcfe8c1SAlbert Zhang * @brief Stop Boot On Fault over DBUS. 13499dcfe8c1SAlbert Zhang * 13509dcfe8c1SAlbert Zhang * @param[in] asyncResp Shared pointer for generating response message. 13519dcfe8c1SAlbert Zhang * 13529dcfe8c1SAlbert Zhang * @return None. 13539dcfe8c1SAlbert Zhang */ 13549dcfe8c1SAlbert Zhang inline void 13559dcfe8c1SAlbert Zhang getStopBootOnFault(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) 13569dcfe8c1SAlbert Zhang { 135762598e31SEd Tanous BMCWEB_LOG_DEBUG("Get Stop Boot On Fault"); 13589dcfe8c1SAlbert Zhang 13599dcfe8c1SAlbert Zhang sdbusplus::asio::getProperty<bool>( 13609dcfe8c1SAlbert Zhang *crow::connections::systemBus, "xyz.openbmc_project.Settings", 13619dcfe8c1SAlbert Zhang "/xyz/openbmc_project/logging/settings", 13629dcfe8c1SAlbert Zhang "xyz.openbmc_project.Logging.Settings", "QuiesceOnHwError", 13639dcfe8c1SAlbert Zhang [asyncResp](const boost::system::error_code& ec, bool value) { 13649dcfe8c1SAlbert Zhang if (ec) 13659dcfe8c1SAlbert Zhang { 13669dcfe8c1SAlbert Zhang if (ec.value() != EBADR) 13679dcfe8c1SAlbert Zhang { 1368b3e86cb0SGunnar Mills BMCWEB_LOG_ERROR("DBUS response error {}", ec); 13699dcfe8c1SAlbert Zhang messages::internalError(asyncResp->res); 13709dcfe8c1SAlbert Zhang } 13719dcfe8c1SAlbert Zhang return; 13729dcfe8c1SAlbert Zhang } 13739dcfe8c1SAlbert Zhang 13749dcfe8c1SAlbert Zhang if (value) 13759dcfe8c1SAlbert Zhang { 13769dcfe8c1SAlbert Zhang asyncResp->res.jsonValue["Boot"]["StopBootOnFault"] = "AnyFault"; 13779dcfe8c1SAlbert Zhang } 13789dcfe8c1SAlbert Zhang else 13799dcfe8c1SAlbert Zhang { 13809dcfe8c1SAlbert Zhang asyncResp->res.jsonValue["Boot"]["StopBootOnFault"] = "Never"; 13819dcfe8c1SAlbert Zhang } 13829dcfe8c1SAlbert Zhang }); 13839dcfe8c1SAlbert Zhang } 13849dcfe8c1SAlbert Zhang 13859dcfe8c1SAlbert Zhang /** 13861981771bSAli Ahmed * @brief Get TrustedModuleRequiredToBoot property. Determines whether or not 13871981771bSAli Ahmed * TPM is required for booting the host. 13881981771bSAli Ahmed * 1389ac106bf6SEd Tanous * @param[in] asyncResp Shared pointer for generating response message. 13901981771bSAli Ahmed * 13911981771bSAli Ahmed * @return None. 13921981771bSAli Ahmed */ 13931981771bSAli Ahmed inline void getTrustedModuleRequiredToBoot( 1394ac106bf6SEd Tanous const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) 13951981771bSAli Ahmed { 139662598e31SEd Tanous BMCWEB_LOG_DEBUG("Get TPM required to boot."); 1397e99073f5SGeorge Liu constexpr std::array<std::string_view, 1> interfaces = { 1398e99073f5SGeorge Liu "xyz.openbmc_project.Control.TPM.Policy"}; 1399e99073f5SGeorge Liu dbus::utility::getSubTree( 1400e99073f5SGeorge Liu "/", 0, interfaces, 1401ac106bf6SEd Tanous [asyncResp](const boost::system::error_code& ec, 1402b9d36b47SEd Tanous const dbus::utility::MapperGetSubTreeResponse& subtree) { 14031981771bSAli Ahmed if (ec) 14041981771bSAli Ahmed { 140562598e31SEd Tanous BMCWEB_LOG_DEBUG("DBUS response error on TPM.Policy GetSubTree{}", 140662598e31SEd Tanous ec); 14071981771bSAli Ahmed // This is an optional D-Bus object so just return if 14081981771bSAli Ahmed // error occurs 14091981771bSAli Ahmed return; 14101981771bSAli Ahmed } 141126f6976fSEd Tanous if (subtree.empty()) 14121981771bSAli Ahmed { 14131981771bSAli Ahmed // As noted above, this is an optional interface so just return 14141981771bSAli Ahmed // if there is no instance found 14151981771bSAli Ahmed return; 14161981771bSAli Ahmed } 14171981771bSAli Ahmed 14181981771bSAli Ahmed /* When there is more than one TPMEnable object... */ 14191981771bSAli Ahmed if (subtree.size() > 1) 14201981771bSAli Ahmed { 142162598e31SEd Tanous BMCWEB_LOG_DEBUG( 142262598e31SEd Tanous "DBUS response has more than 1 TPM Enable object:{}", 142362598e31SEd Tanous subtree.size()); 14241981771bSAli Ahmed // Throw an internal Error and return 1425ac106bf6SEd Tanous messages::internalError(asyncResp->res); 14261981771bSAli Ahmed return; 14271981771bSAli Ahmed } 14281981771bSAli Ahmed 14291981771bSAli Ahmed // Make sure the Dbus response map has a service and objectPath 14301981771bSAli Ahmed // field 14311981771bSAli Ahmed if (subtree[0].first.empty() || subtree[0].second.size() != 1) 14321981771bSAli Ahmed { 143362598e31SEd Tanous BMCWEB_LOG_DEBUG("TPM.Policy mapper error!"); 1434ac106bf6SEd Tanous messages::internalError(asyncResp->res); 14351981771bSAli Ahmed return; 14361981771bSAli Ahmed } 14371981771bSAli Ahmed 14381981771bSAli Ahmed const std::string& path = subtree[0].first; 14391981771bSAli Ahmed const std::string& serv = subtree[0].second.begin()->first; 14401981771bSAli Ahmed 14411981771bSAli Ahmed // Valid TPM Enable object found, now reading the current value 14421e1e598dSJonathan Doman sdbusplus::asio::getProperty<bool>( 14431e1e598dSJonathan Doman *crow::connections::systemBus, serv, path, 14441e1e598dSJonathan Doman "xyz.openbmc_project.Control.TPM.Policy", "TPMEnable", 1445ac106bf6SEd Tanous [asyncResp](const boost::system::error_code& ec2, 1446ac106bf6SEd Tanous bool tpmRequired) { 14478a592810SEd Tanous if (ec2) 14481981771bSAli Ahmed { 1449b3e86cb0SGunnar Mills BMCWEB_LOG_ERROR("D-BUS response error on TPM.Policy Get{}", 145062598e31SEd Tanous ec2); 1451ac106bf6SEd Tanous messages::internalError(asyncResp->res); 14521981771bSAli Ahmed return; 14531981771bSAli Ahmed } 14541981771bSAli Ahmed 14551e1e598dSJonathan Doman if (tpmRequired) 14561981771bSAli Ahmed { 1457ac106bf6SEd Tanous asyncResp->res 1458ac106bf6SEd Tanous .jsonValue["Boot"]["TrustedModuleRequiredToBoot"] = 14591981771bSAli Ahmed "Required"; 14601981771bSAli Ahmed } 14611981771bSAli Ahmed else 14621981771bSAli Ahmed { 1463ac106bf6SEd Tanous asyncResp->res 1464ac106bf6SEd Tanous .jsonValue["Boot"]["TrustedModuleRequiredToBoot"] = 14651981771bSAli Ahmed "Disabled"; 14661981771bSAli Ahmed } 14671e1e598dSJonathan Doman }); 1468e99073f5SGeorge Liu }); 14691981771bSAli Ahmed } 14701981771bSAli Ahmed 14711981771bSAli Ahmed /** 14721c05dae3SAli Ahmed * @brief Set TrustedModuleRequiredToBoot property. Determines whether or not 14731c05dae3SAli Ahmed * TPM is required for booting the host. 14741c05dae3SAli Ahmed * 1475ac106bf6SEd Tanous * @param[in] asyncResp Shared pointer for generating response message. 14761c05dae3SAli Ahmed * @param[in] tpmRequired Value to set TPM Required To Boot property to. 14771c05dae3SAli Ahmed * 14781c05dae3SAli Ahmed * @return None. 14791c05dae3SAli Ahmed */ 14801c05dae3SAli Ahmed inline void setTrustedModuleRequiredToBoot( 1481ac106bf6SEd Tanous const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, const bool tpmRequired) 14821c05dae3SAli Ahmed { 148362598e31SEd Tanous BMCWEB_LOG_DEBUG("Set TrustedModuleRequiredToBoot."); 1484e99073f5SGeorge Liu constexpr std::array<std::string_view, 1> interfaces = { 1485e99073f5SGeorge Liu "xyz.openbmc_project.Control.TPM.Policy"}; 1486e99073f5SGeorge Liu dbus::utility::getSubTree( 1487e99073f5SGeorge Liu "/", 0, interfaces, 1488ac106bf6SEd Tanous [asyncResp, 1489e99073f5SGeorge Liu tpmRequired](const boost::system::error_code& ec, 1490e99073f5SGeorge Liu const dbus::utility::MapperGetSubTreeResponse& subtree) { 14911c05dae3SAli Ahmed if (ec) 14921c05dae3SAli Ahmed { 1493b3e86cb0SGunnar Mills BMCWEB_LOG_ERROR("DBUS response error on TPM.Policy GetSubTree{}", 149462598e31SEd Tanous ec); 1495ac106bf6SEd Tanous messages::internalError(asyncResp->res); 14961c05dae3SAli Ahmed return; 14971c05dae3SAli Ahmed } 149826f6976fSEd Tanous if (subtree.empty()) 14991c05dae3SAli Ahmed { 1500ac106bf6SEd Tanous messages::propertyValueNotInList(asyncResp->res, "ComputerSystem", 15011c05dae3SAli Ahmed "TrustedModuleRequiredToBoot"); 15021c05dae3SAli Ahmed return; 15031c05dae3SAli Ahmed } 15041c05dae3SAli Ahmed 15051c05dae3SAli Ahmed /* When there is more than one TPMEnable object... */ 15061c05dae3SAli Ahmed if (subtree.size() > 1) 15071c05dae3SAli Ahmed { 150862598e31SEd Tanous BMCWEB_LOG_DEBUG( 150962598e31SEd Tanous "DBUS response has more than 1 TPM Enable object:{}", 151062598e31SEd Tanous subtree.size()); 15111c05dae3SAli Ahmed // Throw an internal Error and return 1512ac106bf6SEd Tanous messages::internalError(asyncResp->res); 15131c05dae3SAli Ahmed return; 15141c05dae3SAli Ahmed } 15151c05dae3SAli Ahmed 15161c05dae3SAli Ahmed // Make sure the Dbus response map has a service and objectPath 15171c05dae3SAli Ahmed // field 15181c05dae3SAli Ahmed if (subtree[0].first.empty() || subtree[0].second.size() != 1) 15191c05dae3SAli Ahmed { 152062598e31SEd Tanous BMCWEB_LOG_DEBUG("TPM.Policy mapper error!"); 1521ac106bf6SEd Tanous messages::internalError(asyncResp->res); 15221c05dae3SAli Ahmed return; 15231c05dae3SAli Ahmed } 15241c05dae3SAli Ahmed 15251c05dae3SAli Ahmed const std::string& path = subtree[0].first; 15261c05dae3SAli Ahmed const std::string& serv = subtree[0].second.begin()->first; 15271c05dae3SAli Ahmed 15281c05dae3SAli Ahmed if (serv.empty()) 15291c05dae3SAli Ahmed { 153062598e31SEd Tanous BMCWEB_LOG_DEBUG("TPM.Policy service mapper error!"); 1531ac106bf6SEd Tanous messages::internalError(asyncResp->res); 15321c05dae3SAli Ahmed return; 15331c05dae3SAli Ahmed } 15341c05dae3SAli Ahmed 15351c05dae3SAli Ahmed // Valid TPM Enable object found, now setting the value 1536*e93abac6SGinu George setDbusProperty(asyncResp, "Boot/TrustedModuleRequiredToBoot", serv, 1537*e93abac6SGinu George path, "xyz.openbmc_project.Control.TPM.Policy", 1538*e93abac6SGinu George "TPMEnable", tpmRequired); 1539e99073f5SGeorge Liu }); 15401c05dae3SAli Ahmed } 15411c05dae3SAli Ahmed 15421c05dae3SAli Ahmed /** 1543491d8ee7SSantosh Puranik * @brief Sets boot properties into DBUS object(s). 1544491d8ee7SSantosh Puranik * 1545ac106bf6SEd Tanous * @param[in] asyncResp Shared pointer for generating response message. 1546cd9a4666SKonstantin Aladyshev * @param[in] bootType The boot type to set. 1547cd9a4666SKonstantin Aladyshev * @return Integer error code. 1548cd9a4666SKonstantin Aladyshev */ 1549ac106bf6SEd Tanous inline void setBootType(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 1550cd9a4666SKonstantin Aladyshev const std::optional<std::string>& bootType) 1551cd9a4666SKonstantin Aladyshev { 1552c21865c4SKonstantin Aladyshev std::string bootTypeStr; 1553cd9a4666SKonstantin Aladyshev 1554c21865c4SKonstantin Aladyshev if (!bootType) 1555cd9a4666SKonstantin Aladyshev { 1556c21865c4SKonstantin Aladyshev return; 1557c21865c4SKonstantin Aladyshev } 1558c21865c4SKonstantin Aladyshev 1559cd9a4666SKonstantin Aladyshev // Source target specified 156062598e31SEd Tanous BMCWEB_LOG_DEBUG("Boot type: {}", *bootType); 1561cd9a4666SKonstantin Aladyshev // Figure out which DBUS interface and property to use 1562cd9a4666SKonstantin Aladyshev if (*bootType == "Legacy") 1563cd9a4666SKonstantin Aladyshev { 1564cd9a4666SKonstantin Aladyshev bootTypeStr = "xyz.openbmc_project.Control.Boot.Type.Types.Legacy"; 1565cd9a4666SKonstantin Aladyshev } 1566cd9a4666SKonstantin Aladyshev else if (*bootType == "UEFI") 1567cd9a4666SKonstantin Aladyshev { 1568cd9a4666SKonstantin Aladyshev bootTypeStr = "xyz.openbmc_project.Control.Boot.Type.Types.EFI"; 1569cd9a4666SKonstantin Aladyshev } 1570cd9a4666SKonstantin Aladyshev else 1571cd9a4666SKonstantin Aladyshev { 157262598e31SEd Tanous BMCWEB_LOG_DEBUG("Invalid property value for " 157362598e31SEd Tanous "BootSourceOverrideMode: {}", 157462598e31SEd Tanous *bootType); 1575ac106bf6SEd Tanous messages::propertyValueNotInList(asyncResp->res, *bootType, 1576cd9a4666SKonstantin Aladyshev "BootSourceOverrideMode"); 1577cd9a4666SKonstantin Aladyshev return; 1578cd9a4666SKonstantin Aladyshev } 1579cd9a4666SKonstantin Aladyshev 1580cd9a4666SKonstantin Aladyshev // Act on validated parameters 158162598e31SEd Tanous BMCWEB_LOG_DEBUG("DBUS boot type: {}", bootTypeStr); 1582cd9a4666SKonstantin Aladyshev 1583*e93abac6SGinu George setDbusProperty(asyncResp, "Boot/BootSourceOverrideMode", 1584*e93abac6SGinu George "xyz.openbmc_project.Settings", 158587c44966SAsmitha Karunanithi sdbusplus::message::object_path( 158687c44966SAsmitha Karunanithi "/xyz/openbmc_project/control/host0/boot"), 158787c44966SAsmitha Karunanithi "xyz.openbmc_project.Control.Boot.Type", "BootType", 1588*e93abac6SGinu George bootTypeStr); 1589cd9a4666SKonstantin Aladyshev } 1590cd9a4666SKonstantin Aladyshev 1591cd9a4666SKonstantin Aladyshev /** 1592cd9a4666SKonstantin Aladyshev * @brief Sets boot properties into DBUS object(s). 1593cd9a4666SKonstantin Aladyshev * 1594ac106bf6SEd Tanous * @param[in] asyncResp Shared pointer for generating response 1595ac106bf6SEd Tanous * message. 1596c21865c4SKonstantin Aladyshev * @param[in] bootType The boot type to set. 1597c21865c4SKonstantin Aladyshev * @return Integer error code. 1598c21865c4SKonstantin Aladyshev */ 1599ac106bf6SEd Tanous inline void setBootEnable(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 1600c21865c4SKonstantin Aladyshev const std::optional<std::string>& bootEnable) 1601c21865c4SKonstantin Aladyshev { 1602c21865c4SKonstantin Aladyshev if (!bootEnable) 1603c21865c4SKonstantin Aladyshev { 1604c21865c4SKonstantin Aladyshev return; 1605c21865c4SKonstantin Aladyshev } 1606c21865c4SKonstantin Aladyshev // Source target specified 160762598e31SEd Tanous BMCWEB_LOG_DEBUG("Boot enable: {}", *bootEnable); 1608c21865c4SKonstantin Aladyshev 1609c21865c4SKonstantin Aladyshev bool bootOverrideEnable = false; 1610c21865c4SKonstantin Aladyshev bool bootOverridePersistent = false; 1611c21865c4SKonstantin Aladyshev // Figure out which DBUS interface and property to use 1612c21865c4SKonstantin Aladyshev if (*bootEnable == "Disabled") 1613c21865c4SKonstantin Aladyshev { 1614c21865c4SKonstantin Aladyshev bootOverrideEnable = false; 1615c21865c4SKonstantin Aladyshev } 1616c21865c4SKonstantin Aladyshev else if (*bootEnable == "Once") 1617c21865c4SKonstantin Aladyshev { 1618c21865c4SKonstantin Aladyshev bootOverrideEnable = true; 1619c21865c4SKonstantin Aladyshev bootOverridePersistent = false; 1620c21865c4SKonstantin Aladyshev } 1621c21865c4SKonstantin Aladyshev else if (*bootEnable == "Continuous") 1622c21865c4SKonstantin Aladyshev { 1623c21865c4SKonstantin Aladyshev bootOverrideEnable = true; 1624c21865c4SKonstantin Aladyshev bootOverridePersistent = true; 1625c21865c4SKonstantin Aladyshev } 1626c21865c4SKonstantin Aladyshev else 1627c21865c4SKonstantin Aladyshev { 162862598e31SEd Tanous BMCWEB_LOG_DEBUG( 162962598e31SEd Tanous "Invalid property value for BootSourceOverrideEnabled: {}", 163062598e31SEd Tanous *bootEnable); 1631ac106bf6SEd Tanous messages::propertyValueNotInList(asyncResp->res, *bootEnable, 1632c21865c4SKonstantin Aladyshev "BootSourceOverrideEnabled"); 1633c21865c4SKonstantin Aladyshev return; 1634c21865c4SKonstantin Aladyshev } 1635c21865c4SKonstantin Aladyshev 1636c21865c4SKonstantin Aladyshev // Act on validated parameters 163762598e31SEd Tanous BMCWEB_LOG_DEBUG("DBUS boot override enable: {}", bootOverrideEnable); 1638c21865c4SKonstantin Aladyshev 1639*e93abac6SGinu George setDbusProperty(asyncResp, "Boot/BootSourceOverrideEnabled", 1640*e93abac6SGinu George "xyz.openbmc_project.Settings", 164187c44966SAsmitha Karunanithi sdbusplus::message::object_path( 164287c44966SAsmitha Karunanithi "/xyz/openbmc_project/control/host0/boot"), 164387c44966SAsmitha Karunanithi "xyz.openbmc_project.Object.Enable", "Enabled", 1644*e93abac6SGinu George bootOverrideEnable); 1645c21865c4SKonstantin Aladyshev 1646c21865c4SKonstantin Aladyshev if (!bootOverrideEnable) 1647c21865c4SKonstantin Aladyshev { 1648c21865c4SKonstantin Aladyshev return; 1649c21865c4SKonstantin Aladyshev } 1650c21865c4SKonstantin Aladyshev 1651c21865c4SKonstantin Aladyshev // In case boot override is enabled we need to set correct value for the 1652c21865c4SKonstantin Aladyshev // 'one_time' enable DBus interface 165362598e31SEd Tanous BMCWEB_LOG_DEBUG("DBUS boot override persistent: {}", 165462598e31SEd Tanous bootOverridePersistent); 1655c21865c4SKonstantin Aladyshev 1656*e93abac6SGinu George setDbusProperty(asyncResp, "Boot/BootSourceOverrideEnabled", 1657*e93abac6SGinu George "xyz.openbmc_project.Settings", 165887c44966SAsmitha Karunanithi sdbusplus::message::object_path( 165987c44966SAsmitha Karunanithi "/xyz/openbmc_project/control/host0/boot/one_time"), 166087c44966SAsmitha Karunanithi "xyz.openbmc_project.Object.Enable", "Enabled", 1661*e93abac6SGinu George !bootOverridePersistent); 1662c21865c4SKonstantin Aladyshev } 1663c21865c4SKonstantin Aladyshev 1664c21865c4SKonstantin Aladyshev /** 1665c21865c4SKonstantin Aladyshev * @brief Sets boot properties into DBUS object(s). 1666c21865c4SKonstantin Aladyshev * 1667ac106bf6SEd Tanous * @param[in] asyncResp Shared pointer for generating response message. 1668491d8ee7SSantosh Puranik * @param[in] bootSource The boot source to set. 1669491d8ee7SSantosh Puranik * 1670265c1602SJohnathan Mantey * @return Integer error code. 1671491d8ee7SSantosh Puranik */ 1672ac106bf6SEd Tanous inline void 1673ac106bf6SEd Tanous setBootModeOrSource(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 1674cd9a4666SKonstantin Aladyshev const std::optional<std::string>& bootSource) 1675491d8ee7SSantosh Puranik { 1676c21865c4SKonstantin Aladyshev std::string bootSourceStr; 1677c21865c4SKonstantin Aladyshev std::string bootModeStr; 1678944ffaf9SJohnathan Mantey 1679c21865c4SKonstantin Aladyshev if (!bootSource) 1680491d8ee7SSantosh Puranik { 1681c21865c4SKonstantin Aladyshev return; 1682c21865c4SKonstantin Aladyshev } 1683c21865c4SKonstantin Aladyshev 1684491d8ee7SSantosh Puranik // Source target specified 168562598e31SEd Tanous BMCWEB_LOG_DEBUG("Boot source: {}", *bootSource); 1686491d8ee7SSantosh Puranik // Figure out which DBUS interface and property to use 1687ac106bf6SEd Tanous if (assignBootParameters(asyncResp, *bootSource, bootSourceStr, 1688ac106bf6SEd Tanous bootModeStr) != 0) 1689491d8ee7SSantosh Puranik { 169062598e31SEd Tanous BMCWEB_LOG_DEBUG( 169162598e31SEd Tanous "Invalid property value for BootSourceOverrideTarget: {}", 169262598e31SEd Tanous *bootSource); 1693ac106bf6SEd Tanous messages::propertyValueNotInList(asyncResp->res, *bootSource, 1694491d8ee7SSantosh Puranik "BootSourceTargetOverride"); 1695491d8ee7SSantosh Puranik return; 1696491d8ee7SSantosh Puranik } 1697491d8ee7SSantosh Puranik 1698944ffaf9SJohnathan Mantey // Act on validated parameters 169962598e31SEd Tanous BMCWEB_LOG_DEBUG("DBUS boot source: {}", bootSourceStr); 170062598e31SEd Tanous BMCWEB_LOG_DEBUG("DBUS boot mode: {}", bootModeStr); 1701944ffaf9SJohnathan Mantey 1702*e93abac6SGinu George setDbusProperty(asyncResp, "Boot/BootSourceOverrideTarget", 1703*e93abac6SGinu George "xyz.openbmc_project.Settings", 170487c44966SAsmitha Karunanithi sdbusplus::message::object_path( 170587c44966SAsmitha Karunanithi "/xyz/openbmc_project/control/host0/boot"), 170687c44966SAsmitha Karunanithi "xyz.openbmc_project.Control.Boot.Source", "BootSource", 1707*e93abac6SGinu George bootSourceStr); 1708*e93abac6SGinu George setDbusProperty(asyncResp, "Boot/BootSourceOverrideTarget", 1709*e93abac6SGinu George "xyz.openbmc_project.Settings", 171087c44966SAsmitha Karunanithi sdbusplus::message::object_path( 171187c44966SAsmitha Karunanithi "/xyz/openbmc_project/control/host0/boot"), 171287c44966SAsmitha Karunanithi "xyz.openbmc_project.Control.Boot.Mode", "BootMode", 1713*e93abac6SGinu George bootModeStr); 1714cd9a4666SKonstantin Aladyshev } 1715944ffaf9SJohnathan Mantey 1716cd9a4666SKonstantin Aladyshev /** 1717c21865c4SKonstantin Aladyshev * @brief Sets Boot source override properties. 1718491d8ee7SSantosh Puranik * 1719ac106bf6SEd Tanous * @param[in] asyncResp Shared pointer for generating response message. 1720491d8ee7SSantosh Puranik * @param[in] bootSource The boot source from incoming RF request. 1721cd9a4666SKonstantin Aladyshev * @param[in] bootType The boot type from incoming RF request. 1722491d8ee7SSantosh Puranik * @param[in] bootEnable The boot override enable from incoming RF request. 1723491d8ee7SSantosh Puranik * 1724265c1602SJohnathan Mantey * @return Integer error code. 1725491d8ee7SSantosh Puranik */ 1726c21865c4SKonstantin Aladyshev 1727ac106bf6SEd Tanous inline void 1728ac106bf6SEd Tanous setBootProperties(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 1729c21865c4SKonstantin Aladyshev const std::optional<std::string>& bootSource, 1730c21865c4SKonstantin Aladyshev const std::optional<std::string>& bootType, 1731c21865c4SKonstantin Aladyshev const std::optional<std::string>& bootEnable) 1732491d8ee7SSantosh Puranik { 173362598e31SEd Tanous BMCWEB_LOG_DEBUG("Set boot information."); 1734491d8ee7SSantosh Puranik 1735ac106bf6SEd Tanous setBootModeOrSource(asyncResp, bootSource); 1736ac106bf6SEd Tanous setBootType(asyncResp, bootType); 1737ac106bf6SEd Tanous setBootEnable(asyncResp, bootEnable); 1738491d8ee7SSantosh Puranik } 1739491d8ee7SSantosh Puranik 1740c6a620f2SGeorge Liu /** 174198e386ecSGunnar Mills * @brief Sets AssetTag 174298e386ecSGunnar Mills * 1743ac106bf6SEd Tanous * @param[in] asyncResp Shared pointer for generating response message. 174498e386ecSGunnar Mills * @param[in] assetTag "AssetTag" from request. 174598e386ecSGunnar Mills * 174698e386ecSGunnar Mills * @return None. 174798e386ecSGunnar Mills */ 1748ac106bf6SEd Tanous inline void setAssetTag(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 174998e386ecSGunnar Mills const std::string& assetTag) 175098e386ecSGunnar Mills { 1751e99073f5SGeorge Liu constexpr std::array<std::string_view, 1> interfaces = { 1752e99073f5SGeorge Liu "xyz.openbmc_project.Inventory.Item.System"}; 1753e99073f5SGeorge Liu dbus::utility::getSubTree( 1754e99073f5SGeorge Liu "/xyz/openbmc_project/inventory", 0, interfaces, 1755ac106bf6SEd Tanous [asyncResp, 1756e99073f5SGeorge Liu assetTag](const boost::system::error_code& ec, 1757b9d36b47SEd Tanous const dbus::utility::MapperGetSubTreeResponse& subtree) { 175898e386ecSGunnar Mills if (ec) 175998e386ecSGunnar Mills { 176062598e31SEd Tanous BMCWEB_LOG_DEBUG("D-Bus response error on GetSubTree {}", ec); 1761ac106bf6SEd Tanous messages::internalError(asyncResp->res); 176298e386ecSGunnar Mills return; 176398e386ecSGunnar Mills } 176426f6976fSEd Tanous if (subtree.empty()) 176598e386ecSGunnar Mills { 176662598e31SEd Tanous BMCWEB_LOG_DEBUG("Can't find system D-Bus object!"); 1767ac106bf6SEd Tanous messages::internalError(asyncResp->res); 176898e386ecSGunnar Mills return; 176998e386ecSGunnar Mills } 177098e386ecSGunnar Mills // Assume only 1 system D-Bus object 177198e386ecSGunnar Mills // Throw an error if there is more than 1 177298e386ecSGunnar Mills if (subtree.size() > 1) 177398e386ecSGunnar Mills { 177462598e31SEd Tanous BMCWEB_LOG_DEBUG("Found more than 1 system D-Bus object!"); 1775ac106bf6SEd Tanous messages::internalError(asyncResp->res); 177698e386ecSGunnar Mills return; 177798e386ecSGunnar Mills } 177898e386ecSGunnar Mills if (subtree[0].first.empty() || subtree[0].second.size() != 1) 177998e386ecSGunnar Mills { 178062598e31SEd Tanous BMCWEB_LOG_DEBUG("Asset Tag Set mapper error!"); 1781ac106bf6SEd Tanous messages::internalError(asyncResp->res); 178298e386ecSGunnar Mills return; 178398e386ecSGunnar Mills } 178498e386ecSGunnar Mills 178598e386ecSGunnar Mills const std::string& path = subtree[0].first; 178698e386ecSGunnar Mills const std::string& service = subtree[0].second.begin()->first; 178798e386ecSGunnar Mills 178898e386ecSGunnar Mills if (service.empty()) 178998e386ecSGunnar Mills { 179062598e31SEd Tanous BMCWEB_LOG_DEBUG("Asset Tag Set service mapper error!"); 1791ac106bf6SEd Tanous messages::internalError(asyncResp->res); 179298e386ecSGunnar Mills return; 179398e386ecSGunnar Mills } 179498e386ecSGunnar Mills 1795*e93abac6SGinu George setDbusProperty(asyncResp, "AssetTag", service, path, 179687c44966SAsmitha Karunanithi "xyz.openbmc_project.Inventory.Decorator.AssetTag", 1797*e93abac6SGinu George "AssetTag", assetTag); 1798e99073f5SGeorge Liu }); 179998e386ecSGunnar Mills } 180098e386ecSGunnar Mills 180198e386ecSGunnar Mills /** 18029dcfe8c1SAlbert Zhang * @brief Validate the specified stopBootOnFault is valid and return the 18039dcfe8c1SAlbert Zhang * stopBootOnFault name associated with that string 18049dcfe8c1SAlbert Zhang * 18059dcfe8c1SAlbert Zhang * @param[in] stopBootOnFaultString String representing the desired 18069dcfe8c1SAlbert Zhang * stopBootOnFault 18079dcfe8c1SAlbert Zhang * 18089dcfe8c1SAlbert Zhang * @return stopBootOnFault value or empty if incoming value is not valid 18099dcfe8c1SAlbert Zhang */ 18109dcfe8c1SAlbert Zhang inline std::optional<bool> 18119dcfe8c1SAlbert Zhang validstopBootOnFault(const std::string& stopBootOnFaultString) 18129dcfe8c1SAlbert Zhang { 18139dcfe8c1SAlbert Zhang if (stopBootOnFaultString == "AnyFault") 18149dcfe8c1SAlbert Zhang { 18159dcfe8c1SAlbert Zhang return true; 18169dcfe8c1SAlbert Zhang } 18179dcfe8c1SAlbert Zhang 18189dcfe8c1SAlbert Zhang if (stopBootOnFaultString == "Never") 18199dcfe8c1SAlbert Zhang { 18209dcfe8c1SAlbert Zhang return false; 18219dcfe8c1SAlbert Zhang } 18229dcfe8c1SAlbert Zhang 18239dcfe8c1SAlbert Zhang return std::nullopt; 18249dcfe8c1SAlbert Zhang } 18259dcfe8c1SAlbert Zhang 18269dcfe8c1SAlbert Zhang /** 18279dcfe8c1SAlbert Zhang * @brief Sets stopBootOnFault 18289dcfe8c1SAlbert Zhang * 1829fc3edfddSEd Tanous * @param[in] asyncResp Shared pointer for generating response message. 18309dcfe8c1SAlbert Zhang * @param[in] stopBootOnFault "StopBootOnFault" from request. 18319dcfe8c1SAlbert Zhang * 18329dcfe8c1SAlbert Zhang * @return None. 18339dcfe8c1SAlbert Zhang */ 1834fc3edfddSEd Tanous inline void 1835fc3edfddSEd Tanous setStopBootOnFault(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 18369dcfe8c1SAlbert Zhang const std::string& stopBootOnFault) 18379dcfe8c1SAlbert Zhang { 183862598e31SEd Tanous BMCWEB_LOG_DEBUG("Set Stop Boot On Fault."); 18399dcfe8c1SAlbert Zhang 18409dcfe8c1SAlbert Zhang std::optional<bool> stopBootEnabled = validstopBootOnFault(stopBootOnFault); 18419dcfe8c1SAlbert Zhang if (!stopBootEnabled) 18429dcfe8c1SAlbert Zhang { 184362598e31SEd Tanous BMCWEB_LOG_DEBUG("Invalid property value for StopBootOnFault: {}", 184462598e31SEd Tanous stopBootOnFault); 1845fc3edfddSEd Tanous messages::propertyValueNotInList(asyncResp->res, stopBootOnFault, 18469dcfe8c1SAlbert Zhang "StopBootOnFault"); 18479dcfe8c1SAlbert Zhang return; 18489dcfe8c1SAlbert Zhang } 18499dcfe8c1SAlbert Zhang 1850*e93abac6SGinu George setDbusProperty(asyncResp, "Boot/StopBootOnFault", 1851*e93abac6SGinu George "xyz.openbmc_project.Settings", 185287c44966SAsmitha Karunanithi sdbusplus::message::object_path( 185387c44966SAsmitha Karunanithi "/xyz/openbmc_project/logging/settings"), 1854fc3edfddSEd Tanous "xyz.openbmc_project.Logging.Settings", "QuiesceOnHwError", 1855*e93abac6SGinu George *stopBootEnabled); 18569dcfe8c1SAlbert Zhang } 18579dcfe8c1SAlbert Zhang 18589dcfe8c1SAlbert Zhang /** 185969f35306SGunnar Mills * @brief Sets automaticRetry (Auto Reboot) 186069f35306SGunnar Mills * 1861ac106bf6SEd Tanous * @param[in] asyncResp Shared pointer for generating response message. 186269f35306SGunnar Mills * @param[in] automaticRetryConfig "AutomaticRetryConfig" from request. 186369f35306SGunnar Mills * 186469f35306SGunnar Mills * @return None. 186569f35306SGunnar Mills */ 1866ac106bf6SEd Tanous inline void 1867ac106bf6SEd Tanous setAutomaticRetry(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 1868f23b7296SEd Tanous const std::string& automaticRetryConfig) 186969f35306SGunnar Mills { 187062598e31SEd Tanous BMCWEB_LOG_DEBUG("Set Automatic Retry."); 187169f35306SGunnar Mills 187269f35306SGunnar Mills // OpenBMC only supports "Disabled" and "RetryAttempts". 1873543f4400SEd Tanous bool autoRebootEnabled = false; 187469f35306SGunnar Mills 187569f35306SGunnar Mills if (automaticRetryConfig == "Disabled") 187669f35306SGunnar Mills { 187769f35306SGunnar Mills autoRebootEnabled = false; 187869f35306SGunnar Mills } 187969f35306SGunnar Mills else if (automaticRetryConfig == "RetryAttempts") 188069f35306SGunnar Mills { 188169f35306SGunnar Mills autoRebootEnabled = true; 188269f35306SGunnar Mills } 188369f35306SGunnar Mills else 188469f35306SGunnar Mills { 188562598e31SEd Tanous BMCWEB_LOG_DEBUG("Invalid property value for AutomaticRetryConfig: {}", 188662598e31SEd Tanous automaticRetryConfig); 1887ac106bf6SEd Tanous messages::propertyValueNotInList(asyncResp->res, automaticRetryConfig, 188869f35306SGunnar Mills "AutomaticRetryConfig"); 188969f35306SGunnar Mills return; 189069f35306SGunnar Mills } 189169f35306SGunnar Mills 1892*e93abac6SGinu George setDbusProperty(asyncResp, "Boot/AutomaticRetryConfig", 1893*e93abac6SGinu George "xyz.openbmc_project.Settings", 189487c44966SAsmitha Karunanithi sdbusplus::message::object_path( 189587c44966SAsmitha Karunanithi "/xyz/openbmc_project/control/host0/auto_reboot"), 189687c44966SAsmitha Karunanithi "xyz.openbmc_project.Control.Boot.RebootPolicy", 1897*e93abac6SGinu George "AutoReboot", autoRebootEnabled); 189869f35306SGunnar Mills } 189969f35306SGunnar Mills 19008d69c668SEd Tanous inline std::string dbusPowerRestorePolicyFromRedfish(std::string_view policy) 19018d69c668SEd Tanous { 19028d69c668SEd Tanous if (policy == "AlwaysOn") 19038d69c668SEd Tanous { 19048d69c668SEd Tanous return "xyz.openbmc_project.Control.Power.RestorePolicy.Policy.AlwaysOn"; 19058d69c668SEd Tanous } 19068d69c668SEd Tanous if (policy == "AlwaysOff") 19078d69c668SEd Tanous { 19088d69c668SEd Tanous return "xyz.openbmc_project.Control.Power.RestorePolicy.Policy.AlwaysOff"; 19098d69c668SEd Tanous } 19108d69c668SEd Tanous if (policy == "LastState") 19118d69c668SEd Tanous { 19128d69c668SEd Tanous return "xyz.openbmc_project.Control.Power.RestorePolicy.Policy.Restore"; 19138d69c668SEd Tanous } 19148d69c668SEd Tanous return ""; 19158d69c668SEd Tanous } 19168d69c668SEd Tanous 191769f35306SGunnar Mills /** 1918c6a620f2SGeorge Liu * @brief Sets power restore policy properties. 1919c6a620f2SGeorge Liu * 1920ac106bf6SEd Tanous * @param[in] asyncResp Shared pointer for generating response message. 1921c6a620f2SGeorge Liu * @param[in] policy power restore policy properties from request. 1922c6a620f2SGeorge Liu * 1923c6a620f2SGeorge Liu * @return None. 1924c6a620f2SGeorge Liu */ 19258d1b46d7Szhanghch05 inline void 1926ac106bf6SEd Tanous setPowerRestorePolicy(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 19278d69c668SEd Tanous std::string_view policy) 1928c6a620f2SGeorge Liu { 192962598e31SEd Tanous BMCWEB_LOG_DEBUG("Set power restore policy."); 1930c6a620f2SGeorge Liu 19318d69c668SEd Tanous std::string powerRestorePolicy = dbusPowerRestorePolicyFromRedfish(policy); 1932c6a620f2SGeorge Liu 19338d69c668SEd Tanous if (powerRestorePolicy.empty()) 1934c6a620f2SGeorge Liu { 1935ac106bf6SEd Tanous messages::propertyValueNotInList(asyncResp->res, policy, 19364e69c904SGunnar Mills "PowerRestorePolicy"); 1937c6a620f2SGeorge Liu return; 1938c6a620f2SGeorge Liu } 1939c6a620f2SGeorge Liu 194087c44966SAsmitha Karunanithi setDbusProperty( 1941*e93abac6SGinu George asyncResp, "PowerRestorePolicy", "xyz.openbmc_project.Settings", 194287c44966SAsmitha Karunanithi sdbusplus::message::object_path( 194387c44966SAsmitha Karunanithi "/xyz/openbmc_project/control/host0/power_restore_policy"), 19449ae226faSGeorge Liu "xyz.openbmc_project.Control.Power.RestorePolicy", "PowerRestorePolicy", 1945*e93abac6SGinu George powerRestorePolicy); 1946c6a620f2SGeorge Liu } 1947c6a620f2SGeorge Liu 1948a6349918SAppaRao Puli /** 1949a6349918SAppaRao Puli * @brief Retrieves provisioning status 1950a6349918SAppaRao Puli * 195125b54dbaSEd Tanous * @param[in] asyncResp Shared pointer for completing asynchronous 195225b54dbaSEd Tanous * calls. 1953a6349918SAppaRao Puli * 1954a6349918SAppaRao Puli * @return None. 1955a6349918SAppaRao Puli */ 195625b54dbaSEd Tanous inline void 195725b54dbaSEd Tanous getProvisioningStatus(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) 1958a6349918SAppaRao Puli { 195962598e31SEd Tanous BMCWEB_LOG_DEBUG("Get OEM information."); 1960bc1d29deSKrzysztof Grobelny sdbusplus::asio::getAllProperties( 1961bc1d29deSKrzysztof Grobelny *crow::connections::systemBus, "xyz.openbmc_project.PFR.Manager", 1962bc1d29deSKrzysztof Grobelny "/xyz/openbmc_project/pfr", "xyz.openbmc_project.PFR.Attributes", 1963ac106bf6SEd Tanous [asyncResp](const boost::system::error_code& ec, 1964b9d36b47SEd Tanous const dbus::utility::DBusPropertiesMap& propertiesList) { 1965b99fb1a9SAppaRao Puli nlohmann::json& oemPFR = 1966ac106bf6SEd Tanous asyncResp->res.jsonValue["Oem"]["OpenBmc"]["FirmwareProvisioning"]; 1967ac106bf6SEd Tanous asyncResp->res.jsonValue["Oem"]["OpenBmc"]["@odata.type"] = 196850626f4fSJames Feist "#OemComputerSystem.OpenBmc"; 196950626f4fSJames Feist oemPFR["@odata.type"] = "#OemComputerSystem.FirmwareProvisioning"; 197050626f4fSJames Feist 1971a6349918SAppaRao Puli if (ec) 1972a6349918SAppaRao Puli { 197362598e31SEd Tanous BMCWEB_LOG_DEBUG("DBUS response error {}", ec); 1974b99fb1a9SAppaRao Puli // not an error, don't have to have the interface 1975b99fb1a9SAppaRao Puli oemPFR["ProvisioningStatus"] = "NotProvisioned"; 1976a6349918SAppaRao Puli return; 1977a6349918SAppaRao Puli } 1978a6349918SAppaRao Puli 1979a6349918SAppaRao Puli const bool* provState = nullptr; 1980a6349918SAppaRao Puli const bool* lockState = nullptr; 1981bc1d29deSKrzysztof Grobelny 1982bc1d29deSKrzysztof Grobelny const bool success = sdbusplus::unpackPropertiesNoThrow( 19830d4befa8SJiaqing Zhao dbus_utils::UnpackErrorPrinter(), propertiesList, "UfmProvisioned", 19840d4befa8SJiaqing Zhao provState, "UfmLocked", lockState); 1985bc1d29deSKrzysztof Grobelny 1986bc1d29deSKrzysztof Grobelny if (!success) 1987a6349918SAppaRao Puli { 1988ac106bf6SEd Tanous messages::internalError(asyncResp->res); 1989bc1d29deSKrzysztof Grobelny return; 1990a6349918SAppaRao Puli } 1991a6349918SAppaRao Puli 1992a6349918SAppaRao Puli if ((provState == nullptr) || (lockState == nullptr)) 1993a6349918SAppaRao Puli { 199462598e31SEd Tanous BMCWEB_LOG_DEBUG("Unable to get PFR attributes."); 1995ac106bf6SEd Tanous messages::internalError(asyncResp->res); 1996a6349918SAppaRao Puli return; 1997a6349918SAppaRao Puli } 1998a6349918SAppaRao Puli 199925b54dbaSEd Tanous if (*provState) 2000a6349918SAppaRao Puli { 200125b54dbaSEd Tanous if (*lockState) 2002a6349918SAppaRao Puli { 2003a6349918SAppaRao Puli oemPFR["ProvisioningStatus"] = "ProvisionedAndLocked"; 2004a6349918SAppaRao Puli } 2005a6349918SAppaRao Puli else 2006a6349918SAppaRao Puli { 2007a6349918SAppaRao Puli oemPFR["ProvisioningStatus"] = "ProvisionedButNotLocked"; 2008a6349918SAppaRao Puli } 2009a6349918SAppaRao Puli } 2010a6349918SAppaRao Puli else 2011a6349918SAppaRao Puli { 2012a6349918SAppaRao Puli oemPFR["ProvisioningStatus"] = "NotProvisioned"; 2013a6349918SAppaRao Puli } 2014bc1d29deSKrzysztof Grobelny }); 2015a6349918SAppaRao Puli } 2016a6349918SAppaRao Puli 2017491d8ee7SSantosh Puranik /** 20186b9ac4f2SChris Cain * @brief Translate the PowerMode string to enum value 20193a2d0424SChris Cain * 20206b9ac4f2SChris Cain * @param[in] modeString PowerMode string to be translated 20213a2d0424SChris Cain * 20226b9ac4f2SChris Cain * @return PowerMode enum 20233a2d0424SChris Cain */ 20246b9ac4f2SChris Cain inline computer_system::PowerMode 20256b9ac4f2SChris Cain translatePowerModeString(const std::string& modeString) 20263a2d0424SChris Cain { 2027b6655101SChris Cain using PowerMode = computer_system::PowerMode; 2028b6655101SChris Cain 20296b9ac4f2SChris Cain if (modeString == "xyz.openbmc_project.Control.Power.Mode.PowerMode.Static") 20303a2d0424SChris Cain { 20316b9ac4f2SChris Cain return PowerMode::Static; 20323a2d0424SChris Cain } 20336b9ac4f2SChris Cain if (modeString == 20340fda0f12SGeorge Liu "xyz.openbmc_project.Control.Power.Mode.PowerMode.MaximumPerformance") 20353a2d0424SChris Cain { 20366b9ac4f2SChris Cain return PowerMode::MaximumPerformance; 20373a2d0424SChris Cain } 20386b9ac4f2SChris Cain if (modeString == 20390fda0f12SGeorge Liu "xyz.openbmc_project.Control.Power.Mode.PowerMode.PowerSaving") 20403a2d0424SChris Cain { 20416b9ac4f2SChris Cain return PowerMode::PowerSaving; 2042b6655101SChris Cain } 20436b9ac4f2SChris Cain if (modeString == 2044b6655101SChris Cain "xyz.openbmc_project.Control.Power.Mode.PowerMode.BalancedPerformance") 2045b6655101SChris Cain { 20466b9ac4f2SChris Cain return PowerMode::BalancedPerformance; 2047b6655101SChris Cain } 20486b9ac4f2SChris Cain if (modeString == 2049b6655101SChris Cain "xyz.openbmc_project.Control.Power.Mode.PowerMode.EfficiencyFavorPerformance") 2050b6655101SChris Cain { 20516b9ac4f2SChris Cain return PowerMode::EfficiencyFavorPerformance; 2052b6655101SChris Cain } 20536b9ac4f2SChris Cain if (modeString == 2054b6655101SChris Cain "xyz.openbmc_project.Control.Power.Mode.PowerMode.EfficiencyFavorPower") 2055b6655101SChris Cain { 20566b9ac4f2SChris Cain return PowerMode::EfficiencyFavorPower; 20573a2d0424SChris Cain } 20586b9ac4f2SChris Cain if (modeString == "xyz.openbmc_project.Control.Power.Mode.PowerMode.OEM") 20593a2d0424SChris Cain { 20606b9ac4f2SChris Cain return PowerMode::OEM; 20616b9ac4f2SChris Cain } 20626b9ac4f2SChris Cain // Any other values would be invalid 20636b9ac4f2SChris Cain BMCWEB_LOG_ERROR("PowerMode value was not valid: {}", modeString); 20646b9ac4f2SChris Cain return PowerMode::Invalid; 20656b9ac4f2SChris Cain } 20666b9ac4f2SChris Cain 20676b9ac4f2SChris Cain inline void 20686b9ac4f2SChris Cain afterGetPowerMode(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 20696b9ac4f2SChris Cain const boost::system::error_code& ec, 20706b9ac4f2SChris Cain const dbus::utility::DBusPropertiesMap& properties) 20716b9ac4f2SChris Cain { 20726b9ac4f2SChris Cain if (ec) 20736b9ac4f2SChris Cain { 20746b9ac4f2SChris Cain BMCWEB_LOG_ERROR("DBUS response error on PowerMode GetAll: {}", ec); 20756b9ac4f2SChris Cain messages::internalError(asyncResp->res); 20766b9ac4f2SChris Cain return; 20776b9ac4f2SChris Cain } 20786b9ac4f2SChris Cain 20796b9ac4f2SChris Cain std::string powerMode; 20806b9ac4f2SChris Cain const std::vector<std::string>* allowedModes = nullptr; 20816b9ac4f2SChris Cain const bool success = sdbusplus::unpackPropertiesNoThrow( 20826b9ac4f2SChris Cain dbus_utils::UnpackErrorPrinter(), properties, "PowerMode", powerMode, 20836b9ac4f2SChris Cain "AllowedPowerModes", allowedModes); 20846b9ac4f2SChris Cain 20856b9ac4f2SChris Cain if (!success) 20866b9ac4f2SChris Cain { 20876b9ac4f2SChris Cain messages::internalError(asyncResp->res); 20886b9ac4f2SChris Cain return; 20896b9ac4f2SChris Cain } 20906b9ac4f2SChris Cain 20916b9ac4f2SChris Cain nlohmann::json::array_t modeList; 20926b9ac4f2SChris Cain if (allowedModes == nullptr) 20936b9ac4f2SChris Cain { 20946b9ac4f2SChris Cain modeList.emplace_back("Static"); 20956b9ac4f2SChris Cain modeList.emplace_back("MaximumPerformance"); 20966b9ac4f2SChris Cain modeList.emplace_back("PowerSaving"); 20973a2d0424SChris Cain } 20983a2d0424SChris Cain else 20993a2d0424SChris Cain { 21006b9ac4f2SChris Cain for (const auto& aMode : *allowedModes) 21016b9ac4f2SChris Cain { 21026b9ac4f2SChris Cain computer_system::PowerMode modeValue = 21036b9ac4f2SChris Cain translatePowerModeString(aMode); 21046b9ac4f2SChris Cain if (modeValue == computer_system::PowerMode::Invalid) 21056b9ac4f2SChris Cain { 2106ac106bf6SEd Tanous messages::internalError(asyncResp->res); 21076b9ac4f2SChris Cain continue; 21086b9ac4f2SChris Cain } 21096b9ac4f2SChris Cain modeList.emplace_back(modeValue); 21103a2d0424SChris Cain } 21113a2d0424SChris Cain } 21126b9ac4f2SChris Cain asyncResp->res.jsonValue["PowerMode@Redfish.AllowableValues"] = modeList; 21133a2d0424SChris Cain 21146b9ac4f2SChris Cain BMCWEB_LOG_DEBUG("Current power mode: {}", powerMode); 21156b9ac4f2SChris Cain const computer_system::PowerMode modeValue = 21166b9ac4f2SChris Cain translatePowerModeString(powerMode); 21176b9ac4f2SChris Cain if (modeValue == computer_system::PowerMode::Invalid) 21186b9ac4f2SChris Cain { 21196b9ac4f2SChris Cain messages::internalError(asyncResp->res); 21206b9ac4f2SChris Cain return; 21216b9ac4f2SChris Cain } 21226b9ac4f2SChris Cain asyncResp->res.jsonValue["PowerMode"] = modeValue; 21236b9ac4f2SChris Cain } 21243a2d0424SChris Cain /** 21253a2d0424SChris Cain * @brief Retrieves system power mode 21263a2d0424SChris Cain * 2127ac106bf6SEd Tanous * @param[in] asyncResp Shared pointer for generating response message. 21283a2d0424SChris Cain * 21293a2d0424SChris Cain * @return None. 21303a2d0424SChris Cain */ 2131ac106bf6SEd Tanous inline void getPowerMode(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) 21323a2d0424SChris Cain { 213362598e31SEd Tanous BMCWEB_LOG_DEBUG("Get power mode."); 21343a2d0424SChris Cain 21353a2d0424SChris Cain // Get Power Mode object path: 2136e99073f5SGeorge Liu constexpr std::array<std::string_view, 1> interfaces = { 2137e99073f5SGeorge Liu "xyz.openbmc_project.Control.Power.Mode"}; 2138e99073f5SGeorge Liu dbus::utility::getSubTree( 2139e99073f5SGeorge Liu "/", 0, interfaces, 2140ac106bf6SEd Tanous [asyncResp](const boost::system::error_code& ec, 2141b9d36b47SEd Tanous const dbus::utility::MapperGetSubTreeResponse& subtree) { 21423a2d0424SChris Cain if (ec) 21433a2d0424SChris Cain { 214462598e31SEd Tanous BMCWEB_LOG_DEBUG("DBUS response error on Power.Mode GetSubTree {}", 214562598e31SEd Tanous ec); 21463a2d0424SChris Cain // This is an optional D-Bus object so just return if 21473a2d0424SChris Cain // error occurs 21483a2d0424SChris Cain return; 21493a2d0424SChris Cain } 21503a2d0424SChris Cain if (subtree.empty()) 21513a2d0424SChris Cain { 21523a2d0424SChris Cain // As noted above, this is an optional interface so just return 21533a2d0424SChris Cain // if there is no instance found 21543a2d0424SChris Cain return; 21553a2d0424SChris Cain } 21563a2d0424SChris Cain if (subtree.size() > 1) 21573a2d0424SChris Cain { 21583a2d0424SChris Cain // More then one PowerMode object is not supported and is an 21593a2d0424SChris Cain // error 216062598e31SEd Tanous BMCWEB_LOG_DEBUG( 216162598e31SEd Tanous "Found more than 1 system D-Bus Power.Mode objects: {}", 216262598e31SEd Tanous subtree.size()); 2163ac106bf6SEd Tanous messages::internalError(asyncResp->res); 21643a2d0424SChris Cain return; 21653a2d0424SChris Cain } 21663a2d0424SChris Cain if ((subtree[0].first.empty()) || (subtree[0].second.size() != 1)) 21673a2d0424SChris Cain { 216862598e31SEd Tanous BMCWEB_LOG_DEBUG("Power.Mode mapper error!"); 2169ac106bf6SEd Tanous messages::internalError(asyncResp->res); 21703a2d0424SChris Cain return; 21713a2d0424SChris Cain } 21723a2d0424SChris Cain const std::string& path = subtree[0].first; 21733a2d0424SChris Cain const std::string& service = subtree[0].second.begin()->first; 21743a2d0424SChris Cain if (service.empty()) 21753a2d0424SChris Cain { 217662598e31SEd Tanous BMCWEB_LOG_DEBUG("Power.Mode service mapper error!"); 2177ac106bf6SEd Tanous messages::internalError(asyncResp->res); 21783a2d0424SChris Cain return; 21793a2d0424SChris Cain } 21806b9ac4f2SChris Cain 21816b9ac4f2SChris Cain // Valid Power Mode object found, now read the mode properties 21826b9ac4f2SChris Cain sdbusplus::asio::getAllProperties( 21831e1e598dSJonathan Doman *crow::connections::systemBus, service, path, 21846b9ac4f2SChris Cain "xyz.openbmc_project.Control.Power.Mode", 2185ac106bf6SEd Tanous [asyncResp](const boost::system::error_code& ec2, 21866b9ac4f2SChris Cain const dbus::utility::DBusPropertiesMap& properties) { 21876b9ac4f2SChris Cain afterGetPowerMode(asyncResp, ec2, properties); 21881e1e598dSJonathan Doman }); 2189e99073f5SGeorge Liu }); 21903a2d0424SChris Cain } 21913a2d0424SChris Cain 21923a2d0424SChris Cain /** 21933a2d0424SChris Cain * @brief Validate the specified mode is valid and return the PowerMode 21943a2d0424SChris Cain * name associated with that string 21953a2d0424SChris Cain * 2196ac106bf6SEd Tanous * @param[in] asyncResp Shared pointer for generating response message. 2197b6655101SChris Cain * @param[in] modeValue String representing the desired PowerMode 21983a2d0424SChris Cain * 21993a2d0424SChris Cain * @return PowerMode value or empty string if mode is not valid 22003a2d0424SChris Cain */ 22013a2d0424SChris Cain inline std::string 2202ac106bf6SEd Tanous validatePowerMode(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 2203b6655101SChris Cain const nlohmann::json& modeValue) 22043a2d0424SChris Cain { 2205b6655101SChris Cain using PowerMode = computer_system::PowerMode; 22063a2d0424SChris Cain std::string mode; 22073a2d0424SChris Cain 2208b6655101SChris Cain if (modeValue == PowerMode::Static) 22093a2d0424SChris Cain { 22103a2d0424SChris Cain mode = "xyz.openbmc_project.Control.Power.Mode.PowerMode.Static"; 22113a2d0424SChris Cain } 2212b6655101SChris Cain else if (modeValue == PowerMode::MaximumPerformance) 22133a2d0424SChris Cain { 22140fda0f12SGeorge Liu mode = 22150fda0f12SGeorge Liu "xyz.openbmc_project.Control.Power.Mode.PowerMode.MaximumPerformance"; 22163a2d0424SChris Cain } 2217b6655101SChris Cain else if (modeValue == PowerMode::PowerSaving) 22183a2d0424SChris Cain { 22193a2d0424SChris Cain mode = "xyz.openbmc_project.Control.Power.Mode.PowerMode.PowerSaving"; 22203a2d0424SChris Cain } 2221b6655101SChris Cain else if (modeValue == PowerMode::BalancedPerformance) 2222b6655101SChris Cain { 2223b6655101SChris Cain mode = 2224b6655101SChris Cain "xyz.openbmc_project.Control.Power.Mode.PowerMode.BalancedPerformance"; 2225b6655101SChris Cain } 2226b6655101SChris Cain else if (modeValue == PowerMode::EfficiencyFavorPerformance) 2227b6655101SChris Cain { 2228b6655101SChris Cain mode = 2229b6655101SChris Cain "xyz.openbmc_project.Control.Power.Mode.PowerMode.EfficiencyFavorPerformance"; 2230b6655101SChris Cain } 2231b6655101SChris Cain else if (modeValue == PowerMode::EfficiencyFavorPower) 2232b6655101SChris Cain { 2233b6655101SChris Cain mode = 2234b6655101SChris Cain "xyz.openbmc_project.Control.Power.Mode.PowerMode.EfficiencyFavorPower"; 2235b6655101SChris Cain } 22363a2d0424SChris Cain else 22373a2d0424SChris Cain { 2238b6655101SChris Cain messages::propertyValueNotInList(asyncResp->res, modeValue.dump(), 2239ac106bf6SEd Tanous "PowerMode"); 22403a2d0424SChris Cain } 22413a2d0424SChris Cain return mode; 22423a2d0424SChris Cain } 22433a2d0424SChris Cain 22443a2d0424SChris Cain /** 22453a2d0424SChris Cain * @brief Sets system power mode. 22463a2d0424SChris Cain * 2247ac106bf6SEd Tanous * @param[in] asyncResp Shared pointer for generating response message. 22483a2d0424SChris Cain * @param[in] pmode System power mode from request. 22493a2d0424SChris Cain * 22503a2d0424SChris Cain * @return None. 22513a2d0424SChris Cain */ 2252ac106bf6SEd Tanous inline void setPowerMode(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 22533a2d0424SChris Cain const std::string& pmode) 22543a2d0424SChris Cain { 225562598e31SEd Tanous BMCWEB_LOG_DEBUG("Set power mode."); 22563a2d0424SChris Cain 2257ac106bf6SEd Tanous std::string powerMode = validatePowerMode(asyncResp, pmode); 22583a2d0424SChris Cain if (powerMode.empty()) 22593a2d0424SChris Cain { 22603a2d0424SChris Cain return; 22613a2d0424SChris Cain } 22623a2d0424SChris Cain 22633a2d0424SChris Cain // Get Power Mode object path: 2264e99073f5SGeorge Liu constexpr std::array<std::string_view, 1> interfaces = { 2265e99073f5SGeorge Liu "xyz.openbmc_project.Control.Power.Mode"}; 2266e99073f5SGeorge Liu dbus::utility::getSubTree( 2267e99073f5SGeorge Liu "/", 0, interfaces, 2268ac106bf6SEd Tanous [asyncResp, 2269e99073f5SGeorge Liu powerMode](const boost::system::error_code& ec, 2270b9d36b47SEd Tanous const dbus::utility::MapperGetSubTreeResponse& subtree) { 22713a2d0424SChris Cain if (ec) 22723a2d0424SChris Cain { 2273b3e86cb0SGunnar Mills BMCWEB_LOG_ERROR("DBUS response error on Power.Mode GetSubTree {}", 227462598e31SEd Tanous ec); 22753a2d0424SChris Cain // This is an optional D-Bus object, but user attempted to patch 2276ac106bf6SEd Tanous messages::internalError(asyncResp->res); 22773a2d0424SChris Cain return; 22783a2d0424SChris Cain } 22793a2d0424SChris Cain if (subtree.empty()) 22803a2d0424SChris Cain { 22813a2d0424SChris Cain // This is an optional D-Bus object, but user attempted to patch 2282ac106bf6SEd Tanous messages::resourceNotFound(asyncResp->res, "ComputerSystem", 22833a2d0424SChris Cain "PowerMode"); 22843a2d0424SChris Cain return; 22853a2d0424SChris Cain } 22863a2d0424SChris Cain if (subtree.size() > 1) 22873a2d0424SChris Cain { 22883a2d0424SChris Cain // More then one PowerMode object is not supported and is an 22893a2d0424SChris Cain // error 229062598e31SEd Tanous BMCWEB_LOG_DEBUG( 229162598e31SEd Tanous "Found more than 1 system D-Bus Power.Mode objects: {}", 229262598e31SEd Tanous subtree.size()); 2293ac106bf6SEd Tanous messages::internalError(asyncResp->res); 22943a2d0424SChris Cain return; 22953a2d0424SChris Cain } 22963a2d0424SChris Cain if ((subtree[0].first.empty()) || (subtree[0].second.size() != 1)) 22973a2d0424SChris Cain { 229862598e31SEd Tanous BMCWEB_LOG_DEBUG("Power.Mode mapper error!"); 2299ac106bf6SEd Tanous messages::internalError(asyncResp->res); 23003a2d0424SChris Cain return; 23013a2d0424SChris Cain } 23023a2d0424SChris Cain const std::string& path = subtree[0].first; 23033a2d0424SChris Cain const std::string& service = subtree[0].second.begin()->first; 23043a2d0424SChris Cain if (service.empty()) 23053a2d0424SChris Cain { 230662598e31SEd Tanous BMCWEB_LOG_DEBUG("Power.Mode service mapper error!"); 2307ac106bf6SEd Tanous messages::internalError(asyncResp->res); 23083a2d0424SChris Cain return; 23093a2d0424SChris Cain } 23103a2d0424SChris Cain 231162598e31SEd Tanous BMCWEB_LOG_DEBUG("Setting power mode({}) -> {}", powerMode, path); 23123a2d0424SChris Cain 23133a2d0424SChris Cain // Set the Power Mode property 2314*e93abac6SGinu George setDbusProperty(asyncResp, "PowerMode", service, path, 231587c44966SAsmitha Karunanithi "xyz.openbmc_project.Control.Power.Mode", "PowerMode", 2316*e93abac6SGinu George powerMode); 2317e99073f5SGeorge Liu }); 23183a2d0424SChris Cain } 23193a2d0424SChris Cain 23203a2d0424SChris Cain /** 232151709ffdSYong Li * @brief Translates watchdog timeout action DBUS property value to redfish. 232251709ffdSYong Li * 232351709ffdSYong Li * @param[in] dbusAction The watchdog timeout action in D-BUS. 232451709ffdSYong Li * 232551709ffdSYong Li * @return Returns as a string, the timeout action in Redfish terms. If 232651709ffdSYong Li * translation cannot be done, returns an empty string. 232751709ffdSYong Li */ 232823a21a1cSEd Tanous inline std::string dbusToRfWatchdogAction(const std::string& dbusAction) 232951709ffdSYong Li { 233051709ffdSYong Li if (dbusAction == "xyz.openbmc_project.State.Watchdog.Action.None") 233151709ffdSYong Li { 233251709ffdSYong Li return "None"; 233351709ffdSYong Li } 23343174e4dfSEd Tanous if (dbusAction == "xyz.openbmc_project.State.Watchdog.Action.HardReset") 233551709ffdSYong Li { 233651709ffdSYong Li return "ResetSystem"; 233751709ffdSYong Li } 23383174e4dfSEd Tanous if (dbusAction == "xyz.openbmc_project.State.Watchdog.Action.PowerOff") 233951709ffdSYong Li { 234051709ffdSYong Li return "PowerDown"; 234151709ffdSYong Li } 23423174e4dfSEd Tanous if (dbusAction == "xyz.openbmc_project.State.Watchdog.Action.PowerCycle") 234351709ffdSYong Li { 234451709ffdSYong Li return "PowerCycle"; 234551709ffdSYong Li } 234651709ffdSYong Li 234751709ffdSYong Li return ""; 234851709ffdSYong Li } 234951709ffdSYong Li 235051709ffdSYong Li /** 2351c45f0082SYong Li *@brief Translates timeout action from Redfish to DBUS property value. 2352c45f0082SYong Li * 2353c45f0082SYong Li *@param[in] rfAction The timeout action in Redfish. 2354c45f0082SYong Li * 2355c45f0082SYong Li *@return Returns as a string, the time_out action as expected by DBUS. 2356c45f0082SYong Li *If translation cannot be done, returns an empty string. 2357c45f0082SYong Li */ 2358c45f0082SYong Li 235923a21a1cSEd Tanous inline std::string rfToDbusWDTTimeOutAct(const std::string& rfAction) 2360c45f0082SYong Li { 2361c45f0082SYong Li if (rfAction == "None") 2362c45f0082SYong Li { 2363c45f0082SYong Li return "xyz.openbmc_project.State.Watchdog.Action.None"; 2364c45f0082SYong Li } 23653174e4dfSEd Tanous if (rfAction == "PowerCycle") 2366c45f0082SYong Li { 2367c45f0082SYong Li return "xyz.openbmc_project.State.Watchdog.Action.PowerCycle"; 2368c45f0082SYong Li } 23693174e4dfSEd Tanous if (rfAction == "PowerDown") 2370c45f0082SYong Li { 2371c45f0082SYong Li return "xyz.openbmc_project.State.Watchdog.Action.PowerOff"; 2372c45f0082SYong Li } 23733174e4dfSEd Tanous if (rfAction == "ResetSystem") 2374c45f0082SYong Li { 2375c45f0082SYong Li return "xyz.openbmc_project.State.Watchdog.Action.HardReset"; 2376c45f0082SYong Li } 2377c45f0082SYong Li 2378c45f0082SYong Li return ""; 2379c45f0082SYong Li } 2380c45f0082SYong Li 2381c45f0082SYong Li /** 238251709ffdSYong Li * @brief Retrieves host watchdog timer properties over DBUS 238351709ffdSYong Li * 2384ac106bf6SEd Tanous * @param[in] asyncResp Shared pointer for completing asynchronous calls. 238551709ffdSYong Li * 238651709ffdSYong Li * @return None. 238751709ffdSYong Li */ 23888d1b46d7Szhanghch05 inline void 2389ac106bf6SEd Tanous getHostWatchdogTimer(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) 239051709ffdSYong Li { 239162598e31SEd Tanous BMCWEB_LOG_DEBUG("Get host watchodg"); 2392bc1d29deSKrzysztof Grobelny sdbusplus::asio::getAllProperties( 2393bc1d29deSKrzysztof Grobelny *crow::connections::systemBus, "xyz.openbmc_project.Watchdog", 2394bc1d29deSKrzysztof Grobelny "/xyz/openbmc_project/watchdog/host0", 2395bc1d29deSKrzysztof Grobelny "xyz.openbmc_project.State.Watchdog", 2396ac106bf6SEd Tanous [asyncResp](const boost::system::error_code& ec, 2397b9d36b47SEd Tanous const dbus::utility::DBusPropertiesMap& properties) { 239851709ffdSYong Li if (ec) 239951709ffdSYong Li { 240051709ffdSYong Li // watchdog service is stopped 240162598e31SEd Tanous BMCWEB_LOG_DEBUG("DBUS response error {}", ec); 240251709ffdSYong Li return; 240351709ffdSYong Li } 240451709ffdSYong Li 240562598e31SEd Tanous BMCWEB_LOG_DEBUG("Got {} wdt prop.", properties.size()); 240651709ffdSYong Li 240751709ffdSYong Li nlohmann::json& hostWatchdogTimer = 2408ac106bf6SEd Tanous asyncResp->res.jsonValue["HostWatchdogTimer"]; 240951709ffdSYong Li 241051709ffdSYong Li // watchdog service is running/enabled 241151709ffdSYong Li hostWatchdogTimer["Status"]["State"] = "Enabled"; 241251709ffdSYong Li 2413bc1d29deSKrzysztof Grobelny const bool* enabled = nullptr; 2414bc1d29deSKrzysztof Grobelny const std::string* expireAction = nullptr; 241551709ffdSYong Li 2416bc1d29deSKrzysztof Grobelny const bool success = sdbusplus::unpackPropertiesNoThrow( 2417bc1d29deSKrzysztof Grobelny dbus_utils::UnpackErrorPrinter(), properties, "Enabled", enabled, 2418bc1d29deSKrzysztof Grobelny "ExpireAction", expireAction); 2419bc1d29deSKrzysztof Grobelny 2420bc1d29deSKrzysztof Grobelny if (!success) 242151709ffdSYong Li { 2422ac106bf6SEd Tanous messages::internalError(asyncResp->res); 2423601af5edSChicago Duan return; 242451709ffdSYong Li } 242551709ffdSYong Li 2426bc1d29deSKrzysztof Grobelny if (enabled != nullptr) 242751709ffdSYong Li { 2428bc1d29deSKrzysztof Grobelny hostWatchdogTimer["FunctionEnabled"] = *enabled; 242951709ffdSYong Li } 243051709ffdSYong Li 2431bc1d29deSKrzysztof Grobelny if (expireAction != nullptr) 2432bc1d29deSKrzysztof Grobelny { 2433bc1d29deSKrzysztof Grobelny std::string action = dbusToRfWatchdogAction(*expireAction); 243451709ffdSYong Li if (action.empty()) 243551709ffdSYong Li { 2436ac106bf6SEd Tanous messages::internalError(asyncResp->res); 2437601af5edSChicago Duan return; 243851709ffdSYong Li } 243951709ffdSYong Li hostWatchdogTimer["TimeoutAction"] = action; 244051709ffdSYong Li } 2441bc1d29deSKrzysztof Grobelny }); 244251709ffdSYong Li } 244351709ffdSYong Li 244451709ffdSYong Li /** 2445c45f0082SYong Li * @brief Sets Host WatchDog Timer properties. 2446c45f0082SYong Li * 2447ac106bf6SEd Tanous * @param[in] asyncResp Shared pointer for generating response message. 2448c45f0082SYong Li * @param[in] wdtEnable The WDTimer Enable value (true/false) from incoming 2449c45f0082SYong Li * RF request. 2450c45f0082SYong Li * @param[in] wdtTimeOutAction The WDT Timeout action, from incoming RF request. 2451c45f0082SYong Li * 2452c45f0082SYong Li * @return None. 2453c45f0082SYong Li */ 2454ac106bf6SEd Tanous inline void 2455ac106bf6SEd Tanous setWDTProperties(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 2456c45f0082SYong Li const std::optional<bool> wdtEnable, 2457c45f0082SYong Li const std::optional<std::string>& wdtTimeOutAction) 2458c45f0082SYong Li { 245962598e31SEd Tanous BMCWEB_LOG_DEBUG("Set host watchdog"); 2460c45f0082SYong Li 2461c45f0082SYong Li if (wdtTimeOutAction) 2462c45f0082SYong Li { 2463c45f0082SYong Li std::string wdtTimeOutActStr = rfToDbusWDTTimeOutAct(*wdtTimeOutAction); 2464c45f0082SYong Li // check if TimeOut Action is Valid 2465c45f0082SYong Li if (wdtTimeOutActStr.empty()) 2466c45f0082SYong Li { 246762598e31SEd Tanous BMCWEB_LOG_DEBUG("Unsupported value for TimeoutAction: {}", 246862598e31SEd Tanous *wdtTimeOutAction); 2469ac106bf6SEd Tanous messages::propertyValueNotInList(asyncResp->res, *wdtTimeOutAction, 2470c45f0082SYong Li "TimeoutAction"); 2471c45f0082SYong Li return; 2472c45f0082SYong Li } 2473c45f0082SYong Li 2474*e93abac6SGinu George setDbusProperty(asyncResp, "HostWatchdogTimer/TimeoutAction", 2475*e93abac6SGinu George "xyz.openbmc_project.Watchdog", 247687c44966SAsmitha Karunanithi sdbusplus::message::object_path( 247787c44966SAsmitha Karunanithi "/xyz/openbmc_project/watchdog/host0"), 24789ae226faSGeorge Liu "xyz.openbmc_project.State.Watchdog", "ExpireAction", 2479*e93abac6SGinu George wdtTimeOutActStr); 2480c45f0082SYong Li } 2481c45f0082SYong Li 2482c45f0082SYong Li if (wdtEnable) 2483c45f0082SYong Li { 2484*e93abac6SGinu George setDbusProperty(asyncResp, "HostWatchdogTimer/FunctionEnabled", 2485*e93abac6SGinu George "xyz.openbmc_project.Watchdog", 248687c44966SAsmitha Karunanithi sdbusplus::message::object_path( 248787c44966SAsmitha Karunanithi "/xyz/openbmc_project/watchdog/host0"), 248887c44966SAsmitha Karunanithi "xyz.openbmc_project.State.Watchdog", "Enabled", 2489*e93abac6SGinu George *wdtEnable); 2490c45f0082SYong Li } 2491c45f0082SYong Li } 2492c45f0082SYong Li 249337bbf98cSChris Cain /** 249437bbf98cSChris Cain * @brief Parse the Idle Power Saver properties into json 249537bbf98cSChris Cain * 2496ac106bf6SEd Tanous * @param[in] asyncResp Shared pointer for completing asynchronous calls. 249737bbf98cSChris Cain * @param[in] properties IPS property data from DBus. 249837bbf98cSChris Cain * 249937bbf98cSChris Cain * @return true if successful 250037bbf98cSChris Cain */ 25011e5b7c88SJiaqing Zhao inline bool 2502ac106bf6SEd Tanous parseIpsProperties(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 25031e5b7c88SJiaqing Zhao const dbus::utility::DBusPropertiesMap& properties) 250437bbf98cSChris Cain { 2505bc1d29deSKrzysztof Grobelny const bool* enabled = nullptr; 2506bc1d29deSKrzysztof Grobelny const uint8_t* enterUtilizationPercent = nullptr; 2507bc1d29deSKrzysztof Grobelny const uint64_t* enterDwellTime = nullptr; 2508bc1d29deSKrzysztof Grobelny const uint8_t* exitUtilizationPercent = nullptr; 2509bc1d29deSKrzysztof Grobelny const uint64_t* exitDwellTime = nullptr; 2510bc1d29deSKrzysztof Grobelny 2511bc1d29deSKrzysztof Grobelny const bool success = sdbusplus::unpackPropertiesNoThrow( 2512bc1d29deSKrzysztof Grobelny dbus_utils::UnpackErrorPrinter(), properties, "Enabled", enabled, 25132661b72cSChris Cain "EnterUtilizationPercent", enterUtilizationPercent, "EnterDwellTime", 25142661b72cSChris Cain enterDwellTime, "ExitUtilizationPercent", exitUtilizationPercent, 25152661b72cSChris Cain "ExitDwellTime", exitDwellTime); 2516bc1d29deSKrzysztof Grobelny 2517bc1d29deSKrzysztof Grobelny if (!success) 251837bbf98cSChris Cain { 251937bbf98cSChris Cain return false; 252037bbf98cSChris Cain } 2521bc1d29deSKrzysztof Grobelny 2522bc1d29deSKrzysztof Grobelny if (enabled != nullptr) 252337bbf98cSChris Cain { 2524ac106bf6SEd Tanous asyncResp->res.jsonValue["IdlePowerSaver"]["Enabled"] = *enabled; 252537bbf98cSChris Cain } 2526bc1d29deSKrzysztof Grobelny 2527bc1d29deSKrzysztof Grobelny if (enterUtilizationPercent != nullptr) 252837bbf98cSChris Cain { 2529ac106bf6SEd Tanous asyncResp->res.jsonValue["IdlePowerSaver"]["EnterUtilizationPercent"] = 2530bc1d29deSKrzysztof Grobelny *enterUtilizationPercent; 253137bbf98cSChris Cain } 2532bc1d29deSKrzysztof Grobelny 2533bc1d29deSKrzysztof Grobelny if (enterDwellTime != nullptr) 2534bc1d29deSKrzysztof Grobelny { 2535bc1d29deSKrzysztof Grobelny const std::chrono::duration<uint64_t, std::milli> ms(*enterDwellTime); 2536ac106bf6SEd Tanous asyncResp->res.jsonValue["IdlePowerSaver"]["EnterDwellTimeSeconds"] = 253737bbf98cSChris Cain std::chrono::duration_cast<std::chrono::duration<uint64_t>>(ms) 253837bbf98cSChris Cain .count(); 253937bbf98cSChris Cain } 2540bc1d29deSKrzysztof Grobelny 2541bc1d29deSKrzysztof Grobelny if (exitUtilizationPercent != nullptr) 254237bbf98cSChris Cain { 2543ac106bf6SEd Tanous asyncResp->res.jsonValue["IdlePowerSaver"]["ExitUtilizationPercent"] = 2544bc1d29deSKrzysztof Grobelny *exitUtilizationPercent; 254537bbf98cSChris Cain } 2546bc1d29deSKrzysztof Grobelny 2547bc1d29deSKrzysztof Grobelny if (exitDwellTime != nullptr) 254837bbf98cSChris Cain { 2549bc1d29deSKrzysztof Grobelny const std::chrono::duration<uint64_t, std::milli> ms(*exitDwellTime); 2550ac106bf6SEd Tanous asyncResp->res.jsonValue["IdlePowerSaver"]["ExitDwellTimeSeconds"] = 255137bbf98cSChris Cain std::chrono::duration_cast<std::chrono::duration<uint64_t>>(ms) 255237bbf98cSChris Cain .count(); 255337bbf98cSChris Cain } 255437bbf98cSChris Cain 255537bbf98cSChris Cain return true; 255637bbf98cSChris Cain } 255737bbf98cSChris Cain 255837bbf98cSChris Cain /** 255937bbf98cSChris Cain * @brief Retrieves host watchdog timer properties over DBUS 256037bbf98cSChris Cain * 2561ac106bf6SEd Tanous * @param[in] asyncResp Shared pointer for completing asynchronous calls. 256237bbf98cSChris Cain * 256337bbf98cSChris Cain * @return None. 256437bbf98cSChris Cain */ 2565ac106bf6SEd Tanous inline void 2566ac106bf6SEd Tanous getIdlePowerSaver(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) 256737bbf98cSChris Cain { 256862598e31SEd Tanous BMCWEB_LOG_DEBUG("Get idle power saver parameters"); 256937bbf98cSChris Cain 257037bbf98cSChris Cain // Get IdlePowerSaver object path: 2571e99073f5SGeorge Liu constexpr std::array<std::string_view, 1> interfaces = { 2572e99073f5SGeorge Liu "xyz.openbmc_project.Control.Power.IdlePowerSaver"}; 2573e99073f5SGeorge Liu dbus::utility::getSubTree( 2574e99073f5SGeorge Liu "/", 0, interfaces, 2575ac106bf6SEd Tanous [asyncResp](const boost::system::error_code& ec, 2576b9d36b47SEd Tanous const dbus::utility::MapperGetSubTreeResponse& subtree) { 257737bbf98cSChris Cain if (ec) 257837bbf98cSChris Cain { 2579b3e86cb0SGunnar Mills BMCWEB_LOG_ERROR( 258062598e31SEd Tanous "DBUS response error on Power.IdlePowerSaver GetSubTree {}", 258162598e31SEd Tanous ec); 2582ac106bf6SEd Tanous messages::internalError(asyncResp->res); 258337bbf98cSChris Cain return; 258437bbf98cSChris Cain } 258537bbf98cSChris Cain if (subtree.empty()) 258637bbf98cSChris Cain { 258737bbf98cSChris Cain // This is an optional interface so just return 258837bbf98cSChris Cain // if there is no instance found 258962598e31SEd Tanous BMCWEB_LOG_DEBUG("No instances found"); 259037bbf98cSChris Cain return; 259137bbf98cSChris Cain } 259237bbf98cSChris Cain if (subtree.size() > 1) 259337bbf98cSChris Cain { 259437bbf98cSChris Cain // More then one PowerIdlePowerSaver object is not supported and 259537bbf98cSChris Cain // is an error 259662598e31SEd Tanous BMCWEB_LOG_DEBUG("Found more than 1 system D-Bus " 259762598e31SEd Tanous "Power.IdlePowerSaver objects: {}", 259862598e31SEd Tanous subtree.size()); 2599ac106bf6SEd Tanous messages::internalError(asyncResp->res); 260037bbf98cSChris Cain return; 260137bbf98cSChris Cain } 260237bbf98cSChris Cain if ((subtree[0].first.empty()) || (subtree[0].second.size() != 1)) 260337bbf98cSChris Cain { 260462598e31SEd Tanous BMCWEB_LOG_DEBUG("Power.IdlePowerSaver mapper error!"); 2605ac106bf6SEd Tanous messages::internalError(asyncResp->res); 260637bbf98cSChris Cain return; 260737bbf98cSChris Cain } 260837bbf98cSChris Cain const std::string& path = subtree[0].first; 260937bbf98cSChris Cain const std::string& service = subtree[0].second.begin()->first; 261037bbf98cSChris Cain if (service.empty()) 261137bbf98cSChris Cain { 261262598e31SEd Tanous BMCWEB_LOG_DEBUG("Power.IdlePowerSaver service mapper error!"); 2613ac106bf6SEd Tanous messages::internalError(asyncResp->res); 261437bbf98cSChris Cain return; 261537bbf98cSChris Cain } 261637bbf98cSChris Cain 261737bbf98cSChris Cain // Valid IdlePowerSaver object found, now read the current values 2618bc1d29deSKrzysztof Grobelny sdbusplus::asio::getAllProperties( 2619bc1d29deSKrzysztof Grobelny *crow::connections::systemBus, service, path, 2620bc1d29deSKrzysztof Grobelny "xyz.openbmc_project.Control.Power.IdlePowerSaver", 2621ac106bf6SEd Tanous [asyncResp](const boost::system::error_code& ec2, 26221e5b7c88SJiaqing Zhao const dbus::utility::DBusPropertiesMap& properties) { 26238a592810SEd Tanous if (ec2) 262437bbf98cSChris Cain { 262562598e31SEd Tanous BMCWEB_LOG_ERROR( 262662598e31SEd Tanous "DBUS response error on IdlePowerSaver GetAll: {}", ec2); 2627ac106bf6SEd Tanous messages::internalError(asyncResp->res); 262837bbf98cSChris Cain return; 262937bbf98cSChris Cain } 263037bbf98cSChris Cain 2631ac106bf6SEd Tanous if (!parseIpsProperties(asyncResp, properties)) 263237bbf98cSChris Cain { 2633ac106bf6SEd Tanous messages::internalError(asyncResp->res); 263437bbf98cSChris Cain return; 263537bbf98cSChris Cain } 2636bc1d29deSKrzysztof Grobelny }); 2637e99073f5SGeorge Liu }); 263837bbf98cSChris Cain 263962598e31SEd Tanous BMCWEB_LOG_DEBUG("EXIT: Get idle power saver parameters"); 264037bbf98cSChris Cain } 264137bbf98cSChris Cain 264237bbf98cSChris Cain /** 264337bbf98cSChris Cain * @brief Sets Idle Power Saver properties. 264437bbf98cSChris Cain * 2645ac106bf6SEd Tanous * @param[in] asyncResp Shared pointer for generating response message. 264637bbf98cSChris Cain * @param[in] ipsEnable The IPS Enable value (true/false) from incoming 264737bbf98cSChris Cain * RF request. 264837bbf98cSChris Cain * @param[in] ipsEnterUtil The utilization limit to enter idle state. 264937bbf98cSChris Cain * @param[in] ipsEnterTime The time the utilization must be below ipsEnterUtil 265037bbf98cSChris Cain * before entering idle state. 265137bbf98cSChris Cain * @param[in] ipsExitUtil The utilization limit when exiting idle state. 265237bbf98cSChris Cain * @param[in] ipsExitTime The time the utilization must be above ipsExutUtil 265337bbf98cSChris Cain * before exiting idle state 265437bbf98cSChris Cain * 265537bbf98cSChris Cain * @return None. 265637bbf98cSChris Cain */ 2657ac106bf6SEd Tanous inline void 2658ac106bf6SEd Tanous setIdlePowerSaver(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 265937bbf98cSChris Cain const std::optional<bool> ipsEnable, 266037bbf98cSChris Cain const std::optional<uint8_t> ipsEnterUtil, 266137bbf98cSChris Cain const std::optional<uint64_t> ipsEnterTime, 266237bbf98cSChris Cain const std::optional<uint8_t> ipsExitUtil, 266337bbf98cSChris Cain const std::optional<uint64_t> ipsExitTime) 266437bbf98cSChris Cain { 266562598e31SEd Tanous BMCWEB_LOG_DEBUG("Set idle power saver properties"); 266637bbf98cSChris Cain 266737bbf98cSChris Cain // Get IdlePowerSaver object path: 2668e99073f5SGeorge Liu constexpr std::array<std::string_view, 1> interfaces = { 2669e99073f5SGeorge Liu "xyz.openbmc_project.Control.Power.IdlePowerSaver"}; 2670e99073f5SGeorge Liu dbus::utility::getSubTree( 2671e99073f5SGeorge Liu "/", 0, interfaces, 2672ac106bf6SEd Tanous [asyncResp, ipsEnable, ipsEnterUtil, ipsEnterTime, ipsExitUtil, 2673e99073f5SGeorge Liu ipsExitTime](const boost::system::error_code& ec, 2674b9d36b47SEd Tanous const dbus::utility::MapperGetSubTreeResponse& subtree) { 267537bbf98cSChris Cain if (ec) 267637bbf98cSChris Cain { 2677b3e86cb0SGunnar Mills BMCWEB_LOG_ERROR( 267862598e31SEd Tanous "DBUS response error on Power.IdlePowerSaver GetSubTree {}", 267962598e31SEd Tanous ec); 2680ac106bf6SEd Tanous messages::internalError(asyncResp->res); 268137bbf98cSChris Cain return; 268237bbf98cSChris Cain } 268337bbf98cSChris Cain if (subtree.empty()) 268437bbf98cSChris Cain { 268537bbf98cSChris Cain // This is an optional D-Bus object, but user attempted to patch 2686ac106bf6SEd Tanous messages::resourceNotFound(asyncResp->res, "ComputerSystem", 268737bbf98cSChris Cain "IdlePowerSaver"); 268837bbf98cSChris Cain return; 268937bbf98cSChris Cain } 269037bbf98cSChris Cain if (subtree.size() > 1) 269137bbf98cSChris Cain { 269237bbf98cSChris Cain // More then one PowerIdlePowerSaver object is not supported and 269337bbf98cSChris Cain // is an error 269462598e31SEd Tanous BMCWEB_LOG_DEBUG( 269562598e31SEd Tanous "Found more than 1 system D-Bus Power.IdlePowerSaver objects: {}", 269662598e31SEd Tanous subtree.size()); 2697ac106bf6SEd Tanous messages::internalError(asyncResp->res); 269837bbf98cSChris Cain return; 269937bbf98cSChris Cain } 270037bbf98cSChris Cain if ((subtree[0].first.empty()) || (subtree[0].second.size() != 1)) 270137bbf98cSChris Cain { 270262598e31SEd Tanous BMCWEB_LOG_DEBUG("Power.IdlePowerSaver mapper error!"); 2703ac106bf6SEd Tanous messages::internalError(asyncResp->res); 270437bbf98cSChris Cain return; 270537bbf98cSChris Cain } 270637bbf98cSChris Cain const std::string& path = subtree[0].first; 270737bbf98cSChris Cain const std::string& service = subtree[0].second.begin()->first; 270837bbf98cSChris Cain if (service.empty()) 270937bbf98cSChris Cain { 271062598e31SEd Tanous BMCWEB_LOG_DEBUG("Power.IdlePowerSaver service mapper error!"); 2711ac106bf6SEd Tanous messages::internalError(asyncResp->res); 271237bbf98cSChris Cain return; 271337bbf98cSChris Cain } 271437bbf98cSChris Cain 271537bbf98cSChris Cain // Valid Power IdlePowerSaver object found, now set any values that 271637bbf98cSChris Cain // need to be updated 271737bbf98cSChris Cain 271837bbf98cSChris Cain if (ipsEnable) 271937bbf98cSChris Cain { 2720*e93abac6SGinu George setDbusProperty(asyncResp, "IdlePowerSaver/Enabled", service, path, 272187c44966SAsmitha Karunanithi "xyz.openbmc_project.Control.Power.IdlePowerSaver", 2722*e93abac6SGinu George "Enabled", *ipsEnable); 272337bbf98cSChris Cain } 272437bbf98cSChris Cain if (ipsEnterUtil) 272537bbf98cSChris Cain { 2726*e93abac6SGinu George setDbusProperty(asyncResp, "IdlePowerSaver/EnterUtilizationPercent", 2727*e93abac6SGinu George service, path, 27289ae226faSGeorge Liu "xyz.openbmc_project.Control.Power.IdlePowerSaver", 2729*e93abac6SGinu George "EnterUtilizationPercent", *ipsEnterUtil); 273037bbf98cSChris Cain } 273137bbf98cSChris Cain if (ipsEnterTime) 273237bbf98cSChris Cain { 273337bbf98cSChris Cain // Convert from seconds into milliseconds for DBus 273437bbf98cSChris Cain const uint64_t timeMilliseconds = *ipsEnterTime * 1000; 2735*e93abac6SGinu George setDbusProperty(asyncResp, "IdlePowerSaver/EnterDwellTimeSeconds", 2736*e93abac6SGinu George service, path, 27379ae226faSGeorge Liu "xyz.openbmc_project.Control.Power.IdlePowerSaver", 2738*e93abac6SGinu George "EnterDwellTime", timeMilliseconds); 273937bbf98cSChris Cain } 274037bbf98cSChris Cain if (ipsExitUtil) 274137bbf98cSChris Cain { 2742*e93abac6SGinu George setDbusProperty(asyncResp, "IdlePowerSaver/ExitUtilizationPercent", 2743*e93abac6SGinu George service, path, 27449ae226faSGeorge Liu "xyz.openbmc_project.Control.Power.IdlePowerSaver", 2745*e93abac6SGinu George "ExitUtilizationPercent", *ipsExitUtil); 274637bbf98cSChris Cain } 274737bbf98cSChris Cain if (ipsExitTime) 274837bbf98cSChris Cain { 274937bbf98cSChris Cain // Convert from seconds into milliseconds for DBus 275037bbf98cSChris Cain const uint64_t timeMilliseconds = *ipsExitTime * 1000; 2751*e93abac6SGinu George setDbusProperty(asyncResp, "IdlePowerSaver/ExitDwellTimeSeconds", 2752*e93abac6SGinu George service, path, 27539ae226faSGeorge Liu "xyz.openbmc_project.Control.Power.IdlePowerSaver", 2754*e93abac6SGinu George "ExitDwellTime", timeMilliseconds); 275537bbf98cSChris Cain } 2756e99073f5SGeorge Liu }); 275737bbf98cSChris Cain 275862598e31SEd Tanous BMCWEB_LOG_DEBUG("EXIT: Set idle power saver parameters"); 275937bbf98cSChris Cain } 276037bbf98cSChris Cain 2761c1e219d5SEd Tanous inline void handleComputerSystemCollectionHead( 2762dd60b9edSEd Tanous crow::App& app, const crow::Request& req, 2763dd60b9edSEd Tanous const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) 2764dd60b9edSEd Tanous { 2765dd60b9edSEd Tanous if (!redfish::setUpRedfishRoute(app, req, asyncResp)) 2766dd60b9edSEd Tanous { 2767dd60b9edSEd Tanous return; 2768dd60b9edSEd Tanous } 2769dd60b9edSEd Tanous asyncResp->res.addHeader( 2770dd60b9edSEd Tanous boost::beast::http::field::link, 2771dd60b9edSEd Tanous "</redfish/v1/JsonSchemas/ComputerSystemCollection/ComputerSystemCollection.json>; rel=describedby"); 2772dd60b9edSEd Tanous } 2773dd60b9edSEd Tanous 2774c1e219d5SEd Tanous inline void handleComputerSystemCollectionGet( 2775c1e219d5SEd Tanous crow::App& app, const crow::Request& req, 2776c1e219d5SEd Tanous const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) 27771abe55efSEd Tanous { 27783ba00073SCarson Labrado if (!redfish::setUpRedfishRoute(app, req, asyncResp)) 2779f4c99e70SEd Tanous { 2780f4c99e70SEd Tanous return; 2781f4c99e70SEd Tanous } 2782dd60b9edSEd Tanous 2783dd60b9edSEd Tanous asyncResp->res.addHeader( 2784dd60b9edSEd Tanous boost::beast::http::field::link, 2785dd60b9edSEd Tanous "</redfish/v1/JsonSchemas/ComputerSystemCollection.json>; rel=describedby"); 27868d1b46d7Szhanghch05 asyncResp->res.jsonValue["@odata.type"] = 27870f74e643SEd Tanous "#ComputerSystemCollection.ComputerSystemCollection"; 27888d1b46d7Szhanghch05 asyncResp->res.jsonValue["@odata.id"] = "/redfish/v1/Systems"; 27898d1b46d7Szhanghch05 asyncResp->res.jsonValue["Name"] = "Computer System Collection"; 2790462023adSSunitha Harish 27917f3e84a1SEd Tanous nlohmann::json& ifaceArray = asyncResp->res.jsonValue["Members"]; 27927f3e84a1SEd Tanous ifaceArray = nlohmann::json::array(); 279325b54dbaSEd Tanous if constexpr (BMCWEB_EXPERIMENTAL_REDFISH_MULTI_COMPUTER_SYSTEM) 27947f3e84a1SEd Tanous { 27957f3e84a1SEd Tanous asyncResp->res.jsonValue["Members@odata.count"] = 0; 27967f3e84a1SEd Tanous // Option currently returns no systems. TBD 27977f3e84a1SEd Tanous return; 27987f3e84a1SEd Tanous } 27997f3e84a1SEd Tanous asyncResp->res.jsonValue["Members@odata.count"] = 1; 28007f3e84a1SEd Tanous nlohmann::json::object_t system; 2801253f11b8SEd Tanous system["@odata.id"] = boost::urls::format("/redfish/v1/Systems/{}", 2802253f11b8SEd Tanous BMCWEB_REDFISH_SYSTEM_URI_NAME); 28037f3e84a1SEd Tanous ifaceArray.emplace_back(std::move(system)); 28041e1e598dSJonathan Doman sdbusplus::asio::getProperty<std::string>( 2805002d39b4SEd Tanous *crow::connections::systemBus, "xyz.openbmc_project.Settings", 28061e1e598dSJonathan Doman "/xyz/openbmc_project/network/hypervisor", 2807002d39b4SEd Tanous "xyz.openbmc_project.Network.SystemConfiguration", "HostName", 28085e7e2dc5SEd Tanous [asyncResp](const boost::system::error_code& ec2, 28091e1e598dSJonathan Doman const std::string& /*hostName*/) { 28107f3e84a1SEd Tanous if (ec2) 2811462023adSSunitha Harish { 28127f3e84a1SEd Tanous return; 28137f3e84a1SEd Tanous } 28147f3e84a1SEd Tanous auto val = asyncResp->res.jsonValue.find("Members@odata.count"); 28157f3e84a1SEd Tanous if (val == asyncResp->res.jsonValue.end()) 28167f3e84a1SEd Tanous { 281762598e31SEd Tanous BMCWEB_LOG_CRITICAL("Count wasn't found??"); 28187f3e84a1SEd Tanous return; 28197f3e84a1SEd Tanous } 28207f3e84a1SEd Tanous uint64_t* count = val->get_ptr<uint64_t*>(); 28217f3e84a1SEd Tanous if (count == nullptr) 28227f3e84a1SEd Tanous { 282362598e31SEd Tanous BMCWEB_LOG_CRITICAL("Count wasn't found??"); 28247f3e84a1SEd Tanous return; 28257f3e84a1SEd Tanous } 28267f3e84a1SEd Tanous *count = *count + 1; 282762598e31SEd Tanous BMCWEB_LOG_DEBUG("Hypervisor is available"); 28287f3e84a1SEd Tanous nlohmann::json& ifaceArray2 = asyncResp->res.jsonValue["Members"]; 28291476687dSEd Tanous nlohmann::json::object_t hypervisor; 2830002d39b4SEd Tanous hypervisor["@odata.id"] = "/redfish/v1/Systems/hypervisor"; 28317f3e84a1SEd Tanous ifaceArray2.emplace_back(std::move(hypervisor)); 28321e1e598dSJonathan Doman }); 2833c1e219d5SEd Tanous } 2834c1e219d5SEd Tanous 2835c1e219d5SEd Tanous /** 28367e860f15SJohn Edward Broadbent * Function transceives data with dbus directly. 28377e860f15SJohn Edward Broadbent */ 28384f48d5f6SEd Tanous inline void doNMI(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) 28397e860f15SJohn Edward Broadbent { 284089492a15SPatrick Williams constexpr const char* serviceName = "xyz.openbmc_project.Control.Host.NMI"; 284189492a15SPatrick Williams constexpr const char* objectPath = "/xyz/openbmc_project/control/host0/nmi"; 284289492a15SPatrick Williams constexpr const char* interfaceName = 28437e860f15SJohn Edward Broadbent "xyz.openbmc_project.Control.Host.NMI"; 284489492a15SPatrick Williams constexpr const char* method = "NMI"; 28457e860f15SJohn Edward Broadbent 28467e860f15SJohn Edward Broadbent crow::connections::systemBus->async_method_call( 28475e7e2dc5SEd Tanous [asyncResp](const boost::system::error_code& ec) { 28487e860f15SJohn Edward Broadbent if (ec) 28497e860f15SJohn Edward Broadbent { 285062598e31SEd Tanous BMCWEB_LOG_ERROR(" Bad D-Bus request error: {}", ec); 28517e860f15SJohn Edward Broadbent messages::internalError(asyncResp->res); 28527e860f15SJohn Edward Broadbent return; 28537e860f15SJohn Edward Broadbent } 28547e860f15SJohn Edward Broadbent messages::success(asyncResp->res); 28557e860f15SJohn Edward Broadbent }, 28567e860f15SJohn Edward Broadbent serviceName, objectPath, interfaceName, method); 28577e860f15SJohn Edward Broadbent } 2858c5b2abe0SLewanczyk, Dawid 2859c1e219d5SEd Tanous inline void handleComputerSystemResetActionPost( 2860c1e219d5SEd Tanous crow::App& app, const crow::Request& req, 28617f3e84a1SEd Tanous const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 2862c1e219d5SEd Tanous const std::string& systemName) 2863c1e219d5SEd Tanous { 28643ba00073SCarson Labrado if (!redfish::setUpRedfishRoute(app, req, asyncResp)) 286545ca1b86SEd Tanous { 286645ca1b86SEd Tanous return; 286745ca1b86SEd Tanous } 2868253f11b8SEd Tanous if (systemName != BMCWEB_REDFISH_SYSTEM_URI_NAME) 2869c1e219d5SEd Tanous { 2870c1e219d5SEd Tanous messages::resourceNotFound(asyncResp->res, "ComputerSystem", 2871c1e219d5SEd Tanous systemName); 2872c1e219d5SEd Tanous return; 2873c1e219d5SEd Tanous } 287425b54dbaSEd Tanous if constexpr (BMCWEB_EXPERIMENTAL_REDFISH_MULTI_COMPUTER_SYSTEM) 28757f3e84a1SEd Tanous { 28767f3e84a1SEd Tanous // Option currently returns no systems. TBD 28777f3e84a1SEd Tanous messages::resourceNotFound(asyncResp->res, "ComputerSystem", 2878c1e219d5SEd Tanous systemName); 28797f3e84a1SEd Tanous return; 28807f3e84a1SEd Tanous } 28819712f8acSEd Tanous std::string resetType; 2882c1e219d5SEd Tanous if (!json_util::readJsonAction(req, asyncResp->res, "ResetType", resetType)) 2883cc340dd9SEd Tanous { 2884cc340dd9SEd Tanous return; 2885cc340dd9SEd Tanous } 2886cc340dd9SEd Tanous 2887d22c8396SJason M. Bills // Get the command and host vs. chassis 2888cc340dd9SEd Tanous std::string command; 2889543f4400SEd Tanous bool hostCommand = true; 2890d4d25793SEd Tanous if ((resetType == "On") || (resetType == "ForceOn")) 2891cc340dd9SEd Tanous { 2892cc340dd9SEd Tanous command = "xyz.openbmc_project.State.Host.Transition.On"; 2893d22c8396SJason M. Bills hostCommand = true; 2894d22c8396SJason M. Bills } 2895d22c8396SJason M. Bills else if (resetType == "ForceOff") 2896d22c8396SJason M. Bills { 2897d22c8396SJason M. Bills command = "xyz.openbmc_project.State.Chassis.Transition.Off"; 2898d22c8396SJason M. Bills hostCommand = false; 2899d22c8396SJason M. Bills } 2900d22c8396SJason M. Bills else if (resetType == "ForceRestart") 2901d22c8396SJason M. Bills { 2902c1e219d5SEd Tanous command = "xyz.openbmc_project.State.Host.Transition.ForceWarmReboot"; 290386a0851aSJason M. Bills hostCommand = true; 2904cc340dd9SEd Tanous } 29059712f8acSEd Tanous else if (resetType == "GracefulShutdown") 2906cc340dd9SEd Tanous { 2907cc340dd9SEd Tanous command = "xyz.openbmc_project.State.Host.Transition.Off"; 2908d22c8396SJason M. Bills hostCommand = true; 2909cc340dd9SEd Tanous } 29109712f8acSEd Tanous else if (resetType == "GracefulRestart") 2911cc340dd9SEd Tanous { 29120fda0f12SGeorge Liu command = 29130fda0f12SGeorge Liu "xyz.openbmc_project.State.Host.Transition.GracefulWarmReboot"; 2914d22c8396SJason M. Bills hostCommand = true; 2915d22c8396SJason M. Bills } 2916d22c8396SJason M. Bills else if (resetType == "PowerCycle") 2917d22c8396SJason M. Bills { 291886a0851aSJason M. Bills command = "xyz.openbmc_project.State.Host.Transition.Reboot"; 291986a0851aSJason M. Bills hostCommand = true; 2920cc340dd9SEd Tanous } 2921bfd5b826SLakshminarayana R. Kammath else if (resetType == "Nmi") 2922bfd5b826SLakshminarayana R. Kammath { 2923bfd5b826SLakshminarayana R. Kammath doNMI(asyncResp); 2924bfd5b826SLakshminarayana R. Kammath return; 2925bfd5b826SLakshminarayana R. Kammath } 2926cc340dd9SEd Tanous else 2927cc340dd9SEd Tanous { 2928c1e219d5SEd Tanous messages::actionParameterUnknown(asyncResp->res, "Reset", resetType); 2929cc340dd9SEd Tanous return; 2930cc340dd9SEd Tanous } 2931d02aad39SEd Tanous sdbusplus::message::object_path statePath("/xyz/openbmc_project/state"); 2932cc340dd9SEd Tanous 2933d22c8396SJason M. Bills if (hostCommand) 2934d22c8396SJason M. Bills { 2935*e93abac6SGinu George setDbusProperty(asyncResp, "Reset", "xyz.openbmc_project.State.Host", 2936d02aad39SEd Tanous statePath / "host0", "xyz.openbmc_project.State.Host", 2937*e93abac6SGinu George "RequestedHostTransition", command); 2938cc340dd9SEd Tanous } 2939d22c8396SJason M. Bills else 2940d22c8396SJason M. Bills { 2941*e93abac6SGinu George setDbusProperty(asyncResp, "Reset", "xyz.openbmc_project.State.Chassis", 2942d02aad39SEd Tanous statePath / "chassis0", 2943d02aad39SEd Tanous "xyz.openbmc_project.State.Chassis", 2944*e93abac6SGinu George "RequestedPowerTransition", command); 2945d22c8396SJason M. Bills } 2946d22c8396SJason M. Bills } 2947cc340dd9SEd Tanous 2948c1e219d5SEd Tanous inline void handleComputerSystemHead( 2949dd60b9edSEd Tanous App& app, const crow::Request& req, 29507f3e84a1SEd Tanous const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 29517f3e84a1SEd Tanous const std::string& /*systemName*/) 2952dd60b9edSEd Tanous { 2953dd60b9edSEd Tanous if (!redfish::setUpRedfishRoute(app, req, asyncResp)) 2954dd60b9edSEd Tanous { 2955dd60b9edSEd Tanous return; 2956dd60b9edSEd Tanous } 2957dd60b9edSEd Tanous 2958dd60b9edSEd Tanous asyncResp->res.addHeader( 2959dd60b9edSEd Tanous boost::beast::http::field::link, 2960dd60b9edSEd Tanous "</redfish/v1/JsonSchemas/ComputerSystem/ComputerSystem.json>; rel=describedby"); 2961dd60b9edSEd Tanous } 2962dd60b9edSEd Tanous 29635c3e9272SAbhishek Patel inline void afterPortRequest( 29645c3e9272SAbhishek Patel const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 29655c3e9272SAbhishek Patel const boost::system::error_code& ec, 29665c3e9272SAbhishek Patel const std::vector<std::tuple<std::string, std::string, bool>>& socketData) 29675c3e9272SAbhishek Patel { 29685c3e9272SAbhishek Patel if (ec) 29695c3e9272SAbhishek Patel { 2970b3e86cb0SGunnar Mills BMCWEB_LOG_ERROR("DBUS response error {}", ec); 29715c3e9272SAbhishek Patel messages::internalError(asyncResp->res); 29725c3e9272SAbhishek Patel return; 29735c3e9272SAbhishek Patel } 29745c3e9272SAbhishek Patel for (const auto& data : socketData) 29755c3e9272SAbhishek Patel { 29765c3e9272SAbhishek Patel const std::string& socketPath = get<0>(data); 29775c3e9272SAbhishek Patel const std::string& protocolName = get<1>(data); 29785c3e9272SAbhishek Patel bool isProtocolEnabled = get<2>(data); 29795c3e9272SAbhishek Patel nlohmann::json& dataJson = asyncResp->res.jsonValue["SerialConsole"]; 29805c3e9272SAbhishek Patel dataJson[protocolName]["ServiceEnabled"] = isProtocolEnabled; 29815c3e9272SAbhishek Patel // need to retrieve port number for 29825c3e9272SAbhishek Patel // obmc-console-ssh service 29835c3e9272SAbhishek Patel if (protocolName == "SSH") 29845c3e9272SAbhishek Patel { 29855c3e9272SAbhishek Patel getPortNumber(socketPath, [asyncResp, protocolName]( 298681c4e330SEd Tanous const boost::system::error_code& ec1, 29875c3e9272SAbhishek Patel int portNumber) { 29885c3e9272SAbhishek Patel if (ec1) 29895c3e9272SAbhishek Patel { 2990b3e86cb0SGunnar Mills BMCWEB_LOG_ERROR("DBUS response error {}", ec1); 29915c3e9272SAbhishek Patel messages::internalError(asyncResp->res); 29925c3e9272SAbhishek Patel return; 29935c3e9272SAbhishek Patel } 29945c3e9272SAbhishek Patel nlohmann::json& dataJson1 = 29955c3e9272SAbhishek Patel asyncResp->res.jsonValue["SerialConsole"]; 29965c3e9272SAbhishek Patel dataJson1[protocolName]["Port"] = portNumber; 29975c3e9272SAbhishek Patel }); 29985c3e9272SAbhishek Patel } 29995c3e9272SAbhishek Patel } 30005c3e9272SAbhishek Patel } 3001c1e219d5SEd Tanous 3002c1e219d5SEd Tanous inline void 3003c1e219d5SEd Tanous handleComputerSystemGet(crow::App& app, const crow::Request& req, 300422d268cbSEd Tanous const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 3005c1e219d5SEd Tanous const std::string& systemName) 3006c1e219d5SEd Tanous { 30073ba00073SCarson Labrado if (!redfish::setUpRedfishRoute(app, req, asyncResp)) 300845ca1b86SEd Tanous { 300945ca1b86SEd Tanous return; 301045ca1b86SEd Tanous } 3011746b56f3SAsmitha Karunanithi 301225b54dbaSEd Tanous if constexpr (BMCWEB_EXPERIMENTAL_REDFISH_MULTI_COMPUTER_SYSTEM) 30137f3e84a1SEd Tanous { 30147f3e84a1SEd Tanous // Option currently returns no systems. TBD 30157f3e84a1SEd Tanous messages::resourceNotFound(asyncResp->res, "ComputerSystem", 30167f3e84a1SEd Tanous systemName); 30177f3e84a1SEd Tanous return; 30187f3e84a1SEd Tanous } 30197f3e84a1SEd Tanous 3020746b56f3SAsmitha Karunanithi if (systemName == "hypervisor") 3021746b56f3SAsmitha Karunanithi { 3022746b56f3SAsmitha Karunanithi handleHypervisorSystemGet(asyncResp); 3023746b56f3SAsmitha Karunanithi return; 3024746b56f3SAsmitha Karunanithi } 3025746b56f3SAsmitha Karunanithi 3026253f11b8SEd Tanous if (systemName != BMCWEB_REDFISH_SYSTEM_URI_NAME) 302722d268cbSEd Tanous { 302822d268cbSEd Tanous messages::resourceNotFound(asyncResp->res, "ComputerSystem", 302922d268cbSEd Tanous systemName); 303022d268cbSEd Tanous return; 303122d268cbSEd Tanous } 3032dd60b9edSEd Tanous asyncResp->res.addHeader( 3033dd60b9edSEd Tanous boost::beast::http::field::link, 3034dd60b9edSEd Tanous "</redfish/v1/JsonSchemas/ComputerSystem/ComputerSystem.json>; rel=describedby"); 30358d1b46d7Szhanghch05 asyncResp->res.jsonValue["@odata.type"] = 3036b6655101SChris Cain "#ComputerSystem.v1_22_0.ComputerSystem"; 3037253f11b8SEd Tanous asyncResp->res.jsonValue["Name"] = BMCWEB_REDFISH_SYSTEM_URI_NAME; 3038253f11b8SEd Tanous asyncResp->res.jsonValue["Id"] = BMCWEB_REDFISH_SYSTEM_URI_NAME; 30398d1b46d7Szhanghch05 asyncResp->res.jsonValue["SystemType"] = "Physical"; 30408d1b46d7Szhanghch05 asyncResp->res.jsonValue["Description"] = "Computer System"; 30418d1b46d7Szhanghch05 asyncResp->res.jsonValue["ProcessorSummary"]["Count"] = 0; 3042cf0e004cSNinad Palsule asyncResp->res.jsonValue["MemorySummary"]["TotalSystemMemoryGiB"] = 3043dfb2b408SPriyanga Ramasamy double(0); 3044253f11b8SEd Tanous asyncResp->res.jsonValue["@odata.id"] = boost::urls::format( 3045253f11b8SEd Tanous "/redfish/v1/Systems/{}", BMCWEB_REDFISH_SYSTEM_URI_NAME); 304604a258f4SEd Tanous 3047253f11b8SEd Tanous asyncResp->res.jsonValue["Processors"]["@odata.id"] = boost::urls::format( 3048253f11b8SEd Tanous "/redfish/v1/Systems/{}/Processors", BMCWEB_REDFISH_SYSTEM_URI_NAME); 3049253f11b8SEd Tanous asyncResp->res.jsonValue["Memory"]["@odata.id"] = boost::urls::format( 3050253f11b8SEd Tanous "/redfish/v1/Systems/{}/Memory", BMCWEB_REDFISH_SYSTEM_URI_NAME); 3051253f11b8SEd Tanous asyncResp->res.jsonValue["Storage"]["@odata.id"] = boost::urls::format( 3052253f11b8SEd Tanous "/redfish/v1/Systems/{}/Storage", BMCWEB_REDFISH_SYSTEM_URI_NAME); 30533179105bSSunny Srivastava asyncResp->res.jsonValue["FabricAdapters"]["@odata.id"] = 3054253f11b8SEd Tanous boost::urls::format("/redfish/v1/Systems/{}/FabricAdapters", 3055253f11b8SEd Tanous BMCWEB_REDFISH_SYSTEM_URI_NAME); 3056029573d4SEd Tanous 3057002d39b4SEd Tanous asyncResp->res.jsonValue["Actions"]["#ComputerSystem.Reset"]["target"] = 3058253f11b8SEd Tanous boost::urls::format( 3059253f11b8SEd Tanous "/redfish/v1/Systems/{}/Actions/ComputerSystem.Reset", 3060253f11b8SEd Tanous BMCWEB_REDFISH_SYSTEM_URI_NAME); 3061c1e219d5SEd Tanous asyncResp->res 3062c1e219d5SEd Tanous .jsonValue["Actions"]["#ComputerSystem.Reset"]["@Redfish.ActionInfo"] = 3063253f11b8SEd Tanous boost::urls::format("/redfish/v1/Systems/{}/ResetActionInfo", 3064253f11b8SEd Tanous BMCWEB_REDFISH_SYSTEM_URI_NAME); 3065c5b2abe0SLewanczyk, Dawid 3066253f11b8SEd Tanous asyncResp->res.jsonValue["LogServices"]["@odata.id"] = boost::urls::format( 3067253f11b8SEd Tanous "/redfish/v1/Systems/{}/LogServices", BMCWEB_REDFISH_SYSTEM_URI_NAME); 3068253f11b8SEd Tanous asyncResp->res.jsonValue["Bios"]["@odata.id"] = boost::urls::format( 3069253f11b8SEd Tanous "/redfish/v1/Systems/{}/Bios", BMCWEB_REDFISH_SYSTEM_URI_NAME); 3070c4bf6374SJason M. Bills 30711476687dSEd Tanous nlohmann::json::array_t managedBy; 30721476687dSEd Tanous nlohmann::json& manager = managedBy.emplace_back(); 3073253f11b8SEd Tanous manager["@odata.id"] = boost::urls::format("/redfish/v1/Managers/{}", 3074253f11b8SEd Tanous BMCWEB_REDFISH_MANAGER_URI_NAME); 3075002d39b4SEd Tanous asyncResp->res.jsonValue["Links"]["ManagedBy"] = std::move(managedBy); 30761476687dSEd Tanous asyncResp->res.jsonValue["Status"]["Health"] = "OK"; 30771476687dSEd Tanous asyncResp->res.jsonValue["Status"]["State"] = "Enabled"; 30780e8ac5e7SGunnar Mills 30790e8ac5e7SGunnar Mills // Fill in SerialConsole info 3080002d39b4SEd Tanous asyncResp->res.jsonValue["SerialConsole"]["MaxConcurrentSessions"] = 15; 3081c1e219d5SEd Tanous asyncResp->res.jsonValue["SerialConsole"]["IPMI"]["ServiceEnabled"] = true; 30821476687dSEd Tanous 3083c1e219d5SEd Tanous asyncResp->res.jsonValue["SerialConsole"]["SSH"]["ServiceEnabled"] = true; 30841476687dSEd Tanous asyncResp->res.jsonValue["SerialConsole"]["SSH"]["Port"] = 2200; 3085c1e219d5SEd Tanous asyncResp->res.jsonValue["SerialConsole"]["SSH"]["HotKeySequenceDisplay"] = 30861476687dSEd Tanous "Press ~. to exit console"; 30875c3e9272SAbhishek Patel getPortStatusAndPath(std::span{protocolToDBusForSystems}, 30885c3e9272SAbhishek Patel std::bind_front(afterPortRequest, asyncResp)); 30890e8ac5e7SGunnar Mills 309025b54dbaSEd Tanous if constexpr (BMCWEB_KVM) 309125b54dbaSEd Tanous { 30920e8ac5e7SGunnar Mills // Fill in GraphicalConsole info 3093002d39b4SEd Tanous asyncResp->res.jsonValue["GraphicalConsole"]["ServiceEnabled"] = true; 309425b54dbaSEd Tanous asyncResp->res.jsonValue["GraphicalConsole"]["MaxConcurrentSessions"] = 309525b54dbaSEd Tanous 4; 3096613dabeaSEd Tanous asyncResp->res.jsonValue["GraphicalConsole"]["ConnectTypesSupported"] = 3097613dabeaSEd Tanous nlohmann::json::array_t({"KVMIP"}); 309825b54dbaSEd Tanous } 309913451e39SWilly Tu 3100002d39b4SEd Tanous getMainChassisId(asyncResp, 3101002d39b4SEd Tanous [](const std::string& chassisId, 31028d1b46d7Szhanghch05 const std::shared_ptr<bmcweb::AsyncResp>& aRsp) { 3103b2c7e208SEd Tanous nlohmann::json::array_t chassisArray; 3104b2c7e208SEd Tanous nlohmann::json& chassis = chassisArray.emplace_back(); 3105ef4c65b7SEd Tanous chassis["@odata.id"] = boost::urls::format("/redfish/v1/Chassis/{}", 3106ef4c65b7SEd Tanous chassisId); 3107002d39b4SEd Tanous aRsp->res.jsonValue["Links"]["Chassis"] = std::move(chassisArray); 3108c5d03ff4SJennifer Lee }); 3109a3002228SAppaRao Puli 311059a17e4fSGeorge Liu getSystemLocationIndicatorActive(asyncResp); 31119f8bfa7cSGunnar Mills // TODO (Gunnar): Remove IndicatorLED after enough time has passed 3112a3002228SAppaRao Puli getIndicatorLedState(asyncResp); 311351bd2d8aSGunnar Mills getComputerSystem(asyncResp); 31146c34de48SEd Tanous getHostState(asyncResp); 3115491d8ee7SSantosh Puranik getBootProperties(asyncResp); 3116978b8803SAndrew Geissler getBootProgress(asyncResp); 3117b6d5d45cSHieu Huynh getBootProgressLastStateTime(asyncResp); 311870c4d545SLakshmi Yadlapati pcie_util::getPCIeDeviceList(asyncResp, 311970c4d545SLakshmi Yadlapati nlohmann::json::json_pointer("/PCIeDevices")); 312051709ffdSYong Li getHostWatchdogTimer(asyncResp); 3121c6a620f2SGeorge Liu getPowerRestorePolicy(asyncResp); 31229dcfe8c1SAlbert Zhang getStopBootOnFault(asyncResp); 3123797d5daeSCorey Hardesty getAutomaticRetryPolicy(asyncResp); 3124c0557e1aSGunnar Mills getLastResetTime(asyncResp); 312525b54dbaSEd Tanous if constexpr (BMCWEB_REDFISH_PROVISIONING_FEATURE) 312625b54dbaSEd Tanous { 3127a6349918SAppaRao Puli getProvisioningStatus(asyncResp); 312825b54dbaSEd Tanous } 31291981771bSAli Ahmed getTrustedModuleRequiredToBoot(asyncResp); 31303a2d0424SChris Cain getPowerMode(asyncResp); 313137bbf98cSChris Cain getIdlePowerSaver(asyncResp); 3132c1e219d5SEd Tanous } 3133550a6bf8SJiaqing Zhao 3134c1e219d5SEd Tanous inline void handleComputerSystemPatch( 3135c1e219d5SEd Tanous crow::App& app, const crow::Request& req, 313622d268cbSEd Tanous const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 3137c1e219d5SEd Tanous const std::string& systemName) 3138c1e219d5SEd Tanous { 31393ba00073SCarson Labrado if (!redfish::setUpRedfishRoute(app, req, asyncResp)) 314045ca1b86SEd Tanous { 314145ca1b86SEd Tanous return; 314245ca1b86SEd Tanous } 314325b54dbaSEd Tanous if constexpr (BMCWEB_EXPERIMENTAL_REDFISH_MULTI_COMPUTER_SYSTEM) 31447f3e84a1SEd Tanous { 31457f3e84a1SEd Tanous // Option currently returns no systems. TBD 31467f3e84a1SEd Tanous messages::resourceNotFound(asyncResp->res, "ComputerSystem", 31477f3e84a1SEd Tanous systemName); 31487f3e84a1SEd Tanous return; 31497f3e84a1SEd Tanous } 3150253f11b8SEd Tanous if (systemName != BMCWEB_REDFISH_SYSTEM_URI_NAME) 315122d268cbSEd Tanous { 315222d268cbSEd Tanous messages::resourceNotFound(asyncResp->res, "ComputerSystem", 315322d268cbSEd Tanous systemName); 315422d268cbSEd Tanous return; 315522d268cbSEd Tanous } 315622d268cbSEd Tanous 3157dd60b9edSEd Tanous asyncResp->res.addHeader( 3158dd60b9edSEd Tanous boost::beast::http::field::link, 3159dd60b9edSEd Tanous "</redfish/v1/JsonSchemas/ComputerSystem/ComputerSystem.json>; rel=describedby"); 3160dd60b9edSEd Tanous 31619f8bfa7cSGunnar Mills std::optional<bool> locationIndicatorActive; 3162cde19e5fSSantosh Puranik std::optional<std::string> indicatorLed; 316398e386ecSGunnar Mills std::optional<std::string> assetTag; 3164c6a620f2SGeorge Liu std::optional<std::string> powerRestorePolicy; 31653a2d0424SChris Cain std::optional<std::string> powerMode; 3166550a6bf8SJiaqing Zhao std::optional<bool> wdtEnable; 3167550a6bf8SJiaqing Zhao std::optional<std::string> wdtTimeOutAction; 3168550a6bf8SJiaqing Zhao std::optional<std::string> bootSource; 3169550a6bf8SJiaqing Zhao std::optional<std::string> bootType; 3170550a6bf8SJiaqing Zhao std::optional<std::string> bootEnable; 3171550a6bf8SJiaqing Zhao std::optional<std::string> bootAutomaticRetry; 3172797d5daeSCorey Hardesty std::optional<uint32_t> bootAutomaticRetryAttempts; 3173550a6bf8SJiaqing Zhao std::optional<bool> bootTrustedModuleRequired; 31749dcfe8c1SAlbert Zhang std::optional<std::string> stopBootOnFault; 3175550a6bf8SJiaqing Zhao std::optional<bool> ipsEnable; 3176550a6bf8SJiaqing Zhao std::optional<uint8_t> ipsEnterUtil; 3177550a6bf8SJiaqing Zhao std::optional<uint64_t> ipsEnterTime; 3178550a6bf8SJiaqing Zhao std::optional<uint8_t> ipsExitUtil; 3179550a6bf8SJiaqing Zhao std::optional<uint64_t> ipsExitTime; 3180550a6bf8SJiaqing Zhao 3181550a6bf8SJiaqing Zhao // clang-format off 318215ed6780SWilly Tu if (!json_util::readJsonPatch( 3183550a6bf8SJiaqing Zhao req, asyncResp->res, 3184550a6bf8SJiaqing Zhao "IndicatorLED", indicatorLed, 31857e860f15SJohn Edward Broadbent "LocationIndicatorActive", locationIndicatorActive, 3186550a6bf8SJiaqing Zhao "AssetTag", assetTag, 3187550a6bf8SJiaqing Zhao "PowerRestorePolicy", powerRestorePolicy, 3188550a6bf8SJiaqing Zhao "PowerMode", powerMode, 3189550a6bf8SJiaqing Zhao "HostWatchdogTimer/FunctionEnabled", wdtEnable, 3190550a6bf8SJiaqing Zhao "HostWatchdogTimer/TimeoutAction", wdtTimeOutAction, 3191550a6bf8SJiaqing Zhao "Boot/BootSourceOverrideTarget", bootSource, 3192550a6bf8SJiaqing Zhao "Boot/BootSourceOverrideMode", bootType, 3193550a6bf8SJiaqing Zhao "Boot/BootSourceOverrideEnabled", bootEnable, 3194550a6bf8SJiaqing Zhao "Boot/AutomaticRetryConfig", bootAutomaticRetry, 3195797d5daeSCorey Hardesty "Boot/AutomaticRetryAttempts", bootAutomaticRetryAttempts, 3196550a6bf8SJiaqing Zhao "Boot/TrustedModuleRequiredToBoot", bootTrustedModuleRequired, 31979dcfe8c1SAlbert Zhang "Boot/StopBootOnFault", stopBootOnFault, 3198550a6bf8SJiaqing Zhao "IdlePowerSaver/Enabled", ipsEnable, 3199550a6bf8SJiaqing Zhao "IdlePowerSaver/EnterUtilizationPercent", ipsEnterUtil, 3200550a6bf8SJiaqing Zhao "IdlePowerSaver/EnterDwellTimeSeconds", ipsEnterTime, 3201550a6bf8SJiaqing Zhao "IdlePowerSaver/ExitUtilizationPercent", ipsExitUtil, 3202550a6bf8SJiaqing Zhao "IdlePowerSaver/ExitDwellTimeSeconds", ipsExitTime)) 32036617338dSEd Tanous { 32046617338dSEd Tanous return; 32056617338dSEd Tanous } 3206550a6bf8SJiaqing Zhao // clang-format on 3207491d8ee7SSantosh Puranik 32088d1b46d7Szhanghch05 asyncResp->res.result(boost::beast::http::status::no_content); 3209c45f0082SYong Li 321098e386ecSGunnar Mills if (assetTag) 321198e386ecSGunnar Mills { 321298e386ecSGunnar Mills setAssetTag(asyncResp, *assetTag); 321398e386ecSGunnar Mills } 321498e386ecSGunnar Mills 3215550a6bf8SJiaqing Zhao if (wdtEnable || wdtTimeOutAction) 3216c45f0082SYong Li { 3217f23b7296SEd Tanous setWDTProperties(asyncResp, wdtEnable, wdtTimeOutAction); 3218c45f0082SYong Li } 3219c45f0082SYong Li 3220cd9a4666SKonstantin Aladyshev if (bootSource || bootType || bootEnable) 322169f35306SGunnar Mills { 3222002d39b4SEd Tanous setBootProperties(asyncResp, bootSource, bootType, bootEnable); 3223491d8ee7SSantosh Puranik } 3224550a6bf8SJiaqing Zhao if (bootAutomaticRetry) 322569f35306SGunnar Mills { 3226550a6bf8SJiaqing Zhao setAutomaticRetry(asyncResp, *bootAutomaticRetry); 322769f35306SGunnar Mills } 3228ac7e1e0bSAli Ahmed 3229797d5daeSCorey Hardesty if (bootAutomaticRetryAttempts) 3230797d5daeSCorey Hardesty { 3231797d5daeSCorey Hardesty setAutomaticRetryAttempts(asyncResp, 3232797d5daeSCorey Hardesty bootAutomaticRetryAttempts.value()); 3233797d5daeSCorey Hardesty } 3234797d5daeSCorey Hardesty 3235550a6bf8SJiaqing Zhao if (bootTrustedModuleRequired) 3236ac7e1e0bSAli Ahmed { 3237c1e219d5SEd Tanous setTrustedModuleRequiredToBoot(asyncResp, *bootTrustedModuleRequired); 323869f35306SGunnar Mills } 3239265c1602SJohnathan Mantey 32409dcfe8c1SAlbert Zhang if (stopBootOnFault) 32419dcfe8c1SAlbert Zhang { 32429dcfe8c1SAlbert Zhang setStopBootOnFault(asyncResp, *stopBootOnFault); 32439dcfe8c1SAlbert Zhang } 32449dcfe8c1SAlbert Zhang 32459f8bfa7cSGunnar Mills if (locationIndicatorActive) 32469f8bfa7cSGunnar Mills { 324759a17e4fSGeorge Liu setSystemLocationIndicatorActive(asyncResp, *locationIndicatorActive); 32489f8bfa7cSGunnar Mills } 32499f8bfa7cSGunnar Mills 32507e860f15SJohn Edward Broadbent // TODO (Gunnar): Remove IndicatorLED after enough time has 32517e860f15SJohn Edward Broadbent // passed 32529712f8acSEd Tanous if (indicatorLed) 32536617338dSEd Tanous { 3254f23b7296SEd Tanous setIndicatorLedState(asyncResp, *indicatorLed); 3255002d39b4SEd Tanous asyncResp->res.addHeader(boost::beast::http::field::warning, 3256d6aa0093SGunnar Mills "299 - \"IndicatorLED is deprecated. Use " 3257d6aa0093SGunnar Mills "LocationIndicatorActive instead.\""); 32586617338dSEd Tanous } 3259c6a620f2SGeorge Liu 3260c6a620f2SGeorge Liu if (powerRestorePolicy) 3261c6a620f2SGeorge Liu { 32624e69c904SGunnar Mills setPowerRestorePolicy(asyncResp, *powerRestorePolicy); 3263c6a620f2SGeorge Liu } 32643a2d0424SChris Cain 32653a2d0424SChris Cain if (powerMode) 32663a2d0424SChris Cain { 32673a2d0424SChris Cain setPowerMode(asyncResp, *powerMode); 32683a2d0424SChris Cain } 326937bbf98cSChris Cain 3270c1e219d5SEd Tanous if (ipsEnable || ipsEnterUtil || ipsEnterTime || ipsExitUtil || ipsExitTime) 327137bbf98cSChris Cain { 3272002d39b4SEd Tanous setIdlePowerSaver(asyncResp, ipsEnable, ipsEnterUtil, ipsEnterTime, 3273002d39b4SEd Tanous ipsExitUtil, ipsExitTime); 327437bbf98cSChris Cain } 3275c1e219d5SEd Tanous } 32761cb1a9e6SAppaRao Puli 327738c8a6f2SEd Tanous inline void handleSystemCollectionResetActionHead( 3278dd60b9edSEd Tanous crow::App& app, const crow::Request& req, 32797f3e84a1SEd Tanous const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 3280c1e219d5SEd Tanous const std::string& /*systemName*/) 3281dd60b9edSEd Tanous { 3282dd60b9edSEd Tanous if (!redfish::setUpRedfishRoute(app, req, asyncResp)) 3283dd60b9edSEd Tanous { 3284dd60b9edSEd Tanous return; 3285dd60b9edSEd Tanous } 3286dd60b9edSEd Tanous asyncResp->res.addHeader( 3287dd60b9edSEd Tanous boost::beast::http::field::link, 3288dd60b9edSEd Tanous "</redfish/v1/JsonSchemas/ActionInfo/ActionInfo.json>; rel=describedby"); 3289dd60b9edSEd Tanous } 329033e1f122SAndrew Geissler 329133e1f122SAndrew Geissler /** 329233e1f122SAndrew Geissler * @brief Translates allowed host transitions to redfish string 329333e1f122SAndrew Geissler * 329433e1f122SAndrew Geissler * @param[in] dbusAllowedHostTran The allowed host transition on dbus 329533e1f122SAndrew Geissler * @param[out] allowableValues The translated host transition(s) 329633e1f122SAndrew Geissler * 3297efff2b5dSManojkiran Eda * @return Emplaces corresponding Redfish translated value(s) in 329833e1f122SAndrew Geissler * allowableValues. If translation not possible, does nothing to 329933e1f122SAndrew Geissler * allowableValues. 330033e1f122SAndrew Geissler */ 330133e1f122SAndrew Geissler inline void 330233e1f122SAndrew Geissler dbusToRfAllowedHostTransitions(const std::string& dbusAllowedHostTran, 330333e1f122SAndrew Geissler nlohmann::json::array_t& allowableValues) 330433e1f122SAndrew Geissler { 330533e1f122SAndrew Geissler if (dbusAllowedHostTran == "xyz.openbmc_project.State.Host.Transition.On") 330633e1f122SAndrew Geissler { 330733e1f122SAndrew Geissler allowableValues.emplace_back(resource::ResetType::On); 330833e1f122SAndrew Geissler allowableValues.emplace_back(resource::ResetType::ForceOn); 330933e1f122SAndrew Geissler } 331033e1f122SAndrew Geissler else if (dbusAllowedHostTran == 331133e1f122SAndrew Geissler "xyz.openbmc_project.State.Host.Transition.Off") 331233e1f122SAndrew Geissler { 331333e1f122SAndrew Geissler allowableValues.emplace_back(resource::ResetType::GracefulShutdown); 331433e1f122SAndrew Geissler } 331533e1f122SAndrew Geissler else if (dbusAllowedHostTran == 331633e1f122SAndrew Geissler "xyz.openbmc_project.State.Host.Transition.GracefulWarmReboot") 331733e1f122SAndrew Geissler { 331833e1f122SAndrew Geissler allowableValues.emplace_back(resource::ResetType::GracefulRestart); 331933e1f122SAndrew Geissler } 332033e1f122SAndrew Geissler else if (dbusAllowedHostTran == 332133e1f122SAndrew Geissler "xyz.openbmc_project.State.Host.Transition.ForceWarmReboot") 332233e1f122SAndrew Geissler { 332333e1f122SAndrew Geissler allowableValues.emplace_back(resource::ResetType::ForceRestart); 332433e1f122SAndrew Geissler } 332533e1f122SAndrew Geissler else 332633e1f122SAndrew Geissler { 332733e1f122SAndrew Geissler BMCWEB_LOG_WARNING("Unsupported host tran {}", dbusAllowedHostTran); 332833e1f122SAndrew Geissler } 332933e1f122SAndrew Geissler } 333033e1f122SAndrew Geissler 333133e1f122SAndrew Geissler inline void afterGetAllowedHostTransitions( 333233e1f122SAndrew Geissler const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 333333e1f122SAndrew Geissler const boost::system::error_code& ec, 333433e1f122SAndrew Geissler const std::vector<std::string>& allowedHostTransitions) 333533e1f122SAndrew Geissler { 333633e1f122SAndrew Geissler nlohmann::json::array_t allowableValues; 333733e1f122SAndrew Geissler 333833e1f122SAndrew Geissler // Supported on all systems currently 333933e1f122SAndrew Geissler allowableValues.emplace_back(resource::ResetType::ForceOff); 334033e1f122SAndrew Geissler allowableValues.emplace_back(resource::ResetType::PowerCycle); 334133e1f122SAndrew Geissler allowableValues.emplace_back(resource::ResetType::Nmi); 334233e1f122SAndrew Geissler 334333e1f122SAndrew Geissler if (ec) 334433e1f122SAndrew Geissler { 3345e715d14bSEd Tanous if ((ec.value() == 3346e715d14bSEd Tanous boost::system::linux_error::bad_request_descriptor) || 3347e715d14bSEd Tanous (ec.value() == boost::asio::error::basic_errors::host_unreachable)) 334833e1f122SAndrew Geissler { 334933e1f122SAndrew Geissler // Property not implemented so just return defaults 335033e1f122SAndrew Geissler BMCWEB_LOG_DEBUG("Property not available {}", ec); 335133e1f122SAndrew Geissler allowableValues.emplace_back(resource::ResetType::On); 335233e1f122SAndrew Geissler allowableValues.emplace_back(resource::ResetType::ForceOn); 335333e1f122SAndrew Geissler allowableValues.emplace_back(resource::ResetType::ForceRestart); 335433e1f122SAndrew Geissler allowableValues.emplace_back(resource::ResetType::GracefulRestart); 335533e1f122SAndrew Geissler allowableValues.emplace_back(resource::ResetType::GracefulShutdown); 335633e1f122SAndrew Geissler } 335733e1f122SAndrew Geissler else 335833e1f122SAndrew Geissler { 335933e1f122SAndrew Geissler BMCWEB_LOG_ERROR("DBUS response error {}", ec); 336033e1f122SAndrew Geissler messages::internalError(asyncResp->res); 336133e1f122SAndrew Geissler return; 336233e1f122SAndrew Geissler } 336333e1f122SAndrew Geissler } 336433e1f122SAndrew Geissler else 336533e1f122SAndrew Geissler { 336633e1f122SAndrew Geissler for (const std::string& transition : allowedHostTransitions) 336733e1f122SAndrew Geissler { 336833e1f122SAndrew Geissler BMCWEB_LOG_DEBUG("Found allowed host tran {}", transition); 336933e1f122SAndrew Geissler dbusToRfAllowedHostTransitions(transition, allowableValues); 337033e1f122SAndrew Geissler } 337133e1f122SAndrew Geissler } 337233e1f122SAndrew Geissler 337333e1f122SAndrew Geissler nlohmann::json::object_t parameter; 337433e1f122SAndrew Geissler parameter["Name"] = "ResetType"; 337533e1f122SAndrew Geissler parameter["Required"] = true; 337633e1f122SAndrew Geissler parameter["DataType"] = "String"; 337733e1f122SAndrew Geissler parameter["AllowableValues"] = std::move(allowableValues); 337833e1f122SAndrew Geissler nlohmann::json::array_t parameters; 337933e1f122SAndrew Geissler parameters.emplace_back(std::move(parameter)); 338033e1f122SAndrew Geissler asyncResp->res.jsonValue["Parameters"] = std::move(parameters); 338133e1f122SAndrew Geissler } 338233e1f122SAndrew Geissler 3383c1e219d5SEd Tanous inline void handleSystemCollectionResetActionGet( 3384c1e219d5SEd Tanous crow::App& app, const crow::Request& req, 338522d268cbSEd Tanous const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 3386c1e219d5SEd Tanous const std::string& systemName) 3387c1e219d5SEd Tanous { 33883ba00073SCarson Labrado if (!redfish::setUpRedfishRoute(app, req, asyncResp)) 338945ca1b86SEd Tanous { 339045ca1b86SEd Tanous return; 339145ca1b86SEd Tanous } 339225b54dbaSEd Tanous if constexpr (BMCWEB_EXPERIMENTAL_REDFISH_MULTI_COMPUTER_SYSTEM) 33937f3e84a1SEd Tanous { 33947f3e84a1SEd Tanous // Option currently returns no systems. TBD 33957f3e84a1SEd Tanous messages::resourceNotFound(asyncResp->res, "ComputerSystem", 33967f3e84a1SEd Tanous systemName); 33977f3e84a1SEd Tanous return; 33987f3e84a1SEd Tanous } 3399746b56f3SAsmitha Karunanithi 3400746b56f3SAsmitha Karunanithi if (systemName == "hypervisor") 3401746b56f3SAsmitha Karunanithi { 3402746b56f3SAsmitha Karunanithi handleHypervisorResetActionGet(asyncResp); 3403746b56f3SAsmitha Karunanithi return; 3404746b56f3SAsmitha Karunanithi } 3405746b56f3SAsmitha Karunanithi 3406253f11b8SEd Tanous if (systemName != BMCWEB_REDFISH_SYSTEM_URI_NAME) 340722d268cbSEd Tanous { 340822d268cbSEd Tanous messages::resourceNotFound(asyncResp->res, "ComputerSystem", 340922d268cbSEd Tanous systemName); 341022d268cbSEd Tanous return; 341122d268cbSEd Tanous } 341222d268cbSEd Tanous 3413dd60b9edSEd Tanous asyncResp->res.addHeader( 3414dd60b9edSEd Tanous boost::beast::http::field::link, 3415dd60b9edSEd Tanous "</redfish/v1/JsonSchemas/ActionInfo/ActionInfo.json>; rel=describedby"); 34161476687dSEd Tanous 34171476687dSEd Tanous asyncResp->res.jsonValue["@odata.id"] = 3418253f11b8SEd Tanous boost::urls::format("/redfish/v1/Systems/{}/ResetActionInfo", 3419253f11b8SEd Tanous BMCWEB_REDFISH_SYSTEM_URI_NAME); 3420c1e219d5SEd Tanous asyncResp->res.jsonValue["@odata.type"] = "#ActionInfo.v1_1_2.ActionInfo"; 34211476687dSEd Tanous asyncResp->res.jsonValue["Name"] = "Reset Action Info"; 34221476687dSEd Tanous asyncResp->res.jsonValue["Id"] = "ResetActionInfo"; 34233215e700SNan Zhou 342433e1f122SAndrew Geissler // Look to see if system defines AllowedHostTransitions 342533e1f122SAndrew Geissler sdbusplus::asio::getProperty<std::vector<std::string>>( 342633e1f122SAndrew Geissler *crow::connections::systemBus, "xyz.openbmc_project.State.Host", 342733e1f122SAndrew Geissler "/xyz/openbmc_project/state/host0", "xyz.openbmc_project.State.Host", 342833e1f122SAndrew Geissler "AllowedHostTransitions", 342933e1f122SAndrew Geissler [asyncResp](const boost::system::error_code& ec, 343033e1f122SAndrew Geissler const std::vector<std::string>& allowedHostTransitions) { 343133e1f122SAndrew Geissler afterGetAllowedHostTransitions(asyncResp, ec, allowedHostTransitions); 343233e1f122SAndrew Geissler }); 3433c1e219d5SEd Tanous } 3434c1e219d5SEd Tanous /** 3435c1e219d5SEd Tanous * SystemResetActionInfo derived class for delivering Computer Systems 3436c1e219d5SEd Tanous * ResetType AllowableValues using ResetInfo schema. 3437c1e219d5SEd Tanous */ 3438100afe56SEd Tanous inline void requestRoutesSystems(App& app) 3439c1e219d5SEd Tanous { 3440100afe56SEd Tanous BMCWEB_ROUTE(app, "/redfish/v1/Systems/") 3441100afe56SEd Tanous .privileges(redfish::privileges::headComputerSystemCollection) 3442100afe56SEd Tanous .methods(boost::beast::http::verb::head)( 3443100afe56SEd Tanous std::bind_front(handleComputerSystemCollectionHead, std::ref(app))); 3444100afe56SEd Tanous 3445100afe56SEd Tanous BMCWEB_ROUTE(app, "/redfish/v1/Systems/") 3446100afe56SEd Tanous .privileges(redfish::privileges::getComputerSystemCollection) 3447100afe56SEd Tanous .methods(boost::beast::http::verb::get)( 3448100afe56SEd Tanous std::bind_front(handleComputerSystemCollectionGet, std::ref(app))); 3449100afe56SEd Tanous 3450100afe56SEd Tanous BMCWEB_ROUTE(app, "/redfish/v1/Systems/<str>/") 3451100afe56SEd Tanous .privileges(redfish::privileges::headComputerSystem) 3452100afe56SEd Tanous .methods(boost::beast::http::verb::head)( 3453100afe56SEd Tanous std::bind_front(handleComputerSystemHead, std::ref(app))); 3454100afe56SEd Tanous 3455100afe56SEd Tanous BMCWEB_ROUTE(app, "/redfish/v1/Systems/<str>/") 3456100afe56SEd Tanous .privileges(redfish::privileges::getComputerSystem) 3457100afe56SEd Tanous .methods(boost::beast::http::verb::get)( 3458100afe56SEd Tanous std::bind_front(handleComputerSystemGet, std::ref(app))); 3459100afe56SEd Tanous 3460100afe56SEd Tanous BMCWEB_ROUTE(app, "/redfish/v1/Systems/<str>/") 3461100afe56SEd Tanous .privileges(redfish::privileges::patchComputerSystem) 3462100afe56SEd Tanous .methods(boost::beast::http::verb::patch)( 3463100afe56SEd Tanous std::bind_front(handleComputerSystemPatch, std::ref(app))); 3464100afe56SEd Tanous 3465100afe56SEd Tanous BMCWEB_ROUTE(app, "/redfish/v1/Systems/<str>/Actions/ComputerSystem.Reset/") 3466100afe56SEd Tanous .privileges(redfish::privileges::postComputerSystem) 3467100afe56SEd Tanous .methods(boost::beast::http::verb::post)(std::bind_front( 3468100afe56SEd Tanous handleComputerSystemResetActionPost, std::ref(app))); 3469100afe56SEd Tanous 3470c1e219d5SEd Tanous BMCWEB_ROUTE(app, "/redfish/v1/Systems/<str>/ResetActionInfo/") 3471c1e219d5SEd Tanous .privileges(redfish::privileges::headActionInfo) 3472c1e219d5SEd Tanous .methods(boost::beast::http::verb::head)(std::bind_front( 3473c1e219d5SEd Tanous handleSystemCollectionResetActionHead, std::ref(app))); 3474c1e219d5SEd Tanous BMCWEB_ROUTE(app, "/redfish/v1/Systems/<str>/ResetActionInfo/") 3475c1e219d5SEd Tanous .privileges(redfish::privileges::getActionInfo) 3476c1e219d5SEd Tanous .methods(boost::beast::http::verb::get)(std::bind_front( 3477c1e219d5SEd Tanous handleSystemCollectionResetActionGet, std::ref(app))); 34781cb1a9e6SAppaRao Puli } 3479c5b2abe0SLewanczyk, Dawid } // namespace redfish 3480