140e9b92eSEd Tanous // SPDX-License-Identifier: Apache-2.0
240e9b92eSEd Tanous // SPDX-FileCopyrightText: Copyright OpenBMC Authors
340e9b92eSEd Tanous // SPDX-FileCopyrightText: Copyright 2018 Intel Corporation
4c5b2abe0SLewanczyk, Dawid #pragma once
5c5b2abe0SLewanczyk, Dawid
613451e39SWilly Tu #include "bmcweb_config.h"
713451e39SWilly Tu
83ccb3adbSEd Tanous #include "app.hpp"
9d7857201SEd Tanous #include "async_resp.hpp"
101e1e598dSJonathan Doman #include "dbus_singleton.hpp"
117a1dbc48SGeorge Liu #include "dbus_utility.hpp"
12d7857201SEd Tanous #include "error_messages.hpp"
13539d8c6bSEd Tanous #include "generated/enums/action_info.hpp"
148d69c668SEd Tanous #include "generated/enums/computer_system.hpp"
15539d8c6bSEd Tanous #include "generated/enums/open_bmc_computer_system.hpp"
1633e1f122SAndrew Geissler #include "generated/enums/resource.hpp"
17d7857201SEd Tanous #include "http_request.hpp"
18746b56f3SAsmitha Karunanithi #include "hypervisor_system.hpp"
191c8fba97SJames Feist #include "led.hpp"
20d7857201SEd Tanous #include "logging.hpp"
21f4c99e70SEd Tanous #include "query.hpp"
22c5d03ff4SJennifer Lee #include "redfish_util.hpp"
233ccb3adbSEd Tanous #include "registries/privilege_registry.hpp"
243ccb3adbSEd Tanous #include "utils/dbus_utils.hpp"
253ccb3adbSEd Tanous #include "utils/json_utils.hpp"
26472bd202SLakshmi Yadlapati #include "utils/pcie_util.hpp"
273ccb3adbSEd Tanous #include "utils/sw_utils.hpp"
282b82937eSEd Tanous #include "utils/time_utils.hpp"
29c5d03ff4SJennifer Lee
30d7857201SEd Tanous #include <asm-generic/errno.h>
31d7857201SEd Tanous
32fc903b3dSAndrew Geissler #include <boost/asio/error.hpp>
33d7857201SEd Tanous #include <boost/beast/http/field.hpp>
34d7857201SEd Tanous #include <boost/beast/http/status.hpp>
35d7857201SEd Tanous #include <boost/beast/http/verb.hpp>
36e99073f5SGeorge Liu #include <boost/system/error_code.hpp>
3733e1f122SAndrew Geissler #include <boost/system/linux_error.hpp>
38ef4c65b7SEd Tanous #include <boost/url/format.hpp>
39d7857201SEd Tanous #include <nlohmann/json.hpp>
40d7857201SEd Tanous #include <sdbusplus/message/native_types.hpp>
41bc1d29deSKrzysztof Grobelny #include <sdbusplus/unpack_properties.hpp>
421214b7e7SGunnar Mills
437a1dbc48SGeorge Liu #include <array>
44d7857201SEd Tanous #include <chrono>
45d7857201SEd Tanous #include <cstddef>
46d7857201SEd Tanous #include <cstdint>
47d7857201SEd Tanous #include <functional>
4833e1f122SAndrew Geissler #include <memory>
49d7857201SEd Tanous #include <optional>
50d7857201SEd Tanous #include <ratio>
516b9ac4f2SChris Cain #include <string>
527a1dbc48SGeorge Liu #include <string_view>
53d7857201SEd Tanous #include <tuple>
5420fa6a2cSEd Tanous #include <utility>
556b9ac4f2SChris Cain #include <vector>
56c5b2abe0SLewanczyk, Dawid
571abe55efSEd Tanous namespace redfish
581abe55efSEd Tanous {
59c5b2abe0SLewanczyk, Dawid
605c3e9272SAbhishek Patel const static std::array<std::pair<std::string_view, std::string_view>, 2>
615c3e9272SAbhishek Patel protocolToDBusForSystems{
625c3e9272SAbhishek Patel {{"SSH", "obmc-console-ssh"}, {"IPMI", "phosphor-ipmi-net"}}};
635c3e9272SAbhishek Patel
649d3ae10eSAlpana Kumari /**
659d3ae10eSAlpana Kumari * @brief Updates the Functional State of DIMMs
669d3ae10eSAlpana Kumari *
67ac106bf6SEd Tanous * @param[in] asyncResp Shared pointer for completing asynchronous calls
689d3ae10eSAlpana Kumari * @param[in] dimmState Dimm's Functional state, true/false
699d3ae10eSAlpana Kumari *
709d3ae10eSAlpana Kumari * @return None.
719d3ae10eSAlpana Kumari */
updateDimmProperties(const std::shared_ptr<bmcweb::AsyncResp> & asyncResp,bool isDimmFunctional)72bd79bce8SPatrick Williams inline void updateDimmProperties(
73bd79bce8SPatrick Williams const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, bool isDimmFunctional)
749d3ae10eSAlpana Kumari {
7562598e31SEd Tanous BMCWEB_LOG_DEBUG("Dimm Functional: {}", isDimmFunctional);
769d3ae10eSAlpana Kumari
779d3ae10eSAlpana Kumari // Set it as Enabled if at least one DIMM is functional
789d3ae10eSAlpana Kumari // Update STATE only if previous State was DISABLED and current Dimm is
799d3ae10eSAlpana Kumari // ENABLED.
8002cad96eSEd Tanous const nlohmann::json& prevMemSummary =
81ac106bf6SEd Tanous asyncResp->res.jsonValue["MemorySummary"]["Status"]["State"];
829d3ae10eSAlpana Kumari if (prevMemSummary == "Disabled")
839d3ae10eSAlpana Kumari {
84e05aec50SEd Tanous if (isDimmFunctional)
859d3ae10eSAlpana Kumari {
86ac106bf6SEd Tanous asyncResp->res.jsonValue["MemorySummary"]["Status"]["State"] =
879d3ae10eSAlpana Kumari "Enabled";
889d3ae10eSAlpana Kumari }
899d3ae10eSAlpana Kumari }
909d3ae10eSAlpana Kumari }
919d3ae10eSAlpana Kumari
9257e8c9beSAlpana Kumari /*
9357e8c9beSAlpana Kumari * @brief Update "ProcessorSummary" "Status" "State" based on
9457e8c9beSAlpana Kumari * CPU Functional State
9557e8c9beSAlpana Kumari *
96ac106bf6SEd Tanous * @param[in] asyncResp Shared pointer for completing asynchronous calls
9757e8c9beSAlpana Kumari * @param[in] cpuFunctionalState is CPU functional true/false
9857e8c9beSAlpana Kumari *
9957e8c9beSAlpana Kumari * @return None.
10057e8c9beSAlpana Kumari */
modifyCpuFunctionalState(const std::shared_ptr<bmcweb::AsyncResp> & asyncResp,bool isCpuFunctional)101ac106bf6SEd Tanous inline void modifyCpuFunctionalState(
102ac106bf6SEd Tanous const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, bool isCpuFunctional)
10357e8c9beSAlpana Kumari {
10462598e31SEd Tanous BMCWEB_LOG_DEBUG("Cpu Functional: {}", isCpuFunctional);
10557e8c9beSAlpana Kumari
10602cad96eSEd Tanous const nlohmann::json& prevProcState =
107ac106bf6SEd Tanous asyncResp->res.jsonValue["ProcessorSummary"]["Status"]["State"];
10857e8c9beSAlpana Kumari
10957e8c9beSAlpana Kumari // Set it as Enabled if at least one CPU is functional
11057e8c9beSAlpana Kumari // Update STATE only if previous State was Non_Functional and current CPU is
11157e8c9beSAlpana Kumari // Functional.
11257e8c9beSAlpana Kumari if (prevProcState == "Disabled")
11357e8c9beSAlpana Kumari {
114e05aec50SEd Tanous if (isCpuFunctional)
11557e8c9beSAlpana Kumari {
116ac106bf6SEd Tanous asyncResp->res.jsonValue["ProcessorSummary"]["Status"]["State"] =
11757e8c9beSAlpana Kumari "Enabled";
11857e8c9beSAlpana Kumari }
11957e8c9beSAlpana Kumari }
12057e8c9beSAlpana Kumari }
12157e8c9beSAlpana Kumari
122cf0e004cSNinad Palsule /*
123cf0e004cSNinad Palsule * @brief Update "ProcessorSummary" "Count" based on Cpu PresenceState
124cf0e004cSNinad Palsule *
125ac106bf6SEd Tanous * @param[in] asyncResp Shared pointer for completing asynchronous calls
126cf0e004cSNinad Palsule * @param[in] cpuPresenceState CPU present or not
127cf0e004cSNinad Palsule *
128cf0e004cSNinad Palsule * @return None.
129cf0e004cSNinad Palsule */
modifyCpuPresenceState(const std::shared_ptr<bmcweb::AsyncResp> & asyncResp,bool isCpuPresent)130bd79bce8SPatrick Williams inline void modifyCpuPresenceState(
131bd79bce8SPatrick Williams const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, bool isCpuPresent)
132cf0e004cSNinad Palsule {
13362598e31SEd Tanous BMCWEB_LOG_DEBUG("Cpu Present: {}", isCpuPresent);
134cf0e004cSNinad Palsule
135cf0e004cSNinad Palsule if (isCpuPresent)
136cf0e004cSNinad Palsule {
137cf0e004cSNinad Palsule nlohmann::json& procCount =
138ac106bf6SEd Tanous asyncResp->res.jsonValue["ProcessorSummary"]["Count"];
139cf0e004cSNinad Palsule auto* procCountPtr =
140cf0e004cSNinad Palsule procCount.get_ptr<nlohmann::json::number_integer_t*>();
141cf0e004cSNinad Palsule if (procCountPtr != nullptr)
142cf0e004cSNinad Palsule {
143cf0e004cSNinad Palsule // shouldn't be possible to be nullptr
144cf0e004cSNinad Palsule *procCountPtr += 1;
145cf0e004cSNinad Palsule }
146cf0e004cSNinad Palsule }
147cf0e004cSNinad Palsule }
148cf0e004cSNinad Palsule
getProcessorProperties(const std::shared_ptr<bmcweb::AsyncResp> & asyncResp,const std::vector<std::pair<std::string,dbus::utility::DbusVariantType>> & properties)149382d6475SAli Ahmed inline void getProcessorProperties(
150ac106bf6SEd Tanous const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
151382d6475SAli Ahmed const std::vector<std::pair<std::string, dbus::utility::DbusVariantType>>&
152382d6475SAli Ahmed properties)
15303fbed92SAli Ahmed {
15462598e31SEd Tanous BMCWEB_LOG_DEBUG("Got {} Cpu properties.", properties.size());
15503fbed92SAli Ahmed
15603fbed92SAli Ahmed // TODO: Get Model
15703fbed92SAli Ahmed
158bc1d29deSKrzysztof Grobelny const uint16_t* coreCount = nullptr;
15903fbed92SAli Ahmed
160bc1d29deSKrzysztof Grobelny const bool success = sdbusplus::unpackPropertiesNoThrow(
161bc1d29deSKrzysztof Grobelny dbus_utils::UnpackErrorPrinter(), properties, "CoreCount", coreCount);
16203fbed92SAli Ahmed
163bc1d29deSKrzysztof Grobelny if (!success)
16403fbed92SAli Ahmed {
165ac106bf6SEd Tanous messages::internalError(asyncResp->res);
16603fbed92SAli Ahmed return;
16703fbed92SAli Ahmed }
16803fbed92SAli Ahmed
169bc1d29deSKrzysztof Grobelny if (coreCount != nullptr)
17003fbed92SAli Ahmed {
171bc1d29deSKrzysztof Grobelny nlohmann::json& coreCountJson =
172ac106bf6SEd Tanous asyncResp->res.jsonValue["ProcessorSummary"]["CoreCount"];
173bc1d29deSKrzysztof Grobelny uint64_t* coreCountJsonPtr = coreCountJson.get_ptr<uint64_t*>();
174bc1d29deSKrzysztof Grobelny
175bc1d29deSKrzysztof Grobelny if (coreCountJsonPtr == nullptr)
176bc1d29deSKrzysztof Grobelny {
177bc1d29deSKrzysztof Grobelny coreCountJson = *coreCount;
17803fbed92SAli Ahmed }
17903fbed92SAli Ahmed else
18003fbed92SAli Ahmed {
181bc1d29deSKrzysztof Grobelny *coreCountJsonPtr += *coreCount;
18203fbed92SAli Ahmed }
18303fbed92SAli Ahmed }
18403fbed92SAli Ahmed }
18503fbed92SAli Ahmed
18603fbed92SAli Ahmed /*
18703fbed92SAli Ahmed * @brief Get ProcessorSummary fields
18803fbed92SAli Ahmed *
189ac106bf6SEd Tanous * @param[in] asyncResp Shared pointer for completing asynchronous calls
19003fbed92SAli Ahmed * @param[in] service dbus service for Cpu Information
19103fbed92SAli Ahmed * @param[in] path dbus path for Cpu
19203fbed92SAli Ahmed *
19303fbed92SAli Ahmed * @return None.
19403fbed92SAli Ahmed */
getProcessorSummary(const std::shared_ptr<bmcweb::AsyncResp> & asyncResp,const std::string & service,const std::string & path)195*504af5a0SPatrick Williams inline void getProcessorSummary(
196*504af5a0SPatrick Williams const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
197ac106bf6SEd Tanous const std::string& service, const std::string& path)
19803fbed92SAli Ahmed {
199ac106bf6SEd Tanous auto getCpuPresenceState = [asyncResp](const boost::system::error_code& ec3,
200382d6475SAli Ahmed const bool cpuPresenceCheck) {
201382d6475SAli Ahmed if (ec3)
202382d6475SAli Ahmed {
20362598e31SEd Tanous BMCWEB_LOG_ERROR("DBUS response error {}", ec3);
204382d6475SAli Ahmed return;
205382d6475SAli Ahmed }
206ac106bf6SEd Tanous modifyCpuPresenceState(asyncResp, cpuPresenceCheck);
207382d6475SAli Ahmed };
208382d6475SAli Ahmed
209cf0e004cSNinad Palsule // Get the Presence of CPU
210deae6a78SEd Tanous dbus::utility::getProperty<bool>(*crow::connections::systemBus, service,
211deae6a78SEd Tanous path, "xyz.openbmc_project.Inventory.Item",
212deae6a78SEd Tanous "Present", std::move(getCpuPresenceState));
213cf0e004cSNinad Palsule
214deae6a78SEd Tanous dbus::utility::getAllProperties(
215deae6a78SEd Tanous service, path, "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 */
processMemoryProperties(const std::shared_ptr<bmcweb::AsyncResp> & asyncResp,const dbus::utility::DBusPropertiesMap & properties)237*504af5a0SPatrick Williams inline void processMemoryProperties(
238*504af5a0SPatrick Williams 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 */
getMemorySummary(const std::shared_ptr<bmcweb::AsyncResp> & asyncResp,const std::string & service,const std::string & path)288*504af5a0SPatrick Williams inline void getMemorySummary(
289*504af5a0SPatrick Williams const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
290ac106bf6SEd Tanous const std::string& service, const std::string& path)
291cf0e004cSNinad Palsule {
292deae6a78SEd Tanous dbus::utility::getAllProperties(
293deae6a78SEd Tanous service, path, "xyz.openbmc_project.Inventory.Item.Dimm",
294ac106bf6SEd Tanous [asyncResp, service,
295cf0e004cSNinad Palsule path](const boost::system::error_code& ec2,
296cf0e004cSNinad Palsule const dbus::utility::DBusPropertiesMap& properties) {
297cf0e004cSNinad Palsule if (ec2)
298cf0e004cSNinad Palsule {
29962598e31SEd Tanous BMCWEB_LOG_ERROR("DBUS response error {}", ec2);
300ac106bf6SEd Tanous messages::internalError(asyncResp->res);
301cf0e004cSNinad Palsule return;
302cf0e004cSNinad Palsule }
30351bd2d8aSGunnar Mills processMemoryProperties(asyncResp, properties);
304cf0e004cSNinad Palsule });
305cf0e004cSNinad Palsule }
306cf0e004cSNinad Palsule
afterGetUUID(const std::shared_ptr<bmcweb::AsyncResp> & asyncResp,const boost::system::error_code & ec,const dbus::utility::DBusPropertiesMap & properties)307a974c132SLakshmi Yadlapati inline void afterGetUUID(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
308a974c132SLakshmi Yadlapati const boost::system::error_code& ec,
309a974c132SLakshmi Yadlapati const dbus::utility::DBusPropertiesMap& properties)
3101abe55efSEd Tanous {
311a974c132SLakshmi Yadlapati if (ec)
312a974c132SLakshmi Yadlapati {
313a974c132SLakshmi Yadlapati BMCWEB_LOG_ERROR("DBUS response error {}", ec);
314a974c132SLakshmi Yadlapati messages::internalError(asyncResp->res);
315a974c132SLakshmi Yadlapati return;
316a974c132SLakshmi Yadlapati }
317a974c132SLakshmi Yadlapati BMCWEB_LOG_DEBUG("Got {} UUID properties.", properties.size());
318a974c132SLakshmi Yadlapati
319a974c132SLakshmi Yadlapati const std::string* uUID = nullptr;
320a974c132SLakshmi Yadlapati
321a974c132SLakshmi Yadlapati const bool success = sdbusplus::unpackPropertiesNoThrow(
322a974c132SLakshmi Yadlapati dbus_utils::UnpackErrorPrinter(), properties, "UUID", uUID);
323a974c132SLakshmi Yadlapati
324a974c132SLakshmi Yadlapati if (!success)
325a974c132SLakshmi Yadlapati {
326a974c132SLakshmi Yadlapati messages::internalError(asyncResp->res);
327a974c132SLakshmi Yadlapati return;
328a974c132SLakshmi Yadlapati }
329a974c132SLakshmi Yadlapati
330a974c132SLakshmi Yadlapati if (uUID != nullptr)
331a974c132SLakshmi Yadlapati {
332a974c132SLakshmi Yadlapati std::string valueStr = *uUID;
333a974c132SLakshmi Yadlapati if (valueStr.size() == 32)
334a974c132SLakshmi Yadlapati {
335a974c132SLakshmi Yadlapati valueStr.insert(8, 1, '-');
336a974c132SLakshmi Yadlapati valueStr.insert(13, 1, '-');
337a974c132SLakshmi Yadlapati valueStr.insert(18, 1, '-');
338a974c132SLakshmi Yadlapati valueStr.insert(23, 1, '-');
339a974c132SLakshmi Yadlapati }
340a974c132SLakshmi Yadlapati BMCWEB_LOG_DEBUG("UUID = {}", valueStr);
341a974c132SLakshmi Yadlapati asyncResp->res.jsonValue["UUID"] = valueStr;
342a974c132SLakshmi Yadlapati }
343a974c132SLakshmi Yadlapati }
344a974c132SLakshmi Yadlapati
afterGetInventory(const std::shared_ptr<bmcweb::AsyncResp> & asyncResp,const boost::system::error_code & ec,const dbus::utility::DBusPropertiesMap & propertiesList)345*504af5a0SPatrick Williams inline void afterGetInventory(
346*504af5a0SPatrick Williams const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
347a974c132SLakshmi Yadlapati const boost::system::error_code& ec,
348a974c132SLakshmi Yadlapati const dbus::utility::DBusPropertiesMap& propertiesList)
349a974c132SLakshmi Yadlapati {
350a974c132SLakshmi Yadlapati if (ec)
351a974c132SLakshmi Yadlapati {
352a974c132SLakshmi Yadlapati // doesn't have to include this
353a974c132SLakshmi Yadlapati // interface
354a974c132SLakshmi Yadlapati return;
355a974c132SLakshmi Yadlapati }
356a974c132SLakshmi Yadlapati BMCWEB_LOG_DEBUG("Got {} properties for system", propertiesList.size());
357a974c132SLakshmi Yadlapati
358a974c132SLakshmi Yadlapati const std::string* partNumber = nullptr;
359a974c132SLakshmi Yadlapati const std::string* serialNumber = nullptr;
360a974c132SLakshmi Yadlapati const std::string* manufacturer = nullptr;
361a974c132SLakshmi Yadlapati const std::string* model = nullptr;
362a974c132SLakshmi Yadlapati const std::string* subModel = nullptr;
363a974c132SLakshmi Yadlapati
364a974c132SLakshmi Yadlapati const bool success = sdbusplus::unpackPropertiesNoThrow(
365a974c132SLakshmi Yadlapati dbus_utils::UnpackErrorPrinter(), propertiesList, "PartNumber",
366a974c132SLakshmi Yadlapati partNumber, "SerialNumber", serialNumber, "Manufacturer", manufacturer,
367a974c132SLakshmi Yadlapati "Model", model, "SubModel", subModel);
368a974c132SLakshmi Yadlapati
369a974c132SLakshmi Yadlapati if (!success)
370a974c132SLakshmi Yadlapati {
371a974c132SLakshmi Yadlapati messages::internalError(asyncResp->res);
372a974c132SLakshmi Yadlapati return;
373a974c132SLakshmi Yadlapati }
374a974c132SLakshmi Yadlapati
375a974c132SLakshmi Yadlapati if (partNumber != nullptr)
376a974c132SLakshmi Yadlapati {
377a974c132SLakshmi Yadlapati asyncResp->res.jsonValue["PartNumber"] = *partNumber;
378a974c132SLakshmi Yadlapati }
379a974c132SLakshmi Yadlapati
380a974c132SLakshmi Yadlapati if (serialNumber != nullptr)
381a974c132SLakshmi Yadlapati {
382a974c132SLakshmi Yadlapati asyncResp->res.jsonValue["SerialNumber"] = *serialNumber;
383a974c132SLakshmi Yadlapati }
384a974c132SLakshmi Yadlapati
385a974c132SLakshmi Yadlapati if (manufacturer != nullptr)
386a974c132SLakshmi Yadlapati {
387a974c132SLakshmi Yadlapati asyncResp->res.jsonValue["Manufacturer"] = *manufacturer;
388a974c132SLakshmi Yadlapati }
389a974c132SLakshmi Yadlapati
390a974c132SLakshmi Yadlapati if (model != nullptr)
391a974c132SLakshmi Yadlapati {
392a974c132SLakshmi Yadlapati asyncResp->res.jsonValue["Model"] = *model;
393a974c132SLakshmi Yadlapati }
394a974c132SLakshmi Yadlapati
395a974c132SLakshmi Yadlapati if (subModel != nullptr)
396a974c132SLakshmi Yadlapati {
397a974c132SLakshmi Yadlapati asyncResp->res.jsonValue["SubModel"] = *subModel;
398a974c132SLakshmi Yadlapati }
399a974c132SLakshmi Yadlapati
400a974c132SLakshmi Yadlapati // Grab the bios version
401a974c132SLakshmi Yadlapati sw_util::populateSoftwareInformation(asyncResp, sw_util::biosPurpose,
402a974c132SLakshmi Yadlapati "BiosVersion", false);
403a974c132SLakshmi Yadlapati }
404a974c132SLakshmi Yadlapati
afterGetAssetTag(const std::shared_ptr<bmcweb::AsyncResp> & asyncResp,const boost::system::error_code & ec,const std::string & value)405bd79bce8SPatrick Williams inline void afterGetAssetTag(
406bd79bce8SPatrick Williams const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
407bd79bce8SPatrick Williams const boost::system::error_code& ec, const std::string& value)
408a974c132SLakshmi Yadlapati {
409a974c132SLakshmi Yadlapati if (ec)
410a974c132SLakshmi Yadlapati {
411a974c132SLakshmi Yadlapati // doesn't have to include this
412a974c132SLakshmi Yadlapati // interface
413a974c132SLakshmi Yadlapati return;
414a974c132SLakshmi Yadlapati }
415a974c132SLakshmi Yadlapati
416a974c132SLakshmi Yadlapati asyncResp->res.jsonValue["AssetTag"] = value;
417a974c132SLakshmi Yadlapati }
418a974c132SLakshmi Yadlapati
afterSystemGetSubTree(const std::shared_ptr<bmcweb::AsyncResp> & asyncResp,const boost::system::error_code & ec,const dbus::utility::MapperGetSubTreeResponse & subtree)419a974c132SLakshmi Yadlapati inline void afterSystemGetSubTree(
420a974c132SLakshmi Yadlapati const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
421a974c132SLakshmi Yadlapati const boost::system::error_code& ec,
422a974c132SLakshmi Yadlapati const dbus::utility::MapperGetSubTreeResponse& subtree)
423a974c132SLakshmi Yadlapati {
4241abe55efSEd Tanous if (ec)
4251abe55efSEd Tanous {
426b3e86cb0SGunnar Mills BMCWEB_LOG_ERROR("DBUS response error {}", ec);
427ac106bf6SEd Tanous messages::internalError(asyncResp->res);
428c5b2abe0SLewanczyk, Dawid return;
429c5b2abe0SLewanczyk, Dawid }
430c5b2abe0SLewanczyk, Dawid // Iterate over all retrieved ObjectPaths.
431002d39b4SEd Tanous for (const std::pair<
432002d39b4SEd Tanous std::string,
433002d39b4SEd Tanous std::vector<std::pair<std::string, std::vector<std::string>>>>&
4341214b7e7SGunnar Mills object : subtree)
4351abe55efSEd Tanous {
436c5b2abe0SLewanczyk, Dawid const std::string& path = object.first;
43762598e31SEd Tanous BMCWEB_LOG_DEBUG("Got path: {}", path);
438002d39b4SEd Tanous const std::vector<std::pair<std::string, std::vector<std::string>>>&
4391214b7e7SGunnar Mills connectionNames = object.second;
44026f6976fSEd Tanous if (connectionNames.empty())
4411abe55efSEd Tanous {
442c5b2abe0SLewanczyk, Dawid continue;
443c5b2abe0SLewanczyk, Dawid }
444029573d4SEd Tanous
4456c34de48SEd Tanous // This is not system, so check if it's cpu, dimm, UUID or
4466c34de48SEd Tanous // BiosVer
44704a258f4SEd Tanous for (const auto& connection : connectionNames)
4481abe55efSEd Tanous {
44904a258f4SEd Tanous for (const auto& interfaceName : connection.second)
4501abe55efSEd Tanous {
451a974c132SLakshmi Yadlapati if (interfaceName == "xyz.openbmc_project.Inventory.Item.Dimm")
4521abe55efSEd Tanous {
45362598e31SEd Tanous BMCWEB_LOG_DEBUG("Found Dimm, now get its properties.");
4549d3ae10eSAlpana Kumari
455ac106bf6SEd Tanous getMemorySummary(asyncResp, connection.first, path);
4565fd0aafbSNinad Palsule }
45704a258f4SEd Tanous else if (interfaceName ==
45804a258f4SEd Tanous "xyz.openbmc_project.Inventory.Item.Cpu")
4591abe55efSEd Tanous {
46062598e31SEd Tanous BMCWEB_LOG_DEBUG("Found Cpu, now get its properties.");
46157e8c9beSAlpana Kumari
462ac106bf6SEd Tanous getProcessorSummary(asyncResp, connection.first, path);
4635fd0aafbSNinad Palsule }
464002d39b4SEd Tanous else if (interfaceName == "xyz.openbmc_project.Common.UUID")
4651abe55efSEd Tanous {
46662598e31SEd Tanous BMCWEB_LOG_DEBUG("Found UUID, now get its properties.");
467bc1d29deSKrzysztof Grobelny
468deae6a78SEd Tanous dbus::utility::getAllProperties(
469a974c132SLakshmi Yadlapati *crow::connections::systemBus, connection.first, path,
470a974c132SLakshmi Yadlapati "xyz.openbmc_project.Common.UUID",
471ac106bf6SEd Tanous [asyncResp](const boost::system::error_code& ec3,
472b9d36b47SEd Tanous const dbus::utility::DBusPropertiesMap&
4731214b7e7SGunnar Mills properties) {
474a974c132SLakshmi Yadlapati afterGetUUID(asyncResp, ec3, properties);
475bc1d29deSKrzysztof Grobelny });
476c5b2abe0SLewanczyk, Dawid }
477029573d4SEd Tanous else if (interfaceName ==
478029573d4SEd Tanous "xyz.openbmc_project.Inventory.Item.System")
4791abe55efSEd Tanous {
480deae6a78SEd Tanous dbus::utility::getAllProperties(
481a974c132SLakshmi Yadlapati *crow::connections::systemBus, connection.first, path,
482bc1d29deSKrzysztof Grobelny "xyz.openbmc_project.Inventory.Decorator.Asset",
483a974c132SLakshmi Yadlapati [asyncResp](const boost::system::error_code& ec3,
484b9d36b47SEd Tanous const dbus::utility::DBusPropertiesMap&
485a974c132SLakshmi Yadlapati properties) {
486a974c132SLakshmi Yadlapati afterGetInventory(asyncResp, ec3, properties);
487bc1d29deSKrzysztof Grobelny });
488e4a4b9a9SJames Feist
489deae6a78SEd Tanous dbus::utility::getProperty<std::string>(
490deae6a78SEd Tanous connection.first, path,
4911e1e598dSJonathan Doman "xyz.openbmc_project.Inventory.Decorator."
4921e1e598dSJonathan Doman "AssetTag",
4931e1e598dSJonathan Doman "AssetTag",
494a974c132SLakshmi Yadlapati std::bind_front(afterGetAssetTag, asyncResp));
495a974c132SLakshmi Yadlapati }
496a974c132SLakshmi Yadlapati }
497a974c132SLakshmi Yadlapati }
498a974c132SLakshmi Yadlapati }
499a974c132SLakshmi Yadlapati }
500a974c132SLakshmi Yadlapati
501a974c132SLakshmi Yadlapati /*
502a974c132SLakshmi Yadlapati * @brief Retrieves computer system properties over dbus
503a974c132SLakshmi Yadlapati *
504a974c132SLakshmi Yadlapati * @param[in] asyncResp Shared pointer for completing asynchronous calls
505a974c132SLakshmi Yadlapati *
506a974c132SLakshmi Yadlapati * @return None.
507a974c132SLakshmi Yadlapati */
getComputerSystem(const std::shared_ptr<bmcweb::AsyncResp> & asyncResp)508*504af5a0SPatrick Williams inline void getComputerSystem(
509*504af5a0SPatrick Williams const std::shared_ptr<bmcweb::AsyncResp>& asyncResp)
510e4a4b9a9SJames Feist {
511a974c132SLakshmi Yadlapati BMCWEB_LOG_DEBUG("Get available system components.");
512a974c132SLakshmi Yadlapati constexpr std::array<std::string_view, 5> interfaces = {
513a974c132SLakshmi Yadlapati "xyz.openbmc_project.Inventory.Decorator.Asset",
514a974c132SLakshmi Yadlapati "xyz.openbmc_project.Inventory.Item.Cpu",
515a974c132SLakshmi Yadlapati "xyz.openbmc_project.Inventory.Item.Dimm",
516a974c132SLakshmi Yadlapati "xyz.openbmc_project.Inventory.Item.System",
517a974c132SLakshmi Yadlapati "xyz.openbmc_project.Common.UUID",
518a974c132SLakshmi Yadlapati };
519a974c132SLakshmi Yadlapati dbus::utility::getSubTree(
520a974c132SLakshmi Yadlapati "/xyz/openbmc_project/inventory", 0, interfaces,
52151bd2d8aSGunnar Mills std::bind_front(afterSystemGetSubTree, asyncResp));
522c5b2abe0SLewanczyk, Dawid }
523c5b2abe0SLewanczyk, Dawid
524c5b2abe0SLewanczyk, Dawid /**
525c5b2abe0SLewanczyk, Dawid * @brief Retrieves host state properties over dbus
526c5b2abe0SLewanczyk, Dawid *
527ac106bf6SEd Tanous * @param[in] asyncResp Shared pointer for completing asynchronous calls.
528c5b2abe0SLewanczyk, Dawid *
529c5b2abe0SLewanczyk, Dawid * @return None.
530c5b2abe0SLewanczyk, Dawid */
getHostState(const std::shared_ptr<bmcweb::AsyncResp> & asyncResp)531ac106bf6SEd Tanous inline void getHostState(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp)
5321abe55efSEd Tanous {
53362598e31SEd Tanous BMCWEB_LOG_DEBUG("Get host information.");
534deae6a78SEd Tanous dbus::utility::getProperty<std::string>(
535deae6a78SEd Tanous "xyz.openbmc_project.State.Host", "/xyz/openbmc_project/state/host0",
536deae6a78SEd Tanous "xyz.openbmc_project.State.Host", "CurrentHostState",
537ac106bf6SEd Tanous [asyncResp](const boost::system::error_code& ec,
5381e1e598dSJonathan Doman const std::string& hostState) {
5391abe55efSEd Tanous if (ec)
5401abe55efSEd Tanous {
54122228c28SAndrew Geissler if (ec == boost::system::errc::host_unreachable)
54222228c28SAndrew Geissler {
54322228c28SAndrew Geissler // Service not available, no error, just don't return
54422228c28SAndrew Geissler // host state info
54562598e31SEd Tanous BMCWEB_LOG_DEBUG("Service not available {}", ec);
54622228c28SAndrew Geissler return;
54722228c28SAndrew Geissler }
54862598e31SEd Tanous BMCWEB_LOG_ERROR("DBUS response error {}", ec);
549ac106bf6SEd Tanous messages::internalError(asyncResp->res);
550c5b2abe0SLewanczyk, Dawid return;
551c5b2abe0SLewanczyk, Dawid }
5526617338dSEd Tanous
55362598e31SEd Tanous BMCWEB_LOG_DEBUG("Host state: {}", hostState);
554c5b2abe0SLewanczyk, Dawid // Verify Host State
5551e1e598dSJonathan Doman if (hostState == "xyz.openbmc_project.State.Host.HostState.Running")
5561abe55efSEd Tanous {
557bd79bce8SPatrick Williams asyncResp->res.jsonValue["PowerState"] =
558bd79bce8SPatrick Williams resource::PowerState::On;
559539d8c6bSEd Tanous asyncResp->res.jsonValue["Status"]["State"] =
560539d8c6bSEd Tanous resource::State::Enabled;
5611abe55efSEd Tanous }
5621e1e598dSJonathan Doman else if (hostState ==
5630fda0f12SGeorge Liu "xyz.openbmc_project.State.Host.HostState.Quiesced")
5648c888608SGunnar Mills {
565bd79bce8SPatrick Williams asyncResp->res.jsonValue["PowerState"] =
566bd79bce8SPatrick Williams resource::PowerState::On;
567539d8c6bSEd Tanous asyncResp->res.jsonValue["Status"]["State"] =
568539d8c6bSEd Tanous resource::State::Quiesced;
5698c888608SGunnar Mills }
5701e1e598dSJonathan Doman else if (hostState ==
5710fda0f12SGeorge Liu "xyz.openbmc_project.State.Host.HostState.DiagnosticMode")
57283935af9SAndrew Geissler {
573bd79bce8SPatrick Williams asyncResp->res.jsonValue["PowerState"] =
574bd79bce8SPatrick Williams resource::PowerState::On;
575539d8c6bSEd Tanous asyncResp->res.jsonValue["Status"]["State"] =
576539d8c6bSEd Tanous resource::State::InTest;
57783935af9SAndrew Geissler }
5780fda0f12SGeorge Liu else if (
5791e1e598dSJonathan Doman hostState ==
5800fda0f12SGeorge Liu "xyz.openbmc_project.State.Host.HostState.TransitioningToRunning")
5811a2a1437SAndrew Geissler {
582539d8c6bSEd Tanous asyncResp->res.jsonValue["PowerState"] =
583539d8c6bSEd Tanous resource::PowerState::PoweringOn;
584539d8c6bSEd Tanous asyncResp->res.jsonValue["Status"]["State"] =
585539d8c6bSEd Tanous resource::State::Starting;
5861a2a1437SAndrew Geissler }
587bd79bce8SPatrick Williams else if (
588bd79bce8SPatrick Williams hostState ==
5890fda0f12SGeorge Liu "xyz.openbmc_project.State.Host.HostState.TransitioningToOff")
5901a2a1437SAndrew Geissler {
591539d8c6bSEd Tanous asyncResp->res.jsonValue["PowerState"] =
592539d8c6bSEd Tanous resource::PowerState::PoweringOff;
593539d8c6bSEd Tanous asyncResp->res.jsonValue["Status"]["State"] =
594539d8c6bSEd Tanous resource::State::Disabled;
5951a2a1437SAndrew Geissler }
5961abe55efSEd Tanous else
5971abe55efSEd Tanous {
598bd79bce8SPatrick Williams asyncResp->res.jsonValue["PowerState"] =
599bd79bce8SPatrick Williams resource::PowerState::Off;
600539d8c6bSEd Tanous asyncResp->res.jsonValue["Status"]["State"] =
601539d8c6bSEd Tanous resource::State::Disabled;
602c5b2abe0SLewanczyk, Dawid }
6031e1e598dSJonathan Doman });
604c5b2abe0SLewanczyk, Dawid }
605c5b2abe0SLewanczyk, Dawid
606c5b2abe0SLewanczyk, Dawid /**
607786d0f60SGunnar Mills * @brief Translates boot source DBUS property value to redfish.
608491d8ee7SSantosh Puranik *
609491d8ee7SSantosh Puranik * @param[in] dbusSource The boot source in DBUS speak.
610491d8ee7SSantosh Puranik *
611491d8ee7SSantosh Puranik * @return Returns as a string, the boot source in Redfish terms. If translation
612491d8ee7SSantosh Puranik * cannot be done, returns an empty string.
613491d8ee7SSantosh Puranik */
dbusToRfBootSource(const std::string & dbusSource)61423a21a1cSEd Tanous inline std::string dbusToRfBootSource(const std::string& dbusSource)
615491d8ee7SSantosh Puranik {
616491d8ee7SSantosh Puranik if (dbusSource == "xyz.openbmc_project.Control.Boot.Source.Sources.Default")
617491d8ee7SSantosh Puranik {
618491d8ee7SSantosh Puranik return "None";
619491d8ee7SSantosh Puranik }
6203174e4dfSEd Tanous if (dbusSource == "xyz.openbmc_project.Control.Boot.Source.Sources.Disk")
621491d8ee7SSantosh Puranik {
622491d8ee7SSantosh Puranik return "Hdd";
623491d8ee7SSantosh Puranik }
6243174e4dfSEd Tanous if (dbusSource ==
625a71dc0b7SSantosh Puranik "xyz.openbmc_project.Control.Boot.Source.Sources.ExternalMedia")
626491d8ee7SSantosh Puranik {
627491d8ee7SSantosh Puranik return "Cd";
628491d8ee7SSantosh Puranik }
6293174e4dfSEd Tanous if (dbusSource == "xyz.openbmc_project.Control.Boot.Source.Sources.Network")
630491d8ee7SSantosh Puranik {
631491d8ee7SSantosh Puranik return "Pxe";
632491d8ee7SSantosh Puranik }
6333174e4dfSEd Tanous if (dbusSource ==
634944ffaf9SJohnathan Mantey "xyz.openbmc_project.Control.Boot.Source.Sources.RemovableMedia")
6359f16b2c1SJennifer Lee {
6369f16b2c1SJennifer Lee return "Usb";
6379f16b2c1SJennifer Lee }
638491d8ee7SSantosh Puranik return "";
639491d8ee7SSantosh Puranik }
640491d8ee7SSantosh Puranik
641491d8ee7SSantosh Puranik /**
642cd9a4666SKonstantin Aladyshev * @brief Translates boot type DBUS property value to redfish.
643cd9a4666SKonstantin Aladyshev *
644cd9a4666SKonstantin Aladyshev * @param[in] dbusType The boot type in DBUS speak.
645cd9a4666SKonstantin Aladyshev *
646cd9a4666SKonstantin Aladyshev * @return Returns as a string, the boot type in Redfish terms. If translation
647cd9a4666SKonstantin Aladyshev * cannot be done, returns an empty string.
648cd9a4666SKonstantin Aladyshev */
dbusToRfBootType(const std::string & dbusType)649cd9a4666SKonstantin Aladyshev inline std::string dbusToRfBootType(const std::string& dbusType)
650cd9a4666SKonstantin Aladyshev {
651cd9a4666SKonstantin Aladyshev if (dbusType == "xyz.openbmc_project.Control.Boot.Type.Types.Legacy")
652cd9a4666SKonstantin Aladyshev {
653cd9a4666SKonstantin Aladyshev return "Legacy";
654cd9a4666SKonstantin Aladyshev }
655cd9a4666SKonstantin Aladyshev if (dbusType == "xyz.openbmc_project.Control.Boot.Type.Types.EFI")
656cd9a4666SKonstantin Aladyshev {
657cd9a4666SKonstantin Aladyshev return "UEFI";
658cd9a4666SKonstantin Aladyshev }
659cd9a4666SKonstantin Aladyshev return "";
660cd9a4666SKonstantin Aladyshev }
661cd9a4666SKonstantin Aladyshev
662cd9a4666SKonstantin Aladyshev /**
663786d0f60SGunnar Mills * @brief Translates boot mode DBUS property value to redfish.
664491d8ee7SSantosh Puranik *
665491d8ee7SSantosh Puranik * @param[in] dbusMode The boot mode in DBUS speak.
666491d8ee7SSantosh Puranik *
667491d8ee7SSantosh Puranik * @return Returns as a string, the boot mode in Redfish terms. If translation
668491d8ee7SSantosh Puranik * cannot be done, returns an empty string.
669491d8ee7SSantosh Puranik */
dbusToRfBootMode(const std::string & dbusMode)67023a21a1cSEd Tanous inline std::string dbusToRfBootMode(const std::string& dbusMode)
671491d8ee7SSantosh Puranik {
672491d8ee7SSantosh Puranik if (dbusMode == "xyz.openbmc_project.Control.Boot.Mode.Modes.Regular")
673491d8ee7SSantosh Puranik {
674491d8ee7SSantosh Puranik return "None";
675491d8ee7SSantosh Puranik }
6763174e4dfSEd Tanous if (dbusMode == "xyz.openbmc_project.Control.Boot.Mode.Modes.Safe")
677491d8ee7SSantosh Puranik {
678491d8ee7SSantosh Puranik return "Diags";
679491d8ee7SSantosh Puranik }
6803174e4dfSEd Tanous if (dbusMode == "xyz.openbmc_project.Control.Boot.Mode.Modes.Setup")
681491d8ee7SSantosh Puranik {
682491d8ee7SSantosh Puranik return "BiosSetup";
683491d8ee7SSantosh Puranik }
684491d8ee7SSantosh Puranik return "";
685491d8ee7SSantosh Puranik }
686491d8ee7SSantosh Puranik
687491d8ee7SSantosh Puranik /**
688e43914b3SAndrew Geissler * @brief Translates boot progress DBUS property value to redfish.
689e43914b3SAndrew Geissler *
690e43914b3SAndrew Geissler * @param[in] dbusBootProgress The boot progress in DBUS speak.
691e43914b3SAndrew Geissler *
692e43914b3SAndrew Geissler * @return Returns as a string, the boot progress in Redfish terms. If
693e43914b3SAndrew Geissler * translation cannot be done, returns "None".
694e43914b3SAndrew Geissler */
dbusToRfBootProgress(const std::string & dbusBootProgress)695e43914b3SAndrew Geissler inline std::string dbusToRfBootProgress(const std::string& dbusBootProgress)
696e43914b3SAndrew Geissler {
697e43914b3SAndrew Geissler // Now convert the D-Bus BootProgress to the appropriate Redfish
698e43914b3SAndrew Geissler // enum
699e43914b3SAndrew Geissler std::string rfBpLastState = "None";
700e43914b3SAndrew Geissler if (dbusBootProgress == "xyz.openbmc_project.State.Boot.Progress."
701e43914b3SAndrew Geissler "ProgressStages.Unspecified")
702e43914b3SAndrew Geissler {
703e43914b3SAndrew Geissler rfBpLastState = "None";
704e43914b3SAndrew Geissler }
705e43914b3SAndrew Geissler else if (dbusBootProgress ==
706e43914b3SAndrew Geissler "xyz.openbmc_project.State.Boot.Progress.ProgressStages."
707e43914b3SAndrew Geissler "PrimaryProcInit")
708e43914b3SAndrew Geissler {
709e43914b3SAndrew Geissler rfBpLastState = "PrimaryProcessorInitializationStarted";
710e43914b3SAndrew Geissler }
711e43914b3SAndrew Geissler else if (dbusBootProgress ==
712e43914b3SAndrew Geissler "xyz.openbmc_project.State.Boot.Progress.ProgressStages."
713e43914b3SAndrew Geissler "BusInit")
714e43914b3SAndrew Geissler {
715e43914b3SAndrew Geissler rfBpLastState = "BusInitializationStarted";
716e43914b3SAndrew Geissler }
717e43914b3SAndrew Geissler else if (dbusBootProgress ==
718e43914b3SAndrew Geissler "xyz.openbmc_project.State.Boot.Progress.ProgressStages."
719e43914b3SAndrew Geissler "MemoryInit")
720e43914b3SAndrew Geissler {
721e43914b3SAndrew Geissler rfBpLastState = "MemoryInitializationStarted";
722e43914b3SAndrew Geissler }
723e43914b3SAndrew Geissler else if (dbusBootProgress ==
724e43914b3SAndrew Geissler "xyz.openbmc_project.State.Boot.Progress.ProgressStages."
725e43914b3SAndrew Geissler "SecondaryProcInit")
726e43914b3SAndrew Geissler {
727e43914b3SAndrew Geissler rfBpLastState = "SecondaryProcessorInitializationStarted";
728e43914b3SAndrew Geissler }
729e43914b3SAndrew Geissler else if (dbusBootProgress ==
730e43914b3SAndrew Geissler "xyz.openbmc_project.State.Boot.Progress.ProgressStages."
731e43914b3SAndrew Geissler "PCIInit")
732e43914b3SAndrew Geissler {
733e43914b3SAndrew Geissler rfBpLastState = "PCIResourceConfigStarted";
734e43914b3SAndrew Geissler }
735e43914b3SAndrew Geissler else if (dbusBootProgress ==
736e43914b3SAndrew Geissler "xyz.openbmc_project.State.Boot.Progress.ProgressStages."
737e43914b3SAndrew Geissler "SystemSetup")
738e43914b3SAndrew Geissler {
739e43914b3SAndrew Geissler rfBpLastState = "SetupEntered";
740e43914b3SAndrew Geissler }
741e43914b3SAndrew Geissler else if (dbusBootProgress ==
742e43914b3SAndrew Geissler "xyz.openbmc_project.State.Boot.Progress.ProgressStages."
743e43914b3SAndrew Geissler "SystemInitComplete")
744e43914b3SAndrew Geissler {
745e43914b3SAndrew Geissler rfBpLastState = "SystemHardwareInitializationComplete";
746e43914b3SAndrew Geissler }
747e43914b3SAndrew Geissler else if (dbusBootProgress ==
748e43914b3SAndrew Geissler "xyz.openbmc_project.State.Boot.Progress.ProgressStages."
749e43914b3SAndrew Geissler "OSStart")
750e43914b3SAndrew Geissler {
751e43914b3SAndrew Geissler rfBpLastState = "OSBootStarted";
752e43914b3SAndrew Geissler }
753e43914b3SAndrew Geissler else if (dbusBootProgress ==
754e43914b3SAndrew Geissler "xyz.openbmc_project.State.Boot.Progress.ProgressStages."
755e43914b3SAndrew Geissler "OSRunning")
756e43914b3SAndrew Geissler {
757e43914b3SAndrew Geissler rfBpLastState = "OSRunning";
758e43914b3SAndrew Geissler }
759e43914b3SAndrew Geissler else
760e43914b3SAndrew Geissler {
76162598e31SEd Tanous BMCWEB_LOG_DEBUG("Unsupported D-Bus BootProgress {}", dbusBootProgress);
762e43914b3SAndrew Geissler // Just return the default
763e43914b3SAndrew Geissler }
764e43914b3SAndrew Geissler return rfBpLastState;
765e43914b3SAndrew Geissler }
766e43914b3SAndrew Geissler
767e43914b3SAndrew Geissler /**
768786d0f60SGunnar Mills * @brief Translates boot source from Redfish to the DBus boot paths.
769491d8ee7SSantosh Puranik *
770491d8ee7SSantosh Puranik * @param[in] rfSource The boot source in Redfish.
771944ffaf9SJohnathan Mantey * @param[out] bootSource The DBus source
772944ffaf9SJohnathan Mantey * @param[out] bootMode the DBus boot mode
773491d8ee7SSantosh Puranik *
774944ffaf9SJohnathan Mantey * @return Integer error code.
775491d8ee7SSantosh Puranik */
assignBootParameters(const std::shared_ptr<bmcweb::AsyncResp> & asyncResp,const std::string & rfSource,std::string & bootSource,std::string & bootMode)776bd79bce8SPatrick Williams inline int assignBootParameters(
777bd79bce8SPatrick Williams const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
778bd79bce8SPatrick Williams const std::string& rfSource, std::string& bootSource, std::string& bootMode)
779491d8ee7SSantosh Puranik {
780c21865c4SKonstantin Aladyshev bootSource = "xyz.openbmc_project.Control.Boot.Source.Sources.Default";
781c21865c4SKonstantin Aladyshev bootMode = "xyz.openbmc_project.Control.Boot.Mode.Modes.Regular";
782944ffaf9SJohnathan Mantey
783491d8ee7SSantosh Puranik if (rfSource == "None")
784491d8ee7SSantosh Puranik {
785944ffaf9SJohnathan Mantey return 0;
786491d8ee7SSantosh Puranik }
7873174e4dfSEd Tanous if (rfSource == "Pxe")
788491d8ee7SSantosh Puranik {
789944ffaf9SJohnathan Mantey bootSource = "xyz.openbmc_project.Control.Boot.Source.Sources.Network";
790944ffaf9SJohnathan Mantey }
791944ffaf9SJohnathan Mantey else if (rfSource == "Hdd")
792944ffaf9SJohnathan Mantey {
793944ffaf9SJohnathan Mantey bootSource = "xyz.openbmc_project.Control.Boot.Source.Sources.Disk";
794944ffaf9SJohnathan Mantey }
795944ffaf9SJohnathan Mantey else if (rfSource == "Diags")
796944ffaf9SJohnathan Mantey {
797944ffaf9SJohnathan Mantey bootMode = "xyz.openbmc_project.Control.Boot.Mode.Modes.Safe";
798944ffaf9SJohnathan Mantey }
799944ffaf9SJohnathan Mantey else if (rfSource == "Cd")
800944ffaf9SJohnathan Mantey {
801944ffaf9SJohnathan Mantey bootSource =
802944ffaf9SJohnathan Mantey "xyz.openbmc_project.Control.Boot.Source.Sources.ExternalMedia";
803944ffaf9SJohnathan Mantey }
804944ffaf9SJohnathan Mantey else if (rfSource == "BiosSetup")
805944ffaf9SJohnathan Mantey {
806944ffaf9SJohnathan Mantey bootMode = "xyz.openbmc_project.Control.Boot.Mode.Modes.Setup";
807491d8ee7SSantosh Puranik }
8089f16b2c1SJennifer Lee else if (rfSource == "Usb")
8099f16b2c1SJennifer Lee {
810944ffaf9SJohnathan Mantey bootSource =
811944ffaf9SJohnathan Mantey "xyz.openbmc_project.Control.Boot.Source.Sources.RemovableMedia";
8129f16b2c1SJennifer Lee }
813491d8ee7SSantosh Puranik else
814491d8ee7SSantosh Puranik {
81562598e31SEd Tanous BMCWEB_LOG_DEBUG(
81662598e31SEd Tanous "Invalid property value for BootSourceOverrideTarget: {}",
81762598e31SEd Tanous bootSource);
818ac106bf6SEd Tanous messages::propertyValueNotInList(asyncResp->res, rfSource,
819944ffaf9SJohnathan Mantey "BootSourceTargetOverride");
820944ffaf9SJohnathan Mantey return -1;
821491d8ee7SSantosh Puranik }
822944ffaf9SJohnathan Mantey return 0;
823491d8ee7SSantosh Puranik }
8241981771bSAli Ahmed
825978b8803SAndrew Geissler /**
826978b8803SAndrew Geissler * @brief Retrieves boot progress of the system
827978b8803SAndrew Geissler *
828ac106bf6SEd Tanous * @param[in] asyncResp Shared pointer for generating response message.
829978b8803SAndrew Geissler *
830978b8803SAndrew Geissler * @return None.
831978b8803SAndrew Geissler */
getBootProgress(const std::shared_ptr<bmcweb::AsyncResp> & asyncResp)832ac106bf6SEd Tanous inline void getBootProgress(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp)
833978b8803SAndrew Geissler {
834deae6a78SEd Tanous dbus::utility::getProperty<std::string>(
835deae6a78SEd Tanous "xyz.openbmc_project.State.Host", "/xyz/openbmc_project/state/host0",
8361e1e598dSJonathan Doman "xyz.openbmc_project.State.Boot.Progress", "BootProgress",
837ac106bf6SEd Tanous [asyncResp](const boost::system::error_code& ec,
8381e1e598dSJonathan Doman const std::string& bootProgressStr) {
839978b8803SAndrew Geissler if (ec)
840978b8803SAndrew Geissler {
841978b8803SAndrew Geissler // BootProgress is an optional object so just do nothing if
842978b8803SAndrew Geissler // not found
843978b8803SAndrew Geissler return;
844978b8803SAndrew Geissler }
845978b8803SAndrew Geissler
84662598e31SEd Tanous BMCWEB_LOG_DEBUG("Boot Progress: {}", bootProgressStr);
847978b8803SAndrew Geissler
848ac106bf6SEd Tanous asyncResp->res.jsonValue["BootProgress"]["LastState"] =
849e43914b3SAndrew Geissler dbusToRfBootProgress(bootProgressStr);
8501e1e598dSJonathan Doman });
851978b8803SAndrew Geissler }
852491d8ee7SSantosh Puranik
853491d8ee7SSantosh Puranik /**
854b6d5d45cSHieu Huynh * @brief Retrieves boot progress Last Update of the system
855b6d5d45cSHieu Huynh *
856ac106bf6SEd Tanous * @param[in] asyncResp Shared pointer for generating response message.
857b6d5d45cSHieu Huynh *
858b6d5d45cSHieu Huynh * @return None.
859b6d5d45cSHieu Huynh */
getBootProgressLastStateTime(const std::shared_ptr<bmcweb::AsyncResp> & asyncResp)860b6d5d45cSHieu Huynh inline void getBootProgressLastStateTime(
861ac106bf6SEd Tanous const std::shared_ptr<bmcweb::AsyncResp>& asyncResp)
862b6d5d45cSHieu Huynh {
863deae6a78SEd Tanous dbus::utility::getProperty<uint64_t>(
864deae6a78SEd Tanous "xyz.openbmc_project.State.Host", "/xyz/openbmc_project/state/host0",
865b6d5d45cSHieu Huynh "xyz.openbmc_project.State.Boot.Progress", "BootProgressLastUpdate",
866ac106bf6SEd Tanous [asyncResp](const boost::system::error_code& ec,
867b6d5d45cSHieu Huynh const uint64_t lastStateTime) {
868b6d5d45cSHieu Huynh if (ec)
869b6d5d45cSHieu Huynh {
87062598e31SEd Tanous BMCWEB_LOG_DEBUG("D-BUS response error {}", ec);
871b6d5d45cSHieu Huynh return;
872b6d5d45cSHieu Huynh }
873b6d5d45cSHieu Huynh
874b6d5d45cSHieu Huynh // BootProgressLastUpdate is the last time the BootProgress property
875b6d5d45cSHieu Huynh // was updated. The time is the Epoch time, number of microseconds
876b6d5d45cSHieu Huynh // since 1 Jan 1970 00::00::00 UTC."
877b6d5d45cSHieu Huynh // https://github.com/openbmc/phosphor-dbus-interfaces/blob/master/
878b6d5d45cSHieu Huynh // yaml/xyz/openbmc_project/State/Boot/Progress.interface.yaml#L11
879b6d5d45cSHieu Huynh
880b6d5d45cSHieu Huynh // Convert to ISO 8601 standard
881ac106bf6SEd Tanous asyncResp->res.jsonValue["BootProgress"]["LastStateTime"] =
882b6d5d45cSHieu Huynh redfish::time_utils::getDateTimeUintUs(lastStateTime);
883b6d5d45cSHieu Huynh });
884b6d5d45cSHieu Huynh }
885b6d5d45cSHieu Huynh
886b6d5d45cSHieu Huynh /**
887c21865c4SKonstantin Aladyshev * @brief Retrieves boot override type over DBUS and fills out the response
888cd9a4666SKonstantin Aladyshev *
889ac106bf6SEd Tanous * @param[in] asyncResp Shared pointer for generating response message.
890cd9a4666SKonstantin Aladyshev *
891cd9a4666SKonstantin Aladyshev * @return None.
892cd9a4666SKonstantin Aladyshev */
893cd9a4666SKonstantin Aladyshev
getBootOverrideType(const std::shared_ptr<bmcweb::AsyncResp> & asyncResp)894*504af5a0SPatrick Williams inline void getBootOverrideType(
895*504af5a0SPatrick Williams const std::shared_ptr<bmcweb::AsyncResp>& asyncResp)
896cd9a4666SKonstantin Aladyshev {
897deae6a78SEd Tanous dbus::utility::getProperty<std::string>(
898deae6a78SEd Tanous "xyz.openbmc_project.Settings",
8991e1e598dSJonathan Doman "/xyz/openbmc_project/control/host0/boot",
9001e1e598dSJonathan Doman "xyz.openbmc_project.Control.Boot.Type", "BootType",
901ac106bf6SEd Tanous [asyncResp](const boost::system::error_code& ec,
9021e1e598dSJonathan Doman const std::string& bootType) {
903cd9a4666SKonstantin Aladyshev if (ec)
904cd9a4666SKonstantin Aladyshev {
905cd9a4666SKonstantin Aladyshev // not an error, don't have to have the interface
906cd9a4666SKonstantin Aladyshev return;
907cd9a4666SKonstantin Aladyshev }
908cd9a4666SKonstantin Aladyshev
90962598e31SEd Tanous BMCWEB_LOG_DEBUG("Boot type: {}", bootType);
910cd9a4666SKonstantin Aladyshev
911ac106bf6SEd Tanous asyncResp->res
912ac106bf6SEd Tanous .jsonValue["Boot"]
913002d39b4SEd Tanous ["BootSourceOverrideMode@Redfish.AllowableValues"] =
914613dabeaSEd Tanous nlohmann::json::array_t({"Legacy", "UEFI"});
915cd9a4666SKonstantin Aladyshev
9161e1e598dSJonathan Doman auto rfType = dbusToRfBootType(bootType);
917cd9a4666SKonstantin Aladyshev if (rfType.empty())
918cd9a4666SKonstantin Aladyshev {
919ac106bf6SEd Tanous messages::internalError(asyncResp->res);
920cd9a4666SKonstantin Aladyshev return;
921cd9a4666SKonstantin Aladyshev }
922cd9a4666SKonstantin Aladyshev
923ac106bf6SEd Tanous asyncResp->res.jsonValue["Boot"]["BootSourceOverrideMode"] = rfType;
9241e1e598dSJonathan Doman });
925cd9a4666SKonstantin Aladyshev }
926cd9a4666SKonstantin Aladyshev
927cd9a4666SKonstantin Aladyshev /**
928c21865c4SKonstantin Aladyshev * @brief Retrieves boot override mode over DBUS and fills out the response
929491d8ee7SSantosh Puranik *
930ac106bf6SEd Tanous * @param[in] asyncResp Shared pointer for generating response message.
931491d8ee7SSantosh Puranik *
932491d8ee7SSantosh Puranik * @return None.
933491d8ee7SSantosh Puranik */
934c21865c4SKonstantin Aladyshev
getBootOverrideMode(const std::shared_ptr<bmcweb::AsyncResp> & asyncResp)935*504af5a0SPatrick Williams inline void getBootOverrideMode(
936*504af5a0SPatrick Williams const std::shared_ptr<bmcweb::AsyncResp>& asyncResp)
937491d8ee7SSantosh Puranik {
938deae6a78SEd Tanous dbus::utility::getProperty<std::string>(
939deae6a78SEd Tanous "xyz.openbmc_project.Settings",
9401e1e598dSJonathan Doman "/xyz/openbmc_project/control/host0/boot",
9411e1e598dSJonathan Doman "xyz.openbmc_project.Control.Boot.Mode", "BootMode",
942ac106bf6SEd Tanous [asyncResp](const boost::system::error_code& ec,
9431e1e598dSJonathan Doman const std::string& bootModeStr) {
944491d8ee7SSantosh Puranik if (ec)
945491d8ee7SSantosh Puranik {
946b3e86cb0SGunnar Mills BMCWEB_LOG_ERROR("DBUS response error {}", ec);
947ac106bf6SEd Tanous messages::internalError(asyncResp->res);
948491d8ee7SSantosh Puranik return;
949491d8ee7SSantosh Puranik }
950491d8ee7SSantosh Puranik
95162598e31SEd Tanous BMCWEB_LOG_DEBUG("Boot mode: {}", bootModeStr);
952491d8ee7SSantosh Puranik
95320fa6a2cSEd Tanous nlohmann::json::array_t allowed;
95420fa6a2cSEd Tanous allowed.emplace_back("None");
95520fa6a2cSEd Tanous allowed.emplace_back("Pxe");
95620fa6a2cSEd Tanous allowed.emplace_back("Hdd");
95720fa6a2cSEd Tanous allowed.emplace_back("Cd");
95820fa6a2cSEd Tanous allowed.emplace_back("Diags");
95920fa6a2cSEd Tanous allowed.emplace_back("BiosSetup");
96020fa6a2cSEd Tanous allowed.emplace_back("Usb");
96120fa6a2cSEd Tanous
962ac106bf6SEd Tanous asyncResp->res
9630fda0f12SGeorge Liu .jsonValue["Boot"]
96420fa6a2cSEd Tanous ["BootSourceOverrideTarget@Redfish.AllowableValues"] =
96520fa6a2cSEd Tanous std::move(allowed);
9661e1e598dSJonathan Doman if (bootModeStr !=
967491d8ee7SSantosh Puranik "xyz.openbmc_project.Control.Boot.Mode.Modes.Regular")
968491d8ee7SSantosh Puranik {
9691e1e598dSJonathan Doman auto rfMode = dbusToRfBootMode(bootModeStr);
970491d8ee7SSantosh Puranik if (!rfMode.empty())
971491d8ee7SSantosh Puranik {
972bd79bce8SPatrick Williams asyncResp->res
973bd79bce8SPatrick Williams .jsonValue["Boot"]["BootSourceOverrideTarget"] = rfMode;
974491d8ee7SSantosh Puranik }
975491d8ee7SSantosh Puranik }
9761e1e598dSJonathan Doman });
977491d8ee7SSantosh Puranik }
978491d8ee7SSantosh Puranik
979491d8ee7SSantosh Puranik /**
980c21865c4SKonstantin Aladyshev * @brief Retrieves boot override source over DBUS
981491d8ee7SSantosh Puranik *
982ac106bf6SEd Tanous * @param[in] asyncResp Shared pointer for generating response message.
983491d8ee7SSantosh Puranik *
984491d8ee7SSantosh Puranik * @return None.
985491d8ee7SSantosh Puranik */
986c21865c4SKonstantin Aladyshev
getBootOverrideSource(const std::shared_ptr<bmcweb::AsyncResp> & asyncResp)987*504af5a0SPatrick Williams inline void getBootOverrideSource(
988*504af5a0SPatrick Williams const std::shared_ptr<bmcweb::AsyncResp>& asyncResp)
989491d8ee7SSantosh Puranik {
990deae6a78SEd Tanous dbus::utility::getProperty<std::string>(
991deae6a78SEd Tanous "xyz.openbmc_project.Settings",
9921e1e598dSJonathan Doman "/xyz/openbmc_project/control/host0/boot",
9931e1e598dSJonathan Doman "xyz.openbmc_project.Control.Boot.Source", "BootSource",
994ac106bf6SEd Tanous [asyncResp](const boost::system::error_code& ec,
9951e1e598dSJonathan Doman const std::string& bootSourceStr) {
996491d8ee7SSantosh Puranik if (ec)
997491d8ee7SSantosh Puranik {
9985ef735c8SNan Zhou if (ec.value() == boost::asio::error::host_unreachable)
9995ef735c8SNan Zhou {
10005ef735c8SNan Zhou return;
10015ef735c8SNan Zhou }
1002b3e86cb0SGunnar Mills BMCWEB_LOG_ERROR("DBUS response error {}", ec);
1003ac106bf6SEd Tanous messages::internalError(asyncResp->res);
1004491d8ee7SSantosh Puranik return;
1005491d8ee7SSantosh Puranik }
1006491d8ee7SSantosh Puranik
100762598e31SEd Tanous BMCWEB_LOG_DEBUG("Boot source: {}", bootSourceStr);
1008491d8ee7SSantosh Puranik
10091e1e598dSJonathan Doman auto rfSource = dbusToRfBootSource(bootSourceStr);
1010491d8ee7SSantosh Puranik if (!rfSource.empty())
1011491d8ee7SSantosh Puranik {
1012ac106bf6SEd Tanous asyncResp->res.jsonValue["Boot"]["BootSourceOverrideTarget"] =
1013ac106bf6SEd Tanous rfSource;
1014491d8ee7SSantosh Puranik }
1015cd9a4666SKonstantin Aladyshev
1016cd9a4666SKonstantin Aladyshev // Get BootMode as BootSourceOverrideTarget is constructed
1017cd9a4666SKonstantin Aladyshev // from both BootSource and BootMode
1018ac106bf6SEd Tanous getBootOverrideMode(asyncResp);
10191e1e598dSJonathan Doman });
1020491d8ee7SSantosh Puranik }
1021491d8ee7SSantosh Puranik
1022491d8ee7SSantosh Puranik /**
1023c21865c4SKonstantin Aladyshev * @brief This functions abstracts all the logic behind getting a
1024c21865c4SKonstantin Aladyshev * "BootSourceOverrideEnabled" property from an overall boot override enable
1025c21865c4SKonstantin Aladyshev * state
1026491d8ee7SSantosh Puranik *
1027ac106bf6SEd Tanous * @param[in] asyncResp Shared pointer for generating response message.
1028491d8ee7SSantosh Puranik *
1029491d8ee7SSantosh Puranik * @return None.
1030491d8ee7SSantosh Puranik */
1031491d8ee7SSantosh Puranik
processBootOverrideEnable(const std::shared_ptr<bmcweb::AsyncResp> & asyncResp,const bool bootOverrideEnableSetting)1032ac106bf6SEd Tanous inline void processBootOverrideEnable(
1033ac106bf6SEd Tanous const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
1034c21865c4SKonstantin Aladyshev const bool bootOverrideEnableSetting)
1035c21865c4SKonstantin Aladyshev {
1036c21865c4SKonstantin Aladyshev if (!bootOverrideEnableSetting)
1037c21865c4SKonstantin Aladyshev {
1038ac106bf6SEd Tanous asyncResp->res.jsonValue["Boot"]["BootSourceOverrideEnabled"] =
1039ac106bf6SEd Tanous "Disabled";
1040c21865c4SKonstantin Aladyshev return;
1041c21865c4SKonstantin Aladyshev }
1042c21865c4SKonstantin Aladyshev
1043c21865c4SKonstantin Aladyshev // If boot source override is enabled, we need to check 'one_time'
1044c21865c4SKonstantin Aladyshev // property to set a correct value for the "BootSourceOverrideEnabled"
1045deae6a78SEd Tanous dbus::utility::getProperty<bool>(
1046deae6a78SEd Tanous "xyz.openbmc_project.Settings",
10471e1e598dSJonathan Doman "/xyz/openbmc_project/control/host0/boot/one_time",
10481e1e598dSJonathan Doman "xyz.openbmc_project.Object.Enable", "Enabled",
1049ac106bf6SEd Tanous [asyncResp](const boost::system::error_code& ec, bool oneTimeSetting) {
1050491d8ee7SSantosh Puranik if (ec)
1051491d8ee7SSantosh Puranik {
1052b3e86cb0SGunnar Mills BMCWEB_LOG_ERROR("DBUS response error {}", ec);
1053ac106bf6SEd Tanous messages::internalError(asyncResp->res);
1054491d8ee7SSantosh Puranik return;
1055491d8ee7SSantosh Puranik }
1056491d8ee7SSantosh Puranik
1057c21865c4SKonstantin Aladyshev if (oneTimeSetting)
1058c21865c4SKonstantin Aladyshev {
1059ac106bf6SEd Tanous asyncResp->res.jsonValue["Boot"]["BootSourceOverrideEnabled"] =
1060ac106bf6SEd Tanous "Once";
1061c21865c4SKonstantin Aladyshev }
1062c21865c4SKonstantin Aladyshev else
1063c21865c4SKonstantin Aladyshev {
1064ac106bf6SEd Tanous asyncResp->res.jsonValue["Boot"]["BootSourceOverrideEnabled"] =
1065c21865c4SKonstantin Aladyshev "Continuous";
1066c21865c4SKonstantin Aladyshev }
10671e1e598dSJonathan Doman });
1068491d8ee7SSantosh Puranik }
1069491d8ee7SSantosh Puranik
1070491d8ee7SSantosh Puranik /**
1071c21865c4SKonstantin Aladyshev * @brief Retrieves boot override enable over DBUS
1072c21865c4SKonstantin Aladyshev *
1073ac106bf6SEd Tanous * @param[in] asyncResp Shared pointer for generating response message.
1074c21865c4SKonstantin Aladyshev *
1075c21865c4SKonstantin Aladyshev * @return None.
1076c21865c4SKonstantin Aladyshev */
1077c21865c4SKonstantin Aladyshev
getBootOverrideEnable(const std::shared_ptr<bmcweb::AsyncResp> & asyncResp)1078*504af5a0SPatrick Williams inline void getBootOverrideEnable(
1079*504af5a0SPatrick Williams const std::shared_ptr<bmcweb::AsyncResp>& asyncResp)
1080c21865c4SKonstantin Aladyshev {
1081deae6a78SEd Tanous dbus::utility::getProperty<bool>(
1082deae6a78SEd Tanous "xyz.openbmc_project.Settings",
10831e1e598dSJonathan Doman "/xyz/openbmc_project/control/host0/boot",
10841e1e598dSJonathan Doman "xyz.openbmc_project.Object.Enable", "Enabled",
1085ac106bf6SEd Tanous [asyncResp](const boost::system::error_code& ec,
10861e1e598dSJonathan Doman const bool bootOverrideEnable) {
1087c21865c4SKonstantin Aladyshev if (ec)
1088c21865c4SKonstantin Aladyshev {
10895ef735c8SNan Zhou if (ec.value() == boost::asio::error::host_unreachable)
10905ef735c8SNan Zhou {
10915ef735c8SNan Zhou return;
10925ef735c8SNan Zhou }
1093b3e86cb0SGunnar Mills BMCWEB_LOG_ERROR("DBUS response error {}", ec);
1094ac106bf6SEd Tanous messages::internalError(asyncResp->res);
1095c21865c4SKonstantin Aladyshev return;
1096c21865c4SKonstantin Aladyshev }
1097c21865c4SKonstantin Aladyshev
1098ac106bf6SEd Tanous processBootOverrideEnable(asyncResp, bootOverrideEnable);
10991e1e598dSJonathan Doman });
1100c21865c4SKonstantin Aladyshev }
1101c21865c4SKonstantin Aladyshev
1102c21865c4SKonstantin Aladyshev /**
1103c21865c4SKonstantin Aladyshev * @brief Retrieves boot source override properties
1104c21865c4SKonstantin Aladyshev *
1105ac106bf6SEd Tanous * @param[in] asyncResp Shared pointer for generating response message.
1106c21865c4SKonstantin Aladyshev *
1107c21865c4SKonstantin Aladyshev * @return None.
1108c21865c4SKonstantin Aladyshev */
getBootProperties(const std::shared_ptr<bmcweb::AsyncResp> & asyncResp)1109*504af5a0SPatrick Williams inline void getBootProperties(
1110*504af5a0SPatrick Williams const std::shared_ptr<bmcweb::AsyncResp>& asyncResp)
1111c21865c4SKonstantin Aladyshev {
111262598e31SEd Tanous BMCWEB_LOG_DEBUG("Get boot information.");
1113c21865c4SKonstantin Aladyshev
1114ac106bf6SEd Tanous getBootOverrideSource(asyncResp);
1115ac106bf6SEd Tanous getBootOverrideType(asyncResp);
1116ac106bf6SEd Tanous getBootOverrideEnable(asyncResp);
1117c21865c4SKonstantin Aladyshev }
1118c21865c4SKonstantin Aladyshev
1119c21865c4SKonstantin Aladyshev /**
1120c0557e1aSGunnar Mills * @brief Retrieves the Last Reset Time
1121c0557e1aSGunnar Mills *
1122c0557e1aSGunnar Mills * "Reset" is an overloaded term in Redfish, "Reset" includes power on
1123c0557e1aSGunnar Mills * and power off. Even though this is the "system" Redfish object look at the
1124c0557e1aSGunnar Mills * chassis D-Bus interface for the LastStateChangeTime since this has the
1125c0557e1aSGunnar Mills * last power operation time.
1126c0557e1aSGunnar Mills *
1127ac106bf6SEd Tanous * @param[in] asyncResp Shared pointer for generating response message.
1128c0557e1aSGunnar Mills *
1129c0557e1aSGunnar Mills * @return None.
1130c0557e1aSGunnar Mills */
getLastResetTime(const std::shared_ptr<bmcweb::AsyncResp> & asyncResp)1131*504af5a0SPatrick Williams inline void getLastResetTime(
1132*504af5a0SPatrick Williams const std::shared_ptr<bmcweb::AsyncResp>& asyncResp)
1133c0557e1aSGunnar Mills {
113462598e31SEd Tanous BMCWEB_LOG_DEBUG("Getting System Last Reset Time");
1135c0557e1aSGunnar Mills
1136deae6a78SEd Tanous dbus::utility::getProperty<uint64_t>(
1137deae6a78SEd Tanous "xyz.openbmc_project.State.Chassis",
11381e1e598dSJonathan Doman "/xyz/openbmc_project/state/chassis0",
11391e1e598dSJonathan Doman "xyz.openbmc_project.State.Chassis", "LastStateChangeTime",
1140ac106bf6SEd Tanous [asyncResp](const boost::system::error_code& ec,
1141ac106bf6SEd Tanous uint64_t lastResetTime) {
1142c0557e1aSGunnar Mills if (ec)
1143c0557e1aSGunnar Mills {
114462598e31SEd Tanous BMCWEB_LOG_DEBUG("D-BUS response error {}", ec);
1145c0557e1aSGunnar Mills return;
1146c0557e1aSGunnar Mills }
1147c0557e1aSGunnar Mills
1148c0557e1aSGunnar Mills // LastStateChangeTime is epoch time, in milliseconds
1149c0557e1aSGunnar Mills // https://github.com/openbmc/phosphor-dbus-interfaces/blob/33e8e1dd64da53a66e888d33dc82001305cd0bf9/xyz/openbmc_project/State/Chassis.interface.yaml#L19
11501e1e598dSJonathan Doman uint64_t lastResetTimeStamp = lastResetTime / 1000;
1151c0557e1aSGunnar Mills
1152c0557e1aSGunnar Mills // Convert to ISO 8601 standard
1153ac106bf6SEd Tanous asyncResp->res.jsonValue["LastResetTime"] =
11542b82937eSEd Tanous redfish::time_utils::getDateTimeUint(lastResetTimeStamp);
11551e1e598dSJonathan Doman });
1156c0557e1aSGunnar Mills }
1157c0557e1aSGunnar Mills
1158c0557e1aSGunnar Mills /**
1159797d5daeSCorey Hardesty * @brief Retrieves the number of automatic boot Retry attempts allowed/left.
1160797d5daeSCorey Hardesty *
1161797d5daeSCorey Hardesty * The total number of automatic reboot retries allowed "RetryAttempts" and its
1162797d5daeSCorey Hardesty * corresponding property "AttemptsLeft" that keeps track of the amount of
1163797d5daeSCorey Hardesty * automatic retry attempts left are hosted in phosphor-state-manager through
1164797d5daeSCorey Hardesty * dbus.
1165797d5daeSCorey Hardesty *
1166ac106bf6SEd Tanous * @param[in] asyncResp Shared pointer for generating response message.
1167797d5daeSCorey Hardesty *
1168797d5daeSCorey Hardesty * @return None.
1169797d5daeSCorey Hardesty */
getAutomaticRebootAttempts(const std::shared_ptr<bmcweb::AsyncResp> & asyncResp)1170ac106bf6SEd Tanous inline void getAutomaticRebootAttempts(
1171ac106bf6SEd Tanous const std::shared_ptr<bmcweb::AsyncResp>& asyncResp)
1172797d5daeSCorey Hardesty {
117362598e31SEd Tanous BMCWEB_LOG_DEBUG("Get Automatic Retry policy");
1174797d5daeSCorey Hardesty
1175deae6a78SEd Tanous dbus::utility::getAllProperties(
1176deae6a78SEd Tanous "xyz.openbmc_project.State.Host", "/xyz/openbmc_project/state/host0",
1177797d5daeSCorey Hardesty "xyz.openbmc_project.Control.Boot.RebootAttempts",
1178ac106bf6SEd Tanous [asyncResp{asyncResp}](
1179ac106bf6SEd Tanous const boost::system::error_code& ec,
1180797d5daeSCorey Hardesty const dbus::utility::DBusPropertiesMap& propertiesList) {
1181797d5daeSCorey Hardesty if (ec)
1182797d5daeSCorey Hardesty {
1183797d5daeSCorey Hardesty if (ec.value() != EBADR)
1184797d5daeSCorey Hardesty {
118562598e31SEd Tanous BMCWEB_LOG_ERROR("D-Bus responses error: {}", ec);
1186ac106bf6SEd Tanous messages::internalError(asyncResp->res);
1187797d5daeSCorey Hardesty }
1188797d5daeSCorey Hardesty return;
1189797d5daeSCorey Hardesty }
1190797d5daeSCorey Hardesty
1191797d5daeSCorey Hardesty const uint32_t* attemptsLeft = nullptr;
1192797d5daeSCorey Hardesty const uint32_t* retryAttempts = nullptr;
1193797d5daeSCorey Hardesty
1194797d5daeSCorey Hardesty const bool success = sdbusplus::unpackPropertiesNoThrow(
1195bd79bce8SPatrick Williams dbus_utils::UnpackErrorPrinter(), propertiesList,
1196bd79bce8SPatrick Williams "AttemptsLeft", attemptsLeft, "RetryAttempts", retryAttempts);
1197797d5daeSCorey Hardesty
1198797d5daeSCorey Hardesty if (!success)
1199797d5daeSCorey Hardesty {
1200ac106bf6SEd Tanous messages::internalError(asyncResp->res);
1201797d5daeSCorey Hardesty return;
1202797d5daeSCorey Hardesty }
1203797d5daeSCorey Hardesty
1204797d5daeSCorey Hardesty if (attemptsLeft != nullptr)
1205797d5daeSCorey Hardesty {
1206ac106bf6SEd Tanous asyncResp->res
1207ac106bf6SEd Tanous .jsonValue["Boot"]["RemainingAutomaticRetryAttempts"] =
1208797d5daeSCorey Hardesty *attemptsLeft;
1209797d5daeSCorey Hardesty }
1210797d5daeSCorey Hardesty
1211797d5daeSCorey Hardesty if (retryAttempts != nullptr)
1212797d5daeSCorey Hardesty {
1213ac106bf6SEd Tanous asyncResp->res.jsonValue["Boot"]["AutomaticRetryAttempts"] =
1214797d5daeSCorey Hardesty *retryAttempts;
1215797d5daeSCorey Hardesty }
1216797d5daeSCorey Hardesty });
1217797d5daeSCorey Hardesty }
1218797d5daeSCorey Hardesty
1219797d5daeSCorey Hardesty /**
12206bd5a8d2SGunnar Mills * @brief Retrieves Automatic Retry properties. Known on D-Bus as AutoReboot.
12216bd5a8d2SGunnar Mills *
1222ac106bf6SEd Tanous * @param[in] asyncResp Shared pointer for generating response message.
12236bd5a8d2SGunnar Mills *
12246bd5a8d2SGunnar Mills * @return None.
12256bd5a8d2SGunnar Mills */
getAutomaticRetryPolicy(const std::shared_ptr<bmcweb::AsyncResp> & asyncResp)1226*504af5a0SPatrick Williams inline void getAutomaticRetryPolicy(
1227*504af5a0SPatrick Williams const std::shared_ptr<bmcweb::AsyncResp>& asyncResp)
12286bd5a8d2SGunnar Mills {
122962598e31SEd Tanous BMCWEB_LOG_DEBUG("Get Automatic Retry policy");
12306bd5a8d2SGunnar Mills
1231deae6a78SEd Tanous dbus::utility::getProperty<bool>(
1232deae6a78SEd Tanous "xyz.openbmc_project.Settings",
12331e1e598dSJonathan Doman "/xyz/openbmc_project/control/host0/auto_reboot",
12341e1e598dSJonathan Doman "xyz.openbmc_project.Control.Boot.RebootPolicy", "AutoReboot",
1235ac106bf6SEd Tanous [asyncResp](const boost::system::error_code& ec,
1236ac106bf6SEd Tanous bool autoRebootEnabled) {
12376bd5a8d2SGunnar Mills if (ec)
12386bd5a8d2SGunnar Mills {
1239797d5daeSCorey Hardesty if (ec.value() != EBADR)
1240797d5daeSCorey Hardesty {
124162598e31SEd Tanous BMCWEB_LOG_ERROR("D-Bus responses error: {}", ec);
1242ac106bf6SEd Tanous messages::internalError(asyncResp->res);
1243797d5daeSCorey Hardesty }
12446bd5a8d2SGunnar Mills return;
12456bd5a8d2SGunnar Mills }
12466bd5a8d2SGunnar Mills
124762598e31SEd Tanous BMCWEB_LOG_DEBUG("Auto Reboot: {}", autoRebootEnabled);
1248e05aec50SEd Tanous if (autoRebootEnabled)
12496bd5a8d2SGunnar Mills {
1250ac106bf6SEd Tanous asyncResp->res.jsonValue["Boot"]["AutomaticRetryConfig"] =
12516bd5a8d2SGunnar Mills "RetryAttempts";
12526bd5a8d2SGunnar Mills }
12536bd5a8d2SGunnar Mills else
12546bd5a8d2SGunnar Mills {
1255ac106bf6SEd Tanous asyncResp->res.jsonValue["Boot"]["AutomaticRetryConfig"] =
1256ac106bf6SEd Tanous "Disabled";
12576bd5a8d2SGunnar Mills }
1258ac106bf6SEd Tanous getAutomaticRebootAttempts(asyncResp);
125969f35306SGunnar Mills
126069f35306SGunnar Mills // "AutomaticRetryConfig" can be 3 values, Disabled, RetryAlways,
126169f35306SGunnar Mills // and RetryAttempts. OpenBMC only supports Disabled and
126269f35306SGunnar Mills // RetryAttempts.
126320fa6a2cSEd Tanous nlohmann::json::array_t allowed;
126420fa6a2cSEd Tanous allowed.emplace_back("Disabled");
126520fa6a2cSEd Tanous allowed.emplace_back("RetryAttempts");
1266ac106bf6SEd Tanous asyncResp->res
1267bd79bce8SPatrick Williams .jsonValue["Boot"]
1268bd79bce8SPatrick Williams ["AutomaticRetryConfig@Redfish.AllowableValues"] =
126920fa6a2cSEd Tanous std::move(allowed);
12701e1e598dSJonathan Doman });
12716bd5a8d2SGunnar Mills }
12726bd5a8d2SGunnar Mills
12736bd5a8d2SGunnar Mills /**
1274797d5daeSCorey Hardesty * @brief Sets RetryAttempts
1275797d5daeSCorey Hardesty *
1276ac106bf6SEd Tanous * @param[in] asyncResp Shared pointer for generating response message.
1277797d5daeSCorey Hardesty * @param[in] retryAttempts "AutomaticRetryAttempts" from request.
1278797d5daeSCorey Hardesty *
1279797d5daeSCorey Hardesty *@return None.
1280797d5daeSCorey Hardesty */
1281797d5daeSCorey Hardesty
setAutomaticRetryAttempts(const std::shared_ptr<bmcweb::AsyncResp> & asyncResp,const uint32_t retryAttempts)1282ac106bf6SEd Tanous inline void setAutomaticRetryAttempts(
1283ac106bf6SEd Tanous const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
1284797d5daeSCorey Hardesty const uint32_t retryAttempts)
1285797d5daeSCorey Hardesty {
128662598e31SEd Tanous BMCWEB_LOG_DEBUG("Set Automatic Retry Attempts.");
128787c44966SAsmitha Karunanithi setDbusProperty(
1288e93abac6SGinu George asyncResp, "Boot/AutomaticRetryAttempts",
1289e93abac6SGinu George "xyz.openbmc_project.State.Host",
129087c44966SAsmitha Karunanithi sdbusplus::message::object_path("/xyz/openbmc_project/state/host0"),
12919ae226faSGeorge Liu "xyz.openbmc_project.Control.Boot.RebootAttempts", "RetryAttempts",
1292e93abac6SGinu George retryAttempts);
1293797d5daeSCorey Hardesty }
1294797d5daeSCorey Hardesty
12958d69c668SEd Tanous inline computer_system::PowerRestorePolicyTypes
redfishPowerRestorePolicyFromDbus(std::string_view value)12968d69c668SEd Tanous redfishPowerRestorePolicyFromDbus(std::string_view value)
12978d69c668SEd Tanous {
12988d69c668SEd Tanous if (value ==
12998d69c668SEd Tanous "xyz.openbmc_project.Control.Power.RestorePolicy.Policy.AlwaysOn")
13008d69c668SEd Tanous {
13018d69c668SEd Tanous return computer_system::PowerRestorePolicyTypes::AlwaysOn;
13028d69c668SEd Tanous }
13038d69c668SEd Tanous if (value ==
13048d69c668SEd Tanous "xyz.openbmc_project.Control.Power.RestorePolicy.Policy.AlwaysOff")
13058d69c668SEd Tanous {
13068d69c668SEd Tanous return computer_system::PowerRestorePolicyTypes::AlwaysOff;
13078d69c668SEd Tanous }
13088d69c668SEd Tanous if (value ==
13093a34b742SGunnar Mills "xyz.openbmc_project.Control.Power.RestorePolicy.Policy.Restore")
13108d69c668SEd Tanous {
13118d69c668SEd Tanous return computer_system::PowerRestorePolicyTypes::LastState;
13128d69c668SEd Tanous }
13138d69c668SEd Tanous if (value == "xyz.openbmc_project.Control.Power.RestorePolicy.Policy.None")
13148d69c668SEd Tanous {
13158d69c668SEd Tanous return computer_system::PowerRestorePolicyTypes::AlwaysOff;
13168d69c668SEd Tanous }
13178d69c668SEd Tanous return computer_system::PowerRestorePolicyTypes::Invalid;
13188d69c668SEd Tanous }
1319797d5daeSCorey Hardesty /**
1320c6a620f2SGeorge Liu * @brief Retrieves power restore policy over DBUS.
1321c6a620f2SGeorge Liu *
1322ac106bf6SEd Tanous * @param[in] asyncResp Shared pointer for generating response message.
1323c6a620f2SGeorge Liu *
1324c6a620f2SGeorge Liu * @return None.
1325c6a620f2SGeorge Liu */
getPowerRestorePolicy(const std::shared_ptr<bmcweb::AsyncResp> & asyncResp)1326*504af5a0SPatrick Williams inline void getPowerRestorePolicy(
1327*504af5a0SPatrick Williams const std::shared_ptr<bmcweb::AsyncResp>& asyncResp)
1328c6a620f2SGeorge Liu {
132962598e31SEd Tanous BMCWEB_LOG_DEBUG("Get power restore policy");
1330c6a620f2SGeorge Liu
1331deae6a78SEd Tanous dbus::utility::getProperty<std::string>(
1332deae6a78SEd Tanous "xyz.openbmc_project.Settings",
13331e1e598dSJonathan Doman "/xyz/openbmc_project/control/host0/power_restore_policy",
13341e1e598dSJonathan Doman "xyz.openbmc_project.Control.Power.RestorePolicy", "PowerRestorePolicy",
1335ac106bf6SEd Tanous [asyncResp](const boost::system::error_code& ec,
13365e7e2dc5SEd Tanous const std::string& policy) {
1337c6a620f2SGeorge Liu if (ec)
1338c6a620f2SGeorge Liu {
133962598e31SEd Tanous BMCWEB_LOG_DEBUG("DBUS response error {}", ec);
1340c6a620f2SGeorge Liu return;
1341c6a620f2SGeorge Liu }
13428d69c668SEd Tanous computer_system::PowerRestorePolicyTypes restore =
13438d69c668SEd Tanous redfishPowerRestorePolicyFromDbus(policy);
13448d69c668SEd Tanous if (restore == computer_system::PowerRestorePolicyTypes::Invalid)
1345c6a620f2SGeorge Liu {
1346ac106bf6SEd Tanous messages::internalError(asyncResp->res);
1347c6a620f2SGeorge Liu return;
1348c6a620f2SGeorge Liu }
1349c6a620f2SGeorge Liu
13508d69c668SEd Tanous asyncResp->res.jsonValue["PowerRestorePolicy"] = restore;
13511e1e598dSJonathan Doman });
1352c6a620f2SGeorge Liu }
1353c6a620f2SGeorge Liu
1354c6a620f2SGeorge Liu /**
13559dcfe8c1SAlbert Zhang * @brief Stop Boot On Fault over DBUS.
13569dcfe8c1SAlbert Zhang *
13579dcfe8c1SAlbert Zhang * @param[in] asyncResp Shared pointer for generating response message.
13589dcfe8c1SAlbert Zhang *
13599dcfe8c1SAlbert Zhang * @return None.
13609dcfe8c1SAlbert Zhang */
getStopBootOnFault(const std::shared_ptr<bmcweb::AsyncResp> & asyncResp)1361*504af5a0SPatrick Williams inline void getStopBootOnFault(
1362*504af5a0SPatrick Williams const std::shared_ptr<bmcweb::AsyncResp>& asyncResp)
13639dcfe8c1SAlbert Zhang {
136462598e31SEd Tanous BMCWEB_LOG_DEBUG("Get Stop Boot On Fault");
13659dcfe8c1SAlbert Zhang
1366deae6a78SEd Tanous dbus::utility::getProperty<bool>(
1367deae6a78SEd Tanous "xyz.openbmc_project.Settings", "/xyz/openbmc_project/logging/settings",
13689dcfe8c1SAlbert Zhang "xyz.openbmc_project.Logging.Settings", "QuiesceOnHwError",
13699dcfe8c1SAlbert Zhang [asyncResp](const boost::system::error_code& ec, bool value) {
13709dcfe8c1SAlbert Zhang if (ec)
13719dcfe8c1SAlbert Zhang {
13729dcfe8c1SAlbert Zhang if (ec.value() != EBADR)
13739dcfe8c1SAlbert Zhang {
1374b3e86cb0SGunnar Mills BMCWEB_LOG_ERROR("DBUS response error {}", ec);
13759dcfe8c1SAlbert Zhang messages::internalError(asyncResp->res);
13769dcfe8c1SAlbert Zhang }
13779dcfe8c1SAlbert Zhang return;
13789dcfe8c1SAlbert Zhang }
13799dcfe8c1SAlbert Zhang
13809dcfe8c1SAlbert Zhang if (value)
13819dcfe8c1SAlbert Zhang {
1382539d8c6bSEd Tanous asyncResp->res.jsonValue["Boot"]["StopBootOnFault"] =
1383539d8c6bSEd Tanous computer_system::StopBootOnFault::AnyFault;
13849dcfe8c1SAlbert Zhang }
13859dcfe8c1SAlbert Zhang else
13869dcfe8c1SAlbert Zhang {
1387539d8c6bSEd Tanous asyncResp->res.jsonValue["Boot"]["StopBootOnFault"] =
1388539d8c6bSEd Tanous computer_system::StopBootOnFault::Never;
13899dcfe8c1SAlbert Zhang }
13909dcfe8c1SAlbert Zhang });
13919dcfe8c1SAlbert Zhang }
13929dcfe8c1SAlbert Zhang
13939dcfe8c1SAlbert Zhang /**
13941981771bSAli Ahmed * @brief Get TrustedModuleRequiredToBoot property. Determines whether or not
13951981771bSAli Ahmed * TPM is required for booting the host.
13961981771bSAli Ahmed *
1397ac106bf6SEd Tanous * @param[in] asyncResp Shared pointer for generating response message.
13981981771bSAli Ahmed *
13991981771bSAli Ahmed * @return None.
14001981771bSAli Ahmed */
getTrustedModuleRequiredToBoot(const std::shared_ptr<bmcweb::AsyncResp> & asyncResp)14011981771bSAli Ahmed inline void getTrustedModuleRequiredToBoot(
1402ac106bf6SEd Tanous const std::shared_ptr<bmcweb::AsyncResp>& asyncResp)
14031981771bSAli Ahmed {
140462598e31SEd Tanous BMCWEB_LOG_DEBUG("Get TPM required to boot.");
1405e99073f5SGeorge Liu constexpr std::array<std::string_view, 1> interfaces = {
1406e99073f5SGeorge Liu "xyz.openbmc_project.Control.TPM.Policy"};
1407e99073f5SGeorge Liu dbus::utility::getSubTree(
1408e99073f5SGeorge Liu "/", 0, interfaces,
1409ac106bf6SEd Tanous [asyncResp](const boost::system::error_code& ec,
1410b9d36b47SEd Tanous const dbus::utility::MapperGetSubTreeResponse& subtree) {
14111981771bSAli Ahmed if (ec)
14121981771bSAli Ahmed {
1413bd79bce8SPatrick Williams BMCWEB_LOG_DEBUG(
1414bd79bce8SPatrick Williams "DBUS response error on TPM.Policy GetSubTree{}", ec);
14151981771bSAli Ahmed // This is an optional D-Bus object so just return if
14161981771bSAli Ahmed // error occurs
14171981771bSAli Ahmed return;
14181981771bSAli Ahmed }
141926f6976fSEd Tanous if (subtree.empty())
14201981771bSAli Ahmed {
14211981771bSAli Ahmed // As noted above, this is an optional interface so just return
14221981771bSAli Ahmed // if there is no instance found
14231981771bSAli Ahmed return;
14241981771bSAli Ahmed }
14251981771bSAli Ahmed
14261981771bSAli Ahmed /* When there is more than one TPMEnable object... */
14271981771bSAli Ahmed if (subtree.size() > 1)
14281981771bSAli Ahmed {
142962598e31SEd Tanous BMCWEB_LOG_DEBUG(
143062598e31SEd Tanous "DBUS response has more than 1 TPM Enable object:{}",
143162598e31SEd Tanous subtree.size());
14321981771bSAli Ahmed // Throw an internal Error and return
1433ac106bf6SEd Tanous messages::internalError(asyncResp->res);
14341981771bSAli Ahmed return;
14351981771bSAli Ahmed }
14361981771bSAli Ahmed
14371981771bSAli Ahmed // Make sure the Dbus response map has a service and objectPath
14381981771bSAli Ahmed // field
14391981771bSAli Ahmed if (subtree[0].first.empty() || subtree[0].second.size() != 1)
14401981771bSAli Ahmed {
144162598e31SEd Tanous BMCWEB_LOG_DEBUG("TPM.Policy mapper error!");
1442ac106bf6SEd Tanous messages::internalError(asyncResp->res);
14431981771bSAli Ahmed return;
14441981771bSAli Ahmed }
14451981771bSAli Ahmed
14461981771bSAli Ahmed const std::string& path = subtree[0].first;
14471981771bSAli Ahmed const std::string& serv = subtree[0].second.begin()->first;
14481981771bSAli Ahmed
14491981771bSAli Ahmed // Valid TPM Enable object found, now reading the current value
1450deae6a78SEd Tanous dbus::utility::getProperty<bool>(
1451deae6a78SEd Tanous serv, path, "xyz.openbmc_project.Control.TPM.Policy",
1452deae6a78SEd Tanous "TPMEnable",
1453ac106bf6SEd Tanous [asyncResp](const boost::system::error_code& ec2,
1454ac106bf6SEd Tanous bool tpmRequired) {
14558a592810SEd Tanous if (ec2)
14561981771bSAli Ahmed {
1457bd79bce8SPatrick Williams BMCWEB_LOG_ERROR(
1458bd79bce8SPatrick Williams "D-BUS response error on TPM.Policy Get{}", ec2);
1459ac106bf6SEd Tanous messages::internalError(asyncResp->res);
14601981771bSAli Ahmed return;
14611981771bSAli Ahmed }
14621981771bSAli Ahmed
14631e1e598dSJonathan Doman if (tpmRequired)
14641981771bSAli Ahmed {
1465ac106bf6SEd Tanous asyncResp->res
1466ac106bf6SEd Tanous .jsonValue["Boot"]["TrustedModuleRequiredToBoot"] =
14671981771bSAli Ahmed "Required";
14681981771bSAli Ahmed }
14691981771bSAli Ahmed else
14701981771bSAli Ahmed {
1471ac106bf6SEd Tanous asyncResp->res
1472ac106bf6SEd Tanous .jsonValue["Boot"]["TrustedModuleRequiredToBoot"] =
14731981771bSAli Ahmed "Disabled";
14741981771bSAli Ahmed }
14751e1e598dSJonathan Doman });
1476e99073f5SGeorge Liu });
14771981771bSAli Ahmed }
14781981771bSAli Ahmed
14791981771bSAli Ahmed /**
14801c05dae3SAli Ahmed * @brief Set TrustedModuleRequiredToBoot property. Determines whether or not
14811c05dae3SAli Ahmed * TPM is required for booting the host.
14821c05dae3SAli Ahmed *
1483ac106bf6SEd Tanous * @param[in] asyncResp Shared pointer for generating response message.
14841c05dae3SAli Ahmed * @param[in] tpmRequired Value to set TPM Required To Boot property to.
14851c05dae3SAli Ahmed *
14861c05dae3SAli Ahmed * @return None.
14871c05dae3SAli Ahmed */
setTrustedModuleRequiredToBoot(const std::shared_ptr<bmcweb::AsyncResp> & asyncResp,const bool tpmRequired)14881c05dae3SAli Ahmed inline void setTrustedModuleRequiredToBoot(
1489ac106bf6SEd Tanous const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, const bool tpmRequired)
14901c05dae3SAli Ahmed {
149162598e31SEd Tanous BMCWEB_LOG_DEBUG("Set TrustedModuleRequiredToBoot.");
1492e99073f5SGeorge Liu constexpr std::array<std::string_view, 1> interfaces = {
1493e99073f5SGeorge Liu "xyz.openbmc_project.Control.TPM.Policy"};
1494e99073f5SGeorge Liu dbus::utility::getSubTree(
1495e99073f5SGeorge Liu "/", 0, interfaces,
1496ac106bf6SEd Tanous [asyncResp,
1497e99073f5SGeorge Liu tpmRequired](const boost::system::error_code& ec,
1498e99073f5SGeorge Liu const dbus::utility::MapperGetSubTreeResponse& subtree) {
14991c05dae3SAli Ahmed if (ec)
15001c05dae3SAli Ahmed {
1501bd79bce8SPatrick Williams BMCWEB_LOG_ERROR(
1502bd79bce8SPatrick Williams "DBUS response error on TPM.Policy GetSubTree{}", ec);
1503ac106bf6SEd Tanous messages::internalError(asyncResp->res);
15041c05dae3SAli Ahmed return;
15051c05dae3SAli Ahmed }
150626f6976fSEd Tanous if (subtree.empty())
15071c05dae3SAli Ahmed {
1508bd79bce8SPatrick Williams messages::propertyValueNotInList(asyncResp->res,
1509bd79bce8SPatrick Williams "ComputerSystem",
15101c05dae3SAli Ahmed "TrustedModuleRequiredToBoot");
15111c05dae3SAli Ahmed return;
15121c05dae3SAli Ahmed }
15131c05dae3SAli Ahmed
15141c05dae3SAli Ahmed /* When there is more than one TPMEnable object... */
15151c05dae3SAli Ahmed if (subtree.size() > 1)
15161c05dae3SAli Ahmed {
151762598e31SEd Tanous BMCWEB_LOG_DEBUG(
151862598e31SEd Tanous "DBUS response has more than 1 TPM Enable object:{}",
151962598e31SEd Tanous subtree.size());
15201c05dae3SAli Ahmed // Throw an internal Error and return
1521ac106bf6SEd Tanous messages::internalError(asyncResp->res);
15221c05dae3SAli Ahmed return;
15231c05dae3SAli Ahmed }
15241c05dae3SAli Ahmed
15251c05dae3SAli Ahmed // Make sure the Dbus response map has a service and objectPath
15261c05dae3SAli Ahmed // field
15271c05dae3SAli Ahmed if (subtree[0].first.empty() || subtree[0].second.size() != 1)
15281c05dae3SAli Ahmed {
152962598e31SEd Tanous BMCWEB_LOG_DEBUG("TPM.Policy mapper error!");
1530ac106bf6SEd Tanous messages::internalError(asyncResp->res);
15311c05dae3SAli Ahmed return;
15321c05dae3SAli Ahmed }
15331c05dae3SAli Ahmed
15341c05dae3SAli Ahmed const std::string& path = subtree[0].first;
15351c05dae3SAli Ahmed const std::string& serv = subtree[0].second.begin()->first;
15361c05dae3SAli Ahmed
15371c05dae3SAli Ahmed if (serv.empty())
15381c05dae3SAli Ahmed {
153962598e31SEd Tanous BMCWEB_LOG_DEBUG("TPM.Policy service mapper error!");
1540ac106bf6SEd Tanous messages::internalError(asyncResp->res);
15411c05dae3SAli Ahmed return;
15421c05dae3SAli Ahmed }
15431c05dae3SAli Ahmed
15441c05dae3SAli Ahmed // Valid TPM Enable object found, now setting the value
1545e93abac6SGinu George setDbusProperty(asyncResp, "Boot/TrustedModuleRequiredToBoot", serv,
1546e93abac6SGinu George path, "xyz.openbmc_project.Control.TPM.Policy",
1547e93abac6SGinu George "TPMEnable", tpmRequired);
1548e99073f5SGeorge Liu });
15491c05dae3SAli Ahmed }
15501c05dae3SAli Ahmed
15511c05dae3SAli Ahmed /**
1552491d8ee7SSantosh Puranik * @brief Sets boot properties into DBUS object(s).
1553491d8ee7SSantosh Puranik *
1554ac106bf6SEd Tanous * @param[in] asyncResp Shared pointer for generating response message.
1555cd9a4666SKonstantin Aladyshev * @param[in] bootType The boot type to set.
1556cd9a4666SKonstantin Aladyshev * @return Integer error code.
1557cd9a4666SKonstantin Aladyshev */
setBootType(const std::shared_ptr<bmcweb::AsyncResp> & asyncResp,const std::optional<std::string> & bootType)1558ac106bf6SEd Tanous inline void setBootType(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
1559cd9a4666SKonstantin Aladyshev const std::optional<std::string>& bootType)
1560cd9a4666SKonstantin Aladyshev {
1561c21865c4SKonstantin Aladyshev std::string bootTypeStr;
1562cd9a4666SKonstantin Aladyshev
1563c21865c4SKonstantin Aladyshev if (!bootType)
1564cd9a4666SKonstantin Aladyshev {
1565c21865c4SKonstantin Aladyshev return;
1566c21865c4SKonstantin Aladyshev }
1567c21865c4SKonstantin Aladyshev
1568cd9a4666SKonstantin Aladyshev // Source target specified
156962598e31SEd Tanous BMCWEB_LOG_DEBUG("Boot type: {}", *bootType);
1570cd9a4666SKonstantin Aladyshev // Figure out which DBUS interface and property to use
1571cd9a4666SKonstantin Aladyshev if (*bootType == "Legacy")
1572cd9a4666SKonstantin Aladyshev {
1573cd9a4666SKonstantin Aladyshev bootTypeStr = "xyz.openbmc_project.Control.Boot.Type.Types.Legacy";
1574cd9a4666SKonstantin Aladyshev }
1575cd9a4666SKonstantin Aladyshev else if (*bootType == "UEFI")
1576cd9a4666SKonstantin Aladyshev {
1577cd9a4666SKonstantin Aladyshev bootTypeStr = "xyz.openbmc_project.Control.Boot.Type.Types.EFI";
1578cd9a4666SKonstantin Aladyshev }
1579cd9a4666SKonstantin Aladyshev else
1580cd9a4666SKonstantin Aladyshev {
158162598e31SEd Tanous BMCWEB_LOG_DEBUG("Invalid property value for "
158262598e31SEd Tanous "BootSourceOverrideMode: {}",
158362598e31SEd Tanous *bootType);
1584ac106bf6SEd Tanous messages::propertyValueNotInList(asyncResp->res, *bootType,
1585cd9a4666SKonstantin Aladyshev "BootSourceOverrideMode");
1586cd9a4666SKonstantin Aladyshev return;
1587cd9a4666SKonstantin Aladyshev }
1588cd9a4666SKonstantin Aladyshev
1589cd9a4666SKonstantin Aladyshev // Act on validated parameters
159062598e31SEd Tanous BMCWEB_LOG_DEBUG("DBUS boot type: {}", bootTypeStr);
1591cd9a4666SKonstantin Aladyshev
1592e93abac6SGinu George setDbusProperty(asyncResp, "Boot/BootSourceOverrideMode",
1593e93abac6SGinu George "xyz.openbmc_project.Settings",
159487c44966SAsmitha Karunanithi sdbusplus::message::object_path(
159587c44966SAsmitha Karunanithi "/xyz/openbmc_project/control/host0/boot"),
159687c44966SAsmitha Karunanithi "xyz.openbmc_project.Control.Boot.Type", "BootType",
1597e93abac6SGinu George bootTypeStr);
1598cd9a4666SKonstantin Aladyshev }
1599cd9a4666SKonstantin Aladyshev
1600cd9a4666SKonstantin Aladyshev /**
1601cd9a4666SKonstantin Aladyshev * @brief Sets boot properties into DBUS object(s).
1602cd9a4666SKonstantin Aladyshev *
1603ac106bf6SEd Tanous * @param[in] asyncResp Shared pointer for generating response
1604ac106bf6SEd Tanous * message.
1605c21865c4SKonstantin Aladyshev * @param[in] bootType The boot type to set.
1606c21865c4SKonstantin Aladyshev * @return Integer error code.
1607c21865c4SKonstantin Aladyshev */
setBootEnable(const std::shared_ptr<bmcweb::AsyncResp> & asyncResp,const std::optional<std::string> & bootEnable)1608ac106bf6SEd Tanous inline void setBootEnable(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
1609c21865c4SKonstantin Aladyshev const std::optional<std::string>& bootEnable)
1610c21865c4SKonstantin Aladyshev {
1611c21865c4SKonstantin Aladyshev if (!bootEnable)
1612c21865c4SKonstantin Aladyshev {
1613c21865c4SKonstantin Aladyshev return;
1614c21865c4SKonstantin Aladyshev }
1615c21865c4SKonstantin Aladyshev // Source target specified
161662598e31SEd Tanous BMCWEB_LOG_DEBUG("Boot enable: {}", *bootEnable);
1617c21865c4SKonstantin Aladyshev
1618c21865c4SKonstantin Aladyshev bool bootOverrideEnable = false;
1619c21865c4SKonstantin Aladyshev bool bootOverridePersistent = false;
1620c21865c4SKonstantin Aladyshev // Figure out which DBUS interface and property to use
1621c21865c4SKonstantin Aladyshev if (*bootEnable == "Disabled")
1622c21865c4SKonstantin Aladyshev {
1623c21865c4SKonstantin Aladyshev bootOverrideEnable = false;
1624c21865c4SKonstantin Aladyshev }
1625c21865c4SKonstantin Aladyshev else if (*bootEnable == "Once")
1626c21865c4SKonstantin Aladyshev {
1627c21865c4SKonstantin Aladyshev bootOverrideEnable = true;
1628c21865c4SKonstantin Aladyshev bootOverridePersistent = false;
1629c21865c4SKonstantin Aladyshev }
1630c21865c4SKonstantin Aladyshev else if (*bootEnable == "Continuous")
1631c21865c4SKonstantin Aladyshev {
1632c21865c4SKonstantin Aladyshev bootOverrideEnable = true;
1633c21865c4SKonstantin Aladyshev bootOverridePersistent = true;
1634c21865c4SKonstantin Aladyshev }
1635c21865c4SKonstantin Aladyshev else
1636c21865c4SKonstantin Aladyshev {
163762598e31SEd Tanous BMCWEB_LOG_DEBUG(
163862598e31SEd Tanous "Invalid property value for BootSourceOverrideEnabled: {}",
163962598e31SEd Tanous *bootEnable);
1640ac106bf6SEd Tanous messages::propertyValueNotInList(asyncResp->res, *bootEnable,
1641c21865c4SKonstantin Aladyshev "BootSourceOverrideEnabled");
1642c21865c4SKonstantin Aladyshev return;
1643c21865c4SKonstantin Aladyshev }
1644c21865c4SKonstantin Aladyshev
1645c21865c4SKonstantin Aladyshev // Act on validated parameters
164662598e31SEd Tanous BMCWEB_LOG_DEBUG("DBUS boot override enable: {}", bootOverrideEnable);
1647c21865c4SKonstantin Aladyshev
1648e93abac6SGinu George setDbusProperty(asyncResp, "Boot/BootSourceOverrideEnabled",
1649e93abac6SGinu George "xyz.openbmc_project.Settings",
165087c44966SAsmitha Karunanithi sdbusplus::message::object_path(
165187c44966SAsmitha Karunanithi "/xyz/openbmc_project/control/host0/boot"),
165287c44966SAsmitha Karunanithi "xyz.openbmc_project.Object.Enable", "Enabled",
1653e93abac6SGinu George bootOverrideEnable);
1654c21865c4SKonstantin Aladyshev
1655c21865c4SKonstantin Aladyshev if (!bootOverrideEnable)
1656c21865c4SKonstantin Aladyshev {
1657c21865c4SKonstantin Aladyshev return;
1658c21865c4SKonstantin Aladyshev }
1659c21865c4SKonstantin Aladyshev
1660c21865c4SKonstantin Aladyshev // In case boot override is enabled we need to set correct value for the
1661c21865c4SKonstantin Aladyshev // 'one_time' enable DBus interface
166262598e31SEd Tanous BMCWEB_LOG_DEBUG("DBUS boot override persistent: {}",
166362598e31SEd Tanous bootOverridePersistent);
1664c21865c4SKonstantin Aladyshev
1665e93abac6SGinu George setDbusProperty(asyncResp, "Boot/BootSourceOverrideEnabled",
1666e93abac6SGinu George "xyz.openbmc_project.Settings",
166787c44966SAsmitha Karunanithi sdbusplus::message::object_path(
166887c44966SAsmitha Karunanithi "/xyz/openbmc_project/control/host0/boot/one_time"),
166987c44966SAsmitha Karunanithi "xyz.openbmc_project.Object.Enable", "Enabled",
1670e93abac6SGinu George !bootOverridePersistent);
1671c21865c4SKonstantin Aladyshev }
1672c21865c4SKonstantin Aladyshev
1673c21865c4SKonstantin Aladyshev /**
1674c21865c4SKonstantin Aladyshev * @brief Sets boot properties into DBUS object(s).
1675c21865c4SKonstantin Aladyshev *
1676ac106bf6SEd Tanous * @param[in] asyncResp Shared pointer for generating response message.
1677491d8ee7SSantosh Puranik * @param[in] bootSource The boot source to set.
1678491d8ee7SSantosh Puranik *
1679265c1602SJohnathan Mantey * @return Integer error code.
1680491d8ee7SSantosh Puranik */
setBootModeOrSource(const std::shared_ptr<bmcweb::AsyncResp> & asyncResp,const std::optional<std::string> & bootSource)1681*504af5a0SPatrick Williams inline void setBootModeOrSource(
1682*504af5a0SPatrick Williams const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
1683cd9a4666SKonstantin Aladyshev const std::optional<std::string>& bootSource)
1684491d8ee7SSantosh Puranik {
1685c21865c4SKonstantin Aladyshev std::string bootSourceStr;
1686c21865c4SKonstantin Aladyshev std::string bootModeStr;
1687944ffaf9SJohnathan Mantey
1688c21865c4SKonstantin Aladyshev if (!bootSource)
1689491d8ee7SSantosh Puranik {
1690c21865c4SKonstantin Aladyshev return;
1691c21865c4SKonstantin Aladyshev }
1692c21865c4SKonstantin Aladyshev
1693491d8ee7SSantosh Puranik // Source target specified
169462598e31SEd Tanous BMCWEB_LOG_DEBUG("Boot source: {}", *bootSource);
1695491d8ee7SSantosh Puranik // Figure out which DBUS interface and property to use
1696ac106bf6SEd Tanous if (assignBootParameters(asyncResp, *bootSource, bootSourceStr,
1697ac106bf6SEd Tanous bootModeStr) != 0)
1698491d8ee7SSantosh Puranik {
169962598e31SEd Tanous BMCWEB_LOG_DEBUG(
170062598e31SEd Tanous "Invalid property value for BootSourceOverrideTarget: {}",
170162598e31SEd Tanous *bootSource);
1702ac106bf6SEd Tanous messages::propertyValueNotInList(asyncResp->res, *bootSource,
1703491d8ee7SSantosh Puranik "BootSourceTargetOverride");
1704491d8ee7SSantosh Puranik return;
1705491d8ee7SSantosh Puranik }
1706491d8ee7SSantosh Puranik
1707944ffaf9SJohnathan Mantey // Act on validated parameters
170862598e31SEd Tanous BMCWEB_LOG_DEBUG("DBUS boot source: {}", bootSourceStr);
170962598e31SEd Tanous BMCWEB_LOG_DEBUG("DBUS boot mode: {}", bootModeStr);
1710944ffaf9SJohnathan Mantey
1711e93abac6SGinu George setDbusProperty(asyncResp, "Boot/BootSourceOverrideTarget",
1712e93abac6SGinu George "xyz.openbmc_project.Settings",
171387c44966SAsmitha Karunanithi sdbusplus::message::object_path(
171487c44966SAsmitha Karunanithi "/xyz/openbmc_project/control/host0/boot"),
171587c44966SAsmitha Karunanithi "xyz.openbmc_project.Control.Boot.Source", "BootSource",
1716e93abac6SGinu George bootSourceStr);
1717e93abac6SGinu George setDbusProperty(asyncResp, "Boot/BootSourceOverrideTarget",
1718e93abac6SGinu George "xyz.openbmc_project.Settings",
171987c44966SAsmitha Karunanithi sdbusplus::message::object_path(
172087c44966SAsmitha Karunanithi "/xyz/openbmc_project/control/host0/boot"),
172187c44966SAsmitha Karunanithi "xyz.openbmc_project.Control.Boot.Mode", "BootMode",
1722e93abac6SGinu George bootModeStr);
1723cd9a4666SKonstantin Aladyshev }
1724944ffaf9SJohnathan Mantey
1725cd9a4666SKonstantin Aladyshev /**
1726c21865c4SKonstantin Aladyshev * @brief Sets Boot source override properties.
1727491d8ee7SSantosh Puranik *
1728ac106bf6SEd Tanous * @param[in] asyncResp Shared pointer for generating response message.
1729491d8ee7SSantosh Puranik * @param[in] bootSource The boot source from incoming RF request.
1730cd9a4666SKonstantin Aladyshev * @param[in] bootType The boot type from incoming RF request.
1731491d8ee7SSantosh Puranik * @param[in] bootEnable The boot override enable from incoming RF request.
1732491d8ee7SSantosh Puranik *
1733265c1602SJohnathan Mantey * @return Integer error code.
1734491d8ee7SSantosh Puranik */
1735c21865c4SKonstantin Aladyshev
setBootProperties(const std::shared_ptr<bmcweb::AsyncResp> & asyncResp,const std::optional<std::string> & bootSource,const std::optional<std::string> & bootType,const std::optional<std::string> & bootEnable)1736*504af5a0SPatrick Williams inline void setBootProperties(
1737*504af5a0SPatrick Williams const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
1738c21865c4SKonstantin Aladyshev const std::optional<std::string>& bootSource,
1739c21865c4SKonstantin Aladyshev const std::optional<std::string>& bootType,
1740c21865c4SKonstantin Aladyshev const std::optional<std::string>& bootEnable)
1741491d8ee7SSantosh Puranik {
174262598e31SEd Tanous BMCWEB_LOG_DEBUG("Set boot information.");
1743491d8ee7SSantosh Puranik
1744ac106bf6SEd Tanous setBootModeOrSource(asyncResp, bootSource);
1745ac106bf6SEd Tanous setBootType(asyncResp, bootType);
1746ac106bf6SEd Tanous setBootEnable(asyncResp, bootEnable);
1747491d8ee7SSantosh Puranik }
1748491d8ee7SSantosh Puranik
1749c6a620f2SGeorge Liu /**
175098e386ecSGunnar Mills * @brief Sets AssetTag
175198e386ecSGunnar Mills *
1752ac106bf6SEd Tanous * @param[in] asyncResp Shared pointer for generating response message.
175398e386ecSGunnar Mills * @param[in] assetTag "AssetTag" from request.
175498e386ecSGunnar Mills *
175598e386ecSGunnar Mills * @return None.
175698e386ecSGunnar Mills */
setAssetTag(const std::shared_ptr<bmcweb::AsyncResp> & asyncResp,const std::string & assetTag)1757ac106bf6SEd Tanous inline void setAssetTag(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
175898e386ecSGunnar Mills const std::string& assetTag)
175998e386ecSGunnar Mills {
1760e99073f5SGeorge Liu constexpr std::array<std::string_view, 1> interfaces = {
1761e99073f5SGeorge Liu "xyz.openbmc_project.Inventory.Item.System"};
1762e99073f5SGeorge Liu dbus::utility::getSubTree(
1763e99073f5SGeorge Liu "/xyz/openbmc_project/inventory", 0, interfaces,
1764ac106bf6SEd Tanous [asyncResp,
1765e99073f5SGeorge Liu assetTag](const boost::system::error_code& ec,
1766b9d36b47SEd Tanous const dbus::utility::MapperGetSubTreeResponse& subtree) {
176798e386ecSGunnar Mills if (ec)
176898e386ecSGunnar Mills {
176962598e31SEd Tanous BMCWEB_LOG_DEBUG("D-Bus response error on GetSubTree {}", ec);
1770ac106bf6SEd Tanous messages::internalError(asyncResp->res);
177198e386ecSGunnar Mills return;
177298e386ecSGunnar Mills }
177326f6976fSEd Tanous if (subtree.empty())
177498e386ecSGunnar Mills {
177562598e31SEd Tanous BMCWEB_LOG_DEBUG("Can't find system D-Bus object!");
1776ac106bf6SEd Tanous messages::internalError(asyncResp->res);
177798e386ecSGunnar Mills return;
177898e386ecSGunnar Mills }
177998e386ecSGunnar Mills // Assume only 1 system D-Bus object
178098e386ecSGunnar Mills // Throw an error if there is more than 1
178198e386ecSGunnar Mills if (subtree.size() > 1)
178298e386ecSGunnar Mills {
178362598e31SEd Tanous BMCWEB_LOG_DEBUG("Found more than 1 system D-Bus object!");
1784ac106bf6SEd Tanous messages::internalError(asyncResp->res);
178598e386ecSGunnar Mills return;
178698e386ecSGunnar Mills }
178798e386ecSGunnar Mills if (subtree[0].first.empty() || subtree[0].second.size() != 1)
178898e386ecSGunnar Mills {
178962598e31SEd Tanous BMCWEB_LOG_DEBUG("Asset Tag Set mapper error!");
1790ac106bf6SEd Tanous messages::internalError(asyncResp->res);
179198e386ecSGunnar Mills return;
179298e386ecSGunnar Mills }
179398e386ecSGunnar Mills
179498e386ecSGunnar Mills const std::string& path = subtree[0].first;
179598e386ecSGunnar Mills const std::string& service = subtree[0].second.begin()->first;
179698e386ecSGunnar Mills
179798e386ecSGunnar Mills if (service.empty())
179898e386ecSGunnar Mills {
179962598e31SEd Tanous BMCWEB_LOG_DEBUG("Asset Tag Set service mapper error!");
1800ac106bf6SEd Tanous messages::internalError(asyncResp->res);
180198e386ecSGunnar Mills return;
180298e386ecSGunnar Mills }
180398e386ecSGunnar Mills
1804e93abac6SGinu George setDbusProperty(asyncResp, "AssetTag", service, path,
180587c44966SAsmitha Karunanithi "xyz.openbmc_project.Inventory.Decorator.AssetTag",
1806e93abac6SGinu George "AssetTag", assetTag);
1807e99073f5SGeorge Liu });
180898e386ecSGunnar Mills }
180998e386ecSGunnar Mills
181098e386ecSGunnar Mills /**
18119dcfe8c1SAlbert Zhang * @brief Validate the specified stopBootOnFault is valid and return the
18129dcfe8c1SAlbert Zhang * stopBootOnFault name associated with that string
18139dcfe8c1SAlbert Zhang *
18149dcfe8c1SAlbert Zhang * @param[in] stopBootOnFaultString String representing the desired
18159dcfe8c1SAlbert Zhang * stopBootOnFault
18169dcfe8c1SAlbert Zhang *
18179dcfe8c1SAlbert Zhang * @return stopBootOnFault value or empty if incoming value is not valid
18189dcfe8c1SAlbert Zhang */
validstopBootOnFault(const std::string & stopBootOnFaultString)1819*504af5a0SPatrick Williams inline std::optional<bool> validstopBootOnFault(
1820*504af5a0SPatrick Williams const std::string& stopBootOnFaultString)
18219dcfe8c1SAlbert Zhang {
18229dcfe8c1SAlbert Zhang if (stopBootOnFaultString == "AnyFault")
18239dcfe8c1SAlbert Zhang {
18249dcfe8c1SAlbert Zhang return true;
18259dcfe8c1SAlbert Zhang }
18269dcfe8c1SAlbert Zhang
18279dcfe8c1SAlbert Zhang if (stopBootOnFaultString == "Never")
18289dcfe8c1SAlbert Zhang {
18299dcfe8c1SAlbert Zhang return false;
18309dcfe8c1SAlbert Zhang }
18319dcfe8c1SAlbert Zhang
18329dcfe8c1SAlbert Zhang return std::nullopt;
18339dcfe8c1SAlbert Zhang }
18349dcfe8c1SAlbert Zhang
18359dcfe8c1SAlbert Zhang /**
18369dcfe8c1SAlbert Zhang * @brief Sets stopBootOnFault
18379dcfe8c1SAlbert Zhang *
1838fc3edfddSEd Tanous * @param[in] asyncResp Shared pointer for generating response message.
18399dcfe8c1SAlbert Zhang * @param[in] stopBootOnFault "StopBootOnFault" from request.
18409dcfe8c1SAlbert Zhang *
18419dcfe8c1SAlbert Zhang * @return None.
18429dcfe8c1SAlbert Zhang */
setStopBootOnFault(const std::shared_ptr<bmcweb::AsyncResp> & asyncResp,const std::string & stopBootOnFault)1843*504af5a0SPatrick Williams inline void setStopBootOnFault(
1844*504af5a0SPatrick Williams const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
18459dcfe8c1SAlbert Zhang const std::string& stopBootOnFault)
18469dcfe8c1SAlbert Zhang {
184762598e31SEd Tanous BMCWEB_LOG_DEBUG("Set Stop Boot On Fault.");
18489dcfe8c1SAlbert Zhang
18499dcfe8c1SAlbert Zhang std::optional<bool> stopBootEnabled = validstopBootOnFault(stopBootOnFault);
18509dcfe8c1SAlbert Zhang if (!stopBootEnabled)
18519dcfe8c1SAlbert Zhang {
185262598e31SEd Tanous BMCWEB_LOG_DEBUG("Invalid property value for StopBootOnFault: {}",
185362598e31SEd Tanous stopBootOnFault);
1854fc3edfddSEd Tanous messages::propertyValueNotInList(asyncResp->res, stopBootOnFault,
18559dcfe8c1SAlbert Zhang "StopBootOnFault");
18569dcfe8c1SAlbert Zhang return;
18579dcfe8c1SAlbert Zhang }
18589dcfe8c1SAlbert Zhang
1859e93abac6SGinu George setDbusProperty(asyncResp, "Boot/StopBootOnFault",
1860e93abac6SGinu George "xyz.openbmc_project.Settings",
186187c44966SAsmitha Karunanithi sdbusplus::message::object_path(
186287c44966SAsmitha Karunanithi "/xyz/openbmc_project/logging/settings"),
1863fc3edfddSEd Tanous "xyz.openbmc_project.Logging.Settings", "QuiesceOnHwError",
1864e93abac6SGinu George *stopBootEnabled);
18659dcfe8c1SAlbert Zhang }
18669dcfe8c1SAlbert Zhang
18679dcfe8c1SAlbert Zhang /**
186869f35306SGunnar Mills * @brief Sets automaticRetry (Auto Reboot)
186969f35306SGunnar Mills *
1870ac106bf6SEd Tanous * @param[in] asyncResp Shared pointer for generating response message.
187169f35306SGunnar Mills * @param[in] automaticRetryConfig "AutomaticRetryConfig" from request.
187269f35306SGunnar Mills *
187369f35306SGunnar Mills * @return None.
187469f35306SGunnar Mills */
setAutomaticRetry(const std::shared_ptr<bmcweb::AsyncResp> & asyncResp,const std::string & automaticRetryConfig)1875*504af5a0SPatrick Williams inline void setAutomaticRetry(
1876*504af5a0SPatrick Williams const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
1877f23b7296SEd Tanous const std::string& automaticRetryConfig)
187869f35306SGunnar Mills {
187962598e31SEd Tanous BMCWEB_LOG_DEBUG("Set Automatic Retry.");
188069f35306SGunnar Mills
188169f35306SGunnar Mills // OpenBMC only supports "Disabled" and "RetryAttempts".
1882543f4400SEd Tanous bool autoRebootEnabled = false;
188369f35306SGunnar Mills
188469f35306SGunnar Mills if (automaticRetryConfig == "Disabled")
188569f35306SGunnar Mills {
188669f35306SGunnar Mills autoRebootEnabled = false;
188769f35306SGunnar Mills }
188869f35306SGunnar Mills else if (automaticRetryConfig == "RetryAttempts")
188969f35306SGunnar Mills {
189069f35306SGunnar Mills autoRebootEnabled = true;
189169f35306SGunnar Mills }
189269f35306SGunnar Mills else
189369f35306SGunnar Mills {
189462598e31SEd Tanous BMCWEB_LOG_DEBUG("Invalid property value for AutomaticRetryConfig: {}",
189562598e31SEd Tanous automaticRetryConfig);
1896ac106bf6SEd Tanous messages::propertyValueNotInList(asyncResp->res, automaticRetryConfig,
189769f35306SGunnar Mills "AutomaticRetryConfig");
189869f35306SGunnar Mills return;
189969f35306SGunnar Mills }
190069f35306SGunnar Mills
1901e93abac6SGinu George setDbusProperty(asyncResp, "Boot/AutomaticRetryConfig",
1902e93abac6SGinu George "xyz.openbmc_project.Settings",
190387c44966SAsmitha Karunanithi sdbusplus::message::object_path(
190487c44966SAsmitha Karunanithi "/xyz/openbmc_project/control/host0/auto_reboot"),
190587c44966SAsmitha Karunanithi "xyz.openbmc_project.Control.Boot.RebootPolicy",
1906e93abac6SGinu George "AutoReboot", autoRebootEnabled);
190769f35306SGunnar Mills }
190869f35306SGunnar Mills
dbusPowerRestorePolicyFromRedfish(std::string_view policy)19098d69c668SEd Tanous inline std::string dbusPowerRestorePolicyFromRedfish(std::string_view policy)
19108d69c668SEd Tanous {
19118d69c668SEd Tanous if (policy == "AlwaysOn")
19128d69c668SEd Tanous {
19138d69c668SEd Tanous return "xyz.openbmc_project.Control.Power.RestorePolicy.Policy.AlwaysOn";
19148d69c668SEd Tanous }
19158d69c668SEd Tanous if (policy == "AlwaysOff")
19168d69c668SEd Tanous {
19178d69c668SEd Tanous return "xyz.openbmc_project.Control.Power.RestorePolicy.Policy.AlwaysOff";
19188d69c668SEd Tanous }
19198d69c668SEd Tanous if (policy == "LastState")
19208d69c668SEd Tanous {
19218d69c668SEd Tanous return "xyz.openbmc_project.Control.Power.RestorePolicy.Policy.Restore";
19228d69c668SEd Tanous }
19238d69c668SEd Tanous return "";
19248d69c668SEd Tanous }
19258d69c668SEd Tanous
192669f35306SGunnar Mills /**
1927c6a620f2SGeorge Liu * @brief Sets power restore policy properties.
1928c6a620f2SGeorge Liu *
1929ac106bf6SEd Tanous * @param[in] asyncResp Shared pointer for generating response message.
1930c6a620f2SGeorge Liu * @param[in] policy power restore policy properties from request.
1931c6a620f2SGeorge Liu *
1932c6a620f2SGeorge Liu * @return None.
1933c6a620f2SGeorge Liu */
setPowerRestorePolicy(const std::shared_ptr<bmcweb::AsyncResp> & asyncResp,std::string_view policy)1934*504af5a0SPatrick Williams inline void setPowerRestorePolicy(
1935*504af5a0SPatrick Williams const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
19368d69c668SEd Tanous std::string_view policy)
1937c6a620f2SGeorge Liu {
193862598e31SEd Tanous BMCWEB_LOG_DEBUG("Set power restore policy.");
1939c6a620f2SGeorge Liu
19408d69c668SEd Tanous std::string powerRestorePolicy = dbusPowerRestorePolicyFromRedfish(policy);
1941c6a620f2SGeorge Liu
19428d69c668SEd Tanous if (powerRestorePolicy.empty())
1943c6a620f2SGeorge Liu {
1944ac106bf6SEd Tanous messages::propertyValueNotInList(asyncResp->res, policy,
19454e69c904SGunnar Mills "PowerRestorePolicy");
1946c6a620f2SGeorge Liu return;
1947c6a620f2SGeorge Liu }
1948c6a620f2SGeorge Liu
194987c44966SAsmitha Karunanithi setDbusProperty(
1950e93abac6SGinu George asyncResp, "PowerRestorePolicy", "xyz.openbmc_project.Settings",
195187c44966SAsmitha Karunanithi sdbusplus::message::object_path(
195287c44966SAsmitha Karunanithi "/xyz/openbmc_project/control/host0/power_restore_policy"),
19539ae226faSGeorge Liu "xyz.openbmc_project.Control.Power.RestorePolicy", "PowerRestorePolicy",
1954e93abac6SGinu George powerRestorePolicy);
1955c6a620f2SGeorge Liu }
1956c6a620f2SGeorge Liu
1957a6349918SAppaRao Puli /**
1958a6349918SAppaRao Puli * @brief Retrieves provisioning status
1959a6349918SAppaRao Puli *
196025b54dbaSEd Tanous * @param[in] asyncResp Shared pointer for completing asynchronous
196125b54dbaSEd Tanous * calls.
1962a6349918SAppaRao Puli *
1963a6349918SAppaRao Puli * @return None.
1964a6349918SAppaRao Puli */
getProvisioningStatus(const std::shared_ptr<bmcweb::AsyncResp> & asyncResp)1965*504af5a0SPatrick Williams inline void getProvisioningStatus(
1966*504af5a0SPatrick Williams const std::shared_ptr<bmcweb::AsyncResp>& asyncResp)
1967a6349918SAppaRao Puli {
196862598e31SEd Tanous BMCWEB_LOG_DEBUG("Get OEM information.");
1969deae6a78SEd Tanous dbus::utility::getAllProperties(
1970deae6a78SEd Tanous "xyz.openbmc_project.PFR.Manager", "/xyz/openbmc_project/pfr",
1971deae6a78SEd Tanous "xyz.openbmc_project.PFR.Attributes",
1972ac106bf6SEd Tanous [asyncResp](const boost::system::error_code& ec,
1973b9d36b47SEd Tanous const dbus::utility::DBusPropertiesMap& propertiesList) {
1974b99fb1a9SAppaRao Puli nlohmann::json& oemPFR =
1975bd79bce8SPatrick Williams asyncResp->res
1976bd79bce8SPatrick Williams .jsonValue["Oem"]["OpenBmc"]["FirmwareProvisioning"];
1977ac106bf6SEd Tanous asyncResp->res.jsonValue["Oem"]["OpenBmc"]["@odata.type"] =
19781d834d49SEd Tanous "#OpenBMCComputerSystem.v1_0_0.OpenBmc";
1979bd79bce8SPatrick Williams oemPFR["@odata.type"] =
1980bd79bce8SPatrick Williams "#OpenBMCComputerSystem.FirmwareProvisioning";
198150626f4fSJames Feist
1982a6349918SAppaRao Puli if (ec)
1983a6349918SAppaRao Puli {
198462598e31SEd Tanous BMCWEB_LOG_DEBUG("DBUS response error {}", ec);
1985b99fb1a9SAppaRao Puli // not an error, don't have to have the interface
1986539d8c6bSEd Tanous oemPFR["ProvisioningStatus"] = open_bmc_computer_system::
1987539d8c6bSEd Tanous FirmwareProvisioningStatus::NotProvisioned;
1988a6349918SAppaRao Puli return;
1989a6349918SAppaRao Puli }
1990a6349918SAppaRao Puli
1991a6349918SAppaRao Puli const bool* provState = nullptr;
1992a6349918SAppaRao Puli const bool* lockState = nullptr;
1993bc1d29deSKrzysztof Grobelny
1994bc1d29deSKrzysztof Grobelny const bool success = sdbusplus::unpackPropertiesNoThrow(
1995bd79bce8SPatrick Williams dbus_utils::UnpackErrorPrinter(), propertiesList,
1996bd79bce8SPatrick Williams "UfmProvisioned", provState, "UfmLocked", lockState);
1997bc1d29deSKrzysztof Grobelny
1998bc1d29deSKrzysztof Grobelny if (!success)
1999a6349918SAppaRao Puli {
2000ac106bf6SEd Tanous messages::internalError(asyncResp->res);
2001bc1d29deSKrzysztof Grobelny return;
2002a6349918SAppaRao Puli }
2003a6349918SAppaRao Puli
2004a6349918SAppaRao Puli if ((provState == nullptr) || (lockState == nullptr))
2005a6349918SAppaRao Puli {
200662598e31SEd Tanous BMCWEB_LOG_DEBUG("Unable to get PFR attributes.");
2007ac106bf6SEd Tanous messages::internalError(asyncResp->res);
2008a6349918SAppaRao Puli return;
2009a6349918SAppaRao Puli }
2010a6349918SAppaRao Puli
201125b54dbaSEd Tanous if (*provState)
2012a6349918SAppaRao Puli {
201325b54dbaSEd Tanous if (*lockState)
2014a6349918SAppaRao Puli {
2015539d8c6bSEd Tanous oemPFR["ProvisioningStatus"] = open_bmc_computer_system::
2016539d8c6bSEd Tanous FirmwareProvisioningStatus::ProvisionedAndLocked;
2017a6349918SAppaRao Puli }
2018a6349918SAppaRao Puli else
2019a6349918SAppaRao Puli {
2020539d8c6bSEd Tanous oemPFR["ProvisioningStatus"] = open_bmc_computer_system::
2021539d8c6bSEd Tanous FirmwareProvisioningStatus::ProvisionedButNotLocked;
2022a6349918SAppaRao Puli }
2023a6349918SAppaRao Puli }
2024a6349918SAppaRao Puli else
2025a6349918SAppaRao Puli {
2026539d8c6bSEd Tanous oemPFR["ProvisioningStatus"] = open_bmc_computer_system::
2027539d8c6bSEd Tanous FirmwareProvisioningStatus::NotProvisioned;
2028a6349918SAppaRao Puli }
2029bc1d29deSKrzysztof Grobelny });
2030a6349918SAppaRao Puli }
2031a6349918SAppaRao Puli
2032491d8ee7SSantosh Puranik /**
20336b9ac4f2SChris Cain * @brief Translate the PowerMode string to enum value
20343a2d0424SChris Cain *
20356b9ac4f2SChris Cain * @param[in] modeString PowerMode string to be translated
20363a2d0424SChris Cain *
20376b9ac4f2SChris Cain * @return PowerMode enum
20383a2d0424SChris Cain */
translatePowerModeString(const std::string & modeString)2039*504af5a0SPatrick Williams inline computer_system::PowerMode translatePowerModeString(
2040*504af5a0SPatrick Williams const std::string& modeString)
20413a2d0424SChris Cain {
2042b6655101SChris Cain using PowerMode = computer_system::PowerMode;
2043b6655101SChris Cain
20446b9ac4f2SChris Cain if (modeString == "xyz.openbmc_project.Control.Power.Mode.PowerMode.Static")
20453a2d0424SChris Cain {
20466b9ac4f2SChris Cain return PowerMode::Static;
20473a2d0424SChris Cain }
20486b9ac4f2SChris Cain if (modeString ==
20490fda0f12SGeorge Liu "xyz.openbmc_project.Control.Power.Mode.PowerMode.MaximumPerformance")
20503a2d0424SChris Cain {
20516b9ac4f2SChris Cain return PowerMode::MaximumPerformance;
20523a2d0424SChris Cain }
20536b9ac4f2SChris Cain if (modeString ==
20540fda0f12SGeorge Liu "xyz.openbmc_project.Control.Power.Mode.PowerMode.PowerSaving")
20553a2d0424SChris Cain {
20566b9ac4f2SChris Cain return PowerMode::PowerSaving;
2057b6655101SChris Cain }
20586b9ac4f2SChris Cain if (modeString ==
2059b6655101SChris Cain "xyz.openbmc_project.Control.Power.Mode.PowerMode.BalancedPerformance")
2060b6655101SChris Cain {
20616b9ac4f2SChris Cain return PowerMode::BalancedPerformance;
2062b6655101SChris Cain }
20636b9ac4f2SChris Cain if (modeString ==
2064b6655101SChris Cain "xyz.openbmc_project.Control.Power.Mode.PowerMode.EfficiencyFavorPerformance")
2065b6655101SChris Cain {
20666b9ac4f2SChris Cain return PowerMode::EfficiencyFavorPerformance;
2067b6655101SChris Cain }
20686b9ac4f2SChris Cain if (modeString ==
2069b6655101SChris Cain "xyz.openbmc_project.Control.Power.Mode.PowerMode.EfficiencyFavorPower")
2070b6655101SChris Cain {
20716b9ac4f2SChris Cain return PowerMode::EfficiencyFavorPower;
20723a2d0424SChris Cain }
20736b9ac4f2SChris Cain if (modeString == "xyz.openbmc_project.Control.Power.Mode.PowerMode.OEM")
20743a2d0424SChris Cain {
20756b9ac4f2SChris Cain return PowerMode::OEM;
20766b9ac4f2SChris Cain }
20776b9ac4f2SChris Cain // Any other values would be invalid
20786b9ac4f2SChris Cain BMCWEB_LOG_ERROR("PowerMode value was not valid: {}", modeString);
20796b9ac4f2SChris Cain return PowerMode::Invalid;
20806b9ac4f2SChris Cain }
20816b9ac4f2SChris Cain
afterGetPowerMode(const std::shared_ptr<bmcweb::AsyncResp> & asyncResp,const boost::system::error_code & ec,const dbus::utility::DBusPropertiesMap & properties)2082*504af5a0SPatrick Williams inline void afterGetPowerMode(
2083*504af5a0SPatrick Williams const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
20846b9ac4f2SChris Cain const boost::system::error_code& ec,
20856b9ac4f2SChris Cain const dbus::utility::DBusPropertiesMap& properties)
20866b9ac4f2SChris Cain {
20876b9ac4f2SChris Cain if (ec)
20886b9ac4f2SChris Cain {
20896b9ac4f2SChris Cain BMCWEB_LOG_ERROR("DBUS response error on PowerMode GetAll: {}", ec);
20906b9ac4f2SChris Cain messages::internalError(asyncResp->res);
20916b9ac4f2SChris Cain return;
20926b9ac4f2SChris Cain }
20936b9ac4f2SChris Cain
20946b9ac4f2SChris Cain std::string powerMode;
20956b9ac4f2SChris Cain const std::vector<std::string>* allowedModes = nullptr;
20966b9ac4f2SChris Cain const bool success = sdbusplus::unpackPropertiesNoThrow(
20976b9ac4f2SChris Cain dbus_utils::UnpackErrorPrinter(), properties, "PowerMode", powerMode,
20986b9ac4f2SChris Cain "AllowedPowerModes", allowedModes);
20996b9ac4f2SChris Cain
21006b9ac4f2SChris Cain if (!success)
21016b9ac4f2SChris Cain {
21026b9ac4f2SChris Cain messages::internalError(asyncResp->res);
21036b9ac4f2SChris Cain return;
21046b9ac4f2SChris Cain }
21056b9ac4f2SChris Cain
21066b9ac4f2SChris Cain nlohmann::json::array_t modeList;
21076b9ac4f2SChris Cain if (allowedModes == nullptr)
21086b9ac4f2SChris Cain {
21096b9ac4f2SChris Cain modeList.emplace_back("Static");
21106b9ac4f2SChris Cain modeList.emplace_back("MaximumPerformance");
21116b9ac4f2SChris Cain modeList.emplace_back("PowerSaving");
21123a2d0424SChris Cain }
21133a2d0424SChris Cain else
21143a2d0424SChris Cain {
21156b9ac4f2SChris Cain for (const auto& aMode : *allowedModes)
21166b9ac4f2SChris Cain {
21176b9ac4f2SChris Cain computer_system::PowerMode modeValue =
21186b9ac4f2SChris Cain translatePowerModeString(aMode);
21196b9ac4f2SChris Cain if (modeValue == computer_system::PowerMode::Invalid)
21206b9ac4f2SChris Cain {
2121ac106bf6SEd Tanous messages::internalError(asyncResp->res);
21226b9ac4f2SChris Cain continue;
21236b9ac4f2SChris Cain }
21246b9ac4f2SChris Cain modeList.emplace_back(modeValue);
21253a2d0424SChris Cain }
21263a2d0424SChris Cain }
21276b9ac4f2SChris Cain asyncResp->res.jsonValue["PowerMode@Redfish.AllowableValues"] = modeList;
21283a2d0424SChris Cain
21296b9ac4f2SChris Cain BMCWEB_LOG_DEBUG("Current power mode: {}", powerMode);
21306b9ac4f2SChris Cain const computer_system::PowerMode modeValue =
21316b9ac4f2SChris Cain translatePowerModeString(powerMode);
21326b9ac4f2SChris Cain if (modeValue == computer_system::PowerMode::Invalid)
21336b9ac4f2SChris Cain {
21346b9ac4f2SChris Cain messages::internalError(asyncResp->res);
21356b9ac4f2SChris Cain return;
21366b9ac4f2SChris Cain }
21376b9ac4f2SChris Cain asyncResp->res.jsonValue["PowerMode"] = modeValue;
21386b9ac4f2SChris Cain }
21393a2d0424SChris Cain /**
21403a2d0424SChris Cain * @brief Retrieves system power mode
21413a2d0424SChris Cain *
2142ac106bf6SEd Tanous * @param[in] asyncResp Shared pointer for generating response message.
21433a2d0424SChris Cain *
21443a2d0424SChris Cain * @return None.
21453a2d0424SChris Cain */
getPowerMode(const std::shared_ptr<bmcweb::AsyncResp> & asyncResp)2146ac106bf6SEd Tanous inline void getPowerMode(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp)
21473a2d0424SChris Cain {
214862598e31SEd Tanous BMCWEB_LOG_DEBUG("Get power mode.");
21493a2d0424SChris Cain
21503a2d0424SChris Cain // Get Power Mode object path:
2151e99073f5SGeorge Liu constexpr std::array<std::string_view, 1> interfaces = {
2152e99073f5SGeorge Liu "xyz.openbmc_project.Control.Power.Mode"};
2153e99073f5SGeorge Liu dbus::utility::getSubTree(
2154e99073f5SGeorge Liu "/", 0, interfaces,
2155ac106bf6SEd Tanous [asyncResp](const boost::system::error_code& ec,
2156b9d36b47SEd Tanous const dbus::utility::MapperGetSubTreeResponse& subtree) {
21573a2d0424SChris Cain if (ec)
21583a2d0424SChris Cain {
2159bd79bce8SPatrick Williams BMCWEB_LOG_DEBUG(
2160bd79bce8SPatrick Williams "DBUS response error on Power.Mode GetSubTree {}", ec);
21613a2d0424SChris Cain // This is an optional D-Bus object so just return if
21623a2d0424SChris Cain // error occurs
21633a2d0424SChris Cain return;
21643a2d0424SChris Cain }
21653a2d0424SChris Cain if (subtree.empty())
21663a2d0424SChris Cain {
21673a2d0424SChris Cain // As noted above, this is an optional interface so just return
21683a2d0424SChris Cain // if there is no instance found
21693a2d0424SChris Cain return;
21703a2d0424SChris Cain }
21713a2d0424SChris Cain if (subtree.size() > 1)
21723a2d0424SChris Cain {
21733a2d0424SChris Cain // More then one PowerMode object is not supported and is an
21743a2d0424SChris Cain // error
217562598e31SEd Tanous BMCWEB_LOG_DEBUG(
217662598e31SEd Tanous "Found more than 1 system D-Bus Power.Mode objects: {}",
217762598e31SEd Tanous subtree.size());
2178ac106bf6SEd Tanous messages::internalError(asyncResp->res);
21793a2d0424SChris Cain return;
21803a2d0424SChris Cain }
21813a2d0424SChris Cain if ((subtree[0].first.empty()) || (subtree[0].second.size() != 1))
21823a2d0424SChris Cain {
218362598e31SEd Tanous BMCWEB_LOG_DEBUG("Power.Mode mapper error!");
2184ac106bf6SEd Tanous messages::internalError(asyncResp->res);
21853a2d0424SChris Cain return;
21863a2d0424SChris Cain }
21873a2d0424SChris Cain const std::string& path = subtree[0].first;
21883a2d0424SChris Cain const std::string& service = subtree[0].second.begin()->first;
21893a2d0424SChris Cain if (service.empty())
21903a2d0424SChris Cain {
219162598e31SEd Tanous BMCWEB_LOG_DEBUG("Power.Mode service mapper error!");
2192ac106bf6SEd Tanous messages::internalError(asyncResp->res);
21933a2d0424SChris Cain return;
21943a2d0424SChris Cain }
21956b9ac4f2SChris Cain
21966b9ac4f2SChris Cain // Valid Power Mode object found, now read the mode properties
2197deae6a78SEd Tanous dbus::utility::getAllProperties(
21981e1e598dSJonathan Doman *crow::connections::systemBus, service, path,
21996b9ac4f2SChris Cain "xyz.openbmc_project.Control.Power.Mode",
2200bd79bce8SPatrick Williams [asyncResp](
2201bd79bce8SPatrick Williams const boost::system::error_code& ec2,
22026b9ac4f2SChris Cain const dbus::utility::DBusPropertiesMap& properties) {
22036b9ac4f2SChris Cain afterGetPowerMode(asyncResp, ec2, properties);
22041e1e598dSJonathan Doman });
2205e99073f5SGeorge Liu });
22063a2d0424SChris Cain }
22073a2d0424SChris Cain
22083a2d0424SChris Cain /**
22093a2d0424SChris Cain * @brief Validate the specified mode is valid and return the PowerMode
22103a2d0424SChris Cain * name associated with that string
22113a2d0424SChris Cain *
2212ac106bf6SEd Tanous * @param[in] asyncResp Shared pointer for generating response message.
2213b6655101SChris Cain * @param[in] modeValue String representing the desired PowerMode
22143a2d0424SChris Cain *
22153a2d0424SChris Cain * @return PowerMode value or empty string if mode is not valid
22163a2d0424SChris Cain */
validatePowerMode(const std::shared_ptr<bmcweb::AsyncResp> & asyncResp,const nlohmann::json & modeValue)2217*504af5a0SPatrick Williams inline std::string validatePowerMode(
2218*504af5a0SPatrick Williams const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
2219b6655101SChris Cain const nlohmann::json& modeValue)
22203a2d0424SChris Cain {
2221b6655101SChris Cain using PowerMode = computer_system::PowerMode;
22223a2d0424SChris Cain std::string mode;
22233a2d0424SChris Cain
2224b6655101SChris Cain if (modeValue == PowerMode::Static)
22253a2d0424SChris Cain {
22263a2d0424SChris Cain mode = "xyz.openbmc_project.Control.Power.Mode.PowerMode.Static";
22273a2d0424SChris Cain }
2228b6655101SChris Cain else if (modeValue == PowerMode::MaximumPerformance)
22293a2d0424SChris Cain {
22300fda0f12SGeorge Liu mode =
22310fda0f12SGeorge Liu "xyz.openbmc_project.Control.Power.Mode.PowerMode.MaximumPerformance";
22323a2d0424SChris Cain }
2233b6655101SChris Cain else if (modeValue == PowerMode::PowerSaving)
22343a2d0424SChris Cain {
22353a2d0424SChris Cain mode = "xyz.openbmc_project.Control.Power.Mode.PowerMode.PowerSaving";
22363a2d0424SChris Cain }
2237b6655101SChris Cain else if (modeValue == PowerMode::BalancedPerformance)
2238b6655101SChris Cain {
2239b6655101SChris Cain mode =
2240b6655101SChris Cain "xyz.openbmc_project.Control.Power.Mode.PowerMode.BalancedPerformance";
2241b6655101SChris Cain }
2242b6655101SChris Cain else if (modeValue == PowerMode::EfficiencyFavorPerformance)
2243b6655101SChris Cain {
2244b6655101SChris Cain mode =
2245b6655101SChris Cain "xyz.openbmc_project.Control.Power.Mode.PowerMode.EfficiencyFavorPerformance";
2246b6655101SChris Cain }
2247b6655101SChris Cain else if (modeValue == PowerMode::EfficiencyFavorPower)
2248b6655101SChris Cain {
2249b6655101SChris Cain mode =
2250b6655101SChris Cain "xyz.openbmc_project.Control.Power.Mode.PowerMode.EfficiencyFavorPower";
2251b6655101SChris Cain }
22523a2d0424SChris Cain else
22533a2d0424SChris Cain {
2254b6655101SChris Cain messages::propertyValueNotInList(asyncResp->res, modeValue.dump(),
2255ac106bf6SEd Tanous "PowerMode");
22563a2d0424SChris Cain }
22573a2d0424SChris Cain return mode;
22583a2d0424SChris Cain }
22593a2d0424SChris Cain
22603a2d0424SChris Cain /**
22613a2d0424SChris Cain * @brief Sets system power mode.
22623a2d0424SChris Cain *
2263ac106bf6SEd Tanous * @param[in] asyncResp Shared pointer for generating response message.
22643a2d0424SChris Cain * @param[in] pmode System power mode from request.
22653a2d0424SChris Cain *
22663a2d0424SChris Cain * @return None.
22673a2d0424SChris Cain */
setPowerMode(const std::shared_ptr<bmcweb::AsyncResp> & asyncResp,const std::string & pmode)2268ac106bf6SEd Tanous inline void setPowerMode(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
22693a2d0424SChris Cain const std::string& pmode)
22703a2d0424SChris Cain {
227162598e31SEd Tanous BMCWEB_LOG_DEBUG("Set power mode.");
22723a2d0424SChris Cain
2273ac106bf6SEd Tanous std::string powerMode = validatePowerMode(asyncResp, pmode);
22743a2d0424SChris Cain if (powerMode.empty())
22753a2d0424SChris Cain {
22763a2d0424SChris Cain return;
22773a2d0424SChris Cain }
22783a2d0424SChris Cain
22793a2d0424SChris Cain // Get Power Mode object path:
2280e99073f5SGeorge Liu constexpr std::array<std::string_view, 1> interfaces = {
2281e99073f5SGeorge Liu "xyz.openbmc_project.Control.Power.Mode"};
2282e99073f5SGeorge Liu dbus::utility::getSubTree(
2283e99073f5SGeorge Liu "/", 0, interfaces,
2284ac106bf6SEd Tanous [asyncResp,
2285e99073f5SGeorge Liu powerMode](const boost::system::error_code& ec,
2286b9d36b47SEd Tanous const dbus::utility::MapperGetSubTreeResponse& subtree) {
22873a2d0424SChris Cain if (ec)
22883a2d0424SChris Cain {
2289bd79bce8SPatrick Williams BMCWEB_LOG_ERROR(
2290bd79bce8SPatrick Williams "DBUS response error on Power.Mode GetSubTree {}", ec);
22913a2d0424SChris Cain // This is an optional D-Bus object, but user attempted to patch
2292ac106bf6SEd Tanous messages::internalError(asyncResp->res);
22933a2d0424SChris Cain return;
22943a2d0424SChris Cain }
22953a2d0424SChris Cain if (subtree.empty())
22963a2d0424SChris Cain {
22973a2d0424SChris Cain // This is an optional D-Bus object, but user attempted to patch
2298ac106bf6SEd Tanous messages::resourceNotFound(asyncResp->res, "ComputerSystem",
22993a2d0424SChris Cain "PowerMode");
23003a2d0424SChris Cain return;
23013a2d0424SChris Cain }
23023a2d0424SChris Cain if (subtree.size() > 1)
23033a2d0424SChris Cain {
23043a2d0424SChris Cain // More then one PowerMode object is not supported and is an
23053a2d0424SChris Cain // error
230662598e31SEd Tanous BMCWEB_LOG_DEBUG(
230762598e31SEd Tanous "Found more than 1 system D-Bus Power.Mode objects: {}",
230862598e31SEd Tanous subtree.size());
2309ac106bf6SEd Tanous messages::internalError(asyncResp->res);
23103a2d0424SChris Cain return;
23113a2d0424SChris Cain }
23123a2d0424SChris Cain if ((subtree[0].first.empty()) || (subtree[0].second.size() != 1))
23133a2d0424SChris Cain {
231462598e31SEd Tanous BMCWEB_LOG_DEBUG("Power.Mode mapper error!");
2315ac106bf6SEd Tanous messages::internalError(asyncResp->res);
23163a2d0424SChris Cain return;
23173a2d0424SChris Cain }
23183a2d0424SChris Cain const std::string& path = subtree[0].first;
23193a2d0424SChris Cain const std::string& service = subtree[0].second.begin()->first;
23203a2d0424SChris Cain if (service.empty())
23213a2d0424SChris Cain {
232262598e31SEd Tanous BMCWEB_LOG_DEBUG("Power.Mode service mapper error!");
2323ac106bf6SEd Tanous messages::internalError(asyncResp->res);
23243a2d0424SChris Cain return;
23253a2d0424SChris Cain }
23263a2d0424SChris Cain
232762598e31SEd Tanous BMCWEB_LOG_DEBUG("Setting power mode({}) -> {}", powerMode, path);
23283a2d0424SChris Cain
23293a2d0424SChris Cain // Set the Power Mode property
2330e93abac6SGinu George setDbusProperty(asyncResp, "PowerMode", service, path,
2331bd79bce8SPatrick Williams "xyz.openbmc_project.Control.Power.Mode",
2332bd79bce8SPatrick Williams "PowerMode", powerMode);
2333e99073f5SGeorge Liu });
23343a2d0424SChris Cain }
23353a2d0424SChris Cain
23363a2d0424SChris Cain /**
233751709ffdSYong Li * @brief Translates watchdog timeout action DBUS property value to redfish.
233851709ffdSYong Li *
233951709ffdSYong Li * @param[in] dbusAction The watchdog timeout action in D-BUS.
234051709ffdSYong Li *
234151709ffdSYong Li * @return Returns as a string, the timeout action in Redfish terms. If
234251709ffdSYong Li * translation cannot be done, returns an empty string.
234351709ffdSYong Li */
dbusToRfWatchdogAction(const std::string & dbusAction)234423a21a1cSEd Tanous inline std::string dbusToRfWatchdogAction(const std::string& dbusAction)
234551709ffdSYong Li {
234651709ffdSYong Li if (dbusAction == "xyz.openbmc_project.State.Watchdog.Action.None")
234751709ffdSYong Li {
234851709ffdSYong Li return "None";
234951709ffdSYong Li }
23503174e4dfSEd Tanous if (dbusAction == "xyz.openbmc_project.State.Watchdog.Action.HardReset")
235151709ffdSYong Li {
235251709ffdSYong Li return "ResetSystem";
235351709ffdSYong Li }
23543174e4dfSEd Tanous if (dbusAction == "xyz.openbmc_project.State.Watchdog.Action.PowerOff")
235551709ffdSYong Li {
235651709ffdSYong Li return "PowerDown";
235751709ffdSYong Li }
23583174e4dfSEd Tanous if (dbusAction == "xyz.openbmc_project.State.Watchdog.Action.PowerCycle")
235951709ffdSYong Li {
236051709ffdSYong Li return "PowerCycle";
236151709ffdSYong Li }
236251709ffdSYong Li
236351709ffdSYong Li return "";
236451709ffdSYong Li }
236551709ffdSYong Li
236651709ffdSYong Li /**
2367c45f0082SYong Li *@brief Translates timeout action from Redfish to DBUS property value.
2368c45f0082SYong Li *
2369c45f0082SYong Li *@param[in] rfAction The timeout action in Redfish.
2370c45f0082SYong Li *
2371c45f0082SYong Li *@return Returns as a string, the time_out action as expected by DBUS.
2372c45f0082SYong Li *If translation cannot be done, returns an empty string.
2373c45f0082SYong Li */
2374c45f0082SYong Li
rfToDbusWDTTimeOutAct(const std::string & rfAction)237523a21a1cSEd Tanous inline std::string rfToDbusWDTTimeOutAct(const std::string& rfAction)
2376c45f0082SYong Li {
2377c45f0082SYong Li if (rfAction == "None")
2378c45f0082SYong Li {
2379c45f0082SYong Li return "xyz.openbmc_project.State.Watchdog.Action.None";
2380c45f0082SYong Li }
23813174e4dfSEd Tanous if (rfAction == "PowerCycle")
2382c45f0082SYong Li {
2383c45f0082SYong Li return "xyz.openbmc_project.State.Watchdog.Action.PowerCycle";
2384c45f0082SYong Li }
23853174e4dfSEd Tanous if (rfAction == "PowerDown")
2386c45f0082SYong Li {
2387c45f0082SYong Li return "xyz.openbmc_project.State.Watchdog.Action.PowerOff";
2388c45f0082SYong Li }
23893174e4dfSEd Tanous if (rfAction == "ResetSystem")
2390c45f0082SYong Li {
2391c45f0082SYong Li return "xyz.openbmc_project.State.Watchdog.Action.HardReset";
2392c45f0082SYong Li }
2393c45f0082SYong Li
2394c45f0082SYong Li return "";
2395c45f0082SYong Li }
2396c45f0082SYong Li
2397c45f0082SYong Li /**
239851709ffdSYong Li * @brief Retrieves host watchdog timer properties over DBUS
239951709ffdSYong Li *
2400ac106bf6SEd Tanous * @param[in] asyncResp Shared pointer for completing asynchronous calls.
240151709ffdSYong Li *
240251709ffdSYong Li * @return None.
240351709ffdSYong Li */
getHostWatchdogTimer(const std::shared_ptr<bmcweb::AsyncResp> & asyncResp)2404*504af5a0SPatrick Williams inline void getHostWatchdogTimer(
2405*504af5a0SPatrick Williams const std::shared_ptr<bmcweb::AsyncResp>& asyncResp)
240651709ffdSYong Li {
240762598e31SEd Tanous BMCWEB_LOG_DEBUG("Get host watchodg");
2408deae6a78SEd Tanous dbus::utility::getAllProperties(
2409deae6a78SEd Tanous "xyz.openbmc_project.Watchdog", "/xyz/openbmc_project/watchdog/host0",
2410bc1d29deSKrzysztof Grobelny "xyz.openbmc_project.State.Watchdog",
2411ac106bf6SEd Tanous [asyncResp](const boost::system::error_code& ec,
2412b9d36b47SEd Tanous const dbus::utility::DBusPropertiesMap& properties) {
241351709ffdSYong Li if (ec)
241451709ffdSYong Li {
241551709ffdSYong Li // watchdog service is stopped
241662598e31SEd Tanous BMCWEB_LOG_DEBUG("DBUS response error {}", ec);
241751709ffdSYong Li return;
241851709ffdSYong Li }
241951709ffdSYong Li
242062598e31SEd Tanous BMCWEB_LOG_DEBUG("Got {} wdt prop.", properties.size());
242151709ffdSYong Li
242251709ffdSYong Li nlohmann::json& hostWatchdogTimer =
2423ac106bf6SEd Tanous asyncResp->res.jsonValue["HostWatchdogTimer"];
242451709ffdSYong Li
242551709ffdSYong Li // watchdog service is running/enabled
2426539d8c6bSEd Tanous hostWatchdogTimer["Status"]["State"] = resource::State::Enabled;
242751709ffdSYong Li
2428bc1d29deSKrzysztof Grobelny const bool* enabled = nullptr;
2429bc1d29deSKrzysztof Grobelny const std::string* expireAction = nullptr;
243051709ffdSYong Li
2431bc1d29deSKrzysztof Grobelny const bool success = sdbusplus::unpackPropertiesNoThrow(
2432bd79bce8SPatrick Williams dbus_utils::UnpackErrorPrinter(), properties, "Enabled",
2433bd79bce8SPatrick Williams enabled, "ExpireAction", expireAction);
2434bc1d29deSKrzysztof Grobelny
2435bc1d29deSKrzysztof Grobelny if (!success)
243651709ffdSYong Li {
2437ac106bf6SEd Tanous messages::internalError(asyncResp->res);
2438601af5edSChicago Duan return;
243951709ffdSYong Li }
244051709ffdSYong Li
2441bc1d29deSKrzysztof Grobelny if (enabled != nullptr)
244251709ffdSYong Li {
2443bc1d29deSKrzysztof Grobelny hostWatchdogTimer["FunctionEnabled"] = *enabled;
244451709ffdSYong Li }
244551709ffdSYong Li
2446bc1d29deSKrzysztof Grobelny if (expireAction != nullptr)
2447bc1d29deSKrzysztof Grobelny {
2448bc1d29deSKrzysztof Grobelny std::string action = dbusToRfWatchdogAction(*expireAction);
244951709ffdSYong Li if (action.empty())
245051709ffdSYong Li {
2451ac106bf6SEd Tanous messages::internalError(asyncResp->res);
2452601af5edSChicago Duan return;
245351709ffdSYong Li }
245451709ffdSYong Li hostWatchdogTimer["TimeoutAction"] = action;
245551709ffdSYong Li }
2456bc1d29deSKrzysztof Grobelny });
245751709ffdSYong Li }
245851709ffdSYong Li
245951709ffdSYong Li /**
2460c45f0082SYong Li * @brief Sets Host WatchDog Timer properties.
2461c45f0082SYong Li *
2462ac106bf6SEd Tanous * @param[in] asyncResp Shared pointer for generating response message.
2463c45f0082SYong Li * @param[in] wdtEnable The WDTimer Enable value (true/false) from incoming
2464c45f0082SYong Li * RF request.
2465c45f0082SYong Li * @param[in] wdtTimeOutAction The WDT Timeout action, from incoming RF request.
2466c45f0082SYong Li *
2467c45f0082SYong Li * @return None.
2468c45f0082SYong Li */
setWDTProperties(const std::shared_ptr<bmcweb::AsyncResp> & asyncResp,const std::optional<bool> wdtEnable,const std::optional<std::string> & wdtTimeOutAction)2469*504af5a0SPatrick Williams inline void setWDTProperties(
2470*504af5a0SPatrick Williams const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
2471c45f0082SYong Li const std::optional<bool> wdtEnable,
2472c45f0082SYong Li const std::optional<std::string>& wdtTimeOutAction)
2473c45f0082SYong Li {
247462598e31SEd Tanous BMCWEB_LOG_DEBUG("Set host watchdog");
2475c45f0082SYong Li
2476c45f0082SYong Li if (wdtTimeOutAction)
2477c45f0082SYong Li {
2478c45f0082SYong Li std::string wdtTimeOutActStr = rfToDbusWDTTimeOutAct(*wdtTimeOutAction);
2479c45f0082SYong Li // check if TimeOut Action is Valid
2480c45f0082SYong Li if (wdtTimeOutActStr.empty())
2481c45f0082SYong Li {
248262598e31SEd Tanous BMCWEB_LOG_DEBUG("Unsupported value for TimeoutAction: {}",
248362598e31SEd Tanous *wdtTimeOutAction);
2484ac106bf6SEd Tanous messages::propertyValueNotInList(asyncResp->res, *wdtTimeOutAction,
2485c45f0082SYong Li "TimeoutAction");
2486c45f0082SYong Li return;
2487c45f0082SYong Li }
2488c45f0082SYong Li
2489e93abac6SGinu George setDbusProperty(asyncResp, "HostWatchdogTimer/TimeoutAction",
2490e93abac6SGinu George "xyz.openbmc_project.Watchdog",
249187c44966SAsmitha Karunanithi sdbusplus::message::object_path(
249287c44966SAsmitha Karunanithi "/xyz/openbmc_project/watchdog/host0"),
24939ae226faSGeorge Liu "xyz.openbmc_project.State.Watchdog", "ExpireAction",
2494e93abac6SGinu George wdtTimeOutActStr);
2495c45f0082SYong Li }
2496c45f0082SYong Li
2497c45f0082SYong Li if (wdtEnable)
2498c45f0082SYong Li {
2499e93abac6SGinu George setDbusProperty(asyncResp, "HostWatchdogTimer/FunctionEnabled",
2500e93abac6SGinu George "xyz.openbmc_project.Watchdog",
250187c44966SAsmitha Karunanithi sdbusplus::message::object_path(
250287c44966SAsmitha Karunanithi "/xyz/openbmc_project/watchdog/host0"),
250387c44966SAsmitha Karunanithi "xyz.openbmc_project.State.Watchdog", "Enabled",
2504e93abac6SGinu George *wdtEnable);
2505c45f0082SYong Li }
2506c45f0082SYong Li }
2507c45f0082SYong Li
250837bbf98cSChris Cain /**
250937bbf98cSChris Cain * @brief Parse the Idle Power Saver properties into json
251037bbf98cSChris Cain *
2511ac106bf6SEd Tanous * @param[in] asyncResp Shared pointer for completing asynchronous calls.
251237bbf98cSChris Cain * @param[in] properties IPS property data from DBus.
251337bbf98cSChris Cain *
251437bbf98cSChris Cain * @return true if successful
251537bbf98cSChris Cain */
parseIpsProperties(const std::shared_ptr<bmcweb::AsyncResp> & asyncResp,const dbus::utility::DBusPropertiesMap & properties)2516*504af5a0SPatrick Williams inline bool parseIpsProperties(
2517*504af5a0SPatrick Williams const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
25181e5b7c88SJiaqing Zhao const dbus::utility::DBusPropertiesMap& properties)
251937bbf98cSChris Cain {
2520bc1d29deSKrzysztof Grobelny const bool* enabled = nullptr;
2521bc1d29deSKrzysztof Grobelny const uint8_t* enterUtilizationPercent = nullptr;
2522bc1d29deSKrzysztof Grobelny const uint64_t* enterDwellTime = nullptr;
2523bc1d29deSKrzysztof Grobelny const uint8_t* exitUtilizationPercent = nullptr;
2524bc1d29deSKrzysztof Grobelny const uint64_t* exitDwellTime = nullptr;
2525bc1d29deSKrzysztof Grobelny
2526bc1d29deSKrzysztof Grobelny const bool success = sdbusplus::unpackPropertiesNoThrow(
2527bc1d29deSKrzysztof Grobelny dbus_utils::UnpackErrorPrinter(), properties, "Enabled", enabled,
25282661b72cSChris Cain "EnterUtilizationPercent", enterUtilizationPercent, "EnterDwellTime",
25292661b72cSChris Cain enterDwellTime, "ExitUtilizationPercent", exitUtilizationPercent,
25302661b72cSChris Cain "ExitDwellTime", exitDwellTime);
2531bc1d29deSKrzysztof Grobelny
2532bc1d29deSKrzysztof Grobelny if (!success)
253337bbf98cSChris Cain {
253437bbf98cSChris Cain return false;
253537bbf98cSChris Cain }
2536bc1d29deSKrzysztof Grobelny
2537bc1d29deSKrzysztof Grobelny if (enabled != nullptr)
253837bbf98cSChris Cain {
2539ac106bf6SEd Tanous asyncResp->res.jsonValue["IdlePowerSaver"]["Enabled"] = *enabled;
254037bbf98cSChris Cain }
2541bc1d29deSKrzysztof Grobelny
2542bc1d29deSKrzysztof Grobelny if (enterUtilizationPercent != nullptr)
254337bbf98cSChris Cain {
2544ac106bf6SEd Tanous asyncResp->res.jsonValue["IdlePowerSaver"]["EnterUtilizationPercent"] =
2545bc1d29deSKrzysztof Grobelny *enterUtilizationPercent;
254637bbf98cSChris Cain }
2547bc1d29deSKrzysztof Grobelny
2548bc1d29deSKrzysztof Grobelny if (enterDwellTime != nullptr)
2549bc1d29deSKrzysztof Grobelny {
2550bc1d29deSKrzysztof Grobelny const std::chrono::duration<uint64_t, std::milli> ms(*enterDwellTime);
2551ac106bf6SEd Tanous asyncResp->res.jsonValue["IdlePowerSaver"]["EnterDwellTimeSeconds"] =
255237bbf98cSChris Cain std::chrono::duration_cast<std::chrono::duration<uint64_t>>(ms)
255337bbf98cSChris Cain .count();
255437bbf98cSChris Cain }
2555bc1d29deSKrzysztof Grobelny
2556bc1d29deSKrzysztof Grobelny if (exitUtilizationPercent != nullptr)
255737bbf98cSChris Cain {
2558ac106bf6SEd Tanous asyncResp->res.jsonValue["IdlePowerSaver"]["ExitUtilizationPercent"] =
2559bc1d29deSKrzysztof Grobelny *exitUtilizationPercent;
256037bbf98cSChris Cain }
2561bc1d29deSKrzysztof Grobelny
2562bc1d29deSKrzysztof Grobelny if (exitDwellTime != nullptr)
256337bbf98cSChris Cain {
2564bc1d29deSKrzysztof Grobelny const std::chrono::duration<uint64_t, std::milli> ms(*exitDwellTime);
2565ac106bf6SEd Tanous asyncResp->res.jsonValue["IdlePowerSaver"]["ExitDwellTimeSeconds"] =
256637bbf98cSChris Cain std::chrono::duration_cast<std::chrono::duration<uint64_t>>(ms)
256737bbf98cSChris Cain .count();
256837bbf98cSChris Cain }
256937bbf98cSChris Cain
257037bbf98cSChris Cain return true;
257137bbf98cSChris Cain }
257237bbf98cSChris Cain
257337bbf98cSChris Cain /**
257437bbf98cSChris Cain * @brief Retrieves host watchdog timer properties over DBUS
257537bbf98cSChris Cain *
2576ac106bf6SEd Tanous * @param[in] asyncResp Shared pointer for completing asynchronous calls.
257737bbf98cSChris Cain *
257837bbf98cSChris Cain * @return None.
257937bbf98cSChris Cain */
getIdlePowerSaver(const std::shared_ptr<bmcweb::AsyncResp> & asyncResp)2580*504af5a0SPatrick Williams inline void getIdlePowerSaver(
2581*504af5a0SPatrick Williams const std::shared_ptr<bmcweb::AsyncResp>& asyncResp)
258237bbf98cSChris Cain {
258362598e31SEd Tanous BMCWEB_LOG_DEBUG("Get idle power saver parameters");
258437bbf98cSChris Cain
258537bbf98cSChris Cain // Get IdlePowerSaver object path:
2586e99073f5SGeorge Liu constexpr std::array<std::string_view, 1> interfaces = {
2587e99073f5SGeorge Liu "xyz.openbmc_project.Control.Power.IdlePowerSaver"};
2588e99073f5SGeorge Liu dbus::utility::getSubTree(
2589e99073f5SGeorge Liu "/", 0, interfaces,
2590ac106bf6SEd Tanous [asyncResp](const boost::system::error_code& ec,
2591b9d36b47SEd Tanous const dbus::utility::MapperGetSubTreeResponse& subtree) {
259237bbf98cSChris Cain if (ec)
259337bbf98cSChris Cain {
2594b3e86cb0SGunnar Mills BMCWEB_LOG_ERROR(
259562598e31SEd Tanous "DBUS response error on Power.IdlePowerSaver GetSubTree {}",
259662598e31SEd Tanous ec);
2597ac106bf6SEd Tanous messages::internalError(asyncResp->res);
259837bbf98cSChris Cain return;
259937bbf98cSChris Cain }
260037bbf98cSChris Cain if (subtree.empty())
260137bbf98cSChris Cain {
260237bbf98cSChris Cain // This is an optional interface so just return
260337bbf98cSChris Cain // if there is no instance found
260462598e31SEd Tanous BMCWEB_LOG_DEBUG("No instances found");
260537bbf98cSChris Cain return;
260637bbf98cSChris Cain }
260737bbf98cSChris Cain if (subtree.size() > 1)
260837bbf98cSChris Cain {
260937bbf98cSChris Cain // More then one PowerIdlePowerSaver object is not supported and
261037bbf98cSChris Cain // is an error
261162598e31SEd Tanous BMCWEB_LOG_DEBUG("Found more than 1 system D-Bus "
261262598e31SEd Tanous "Power.IdlePowerSaver objects: {}",
261362598e31SEd Tanous subtree.size());
2614ac106bf6SEd Tanous messages::internalError(asyncResp->res);
261537bbf98cSChris Cain return;
261637bbf98cSChris Cain }
261737bbf98cSChris Cain if ((subtree[0].first.empty()) || (subtree[0].second.size() != 1))
261837bbf98cSChris Cain {
261962598e31SEd Tanous BMCWEB_LOG_DEBUG("Power.IdlePowerSaver mapper error!");
2620ac106bf6SEd Tanous messages::internalError(asyncResp->res);
262137bbf98cSChris Cain return;
262237bbf98cSChris Cain }
262337bbf98cSChris Cain const std::string& path = subtree[0].first;
262437bbf98cSChris Cain const std::string& service = subtree[0].second.begin()->first;
262537bbf98cSChris Cain if (service.empty())
262637bbf98cSChris Cain {
262762598e31SEd Tanous BMCWEB_LOG_DEBUG("Power.IdlePowerSaver service mapper error!");
2628ac106bf6SEd Tanous messages::internalError(asyncResp->res);
262937bbf98cSChris Cain return;
263037bbf98cSChris Cain }
263137bbf98cSChris Cain
263237bbf98cSChris Cain // Valid IdlePowerSaver object found, now read the current values
2633deae6a78SEd Tanous dbus::utility::getAllProperties(
2634bc1d29deSKrzysztof Grobelny *crow::connections::systemBus, service, path,
2635bc1d29deSKrzysztof Grobelny "xyz.openbmc_project.Control.Power.IdlePowerSaver",
2636bd79bce8SPatrick Williams [asyncResp](
2637bd79bce8SPatrick Williams const boost::system::error_code& ec2,
26381e5b7c88SJiaqing Zhao const dbus::utility::DBusPropertiesMap& properties) {
26398a592810SEd Tanous if (ec2)
264037bbf98cSChris Cain {
264162598e31SEd Tanous BMCWEB_LOG_ERROR(
2642bd79bce8SPatrick Williams "DBUS response error on IdlePowerSaver GetAll: {}",
2643bd79bce8SPatrick Williams ec2);
2644ac106bf6SEd Tanous messages::internalError(asyncResp->res);
264537bbf98cSChris Cain return;
264637bbf98cSChris Cain }
264737bbf98cSChris Cain
2648ac106bf6SEd Tanous if (!parseIpsProperties(asyncResp, properties))
264937bbf98cSChris Cain {
2650ac106bf6SEd Tanous messages::internalError(asyncResp->res);
265137bbf98cSChris Cain return;
265237bbf98cSChris Cain }
2653bc1d29deSKrzysztof Grobelny });
2654e99073f5SGeorge Liu });
265537bbf98cSChris Cain
265662598e31SEd Tanous BMCWEB_LOG_DEBUG("EXIT: Get idle power saver parameters");
265737bbf98cSChris Cain }
265837bbf98cSChris Cain
265937bbf98cSChris Cain /**
266037bbf98cSChris Cain * @brief Sets Idle Power Saver properties.
266137bbf98cSChris Cain *
2662ac106bf6SEd Tanous * @param[in] asyncResp Shared pointer for generating response message.
266337bbf98cSChris Cain * @param[in] ipsEnable The IPS Enable value (true/false) from incoming
266437bbf98cSChris Cain * RF request.
266537bbf98cSChris Cain * @param[in] ipsEnterUtil The utilization limit to enter idle state.
266637bbf98cSChris Cain * @param[in] ipsEnterTime The time the utilization must be below ipsEnterUtil
266737bbf98cSChris Cain * before entering idle state.
266837bbf98cSChris Cain * @param[in] ipsExitUtil The utilization limit when exiting idle state.
266937bbf98cSChris Cain * @param[in] ipsExitTime The time the utilization must be above ipsExutUtil
267037bbf98cSChris Cain * before exiting idle state
267137bbf98cSChris Cain *
267237bbf98cSChris Cain * @return None.
267337bbf98cSChris Cain */
setIdlePowerSaver(const std::shared_ptr<bmcweb::AsyncResp> & asyncResp,const std::optional<bool> ipsEnable,const std::optional<uint8_t> ipsEnterUtil,const std::optional<uint64_t> ipsEnterTime,const std::optional<uint8_t> ipsExitUtil,const std::optional<uint64_t> ipsExitTime)2674bd79bce8SPatrick Williams inline void setIdlePowerSaver(
2675bd79bce8SPatrick Williams const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
267637bbf98cSChris Cain const std::optional<bool> ipsEnable,
267737bbf98cSChris Cain const std::optional<uint8_t> ipsEnterUtil,
267837bbf98cSChris Cain const std::optional<uint64_t> ipsEnterTime,
267937bbf98cSChris Cain const std::optional<uint8_t> ipsExitUtil,
268037bbf98cSChris Cain const std::optional<uint64_t> ipsExitTime)
268137bbf98cSChris Cain {
268262598e31SEd Tanous BMCWEB_LOG_DEBUG("Set idle power saver properties");
268337bbf98cSChris Cain
268437bbf98cSChris Cain // Get IdlePowerSaver object path:
2685e99073f5SGeorge Liu constexpr std::array<std::string_view, 1> interfaces = {
2686e99073f5SGeorge Liu "xyz.openbmc_project.Control.Power.IdlePowerSaver"};
2687e99073f5SGeorge Liu dbus::utility::getSubTree(
2688e99073f5SGeorge Liu "/", 0, interfaces,
2689ac106bf6SEd Tanous [asyncResp, ipsEnable, ipsEnterUtil, ipsEnterTime, ipsExitUtil,
2690e99073f5SGeorge Liu ipsExitTime](const boost::system::error_code& ec,
2691b9d36b47SEd Tanous const dbus::utility::MapperGetSubTreeResponse& subtree) {
269237bbf98cSChris Cain if (ec)
269337bbf98cSChris Cain {
2694b3e86cb0SGunnar Mills BMCWEB_LOG_ERROR(
269562598e31SEd Tanous "DBUS response error on Power.IdlePowerSaver GetSubTree {}",
269662598e31SEd Tanous ec);
2697ac106bf6SEd Tanous messages::internalError(asyncResp->res);
269837bbf98cSChris Cain return;
269937bbf98cSChris Cain }
270037bbf98cSChris Cain if (subtree.empty())
270137bbf98cSChris Cain {
270237bbf98cSChris Cain // This is an optional D-Bus object, but user attempted to patch
2703ac106bf6SEd Tanous messages::resourceNotFound(asyncResp->res, "ComputerSystem",
270437bbf98cSChris Cain "IdlePowerSaver");
270537bbf98cSChris Cain return;
270637bbf98cSChris Cain }
270737bbf98cSChris Cain if (subtree.size() > 1)
270837bbf98cSChris Cain {
270937bbf98cSChris Cain // More then one PowerIdlePowerSaver object is not supported and
271037bbf98cSChris Cain // is an error
271162598e31SEd Tanous BMCWEB_LOG_DEBUG(
271262598e31SEd Tanous "Found more than 1 system D-Bus Power.IdlePowerSaver objects: {}",
271362598e31SEd Tanous subtree.size());
2714ac106bf6SEd Tanous messages::internalError(asyncResp->res);
271537bbf98cSChris Cain return;
271637bbf98cSChris Cain }
271737bbf98cSChris Cain if ((subtree[0].first.empty()) || (subtree[0].second.size() != 1))
271837bbf98cSChris Cain {
271962598e31SEd Tanous BMCWEB_LOG_DEBUG("Power.IdlePowerSaver mapper error!");
2720ac106bf6SEd Tanous messages::internalError(asyncResp->res);
272137bbf98cSChris Cain return;
272237bbf98cSChris Cain }
272337bbf98cSChris Cain const std::string& path = subtree[0].first;
272437bbf98cSChris Cain const std::string& service = subtree[0].second.begin()->first;
272537bbf98cSChris Cain if (service.empty())
272637bbf98cSChris Cain {
272762598e31SEd Tanous BMCWEB_LOG_DEBUG("Power.IdlePowerSaver service mapper error!");
2728ac106bf6SEd Tanous messages::internalError(asyncResp->res);
272937bbf98cSChris Cain return;
273037bbf98cSChris Cain }
273137bbf98cSChris Cain
273237bbf98cSChris Cain // Valid Power IdlePowerSaver object found, now set any values that
273337bbf98cSChris Cain // need to be updated
273437bbf98cSChris Cain
273537bbf98cSChris Cain if (ipsEnable)
273637bbf98cSChris Cain {
2737bd79bce8SPatrick Williams setDbusProperty(
2738bd79bce8SPatrick Williams asyncResp, "IdlePowerSaver/Enabled", service, path,
273987c44966SAsmitha Karunanithi "xyz.openbmc_project.Control.Power.IdlePowerSaver",
2740e93abac6SGinu George "Enabled", *ipsEnable);
274137bbf98cSChris Cain }
274237bbf98cSChris Cain if (ipsEnterUtil)
274337bbf98cSChris Cain {
2744bd79bce8SPatrick Williams setDbusProperty(
2745bd79bce8SPatrick Williams asyncResp, "IdlePowerSaver/EnterUtilizationPercent",
2746e93abac6SGinu George service, path,
27479ae226faSGeorge Liu "xyz.openbmc_project.Control.Power.IdlePowerSaver",
2748e93abac6SGinu George "EnterUtilizationPercent", *ipsEnterUtil);
274937bbf98cSChris Cain }
275037bbf98cSChris Cain if (ipsEnterTime)
275137bbf98cSChris Cain {
275237bbf98cSChris Cain // Convert from seconds into milliseconds for DBus
275337bbf98cSChris Cain const uint64_t timeMilliseconds = *ipsEnterTime * 1000;
2754bd79bce8SPatrick Williams setDbusProperty(
2755bd79bce8SPatrick Williams asyncResp, "IdlePowerSaver/EnterDwellTimeSeconds", service,
2756bd79bce8SPatrick Williams path, "xyz.openbmc_project.Control.Power.IdlePowerSaver",
2757e93abac6SGinu George "EnterDwellTime", timeMilliseconds);
275837bbf98cSChris Cain }
275937bbf98cSChris Cain if (ipsExitUtil)
276037bbf98cSChris Cain {
2761bd79bce8SPatrick Williams setDbusProperty(
2762bd79bce8SPatrick Williams asyncResp, "IdlePowerSaver/ExitUtilizationPercent", service,
2763bd79bce8SPatrick Williams path, "xyz.openbmc_project.Control.Power.IdlePowerSaver",
2764e93abac6SGinu George "ExitUtilizationPercent", *ipsExitUtil);
276537bbf98cSChris Cain }
276637bbf98cSChris Cain if (ipsExitTime)
276737bbf98cSChris Cain {
276837bbf98cSChris Cain // Convert from seconds into milliseconds for DBus
276937bbf98cSChris Cain const uint64_t timeMilliseconds = *ipsExitTime * 1000;
2770bd79bce8SPatrick Williams setDbusProperty(
2771bd79bce8SPatrick Williams asyncResp, "IdlePowerSaver/ExitDwellTimeSeconds", service,
2772bd79bce8SPatrick Williams path, "xyz.openbmc_project.Control.Power.IdlePowerSaver",
2773e93abac6SGinu George "ExitDwellTime", timeMilliseconds);
277437bbf98cSChris Cain }
2775e99073f5SGeorge Liu });
277637bbf98cSChris Cain
277762598e31SEd Tanous BMCWEB_LOG_DEBUG("EXIT: Set idle power saver parameters");
277837bbf98cSChris Cain }
277937bbf98cSChris Cain
handleComputerSystemCollectionHead(crow::App & app,const crow::Request & req,const std::shared_ptr<bmcweb::AsyncResp> & asyncResp)2780c1e219d5SEd Tanous inline void handleComputerSystemCollectionHead(
2781dd60b9edSEd Tanous crow::App& app, const crow::Request& req,
2782dd60b9edSEd Tanous const std::shared_ptr<bmcweb::AsyncResp>& asyncResp)
2783dd60b9edSEd Tanous {
2784dd60b9edSEd Tanous if (!redfish::setUpRedfishRoute(app, req, asyncResp))
2785dd60b9edSEd Tanous {
2786dd60b9edSEd Tanous return;
2787dd60b9edSEd Tanous }
2788dd60b9edSEd Tanous asyncResp->res.addHeader(
2789dd60b9edSEd Tanous boost::beast::http::field::link,
2790dd60b9edSEd Tanous "</redfish/v1/JsonSchemas/ComputerSystemCollection/ComputerSystemCollection.json>; rel=describedby");
2791dd60b9edSEd Tanous }
2792dd60b9edSEd Tanous
handleComputerSystemCollectionGet(crow::App & app,const crow::Request & req,const std::shared_ptr<bmcweb::AsyncResp> & asyncResp)2793c1e219d5SEd Tanous inline void handleComputerSystemCollectionGet(
2794c1e219d5SEd Tanous crow::App& app, const crow::Request& req,
2795c1e219d5SEd Tanous const std::shared_ptr<bmcweb::AsyncResp>& asyncResp)
27961abe55efSEd Tanous {
27973ba00073SCarson Labrado if (!redfish::setUpRedfishRoute(app, req, asyncResp))
2798f4c99e70SEd Tanous {
2799f4c99e70SEd Tanous return;
2800f4c99e70SEd Tanous }
2801dd60b9edSEd Tanous
2802dd60b9edSEd Tanous asyncResp->res.addHeader(
2803dd60b9edSEd Tanous boost::beast::http::field::link,
2804dd60b9edSEd Tanous "</redfish/v1/JsonSchemas/ComputerSystemCollection.json>; rel=describedby");
28058d1b46d7Szhanghch05 asyncResp->res.jsonValue["@odata.type"] =
28060f74e643SEd Tanous "#ComputerSystemCollection.ComputerSystemCollection";
28078d1b46d7Szhanghch05 asyncResp->res.jsonValue["@odata.id"] = "/redfish/v1/Systems";
28088d1b46d7Szhanghch05 asyncResp->res.jsonValue["Name"] = "Computer System Collection";
2809462023adSSunitha Harish
28107f3e84a1SEd Tanous nlohmann::json& ifaceArray = asyncResp->res.jsonValue["Members"];
28117f3e84a1SEd Tanous ifaceArray = nlohmann::json::array();
281225b54dbaSEd Tanous if constexpr (BMCWEB_EXPERIMENTAL_REDFISH_MULTI_COMPUTER_SYSTEM)
28137f3e84a1SEd Tanous {
28147f3e84a1SEd Tanous asyncResp->res.jsonValue["Members@odata.count"] = 0;
28157f3e84a1SEd Tanous // Option currently returns no systems. TBD
28167f3e84a1SEd Tanous return;
28177f3e84a1SEd Tanous }
28187f3e84a1SEd Tanous asyncResp->res.jsonValue["Members@odata.count"] = 1;
28197f3e84a1SEd Tanous nlohmann::json::object_t system;
2820253f11b8SEd Tanous system["@odata.id"] = boost::urls::format("/redfish/v1/Systems/{}",
2821253f11b8SEd Tanous BMCWEB_REDFISH_SYSTEM_URI_NAME);
28227f3e84a1SEd Tanous ifaceArray.emplace_back(std::move(system));
282368896206SGunnar Mills
282468896206SGunnar Mills if constexpr (BMCWEB_HYPERVISOR_COMPUTER_SYSTEM)
2825462023adSSunitha Harish {
282662598e31SEd Tanous BMCWEB_LOG_DEBUG("Hypervisor is available");
282768896206SGunnar Mills asyncResp->res.jsonValue["Members@odata.count"] = 2;
282868896206SGunnar Mills
28291476687dSEd Tanous nlohmann::json::object_t hypervisor;
2830002d39b4SEd Tanous hypervisor["@odata.id"] = "/redfish/v1/Systems/hypervisor";
283168896206SGunnar Mills ifaceArray.emplace_back(std::move(hypervisor));
283268896206SGunnar Mills }
2833c1e219d5SEd Tanous }
2834c1e219d5SEd Tanous
2835c1e219d5SEd Tanous /**
28367e860f15SJohn Edward Broadbent * Function transceives data with dbus directly.
28377e860f15SJohn Edward Broadbent */
doNMI(const std::shared_ptr<bmcweb::AsyncResp> & asyncResp)28384f48d5f6SEd Tanous inline void doNMI(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp)
28397e860f15SJohn Edward Broadbent {
284089492a15SPatrick Williams constexpr const char* serviceName = "xyz.openbmc_project.Control.Host.NMI";
284189492a15SPatrick Williams constexpr const char* objectPath = "/xyz/openbmc_project/control/host0/nmi";
284289492a15SPatrick Williams constexpr const char* interfaceName =
28437e860f15SJohn Edward Broadbent "xyz.openbmc_project.Control.Host.NMI";
284489492a15SPatrick Williams constexpr const char* method = "NMI";
28457e860f15SJohn Edward Broadbent
28467e860f15SJohn Edward Broadbent crow::connections::systemBus->async_method_call(
28475e7e2dc5SEd Tanous [asyncResp](const boost::system::error_code& ec) {
28487e860f15SJohn Edward Broadbent if (ec)
28497e860f15SJohn Edward Broadbent {
285062598e31SEd Tanous BMCWEB_LOG_ERROR(" Bad D-Bus request error: {}", ec);
28517e860f15SJohn Edward Broadbent messages::internalError(asyncResp->res);
28527e860f15SJohn Edward Broadbent return;
28537e860f15SJohn Edward Broadbent }
28547e860f15SJohn Edward Broadbent messages::success(asyncResp->res);
28557e860f15SJohn Edward Broadbent },
28567e860f15SJohn Edward Broadbent serviceName, objectPath, interfaceName, method);
28577e860f15SJohn Edward Broadbent }
2858c5b2abe0SLewanczyk, Dawid
handleComputerSystemResetActionPost(crow::App & app,const crow::Request & req,const std::shared_ptr<bmcweb::AsyncResp> & asyncResp,const std::string & systemName)2859c1e219d5SEd Tanous inline void handleComputerSystemResetActionPost(
2860c1e219d5SEd Tanous crow::App& app, const crow::Request& req,
28617f3e84a1SEd Tanous const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
2862c1e219d5SEd Tanous const std::string& systemName)
2863c1e219d5SEd Tanous {
28643ba00073SCarson Labrado if (!redfish::setUpRedfishRoute(app, req, asyncResp))
286545ca1b86SEd Tanous {
286645ca1b86SEd Tanous return;
286745ca1b86SEd Tanous }
2868dd7090e6SGunnar Mills
2869dd7090e6SGunnar Mills if constexpr (BMCWEB_HYPERVISOR_COMPUTER_SYSTEM)
2870dd7090e6SGunnar Mills {
2871dd7090e6SGunnar Mills if (systemName == "hypervisor")
2872dd7090e6SGunnar Mills {
2873dd7090e6SGunnar Mills handleHypervisorSystemResetPost(req, asyncResp);
2874dd7090e6SGunnar Mills return;
2875dd7090e6SGunnar Mills }
2876dd7090e6SGunnar Mills }
2877dd7090e6SGunnar Mills
2878253f11b8SEd Tanous if (systemName != BMCWEB_REDFISH_SYSTEM_URI_NAME)
2879c1e219d5SEd Tanous {
2880c1e219d5SEd Tanous messages::resourceNotFound(asyncResp->res, "ComputerSystem",
2881c1e219d5SEd Tanous systemName);
2882c1e219d5SEd Tanous return;
2883c1e219d5SEd Tanous }
288425b54dbaSEd Tanous if constexpr (BMCWEB_EXPERIMENTAL_REDFISH_MULTI_COMPUTER_SYSTEM)
28857f3e84a1SEd Tanous {
28867f3e84a1SEd Tanous // Option currently returns no systems. TBD
28877f3e84a1SEd Tanous messages::resourceNotFound(asyncResp->res, "ComputerSystem",
2888c1e219d5SEd Tanous systemName);
28897f3e84a1SEd Tanous return;
28907f3e84a1SEd Tanous }
28919712f8acSEd Tanous std::string resetType;
2892c1e219d5SEd Tanous if (!json_util::readJsonAction(req, asyncResp->res, "ResetType", resetType))
2893cc340dd9SEd Tanous {
2894cc340dd9SEd Tanous return;
2895cc340dd9SEd Tanous }
2896cc340dd9SEd Tanous
2897d22c8396SJason M. Bills // Get the command and host vs. chassis
2898cc340dd9SEd Tanous std::string command;
2899543f4400SEd Tanous bool hostCommand = true;
2900d4d25793SEd Tanous if ((resetType == "On") || (resetType == "ForceOn"))
2901cc340dd9SEd Tanous {
2902cc340dd9SEd Tanous command = "xyz.openbmc_project.State.Host.Transition.On";
2903d22c8396SJason M. Bills hostCommand = true;
2904d22c8396SJason M. Bills }
2905d22c8396SJason M. Bills else if (resetType == "ForceOff")
2906d22c8396SJason M. Bills {
2907d22c8396SJason M. Bills command = "xyz.openbmc_project.State.Chassis.Transition.Off";
2908d22c8396SJason M. Bills hostCommand = false;
2909d22c8396SJason M. Bills }
2910d22c8396SJason M. Bills else if (resetType == "ForceRestart")
2911d22c8396SJason M. Bills {
2912c1e219d5SEd Tanous command = "xyz.openbmc_project.State.Host.Transition.ForceWarmReboot";
291386a0851aSJason M. Bills hostCommand = true;
2914cc340dd9SEd Tanous }
29159712f8acSEd Tanous else if (resetType == "GracefulShutdown")
2916cc340dd9SEd Tanous {
2917cc340dd9SEd Tanous command = "xyz.openbmc_project.State.Host.Transition.Off";
2918d22c8396SJason M. Bills hostCommand = true;
2919cc340dd9SEd Tanous }
29209712f8acSEd Tanous else if (resetType == "GracefulRestart")
2921cc340dd9SEd Tanous {
29220fda0f12SGeorge Liu command =
29230fda0f12SGeorge Liu "xyz.openbmc_project.State.Host.Transition.GracefulWarmReboot";
2924d22c8396SJason M. Bills hostCommand = true;
2925d22c8396SJason M. Bills }
2926d22c8396SJason M. Bills else if (resetType == "PowerCycle")
2927d22c8396SJason M. Bills {
292886a0851aSJason M. Bills command = "xyz.openbmc_project.State.Host.Transition.Reboot";
292986a0851aSJason M. Bills hostCommand = true;
2930cc340dd9SEd Tanous }
2931bfd5b826SLakshminarayana R. Kammath else if (resetType == "Nmi")
2932bfd5b826SLakshminarayana R. Kammath {
2933bfd5b826SLakshminarayana R. Kammath doNMI(asyncResp);
2934bfd5b826SLakshminarayana R. Kammath return;
2935bfd5b826SLakshminarayana R. Kammath }
2936cc340dd9SEd Tanous else
2937cc340dd9SEd Tanous {
2938c1e219d5SEd Tanous messages::actionParameterUnknown(asyncResp->res, "Reset", resetType);
2939cc340dd9SEd Tanous return;
2940cc340dd9SEd Tanous }
2941d02aad39SEd Tanous sdbusplus::message::object_path statePath("/xyz/openbmc_project/state");
2942cc340dd9SEd Tanous
2943d22c8396SJason M. Bills if (hostCommand)
2944d22c8396SJason M. Bills {
2945e93abac6SGinu George setDbusProperty(asyncResp, "Reset", "xyz.openbmc_project.State.Host",
2946d02aad39SEd Tanous statePath / "host0", "xyz.openbmc_project.State.Host",
2947e93abac6SGinu George "RequestedHostTransition", command);
2948cc340dd9SEd Tanous }
2949d22c8396SJason M. Bills else
2950d22c8396SJason M. Bills {
2951e93abac6SGinu George setDbusProperty(asyncResp, "Reset", "xyz.openbmc_project.State.Chassis",
2952d02aad39SEd Tanous statePath / "chassis0",
2953d02aad39SEd Tanous "xyz.openbmc_project.State.Chassis",
2954e93abac6SGinu George "RequestedPowerTransition", command);
2955d22c8396SJason M. Bills }
2956d22c8396SJason M. Bills }
2957cc340dd9SEd Tanous
handleComputerSystemHead(App & app,const crow::Request & req,const std::shared_ptr<bmcweb::AsyncResp> & asyncResp,const std::string &)2958c1e219d5SEd Tanous inline void handleComputerSystemHead(
2959dd60b9edSEd Tanous App& app, const crow::Request& req,
29607f3e84a1SEd Tanous const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
29617f3e84a1SEd Tanous const std::string& /*systemName*/)
2962dd60b9edSEd Tanous {
2963dd60b9edSEd Tanous if (!redfish::setUpRedfishRoute(app, req, asyncResp))
2964dd60b9edSEd Tanous {
2965dd60b9edSEd Tanous return;
2966dd60b9edSEd Tanous }
2967dd60b9edSEd Tanous
2968dd60b9edSEd Tanous asyncResp->res.addHeader(
2969dd60b9edSEd Tanous boost::beast::http::field::link,
2970dd60b9edSEd Tanous "</redfish/v1/JsonSchemas/ComputerSystem/ComputerSystem.json>; rel=describedby");
2971dd60b9edSEd Tanous }
2972dd60b9edSEd Tanous
afterPortRequest(const std::shared_ptr<bmcweb::AsyncResp> & asyncResp,const boost::system::error_code & ec,const std::vector<std::tuple<std::string,std::string,bool>> & socketData)29735c3e9272SAbhishek Patel inline void afterPortRequest(
29745c3e9272SAbhishek Patel const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
29755c3e9272SAbhishek Patel const boost::system::error_code& ec,
29765c3e9272SAbhishek Patel const std::vector<std::tuple<std::string, std::string, bool>>& socketData)
29775c3e9272SAbhishek Patel {
29785c3e9272SAbhishek Patel if (ec)
29795c3e9272SAbhishek Patel {
2980b3e86cb0SGunnar Mills BMCWEB_LOG_ERROR("DBUS response error {}", ec);
29815c3e9272SAbhishek Patel messages::internalError(asyncResp->res);
29825c3e9272SAbhishek Patel return;
29835c3e9272SAbhishek Patel }
29845c3e9272SAbhishek Patel for (const auto& data : socketData)
29855c3e9272SAbhishek Patel {
29865c3e9272SAbhishek Patel const std::string& socketPath = get<0>(data);
29875c3e9272SAbhishek Patel const std::string& protocolName = get<1>(data);
29885c3e9272SAbhishek Patel bool isProtocolEnabled = get<2>(data);
29895c3e9272SAbhishek Patel nlohmann::json& dataJson = asyncResp->res.jsonValue["SerialConsole"];
29905c3e9272SAbhishek Patel dataJson[protocolName]["ServiceEnabled"] = isProtocolEnabled;
29915c3e9272SAbhishek Patel // need to retrieve port number for
29925c3e9272SAbhishek Patel // obmc-console-ssh service
29935c3e9272SAbhishek Patel if (protocolName == "SSH")
29945c3e9272SAbhishek Patel {
29955c3e9272SAbhishek Patel getPortNumber(socketPath, [asyncResp, protocolName](
299681c4e330SEd Tanous const boost::system::error_code& ec1,
29975c3e9272SAbhishek Patel int portNumber) {
29985c3e9272SAbhishek Patel if (ec1)
29995c3e9272SAbhishek Patel {
3000b3e86cb0SGunnar Mills BMCWEB_LOG_ERROR("DBUS response error {}", ec1);
30015c3e9272SAbhishek Patel messages::internalError(asyncResp->res);
30025c3e9272SAbhishek Patel return;
30035c3e9272SAbhishek Patel }
30045c3e9272SAbhishek Patel nlohmann::json& dataJson1 =
30055c3e9272SAbhishek Patel asyncResp->res.jsonValue["SerialConsole"];
30065c3e9272SAbhishek Patel dataJson1[protocolName]["Port"] = portNumber;
30075c3e9272SAbhishek Patel });
30085c3e9272SAbhishek Patel }
30095c3e9272SAbhishek Patel }
30105c3e9272SAbhishek Patel }
3011c1e219d5SEd Tanous
handleComputerSystemGet(crow::App & app,const crow::Request & req,const std::shared_ptr<bmcweb::AsyncResp> & asyncResp,const std::string & systemName)3012*504af5a0SPatrick Williams inline void handleComputerSystemGet(
3013*504af5a0SPatrick Williams crow::App& app, const crow::Request& req,
301422d268cbSEd Tanous const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
3015c1e219d5SEd Tanous const std::string& systemName)
3016c1e219d5SEd Tanous {
30173ba00073SCarson Labrado if (!redfish::setUpRedfishRoute(app, req, asyncResp))
301845ca1b86SEd Tanous {
301945ca1b86SEd Tanous return;
302045ca1b86SEd Tanous }
3021746b56f3SAsmitha Karunanithi
302225b54dbaSEd Tanous if constexpr (BMCWEB_EXPERIMENTAL_REDFISH_MULTI_COMPUTER_SYSTEM)
30237f3e84a1SEd Tanous {
30247f3e84a1SEd Tanous // Option currently returns no systems. TBD
30257f3e84a1SEd Tanous messages::resourceNotFound(asyncResp->res, "ComputerSystem",
30267f3e84a1SEd Tanous systemName);
30277f3e84a1SEd Tanous return;
30287f3e84a1SEd Tanous }
30297f3e84a1SEd Tanous
303068896206SGunnar Mills if constexpr (BMCWEB_HYPERVISOR_COMPUTER_SYSTEM)
303168896206SGunnar Mills {
3032746b56f3SAsmitha Karunanithi if (systemName == "hypervisor")
3033746b56f3SAsmitha Karunanithi {
3034746b56f3SAsmitha Karunanithi handleHypervisorSystemGet(asyncResp);
3035746b56f3SAsmitha Karunanithi return;
3036746b56f3SAsmitha Karunanithi }
303768896206SGunnar Mills }
3038746b56f3SAsmitha Karunanithi
3039253f11b8SEd Tanous if (systemName != BMCWEB_REDFISH_SYSTEM_URI_NAME)
304022d268cbSEd Tanous {
304122d268cbSEd Tanous messages::resourceNotFound(asyncResp->res, "ComputerSystem",
304222d268cbSEd Tanous systemName);
304322d268cbSEd Tanous return;
304422d268cbSEd Tanous }
3045dd60b9edSEd Tanous asyncResp->res.addHeader(
3046dd60b9edSEd Tanous boost::beast::http::field::link,
3047dd60b9edSEd Tanous "</redfish/v1/JsonSchemas/ComputerSystem/ComputerSystem.json>; rel=describedby");
30488d1b46d7Szhanghch05 asyncResp->res.jsonValue["@odata.type"] =
3049b6655101SChris Cain "#ComputerSystem.v1_22_0.ComputerSystem";
3050253f11b8SEd Tanous asyncResp->res.jsonValue["Name"] = BMCWEB_REDFISH_SYSTEM_URI_NAME;
3051253f11b8SEd Tanous asyncResp->res.jsonValue["Id"] = BMCWEB_REDFISH_SYSTEM_URI_NAME;
3052539d8c6bSEd Tanous asyncResp->res.jsonValue["SystemType"] =
3053539d8c6bSEd Tanous computer_system::SystemType::Physical;
30548d1b46d7Szhanghch05 asyncResp->res.jsonValue["Description"] = "Computer System";
30558d1b46d7Szhanghch05 asyncResp->res.jsonValue["ProcessorSummary"]["Count"] = 0;
3056cf0e004cSNinad Palsule asyncResp->res.jsonValue["MemorySummary"]["TotalSystemMemoryGiB"] =
3057dfb2b408SPriyanga Ramasamy double(0);
3058253f11b8SEd Tanous asyncResp->res.jsonValue["@odata.id"] = boost::urls::format(
3059253f11b8SEd Tanous "/redfish/v1/Systems/{}", BMCWEB_REDFISH_SYSTEM_URI_NAME);
306004a258f4SEd Tanous
3061253f11b8SEd Tanous asyncResp->res.jsonValue["Processors"]["@odata.id"] = boost::urls::format(
3062253f11b8SEd Tanous "/redfish/v1/Systems/{}/Processors", BMCWEB_REDFISH_SYSTEM_URI_NAME);
3063253f11b8SEd Tanous asyncResp->res.jsonValue["Memory"]["@odata.id"] = boost::urls::format(
3064253f11b8SEd Tanous "/redfish/v1/Systems/{}/Memory", BMCWEB_REDFISH_SYSTEM_URI_NAME);
3065253f11b8SEd Tanous asyncResp->res.jsonValue["Storage"]["@odata.id"] = boost::urls::format(
3066253f11b8SEd Tanous "/redfish/v1/Systems/{}/Storage", BMCWEB_REDFISH_SYSTEM_URI_NAME);
30673179105bSSunny Srivastava asyncResp->res.jsonValue["FabricAdapters"]["@odata.id"] =
3068253f11b8SEd Tanous boost::urls::format("/redfish/v1/Systems/{}/FabricAdapters",
3069253f11b8SEd Tanous BMCWEB_REDFISH_SYSTEM_URI_NAME);
3070029573d4SEd Tanous
3071002d39b4SEd Tanous asyncResp->res.jsonValue["Actions"]["#ComputerSystem.Reset"]["target"] =
3072253f11b8SEd Tanous boost::urls::format(
3073253f11b8SEd Tanous "/redfish/v1/Systems/{}/Actions/ComputerSystem.Reset",
3074253f11b8SEd Tanous BMCWEB_REDFISH_SYSTEM_URI_NAME);
3075c1e219d5SEd Tanous asyncResp->res
3076c1e219d5SEd Tanous .jsonValue["Actions"]["#ComputerSystem.Reset"]["@Redfish.ActionInfo"] =
3077253f11b8SEd Tanous boost::urls::format("/redfish/v1/Systems/{}/ResetActionInfo",
3078253f11b8SEd Tanous BMCWEB_REDFISH_SYSTEM_URI_NAME);
3079c5b2abe0SLewanczyk, Dawid
3080253f11b8SEd Tanous asyncResp->res.jsonValue["LogServices"]["@odata.id"] = boost::urls::format(
3081253f11b8SEd Tanous "/redfish/v1/Systems/{}/LogServices", BMCWEB_REDFISH_SYSTEM_URI_NAME);
3082253f11b8SEd Tanous asyncResp->res.jsonValue["Bios"]["@odata.id"] = boost::urls::format(
3083253f11b8SEd Tanous "/redfish/v1/Systems/{}/Bios", BMCWEB_REDFISH_SYSTEM_URI_NAME);
3084c4bf6374SJason M. Bills
30851476687dSEd Tanous nlohmann::json::array_t managedBy;
30861476687dSEd Tanous nlohmann::json& manager = managedBy.emplace_back();
3087253f11b8SEd Tanous manager["@odata.id"] = boost::urls::format("/redfish/v1/Managers/{}",
3088253f11b8SEd Tanous BMCWEB_REDFISH_MANAGER_URI_NAME);
3089002d39b4SEd Tanous asyncResp->res.jsonValue["Links"]["ManagedBy"] = std::move(managedBy);
3090539d8c6bSEd Tanous asyncResp->res.jsonValue["Status"]["Health"] = resource::Health::OK;
3091539d8c6bSEd Tanous asyncResp->res.jsonValue["Status"]["State"] = resource::State::Enabled;
30920e8ac5e7SGunnar Mills
30930e8ac5e7SGunnar Mills // Fill in SerialConsole info
3094002d39b4SEd Tanous asyncResp->res.jsonValue["SerialConsole"]["MaxConcurrentSessions"] = 15;
3095c1e219d5SEd Tanous asyncResp->res.jsonValue["SerialConsole"]["IPMI"]["ServiceEnabled"] = true;
30961476687dSEd Tanous
3097c1e219d5SEd Tanous asyncResp->res.jsonValue["SerialConsole"]["SSH"]["ServiceEnabled"] = true;
30981476687dSEd Tanous asyncResp->res.jsonValue["SerialConsole"]["SSH"]["Port"] = 2200;
3099c1e219d5SEd Tanous asyncResp->res.jsonValue["SerialConsole"]["SSH"]["HotKeySequenceDisplay"] =
31001476687dSEd Tanous "Press ~. to exit console";
31015c3e9272SAbhishek Patel getPortStatusAndPath(std::span{protocolToDBusForSystems},
31025c3e9272SAbhishek Patel std::bind_front(afterPortRequest, asyncResp));
31030e8ac5e7SGunnar Mills
310425b54dbaSEd Tanous if constexpr (BMCWEB_KVM)
310525b54dbaSEd Tanous {
31060e8ac5e7SGunnar Mills // Fill in GraphicalConsole info
3107002d39b4SEd Tanous asyncResp->res.jsonValue["GraphicalConsole"]["ServiceEnabled"] = true;
310825b54dbaSEd Tanous asyncResp->res.jsonValue["GraphicalConsole"]["MaxConcurrentSessions"] =
310925b54dbaSEd Tanous 4;
3110613dabeaSEd Tanous asyncResp->res.jsonValue["GraphicalConsole"]["ConnectTypesSupported"] =
3111613dabeaSEd Tanous nlohmann::json::array_t({"KVMIP"});
311225b54dbaSEd Tanous }
311313451e39SWilly Tu
3114bd79bce8SPatrick Williams getMainChassisId(
3115bd79bce8SPatrick Williams asyncResp, [](const std::string& chassisId,
31168d1b46d7Szhanghch05 const std::shared_ptr<bmcweb::AsyncResp>& aRsp) {
3117b2c7e208SEd Tanous nlohmann::json::array_t chassisArray;
3118b2c7e208SEd Tanous nlohmann::json& chassis = chassisArray.emplace_back();
3119bd79bce8SPatrick Williams chassis["@odata.id"] =
3120bd79bce8SPatrick Williams boost::urls::format("/redfish/v1/Chassis/{}", chassisId);
3121002d39b4SEd Tanous aRsp->res.jsonValue["Links"]["Chassis"] = std::move(chassisArray);
3122c5d03ff4SJennifer Lee });
3123a3002228SAppaRao Puli
312459a17e4fSGeorge Liu getSystemLocationIndicatorActive(asyncResp);
31259f8bfa7cSGunnar Mills // TODO (Gunnar): Remove IndicatorLED after enough time has passed
3126a3002228SAppaRao Puli getIndicatorLedState(asyncResp);
312751bd2d8aSGunnar Mills getComputerSystem(asyncResp);
31286c34de48SEd Tanous getHostState(asyncResp);
3129491d8ee7SSantosh Puranik getBootProperties(asyncResp);
3130978b8803SAndrew Geissler getBootProgress(asyncResp);
3131b6d5d45cSHieu Huynh getBootProgressLastStateTime(asyncResp);
313270c4d545SLakshmi Yadlapati pcie_util::getPCIeDeviceList(asyncResp,
313370c4d545SLakshmi Yadlapati nlohmann::json::json_pointer("/PCIeDevices"));
313451709ffdSYong Li getHostWatchdogTimer(asyncResp);
3135c6a620f2SGeorge Liu getPowerRestorePolicy(asyncResp);
31369dcfe8c1SAlbert Zhang getStopBootOnFault(asyncResp);
3137797d5daeSCorey Hardesty getAutomaticRetryPolicy(asyncResp);
3138c0557e1aSGunnar Mills getLastResetTime(asyncResp);
313925b54dbaSEd Tanous if constexpr (BMCWEB_REDFISH_PROVISIONING_FEATURE)
314025b54dbaSEd Tanous {
3141a6349918SAppaRao Puli getProvisioningStatus(asyncResp);
314225b54dbaSEd Tanous }
31431981771bSAli Ahmed getTrustedModuleRequiredToBoot(asyncResp);
31443a2d0424SChris Cain getPowerMode(asyncResp);
314537bbf98cSChris Cain getIdlePowerSaver(asyncResp);
3146c1e219d5SEd Tanous }
3147550a6bf8SJiaqing Zhao
handleComputerSystemPatch(crow::App & app,const crow::Request & req,const std::shared_ptr<bmcweb::AsyncResp> & asyncResp,const std::string & systemName)3148c1e219d5SEd Tanous inline void handleComputerSystemPatch(
3149c1e219d5SEd Tanous crow::App& app, const crow::Request& req,
315022d268cbSEd Tanous const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
3151c1e219d5SEd Tanous const std::string& systemName)
3152c1e219d5SEd Tanous {
31533ba00073SCarson Labrado if (!redfish::setUpRedfishRoute(app, req, asyncResp))
315445ca1b86SEd Tanous {
315545ca1b86SEd Tanous return;
315645ca1b86SEd Tanous }
315725b54dbaSEd Tanous if constexpr (BMCWEB_EXPERIMENTAL_REDFISH_MULTI_COMPUTER_SYSTEM)
31587f3e84a1SEd Tanous {
31597f3e84a1SEd Tanous // Option currently returns no systems. TBD
31607f3e84a1SEd Tanous messages::resourceNotFound(asyncResp->res, "ComputerSystem",
31617f3e84a1SEd Tanous systemName);
31627f3e84a1SEd Tanous return;
31637f3e84a1SEd Tanous }
3164253f11b8SEd Tanous if (systemName != BMCWEB_REDFISH_SYSTEM_URI_NAME)
316522d268cbSEd Tanous {
316622d268cbSEd Tanous messages::resourceNotFound(asyncResp->res, "ComputerSystem",
316722d268cbSEd Tanous systemName);
316822d268cbSEd Tanous return;
316922d268cbSEd Tanous }
317022d268cbSEd Tanous
3171dd60b9edSEd Tanous asyncResp->res.addHeader(
3172dd60b9edSEd Tanous boost::beast::http::field::link,
3173dd60b9edSEd Tanous "</redfish/v1/JsonSchemas/ComputerSystem/ComputerSystem.json>; rel=describedby");
3174dd60b9edSEd Tanous
31759f8bfa7cSGunnar Mills std::optional<bool> locationIndicatorActive;
3176cde19e5fSSantosh Puranik std::optional<std::string> indicatorLed;
317798e386ecSGunnar Mills std::optional<std::string> assetTag;
3178c6a620f2SGeorge Liu std::optional<std::string> powerRestorePolicy;
31793a2d0424SChris Cain std::optional<std::string> powerMode;
3180550a6bf8SJiaqing Zhao std::optional<bool> wdtEnable;
3181550a6bf8SJiaqing Zhao std::optional<std::string> wdtTimeOutAction;
3182550a6bf8SJiaqing Zhao std::optional<std::string> bootSource;
3183550a6bf8SJiaqing Zhao std::optional<std::string> bootType;
3184550a6bf8SJiaqing Zhao std::optional<std::string> bootEnable;
3185550a6bf8SJiaqing Zhao std::optional<std::string> bootAutomaticRetry;
3186797d5daeSCorey Hardesty std::optional<uint32_t> bootAutomaticRetryAttempts;
3187550a6bf8SJiaqing Zhao std::optional<bool> bootTrustedModuleRequired;
31889dcfe8c1SAlbert Zhang std::optional<std::string> stopBootOnFault;
3189550a6bf8SJiaqing Zhao std::optional<bool> ipsEnable;
3190550a6bf8SJiaqing Zhao std::optional<uint8_t> ipsEnterUtil;
3191550a6bf8SJiaqing Zhao std::optional<uint64_t> ipsEnterTime;
3192550a6bf8SJiaqing Zhao std::optional<uint8_t> ipsExitUtil;
3193550a6bf8SJiaqing Zhao std::optional<uint64_t> ipsExitTime;
3194550a6bf8SJiaqing Zhao
3195afc474aeSMyung Bae if (!json_util::readJsonPatch( //
3196afc474aeSMyung Bae req, asyncResp->res, //
3197afc474aeSMyung Bae "AssetTag", assetTag, //
3198afc474aeSMyung Bae "Boot/AutomaticRetryAttempts", bootAutomaticRetryAttempts, //
3199afc474aeSMyung Bae "Boot/AutomaticRetryConfig", bootAutomaticRetry, //
3200afc474aeSMyung Bae "Boot/BootSourceOverrideEnabled", bootEnable, //
3201afc474aeSMyung Bae "Boot/BootSourceOverrideMode", bootType, //
3202afc474aeSMyung Bae "Boot/BootSourceOverrideTarget", bootSource, //
3203afc474aeSMyung Bae "Boot/StopBootOnFault", stopBootOnFault, //
3204afc474aeSMyung Bae "Boot/TrustedModuleRequiredToBoot", bootTrustedModuleRequired, //
3205afc474aeSMyung Bae "HostWatchdogTimer/FunctionEnabled", wdtEnable, //
3206afc474aeSMyung Bae "HostWatchdogTimer/TimeoutAction", wdtTimeOutAction, //
3207afc474aeSMyung Bae "IdlePowerSaver/Enabled", ipsEnable, //
3208afc474aeSMyung Bae "IdlePowerSaver/EnterDwellTimeSeconds", ipsEnterTime, //
3209afc474aeSMyung Bae "IdlePowerSaver/EnterUtilizationPercent", ipsEnterUtil, //
3210afc474aeSMyung Bae "IdlePowerSaver/ExitDwellTimeSeconds", ipsExitTime, //
3211afc474aeSMyung Bae "IdlePowerSaver/ExitUtilizationPercent", ipsExitUtil, //
3212afc474aeSMyung Bae "IndicatorLED", indicatorLed, //
3213afc474aeSMyung Bae "LocationIndicatorActive", locationIndicatorActive, //
3214afc474aeSMyung Bae "PowerMode", powerMode, //
3215afc474aeSMyung Bae "PowerRestorePolicy", powerRestorePolicy //
3216afc474aeSMyung Bae ))
32176617338dSEd Tanous {
32186617338dSEd Tanous return;
32196617338dSEd Tanous }
3220491d8ee7SSantosh Puranik
32218d1b46d7Szhanghch05 asyncResp->res.result(boost::beast::http::status::no_content);
3222c45f0082SYong Li
322398e386ecSGunnar Mills if (assetTag)
322498e386ecSGunnar Mills {
322598e386ecSGunnar Mills setAssetTag(asyncResp, *assetTag);
322698e386ecSGunnar Mills }
322798e386ecSGunnar Mills
3228550a6bf8SJiaqing Zhao if (wdtEnable || wdtTimeOutAction)
3229c45f0082SYong Li {
3230f23b7296SEd Tanous setWDTProperties(asyncResp, wdtEnable, wdtTimeOutAction);
3231c45f0082SYong Li }
3232c45f0082SYong Li
3233cd9a4666SKonstantin Aladyshev if (bootSource || bootType || bootEnable)
323469f35306SGunnar Mills {
3235002d39b4SEd Tanous setBootProperties(asyncResp, bootSource, bootType, bootEnable);
3236491d8ee7SSantosh Puranik }
3237550a6bf8SJiaqing Zhao if (bootAutomaticRetry)
323869f35306SGunnar Mills {
3239550a6bf8SJiaqing Zhao setAutomaticRetry(asyncResp, *bootAutomaticRetry);
324069f35306SGunnar Mills }
3241ac7e1e0bSAli Ahmed
3242797d5daeSCorey Hardesty if (bootAutomaticRetryAttempts)
3243797d5daeSCorey Hardesty {
3244797d5daeSCorey Hardesty setAutomaticRetryAttempts(asyncResp,
3245797d5daeSCorey Hardesty bootAutomaticRetryAttempts.value());
3246797d5daeSCorey Hardesty }
3247797d5daeSCorey Hardesty
3248550a6bf8SJiaqing Zhao if (bootTrustedModuleRequired)
3249ac7e1e0bSAli Ahmed {
3250c1e219d5SEd Tanous setTrustedModuleRequiredToBoot(asyncResp, *bootTrustedModuleRequired);
325169f35306SGunnar Mills }
3252265c1602SJohnathan Mantey
32539dcfe8c1SAlbert Zhang if (stopBootOnFault)
32549dcfe8c1SAlbert Zhang {
32559dcfe8c1SAlbert Zhang setStopBootOnFault(asyncResp, *stopBootOnFault);
32569dcfe8c1SAlbert Zhang }
32579dcfe8c1SAlbert Zhang
32589f8bfa7cSGunnar Mills if (locationIndicatorActive)
32599f8bfa7cSGunnar Mills {
326059a17e4fSGeorge Liu setSystemLocationIndicatorActive(asyncResp, *locationIndicatorActive);
32619f8bfa7cSGunnar Mills }
32629f8bfa7cSGunnar Mills
32637e860f15SJohn Edward Broadbent // TODO (Gunnar): Remove IndicatorLED after enough time has
32647e860f15SJohn Edward Broadbent // passed
32659712f8acSEd Tanous if (indicatorLed)
32666617338dSEd Tanous {
3267f23b7296SEd Tanous setIndicatorLedState(asyncResp, *indicatorLed);
3268002d39b4SEd Tanous asyncResp->res.addHeader(boost::beast::http::field::warning,
3269d6aa0093SGunnar Mills "299 - \"IndicatorLED is deprecated. Use "
3270d6aa0093SGunnar Mills "LocationIndicatorActive instead.\"");
32716617338dSEd Tanous }
3272c6a620f2SGeorge Liu
3273c6a620f2SGeorge Liu if (powerRestorePolicy)
3274c6a620f2SGeorge Liu {
32754e69c904SGunnar Mills setPowerRestorePolicy(asyncResp, *powerRestorePolicy);
3276c6a620f2SGeorge Liu }
32773a2d0424SChris Cain
32783a2d0424SChris Cain if (powerMode)
32793a2d0424SChris Cain {
32803a2d0424SChris Cain setPowerMode(asyncResp, *powerMode);
32813a2d0424SChris Cain }
328237bbf98cSChris Cain
3283c1e219d5SEd Tanous if (ipsEnable || ipsEnterUtil || ipsEnterTime || ipsExitUtil || ipsExitTime)
328437bbf98cSChris Cain {
3285002d39b4SEd Tanous setIdlePowerSaver(asyncResp, ipsEnable, ipsEnterUtil, ipsEnterTime,
3286002d39b4SEd Tanous ipsExitUtil, ipsExitTime);
328737bbf98cSChris Cain }
3288c1e219d5SEd Tanous }
32891cb1a9e6SAppaRao Puli
handleSystemCollectionResetActionHead(crow::App & app,const crow::Request & req,const std::shared_ptr<bmcweb::AsyncResp> & asyncResp,const std::string &)329038c8a6f2SEd Tanous inline void handleSystemCollectionResetActionHead(
3291dd60b9edSEd Tanous crow::App& app, const crow::Request& req,
32927f3e84a1SEd Tanous const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
3293c1e219d5SEd Tanous const std::string& /*systemName*/)
3294dd60b9edSEd Tanous {
3295dd60b9edSEd Tanous if (!redfish::setUpRedfishRoute(app, req, asyncResp))
3296dd60b9edSEd Tanous {
3297dd60b9edSEd Tanous return;
3298dd60b9edSEd Tanous }
3299dd60b9edSEd Tanous asyncResp->res.addHeader(
3300dd60b9edSEd Tanous boost::beast::http::field::link,
3301dd60b9edSEd Tanous "</redfish/v1/JsonSchemas/ActionInfo/ActionInfo.json>; rel=describedby");
3302dd60b9edSEd Tanous }
330333e1f122SAndrew Geissler
330433e1f122SAndrew Geissler /**
330533e1f122SAndrew Geissler * @brief Translates allowed host transitions to redfish string
330633e1f122SAndrew Geissler *
330733e1f122SAndrew Geissler * @param[in] dbusAllowedHostTran The allowed host transition on dbus
330833e1f122SAndrew Geissler * @param[out] allowableValues The translated host transition(s)
330933e1f122SAndrew Geissler *
3310efff2b5dSManojkiran Eda * @return Emplaces corresponding Redfish translated value(s) in
331133e1f122SAndrew Geissler * allowableValues. If translation not possible, does nothing to
331233e1f122SAndrew Geissler * allowableValues.
331333e1f122SAndrew Geissler */
dbusToRfAllowedHostTransitions(const std::string & dbusAllowedHostTran,nlohmann::json::array_t & allowableValues)3314*504af5a0SPatrick Williams inline void dbusToRfAllowedHostTransitions(
3315*504af5a0SPatrick Williams const std::string& dbusAllowedHostTran,
331633e1f122SAndrew Geissler nlohmann::json::array_t& allowableValues)
331733e1f122SAndrew Geissler {
331833e1f122SAndrew Geissler if (dbusAllowedHostTran == "xyz.openbmc_project.State.Host.Transition.On")
331933e1f122SAndrew Geissler {
332033e1f122SAndrew Geissler allowableValues.emplace_back(resource::ResetType::On);
332133e1f122SAndrew Geissler allowableValues.emplace_back(resource::ResetType::ForceOn);
332233e1f122SAndrew Geissler }
332333e1f122SAndrew Geissler else if (dbusAllowedHostTran ==
332433e1f122SAndrew Geissler "xyz.openbmc_project.State.Host.Transition.Off")
332533e1f122SAndrew Geissler {
332633e1f122SAndrew Geissler allowableValues.emplace_back(resource::ResetType::GracefulShutdown);
332733e1f122SAndrew Geissler }
332833e1f122SAndrew Geissler else if (dbusAllowedHostTran ==
332933e1f122SAndrew Geissler "xyz.openbmc_project.State.Host.Transition.GracefulWarmReboot")
333033e1f122SAndrew Geissler {
333133e1f122SAndrew Geissler allowableValues.emplace_back(resource::ResetType::GracefulRestart);
333233e1f122SAndrew Geissler }
333333e1f122SAndrew Geissler else if (dbusAllowedHostTran ==
333433e1f122SAndrew Geissler "xyz.openbmc_project.State.Host.Transition.ForceWarmReboot")
333533e1f122SAndrew Geissler {
333633e1f122SAndrew Geissler allowableValues.emplace_back(resource::ResetType::ForceRestart);
333733e1f122SAndrew Geissler }
333833e1f122SAndrew Geissler else
333933e1f122SAndrew Geissler {
334033e1f122SAndrew Geissler BMCWEB_LOG_WARNING("Unsupported host tran {}", dbusAllowedHostTran);
334133e1f122SAndrew Geissler }
334233e1f122SAndrew Geissler }
334333e1f122SAndrew Geissler
afterGetAllowedHostTransitions(const std::shared_ptr<bmcweb::AsyncResp> & asyncResp,const boost::system::error_code & ec,const std::vector<std::string> & allowedHostTransitions)334433e1f122SAndrew Geissler inline void afterGetAllowedHostTransitions(
334533e1f122SAndrew Geissler const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
334633e1f122SAndrew Geissler const boost::system::error_code& ec,
334733e1f122SAndrew Geissler const std::vector<std::string>& allowedHostTransitions)
334833e1f122SAndrew Geissler {
334933e1f122SAndrew Geissler nlohmann::json::array_t allowableValues;
335033e1f122SAndrew Geissler
335133e1f122SAndrew Geissler // Supported on all systems currently
335233e1f122SAndrew Geissler allowableValues.emplace_back(resource::ResetType::ForceOff);
335333e1f122SAndrew Geissler allowableValues.emplace_back(resource::ResetType::PowerCycle);
335433e1f122SAndrew Geissler allowableValues.emplace_back(resource::ResetType::Nmi);
335533e1f122SAndrew Geissler
335633e1f122SAndrew Geissler if (ec)
335733e1f122SAndrew Geissler {
3358e715d14bSEd Tanous if ((ec.value() ==
3359e715d14bSEd Tanous boost::system::linux_error::bad_request_descriptor) ||
3360e715d14bSEd Tanous (ec.value() == boost::asio::error::basic_errors::host_unreachable))
336133e1f122SAndrew Geissler {
336233e1f122SAndrew Geissler // Property not implemented so just return defaults
336333e1f122SAndrew Geissler BMCWEB_LOG_DEBUG("Property not available {}", ec);
336433e1f122SAndrew Geissler allowableValues.emplace_back(resource::ResetType::On);
336533e1f122SAndrew Geissler allowableValues.emplace_back(resource::ResetType::ForceOn);
336633e1f122SAndrew Geissler allowableValues.emplace_back(resource::ResetType::ForceRestart);
336733e1f122SAndrew Geissler allowableValues.emplace_back(resource::ResetType::GracefulRestart);
336833e1f122SAndrew Geissler allowableValues.emplace_back(resource::ResetType::GracefulShutdown);
336933e1f122SAndrew Geissler }
337033e1f122SAndrew Geissler else
337133e1f122SAndrew Geissler {
337233e1f122SAndrew Geissler BMCWEB_LOG_ERROR("DBUS response error {}", ec);
337333e1f122SAndrew Geissler messages::internalError(asyncResp->res);
337433e1f122SAndrew Geissler return;
337533e1f122SAndrew Geissler }
337633e1f122SAndrew Geissler }
337733e1f122SAndrew Geissler else
337833e1f122SAndrew Geissler {
337933e1f122SAndrew Geissler for (const std::string& transition : allowedHostTransitions)
338033e1f122SAndrew Geissler {
338133e1f122SAndrew Geissler BMCWEB_LOG_DEBUG("Found allowed host tran {}", transition);
338233e1f122SAndrew Geissler dbusToRfAllowedHostTransitions(transition, allowableValues);
338333e1f122SAndrew Geissler }
338433e1f122SAndrew Geissler }
338533e1f122SAndrew Geissler
338633e1f122SAndrew Geissler nlohmann::json::object_t parameter;
338733e1f122SAndrew Geissler parameter["Name"] = "ResetType";
338833e1f122SAndrew Geissler parameter["Required"] = true;
3389539d8c6bSEd Tanous parameter["DataType"] = action_info::ParameterTypes::String;
339033e1f122SAndrew Geissler parameter["AllowableValues"] = std::move(allowableValues);
339133e1f122SAndrew Geissler nlohmann::json::array_t parameters;
339233e1f122SAndrew Geissler parameters.emplace_back(std::move(parameter));
339333e1f122SAndrew Geissler asyncResp->res.jsonValue["Parameters"] = std::move(parameters);
339433e1f122SAndrew Geissler }
339533e1f122SAndrew Geissler
handleSystemCollectionResetActionGet(crow::App & app,const crow::Request & req,const std::shared_ptr<bmcweb::AsyncResp> & asyncResp,const std::string & systemName)3396c1e219d5SEd Tanous inline void handleSystemCollectionResetActionGet(
3397c1e219d5SEd Tanous crow::App& app, const crow::Request& req,
339822d268cbSEd Tanous const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
3399c1e219d5SEd Tanous const std::string& systemName)
3400c1e219d5SEd Tanous {
34013ba00073SCarson Labrado if (!redfish::setUpRedfishRoute(app, req, asyncResp))
340245ca1b86SEd Tanous {
340345ca1b86SEd Tanous return;
340445ca1b86SEd Tanous }
340525b54dbaSEd Tanous if constexpr (BMCWEB_EXPERIMENTAL_REDFISH_MULTI_COMPUTER_SYSTEM)
34067f3e84a1SEd Tanous {
34077f3e84a1SEd Tanous // Option currently returns no systems. TBD
34087f3e84a1SEd Tanous messages::resourceNotFound(asyncResp->res, "ComputerSystem",
34097f3e84a1SEd Tanous systemName);
34107f3e84a1SEd Tanous return;
34117f3e84a1SEd Tanous }
3412746b56f3SAsmitha Karunanithi
341368896206SGunnar Mills if constexpr (BMCWEB_HYPERVISOR_COMPUTER_SYSTEM)
341468896206SGunnar Mills {
3415746b56f3SAsmitha Karunanithi if (systemName == "hypervisor")
3416746b56f3SAsmitha Karunanithi {
3417746b56f3SAsmitha Karunanithi handleHypervisorResetActionGet(asyncResp);
3418746b56f3SAsmitha Karunanithi return;
3419746b56f3SAsmitha Karunanithi }
342068896206SGunnar Mills }
3421746b56f3SAsmitha Karunanithi
3422253f11b8SEd Tanous if (systemName != BMCWEB_REDFISH_SYSTEM_URI_NAME)
342322d268cbSEd Tanous {
342422d268cbSEd Tanous messages::resourceNotFound(asyncResp->res, "ComputerSystem",
342522d268cbSEd Tanous systemName);
342622d268cbSEd Tanous return;
342722d268cbSEd Tanous }
342822d268cbSEd Tanous
3429dd60b9edSEd Tanous asyncResp->res.addHeader(
3430dd60b9edSEd Tanous boost::beast::http::field::link,
3431dd60b9edSEd Tanous "</redfish/v1/JsonSchemas/ActionInfo/ActionInfo.json>; rel=describedby");
34321476687dSEd Tanous
34331476687dSEd Tanous asyncResp->res.jsonValue["@odata.id"] =
3434253f11b8SEd Tanous boost::urls::format("/redfish/v1/Systems/{}/ResetActionInfo",
3435253f11b8SEd Tanous BMCWEB_REDFISH_SYSTEM_URI_NAME);
3436c1e219d5SEd Tanous asyncResp->res.jsonValue["@odata.type"] = "#ActionInfo.v1_1_2.ActionInfo";
34371476687dSEd Tanous asyncResp->res.jsonValue["Name"] = "Reset Action Info";
34381476687dSEd Tanous asyncResp->res.jsonValue["Id"] = "ResetActionInfo";
34393215e700SNan Zhou
344033e1f122SAndrew Geissler // Look to see if system defines AllowedHostTransitions
3441deae6a78SEd Tanous dbus::utility::getProperty<std::vector<std::string>>(
3442deae6a78SEd Tanous "xyz.openbmc_project.State.Host", "/xyz/openbmc_project/state/host0",
3443deae6a78SEd Tanous "xyz.openbmc_project.State.Host", "AllowedHostTransitions",
344433e1f122SAndrew Geissler [asyncResp](const boost::system::error_code& ec,
344533e1f122SAndrew Geissler const std::vector<std::string>& allowedHostTransitions) {
3446bd79bce8SPatrick Williams afterGetAllowedHostTransitions(asyncResp, ec,
3447bd79bce8SPatrick Williams allowedHostTransitions);
344833e1f122SAndrew Geissler });
3449c1e219d5SEd Tanous }
3450c1e219d5SEd Tanous /**
3451c1e219d5SEd Tanous * SystemResetActionInfo derived class for delivering Computer Systems
3452c1e219d5SEd Tanous * ResetType AllowableValues using ResetInfo schema.
3453c1e219d5SEd Tanous */
requestRoutesSystems(App & app)3454100afe56SEd Tanous inline void requestRoutesSystems(App& app)
3455c1e219d5SEd Tanous {
3456100afe56SEd Tanous BMCWEB_ROUTE(app, "/redfish/v1/Systems/")
3457100afe56SEd Tanous .privileges(redfish::privileges::headComputerSystemCollection)
3458100afe56SEd Tanous .methods(boost::beast::http::verb::head)(
3459100afe56SEd Tanous std::bind_front(handleComputerSystemCollectionHead, std::ref(app)));
3460100afe56SEd Tanous
3461100afe56SEd Tanous BMCWEB_ROUTE(app, "/redfish/v1/Systems/")
3462100afe56SEd Tanous .privileges(redfish::privileges::getComputerSystemCollection)
3463100afe56SEd Tanous .methods(boost::beast::http::verb::get)(
3464100afe56SEd Tanous std::bind_front(handleComputerSystemCollectionGet, std::ref(app)));
3465100afe56SEd Tanous
3466100afe56SEd Tanous BMCWEB_ROUTE(app, "/redfish/v1/Systems/<str>/")
3467100afe56SEd Tanous .privileges(redfish::privileges::headComputerSystem)
3468100afe56SEd Tanous .methods(boost::beast::http::verb::head)(
3469100afe56SEd Tanous std::bind_front(handleComputerSystemHead, std::ref(app)));
3470100afe56SEd Tanous
3471100afe56SEd Tanous BMCWEB_ROUTE(app, "/redfish/v1/Systems/<str>/")
3472100afe56SEd Tanous .privileges(redfish::privileges::getComputerSystem)
3473100afe56SEd Tanous .methods(boost::beast::http::verb::get)(
3474100afe56SEd Tanous std::bind_front(handleComputerSystemGet, std::ref(app)));
3475100afe56SEd Tanous
3476100afe56SEd Tanous BMCWEB_ROUTE(app, "/redfish/v1/Systems/<str>/")
3477100afe56SEd Tanous .privileges(redfish::privileges::patchComputerSystem)
3478100afe56SEd Tanous .methods(boost::beast::http::verb::patch)(
3479100afe56SEd Tanous std::bind_front(handleComputerSystemPatch, std::ref(app)));
3480100afe56SEd Tanous
3481100afe56SEd Tanous BMCWEB_ROUTE(app, "/redfish/v1/Systems/<str>/Actions/ComputerSystem.Reset/")
3482100afe56SEd Tanous .privileges(redfish::privileges::postComputerSystem)
3483100afe56SEd Tanous .methods(boost::beast::http::verb::post)(std::bind_front(
3484100afe56SEd Tanous handleComputerSystemResetActionPost, std::ref(app)));
3485100afe56SEd Tanous
3486c1e219d5SEd Tanous BMCWEB_ROUTE(app, "/redfish/v1/Systems/<str>/ResetActionInfo/")
3487c1e219d5SEd Tanous .privileges(redfish::privileges::headActionInfo)
3488c1e219d5SEd Tanous .methods(boost::beast::http::verb::head)(std::bind_front(
3489c1e219d5SEd Tanous handleSystemCollectionResetActionHead, std::ref(app)));
3490c1e219d5SEd Tanous BMCWEB_ROUTE(app, "/redfish/v1/Systems/<str>/ResetActionInfo/")
3491c1e219d5SEd Tanous .privileges(redfish::privileges::getActionInfo)
3492c1e219d5SEd Tanous .methods(boost::beast::http::verb::get)(std::bind_front(
3493c1e219d5SEd Tanous handleSystemCollectionResetActionGet, std::ref(app)));
34941cb1a9e6SAppaRao Puli }
3495c5b2abe0SLewanczyk, Dawid } // namespace redfish
3496