xref: /openbmc/bmcweb/features/redfish/lib/systems.hpp (revision b3e86cb08a818a31760ede5abf7b1ba5c13bb8bb)
1c5b2abe0SLewanczyk, Dawid /*
2c5b2abe0SLewanczyk, Dawid // Copyright (c) 2018 Intel Corporation
3c5b2abe0SLewanczyk, Dawid //
4c5b2abe0SLewanczyk, Dawid // Licensed under the Apache License, Version 2.0 (the "License");
5c5b2abe0SLewanczyk, Dawid // you may not use this file except in compliance with the License.
6c5b2abe0SLewanczyk, Dawid // You may obtain a copy of the License at
7c5b2abe0SLewanczyk, Dawid //
8c5b2abe0SLewanczyk, Dawid //      http://www.apache.org/licenses/LICENSE-2.0
9c5b2abe0SLewanczyk, Dawid //
10c5b2abe0SLewanczyk, Dawid // Unless required by applicable law or agreed to in writing, software
11c5b2abe0SLewanczyk, Dawid // distributed under the License is distributed on an "AS IS" BASIS,
12c5b2abe0SLewanczyk, Dawid // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13c5b2abe0SLewanczyk, Dawid // See the License for the specific language governing permissions and
14c5b2abe0SLewanczyk, Dawid // limitations under the License.
15c5b2abe0SLewanczyk, Dawid */
16c5b2abe0SLewanczyk, Dawid #pragma once
17c5b2abe0SLewanczyk, Dawid 
1813451e39SWilly Tu #include "bmcweb_config.h"
1913451e39SWilly Tu 
203ccb3adbSEd Tanous #include "app.hpp"
211e1e598dSJonathan Doman #include "dbus_singleton.hpp"
227a1dbc48SGeorge Liu #include "dbus_utility.hpp"
238d69c668SEd Tanous #include "generated/enums/computer_system.hpp"
24b49ac873SJames Feist #include "health.hpp"
25746b56f3SAsmitha Karunanithi #include "hypervisor_system.hpp"
261c8fba97SJames Feist #include "led.hpp"
27f4c99e70SEd Tanous #include "query.hpp"
28c5d03ff4SJennifer Lee #include "redfish_util.hpp"
293ccb3adbSEd Tanous #include "registries/privilege_registry.hpp"
303ccb3adbSEd Tanous #include "utils/dbus_utils.hpp"
313ccb3adbSEd Tanous #include "utils/json_utils.hpp"
32472bd202SLakshmi Yadlapati #include "utils/pcie_util.hpp"
333ccb3adbSEd Tanous #include "utils/sw_utils.hpp"
342b82937eSEd Tanous #include "utils/time_utils.hpp"
35c5d03ff4SJennifer Lee 
36fc903b3dSAndrew Geissler #include <boost/asio/error.hpp>
379712f8acSEd Tanous #include <boost/container/flat_map.hpp>
38e99073f5SGeorge Liu #include <boost/system/error_code.hpp>
39ef4c65b7SEd Tanous #include <boost/url/format.hpp>
401e1e598dSJonathan Doman #include <sdbusplus/asio/property.hpp>
41fc903b3dSAndrew Geissler #include <sdbusplus/message.hpp>
42bc1d29deSKrzysztof Grobelny #include <sdbusplus/unpack_properties.hpp>
431214b7e7SGunnar Mills 
447a1dbc48SGeorge Liu #include <array>
457a1dbc48SGeorge Liu #include <string_view>
46abf2add6SEd Tanous #include <variant>
47c5b2abe0SLewanczyk, Dawid 
481abe55efSEd Tanous namespace redfish
491abe55efSEd Tanous {
50c5b2abe0SLewanczyk, Dawid 
515c3e9272SAbhishek Patel const static std::array<std::pair<std::string_view, std::string_view>, 2>
525c3e9272SAbhishek Patel     protocolToDBusForSystems{
535c3e9272SAbhishek Patel         {{"SSH", "obmc-console-ssh"}, {"IPMI", "phosphor-ipmi-net"}}};
545c3e9272SAbhishek Patel 
559d3ae10eSAlpana Kumari /**
569d3ae10eSAlpana Kumari  * @brief Updates the Functional State of DIMMs
579d3ae10eSAlpana Kumari  *
58ac106bf6SEd Tanous  * @param[in] asyncResp Shared pointer for completing asynchronous calls
599d3ae10eSAlpana Kumari  * @param[in] dimmState Dimm's Functional state, true/false
609d3ae10eSAlpana Kumari  *
619d3ae10eSAlpana Kumari  * @return None.
629d3ae10eSAlpana Kumari  */
638d1b46d7Szhanghch05 inline void
64ac106bf6SEd Tanous     updateDimmProperties(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
651e1e598dSJonathan Doman                          bool isDimmFunctional)
669d3ae10eSAlpana Kumari {
6762598e31SEd Tanous     BMCWEB_LOG_DEBUG("Dimm Functional: {}", isDimmFunctional);
689d3ae10eSAlpana Kumari 
699d3ae10eSAlpana Kumari     // Set it as Enabled if at least one DIMM is functional
709d3ae10eSAlpana Kumari     // Update STATE only if previous State was DISABLED and current Dimm is
719d3ae10eSAlpana Kumari     // ENABLED.
7202cad96eSEd Tanous     const nlohmann::json& prevMemSummary =
73ac106bf6SEd Tanous         asyncResp->res.jsonValue["MemorySummary"]["Status"]["State"];
749d3ae10eSAlpana Kumari     if (prevMemSummary == "Disabled")
759d3ae10eSAlpana Kumari     {
76e05aec50SEd Tanous         if (isDimmFunctional)
779d3ae10eSAlpana Kumari         {
78ac106bf6SEd Tanous             asyncResp->res.jsonValue["MemorySummary"]["Status"]["State"] =
799d3ae10eSAlpana Kumari                 "Enabled";
809d3ae10eSAlpana Kumari         }
819d3ae10eSAlpana Kumari     }
829d3ae10eSAlpana Kumari }
839d3ae10eSAlpana Kumari 
8457e8c9beSAlpana Kumari /*
8557e8c9beSAlpana Kumari  * @brief Update "ProcessorSummary" "Status" "State" based on
8657e8c9beSAlpana Kumari  *        CPU Functional State
8757e8c9beSAlpana Kumari  *
88ac106bf6SEd Tanous  * @param[in] asyncResp Shared pointer for completing asynchronous calls
8957e8c9beSAlpana Kumari  * @param[in] cpuFunctionalState is CPU functional true/false
9057e8c9beSAlpana Kumari  *
9157e8c9beSAlpana Kumari  * @return None.
9257e8c9beSAlpana Kumari  */
93ac106bf6SEd Tanous inline void modifyCpuFunctionalState(
94ac106bf6SEd Tanous     const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, bool isCpuFunctional)
9557e8c9beSAlpana Kumari {
9662598e31SEd Tanous     BMCWEB_LOG_DEBUG("Cpu Functional: {}", isCpuFunctional);
9757e8c9beSAlpana Kumari 
9802cad96eSEd Tanous     const nlohmann::json& prevProcState =
99ac106bf6SEd Tanous         asyncResp->res.jsonValue["ProcessorSummary"]["Status"]["State"];
10057e8c9beSAlpana Kumari 
10157e8c9beSAlpana Kumari     // Set it as Enabled if at least one CPU is functional
10257e8c9beSAlpana Kumari     // Update STATE only if previous State was Non_Functional and current CPU is
10357e8c9beSAlpana Kumari     // Functional.
10457e8c9beSAlpana Kumari     if (prevProcState == "Disabled")
10557e8c9beSAlpana Kumari     {
106e05aec50SEd Tanous         if (isCpuFunctional)
10757e8c9beSAlpana Kumari         {
108ac106bf6SEd Tanous             asyncResp->res.jsonValue["ProcessorSummary"]["Status"]["State"] =
10957e8c9beSAlpana Kumari                 "Enabled";
11057e8c9beSAlpana Kumari         }
11157e8c9beSAlpana Kumari     }
11257e8c9beSAlpana Kumari }
11357e8c9beSAlpana Kumari 
114cf0e004cSNinad Palsule /*
115cf0e004cSNinad Palsule  * @brief Update "ProcessorSummary" "Count" based on Cpu PresenceState
116cf0e004cSNinad Palsule  *
117ac106bf6SEd Tanous  * @param[in] asyncResp Shared pointer for completing asynchronous calls
118cf0e004cSNinad Palsule  * @param[in] cpuPresenceState CPU present or not
119cf0e004cSNinad Palsule  *
120cf0e004cSNinad Palsule  * @return None.
121cf0e004cSNinad Palsule  */
122cf0e004cSNinad Palsule inline void
123ac106bf6SEd Tanous     modifyCpuPresenceState(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
124cf0e004cSNinad Palsule                            bool isCpuPresent)
125cf0e004cSNinad Palsule {
12662598e31SEd Tanous     BMCWEB_LOG_DEBUG("Cpu Present: {}", isCpuPresent);
127cf0e004cSNinad Palsule 
128cf0e004cSNinad Palsule     if (isCpuPresent)
129cf0e004cSNinad Palsule     {
130cf0e004cSNinad Palsule         nlohmann::json& procCount =
131ac106bf6SEd Tanous             asyncResp->res.jsonValue["ProcessorSummary"]["Count"];
132cf0e004cSNinad Palsule         auto* procCountPtr =
133cf0e004cSNinad Palsule             procCount.get_ptr<nlohmann::json::number_integer_t*>();
134cf0e004cSNinad Palsule         if (procCountPtr != nullptr)
135cf0e004cSNinad Palsule         {
136cf0e004cSNinad Palsule             // shouldn't be possible to be nullptr
137cf0e004cSNinad Palsule             *procCountPtr += 1;
138cf0e004cSNinad Palsule         }
139cf0e004cSNinad Palsule     }
140cf0e004cSNinad Palsule }
141cf0e004cSNinad Palsule 
142382d6475SAli Ahmed inline void getProcessorProperties(
143ac106bf6SEd Tanous     const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
144382d6475SAli Ahmed     const std::vector<std::pair<std::string, dbus::utility::DbusVariantType>>&
145382d6475SAli Ahmed         properties)
14603fbed92SAli Ahmed {
14762598e31SEd Tanous     BMCWEB_LOG_DEBUG("Got {} Cpu properties.", properties.size());
14803fbed92SAli Ahmed 
14903fbed92SAli Ahmed     // TODO: Get Model
15003fbed92SAli Ahmed 
151bc1d29deSKrzysztof Grobelny     const uint16_t* coreCount = nullptr;
15203fbed92SAli Ahmed 
153bc1d29deSKrzysztof Grobelny     const bool success = sdbusplus::unpackPropertiesNoThrow(
154bc1d29deSKrzysztof Grobelny         dbus_utils::UnpackErrorPrinter(), properties, "CoreCount", coreCount);
15503fbed92SAli Ahmed 
156bc1d29deSKrzysztof Grobelny     if (!success)
15703fbed92SAli Ahmed     {
158ac106bf6SEd Tanous         messages::internalError(asyncResp->res);
15903fbed92SAli Ahmed         return;
16003fbed92SAli Ahmed     }
16103fbed92SAli Ahmed 
162bc1d29deSKrzysztof Grobelny     if (coreCount != nullptr)
16303fbed92SAli Ahmed     {
164bc1d29deSKrzysztof Grobelny         nlohmann::json& coreCountJson =
165ac106bf6SEd Tanous             asyncResp->res.jsonValue["ProcessorSummary"]["CoreCount"];
166bc1d29deSKrzysztof Grobelny         uint64_t* coreCountJsonPtr = coreCountJson.get_ptr<uint64_t*>();
167bc1d29deSKrzysztof Grobelny 
168bc1d29deSKrzysztof Grobelny         if (coreCountJsonPtr == nullptr)
169bc1d29deSKrzysztof Grobelny         {
170bc1d29deSKrzysztof Grobelny             coreCountJson = *coreCount;
17103fbed92SAli Ahmed         }
17203fbed92SAli Ahmed         else
17303fbed92SAli Ahmed         {
174bc1d29deSKrzysztof Grobelny             *coreCountJsonPtr += *coreCount;
17503fbed92SAli Ahmed         }
17603fbed92SAli Ahmed     }
17703fbed92SAli Ahmed }
17803fbed92SAli Ahmed 
17903fbed92SAli Ahmed /*
18003fbed92SAli Ahmed  * @brief Get ProcessorSummary fields
18103fbed92SAli Ahmed  *
182ac106bf6SEd Tanous  * @param[in] asyncResp Shared pointer for completing asynchronous calls
18303fbed92SAli Ahmed  * @param[in] service dbus service for Cpu Information
18403fbed92SAli Ahmed  * @param[in] path dbus path for Cpu
18503fbed92SAli Ahmed  *
18603fbed92SAli Ahmed  * @return None.
18703fbed92SAli Ahmed  */
188ac106bf6SEd Tanous inline void
189ac106bf6SEd Tanous     getProcessorSummary(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
190ac106bf6SEd Tanous                         const std::string& service, const std::string& path)
19103fbed92SAli Ahmed {
192ac106bf6SEd Tanous     auto getCpuPresenceState = [asyncResp](const boost::system::error_code& ec3,
193382d6475SAli Ahmed                                            const bool cpuPresenceCheck) {
194382d6475SAli Ahmed         if (ec3)
195382d6475SAli Ahmed         {
19662598e31SEd Tanous             BMCWEB_LOG_ERROR("DBUS response error {}", ec3);
197382d6475SAli Ahmed             return;
198382d6475SAli Ahmed         }
199ac106bf6SEd Tanous         modifyCpuPresenceState(asyncResp, cpuPresenceCheck);
200382d6475SAli Ahmed     };
201382d6475SAli Ahmed 
202cf0e004cSNinad Palsule     // Get the Presence of CPU
203cf0e004cSNinad Palsule     sdbusplus::asio::getProperty<bool>(
204cf0e004cSNinad Palsule         *crow::connections::systemBus, service, path,
205cf0e004cSNinad Palsule         "xyz.openbmc_project.Inventory.Item", "Present",
206cf0e004cSNinad Palsule         std::move(getCpuPresenceState));
207cf0e004cSNinad Palsule 
2085fd0aafbSNinad Palsule     if constexpr (bmcwebEnableProcMemStatus)
2095fd0aafbSNinad Palsule     {
2105fd0aafbSNinad Palsule         auto getCpuFunctionalState =
211ac106bf6SEd Tanous             [asyncResp](const boost::system::error_code& ec3,
212382d6475SAli Ahmed                         const bool cpuFunctionalCheck) {
213382d6475SAli Ahmed             if (ec3)
214382d6475SAli Ahmed             {
21562598e31SEd Tanous                 BMCWEB_LOG_ERROR("DBUS response error {}", ec3);
216382d6475SAli Ahmed                 return;
217382d6475SAli Ahmed             }
218ac106bf6SEd Tanous             modifyCpuFunctionalState(asyncResp, cpuFunctionalCheck);
219382d6475SAli Ahmed         };
220382d6475SAli Ahmed 
221382d6475SAli Ahmed         // Get the Functional State
222382d6475SAli Ahmed         sdbusplus::asio::getProperty<bool>(
223382d6475SAli Ahmed             *crow::connections::systemBus, service, path,
2245fd0aafbSNinad Palsule             "xyz.openbmc_project.State.Decorator.OperationalStatus",
2255fd0aafbSNinad Palsule             "Functional", std::move(getCpuFunctionalState));
2265fd0aafbSNinad Palsule     }
227382d6475SAli Ahmed 
228bc1d29deSKrzysztof Grobelny     sdbusplus::asio::getAllProperties(
229bc1d29deSKrzysztof Grobelny         *crow::connections::systemBus, service, path,
230bc1d29deSKrzysztof Grobelny         "xyz.openbmc_project.Inventory.Item.Cpu",
231ac106bf6SEd Tanous         [asyncResp, service,
2325e7e2dc5SEd Tanous          path](const boost::system::error_code& ec2,
233b9d36b47SEd Tanous                const dbus::utility::DBusPropertiesMap& properties) {
23403fbed92SAli Ahmed         if (ec2)
23503fbed92SAli Ahmed         {
23662598e31SEd Tanous             BMCWEB_LOG_ERROR("DBUS response error {}", ec2);
237ac106bf6SEd Tanous             messages::internalError(asyncResp->res);
23803fbed92SAli Ahmed             return;
23903fbed92SAli Ahmed         }
240ac106bf6SEd Tanous         getProcessorProperties(asyncResp, properties);
241bc1d29deSKrzysztof Grobelny         });
24203fbed92SAli Ahmed }
24303fbed92SAli Ahmed 
24457e8c9beSAlpana Kumari /*
245cf0e004cSNinad Palsule  * @brief processMemoryProperties fields
246cf0e004cSNinad Palsule  *
247ac106bf6SEd Tanous  * @param[in] asyncResp Shared pointer for completing asynchronous calls
248cf0e004cSNinad Palsule  * @param[in] service dbus service for memory Information
249cf0e004cSNinad Palsule  * @param[in] path dbus path for Memory
250cf0e004cSNinad Palsule  * @param[in] DBUS properties for memory
251cf0e004cSNinad Palsule  *
252cf0e004cSNinad Palsule  * @return None.
253cf0e004cSNinad Palsule  */
254cf0e004cSNinad Palsule inline void
255ac106bf6SEd Tanous     processMemoryProperties(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
2565fd0aafbSNinad Palsule                             [[maybe_unused]] const std::string& service,
2575fd0aafbSNinad Palsule                             [[maybe_unused]] const std::string& path,
258cf0e004cSNinad Palsule                             const dbus::utility::DBusPropertiesMap& properties)
259cf0e004cSNinad Palsule {
26062598e31SEd Tanous     BMCWEB_LOG_DEBUG("Got {} Dimm properties.", properties.size());
261cf0e004cSNinad Palsule 
262cf0e004cSNinad Palsule     if (properties.empty())
263cf0e004cSNinad Palsule     {
2645fd0aafbSNinad Palsule         if constexpr (bmcwebEnableProcMemStatus)
2655fd0aafbSNinad Palsule         {
266cf0e004cSNinad Palsule             sdbusplus::asio::getProperty<bool>(
267cf0e004cSNinad Palsule                 *crow::connections::systemBus, service, path,
268cf0e004cSNinad Palsule                 "xyz.openbmc_project.State."
269cf0e004cSNinad Palsule                 "Decorator.OperationalStatus",
270cf0e004cSNinad Palsule                 "Functional",
271ac106bf6SEd Tanous                 [asyncResp](const boost::system::error_code& ec3,
272ac106bf6SEd Tanous                             bool dimmState) {
273cf0e004cSNinad Palsule                 if (ec3)
274cf0e004cSNinad Palsule                 {
27562598e31SEd Tanous                     BMCWEB_LOG_ERROR("DBUS response error {}", ec3);
276cf0e004cSNinad Palsule                     return;
277cf0e004cSNinad Palsule                 }
278ac106bf6SEd Tanous                 updateDimmProperties(asyncResp, dimmState);
279cf0e004cSNinad Palsule                 });
2805fd0aafbSNinad Palsule         }
281cf0e004cSNinad Palsule         return;
282cf0e004cSNinad Palsule     }
283cf0e004cSNinad Palsule 
284cf0e004cSNinad Palsule     const size_t* memorySizeInKB = nullptr;
285cf0e004cSNinad Palsule 
286cf0e004cSNinad Palsule     const bool success = sdbusplus::unpackPropertiesNoThrow(
287cf0e004cSNinad Palsule         dbus_utils::UnpackErrorPrinter(), properties, "MemorySizeInKB",
288cf0e004cSNinad Palsule         memorySizeInKB);
289cf0e004cSNinad Palsule 
290cf0e004cSNinad Palsule     if (!success)
291cf0e004cSNinad Palsule     {
292ac106bf6SEd Tanous         messages::internalError(asyncResp->res);
293cf0e004cSNinad Palsule         return;
294cf0e004cSNinad Palsule     }
295cf0e004cSNinad Palsule 
296cf0e004cSNinad Palsule     if (memorySizeInKB != nullptr)
297cf0e004cSNinad Palsule     {
298cf0e004cSNinad Palsule         nlohmann::json& totalMemory =
299ac106bf6SEd Tanous             asyncResp->res.jsonValue["MemorySummary"]["TotalSystemMemoryGiB"];
300dfb2b408SPriyanga Ramasamy         const double* preValue = totalMemory.get_ptr<const double*>();
301cf0e004cSNinad Palsule         if (preValue == nullptr)
302cf0e004cSNinad Palsule         {
303ac106bf6SEd Tanous             asyncResp->res.jsonValue["MemorySummary"]["TotalSystemMemoryGiB"] =
304dfb2b408SPriyanga Ramasamy                 static_cast<double>(*memorySizeInKB) / (1024 * 1024);
305cf0e004cSNinad Palsule         }
306cf0e004cSNinad Palsule         else
307cf0e004cSNinad Palsule         {
308ac106bf6SEd Tanous             asyncResp->res.jsonValue["MemorySummary"]["TotalSystemMemoryGiB"] =
309dfb2b408SPriyanga Ramasamy                 static_cast<double>(*memorySizeInKB) / (1024 * 1024) +
310dfb2b408SPriyanga Ramasamy                 *preValue;
311cf0e004cSNinad Palsule         }
3125fd0aafbSNinad Palsule         if constexpr (bmcwebEnableProcMemStatus)
3135fd0aafbSNinad Palsule         {
314ac106bf6SEd Tanous             asyncResp->res.jsonValue["MemorySummary"]["Status"]["State"] =
3155fd0aafbSNinad Palsule                 "Enabled";
3165fd0aafbSNinad Palsule         }
317cf0e004cSNinad Palsule     }
318cf0e004cSNinad Palsule }
319cf0e004cSNinad Palsule 
320cf0e004cSNinad Palsule /*
321cf0e004cSNinad Palsule  * @brief Get getMemorySummary fields
322cf0e004cSNinad Palsule  *
323ac106bf6SEd Tanous  * @param[in] asyncResp Shared pointer for completing asynchronous calls
324cf0e004cSNinad Palsule  * @param[in] service dbus service for memory Information
325cf0e004cSNinad Palsule  * @param[in] path dbus path for memory
326cf0e004cSNinad Palsule  *
327cf0e004cSNinad Palsule  * @return None.
328cf0e004cSNinad Palsule  */
329ac106bf6SEd Tanous inline void
330ac106bf6SEd Tanous     getMemorySummary(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
331ac106bf6SEd Tanous                      const std::string& service, const std::string& path)
332cf0e004cSNinad Palsule {
333cf0e004cSNinad Palsule     sdbusplus::asio::getAllProperties(
334cf0e004cSNinad Palsule         *crow::connections::systemBus, service, path,
335cf0e004cSNinad Palsule         "xyz.openbmc_project.Inventory.Item.Dimm",
336ac106bf6SEd Tanous         [asyncResp, service,
337cf0e004cSNinad Palsule          path](const boost::system::error_code& ec2,
338cf0e004cSNinad Palsule                const dbus::utility::DBusPropertiesMap& properties) {
339cf0e004cSNinad Palsule         if (ec2)
340cf0e004cSNinad Palsule         {
34162598e31SEd Tanous             BMCWEB_LOG_ERROR("DBUS response error {}", ec2);
342ac106bf6SEd Tanous             messages::internalError(asyncResp->res);
343cf0e004cSNinad Palsule             return;
344cf0e004cSNinad Palsule         }
345ac106bf6SEd Tanous         processMemoryProperties(asyncResp, service, path, properties);
346cf0e004cSNinad Palsule         });
347cf0e004cSNinad Palsule }
348cf0e004cSNinad Palsule 
349cf0e004cSNinad Palsule /*
350c5b2abe0SLewanczyk, Dawid  * @brief Retrieves computer system properties over dbus
351c5b2abe0SLewanczyk, Dawid  *
352ac106bf6SEd Tanous  * @param[in] asyncResp Shared pointer for completing asynchronous calls
3538f9ee3cdSGunnar Mills  * @param[in] systemHealth  Shared HealthPopulate pointer
354c5b2abe0SLewanczyk, Dawid  *
355c5b2abe0SLewanczyk, Dawid  * @return None.
356c5b2abe0SLewanczyk, Dawid  */
357b5a76932SEd Tanous inline void
358ac106bf6SEd Tanous     getComputerSystem(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
359b5a76932SEd Tanous                       const std::shared_ptr<HealthPopulate>& systemHealth)
3601abe55efSEd Tanous {
36162598e31SEd Tanous     BMCWEB_LOG_DEBUG("Get available system components.");
362e99073f5SGeorge Liu     constexpr std::array<std::string_view, 5> interfaces = {
363e99073f5SGeorge Liu         "xyz.openbmc_project.Inventory.Decorator.Asset",
364e99073f5SGeorge Liu         "xyz.openbmc_project.Inventory.Item.Cpu",
365e99073f5SGeorge Liu         "xyz.openbmc_project.Inventory.Item.Dimm",
366e99073f5SGeorge Liu         "xyz.openbmc_project.Inventory.Item.System",
367e99073f5SGeorge Liu         "xyz.openbmc_project.Common.UUID",
368e99073f5SGeorge Liu     };
369e99073f5SGeorge Liu     dbus::utility::getSubTree(
370e99073f5SGeorge Liu         "/xyz/openbmc_project/inventory", 0, interfaces,
371ac106bf6SEd Tanous         [asyncResp,
372e99073f5SGeorge Liu          systemHealth](const boost::system::error_code& ec,
373b9d36b47SEd Tanous                        const dbus::utility::MapperGetSubTreeResponse& subtree) {
3741abe55efSEd Tanous         if (ec)
3751abe55efSEd Tanous         {
376*b3e86cb0SGunnar Mills             BMCWEB_LOG_ERROR("DBUS response error {}", ec);
377ac106bf6SEd Tanous             messages::internalError(asyncResp->res);
378c5b2abe0SLewanczyk, Dawid             return;
379c5b2abe0SLewanczyk, Dawid         }
380c5b2abe0SLewanczyk, Dawid         // Iterate over all retrieved ObjectPaths.
381002d39b4SEd Tanous         for (const std::pair<
382002d39b4SEd Tanous                  std::string,
383002d39b4SEd Tanous                  std::vector<std::pair<std::string, std::vector<std::string>>>>&
3841214b7e7SGunnar Mills                  object : subtree)
3851abe55efSEd Tanous         {
386c5b2abe0SLewanczyk, Dawid             const std::string& path = object.first;
38762598e31SEd Tanous             BMCWEB_LOG_DEBUG("Got path: {}", path);
388002d39b4SEd Tanous             const std::vector<std::pair<std::string, std::vector<std::string>>>&
3891214b7e7SGunnar Mills                 connectionNames = object.second;
39026f6976fSEd Tanous             if (connectionNames.empty())
3911abe55efSEd Tanous             {
392c5b2abe0SLewanczyk, Dawid                 continue;
393c5b2abe0SLewanczyk, Dawid             }
394029573d4SEd Tanous 
3955fd0aafbSNinad Palsule             std::shared_ptr<HealthPopulate> memoryHealth = nullptr;
3965fd0aafbSNinad Palsule             std::shared_ptr<HealthPopulate> cpuHealth = nullptr;
3975bc2dc8eSJames Feist 
3985fd0aafbSNinad Palsule             if constexpr (bmcwebEnableProcMemStatus)
3995fd0aafbSNinad Palsule             {
4005fd0aafbSNinad Palsule                 memoryHealth = std::make_shared<HealthPopulate>(
401ac106bf6SEd Tanous                     asyncResp, "/MemorySummary/Status"_json_pointer);
4025fd0aafbSNinad Palsule                 systemHealth->children.emplace_back(memoryHealth);
4035bc2dc8eSJames Feist 
40413451e39SWilly Tu                 if constexpr (bmcwebEnableHealthPopulate)
40513451e39SWilly Tu                 {
4065fd0aafbSNinad Palsule                     cpuHealth = std::make_shared<HealthPopulate>(
407ac106bf6SEd Tanous                         asyncResp, "/ProcessorSummary/Status"_json_pointer);
4085fd0aafbSNinad Palsule 
4095bc2dc8eSJames Feist                     systemHealth->children.emplace_back(cpuHealth);
41013451e39SWilly Tu                 }
4115fd0aafbSNinad Palsule             }
4125bc2dc8eSJames Feist 
4136c34de48SEd Tanous             // This is not system, so check if it's cpu, dimm, UUID or
4146c34de48SEd Tanous             // BiosVer
41504a258f4SEd Tanous             for (const auto& connection : connectionNames)
4161abe55efSEd Tanous             {
41704a258f4SEd Tanous                 for (const auto& interfaceName : connection.second)
4181abe55efSEd Tanous                 {
41904a258f4SEd Tanous                     if (interfaceName ==
42004a258f4SEd Tanous                         "xyz.openbmc_project.Inventory.Item.Dimm")
4211abe55efSEd Tanous                     {
42262598e31SEd Tanous                         BMCWEB_LOG_DEBUG("Found Dimm, now get its properties.");
4239d3ae10eSAlpana Kumari 
424ac106bf6SEd Tanous                         getMemorySummary(asyncResp, connection.first, path);
4255bc2dc8eSJames Feist 
4265fd0aafbSNinad Palsule                         if constexpr (bmcwebEnableProcMemStatus)
4275fd0aafbSNinad Palsule                         {
4285bc2dc8eSJames Feist                             memoryHealth->inventory.emplace_back(path);
4291abe55efSEd Tanous                         }
4305fd0aafbSNinad Palsule                     }
43104a258f4SEd Tanous                     else if (interfaceName ==
43204a258f4SEd Tanous                              "xyz.openbmc_project.Inventory.Item.Cpu")
4331abe55efSEd Tanous                     {
43462598e31SEd Tanous                         BMCWEB_LOG_DEBUG("Found Cpu, now get its properties.");
43557e8c9beSAlpana Kumari 
436ac106bf6SEd Tanous                         getProcessorSummary(asyncResp, connection.first, path);
4375bc2dc8eSJames Feist 
4385fd0aafbSNinad Palsule                         if constexpr (bmcwebEnableProcMemStatus)
4395fd0aafbSNinad Palsule                         {
4405bc2dc8eSJames Feist                             cpuHealth->inventory.emplace_back(path);
4411abe55efSEd Tanous                         }
4425fd0aafbSNinad Palsule                     }
443002d39b4SEd Tanous                     else if (interfaceName == "xyz.openbmc_project.Common.UUID")
4441abe55efSEd Tanous                     {
44562598e31SEd Tanous                         BMCWEB_LOG_DEBUG("Found UUID, now get its properties.");
446bc1d29deSKrzysztof Grobelny 
447bc1d29deSKrzysztof Grobelny                         sdbusplus::asio::getAllProperties(
448bc1d29deSKrzysztof Grobelny                             *crow::connections::systemBus, connection.first,
449bc1d29deSKrzysztof Grobelny                             path, "xyz.openbmc_project.Common.UUID",
450ac106bf6SEd Tanous                             [asyncResp](const boost::system::error_code& ec3,
451b9d36b47SEd Tanous                                         const dbus::utility::DBusPropertiesMap&
4521214b7e7SGunnar Mills                                             properties) {
453cb13a392SEd Tanous                             if (ec3)
4541abe55efSEd Tanous                             {
455*b3e86cb0SGunnar Mills                                 BMCWEB_LOG_ERROR("DBUS response error {}", ec3);
456ac106bf6SEd Tanous                                 messages::internalError(asyncResp->res);
457c5b2abe0SLewanczyk, Dawid                                 return;
458c5b2abe0SLewanczyk, Dawid                             }
45962598e31SEd Tanous                             BMCWEB_LOG_DEBUG("Got {} UUID properties.",
46062598e31SEd Tanous                                              properties.size());
46104a258f4SEd Tanous 
462bc1d29deSKrzysztof Grobelny                             const std::string* uUID = nullptr;
463bc1d29deSKrzysztof Grobelny 
464bc1d29deSKrzysztof Grobelny                             const bool success =
465bc1d29deSKrzysztof Grobelny                                 sdbusplus::unpackPropertiesNoThrow(
466bc1d29deSKrzysztof Grobelny                                     dbus_utils::UnpackErrorPrinter(),
467bc1d29deSKrzysztof Grobelny                                     properties, "UUID", uUID);
468bc1d29deSKrzysztof Grobelny 
469bc1d29deSKrzysztof Grobelny                             if (!success)
4701abe55efSEd Tanous                             {
471ac106bf6SEd Tanous                                 messages::internalError(asyncResp->res);
472bc1d29deSKrzysztof Grobelny                                 return;
473bc1d29deSKrzysztof Grobelny                             }
474bc1d29deSKrzysztof Grobelny 
475bc1d29deSKrzysztof Grobelny                             if (uUID != nullptr)
476bc1d29deSKrzysztof Grobelny                             {
477bc1d29deSKrzysztof Grobelny                                 std::string valueStr = *uUID;
47804a258f4SEd Tanous                                 if (valueStr.size() == 32)
4791abe55efSEd Tanous                                 {
480029573d4SEd Tanous                                     valueStr.insert(8, 1, '-');
481029573d4SEd Tanous                                     valueStr.insert(13, 1, '-');
482029573d4SEd Tanous                                     valueStr.insert(18, 1, '-');
483029573d4SEd Tanous                                     valueStr.insert(23, 1, '-');
48404a258f4SEd Tanous                                 }
48562598e31SEd Tanous                                 BMCWEB_LOG_DEBUG("UUID = {}", valueStr);
486ac106bf6SEd Tanous                                 asyncResp->res.jsonValue["UUID"] = valueStr;
487c5b2abe0SLewanczyk, Dawid                             }
488bc1d29deSKrzysztof Grobelny                             });
489c5b2abe0SLewanczyk, Dawid                     }
490029573d4SEd Tanous                     else if (interfaceName ==
491029573d4SEd Tanous                              "xyz.openbmc_project.Inventory.Item.System")
4921abe55efSEd Tanous                     {
493bc1d29deSKrzysztof Grobelny                         sdbusplus::asio::getAllProperties(
494bc1d29deSKrzysztof Grobelny                             *crow::connections::systemBus, connection.first,
495bc1d29deSKrzysztof Grobelny                             path,
496bc1d29deSKrzysztof Grobelny                             "xyz.openbmc_project.Inventory.Decorator.Asset",
497ac106bf6SEd Tanous                             [asyncResp](const boost::system::error_code& ec2,
498b9d36b47SEd Tanous                                         const dbus::utility::DBusPropertiesMap&
4991214b7e7SGunnar Mills                                             propertiesList) {
500cb13a392SEd Tanous                             if (ec2)
501029573d4SEd Tanous                             {
502e4a4b9a9SJames Feist                                 // doesn't have to include this
503e4a4b9a9SJames Feist                                 // interface
504029573d4SEd Tanous                                 return;
505029573d4SEd Tanous                             }
50662598e31SEd Tanous                             BMCWEB_LOG_DEBUG("Got {} properties for system",
50762598e31SEd Tanous                                              propertiesList.size());
508bc1d29deSKrzysztof Grobelny 
509bc1d29deSKrzysztof Grobelny                             const std::string* partNumber = nullptr;
510bc1d29deSKrzysztof Grobelny                             const std::string* serialNumber = nullptr;
511bc1d29deSKrzysztof Grobelny                             const std::string* manufacturer = nullptr;
512bc1d29deSKrzysztof Grobelny                             const std::string* model = nullptr;
513bc1d29deSKrzysztof Grobelny                             const std::string* subModel = nullptr;
514bc1d29deSKrzysztof Grobelny 
515bc1d29deSKrzysztof Grobelny                             const bool success =
516bc1d29deSKrzysztof Grobelny                                 sdbusplus::unpackPropertiesNoThrow(
517bc1d29deSKrzysztof Grobelny                                     dbus_utils::UnpackErrorPrinter(),
518bc1d29deSKrzysztof Grobelny                                     propertiesList, "PartNumber", partNumber,
519bc1d29deSKrzysztof Grobelny                                     "SerialNumber", serialNumber,
520bc1d29deSKrzysztof Grobelny                                     "Manufacturer", manufacturer, "Model",
521bc1d29deSKrzysztof Grobelny                                     model, "SubModel", subModel);
522bc1d29deSKrzysztof Grobelny 
523bc1d29deSKrzysztof Grobelny                             if (!success)
524029573d4SEd Tanous                             {
525ac106bf6SEd Tanous                                 messages::internalError(asyncResp->res);
526bc1d29deSKrzysztof Grobelny                                 return;
527029573d4SEd Tanous                             }
528bc1d29deSKrzysztof Grobelny 
529bc1d29deSKrzysztof Grobelny                             if (partNumber != nullptr)
530bc1d29deSKrzysztof Grobelny                             {
531ac106bf6SEd Tanous                                 asyncResp->res.jsonValue["PartNumber"] =
532bc1d29deSKrzysztof Grobelny                                     *partNumber;
533029573d4SEd Tanous                             }
534bc1d29deSKrzysztof Grobelny 
535bc1d29deSKrzysztof Grobelny                             if (serialNumber != nullptr)
536bc1d29deSKrzysztof Grobelny                             {
537ac106bf6SEd Tanous                                 asyncResp->res.jsonValue["SerialNumber"] =
538bc1d29deSKrzysztof Grobelny                                     *serialNumber;
539bc1d29deSKrzysztof Grobelny                             }
540bc1d29deSKrzysztof Grobelny 
541bc1d29deSKrzysztof Grobelny                             if (manufacturer != nullptr)
542bc1d29deSKrzysztof Grobelny                             {
543ac106bf6SEd Tanous                                 asyncResp->res.jsonValue["Manufacturer"] =
544bc1d29deSKrzysztof Grobelny                                     *manufacturer;
545bc1d29deSKrzysztof Grobelny                             }
546bc1d29deSKrzysztof Grobelny 
547bc1d29deSKrzysztof Grobelny                             if (model != nullptr)
548bc1d29deSKrzysztof Grobelny                             {
549ac106bf6SEd Tanous                                 asyncResp->res.jsonValue["Model"] = *model;
550bc1d29deSKrzysztof Grobelny                             }
551bc1d29deSKrzysztof Grobelny 
552bc1d29deSKrzysztof Grobelny                             if (subModel != nullptr)
553bc1d29deSKrzysztof Grobelny                             {
554ac106bf6SEd Tanous                                 asyncResp->res.jsonValue["SubModel"] =
555ac106bf6SEd Tanous                                     *subModel;
556fc5afcf9Sbeccabroek                             }
557c1e236a6SGunnar Mills 
558cb7e1e7bSAndrew Geissler                             // Grab the bios version
559eee0013eSWilly Tu                             sw_util::populateSoftwareInformation(
560ac106bf6SEd Tanous                                 asyncResp, sw_util::biosPurpose, "BiosVersion",
561002d39b4SEd Tanous                                 false);
562bc1d29deSKrzysztof Grobelny                             });
563e4a4b9a9SJames Feist 
5641e1e598dSJonathan Doman                         sdbusplus::asio::getProperty<std::string>(
5651e1e598dSJonathan Doman                             *crow::connections::systemBus, connection.first,
5661e1e598dSJonathan Doman                             path,
5671e1e598dSJonathan Doman                             "xyz.openbmc_project.Inventory.Decorator."
5681e1e598dSJonathan Doman                             "AssetTag",
5691e1e598dSJonathan Doman                             "AssetTag",
570ac106bf6SEd Tanous                             [asyncResp](const boost::system::error_code& ec2,
5711e1e598dSJonathan Doman                                         const std::string& value) {
572cb13a392SEd Tanous                             if (ec2)
573e4a4b9a9SJames Feist                             {
574e4a4b9a9SJames Feist                                 // doesn't have to include this
575e4a4b9a9SJames Feist                                 // interface
576e4a4b9a9SJames Feist                                 return;
577e4a4b9a9SJames Feist                             }
578e4a4b9a9SJames Feist 
579ac106bf6SEd Tanous                             asyncResp->res.jsonValue["AssetTag"] = value;
5801e1e598dSJonathan Doman                             });
581029573d4SEd Tanous                     }
582029573d4SEd Tanous                 }
583029573d4SEd Tanous             }
584c5b2abe0SLewanczyk, Dawid         }
5856617338dSEd Tanous         });
586c5b2abe0SLewanczyk, Dawid }
587c5b2abe0SLewanczyk, Dawid 
588c5b2abe0SLewanczyk, Dawid /**
589c5b2abe0SLewanczyk, Dawid  * @brief Retrieves host state properties over dbus
590c5b2abe0SLewanczyk, Dawid  *
591ac106bf6SEd Tanous  * @param[in] asyncResp     Shared pointer for completing asynchronous calls.
592c5b2abe0SLewanczyk, Dawid  *
593c5b2abe0SLewanczyk, Dawid  * @return None.
594c5b2abe0SLewanczyk, Dawid  */
595ac106bf6SEd Tanous inline void getHostState(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp)
5961abe55efSEd Tanous {
59762598e31SEd Tanous     BMCWEB_LOG_DEBUG("Get host information.");
5981e1e598dSJonathan Doman     sdbusplus::asio::getProperty<std::string>(
5991e1e598dSJonathan Doman         *crow::connections::systemBus, "xyz.openbmc_project.State.Host",
6001e1e598dSJonathan Doman         "/xyz/openbmc_project/state/host0", "xyz.openbmc_project.State.Host",
6011e1e598dSJonathan Doman         "CurrentHostState",
602ac106bf6SEd Tanous         [asyncResp](const boost::system::error_code& ec,
6031e1e598dSJonathan Doman                     const std::string& hostState) {
6041abe55efSEd Tanous         if (ec)
6051abe55efSEd Tanous         {
60622228c28SAndrew Geissler             if (ec == boost::system::errc::host_unreachable)
60722228c28SAndrew Geissler             {
60822228c28SAndrew Geissler                 // Service not available, no error, just don't return
60922228c28SAndrew Geissler                 // host state info
61062598e31SEd Tanous                 BMCWEB_LOG_DEBUG("Service not available {}", ec);
61122228c28SAndrew Geissler                 return;
61222228c28SAndrew Geissler             }
61362598e31SEd Tanous             BMCWEB_LOG_ERROR("DBUS response error {}", ec);
614ac106bf6SEd Tanous             messages::internalError(asyncResp->res);
615c5b2abe0SLewanczyk, Dawid             return;
616c5b2abe0SLewanczyk, Dawid         }
6176617338dSEd Tanous 
61862598e31SEd Tanous         BMCWEB_LOG_DEBUG("Host state: {}", hostState);
619c5b2abe0SLewanczyk, Dawid         // Verify Host State
6201e1e598dSJonathan Doman         if (hostState == "xyz.openbmc_project.State.Host.HostState.Running")
6211abe55efSEd Tanous         {
622ac106bf6SEd Tanous             asyncResp->res.jsonValue["PowerState"] = "On";
623ac106bf6SEd Tanous             asyncResp->res.jsonValue["Status"]["State"] = "Enabled";
6241abe55efSEd Tanous         }
6251e1e598dSJonathan Doman         else if (hostState ==
6260fda0f12SGeorge Liu                  "xyz.openbmc_project.State.Host.HostState.Quiesced")
6278c888608SGunnar Mills         {
628ac106bf6SEd Tanous             asyncResp->res.jsonValue["PowerState"] = "On";
629ac106bf6SEd Tanous             asyncResp->res.jsonValue["Status"]["State"] = "Quiesced";
6308c888608SGunnar Mills         }
6311e1e598dSJonathan Doman         else if (hostState ==
6320fda0f12SGeorge Liu                  "xyz.openbmc_project.State.Host.HostState.DiagnosticMode")
63383935af9SAndrew Geissler         {
634ac106bf6SEd Tanous             asyncResp->res.jsonValue["PowerState"] = "On";
635ac106bf6SEd Tanous             asyncResp->res.jsonValue["Status"]["State"] = "InTest";
63683935af9SAndrew Geissler         }
6370fda0f12SGeorge Liu         else if (
6381e1e598dSJonathan Doman             hostState ==
6390fda0f12SGeorge Liu             "xyz.openbmc_project.State.Host.HostState.TransitioningToRunning")
6401a2a1437SAndrew Geissler         {
641ac106bf6SEd Tanous             asyncResp->res.jsonValue["PowerState"] = "PoweringOn";
642ac106bf6SEd Tanous             asyncResp->res.jsonValue["Status"]["State"] = "Starting";
6431a2a1437SAndrew Geissler         }
644002d39b4SEd Tanous         else if (hostState ==
6450fda0f12SGeorge Liu                  "xyz.openbmc_project.State.Host.HostState.TransitioningToOff")
6461a2a1437SAndrew Geissler         {
647ac106bf6SEd Tanous             asyncResp->res.jsonValue["PowerState"] = "PoweringOff";
648ac106bf6SEd Tanous             asyncResp->res.jsonValue["Status"]["State"] = "Disabled";
6491a2a1437SAndrew Geissler         }
6501abe55efSEd Tanous         else
6511abe55efSEd Tanous         {
652ac106bf6SEd Tanous             asyncResp->res.jsonValue["PowerState"] = "Off";
653ac106bf6SEd Tanous             asyncResp->res.jsonValue["Status"]["State"] = "Disabled";
654c5b2abe0SLewanczyk, Dawid         }
6551e1e598dSJonathan Doman         });
656c5b2abe0SLewanczyk, Dawid }
657c5b2abe0SLewanczyk, Dawid 
658c5b2abe0SLewanczyk, Dawid /**
659786d0f60SGunnar Mills  * @brief Translates boot source DBUS property value to redfish.
660491d8ee7SSantosh Puranik  *
661491d8ee7SSantosh Puranik  * @param[in] dbusSource    The boot source in DBUS speak.
662491d8ee7SSantosh Puranik  *
663491d8ee7SSantosh Puranik  * @return Returns as a string, the boot source in Redfish terms. If translation
664491d8ee7SSantosh Puranik  * cannot be done, returns an empty string.
665491d8ee7SSantosh Puranik  */
66623a21a1cSEd Tanous inline std::string dbusToRfBootSource(const std::string& dbusSource)
667491d8ee7SSantosh Puranik {
668491d8ee7SSantosh Puranik     if (dbusSource == "xyz.openbmc_project.Control.Boot.Source.Sources.Default")
669491d8ee7SSantosh Puranik     {
670491d8ee7SSantosh Puranik         return "None";
671491d8ee7SSantosh Puranik     }
6723174e4dfSEd Tanous     if (dbusSource == "xyz.openbmc_project.Control.Boot.Source.Sources.Disk")
673491d8ee7SSantosh Puranik     {
674491d8ee7SSantosh Puranik         return "Hdd";
675491d8ee7SSantosh Puranik     }
6763174e4dfSEd Tanous     if (dbusSource ==
677a71dc0b7SSantosh Puranik         "xyz.openbmc_project.Control.Boot.Source.Sources.ExternalMedia")
678491d8ee7SSantosh Puranik     {
679491d8ee7SSantosh Puranik         return "Cd";
680491d8ee7SSantosh Puranik     }
6813174e4dfSEd Tanous     if (dbusSource == "xyz.openbmc_project.Control.Boot.Source.Sources.Network")
682491d8ee7SSantosh Puranik     {
683491d8ee7SSantosh Puranik         return "Pxe";
684491d8ee7SSantosh Puranik     }
6853174e4dfSEd Tanous     if (dbusSource ==
686944ffaf9SJohnathan Mantey         "xyz.openbmc_project.Control.Boot.Source.Sources.RemovableMedia")
6879f16b2c1SJennifer Lee     {
6889f16b2c1SJennifer Lee         return "Usb";
6899f16b2c1SJennifer Lee     }
690491d8ee7SSantosh Puranik     return "";
691491d8ee7SSantosh Puranik }
692491d8ee7SSantosh Puranik 
693491d8ee7SSantosh Puranik /**
694cd9a4666SKonstantin Aladyshev  * @brief Translates boot type DBUS property value to redfish.
695cd9a4666SKonstantin Aladyshev  *
696cd9a4666SKonstantin Aladyshev  * @param[in] dbusType    The boot type in DBUS speak.
697cd9a4666SKonstantin Aladyshev  *
698cd9a4666SKonstantin Aladyshev  * @return Returns as a string, the boot type in Redfish terms. If translation
699cd9a4666SKonstantin Aladyshev  * cannot be done, returns an empty string.
700cd9a4666SKonstantin Aladyshev  */
701cd9a4666SKonstantin Aladyshev inline std::string dbusToRfBootType(const std::string& dbusType)
702cd9a4666SKonstantin Aladyshev {
703cd9a4666SKonstantin Aladyshev     if (dbusType == "xyz.openbmc_project.Control.Boot.Type.Types.Legacy")
704cd9a4666SKonstantin Aladyshev     {
705cd9a4666SKonstantin Aladyshev         return "Legacy";
706cd9a4666SKonstantin Aladyshev     }
707cd9a4666SKonstantin Aladyshev     if (dbusType == "xyz.openbmc_project.Control.Boot.Type.Types.EFI")
708cd9a4666SKonstantin Aladyshev     {
709cd9a4666SKonstantin Aladyshev         return "UEFI";
710cd9a4666SKonstantin Aladyshev     }
711cd9a4666SKonstantin Aladyshev     return "";
712cd9a4666SKonstantin Aladyshev }
713cd9a4666SKonstantin Aladyshev 
714cd9a4666SKonstantin Aladyshev /**
715786d0f60SGunnar Mills  * @brief Translates boot mode DBUS property value to redfish.
716491d8ee7SSantosh Puranik  *
717491d8ee7SSantosh Puranik  * @param[in] dbusMode    The boot mode in DBUS speak.
718491d8ee7SSantosh Puranik  *
719491d8ee7SSantosh Puranik  * @return Returns as a string, the boot mode in Redfish terms. If translation
720491d8ee7SSantosh Puranik  * cannot be done, returns an empty string.
721491d8ee7SSantosh Puranik  */
72223a21a1cSEd Tanous inline std::string dbusToRfBootMode(const std::string& dbusMode)
723491d8ee7SSantosh Puranik {
724491d8ee7SSantosh Puranik     if (dbusMode == "xyz.openbmc_project.Control.Boot.Mode.Modes.Regular")
725491d8ee7SSantosh Puranik     {
726491d8ee7SSantosh Puranik         return "None";
727491d8ee7SSantosh Puranik     }
7283174e4dfSEd Tanous     if (dbusMode == "xyz.openbmc_project.Control.Boot.Mode.Modes.Safe")
729491d8ee7SSantosh Puranik     {
730491d8ee7SSantosh Puranik         return "Diags";
731491d8ee7SSantosh Puranik     }
7323174e4dfSEd Tanous     if (dbusMode == "xyz.openbmc_project.Control.Boot.Mode.Modes.Setup")
733491d8ee7SSantosh Puranik     {
734491d8ee7SSantosh Puranik         return "BiosSetup";
735491d8ee7SSantosh Puranik     }
736491d8ee7SSantosh Puranik     return "";
737491d8ee7SSantosh Puranik }
738491d8ee7SSantosh Puranik 
739491d8ee7SSantosh Puranik /**
740e43914b3SAndrew Geissler  * @brief Translates boot progress DBUS property value to redfish.
741e43914b3SAndrew Geissler  *
742e43914b3SAndrew Geissler  * @param[in] dbusBootProgress    The boot progress in DBUS speak.
743e43914b3SAndrew Geissler  *
744e43914b3SAndrew Geissler  * @return Returns as a string, the boot progress in Redfish terms. If
745e43914b3SAndrew Geissler  *         translation cannot be done, returns "None".
746e43914b3SAndrew Geissler  */
747e43914b3SAndrew Geissler inline std::string dbusToRfBootProgress(const std::string& dbusBootProgress)
748e43914b3SAndrew Geissler {
749e43914b3SAndrew Geissler     // Now convert the D-Bus BootProgress to the appropriate Redfish
750e43914b3SAndrew Geissler     // enum
751e43914b3SAndrew Geissler     std::string rfBpLastState = "None";
752e43914b3SAndrew Geissler     if (dbusBootProgress == "xyz.openbmc_project.State.Boot.Progress."
753e43914b3SAndrew Geissler                             "ProgressStages.Unspecified")
754e43914b3SAndrew Geissler     {
755e43914b3SAndrew Geissler         rfBpLastState = "None";
756e43914b3SAndrew Geissler     }
757e43914b3SAndrew Geissler     else if (dbusBootProgress ==
758e43914b3SAndrew Geissler              "xyz.openbmc_project.State.Boot.Progress.ProgressStages."
759e43914b3SAndrew Geissler              "PrimaryProcInit")
760e43914b3SAndrew Geissler     {
761e43914b3SAndrew Geissler         rfBpLastState = "PrimaryProcessorInitializationStarted";
762e43914b3SAndrew Geissler     }
763e43914b3SAndrew Geissler     else if (dbusBootProgress ==
764e43914b3SAndrew Geissler              "xyz.openbmc_project.State.Boot.Progress.ProgressStages."
765e43914b3SAndrew Geissler              "BusInit")
766e43914b3SAndrew Geissler     {
767e43914b3SAndrew Geissler         rfBpLastState = "BusInitializationStarted";
768e43914b3SAndrew Geissler     }
769e43914b3SAndrew Geissler     else if (dbusBootProgress ==
770e43914b3SAndrew Geissler              "xyz.openbmc_project.State.Boot.Progress.ProgressStages."
771e43914b3SAndrew Geissler              "MemoryInit")
772e43914b3SAndrew Geissler     {
773e43914b3SAndrew Geissler         rfBpLastState = "MemoryInitializationStarted";
774e43914b3SAndrew Geissler     }
775e43914b3SAndrew Geissler     else if (dbusBootProgress ==
776e43914b3SAndrew Geissler              "xyz.openbmc_project.State.Boot.Progress.ProgressStages."
777e43914b3SAndrew Geissler              "SecondaryProcInit")
778e43914b3SAndrew Geissler     {
779e43914b3SAndrew Geissler         rfBpLastState = "SecondaryProcessorInitializationStarted";
780e43914b3SAndrew Geissler     }
781e43914b3SAndrew Geissler     else if (dbusBootProgress ==
782e43914b3SAndrew Geissler              "xyz.openbmc_project.State.Boot.Progress.ProgressStages."
783e43914b3SAndrew Geissler              "PCIInit")
784e43914b3SAndrew Geissler     {
785e43914b3SAndrew Geissler         rfBpLastState = "PCIResourceConfigStarted";
786e43914b3SAndrew Geissler     }
787e43914b3SAndrew Geissler     else if (dbusBootProgress ==
788e43914b3SAndrew Geissler              "xyz.openbmc_project.State.Boot.Progress.ProgressStages."
789e43914b3SAndrew Geissler              "SystemSetup")
790e43914b3SAndrew Geissler     {
791e43914b3SAndrew Geissler         rfBpLastState = "SetupEntered";
792e43914b3SAndrew Geissler     }
793e43914b3SAndrew Geissler     else if (dbusBootProgress ==
794e43914b3SAndrew Geissler              "xyz.openbmc_project.State.Boot.Progress.ProgressStages."
795e43914b3SAndrew Geissler              "SystemInitComplete")
796e43914b3SAndrew Geissler     {
797e43914b3SAndrew Geissler         rfBpLastState = "SystemHardwareInitializationComplete";
798e43914b3SAndrew Geissler     }
799e43914b3SAndrew Geissler     else if (dbusBootProgress ==
800e43914b3SAndrew Geissler              "xyz.openbmc_project.State.Boot.Progress.ProgressStages."
801e43914b3SAndrew Geissler              "OSStart")
802e43914b3SAndrew Geissler     {
803e43914b3SAndrew Geissler         rfBpLastState = "OSBootStarted";
804e43914b3SAndrew Geissler     }
805e43914b3SAndrew Geissler     else if (dbusBootProgress ==
806e43914b3SAndrew Geissler              "xyz.openbmc_project.State.Boot.Progress.ProgressStages."
807e43914b3SAndrew Geissler              "OSRunning")
808e43914b3SAndrew Geissler     {
809e43914b3SAndrew Geissler         rfBpLastState = "OSRunning";
810e43914b3SAndrew Geissler     }
811e43914b3SAndrew Geissler     else
812e43914b3SAndrew Geissler     {
81362598e31SEd Tanous         BMCWEB_LOG_DEBUG("Unsupported D-Bus BootProgress {}", dbusBootProgress);
814e43914b3SAndrew Geissler         // Just return the default
815e43914b3SAndrew Geissler     }
816e43914b3SAndrew Geissler     return rfBpLastState;
817e43914b3SAndrew Geissler }
818e43914b3SAndrew Geissler 
819e43914b3SAndrew Geissler /**
820786d0f60SGunnar Mills  * @brief Translates boot source from Redfish to the DBus boot paths.
821491d8ee7SSantosh Puranik  *
822491d8ee7SSantosh Puranik  * @param[in] rfSource    The boot source in Redfish.
823944ffaf9SJohnathan Mantey  * @param[out] bootSource The DBus source
824944ffaf9SJohnathan Mantey  * @param[out] bootMode   the DBus boot mode
825491d8ee7SSantosh Puranik  *
826944ffaf9SJohnathan Mantey  * @return Integer error code.
827491d8ee7SSantosh Puranik  */
828ac106bf6SEd Tanous inline int
829ac106bf6SEd Tanous     assignBootParameters(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
830ac106bf6SEd Tanous                          const std::string& rfSource, std::string& bootSource,
831ac106bf6SEd Tanous                          std::string& bootMode)
832491d8ee7SSantosh Puranik {
833c21865c4SKonstantin Aladyshev     bootSource = "xyz.openbmc_project.Control.Boot.Source.Sources.Default";
834c21865c4SKonstantin Aladyshev     bootMode = "xyz.openbmc_project.Control.Boot.Mode.Modes.Regular";
835944ffaf9SJohnathan Mantey 
836491d8ee7SSantosh Puranik     if (rfSource == "None")
837491d8ee7SSantosh Puranik     {
838944ffaf9SJohnathan Mantey         return 0;
839491d8ee7SSantosh Puranik     }
8403174e4dfSEd Tanous     if (rfSource == "Pxe")
841491d8ee7SSantosh Puranik     {
842944ffaf9SJohnathan Mantey         bootSource = "xyz.openbmc_project.Control.Boot.Source.Sources.Network";
843944ffaf9SJohnathan Mantey     }
844944ffaf9SJohnathan Mantey     else if (rfSource == "Hdd")
845944ffaf9SJohnathan Mantey     {
846944ffaf9SJohnathan Mantey         bootSource = "xyz.openbmc_project.Control.Boot.Source.Sources.Disk";
847944ffaf9SJohnathan Mantey     }
848944ffaf9SJohnathan Mantey     else if (rfSource == "Diags")
849944ffaf9SJohnathan Mantey     {
850944ffaf9SJohnathan Mantey         bootMode = "xyz.openbmc_project.Control.Boot.Mode.Modes.Safe";
851944ffaf9SJohnathan Mantey     }
852944ffaf9SJohnathan Mantey     else if (rfSource == "Cd")
853944ffaf9SJohnathan Mantey     {
854944ffaf9SJohnathan Mantey         bootSource =
855944ffaf9SJohnathan Mantey             "xyz.openbmc_project.Control.Boot.Source.Sources.ExternalMedia";
856944ffaf9SJohnathan Mantey     }
857944ffaf9SJohnathan Mantey     else if (rfSource == "BiosSetup")
858944ffaf9SJohnathan Mantey     {
859944ffaf9SJohnathan Mantey         bootMode = "xyz.openbmc_project.Control.Boot.Mode.Modes.Setup";
860491d8ee7SSantosh Puranik     }
8619f16b2c1SJennifer Lee     else if (rfSource == "Usb")
8629f16b2c1SJennifer Lee     {
863944ffaf9SJohnathan Mantey         bootSource =
864944ffaf9SJohnathan Mantey             "xyz.openbmc_project.Control.Boot.Source.Sources.RemovableMedia";
8659f16b2c1SJennifer Lee     }
866491d8ee7SSantosh Puranik     else
867491d8ee7SSantosh Puranik     {
86862598e31SEd Tanous         BMCWEB_LOG_DEBUG(
86962598e31SEd Tanous             "Invalid property value for BootSourceOverrideTarget: {}",
87062598e31SEd Tanous             bootSource);
871ac106bf6SEd Tanous         messages::propertyValueNotInList(asyncResp->res, rfSource,
872944ffaf9SJohnathan Mantey                                          "BootSourceTargetOverride");
873944ffaf9SJohnathan Mantey         return -1;
874491d8ee7SSantosh Puranik     }
875944ffaf9SJohnathan Mantey     return 0;
876491d8ee7SSantosh Puranik }
8771981771bSAli Ahmed 
878978b8803SAndrew Geissler /**
879978b8803SAndrew Geissler  * @brief Retrieves boot progress of the system
880978b8803SAndrew Geissler  *
881ac106bf6SEd Tanous  * @param[in] asyncResp  Shared pointer for generating response message.
882978b8803SAndrew Geissler  *
883978b8803SAndrew Geissler  * @return None.
884978b8803SAndrew Geissler  */
885ac106bf6SEd Tanous inline void getBootProgress(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp)
886978b8803SAndrew Geissler {
8871e1e598dSJonathan Doman     sdbusplus::asio::getProperty<std::string>(
8881e1e598dSJonathan Doman         *crow::connections::systemBus, "xyz.openbmc_project.State.Host",
8891e1e598dSJonathan Doman         "/xyz/openbmc_project/state/host0",
8901e1e598dSJonathan Doman         "xyz.openbmc_project.State.Boot.Progress", "BootProgress",
891ac106bf6SEd Tanous         [asyncResp](const boost::system::error_code& ec,
8921e1e598dSJonathan Doman                     const std::string& bootProgressStr) {
893978b8803SAndrew Geissler         if (ec)
894978b8803SAndrew Geissler         {
895978b8803SAndrew Geissler             // BootProgress is an optional object so just do nothing if
896978b8803SAndrew Geissler             // not found
897978b8803SAndrew Geissler             return;
898978b8803SAndrew Geissler         }
899978b8803SAndrew Geissler 
90062598e31SEd Tanous         BMCWEB_LOG_DEBUG("Boot Progress: {}", bootProgressStr);
901978b8803SAndrew Geissler 
902ac106bf6SEd Tanous         asyncResp->res.jsonValue["BootProgress"]["LastState"] =
903e43914b3SAndrew Geissler             dbusToRfBootProgress(bootProgressStr);
9041e1e598dSJonathan Doman         });
905978b8803SAndrew Geissler }
906491d8ee7SSantosh Puranik 
907491d8ee7SSantosh Puranik /**
908b6d5d45cSHieu Huynh  * @brief Retrieves boot progress Last Update of the system
909b6d5d45cSHieu Huynh  *
910ac106bf6SEd Tanous  * @param[in] asyncResp  Shared pointer for generating response message.
911b6d5d45cSHieu Huynh  *
912b6d5d45cSHieu Huynh  * @return None.
913b6d5d45cSHieu Huynh  */
914b6d5d45cSHieu Huynh inline void getBootProgressLastStateTime(
915ac106bf6SEd Tanous     const std::shared_ptr<bmcweb::AsyncResp>& asyncResp)
916b6d5d45cSHieu Huynh {
917b6d5d45cSHieu Huynh     sdbusplus::asio::getProperty<uint64_t>(
918b6d5d45cSHieu Huynh         *crow::connections::systemBus, "xyz.openbmc_project.State.Host",
919b6d5d45cSHieu Huynh         "/xyz/openbmc_project/state/host0",
920b6d5d45cSHieu Huynh         "xyz.openbmc_project.State.Boot.Progress", "BootProgressLastUpdate",
921ac106bf6SEd Tanous         [asyncResp](const boost::system::error_code& ec,
922b6d5d45cSHieu Huynh                     const uint64_t lastStateTime) {
923b6d5d45cSHieu Huynh         if (ec)
924b6d5d45cSHieu Huynh         {
92562598e31SEd Tanous             BMCWEB_LOG_DEBUG("D-BUS response error {}", ec);
926b6d5d45cSHieu Huynh             return;
927b6d5d45cSHieu Huynh         }
928b6d5d45cSHieu Huynh 
929b6d5d45cSHieu Huynh         // BootProgressLastUpdate is the last time the BootProgress property
930b6d5d45cSHieu Huynh         // was updated. The time is the Epoch time, number of microseconds
931b6d5d45cSHieu Huynh         // since 1 Jan 1970 00::00::00 UTC."
932b6d5d45cSHieu Huynh         // https://github.com/openbmc/phosphor-dbus-interfaces/blob/master/
933b6d5d45cSHieu Huynh         // yaml/xyz/openbmc_project/State/Boot/Progress.interface.yaml#L11
934b6d5d45cSHieu Huynh 
935b6d5d45cSHieu Huynh         // Convert to ISO 8601 standard
936ac106bf6SEd Tanous         asyncResp->res.jsonValue["BootProgress"]["LastStateTime"] =
937b6d5d45cSHieu Huynh             redfish::time_utils::getDateTimeUintUs(lastStateTime);
938b6d5d45cSHieu Huynh         });
939b6d5d45cSHieu Huynh }
940b6d5d45cSHieu Huynh 
941b6d5d45cSHieu Huynh /**
942c21865c4SKonstantin Aladyshev  * @brief Retrieves boot override type over DBUS and fills out the response
943cd9a4666SKonstantin Aladyshev  *
944ac106bf6SEd Tanous  * @param[in] asyncResp         Shared pointer for generating response message.
945cd9a4666SKonstantin Aladyshev  *
946cd9a4666SKonstantin Aladyshev  * @return None.
947cd9a4666SKonstantin Aladyshev  */
948cd9a4666SKonstantin Aladyshev 
949ac106bf6SEd Tanous inline void
950ac106bf6SEd Tanous     getBootOverrideType(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp)
951cd9a4666SKonstantin Aladyshev {
9521e1e598dSJonathan Doman     sdbusplus::asio::getProperty<std::string>(
9531e1e598dSJonathan Doman         *crow::connections::systemBus, "xyz.openbmc_project.Settings",
9541e1e598dSJonathan Doman         "/xyz/openbmc_project/control/host0/boot",
9551e1e598dSJonathan Doman         "xyz.openbmc_project.Control.Boot.Type", "BootType",
956ac106bf6SEd Tanous         [asyncResp](const boost::system::error_code& ec,
9571e1e598dSJonathan Doman                     const std::string& bootType) {
958cd9a4666SKonstantin Aladyshev         if (ec)
959cd9a4666SKonstantin Aladyshev         {
960cd9a4666SKonstantin Aladyshev             // not an error, don't have to have the interface
961cd9a4666SKonstantin Aladyshev             return;
962cd9a4666SKonstantin Aladyshev         }
963cd9a4666SKonstantin Aladyshev 
96462598e31SEd Tanous         BMCWEB_LOG_DEBUG("Boot type: {}", bootType);
965cd9a4666SKonstantin Aladyshev 
966ac106bf6SEd Tanous         asyncResp->res
967ac106bf6SEd Tanous             .jsonValue["Boot"]
968002d39b4SEd Tanous                       ["BootSourceOverrideMode@Redfish.AllowableValues"] =
969613dabeaSEd Tanous             nlohmann::json::array_t({"Legacy", "UEFI"});
970cd9a4666SKonstantin Aladyshev 
9711e1e598dSJonathan Doman         auto rfType = dbusToRfBootType(bootType);
972cd9a4666SKonstantin Aladyshev         if (rfType.empty())
973cd9a4666SKonstantin Aladyshev         {
974ac106bf6SEd Tanous             messages::internalError(asyncResp->res);
975cd9a4666SKonstantin Aladyshev             return;
976cd9a4666SKonstantin Aladyshev         }
977cd9a4666SKonstantin Aladyshev 
978ac106bf6SEd Tanous         asyncResp->res.jsonValue["Boot"]["BootSourceOverrideMode"] = rfType;
9791e1e598dSJonathan Doman         });
980cd9a4666SKonstantin Aladyshev }
981cd9a4666SKonstantin Aladyshev 
982cd9a4666SKonstantin Aladyshev /**
983c21865c4SKonstantin Aladyshev  * @brief Retrieves boot override mode over DBUS and fills out the response
984491d8ee7SSantosh Puranik  *
985ac106bf6SEd Tanous  * @param[in] asyncResp         Shared pointer for generating response message.
986491d8ee7SSantosh Puranik  *
987491d8ee7SSantosh Puranik  * @return None.
988491d8ee7SSantosh Puranik  */
989c21865c4SKonstantin Aladyshev 
990ac106bf6SEd Tanous inline void
991ac106bf6SEd Tanous     getBootOverrideMode(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp)
992491d8ee7SSantosh Puranik {
9931e1e598dSJonathan Doman     sdbusplus::asio::getProperty<std::string>(
9941e1e598dSJonathan Doman         *crow::connections::systemBus, "xyz.openbmc_project.Settings",
9951e1e598dSJonathan Doman         "/xyz/openbmc_project/control/host0/boot",
9961e1e598dSJonathan Doman         "xyz.openbmc_project.Control.Boot.Mode", "BootMode",
997ac106bf6SEd Tanous         [asyncResp](const boost::system::error_code& ec,
9981e1e598dSJonathan Doman                     const std::string& bootModeStr) {
999491d8ee7SSantosh Puranik         if (ec)
1000491d8ee7SSantosh Puranik         {
1001*b3e86cb0SGunnar Mills             BMCWEB_LOG_ERROR("DBUS response error {}", ec);
1002ac106bf6SEd Tanous             messages::internalError(asyncResp->res);
1003491d8ee7SSantosh Puranik             return;
1004491d8ee7SSantosh Puranik         }
1005491d8ee7SSantosh Puranik 
100662598e31SEd Tanous         BMCWEB_LOG_DEBUG("Boot mode: {}", bootModeStr);
1007491d8ee7SSantosh Puranik 
1008ac106bf6SEd Tanous         asyncResp->res
10090fda0f12SGeorge Liu             .jsonValue["Boot"]
1010002d39b4SEd Tanous                       ["BootSourceOverrideTarget@Redfish.AllowableValues"] = {
1011002d39b4SEd Tanous             "None", "Pxe", "Hdd", "Cd", "Diags", "BiosSetup", "Usb"};
1012491d8ee7SSantosh Puranik 
10131e1e598dSJonathan Doman         if (bootModeStr !=
1014491d8ee7SSantosh Puranik             "xyz.openbmc_project.Control.Boot.Mode.Modes.Regular")
1015491d8ee7SSantosh Puranik         {
10161e1e598dSJonathan Doman             auto rfMode = dbusToRfBootMode(bootModeStr);
1017491d8ee7SSantosh Puranik             if (!rfMode.empty())
1018491d8ee7SSantosh Puranik             {
1019ac106bf6SEd Tanous                 asyncResp->res.jsonValue["Boot"]["BootSourceOverrideTarget"] =
1020491d8ee7SSantosh Puranik                     rfMode;
1021491d8ee7SSantosh Puranik             }
1022491d8ee7SSantosh Puranik         }
10231e1e598dSJonathan Doman         });
1024491d8ee7SSantosh Puranik }
1025491d8ee7SSantosh Puranik 
1026491d8ee7SSantosh Puranik /**
1027c21865c4SKonstantin Aladyshev  * @brief Retrieves boot override source over DBUS
1028491d8ee7SSantosh Puranik  *
1029ac106bf6SEd Tanous  * @param[in] asyncResp         Shared pointer for generating response message.
1030491d8ee7SSantosh Puranik  *
1031491d8ee7SSantosh Puranik  * @return None.
1032491d8ee7SSantosh Puranik  */
1033c21865c4SKonstantin Aladyshev 
1034c21865c4SKonstantin Aladyshev inline void
1035ac106bf6SEd Tanous     getBootOverrideSource(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp)
1036491d8ee7SSantosh Puranik {
10371e1e598dSJonathan Doman     sdbusplus::asio::getProperty<std::string>(
10381e1e598dSJonathan Doman         *crow::connections::systemBus, "xyz.openbmc_project.Settings",
10391e1e598dSJonathan Doman         "/xyz/openbmc_project/control/host0/boot",
10401e1e598dSJonathan Doman         "xyz.openbmc_project.Control.Boot.Source", "BootSource",
1041ac106bf6SEd Tanous         [asyncResp](const boost::system::error_code& ec,
10421e1e598dSJonathan Doman                     const std::string& bootSourceStr) {
1043491d8ee7SSantosh Puranik         if (ec)
1044491d8ee7SSantosh Puranik         {
10455ef735c8SNan Zhou             if (ec.value() == boost::asio::error::host_unreachable)
10465ef735c8SNan Zhou             {
10475ef735c8SNan Zhou                 return;
10485ef735c8SNan Zhou             }
1049*b3e86cb0SGunnar Mills             BMCWEB_LOG_ERROR("DBUS response error {}", ec);
1050ac106bf6SEd Tanous             messages::internalError(asyncResp->res);
1051491d8ee7SSantosh Puranik             return;
1052491d8ee7SSantosh Puranik         }
1053491d8ee7SSantosh Puranik 
105462598e31SEd Tanous         BMCWEB_LOG_DEBUG("Boot source: {}", bootSourceStr);
1055491d8ee7SSantosh Puranik 
10561e1e598dSJonathan Doman         auto rfSource = dbusToRfBootSource(bootSourceStr);
1057491d8ee7SSantosh Puranik         if (!rfSource.empty())
1058491d8ee7SSantosh Puranik         {
1059ac106bf6SEd Tanous             asyncResp->res.jsonValue["Boot"]["BootSourceOverrideTarget"] =
1060ac106bf6SEd Tanous                 rfSource;
1061491d8ee7SSantosh Puranik         }
1062cd9a4666SKonstantin Aladyshev 
1063cd9a4666SKonstantin Aladyshev         // Get BootMode as BootSourceOverrideTarget is constructed
1064cd9a4666SKonstantin Aladyshev         // from both BootSource and BootMode
1065ac106bf6SEd Tanous         getBootOverrideMode(asyncResp);
10661e1e598dSJonathan Doman         });
1067491d8ee7SSantosh Puranik }
1068491d8ee7SSantosh Puranik 
1069491d8ee7SSantosh Puranik /**
1070c21865c4SKonstantin Aladyshev  * @brief This functions abstracts all the logic behind getting a
1071c21865c4SKonstantin Aladyshev  * "BootSourceOverrideEnabled" property from an overall boot override enable
1072c21865c4SKonstantin Aladyshev  * state
1073491d8ee7SSantosh Puranik  *
1074ac106bf6SEd Tanous  * @param[in] asyncResp     Shared pointer for generating response message.
1075491d8ee7SSantosh Puranik  *
1076491d8ee7SSantosh Puranik  * @return None.
1077491d8ee7SSantosh Puranik  */
1078491d8ee7SSantosh Puranik 
1079ac106bf6SEd Tanous inline void processBootOverrideEnable(
1080ac106bf6SEd Tanous     const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
1081c21865c4SKonstantin Aladyshev     const bool bootOverrideEnableSetting)
1082c21865c4SKonstantin Aladyshev {
1083c21865c4SKonstantin Aladyshev     if (!bootOverrideEnableSetting)
1084c21865c4SKonstantin Aladyshev     {
1085ac106bf6SEd Tanous         asyncResp->res.jsonValue["Boot"]["BootSourceOverrideEnabled"] =
1086ac106bf6SEd Tanous             "Disabled";
1087c21865c4SKonstantin Aladyshev         return;
1088c21865c4SKonstantin Aladyshev     }
1089c21865c4SKonstantin Aladyshev 
1090c21865c4SKonstantin Aladyshev     // If boot source override is enabled, we need to check 'one_time'
1091c21865c4SKonstantin Aladyshev     // property to set a correct value for the "BootSourceOverrideEnabled"
10921e1e598dSJonathan Doman     sdbusplus::asio::getProperty<bool>(
10931e1e598dSJonathan Doman         *crow::connections::systemBus, "xyz.openbmc_project.Settings",
10941e1e598dSJonathan Doman         "/xyz/openbmc_project/control/host0/boot/one_time",
10951e1e598dSJonathan Doman         "xyz.openbmc_project.Object.Enable", "Enabled",
1096ac106bf6SEd Tanous         [asyncResp](const boost::system::error_code& ec, bool oneTimeSetting) {
1097491d8ee7SSantosh Puranik         if (ec)
1098491d8ee7SSantosh Puranik         {
1099*b3e86cb0SGunnar Mills             BMCWEB_LOG_ERROR("DBUS response error {}", ec);
1100ac106bf6SEd Tanous             messages::internalError(asyncResp->res);
1101491d8ee7SSantosh Puranik             return;
1102491d8ee7SSantosh Puranik         }
1103491d8ee7SSantosh Puranik 
1104c21865c4SKonstantin Aladyshev         if (oneTimeSetting)
1105c21865c4SKonstantin Aladyshev         {
1106ac106bf6SEd Tanous             asyncResp->res.jsonValue["Boot"]["BootSourceOverrideEnabled"] =
1107ac106bf6SEd Tanous                 "Once";
1108c21865c4SKonstantin Aladyshev         }
1109c21865c4SKonstantin Aladyshev         else
1110c21865c4SKonstantin Aladyshev         {
1111ac106bf6SEd Tanous             asyncResp->res.jsonValue["Boot"]["BootSourceOverrideEnabled"] =
1112c21865c4SKonstantin Aladyshev                 "Continuous";
1113c21865c4SKonstantin Aladyshev         }
11141e1e598dSJonathan Doman         });
1115491d8ee7SSantosh Puranik }
1116491d8ee7SSantosh Puranik 
1117491d8ee7SSantosh Puranik /**
1118c21865c4SKonstantin Aladyshev  * @brief Retrieves boot override enable over DBUS
1119c21865c4SKonstantin Aladyshev  *
1120ac106bf6SEd Tanous  * @param[in] asyncResp     Shared pointer for generating response message.
1121c21865c4SKonstantin Aladyshev  *
1122c21865c4SKonstantin Aladyshev  * @return None.
1123c21865c4SKonstantin Aladyshev  */
1124c21865c4SKonstantin Aladyshev 
1125c21865c4SKonstantin Aladyshev inline void
1126ac106bf6SEd Tanous     getBootOverrideEnable(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp)
1127c21865c4SKonstantin Aladyshev {
11281e1e598dSJonathan Doman     sdbusplus::asio::getProperty<bool>(
11291e1e598dSJonathan Doman         *crow::connections::systemBus, "xyz.openbmc_project.Settings",
11301e1e598dSJonathan Doman         "/xyz/openbmc_project/control/host0/boot",
11311e1e598dSJonathan Doman         "xyz.openbmc_project.Object.Enable", "Enabled",
1132ac106bf6SEd Tanous         [asyncResp](const boost::system::error_code& ec,
11331e1e598dSJonathan Doman                     const bool bootOverrideEnable) {
1134c21865c4SKonstantin Aladyshev         if (ec)
1135c21865c4SKonstantin Aladyshev         {
11365ef735c8SNan Zhou             if (ec.value() == boost::asio::error::host_unreachable)
11375ef735c8SNan Zhou             {
11385ef735c8SNan Zhou                 return;
11395ef735c8SNan Zhou             }
1140*b3e86cb0SGunnar Mills             BMCWEB_LOG_ERROR("DBUS response error {}", ec);
1141ac106bf6SEd Tanous             messages::internalError(asyncResp->res);
1142c21865c4SKonstantin Aladyshev             return;
1143c21865c4SKonstantin Aladyshev         }
1144c21865c4SKonstantin Aladyshev 
1145ac106bf6SEd Tanous         processBootOverrideEnable(asyncResp, bootOverrideEnable);
11461e1e598dSJonathan Doman         });
1147c21865c4SKonstantin Aladyshev }
1148c21865c4SKonstantin Aladyshev 
1149c21865c4SKonstantin Aladyshev /**
1150c21865c4SKonstantin Aladyshev  * @brief Retrieves boot source override properties
1151c21865c4SKonstantin Aladyshev  *
1152ac106bf6SEd Tanous  * @param[in] asyncResp     Shared pointer for generating response message.
1153c21865c4SKonstantin Aladyshev  *
1154c21865c4SKonstantin Aladyshev  * @return None.
1155c21865c4SKonstantin Aladyshev  */
1156ac106bf6SEd Tanous inline void
1157ac106bf6SEd Tanous     getBootProperties(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp)
1158c21865c4SKonstantin Aladyshev {
115962598e31SEd Tanous     BMCWEB_LOG_DEBUG("Get boot information.");
1160c21865c4SKonstantin Aladyshev 
1161ac106bf6SEd Tanous     getBootOverrideSource(asyncResp);
1162ac106bf6SEd Tanous     getBootOverrideType(asyncResp);
1163ac106bf6SEd Tanous     getBootOverrideEnable(asyncResp);
1164c21865c4SKonstantin Aladyshev }
1165c21865c4SKonstantin Aladyshev 
1166c21865c4SKonstantin Aladyshev /**
1167c0557e1aSGunnar Mills  * @brief Retrieves the Last Reset Time
1168c0557e1aSGunnar Mills  *
1169c0557e1aSGunnar Mills  * "Reset" is an overloaded term in Redfish, "Reset" includes power on
1170c0557e1aSGunnar Mills  * and power off. Even though this is the "system" Redfish object look at the
1171c0557e1aSGunnar Mills  * chassis D-Bus interface for the LastStateChangeTime since this has the
1172c0557e1aSGunnar Mills  * last power operation time.
1173c0557e1aSGunnar Mills  *
1174ac106bf6SEd Tanous  * @param[in] asyncResp     Shared pointer for generating response message.
1175c0557e1aSGunnar Mills  *
1176c0557e1aSGunnar Mills  * @return None.
1177c0557e1aSGunnar Mills  */
1178ac106bf6SEd Tanous inline void
1179ac106bf6SEd Tanous     getLastResetTime(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp)
1180c0557e1aSGunnar Mills {
118162598e31SEd Tanous     BMCWEB_LOG_DEBUG("Getting System Last Reset Time");
1182c0557e1aSGunnar Mills 
11831e1e598dSJonathan Doman     sdbusplus::asio::getProperty<uint64_t>(
11841e1e598dSJonathan Doman         *crow::connections::systemBus, "xyz.openbmc_project.State.Chassis",
11851e1e598dSJonathan Doman         "/xyz/openbmc_project/state/chassis0",
11861e1e598dSJonathan Doman         "xyz.openbmc_project.State.Chassis", "LastStateChangeTime",
1187ac106bf6SEd Tanous         [asyncResp](const boost::system::error_code& ec,
1188ac106bf6SEd Tanous                     uint64_t lastResetTime) {
1189c0557e1aSGunnar Mills         if (ec)
1190c0557e1aSGunnar Mills         {
119162598e31SEd Tanous             BMCWEB_LOG_DEBUG("D-BUS response error {}", ec);
1192c0557e1aSGunnar Mills             return;
1193c0557e1aSGunnar Mills         }
1194c0557e1aSGunnar Mills 
1195c0557e1aSGunnar Mills         // LastStateChangeTime is epoch time, in milliseconds
1196c0557e1aSGunnar Mills         // https://github.com/openbmc/phosphor-dbus-interfaces/blob/33e8e1dd64da53a66e888d33dc82001305cd0bf9/xyz/openbmc_project/State/Chassis.interface.yaml#L19
11971e1e598dSJonathan Doman         uint64_t lastResetTimeStamp = lastResetTime / 1000;
1198c0557e1aSGunnar Mills 
1199c0557e1aSGunnar Mills         // Convert to ISO 8601 standard
1200ac106bf6SEd Tanous         asyncResp->res.jsonValue["LastResetTime"] =
12012b82937eSEd Tanous             redfish::time_utils::getDateTimeUint(lastResetTimeStamp);
12021e1e598dSJonathan Doman         });
1203c0557e1aSGunnar Mills }
1204c0557e1aSGunnar Mills 
1205c0557e1aSGunnar Mills /**
1206797d5daeSCorey Hardesty  * @brief Retrieves the number of automatic boot Retry attempts allowed/left.
1207797d5daeSCorey Hardesty  *
1208797d5daeSCorey Hardesty  * The total number of automatic reboot retries allowed "RetryAttempts" and its
1209797d5daeSCorey Hardesty  * corresponding property "AttemptsLeft" that keeps track of the amount of
1210797d5daeSCorey Hardesty  * automatic retry attempts left are hosted in phosphor-state-manager through
1211797d5daeSCorey Hardesty  * dbus.
1212797d5daeSCorey Hardesty  *
1213ac106bf6SEd Tanous  * @param[in] asyncResp     Shared pointer for generating response message.
1214797d5daeSCorey Hardesty  *
1215797d5daeSCorey Hardesty  * @return None.
1216797d5daeSCorey Hardesty  */
1217ac106bf6SEd Tanous inline void getAutomaticRebootAttempts(
1218ac106bf6SEd Tanous     const std::shared_ptr<bmcweb::AsyncResp>& asyncResp)
1219797d5daeSCorey Hardesty {
122062598e31SEd Tanous     BMCWEB_LOG_DEBUG("Get Automatic Retry policy");
1221797d5daeSCorey Hardesty 
1222797d5daeSCorey Hardesty     sdbusplus::asio::getAllProperties(
1223797d5daeSCorey Hardesty         *crow::connections::systemBus, "xyz.openbmc_project.State.Host",
1224797d5daeSCorey Hardesty         "/xyz/openbmc_project/state/host0",
1225797d5daeSCorey Hardesty         "xyz.openbmc_project.Control.Boot.RebootAttempts",
1226ac106bf6SEd Tanous         [asyncResp{asyncResp}](
1227ac106bf6SEd Tanous             const boost::system::error_code& ec,
1228797d5daeSCorey Hardesty             const dbus::utility::DBusPropertiesMap& propertiesList) {
1229797d5daeSCorey Hardesty         if (ec)
1230797d5daeSCorey Hardesty         {
1231797d5daeSCorey Hardesty             if (ec.value() != EBADR)
1232797d5daeSCorey Hardesty             {
123362598e31SEd Tanous                 BMCWEB_LOG_ERROR("D-Bus responses error: {}", ec);
1234ac106bf6SEd Tanous                 messages::internalError(asyncResp->res);
1235797d5daeSCorey Hardesty             }
1236797d5daeSCorey Hardesty             return;
1237797d5daeSCorey Hardesty         }
1238797d5daeSCorey Hardesty 
1239797d5daeSCorey Hardesty         const uint32_t* attemptsLeft = nullptr;
1240797d5daeSCorey Hardesty         const uint32_t* retryAttempts = nullptr;
1241797d5daeSCorey Hardesty 
1242797d5daeSCorey Hardesty         const bool success = sdbusplus::unpackPropertiesNoThrow(
1243797d5daeSCorey Hardesty             dbus_utils::UnpackErrorPrinter(), propertiesList, "AttemptsLeft",
1244797d5daeSCorey Hardesty             attemptsLeft, "RetryAttempts", retryAttempts);
1245797d5daeSCorey Hardesty 
1246797d5daeSCorey Hardesty         if (!success)
1247797d5daeSCorey Hardesty         {
1248ac106bf6SEd Tanous             messages::internalError(asyncResp->res);
1249797d5daeSCorey Hardesty             return;
1250797d5daeSCorey Hardesty         }
1251797d5daeSCorey Hardesty 
1252797d5daeSCorey Hardesty         if (attemptsLeft != nullptr)
1253797d5daeSCorey Hardesty         {
1254ac106bf6SEd Tanous             asyncResp->res
1255ac106bf6SEd Tanous                 .jsonValue["Boot"]["RemainingAutomaticRetryAttempts"] =
1256797d5daeSCorey Hardesty                 *attemptsLeft;
1257797d5daeSCorey Hardesty         }
1258797d5daeSCorey Hardesty 
1259797d5daeSCorey Hardesty         if (retryAttempts != nullptr)
1260797d5daeSCorey Hardesty         {
1261ac106bf6SEd Tanous             asyncResp->res.jsonValue["Boot"]["AutomaticRetryAttempts"] =
1262797d5daeSCorey Hardesty                 *retryAttempts;
1263797d5daeSCorey Hardesty         }
1264797d5daeSCorey Hardesty         });
1265797d5daeSCorey Hardesty }
1266797d5daeSCorey Hardesty 
1267797d5daeSCorey Hardesty /**
12686bd5a8d2SGunnar Mills  * @brief Retrieves Automatic Retry properties. Known on D-Bus as AutoReboot.
12696bd5a8d2SGunnar Mills  *
1270ac106bf6SEd Tanous  * @param[in] asyncResp     Shared pointer for generating response message.
12716bd5a8d2SGunnar Mills  *
12726bd5a8d2SGunnar Mills  * @return None.
12736bd5a8d2SGunnar Mills  */
1274797d5daeSCorey Hardesty inline void
1275ac106bf6SEd Tanous     getAutomaticRetryPolicy(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp)
12766bd5a8d2SGunnar Mills {
127762598e31SEd Tanous     BMCWEB_LOG_DEBUG("Get Automatic Retry policy");
12786bd5a8d2SGunnar Mills 
12791e1e598dSJonathan Doman     sdbusplus::asio::getProperty<bool>(
12801e1e598dSJonathan Doman         *crow::connections::systemBus, "xyz.openbmc_project.Settings",
12811e1e598dSJonathan Doman         "/xyz/openbmc_project/control/host0/auto_reboot",
12821e1e598dSJonathan Doman         "xyz.openbmc_project.Control.Boot.RebootPolicy", "AutoReboot",
1283ac106bf6SEd Tanous         [asyncResp](const boost::system::error_code& ec,
1284ac106bf6SEd Tanous                     bool autoRebootEnabled) {
12856bd5a8d2SGunnar Mills         if (ec)
12866bd5a8d2SGunnar Mills         {
1287797d5daeSCorey Hardesty             if (ec.value() != EBADR)
1288797d5daeSCorey Hardesty             {
128962598e31SEd Tanous                 BMCWEB_LOG_ERROR("D-Bus responses error: {}", ec);
1290ac106bf6SEd Tanous                 messages::internalError(asyncResp->res);
1291797d5daeSCorey Hardesty             }
12926bd5a8d2SGunnar Mills             return;
12936bd5a8d2SGunnar Mills         }
12946bd5a8d2SGunnar Mills 
129562598e31SEd Tanous         BMCWEB_LOG_DEBUG("Auto Reboot: {}", autoRebootEnabled);
1296e05aec50SEd Tanous         if (autoRebootEnabled)
12976bd5a8d2SGunnar Mills         {
1298ac106bf6SEd Tanous             asyncResp->res.jsonValue["Boot"]["AutomaticRetryConfig"] =
12996bd5a8d2SGunnar Mills                 "RetryAttempts";
13006bd5a8d2SGunnar Mills         }
13016bd5a8d2SGunnar Mills         else
13026bd5a8d2SGunnar Mills         {
1303ac106bf6SEd Tanous             asyncResp->res.jsonValue["Boot"]["AutomaticRetryConfig"] =
1304ac106bf6SEd Tanous                 "Disabled";
13056bd5a8d2SGunnar Mills         }
1306ac106bf6SEd Tanous         getAutomaticRebootAttempts(asyncResp);
130769f35306SGunnar Mills 
130869f35306SGunnar Mills         // "AutomaticRetryConfig" can be 3 values, Disabled, RetryAlways,
130969f35306SGunnar Mills         // and RetryAttempts. OpenBMC only supports Disabled and
131069f35306SGunnar Mills         // RetryAttempts.
1311ac106bf6SEd Tanous         asyncResp->res
1312ac106bf6SEd Tanous             .jsonValue["Boot"]["AutomaticRetryConfig@Redfish.AllowableValues"] =
1313ac106bf6SEd Tanous             {"Disabled", "RetryAttempts"};
13141e1e598dSJonathan Doman         });
13156bd5a8d2SGunnar Mills }
13166bd5a8d2SGunnar Mills 
13176bd5a8d2SGunnar Mills /**
1318797d5daeSCorey Hardesty  * @brief Sets RetryAttempts
1319797d5daeSCorey Hardesty  *
1320ac106bf6SEd Tanous  * @param[in] asyncResp   Shared pointer for generating response message.
1321797d5daeSCorey Hardesty  * @param[in] retryAttempts  "AutomaticRetryAttempts" from request.
1322797d5daeSCorey Hardesty  *
1323797d5daeSCorey Hardesty  *@return None.
1324797d5daeSCorey Hardesty  */
1325797d5daeSCorey Hardesty 
1326ac106bf6SEd Tanous inline void setAutomaticRetryAttempts(
1327ac106bf6SEd Tanous     const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
1328797d5daeSCorey Hardesty     const uint32_t retryAttempts)
1329797d5daeSCorey Hardesty {
133062598e31SEd Tanous     BMCWEB_LOG_DEBUG("Set Automatic Retry Attempts.");
13319ae226faSGeorge Liu     sdbusplus::asio::setProperty(
13329ae226faSGeorge Liu         *crow::connections::systemBus, "xyz.openbmc_project.State.Host",
13339ae226faSGeorge Liu         "/xyz/openbmc_project/state/host0",
13349ae226faSGeorge Liu         "xyz.openbmc_project.Control.Boot.RebootAttempts", "RetryAttempts",
13359ae226faSGeorge Liu         retryAttempts, [asyncResp](const boost::system::error_code& ec) {
1336797d5daeSCorey Hardesty             if (ec)
1337797d5daeSCorey Hardesty             {
133862598e31SEd Tanous                 BMCWEB_LOG_ERROR(
133962598e31SEd Tanous                     "DBUS response error: Set setAutomaticRetryAttempts{}", ec);
1340ac106bf6SEd Tanous                 messages::internalError(asyncResp->res);
1341797d5daeSCorey Hardesty                 return;
1342797d5daeSCorey Hardesty             }
13439ae226faSGeorge Liu         });
1344797d5daeSCorey Hardesty }
1345797d5daeSCorey Hardesty 
13468d69c668SEd Tanous inline computer_system::PowerRestorePolicyTypes
13478d69c668SEd Tanous     redfishPowerRestorePolicyFromDbus(std::string_view value)
13488d69c668SEd Tanous {
13498d69c668SEd Tanous     if (value ==
13508d69c668SEd Tanous         "xyz.openbmc_project.Control.Power.RestorePolicy.Policy.AlwaysOn")
13518d69c668SEd Tanous     {
13528d69c668SEd Tanous         return computer_system::PowerRestorePolicyTypes::AlwaysOn;
13538d69c668SEd Tanous     }
13548d69c668SEd Tanous     if (value ==
13558d69c668SEd Tanous         "xyz.openbmc_project.Control.Power.RestorePolicy.Policy.AlwaysOff")
13568d69c668SEd Tanous     {
13578d69c668SEd Tanous         return computer_system::PowerRestorePolicyTypes::AlwaysOff;
13588d69c668SEd Tanous     }
13598d69c668SEd Tanous     if (value ==
13603a34b742SGunnar Mills         "xyz.openbmc_project.Control.Power.RestorePolicy.Policy.Restore")
13618d69c668SEd Tanous     {
13628d69c668SEd Tanous         return computer_system::PowerRestorePolicyTypes::LastState;
13638d69c668SEd Tanous     }
13648d69c668SEd Tanous     if (value == "xyz.openbmc_project.Control.Power.RestorePolicy.Policy.None")
13658d69c668SEd Tanous     {
13668d69c668SEd Tanous         return computer_system::PowerRestorePolicyTypes::AlwaysOff;
13678d69c668SEd Tanous     }
13688d69c668SEd Tanous     return computer_system::PowerRestorePolicyTypes::Invalid;
13698d69c668SEd Tanous }
1370797d5daeSCorey Hardesty /**
1371c6a620f2SGeorge Liu  * @brief Retrieves power restore policy over DBUS.
1372c6a620f2SGeorge Liu  *
1373ac106bf6SEd Tanous  * @param[in] asyncResp     Shared pointer for generating response message.
1374c6a620f2SGeorge Liu  *
1375c6a620f2SGeorge Liu  * @return None.
1376c6a620f2SGeorge Liu  */
13778d1b46d7Szhanghch05 inline void
1378ac106bf6SEd Tanous     getPowerRestorePolicy(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp)
1379c6a620f2SGeorge Liu {
138062598e31SEd Tanous     BMCWEB_LOG_DEBUG("Get power restore policy");
1381c6a620f2SGeorge Liu 
13821e1e598dSJonathan Doman     sdbusplus::asio::getProperty<std::string>(
13831e1e598dSJonathan Doman         *crow::connections::systemBus, "xyz.openbmc_project.Settings",
13841e1e598dSJonathan Doman         "/xyz/openbmc_project/control/host0/power_restore_policy",
13851e1e598dSJonathan Doman         "xyz.openbmc_project.Control.Power.RestorePolicy", "PowerRestorePolicy",
1386ac106bf6SEd Tanous         [asyncResp](const boost::system::error_code& ec,
13875e7e2dc5SEd Tanous                     const std::string& policy) {
1388c6a620f2SGeorge Liu         if (ec)
1389c6a620f2SGeorge Liu         {
139062598e31SEd Tanous             BMCWEB_LOG_DEBUG("DBUS response error {}", ec);
1391c6a620f2SGeorge Liu             return;
1392c6a620f2SGeorge Liu         }
13938d69c668SEd Tanous         computer_system::PowerRestorePolicyTypes restore =
13948d69c668SEd Tanous             redfishPowerRestorePolicyFromDbus(policy);
13958d69c668SEd Tanous         if (restore == computer_system::PowerRestorePolicyTypes::Invalid)
1396c6a620f2SGeorge Liu         {
1397ac106bf6SEd Tanous             messages::internalError(asyncResp->res);
1398c6a620f2SGeorge Liu             return;
1399c6a620f2SGeorge Liu         }
1400c6a620f2SGeorge Liu 
14018d69c668SEd Tanous         asyncResp->res.jsonValue["PowerRestorePolicy"] = restore;
14021e1e598dSJonathan Doman         });
1403c6a620f2SGeorge Liu }
1404c6a620f2SGeorge Liu 
1405c6a620f2SGeorge Liu /**
14069dcfe8c1SAlbert Zhang  * @brief Stop Boot On Fault over DBUS.
14079dcfe8c1SAlbert Zhang  *
14089dcfe8c1SAlbert Zhang  * @param[in] asyncResp     Shared pointer for generating response message.
14099dcfe8c1SAlbert Zhang  *
14109dcfe8c1SAlbert Zhang  * @return None.
14119dcfe8c1SAlbert Zhang  */
14129dcfe8c1SAlbert Zhang inline void
14139dcfe8c1SAlbert Zhang     getStopBootOnFault(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp)
14149dcfe8c1SAlbert Zhang {
141562598e31SEd Tanous     BMCWEB_LOG_DEBUG("Get Stop Boot On Fault");
14169dcfe8c1SAlbert Zhang 
14179dcfe8c1SAlbert Zhang     sdbusplus::asio::getProperty<bool>(
14189dcfe8c1SAlbert Zhang         *crow::connections::systemBus, "xyz.openbmc_project.Settings",
14199dcfe8c1SAlbert Zhang         "/xyz/openbmc_project/logging/settings",
14209dcfe8c1SAlbert Zhang         "xyz.openbmc_project.Logging.Settings", "QuiesceOnHwError",
14219dcfe8c1SAlbert Zhang         [asyncResp](const boost::system::error_code& ec, bool value) {
14229dcfe8c1SAlbert Zhang         if (ec)
14239dcfe8c1SAlbert Zhang         {
14249dcfe8c1SAlbert Zhang             if (ec.value() != EBADR)
14259dcfe8c1SAlbert Zhang             {
1426*b3e86cb0SGunnar Mills                 BMCWEB_LOG_ERROR("DBUS response error {}", ec);
14279dcfe8c1SAlbert Zhang                 messages::internalError(asyncResp->res);
14289dcfe8c1SAlbert Zhang             }
14299dcfe8c1SAlbert Zhang             return;
14309dcfe8c1SAlbert Zhang         }
14319dcfe8c1SAlbert Zhang 
14329dcfe8c1SAlbert Zhang         if (value)
14339dcfe8c1SAlbert Zhang         {
14349dcfe8c1SAlbert Zhang             asyncResp->res.jsonValue["Boot"]["StopBootOnFault"] = "AnyFault";
14359dcfe8c1SAlbert Zhang         }
14369dcfe8c1SAlbert Zhang         else
14379dcfe8c1SAlbert Zhang         {
14389dcfe8c1SAlbert Zhang             asyncResp->res.jsonValue["Boot"]["StopBootOnFault"] = "Never";
14399dcfe8c1SAlbert Zhang         }
14409dcfe8c1SAlbert Zhang         });
14419dcfe8c1SAlbert Zhang }
14429dcfe8c1SAlbert Zhang 
14439dcfe8c1SAlbert Zhang /**
14441981771bSAli Ahmed  * @brief Get TrustedModuleRequiredToBoot property. Determines whether or not
14451981771bSAli Ahmed  * TPM is required for booting the host.
14461981771bSAli Ahmed  *
1447ac106bf6SEd Tanous  * @param[in] asyncResp     Shared pointer for generating response message.
14481981771bSAli Ahmed  *
14491981771bSAli Ahmed  * @return None.
14501981771bSAli Ahmed  */
14511981771bSAli Ahmed inline void getTrustedModuleRequiredToBoot(
1452ac106bf6SEd Tanous     const std::shared_ptr<bmcweb::AsyncResp>& asyncResp)
14531981771bSAli Ahmed {
145462598e31SEd Tanous     BMCWEB_LOG_DEBUG("Get TPM required to boot.");
1455e99073f5SGeorge Liu     constexpr std::array<std::string_view, 1> interfaces = {
1456e99073f5SGeorge Liu         "xyz.openbmc_project.Control.TPM.Policy"};
1457e99073f5SGeorge Liu     dbus::utility::getSubTree(
1458e99073f5SGeorge Liu         "/", 0, interfaces,
1459ac106bf6SEd Tanous         [asyncResp](const boost::system::error_code& ec,
1460b9d36b47SEd Tanous                     const dbus::utility::MapperGetSubTreeResponse& subtree) {
14611981771bSAli Ahmed         if (ec)
14621981771bSAli Ahmed         {
146362598e31SEd Tanous             BMCWEB_LOG_DEBUG("DBUS response error on TPM.Policy GetSubTree{}",
146462598e31SEd Tanous                              ec);
14651981771bSAli Ahmed             // This is an optional D-Bus object so just return if
14661981771bSAli Ahmed             // error occurs
14671981771bSAli Ahmed             return;
14681981771bSAli Ahmed         }
146926f6976fSEd Tanous         if (subtree.empty())
14701981771bSAli Ahmed         {
14711981771bSAli Ahmed             // As noted above, this is an optional interface so just return
14721981771bSAli Ahmed             // if there is no instance found
14731981771bSAli Ahmed             return;
14741981771bSAli Ahmed         }
14751981771bSAli Ahmed 
14761981771bSAli Ahmed         /* When there is more than one TPMEnable object... */
14771981771bSAli Ahmed         if (subtree.size() > 1)
14781981771bSAli Ahmed         {
147962598e31SEd Tanous             BMCWEB_LOG_DEBUG(
148062598e31SEd Tanous                 "DBUS response has more than 1 TPM Enable object:{}",
148162598e31SEd Tanous                 subtree.size());
14821981771bSAli Ahmed             // Throw an internal Error and return
1483ac106bf6SEd Tanous             messages::internalError(asyncResp->res);
14841981771bSAli Ahmed             return;
14851981771bSAli Ahmed         }
14861981771bSAli Ahmed 
14871981771bSAli Ahmed         // Make sure the Dbus response map has a service and objectPath
14881981771bSAli Ahmed         // field
14891981771bSAli Ahmed         if (subtree[0].first.empty() || subtree[0].second.size() != 1)
14901981771bSAli Ahmed         {
149162598e31SEd Tanous             BMCWEB_LOG_DEBUG("TPM.Policy mapper error!");
1492ac106bf6SEd Tanous             messages::internalError(asyncResp->res);
14931981771bSAli Ahmed             return;
14941981771bSAli Ahmed         }
14951981771bSAli Ahmed 
14961981771bSAli Ahmed         const std::string& path = subtree[0].first;
14971981771bSAli Ahmed         const std::string& serv = subtree[0].second.begin()->first;
14981981771bSAli Ahmed 
14991981771bSAli Ahmed         // Valid TPM Enable object found, now reading the current value
15001e1e598dSJonathan Doman         sdbusplus::asio::getProperty<bool>(
15011e1e598dSJonathan Doman             *crow::connections::systemBus, serv, path,
15021e1e598dSJonathan Doman             "xyz.openbmc_project.Control.TPM.Policy", "TPMEnable",
1503ac106bf6SEd Tanous             [asyncResp](const boost::system::error_code& ec2,
1504ac106bf6SEd Tanous                         bool tpmRequired) {
15058a592810SEd Tanous             if (ec2)
15061981771bSAli Ahmed             {
1507*b3e86cb0SGunnar Mills                 BMCWEB_LOG_ERROR("D-BUS response error on TPM.Policy Get{}",
150862598e31SEd Tanous                                  ec2);
1509ac106bf6SEd Tanous                 messages::internalError(asyncResp->res);
15101981771bSAli Ahmed                 return;
15111981771bSAli Ahmed             }
15121981771bSAli Ahmed 
15131e1e598dSJonathan Doman             if (tpmRequired)
15141981771bSAli Ahmed             {
1515ac106bf6SEd Tanous                 asyncResp->res
1516ac106bf6SEd Tanous                     .jsonValue["Boot"]["TrustedModuleRequiredToBoot"] =
15171981771bSAli Ahmed                     "Required";
15181981771bSAli Ahmed             }
15191981771bSAli Ahmed             else
15201981771bSAli Ahmed             {
1521ac106bf6SEd Tanous                 asyncResp->res
1522ac106bf6SEd Tanous                     .jsonValue["Boot"]["TrustedModuleRequiredToBoot"] =
15231981771bSAli Ahmed                     "Disabled";
15241981771bSAli Ahmed             }
15251e1e598dSJonathan Doman             });
1526e99073f5SGeorge Liu         });
15271981771bSAli Ahmed }
15281981771bSAli Ahmed 
15291981771bSAli Ahmed /**
15301c05dae3SAli Ahmed  * @brief Set TrustedModuleRequiredToBoot property. Determines whether or not
15311c05dae3SAli Ahmed  * TPM is required for booting the host.
15321c05dae3SAli Ahmed  *
1533ac106bf6SEd Tanous  * @param[in] asyncResp     Shared pointer for generating response message.
15341c05dae3SAli Ahmed  * @param[in] tpmRequired   Value to set TPM Required To Boot property to.
15351c05dae3SAli Ahmed  *
15361c05dae3SAli Ahmed  * @return None.
15371c05dae3SAli Ahmed  */
15381c05dae3SAli Ahmed inline void setTrustedModuleRequiredToBoot(
1539ac106bf6SEd Tanous     const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, const bool tpmRequired)
15401c05dae3SAli Ahmed {
154162598e31SEd Tanous     BMCWEB_LOG_DEBUG("Set TrustedModuleRequiredToBoot.");
1542e99073f5SGeorge Liu     constexpr std::array<std::string_view, 1> interfaces = {
1543e99073f5SGeorge Liu         "xyz.openbmc_project.Control.TPM.Policy"};
1544e99073f5SGeorge Liu     dbus::utility::getSubTree(
1545e99073f5SGeorge Liu         "/", 0, interfaces,
1546ac106bf6SEd Tanous         [asyncResp,
1547e99073f5SGeorge Liu          tpmRequired](const boost::system::error_code& ec,
1548e99073f5SGeorge Liu                       const dbus::utility::MapperGetSubTreeResponse& subtree) {
15491c05dae3SAli Ahmed         if (ec)
15501c05dae3SAli Ahmed         {
1551*b3e86cb0SGunnar Mills             BMCWEB_LOG_ERROR("DBUS response error on TPM.Policy GetSubTree{}",
155262598e31SEd Tanous                              ec);
1553ac106bf6SEd Tanous             messages::internalError(asyncResp->res);
15541c05dae3SAli Ahmed             return;
15551c05dae3SAli Ahmed         }
155626f6976fSEd Tanous         if (subtree.empty())
15571c05dae3SAli Ahmed         {
1558ac106bf6SEd Tanous             messages::propertyValueNotInList(asyncResp->res, "ComputerSystem",
15591c05dae3SAli Ahmed                                              "TrustedModuleRequiredToBoot");
15601c05dae3SAli Ahmed             return;
15611c05dae3SAli Ahmed         }
15621c05dae3SAli Ahmed 
15631c05dae3SAli Ahmed         /* When there is more than one TPMEnable object... */
15641c05dae3SAli Ahmed         if (subtree.size() > 1)
15651c05dae3SAli Ahmed         {
156662598e31SEd Tanous             BMCWEB_LOG_DEBUG(
156762598e31SEd Tanous                 "DBUS response has more than 1 TPM Enable object:{}",
156862598e31SEd Tanous                 subtree.size());
15691c05dae3SAli Ahmed             // Throw an internal Error and return
1570ac106bf6SEd Tanous             messages::internalError(asyncResp->res);
15711c05dae3SAli Ahmed             return;
15721c05dae3SAli Ahmed         }
15731c05dae3SAli Ahmed 
15741c05dae3SAli Ahmed         // Make sure the Dbus response map has a service and objectPath
15751c05dae3SAli Ahmed         // field
15761c05dae3SAli Ahmed         if (subtree[0].first.empty() || subtree[0].second.size() != 1)
15771c05dae3SAli Ahmed         {
157862598e31SEd Tanous             BMCWEB_LOG_DEBUG("TPM.Policy mapper error!");
1579ac106bf6SEd Tanous             messages::internalError(asyncResp->res);
15801c05dae3SAli Ahmed             return;
15811c05dae3SAli Ahmed         }
15821c05dae3SAli Ahmed 
15831c05dae3SAli Ahmed         const std::string& path = subtree[0].first;
15841c05dae3SAli Ahmed         const std::string& serv = subtree[0].second.begin()->first;
15851c05dae3SAli Ahmed 
15861c05dae3SAli Ahmed         if (serv.empty())
15871c05dae3SAli Ahmed         {
158862598e31SEd Tanous             BMCWEB_LOG_DEBUG("TPM.Policy service mapper error!");
1589ac106bf6SEd Tanous             messages::internalError(asyncResp->res);
15901c05dae3SAli Ahmed             return;
15911c05dae3SAli Ahmed         }
15921c05dae3SAli Ahmed 
15931c05dae3SAli Ahmed         // Valid TPM Enable object found, now setting the value
15949ae226faSGeorge Liu         sdbusplus::asio::setProperty(
15959ae226faSGeorge Liu             *crow::connections::systemBus, serv, path,
15969ae226faSGeorge Liu             "xyz.openbmc_project.Control.TPM.Policy", "TPMEnable", tpmRequired,
1597ac106bf6SEd Tanous             [asyncResp](const boost::system::error_code& ec2) {
15988a592810SEd Tanous             if (ec2)
15991c05dae3SAli Ahmed             {
1600*b3e86cb0SGunnar Mills                 BMCWEB_LOG_ERROR(
160162598e31SEd Tanous                     "DBUS response error: Set TrustedModuleRequiredToBoot{}",
160262598e31SEd Tanous                     ec2);
1603ac106bf6SEd Tanous                 messages::internalError(asyncResp->res);
16041c05dae3SAli Ahmed                 return;
16051c05dae3SAli Ahmed             }
160662598e31SEd Tanous             BMCWEB_LOG_DEBUG("Set TrustedModuleRequiredToBoot done.");
16079ae226faSGeorge Liu             });
1608e99073f5SGeorge Liu         });
16091c05dae3SAli Ahmed }
16101c05dae3SAli Ahmed 
16111c05dae3SAli Ahmed /**
1612491d8ee7SSantosh Puranik  * @brief Sets boot properties into DBUS object(s).
1613491d8ee7SSantosh Puranik  *
1614ac106bf6SEd Tanous  * @param[in] asyncResp       Shared pointer for generating response message.
1615cd9a4666SKonstantin Aladyshev  * @param[in] bootType        The boot type to set.
1616cd9a4666SKonstantin Aladyshev  * @return Integer error code.
1617cd9a4666SKonstantin Aladyshev  */
1618ac106bf6SEd Tanous inline void setBootType(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
1619cd9a4666SKonstantin Aladyshev                         const std::optional<std::string>& bootType)
1620cd9a4666SKonstantin Aladyshev {
1621c21865c4SKonstantin Aladyshev     std::string bootTypeStr;
1622cd9a4666SKonstantin Aladyshev 
1623c21865c4SKonstantin Aladyshev     if (!bootType)
1624cd9a4666SKonstantin Aladyshev     {
1625c21865c4SKonstantin Aladyshev         return;
1626c21865c4SKonstantin Aladyshev     }
1627c21865c4SKonstantin Aladyshev 
1628cd9a4666SKonstantin Aladyshev     // Source target specified
162962598e31SEd Tanous     BMCWEB_LOG_DEBUG("Boot type: {}", *bootType);
1630cd9a4666SKonstantin Aladyshev     // Figure out which DBUS interface and property to use
1631cd9a4666SKonstantin Aladyshev     if (*bootType == "Legacy")
1632cd9a4666SKonstantin Aladyshev     {
1633cd9a4666SKonstantin Aladyshev         bootTypeStr = "xyz.openbmc_project.Control.Boot.Type.Types.Legacy";
1634cd9a4666SKonstantin Aladyshev     }
1635cd9a4666SKonstantin Aladyshev     else if (*bootType == "UEFI")
1636cd9a4666SKonstantin Aladyshev     {
1637cd9a4666SKonstantin Aladyshev         bootTypeStr = "xyz.openbmc_project.Control.Boot.Type.Types.EFI";
1638cd9a4666SKonstantin Aladyshev     }
1639cd9a4666SKonstantin Aladyshev     else
1640cd9a4666SKonstantin Aladyshev     {
164162598e31SEd Tanous         BMCWEB_LOG_DEBUG("Invalid property value for "
164262598e31SEd Tanous                          "BootSourceOverrideMode: {}",
164362598e31SEd Tanous                          *bootType);
1644ac106bf6SEd Tanous         messages::propertyValueNotInList(asyncResp->res, *bootType,
1645cd9a4666SKonstantin Aladyshev                                          "BootSourceOverrideMode");
1646cd9a4666SKonstantin Aladyshev         return;
1647cd9a4666SKonstantin Aladyshev     }
1648cd9a4666SKonstantin Aladyshev 
1649cd9a4666SKonstantin Aladyshev     // Act on validated parameters
165062598e31SEd Tanous     BMCWEB_LOG_DEBUG("DBUS boot type: {}", bootTypeStr);
1651cd9a4666SKonstantin Aladyshev 
16529ae226faSGeorge Liu     sdbusplus::asio::setProperty(
16539ae226faSGeorge Liu         *crow::connections::systemBus, "xyz.openbmc_project.Settings",
16549ae226faSGeorge Liu         "/xyz/openbmc_project/control/host0/boot",
16559ae226faSGeorge Liu         "xyz.openbmc_project.Control.Boot.Type", "BootType", bootTypeStr,
1656ac106bf6SEd Tanous         [asyncResp](const boost::system::error_code& ec) {
1657cd9a4666SKonstantin Aladyshev         if (ec)
1658cd9a4666SKonstantin Aladyshev         {
1659cd9a4666SKonstantin Aladyshev             if (ec.value() == boost::asio::error::host_unreachable)
1660cd9a4666SKonstantin Aladyshev             {
1661ac106bf6SEd Tanous                 messages::resourceNotFound(asyncResp->res, "Set", "BootType");
1662cd9a4666SKonstantin Aladyshev                 return;
1663cd9a4666SKonstantin Aladyshev             }
1664*b3e86cb0SGunnar Mills             BMCWEB_LOG_ERROR("DBUS response error {}", ec);
1665ac106bf6SEd Tanous             messages::internalError(asyncResp->res);
1666cd9a4666SKonstantin Aladyshev             return;
1667cd9a4666SKonstantin Aladyshev         }
166862598e31SEd Tanous         BMCWEB_LOG_DEBUG("Boot type update done.");
16699ae226faSGeorge Liu         });
1670cd9a4666SKonstantin Aladyshev }
1671cd9a4666SKonstantin Aladyshev 
1672cd9a4666SKonstantin Aladyshev /**
1673cd9a4666SKonstantin Aladyshev  * @brief Sets boot properties into DBUS object(s).
1674cd9a4666SKonstantin Aladyshev  *
1675ac106bf6SEd Tanous  * @param[in] asyncResp           Shared pointer for generating response
1676ac106bf6SEd Tanous  * message.
1677c21865c4SKonstantin Aladyshev  * @param[in] bootType        The boot type to set.
1678c21865c4SKonstantin Aladyshev  * @return Integer error code.
1679c21865c4SKonstantin Aladyshev  */
1680ac106bf6SEd Tanous inline void setBootEnable(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
1681c21865c4SKonstantin Aladyshev                           const std::optional<std::string>& bootEnable)
1682c21865c4SKonstantin Aladyshev {
1683c21865c4SKonstantin Aladyshev     if (!bootEnable)
1684c21865c4SKonstantin Aladyshev     {
1685c21865c4SKonstantin Aladyshev         return;
1686c21865c4SKonstantin Aladyshev     }
1687c21865c4SKonstantin Aladyshev     // Source target specified
168862598e31SEd Tanous     BMCWEB_LOG_DEBUG("Boot enable: {}", *bootEnable);
1689c21865c4SKonstantin Aladyshev 
1690c21865c4SKonstantin Aladyshev     bool bootOverrideEnable = false;
1691c21865c4SKonstantin Aladyshev     bool bootOverridePersistent = false;
1692c21865c4SKonstantin Aladyshev     // Figure out which DBUS interface and property to use
1693c21865c4SKonstantin Aladyshev     if (*bootEnable == "Disabled")
1694c21865c4SKonstantin Aladyshev     {
1695c21865c4SKonstantin Aladyshev         bootOverrideEnable = false;
1696c21865c4SKonstantin Aladyshev     }
1697c21865c4SKonstantin Aladyshev     else if (*bootEnable == "Once")
1698c21865c4SKonstantin Aladyshev     {
1699c21865c4SKonstantin Aladyshev         bootOverrideEnable = true;
1700c21865c4SKonstantin Aladyshev         bootOverridePersistent = false;
1701c21865c4SKonstantin Aladyshev     }
1702c21865c4SKonstantin Aladyshev     else if (*bootEnable == "Continuous")
1703c21865c4SKonstantin Aladyshev     {
1704c21865c4SKonstantin Aladyshev         bootOverrideEnable = true;
1705c21865c4SKonstantin Aladyshev         bootOverridePersistent = true;
1706c21865c4SKonstantin Aladyshev     }
1707c21865c4SKonstantin Aladyshev     else
1708c21865c4SKonstantin Aladyshev     {
170962598e31SEd Tanous         BMCWEB_LOG_DEBUG(
171062598e31SEd Tanous             "Invalid property value for BootSourceOverrideEnabled: {}",
171162598e31SEd Tanous             *bootEnable);
1712ac106bf6SEd Tanous         messages::propertyValueNotInList(asyncResp->res, *bootEnable,
1713c21865c4SKonstantin Aladyshev                                          "BootSourceOverrideEnabled");
1714c21865c4SKonstantin Aladyshev         return;
1715c21865c4SKonstantin Aladyshev     }
1716c21865c4SKonstantin Aladyshev 
1717c21865c4SKonstantin Aladyshev     // Act on validated parameters
171862598e31SEd Tanous     BMCWEB_LOG_DEBUG("DBUS boot override enable: {}", bootOverrideEnable);
1719c21865c4SKonstantin Aladyshev 
17209ae226faSGeorge Liu     sdbusplus::asio::setProperty(
17219ae226faSGeorge Liu         *crow::connections::systemBus, "xyz.openbmc_project.Settings",
17229ae226faSGeorge Liu         "/xyz/openbmc_project/control/host0/boot",
17239ae226faSGeorge Liu         "xyz.openbmc_project.Object.Enable", "Enabled", bootOverrideEnable,
1724ac106bf6SEd Tanous         [asyncResp](const boost::system::error_code& ec2) {
17258a592810SEd Tanous         if (ec2)
1726c21865c4SKonstantin Aladyshev         {
1727*b3e86cb0SGunnar Mills             BMCWEB_LOG_ERROR("DBUS response error {}", ec2);
1728ac106bf6SEd Tanous             messages::internalError(asyncResp->res);
1729c21865c4SKonstantin Aladyshev             return;
1730c21865c4SKonstantin Aladyshev         }
173162598e31SEd Tanous         BMCWEB_LOG_DEBUG("Boot override enable update done.");
17329ae226faSGeorge Liu         });
1733c21865c4SKonstantin Aladyshev 
1734c21865c4SKonstantin Aladyshev     if (!bootOverrideEnable)
1735c21865c4SKonstantin Aladyshev     {
1736c21865c4SKonstantin Aladyshev         return;
1737c21865c4SKonstantin Aladyshev     }
1738c21865c4SKonstantin Aladyshev 
1739c21865c4SKonstantin Aladyshev     // In case boot override is enabled we need to set correct value for the
1740c21865c4SKonstantin Aladyshev     // 'one_time' enable DBus interface
174162598e31SEd Tanous     BMCWEB_LOG_DEBUG("DBUS boot override persistent: {}",
174262598e31SEd Tanous                      bootOverridePersistent);
1743c21865c4SKonstantin Aladyshev 
17449ae226faSGeorge Liu     sdbusplus::asio::setProperty(
17459ae226faSGeorge Liu         *crow::connections::systemBus, "xyz.openbmc_project.Settings",
17469ae226faSGeorge Liu         "/xyz/openbmc_project/control/host0/boot/one_time",
17479ae226faSGeorge Liu         "xyz.openbmc_project.Object.Enable", "Enabled", !bootOverridePersistent,
1748ac106bf6SEd Tanous         [asyncResp](const boost::system::error_code& ec) {
1749c21865c4SKonstantin Aladyshev         if (ec)
1750c21865c4SKonstantin Aladyshev         {
1751*b3e86cb0SGunnar Mills             BMCWEB_LOG_ERROR("DBUS response error {}", ec);
1752ac106bf6SEd Tanous             messages::internalError(asyncResp->res);
1753c21865c4SKonstantin Aladyshev             return;
1754c21865c4SKonstantin Aladyshev         }
175562598e31SEd Tanous         BMCWEB_LOG_DEBUG("Boot one_time update done.");
17569ae226faSGeorge Liu         });
1757c21865c4SKonstantin Aladyshev }
1758c21865c4SKonstantin Aladyshev 
1759c21865c4SKonstantin Aladyshev /**
1760c21865c4SKonstantin Aladyshev  * @brief Sets boot properties into DBUS object(s).
1761c21865c4SKonstantin Aladyshev  *
1762ac106bf6SEd Tanous  * @param[in] asyncResp       Shared pointer for generating response message.
1763491d8ee7SSantosh Puranik  * @param[in] bootSource      The boot source to set.
1764491d8ee7SSantosh Puranik  *
1765265c1602SJohnathan Mantey  * @return Integer error code.
1766491d8ee7SSantosh Puranik  */
1767ac106bf6SEd Tanous inline void
1768ac106bf6SEd Tanous     setBootModeOrSource(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
1769cd9a4666SKonstantin Aladyshev                         const std::optional<std::string>& bootSource)
1770491d8ee7SSantosh Puranik {
1771c21865c4SKonstantin Aladyshev     std::string bootSourceStr;
1772c21865c4SKonstantin Aladyshev     std::string bootModeStr;
1773944ffaf9SJohnathan Mantey 
1774c21865c4SKonstantin Aladyshev     if (!bootSource)
1775491d8ee7SSantosh Puranik     {
1776c21865c4SKonstantin Aladyshev         return;
1777c21865c4SKonstantin Aladyshev     }
1778c21865c4SKonstantin Aladyshev 
1779491d8ee7SSantosh Puranik     // Source target specified
178062598e31SEd Tanous     BMCWEB_LOG_DEBUG("Boot source: {}", *bootSource);
1781491d8ee7SSantosh Puranik     // Figure out which DBUS interface and property to use
1782ac106bf6SEd Tanous     if (assignBootParameters(asyncResp, *bootSource, bootSourceStr,
1783ac106bf6SEd Tanous                              bootModeStr) != 0)
1784491d8ee7SSantosh Puranik     {
178562598e31SEd Tanous         BMCWEB_LOG_DEBUG(
178662598e31SEd Tanous             "Invalid property value for BootSourceOverrideTarget: {}",
178762598e31SEd Tanous             *bootSource);
1788ac106bf6SEd Tanous         messages::propertyValueNotInList(asyncResp->res, *bootSource,
1789491d8ee7SSantosh Puranik                                          "BootSourceTargetOverride");
1790491d8ee7SSantosh Puranik         return;
1791491d8ee7SSantosh Puranik     }
1792491d8ee7SSantosh Puranik 
1793944ffaf9SJohnathan Mantey     // Act on validated parameters
179462598e31SEd Tanous     BMCWEB_LOG_DEBUG("DBUS boot source: {}", bootSourceStr);
179562598e31SEd Tanous     BMCWEB_LOG_DEBUG("DBUS boot mode: {}", bootModeStr);
1796944ffaf9SJohnathan Mantey 
17979ae226faSGeorge Liu     sdbusplus::asio::setProperty(
17989ae226faSGeorge Liu         *crow::connections::systemBus, "xyz.openbmc_project.Settings",
17999ae226faSGeorge Liu         "/xyz/openbmc_project/control/host0/boot",
18009ae226faSGeorge Liu         "xyz.openbmc_project.Control.Boot.Source", "BootSource", bootSourceStr,
1801ac106bf6SEd Tanous         [asyncResp](const boost::system::error_code& ec) {
1802491d8ee7SSantosh Puranik         if (ec)
1803491d8ee7SSantosh Puranik         {
1804*b3e86cb0SGunnar Mills             BMCWEB_LOG_ERROR("DBUS response error {}", ec);
1805ac106bf6SEd Tanous             messages::internalError(asyncResp->res);
1806491d8ee7SSantosh Puranik             return;
1807491d8ee7SSantosh Puranik         }
180862598e31SEd Tanous         BMCWEB_LOG_DEBUG("Boot source update done.");
18099ae226faSGeorge Liu         });
1810944ffaf9SJohnathan Mantey 
18119ae226faSGeorge Liu     sdbusplus::asio::setProperty(
18129ae226faSGeorge Liu         *crow::connections::systemBus, "xyz.openbmc_project.Settings",
18139ae226faSGeorge Liu         "/xyz/openbmc_project/control/host0/boot",
18149ae226faSGeorge Liu         "xyz.openbmc_project.Control.Boot.Mode", "BootMode", bootModeStr,
1815ac106bf6SEd Tanous         [asyncResp](const boost::system::error_code& ec) {
1816491d8ee7SSantosh Puranik         if (ec)
1817491d8ee7SSantosh Puranik         {
1818*b3e86cb0SGunnar Mills             BMCWEB_LOG_ERROR("DBUS response error {}", ec);
1819ac106bf6SEd Tanous             messages::internalError(asyncResp->res);
1820491d8ee7SSantosh Puranik             return;
1821491d8ee7SSantosh Puranik         }
182262598e31SEd Tanous         BMCWEB_LOG_DEBUG("Boot mode update done.");
18239ae226faSGeorge Liu         });
1824cd9a4666SKonstantin Aladyshev }
1825944ffaf9SJohnathan Mantey 
1826cd9a4666SKonstantin Aladyshev /**
1827c21865c4SKonstantin Aladyshev  * @brief Sets Boot source override properties.
1828491d8ee7SSantosh Puranik  *
1829ac106bf6SEd Tanous  * @param[in] asyncResp  Shared pointer for generating response message.
1830491d8ee7SSantosh Puranik  * @param[in] bootSource The boot source from incoming RF request.
1831cd9a4666SKonstantin Aladyshev  * @param[in] bootType   The boot type from incoming RF request.
1832491d8ee7SSantosh Puranik  * @param[in] bootEnable The boot override enable from incoming RF request.
1833491d8ee7SSantosh Puranik  *
1834265c1602SJohnathan Mantey  * @return Integer error code.
1835491d8ee7SSantosh Puranik  */
1836c21865c4SKonstantin Aladyshev 
1837ac106bf6SEd Tanous inline void
1838ac106bf6SEd Tanous     setBootProperties(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
1839c21865c4SKonstantin Aladyshev                       const std::optional<std::string>& bootSource,
1840c21865c4SKonstantin Aladyshev                       const std::optional<std::string>& bootType,
1841c21865c4SKonstantin Aladyshev                       const std::optional<std::string>& bootEnable)
1842491d8ee7SSantosh Puranik {
184362598e31SEd Tanous     BMCWEB_LOG_DEBUG("Set boot information.");
1844491d8ee7SSantosh Puranik 
1845ac106bf6SEd Tanous     setBootModeOrSource(asyncResp, bootSource);
1846ac106bf6SEd Tanous     setBootType(asyncResp, bootType);
1847ac106bf6SEd Tanous     setBootEnable(asyncResp, bootEnable);
1848491d8ee7SSantosh Puranik }
1849491d8ee7SSantosh Puranik 
1850c6a620f2SGeorge Liu /**
185198e386ecSGunnar Mills  * @brief Sets AssetTag
185298e386ecSGunnar Mills  *
1853ac106bf6SEd Tanous  * @param[in] asyncResp Shared pointer for generating response message.
185498e386ecSGunnar Mills  * @param[in] assetTag  "AssetTag" from request.
185598e386ecSGunnar Mills  *
185698e386ecSGunnar Mills  * @return None.
185798e386ecSGunnar Mills  */
1858ac106bf6SEd Tanous inline void setAssetTag(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
185998e386ecSGunnar Mills                         const std::string& assetTag)
186098e386ecSGunnar Mills {
1861e99073f5SGeorge Liu     constexpr std::array<std::string_view, 1> interfaces = {
1862e99073f5SGeorge Liu         "xyz.openbmc_project.Inventory.Item.System"};
1863e99073f5SGeorge Liu     dbus::utility::getSubTree(
1864e99073f5SGeorge Liu         "/xyz/openbmc_project/inventory", 0, interfaces,
1865ac106bf6SEd Tanous         [asyncResp,
1866e99073f5SGeorge Liu          assetTag](const boost::system::error_code& ec,
1867b9d36b47SEd Tanous                    const dbus::utility::MapperGetSubTreeResponse& subtree) {
186898e386ecSGunnar Mills         if (ec)
186998e386ecSGunnar Mills         {
187062598e31SEd Tanous             BMCWEB_LOG_DEBUG("D-Bus response error on GetSubTree {}", ec);
1871ac106bf6SEd Tanous             messages::internalError(asyncResp->res);
187298e386ecSGunnar Mills             return;
187398e386ecSGunnar Mills         }
187426f6976fSEd Tanous         if (subtree.empty())
187598e386ecSGunnar Mills         {
187662598e31SEd Tanous             BMCWEB_LOG_DEBUG("Can't find system D-Bus object!");
1877ac106bf6SEd Tanous             messages::internalError(asyncResp->res);
187898e386ecSGunnar Mills             return;
187998e386ecSGunnar Mills         }
188098e386ecSGunnar Mills         // Assume only 1 system D-Bus object
188198e386ecSGunnar Mills         // Throw an error if there is more than 1
188298e386ecSGunnar Mills         if (subtree.size() > 1)
188398e386ecSGunnar Mills         {
188462598e31SEd Tanous             BMCWEB_LOG_DEBUG("Found more than 1 system D-Bus object!");
1885ac106bf6SEd Tanous             messages::internalError(asyncResp->res);
188698e386ecSGunnar Mills             return;
188798e386ecSGunnar Mills         }
188898e386ecSGunnar Mills         if (subtree[0].first.empty() || subtree[0].second.size() != 1)
188998e386ecSGunnar Mills         {
189062598e31SEd Tanous             BMCWEB_LOG_DEBUG("Asset Tag Set mapper error!");
1891ac106bf6SEd Tanous             messages::internalError(asyncResp->res);
189298e386ecSGunnar Mills             return;
189398e386ecSGunnar Mills         }
189498e386ecSGunnar Mills 
189598e386ecSGunnar Mills         const std::string& path = subtree[0].first;
189698e386ecSGunnar Mills         const std::string& service = subtree[0].second.begin()->first;
189798e386ecSGunnar Mills 
189898e386ecSGunnar Mills         if (service.empty())
189998e386ecSGunnar Mills         {
190062598e31SEd Tanous             BMCWEB_LOG_DEBUG("Asset Tag Set service mapper error!");
1901ac106bf6SEd Tanous             messages::internalError(asyncResp->res);
190298e386ecSGunnar Mills             return;
190398e386ecSGunnar Mills         }
190498e386ecSGunnar Mills 
19059ae226faSGeorge Liu         sdbusplus::asio::setProperty(
19069ae226faSGeorge Liu             *crow::connections::systemBus, service, path,
19079ae226faSGeorge Liu             "xyz.openbmc_project.Inventory.Decorator.AssetTag", "AssetTag",
19089ae226faSGeorge Liu             assetTag, [asyncResp](const boost::system::error_code& ec2) {
190998e386ecSGunnar Mills                 if (ec2)
191098e386ecSGunnar Mills                 {
1911*b3e86cb0SGunnar Mills                     BMCWEB_LOG_ERROR("D-Bus response error on AssetTag Set {}",
191262598e31SEd Tanous                                      ec2);
1913ac106bf6SEd Tanous                     messages::internalError(asyncResp->res);
191498e386ecSGunnar Mills                     return;
191598e386ecSGunnar Mills                 }
19169ae226faSGeorge Liu             });
1917e99073f5SGeorge Liu         });
191898e386ecSGunnar Mills }
191998e386ecSGunnar Mills 
192098e386ecSGunnar Mills /**
19219dcfe8c1SAlbert Zhang  * @brief Validate the specified stopBootOnFault is valid and return the
19229dcfe8c1SAlbert Zhang  * stopBootOnFault name associated with that string
19239dcfe8c1SAlbert Zhang  *
19249dcfe8c1SAlbert Zhang  * @param[in] stopBootOnFaultString  String representing the desired
19259dcfe8c1SAlbert Zhang  * stopBootOnFault
19269dcfe8c1SAlbert Zhang  *
19279dcfe8c1SAlbert Zhang  * @return stopBootOnFault value or empty  if incoming value is not valid
19289dcfe8c1SAlbert Zhang  */
19299dcfe8c1SAlbert Zhang inline std::optional<bool>
19309dcfe8c1SAlbert Zhang     validstopBootOnFault(const std::string& stopBootOnFaultString)
19319dcfe8c1SAlbert Zhang {
19329dcfe8c1SAlbert Zhang     if (stopBootOnFaultString == "AnyFault")
19339dcfe8c1SAlbert Zhang     {
19349dcfe8c1SAlbert Zhang         return true;
19359dcfe8c1SAlbert Zhang     }
19369dcfe8c1SAlbert Zhang 
19379dcfe8c1SAlbert Zhang     if (stopBootOnFaultString == "Never")
19389dcfe8c1SAlbert Zhang     {
19399dcfe8c1SAlbert Zhang         return false;
19409dcfe8c1SAlbert Zhang     }
19419dcfe8c1SAlbert Zhang 
19429dcfe8c1SAlbert Zhang     return std::nullopt;
19439dcfe8c1SAlbert Zhang }
19449dcfe8c1SAlbert Zhang 
19459dcfe8c1SAlbert Zhang /**
19469dcfe8c1SAlbert Zhang  * @brief Sets stopBootOnFault
19479dcfe8c1SAlbert Zhang  *
1948fc3edfddSEd Tanous  * @param[in] asyncResp   Shared pointer for generating response message.
19499dcfe8c1SAlbert Zhang  * @param[in] stopBootOnFault  "StopBootOnFault" from request.
19509dcfe8c1SAlbert Zhang  *
19519dcfe8c1SAlbert Zhang  * @return None.
19529dcfe8c1SAlbert Zhang  */
1953fc3edfddSEd Tanous inline void
1954fc3edfddSEd Tanous     setStopBootOnFault(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
19559dcfe8c1SAlbert Zhang                        const std::string& stopBootOnFault)
19569dcfe8c1SAlbert Zhang {
195762598e31SEd Tanous     BMCWEB_LOG_DEBUG("Set Stop Boot On Fault.");
19589dcfe8c1SAlbert Zhang 
19599dcfe8c1SAlbert Zhang     std::optional<bool> stopBootEnabled = validstopBootOnFault(stopBootOnFault);
19609dcfe8c1SAlbert Zhang     if (!stopBootEnabled)
19619dcfe8c1SAlbert Zhang     {
196262598e31SEd Tanous         BMCWEB_LOG_DEBUG("Invalid property value for StopBootOnFault: {}",
196362598e31SEd Tanous                          stopBootOnFault);
1964fc3edfddSEd Tanous         messages::propertyValueNotInList(asyncResp->res, stopBootOnFault,
19659dcfe8c1SAlbert Zhang                                          "StopBootOnFault");
19669dcfe8c1SAlbert Zhang         return;
19679dcfe8c1SAlbert Zhang     }
19689dcfe8c1SAlbert Zhang 
1969fc3edfddSEd Tanous     sdbusplus::asio::setProperty(
1970fc3edfddSEd Tanous         *crow::connections::systemBus, "xyz.openbmc_project.Settings",
19719dcfe8c1SAlbert Zhang         "/xyz/openbmc_project/logging/settings",
1972fc3edfddSEd Tanous         "xyz.openbmc_project.Logging.Settings", "QuiesceOnHwError",
1973fc3edfddSEd Tanous         *stopBootEnabled, [asyncResp](const boost::system::error_code& ec) {
19749dcfe8c1SAlbert Zhang             if (ec)
19759dcfe8c1SAlbert Zhang             {
19769dcfe8c1SAlbert Zhang                 if (ec.value() != EBADR)
19779dcfe8c1SAlbert Zhang                 {
1978*b3e86cb0SGunnar Mills                     BMCWEB_LOG_ERROR("DBUS response error {}", ec);
1979fc3edfddSEd Tanous                     messages::internalError(asyncResp->res);
19809dcfe8c1SAlbert Zhang                 }
19819dcfe8c1SAlbert Zhang                 return;
19829dcfe8c1SAlbert Zhang             }
19839dcfe8c1SAlbert Zhang         });
19849dcfe8c1SAlbert Zhang }
19859dcfe8c1SAlbert Zhang 
19869dcfe8c1SAlbert Zhang /**
198769f35306SGunnar Mills  * @brief Sets automaticRetry (Auto Reboot)
198869f35306SGunnar Mills  *
1989ac106bf6SEd Tanous  * @param[in] asyncResp   Shared pointer for generating response message.
199069f35306SGunnar Mills  * @param[in] automaticRetryConfig  "AutomaticRetryConfig" from request.
199169f35306SGunnar Mills  *
199269f35306SGunnar Mills  * @return None.
199369f35306SGunnar Mills  */
1994ac106bf6SEd Tanous inline void
1995ac106bf6SEd Tanous     setAutomaticRetry(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
1996f23b7296SEd Tanous                       const std::string& automaticRetryConfig)
199769f35306SGunnar Mills {
199862598e31SEd Tanous     BMCWEB_LOG_DEBUG("Set Automatic Retry.");
199969f35306SGunnar Mills 
200069f35306SGunnar Mills     // OpenBMC only supports "Disabled" and "RetryAttempts".
2001543f4400SEd Tanous     bool autoRebootEnabled = false;
200269f35306SGunnar Mills 
200369f35306SGunnar Mills     if (automaticRetryConfig == "Disabled")
200469f35306SGunnar Mills     {
200569f35306SGunnar Mills         autoRebootEnabled = false;
200669f35306SGunnar Mills     }
200769f35306SGunnar Mills     else if (automaticRetryConfig == "RetryAttempts")
200869f35306SGunnar Mills     {
200969f35306SGunnar Mills         autoRebootEnabled = true;
201069f35306SGunnar Mills     }
201169f35306SGunnar Mills     else
201269f35306SGunnar Mills     {
201362598e31SEd Tanous         BMCWEB_LOG_DEBUG("Invalid property value for AutomaticRetryConfig: {}",
201462598e31SEd Tanous                          automaticRetryConfig);
2015ac106bf6SEd Tanous         messages::propertyValueNotInList(asyncResp->res, automaticRetryConfig,
201669f35306SGunnar Mills                                          "AutomaticRetryConfig");
201769f35306SGunnar Mills         return;
201869f35306SGunnar Mills     }
201969f35306SGunnar Mills 
20209ae226faSGeorge Liu     sdbusplus::asio::setProperty(
20219ae226faSGeorge Liu         *crow::connections::systemBus, "xyz.openbmc_project.Settings",
20229ae226faSGeorge Liu         "/xyz/openbmc_project/control/host0/auto_reboot",
20239ae226faSGeorge Liu         "xyz.openbmc_project.Control.Boot.RebootPolicy", "AutoReboot",
20249ae226faSGeorge Liu         autoRebootEnabled, [asyncResp](const boost::system::error_code& ec) {
202569f35306SGunnar Mills             if (ec)
202669f35306SGunnar Mills             {
2027*b3e86cb0SGunnar Mills                 BMCWEB_LOG_ERROR("DBUS response error {}", ec);
2028ac106bf6SEd Tanous                 messages::internalError(asyncResp->res);
202969f35306SGunnar Mills                 return;
203069f35306SGunnar Mills             }
20319ae226faSGeorge Liu         });
203269f35306SGunnar Mills }
203369f35306SGunnar Mills 
20348d69c668SEd Tanous inline std::string dbusPowerRestorePolicyFromRedfish(std::string_view policy)
20358d69c668SEd Tanous {
20368d69c668SEd Tanous     if (policy == "AlwaysOn")
20378d69c668SEd Tanous     {
20388d69c668SEd Tanous         return "xyz.openbmc_project.Control.Power.RestorePolicy.Policy.AlwaysOn";
20398d69c668SEd Tanous     }
20408d69c668SEd Tanous     if (policy == "AlwaysOff")
20418d69c668SEd Tanous     {
20428d69c668SEd Tanous         return "xyz.openbmc_project.Control.Power.RestorePolicy.Policy.AlwaysOff";
20438d69c668SEd Tanous     }
20448d69c668SEd Tanous     if (policy == "LastState")
20458d69c668SEd Tanous     {
20468d69c668SEd Tanous         return "xyz.openbmc_project.Control.Power.RestorePolicy.Policy.Restore";
20478d69c668SEd Tanous     }
20488d69c668SEd Tanous     return "";
20498d69c668SEd Tanous }
20508d69c668SEd Tanous 
205169f35306SGunnar Mills /**
2052c6a620f2SGeorge Liu  * @brief Sets power restore policy properties.
2053c6a620f2SGeorge Liu  *
2054ac106bf6SEd Tanous  * @param[in] asyncResp   Shared pointer for generating response message.
2055c6a620f2SGeorge Liu  * @param[in] policy  power restore policy properties from request.
2056c6a620f2SGeorge Liu  *
2057c6a620f2SGeorge Liu  * @return None.
2058c6a620f2SGeorge Liu  */
20598d1b46d7Szhanghch05 inline void
2060ac106bf6SEd Tanous     setPowerRestorePolicy(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
20618d69c668SEd Tanous                           std::string_view policy)
2062c6a620f2SGeorge Liu {
206362598e31SEd Tanous     BMCWEB_LOG_DEBUG("Set power restore policy.");
2064c6a620f2SGeorge Liu 
20658d69c668SEd Tanous     std::string powerRestorePolicy = dbusPowerRestorePolicyFromRedfish(policy);
2066c6a620f2SGeorge Liu 
20678d69c668SEd Tanous     if (powerRestorePolicy.empty())
2068c6a620f2SGeorge Liu     {
2069ac106bf6SEd Tanous         messages::propertyValueNotInList(asyncResp->res, policy,
20704e69c904SGunnar Mills                                          "PowerRestorePolicy");
2071c6a620f2SGeorge Liu         return;
2072c6a620f2SGeorge Liu     }
2073c6a620f2SGeorge Liu 
20749ae226faSGeorge Liu     sdbusplus::asio::setProperty(
20759ae226faSGeorge Liu         *crow::connections::systemBus, "xyz.openbmc_project.Settings",
20769ae226faSGeorge Liu         "/xyz/openbmc_project/control/host0/power_restore_policy",
20779ae226faSGeorge Liu         "xyz.openbmc_project.Control.Power.RestorePolicy", "PowerRestorePolicy",
20789ae226faSGeorge Liu         powerRestorePolicy, [asyncResp](const boost::system::error_code& ec) {
2079c6a620f2SGeorge Liu             if (ec)
2080c6a620f2SGeorge Liu             {
2081*b3e86cb0SGunnar Mills                 BMCWEB_LOG_ERROR("DBUS response error {}", ec);
2082ac106bf6SEd Tanous                 messages::internalError(asyncResp->res);
2083c6a620f2SGeorge Liu                 return;
2084c6a620f2SGeorge Liu             }
20859ae226faSGeorge Liu         });
2086c6a620f2SGeorge Liu }
2087c6a620f2SGeorge Liu 
2088a6349918SAppaRao Puli #ifdef BMCWEB_ENABLE_REDFISH_PROVISIONING_FEATURE
2089a6349918SAppaRao Puli /**
2090a6349918SAppaRao Puli  * @brief Retrieves provisioning status
2091a6349918SAppaRao Puli  *
2092ac106bf6SEd Tanous  * @param[in] asyncResp     Shared pointer for completing asynchronous calls.
2093a6349918SAppaRao Puli  *
2094a6349918SAppaRao Puli  * @return None.
2095a6349918SAppaRao Puli  */
2096ac106bf6SEd Tanous inline void getProvisioningStatus(std::shared_ptr<bmcweb::AsyncResp> asyncResp)
2097a6349918SAppaRao Puli {
209862598e31SEd Tanous     BMCWEB_LOG_DEBUG("Get OEM information.");
2099bc1d29deSKrzysztof Grobelny     sdbusplus::asio::getAllProperties(
2100bc1d29deSKrzysztof Grobelny         *crow::connections::systemBus, "xyz.openbmc_project.PFR.Manager",
2101bc1d29deSKrzysztof Grobelny         "/xyz/openbmc_project/pfr", "xyz.openbmc_project.PFR.Attributes",
2102ac106bf6SEd Tanous         [asyncResp](const boost::system::error_code& ec,
2103b9d36b47SEd Tanous                     const dbus::utility::DBusPropertiesMap& propertiesList) {
2104b99fb1a9SAppaRao Puli         nlohmann::json& oemPFR =
2105ac106bf6SEd Tanous             asyncResp->res.jsonValue["Oem"]["OpenBmc"]["FirmwareProvisioning"];
2106ac106bf6SEd Tanous         asyncResp->res.jsonValue["Oem"]["OpenBmc"]["@odata.type"] =
210750626f4fSJames Feist             "#OemComputerSystem.OpenBmc";
210850626f4fSJames Feist         oemPFR["@odata.type"] = "#OemComputerSystem.FirmwareProvisioning";
210950626f4fSJames Feist 
2110a6349918SAppaRao Puli         if (ec)
2111a6349918SAppaRao Puli         {
211262598e31SEd Tanous             BMCWEB_LOG_DEBUG("DBUS response error {}", ec);
2113b99fb1a9SAppaRao Puli             // not an error, don't have to have the interface
2114b99fb1a9SAppaRao Puli             oemPFR["ProvisioningStatus"] = "NotProvisioned";
2115a6349918SAppaRao Puli             return;
2116a6349918SAppaRao Puli         }
2117a6349918SAppaRao Puli 
2118a6349918SAppaRao Puli         const bool* provState = nullptr;
2119a6349918SAppaRao Puli         const bool* lockState = nullptr;
2120bc1d29deSKrzysztof Grobelny 
2121bc1d29deSKrzysztof Grobelny         const bool success = sdbusplus::unpackPropertiesNoThrow(
21220d4befa8SJiaqing Zhao             dbus_utils::UnpackErrorPrinter(), propertiesList, "UfmProvisioned",
21230d4befa8SJiaqing Zhao             provState, "UfmLocked", lockState);
2124bc1d29deSKrzysztof Grobelny 
2125bc1d29deSKrzysztof Grobelny         if (!success)
2126a6349918SAppaRao Puli         {
2127ac106bf6SEd Tanous             messages::internalError(asyncResp->res);
2128bc1d29deSKrzysztof Grobelny             return;
2129a6349918SAppaRao Puli         }
2130a6349918SAppaRao Puli 
2131a6349918SAppaRao Puli         if ((provState == nullptr) || (lockState == nullptr))
2132a6349918SAppaRao Puli         {
213362598e31SEd Tanous             BMCWEB_LOG_DEBUG("Unable to get PFR attributes.");
2134ac106bf6SEd Tanous             messages::internalError(asyncResp->res);
2135a6349918SAppaRao Puli             return;
2136a6349918SAppaRao Puli         }
2137a6349918SAppaRao Puli 
2138a6349918SAppaRao Puli         if (*provState == true)
2139a6349918SAppaRao Puli         {
2140a6349918SAppaRao Puli             if (*lockState == true)
2141a6349918SAppaRao Puli             {
2142a6349918SAppaRao Puli                 oemPFR["ProvisioningStatus"] = "ProvisionedAndLocked";
2143a6349918SAppaRao Puli             }
2144a6349918SAppaRao Puli             else
2145a6349918SAppaRao Puli             {
2146a6349918SAppaRao Puli                 oemPFR["ProvisioningStatus"] = "ProvisionedButNotLocked";
2147a6349918SAppaRao Puli             }
2148a6349918SAppaRao Puli         }
2149a6349918SAppaRao Puli         else
2150a6349918SAppaRao Puli         {
2151a6349918SAppaRao Puli             oemPFR["ProvisioningStatus"] = "NotProvisioned";
2152a6349918SAppaRao Puli         }
2153bc1d29deSKrzysztof Grobelny         });
2154a6349918SAppaRao Puli }
2155a6349918SAppaRao Puli #endif
2156a6349918SAppaRao Puli 
2157491d8ee7SSantosh Puranik /**
21583a2d0424SChris Cain  * @brief Translate the PowerMode to a response message.
21593a2d0424SChris Cain  *
2160ac106bf6SEd Tanous  * @param[in] asyncResp  Shared pointer for generating response message.
21613a2d0424SChris Cain  * @param[in] modeValue  PowerMode value to be translated
21623a2d0424SChris Cain  *
21633a2d0424SChris Cain  * @return None.
21643a2d0424SChris Cain  */
2165ac106bf6SEd Tanous inline void
2166ac106bf6SEd Tanous     translatePowerMode(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
21673a2d0424SChris Cain                        const std::string& modeValue)
21683a2d0424SChris Cain {
21690fda0f12SGeorge Liu     if (modeValue == "xyz.openbmc_project.Control.Power.Mode.PowerMode.Static")
21703a2d0424SChris Cain     {
2171ac106bf6SEd Tanous         asyncResp->res.jsonValue["PowerMode"] = "Static";
21723a2d0424SChris Cain     }
21730fda0f12SGeorge Liu     else if (
21740fda0f12SGeorge Liu         modeValue ==
21750fda0f12SGeorge Liu         "xyz.openbmc_project.Control.Power.Mode.PowerMode.MaximumPerformance")
21763a2d0424SChris Cain     {
2177ac106bf6SEd Tanous         asyncResp->res.jsonValue["PowerMode"] = "MaximumPerformance";
21783a2d0424SChris Cain     }
21790fda0f12SGeorge Liu     else if (modeValue ==
21800fda0f12SGeorge Liu              "xyz.openbmc_project.Control.Power.Mode.PowerMode.PowerSaving")
21813a2d0424SChris Cain     {
2182ac106bf6SEd Tanous         asyncResp->res.jsonValue["PowerMode"] = "PowerSaving";
21833a2d0424SChris Cain     }
21840fda0f12SGeorge Liu     else if (modeValue ==
21850fda0f12SGeorge Liu              "xyz.openbmc_project.Control.Power.Mode.PowerMode.OEM")
21863a2d0424SChris Cain     {
2187ac106bf6SEd Tanous         asyncResp->res.jsonValue["PowerMode"] = "OEM";
21883a2d0424SChris Cain     }
21893a2d0424SChris Cain     else
21903a2d0424SChris Cain     {
21913a2d0424SChris Cain         // Any other values would be invalid
219262598e31SEd Tanous         BMCWEB_LOG_DEBUG("PowerMode value was not valid: {}", modeValue);
2193ac106bf6SEd Tanous         messages::internalError(asyncResp->res);
21943a2d0424SChris Cain     }
21953a2d0424SChris Cain }
21963a2d0424SChris Cain 
21973a2d0424SChris Cain /**
21983a2d0424SChris Cain  * @brief Retrieves system power mode
21993a2d0424SChris Cain  *
2200ac106bf6SEd Tanous  * @param[in] asyncResp  Shared pointer for generating response message.
22013a2d0424SChris Cain  *
22023a2d0424SChris Cain  * @return None.
22033a2d0424SChris Cain  */
2204ac106bf6SEd Tanous inline void getPowerMode(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp)
22053a2d0424SChris Cain {
220662598e31SEd Tanous     BMCWEB_LOG_DEBUG("Get power mode.");
22073a2d0424SChris Cain 
22083a2d0424SChris Cain     // Get Power Mode object path:
2209e99073f5SGeorge Liu     constexpr std::array<std::string_view, 1> interfaces = {
2210e99073f5SGeorge Liu         "xyz.openbmc_project.Control.Power.Mode"};
2211e99073f5SGeorge Liu     dbus::utility::getSubTree(
2212e99073f5SGeorge Liu         "/", 0, interfaces,
2213ac106bf6SEd Tanous         [asyncResp](const boost::system::error_code& ec,
2214b9d36b47SEd Tanous                     const dbus::utility::MapperGetSubTreeResponse& subtree) {
22153a2d0424SChris Cain         if (ec)
22163a2d0424SChris Cain         {
221762598e31SEd Tanous             BMCWEB_LOG_DEBUG("DBUS response error on Power.Mode GetSubTree {}",
221862598e31SEd Tanous                              ec);
22193a2d0424SChris Cain             // This is an optional D-Bus object so just return if
22203a2d0424SChris Cain             // error occurs
22213a2d0424SChris Cain             return;
22223a2d0424SChris Cain         }
22233a2d0424SChris Cain         if (subtree.empty())
22243a2d0424SChris Cain         {
22253a2d0424SChris Cain             // As noted above, this is an optional interface so just return
22263a2d0424SChris Cain             // if there is no instance found
22273a2d0424SChris Cain             return;
22283a2d0424SChris Cain         }
22293a2d0424SChris Cain         if (subtree.size() > 1)
22303a2d0424SChris Cain         {
22313a2d0424SChris Cain             // More then one PowerMode object is not supported and is an
22323a2d0424SChris Cain             // error
223362598e31SEd Tanous             BMCWEB_LOG_DEBUG(
223462598e31SEd Tanous                 "Found more than 1 system D-Bus Power.Mode objects: {}",
223562598e31SEd Tanous                 subtree.size());
2236ac106bf6SEd Tanous             messages::internalError(asyncResp->res);
22373a2d0424SChris Cain             return;
22383a2d0424SChris Cain         }
22393a2d0424SChris Cain         if ((subtree[0].first.empty()) || (subtree[0].second.size() != 1))
22403a2d0424SChris Cain         {
224162598e31SEd Tanous             BMCWEB_LOG_DEBUG("Power.Mode mapper error!");
2242ac106bf6SEd Tanous             messages::internalError(asyncResp->res);
22433a2d0424SChris Cain             return;
22443a2d0424SChris Cain         }
22453a2d0424SChris Cain         const std::string& path = subtree[0].first;
22463a2d0424SChris Cain         const std::string& service = subtree[0].second.begin()->first;
22473a2d0424SChris Cain         if (service.empty())
22483a2d0424SChris Cain         {
224962598e31SEd Tanous             BMCWEB_LOG_DEBUG("Power.Mode service mapper error!");
2250ac106bf6SEd Tanous             messages::internalError(asyncResp->res);
22513a2d0424SChris Cain             return;
22523a2d0424SChris Cain         }
22533a2d0424SChris Cain         // Valid Power Mode object found, now read the current value
22541e1e598dSJonathan Doman         sdbusplus::asio::getProperty<std::string>(
22551e1e598dSJonathan Doman             *crow::connections::systemBus, service, path,
22561e1e598dSJonathan Doman             "xyz.openbmc_project.Control.Power.Mode", "PowerMode",
2257ac106bf6SEd Tanous             [asyncResp](const boost::system::error_code& ec2,
22581e1e598dSJonathan Doman                         const std::string& pmode) {
22598a592810SEd Tanous             if (ec2)
22603a2d0424SChris Cain             {
2261*b3e86cb0SGunnar Mills                 BMCWEB_LOG_ERROR("DBUS response error on PowerMode Get: {}",
226262598e31SEd Tanous                                  ec2);
2263ac106bf6SEd Tanous                 messages::internalError(asyncResp->res);
22643a2d0424SChris Cain                 return;
22653a2d0424SChris Cain             }
22663a2d0424SChris Cain 
2267ac106bf6SEd Tanous             asyncResp->res.jsonValue["PowerMode@Redfish.AllowableValues"] = {
2268002d39b4SEd Tanous                 "Static", "MaximumPerformance", "PowerSaving"};
22693a2d0424SChris Cain 
227062598e31SEd Tanous             BMCWEB_LOG_DEBUG("Current power mode: {}", pmode);
2271ac106bf6SEd Tanous             translatePowerMode(asyncResp, pmode);
22721e1e598dSJonathan Doman             });
2273e99073f5SGeorge Liu         });
22743a2d0424SChris Cain }
22753a2d0424SChris Cain 
22763a2d0424SChris Cain /**
22773a2d0424SChris Cain  * @brief Validate the specified mode is valid and return the PowerMode
22783a2d0424SChris Cain  * name associated with that string
22793a2d0424SChris Cain  *
2280ac106bf6SEd Tanous  * @param[in] asyncResp   Shared pointer for generating response message.
22813a2d0424SChris Cain  * @param[in] modeString  String representing the desired PowerMode
22823a2d0424SChris Cain  *
22833a2d0424SChris Cain  * @return PowerMode value or empty string if mode is not valid
22843a2d0424SChris Cain  */
22853a2d0424SChris Cain inline std::string
2286ac106bf6SEd Tanous     validatePowerMode(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
22873a2d0424SChris Cain                       const std::string& modeString)
22883a2d0424SChris Cain {
22893a2d0424SChris Cain     std::string mode;
22903a2d0424SChris Cain 
22913a2d0424SChris Cain     if (modeString == "Static")
22923a2d0424SChris Cain     {
22933a2d0424SChris Cain         mode = "xyz.openbmc_project.Control.Power.Mode.PowerMode.Static";
22943a2d0424SChris Cain     }
22953a2d0424SChris Cain     else if (modeString == "MaximumPerformance")
22963a2d0424SChris Cain     {
22970fda0f12SGeorge Liu         mode =
22980fda0f12SGeorge Liu             "xyz.openbmc_project.Control.Power.Mode.PowerMode.MaximumPerformance";
22993a2d0424SChris Cain     }
23003a2d0424SChris Cain     else if (modeString == "PowerSaving")
23013a2d0424SChris Cain     {
23023a2d0424SChris Cain         mode = "xyz.openbmc_project.Control.Power.Mode.PowerMode.PowerSaving";
23033a2d0424SChris Cain     }
23043a2d0424SChris Cain     else
23053a2d0424SChris Cain     {
2306ac106bf6SEd Tanous         messages::propertyValueNotInList(asyncResp->res, modeString,
2307ac106bf6SEd Tanous                                          "PowerMode");
23083a2d0424SChris Cain     }
23093a2d0424SChris Cain     return mode;
23103a2d0424SChris Cain }
23113a2d0424SChris Cain 
23123a2d0424SChris Cain /**
23133a2d0424SChris Cain  * @brief Sets system power mode.
23143a2d0424SChris Cain  *
2315ac106bf6SEd Tanous  * @param[in] asyncResp   Shared pointer for generating response message.
23163a2d0424SChris Cain  * @param[in] pmode   System power mode from request.
23173a2d0424SChris Cain  *
23183a2d0424SChris Cain  * @return None.
23193a2d0424SChris Cain  */
2320ac106bf6SEd Tanous inline void setPowerMode(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
23213a2d0424SChris Cain                          const std::string& pmode)
23223a2d0424SChris Cain {
232362598e31SEd Tanous     BMCWEB_LOG_DEBUG("Set power mode.");
23243a2d0424SChris Cain 
2325ac106bf6SEd Tanous     std::string powerMode = validatePowerMode(asyncResp, pmode);
23263a2d0424SChris Cain     if (powerMode.empty())
23273a2d0424SChris Cain     {
23283a2d0424SChris Cain         return;
23293a2d0424SChris Cain     }
23303a2d0424SChris Cain 
23313a2d0424SChris Cain     // Get Power Mode object path:
2332e99073f5SGeorge Liu     constexpr std::array<std::string_view, 1> interfaces = {
2333e99073f5SGeorge Liu         "xyz.openbmc_project.Control.Power.Mode"};
2334e99073f5SGeorge Liu     dbus::utility::getSubTree(
2335e99073f5SGeorge Liu         "/", 0, interfaces,
2336ac106bf6SEd Tanous         [asyncResp,
2337e99073f5SGeorge Liu          powerMode](const boost::system::error_code& ec,
2338b9d36b47SEd Tanous                     const dbus::utility::MapperGetSubTreeResponse& subtree) {
23393a2d0424SChris Cain         if (ec)
23403a2d0424SChris Cain         {
2341*b3e86cb0SGunnar Mills             BMCWEB_LOG_ERROR("DBUS response error on Power.Mode GetSubTree {}",
234262598e31SEd Tanous                              ec);
23433a2d0424SChris Cain             // This is an optional D-Bus object, but user attempted to patch
2344ac106bf6SEd Tanous             messages::internalError(asyncResp->res);
23453a2d0424SChris Cain             return;
23463a2d0424SChris Cain         }
23473a2d0424SChris Cain         if (subtree.empty())
23483a2d0424SChris Cain         {
23493a2d0424SChris Cain             // This is an optional D-Bus object, but user attempted to patch
2350ac106bf6SEd Tanous             messages::resourceNotFound(asyncResp->res, "ComputerSystem",
23513a2d0424SChris Cain                                        "PowerMode");
23523a2d0424SChris Cain             return;
23533a2d0424SChris Cain         }
23543a2d0424SChris Cain         if (subtree.size() > 1)
23553a2d0424SChris Cain         {
23563a2d0424SChris Cain             // More then one PowerMode object is not supported and is an
23573a2d0424SChris Cain             // error
235862598e31SEd Tanous             BMCWEB_LOG_DEBUG(
235962598e31SEd Tanous                 "Found more than 1 system D-Bus Power.Mode objects: {}",
236062598e31SEd Tanous                 subtree.size());
2361ac106bf6SEd Tanous             messages::internalError(asyncResp->res);
23623a2d0424SChris Cain             return;
23633a2d0424SChris Cain         }
23643a2d0424SChris Cain         if ((subtree[0].first.empty()) || (subtree[0].second.size() != 1))
23653a2d0424SChris Cain         {
236662598e31SEd Tanous             BMCWEB_LOG_DEBUG("Power.Mode mapper error!");
2367ac106bf6SEd Tanous             messages::internalError(asyncResp->res);
23683a2d0424SChris Cain             return;
23693a2d0424SChris Cain         }
23703a2d0424SChris Cain         const std::string& path = subtree[0].first;
23713a2d0424SChris Cain         const std::string& service = subtree[0].second.begin()->first;
23723a2d0424SChris Cain         if (service.empty())
23733a2d0424SChris Cain         {
237462598e31SEd Tanous             BMCWEB_LOG_DEBUG("Power.Mode service mapper error!");
2375ac106bf6SEd Tanous             messages::internalError(asyncResp->res);
23763a2d0424SChris Cain             return;
23773a2d0424SChris Cain         }
23783a2d0424SChris Cain 
237962598e31SEd Tanous         BMCWEB_LOG_DEBUG("Setting power mode({}) -> {}", powerMode, path);
23803a2d0424SChris Cain 
23813a2d0424SChris Cain         // Set the Power Mode property
23829ae226faSGeorge Liu         sdbusplus::asio::setProperty(
23839ae226faSGeorge Liu             *crow::connections::systemBus, service, path,
23849ae226faSGeorge Liu             "xyz.openbmc_project.Control.Power.Mode", "PowerMode", powerMode,
2385ac106bf6SEd Tanous             [asyncResp](const boost::system::error_code& ec2) {
23868a592810SEd Tanous             if (ec2)
23873a2d0424SChris Cain             {
2388*b3e86cb0SGunnar Mills                 BMCWEB_LOG_ERROR("DBUS response error {}", ec2);
2389ac106bf6SEd Tanous                 messages::internalError(asyncResp->res);
23903a2d0424SChris Cain                 return;
23913a2d0424SChris Cain             }
23929ae226faSGeorge Liu             });
2393e99073f5SGeorge Liu         });
23943a2d0424SChris Cain }
23953a2d0424SChris Cain 
23963a2d0424SChris Cain /**
239751709ffdSYong Li  * @brief Translates watchdog timeout action DBUS property value to redfish.
239851709ffdSYong Li  *
239951709ffdSYong Li  * @param[in] dbusAction    The watchdog timeout action in D-BUS.
240051709ffdSYong Li  *
240151709ffdSYong Li  * @return Returns as a string, the timeout action in Redfish terms. If
240251709ffdSYong Li  * translation cannot be done, returns an empty string.
240351709ffdSYong Li  */
240423a21a1cSEd Tanous inline std::string dbusToRfWatchdogAction(const std::string& dbusAction)
240551709ffdSYong Li {
240651709ffdSYong Li     if (dbusAction == "xyz.openbmc_project.State.Watchdog.Action.None")
240751709ffdSYong Li     {
240851709ffdSYong Li         return "None";
240951709ffdSYong Li     }
24103174e4dfSEd Tanous     if (dbusAction == "xyz.openbmc_project.State.Watchdog.Action.HardReset")
241151709ffdSYong Li     {
241251709ffdSYong Li         return "ResetSystem";
241351709ffdSYong Li     }
24143174e4dfSEd Tanous     if (dbusAction == "xyz.openbmc_project.State.Watchdog.Action.PowerOff")
241551709ffdSYong Li     {
241651709ffdSYong Li         return "PowerDown";
241751709ffdSYong Li     }
24183174e4dfSEd Tanous     if (dbusAction == "xyz.openbmc_project.State.Watchdog.Action.PowerCycle")
241951709ffdSYong Li     {
242051709ffdSYong Li         return "PowerCycle";
242151709ffdSYong Li     }
242251709ffdSYong Li 
242351709ffdSYong Li     return "";
242451709ffdSYong Li }
242551709ffdSYong Li 
242651709ffdSYong Li /**
2427c45f0082SYong Li  *@brief Translates timeout action from Redfish to DBUS property value.
2428c45f0082SYong Li  *
2429c45f0082SYong Li  *@param[in] rfAction The timeout action in Redfish.
2430c45f0082SYong Li  *
2431c45f0082SYong Li  *@return Returns as a string, the time_out action as expected by DBUS.
2432c45f0082SYong Li  *If translation cannot be done, returns an empty string.
2433c45f0082SYong Li  */
2434c45f0082SYong Li 
243523a21a1cSEd Tanous inline std::string rfToDbusWDTTimeOutAct(const std::string& rfAction)
2436c45f0082SYong Li {
2437c45f0082SYong Li     if (rfAction == "None")
2438c45f0082SYong Li     {
2439c45f0082SYong Li         return "xyz.openbmc_project.State.Watchdog.Action.None";
2440c45f0082SYong Li     }
24413174e4dfSEd Tanous     if (rfAction == "PowerCycle")
2442c45f0082SYong Li     {
2443c45f0082SYong Li         return "xyz.openbmc_project.State.Watchdog.Action.PowerCycle";
2444c45f0082SYong Li     }
24453174e4dfSEd Tanous     if (rfAction == "PowerDown")
2446c45f0082SYong Li     {
2447c45f0082SYong Li         return "xyz.openbmc_project.State.Watchdog.Action.PowerOff";
2448c45f0082SYong Li     }
24493174e4dfSEd Tanous     if (rfAction == "ResetSystem")
2450c45f0082SYong Li     {
2451c45f0082SYong Li         return "xyz.openbmc_project.State.Watchdog.Action.HardReset";
2452c45f0082SYong Li     }
2453c45f0082SYong Li 
2454c45f0082SYong Li     return "";
2455c45f0082SYong Li }
2456c45f0082SYong Li 
2457c45f0082SYong Li /**
245851709ffdSYong Li  * @brief Retrieves host watchdog timer properties over DBUS
245951709ffdSYong Li  *
2460ac106bf6SEd Tanous  * @param[in] asyncResp     Shared pointer for completing asynchronous calls.
246151709ffdSYong Li  *
246251709ffdSYong Li  * @return None.
246351709ffdSYong Li  */
24648d1b46d7Szhanghch05 inline void
2465ac106bf6SEd Tanous     getHostWatchdogTimer(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp)
246651709ffdSYong Li {
246762598e31SEd Tanous     BMCWEB_LOG_DEBUG("Get host watchodg");
2468bc1d29deSKrzysztof Grobelny     sdbusplus::asio::getAllProperties(
2469bc1d29deSKrzysztof Grobelny         *crow::connections::systemBus, "xyz.openbmc_project.Watchdog",
2470bc1d29deSKrzysztof Grobelny         "/xyz/openbmc_project/watchdog/host0",
2471bc1d29deSKrzysztof Grobelny         "xyz.openbmc_project.State.Watchdog",
2472ac106bf6SEd Tanous         [asyncResp](const boost::system::error_code& ec,
2473b9d36b47SEd Tanous                     const dbus::utility::DBusPropertiesMap& properties) {
247451709ffdSYong Li         if (ec)
247551709ffdSYong Li         {
247651709ffdSYong Li             // watchdog service is stopped
247762598e31SEd Tanous             BMCWEB_LOG_DEBUG("DBUS response error {}", ec);
247851709ffdSYong Li             return;
247951709ffdSYong Li         }
248051709ffdSYong Li 
248162598e31SEd Tanous         BMCWEB_LOG_DEBUG("Got {} wdt prop.", properties.size());
248251709ffdSYong Li 
248351709ffdSYong Li         nlohmann::json& hostWatchdogTimer =
2484ac106bf6SEd Tanous             asyncResp->res.jsonValue["HostWatchdogTimer"];
248551709ffdSYong Li 
248651709ffdSYong Li         // watchdog service is running/enabled
248751709ffdSYong Li         hostWatchdogTimer["Status"]["State"] = "Enabled";
248851709ffdSYong Li 
2489bc1d29deSKrzysztof Grobelny         const bool* enabled = nullptr;
2490bc1d29deSKrzysztof Grobelny         const std::string* expireAction = nullptr;
249151709ffdSYong Li 
2492bc1d29deSKrzysztof Grobelny         const bool success = sdbusplus::unpackPropertiesNoThrow(
2493bc1d29deSKrzysztof Grobelny             dbus_utils::UnpackErrorPrinter(), properties, "Enabled", enabled,
2494bc1d29deSKrzysztof Grobelny             "ExpireAction", expireAction);
2495bc1d29deSKrzysztof Grobelny 
2496bc1d29deSKrzysztof Grobelny         if (!success)
249751709ffdSYong Li         {
2498ac106bf6SEd Tanous             messages::internalError(asyncResp->res);
2499601af5edSChicago Duan             return;
250051709ffdSYong Li         }
250151709ffdSYong Li 
2502bc1d29deSKrzysztof Grobelny         if (enabled != nullptr)
250351709ffdSYong Li         {
2504bc1d29deSKrzysztof Grobelny             hostWatchdogTimer["FunctionEnabled"] = *enabled;
250551709ffdSYong Li         }
250651709ffdSYong Li 
2507bc1d29deSKrzysztof Grobelny         if (expireAction != nullptr)
2508bc1d29deSKrzysztof Grobelny         {
2509bc1d29deSKrzysztof Grobelny             std::string action = dbusToRfWatchdogAction(*expireAction);
251051709ffdSYong Li             if (action.empty())
251151709ffdSYong Li             {
2512ac106bf6SEd Tanous                 messages::internalError(asyncResp->res);
2513601af5edSChicago Duan                 return;
251451709ffdSYong Li             }
251551709ffdSYong Li             hostWatchdogTimer["TimeoutAction"] = action;
251651709ffdSYong Li         }
2517bc1d29deSKrzysztof Grobelny         });
251851709ffdSYong Li }
251951709ffdSYong Li 
252051709ffdSYong Li /**
2521c45f0082SYong Li  * @brief Sets Host WatchDog Timer properties.
2522c45f0082SYong Li  *
2523ac106bf6SEd Tanous  * @param[in] asyncResp  Shared pointer for generating response message.
2524c45f0082SYong Li  * @param[in] wdtEnable  The WDTimer Enable value (true/false) from incoming
2525c45f0082SYong Li  *                       RF request.
2526c45f0082SYong Li  * @param[in] wdtTimeOutAction The WDT Timeout action, from incoming RF request.
2527c45f0082SYong Li  *
2528c45f0082SYong Li  * @return None.
2529c45f0082SYong Li  */
2530ac106bf6SEd Tanous inline void
2531ac106bf6SEd Tanous     setWDTProperties(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
2532c45f0082SYong Li                      const std::optional<bool> wdtEnable,
2533c45f0082SYong Li                      const std::optional<std::string>& wdtTimeOutAction)
2534c45f0082SYong Li {
253562598e31SEd Tanous     BMCWEB_LOG_DEBUG("Set host watchdog");
2536c45f0082SYong Li 
2537c45f0082SYong Li     if (wdtTimeOutAction)
2538c45f0082SYong Li     {
2539c45f0082SYong Li         std::string wdtTimeOutActStr = rfToDbusWDTTimeOutAct(*wdtTimeOutAction);
2540c45f0082SYong Li         // check if TimeOut Action is Valid
2541c45f0082SYong Li         if (wdtTimeOutActStr.empty())
2542c45f0082SYong Li         {
254362598e31SEd Tanous             BMCWEB_LOG_DEBUG("Unsupported value for TimeoutAction: {}",
254462598e31SEd Tanous                              *wdtTimeOutAction);
2545ac106bf6SEd Tanous             messages::propertyValueNotInList(asyncResp->res, *wdtTimeOutAction,
2546c45f0082SYong Li                                              "TimeoutAction");
2547c45f0082SYong Li             return;
2548c45f0082SYong Li         }
2549c45f0082SYong Li 
25509ae226faSGeorge Liu         sdbusplus::asio::setProperty(
25519ae226faSGeorge Liu             *crow::connections::systemBus, "xyz.openbmc_project.Watchdog",
25529ae226faSGeorge Liu             "/xyz/openbmc_project/watchdog/host0",
25539ae226faSGeorge Liu             "xyz.openbmc_project.State.Watchdog", "ExpireAction",
25549ae226faSGeorge Liu             wdtTimeOutActStr, [asyncResp](const boost::system::error_code& ec) {
2555c45f0082SYong Li                 if (ec)
2556c45f0082SYong Li                 {
2557*b3e86cb0SGunnar Mills                     BMCWEB_LOG_ERROR("DBUS response error {}", ec);
2558ac106bf6SEd Tanous                     messages::internalError(asyncResp->res);
2559c45f0082SYong Li                     return;
2560c45f0082SYong Li                 }
25619ae226faSGeorge Liu             });
2562c45f0082SYong Li     }
2563c45f0082SYong Li 
2564c45f0082SYong Li     if (wdtEnable)
2565c45f0082SYong Li     {
25669ae226faSGeorge Liu         sdbusplus::asio::setProperty(
25679ae226faSGeorge Liu             *crow::connections::systemBus, "xyz.openbmc_project.Watchdog",
25689ae226faSGeorge Liu             "/xyz/openbmc_project/watchdog/host0",
25699ae226faSGeorge Liu             "xyz.openbmc_project.State.Watchdog", "Enabled", *wdtEnable,
2570ac106bf6SEd Tanous             [asyncResp](const boost::system::error_code& ec) {
2571c45f0082SYong Li             if (ec)
2572c45f0082SYong Li             {
2573*b3e86cb0SGunnar Mills                 BMCWEB_LOG_ERROR("DBUS response error {}", ec);
2574ac106bf6SEd Tanous                 messages::internalError(asyncResp->res);
2575c45f0082SYong Li                 return;
2576c45f0082SYong Li             }
25779ae226faSGeorge Liu             });
2578c45f0082SYong Li     }
2579c45f0082SYong Li }
2580c45f0082SYong Li 
258137bbf98cSChris Cain /**
258237bbf98cSChris Cain  * @brief Parse the Idle Power Saver properties into json
258337bbf98cSChris Cain  *
2584ac106bf6SEd Tanous  * @param[in] asyncResp   Shared pointer for completing asynchronous calls.
258537bbf98cSChris Cain  * @param[in] properties  IPS property data from DBus.
258637bbf98cSChris Cain  *
258737bbf98cSChris Cain  * @return true if successful
258837bbf98cSChris Cain  */
25891e5b7c88SJiaqing Zhao inline bool
2590ac106bf6SEd Tanous     parseIpsProperties(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
25911e5b7c88SJiaqing Zhao                        const dbus::utility::DBusPropertiesMap& properties)
259237bbf98cSChris Cain {
2593bc1d29deSKrzysztof Grobelny     const bool* enabled = nullptr;
2594bc1d29deSKrzysztof Grobelny     const uint8_t* enterUtilizationPercent = nullptr;
2595bc1d29deSKrzysztof Grobelny     const uint64_t* enterDwellTime = nullptr;
2596bc1d29deSKrzysztof Grobelny     const uint8_t* exitUtilizationPercent = nullptr;
2597bc1d29deSKrzysztof Grobelny     const uint64_t* exitDwellTime = nullptr;
2598bc1d29deSKrzysztof Grobelny 
2599bc1d29deSKrzysztof Grobelny     const bool success = sdbusplus::unpackPropertiesNoThrow(
2600bc1d29deSKrzysztof Grobelny         dbus_utils::UnpackErrorPrinter(), properties, "Enabled", enabled,
26012661b72cSChris Cain         "EnterUtilizationPercent", enterUtilizationPercent, "EnterDwellTime",
26022661b72cSChris Cain         enterDwellTime, "ExitUtilizationPercent", exitUtilizationPercent,
26032661b72cSChris Cain         "ExitDwellTime", exitDwellTime);
2604bc1d29deSKrzysztof Grobelny 
2605bc1d29deSKrzysztof Grobelny     if (!success)
260637bbf98cSChris Cain     {
260737bbf98cSChris Cain         return false;
260837bbf98cSChris Cain     }
2609bc1d29deSKrzysztof Grobelny 
2610bc1d29deSKrzysztof Grobelny     if (enabled != nullptr)
261137bbf98cSChris Cain     {
2612ac106bf6SEd Tanous         asyncResp->res.jsonValue["IdlePowerSaver"]["Enabled"] = *enabled;
261337bbf98cSChris Cain     }
2614bc1d29deSKrzysztof Grobelny 
2615bc1d29deSKrzysztof Grobelny     if (enterUtilizationPercent != nullptr)
261637bbf98cSChris Cain     {
2617ac106bf6SEd Tanous         asyncResp->res.jsonValue["IdlePowerSaver"]["EnterUtilizationPercent"] =
2618bc1d29deSKrzysztof Grobelny             *enterUtilizationPercent;
261937bbf98cSChris Cain     }
2620bc1d29deSKrzysztof Grobelny 
2621bc1d29deSKrzysztof Grobelny     if (enterDwellTime != nullptr)
2622bc1d29deSKrzysztof Grobelny     {
2623bc1d29deSKrzysztof Grobelny         const std::chrono::duration<uint64_t, std::milli> ms(*enterDwellTime);
2624ac106bf6SEd Tanous         asyncResp->res.jsonValue["IdlePowerSaver"]["EnterDwellTimeSeconds"] =
262537bbf98cSChris Cain             std::chrono::duration_cast<std::chrono::duration<uint64_t>>(ms)
262637bbf98cSChris Cain                 .count();
262737bbf98cSChris Cain     }
2628bc1d29deSKrzysztof Grobelny 
2629bc1d29deSKrzysztof Grobelny     if (exitUtilizationPercent != nullptr)
263037bbf98cSChris Cain     {
2631ac106bf6SEd Tanous         asyncResp->res.jsonValue["IdlePowerSaver"]["ExitUtilizationPercent"] =
2632bc1d29deSKrzysztof Grobelny             *exitUtilizationPercent;
263337bbf98cSChris Cain     }
2634bc1d29deSKrzysztof Grobelny 
2635bc1d29deSKrzysztof Grobelny     if (exitDwellTime != nullptr)
263637bbf98cSChris Cain     {
2637bc1d29deSKrzysztof Grobelny         const std::chrono::duration<uint64_t, std::milli> ms(*exitDwellTime);
2638ac106bf6SEd Tanous         asyncResp->res.jsonValue["IdlePowerSaver"]["ExitDwellTimeSeconds"] =
263937bbf98cSChris Cain             std::chrono::duration_cast<std::chrono::duration<uint64_t>>(ms)
264037bbf98cSChris Cain                 .count();
264137bbf98cSChris Cain     }
264237bbf98cSChris Cain 
264337bbf98cSChris Cain     return true;
264437bbf98cSChris Cain }
264537bbf98cSChris Cain 
264637bbf98cSChris Cain /**
264737bbf98cSChris Cain  * @brief Retrieves host watchdog timer properties over DBUS
264837bbf98cSChris Cain  *
2649ac106bf6SEd Tanous  * @param[in] asyncResp     Shared pointer for completing asynchronous calls.
265037bbf98cSChris Cain  *
265137bbf98cSChris Cain  * @return None.
265237bbf98cSChris Cain  */
2653ac106bf6SEd Tanous inline void
2654ac106bf6SEd Tanous     getIdlePowerSaver(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp)
265537bbf98cSChris Cain {
265662598e31SEd Tanous     BMCWEB_LOG_DEBUG("Get idle power saver parameters");
265737bbf98cSChris Cain 
265837bbf98cSChris Cain     // Get IdlePowerSaver object path:
2659e99073f5SGeorge Liu     constexpr std::array<std::string_view, 1> interfaces = {
2660e99073f5SGeorge Liu         "xyz.openbmc_project.Control.Power.IdlePowerSaver"};
2661e99073f5SGeorge Liu     dbus::utility::getSubTree(
2662e99073f5SGeorge Liu         "/", 0, interfaces,
2663ac106bf6SEd Tanous         [asyncResp](const boost::system::error_code& ec,
2664b9d36b47SEd Tanous                     const dbus::utility::MapperGetSubTreeResponse& subtree) {
266537bbf98cSChris Cain         if (ec)
266637bbf98cSChris Cain         {
2667*b3e86cb0SGunnar Mills             BMCWEB_LOG_ERROR(
266862598e31SEd Tanous                 "DBUS response error on Power.IdlePowerSaver GetSubTree {}",
266962598e31SEd Tanous                 ec);
2670ac106bf6SEd Tanous             messages::internalError(asyncResp->res);
267137bbf98cSChris Cain             return;
267237bbf98cSChris Cain         }
267337bbf98cSChris Cain         if (subtree.empty())
267437bbf98cSChris Cain         {
267537bbf98cSChris Cain             // This is an optional interface so just return
267637bbf98cSChris Cain             // if there is no instance found
267762598e31SEd Tanous             BMCWEB_LOG_DEBUG("No instances found");
267837bbf98cSChris Cain             return;
267937bbf98cSChris Cain         }
268037bbf98cSChris Cain         if (subtree.size() > 1)
268137bbf98cSChris Cain         {
268237bbf98cSChris Cain             // More then one PowerIdlePowerSaver object is not supported and
268337bbf98cSChris Cain             // is an error
268462598e31SEd Tanous             BMCWEB_LOG_DEBUG("Found more than 1 system D-Bus "
268562598e31SEd Tanous                              "Power.IdlePowerSaver objects: {}",
268662598e31SEd Tanous                              subtree.size());
2687ac106bf6SEd Tanous             messages::internalError(asyncResp->res);
268837bbf98cSChris Cain             return;
268937bbf98cSChris Cain         }
269037bbf98cSChris Cain         if ((subtree[0].first.empty()) || (subtree[0].second.size() != 1))
269137bbf98cSChris Cain         {
269262598e31SEd Tanous             BMCWEB_LOG_DEBUG("Power.IdlePowerSaver mapper error!");
2693ac106bf6SEd Tanous             messages::internalError(asyncResp->res);
269437bbf98cSChris Cain             return;
269537bbf98cSChris Cain         }
269637bbf98cSChris Cain         const std::string& path = subtree[0].first;
269737bbf98cSChris Cain         const std::string& service = subtree[0].second.begin()->first;
269837bbf98cSChris Cain         if (service.empty())
269937bbf98cSChris Cain         {
270062598e31SEd Tanous             BMCWEB_LOG_DEBUG("Power.IdlePowerSaver service mapper error!");
2701ac106bf6SEd Tanous             messages::internalError(asyncResp->res);
270237bbf98cSChris Cain             return;
270337bbf98cSChris Cain         }
270437bbf98cSChris Cain 
270537bbf98cSChris Cain         // Valid IdlePowerSaver object found, now read the current values
2706bc1d29deSKrzysztof Grobelny         sdbusplus::asio::getAllProperties(
2707bc1d29deSKrzysztof Grobelny             *crow::connections::systemBus, service, path,
2708bc1d29deSKrzysztof Grobelny             "xyz.openbmc_project.Control.Power.IdlePowerSaver",
2709ac106bf6SEd Tanous             [asyncResp](const boost::system::error_code& ec2,
27101e5b7c88SJiaqing Zhao                         const dbus::utility::DBusPropertiesMap& properties) {
27118a592810SEd Tanous             if (ec2)
271237bbf98cSChris Cain             {
271362598e31SEd Tanous                 BMCWEB_LOG_ERROR(
271462598e31SEd Tanous                     "DBUS response error on IdlePowerSaver GetAll: {}", ec2);
2715ac106bf6SEd Tanous                 messages::internalError(asyncResp->res);
271637bbf98cSChris Cain                 return;
271737bbf98cSChris Cain             }
271837bbf98cSChris Cain 
2719ac106bf6SEd Tanous             if (!parseIpsProperties(asyncResp, properties))
272037bbf98cSChris Cain             {
2721ac106bf6SEd Tanous                 messages::internalError(asyncResp->res);
272237bbf98cSChris Cain                 return;
272337bbf98cSChris Cain             }
2724bc1d29deSKrzysztof Grobelny             });
2725e99073f5SGeorge Liu         });
272637bbf98cSChris Cain 
272762598e31SEd Tanous     BMCWEB_LOG_DEBUG("EXIT: Get idle power saver parameters");
272837bbf98cSChris Cain }
272937bbf98cSChris Cain 
273037bbf98cSChris Cain /**
273137bbf98cSChris Cain  * @brief Sets Idle Power Saver properties.
273237bbf98cSChris Cain  *
2733ac106bf6SEd Tanous  * @param[in] asyncResp  Shared pointer for generating response message.
273437bbf98cSChris Cain  * @param[in] ipsEnable  The IPS Enable value (true/false) from incoming
273537bbf98cSChris Cain  *                       RF request.
273637bbf98cSChris Cain  * @param[in] ipsEnterUtil The utilization limit to enter idle state.
273737bbf98cSChris Cain  * @param[in] ipsEnterTime The time the utilization must be below ipsEnterUtil
273837bbf98cSChris Cain  * before entering idle state.
273937bbf98cSChris Cain  * @param[in] ipsExitUtil The utilization limit when exiting idle state.
274037bbf98cSChris Cain  * @param[in] ipsExitTime The time the utilization must be above ipsExutUtil
274137bbf98cSChris Cain  * before exiting idle state
274237bbf98cSChris Cain  *
274337bbf98cSChris Cain  * @return None.
274437bbf98cSChris Cain  */
2745ac106bf6SEd Tanous inline void
2746ac106bf6SEd Tanous     setIdlePowerSaver(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
274737bbf98cSChris Cain                       const std::optional<bool> ipsEnable,
274837bbf98cSChris Cain                       const std::optional<uint8_t> ipsEnterUtil,
274937bbf98cSChris Cain                       const std::optional<uint64_t> ipsEnterTime,
275037bbf98cSChris Cain                       const std::optional<uint8_t> ipsExitUtil,
275137bbf98cSChris Cain                       const std::optional<uint64_t> ipsExitTime)
275237bbf98cSChris Cain {
275362598e31SEd Tanous     BMCWEB_LOG_DEBUG("Set idle power saver properties");
275437bbf98cSChris Cain 
275537bbf98cSChris Cain     // Get IdlePowerSaver object path:
2756e99073f5SGeorge Liu     constexpr std::array<std::string_view, 1> interfaces = {
2757e99073f5SGeorge Liu         "xyz.openbmc_project.Control.Power.IdlePowerSaver"};
2758e99073f5SGeorge Liu     dbus::utility::getSubTree(
2759e99073f5SGeorge Liu         "/", 0, interfaces,
2760ac106bf6SEd Tanous         [asyncResp, ipsEnable, ipsEnterUtil, ipsEnterTime, ipsExitUtil,
2761e99073f5SGeorge Liu          ipsExitTime](const boost::system::error_code& ec,
2762b9d36b47SEd Tanous                       const dbus::utility::MapperGetSubTreeResponse& subtree) {
276337bbf98cSChris Cain         if (ec)
276437bbf98cSChris Cain         {
2765*b3e86cb0SGunnar Mills             BMCWEB_LOG_ERROR(
276662598e31SEd Tanous                 "DBUS response error on Power.IdlePowerSaver GetSubTree {}",
276762598e31SEd Tanous                 ec);
2768ac106bf6SEd Tanous             messages::internalError(asyncResp->res);
276937bbf98cSChris Cain             return;
277037bbf98cSChris Cain         }
277137bbf98cSChris Cain         if (subtree.empty())
277237bbf98cSChris Cain         {
277337bbf98cSChris Cain             // This is an optional D-Bus object, but user attempted to patch
2774ac106bf6SEd Tanous             messages::resourceNotFound(asyncResp->res, "ComputerSystem",
277537bbf98cSChris Cain                                        "IdlePowerSaver");
277637bbf98cSChris Cain             return;
277737bbf98cSChris Cain         }
277837bbf98cSChris Cain         if (subtree.size() > 1)
277937bbf98cSChris Cain         {
278037bbf98cSChris Cain             // More then one PowerIdlePowerSaver object is not supported and
278137bbf98cSChris Cain             // is an error
278262598e31SEd Tanous             BMCWEB_LOG_DEBUG(
278362598e31SEd Tanous                 "Found more than 1 system D-Bus Power.IdlePowerSaver objects: {}",
278462598e31SEd Tanous                 subtree.size());
2785ac106bf6SEd Tanous             messages::internalError(asyncResp->res);
278637bbf98cSChris Cain             return;
278737bbf98cSChris Cain         }
278837bbf98cSChris Cain         if ((subtree[0].first.empty()) || (subtree[0].second.size() != 1))
278937bbf98cSChris Cain         {
279062598e31SEd Tanous             BMCWEB_LOG_DEBUG("Power.IdlePowerSaver mapper error!");
2791ac106bf6SEd Tanous             messages::internalError(asyncResp->res);
279237bbf98cSChris Cain             return;
279337bbf98cSChris Cain         }
279437bbf98cSChris Cain         const std::string& path = subtree[0].first;
279537bbf98cSChris Cain         const std::string& service = subtree[0].second.begin()->first;
279637bbf98cSChris Cain         if (service.empty())
279737bbf98cSChris Cain         {
279862598e31SEd Tanous             BMCWEB_LOG_DEBUG("Power.IdlePowerSaver service mapper error!");
2799ac106bf6SEd Tanous             messages::internalError(asyncResp->res);
280037bbf98cSChris Cain             return;
280137bbf98cSChris Cain         }
280237bbf98cSChris Cain 
280337bbf98cSChris Cain         // Valid Power IdlePowerSaver object found, now set any values that
280437bbf98cSChris Cain         // need to be updated
280537bbf98cSChris Cain 
280637bbf98cSChris Cain         if (ipsEnable)
280737bbf98cSChris Cain         {
28089ae226faSGeorge Liu             sdbusplus::asio::setProperty(
28099ae226faSGeorge Liu                 *crow::connections::systemBus, service, path,
28109ae226faSGeorge Liu                 "xyz.openbmc_project.Control.Power.IdlePowerSaver", "Enabled",
28119ae226faSGeorge Liu                 *ipsEnable, [asyncResp](const boost::system::error_code& ec2) {
28128a592810SEd Tanous                     if (ec2)
281337bbf98cSChris Cain                     {
2814*b3e86cb0SGunnar Mills                         BMCWEB_LOG_ERROR("DBUS response error {}", ec2);
2815ac106bf6SEd Tanous                         messages::internalError(asyncResp->res);
281637bbf98cSChris Cain                         return;
281737bbf98cSChris Cain                     }
28189ae226faSGeorge Liu                 });
281937bbf98cSChris Cain         }
282037bbf98cSChris Cain         if (ipsEnterUtil)
282137bbf98cSChris Cain         {
28229ae226faSGeorge Liu             sdbusplus::asio::setProperty(
28239ae226faSGeorge Liu                 *crow::connections::systemBus, service, path,
28249ae226faSGeorge Liu                 "xyz.openbmc_project.Control.Power.IdlePowerSaver",
28259ae226faSGeorge Liu                 "EnterUtilizationPercent", *ipsEnterUtil,
2826ac106bf6SEd Tanous                 [asyncResp](const boost::system::error_code& ec2) {
28278a592810SEd Tanous                 if (ec2)
282837bbf98cSChris Cain                 {
2829*b3e86cb0SGunnar Mills                     BMCWEB_LOG_ERROR("DBUS response error {}", ec2);
2830ac106bf6SEd Tanous                     messages::internalError(asyncResp->res);
283137bbf98cSChris Cain                     return;
283237bbf98cSChris Cain                 }
28339ae226faSGeorge Liu                 });
283437bbf98cSChris Cain         }
283537bbf98cSChris Cain         if (ipsEnterTime)
283637bbf98cSChris Cain         {
283737bbf98cSChris Cain             // Convert from seconds into milliseconds for DBus
283837bbf98cSChris Cain             const uint64_t timeMilliseconds = *ipsEnterTime * 1000;
28399ae226faSGeorge Liu             sdbusplus::asio::setProperty(
28409ae226faSGeorge Liu                 *crow::connections::systemBus, service, path,
28419ae226faSGeorge Liu                 "xyz.openbmc_project.Control.Power.IdlePowerSaver",
28429ae226faSGeorge Liu                 "EnterDwellTime", timeMilliseconds,
2843ac106bf6SEd Tanous                 [asyncResp](const boost::system::error_code& ec2) {
28448a592810SEd Tanous                 if (ec2)
284537bbf98cSChris Cain                 {
2846*b3e86cb0SGunnar Mills                     BMCWEB_LOG_ERROR("DBUS response error {}", ec2);
2847ac106bf6SEd Tanous                     messages::internalError(asyncResp->res);
284837bbf98cSChris Cain                     return;
284937bbf98cSChris Cain                 }
28509ae226faSGeorge Liu                 });
285137bbf98cSChris Cain         }
285237bbf98cSChris Cain         if (ipsExitUtil)
285337bbf98cSChris Cain         {
28549ae226faSGeorge Liu             sdbusplus::asio::setProperty(
28559ae226faSGeorge Liu                 *crow::connections::systemBus, service, path,
28569ae226faSGeorge Liu                 "xyz.openbmc_project.Control.Power.IdlePowerSaver",
28579ae226faSGeorge Liu                 "ExitUtilizationPercent", *ipsExitUtil,
2858ac106bf6SEd Tanous                 [asyncResp](const boost::system::error_code& ec2) {
28598a592810SEd Tanous                 if (ec2)
286037bbf98cSChris Cain                 {
2861*b3e86cb0SGunnar Mills                     BMCWEB_LOG_ERROR("DBUS response error {}", ec2);
2862ac106bf6SEd Tanous                     messages::internalError(asyncResp->res);
286337bbf98cSChris Cain                     return;
286437bbf98cSChris Cain                 }
28659ae226faSGeorge Liu                 });
286637bbf98cSChris Cain         }
286737bbf98cSChris Cain         if (ipsExitTime)
286837bbf98cSChris Cain         {
286937bbf98cSChris Cain             // Convert from seconds into milliseconds for DBus
287037bbf98cSChris Cain             const uint64_t timeMilliseconds = *ipsExitTime * 1000;
28719ae226faSGeorge Liu             sdbusplus::asio::setProperty(
28729ae226faSGeorge Liu                 *crow::connections::systemBus, service, path,
28739ae226faSGeorge Liu                 "xyz.openbmc_project.Control.Power.IdlePowerSaver",
28749ae226faSGeorge Liu                 "ExitDwellTime", timeMilliseconds,
2875ac106bf6SEd Tanous                 [asyncResp](const boost::system::error_code& ec2) {
28768a592810SEd Tanous                 if (ec2)
287737bbf98cSChris Cain                 {
2878*b3e86cb0SGunnar Mills                     BMCWEB_LOG_ERROR("DBUS response error {}", ec2);
2879ac106bf6SEd Tanous                     messages::internalError(asyncResp->res);
288037bbf98cSChris Cain                     return;
288137bbf98cSChris Cain                 }
28829ae226faSGeorge Liu                 });
288337bbf98cSChris Cain         }
2884e99073f5SGeorge Liu         });
288537bbf98cSChris Cain 
288662598e31SEd Tanous     BMCWEB_LOG_DEBUG("EXIT: Set idle power saver parameters");
288737bbf98cSChris Cain }
288837bbf98cSChris Cain 
2889c1e219d5SEd Tanous inline void handleComputerSystemCollectionHead(
2890dd60b9edSEd Tanous     crow::App& app, const crow::Request& req,
2891dd60b9edSEd Tanous     const std::shared_ptr<bmcweb::AsyncResp>& asyncResp)
2892dd60b9edSEd Tanous {
2893dd60b9edSEd Tanous     if (!redfish::setUpRedfishRoute(app, req, asyncResp))
2894dd60b9edSEd Tanous     {
2895dd60b9edSEd Tanous         return;
2896dd60b9edSEd Tanous     }
2897dd60b9edSEd Tanous     asyncResp->res.addHeader(
2898dd60b9edSEd Tanous         boost::beast::http::field::link,
2899dd60b9edSEd Tanous         "</redfish/v1/JsonSchemas/ComputerSystemCollection/ComputerSystemCollection.json>; rel=describedby");
2900dd60b9edSEd Tanous }
2901dd60b9edSEd Tanous 
2902c1e219d5SEd Tanous inline void handleComputerSystemCollectionGet(
2903c1e219d5SEd Tanous     crow::App& app, const crow::Request& req,
2904c1e219d5SEd Tanous     const std::shared_ptr<bmcweb::AsyncResp>& asyncResp)
29051abe55efSEd Tanous {
29063ba00073SCarson Labrado     if (!redfish::setUpRedfishRoute(app, req, asyncResp))
2907f4c99e70SEd Tanous     {
2908f4c99e70SEd Tanous         return;
2909f4c99e70SEd Tanous     }
2910dd60b9edSEd Tanous 
2911dd60b9edSEd Tanous     asyncResp->res.addHeader(
2912dd60b9edSEd Tanous         boost::beast::http::field::link,
2913dd60b9edSEd Tanous         "</redfish/v1/JsonSchemas/ComputerSystemCollection.json>; rel=describedby");
29148d1b46d7Szhanghch05     asyncResp->res.jsonValue["@odata.type"] =
29150f74e643SEd Tanous         "#ComputerSystemCollection.ComputerSystemCollection";
29168d1b46d7Szhanghch05     asyncResp->res.jsonValue["@odata.id"] = "/redfish/v1/Systems";
29178d1b46d7Szhanghch05     asyncResp->res.jsonValue["Name"] = "Computer System Collection";
2918462023adSSunitha Harish 
29197f3e84a1SEd Tanous     nlohmann::json& ifaceArray = asyncResp->res.jsonValue["Members"];
29207f3e84a1SEd Tanous     ifaceArray = nlohmann::json::array();
29217f3e84a1SEd Tanous     if constexpr (bmcwebEnableMultiHost)
29227f3e84a1SEd Tanous     {
29237f3e84a1SEd Tanous         asyncResp->res.jsonValue["Members@odata.count"] = 0;
29247f3e84a1SEd Tanous         // Option currently returns no systems.  TBD
29257f3e84a1SEd Tanous         return;
29267f3e84a1SEd Tanous     }
29277f3e84a1SEd Tanous     asyncResp->res.jsonValue["Members@odata.count"] = 1;
29287f3e84a1SEd Tanous     nlohmann::json::object_t system;
29297f3e84a1SEd Tanous     system["@odata.id"] = "/redfish/v1/Systems/system";
29307f3e84a1SEd Tanous     ifaceArray.emplace_back(std::move(system));
29311e1e598dSJonathan Doman     sdbusplus::asio::getProperty<std::string>(
2932002d39b4SEd Tanous         *crow::connections::systemBus, "xyz.openbmc_project.Settings",
29331e1e598dSJonathan Doman         "/xyz/openbmc_project/network/hypervisor",
2934002d39b4SEd Tanous         "xyz.openbmc_project.Network.SystemConfiguration", "HostName",
29355e7e2dc5SEd Tanous         [asyncResp](const boost::system::error_code& ec2,
29361e1e598dSJonathan Doman                     const std::string& /*hostName*/) {
29377f3e84a1SEd Tanous         if (ec2)
2938462023adSSunitha Harish         {
29397f3e84a1SEd Tanous             return;
29407f3e84a1SEd Tanous         }
29417f3e84a1SEd Tanous         auto val = asyncResp->res.jsonValue.find("Members@odata.count");
29427f3e84a1SEd Tanous         if (val == asyncResp->res.jsonValue.end())
29437f3e84a1SEd Tanous         {
294462598e31SEd Tanous             BMCWEB_LOG_CRITICAL("Count wasn't found??");
29457f3e84a1SEd Tanous             return;
29467f3e84a1SEd Tanous         }
29477f3e84a1SEd Tanous         uint64_t* count = val->get_ptr<uint64_t*>();
29487f3e84a1SEd Tanous         if (count == nullptr)
29497f3e84a1SEd Tanous         {
295062598e31SEd Tanous             BMCWEB_LOG_CRITICAL("Count wasn't found??");
29517f3e84a1SEd Tanous             return;
29527f3e84a1SEd Tanous         }
29537f3e84a1SEd Tanous         *count = *count + 1;
295462598e31SEd Tanous         BMCWEB_LOG_DEBUG("Hypervisor is available");
29557f3e84a1SEd Tanous         nlohmann::json& ifaceArray2 = asyncResp->res.jsonValue["Members"];
29561476687dSEd Tanous         nlohmann::json::object_t hypervisor;
2957002d39b4SEd Tanous         hypervisor["@odata.id"] = "/redfish/v1/Systems/hypervisor";
29587f3e84a1SEd Tanous         ifaceArray2.emplace_back(std::move(hypervisor));
29591e1e598dSJonathan Doman         });
2960c1e219d5SEd Tanous }
2961c1e219d5SEd Tanous 
2962c1e219d5SEd Tanous /**
29637e860f15SJohn Edward Broadbent  * Function transceives data with dbus directly.
29647e860f15SJohn Edward Broadbent  */
29654f48d5f6SEd Tanous inline void doNMI(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp)
29667e860f15SJohn Edward Broadbent {
296789492a15SPatrick Williams     constexpr const char* serviceName = "xyz.openbmc_project.Control.Host.NMI";
296889492a15SPatrick Williams     constexpr const char* objectPath = "/xyz/openbmc_project/control/host0/nmi";
296989492a15SPatrick Williams     constexpr const char* interfaceName =
29707e860f15SJohn Edward Broadbent         "xyz.openbmc_project.Control.Host.NMI";
297189492a15SPatrick Williams     constexpr const char* method = "NMI";
29727e860f15SJohn Edward Broadbent 
29737e860f15SJohn Edward Broadbent     crow::connections::systemBus->async_method_call(
29745e7e2dc5SEd Tanous         [asyncResp](const boost::system::error_code& ec) {
29757e860f15SJohn Edward Broadbent         if (ec)
29767e860f15SJohn Edward Broadbent         {
297762598e31SEd Tanous             BMCWEB_LOG_ERROR(" Bad D-Bus request error: {}", ec);
29787e860f15SJohn Edward Broadbent             messages::internalError(asyncResp->res);
29797e860f15SJohn Edward Broadbent             return;
29807e860f15SJohn Edward Broadbent         }
29817e860f15SJohn Edward Broadbent         messages::success(asyncResp->res);
29827e860f15SJohn Edward Broadbent         },
29837e860f15SJohn Edward Broadbent         serviceName, objectPath, interfaceName, method);
29847e860f15SJohn Edward Broadbent }
2985c5b2abe0SLewanczyk, Dawid 
2986c5b2abe0SLewanczyk, Dawid /**
2987fc903b3dSAndrew Geissler  * Handle error responses from d-bus for system power requests
2988fc903b3dSAndrew Geissler  */
2989fc903b3dSAndrew Geissler inline void handleSystemActionResetError(const boost::system::error_code& ec,
2990fc903b3dSAndrew Geissler                                          const sdbusplus::message_t& eMsg,
2991fc903b3dSAndrew Geissler                                          std::string_view resetType,
2992fc903b3dSAndrew Geissler                                          crow::Response& res)
2993fc903b3dSAndrew Geissler {
2994fc903b3dSAndrew Geissler     if (ec.value() == boost::asio::error::invalid_argument)
2995fc903b3dSAndrew Geissler     {
2996fc903b3dSAndrew Geissler         messages::actionParameterNotSupported(res, resetType, "Reset");
2997fc903b3dSAndrew Geissler         return;
2998fc903b3dSAndrew Geissler     }
2999fc903b3dSAndrew Geissler 
3000fc903b3dSAndrew Geissler     if (eMsg.get_error() == nullptr)
3001fc903b3dSAndrew Geissler     {
300262598e31SEd Tanous         BMCWEB_LOG_ERROR("D-Bus response error: {}", ec);
3003fc903b3dSAndrew Geissler         messages::internalError(res);
3004fc903b3dSAndrew Geissler         return;
3005fc903b3dSAndrew Geissler     }
3006fc903b3dSAndrew Geissler     std::string_view errorMessage = eMsg.get_error()->name;
3007fc903b3dSAndrew Geissler 
3008fc903b3dSAndrew Geissler     // If operation failed due to BMC not being in Ready state, tell
3009fc903b3dSAndrew Geissler     // user to retry in a bit
3010fc903b3dSAndrew Geissler     if ((errorMessage ==
3011fc903b3dSAndrew Geissler          std::string_view(
3012fc903b3dSAndrew Geissler              "xyz.openbmc_project.State.Chassis.Error.BMCNotReady")) ||
3013fc903b3dSAndrew Geissler         (errorMessage ==
3014fc903b3dSAndrew Geissler          std::string_view("xyz.openbmc_project.State.Host.Error.BMCNotReady")))
3015fc903b3dSAndrew Geissler     {
301662598e31SEd Tanous         BMCWEB_LOG_DEBUG("BMC not ready, operation not allowed right now");
3017fc903b3dSAndrew Geissler         messages::serviceTemporarilyUnavailable(res, "10");
3018fc903b3dSAndrew Geissler         return;
3019fc903b3dSAndrew Geissler     }
3020fc903b3dSAndrew Geissler 
302162598e31SEd Tanous     BMCWEB_LOG_ERROR("System Action Reset transition fail {} sdbusplus:{}", ec,
302262598e31SEd Tanous                      errorMessage);
3023fc903b3dSAndrew Geissler     messages::internalError(res);
3024fc903b3dSAndrew Geissler }
3025fc903b3dSAndrew Geissler 
3026c1e219d5SEd Tanous inline void handleComputerSystemResetActionPost(
3027c1e219d5SEd Tanous     crow::App& app, const crow::Request& req,
30287f3e84a1SEd Tanous     const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
3029c1e219d5SEd Tanous     const std::string& systemName)
3030c1e219d5SEd Tanous {
30313ba00073SCarson Labrado     if (!redfish::setUpRedfishRoute(app, req, asyncResp))
303245ca1b86SEd Tanous     {
303345ca1b86SEd Tanous         return;
303445ca1b86SEd Tanous     }
3035c1e219d5SEd Tanous     if (systemName != "system")
3036c1e219d5SEd Tanous     {
3037c1e219d5SEd Tanous         messages::resourceNotFound(asyncResp->res, "ComputerSystem",
3038c1e219d5SEd Tanous                                    systemName);
3039c1e219d5SEd Tanous         return;
3040c1e219d5SEd Tanous     }
30417f3e84a1SEd Tanous     if constexpr (bmcwebEnableMultiHost)
30427f3e84a1SEd Tanous     {
30437f3e84a1SEd Tanous         // Option currently returns no systems.  TBD
30447f3e84a1SEd Tanous         messages::resourceNotFound(asyncResp->res, "ComputerSystem",
3045c1e219d5SEd Tanous                                    systemName);
30467f3e84a1SEd Tanous         return;
30477f3e84a1SEd Tanous     }
30489712f8acSEd Tanous     std::string resetType;
3049c1e219d5SEd Tanous     if (!json_util::readJsonAction(req, asyncResp->res, "ResetType", resetType))
3050cc340dd9SEd Tanous     {
3051cc340dd9SEd Tanous         return;
3052cc340dd9SEd Tanous     }
3053cc340dd9SEd Tanous 
3054d22c8396SJason M. Bills     // Get the command and host vs. chassis
3055cc340dd9SEd Tanous     std::string command;
3056543f4400SEd Tanous     bool hostCommand = true;
3057d4d25793SEd Tanous     if ((resetType == "On") || (resetType == "ForceOn"))
3058cc340dd9SEd Tanous     {
3059cc340dd9SEd Tanous         command = "xyz.openbmc_project.State.Host.Transition.On";
3060d22c8396SJason M. Bills         hostCommand = true;
3061d22c8396SJason M. Bills     }
3062d22c8396SJason M. Bills     else if (resetType == "ForceOff")
3063d22c8396SJason M. Bills     {
3064d22c8396SJason M. Bills         command = "xyz.openbmc_project.State.Chassis.Transition.Off";
3065d22c8396SJason M. Bills         hostCommand = false;
3066d22c8396SJason M. Bills     }
3067d22c8396SJason M. Bills     else if (resetType == "ForceRestart")
3068d22c8396SJason M. Bills     {
3069c1e219d5SEd Tanous         command = "xyz.openbmc_project.State.Host.Transition.ForceWarmReboot";
307086a0851aSJason M. Bills         hostCommand = true;
3071cc340dd9SEd Tanous     }
30729712f8acSEd Tanous     else if (resetType == "GracefulShutdown")
3073cc340dd9SEd Tanous     {
3074cc340dd9SEd Tanous         command = "xyz.openbmc_project.State.Host.Transition.Off";
3075d22c8396SJason M. Bills         hostCommand = true;
3076cc340dd9SEd Tanous     }
30779712f8acSEd Tanous     else if (resetType == "GracefulRestart")
3078cc340dd9SEd Tanous     {
30790fda0f12SGeorge Liu         command =
30800fda0f12SGeorge Liu             "xyz.openbmc_project.State.Host.Transition.GracefulWarmReboot";
3081d22c8396SJason M. Bills         hostCommand = true;
3082d22c8396SJason M. Bills     }
3083d22c8396SJason M. Bills     else if (resetType == "PowerCycle")
3084d22c8396SJason M. Bills     {
308586a0851aSJason M. Bills         command = "xyz.openbmc_project.State.Host.Transition.Reboot";
308686a0851aSJason M. Bills         hostCommand = true;
3087cc340dd9SEd Tanous     }
3088bfd5b826SLakshminarayana R. Kammath     else if (resetType == "Nmi")
3089bfd5b826SLakshminarayana R. Kammath     {
3090bfd5b826SLakshminarayana R. Kammath         doNMI(asyncResp);
3091bfd5b826SLakshminarayana R. Kammath         return;
3092bfd5b826SLakshminarayana R. Kammath     }
3093cc340dd9SEd Tanous     else
3094cc340dd9SEd Tanous     {
3095c1e219d5SEd Tanous         messages::actionParameterUnknown(asyncResp->res, "Reset", resetType);
3096cc340dd9SEd Tanous         return;
3097cc340dd9SEd Tanous     }
3098cc340dd9SEd Tanous 
3099d22c8396SJason M. Bills     if (hostCommand)
3100d22c8396SJason M. Bills     {
31019ae226faSGeorge Liu         sdbusplus::asio::setProperty(
31029ae226faSGeorge Liu             *crow::connections::systemBus, "xyz.openbmc_project.State.Host",
31039ae226faSGeorge Liu             "/xyz/openbmc_project/state/host0",
31049ae226faSGeorge Liu             "xyz.openbmc_project.State.Host", "RequestedHostTransition",
31059ae226faSGeorge Liu             command,
3106fc903b3dSAndrew Geissler             [asyncResp, resetType](const boost::system::error_code& ec,
3107fc903b3dSAndrew Geissler                                    sdbusplus::message_t& sdbusErrMsg) {
3108cc340dd9SEd Tanous             if (ec)
3109cc340dd9SEd Tanous             {
3110fc903b3dSAndrew Geissler                 handleSystemActionResetError(ec, sdbusErrMsg, resetType,
3111fc903b3dSAndrew Geissler                                              asyncResp->res);
3112fc903b3dSAndrew Geissler 
3113cc340dd9SEd Tanous                 return;
3114cc340dd9SEd Tanous             }
3115f12894f8SJason M. Bills             messages::success(asyncResp->res);
31169ae226faSGeorge Liu             });
3117cc340dd9SEd Tanous     }
3118d22c8396SJason M. Bills     else
3119d22c8396SJason M. Bills     {
31209ae226faSGeorge Liu         sdbusplus::asio::setProperty(
31219ae226faSGeorge Liu             *crow::connections::systemBus, "xyz.openbmc_project.State.Chassis",
31229ae226faSGeorge Liu             "/xyz/openbmc_project/state/chassis0",
31239ae226faSGeorge Liu             "xyz.openbmc_project.State.Chassis", "RequestedPowerTransition",
31249ae226faSGeorge Liu             command,
3125fc903b3dSAndrew Geissler             [asyncResp, resetType](const boost::system::error_code& ec,
3126fc903b3dSAndrew Geissler                                    sdbusplus::message_t& sdbusErrMsg) {
3127d22c8396SJason M. Bills             if (ec)
3128d22c8396SJason M. Bills             {
3129fc903b3dSAndrew Geissler                 handleSystemActionResetError(ec, sdbusErrMsg, resetType,
3130fc903b3dSAndrew Geissler                                              asyncResp->res);
3131d22c8396SJason M. Bills                 return;
3132d22c8396SJason M. Bills             }
3133d22c8396SJason M. Bills             messages::success(asyncResp->res);
31349ae226faSGeorge Liu             });
3135d22c8396SJason M. Bills     }
3136d22c8396SJason M. Bills }
3137cc340dd9SEd Tanous 
3138c1e219d5SEd Tanous inline void handleComputerSystemHead(
3139dd60b9edSEd Tanous     App& app, const crow::Request& req,
31407f3e84a1SEd Tanous     const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
31417f3e84a1SEd Tanous     const std::string& /*systemName*/)
3142dd60b9edSEd Tanous {
3143dd60b9edSEd Tanous     if (!redfish::setUpRedfishRoute(app, req, asyncResp))
3144dd60b9edSEd Tanous     {
3145dd60b9edSEd Tanous         return;
3146dd60b9edSEd Tanous     }
3147dd60b9edSEd Tanous 
3148dd60b9edSEd Tanous     asyncResp->res.addHeader(
3149dd60b9edSEd Tanous         boost::beast::http::field::link,
3150dd60b9edSEd Tanous         "</redfish/v1/JsonSchemas/ComputerSystem/ComputerSystem.json>; rel=describedby");
3151dd60b9edSEd Tanous }
3152dd60b9edSEd Tanous 
31535c3e9272SAbhishek Patel inline void afterPortRequest(
31545c3e9272SAbhishek Patel     const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
31555c3e9272SAbhishek Patel     const boost::system::error_code& ec,
31565c3e9272SAbhishek Patel     const std::vector<std::tuple<std::string, std::string, bool>>& socketData)
31575c3e9272SAbhishek Patel {
31585c3e9272SAbhishek Patel     if (ec)
31595c3e9272SAbhishek Patel     {
3160*b3e86cb0SGunnar Mills         BMCWEB_LOG_ERROR("DBUS response error {}", ec);
31615c3e9272SAbhishek Patel         messages::internalError(asyncResp->res);
31625c3e9272SAbhishek Patel         return;
31635c3e9272SAbhishek Patel     }
31645c3e9272SAbhishek Patel     for (const auto& data : socketData)
31655c3e9272SAbhishek Patel     {
31665c3e9272SAbhishek Patel         const std::string& socketPath = get<0>(data);
31675c3e9272SAbhishek Patel         const std::string& protocolName = get<1>(data);
31685c3e9272SAbhishek Patel         bool isProtocolEnabled = get<2>(data);
31695c3e9272SAbhishek Patel         nlohmann::json& dataJson = asyncResp->res.jsonValue["SerialConsole"];
31705c3e9272SAbhishek Patel         dataJson[protocolName]["ServiceEnabled"] = isProtocolEnabled;
31715c3e9272SAbhishek Patel         // need to retrieve port number for
31725c3e9272SAbhishek Patel         // obmc-console-ssh service
31735c3e9272SAbhishek Patel         if (protocolName == "SSH")
31745c3e9272SAbhishek Patel         {
31755c3e9272SAbhishek Patel             getPortNumber(socketPath, [asyncResp, protocolName](
317681c4e330SEd Tanous                                           const boost::system::error_code& ec1,
31775c3e9272SAbhishek Patel                                           int portNumber) {
31785c3e9272SAbhishek Patel                 if (ec1)
31795c3e9272SAbhishek Patel                 {
3180*b3e86cb0SGunnar Mills                     BMCWEB_LOG_ERROR("DBUS response error {}", ec1);
31815c3e9272SAbhishek Patel                     messages::internalError(asyncResp->res);
31825c3e9272SAbhishek Patel                     return;
31835c3e9272SAbhishek Patel                 }
31845c3e9272SAbhishek Patel                 nlohmann::json& dataJson1 =
31855c3e9272SAbhishek Patel                     asyncResp->res.jsonValue["SerialConsole"];
31865c3e9272SAbhishek Patel                 dataJson1[protocolName]["Port"] = portNumber;
31875c3e9272SAbhishek Patel             });
31885c3e9272SAbhishek Patel         }
31895c3e9272SAbhishek Patel     }
31905c3e9272SAbhishek Patel }
3191c1e219d5SEd Tanous 
3192c1e219d5SEd Tanous inline void
3193c1e219d5SEd Tanous     handleComputerSystemGet(crow::App& app, const crow::Request& req,
319422d268cbSEd Tanous                             const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
3195c1e219d5SEd Tanous                             const std::string& systemName)
3196c1e219d5SEd Tanous {
31973ba00073SCarson Labrado     if (!redfish::setUpRedfishRoute(app, req, asyncResp))
319845ca1b86SEd Tanous     {
319945ca1b86SEd Tanous         return;
320045ca1b86SEd Tanous     }
3201746b56f3SAsmitha Karunanithi 
32027f3e84a1SEd Tanous     if constexpr (bmcwebEnableMultiHost)
32037f3e84a1SEd Tanous     {
32047f3e84a1SEd Tanous         // Option currently returns no systems.  TBD
32057f3e84a1SEd Tanous         messages::resourceNotFound(asyncResp->res, "ComputerSystem",
32067f3e84a1SEd Tanous                                    systemName);
32077f3e84a1SEd Tanous         return;
32087f3e84a1SEd Tanous     }
32097f3e84a1SEd Tanous 
3210746b56f3SAsmitha Karunanithi     if (systemName == "hypervisor")
3211746b56f3SAsmitha Karunanithi     {
3212746b56f3SAsmitha Karunanithi         handleHypervisorSystemGet(asyncResp);
3213746b56f3SAsmitha Karunanithi         return;
3214746b56f3SAsmitha Karunanithi     }
3215746b56f3SAsmitha Karunanithi 
321622d268cbSEd Tanous     if (systemName != "system")
321722d268cbSEd Tanous     {
321822d268cbSEd Tanous         messages::resourceNotFound(asyncResp->res, "ComputerSystem",
321922d268cbSEd Tanous                                    systemName);
322022d268cbSEd Tanous         return;
322122d268cbSEd Tanous     }
3222dd60b9edSEd Tanous     asyncResp->res.addHeader(
3223dd60b9edSEd Tanous         boost::beast::http::field::link,
3224dd60b9edSEd Tanous         "</redfish/v1/JsonSchemas/ComputerSystem/ComputerSystem.json>; rel=describedby");
32258d1b46d7Szhanghch05     asyncResp->res.jsonValue["@odata.type"] =
322637bbf98cSChris Cain         "#ComputerSystem.v1_16_0.ComputerSystem";
32278d1b46d7Szhanghch05     asyncResp->res.jsonValue["Name"] = "system";
32288d1b46d7Szhanghch05     asyncResp->res.jsonValue["Id"] = "system";
32298d1b46d7Szhanghch05     asyncResp->res.jsonValue["SystemType"] = "Physical";
32308d1b46d7Szhanghch05     asyncResp->res.jsonValue["Description"] = "Computer System";
32318d1b46d7Szhanghch05     asyncResp->res.jsonValue["ProcessorSummary"]["Count"] = 0;
32325fd0aafbSNinad Palsule     if constexpr (bmcwebEnableProcMemStatus)
32335fd0aafbSNinad Palsule     {
32348d1b46d7Szhanghch05         asyncResp->res.jsonValue["ProcessorSummary"]["Status"]["State"] =
32358d1b46d7Szhanghch05             "Disabled";
32368d1b46d7Szhanghch05         asyncResp->res.jsonValue["MemorySummary"]["Status"]["State"] =
32378d1b46d7Szhanghch05             "Disabled";
32385fd0aafbSNinad Palsule     }
3239cf0e004cSNinad Palsule     asyncResp->res.jsonValue["MemorySummary"]["TotalSystemMemoryGiB"] =
3240dfb2b408SPriyanga Ramasamy         double(0);
3241002d39b4SEd Tanous     asyncResp->res.jsonValue["@odata.id"] = "/redfish/v1/Systems/system";
324204a258f4SEd Tanous 
32431476687dSEd Tanous     asyncResp->res.jsonValue["Processors"]["@odata.id"] =
32441476687dSEd Tanous         "/redfish/v1/Systems/system/Processors";
32451476687dSEd Tanous     asyncResp->res.jsonValue["Memory"]["@odata.id"] =
32461476687dSEd Tanous         "/redfish/v1/Systems/system/Memory";
32471476687dSEd Tanous     asyncResp->res.jsonValue["Storage"]["@odata.id"] =
32481476687dSEd Tanous         "/redfish/v1/Systems/system/Storage";
32493179105bSSunny Srivastava     asyncResp->res.jsonValue["FabricAdapters"]["@odata.id"] =
32503179105bSSunny Srivastava         "/redfish/v1/Systems/system/FabricAdapters";
3251029573d4SEd Tanous 
3252002d39b4SEd Tanous     asyncResp->res.jsonValue["Actions"]["#ComputerSystem.Reset"]["target"] =
32531476687dSEd Tanous         "/redfish/v1/Systems/system/Actions/ComputerSystem.Reset";
3254c1e219d5SEd Tanous     asyncResp->res
3255c1e219d5SEd Tanous         .jsonValue["Actions"]["#ComputerSystem.Reset"]["@Redfish.ActionInfo"] =
32561476687dSEd Tanous         "/redfish/v1/Systems/system/ResetActionInfo";
3257c5b2abe0SLewanczyk, Dawid 
32581476687dSEd Tanous     asyncResp->res.jsonValue["LogServices"]["@odata.id"] =
32591476687dSEd Tanous         "/redfish/v1/Systems/system/LogServices";
32601476687dSEd Tanous     asyncResp->res.jsonValue["Bios"]["@odata.id"] =
32611476687dSEd Tanous         "/redfish/v1/Systems/system/Bios";
3262c4bf6374SJason M. Bills 
32631476687dSEd Tanous     nlohmann::json::array_t managedBy;
32641476687dSEd Tanous     nlohmann::json& manager = managedBy.emplace_back();
32651476687dSEd Tanous     manager["@odata.id"] = "/redfish/v1/Managers/bmc";
3266002d39b4SEd Tanous     asyncResp->res.jsonValue["Links"]["ManagedBy"] = std::move(managedBy);
32671476687dSEd Tanous     asyncResp->res.jsonValue["Status"]["Health"] = "OK";
32681476687dSEd Tanous     asyncResp->res.jsonValue["Status"]["State"] = "Enabled";
32690e8ac5e7SGunnar Mills 
32700e8ac5e7SGunnar Mills     // Fill in SerialConsole info
3271002d39b4SEd Tanous     asyncResp->res.jsonValue["SerialConsole"]["MaxConcurrentSessions"] = 15;
3272c1e219d5SEd Tanous     asyncResp->res.jsonValue["SerialConsole"]["IPMI"]["ServiceEnabled"] = true;
32731476687dSEd Tanous 
3274c1e219d5SEd Tanous     asyncResp->res.jsonValue["SerialConsole"]["SSH"]["ServiceEnabled"] = true;
32751476687dSEd Tanous     asyncResp->res.jsonValue["SerialConsole"]["SSH"]["Port"] = 2200;
3276c1e219d5SEd Tanous     asyncResp->res.jsonValue["SerialConsole"]["SSH"]["HotKeySequenceDisplay"] =
32771476687dSEd Tanous         "Press ~. to exit console";
32785c3e9272SAbhishek Patel     getPortStatusAndPath(std::span{protocolToDBusForSystems},
32795c3e9272SAbhishek Patel                          std::bind_front(afterPortRequest, asyncResp));
32800e8ac5e7SGunnar Mills 
32810e8ac5e7SGunnar Mills #ifdef BMCWEB_ENABLE_KVM
32820e8ac5e7SGunnar Mills     // Fill in GraphicalConsole info
3283002d39b4SEd Tanous     asyncResp->res.jsonValue["GraphicalConsole"]["ServiceEnabled"] = true;
3284c1e219d5SEd Tanous     asyncResp->res.jsonValue["GraphicalConsole"]["MaxConcurrentSessions"] = 4;
3285613dabeaSEd Tanous     asyncResp->res.jsonValue["GraphicalConsole"]["ConnectTypesSupported"] =
3286613dabeaSEd Tanous         nlohmann::json::array_t({"KVMIP"});
32871476687dSEd Tanous 
32880e8ac5e7SGunnar Mills #endif // BMCWEB_ENABLE_KVM
328913451e39SWilly Tu 
329013451e39SWilly Tu     auto health = std::make_shared<HealthPopulate>(asyncResp);
329113451e39SWilly Tu     if constexpr (bmcwebEnableHealthPopulate)
329213451e39SWilly Tu     {
32937a1dbc48SGeorge Liu         constexpr std::array<std::string_view, 4> inventoryForSystems{
3294b49ac873SJames Feist             "xyz.openbmc_project.Inventory.Item.Dimm",
32952ad9c2f6SJames Feist             "xyz.openbmc_project.Inventory.Item.Cpu",
3296e284a7c1SJames Feist             "xyz.openbmc_project.Inventory.Item.Drive",
3297e284a7c1SJames Feist             "xyz.openbmc_project.Inventory.Item.StorageController"};
3298b49ac873SJames Feist 
32997a1dbc48SGeorge Liu         dbus::utility::getSubTreePaths(
33007a1dbc48SGeorge Liu             "/", 0, inventoryForSystems,
33017a1dbc48SGeorge Liu             [health](const boost::system::error_code& ec,
3302914e2d5dSEd Tanous                      const std::vector<std::string>& resp) {
3303b49ac873SJames Feist             if (ec)
3304b49ac873SJames Feist             {
3305b49ac873SJames Feist                 // no inventory
3306b49ac873SJames Feist                 return;
3307b49ac873SJames Feist             }
3308b49ac873SJames Feist 
3309914e2d5dSEd Tanous             health->inventory = resp;
33107a1dbc48SGeorge Liu             });
3311b49ac873SJames Feist         health->populate();
331213451e39SWilly Tu     }
3313b49ac873SJames Feist 
3314002d39b4SEd Tanous     getMainChassisId(asyncResp,
3315002d39b4SEd Tanous                      [](const std::string& chassisId,
33168d1b46d7Szhanghch05                         const std::shared_ptr<bmcweb::AsyncResp>& aRsp) {
3317b2c7e208SEd Tanous         nlohmann::json::array_t chassisArray;
3318b2c7e208SEd Tanous         nlohmann::json& chassis = chassisArray.emplace_back();
3319ef4c65b7SEd Tanous         chassis["@odata.id"] = boost::urls::format("/redfish/v1/Chassis/{}",
3320ef4c65b7SEd Tanous                                                    chassisId);
3321002d39b4SEd Tanous         aRsp->res.jsonValue["Links"]["Chassis"] = std::move(chassisArray);
3322c5d03ff4SJennifer Lee     });
3323a3002228SAppaRao Puli 
33249f8bfa7cSGunnar Mills     getLocationIndicatorActive(asyncResp);
33259f8bfa7cSGunnar Mills     // TODO (Gunnar): Remove IndicatorLED after enough time has passed
3326a3002228SAppaRao Puli     getIndicatorLedState(asyncResp);
33275bc2dc8eSJames Feist     getComputerSystem(asyncResp, health);
33286c34de48SEd Tanous     getHostState(asyncResp);
3329491d8ee7SSantosh Puranik     getBootProperties(asyncResp);
3330978b8803SAndrew Geissler     getBootProgress(asyncResp);
3331b6d5d45cSHieu Huynh     getBootProgressLastStateTime(asyncResp);
3332472bd202SLakshmi Yadlapati     pcie_util::getPCIeDeviceList(asyncResp, "PCIeDevices");
333351709ffdSYong Li     getHostWatchdogTimer(asyncResp);
3334c6a620f2SGeorge Liu     getPowerRestorePolicy(asyncResp);
33359dcfe8c1SAlbert Zhang     getStopBootOnFault(asyncResp);
3336797d5daeSCorey Hardesty     getAutomaticRetryPolicy(asyncResp);
3337c0557e1aSGunnar Mills     getLastResetTime(asyncResp);
3338a6349918SAppaRao Puli #ifdef BMCWEB_ENABLE_REDFISH_PROVISIONING_FEATURE
3339a6349918SAppaRao Puli     getProvisioningStatus(asyncResp);
3340a6349918SAppaRao Puli #endif
33411981771bSAli Ahmed     getTrustedModuleRequiredToBoot(asyncResp);
33423a2d0424SChris Cain     getPowerMode(asyncResp);
334337bbf98cSChris Cain     getIdlePowerSaver(asyncResp);
3344c1e219d5SEd Tanous }
3345550a6bf8SJiaqing Zhao 
3346c1e219d5SEd Tanous inline void handleComputerSystemPatch(
3347c1e219d5SEd Tanous     crow::App& app, const crow::Request& req,
334822d268cbSEd Tanous     const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
3349c1e219d5SEd Tanous     const std::string& systemName)
3350c1e219d5SEd Tanous {
33513ba00073SCarson Labrado     if (!redfish::setUpRedfishRoute(app, req, asyncResp))
335245ca1b86SEd Tanous     {
335345ca1b86SEd Tanous         return;
335445ca1b86SEd Tanous     }
33557f3e84a1SEd Tanous     if constexpr (bmcwebEnableMultiHost)
33567f3e84a1SEd Tanous     {
33577f3e84a1SEd Tanous         // Option currently returns no systems.  TBD
33587f3e84a1SEd Tanous         messages::resourceNotFound(asyncResp->res, "ComputerSystem",
33597f3e84a1SEd Tanous                                    systemName);
33607f3e84a1SEd Tanous         return;
33617f3e84a1SEd Tanous     }
336222d268cbSEd Tanous     if (systemName != "system")
336322d268cbSEd Tanous     {
336422d268cbSEd Tanous         messages::resourceNotFound(asyncResp->res, "ComputerSystem",
336522d268cbSEd Tanous                                    systemName);
336622d268cbSEd Tanous         return;
336722d268cbSEd Tanous     }
336822d268cbSEd Tanous 
3369dd60b9edSEd Tanous     asyncResp->res.addHeader(
3370dd60b9edSEd Tanous         boost::beast::http::field::link,
3371dd60b9edSEd Tanous         "</redfish/v1/JsonSchemas/ComputerSystem/ComputerSystem.json>; rel=describedby");
3372dd60b9edSEd Tanous 
33739f8bfa7cSGunnar Mills     std::optional<bool> locationIndicatorActive;
3374cde19e5fSSantosh Puranik     std::optional<std::string> indicatorLed;
337598e386ecSGunnar Mills     std::optional<std::string> assetTag;
3376c6a620f2SGeorge Liu     std::optional<std::string> powerRestorePolicy;
33773a2d0424SChris Cain     std::optional<std::string> powerMode;
3378550a6bf8SJiaqing Zhao     std::optional<bool> wdtEnable;
3379550a6bf8SJiaqing Zhao     std::optional<std::string> wdtTimeOutAction;
3380550a6bf8SJiaqing Zhao     std::optional<std::string> bootSource;
3381550a6bf8SJiaqing Zhao     std::optional<std::string> bootType;
3382550a6bf8SJiaqing Zhao     std::optional<std::string> bootEnable;
3383550a6bf8SJiaqing Zhao     std::optional<std::string> bootAutomaticRetry;
3384797d5daeSCorey Hardesty     std::optional<uint32_t> bootAutomaticRetryAttempts;
3385550a6bf8SJiaqing Zhao     std::optional<bool> bootTrustedModuleRequired;
33869dcfe8c1SAlbert Zhang     std::optional<std::string> stopBootOnFault;
3387550a6bf8SJiaqing Zhao     std::optional<bool> ipsEnable;
3388550a6bf8SJiaqing Zhao     std::optional<uint8_t> ipsEnterUtil;
3389550a6bf8SJiaqing Zhao     std::optional<uint64_t> ipsEnterTime;
3390550a6bf8SJiaqing Zhao     std::optional<uint8_t> ipsExitUtil;
3391550a6bf8SJiaqing Zhao     std::optional<uint64_t> ipsExitTime;
3392550a6bf8SJiaqing Zhao 
3393550a6bf8SJiaqing Zhao     // clang-format off
339415ed6780SWilly Tu                 if (!json_util::readJsonPatch(
3395550a6bf8SJiaqing Zhao                         req, asyncResp->res,
3396550a6bf8SJiaqing Zhao                         "IndicatorLED", indicatorLed,
33977e860f15SJohn Edward Broadbent                         "LocationIndicatorActive", locationIndicatorActive,
3398550a6bf8SJiaqing Zhao                         "AssetTag", assetTag,
3399550a6bf8SJiaqing Zhao                         "PowerRestorePolicy", powerRestorePolicy,
3400550a6bf8SJiaqing Zhao                         "PowerMode", powerMode,
3401550a6bf8SJiaqing Zhao                         "HostWatchdogTimer/FunctionEnabled", wdtEnable,
3402550a6bf8SJiaqing Zhao                         "HostWatchdogTimer/TimeoutAction", wdtTimeOutAction,
3403550a6bf8SJiaqing Zhao                         "Boot/BootSourceOverrideTarget", bootSource,
3404550a6bf8SJiaqing Zhao                         "Boot/BootSourceOverrideMode", bootType,
3405550a6bf8SJiaqing Zhao                         "Boot/BootSourceOverrideEnabled", bootEnable,
3406550a6bf8SJiaqing Zhao                         "Boot/AutomaticRetryConfig", bootAutomaticRetry,
3407797d5daeSCorey Hardesty                         "Boot/AutomaticRetryAttempts", bootAutomaticRetryAttempts,
3408550a6bf8SJiaqing Zhao                         "Boot/TrustedModuleRequiredToBoot", bootTrustedModuleRequired,
34099dcfe8c1SAlbert Zhang                         "Boot/StopBootOnFault", stopBootOnFault,
3410550a6bf8SJiaqing Zhao                         "IdlePowerSaver/Enabled", ipsEnable,
3411550a6bf8SJiaqing Zhao                         "IdlePowerSaver/EnterUtilizationPercent", ipsEnterUtil,
3412550a6bf8SJiaqing Zhao                         "IdlePowerSaver/EnterDwellTimeSeconds", ipsEnterTime,
3413550a6bf8SJiaqing Zhao                         "IdlePowerSaver/ExitUtilizationPercent", ipsExitUtil,
3414550a6bf8SJiaqing Zhao                         "IdlePowerSaver/ExitDwellTimeSeconds", ipsExitTime))
34156617338dSEd Tanous                 {
34166617338dSEd Tanous                     return;
34176617338dSEd Tanous                 }
3418550a6bf8SJiaqing Zhao     // clang-format on
3419491d8ee7SSantosh Puranik 
34208d1b46d7Szhanghch05     asyncResp->res.result(boost::beast::http::status::no_content);
3421c45f0082SYong Li 
342298e386ecSGunnar Mills     if (assetTag)
342398e386ecSGunnar Mills     {
342498e386ecSGunnar Mills         setAssetTag(asyncResp, *assetTag);
342598e386ecSGunnar Mills     }
342698e386ecSGunnar Mills 
3427550a6bf8SJiaqing Zhao     if (wdtEnable || wdtTimeOutAction)
3428c45f0082SYong Li     {
3429f23b7296SEd Tanous         setWDTProperties(asyncResp, wdtEnable, wdtTimeOutAction);
3430c45f0082SYong Li     }
3431c45f0082SYong Li 
3432cd9a4666SKonstantin Aladyshev     if (bootSource || bootType || bootEnable)
343369f35306SGunnar Mills     {
3434002d39b4SEd Tanous         setBootProperties(asyncResp, bootSource, bootType, bootEnable);
3435491d8ee7SSantosh Puranik     }
3436550a6bf8SJiaqing Zhao     if (bootAutomaticRetry)
343769f35306SGunnar Mills     {
3438550a6bf8SJiaqing Zhao         setAutomaticRetry(asyncResp, *bootAutomaticRetry);
343969f35306SGunnar Mills     }
3440ac7e1e0bSAli Ahmed 
3441797d5daeSCorey Hardesty     if (bootAutomaticRetryAttempts)
3442797d5daeSCorey Hardesty     {
3443797d5daeSCorey Hardesty         setAutomaticRetryAttempts(asyncResp,
3444797d5daeSCorey Hardesty                                   bootAutomaticRetryAttempts.value());
3445797d5daeSCorey Hardesty     }
3446797d5daeSCorey Hardesty 
3447550a6bf8SJiaqing Zhao     if (bootTrustedModuleRequired)
3448ac7e1e0bSAli Ahmed     {
3449c1e219d5SEd Tanous         setTrustedModuleRequiredToBoot(asyncResp, *bootTrustedModuleRequired);
345069f35306SGunnar Mills     }
3451265c1602SJohnathan Mantey 
34529dcfe8c1SAlbert Zhang     if (stopBootOnFault)
34539dcfe8c1SAlbert Zhang     {
34549dcfe8c1SAlbert Zhang         setStopBootOnFault(asyncResp, *stopBootOnFault);
34559dcfe8c1SAlbert Zhang     }
34569dcfe8c1SAlbert Zhang 
34579f8bfa7cSGunnar Mills     if (locationIndicatorActive)
34589f8bfa7cSGunnar Mills     {
3459002d39b4SEd Tanous         setLocationIndicatorActive(asyncResp, *locationIndicatorActive);
34609f8bfa7cSGunnar Mills     }
34619f8bfa7cSGunnar Mills 
34627e860f15SJohn Edward Broadbent     // TODO (Gunnar): Remove IndicatorLED after enough time has
34637e860f15SJohn Edward Broadbent     // passed
34649712f8acSEd Tanous     if (indicatorLed)
34656617338dSEd Tanous     {
3466f23b7296SEd Tanous         setIndicatorLedState(asyncResp, *indicatorLed);
3467002d39b4SEd Tanous         asyncResp->res.addHeader(boost::beast::http::field::warning,
3468d6aa0093SGunnar Mills                                  "299 - \"IndicatorLED is deprecated. Use "
3469d6aa0093SGunnar Mills                                  "LocationIndicatorActive instead.\"");
34706617338dSEd Tanous     }
3471c6a620f2SGeorge Liu 
3472c6a620f2SGeorge Liu     if (powerRestorePolicy)
3473c6a620f2SGeorge Liu     {
34744e69c904SGunnar Mills         setPowerRestorePolicy(asyncResp, *powerRestorePolicy);
3475c6a620f2SGeorge Liu     }
34763a2d0424SChris Cain 
34773a2d0424SChris Cain     if (powerMode)
34783a2d0424SChris Cain     {
34793a2d0424SChris Cain         setPowerMode(asyncResp, *powerMode);
34803a2d0424SChris Cain     }
348137bbf98cSChris Cain 
3482c1e219d5SEd Tanous     if (ipsEnable || ipsEnterUtil || ipsEnterTime || ipsExitUtil || ipsExitTime)
348337bbf98cSChris Cain     {
3484002d39b4SEd Tanous         setIdlePowerSaver(asyncResp, ipsEnable, ipsEnterUtil, ipsEnterTime,
3485002d39b4SEd Tanous                           ipsExitUtil, ipsExitTime);
348637bbf98cSChris Cain     }
3487c1e219d5SEd Tanous }
34881cb1a9e6SAppaRao Puli 
348938c8a6f2SEd Tanous inline void handleSystemCollectionResetActionHead(
3490dd60b9edSEd Tanous     crow::App& app, const crow::Request& req,
34917f3e84a1SEd Tanous     const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
3492c1e219d5SEd Tanous     const std::string& /*systemName*/)
3493dd60b9edSEd Tanous {
3494dd60b9edSEd Tanous     if (!redfish::setUpRedfishRoute(app, req, asyncResp))
3495dd60b9edSEd Tanous     {
3496dd60b9edSEd Tanous         return;
3497dd60b9edSEd Tanous     }
3498dd60b9edSEd Tanous     asyncResp->res.addHeader(
3499dd60b9edSEd Tanous         boost::beast::http::field::link,
3500dd60b9edSEd Tanous         "</redfish/v1/JsonSchemas/ActionInfo/ActionInfo.json>; rel=describedby");
3501dd60b9edSEd Tanous }
3502c1e219d5SEd Tanous inline void handleSystemCollectionResetActionGet(
3503c1e219d5SEd Tanous     crow::App& app, const crow::Request& req,
350422d268cbSEd Tanous     const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
3505c1e219d5SEd Tanous     const std::string& systemName)
3506c1e219d5SEd Tanous {
35073ba00073SCarson Labrado     if (!redfish::setUpRedfishRoute(app, req, asyncResp))
350845ca1b86SEd Tanous     {
350945ca1b86SEd Tanous         return;
351045ca1b86SEd Tanous     }
35117f3e84a1SEd Tanous     if constexpr (bmcwebEnableMultiHost)
35127f3e84a1SEd Tanous     {
35137f3e84a1SEd Tanous         // Option currently returns no systems.  TBD
35147f3e84a1SEd Tanous         messages::resourceNotFound(asyncResp->res, "ComputerSystem",
35157f3e84a1SEd Tanous                                    systemName);
35167f3e84a1SEd Tanous         return;
35177f3e84a1SEd Tanous     }
3518746b56f3SAsmitha Karunanithi 
3519746b56f3SAsmitha Karunanithi     if (systemName == "hypervisor")
3520746b56f3SAsmitha Karunanithi     {
3521746b56f3SAsmitha Karunanithi         handleHypervisorResetActionGet(asyncResp);
3522746b56f3SAsmitha Karunanithi         return;
3523746b56f3SAsmitha Karunanithi     }
3524746b56f3SAsmitha Karunanithi 
352522d268cbSEd Tanous     if (systemName != "system")
352622d268cbSEd Tanous     {
352722d268cbSEd Tanous         messages::resourceNotFound(asyncResp->res, "ComputerSystem",
352822d268cbSEd Tanous                                    systemName);
352922d268cbSEd Tanous         return;
353022d268cbSEd Tanous     }
353122d268cbSEd Tanous 
3532dd60b9edSEd Tanous     asyncResp->res.addHeader(
3533dd60b9edSEd Tanous         boost::beast::http::field::link,
3534dd60b9edSEd Tanous         "</redfish/v1/JsonSchemas/ActionInfo/ActionInfo.json>; rel=describedby");
35351476687dSEd Tanous 
35361476687dSEd Tanous     asyncResp->res.jsonValue["@odata.id"] =
35371476687dSEd Tanous         "/redfish/v1/Systems/system/ResetActionInfo";
3538c1e219d5SEd Tanous     asyncResp->res.jsonValue["@odata.type"] = "#ActionInfo.v1_1_2.ActionInfo";
35391476687dSEd Tanous     asyncResp->res.jsonValue["Name"] = "Reset Action Info";
35401476687dSEd Tanous     asyncResp->res.jsonValue["Id"] = "ResetActionInfo";
35413215e700SNan Zhou 
35423215e700SNan Zhou     nlohmann::json::array_t parameters;
35433215e700SNan Zhou     nlohmann::json::object_t parameter;
35443215e700SNan Zhou 
35453215e700SNan Zhou     parameter["Name"] = "ResetType";
35463215e700SNan Zhou     parameter["Required"] = true;
35473215e700SNan Zhou     parameter["DataType"] = "String";
35483215e700SNan Zhou     nlohmann::json::array_t allowableValues;
35493215e700SNan Zhou     allowableValues.emplace_back("On");
35503215e700SNan Zhou     allowableValues.emplace_back("ForceOff");
35513215e700SNan Zhou     allowableValues.emplace_back("ForceOn");
35523215e700SNan Zhou     allowableValues.emplace_back("ForceRestart");
35533215e700SNan Zhou     allowableValues.emplace_back("GracefulRestart");
35543215e700SNan Zhou     allowableValues.emplace_back("GracefulShutdown");
35553215e700SNan Zhou     allowableValues.emplace_back("PowerCycle");
35563215e700SNan Zhou     allowableValues.emplace_back("Nmi");
35573215e700SNan Zhou     parameter["AllowableValues"] = std::move(allowableValues);
35583215e700SNan Zhou     parameters.emplace_back(std::move(parameter));
35593215e700SNan Zhou 
35603215e700SNan Zhou     asyncResp->res.jsonValue["Parameters"] = std::move(parameters);
3561c1e219d5SEd Tanous }
3562c1e219d5SEd Tanous /**
3563c1e219d5SEd Tanous  * SystemResetActionInfo derived class for delivering Computer Systems
3564c1e219d5SEd Tanous  * ResetType AllowableValues using ResetInfo schema.
3565c1e219d5SEd Tanous  */
3566100afe56SEd Tanous inline void requestRoutesSystems(App& app)
3567c1e219d5SEd Tanous {
3568100afe56SEd Tanous     BMCWEB_ROUTE(app, "/redfish/v1/Systems/")
3569100afe56SEd Tanous         .privileges(redfish::privileges::headComputerSystemCollection)
3570100afe56SEd Tanous         .methods(boost::beast::http::verb::head)(
3571100afe56SEd Tanous             std::bind_front(handleComputerSystemCollectionHead, std::ref(app)));
3572100afe56SEd Tanous 
3573100afe56SEd Tanous     BMCWEB_ROUTE(app, "/redfish/v1/Systems/")
3574100afe56SEd Tanous         .privileges(redfish::privileges::getComputerSystemCollection)
3575100afe56SEd Tanous         .methods(boost::beast::http::verb::get)(
3576100afe56SEd Tanous             std::bind_front(handleComputerSystemCollectionGet, std::ref(app)));
3577100afe56SEd Tanous 
3578100afe56SEd Tanous     BMCWEB_ROUTE(app, "/redfish/v1/Systems/<str>/")
3579100afe56SEd Tanous         .privileges(redfish::privileges::headComputerSystem)
3580100afe56SEd Tanous         .methods(boost::beast::http::verb::head)(
3581100afe56SEd Tanous             std::bind_front(handleComputerSystemHead, std::ref(app)));
3582100afe56SEd Tanous 
3583100afe56SEd Tanous     BMCWEB_ROUTE(app, "/redfish/v1/Systems/<str>/")
3584100afe56SEd Tanous         .privileges(redfish::privileges::getComputerSystem)
3585100afe56SEd Tanous         .methods(boost::beast::http::verb::get)(
3586100afe56SEd Tanous             std::bind_front(handleComputerSystemGet, std::ref(app)));
3587100afe56SEd Tanous 
3588100afe56SEd Tanous     BMCWEB_ROUTE(app, "/redfish/v1/Systems/<str>/")
3589100afe56SEd Tanous         .privileges(redfish::privileges::patchComputerSystem)
3590100afe56SEd Tanous         .methods(boost::beast::http::verb::patch)(
3591100afe56SEd Tanous             std::bind_front(handleComputerSystemPatch, std::ref(app)));
3592100afe56SEd Tanous 
3593100afe56SEd Tanous     BMCWEB_ROUTE(app, "/redfish/v1/Systems/<str>/Actions/ComputerSystem.Reset/")
3594100afe56SEd Tanous         .privileges(redfish::privileges::postComputerSystem)
3595100afe56SEd Tanous         .methods(boost::beast::http::verb::post)(std::bind_front(
3596100afe56SEd Tanous             handleComputerSystemResetActionPost, std::ref(app)));
3597100afe56SEd Tanous 
3598c1e219d5SEd Tanous     BMCWEB_ROUTE(app, "/redfish/v1/Systems/<str>/ResetActionInfo/")
3599c1e219d5SEd Tanous         .privileges(redfish::privileges::headActionInfo)
3600c1e219d5SEd Tanous         .methods(boost::beast::http::verb::head)(std::bind_front(
3601c1e219d5SEd Tanous             handleSystemCollectionResetActionHead, std::ref(app)));
3602c1e219d5SEd Tanous     BMCWEB_ROUTE(app, "/redfish/v1/Systems/<str>/ResetActionInfo/")
3603c1e219d5SEd Tanous         .privileges(redfish::privileges::getActionInfo)
3604c1e219d5SEd Tanous         .methods(boost::beast::http::verb::get)(std::bind_front(
3605c1e219d5SEd Tanous             handleSystemCollectionResetActionGet, std::ref(app)));
36061cb1a9e6SAppaRao Puli }
3607c5b2abe0SLewanczyk, Dawid } // namespace redfish
3608