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> 49*20fa6a2cSEd 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 946*20fa6a2cSEd Tanous nlohmann::json::array_t allowed; 947*20fa6a2cSEd Tanous allowed.emplace_back("None"); 948*20fa6a2cSEd Tanous allowed.emplace_back("Pxe"); 949*20fa6a2cSEd Tanous allowed.emplace_back("Hdd"); 950*20fa6a2cSEd Tanous allowed.emplace_back("Cd"); 951*20fa6a2cSEd Tanous allowed.emplace_back("Diags"); 952*20fa6a2cSEd Tanous allowed.emplace_back("BiosSetup"); 953*20fa6a2cSEd Tanous allowed.emplace_back("Usb"); 954*20fa6a2cSEd Tanous 955ac106bf6SEd Tanous asyncResp->res 9560fda0f12SGeorge Liu .jsonValue["Boot"] 957*20fa6a2cSEd Tanous ["BootSourceOverrideTarget@Redfish.AllowableValues"] = 958*20fa6a2cSEd 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. 1257*20fa6a2cSEd Tanous nlohmann::json::array_t allowed; 1258*20fa6a2cSEd Tanous allowed.emplace_back("Disabled"); 1259*20fa6a2cSEd Tanous allowed.emplace_back("RetryAttempts"); 1260ac106bf6SEd Tanous asyncResp->res 1261ac106bf6SEd Tanous .jsonValue["Boot"]["AutomaticRetryConfig@Redfish.AllowableValues"] = 1262*20fa6a2cSEd 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( 128187c44966SAsmitha Karunanithi asyncResp, "xyz.openbmc_project.State.Host", 128287c44966SAsmitha Karunanithi sdbusplus::message::object_path("/xyz/openbmc_project/state/host0"), 12839ae226faSGeorge Liu "xyz.openbmc_project.Control.Boot.RebootAttempts", "RetryAttempts", 128487c44966SAsmitha Karunanithi "Boot/AutomaticRetryAttempts", retryAttempts); 1285797d5daeSCorey Hardesty } 1286797d5daeSCorey Hardesty 12878d69c668SEd Tanous inline computer_system::PowerRestorePolicyTypes 12888d69c668SEd Tanous redfishPowerRestorePolicyFromDbus(std::string_view value) 12898d69c668SEd Tanous { 12908d69c668SEd Tanous if (value == 12918d69c668SEd Tanous "xyz.openbmc_project.Control.Power.RestorePolicy.Policy.AlwaysOn") 12928d69c668SEd Tanous { 12938d69c668SEd Tanous return computer_system::PowerRestorePolicyTypes::AlwaysOn; 12948d69c668SEd Tanous } 12958d69c668SEd Tanous if (value == 12968d69c668SEd Tanous "xyz.openbmc_project.Control.Power.RestorePolicy.Policy.AlwaysOff") 12978d69c668SEd Tanous { 12988d69c668SEd Tanous return computer_system::PowerRestorePolicyTypes::AlwaysOff; 12998d69c668SEd Tanous } 13008d69c668SEd Tanous if (value == 13013a34b742SGunnar Mills "xyz.openbmc_project.Control.Power.RestorePolicy.Policy.Restore") 13028d69c668SEd Tanous { 13038d69c668SEd Tanous return computer_system::PowerRestorePolicyTypes::LastState; 13048d69c668SEd Tanous } 13058d69c668SEd Tanous if (value == "xyz.openbmc_project.Control.Power.RestorePolicy.Policy.None") 13068d69c668SEd Tanous { 13078d69c668SEd Tanous return computer_system::PowerRestorePolicyTypes::AlwaysOff; 13088d69c668SEd Tanous } 13098d69c668SEd Tanous return computer_system::PowerRestorePolicyTypes::Invalid; 13108d69c668SEd Tanous } 1311797d5daeSCorey Hardesty /** 1312c6a620f2SGeorge Liu * @brief Retrieves power restore policy over DBUS. 1313c6a620f2SGeorge Liu * 1314ac106bf6SEd Tanous * @param[in] asyncResp Shared pointer for generating response message. 1315c6a620f2SGeorge Liu * 1316c6a620f2SGeorge Liu * @return None. 1317c6a620f2SGeorge Liu */ 13188d1b46d7Szhanghch05 inline void 1319ac106bf6SEd Tanous getPowerRestorePolicy(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) 1320c6a620f2SGeorge Liu { 132162598e31SEd Tanous BMCWEB_LOG_DEBUG("Get power restore policy"); 1322c6a620f2SGeorge Liu 13231e1e598dSJonathan Doman sdbusplus::asio::getProperty<std::string>( 13241e1e598dSJonathan Doman *crow::connections::systemBus, "xyz.openbmc_project.Settings", 13251e1e598dSJonathan Doman "/xyz/openbmc_project/control/host0/power_restore_policy", 13261e1e598dSJonathan Doman "xyz.openbmc_project.Control.Power.RestorePolicy", "PowerRestorePolicy", 1327ac106bf6SEd Tanous [asyncResp](const boost::system::error_code& ec, 13285e7e2dc5SEd Tanous const std::string& policy) { 1329c6a620f2SGeorge Liu if (ec) 1330c6a620f2SGeorge Liu { 133162598e31SEd Tanous BMCWEB_LOG_DEBUG("DBUS response error {}", ec); 1332c6a620f2SGeorge Liu return; 1333c6a620f2SGeorge Liu } 13348d69c668SEd Tanous computer_system::PowerRestorePolicyTypes restore = 13358d69c668SEd Tanous redfishPowerRestorePolicyFromDbus(policy); 13368d69c668SEd Tanous if (restore == computer_system::PowerRestorePolicyTypes::Invalid) 1337c6a620f2SGeorge Liu { 1338ac106bf6SEd Tanous messages::internalError(asyncResp->res); 1339c6a620f2SGeorge Liu return; 1340c6a620f2SGeorge Liu } 1341c6a620f2SGeorge Liu 13428d69c668SEd Tanous asyncResp->res.jsonValue["PowerRestorePolicy"] = restore; 13431e1e598dSJonathan Doman }); 1344c6a620f2SGeorge Liu } 1345c6a620f2SGeorge Liu 1346c6a620f2SGeorge Liu /** 13479dcfe8c1SAlbert Zhang * @brief Stop Boot On Fault over DBUS. 13489dcfe8c1SAlbert Zhang * 13499dcfe8c1SAlbert Zhang * @param[in] asyncResp Shared pointer for generating response message. 13509dcfe8c1SAlbert Zhang * 13519dcfe8c1SAlbert Zhang * @return None. 13529dcfe8c1SAlbert Zhang */ 13539dcfe8c1SAlbert Zhang inline void 13549dcfe8c1SAlbert Zhang getStopBootOnFault(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) 13559dcfe8c1SAlbert Zhang { 135662598e31SEd Tanous BMCWEB_LOG_DEBUG("Get Stop Boot On Fault"); 13579dcfe8c1SAlbert Zhang 13589dcfe8c1SAlbert Zhang sdbusplus::asio::getProperty<bool>( 13599dcfe8c1SAlbert Zhang *crow::connections::systemBus, "xyz.openbmc_project.Settings", 13609dcfe8c1SAlbert Zhang "/xyz/openbmc_project/logging/settings", 13619dcfe8c1SAlbert Zhang "xyz.openbmc_project.Logging.Settings", "QuiesceOnHwError", 13629dcfe8c1SAlbert Zhang [asyncResp](const boost::system::error_code& ec, bool value) { 13639dcfe8c1SAlbert Zhang if (ec) 13649dcfe8c1SAlbert Zhang { 13659dcfe8c1SAlbert Zhang if (ec.value() != EBADR) 13669dcfe8c1SAlbert Zhang { 1367b3e86cb0SGunnar Mills BMCWEB_LOG_ERROR("DBUS response error {}", ec); 13689dcfe8c1SAlbert Zhang messages::internalError(asyncResp->res); 13699dcfe8c1SAlbert Zhang } 13709dcfe8c1SAlbert Zhang return; 13719dcfe8c1SAlbert Zhang } 13729dcfe8c1SAlbert Zhang 13739dcfe8c1SAlbert Zhang if (value) 13749dcfe8c1SAlbert Zhang { 13759dcfe8c1SAlbert Zhang asyncResp->res.jsonValue["Boot"]["StopBootOnFault"] = "AnyFault"; 13769dcfe8c1SAlbert Zhang } 13779dcfe8c1SAlbert Zhang else 13789dcfe8c1SAlbert Zhang { 13799dcfe8c1SAlbert Zhang asyncResp->res.jsonValue["Boot"]["StopBootOnFault"] = "Never"; 13809dcfe8c1SAlbert Zhang } 13819dcfe8c1SAlbert Zhang }); 13829dcfe8c1SAlbert Zhang } 13839dcfe8c1SAlbert Zhang 13849dcfe8c1SAlbert Zhang /** 13851981771bSAli Ahmed * @brief Get TrustedModuleRequiredToBoot property. Determines whether or not 13861981771bSAli Ahmed * TPM is required for booting the host. 13871981771bSAli Ahmed * 1388ac106bf6SEd Tanous * @param[in] asyncResp Shared pointer for generating response message. 13891981771bSAli Ahmed * 13901981771bSAli Ahmed * @return None. 13911981771bSAli Ahmed */ 13921981771bSAli Ahmed inline void getTrustedModuleRequiredToBoot( 1393ac106bf6SEd Tanous const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) 13941981771bSAli Ahmed { 139562598e31SEd Tanous BMCWEB_LOG_DEBUG("Get TPM required to boot."); 1396e99073f5SGeorge Liu constexpr std::array<std::string_view, 1> interfaces = { 1397e99073f5SGeorge Liu "xyz.openbmc_project.Control.TPM.Policy"}; 1398e99073f5SGeorge Liu dbus::utility::getSubTree( 1399e99073f5SGeorge Liu "/", 0, interfaces, 1400ac106bf6SEd Tanous [asyncResp](const boost::system::error_code& ec, 1401b9d36b47SEd Tanous const dbus::utility::MapperGetSubTreeResponse& subtree) { 14021981771bSAli Ahmed if (ec) 14031981771bSAli Ahmed { 140462598e31SEd Tanous BMCWEB_LOG_DEBUG("DBUS response error on TPM.Policy GetSubTree{}", 140562598e31SEd Tanous ec); 14061981771bSAli Ahmed // This is an optional D-Bus object so just return if 14071981771bSAli Ahmed // error occurs 14081981771bSAli Ahmed return; 14091981771bSAli Ahmed } 141026f6976fSEd Tanous if (subtree.empty()) 14111981771bSAli Ahmed { 14121981771bSAli Ahmed // As noted above, this is an optional interface so just return 14131981771bSAli Ahmed // if there is no instance found 14141981771bSAli Ahmed return; 14151981771bSAli Ahmed } 14161981771bSAli Ahmed 14171981771bSAli Ahmed /* When there is more than one TPMEnable object... */ 14181981771bSAli Ahmed if (subtree.size() > 1) 14191981771bSAli Ahmed { 142062598e31SEd Tanous BMCWEB_LOG_DEBUG( 142162598e31SEd Tanous "DBUS response has more than 1 TPM Enable object:{}", 142262598e31SEd Tanous subtree.size()); 14231981771bSAli Ahmed // Throw an internal Error and return 1424ac106bf6SEd Tanous messages::internalError(asyncResp->res); 14251981771bSAli Ahmed return; 14261981771bSAli Ahmed } 14271981771bSAli Ahmed 14281981771bSAli Ahmed // Make sure the Dbus response map has a service and objectPath 14291981771bSAli Ahmed // field 14301981771bSAli Ahmed if (subtree[0].first.empty() || subtree[0].second.size() != 1) 14311981771bSAli Ahmed { 143262598e31SEd Tanous BMCWEB_LOG_DEBUG("TPM.Policy mapper error!"); 1433ac106bf6SEd Tanous messages::internalError(asyncResp->res); 14341981771bSAli Ahmed return; 14351981771bSAli Ahmed } 14361981771bSAli Ahmed 14371981771bSAli Ahmed const std::string& path = subtree[0].first; 14381981771bSAli Ahmed const std::string& serv = subtree[0].second.begin()->first; 14391981771bSAli Ahmed 14401981771bSAli Ahmed // Valid TPM Enable object found, now reading the current value 14411e1e598dSJonathan Doman sdbusplus::asio::getProperty<bool>( 14421e1e598dSJonathan Doman *crow::connections::systemBus, serv, path, 14431e1e598dSJonathan Doman "xyz.openbmc_project.Control.TPM.Policy", "TPMEnable", 1444ac106bf6SEd Tanous [asyncResp](const boost::system::error_code& ec2, 1445ac106bf6SEd Tanous bool tpmRequired) { 14468a592810SEd Tanous if (ec2) 14471981771bSAli Ahmed { 1448b3e86cb0SGunnar Mills BMCWEB_LOG_ERROR("D-BUS response error on TPM.Policy Get{}", 144962598e31SEd Tanous ec2); 1450ac106bf6SEd Tanous messages::internalError(asyncResp->res); 14511981771bSAli Ahmed return; 14521981771bSAli Ahmed } 14531981771bSAli Ahmed 14541e1e598dSJonathan Doman if (tpmRequired) 14551981771bSAli Ahmed { 1456ac106bf6SEd Tanous asyncResp->res 1457ac106bf6SEd Tanous .jsonValue["Boot"]["TrustedModuleRequiredToBoot"] = 14581981771bSAli Ahmed "Required"; 14591981771bSAli Ahmed } 14601981771bSAli Ahmed else 14611981771bSAli Ahmed { 1462ac106bf6SEd Tanous asyncResp->res 1463ac106bf6SEd Tanous .jsonValue["Boot"]["TrustedModuleRequiredToBoot"] = 14641981771bSAli Ahmed "Disabled"; 14651981771bSAli Ahmed } 14661e1e598dSJonathan Doman }); 1467e99073f5SGeorge Liu }); 14681981771bSAli Ahmed } 14691981771bSAli Ahmed 14701981771bSAli Ahmed /** 14711c05dae3SAli Ahmed * @brief Set TrustedModuleRequiredToBoot property. Determines whether or not 14721c05dae3SAli Ahmed * TPM is required for booting the host. 14731c05dae3SAli Ahmed * 1474ac106bf6SEd Tanous * @param[in] asyncResp Shared pointer for generating response message. 14751c05dae3SAli Ahmed * @param[in] tpmRequired Value to set TPM Required To Boot property to. 14761c05dae3SAli Ahmed * 14771c05dae3SAli Ahmed * @return None. 14781c05dae3SAli Ahmed */ 14791c05dae3SAli Ahmed inline void setTrustedModuleRequiredToBoot( 1480ac106bf6SEd Tanous const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, const bool tpmRequired) 14811c05dae3SAli Ahmed { 148262598e31SEd Tanous BMCWEB_LOG_DEBUG("Set TrustedModuleRequiredToBoot."); 1483e99073f5SGeorge Liu constexpr std::array<std::string_view, 1> interfaces = { 1484e99073f5SGeorge Liu "xyz.openbmc_project.Control.TPM.Policy"}; 1485e99073f5SGeorge Liu dbus::utility::getSubTree( 1486e99073f5SGeorge Liu "/", 0, interfaces, 1487ac106bf6SEd Tanous [asyncResp, 1488e99073f5SGeorge Liu tpmRequired](const boost::system::error_code& ec, 1489e99073f5SGeorge Liu const dbus::utility::MapperGetSubTreeResponse& subtree) { 14901c05dae3SAli Ahmed if (ec) 14911c05dae3SAli Ahmed { 1492b3e86cb0SGunnar Mills BMCWEB_LOG_ERROR("DBUS response error on TPM.Policy GetSubTree{}", 149362598e31SEd Tanous ec); 1494ac106bf6SEd Tanous messages::internalError(asyncResp->res); 14951c05dae3SAli Ahmed return; 14961c05dae3SAli Ahmed } 149726f6976fSEd Tanous if (subtree.empty()) 14981c05dae3SAli Ahmed { 1499ac106bf6SEd Tanous messages::propertyValueNotInList(asyncResp->res, "ComputerSystem", 15001c05dae3SAli Ahmed "TrustedModuleRequiredToBoot"); 15011c05dae3SAli Ahmed return; 15021c05dae3SAli Ahmed } 15031c05dae3SAli Ahmed 15041c05dae3SAli Ahmed /* When there is more than one TPMEnable object... */ 15051c05dae3SAli Ahmed if (subtree.size() > 1) 15061c05dae3SAli Ahmed { 150762598e31SEd Tanous BMCWEB_LOG_DEBUG( 150862598e31SEd Tanous "DBUS response has more than 1 TPM Enable object:{}", 150962598e31SEd Tanous subtree.size()); 15101c05dae3SAli Ahmed // Throw an internal Error and return 1511ac106bf6SEd Tanous messages::internalError(asyncResp->res); 15121c05dae3SAli Ahmed return; 15131c05dae3SAli Ahmed } 15141c05dae3SAli Ahmed 15151c05dae3SAli Ahmed // Make sure the Dbus response map has a service and objectPath 15161c05dae3SAli Ahmed // field 15171c05dae3SAli Ahmed if (subtree[0].first.empty() || subtree[0].second.size() != 1) 15181c05dae3SAli Ahmed { 151962598e31SEd Tanous BMCWEB_LOG_DEBUG("TPM.Policy mapper error!"); 1520ac106bf6SEd Tanous messages::internalError(asyncResp->res); 15211c05dae3SAli Ahmed return; 15221c05dae3SAli Ahmed } 15231c05dae3SAli Ahmed 15241c05dae3SAli Ahmed const std::string& path = subtree[0].first; 15251c05dae3SAli Ahmed const std::string& serv = subtree[0].second.begin()->first; 15261c05dae3SAli Ahmed 15271c05dae3SAli Ahmed if (serv.empty()) 15281c05dae3SAli Ahmed { 152962598e31SEd Tanous BMCWEB_LOG_DEBUG("TPM.Policy service mapper error!"); 1530ac106bf6SEd Tanous messages::internalError(asyncResp->res); 15311c05dae3SAli Ahmed return; 15321c05dae3SAli Ahmed } 15331c05dae3SAli Ahmed 15341c05dae3SAli Ahmed // Valid TPM Enable object found, now setting the value 153587c44966SAsmitha Karunanithi setDbusProperty(asyncResp, serv, path, 153687c44966SAsmitha Karunanithi "xyz.openbmc_project.Control.TPM.Policy", "TPMEnable", 153787c44966SAsmitha Karunanithi "Boot/TrustedModuleRequiredToBoot", tpmRequired); 1538e99073f5SGeorge Liu }); 15391c05dae3SAli Ahmed } 15401c05dae3SAli Ahmed 15411c05dae3SAli Ahmed /** 1542491d8ee7SSantosh Puranik * @brief Sets boot properties into DBUS object(s). 1543491d8ee7SSantosh Puranik * 1544ac106bf6SEd Tanous * @param[in] asyncResp Shared pointer for generating response message. 1545cd9a4666SKonstantin Aladyshev * @param[in] bootType The boot type to set. 1546cd9a4666SKonstantin Aladyshev * @return Integer error code. 1547cd9a4666SKonstantin Aladyshev */ 1548ac106bf6SEd Tanous inline void setBootType(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 1549cd9a4666SKonstantin Aladyshev const std::optional<std::string>& bootType) 1550cd9a4666SKonstantin Aladyshev { 1551c21865c4SKonstantin Aladyshev std::string bootTypeStr; 1552cd9a4666SKonstantin Aladyshev 1553c21865c4SKonstantin Aladyshev if (!bootType) 1554cd9a4666SKonstantin Aladyshev { 1555c21865c4SKonstantin Aladyshev return; 1556c21865c4SKonstantin Aladyshev } 1557c21865c4SKonstantin Aladyshev 1558cd9a4666SKonstantin Aladyshev // Source target specified 155962598e31SEd Tanous BMCWEB_LOG_DEBUG("Boot type: {}", *bootType); 1560cd9a4666SKonstantin Aladyshev // Figure out which DBUS interface and property to use 1561cd9a4666SKonstantin Aladyshev if (*bootType == "Legacy") 1562cd9a4666SKonstantin Aladyshev { 1563cd9a4666SKonstantin Aladyshev bootTypeStr = "xyz.openbmc_project.Control.Boot.Type.Types.Legacy"; 1564cd9a4666SKonstantin Aladyshev } 1565cd9a4666SKonstantin Aladyshev else if (*bootType == "UEFI") 1566cd9a4666SKonstantin Aladyshev { 1567cd9a4666SKonstantin Aladyshev bootTypeStr = "xyz.openbmc_project.Control.Boot.Type.Types.EFI"; 1568cd9a4666SKonstantin Aladyshev } 1569cd9a4666SKonstantin Aladyshev else 1570cd9a4666SKonstantin Aladyshev { 157162598e31SEd Tanous BMCWEB_LOG_DEBUG("Invalid property value for " 157262598e31SEd Tanous "BootSourceOverrideMode: {}", 157362598e31SEd Tanous *bootType); 1574ac106bf6SEd Tanous messages::propertyValueNotInList(asyncResp->res, *bootType, 1575cd9a4666SKonstantin Aladyshev "BootSourceOverrideMode"); 1576cd9a4666SKonstantin Aladyshev return; 1577cd9a4666SKonstantin Aladyshev } 1578cd9a4666SKonstantin Aladyshev 1579cd9a4666SKonstantin Aladyshev // Act on validated parameters 158062598e31SEd Tanous BMCWEB_LOG_DEBUG("DBUS boot type: {}", bootTypeStr); 1581cd9a4666SKonstantin Aladyshev 158287c44966SAsmitha Karunanithi setDbusProperty(asyncResp, "xyz.openbmc_project.Settings", 158387c44966SAsmitha Karunanithi sdbusplus::message::object_path( 158487c44966SAsmitha Karunanithi "/xyz/openbmc_project/control/host0/boot"), 158587c44966SAsmitha Karunanithi "xyz.openbmc_project.Control.Boot.Type", "BootType", 158687c44966SAsmitha Karunanithi "Boot/BootSourceOverrideMode", bootTypeStr); 1587cd9a4666SKonstantin Aladyshev } 1588cd9a4666SKonstantin Aladyshev 1589cd9a4666SKonstantin Aladyshev /** 1590cd9a4666SKonstantin Aladyshev * @brief Sets boot properties into DBUS object(s). 1591cd9a4666SKonstantin Aladyshev * 1592ac106bf6SEd Tanous * @param[in] asyncResp Shared pointer for generating response 1593ac106bf6SEd Tanous * message. 1594c21865c4SKonstantin Aladyshev * @param[in] bootType The boot type to set. 1595c21865c4SKonstantin Aladyshev * @return Integer error code. 1596c21865c4SKonstantin Aladyshev */ 1597ac106bf6SEd Tanous inline void setBootEnable(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 1598c21865c4SKonstantin Aladyshev const std::optional<std::string>& bootEnable) 1599c21865c4SKonstantin Aladyshev { 1600c21865c4SKonstantin Aladyshev if (!bootEnable) 1601c21865c4SKonstantin Aladyshev { 1602c21865c4SKonstantin Aladyshev return; 1603c21865c4SKonstantin Aladyshev } 1604c21865c4SKonstantin Aladyshev // Source target specified 160562598e31SEd Tanous BMCWEB_LOG_DEBUG("Boot enable: {}", *bootEnable); 1606c21865c4SKonstantin Aladyshev 1607c21865c4SKonstantin Aladyshev bool bootOverrideEnable = false; 1608c21865c4SKonstantin Aladyshev bool bootOverridePersistent = false; 1609c21865c4SKonstantin Aladyshev // Figure out which DBUS interface and property to use 1610c21865c4SKonstantin Aladyshev if (*bootEnable == "Disabled") 1611c21865c4SKonstantin Aladyshev { 1612c21865c4SKonstantin Aladyshev bootOverrideEnable = false; 1613c21865c4SKonstantin Aladyshev } 1614c21865c4SKonstantin Aladyshev else if (*bootEnable == "Once") 1615c21865c4SKonstantin Aladyshev { 1616c21865c4SKonstantin Aladyshev bootOverrideEnable = true; 1617c21865c4SKonstantin Aladyshev bootOverridePersistent = false; 1618c21865c4SKonstantin Aladyshev } 1619c21865c4SKonstantin Aladyshev else if (*bootEnable == "Continuous") 1620c21865c4SKonstantin Aladyshev { 1621c21865c4SKonstantin Aladyshev bootOverrideEnable = true; 1622c21865c4SKonstantin Aladyshev bootOverridePersistent = true; 1623c21865c4SKonstantin Aladyshev } 1624c21865c4SKonstantin Aladyshev else 1625c21865c4SKonstantin Aladyshev { 162662598e31SEd Tanous BMCWEB_LOG_DEBUG( 162762598e31SEd Tanous "Invalid property value for BootSourceOverrideEnabled: {}", 162862598e31SEd Tanous *bootEnable); 1629ac106bf6SEd Tanous messages::propertyValueNotInList(asyncResp->res, *bootEnable, 1630c21865c4SKonstantin Aladyshev "BootSourceOverrideEnabled"); 1631c21865c4SKonstantin Aladyshev return; 1632c21865c4SKonstantin Aladyshev } 1633c21865c4SKonstantin Aladyshev 1634c21865c4SKonstantin Aladyshev // Act on validated parameters 163562598e31SEd Tanous BMCWEB_LOG_DEBUG("DBUS boot override enable: {}", bootOverrideEnable); 1636c21865c4SKonstantin Aladyshev 163787c44966SAsmitha Karunanithi setDbusProperty(asyncResp, "xyz.openbmc_project.Settings", 163887c44966SAsmitha Karunanithi sdbusplus::message::object_path( 163987c44966SAsmitha Karunanithi "/xyz/openbmc_project/control/host0/boot"), 164087c44966SAsmitha Karunanithi "xyz.openbmc_project.Object.Enable", "Enabled", 164187c44966SAsmitha Karunanithi "Boot/BootSourceOverrideEnabled", bootOverrideEnable); 1642c21865c4SKonstantin Aladyshev 1643c21865c4SKonstantin Aladyshev if (!bootOverrideEnable) 1644c21865c4SKonstantin Aladyshev { 1645c21865c4SKonstantin Aladyshev return; 1646c21865c4SKonstantin Aladyshev } 1647c21865c4SKonstantin Aladyshev 1648c21865c4SKonstantin Aladyshev // In case boot override is enabled we need to set correct value for the 1649c21865c4SKonstantin Aladyshev // 'one_time' enable DBus interface 165062598e31SEd Tanous BMCWEB_LOG_DEBUG("DBUS boot override persistent: {}", 165162598e31SEd Tanous bootOverridePersistent); 1652c21865c4SKonstantin Aladyshev 165387c44966SAsmitha Karunanithi setDbusProperty(asyncResp, "xyz.openbmc_project.Settings", 165487c44966SAsmitha Karunanithi sdbusplus::message::object_path( 165587c44966SAsmitha Karunanithi "/xyz/openbmc_project/control/host0/boot/one_time"), 165687c44966SAsmitha Karunanithi "xyz.openbmc_project.Object.Enable", "Enabled", 165787c44966SAsmitha Karunanithi "Boot/BootSourceOverrideEnabled", !bootOverridePersistent); 1658c21865c4SKonstantin Aladyshev } 1659c21865c4SKonstantin Aladyshev 1660c21865c4SKonstantin Aladyshev /** 1661c21865c4SKonstantin Aladyshev * @brief Sets boot properties into DBUS object(s). 1662c21865c4SKonstantin Aladyshev * 1663ac106bf6SEd Tanous * @param[in] asyncResp Shared pointer for generating response message. 1664491d8ee7SSantosh Puranik * @param[in] bootSource The boot source to set. 1665491d8ee7SSantosh Puranik * 1666265c1602SJohnathan Mantey * @return Integer error code. 1667491d8ee7SSantosh Puranik */ 1668ac106bf6SEd Tanous inline void 1669ac106bf6SEd Tanous setBootModeOrSource(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 1670cd9a4666SKonstantin Aladyshev const std::optional<std::string>& bootSource) 1671491d8ee7SSantosh Puranik { 1672c21865c4SKonstantin Aladyshev std::string bootSourceStr; 1673c21865c4SKonstantin Aladyshev std::string bootModeStr; 1674944ffaf9SJohnathan Mantey 1675c21865c4SKonstantin Aladyshev if (!bootSource) 1676491d8ee7SSantosh Puranik { 1677c21865c4SKonstantin Aladyshev return; 1678c21865c4SKonstantin Aladyshev } 1679c21865c4SKonstantin Aladyshev 1680491d8ee7SSantosh Puranik // Source target specified 168162598e31SEd Tanous BMCWEB_LOG_DEBUG("Boot source: {}", *bootSource); 1682491d8ee7SSantosh Puranik // Figure out which DBUS interface and property to use 1683ac106bf6SEd Tanous if (assignBootParameters(asyncResp, *bootSource, bootSourceStr, 1684ac106bf6SEd Tanous bootModeStr) != 0) 1685491d8ee7SSantosh Puranik { 168662598e31SEd Tanous BMCWEB_LOG_DEBUG( 168762598e31SEd Tanous "Invalid property value for BootSourceOverrideTarget: {}", 168862598e31SEd Tanous *bootSource); 1689ac106bf6SEd Tanous messages::propertyValueNotInList(asyncResp->res, *bootSource, 1690491d8ee7SSantosh Puranik "BootSourceTargetOverride"); 1691491d8ee7SSantosh Puranik return; 1692491d8ee7SSantosh Puranik } 1693491d8ee7SSantosh Puranik 1694944ffaf9SJohnathan Mantey // Act on validated parameters 169562598e31SEd Tanous BMCWEB_LOG_DEBUG("DBUS boot source: {}", bootSourceStr); 169662598e31SEd Tanous BMCWEB_LOG_DEBUG("DBUS boot mode: {}", bootModeStr); 1697944ffaf9SJohnathan Mantey 169887c44966SAsmitha Karunanithi setDbusProperty(asyncResp, "xyz.openbmc_project.Settings", 169987c44966SAsmitha Karunanithi sdbusplus::message::object_path( 170087c44966SAsmitha Karunanithi "/xyz/openbmc_project/control/host0/boot"), 170187c44966SAsmitha Karunanithi "xyz.openbmc_project.Control.Boot.Source", "BootSource", 170287c44966SAsmitha Karunanithi "Boot/BootSourceOverrideTarget", bootSourceStr); 170387c44966SAsmitha Karunanithi setDbusProperty(asyncResp, "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.Mode", "BootMode", 170787c44966SAsmitha Karunanithi "Boot/BootSourceOverrideTarget", bootModeStr); 1708cd9a4666SKonstantin Aladyshev } 1709944ffaf9SJohnathan Mantey 1710cd9a4666SKonstantin Aladyshev /** 1711c21865c4SKonstantin Aladyshev * @brief Sets Boot source override properties. 1712491d8ee7SSantosh Puranik * 1713ac106bf6SEd Tanous * @param[in] asyncResp Shared pointer for generating response message. 1714491d8ee7SSantosh Puranik * @param[in] bootSource The boot source from incoming RF request. 1715cd9a4666SKonstantin Aladyshev * @param[in] bootType The boot type from incoming RF request. 1716491d8ee7SSantosh Puranik * @param[in] bootEnable The boot override enable from incoming RF request. 1717491d8ee7SSantosh Puranik * 1718265c1602SJohnathan Mantey * @return Integer error code. 1719491d8ee7SSantosh Puranik */ 1720c21865c4SKonstantin Aladyshev 1721ac106bf6SEd Tanous inline void 1722ac106bf6SEd Tanous setBootProperties(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 1723c21865c4SKonstantin Aladyshev const std::optional<std::string>& bootSource, 1724c21865c4SKonstantin Aladyshev const std::optional<std::string>& bootType, 1725c21865c4SKonstantin Aladyshev const std::optional<std::string>& bootEnable) 1726491d8ee7SSantosh Puranik { 172762598e31SEd Tanous BMCWEB_LOG_DEBUG("Set boot information."); 1728491d8ee7SSantosh Puranik 1729ac106bf6SEd Tanous setBootModeOrSource(asyncResp, bootSource); 1730ac106bf6SEd Tanous setBootType(asyncResp, bootType); 1731ac106bf6SEd Tanous setBootEnable(asyncResp, bootEnable); 1732491d8ee7SSantosh Puranik } 1733491d8ee7SSantosh Puranik 1734c6a620f2SGeorge Liu /** 173598e386ecSGunnar Mills * @brief Sets AssetTag 173698e386ecSGunnar Mills * 1737ac106bf6SEd Tanous * @param[in] asyncResp Shared pointer for generating response message. 173898e386ecSGunnar Mills * @param[in] assetTag "AssetTag" from request. 173998e386ecSGunnar Mills * 174098e386ecSGunnar Mills * @return None. 174198e386ecSGunnar Mills */ 1742ac106bf6SEd Tanous inline void setAssetTag(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 174398e386ecSGunnar Mills const std::string& assetTag) 174498e386ecSGunnar Mills { 1745e99073f5SGeorge Liu constexpr std::array<std::string_view, 1> interfaces = { 1746e99073f5SGeorge Liu "xyz.openbmc_project.Inventory.Item.System"}; 1747e99073f5SGeorge Liu dbus::utility::getSubTree( 1748e99073f5SGeorge Liu "/xyz/openbmc_project/inventory", 0, interfaces, 1749ac106bf6SEd Tanous [asyncResp, 1750e99073f5SGeorge Liu assetTag](const boost::system::error_code& ec, 1751b9d36b47SEd Tanous const dbus::utility::MapperGetSubTreeResponse& subtree) { 175298e386ecSGunnar Mills if (ec) 175398e386ecSGunnar Mills { 175462598e31SEd Tanous BMCWEB_LOG_DEBUG("D-Bus response error on GetSubTree {}", ec); 1755ac106bf6SEd Tanous messages::internalError(asyncResp->res); 175698e386ecSGunnar Mills return; 175798e386ecSGunnar Mills } 175826f6976fSEd Tanous if (subtree.empty()) 175998e386ecSGunnar Mills { 176062598e31SEd Tanous BMCWEB_LOG_DEBUG("Can't find system D-Bus object!"); 1761ac106bf6SEd Tanous messages::internalError(asyncResp->res); 176298e386ecSGunnar Mills return; 176398e386ecSGunnar Mills } 176498e386ecSGunnar Mills // Assume only 1 system D-Bus object 176598e386ecSGunnar Mills // Throw an error if there is more than 1 176698e386ecSGunnar Mills if (subtree.size() > 1) 176798e386ecSGunnar Mills { 176862598e31SEd Tanous BMCWEB_LOG_DEBUG("Found more than 1 system D-Bus object!"); 1769ac106bf6SEd Tanous messages::internalError(asyncResp->res); 177098e386ecSGunnar Mills return; 177198e386ecSGunnar Mills } 177298e386ecSGunnar Mills if (subtree[0].first.empty() || subtree[0].second.size() != 1) 177398e386ecSGunnar Mills { 177462598e31SEd Tanous BMCWEB_LOG_DEBUG("Asset Tag Set mapper error!"); 1775ac106bf6SEd Tanous messages::internalError(asyncResp->res); 177698e386ecSGunnar Mills return; 177798e386ecSGunnar Mills } 177898e386ecSGunnar Mills 177998e386ecSGunnar Mills const std::string& path = subtree[0].first; 178098e386ecSGunnar Mills const std::string& service = subtree[0].second.begin()->first; 178198e386ecSGunnar Mills 178298e386ecSGunnar Mills if (service.empty()) 178398e386ecSGunnar Mills { 178462598e31SEd Tanous BMCWEB_LOG_DEBUG("Asset Tag Set service mapper error!"); 1785ac106bf6SEd Tanous messages::internalError(asyncResp->res); 178698e386ecSGunnar Mills return; 178798e386ecSGunnar Mills } 178898e386ecSGunnar Mills 178987c44966SAsmitha Karunanithi setDbusProperty(asyncResp, service, path, 179087c44966SAsmitha Karunanithi "xyz.openbmc_project.Inventory.Decorator.AssetTag", 179187c44966SAsmitha Karunanithi "AssetTag", "AssetTag", assetTag); 1792e99073f5SGeorge Liu }); 179398e386ecSGunnar Mills } 179498e386ecSGunnar Mills 179598e386ecSGunnar Mills /** 17969dcfe8c1SAlbert Zhang * @brief Validate the specified stopBootOnFault is valid and return the 17979dcfe8c1SAlbert Zhang * stopBootOnFault name associated with that string 17989dcfe8c1SAlbert Zhang * 17999dcfe8c1SAlbert Zhang * @param[in] stopBootOnFaultString String representing the desired 18009dcfe8c1SAlbert Zhang * stopBootOnFault 18019dcfe8c1SAlbert Zhang * 18029dcfe8c1SAlbert Zhang * @return stopBootOnFault value or empty if incoming value is not valid 18039dcfe8c1SAlbert Zhang */ 18049dcfe8c1SAlbert Zhang inline std::optional<bool> 18059dcfe8c1SAlbert Zhang validstopBootOnFault(const std::string& stopBootOnFaultString) 18069dcfe8c1SAlbert Zhang { 18079dcfe8c1SAlbert Zhang if (stopBootOnFaultString == "AnyFault") 18089dcfe8c1SAlbert Zhang { 18099dcfe8c1SAlbert Zhang return true; 18109dcfe8c1SAlbert Zhang } 18119dcfe8c1SAlbert Zhang 18129dcfe8c1SAlbert Zhang if (stopBootOnFaultString == "Never") 18139dcfe8c1SAlbert Zhang { 18149dcfe8c1SAlbert Zhang return false; 18159dcfe8c1SAlbert Zhang } 18169dcfe8c1SAlbert Zhang 18179dcfe8c1SAlbert Zhang return std::nullopt; 18189dcfe8c1SAlbert Zhang } 18199dcfe8c1SAlbert Zhang 18209dcfe8c1SAlbert Zhang /** 18219dcfe8c1SAlbert Zhang * @brief Sets stopBootOnFault 18229dcfe8c1SAlbert Zhang * 1823fc3edfddSEd Tanous * @param[in] asyncResp Shared pointer for generating response message. 18249dcfe8c1SAlbert Zhang * @param[in] stopBootOnFault "StopBootOnFault" from request. 18259dcfe8c1SAlbert Zhang * 18269dcfe8c1SAlbert Zhang * @return None. 18279dcfe8c1SAlbert Zhang */ 1828fc3edfddSEd Tanous inline void 1829fc3edfddSEd Tanous setStopBootOnFault(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 18309dcfe8c1SAlbert Zhang const std::string& stopBootOnFault) 18319dcfe8c1SAlbert Zhang { 183262598e31SEd Tanous BMCWEB_LOG_DEBUG("Set Stop Boot On Fault."); 18339dcfe8c1SAlbert Zhang 18349dcfe8c1SAlbert Zhang std::optional<bool> stopBootEnabled = validstopBootOnFault(stopBootOnFault); 18359dcfe8c1SAlbert Zhang if (!stopBootEnabled) 18369dcfe8c1SAlbert Zhang { 183762598e31SEd Tanous BMCWEB_LOG_DEBUG("Invalid property value for StopBootOnFault: {}", 183862598e31SEd Tanous stopBootOnFault); 1839fc3edfddSEd Tanous messages::propertyValueNotInList(asyncResp->res, stopBootOnFault, 18409dcfe8c1SAlbert Zhang "StopBootOnFault"); 18419dcfe8c1SAlbert Zhang return; 18429dcfe8c1SAlbert Zhang } 18439dcfe8c1SAlbert Zhang 184487c44966SAsmitha Karunanithi setDbusProperty(asyncResp, "xyz.openbmc_project.Settings", 184587c44966SAsmitha Karunanithi sdbusplus::message::object_path( 184687c44966SAsmitha Karunanithi "/xyz/openbmc_project/logging/settings"), 1847fc3edfddSEd Tanous "xyz.openbmc_project.Logging.Settings", "QuiesceOnHwError", 184887c44966SAsmitha Karunanithi "Boot/StopBootOnFault", *stopBootEnabled); 18499dcfe8c1SAlbert Zhang } 18509dcfe8c1SAlbert Zhang 18519dcfe8c1SAlbert Zhang /** 185269f35306SGunnar Mills * @brief Sets automaticRetry (Auto Reboot) 185369f35306SGunnar Mills * 1854ac106bf6SEd Tanous * @param[in] asyncResp Shared pointer for generating response message. 185569f35306SGunnar Mills * @param[in] automaticRetryConfig "AutomaticRetryConfig" from request. 185669f35306SGunnar Mills * 185769f35306SGunnar Mills * @return None. 185869f35306SGunnar Mills */ 1859ac106bf6SEd Tanous inline void 1860ac106bf6SEd Tanous setAutomaticRetry(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 1861f23b7296SEd Tanous const std::string& automaticRetryConfig) 186269f35306SGunnar Mills { 186362598e31SEd Tanous BMCWEB_LOG_DEBUG("Set Automatic Retry."); 186469f35306SGunnar Mills 186569f35306SGunnar Mills // OpenBMC only supports "Disabled" and "RetryAttempts". 1866543f4400SEd Tanous bool autoRebootEnabled = false; 186769f35306SGunnar Mills 186869f35306SGunnar Mills if (automaticRetryConfig == "Disabled") 186969f35306SGunnar Mills { 187069f35306SGunnar Mills autoRebootEnabled = false; 187169f35306SGunnar Mills } 187269f35306SGunnar Mills else if (automaticRetryConfig == "RetryAttempts") 187369f35306SGunnar Mills { 187469f35306SGunnar Mills autoRebootEnabled = true; 187569f35306SGunnar Mills } 187669f35306SGunnar Mills else 187769f35306SGunnar Mills { 187862598e31SEd Tanous BMCWEB_LOG_DEBUG("Invalid property value for AutomaticRetryConfig: {}", 187962598e31SEd Tanous automaticRetryConfig); 1880ac106bf6SEd Tanous messages::propertyValueNotInList(asyncResp->res, automaticRetryConfig, 188169f35306SGunnar Mills "AutomaticRetryConfig"); 188269f35306SGunnar Mills return; 188369f35306SGunnar Mills } 188469f35306SGunnar Mills 188587c44966SAsmitha Karunanithi setDbusProperty(asyncResp, "xyz.openbmc_project.Settings", 188687c44966SAsmitha Karunanithi sdbusplus::message::object_path( 188787c44966SAsmitha Karunanithi "/xyz/openbmc_project/control/host0/auto_reboot"), 188887c44966SAsmitha Karunanithi "xyz.openbmc_project.Control.Boot.RebootPolicy", 188987c44966SAsmitha Karunanithi "AutoReboot", "Boot/AutomaticRetryConfig", 189087c44966SAsmitha Karunanithi autoRebootEnabled); 189169f35306SGunnar Mills } 189269f35306SGunnar Mills 18938d69c668SEd Tanous inline std::string dbusPowerRestorePolicyFromRedfish(std::string_view policy) 18948d69c668SEd Tanous { 18958d69c668SEd Tanous if (policy == "AlwaysOn") 18968d69c668SEd Tanous { 18978d69c668SEd Tanous return "xyz.openbmc_project.Control.Power.RestorePolicy.Policy.AlwaysOn"; 18988d69c668SEd Tanous } 18998d69c668SEd Tanous if (policy == "AlwaysOff") 19008d69c668SEd Tanous { 19018d69c668SEd Tanous return "xyz.openbmc_project.Control.Power.RestorePolicy.Policy.AlwaysOff"; 19028d69c668SEd Tanous } 19038d69c668SEd Tanous if (policy == "LastState") 19048d69c668SEd Tanous { 19058d69c668SEd Tanous return "xyz.openbmc_project.Control.Power.RestorePolicy.Policy.Restore"; 19068d69c668SEd Tanous } 19078d69c668SEd Tanous return ""; 19088d69c668SEd Tanous } 19098d69c668SEd Tanous 191069f35306SGunnar Mills /** 1911c6a620f2SGeorge Liu * @brief Sets power restore policy properties. 1912c6a620f2SGeorge Liu * 1913ac106bf6SEd Tanous * @param[in] asyncResp Shared pointer for generating response message. 1914c6a620f2SGeorge Liu * @param[in] policy power restore policy properties from request. 1915c6a620f2SGeorge Liu * 1916c6a620f2SGeorge Liu * @return None. 1917c6a620f2SGeorge Liu */ 19188d1b46d7Szhanghch05 inline void 1919ac106bf6SEd Tanous setPowerRestorePolicy(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 19208d69c668SEd Tanous std::string_view policy) 1921c6a620f2SGeorge Liu { 192262598e31SEd Tanous BMCWEB_LOG_DEBUG("Set power restore policy."); 1923c6a620f2SGeorge Liu 19248d69c668SEd Tanous std::string powerRestorePolicy = dbusPowerRestorePolicyFromRedfish(policy); 1925c6a620f2SGeorge Liu 19268d69c668SEd Tanous if (powerRestorePolicy.empty()) 1927c6a620f2SGeorge Liu { 1928ac106bf6SEd Tanous messages::propertyValueNotInList(asyncResp->res, policy, 19294e69c904SGunnar Mills "PowerRestorePolicy"); 1930c6a620f2SGeorge Liu return; 1931c6a620f2SGeorge Liu } 1932c6a620f2SGeorge Liu 193387c44966SAsmitha Karunanithi setDbusProperty( 193487c44966SAsmitha Karunanithi asyncResp, "xyz.openbmc_project.Settings", 193587c44966SAsmitha Karunanithi sdbusplus::message::object_path( 193687c44966SAsmitha Karunanithi "/xyz/openbmc_project/control/host0/power_restore_policy"), 19379ae226faSGeorge Liu "xyz.openbmc_project.Control.Power.RestorePolicy", "PowerRestorePolicy", 193887c44966SAsmitha Karunanithi "PowerRestorePolicy", powerRestorePolicy); 1939c6a620f2SGeorge Liu } 1940c6a620f2SGeorge Liu 1941a6349918SAppaRao Puli /** 1942a6349918SAppaRao Puli * @brief Retrieves provisioning status 1943a6349918SAppaRao Puli * 194425b54dbaSEd Tanous * @param[in] asyncResp Shared pointer for completing asynchronous 194525b54dbaSEd Tanous * calls. 1946a6349918SAppaRao Puli * 1947a6349918SAppaRao Puli * @return None. 1948a6349918SAppaRao Puli */ 194925b54dbaSEd Tanous inline void 195025b54dbaSEd Tanous getProvisioningStatus(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) 1951a6349918SAppaRao Puli { 195262598e31SEd Tanous BMCWEB_LOG_DEBUG("Get OEM information."); 1953bc1d29deSKrzysztof Grobelny sdbusplus::asio::getAllProperties( 1954bc1d29deSKrzysztof Grobelny *crow::connections::systemBus, "xyz.openbmc_project.PFR.Manager", 1955bc1d29deSKrzysztof Grobelny "/xyz/openbmc_project/pfr", "xyz.openbmc_project.PFR.Attributes", 1956ac106bf6SEd Tanous [asyncResp](const boost::system::error_code& ec, 1957b9d36b47SEd Tanous const dbus::utility::DBusPropertiesMap& propertiesList) { 1958b99fb1a9SAppaRao Puli nlohmann::json& oemPFR = 1959ac106bf6SEd Tanous asyncResp->res.jsonValue["Oem"]["OpenBmc"]["FirmwareProvisioning"]; 1960ac106bf6SEd Tanous asyncResp->res.jsonValue["Oem"]["OpenBmc"]["@odata.type"] = 196150626f4fSJames Feist "#OemComputerSystem.OpenBmc"; 196250626f4fSJames Feist oemPFR["@odata.type"] = "#OemComputerSystem.FirmwareProvisioning"; 196350626f4fSJames Feist 1964a6349918SAppaRao Puli if (ec) 1965a6349918SAppaRao Puli { 196662598e31SEd Tanous BMCWEB_LOG_DEBUG("DBUS response error {}", ec); 1967b99fb1a9SAppaRao Puli // not an error, don't have to have the interface 1968b99fb1a9SAppaRao Puli oemPFR["ProvisioningStatus"] = "NotProvisioned"; 1969a6349918SAppaRao Puli return; 1970a6349918SAppaRao Puli } 1971a6349918SAppaRao Puli 1972a6349918SAppaRao Puli const bool* provState = nullptr; 1973a6349918SAppaRao Puli const bool* lockState = nullptr; 1974bc1d29deSKrzysztof Grobelny 1975bc1d29deSKrzysztof Grobelny const bool success = sdbusplus::unpackPropertiesNoThrow( 19760d4befa8SJiaqing Zhao dbus_utils::UnpackErrorPrinter(), propertiesList, "UfmProvisioned", 19770d4befa8SJiaqing Zhao provState, "UfmLocked", lockState); 1978bc1d29deSKrzysztof Grobelny 1979bc1d29deSKrzysztof Grobelny if (!success) 1980a6349918SAppaRao Puli { 1981ac106bf6SEd Tanous messages::internalError(asyncResp->res); 1982bc1d29deSKrzysztof Grobelny return; 1983a6349918SAppaRao Puli } 1984a6349918SAppaRao Puli 1985a6349918SAppaRao Puli if ((provState == nullptr) || (lockState == nullptr)) 1986a6349918SAppaRao Puli { 198762598e31SEd Tanous BMCWEB_LOG_DEBUG("Unable to get PFR attributes."); 1988ac106bf6SEd Tanous messages::internalError(asyncResp->res); 1989a6349918SAppaRao Puli return; 1990a6349918SAppaRao Puli } 1991a6349918SAppaRao Puli 199225b54dbaSEd Tanous if (*provState) 1993a6349918SAppaRao Puli { 199425b54dbaSEd Tanous if (*lockState) 1995a6349918SAppaRao Puli { 1996a6349918SAppaRao Puli oemPFR["ProvisioningStatus"] = "ProvisionedAndLocked"; 1997a6349918SAppaRao Puli } 1998a6349918SAppaRao Puli else 1999a6349918SAppaRao Puli { 2000a6349918SAppaRao Puli oemPFR["ProvisioningStatus"] = "ProvisionedButNotLocked"; 2001a6349918SAppaRao Puli } 2002a6349918SAppaRao Puli } 2003a6349918SAppaRao Puli else 2004a6349918SAppaRao Puli { 2005a6349918SAppaRao Puli oemPFR["ProvisioningStatus"] = "NotProvisioned"; 2006a6349918SAppaRao Puli } 2007bc1d29deSKrzysztof Grobelny }); 2008a6349918SAppaRao Puli } 2009a6349918SAppaRao Puli 2010491d8ee7SSantosh Puranik /** 20116b9ac4f2SChris Cain * @brief Translate the PowerMode string to enum value 20123a2d0424SChris Cain * 20136b9ac4f2SChris Cain * @param[in] modeString PowerMode string to be translated 20143a2d0424SChris Cain * 20156b9ac4f2SChris Cain * @return PowerMode enum 20163a2d0424SChris Cain */ 20176b9ac4f2SChris Cain inline computer_system::PowerMode 20186b9ac4f2SChris Cain translatePowerModeString(const std::string& modeString) 20193a2d0424SChris Cain { 2020b6655101SChris Cain using PowerMode = computer_system::PowerMode; 2021b6655101SChris Cain 20226b9ac4f2SChris Cain if (modeString == "xyz.openbmc_project.Control.Power.Mode.PowerMode.Static") 20233a2d0424SChris Cain { 20246b9ac4f2SChris Cain return PowerMode::Static; 20253a2d0424SChris Cain } 20266b9ac4f2SChris Cain if (modeString == 20270fda0f12SGeorge Liu "xyz.openbmc_project.Control.Power.Mode.PowerMode.MaximumPerformance") 20283a2d0424SChris Cain { 20296b9ac4f2SChris Cain return PowerMode::MaximumPerformance; 20303a2d0424SChris Cain } 20316b9ac4f2SChris Cain if (modeString == 20320fda0f12SGeorge Liu "xyz.openbmc_project.Control.Power.Mode.PowerMode.PowerSaving") 20333a2d0424SChris Cain { 20346b9ac4f2SChris Cain return PowerMode::PowerSaving; 2035b6655101SChris Cain } 20366b9ac4f2SChris Cain if (modeString == 2037b6655101SChris Cain "xyz.openbmc_project.Control.Power.Mode.PowerMode.BalancedPerformance") 2038b6655101SChris Cain { 20396b9ac4f2SChris Cain return PowerMode::BalancedPerformance; 2040b6655101SChris Cain } 20416b9ac4f2SChris Cain if (modeString == 2042b6655101SChris Cain "xyz.openbmc_project.Control.Power.Mode.PowerMode.EfficiencyFavorPerformance") 2043b6655101SChris Cain { 20446b9ac4f2SChris Cain return PowerMode::EfficiencyFavorPerformance; 2045b6655101SChris Cain } 20466b9ac4f2SChris Cain if (modeString == 2047b6655101SChris Cain "xyz.openbmc_project.Control.Power.Mode.PowerMode.EfficiencyFavorPower") 2048b6655101SChris Cain { 20496b9ac4f2SChris Cain return PowerMode::EfficiencyFavorPower; 20503a2d0424SChris Cain } 20516b9ac4f2SChris Cain if (modeString == "xyz.openbmc_project.Control.Power.Mode.PowerMode.OEM") 20523a2d0424SChris Cain { 20536b9ac4f2SChris Cain return PowerMode::OEM; 20546b9ac4f2SChris Cain } 20556b9ac4f2SChris Cain // Any other values would be invalid 20566b9ac4f2SChris Cain BMCWEB_LOG_ERROR("PowerMode value was not valid: {}", modeString); 20576b9ac4f2SChris Cain return PowerMode::Invalid; 20586b9ac4f2SChris Cain } 20596b9ac4f2SChris Cain 20606b9ac4f2SChris Cain inline void 20616b9ac4f2SChris Cain afterGetPowerMode(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 20626b9ac4f2SChris Cain const boost::system::error_code& ec, 20636b9ac4f2SChris Cain const dbus::utility::DBusPropertiesMap& properties) 20646b9ac4f2SChris Cain { 20656b9ac4f2SChris Cain if (ec) 20666b9ac4f2SChris Cain { 20676b9ac4f2SChris Cain BMCWEB_LOG_ERROR("DBUS response error on PowerMode GetAll: {}", ec); 20686b9ac4f2SChris Cain messages::internalError(asyncResp->res); 20696b9ac4f2SChris Cain return; 20706b9ac4f2SChris Cain } 20716b9ac4f2SChris Cain 20726b9ac4f2SChris Cain std::string powerMode; 20736b9ac4f2SChris Cain const std::vector<std::string>* allowedModes = nullptr; 20746b9ac4f2SChris Cain const bool success = sdbusplus::unpackPropertiesNoThrow( 20756b9ac4f2SChris Cain dbus_utils::UnpackErrorPrinter(), properties, "PowerMode", powerMode, 20766b9ac4f2SChris Cain "AllowedPowerModes", allowedModes); 20776b9ac4f2SChris Cain 20786b9ac4f2SChris Cain if (!success) 20796b9ac4f2SChris Cain { 20806b9ac4f2SChris Cain messages::internalError(asyncResp->res); 20816b9ac4f2SChris Cain return; 20826b9ac4f2SChris Cain } 20836b9ac4f2SChris Cain 20846b9ac4f2SChris Cain nlohmann::json::array_t modeList; 20856b9ac4f2SChris Cain if (allowedModes == nullptr) 20866b9ac4f2SChris Cain { 20876b9ac4f2SChris Cain modeList.emplace_back("Static"); 20886b9ac4f2SChris Cain modeList.emplace_back("MaximumPerformance"); 20896b9ac4f2SChris Cain modeList.emplace_back("PowerSaving"); 20903a2d0424SChris Cain } 20913a2d0424SChris Cain else 20923a2d0424SChris Cain { 20936b9ac4f2SChris Cain for (const auto& aMode : *allowedModes) 20946b9ac4f2SChris Cain { 20956b9ac4f2SChris Cain computer_system::PowerMode modeValue = 20966b9ac4f2SChris Cain translatePowerModeString(aMode); 20976b9ac4f2SChris Cain if (modeValue == computer_system::PowerMode::Invalid) 20986b9ac4f2SChris Cain { 2099ac106bf6SEd Tanous messages::internalError(asyncResp->res); 21006b9ac4f2SChris Cain continue; 21016b9ac4f2SChris Cain } 21026b9ac4f2SChris Cain modeList.emplace_back(modeValue); 21033a2d0424SChris Cain } 21043a2d0424SChris Cain } 21056b9ac4f2SChris Cain asyncResp->res.jsonValue["PowerMode@Redfish.AllowableValues"] = modeList; 21063a2d0424SChris Cain 21076b9ac4f2SChris Cain BMCWEB_LOG_DEBUG("Current power mode: {}", powerMode); 21086b9ac4f2SChris Cain const computer_system::PowerMode modeValue = 21096b9ac4f2SChris Cain translatePowerModeString(powerMode); 21106b9ac4f2SChris Cain if (modeValue == computer_system::PowerMode::Invalid) 21116b9ac4f2SChris Cain { 21126b9ac4f2SChris Cain messages::internalError(asyncResp->res); 21136b9ac4f2SChris Cain return; 21146b9ac4f2SChris Cain } 21156b9ac4f2SChris Cain asyncResp->res.jsonValue["PowerMode"] = modeValue; 21166b9ac4f2SChris Cain } 21173a2d0424SChris Cain /** 21183a2d0424SChris Cain * @brief Retrieves system power mode 21193a2d0424SChris Cain * 2120ac106bf6SEd Tanous * @param[in] asyncResp Shared pointer for generating response message. 21213a2d0424SChris Cain * 21223a2d0424SChris Cain * @return None. 21233a2d0424SChris Cain */ 2124ac106bf6SEd Tanous inline void getPowerMode(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) 21253a2d0424SChris Cain { 212662598e31SEd Tanous BMCWEB_LOG_DEBUG("Get power mode."); 21273a2d0424SChris Cain 21283a2d0424SChris Cain // Get Power Mode object path: 2129e99073f5SGeorge Liu constexpr std::array<std::string_view, 1> interfaces = { 2130e99073f5SGeorge Liu "xyz.openbmc_project.Control.Power.Mode"}; 2131e99073f5SGeorge Liu dbus::utility::getSubTree( 2132e99073f5SGeorge Liu "/", 0, interfaces, 2133ac106bf6SEd Tanous [asyncResp](const boost::system::error_code& ec, 2134b9d36b47SEd Tanous const dbus::utility::MapperGetSubTreeResponse& subtree) { 21353a2d0424SChris Cain if (ec) 21363a2d0424SChris Cain { 213762598e31SEd Tanous BMCWEB_LOG_DEBUG("DBUS response error on Power.Mode GetSubTree {}", 213862598e31SEd Tanous ec); 21393a2d0424SChris Cain // This is an optional D-Bus object so just return if 21403a2d0424SChris Cain // error occurs 21413a2d0424SChris Cain return; 21423a2d0424SChris Cain } 21433a2d0424SChris Cain if (subtree.empty()) 21443a2d0424SChris Cain { 21453a2d0424SChris Cain // As noted above, this is an optional interface so just return 21463a2d0424SChris Cain // if there is no instance found 21473a2d0424SChris Cain return; 21483a2d0424SChris Cain } 21493a2d0424SChris Cain if (subtree.size() > 1) 21503a2d0424SChris Cain { 21513a2d0424SChris Cain // More then one PowerMode object is not supported and is an 21523a2d0424SChris Cain // error 215362598e31SEd Tanous BMCWEB_LOG_DEBUG( 215462598e31SEd Tanous "Found more than 1 system D-Bus Power.Mode objects: {}", 215562598e31SEd Tanous subtree.size()); 2156ac106bf6SEd Tanous messages::internalError(asyncResp->res); 21573a2d0424SChris Cain return; 21583a2d0424SChris Cain } 21593a2d0424SChris Cain if ((subtree[0].first.empty()) || (subtree[0].second.size() != 1)) 21603a2d0424SChris Cain { 216162598e31SEd Tanous BMCWEB_LOG_DEBUG("Power.Mode mapper error!"); 2162ac106bf6SEd Tanous messages::internalError(asyncResp->res); 21633a2d0424SChris Cain return; 21643a2d0424SChris Cain } 21653a2d0424SChris Cain const std::string& path = subtree[0].first; 21663a2d0424SChris Cain const std::string& service = subtree[0].second.begin()->first; 21673a2d0424SChris Cain if (service.empty()) 21683a2d0424SChris Cain { 216962598e31SEd Tanous BMCWEB_LOG_DEBUG("Power.Mode service mapper error!"); 2170ac106bf6SEd Tanous messages::internalError(asyncResp->res); 21713a2d0424SChris Cain return; 21723a2d0424SChris Cain } 21736b9ac4f2SChris Cain 21746b9ac4f2SChris Cain // Valid Power Mode object found, now read the mode properties 21756b9ac4f2SChris Cain sdbusplus::asio::getAllProperties( 21761e1e598dSJonathan Doman *crow::connections::systemBus, service, path, 21776b9ac4f2SChris Cain "xyz.openbmc_project.Control.Power.Mode", 2178ac106bf6SEd Tanous [asyncResp](const boost::system::error_code& ec2, 21796b9ac4f2SChris Cain const dbus::utility::DBusPropertiesMap& properties) { 21806b9ac4f2SChris Cain afterGetPowerMode(asyncResp, ec2, properties); 21811e1e598dSJonathan Doman }); 2182e99073f5SGeorge Liu }); 21833a2d0424SChris Cain } 21843a2d0424SChris Cain 21853a2d0424SChris Cain /** 21863a2d0424SChris Cain * @brief Validate the specified mode is valid and return the PowerMode 21873a2d0424SChris Cain * name associated with that string 21883a2d0424SChris Cain * 2189ac106bf6SEd Tanous * @param[in] asyncResp Shared pointer for generating response message. 2190b6655101SChris Cain * @param[in] modeValue String representing the desired PowerMode 21913a2d0424SChris Cain * 21923a2d0424SChris Cain * @return PowerMode value or empty string if mode is not valid 21933a2d0424SChris Cain */ 21943a2d0424SChris Cain inline std::string 2195ac106bf6SEd Tanous validatePowerMode(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 2196b6655101SChris Cain const nlohmann::json& modeValue) 21973a2d0424SChris Cain { 2198b6655101SChris Cain using PowerMode = computer_system::PowerMode; 21993a2d0424SChris Cain std::string mode; 22003a2d0424SChris Cain 2201b6655101SChris Cain if (modeValue == PowerMode::Static) 22023a2d0424SChris Cain { 22033a2d0424SChris Cain mode = "xyz.openbmc_project.Control.Power.Mode.PowerMode.Static"; 22043a2d0424SChris Cain } 2205b6655101SChris Cain else if (modeValue == PowerMode::MaximumPerformance) 22063a2d0424SChris Cain { 22070fda0f12SGeorge Liu mode = 22080fda0f12SGeorge Liu "xyz.openbmc_project.Control.Power.Mode.PowerMode.MaximumPerformance"; 22093a2d0424SChris Cain } 2210b6655101SChris Cain else if (modeValue == PowerMode::PowerSaving) 22113a2d0424SChris Cain { 22123a2d0424SChris Cain mode = "xyz.openbmc_project.Control.Power.Mode.PowerMode.PowerSaving"; 22133a2d0424SChris Cain } 2214b6655101SChris Cain else if (modeValue == PowerMode::BalancedPerformance) 2215b6655101SChris Cain { 2216b6655101SChris Cain mode = 2217b6655101SChris Cain "xyz.openbmc_project.Control.Power.Mode.PowerMode.BalancedPerformance"; 2218b6655101SChris Cain } 2219b6655101SChris Cain else if (modeValue == PowerMode::EfficiencyFavorPerformance) 2220b6655101SChris Cain { 2221b6655101SChris Cain mode = 2222b6655101SChris Cain "xyz.openbmc_project.Control.Power.Mode.PowerMode.EfficiencyFavorPerformance"; 2223b6655101SChris Cain } 2224b6655101SChris Cain else if (modeValue == PowerMode::EfficiencyFavorPower) 2225b6655101SChris Cain { 2226b6655101SChris Cain mode = 2227b6655101SChris Cain "xyz.openbmc_project.Control.Power.Mode.PowerMode.EfficiencyFavorPower"; 2228b6655101SChris Cain } 22293a2d0424SChris Cain else 22303a2d0424SChris Cain { 2231b6655101SChris Cain messages::propertyValueNotInList(asyncResp->res, modeValue.dump(), 2232ac106bf6SEd Tanous "PowerMode"); 22333a2d0424SChris Cain } 22343a2d0424SChris Cain return mode; 22353a2d0424SChris Cain } 22363a2d0424SChris Cain 22373a2d0424SChris Cain /** 22383a2d0424SChris Cain * @brief Sets system power mode. 22393a2d0424SChris Cain * 2240ac106bf6SEd Tanous * @param[in] asyncResp Shared pointer for generating response message. 22413a2d0424SChris Cain * @param[in] pmode System power mode from request. 22423a2d0424SChris Cain * 22433a2d0424SChris Cain * @return None. 22443a2d0424SChris Cain */ 2245ac106bf6SEd Tanous inline void setPowerMode(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 22463a2d0424SChris Cain const std::string& pmode) 22473a2d0424SChris Cain { 224862598e31SEd Tanous BMCWEB_LOG_DEBUG("Set power mode."); 22493a2d0424SChris Cain 2250ac106bf6SEd Tanous std::string powerMode = validatePowerMode(asyncResp, pmode); 22513a2d0424SChris Cain if (powerMode.empty()) 22523a2d0424SChris Cain { 22533a2d0424SChris Cain return; 22543a2d0424SChris Cain } 22553a2d0424SChris Cain 22563a2d0424SChris Cain // Get Power Mode object path: 2257e99073f5SGeorge Liu constexpr std::array<std::string_view, 1> interfaces = { 2258e99073f5SGeorge Liu "xyz.openbmc_project.Control.Power.Mode"}; 2259e99073f5SGeorge Liu dbus::utility::getSubTree( 2260e99073f5SGeorge Liu "/", 0, interfaces, 2261ac106bf6SEd Tanous [asyncResp, 2262e99073f5SGeorge Liu powerMode](const boost::system::error_code& ec, 2263b9d36b47SEd Tanous const dbus::utility::MapperGetSubTreeResponse& subtree) { 22643a2d0424SChris Cain if (ec) 22653a2d0424SChris Cain { 2266b3e86cb0SGunnar Mills BMCWEB_LOG_ERROR("DBUS response error on Power.Mode GetSubTree {}", 226762598e31SEd Tanous ec); 22683a2d0424SChris Cain // This is an optional D-Bus object, but user attempted to patch 2269ac106bf6SEd Tanous messages::internalError(asyncResp->res); 22703a2d0424SChris Cain return; 22713a2d0424SChris Cain } 22723a2d0424SChris Cain if (subtree.empty()) 22733a2d0424SChris Cain { 22743a2d0424SChris Cain // This is an optional D-Bus object, but user attempted to patch 2275ac106bf6SEd Tanous messages::resourceNotFound(asyncResp->res, "ComputerSystem", 22763a2d0424SChris Cain "PowerMode"); 22773a2d0424SChris Cain return; 22783a2d0424SChris Cain } 22793a2d0424SChris Cain if (subtree.size() > 1) 22803a2d0424SChris Cain { 22813a2d0424SChris Cain // More then one PowerMode object is not supported and is an 22823a2d0424SChris Cain // error 228362598e31SEd Tanous BMCWEB_LOG_DEBUG( 228462598e31SEd Tanous "Found more than 1 system D-Bus Power.Mode objects: {}", 228562598e31SEd Tanous subtree.size()); 2286ac106bf6SEd Tanous messages::internalError(asyncResp->res); 22873a2d0424SChris Cain return; 22883a2d0424SChris Cain } 22893a2d0424SChris Cain if ((subtree[0].first.empty()) || (subtree[0].second.size() != 1)) 22903a2d0424SChris Cain { 229162598e31SEd Tanous BMCWEB_LOG_DEBUG("Power.Mode mapper error!"); 2292ac106bf6SEd Tanous messages::internalError(asyncResp->res); 22933a2d0424SChris Cain return; 22943a2d0424SChris Cain } 22953a2d0424SChris Cain const std::string& path = subtree[0].first; 22963a2d0424SChris Cain const std::string& service = subtree[0].second.begin()->first; 22973a2d0424SChris Cain if (service.empty()) 22983a2d0424SChris Cain { 229962598e31SEd Tanous BMCWEB_LOG_DEBUG("Power.Mode service mapper error!"); 2300ac106bf6SEd Tanous messages::internalError(asyncResp->res); 23013a2d0424SChris Cain return; 23023a2d0424SChris Cain } 23033a2d0424SChris Cain 230462598e31SEd Tanous BMCWEB_LOG_DEBUG("Setting power mode({}) -> {}", powerMode, path); 23053a2d0424SChris Cain 23063a2d0424SChris Cain // Set the Power Mode property 230787c44966SAsmitha Karunanithi setDbusProperty(asyncResp, service, path, 230887c44966SAsmitha Karunanithi "xyz.openbmc_project.Control.Power.Mode", "PowerMode", 230987c44966SAsmitha Karunanithi "PowerMode", powerMode); 2310e99073f5SGeorge Liu }); 23113a2d0424SChris Cain } 23123a2d0424SChris Cain 23133a2d0424SChris Cain /** 231451709ffdSYong Li * @brief Translates watchdog timeout action DBUS property value to redfish. 231551709ffdSYong Li * 231651709ffdSYong Li * @param[in] dbusAction The watchdog timeout action in D-BUS. 231751709ffdSYong Li * 231851709ffdSYong Li * @return Returns as a string, the timeout action in Redfish terms. If 231951709ffdSYong Li * translation cannot be done, returns an empty string. 232051709ffdSYong Li */ 232123a21a1cSEd Tanous inline std::string dbusToRfWatchdogAction(const std::string& dbusAction) 232251709ffdSYong Li { 232351709ffdSYong Li if (dbusAction == "xyz.openbmc_project.State.Watchdog.Action.None") 232451709ffdSYong Li { 232551709ffdSYong Li return "None"; 232651709ffdSYong Li } 23273174e4dfSEd Tanous if (dbusAction == "xyz.openbmc_project.State.Watchdog.Action.HardReset") 232851709ffdSYong Li { 232951709ffdSYong Li return "ResetSystem"; 233051709ffdSYong Li } 23313174e4dfSEd Tanous if (dbusAction == "xyz.openbmc_project.State.Watchdog.Action.PowerOff") 233251709ffdSYong Li { 233351709ffdSYong Li return "PowerDown"; 233451709ffdSYong Li } 23353174e4dfSEd Tanous if (dbusAction == "xyz.openbmc_project.State.Watchdog.Action.PowerCycle") 233651709ffdSYong Li { 233751709ffdSYong Li return "PowerCycle"; 233851709ffdSYong Li } 233951709ffdSYong Li 234051709ffdSYong Li return ""; 234151709ffdSYong Li } 234251709ffdSYong Li 234351709ffdSYong Li /** 2344c45f0082SYong Li *@brief Translates timeout action from Redfish to DBUS property value. 2345c45f0082SYong Li * 2346c45f0082SYong Li *@param[in] rfAction The timeout action in Redfish. 2347c45f0082SYong Li * 2348c45f0082SYong Li *@return Returns as a string, the time_out action as expected by DBUS. 2349c45f0082SYong Li *If translation cannot be done, returns an empty string. 2350c45f0082SYong Li */ 2351c45f0082SYong Li 235223a21a1cSEd Tanous inline std::string rfToDbusWDTTimeOutAct(const std::string& rfAction) 2353c45f0082SYong Li { 2354c45f0082SYong Li if (rfAction == "None") 2355c45f0082SYong Li { 2356c45f0082SYong Li return "xyz.openbmc_project.State.Watchdog.Action.None"; 2357c45f0082SYong Li } 23583174e4dfSEd Tanous if (rfAction == "PowerCycle") 2359c45f0082SYong Li { 2360c45f0082SYong Li return "xyz.openbmc_project.State.Watchdog.Action.PowerCycle"; 2361c45f0082SYong Li } 23623174e4dfSEd Tanous if (rfAction == "PowerDown") 2363c45f0082SYong Li { 2364c45f0082SYong Li return "xyz.openbmc_project.State.Watchdog.Action.PowerOff"; 2365c45f0082SYong Li } 23663174e4dfSEd Tanous if (rfAction == "ResetSystem") 2367c45f0082SYong Li { 2368c45f0082SYong Li return "xyz.openbmc_project.State.Watchdog.Action.HardReset"; 2369c45f0082SYong Li } 2370c45f0082SYong Li 2371c45f0082SYong Li return ""; 2372c45f0082SYong Li } 2373c45f0082SYong Li 2374c45f0082SYong Li /** 237551709ffdSYong Li * @brief Retrieves host watchdog timer properties over DBUS 237651709ffdSYong Li * 2377ac106bf6SEd Tanous * @param[in] asyncResp Shared pointer for completing asynchronous calls. 237851709ffdSYong Li * 237951709ffdSYong Li * @return None. 238051709ffdSYong Li */ 23818d1b46d7Szhanghch05 inline void 2382ac106bf6SEd Tanous getHostWatchdogTimer(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) 238351709ffdSYong Li { 238462598e31SEd Tanous BMCWEB_LOG_DEBUG("Get host watchodg"); 2385bc1d29deSKrzysztof Grobelny sdbusplus::asio::getAllProperties( 2386bc1d29deSKrzysztof Grobelny *crow::connections::systemBus, "xyz.openbmc_project.Watchdog", 2387bc1d29deSKrzysztof Grobelny "/xyz/openbmc_project/watchdog/host0", 2388bc1d29deSKrzysztof Grobelny "xyz.openbmc_project.State.Watchdog", 2389ac106bf6SEd Tanous [asyncResp](const boost::system::error_code& ec, 2390b9d36b47SEd Tanous const dbus::utility::DBusPropertiesMap& properties) { 239151709ffdSYong Li if (ec) 239251709ffdSYong Li { 239351709ffdSYong Li // watchdog service is stopped 239462598e31SEd Tanous BMCWEB_LOG_DEBUG("DBUS response error {}", ec); 239551709ffdSYong Li return; 239651709ffdSYong Li } 239751709ffdSYong Li 239862598e31SEd Tanous BMCWEB_LOG_DEBUG("Got {} wdt prop.", properties.size()); 239951709ffdSYong Li 240051709ffdSYong Li nlohmann::json& hostWatchdogTimer = 2401ac106bf6SEd Tanous asyncResp->res.jsonValue["HostWatchdogTimer"]; 240251709ffdSYong Li 240351709ffdSYong Li // watchdog service is running/enabled 240451709ffdSYong Li hostWatchdogTimer["Status"]["State"] = "Enabled"; 240551709ffdSYong Li 2406bc1d29deSKrzysztof Grobelny const bool* enabled = nullptr; 2407bc1d29deSKrzysztof Grobelny const std::string* expireAction = nullptr; 240851709ffdSYong Li 2409bc1d29deSKrzysztof Grobelny const bool success = sdbusplus::unpackPropertiesNoThrow( 2410bc1d29deSKrzysztof Grobelny dbus_utils::UnpackErrorPrinter(), properties, "Enabled", enabled, 2411bc1d29deSKrzysztof Grobelny "ExpireAction", expireAction); 2412bc1d29deSKrzysztof Grobelny 2413bc1d29deSKrzysztof Grobelny if (!success) 241451709ffdSYong Li { 2415ac106bf6SEd Tanous messages::internalError(asyncResp->res); 2416601af5edSChicago Duan return; 241751709ffdSYong Li } 241851709ffdSYong Li 2419bc1d29deSKrzysztof Grobelny if (enabled != nullptr) 242051709ffdSYong Li { 2421bc1d29deSKrzysztof Grobelny hostWatchdogTimer["FunctionEnabled"] = *enabled; 242251709ffdSYong Li } 242351709ffdSYong Li 2424bc1d29deSKrzysztof Grobelny if (expireAction != nullptr) 2425bc1d29deSKrzysztof Grobelny { 2426bc1d29deSKrzysztof Grobelny std::string action = dbusToRfWatchdogAction(*expireAction); 242751709ffdSYong Li if (action.empty()) 242851709ffdSYong Li { 2429ac106bf6SEd Tanous messages::internalError(asyncResp->res); 2430601af5edSChicago Duan return; 243151709ffdSYong Li } 243251709ffdSYong Li hostWatchdogTimer["TimeoutAction"] = action; 243351709ffdSYong Li } 2434bc1d29deSKrzysztof Grobelny }); 243551709ffdSYong Li } 243651709ffdSYong Li 243751709ffdSYong Li /** 2438c45f0082SYong Li * @brief Sets Host WatchDog Timer properties. 2439c45f0082SYong Li * 2440ac106bf6SEd Tanous * @param[in] asyncResp Shared pointer for generating response message. 2441c45f0082SYong Li * @param[in] wdtEnable The WDTimer Enable value (true/false) from incoming 2442c45f0082SYong Li * RF request. 2443c45f0082SYong Li * @param[in] wdtTimeOutAction The WDT Timeout action, from incoming RF request. 2444c45f0082SYong Li * 2445c45f0082SYong Li * @return None. 2446c45f0082SYong Li */ 2447ac106bf6SEd Tanous inline void 2448ac106bf6SEd Tanous setWDTProperties(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 2449c45f0082SYong Li const std::optional<bool> wdtEnable, 2450c45f0082SYong Li const std::optional<std::string>& wdtTimeOutAction) 2451c45f0082SYong Li { 245262598e31SEd Tanous BMCWEB_LOG_DEBUG("Set host watchdog"); 2453c45f0082SYong Li 2454c45f0082SYong Li if (wdtTimeOutAction) 2455c45f0082SYong Li { 2456c45f0082SYong Li std::string wdtTimeOutActStr = rfToDbusWDTTimeOutAct(*wdtTimeOutAction); 2457c45f0082SYong Li // check if TimeOut Action is Valid 2458c45f0082SYong Li if (wdtTimeOutActStr.empty()) 2459c45f0082SYong Li { 246062598e31SEd Tanous BMCWEB_LOG_DEBUG("Unsupported value for TimeoutAction: {}", 246162598e31SEd Tanous *wdtTimeOutAction); 2462ac106bf6SEd Tanous messages::propertyValueNotInList(asyncResp->res, *wdtTimeOutAction, 2463c45f0082SYong Li "TimeoutAction"); 2464c45f0082SYong Li return; 2465c45f0082SYong Li } 2466c45f0082SYong Li 246787c44966SAsmitha Karunanithi setDbusProperty(asyncResp, "xyz.openbmc_project.Watchdog", 246887c44966SAsmitha Karunanithi sdbusplus::message::object_path( 246987c44966SAsmitha Karunanithi "/xyz/openbmc_project/watchdog/host0"), 24709ae226faSGeorge Liu "xyz.openbmc_project.State.Watchdog", "ExpireAction", 247187c44966SAsmitha Karunanithi "HostWatchdogTimer/TimeoutAction", wdtTimeOutActStr); 2472c45f0082SYong Li } 2473c45f0082SYong Li 2474c45f0082SYong Li if (wdtEnable) 2475c45f0082SYong Li { 247687c44966SAsmitha Karunanithi setDbusProperty(asyncResp, "xyz.openbmc_project.Watchdog", 247787c44966SAsmitha Karunanithi sdbusplus::message::object_path( 247887c44966SAsmitha Karunanithi "/xyz/openbmc_project/watchdog/host0"), 247987c44966SAsmitha Karunanithi "xyz.openbmc_project.State.Watchdog", "Enabled", 248087c44966SAsmitha Karunanithi "HostWatchdogTimer/FunctionEnabled", *wdtEnable); 2481c45f0082SYong Li } 2482c45f0082SYong Li } 2483c45f0082SYong Li 248437bbf98cSChris Cain /** 248537bbf98cSChris Cain * @brief Parse the Idle Power Saver properties into json 248637bbf98cSChris Cain * 2487ac106bf6SEd Tanous * @param[in] asyncResp Shared pointer for completing asynchronous calls. 248837bbf98cSChris Cain * @param[in] properties IPS property data from DBus. 248937bbf98cSChris Cain * 249037bbf98cSChris Cain * @return true if successful 249137bbf98cSChris Cain */ 24921e5b7c88SJiaqing Zhao inline bool 2493ac106bf6SEd Tanous parseIpsProperties(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 24941e5b7c88SJiaqing Zhao const dbus::utility::DBusPropertiesMap& properties) 249537bbf98cSChris Cain { 2496bc1d29deSKrzysztof Grobelny const bool* enabled = nullptr; 2497bc1d29deSKrzysztof Grobelny const uint8_t* enterUtilizationPercent = nullptr; 2498bc1d29deSKrzysztof Grobelny const uint64_t* enterDwellTime = nullptr; 2499bc1d29deSKrzysztof Grobelny const uint8_t* exitUtilizationPercent = nullptr; 2500bc1d29deSKrzysztof Grobelny const uint64_t* exitDwellTime = nullptr; 2501bc1d29deSKrzysztof Grobelny 2502bc1d29deSKrzysztof Grobelny const bool success = sdbusplus::unpackPropertiesNoThrow( 2503bc1d29deSKrzysztof Grobelny dbus_utils::UnpackErrorPrinter(), properties, "Enabled", enabled, 25042661b72cSChris Cain "EnterUtilizationPercent", enterUtilizationPercent, "EnterDwellTime", 25052661b72cSChris Cain enterDwellTime, "ExitUtilizationPercent", exitUtilizationPercent, 25062661b72cSChris Cain "ExitDwellTime", exitDwellTime); 2507bc1d29deSKrzysztof Grobelny 2508bc1d29deSKrzysztof Grobelny if (!success) 250937bbf98cSChris Cain { 251037bbf98cSChris Cain return false; 251137bbf98cSChris Cain } 2512bc1d29deSKrzysztof Grobelny 2513bc1d29deSKrzysztof Grobelny if (enabled != nullptr) 251437bbf98cSChris Cain { 2515ac106bf6SEd Tanous asyncResp->res.jsonValue["IdlePowerSaver"]["Enabled"] = *enabled; 251637bbf98cSChris Cain } 2517bc1d29deSKrzysztof Grobelny 2518bc1d29deSKrzysztof Grobelny if (enterUtilizationPercent != nullptr) 251937bbf98cSChris Cain { 2520ac106bf6SEd Tanous asyncResp->res.jsonValue["IdlePowerSaver"]["EnterUtilizationPercent"] = 2521bc1d29deSKrzysztof Grobelny *enterUtilizationPercent; 252237bbf98cSChris Cain } 2523bc1d29deSKrzysztof Grobelny 2524bc1d29deSKrzysztof Grobelny if (enterDwellTime != nullptr) 2525bc1d29deSKrzysztof Grobelny { 2526bc1d29deSKrzysztof Grobelny const std::chrono::duration<uint64_t, std::milli> ms(*enterDwellTime); 2527ac106bf6SEd Tanous asyncResp->res.jsonValue["IdlePowerSaver"]["EnterDwellTimeSeconds"] = 252837bbf98cSChris Cain std::chrono::duration_cast<std::chrono::duration<uint64_t>>(ms) 252937bbf98cSChris Cain .count(); 253037bbf98cSChris Cain } 2531bc1d29deSKrzysztof Grobelny 2532bc1d29deSKrzysztof Grobelny if (exitUtilizationPercent != nullptr) 253337bbf98cSChris Cain { 2534ac106bf6SEd Tanous asyncResp->res.jsonValue["IdlePowerSaver"]["ExitUtilizationPercent"] = 2535bc1d29deSKrzysztof Grobelny *exitUtilizationPercent; 253637bbf98cSChris Cain } 2537bc1d29deSKrzysztof Grobelny 2538bc1d29deSKrzysztof Grobelny if (exitDwellTime != nullptr) 253937bbf98cSChris Cain { 2540bc1d29deSKrzysztof Grobelny const std::chrono::duration<uint64_t, std::milli> ms(*exitDwellTime); 2541ac106bf6SEd Tanous asyncResp->res.jsonValue["IdlePowerSaver"]["ExitDwellTimeSeconds"] = 254237bbf98cSChris Cain std::chrono::duration_cast<std::chrono::duration<uint64_t>>(ms) 254337bbf98cSChris Cain .count(); 254437bbf98cSChris Cain } 254537bbf98cSChris Cain 254637bbf98cSChris Cain return true; 254737bbf98cSChris Cain } 254837bbf98cSChris Cain 254937bbf98cSChris Cain /** 255037bbf98cSChris Cain * @brief Retrieves host watchdog timer properties over DBUS 255137bbf98cSChris Cain * 2552ac106bf6SEd Tanous * @param[in] asyncResp Shared pointer for completing asynchronous calls. 255337bbf98cSChris Cain * 255437bbf98cSChris Cain * @return None. 255537bbf98cSChris Cain */ 2556ac106bf6SEd Tanous inline void 2557ac106bf6SEd Tanous getIdlePowerSaver(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) 255837bbf98cSChris Cain { 255962598e31SEd Tanous BMCWEB_LOG_DEBUG("Get idle power saver parameters"); 256037bbf98cSChris Cain 256137bbf98cSChris Cain // Get IdlePowerSaver object path: 2562e99073f5SGeorge Liu constexpr std::array<std::string_view, 1> interfaces = { 2563e99073f5SGeorge Liu "xyz.openbmc_project.Control.Power.IdlePowerSaver"}; 2564e99073f5SGeorge Liu dbus::utility::getSubTree( 2565e99073f5SGeorge Liu "/", 0, interfaces, 2566ac106bf6SEd Tanous [asyncResp](const boost::system::error_code& ec, 2567b9d36b47SEd Tanous const dbus::utility::MapperGetSubTreeResponse& subtree) { 256837bbf98cSChris Cain if (ec) 256937bbf98cSChris Cain { 2570b3e86cb0SGunnar Mills BMCWEB_LOG_ERROR( 257162598e31SEd Tanous "DBUS response error on Power.IdlePowerSaver GetSubTree {}", 257262598e31SEd Tanous ec); 2573ac106bf6SEd Tanous messages::internalError(asyncResp->res); 257437bbf98cSChris Cain return; 257537bbf98cSChris Cain } 257637bbf98cSChris Cain if (subtree.empty()) 257737bbf98cSChris Cain { 257837bbf98cSChris Cain // This is an optional interface so just return 257937bbf98cSChris Cain // if there is no instance found 258062598e31SEd Tanous BMCWEB_LOG_DEBUG("No instances found"); 258137bbf98cSChris Cain return; 258237bbf98cSChris Cain } 258337bbf98cSChris Cain if (subtree.size() > 1) 258437bbf98cSChris Cain { 258537bbf98cSChris Cain // More then one PowerIdlePowerSaver object is not supported and 258637bbf98cSChris Cain // is an error 258762598e31SEd Tanous BMCWEB_LOG_DEBUG("Found more than 1 system D-Bus " 258862598e31SEd Tanous "Power.IdlePowerSaver objects: {}", 258962598e31SEd Tanous subtree.size()); 2590ac106bf6SEd Tanous messages::internalError(asyncResp->res); 259137bbf98cSChris Cain return; 259237bbf98cSChris Cain } 259337bbf98cSChris Cain if ((subtree[0].first.empty()) || (subtree[0].second.size() != 1)) 259437bbf98cSChris Cain { 259562598e31SEd Tanous BMCWEB_LOG_DEBUG("Power.IdlePowerSaver mapper error!"); 2596ac106bf6SEd Tanous messages::internalError(asyncResp->res); 259737bbf98cSChris Cain return; 259837bbf98cSChris Cain } 259937bbf98cSChris Cain const std::string& path = subtree[0].first; 260037bbf98cSChris Cain const std::string& service = subtree[0].second.begin()->first; 260137bbf98cSChris Cain if (service.empty()) 260237bbf98cSChris Cain { 260362598e31SEd Tanous BMCWEB_LOG_DEBUG("Power.IdlePowerSaver service mapper error!"); 2604ac106bf6SEd Tanous messages::internalError(asyncResp->res); 260537bbf98cSChris Cain return; 260637bbf98cSChris Cain } 260737bbf98cSChris Cain 260837bbf98cSChris Cain // Valid IdlePowerSaver object found, now read the current values 2609bc1d29deSKrzysztof Grobelny sdbusplus::asio::getAllProperties( 2610bc1d29deSKrzysztof Grobelny *crow::connections::systemBus, service, path, 2611bc1d29deSKrzysztof Grobelny "xyz.openbmc_project.Control.Power.IdlePowerSaver", 2612ac106bf6SEd Tanous [asyncResp](const boost::system::error_code& ec2, 26131e5b7c88SJiaqing Zhao const dbus::utility::DBusPropertiesMap& properties) { 26148a592810SEd Tanous if (ec2) 261537bbf98cSChris Cain { 261662598e31SEd Tanous BMCWEB_LOG_ERROR( 261762598e31SEd Tanous "DBUS response error on IdlePowerSaver GetAll: {}", ec2); 2618ac106bf6SEd Tanous messages::internalError(asyncResp->res); 261937bbf98cSChris Cain return; 262037bbf98cSChris Cain } 262137bbf98cSChris Cain 2622ac106bf6SEd Tanous if (!parseIpsProperties(asyncResp, properties)) 262337bbf98cSChris Cain { 2624ac106bf6SEd Tanous messages::internalError(asyncResp->res); 262537bbf98cSChris Cain return; 262637bbf98cSChris Cain } 2627bc1d29deSKrzysztof Grobelny }); 2628e99073f5SGeorge Liu }); 262937bbf98cSChris Cain 263062598e31SEd Tanous BMCWEB_LOG_DEBUG("EXIT: Get idle power saver parameters"); 263137bbf98cSChris Cain } 263237bbf98cSChris Cain 263337bbf98cSChris Cain /** 263437bbf98cSChris Cain * @brief Sets Idle Power Saver properties. 263537bbf98cSChris Cain * 2636ac106bf6SEd Tanous * @param[in] asyncResp Shared pointer for generating response message. 263737bbf98cSChris Cain * @param[in] ipsEnable The IPS Enable value (true/false) from incoming 263837bbf98cSChris Cain * RF request. 263937bbf98cSChris Cain * @param[in] ipsEnterUtil The utilization limit to enter idle state. 264037bbf98cSChris Cain * @param[in] ipsEnterTime The time the utilization must be below ipsEnterUtil 264137bbf98cSChris Cain * before entering idle state. 264237bbf98cSChris Cain * @param[in] ipsExitUtil The utilization limit when exiting idle state. 264337bbf98cSChris Cain * @param[in] ipsExitTime The time the utilization must be above ipsExutUtil 264437bbf98cSChris Cain * before exiting idle state 264537bbf98cSChris Cain * 264637bbf98cSChris Cain * @return None. 264737bbf98cSChris Cain */ 2648ac106bf6SEd Tanous inline void 2649ac106bf6SEd Tanous setIdlePowerSaver(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 265037bbf98cSChris Cain const std::optional<bool> ipsEnable, 265137bbf98cSChris Cain const std::optional<uint8_t> ipsEnterUtil, 265237bbf98cSChris Cain const std::optional<uint64_t> ipsEnterTime, 265337bbf98cSChris Cain const std::optional<uint8_t> ipsExitUtil, 265437bbf98cSChris Cain const std::optional<uint64_t> ipsExitTime) 265537bbf98cSChris Cain { 265662598e31SEd Tanous BMCWEB_LOG_DEBUG("Set idle power saver properties"); 265737bbf98cSChris Cain 265837bbf98cSChris Cain // Get IdlePowerSaver object path: 2659e99073f5SGeorge Liu constexpr std::array<std::string_view, 1> interfaces = { 2660e99073f5SGeorge Liu "xyz.openbmc_project.Control.Power.IdlePowerSaver"}; 2661e99073f5SGeorge Liu dbus::utility::getSubTree( 2662e99073f5SGeorge Liu "/", 0, interfaces, 2663ac106bf6SEd Tanous [asyncResp, ipsEnable, ipsEnterUtil, ipsEnterTime, ipsExitUtil, 2664e99073f5SGeorge Liu ipsExitTime](const boost::system::error_code& ec, 2665b9d36b47SEd Tanous const dbus::utility::MapperGetSubTreeResponse& subtree) { 266637bbf98cSChris Cain if (ec) 266737bbf98cSChris Cain { 2668b3e86cb0SGunnar Mills BMCWEB_LOG_ERROR( 266962598e31SEd Tanous "DBUS response error on Power.IdlePowerSaver GetSubTree {}", 267062598e31SEd Tanous ec); 2671ac106bf6SEd Tanous messages::internalError(asyncResp->res); 267237bbf98cSChris Cain return; 267337bbf98cSChris Cain } 267437bbf98cSChris Cain if (subtree.empty()) 267537bbf98cSChris Cain { 267637bbf98cSChris Cain // This is an optional D-Bus object, but user attempted to patch 2677ac106bf6SEd Tanous messages::resourceNotFound(asyncResp->res, "ComputerSystem", 267837bbf98cSChris Cain "IdlePowerSaver"); 267937bbf98cSChris Cain return; 268037bbf98cSChris Cain } 268137bbf98cSChris Cain if (subtree.size() > 1) 268237bbf98cSChris Cain { 268337bbf98cSChris Cain // More then one PowerIdlePowerSaver object is not supported and 268437bbf98cSChris Cain // is an error 268562598e31SEd Tanous BMCWEB_LOG_DEBUG( 268662598e31SEd Tanous "Found more than 1 system D-Bus Power.IdlePowerSaver objects: {}", 268762598e31SEd Tanous subtree.size()); 2688ac106bf6SEd Tanous messages::internalError(asyncResp->res); 268937bbf98cSChris Cain return; 269037bbf98cSChris Cain } 269137bbf98cSChris Cain if ((subtree[0].first.empty()) || (subtree[0].second.size() != 1)) 269237bbf98cSChris Cain { 269362598e31SEd Tanous BMCWEB_LOG_DEBUG("Power.IdlePowerSaver mapper error!"); 2694ac106bf6SEd Tanous messages::internalError(asyncResp->res); 269537bbf98cSChris Cain return; 269637bbf98cSChris Cain } 269737bbf98cSChris Cain const std::string& path = subtree[0].first; 269837bbf98cSChris Cain const std::string& service = subtree[0].second.begin()->first; 269937bbf98cSChris Cain if (service.empty()) 270037bbf98cSChris Cain { 270162598e31SEd Tanous BMCWEB_LOG_DEBUG("Power.IdlePowerSaver service mapper error!"); 2702ac106bf6SEd Tanous messages::internalError(asyncResp->res); 270337bbf98cSChris Cain return; 270437bbf98cSChris Cain } 270537bbf98cSChris Cain 270637bbf98cSChris Cain // Valid Power IdlePowerSaver object found, now set any values that 270737bbf98cSChris Cain // need to be updated 270837bbf98cSChris Cain 270937bbf98cSChris Cain if (ipsEnable) 271037bbf98cSChris Cain { 271187c44966SAsmitha Karunanithi setDbusProperty(asyncResp, service, path, 271287c44966SAsmitha Karunanithi "xyz.openbmc_project.Control.Power.IdlePowerSaver", 271387c44966SAsmitha Karunanithi "Enabled", "IdlePowerSaver/Enabled", *ipsEnable); 271437bbf98cSChris Cain } 271537bbf98cSChris Cain if (ipsEnterUtil) 271637bbf98cSChris Cain { 271787c44966SAsmitha Karunanithi setDbusProperty(asyncResp, service, path, 27189ae226faSGeorge Liu "xyz.openbmc_project.Control.Power.IdlePowerSaver", 271987c44966SAsmitha Karunanithi "EnterUtilizationPercent", 272087c44966SAsmitha Karunanithi "IdlePowerSaver/EnterUtilizationPercent", 272187c44966SAsmitha Karunanithi *ipsEnterUtil); 272237bbf98cSChris Cain } 272337bbf98cSChris Cain if (ipsEnterTime) 272437bbf98cSChris Cain { 272537bbf98cSChris Cain // Convert from seconds into milliseconds for DBus 272637bbf98cSChris Cain const uint64_t timeMilliseconds = *ipsEnterTime * 1000; 272787c44966SAsmitha Karunanithi setDbusProperty(asyncResp, service, path, 27289ae226faSGeorge Liu "xyz.openbmc_project.Control.Power.IdlePowerSaver", 272987c44966SAsmitha Karunanithi "EnterDwellTime", 273087c44966SAsmitha Karunanithi "IdlePowerSaver/EnterDwellTimeSeconds", 273187c44966SAsmitha Karunanithi timeMilliseconds); 273237bbf98cSChris Cain } 273337bbf98cSChris Cain if (ipsExitUtil) 273437bbf98cSChris Cain { 273587c44966SAsmitha Karunanithi setDbusProperty(asyncResp, service, path, 27369ae226faSGeorge Liu "xyz.openbmc_project.Control.Power.IdlePowerSaver", 273787c44966SAsmitha Karunanithi "ExitUtilizationPercent", 273887c44966SAsmitha Karunanithi "IdlePowerSaver/ExitUtilizationPercent", 273987c44966SAsmitha Karunanithi *ipsExitUtil); 274037bbf98cSChris Cain } 274137bbf98cSChris Cain if (ipsExitTime) 274237bbf98cSChris Cain { 274337bbf98cSChris Cain // Convert from seconds into milliseconds for DBus 274437bbf98cSChris Cain const uint64_t timeMilliseconds = *ipsExitTime * 1000; 274587c44966SAsmitha Karunanithi setDbusProperty(asyncResp, service, path, 27469ae226faSGeorge Liu "xyz.openbmc_project.Control.Power.IdlePowerSaver", 274787c44966SAsmitha Karunanithi "ExitDwellTime", 274887c44966SAsmitha Karunanithi "IdlePowerSaver/ExitDwellTimeSeconds", 274987c44966SAsmitha Karunanithi timeMilliseconds); 275037bbf98cSChris Cain } 2751e99073f5SGeorge Liu }); 275237bbf98cSChris Cain 275362598e31SEd Tanous BMCWEB_LOG_DEBUG("EXIT: Set idle power saver parameters"); 275437bbf98cSChris Cain } 275537bbf98cSChris Cain 2756c1e219d5SEd Tanous inline void handleComputerSystemCollectionHead( 2757dd60b9edSEd Tanous crow::App& app, const crow::Request& req, 2758dd60b9edSEd Tanous const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) 2759dd60b9edSEd Tanous { 2760dd60b9edSEd Tanous if (!redfish::setUpRedfishRoute(app, req, asyncResp)) 2761dd60b9edSEd Tanous { 2762dd60b9edSEd Tanous return; 2763dd60b9edSEd Tanous } 2764dd60b9edSEd Tanous asyncResp->res.addHeader( 2765dd60b9edSEd Tanous boost::beast::http::field::link, 2766dd60b9edSEd Tanous "</redfish/v1/JsonSchemas/ComputerSystemCollection/ComputerSystemCollection.json>; rel=describedby"); 2767dd60b9edSEd Tanous } 2768dd60b9edSEd Tanous 2769c1e219d5SEd Tanous inline void handleComputerSystemCollectionGet( 2770c1e219d5SEd Tanous crow::App& app, const crow::Request& req, 2771c1e219d5SEd Tanous const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) 27721abe55efSEd Tanous { 27733ba00073SCarson Labrado if (!redfish::setUpRedfishRoute(app, req, asyncResp)) 2774f4c99e70SEd Tanous { 2775f4c99e70SEd Tanous return; 2776f4c99e70SEd Tanous } 2777dd60b9edSEd Tanous 2778dd60b9edSEd Tanous asyncResp->res.addHeader( 2779dd60b9edSEd Tanous boost::beast::http::field::link, 2780dd60b9edSEd Tanous "</redfish/v1/JsonSchemas/ComputerSystemCollection.json>; rel=describedby"); 27818d1b46d7Szhanghch05 asyncResp->res.jsonValue["@odata.type"] = 27820f74e643SEd Tanous "#ComputerSystemCollection.ComputerSystemCollection"; 27838d1b46d7Szhanghch05 asyncResp->res.jsonValue["@odata.id"] = "/redfish/v1/Systems"; 27848d1b46d7Szhanghch05 asyncResp->res.jsonValue["Name"] = "Computer System Collection"; 2785462023adSSunitha Harish 27867f3e84a1SEd Tanous nlohmann::json& ifaceArray = asyncResp->res.jsonValue["Members"]; 27877f3e84a1SEd Tanous ifaceArray = nlohmann::json::array(); 278825b54dbaSEd Tanous if constexpr (BMCWEB_EXPERIMENTAL_REDFISH_MULTI_COMPUTER_SYSTEM) 27897f3e84a1SEd Tanous { 27907f3e84a1SEd Tanous asyncResp->res.jsonValue["Members@odata.count"] = 0; 27917f3e84a1SEd Tanous // Option currently returns no systems. TBD 27927f3e84a1SEd Tanous return; 27937f3e84a1SEd Tanous } 27947f3e84a1SEd Tanous asyncResp->res.jsonValue["Members@odata.count"] = 1; 27957f3e84a1SEd Tanous nlohmann::json::object_t system; 2796253f11b8SEd Tanous system["@odata.id"] = boost::urls::format("/redfish/v1/Systems/{}", 2797253f11b8SEd Tanous BMCWEB_REDFISH_SYSTEM_URI_NAME); 27987f3e84a1SEd Tanous ifaceArray.emplace_back(std::move(system)); 27991e1e598dSJonathan Doman sdbusplus::asio::getProperty<std::string>( 2800002d39b4SEd Tanous *crow::connections::systemBus, "xyz.openbmc_project.Settings", 28011e1e598dSJonathan Doman "/xyz/openbmc_project/network/hypervisor", 2802002d39b4SEd Tanous "xyz.openbmc_project.Network.SystemConfiguration", "HostName", 28035e7e2dc5SEd Tanous [asyncResp](const boost::system::error_code& ec2, 28041e1e598dSJonathan Doman const std::string& /*hostName*/) { 28057f3e84a1SEd Tanous if (ec2) 2806462023adSSunitha Harish { 28077f3e84a1SEd Tanous return; 28087f3e84a1SEd Tanous } 28097f3e84a1SEd Tanous auto val = asyncResp->res.jsonValue.find("Members@odata.count"); 28107f3e84a1SEd Tanous if (val == asyncResp->res.jsonValue.end()) 28117f3e84a1SEd Tanous { 281262598e31SEd Tanous BMCWEB_LOG_CRITICAL("Count wasn't found??"); 28137f3e84a1SEd Tanous return; 28147f3e84a1SEd Tanous } 28157f3e84a1SEd Tanous uint64_t* count = val->get_ptr<uint64_t*>(); 28167f3e84a1SEd Tanous if (count == nullptr) 28177f3e84a1SEd Tanous { 281862598e31SEd Tanous BMCWEB_LOG_CRITICAL("Count wasn't found??"); 28197f3e84a1SEd Tanous return; 28207f3e84a1SEd Tanous } 28217f3e84a1SEd Tanous *count = *count + 1; 282262598e31SEd Tanous BMCWEB_LOG_DEBUG("Hypervisor is available"); 28237f3e84a1SEd Tanous nlohmann::json& ifaceArray2 = asyncResp->res.jsonValue["Members"]; 28241476687dSEd Tanous nlohmann::json::object_t hypervisor; 2825002d39b4SEd Tanous hypervisor["@odata.id"] = "/redfish/v1/Systems/hypervisor"; 28267f3e84a1SEd Tanous ifaceArray2.emplace_back(std::move(hypervisor)); 28271e1e598dSJonathan Doman }); 2828c1e219d5SEd Tanous } 2829c1e219d5SEd Tanous 2830c1e219d5SEd Tanous /** 28317e860f15SJohn Edward Broadbent * Function transceives data with dbus directly. 28327e860f15SJohn Edward Broadbent */ 28334f48d5f6SEd Tanous inline void doNMI(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) 28347e860f15SJohn Edward Broadbent { 283589492a15SPatrick Williams constexpr const char* serviceName = "xyz.openbmc_project.Control.Host.NMI"; 283689492a15SPatrick Williams constexpr const char* objectPath = "/xyz/openbmc_project/control/host0/nmi"; 283789492a15SPatrick Williams constexpr const char* interfaceName = 28387e860f15SJohn Edward Broadbent "xyz.openbmc_project.Control.Host.NMI"; 283989492a15SPatrick Williams constexpr const char* method = "NMI"; 28407e860f15SJohn Edward Broadbent 28417e860f15SJohn Edward Broadbent crow::connections::systemBus->async_method_call( 28425e7e2dc5SEd Tanous [asyncResp](const boost::system::error_code& ec) { 28437e860f15SJohn Edward Broadbent if (ec) 28447e860f15SJohn Edward Broadbent { 284562598e31SEd Tanous BMCWEB_LOG_ERROR(" Bad D-Bus request error: {}", ec); 28467e860f15SJohn Edward Broadbent messages::internalError(asyncResp->res); 28477e860f15SJohn Edward Broadbent return; 28487e860f15SJohn Edward Broadbent } 28497e860f15SJohn Edward Broadbent messages::success(asyncResp->res); 28507e860f15SJohn Edward Broadbent }, 28517e860f15SJohn Edward Broadbent serviceName, objectPath, interfaceName, method); 28527e860f15SJohn Edward Broadbent } 2853c5b2abe0SLewanczyk, Dawid 2854c1e219d5SEd Tanous inline void handleComputerSystemResetActionPost( 2855c1e219d5SEd Tanous crow::App& app, const crow::Request& req, 28567f3e84a1SEd Tanous const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 2857c1e219d5SEd Tanous const std::string& systemName) 2858c1e219d5SEd Tanous { 28593ba00073SCarson Labrado if (!redfish::setUpRedfishRoute(app, req, asyncResp)) 286045ca1b86SEd Tanous { 286145ca1b86SEd Tanous return; 286245ca1b86SEd Tanous } 2863253f11b8SEd Tanous if (systemName != BMCWEB_REDFISH_SYSTEM_URI_NAME) 2864c1e219d5SEd Tanous { 2865c1e219d5SEd Tanous messages::resourceNotFound(asyncResp->res, "ComputerSystem", 2866c1e219d5SEd Tanous systemName); 2867c1e219d5SEd Tanous return; 2868c1e219d5SEd Tanous } 286925b54dbaSEd Tanous if constexpr (BMCWEB_EXPERIMENTAL_REDFISH_MULTI_COMPUTER_SYSTEM) 28707f3e84a1SEd Tanous { 28717f3e84a1SEd Tanous // Option currently returns no systems. TBD 28727f3e84a1SEd Tanous messages::resourceNotFound(asyncResp->res, "ComputerSystem", 2873c1e219d5SEd Tanous systemName); 28747f3e84a1SEd Tanous return; 28757f3e84a1SEd Tanous } 28769712f8acSEd Tanous std::string resetType; 2877c1e219d5SEd Tanous if (!json_util::readJsonAction(req, asyncResp->res, "ResetType", resetType)) 2878cc340dd9SEd Tanous { 2879cc340dd9SEd Tanous return; 2880cc340dd9SEd Tanous } 2881cc340dd9SEd Tanous 2882d22c8396SJason M. Bills // Get the command and host vs. chassis 2883cc340dd9SEd Tanous std::string command; 2884543f4400SEd Tanous bool hostCommand = true; 2885d4d25793SEd Tanous if ((resetType == "On") || (resetType == "ForceOn")) 2886cc340dd9SEd Tanous { 2887cc340dd9SEd Tanous command = "xyz.openbmc_project.State.Host.Transition.On"; 2888d22c8396SJason M. Bills hostCommand = true; 2889d22c8396SJason M. Bills } 2890d22c8396SJason M. Bills else if (resetType == "ForceOff") 2891d22c8396SJason M. Bills { 2892d22c8396SJason M. Bills command = "xyz.openbmc_project.State.Chassis.Transition.Off"; 2893d22c8396SJason M. Bills hostCommand = false; 2894d22c8396SJason M. Bills } 2895d22c8396SJason M. Bills else if (resetType == "ForceRestart") 2896d22c8396SJason M. Bills { 2897c1e219d5SEd Tanous command = "xyz.openbmc_project.State.Host.Transition.ForceWarmReboot"; 289886a0851aSJason M. Bills hostCommand = true; 2899cc340dd9SEd Tanous } 29009712f8acSEd Tanous else if (resetType == "GracefulShutdown") 2901cc340dd9SEd Tanous { 2902cc340dd9SEd Tanous command = "xyz.openbmc_project.State.Host.Transition.Off"; 2903d22c8396SJason M. Bills hostCommand = true; 2904cc340dd9SEd Tanous } 29059712f8acSEd Tanous else if (resetType == "GracefulRestart") 2906cc340dd9SEd Tanous { 29070fda0f12SGeorge Liu command = 29080fda0f12SGeorge Liu "xyz.openbmc_project.State.Host.Transition.GracefulWarmReboot"; 2909d22c8396SJason M. Bills hostCommand = true; 2910d22c8396SJason M. Bills } 2911d22c8396SJason M. Bills else if (resetType == "PowerCycle") 2912d22c8396SJason M. Bills { 291386a0851aSJason M. Bills command = "xyz.openbmc_project.State.Host.Transition.Reboot"; 291486a0851aSJason M. Bills hostCommand = true; 2915cc340dd9SEd Tanous } 2916bfd5b826SLakshminarayana R. Kammath else if (resetType == "Nmi") 2917bfd5b826SLakshminarayana R. Kammath { 2918bfd5b826SLakshminarayana R. Kammath doNMI(asyncResp); 2919bfd5b826SLakshminarayana R. Kammath return; 2920bfd5b826SLakshminarayana R. Kammath } 2921cc340dd9SEd Tanous else 2922cc340dd9SEd Tanous { 2923c1e219d5SEd Tanous messages::actionParameterUnknown(asyncResp->res, "Reset", resetType); 2924cc340dd9SEd Tanous return; 2925cc340dd9SEd Tanous } 2926d02aad39SEd Tanous sdbusplus::message::object_path statePath("/xyz/openbmc_project/state"); 2927cc340dd9SEd Tanous 2928d22c8396SJason M. Bills if (hostCommand) 2929d22c8396SJason M. Bills { 2930d02aad39SEd Tanous setDbusProperty(asyncResp, "xyz.openbmc_project.State.Host", 2931d02aad39SEd Tanous statePath / "host0", "xyz.openbmc_project.State.Host", 2932d02aad39SEd Tanous "RequestedHostTransition", "Reset", command); 2933cc340dd9SEd Tanous } 2934d22c8396SJason M. Bills else 2935d22c8396SJason M. Bills { 2936d02aad39SEd Tanous setDbusProperty(asyncResp, "xyz.openbmc_project.State.Chassis", 2937d02aad39SEd Tanous statePath / "chassis0", 2938d02aad39SEd Tanous "xyz.openbmc_project.State.Chassis", 2939d02aad39SEd Tanous "RequestedPowerTransition", "Reset", command); 2940d22c8396SJason M. Bills } 2941d22c8396SJason M. Bills } 2942cc340dd9SEd Tanous 2943c1e219d5SEd Tanous inline void handleComputerSystemHead( 2944dd60b9edSEd Tanous App& app, const crow::Request& req, 29457f3e84a1SEd Tanous const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 29467f3e84a1SEd Tanous const std::string& /*systemName*/) 2947dd60b9edSEd Tanous { 2948dd60b9edSEd Tanous if (!redfish::setUpRedfishRoute(app, req, asyncResp)) 2949dd60b9edSEd Tanous { 2950dd60b9edSEd Tanous return; 2951dd60b9edSEd Tanous } 2952dd60b9edSEd Tanous 2953dd60b9edSEd Tanous asyncResp->res.addHeader( 2954dd60b9edSEd Tanous boost::beast::http::field::link, 2955dd60b9edSEd Tanous "</redfish/v1/JsonSchemas/ComputerSystem/ComputerSystem.json>; rel=describedby"); 2956dd60b9edSEd Tanous } 2957dd60b9edSEd Tanous 29585c3e9272SAbhishek Patel inline void afterPortRequest( 29595c3e9272SAbhishek Patel const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 29605c3e9272SAbhishek Patel const boost::system::error_code& ec, 29615c3e9272SAbhishek Patel const std::vector<std::tuple<std::string, std::string, bool>>& socketData) 29625c3e9272SAbhishek Patel { 29635c3e9272SAbhishek Patel if (ec) 29645c3e9272SAbhishek Patel { 2965b3e86cb0SGunnar Mills BMCWEB_LOG_ERROR("DBUS response error {}", ec); 29665c3e9272SAbhishek Patel messages::internalError(asyncResp->res); 29675c3e9272SAbhishek Patel return; 29685c3e9272SAbhishek Patel } 29695c3e9272SAbhishek Patel for (const auto& data : socketData) 29705c3e9272SAbhishek Patel { 29715c3e9272SAbhishek Patel const std::string& socketPath = get<0>(data); 29725c3e9272SAbhishek Patel const std::string& protocolName = get<1>(data); 29735c3e9272SAbhishek Patel bool isProtocolEnabled = get<2>(data); 29745c3e9272SAbhishek Patel nlohmann::json& dataJson = asyncResp->res.jsonValue["SerialConsole"]; 29755c3e9272SAbhishek Patel dataJson[protocolName]["ServiceEnabled"] = isProtocolEnabled; 29765c3e9272SAbhishek Patel // need to retrieve port number for 29775c3e9272SAbhishek Patel // obmc-console-ssh service 29785c3e9272SAbhishek Patel if (protocolName == "SSH") 29795c3e9272SAbhishek Patel { 29805c3e9272SAbhishek Patel getPortNumber(socketPath, [asyncResp, protocolName]( 298181c4e330SEd Tanous const boost::system::error_code& ec1, 29825c3e9272SAbhishek Patel int portNumber) { 29835c3e9272SAbhishek Patel if (ec1) 29845c3e9272SAbhishek Patel { 2985b3e86cb0SGunnar Mills BMCWEB_LOG_ERROR("DBUS response error {}", ec1); 29865c3e9272SAbhishek Patel messages::internalError(asyncResp->res); 29875c3e9272SAbhishek Patel return; 29885c3e9272SAbhishek Patel } 29895c3e9272SAbhishek Patel nlohmann::json& dataJson1 = 29905c3e9272SAbhishek Patel asyncResp->res.jsonValue["SerialConsole"]; 29915c3e9272SAbhishek Patel dataJson1[protocolName]["Port"] = portNumber; 29925c3e9272SAbhishek Patel }); 29935c3e9272SAbhishek Patel } 29945c3e9272SAbhishek Patel } 29955c3e9272SAbhishek Patel } 2996c1e219d5SEd Tanous 2997c1e219d5SEd Tanous inline void 2998c1e219d5SEd Tanous handleComputerSystemGet(crow::App& app, const crow::Request& req, 299922d268cbSEd Tanous const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 3000c1e219d5SEd Tanous const std::string& systemName) 3001c1e219d5SEd Tanous { 30023ba00073SCarson Labrado if (!redfish::setUpRedfishRoute(app, req, asyncResp)) 300345ca1b86SEd Tanous { 300445ca1b86SEd Tanous return; 300545ca1b86SEd Tanous } 3006746b56f3SAsmitha Karunanithi 300725b54dbaSEd Tanous if constexpr (BMCWEB_EXPERIMENTAL_REDFISH_MULTI_COMPUTER_SYSTEM) 30087f3e84a1SEd Tanous { 30097f3e84a1SEd Tanous // Option currently returns no systems. TBD 30107f3e84a1SEd Tanous messages::resourceNotFound(asyncResp->res, "ComputerSystem", 30117f3e84a1SEd Tanous systemName); 30127f3e84a1SEd Tanous return; 30137f3e84a1SEd Tanous } 30147f3e84a1SEd Tanous 3015746b56f3SAsmitha Karunanithi if (systemName == "hypervisor") 3016746b56f3SAsmitha Karunanithi { 3017746b56f3SAsmitha Karunanithi handleHypervisorSystemGet(asyncResp); 3018746b56f3SAsmitha Karunanithi return; 3019746b56f3SAsmitha Karunanithi } 3020746b56f3SAsmitha Karunanithi 3021253f11b8SEd Tanous if (systemName != BMCWEB_REDFISH_SYSTEM_URI_NAME) 302222d268cbSEd Tanous { 302322d268cbSEd Tanous messages::resourceNotFound(asyncResp->res, "ComputerSystem", 302422d268cbSEd Tanous systemName); 302522d268cbSEd Tanous return; 302622d268cbSEd Tanous } 3027dd60b9edSEd Tanous asyncResp->res.addHeader( 3028dd60b9edSEd Tanous boost::beast::http::field::link, 3029dd60b9edSEd Tanous "</redfish/v1/JsonSchemas/ComputerSystem/ComputerSystem.json>; rel=describedby"); 30308d1b46d7Szhanghch05 asyncResp->res.jsonValue["@odata.type"] = 3031b6655101SChris Cain "#ComputerSystem.v1_22_0.ComputerSystem"; 3032253f11b8SEd Tanous asyncResp->res.jsonValue["Name"] = BMCWEB_REDFISH_SYSTEM_URI_NAME; 3033253f11b8SEd Tanous asyncResp->res.jsonValue["Id"] = BMCWEB_REDFISH_SYSTEM_URI_NAME; 30348d1b46d7Szhanghch05 asyncResp->res.jsonValue["SystemType"] = "Physical"; 30358d1b46d7Szhanghch05 asyncResp->res.jsonValue["Description"] = "Computer System"; 30368d1b46d7Szhanghch05 asyncResp->res.jsonValue["ProcessorSummary"]["Count"] = 0; 3037cf0e004cSNinad Palsule asyncResp->res.jsonValue["MemorySummary"]["TotalSystemMemoryGiB"] = 3038dfb2b408SPriyanga Ramasamy double(0); 3039253f11b8SEd Tanous asyncResp->res.jsonValue["@odata.id"] = boost::urls::format( 3040253f11b8SEd Tanous "/redfish/v1/Systems/{}", BMCWEB_REDFISH_SYSTEM_URI_NAME); 304104a258f4SEd Tanous 3042253f11b8SEd Tanous asyncResp->res.jsonValue["Processors"]["@odata.id"] = boost::urls::format( 3043253f11b8SEd Tanous "/redfish/v1/Systems/{}/Processors", BMCWEB_REDFISH_SYSTEM_URI_NAME); 3044253f11b8SEd Tanous asyncResp->res.jsonValue["Memory"]["@odata.id"] = boost::urls::format( 3045253f11b8SEd Tanous "/redfish/v1/Systems/{}/Memory", BMCWEB_REDFISH_SYSTEM_URI_NAME); 3046253f11b8SEd Tanous asyncResp->res.jsonValue["Storage"]["@odata.id"] = boost::urls::format( 3047253f11b8SEd Tanous "/redfish/v1/Systems/{}/Storage", BMCWEB_REDFISH_SYSTEM_URI_NAME); 30483179105bSSunny Srivastava asyncResp->res.jsonValue["FabricAdapters"]["@odata.id"] = 3049253f11b8SEd Tanous boost::urls::format("/redfish/v1/Systems/{}/FabricAdapters", 3050253f11b8SEd Tanous BMCWEB_REDFISH_SYSTEM_URI_NAME); 3051029573d4SEd Tanous 3052002d39b4SEd Tanous asyncResp->res.jsonValue["Actions"]["#ComputerSystem.Reset"]["target"] = 3053253f11b8SEd Tanous boost::urls::format( 3054253f11b8SEd Tanous "/redfish/v1/Systems/{}/Actions/ComputerSystem.Reset", 3055253f11b8SEd Tanous BMCWEB_REDFISH_SYSTEM_URI_NAME); 3056c1e219d5SEd Tanous asyncResp->res 3057c1e219d5SEd Tanous .jsonValue["Actions"]["#ComputerSystem.Reset"]["@Redfish.ActionInfo"] = 3058253f11b8SEd Tanous boost::urls::format("/redfish/v1/Systems/{}/ResetActionInfo", 3059253f11b8SEd Tanous BMCWEB_REDFISH_SYSTEM_URI_NAME); 3060c5b2abe0SLewanczyk, Dawid 3061253f11b8SEd Tanous asyncResp->res.jsonValue["LogServices"]["@odata.id"] = boost::urls::format( 3062253f11b8SEd Tanous "/redfish/v1/Systems/{}/LogServices", BMCWEB_REDFISH_SYSTEM_URI_NAME); 3063253f11b8SEd Tanous asyncResp->res.jsonValue["Bios"]["@odata.id"] = boost::urls::format( 3064253f11b8SEd Tanous "/redfish/v1/Systems/{}/Bios", BMCWEB_REDFISH_SYSTEM_URI_NAME); 3065c4bf6374SJason M. Bills 30661476687dSEd Tanous nlohmann::json::array_t managedBy; 30671476687dSEd Tanous nlohmann::json& manager = managedBy.emplace_back(); 3068253f11b8SEd Tanous manager["@odata.id"] = boost::urls::format("/redfish/v1/Managers/{}", 3069253f11b8SEd Tanous BMCWEB_REDFISH_MANAGER_URI_NAME); 3070002d39b4SEd Tanous asyncResp->res.jsonValue["Links"]["ManagedBy"] = std::move(managedBy); 30711476687dSEd Tanous asyncResp->res.jsonValue["Status"]["Health"] = "OK"; 30721476687dSEd Tanous asyncResp->res.jsonValue["Status"]["State"] = "Enabled"; 30730e8ac5e7SGunnar Mills 30740e8ac5e7SGunnar Mills // Fill in SerialConsole info 3075002d39b4SEd Tanous asyncResp->res.jsonValue["SerialConsole"]["MaxConcurrentSessions"] = 15; 3076c1e219d5SEd Tanous asyncResp->res.jsonValue["SerialConsole"]["IPMI"]["ServiceEnabled"] = true; 30771476687dSEd Tanous 3078c1e219d5SEd Tanous asyncResp->res.jsonValue["SerialConsole"]["SSH"]["ServiceEnabled"] = true; 30791476687dSEd Tanous asyncResp->res.jsonValue["SerialConsole"]["SSH"]["Port"] = 2200; 3080c1e219d5SEd Tanous asyncResp->res.jsonValue["SerialConsole"]["SSH"]["HotKeySequenceDisplay"] = 30811476687dSEd Tanous "Press ~. to exit console"; 30825c3e9272SAbhishek Patel getPortStatusAndPath(std::span{protocolToDBusForSystems}, 30835c3e9272SAbhishek Patel std::bind_front(afterPortRequest, asyncResp)); 30840e8ac5e7SGunnar Mills 308525b54dbaSEd Tanous if constexpr (BMCWEB_KVM) 308625b54dbaSEd Tanous { 30870e8ac5e7SGunnar Mills // Fill in GraphicalConsole info 3088002d39b4SEd Tanous asyncResp->res.jsonValue["GraphicalConsole"]["ServiceEnabled"] = true; 308925b54dbaSEd Tanous asyncResp->res.jsonValue["GraphicalConsole"]["MaxConcurrentSessions"] = 309025b54dbaSEd Tanous 4; 3091613dabeaSEd Tanous asyncResp->res.jsonValue["GraphicalConsole"]["ConnectTypesSupported"] = 3092613dabeaSEd Tanous nlohmann::json::array_t({"KVMIP"}); 309325b54dbaSEd Tanous } 309413451e39SWilly Tu 3095002d39b4SEd Tanous getMainChassisId(asyncResp, 3096002d39b4SEd Tanous [](const std::string& chassisId, 30978d1b46d7Szhanghch05 const std::shared_ptr<bmcweb::AsyncResp>& aRsp) { 3098b2c7e208SEd Tanous nlohmann::json::array_t chassisArray; 3099b2c7e208SEd Tanous nlohmann::json& chassis = chassisArray.emplace_back(); 3100ef4c65b7SEd Tanous chassis["@odata.id"] = boost::urls::format("/redfish/v1/Chassis/{}", 3101ef4c65b7SEd Tanous chassisId); 3102002d39b4SEd Tanous aRsp->res.jsonValue["Links"]["Chassis"] = std::move(chassisArray); 3103c5d03ff4SJennifer Lee }); 3104a3002228SAppaRao Puli 310559a17e4fSGeorge Liu getSystemLocationIndicatorActive(asyncResp); 31069f8bfa7cSGunnar Mills // TODO (Gunnar): Remove IndicatorLED after enough time has passed 3107a3002228SAppaRao Puli getIndicatorLedState(asyncResp); 310851bd2d8aSGunnar Mills getComputerSystem(asyncResp); 31096c34de48SEd Tanous getHostState(asyncResp); 3110491d8ee7SSantosh Puranik getBootProperties(asyncResp); 3111978b8803SAndrew Geissler getBootProgress(asyncResp); 3112b6d5d45cSHieu Huynh getBootProgressLastStateTime(asyncResp); 311370c4d545SLakshmi Yadlapati pcie_util::getPCIeDeviceList(asyncResp, 311470c4d545SLakshmi Yadlapati nlohmann::json::json_pointer("/PCIeDevices")); 311551709ffdSYong Li getHostWatchdogTimer(asyncResp); 3116c6a620f2SGeorge Liu getPowerRestorePolicy(asyncResp); 31179dcfe8c1SAlbert Zhang getStopBootOnFault(asyncResp); 3118797d5daeSCorey Hardesty getAutomaticRetryPolicy(asyncResp); 3119c0557e1aSGunnar Mills getLastResetTime(asyncResp); 312025b54dbaSEd Tanous if constexpr (BMCWEB_REDFISH_PROVISIONING_FEATURE) 312125b54dbaSEd Tanous { 3122a6349918SAppaRao Puli getProvisioningStatus(asyncResp); 312325b54dbaSEd Tanous } 31241981771bSAli Ahmed getTrustedModuleRequiredToBoot(asyncResp); 31253a2d0424SChris Cain getPowerMode(asyncResp); 312637bbf98cSChris Cain getIdlePowerSaver(asyncResp); 3127c1e219d5SEd Tanous } 3128550a6bf8SJiaqing Zhao 3129c1e219d5SEd Tanous inline void handleComputerSystemPatch( 3130c1e219d5SEd Tanous crow::App& app, const crow::Request& req, 313122d268cbSEd Tanous const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 3132c1e219d5SEd Tanous const std::string& systemName) 3133c1e219d5SEd Tanous { 31343ba00073SCarson Labrado if (!redfish::setUpRedfishRoute(app, req, asyncResp)) 313545ca1b86SEd Tanous { 313645ca1b86SEd Tanous return; 313745ca1b86SEd Tanous } 313825b54dbaSEd Tanous if constexpr (BMCWEB_EXPERIMENTAL_REDFISH_MULTI_COMPUTER_SYSTEM) 31397f3e84a1SEd Tanous { 31407f3e84a1SEd Tanous // Option currently returns no systems. TBD 31417f3e84a1SEd Tanous messages::resourceNotFound(asyncResp->res, "ComputerSystem", 31427f3e84a1SEd Tanous systemName); 31437f3e84a1SEd Tanous return; 31447f3e84a1SEd Tanous } 3145253f11b8SEd Tanous if (systemName != BMCWEB_REDFISH_SYSTEM_URI_NAME) 314622d268cbSEd Tanous { 314722d268cbSEd Tanous messages::resourceNotFound(asyncResp->res, "ComputerSystem", 314822d268cbSEd Tanous systemName); 314922d268cbSEd Tanous return; 315022d268cbSEd Tanous } 315122d268cbSEd Tanous 3152dd60b9edSEd Tanous asyncResp->res.addHeader( 3153dd60b9edSEd Tanous boost::beast::http::field::link, 3154dd60b9edSEd Tanous "</redfish/v1/JsonSchemas/ComputerSystem/ComputerSystem.json>; rel=describedby"); 3155dd60b9edSEd Tanous 31569f8bfa7cSGunnar Mills std::optional<bool> locationIndicatorActive; 3157cde19e5fSSantosh Puranik std::optional<std::string> indicatorLed; 315898e386ecSGunnar Mills std::optional<std::string> assetTag; 3159c6a620f2SGeorge Liu std::optional<std::string> powerRestorePolicy; 31603a2d0424SChris Cain std::optional<std::string> powerMode; 3161550a6bf8SJiaqing Zhao std::optional<bool> wdtEnable; 3162550a6bf8SJiaqing Zhao std::optional<std::string> wdtTimeOutAction; 3163550a6bf8SJiaqing Zhao std::optional<std::string> bootSource; 3164550a6bf8SJiaqing Zhao std::optional<std::string> bootType; 3165550a6bf8SJiaqing Zhao std::optional<std::string> bootEnable; 3166550a6bf8SJiaqing Zhao std::optional<std::string> bootAutomaticRetry; 3167797d5daeSCorey Hardesty std::optional<uint32_t> bootAutomaticRetryAttempts; 3168550a6bf8SJiaqing Zhao std::optional<bool> bootTrustedModuleRequired; 31699dcfe8c1SAlbert Zhang std::optional<std::string> stopBootOnFault; 3170550a6bf8SJiaqing Zhao std::optional<bool> ipsEnable; 3171550a6bf8SJiaqing Zhao std::optional<uint8_t> ipsEnterUtil; 3172550a6bf8SJiaqing Zhao std::optional<uint64_t> ipsEnterTime; 3173550a6bf8SJiaqing Zhao std::optional<uint8_t> ipsExitUtil; 3174550a6bf8SJiaqing Zhao std::optional<uint64_t> ipsExitTime; 3175550a6bf8SJiaqing Zhao 3176550a6bf8SJiaqing Zhao // clang-format off 317715ed6780SWilly Tu if (!json_util::readJsonPatch( 3178550a6bf8SJiaqing Zhao req, asyncResp->res, 3179550a6bf8SJiaqing Zhao "IndicatorLED", indicatorLed, 31807e860f15SJohn Edward Broadbent "LocationIndicatorActive", locationIndicatorActive, 3181550a6bf8SJiaqing Zhao "AssetTag", assetTag, 3182550a6bf8SJiaqing Zhao "PowerRestorePolicy", powerRestorePolicy, 3183550a6bf8SJiaqing Zhao "PowerMode", powerMode, 3184550a6bf8SJiaqing Zhao "HostWatchdogTimer/FunctionEnabled", wdtEnable, 3185550a6bf8SJiaqing Zhao "HostWatchdogTimer/TimeoutAction", wdtTimeOutAction, 3186550a6bf8SJiaqing Zhao "Boot/BootSourceOverrideTarget", bootSource, 3187550a6bf8SJiaqing Zhao "Boot/BootSourceOverrideMode", bootType, 3188550a6bf8SJiaqing Zhao "Boot/BootSourceOverrideEnabled", bootEnable, 3189550a6bf8SJiaqing Zhao "Boot/AutomaticRetryConfig", bootAutomaticRetry, 3190797d5daeSCorey Hardesty "Boot/AutomaticRetryAttempts", bootAutomaticRetryAttempts, 3191550a6bf8SJiaqing Zhao "Boot/TrustedModuleRequiredToBoot", bootTrustedModuleRequired, 31929dcfe8c1SAlbert Zhang "Boot/StopBootOnFault", stopBootOnFault, 3193550a6bf8SJiaqing Zhao "IdlePowerSaver/Enabled", ipsEnable, 3194550a6bf8SJiaqing Zhao "IdlePowerSaver/EnterUtilizationPercent", ipsEnterUtil, 3195550a6bf8SJiaqing Zhao "IdlePowerSaver/EnterDwellTimeSeconds", ipsEnterTime, 3196550a6bf8SJiaqing Zhao "IdlePowerSaver/ExitUtilizationPercent", ipsExitUtil, 3197550a6bf8SJiaqing Zhao "IdlePowerSaver/ExitDwellTimeSeconds", ipsExitTime)) 31986617338dSEd Tanous { 31996617338dSEd Tanous return; 32006617338dSEd Tanous } 3201550a6bf8SJiaqing Zhao // clang-format on 3202491d8ee7SSantosh Puranik 32038d1b46d7Szhanghch05 asyncResp->res.result(boost::beast::http::status::no_content); 3204c45f0082SYong Li 320598e386ecSGunnar Mills if (assetTag) 320698e386ecSGunnar Mills { 320798e386ecSGunnar Mills setAssetTag(asyncResp, *assetTag); 320898e386ecSGunnar Mills } 320998e386ecSGunnar Mills 3210550a6bf8SJiaqing Zhao if (wdtEnable || wdtTimeOutAction) 3211c45f0082SYong Li { 3212f23b7296SEd Tanous setWDTProperties(asyncResp, wdtEnable, wdtTimeOutAction); 3213c45f0082SYong Li } 3214c45f0082SYong Li 3215cd9a4666SKonstantin Aladyshev if (bootSource || bootType || bootEnable) 321669f35306SGunnar Mills { 3217002d39b4SEd Tanous setBootProperties(asyncResp, bootSource, bootType, bootEnable); 3218491d8ee7SSantosh Puranik } 3219550a6bf8SJiaqing Zhao if (bootAutomaticRetry) 322069f35306SGunnar Mills { 3221550a6bf8SJiaqing Zhao setAutomaticRetry(asyncResp, *bootAutomaticRetry); 322269f35306SGunnar Mills } 3223ac7e1e0bSAli Ahmed 3224797d5daeSCorey Hardesty if (bootAutomaticRetryAttempts) 3225797d5daeSCorey Hardesty { 3226797d5daeSCorey Hardesty setAutomaticRetryAttempts(asyncResp, 3227797d5daeSCorey Hardesty bootAutomaticRetryAttempts.value()); 3228797d5daeSCorey Hardesty } 3229797d5daeSCorey Hardesty 3230550a6bf8SJiaqing Zhao if (bootTrustedModuleRequired) 3231ac7e1e0bSAli Ahmed { 3232c1e219d5SEd Tanous setTrustedModuleRequiredToBoot(asyncResp, *bootTrustedModuleRequired); 323369f35306SGunnar Mills } 3234265c1602SJohnathan Mantey 32359dcfe8c1SAlbert Zhang if (stopBootOnFault) 32369dcfe8c1SAlbert Zhang { 32379dcfe8c1SAlbert Zhang setStopBootOnFault(asyncResp, *stopBootOnFault); 32389dcfe8c1SAlbert Zhang } 32399dcfe8c1SAlbert Zhang 32409f8bfa7cSGunnar Mills if (locationIndicatorActive) 32419f8bfa7cSGunnar Mills { 324259a17e4fSGeorge Liu setSystemLocationIndicatorActive(asyncResp, *locationIndicatorActive); 32439f8bfa7cSGunnar Mills } 32449f8bfa7cSGunnar Mills 32457e860f15SJohn Edward Broadbent // TODO (Gunnar): Remove IndicatorLED after enough time has 32467e860f15SJohn Edward Broadbent // passed 32479712f8acSEd Tanous if (indicatorLed) 32486617338dSEd Tanous { 3249f23b7296SEd Tanous setIndicatorLedState(asyncResp, *indicatorLed); 3250002d39b4SEd Tanous asyncResp->res.addHeader(boost::beast::http::field::warning, 3251d6aa0093SGunnar Mills "299 - \"IndicatorLED is deprecated. Use " 3252d6aa0093SGunnar Mills "LocationIndicatorActive instead.\""); 32536617338dSEd Tanous } 3254c6a620f2SGeorge Liu 3255c6a620f2SGeorge Liu if (powerRestorePolicy) 3256c6a620f2SGeorge Liu { 32574e69c904SGunnar Mills setPowerRestorePolicy(asyncResp, *powerRestorePolicy); 3258c6a620f2SGeorge Liu } 32593a2d0424SChris Cain 32603a2d0424SChris Cain if (powerMode) 32613a2d0424SChris Cain { 32623a2d0424SChris Cain setPowerMode(asyncResp, *powerMode); 32633a2d0424SChris Cain } 326437bbf98cSChris Cain 3265c1e219d5SEd Tanous if (ipsEnable || ipsEnterUtil || ipsEnterTime || ipsExitUtil || ipsExitTime) 326637bbf98cSChris Cain { 3267002d39b4SEd Tanous setIdlePowerSaver(asyncResp, ipsEnable, ipsEnterUtil, ipsEnterTime, 3268002d39b4SEd Tanous ipsExitUtil, ipsExitTime); 326937bbf98cSChris Cain } 3270c1e219d5SEd Tanous } 32711cb1a9e6SAppaRao Puli 327238c8a6f2SEd Tanous inline void handleSystemCollectionResetActionHead( 3273dd60b9edSEd Tanous crow::App& app, const crow::Request& req, 32747f3e84a1SEd Tanous const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 3275c1e219d5SEd Tanous const std::string& /*systemName*/) 3276dd60b9edSEd Tanous { 3277dd60b9edSEd Tanous if (!redfish::setUpRedfishRoute(app, req, asyncResp)) 3278dd60b9edSEd Tanous { 3279dd60b9edSEd Tanous return; 3280dd60b9edSEd Tanous } 3281dd60b9edSEd Tanous asyncResp->res.addHeader( 3282dd60b9edSEd Tanous boost::beast::http::field::link, 3283dd60b9edSEd Tanous "</redfish/v1/JsonSchemas/ActionInfo/ActionInfo.json>; rel=describedby"); 3284dd60b9edSEd Tanous } 328533e1f122SAndrew Geissler 328633e1f122SAndrew Geissler /** 328733e1f122SAndrew Geissler * @brief Translates allowed host transitions to redfish string 328833e1f122SAndrew Geissler * 328933e1f122SAndrew Geissler * @param[in] dbusAllowedHostTran The allowed host transition on dbus 329033e1f122SAndrew Geissler * @param[out] allowableValues The translated host transition(s) 329133e1f122SAndrew Geissler * 329233e1f122SAndrew Geissler * @return Emplaces correpsonding Redfish translated value(s) in 329333e1f122SAndrew Geissler * allowableValues. If translation not possible, does nothing to 329433e1f122SAndrew Geissler * allowableValues. 329533e1f122SAndrew Geissler */ 329633e1f122SAndrew Geissler inline void 329733e1f122SAndrew Geissler dbusToRfAllowedHostTransitions(const std::string& dbusAllowedHostTran, 329833e1f122SAndrew Geissler nlohmann::json::array_t& allowableValues) 329933e1f122SAndrew Geissler { 330033e1f122SAndrew Geissler if (dbusAllowedHostTran == "xyz.openbmc_project.State.Host.Transition.On") 330133e1f122SAndrew Geissler { 330233e1f122SAndrew Geissler allowableValues.emplace_back(resource::ResetType::On); 330333e1f122SAndrew Geissler allowableValues.emplace_back(resource::ResetType::ForceOn); 330433e1f122SAndrew Geissler } 330533e1f122SAndrew Geissler else if (dbusAllowedHostTran == 330633e1f122SAndrew Geissler "xyz.openbmc_project.State.Host.Transition.Off") 330733e1f122SAndrew Geissler { 330833e1f122SAndrew Geissler allowableValues.emplace_back(resource::ResetType::GracefulShutdown); 330933e1f122SAndrew Geissler } 331033e1f122SAndrew Geissler else if (dbusAllowedHostTran == 331133e1f122SAndrew Geissler "xyz.openbmc_project.State.Host.Transition.GracefulWarmReboot") 331233e1f122SAndrew Geissler { 331333e1f122SAndrew Geissler allowableValues.emplace_back(resource::ResetType::GracefulRestart); 331433e1f122SAndrew Geissler } 331533e1f122SAndrew Geissler else if (dbusAllowedHostTran == 331633e1f122SAndrew Geissler "xyz.openbmc_project.State.Host.Transition.ForceWarmReboot") 331733e1f122SAndrew Geissler { 331833e1f122SAndrew Geissler allowableValues.emplace_back(resource::ResetType::ForceRestart); 331933e1f122SAndrew Geissler } 332033e1f122SAndrew Geissler else 332133e1f122SAndrew Geissler { 332233e1f122SAndrew Geissler BMCWEB_LOG_WARNING("Unsupported host tran {}", dbusAllowedHostTran); 332333e1f122SAndrew Geissler } 332433e1f122SAndrew Geissler } 332533e1f122SAndrew Geissler 332633e1f122SAndrew Geissler inline void afterGetAllowedHostTransitions( 332733e1f122SAndrew Geissler const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 332833e1f122SAndrew Geissler const boost::system::error_code& ec, 332933e1f122SAndrew Geissler const std::vector<std::string>& allowedHostTransitions) 333033e1f122SAndrew Geissler { 333133e1f122SAndrew Geissler nlohmann::json::array_t allowableValues; 333233e1f122SAndrew Geissler 333333e1f122SAndrew Geissler // Supported on all systems currently 333433e1f122SAndrew Geissler allowableValues.emplace_back(resource::ResetType::ForceOff); 333533e1f122SAndrew Geissler allowableValues.emplace_back(resource::ResetType::PowerCycle); 333633e1f122SAndrew Geissler allowableValues.emplace_back(resource::ResetType::Nmi); 333733e1f122SAndrew Geissler 333833e1f122SAndrew Geissler if (ec) 333933e1f122SAndrew Geissler { 3340e715d14bSEd Tanous if ((ec.value() == 3341e715d14bSEd Tanous boost::system::linux_error::bad_request_descriptor) || 3342e715d14bSEd Tanous (ec.value() == boost::asio::error::basic_errors::host_unreachable)) 334333e1f122SAndrew Geissler { 334433e1f122SAndrew Geissler // Property not implemented so just return defaults 334533e1f122SAndrew Geissler BMCWEB_LOG_DEBUG("Property not available {}", ec); 334633e1f122SAndrew Geissler allowableValues.emplace_back(resource::ResetType::On); 334733e1f122SAndrew Geissler allowableValues.emplace_back(resource::ResetType::ForceOn); 334833e1f122SAndrew Geissler allowableValues.emplace_back(resource::ResetType::ForceRestart); 334933e1f122SAndrew Geissler allowableValues.emplace_back(resource::ResetType::GracefulRestart); 335033e1f122SAndrew Geissler allowableValues.emplace_back(resource::ResetType::GracefulShutdown); 335133e1f122SAndrew Geissler } 335233e1f122SAndrew Geissler else 335333e1f122SAndrew Geissler { 335433e1f122SAndrew Geissler BMCWEB_LOG_ERROR("DBUS response error {}", ec); 335533e1f122SAndrew Geissler messages::internalError(asyncResp->res); 335633e1f122SAndrew Geissler return; 335733e1f122SAndrew Geissler } 335833e1f122SAndrew Geissler } 335933e1f122SAndrew Geissler else 336033e1f122SAndrew Geissler { 336133e1f122SAndrew Geissler for (const std::string& transition : allowedHostTransitions) 336233e1f122SAndrew Geissler { 336333e1f122SAndrew Geissler BMCWEB_LOG_DEBUG("Found allowed host tran {}", transition); 336433e1f122SAndrew Geissler dbusToRfAllowedHostTransitions(transition, allowableValues); 336533e1f122SAndrew Geissler } 336633e1f122SAndrew Geissler } 336733e1f122SAndrew Geissler 336833e1f122SAndrew Geissler nlohmann::json::object_t parameter; 336933e1f122SAndrew Geissler parameter["Name"] = "ResetType"; 337033e1f122SAndrew Geissler parameter["Required"] = true; 337133e1f122SAndrew Geissler parameter["DataType"] = "String"; 337233e1f122SAndrew Geissler parameter["AllowableValues"] = std::move(allowableValues); 337333e1f122SAndrew Geissler nlohmann::json::array_t parameters; 337433e1f122SAndrew Geissler parameters.emplace_back(std::move(parameter)); 337533e1f122SAndrew Geissler asyncResp->res.jsonValue["Parameters"] = std::move(parameters); 337633e1f122SAndrew Geissler } 337733e1f122SAndrew Geissler 3378c1e219d5SEd Tanous inline void handleSystemCollectionResetActionGet( 3379c1e219d5SEd Tanous crow::App& app, const crow::Request& req, 338022d268cbSEd Tanous const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 3381c1e219d5SEd Tanous const std::string& systemName) 3382c1e219d5SEd Tanous { 33833ba00073SCarson Labrado if (!redfish::setUpRedfishRoute(app, req, asyncResp)) 338445ca1b86SEd Tanous { 338545ca1b86SEd Tanous return; 338645ca1b86SEd Tanous } 338725b54dbaSEd Tanous if constexpr (BMCWEB_EXPERIMENTAL_REDFISH_MULTI_COMPUTER_SYSTEM) 33887f3e84a1SEd Tanous { 33897f3e84a1SEd Tanous // Option currently returns no systems. TBD 33907f3e84a1SEd Tanous messages::resourceNotFound(asyncResp->res, "ComputerSystem", 33917f3e84a1SEd Tanous systemName); 33927f3e84a1SEd Tanous return; 33937f3e84a1SEd Tanous } 3394746b56f3SAsmitha Karunanithi 3395746b56f3SAsmitha Karunanithi if (systemName == "hypervisor") 3396746b56f3SAsmitha Karunanithi { 3397746b56f3SAsmitha Karunanithi handleHypervisorResetActionGet(asyncResp); 3398746b56f3SAsmitha Karunanithi return; 3399746b56f3SAsmitha Karunanithi } 3400746b56f3SAsmitha Karunanithi 3401253f11b8SEd Tanous if (systemName != BMCWEB_REDFISH_SYSTEM_URI_NAME) 340222d268cbSEd Tanous { 340322d268cbSEd Tanous messages::resourceNotFound(asyncResp->res, "ComputerSystem", 340422d268cbSEd Tanous systemName); 340522d268cbSEd Tanous return; 340622d268cbSEd Tanous } 340722d268cbSEd Tanous 3408dd60b9edSEd Tanous asyncResp->res.addHeader( 3409dd60b9edSEd Tanous boost::beast::http::field::link, 3410dd60b9edSEd Tanous "</redfish/v1/JsonSchemas/ActionInfo/ActionInfo.json>; rel=describedby"); 34111476687dSEd Tanous 34121476687dSEd Tanous asyncResp->res.jsonValue["@odata.id"] = 3413253f11b8SEd Tanous boost::urls::format("/redfish/v1/Systems/{}/ResetActionInfo", 3414253f11b8SEd Tanous BMCWEB_REDFISH_SYSTEM_URI_NAME); 3415c1e219d5SEd Tanous asyncResp->res.jsonValue["@odata.type"] = "#ActionInfo.v1_1_2.ActionInfo"; 34161476687dSEd Tanous asyncResp->res.jsonValue["Name"] = "Reset Action Info"; 34171476687dSEd Tanous asyncResp->res.jsonValue["Id"] = "ResetActionInfo"; 34183215e700SNan Zhou 341933e1f122SAndrew Geissler // Look to see if system defines AllowedHostTransitions 342033e1f122SAndrew Geissler sdbusplus::asio::getProperty<std::vector<std::string>>( 342133e1f122SAndrew Geissler *crow::connections::systemBus, "xyz.openbmc_project.State.Host", 342233e1f122SAndrew Geissler "/xyz/openbmc_project/state/host0", "xyz.openbmc_project.State.Host", 342333e1f122SAndrew Geissler "AllowedHostTransitions", 342433e1f122SAndrew Geissler [asyncResp](const boost::system::error_code& ec, 342533e1f122SAndrew Geissler const std::vector<std::string>& allowedHostTransitions) { 342633e1f122SAndrew Geissler afterGetAllowedHostTransitions(asyncResp, ec, allowedHostTransitions); 342733e1f122SAndrew Geissler }); 3428c1e219d5SEd Tanous } 3429c1e219d5SEd Tanous /** 3430c1e219d5SEd Tanous * SystemResetActionInfo derived class for delivering Computer Systems 3431c1e219d5SEd Tanous * ResetType AllowableValues using ResetInfo schema. 3432c1e219d5SEd Tanous */ 3433100afe56SEd Tanous inline void requestRoutesSystems(App& app) 3434c1e219d5SEd Tanous { 3435100afe56SEd Tanous BMCWEB_ROUTE(app, "/redfish/v1/Systems/") 3436100afe56SEd Tanous .privileges(redfish::privileges::headComputerSystemCollection) 3437100afe56SEd Tanous .methods(boost::beast::http::verb::head)( 3438100afe56SEd Tanous std::bind_front(handleComputerSystemCollectionHead, std::ref(app))); 3439100afe56SEd Tanous 3440100afe56SEd Tanous BMCWEB_ROUTE(app, "/redfish/v1/Systems/") 3441100afe56SEd Tanous .privileges(redfish::privileges::getComputerSystemCollection) 3442100afe56SEd Tanous .methods(boost::beast::http::verb::get)( 3443100afe56SEd Tanous std::bind_front(handleComputerSystemCollectionGet, std::ref(app))); 3444100afe56SEd Tanous 3445100afe56SEd Tanous BMCWEB_ROUTE(app, "/redfish/v1/Systems/<str>/") 3446100afe56SEd Tanous .privileges(redfish::privileges::headComputerSystem) 3447100afe56SEd Tanous .methods(boost::beast::http::verb::head)( 3448100afe56SEd Tanous std::bind_front(handleComputerSystemHead, std::ref(app))); 3449100afe56SEd Tanous 3450100afe56SEd Tanous BMCWEB_ROUTE(app, "/redfish/v1/Systems/<str>/") 3451100afe56SEd Tanous .privileges(redfish::privileges::getComputerSystem) 3452100afe56SEd Tanous .methods(boost::beast::http::verb::get)( 3453100afe56SEd Tanous std::bind_front(handleComputerSystemGet, std::ref(app))); 3454100afe56SEd Tanous 3455100afe56SEd Tanous BMCWEB_ROUTE(app, "/redfish/v1/Systems/<str>/") 3456100afe56SEd Tanous .privileges(redfish::privileges::patchComputerSystem) 3457100afe56SEd Tanous .methods(boost::beast::http::verb::patch)( 3458100afe56SEd Tanous std::bind_front(handleComputerSystemPatch, std::ref(app))); 3459100afe56SEd Tanous 3460100afe56SEd Tanous BMCWEB_ROUTE(app, "/redfish/v1/Systems/<str>/Actions/ComputerSystem.Reset/") 3461100afe56SEd Tanous .privileges(redfish::privileges::postComputerSystem) 3462100afe56SEd Tanous .methods(boost::beast::http::verb::post)(std::bind_front( 3463100afe56SEd Tanous handleComputerSystemResetActionPost, std::ref(app))); 3464100afe56SEd Tanous 3465c1e219d5SEd Tanous BMCWEB_ROUTE(app, "/redfish/v1/Systems/<str>/ResetActionInfo/") 3466c1e219d5SEd Tanous .privileges(redfish::privileges::headActionInfo) 3467c1e219d5SEd Tanous .methods(boost::beast::http::verb::head)(std::bind_front( 3468c1e219d5SEd Tanous handleSystemCollectionResetActionHead, std::ref(app))); 3469c1e219d5SEd Tanous BMCWEB_ROUTE(app, "/redfish/v1/Systems/<str>/ResetActionInfo/") 3470c1e219d5SEd Tanous .privileges(redfish::privileges::getActionInfo) 3471c1e219d5SEd Tanous .methods(boost::beast::http::verb::get)(std::bind_front( 3472c1e219d5SEd Tanous handleSystemCollectionResetActionGet, std::ref(app))); 34731cb1a9e6SAppaRao Puli } 3474c5b2abe0SLewanczyk, Dawid } // namespace redfish 3475