xref: /openbmc/bmcweb/features/redfish/lib/systems.hpp (revision a3002228555bbabb42387a27e8b4ec55240ce7eb)
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 
18b49ac873SJames Feist #include "health.hpp"
19f5c9f8bdSJason M. Bills #include "pcie.hpp"
20c5d03ff4SJennifer Lee #include "redfish_util.hpp"
21c5d03ff4SJennifer Lee 
229712f8acSEd Tanous #include <boost/container/flat_map.hpp>
239712f8acSEd Tanous #include <node.hpp>
24cb7e1e7bSAndrew Geissler #include <utils/fw_utils.hpp>
25c5b2abe0SLewanczyk, Dawid #include <utils/json_utils.hpp>
26abf2add6SEd Tanous #include <variant>
27c5b2abe0SLewanczyk, Dawid 
281abe55efSEd Tanous namespace redfish
291abe55efSEd Tanous {
30c5b2abe0SLewanczyk, Dawid 
319d3ae10eSAlpana Kumari /**
329d3ae10eSAlpana Kumari  * @brief Updates the Functional State of DIMMs
339d3ae10eSAlpana Kumari  *
349d3ae10eSAlpana Kumari  * @param[in] aResp Shared pointer for completing asynchronous calls
359d3ae10eSAlpana Kumari  * @param[in] dimmState Dimm's Functional state, true/false
369d3ae10eSAlpana Kumari  *
379d3ae10eSAlpana Kumari  * @return None.
389d3ae10eSAlpana Kumari  */
399d3ae10eSAlpana Kumari void updateDimmProperties(std::shared_ptr<AsyncResp> aResp,
409d3ae10eSAlpana Kumari                           const std::variant<bool> &dimmState)
419d3ae10eSAlpana Kumari {
429d3ae10eSAlpana Kumari     const bool *isDimmFunctional = std::get_if<bool>(&dimmState);
439d3ae10eSAlpana Kumari     if (isDimmFunctional == nullptr)
449d3ae10eSAlpana Kumari     {
459d3ae10eSAlpana Kumari         messages::internalError(aResp->res);
469d3ae10eSAlpana Kumari         return;
479d3ae10eSAlpana Kumari     }
489d3ae10eSAlpana Kumari     BMCWEB_LOG_DEBUG << "Dimm Functional: " << *isDimmFunctional;
499d3ae10eSAlpana Kumari 
509d3ae10eSAlpana Kumari     // Set it as Enabled if atleast one DIMM is functional
519d3ae10eSAlpana Kumari     // Update STATE only if previous State was DISABLED and current Dimm is
529d3ae10eSAlpana Kumari     // ENABLED.
539d3ae10eSAlpana Kumari     nlohmann::json &prevMemSummary =
549d3ae10eSAlpana Kumari         aResp->res.jsonValue["MemorySummary"]["Status"]["State"];
559d3ae10eSAlpana Kumari     if (prevMemSummary == "Disabled")
569d3ae10eSAlpana Kumari     {
579d3ae10eSAlpana Kumari         if (*isDimmFunctional == true)
589d3ae10eSAlpana Kumari         {
599d3ae10eSAlpana Kumari             aResp->res.jsonValue["MemorySummary"]["Status"]["State"] =
609d3ae10eSAlpana Kumari                 "Enabled";
619d3ae10eSAlpana Kumari         }
629d3ae10eSAlpana Kumari     }
639d3ae10eSAlpana Kumari }
649d3ae10eSAlpana Kumari 
6557e8c9beSAlpana Kumari /*
6657e8c9beSAlpana Kumari  * @brief Update "ProcessorSummary" "Count" based on Cpu PresenceState
6757e8c9beSAlpana Kumari  *
6857e8c9beSAlpana Kumari  * @param[in] aResp Shared pointer for completing asynchronous calls
6957e8c9beSAlpana Kumari  * @param[in] cpuPresenceState CPU present or not
7057e8c9beSAlpana Kumari  *
7157e8c9beSAlpana Kumari  * @return None.
7257e8c9beSAlpana Kumari  */
7357e8c9beSAlpana Kumari void modifyCpuPresenceState(std::shared_ptr<AsyncResp> aResp,
7457e8c9beSAlpana Kumari                             const std::variant<bool> &cpuPresenceState)
7557e8c9beSAlpana Kumari {
7657e8c9beSAlpana Kumari     const bool *isCpuPresent = std::get_if<bool>(&cpuPresenceState);
7757e8c9beSAlpana Kumari 
7857e8c9beSAlpana Kumari     if (isCpuPresent == nullptr)
7957e8c9beSAlpana Kumari     {
8057e8c9beSAlpana Kumari         messages::internalError(aResp->res);
8157e8c9beSAlpana Kumari         return;
8257e8c9beSAlpana Kumari     }
8357e8c9beSAlpana Kumari     BMCWEB_LOG_DEBUG << "Cpu Present: " << *isCpuPresent;
8457e8c9beSAlpana Kumari 
8557e8c9beSAlpana Kumari     nlohmann::json &procCount =
8657e8c9beSAlpana Kumari         aResp->res.jsonValue["ProcessorSummary"]["Count"];
8757e8c9beSAlpana Kumari     if (*isCpuPresent == true)
8857e8c9beSAlpana Kumari     {
8957e8c9beSAlpana Kumari         procCount = procCount.get<int>() + 1;
9057e8c9beSAlpana Kumari     }
9157e8c9beSAlpana Kumari     aResp->res.jsonValue["ProcessorSummary"]["Count"] = procCount;
9257e8c9beSAlpana Kumari }
9357e8c9beSAlpana Kumari 
9457e8c9beSAlpana Kumari /*
9557e8c9beSAlpana Kumari  * @brief Update "ProcessorSummary" "Status" "State" based on
9657e8c9beSAlpana Kumari  *        CPU Functional State
9757e8c9beSAlpana Kumari  *
9857e8c9beSAlpana Kumari  * @param[in] aResp Shared pointer for completing asynchronous calls
9957e8c9beSAlpana Kumari  * @param[in] cpuFunctionalState is CPU functional true/false
10057e8c9beSAlpana Kumari  *
10157e8c9beSAlpana Kumari  * @return None.
10257e8c9beSAlpana Kumari  */
10357e8c9beSAlpana Kumari void modifyCpuFunctionalState(std::shared_ptr<AsyncResp> aResp,
10457e8c9beSAlpana Kumari                               const std::variant<bool> &cpuFunctionalState)
10557e8c9beSAlpana Kumari {
10657e8c9beSAlpana Kumari     const bool *isCpuFunctional = std::get_if<bool>(&cpuFunctionalState);
10757e8c9beSAlpana Kumari 
10857e8c9beSAlpana Kumari     if (isCpuFunctional == nullptr)
10957e8c9beSAlpana Kumari     {
11057e8c9beSAlpana Kumari         messages::internalError(aResp->res);
11157e8c9beSAlpana Kumari         return;
11257e8c9beSAlpana Kumari     }
11357e8c9beSAlpana Kumari     BMCWEB_LOG_DEBUG << "Cpu Functional: " << *isCpuFunctional;
11457e8c9beSAlpana Kumari 
11557e8c9beSAlpana Kumari     nlohmann::json &prevProcState =
11657e8c9beSAlpana Kumari         aResp->res.jsonValue["ProcessorSummary"]["Status"]["State"];
11757e8c9beSAlpana Kumari 
11857e8c9beSAlpana Kumari     // Set it as Enabled if atleast one CPU is functional
11957e8c9beSAlpana Kumari     // Update STATE only if previous State was Non_Functional and current CPU is
12057e8c9beSAlpana Kumari     // Functional.
12157e8c9beSAlpana Kumari     if (prevProcState == "Disabled")
12257e8c9beSAlpana Kumari     {
12357e8c9beSAlpana Kumari         if (*isCpuFunctional == true)
12457e8c9beSAlpana Kumari         {
12557e8c9beSAlpana Kumari             aResp->res.jsonValue["ProcessorSummary"]["Status"]["State"] =
12657e8c9beSAlpana Kumari                 "Enabled";
12757e8c9beSAlpana Kumari         }
12857e8c9beSAlpana Kumari     }
12957e8c9beSAlpana Kumari }
13057e8c9beSAlpana Kumari 
13157e8c9beSAlpana Kumari /*
132c5b2abe0SLewanczyk, Dawid  * @brief Retrieves computer system properties over dbus
133c5b2abe0SLewanczyk, Dawid  *
134c5b2abe0SLewanczyk, Dawid  * @param[in] aResp Shared pointer for completing asynchronous calls
135c5b2abe0SLewanczyk, Dawid  * @param[in] name  Computer system name from request
136c5b2abe0SLewanczyk, Dawid  *
137c5b2abe0SLewanczyk, Dawid  * @return None.
138c5b2abe0SLewanczyk, Dawid  */
1395bc2dc8eSJames Feist void getComputerSystem(std::shared_ptr<AsyncResp> aResp,
1405bc2dc8eSJames Feist                        std::shared_ptr<HealthPopulate> systemHealth)
1411abe55efSEd Tanous {
14255c7b7a2SEd Tanous     BMCWEB_LOG_DEBUG << "Get available system components.";
1439d3ae10eSAlpana Kumari 
14455c7b7a2SEd Tanous     crow::connections::systemBus->async_method_call(
1455bc2dc8eSJames Feist         [aResp, systemHealth](
146c5b2abe0SLewanczyk, Dawid             const boost::system::error_code ec,
147c5b2abe0SLewanczyk, Dawid             const std::vector<std::pair<
1486c34de48SEd Tanous                 std::string,
1496c34de48SEd Tanous                 std::vector<std::pair<std::string, std::vector<std::string>>>>>
150c5b2abe0SLewanczyk, Dawid                 &subtree) {
1511abe55efSEd Tanous             if (ec)
1521abe55efSEd Tanous             {
15355c7b7a2SEd Tanous                 BMCWEB_LOG_DEBUG << "DBUS response error";
154f12894f8SJason M. Bills                 messages::internalError(aResp->res);
155c5b2abe0SLewanczyk, Dawid                 return;
156c5b2abe0SLewanczyk, Dawid             }
157c5b2abe0SLewanczyk, Dawid             // Iterate over all retrieved ObjectPaths.
1586c34de48SEd Tanous             for (const std::pair<std::string,
1596c34de48SEd Tanous                                  std::vector<std::pair<
1606c34de48SEd Tanous                                      std::string, std::vector<std::string>>>>
1611abe55efSEd Tanous                      &object : subtree)
1621abe55efSEd Tanous             {
163c5b2abe0SLewanczyk, Dawid                 const std::string &path = object.first;
16455c7b7a2SEd Tanous                 BMCWEB_LOG_DEBUG << "Got path: " << path;
1651abe55efSEd Tanous                 const std::vector<
1661abe55efSEd Tanous                     std::pair<std::string, std::vector<std::string>>>
167c5b2abe0SLewanczyk, Dawid                     &connectionNames = object.second;
1681abe55efSEd Tanous                 if (connectionNames.size() < 1)
1691abe55efSEd Tanous                 {
170c5b2abe0SLewanczyk, Dawid                     continue;
171c5b2abe0SLewanczyk, Dawid                 }
172029573d4SEd Tanous 
1735bc2dc8eSJames Feist                 auto memoryHealth = std::make_shared<HealthPopulate>(
1745bc2dc8eSJames Feist                     aResp, aResp->res.jsonValue["MemorySummary"]["Status"]);
1755bc2dc8eSJames Feist 
1765bc2dc8eSJames Feist                 auto cpuHealth = std::make_shared<HealthPopulate>(
1775bc2dc8eSJames Feist                     aResp, aResp->res.jsonValue["ProcessorSummary"]["Status"]);
1785bc2dc8eSJames Feist 
1795bc2dc8eSJames Feist                 systemHealth->children.emplace_back(memoryHealth);
1805bc2dc8eSJames Feist                 systemHealth->children.emplace_back(cpuHealth);
1815bc2dc8eSJames Feist 
1826c34de48SEd Tanous                 // This is not system, so check if it's cpu, dimm, UUID or
1836c34de48SEd Tanous                 // BiosVer
18404a258f4SEd Tanous                 for (const auto &connection : connectionNames)
1851abe55efSEd Tanous                 {
18604a258f4SEd Tanous                     for (const auto &interfaceName : connection.second)
1871abe55efSEd Tanous                     {
18804a258f4SEd Tanous                         if (interfaceName ==
18904a258f4SEd Tanous                             "xyz.openbmc_project.Inventory.Item.Dimm")
1901abe55efSEd Tanous                         {
1911abe55efSEd Tanous                             BMCWEB_LOG_DEBUG
19204a258f4SEd Tanous                                 << "Found Dimm, now get its properties.";
1939d3ae10eSAlpana Kumari 
19455c7b7a2SEd Tanous                             crow::connections::systemBus->async_method_call(
1959d3ae10eSAlpana Kumari                                 [aResp, service{connection.first},
1969d3ae10eSAlpana Kumari                                  path(std::move(path))](
1979d3ae10eSAlpana Kumari                                     const boost::system::error_code ec,
1986c34de48SEd Tanous                                     const std::vector<
1996c34de48SEd Tanous                                         std::pair<std::string, VariantType>>
2001abe55efSEd Tanous                                         &properties) {
2011abe55efSEd Tanous                                     if (ec)
2021abe55efSEd Tanous                                     {
2031abe55efSEd Tanous                                         BMCWEB_LOG_ERROR
2046c34de48SEd Tanous                                             << "DBUS response error " << ec;
205f12894f8SJason M. Bills                                         messages::internalError(aResp->res);
206c5b2abe0SLewanczyk, Dawid                                         return;
207c5b2abe0SLewanczyk, Dawid                                     }
2086c34de48SEd Tanous                                     BMCWEB_LOG_DEBUG << "Got "
2096c34de48SEd Tanous                                                      << properties.size()
210c5b2abe0SLewanczyk, Dawid                                                      << " Dimm properties.";
2119d3ae10eSAlpana Kumari 
2129d3ae10eSAlpana Kumari                                     if (properties.size() > 0)
2139d3ae10eSAlpana Kumari                                     {
21404a258f4SEd Tanous                                         for (const std::pair<std::string,
21504a258f4SEd Tanous                                                              VariantType>
21604a258f4SEd Tanous                                                  &property : properties)
2171abe55efSEd Tanous                                         {
2189d3ae10eSAlpana Kumari                                             if (property.first ==
2199d3ae10eSAlpana Kumari                                                 "MemorySizeInKb")
2201abe55efSEd Tanous                                             {
22104a258f4SEd Tanous                                                 const uint64_t *value =
2229d3ae10eSAlpana Kumari                                                     sdbusplus::message::
2239d3ae10eSAlpana Kumari                                                         variant_ns::get_if<
2249d3ae10eSAlpana Kumari                                                             uint64_t>(
2251b6b96c5SEd Tanous                                                             &property.second);
22604a258f4SEd Tanous                                                 if (value != nullptr)
2271abe55efSEd Tanous                                                 {
2281abe55efSEd Tanous                                                     aResp->res.jsonValue
2296c34de48SEd Tanous                                                         ["TotalSystemMemoryGi"
2306c34de48SEd Tanous                                                          "B"] +=
23104a258f4SEd Tanous                                                         *value / (1024 * 1024);
2329d3ae10eSAlpana Kumari                                                     aResp->res.jsonValue
2339d3ae10eSAlpana Kumari                                                         ["MemorySummary"]
2349d3ae10eSAlpana Kumari                                                         ["Status"]["State"] =
2351abe55efSEd Tanous                                                         "Enabled";
236c5b2abe0SLewanczyk, Dawid                                                 }
237c5b2abe0SLewanczyk, Dawid                                             }
238c5b2abe0SLewanczyk, Dawid                                         }
2399d3ae10eSAlpana Kumari                                     }
2409d3ae10eSAlpana Kumari                                     else
2419d3ae10eSAlpana Kumari                                     {
2429d3ae10eSAlpana Kumari                                         auto getDimmProperties =
2439d3ae10eSAlpana Kumari                                             [aResp](
2449d3ae10eSAlpana Kumari                                                 const boost::system::error_code
2459d3ae10eSAlpana Kumari                                                     ec,
2469d3ae10eSAlpana Kumari                                                 const std::variant<bool>
2479d3ae10eSAlpana Kumari                                                     &dimmState) {
2489d3ae10eSAlpana Kumari                                                 if (ec)
2499d3ae10eSAlpana Kumari                                                 {
2509d3ae10eSAlpana Kumari                                                     BMCWEB_LOG_ERROR
2519d3ae10eSAlpana Kumari                                                         << "DBUS response "
2529d3ae10eSAlpana Kumari                                                            "error "
2539d3ae10eSAlpana Kumari                                                         << ec;
2549d3ae10eSAlpana Kumari                                                     return;
2559d3ae10eSAlpana Kumari                                                 }
2569d3ae10eSAlpana Kumari                                                 updateDimmProperties(aResp,
2579d3ae10eSAlpana Kumari                                                                      dimmState);
2589d3ae10eSAlpana Kumari                                             };
2599d3ae10eSAlpana Kumari                                         crow::connections::systemBus
2609d3ae10eSAlpana Kumari                                             ->async_method_call(
2619d3ae10eSAlpana Kumari                                                 std::move(getDimmProperties),
2629d3ae10eSAlpana Kumari                                                 service, path,
2639d3ae10eSAlpana Kumari                                                 "org.freedesktop.DBus."
2649d3ae10eSAlpana Kumari                                                 "Properties",
2659d3ae10eSAlpana Kumari                                                 "Get",
2669d3ae10eSAlpana Kumari                                                 "xyz.openbmc_project.State."
2679d3ae10eSAlpana Kumari                                                 "Decorator.OperationalStatus",
2689d3ae10eSAlpana Kumari                                                 "Functional");
2699d3ae10eSAlpana Kumari                                     }
270c5b2abe0SLewanczyk, Dawid                                 },
27104a258f4SEd Tanous                                 connection.first, path,
2726c34de48SEd Tanous                                 "org.freedesktop.DBus.Properties", "GetAll",
2736c34de48SEd Tanous                                 "xyz.openbmc_project.Inventory.Item.Dimm");
2745bc2dc8eSJames Feist 
2755bc2dc8eSJames Feist                             memoryHealth->inventory.emplace_back(path);
2761abe55efSEd Tanous                         }
27704a258f4SEd Tanous                         else if (interfaceName ==
27804a258f4SEd Tanous                                  "xyz.openbmc_project.Inventory.Item.Cpu")
2791abe55efSEd Tanous                         {
2801abe55efSEd Tanous                             BMCWEB_LOG_DEBUG
28104a258f4SEd Tanous                                 << "Found Cpu, now get its properties.";
28257e8c9beSAlpana Kumari 
283a0803efaSEd Tanous                             crow::connections::systemBus->async_method_call(
28457e8c9beSAlpana Kumari                                 [aResp, service{connection.first},
28557e8c9beSAlpana Kumari                                  path(std::move(path))](
28657e8c9beSAlpana Kumari                                     const boost::system::error_code ec,
2876c34de48SEd Tanous                                     const std::vector<
2886c34de48SEd Tanous                                         std::pair<std::string, VariantType>>
2891abe55efSEd Tanous                                         &properties) {
2901abe55efSEd Tanous                                     if (ec)
2911abe55efSEd Tanous                                     {
2921abe55efSEd Tanous                                         BMCWEB_LOG_ERROR
2936c34de48SEd Tanous                                             << "DBUS response error " << ec;
294f12894f8SJason M. Bills                                         messages::internalError(aResp->res);
295c5b2abe0SLewanczyk, Dawid                                         return;
296c5b2abe0SLewanczyk, Dawid                                     }
2976c34de48SEd Tanous                                     BMCWEB_LOG_DEBUG << "Got "
2986c34de48SEd Tanous                                                      << properties.size()
299c5b2abe0SLewanczyk, Dawid                                                      << " Cpu properties.";
30057e8c9beSAlpana Kumari 
30157e8c9beSAlpana Kumari                                     if (properties.size() > 0)
30257e8c9beSAlpana Kumari                                     {
30304a258f4SEd Tanous                                         for (const auto &property : properties)
3041abe55efSEd Tanous                                         {
30557e8c9beSAlpana Kumari                                             if (property.first ==
30657e8c9beSAlpana Kumari                                                 "ProcessorFamily")
3071abe55efSEd Tanous                                             {
308a0803efaSEd Tanous                                                 const std::string *value =
30957e8c9beSAlpana Kumari                                                     sdbusplus::message::
31057e8c9beSAlpana Kumari                                                         variant_ns::get_if<
31157e8c9beSAlpana Kumari                                                             std::string>(
3121b6b96c5SEd Tanous                                                             &property.second);
3131abe55efSEd Tanous                                                 if (value != nullptr)
3141abe55efSEd Tanous                                                 {
31557e8c9beSAlpana Kumari                                                     nlohmann::json
31657e8c9beSAlpana Kumari                                                         &procSummary =
3171abe55efSEd Tanous                                                             aResp->res.jsonValue
3186c34de48SEd Tanous                                                                 ["ProcessorSumm"
31904a258f4SEd Tanous                                                                  "ary"];
32004a258f4SEd Tanous                                                     nlohmann::json &procCount =
32104a258f4SEd Tanous                                                         procSummary["Count"];
32204a258f4SEd Tanous                                                     procCount =
32357e8c9beSAlpana Kumari                                                         procCount.get<int>() +
32457e8c9beSAlpana Kumari                                                         1;
32557e8c9beSAlpana Kumari                                                     procSummary["Status"]
32657e8c9beSAlpana Kumari                                                                ["State"] =
327c5b2abe0SLewanczyk, Dawid                                                                    "Enabled";
32857e8c9beSAlpana Kumari                                                     procSummary["Model"] =
32957e8c9beSAlpana Kumari                                                         *value;
330c5b2abe0SLewanczyk, Dawid                                                 }
331c5b2abe0SLewanczyk, Dawid                                             }
332c5b2abe0SLewanczyk, Dawid                                         }
33357e8c9beSAlpana Kumari                                     }
33457e8c9beSAlpana Kumari                                     else
33557e8c9beSAlpana Kumari                                     {
33657e8c9beSAlpana Kumari                                         auto getCpuPresenceState =
33757e8c9beSAlpana Kumari                                             [aResp](
33857e8c9beSAlpana Kumari                                                 const boost::system::error_code
33957e8c9beSAlpana Kumari                                                     ec,
34057e8c9beSAlpana Kumari                                                 const std::variant<bool>
34157e8c9beSAlpana Kumari                                                     &cpuPresenceCheck) {
34257e8c9beSAlpana Kumari                                                 if (ec)
34357e8c9beSAlpana Kumari                                                 {
34457e8c9beSAlpana Kumari                                                     BMCWEB_LOG_ERROR
34557e8c9beSAlpana Kumari                                                         << "DBUS response "
34657e8c9beSAlpana Kumari                                                            "error "
34757e8c9beSAlpana Kumari                                                         << ec;
34857e8c9beSAlpana Kumari                                                     return;
34957e8c9beSAlpana Kumari                                                 }
35057e8c9beSAlpana Kumari                                                 modifyCpuPresenceState(
35157e8c9beSAlpana Kumari                                                     aResp, cpuPresenceCheck);
35257e8c9beSAlpana Kumari                                             };
35357e8c9beSAlpana Kumari 
35457e8c9beSAlpana Kumari                                         auto getCpuFunctionalState =
35557e8c9beSAlpana Kumari                                             [aResp](
35657e8c9beSAlpana Kumari                                                 const boost::system::error_code
35757e8c9beSAlpana Kumari                                                     ec,
35857e8c9beSAlpana Kumari                                                 const std::variant<bool>
35957e8c9beSAlpana Kumari                                                     &cpuFunctionalCheck) {
36057e8c9beSAlpana Kumari                                                 if (ec)
36157e8c9beSAlpana Kumari                                                 {
36257e8c9beSAlpana Kumari                                                     BMCWEB_LOG_ERROR
36357e8c9beSAlpana Kumari                                                         << "DBUS response "
36457e8c9beSAlpana Kumari                                                            "error "
36557e8c9beSAlpana Kumari                                                         << ec;
36657e8c9beSAlpana Kumari                                                     return;
36757e8c9beSAlpana Kumari                                                 }
36857e8c9beSAlpana Kumari                                                 modifyCpuFunctionalState(
36957e8c9beSAlpana Kumari                                                     aResp, cpuFunctionalCheck);
37057e8c9beSAlpana Kumari                                             };
37157e8c9beSAlpana Kumari                                         // Get the Presence of CPU
37257e8c9beSAlpana Kumari                                         crow::connections::systemBus
37357e8c9beSAlpana Kumari                                             ->async_method_call(
37457e8c9beSAlpana Kumari                                                 std::move(getCpuPresenceState),
37557e8c9beSAlpana Kumari                                                 service, path,
37657e8c9beSAlpana Kumari                                                 "org.freedesktop.DBus."
37757e8c9beSAlpana Kumari                                                 "Properties",
37857e8c9beSAlpana Kumari                                                 "Get",
37957e8c9beSAlpana Kumari                                                 "xyz.openbmc_project.Inventory."
38057e8c9beSAlpana Kumari                                                 "Item",
38157e8c9beSAlpana Kumari                                                 "Present");
38257e8c9beSAlpana Kumari 
38357e8c9beSAlpana Kumari                                         // Get the Functional State
38457e8c9beSAlpana Kumari                                         crow::connections::systemBus
38557e8c9beSAlpana Kumari                                             ->async_method_call(
38657e8c9beSAlpana Kumari                                                 std::move(
38757e8c9beSAlpana Kumari                                                     getCpuFunctionalState),
38857e8c9beSAlpana Kumari                                                 service, path,
38957e8c9beSAlpana Kumari                                                 "org.freedesktop.DBus."
39057e8c9beSAlpana Kumari                                                 "Properties",
39157e8c9beSAlpana Kumari                                                 "Get",
39257e8c9beSAlpana Kumari                                                 "xyz.openbmc_project.State."
39357e8c9beSAlpana Kumari                                                 "Decorator."
39457e8c9beSAlpana Kumari                                                 "OperationalStatus",
39557e8c9beSAlpana Kumari                                                 "Functional");
39657e8c9beSAlpana Kumari 
39757e8c9beSAlpana Kumari                                         // Get the MODEL from
39857e8c9beSAlpana Kumari                                         // xyz.openbmc_project.Inventory.Decorator.Asset
39957e8c9beSAlpana Kumari                                         // support it later as Model  is Empty
40057e8c9beSAlpana Kumari                                         // currently.
40157e8c9beSAlpana Kumari                                     }
402c5b2abe0SLewanczyk, Dawid                                 },
40304a258f4SEd Tanous                                 connection.first, path,
4046c34de48SEd Tanous                                 "org.freedesktop.DBus.Properties", "GetAll",
4056c34de48SEd Tanous                                 "xyz.openbmc_project.Inventory.Item.Cpu");
4065bc2dc8eSJames Feist 
4075bc2dc8eSJames Feist                             cpuHealth->inventory.emplace_back(path);
4081abe55efSEd Tanous                         }
40904a258f4SEd Tanous                         else if (interfaceName ==
41004a258f4SEd Tanous                                  "xyz.openbmc_project.Common.UUID")
4111abe55efSEd Tanous                         {
4121abe55efSEd Tanous                             BMCWEB_LOG_DEBUG
41304a258f4SEd Tanous                                 << "Found UUID, now get its properties.";
41455c7b7a2SEd Tanous                             crow::connections::systemBus->async_method_call(
415029573d4SEd Tanous                                 [aResp](const boost::system::error_code ec,
4166c34de48SEd Tanous                                         const std::vector<
4176c34de48SEd Tanous                                             std::pair<std::string, VariantType>>
4181abe55efSEd Tanous                                             &properties) {
4191abe55efSEd Tanous                                     if (ec)
4201abe55efSEd Tanous                                     {
4211abe55efSEd Tanous                                         BMCWEB_LOG_DEBUG
4226c34de48SEd Tanous                                             << "DBUS response error " << ec;
423f12894f8SJason M. Bills                                         messages::internalError(aResp->res);
424c5b2abe0SLewanczyk, Dawid                                         return;
425c5b2abe0SLewanczyk, Dawid                                     }
4266c34de48SEd Tanous                                     BMCWEB_LOG_DEBUG << "Got "
4276c34de48SEd Tanous                                                      << properties.size()
428c5b2abe0SLewanczyk, Dawid                                                      << " UUID properties.";
4291abe55efSEd Tanous                                     for (const std::pair<std::string,
43004a258f4SEd Tanous                                                          VariantType>
43104a258f4SEd Tanous                                              &property : properties)
4321abe55efSEd Tanous                                     {
43304a258f4SEd Tanous                                         if (property.first == "UUID")
4341abe55efSEd Tanous                                         {
435c5b2abe0SLewanczyk, Dawid                                             const std::string *value =
436029573d4SEd Tanous                                                 sdbusplus::message::variant_ns::
437029573d4SEd Tanous                                                     get_if<std::string>(
4381b6b96c5SEd Tanous                                                         &property.second);
43904a258f4SEd Tanous 
4401abe55efSEd Tanous                                             if (value != nullptr)
4411abe55efSEd Tanous                                             {
442029573d4SEd Tanous                                                 std::string valueStr = *value;
44304a258f4SEd Tanous                                                 if (valueStr.size() == 32)
4441abe55efSEd Tanous                                                 {
445029573d4SEd Tanous                                                     valueStr.insert(8, 1, '-');
446029573d4SEd Tanous                                                     valueStr.insert(13, 1, '-');
447029573d4SEd Tanous                                                     valueStr.insert(18, 1, '-');
448029573d4SEd Tanous                                                     valueStr.insert(23, 1, '-');
44904a258f4SEd Tanous                                                 }
450029573d4SEd Tanous                                                 BMCWEB_LOG_DEBUG << "UUID = "
45104a258f4SEd Tanous                                                                  << valueStr;
452029573d4SEd Tanous                                                 aResp->res.jsonValue["UUID"] =
45304a258f4SEd Tanous                                                     valueStr;
454c5b2abe0SLewanczyk, Dawid                                             }
455c5b2abe0SLewanczyk, Dawid                                         }
456c5b2abe0SLewanczyk, Dawid                                     }
457c5b2abe0SLewanczyk, Dawid                                 },
45804a258f4SEd Tanous                                 connection.first, path,
4596c34de48SEd Tanous                                 "org.freedesktop.DBus.Properties", "GetAll",
4601abe55efSEd Tanous                                 "xyz.openbmc_project.Common.UUID");
461c5b2abe0SLewanczyk, Dawid                         }
462029573d4SEd Tanous                         else if (interfaceName ==
463029573d4SEd Tanous                                  "xyz.openbmc_project.Inventory.Item.System")
4641abe55efSEd Tanous                         {
465029573d4SEd Tanous                             crow::connections::systemBus->async_method_call(
466029573d4SEd Tanous                                 [aResp](const boost::system::error_code ec,
467029573d4SEd Tanous                                         const std::vector<
468029573d4SEd Tanous                                             std::pair<std::string, VariantType>>
469029573d4SEd Tanous                                             &propertiesList) {
470029573d4SEd Tanous                                     if (ec)
471029573d4SEd Tanous                                     {
472e4a4b9a9SJames Feist                                         // doesn't have to include this
473e4a4b9a9SJames Feist                                         // interface
474029573d4SEd Tanous                                         return;
475029573d4SEd Tanous                                     }
476698654b6SGunnar Mills                                     BMCWEB_LOG_DEBUG
477698654b6SGunnar Mills                                         << "Got " << propertiesList.size()
478029573d4SEd Tanous                                         << " properties for system";
479029573d4SEd Tanous                                     for (const std::pair<std::string,
480029573d4SEd Tanous                                                          VariantType>
481029573d4SEd Tanous                                              &property : propertiesList)
482029573d4SEd Tanous                                     {
483fc5afcf9Sbeccabroek                                         const std::string &propertyName =
484fc5afcf9Sbeccabroek                                             property.first;
485fc5afcf9Sbeccabroek                                         if ((propertyName == "PartNumber") ||
486fc5afcf9Sbeccabroek                                             (propertyName == "SerialNumber") ||
487fc5afcf9Sbeccabroek                                             (propertyName == "Manufacturer") ||
488fc5afcf9Sbeccabroek                                             (propertyName == "Model"))
489fc5afcf9Sbeccabroek                                         {
490029573d4SEd Tanous                                             const std::string *value =
491fc5afcf9Sbeccabroek                                                 std::get_if<std::string>(
492029573d4SEd Tanous                                                     &property.second);
493029573d4SEd Tanous                                             if (value != nullptr)
494029573d4SEd Tanous                                             {
495029573d4SEd Tanous                                                 aResp->res
496fc5afcf9Sbeccabroek                                                     .jsonValue[propertyName] =
497029573d4SEd Tanous                                                     *value;
498029573d4SEd Tanous                                             }
499029573d4SEd Tanous                                         }
500fc5afcf9Sbeccabroek                                     }
501029573d4SEd Tanous                                     aResp->res.jsonValue["Name"] = "system";
502029573d4SEd Tanous                                     aResp->res.jsonValue["Id"] =
503029573d4SEd Tanous                                         aResp->res.jsonValue["SerialNumber"];
504cb7e1e7bSAndrew Geissler                                     // Grab the bios version
505cb7e1e7bSAndrew Geissler                                     fw_util::getActiveFwVersion(
506cb7e1e7bSAndrew Geissler                                         aResp, fw_util::biosPurpose,
507cb7e1e7bSAndrew Geissler                                         "BiosVersion");
508029573d4SEd Tanous                                 },
509029573d4SEd Tanous                                 connection.first, path,
510029573d4SEd Tanous                                 "org.freedesktop.DBus.Properties", "GetAll",
511029573d4SEd Tanous                                 "xyz.openbmc_project.Inventory.Decorator."
512029573d4SEd Tanous                                 "Asset");
513e4a4b9a9SJames Feist 
514e4a4b9a9SJames Feist                             crow::connections::systemBus->async_method_call(
515e4a4b9a9SJames Feist                                 [aResp](
516e4a4b9a9SJames Feist                                     const boost::system::error_code ec,
517e4a4b9a9SJames Feist                                     const std::variant<std::string> &property) {
518e4a4b9a9SJames Feist                                     if (ec)
519e4a4b9a9SJames Feist                                     {
520e4a4b9a9SJames Feist                                         // doesn't have to include this
521e4a4b9a9SJames Feist                                         // interface
522e4a4b9a9SJames Feist                                         return;
523e4a4b9a9SJames Feist                                     }
524e4a4b9a9SJames Feist 
525e4a4b9a9SJames Feist                                     const std::string *value =
526e4a4b9a9SJames Feist                                         std::get_if<std::string>(&property);
527e4a4b9a9SJames Feist                                     if (value != nullptr)
528e4a4b9a9SJames Feist                                     {
529e4a4b9a9SJames Feist                                         aResp->res.jsonValue["AssetTag"] =
530e4a4b9a9SJames Feist                                             *value;
531e4a4b9a9SJames Feist                                     }
532e4a4b9a9SJames Feist                                 },
533e4a4b9a9SJames Feist                                 connection.first, path,
534e4a4b9a9SJames Feist                                 "org.freedesktop.DBus.Properties", "Get",
535e4a4b9a9SJames Feist                                 "xyz.openbmc_project.Inventory.Decorator."
536e4a4b9a9SJames Feist                                 "AssetTag",
537e4a4b9a9SJames Feist                                 "AssetTag");
538029573d4SEd Tanous                         }
539029573d4SEd Tanous                     }
540029573d4SEd Tanous                 }
541c5b2abe0SLewanczyk, Dawid             }
542c5b2abe0SLewanczyk, Dawid         },
543c5b2abe0SLewanczyk, Dawid         "xyz.openbmc_project.ObjectMapper",
544c5b2abe0SLewanczyk, Dawid         "/xyz/openbmc_project/object_mapper",
545c5b2abe0SLewanczyk, Dawid         "xyz.openbmc_project.ObjectMapper", "GetSubTree",
5466617338dSEd Tanous         "/xyz/openbmc_project/inventory", int32_t(0),
5476617338dSEd Tanous         std::array<const char *, 5>{
5486617338dSEd Tanous             "xyz.openbmc_project.Inventory.Decorator.Asset",
5496617338dSEd Tanous             "xyz.openbmc_project.Inventory.Item.Cpu",
5506617338dSEd Tanous             "xyz.openbmc_project.Inventory.Item.Dimm",
5516617338dSEd Tanous             "xyz.openbmc_project.Inventory.Item.System",
5526617338dSEd Tanous             "xyz.openbmc_project.Common.UUID",
5536617338dSEd Tanous         });
554c5b2abe0SLewanczyk, Dawid }
555c5b2abe0SLewanczyk, Dawid 
556c5b2abe0SLewanczyk, Dawid /**
557c5b2abe0SLewanczyk, Dawid  * @brief Retrieves identify led group properties over dbus
558c5b2abe0SLewanczyk, Dawid  *
559491d8ee7SSantosh Puranik  * @param[in] aResp     Shared pointer for generating response message.
560c5b2abe0SLewanczyk, Dawid  *
561c5b2abe0SLewanczyk, Dawid  * @return None.
562c5b2abe0SLewanczyk, Dawid  */
563*a3002228SAppaRao Puli void getIndicatorLedState(std::shared_ptr<AsyncResp> aResp)
5641abe55efSEd Tanous {
56555c7b7a2SEd Tanous     BMCWEB_LOG_DEBUG << "Get led groups";
56655c7b7a2SEd Tanous     crow::connections::systemBus->async_method_call(
567*a3002228SAppaRao Puli         [aResp](const boost::system::error_code ec,
568*a3002228SAppaRao Puli                 const std::variant<bool> asserted) {
5691abe55efSEd Tanous             if (ec)
5701abe55efSEd Tanous             {
57155c7b7a2SEd Tanous                 BMCWEB_LOG_DEBUG << "DBUS response error " << ec;
572f12894f8SJason M. Bills                 messages::internalError(aResp->res);
573c5b2abe0SLewanczyk, Dawid                 return;
574c5b2abe0SLewanczyk, Dawid             }
575*a3002228SAppaRao Puli 
576*a3002228SAppaRao Puli             const bool *blinking = std::get_if<bool>(&asserted);
577*a3002228SAppaRao Puli             if (!blinking)
5781abe55efSEd Tanous             {
579*a3002228SAppaRao Puli                 BMCWEB_LOG_DEBUG << "Get identity blinking LED failed";
580*a3002228SAppaRao Puli                 messages::internalError(aResp->res);
581*a3002228SAppaRao Puli                 return;
582*a3002228SAppaRao Puli             }
583*a3002228SAppaRao Puli             // Blinking ON, no need to check enclosure_identify assert.
584*a3002228SAppaRao Puli             if (*blinking)
5851abe55efSEd Tanous             {
586*a3002228SAppaRao Puli                 aResp->res.jsonValue["IndicatorLED"] = "Blinking";
587*a3002228SAppaRao Puli                 return;
588*a3002228SAppaRao Puli             }
589*a3002228SAppaRao Puli             crow::connections::systemBus->async_method_call(
590*a3002228SAppaRao Puli                 [aResp](const boost::system::error_code ec,
591*a3002228SAppaRao Puli                         const std::variant<bool> asserted) {
592*a3002228SAppaRao Puli                     if (ec)
5931abe55efSEd Tanous                     {
594*a3002228SAppaRao Puli                         BMCWEB_LOG_DEBUG << "DBUS response error " << ec;
595*a3002228SAppaRao Puli                         messages::internalError(aResp->res);
596*a3002228SAppaRao Puli                         return;
597*a3002228SAppaRao Puli                     }
598*a3002228SAppaRao Puli 
599*a3002228SAppaRao Puli                     const bool *ledOn = std::get_if<bool>(&asserted);
600*a3002228SAppaRao Puli                     if (!ledOn)
6011abe55efSEd Tanous                     {
602*a3002228SAppaRao Puli                         BMCWEB_LOG_DEBUG << "Get enclosure identity led failed";
603*a3002228SAppaRao Puli                         messages::internalError(aResp->res);
604*a3002228SAppaRao Puli                         return;
605*a3002228SAppaRao Puli                     }
606*a3002228SAppaRao Puli 
607*a3002228SAppaRao Puli                     if (*ledOn)
6081abe55efSEd Tanous                     {
609*a3002228SAppaRao Puli                         aResp->res.jsonValue["IndicatorLED"] = "Lit";
6101abe55efSEd Tanous                     }
6111abe55efSEd Tanous                     else
6121abe55efSEd Tanous                     {
613*a3002228SAppaRao Puli                         aResp->res.jsonValue["IndicatorLED"] = "Off";
614c5b2abe0SLewanczyk, Dawid                     }
615*a3002228SAppaRao Puli                     return;
616*a3002228SAppaRao Puli                 },
617*a3002228SAppaRao Puli                 "xyz.openbmc_project.LED.GroupManager",
618*a3002228SAppaRao Puli                 "/xyz/openbmc_project/led/groups/enclosure_identify",
619*a3002228SAppaRao Puli                 "org.freedesktop.DBus.Properties", "Get",
620*a3002228SAppaRao Puli                 "xyz.openbmc_project.Led.Group", "Asserted");
621*a3002228SAppaRao Puli         },
622*a3002228SAppaRao Puli         "xyz.openbmc_project.LED.GroupManager",
623*a3002228SAppaRao Puli         "/xyz/openbmc_project/led/groups/enclosure_identify_blink",
624*a3002228SAppaRao Puli         "org.freedesktop.DBus.Properties", "Get",
625*a3002228SAppaRao Puli         "xyz.openbmc_project.Led.Group", "Asserted");
626c5b2abe0SLewanczyk, Dawid }
627*a3002228SAppaRao Puli /**
628*a3002228SAppaRao Puli  * @brief Sets identify led group properties
629*a3002228SAppaRao Puli  *
630*a3002228SAppaRao Puli  * @param[in] aResp     Shared pointer for generating response message.
631*a3002228SAppaRao Puli  * @param[in] ledState  LED state passed from request
632*a3002228SAppaRao Puli  *
633*a3002228SAppaRao Puli  * @return None.
634*a3002228SAppaRao Puli  */
635*a3002228SAppaRao Puli void setIndicatorLedState(std::shared_ptr<AsyncResp> aResp,
636*a3002228SAppaRao Puli                           const std::string &ledState)
637*a3002228SAppaRao Puli {
638*a3002228SAppaRao Puli     BMCWEB_LOG_DEBUG << "Set led groups";
639*a3002228SAppaRao Puli     bool ledOn = false;
640*a3002228SAppaRao Puli     bool ledBlinkng = false;
641*a3002228SAppaRao Puli 
642*a3002228SAppaRao Puli     if (ledState == "Lit")
643*a3002228SAppaRao Puli     {
644*a3002228SAppaRao Puli         ledOn = true;
645c5b2abe0SLewanczyk, Dawid     }
646*a3002228SAppaRao Puli     else if (ledState == "Blinking")
647*a3002228SAppaRao Puli     {
648*a3002228SAppaRao Puli         ledBlinkng = true;
649c5b2abe0SLewanczyk, Dawid     }
650*a3002228SAppaRao Puli     else if (ledState != "Off")
651*a3002228SAppaRao Puli     {
652*a3002228SAppaRao Puli         messages::propertyValueNotInList(aResp->res, ledState, "IndicatorLED");
653*a3002228SAppaRao Puli         return;
654c5b2abe0SLewanczyk, Dawid     }
655*a3002228SAppaRao Puli 
656*a3002228SAppaRao Puli     crow::connections::systemBus->async_method_call(
657*a3002228SAppaRao Puli         [aResp](const boost::system::error_code ec,
658*a3002228SAppaRao Puli                 const std::variant<bool> asserted) {
659*a3002228SAppaRao Puli             if (ec)
660*a3002228SAppaRao Puli             {
661*a3002228SAppaRao Puli                 BMCWEB_LOG_DEBUG << "DBUS response error " << ec;
662*a3002228SAppaRao Puli                 messages::internalError(aResp->res);
663*a3002228SAppaRao Puli                 return;
664c5b2abe0SLewanczyk, Dawid             }
665c5b2abe0SLewanczyk, Dawid         },
666c5b2abe0SLewanczyk, Dawid         "xyz.openbmc_project.LED.GroupManager",
667*a3002228SAppaRao Puli         "/xyz/openbmc_project/led/groups/enclosure_identify",
668*a3002228SAppaRao Puli         "org.freedesktop.DBus.Properties", "Set",
669*a3002228SAppaRao Puli         "xyz.openbmc_project.Led.Group", "Asserted", std::variant<bool>(ledOn));
670*a3002228SAppaRao Puli 
671*a3002228SAppaRao Puli     crow::connections::systemBus->async_method_call(
672*a3002228SAppaRao Puli         [aResp](const boost::system::error_code ec,
673*a3002228SAppaRao Puli                 const std::variant<bool> asserted) {
674*a3002228SAppaRao Puli             if (ec)
675*a3002228SAppaRao Puli             {
676*a3002228SAppaRao Puli                 BMCWEB_LOG_DEBUG << "DBUS response error " << ec;
677*a3002228SAppaRao Puli                 messages::internalError(aResp->res);
678*a3002228SAppaRao Puli                 return;
679*a3002228SAppaRao Puli             }
680*a3002228SAppaRao Puli         },
681*a3002228SAppaRao Puli         "xyz.openbmc_project.LED.GroupManager",
682*a3002228SAppaRao Puli         "/xyz/openbmc_project/led/groups/enclosure_identify_blink",
683*a3002228SAppaRao Puli         "org.freedesktop.DBus.Properties", "Set",
684*a3002228SAppaRao Puli         "xyz.openbmc_project.Led.Group", "Asserted",
685*a3002228SAppaRao Puli         std::variant<bool>(ledBlinkng));
686c5b2abe0SLewanczyk, Dawid }
687c5b2abe0SLewanczyk, Dawid 
688c5b2abe0SLewanczyk, Dawid /**
689c5b2abe0SLewanczyk, Dawid  * @brief Retrieves host state properties over dbus
690c5b2abe0SLewanczyk, Dawid  *
691c5b2abe0SLewanczyk, Dawid  * @param[in] aResp     Shared pointer for completing asynchronous calls.
692c5b2abe0SLewanczyk, Dawid  *
693c5b2abe0SLewanczyk, Dawid  * @return None.
694c5b2abe0SLewanczyk, Dawid  */
695a0803efaSEd Tanous void getHostState(std::shared_ptr<AsyncResp> aResp)
6961abe55efSEd Tanous {
69755c7b7a2SEd Tanous     BMCWEB_LOG_DEBUG << "Get host information.";
69855c7b7a2SEd Tanous     crow::connections::systemBus->async_method_call(
699c5d03ff4SJennifer Lee         [aResp](const boost::system::error_code ec,
700abf2add6SEd Tanous                 const std::variant<std::string> &hostState) {
7011abe55efSEd Tanous             if (ec)
7021abe55efSEd Tanous             {
70355c7b7a2SEd Tanous                 BMCWEB_LOG_DEBUG << "DBUS response error " << ec;
704f12894f8SJason M. Bills                 messages::internalError(aResp->res);
705c5b2abe0SLewanczyk, Dawid                 return;
706c5b2abe0SLewanczyk, Dawid             }
7076617338dSEd Tanous 
708abf2add6SEd Tanous             const std::string *s = std::get_if<std::string>(&hostState);
70955c7b7a2SEd Tanous             BMCWEB_LOG_DEBUG << "Host state: " << *s;
7106617338dSEd Tanous             if (s != nullptr)
7111abe55efSEd Tanous             {
712c5b2abe0SLewanczyk, Dawid                 // Verify Host State
71394732661SAndrew Geissler                 if (*s == "xyz.openbmc_project.State.Host.HostState.Running")
7141abe55efSEd Tanous                 {
71555c7b7a2SEd Tanous                     aResp->res.jsonValue["PowerState"] = "On";
7166617338dSEd Tanous                     aResp->res.jsonValue["Status"]["State"] = "Enabled";
7171abe55efSEd Tanous                 }
7181abe55efSEd Tanous                 else
7191abe55efSEd Tanous                 {
72055c7b7a2SEd Tanous                     aResp->res.jsonValue["PowerState"] = "Off";
7216617338dSEd Tanous                     aResp->res.jsonValue["Status"]["State"] = "Disabled";
722c5b2abe0SLewanczyk, Dawid                 }
723c5b2abe0SLewanczyk, Dawid             }
724c5b2abe0SLewanczyk, Dawid         },
7256c34de48SEd Tanous         "xyz.openbmc_project.State.Host", "/xyz/openbmc_project/state/host0",
7266617338dSEd Tanous         "org.freedesktop.DBus.Properties", "Get",
7276617338dSEd Tanous         "xyz.openbmc_project.State.Host", "CurrentHostState");
728c5b2abe0SLewanczyk, Dawid }
729c5b2abe0SLewanczyk, Dawid 
730c5b2abe0SLewanczyk, Dawid /**
731491d8ee7SSantosh Puranik  * @brief Traslates boot source DBUS property value to redfish.
732491d8ee7SSantosh Puranik  *
733491d8ee7SSantosh Puranik  * @param[in] dbusSource    The boot source in DBUS speak.
734491d8ee7SSantosh Puranik  *
735491d8ee7SSantosh Puranik  * @return Returns as a string, the boot source in Redfish terms. If translation
736491d8ee7SSantosh Puranik  * cannot be done, returns an empty string.
737491d8ee7SSantosh Puranik  */
738491d8ee7SSantosh Puranik static std::string dbusToRfBootSource(const std::string &dbusSource)
739491d8ee7SSantosh Puranik {
740491d8ee7SSantosh Puranik     if (dbusSource == "xyz.openbmc_project.Control.Boot.Source.Sources.Default")
741491d8ee7SSantosh Puranik     {
742491d8ee7SSantosh Puranik         return "None";
743491d8ee7SSantosh Puranik     }
744491d8ee7SSantosh Puranik     else if (dbusSource ==
745491d8ee7SSantosh Puranik              "xyz.openbmc_project.Control.Boot.Source.Sources.Disk")
746491d8ee7SSantosh Puranik     {
747491d8ee7SSantosh Puranik         return "Hdd";
748491d8ee7SSantosh Puranik     }
749491d8ee7SSantosh Puranik     else if (dbusSource ==
750a71dc0b7SSantosh Puranik              "xyz.openbmc_project.Control.Boot.Source.Sources.ExternalMedia")
751491d8ee7SSantosh Puranik     {
752491d8ee7SSantosh Puranik         return "Cd";
753491d8ee7SSantosh Puranik     }
754491d8ee7SSantosh Puranik     else if (dbusSource ==
755491d8ee7SSantosh Puranik              "xyz.openbmc_project.Control.Boot.Source.Sources.Network")
756491d8ee7SSantosh Puranik     {
757491d8ee7SSantosh Puranik         return "Pxe";
758491d8ee7SSantosh Puranik     }
7599f16b2c1SJennifer Lee     else if (dbusSource ==
760944ffaf9SJohnathan Mantey              "xyz.openbmc_project.Control.Boot.Source.Sources.RemovableMedia")
7619f16b2c1SJennifer Lee     {
7629f16b2c1SJennifer Lee         return "Usb";
7639f16b2c1SJennifer Lee     }
764491d8ee7SSantosh Puranik     else
765491d8ee7SSantosh Puranik     {
766491d8ee7SSantosh Puranik         return "";
767491d8ee7SSantosh Puranik     }
768491d8ee7SSantosh Puranik }
769491d8ee7SSantosh Puranik 
770491d8ee7SSantosh Puranik /**
771491d8ee7SSantosh Puranik  * @brief Traslates boot mode DBUS property value to redfish.
772491d8ee7SSantosh Puranik  *
773491d8ee7SSantosh Puranik  * @param[in] dbusMode    The boot mode in DBUS speak.
774491d8ee7SSantosh Puranik  *
775491d8ee7SSantosh Puranik  * @return Returns as a string, the boot mode in Redfish terms. If translation
776491d8ee7SSantosh Puranik  * cannot be done, returns an empty string.
777491d8ee7SSantosh Puranik  */
778491d8ee7SSantosh Puranik static std::string dbusToRfBootMode(const std::string &dbusMode)
779491d8ee7SSantosh Puranik {
780491d8ee7SSantosh Puranik     if (dbusMode == "xyz.openbmc_project.Control.Boot.Mode.Modes.Regular")
781491d8ee7SSantosh Puranik     {
782491d8ee7SSantosh Puranik         return "None";
783491d8ee7SSantosh Puranik     }
784491d8ee7SSantosh Puranik     else if (dbusMode == "xyz.openbmc_project.Control.Boot.Mode.Modes.Safe")
785491d8ee7SSantosh Puranik     {
786491d8ee7SSantosh Puranik         return "Diags";
787491d8ee7SSantosh Puranik     }
788491d8ee7SSantosh Puranik     else if (dbusMode == "xyz.openbmc_project.Control.Boot.Mode.Modes.Setup")
789491d8ee7SSantosh Puranik     {
790491d8ee7SSantosh Puranik         return "BiosSetup";
791491d8ee7SSantosh Puranik     }
792491d8ee7SSantosh Puranik     else
793491d8ee7SSantosh Puranik     {
794491d8ee7SSantosh Puranik         return "";
795491d8ee7SSantosh Puranik     }
796491d8ee7SSantosh Puranik }
797491d8ee7SSantosh Puranik 
798491d8ee7SSantosh Puranik /**
799944ffaf9SJohnathan Mantey  * @brief Traslates boot source from Redfish to the DBus boot paths.
800491d8ee7SSantosh Puranik  *
801491d8ee7SSantosh Puranik  * @param[in] rfSource    The boot source in Redfish.
802944ffaf9SJohnathan Mantey  * @param[out] bootSource The DBus source
803944ffaf9SJohnathan Mantey  * @param[out] bootMode   the DBus boot mode
804491d8ee7SSantosh Puranik  *
805944ffaf9SJohnathan Mantey  * @return Integer error code.
806491d8ee7SSantosh Puranik  */
807944ffaf9SJohnathan Mantey static int assignBootParameters(std::shared_ptr<AsyncResp> aResp,
808944ffaf9SJohnathan Mantey                                 const std::string &rfSource,
809944ffaf9SJohnathan Mantey                                 std::string &bootSource, std::string &bootMode)
810491d8ee7SSantosh Puranik {
811944ffaf9SJohnathan Mantey     // The caller has initialized the bootSource and bootMode to:
812944ffaf9SJohnathan Mantey     // bootMode = "xyz.openbmc_project.Control.Boot.Mode.Modes.Regular";
813944ffaf9SJohnathan Mantey     // bootSource = "xyz.openbmc_project.Control.Boot.Source.Sources.Default";
814944ffaf9SJohnathan Mantey     // Only modify the bootSource/bootMode variable needed to achieve the
815944ffaf9SJohnathan Mantey     // desired boot action.
816944ffaf9SJohnathan Mantey 
817491d8ee7SSantosh Puranik     if (rfSource == "None")
818491d8ee7SSantosh Puranik     {
819944ffaf9SJohnathan Mantey         return 0;
820491d8ee7SSantosh Puranik     }
821491d8ee7SSantosh Puranik     else if (rfSource == "Pxe")
822491d8ee7SSantosh Puranik     {
823944ffaf9SJohnathan Mantey         bootSource = "xyz.openbmc_project.Control.Boot.Source.Sources.Network";
824944ffaf9SJohnathan Mantey     }
825944ffaf9SJohnathan Mantey     else if (rfSource == "Hdd")
826944ffaf9SJohnathan Mantey     {
827944ffaf9SJohnathan Mantey         bootSource = "xyz.openbmc_project.Control.Boot.Source.Sources.Disk";
828944ffaf9SJohnathan Mantey     }
829944ffaf9SJohnathan Mantey     else if (rfSource == "Diags")
830944ffaf9SJohnathan Mantey     {
831944ffaf9SJohnathan Mantey         bootMode = "xyz.openbmc_project.Control.Boot.Mode.Modes.Safe";
832944ffaf9SJohnathan Mantey     }
833944ffaf9SJohnathan Mantey     else if (rfSource == "Cd")
834944ffaf9SJohnathan Mantey     {
835944ffaf9SJohnathan Mantey         bootSource =
836944ffaf9SJohnathan Mantey             "xyz.openbmc_project.Control.Boot.Source.Sources.ExternalMedia";
837944ffaf9SJohnathan Mantey     }
838944ffaf9SJohnathan Mantey     else if (rfSource == "BiosSetup")
839944ffaf9SJohnathan Mantey     {
840944ffaf9SJohnathan Mantey         bootMode = "xyz.openbmc_project.Control.Boot.Mode.Modes.Setup";
841491d8ee7SSantosh Puranik     }
8429f16b2c1SJennifer Lee     else if (rfSource == "Usb")
8439f16b2c1SJennifer Lee     {
844944ffaf9SJohnathan Mantey         bootSource =
845944ffaf9SJohnathan Mantey             "xyz.openbmc_project.Control.Boot.Source.Sources.RemovableMedia";
8469f16b2c1SJennifer Lee     }
847491d8ee7SSantosh Puranik     else
848491d8ee7SSantosh Puranik     {
849944ffaf9SJohnathan Mantey         BMCWEB_LOG_DEBUG << "Invalid property value for "
850944ffaf9SJohnathan Mantey                             "BootSourceOverrideTarget: "
851944ffaf9SJohnathan Mantey                          << bootSource;
852944ffaf9SJohnathan Mantey         messages::propertyValueNotInList(aResp->res, rfSource,
853944ffaf9SJohnathan Mantey                                          "BootSourceTargetOverride");
854944ffaf9SJohnathan Mantey         return -1;
855491d8ee7SSantosh Puranik     }
856944ffaf9SJohnathan Mantey     return 0;
857491d8ee7SSantosh Puranik }
858491d8ee7SSantosh Puranik 
859491d8ee7SSantosh Puranik /**
860491d8ee7SSantosh Puranik  * @brief Retrieves boot mode over DBUS and fills out the response
861491d8ee7SSantosh Puranik  *
862491d8ee7SSantosh Puranik  * @param[in] aResp         Shared pointer for generating response message.
863491d8ee7SSantosh Puranik  * @param[in] bootDbusObj   The dbus object to query for boot properties.
864491d8ee7SSantosh Puranik  *
865491d8ee7SSantosh Puranik  * @return None.
866491d8ee7SSantosh Puranik  */
867491d8ee7SSantosh Puranik static void getBootMode(std::shared_ptr<AsyncResp> aResp,
868491d8ee7SSantosh Puranik                         std::string bootDbusObj)
869491d8ee7SSantosh Puranik {
870491d8ee7SSantosh Puranik     crow::connections::systemBus->async_method_call(
871491d8ee7SSantosh Puranik         [aResp](const boost::system::error_code ec,
872491d8ee7SSantosh Puranik                 const std::variant<std::string> &bootMode) {
873491d8ee7SSantosh Puranik             if (ec)
874491d8ee7SSantosh Puranik             {
875491d8ee7SSantosh Puranik                 BMCWEB_LOG_DEBUG << "DBUS response error " << ec;
876491d8ee7SSantosh Puranik                 messages::internalError(aResp->res);
877491d8ee7SSantosh Puranik                 return;
878491d8ee7SSantosh Puranik             }
879491d8ee7SSantosh Puranik 
880491d8ee7SSantosh Puranik             const std::string *bootModeStr =
881491d8ee7SSantosh Puranik                 std::get_if<std::string>(&bootMode);
882491d8ee7SSantosh Puranik 
883491d8ee7SSantosh Puranik             if (!bootModeStr)
884491d8ee7SSantosh Puranik             {
885491d8ee7SSantosh Puranik                 messages::internalError(aResp->res);
886491d8ee7SSantosh Puranik                 return;
887491d8ee7SSantosh Puranik             }
888491d8ee7SSantosh Puranik 
889491d8ee7SSantosh Puranik             BMCWEB_LOG_DEBUG << "Boot mode: " << *bootModeStr;
890491d8ee7SSantosh Puranik 
891491d8ee7SSantosh Puranik             // TODO (Santosh): Do we need to support override mode?
892491d8ee7SSantosh Puranik             aResp->res.jsonValue["Boot"]["BootSourceOverrideMode"] = "Legacy";
893491d8ee7SSantosh Puranik             aResp->res.jsonValue["Boot"]["BootSourceOverrideTarget@Redfish."
894491d8ee7SSantosh Puranik                                          "AllowableValues"] = {
895944ffaf9SJohnathan Mantey                 "None", "Pxe", "Hdd", "Cd", "Diags", "BiosSetup", "Usb"};
896491d8ee7SSantosh Puranik 
897491d8ee7SSantosh Puranik             if (*bootModeStr !=
898491d8ee7SSantosh Puranik                 "xyz.openbmc_project.Control.Boot.Mode.Modes.Regular")
899491d8ee7SSantosh Puranik             {
900491d8ee7SSantosh Puranik                 auto rfMode = dbusToRfBootMode(*bootModeStr);
901491d8ee7SSantosh Puranik                 if (!rfMode.empty())
902491d8ee7SSantosh Puranik                 {
903491d8ee7SSantosh Puranik                     aResp->res.jsonValue["Boot"]["BootSourceOverrideTarget"] =
904491d8ee7SSantosh Puranik                         rfMode;
905491d8ee7SSantosh Puranik                 }
906491d8ee7SSantosh Puranik             }
907491d8ee7SSantosh Puranik 
908491d8ee7SSantosh Puranik             // If the BootSourceOverrideTarget is still "None" at the end,
909491d8ee7SSantosh Puranik             // reset the BootSourceOverrideEnabled to indicate that
910491d8ee7SSantosh Puranik             // overrides are disabled
911491d8ee7SSantosh Puranik             if (aResp->res.jsonValue["Boot"]["BootSourceOverrideTarget"] ==
912491d8ee7SSantosh Puranik                 "None")
913491d8ee7SSantosh Puranik             {
914491d8ee7SSantosh Puranik                 aResp->res.jsonValue["Boot"]["BootSourceOverrideEnabled"] =
915491d8ee7SSantosh Puranik                     "Disabled";
916491d8ee7SSantosh Puranik             }
917491d8ee7SSantosh Puranik         },
918491d8ee7SSantosh Puranik         "xyz.openbmc_project.Settings", bootDbusObj,
919491d8ee7SSantosh Puranik         "org.freedesktop.DBus.Properties", "Get",
920491d8ee7SSantosh Puranik         "xyz.openbmc_project.Control.Boot.Mode", "BootMode");
921491d8ee7SSantosh Puranik }
922491d8ee7SSantosh Puranik 
923491d8ee7SSantosh Puranik /**
924491d8ee7SSantosh Puranik  * @brief Retrieves boot source over DBUS
925491d8ee7SSantosh Puranik  *
926491d8ee7SSantosh Puranik  * @param[in] aResp         Shared pointer for generating response message.
927491d8ee7SSantosh Puranik  * @param[in] oneTimeEnable Boolean to indicate boot properties are one-time.
928491d8ee7SSantosh Puranik  *
929491d8ee7SSantosh Puranik  * @return None.
930491d8ee7SSantosh Puranik  */
931491d8ee7SSantosh Puranik static void getBootSource(std::shared_ptr<AsyncResp> aResp, bool oneTimeEnabled)
932491d8ee7SSantosh Puranik {
933491d8ee7SSantosh Puranik     std::string bootDbusObj =
934491d8ee7SSantosh Puranik         oneTimeEnabled ? "/xyz/openbmc_project/control/host0/boot/one_time"
935491d8ee7SSantosh Puranik                        : "/xyz/openbmc_project/control/host0/boot";
936491d8ee7SSantosh Puranik 
937491d8ee7SSantosh Puranik     BMCWEB_LOG_DEBUG << "Is one time: " << oneTimeEnabled;
938491d8ee7SSantosh Puranik     aResp->res.jsonValue["Boot"]["BootSourceOverrideEnabled"] =
939491d8ee7SSantosh Puranik         (oneTimeEnabled) ? "Once" : "Continuous";
940491d8ee7SSantosh Puranik 
941491d8ee7SSantosh Puranik     crow::connections::systemBus->async_method_call(
942491d8ee7SSantosh Puranik         [aResp, bootDbusObj](const boost::system::error_code ec,
943491d8ee7SSantosh Puranik                              const std::variant<std::string> &bootSource) {
944491d8ee7SSantosh Puranik             if (ec)
945491d8ee7SSantosh Puranik             {
946491d8ee7SSantosh Puranik                 BMCWEB_LOG_DEBUG << "DBUS response error " << ec;
947491d8ee7SSantosh Puranik                 messages::internalError(aResp->res);
948491d8ee7SSantosh Puranik                 return;
949491d8ee7SSantosh Puranik             }
950491d8ee7SSantosh Puranik 
951491d8ee7SSantosh Puranik             const std::string *bootSourceStr =
952491d8ee7SSantosh Puranik                 std::get_if<std::string>(&bootSource);
953491d8ee7SSantosh Puranik 
954491d8ee7SSantosh Puranik             if (!bootSourceStr)
955491d8ee7SSantosh Puranik             {
956491d8ee7SSantosh Puranik                 messages::internalError(aResp->res);
957491d8ee7SSantosh Puranik                 return;
958491d8ee7SSantosh Puranik             }
959491d8ee7SSantosh Puranik             BMCWEB_LOG_DEBUG << "Boot source: " << *bootSourceStr;
960491d8ee7SSantosh Puranik 
961491d8ee7SSantosh Puranik             auto rfSource = dbusToRfBootSource(*bootSourceStr);
962491d8ee7SSantosh Puranik             if (!rfSource.empty())
963491d8ee7SSantosh Puranik             {
964491d8ee7SSantosh Puranik                 aResp->res.jsonValue["Boot"]["BootSourceOverrideTarget"] =
965491d8ee7SSantosh Puranik                     rfSource;
966491d8ee7SSantosh Puranik             }
967491d8ee7SSantosh Puranik         },
968491d8ee7SSantosh Puranik         "xyz.openbmc_project.Settings", bootDbusObj,
969491d8ee7SSantosh Puranik         "org.freedesktop.DBus.Properties", "Get",
970491d8ee7SSantosh Puranik         "xyz.openbmc_project.Control.Boot.Source", "BootSource");
971491d8ee7SSantosh Puranik     getBootMode(std::move(aResp), std::move(bootDbusObj));
972491d8ee7SSantosh Puranik }
973491d8ee7SSantosh Puranik 
974491d8ee7SSantosh Puranik /**
975491d8ee7SSantosh Puranik  * @brief Retrieves "One time" enabled setting over DBUS and calls function to
976491d8ee7SSantosh Puranik  * get boot source and boot mode.
977491d8ee7SSantosh Puranik  *
978491d8ee7SSantosh Puranik  * @param[in] aResp     Shared pointer for generating response message.
979491d8ee7SSantosh Puranik  *
980491d8ee7SSantosh Puranik  * @return None.
981491d8ee7SSantosh Puranik  */
982491d8ee7SSantosh Puranik static void getBootProperties(std::shared_ptr<AsyncResp> aResp)
983491d8ee7SSantosh Puranik {
984491d8ee7SSantosh Puranik     BMCWEB_LOG_DEBUG << "Get boot information.";
985491d8ee7SSantosh Puranik 
986491d8ee7SSantosh Puranik     crow::connections::systemBus->async_method_call(
987c5d03ff4SJennifer Lee         [aResp](const boost::system::error_code ec,
988491d8ee7SSantosh Puranik                 const sdbusplus::message::variant<bool> &oneTime) {
989491d8ee7SSantosh Puranik             if (ec)
990491d8ee7SSantosh Puranik             {
991491d8ee7SSantosh Puranik                 BMCWEB_LOG_DEBUG << "DBUS response error " << ec;
9922a833c77SJames Feist                 // not an error, don't have to have the interface
993491d8ee7SSantosh Puranik                 return;
994491d8ee7SSantosh Puranik             }
995491d8ee7SSantosh Puranik 
996491d8ee7SSantosh Puranik             const bool *oneTimePtr = std::get_if<bool>(&oneTime);
997491d8ee7SSantosh Puranik 
998491d8ee7SSantosh Puranik             if (!oneTimePtr)
999491d8ee7SSantosh Puranik             {
1000491d8ee7SSantosh Puranik                 messages::internalError(aResp->res);
1001491d8ee7SSantosh Puranik                 return;
1002491d8ee7SSantosh Puranik             }
1003491d8ee7SSantosh Puranik             getBootSource(aResp, *oneTimePtr);
1004491d8ee7SSantosh Puranik         },
1005491d8ee7SSantosh Puranik         "xyz.openbmc_project.Settings",
1006491d8ee7SSantosh Puranik         "/xyz/openbmc_project/control/host0/boot/one_time",
1007491d8ee7SSantosh Puranik         "org.freedesktop.DBus.Properties", "Get",
1008491d8ee7SSantosh Puranik         "xyz.openbmc_project.Object.Enable", "Enabled");
1009491d8ee7SSantosh Puranik }
1010491d8ee7SSantosh Puranik 
1011491d8ee7SSantosh Puranik /**
1012491d8ee7SSantosh Puranik  * @brief Sets boot properties into DBUS object(s).
1013491d8ee7SSantosh Puranik  *
1014491d8ee7SSantosh Puranik  * @param[in] aResp           Shared pointer for generating response message.
1015491d8ee7SSantosh Puranik  * @param[in] oneTimeEnabled  Is "one-time" setting already enabled.
1016491d8ee7SSantosh Puranik  * @param[in] bootSource      The boot source to set.
1017491d8ee7SSantosh Puranik  * @param[in] bootEnable      The source override "enable" to set.
1018491d8ee7SSantosh Puranik  *
1019265c1602SJohnathan Mantey  * @return Integer error code.
1020491d8ee7SSantosh Puranik  */
1021491d8ee7SSantosh Puranik static void setBootModeOrSource(std::shared_ptr<AsyncResp> aResp,
1022491d8ee7SSantosh Puranik                                 bool oneTimeEnabled,
1023491d8ee7SSantosh Puranik                                 std::optional<std::string> bootSource,
1024491d8ee7SSantosh Puranik                                 std::optional<std::string> bootEnable)
1025491d8ee7SSantosh Puranik {
1026944ffaf9SJohnathan Mantey     std::string bootSourceStr =
1027944ffaf9SJohnathan Mantey         "xyz.openbmc_project.Control.Boot.Source.Sources.Default";
1028944ffaf9SJohnathan Mantey     std::string bootModeStr =
1029944ffaf9SJohnathan Mantey         "xyz.openbmc_project.Control.Boot.Mode.Modes.Regular";
1030491d8ee7SSantosh Puranik     bool oneTimeSetting = oneTimeEnabled;
1031944ffaf9SJohnathan Mantey     bool useBootSource = true;
1032944ffaf9SJohnathan Mantey 
1033491d8ee7SSantosh Puranik     // Validate incoming parameters
1034491d8ee7SSantosh Puranik     if (bootEnable)
1035491d8ee7SSantosh Puranik     {
1036491d8ee7SSantosh Puranik         if (*bootEnable == "Once")
1037491d8ee7SSantosh Puranik         {
1038491d8ee7SSantosh Puranik             oneTimeSetting = true;
1039491d8ee7SSantosh Puranik         }
1040491d8ee7SSantosh Puranik         else if (*bootEnable == "Continuous")
1041491d8ee7SSantosh Puranik         {
1042491d8ee7SSantosh Puranik             oneTimeSetting = false;
1043491d8ee7SSantosh Puranik         }
1044491d8ee7SSantosh Puranik         else if (*bootEnable == "Disabled")
1045491d8ee7SSantosh Puranik         {
1046944ffaf9SJohnathan Mantey             BMCWEB_LOG_DEBUG << "Boot source override will be disabled";
1047491d8ee7SSantosh Puranik             oneTimeSetting = false;
1048944ffaf9SJohnathan Mantey             useBootSource = false;
1049491d8ee7SSantosh Puranik         }
1050491d8ee7SSantosh Puranik         else
1051491d8ee7SSantosh Puranik         {
1052491d8ee7SSantosh Puranik             BMCWEB_LOG_DEBUG << "Unsupported value for "
1053491d8ee7SSantosh Puranik                                 "BootSourceOverrideEnabled: "
1054491d8ee7SSantosh Puranik                              << *bootEnable;
1055491d8ee7SSantosh Puranik             messages::propertyValueNotInList(aResp->res, *bootEnable,
1056491d8ee7SSantosh Puranik                                              "BootSourceOverrideEnabled");
1057491d8ee7SSantosh Puranik             return;
1058491d8ee7SSantosh Puranik         }
1059491d8ee7SSantosh Puranik     }
1060491d8ee7SSantosh Puranik 
1061944ffaf9SJohnathan Mantey     if (bootSource && useBootSource)
1062491d8ee7SSantosh Puranik     {
1063491d8ee7SSantosh Puranik         // Source target specified
1064491d8ee7SSantosh Puranik         BMCWEB_LOG_DEBUG << "Boot source: " << *bootSource;
1065491d8ee7SSantosh Puranik         // Figure out which DBUS interface and property to use
1066944ffaf9SJohnathan Mantey         if (assignBootParameters(aResp, *bootSource, bootSourceStr,
1067944ffaf9SJohnathan Mantey                                  bootModeStr))
1068491d8ee7SSantosh Puranik         {
1069944ffaf9SJohnathan Mantey             BMCWEB_LOG_DEBUG
1070944ffaf9SJohnathan Mantey                 << "Invalid property value for BootSourceOverrideTarget: "
1071491d8ee7SSantosh Puranik                 << *bootSource;
1072491d8ee7SSantosh Puranik             messages::propertyValueNotInList(aResp->res, *bootSource,
1073491d8ee7SSantosh Puranik                                              "BootSourceTargetOverride");
1074491d8ee7SSantosh Puranik             return;
1075491d8ee7SSantosh Puranik         }
1076944ffaf9SJohnathan Mantey     }
1077491d8ee7SSantosh Puranik 
1078944ffaf9SJohnathan Mantey     // Act on validated parameters
1079944ffaf9SJohnathan Mantey     BMCWEB_LOG_DEBUG << "DBUS boot source: " << bootSourceStr;
1080944ffaf9SJohnathan Mantey     BMCWEB_LOG_DEBUG << "DBUS boot mode: " << bootModeStr;
1081944ffaf9SJohnathan Mantey     const char *bootObj =
1082944ffaf9SJohnathan Mantey         oneTimeSetting ? "/xyz/openbmc_project/control/host0/boot/one_time"
1083944ffaf9SJohnathan Mantey                        : "/xyz/openbmc_project/control/host0/boot";
1084944ffaf9SJohnathan Mantey 
1085491d8ee7SSantosh Puranik     crow::connections::systemBus->async_method_call(
1086491d8ee7SSantosh Puranik         [aResp](const boost::system::error_code ec) {
1087491d8ee7SSantosh Puranik             if (ec)
1088491d8ee7SSantosh Puranik             {
1089491d8ee7SSantosh Puranik                 BMCWEB_LOG_DEBUG << "DBUS response error " << ec;
1090491d8ee7SSantosh Puranik                 messages::internalError(aResp->res);
1091491d8ee7SSantosh Puranik                 return;
1092491d8ee7SSantosh Puranik             }
1093491d8ee7SSantosh Puranik             BMCWEB_LOG_DEBUG << "Boot source update done.";
1094491d8ee7SSantosh Puranik         },
1095491d8ee7SSantosh Puranik         "xyz.openbmc_project.Settings", bootObj,
1096491d8ee7SSantosh Puranik         "org.freedesktop.DBus.Properties", "Set",
1097491d8ee7SSantosh Puranik         "xyz.openbmc_project.Control.Boot.Source", "BootSource",
1098491d8ee7SSantosh Puranik         std::variant<std::string>(bootSourceStr));
1099944ffaf9SJohnathan Mantey 
1100491d8ee7SSantosh Puranik     crow::connections::systemBus->async_method_call(
1101491d8ee7SSantosh Puranik         [aResp](const boost::system::error_code ec) {
1102491d8ee7SSantosh Puranik             if (ec)
1103491d8ee7SSantosh Puranik             {
1104491d8ee7SSantosh Puranik                 BMCWEB_LOG_DEBUG << "DBUS response error " << ec;
1105491d8ee7SSantosh Puranik                 messages::internalError(aResp->res);
1106491d8ee7SSantosh Puranik                 return;
1107491d8ee7SSantosh Puranik             }
1108491d8ee7SSantosh Puranik             BMCWEB_LOG_DEBUG << "Boot mode update done.";
1109491d8ee7SSantosh Puranik         },
1110491d8ee7SSantosh Puranik         "xyz.openbmc_project.Settings", bootObj,
1111491d8ee7SSantosh Puranik         "org.freedesktop.DBus.Properties", "Set",
1112491d8ee7SSantosh Puranik         "xyz.openbmc_project.Control.Boot.Mode", "BootMode",
1113491d8ee7SSantosh Puranik         std::variant<std::string>(bootModeStr));
1114944ffaf9SJohnathan Mantey 
1115491d8ee7SSantosh Puranik     crow::connections::systemBus->async_method_call(
1116491d8ee7SSantosh Puranik         [aResp{std::move(aResp)}](const boost::system::error_code ec) {
1117491d8ee7SSantosh Puranik             if (ec)
1118491d8ee7SSantosh Puranik             {
1119491d8ee7SSantosh Puranik                 BMCWEB_LOG_DEBUG << "DBUS response error " << ec;
1120491d8ee7SSantosh Puranik                 messages::internalError(aResp->res);
1121491d8ee7SSantosh Puranik                 return;
1122491d8ee7SSantosh Puranik             }
1123491d8ee7SSantosh Puranik             BMCWEB_LOG_DEBUG << "Boot enable update done.";
1124491d8ee7SSantosh Puranik         },
1125491d8ee7SSantosh Puranik         "xyz.openbmc_project.Settings",
1126491d8ee7SSantosh Puranik         "/xyz/openbmc_project/control/host0/boot/one_time",
1127491d8ee7SSantosh Puranik         "org.freedesktop.DBus.Properties", "Set",
1128491d8ee7SSantosh Puranik         "xyz.openbmc_project.Object.Enable", "Enabled",
1129491d8ee7SSantosh Puranik         std::variant<bool>(oneTimeSetting));
1130491d8ee7SSantosh Puranik }
1131491d8ee7SSantosh Puranik 
1132491d8ee7SSantosh Puranik /**
1133491d8ee7SSantosh Puranik  * @brief Retrieves "One time" enabled setting over DBUS and calls function to
1134491d8ee7SSantosh Puranik  * set boot source/boot mode properties.
1135491d8ee7SSantosh Puranik  *
1136491d8ee7SSantosh Puranik  * @param[in] aResp      Shared pointer for generating response message.
1137491d8ee7SSantosh Puranik  * @param[in] bootSource The boot source from incoming RF request.
1138491d8ee7SSantosh Puranik  * @param[in] bootEnable The boot override enable from incoming RF request.
1139491d8ee7SSantosh Puranik  *
1140265c1602SJohnathan Mantey  * @return Integer error code.
1141491d8ee7SSantosh Puranik  */
1142491d8ee7SSantosh Puranik static void setBootProperties(std::shared_ptr<AsyncResp> aResp,
1143491d8ee7SSantosh Puranik                               std::optional<std::string> bootSource,
1144491d8ee7SSantosh Puranik                               std::optional<std::string> bootEnable)
1145491d8ee7SSantosh Puranik {
1146491d8ee7SSantosh Puranik     BMCWEB_LOG_DEBUG << "Set boot information.";
1147491d8ee7SSantosh Puranik 
1148491d8ee7SSantosh Puranik     crow::connections::systemBus->async_method_call(
1149265c1602SJohnathan Mantey         [aResp, bootSource{std::move(bootSource)},
1150491d8ee7SSantosh Puranik          bootEnable{std::move(bootEnable)}](
1151491d8ee7SSantosh Puranik             const boost::system::error_code ec,
1152491d8ee7SSantosh Puranik             const sdbusplus::message::variant<bool> &oneTime) {
1153491d8ee7SSantosh Puranik             if (ec)
1154491d8ee7SSantosh Puranik             {
1155491d8ee7SSantosh Puranik                 BMCWEB_LOG_DEBUG << "DBUS response error " << ec;
1156491d8ee7SSantosh Puranik                 messages::internalError(aResp->res);
1157491d8ee7SSantosh Puranik                 return;
1158491d8ee7SSantosh Puranik             }
1159491d8ee7SSantosh Puranik 
1160491d8ee7SSantosh Puranik             const bool *oneTimePtr = std::get_if<bool>(&oneTime);
1161491d8ee7SSantosh Puranik 
1162491d8ee7SSantosh Puranik             if (!oneTimePtr)
1163491d8ee7SSantosh Puranik             {
1164491d8ee7SSantosh Puranik                 messages::internalError(aResp->res);
1165491d8ee7SSantosh Puranik                 return;
1166491d8ee7SSantosh Puranik             }
1167491d8ee7SSantosh Puranik 
1168491d8ee7SSantosh Puranik             BMCWEB_LOG_DEBUG << "Got one time: " << *oneTimePtr;
1169491d8ee7SSantosh Puranik 
1170491d8ee7SSantosh Puranik             setBootModeOrSource(aResp, *oneTimePtr, std::move(bootSource),
1171491d8ee7SSantosh Puranik                                 std::move(bootEnable));
1172491d8ee7SSantosh Puranik         },
1173491d8ee7SSantosh Puranik         "xyz.openbmc_project.Settings",
1174491d8ee7SSantosh Puranik         "/xyz/openbmc_project/control/host0/boot/one_time",
1175491d8ee7SSantosh Puranik         "org.freedesktop.DBus.Properties", "Get",
1176491d8ee7SSantosh Puranik         "xyz.openbmc_project.Object.Enable", "Enabled");
1177491d8ee7SSantosh Puranik }
1178491d8ee7SSantosh Puranik 
1179a6349918SAppaRao Puli #ifdef BMCWEB_ENABLE_REDFISH_PROVISIONING_FEATURE
1180a6349918SAppaRao Puli /**
1181a6349918SAppaRao Puli  * @brief Retrieves provisioning status
1182a6349918SAppaRao Puli  *
1183a6349918SAppaRao Puli  * @param[in] aResp     Shared pointer for completing asynchronous calls.
1184a6349918SAppaRao Puli  *
1185a6349918SAppaRao Puli  * @return None.
1186a6349918SAppaRao Puli  */
1187a6349918SAppaRao Puli void getProvisioningStatus(std::shared_ptr<AsyncResp> aResp)
1188a6349918SAppaRao Puli {
1189a6349918SAppaRao Puli     BMCWEB_LOG_DEBUG << "Get OEM information.";
1190a6349918SAppaRao Puli     crow::connections::systemBus->async_method_call(
1191a6349918SAppaRao Puli         [aResp](const boost::system::error_code ec,
1192a6349918SAppaRao Puli                 const std::vector<std::pair<std::string, VariantType>>
1193a6349918SAppaRao Puli                     &propertiesList) {
1194a6349918SAppaRao Puli             if (ec)
1195a6349918SAppaRao Puli             {
1196a6349918SAppaRao Puli                 BMCWEB_LOG_DEBUG << "DBUS response error " << ec;
1197a6349918SAppaRao Puli                 messages::internalError(aResp->res);
1198a6349918SAppaRao Puli                 return;
1199a6349918SAppaRao Puli             }
1200a6349918SAppaRao Puli 
1201a6349918SAppaRao Puli             const bool *provState = nullptr;
1202a6349918SAppaRao Puli             const bool *lockState = nullptr;
1203a6349918SAppaRao Puli             for (const std::pair<std::string, VariantType> &property :
1204a6349918SAppaRao Puli                  propertiesList)
1205a6349918SAppaRao Puli             {
1206a6349918SAppaRao Puli                 if (property.first == "UfmProvisioned")
1207a6349918SAppaRao Puli                 {
1208a6349918SAppaRao Puli                     provState = std::get_if<bool>(&property.second);
1209a6349918SAppaRao Puli                 }
1210a6349918SAppaRao Puli                 else if (property.first == "UfmLocked")
1211a6349918SAppaRao Puli                 {
1212a6349918SAppaRao Puli                     lockState = std::get_if<bool>(&property.second);
1213a6349918SAppaRao Puli                 }
1214a6349918SAppaRao Puli             }
1215a6349918SAppaRao Puli 
1216a6349918SAppaRao Puli             if ((provState == nullptr) || (lockState == nullptr))
1217a6349918SAppaRao Puli             {
1218a6349918SAppaRao Puli                 BMCWEB_LOG_DEBUG << "Unable to get PFR attributes.";
1219a6349918SAppaRao Puli                 messages::internalError(aResp->res);
1220a6349918SAppaRao Puli                 return;
1221a6349918SAppaRao Puli             }
1222a6349918SAppaRao Puli 
1223a6349918SAppaRao Puli             nlohmann::json &oemPFR =
1224a6349918SAppaRao Puli                 aResp->res.jsonValue["Oem"]["OpenBmc"]["FirmwareProvisioning"];
1225a6349918SAppaRao Puli             if (*provState == true)
1226a6349918SAppaRao Puli             {
1227a6349918SAppaRao Puli                 if (*lockState == true)
1228a6349918SAppaRao Puli                 {
1229a6349918SAppaRao Puli                     oemPFR["ProvisioningStatus"] = "ProvisionedAndLocked";
1230a6349918SAppaRao Puli                 }
1231a6349918SAppaRao Puli                 else
1232a6349918SAppaRao Puli                 {
1233a6349918SAppaRao Puli                     oemPFR["ProvisioningStatus"] = "ProvisionedButNotLocked";
1234a6349918SAppaRao Puli                 }
1235a6349918SAppaRao Puli             }
1236a6349918SAppaRao Puli             else
1237a6349918SAppaRao Puli             {
1238a6349918SAppaRao Puli                 oemPFR["ProvisioningStatus"] = "NotProvisioned";
1239a6349918SAppaRao Puli             }
1240a6349918SAppaRao Puli         },
1241a6349918SAppaRao Puli         "xyz.openbmc_project.PFR.Manager", "/xyz/openbmc_project/pfr",
1242a6349918SAppaRao Puli         "org.freedesktop.DBus.Properties", "GetAll",
1243a6349918SAppaRao Puli         "xyz.openbmc_project.PFR.Attributes");
1244a6349918SAppaRao Puli }
1245a6349918SAppaRao Puli #endif
1246a6349918SAppaRao Puli 
1247491d8ee7SSantosh Puranik /**
124851709ffdSYong Li  * @brief Translates watchdog timeout action DBUS property value to redfish.
124951709ffdSYong Li  *
125051709ffdSYong Li  * @param[in] dbusAction    The watchdog timeout action in D-BUS.
125151709ffdSYong Li  *
125251709ffdSYong Li  * @return Returns as a string, the timeout action in Redfish terms. If
125351709ffdSYong Li  * translation cannot be done, returns an empty string.
125451709ffdSYong Li  */
125551709ffdSYong Li static std::string dbusToRfWatchdogAction(const std::string &dbusAction)
125651709ffdSYong Li {
125751709ffdSYong Li     if (dbusAction == "xyz.openbmc_project.State.Watchdog.Action.None")
125851709ffdSYong Li     {
125951709ffdSYong Li         return "None";
126051709ffdSYong Li     }
126151709ffdSYong Li     else if (dbusAction ==
126251709ffdSYong Li              "xyz.openbmc_project.State.Watchdog.Action.HardReset")
126351709ffdSYong Li     {
126451709ffdSYong Li         return "ResetSystem";
126551709ffdSYong Li     }
126651709ffdSYong Li     else if (dbusAction == "xyz.openbmc_project.State.Watchdog.Action.PowerOff")
126751709ffdSYong Li     {
126851709ffdSYong Li         return "PowerDown";
126951709ffdSYong Li     }
127051709ffdSYong Li     else if (dbusAction ==
127151709ffdSYong Li              "xyz.openbmc_project.State.Watchdog.Action.PowerCycle")
127251709ffdSYong Li     {
127351709ffdSYong Li         return "PowerCycle";
127451709ffdSYong Li     }
127551709ffdSYong Li 
127651709ffdSYong Li     return "";
127751709ffdSYong Li }
127851709ffdSYong Li 
127951709ffdSYong Li /**
1280c45f0082SYong Li  *@brief Translates timeout action from Redfish to DBUS property value.
1281c45f0082SYong Li  *
1282c45f0082SYong Li  *@param[in] rfAction The timeout action in Redfish.
1283c45f0082SYong Li  *
1284c45f0082SYong Li  *@return Returns as a string, the time_out action as expected by DBUS.
1285c45f0082SYong Li  *If translation cannot be done, returns an empty string.
1286c45f0082SYong Li  */
1287c45f0082SYong Li 
1288c45f0082SYong Li static std::string rfToDbusWDTTimeOutAct(const std::string &rfAction)
1289c45f0082SYong Li {
1290c45f0082SYong Li     if (rfAction == "None")
1291c45f0082SYong Li     {
1292c45f0082SYong Li         return "xyz.openbmc_project.State.Watchdog.Action.None";
1293c45f0082SYong Li     }
1294c45f0082SYong Li     else if (rfAction == "PowerCycle")
1295c45f0082SYong Li     {
1296c45f0082SYong Li         return "xyz.openbmc_project.State.Watchdog.Action.PowerCycle";
1297c45f0082SYong Li     }
1298c45f0082SYong Li     else if (rfAction == "PowerDown")
1299c45f0082SYong Li     {
1300c45f0082SYong Li         return "xyz.openbmc_project.State.Watchdog.Action.PowerOff";
1301c45f0082SYong Li     }
1302c45f0082SYong Li     else if (rfAction == "ResetSystem")
1303c45f0082SYong Li     {
1304c45f0082SYong Li         return "xyz.openbmc_project.State.Watchdog.Action.HardReset";
1305c45f0082SYong Li     }
1306c45f0082SYong Li 
1307c45f0082SYong Li     return "";
1308c45f0082SYong Li }
1309c45f0082SYong Li 
1310c45f0082SYong Li /**
131151709ffdSYong Li  * @brief Retrieves host watchdog timer properties over DBUS
131251709ffdSYong Li  *
131351709ffdSYong Li  * @param[in] aResp     Shared pointer for completing asynchronous calls.
131451709ffdSYong Li  *
131551709ffdSYong Li  * @return None.
131651709ffdSYong Li  */
131751709ffdSYong Li void getHostWatchdogTimer(std::shared_ptr<AsyncResp> aResp)
131851709ffdSYong Li {
131951709ffdSYong Li     BMCWEB_LOG_DEBUG << "Get host watchodg";
132051709ffdSYong Li     crow::connections::systemBus->async_method_call(
132151709ffdSYong Li         [aResp](const boost::system::error_code ec,
132251709ffdSYong Li                 PropertiesType &properties) {
132351709ffdSYong Li             if (ec)
132451709ffdSYong Li             {
132551709ffdSYong Li                 // watchdog service is stopped
132651709ffdSYong Li                 BMCWEB_LOG_DEBUG << "DBUS response error " << ec;
132751709ffdSYong Li                 return;
132851709ffdSYong Li             }
132951709ffdSYong Li 
133051709ffdSYong Li             BMCWEB_LOG_DEBUG << "Got " << properties.size() << " wdt prop.";
133151709ffdSYong Li 
133251709ffdSYong Li             nlohmann::json &hostWatchdogTimer =
133351709ffdSYong Li                 aResp->res.jsonValue["HostWatchdogTimer"];
133451709ffdSYong Li 
133551709ffdSYong Li             // watchdog service is running/enabled
133651709ffdSYong Li             hostWatchdogTimer["Status"]["State"] = "Enabled";
133751709ffdSYong Li 
133851709ffdSYong Li             for (const auto &property : properties)
133951709ffdSYong Li             {
134051709ffdSYong Li                 BMCWEB_LOG_DEBUG << "prop=" << property.first;
134151709ffdSYong Li                 if (property.first == "Enabled")
134251709ffdSYong Li                 {
134351709ffdSYong Li                     const bool *state = std::get_if<bool>(&property.second);
134451709ffdSYong Li 
134551709ffdSYong Li                     if (!state)
134651709ffdSYong Li                     {
134751709ffdSYong Li                         messages::internalError(aResp->res);
134851709ffdSYong Li                         continue;
134951709ffdSYong Li                     }
135051709ffdSYong Li 
135151709ffdSYong Li                     hostWatchdogTimer["FunctionEnabled"] = *state;
135251709ffdSYong Li                 }
135351709ffdSYong Li                 else if (property.first == "ExpireAction")
135451709ffdSYong Li                 {
135551709ffdSYong Li                     const std::string *s =
135651709ffdSYong Li                         std::get_if<std::string>(&property.second);
135751709ffdSYong Li                     if (!s)
135851709ffdSYong Li                     {
135951709ffdSYong Li                         messages::internalError(aResp->res);
136051709ffdSYong Li                         continue;
136151709ffdSYong Li                     }
136251709ffdSYong Li 
136351709ffdSYong Li                     std::string action = dbusToRfWatchdogAction(*s);
136451709ffdSYong Li                     if (action.empty())
136551709ffdSYong Li                     {
136651709ffdSYong Li                         messages::internalError(aResp->res);
136751709ffdSYong Li                         continue;
136851709ffdSYong Li                     }
136951709ffdSYong Li                     hostWatchdogTimer["TimeoutAction"] = action;
137051709ffdSYong Li                 }
137151709ffdSYong Li             }
137251709ffdSYong Li         },
137351709ffdSYong Li         "xyz.openbmc_project.Watchdog", "/xyz/openbmc_project/watchdog/host0",
137451709ffdSYong Li         "org.freedesktop.DBus.Properties", "GetAll",
137551709ffdSYong Li         "xyz.openbmc_project.State.Watchdog");
137651709ffdSYong Li }
137751709ffdSYong Li 
137851709ffdSYong Li /**
1379c45f0082SYong Li  * @brief Sets Host WatchDog Timer properties.
1380c45f0082SYong Li  *
1381c45f0082SYong Li  * @param[in] aResp      Shared pointer for generating response message.
1382c45f0082SYong Li  * @param[in] wdtEnable  The WDTimer Enable value (true/false) from incoming
1383c45f0082SYong Li  *                       RF request.
1384c45f0082SYong Li  * @param[in] wdtTimeOutAction The WDT Timeout action, from incoming RF request.
1385c45f0082SYong Li  *
1386c45f0082SYong Li  * @return None.
1387c45f0082SYong Li  */
1388c45f0082SYong Li static void setWDTProperties(std::shared_ptr<AsyncResp> aResp,
1389c45f0082SYong Li                              const std::optional<bool> wdtEnable,
1390c45f0082SYong Li                              const std::optional<std::string> &wdtTimeOutAction)
1391c45f0082SYong Li {
1392c45f0082SYong Li     BMCWEB_LOG_DEBUG << "Set host watchdog";
1393c45f0082SYong Li 
1394c45f0082SYong Li     if (wdtTimeOutAction)
1395c45f0082SYong Li     {
1396c45f0082SYong Li         std::string wdtTimeOutActStr = rfToDbusWDTTimeOutAct(*wdtTimeOutAction);
1397c45f0082SYong Li         // check if TimeOut Action is Valid
1398c45f0082SYong Li         if (wdtTimeOutActStr.empty())
1399c45f0082SYong Li         {
1400c45f0082SYong Li             BMCWEB_LOG_DEBUG << "Unsupported value for TimeoutAction: "
1401c45f0082SYong Li                              << *wdtTimeOutAction;
1402c45f0082SYong Li             messages::propertyValueNotInList(aResp->res, *wdtTimeOutAction,
1403c45f0082SYong Li                                              "TimeoutAction");
1404c45f0082SYong Li             return;
1405c45f0082SYong Li         }
1406c45f0082SYong Li 
1407c45f0082SYong Li         crow::connections::systemBus->async_method_call(
1408c45f0082SYong Li             [aResp](const boost::system::error_code ec) {
1409c45f0082SYong Li                 if (ec)
1410c45f0082SYong Li                 {
1411c45f0082SYong Li                     BMCWEB_LOG_DEBUG << "DBUS response error " << ec;
1412c45f0082SYong Li                     messages::internalError(aResp->res);
1413c45f0082SYong Li                     return;
1414c45f0082SYong Li                 }
1415c45f0082SYong Li             },
1416c45f0082SYong Li             "xyz.openbmc_project.Watchdog",
1417c45f0082SYong Li             "/xyz/openbmc_project/watchdog/host0",
1418c45f0082SYong Li             "org.freedesktop.DBus.Properties", "Set",
1419c45f0082SYong Li             "xyz.openbmc_project.State.Watchdog", "ExpireAction",
1420c45f0082SYong Li             std::variant<std::string>(wdtTimeOutActStr));
1421c45f0082SYong Li     }
1422c45f0082SYong Li 
1423c45f0082SYong Li     if (wdtEnable)
1424c45f0082SYong Li     {
1425c45f0082SYong Li         crow::connections::systemBus->async_method_call(
1426c45f0082SYong Li             [aResp](const boost::system::error_code ec) {
1427c45f0082SYong Li                 if (ec)
1428c45f0082SYong Li                 {
1429c45f0082SYong Li                     BMCWEB_LOG_DEBUG << "DBUS response error " << ec;
1430c45f0082SYong Li                     messages::internalError(aResp->res);
1431c45f0082SYong Li                     return;
1432c45f0082SYong Li                 }
1433c45f0082SYong Li             },
1434c45f0082SYong Li             "xyz.openbmc_project.Watchdog",
1435c45f0082SYong Li             "/xyz/openbmc_project/watchdog/host0",
1436c45f0082SYong Li             "org.freedesktop.DBus.Properties", "Set",
1437c45f0082SYong Li             "xyz.openbmc_project.State.Watchdog", "Enabled",
1438c45f0082SYong Li             std::variant<bool>(*wdtEnable));
1439c45f0082SYong Li     }
1440c45f0082SYong Li }
1441c45f0082SYong Li 
1442c45f0082SYong Li /**
1443c5b2abe0SLewanczyk, Dawid  * SystemsCollection derived class for delivering ComputerSystems Collection
1444c5b2abe0SLewanczyk, Dawid  * Schema
1445c5b2abe0SLewanczyk, Dawid  */
14461abe55efSEd Tanous class SystemsCollection : public Node
14471abe55efSEd Tanous {
1448c5b2abe0SLewanczyk, Dawid   public:
14491abe55efSEd Tanous     SystemsCollection(CrowApp &app) : Node(app, "/redfish/v1/Systems/")
14501abe55efSEd Tanous     {
1451c5b2abe0SLewanczyk, Dawid         entityPrivileges = {
1452c5b2abe0SLewanczyk, Dawid             {boost::beast::http::verb::get, {{"Login"}}},
1453c5b2abe0SLewanczyk, Dawid             {boost::beast::http::verb::head, {{"Login"}}},
1454c5b2abe0SLewanczyk, Dawid             {boost::beast::http::verb::patch, {{"ConfigureComponents"}}},
1455c5b2abe0SLewanczyk, Dawid             {boost::beast::http::verb::put, {{"ConfigureComponents"}}},
1456c5b2abe0SLewanczyk, Dawid             {boost::beast::http::verb::delete_, {{"ConfigureComponents"}}},
1457c5b2abe0SLewanczyk, Dawid             {boost::beast::http::verb::post, {{"ConfigureComponents"}}}};
1458c5b2abe0SLewanczyk, Dawid     }
1459c5b2abe0SLewanczyk, Dawid 
1460c5b2abe0SLewanczyk, Dawid   private:
146155c7b7a2SEd Tanous     void doGet(crow::Response &res, const crow::Request &req,
14621abe55efSEd Tanous                const std::vector<std::string> &params) override
14631abe55efSEd Tanous     {
14640f74e643SEd Tanous         res.jsonValue["@odata.type"] =
14650f74e643SEd Tanous             "#ComputerSystemCollection.ComputerSystemCollection";
14660f74e643SEd Tanous         res.jsonValue["@odata.id"] = "/redfish/v1/Systems";
14670f74e643SEd Tanous         res.jsonValue["@odata.context"] =
14680f74e643SEd Tanous             "/redfish/v1/"
14690f74e643SEd Tanous             "$metadata#ComputerSystemCollection.ComputerSystemCollection";
14700f74e643SEd Tanous         res.jsonValue["Name"] = "Computer System Collection";
1471029573d4SEd Tanous         res.jsonValue["Members"] = {
1472029573d4SEd Tanous             {{"@odata.id", "/redfish/v1/Systems/system"}}};
1473029573d4SEd Tanous         res.jsonValue["Members@odata.count"] = 1;
1474029573d4SEd Tanous         res.end();
1475c5b2abe0SLewanczyk, Dawid     }
1476c5b2abe0SLewanczyk, Dawid };
1477c5b2abe0SLewanczyk, Dawid 
1478c5b2abe0SLewanczyk, Dawid /**
1479cc340dd9SEd Tanous  * SystemActionsReset class supports handle POST method for Reset action.
1480cc340dd9SEd Tanous  * The class retrieves and sends data directly to D-Bus.
1481cc340dd9SEd Tanous  */
1482cc340dd9SEd Tanous class SystemActionsReset : public Node
1483cc340dd9SEd Tanous {
1484cc340dd9SEd Tanous   public:
1485cc340dd9SEd Tanous     SystemActionsReset(CrowApp &app) :
1486029573d4SEd Tanous         Node(app, "/redfish/v1/Systems/system/Actions/ComputerSystem.Reset/")
1487cc340dd9SEd Tanous     {
1488cc340dd9SEd Tanous         entityPrivileges = {
1489cc340dd9SEd Tanous             {boost::beast::http::verb::post, {{"ConfigureComponents"}}}};
1490cc340dd9SEd Tanous     }
1491cc340dd9SEd Tanous 
1492cc340dd9SEd Tanous   private:
1493cc340dd9SEd Tanous     /**
1494cc340dd9SEd Tanous      * Function handles POST method request.
1495cc340dd9SEd Tanous      * Analyzes POST body message before sends Reset request data to D-Bus.
1496cc340dd9SEd Tanous      */
1497cc340dd9SEd Tanous     void doPost(crow::Response &res, const crow::Request &req,
1498cc340dd9SEd Tanous                 const std::vector<std::string> &params) override
1499cc340dd9SEd Tanous     {
1500cc340dd9SEd Tanous         auto asyncResp = std::make_shared<AsyncResp>(res);
1501cc340dd9SEd Tanous 
15029712f8acSEd Tanous         std::string resetType;
15039712f8acSEd Tanous         if (!json_util::readJson(req, res, "ResetType", resetType))
1504cc340dd9SEd Tanous         {
1505cc340dd9SEd Tanous             return;
1506cc340dd9SEd Tanous         }
1507cc340dd9SEd Tanous 
1508d22c8396SJason M. Bills         // Get the command and host vs. chassis
1509cc340dd9SEd Tanous         std::string command;
1510d22c8396SJason M. Bills         bool hostCommand;
15119712f8acSEd Tanous         if (resetType == "On")
1512cc340dd9SEd Tanous         {
1513cc340dd9SEd Tanous             command = "xyz.openbmc_project.State.Host.Transition.On";
1514d22c8396SJason M. Bills             hostCommand = true;
1515d22c8396SJason M. Bills         }
1516d22c8396SJason M. Bills         else if (resetType == "ForceOff")
1517d22c8396SJason M. Bills         {
1518d22c8396SJason M. Bills             command = "xyz.openbmc_project.State.Chassis.Transition.Off";
1519d22c8396SJason M. Bills             hostCommand = false;
1520d22c8396SJason M. Bills         }
1521d22c8396SJason M. Bills         else if (resetType == "ForceOn")
1522d22c8396SJason M. Bills         {
1523d22c8396SJason M. Bills             command = "xyz.openbmc_project.State.Host.Transition.On";
1524d22c8396SJason M. Bills             hostCommand = true;
1525d22c8396SJason M. Bills         }
1526d22c8396SJason M. Bills         else if (resetType == "ForceRestart")
1527d22c8396SJason M. Bills         {
1528d22c8396SJason M. Bills             command = "xyz.openbmc_project.State.Chassis.Transition.Reset";
1529d22c8396SJason M. Bills             hostCommand = false;
1530cc340dd9SEd Tanous         }
15319712f8acSEd Tanous         else if (resetType == "GracefulShutdown")
1532cc340dd9SEd Tanous         {
1533cc340dd9SEd Tanous             command = "xyz.openbmc_project.State.Host.Transition.Off";
1534d22c8396SJason M. Bills             hostCommand = true;
1535cc340dd9SEd Tanous         }
15369712f8acSEd Tanous         else if (resetType == "GracefulRestart")
1537cc340dd9SEd Tanous         {
15389712f8acSEd Tanous             command = "xyz.openbmc_project.State.Host.Transition.Reboot";
1539d22c8396SJason M. Bills             hostCommand = true;
1540d22c8396SJason M. Bills         }
1541d22c8396SJason M. Bills         else if (resetType == "PowerCycle")
1542d22c8396SJason M. Bills         {
1543d22c8396SJason M. Bills             command = "xyz.openbmc_project.State.Chassis.Transition.PowerCycle";
1544d22c8396SJason M. Bills             hostCommand = false;
1545cc340dd9SEd Tanous         }
1546bfd5b826SLakshminarayana R. Kammath         else if (resetType == "Nmi")
1547bfd5b826SLakshminarayana R. Kammath         {
1548bfd5b826SLakshminarayana R. Kammath             doNMI(asyncResp);
1549bfd5b826SLakshminarayana R. Kammath             return;
1550bfd5b826SLakshminarayana R. Kammath         }
1551cc340dd9SEd Tanous         else
1552cc340dd9SEd Tanous         {
1553f12894f8SJason M. Bills             messages::actionParameterUnknown(res, "Reset", resetType);
1554cc340dd9SEd Tanous             return;
1555cc340dd9SEd Tanous         }
1556cc340dd9SEd Tanous 
1557d22c8396SJason M. Bills         if (hostCommand)
1558d22c8396SJason M. Bills         {
1559cc340dd9SEd Tanous             crow::connections::systemBus->async_method_call(
1560d22c8396SJason M. Bills                 [asyncResp, resetType](const boost::system::error_code ec) {
1561cc340dd9SEd Tanous                     if (ec)
1562cc340dd9SEd Tanous                     {
1563cc340dd9SEd Tanous                         BMCWEB_LOG_ERROR << "D-Bus responses error: " << ec;
1564d22c8396SJason M. Bills                         if (ec.value() == boost::asio::error::invalid_argument)
1565d22c8396SJason M. Bills                         {
1566d22c8396SJason M. Bills                             messages::actionParameterNotSupported(
1567d22c8396SJason M. Bills                                 asyncResp->res, resetType, "Reset");
1568d22c8396SJason M. Bills                         }
1569d22c8396SJason M. Bills                         else
1570d22c8396SJason M. Bills                         {
1571f12894f8SJason M. Bills                             messages::internalError(asyncResp->res);
1572d22c8396SJason M. Bills                         }
1573cc340dd9SEd Tanous                         return;
1574cc340dd9SEd Tanous                     }
1575f12894f8SJason M. Bills                     messages::success(asyncResp->res);
1576cc340dd9SEd Tanous                 },
1577cc340dd9SEd Tanous                 "xyz.openbmc_project.State.Host",
1578cc340dd9SEd Tanous                 "/xyz/openbmc_project/state/host0",
1579cc340dd9SEd Tanous                 "org.freedesktop.DBus.Properties", "Set",
15809712f8acSEd Tanous                 "xyz.openbmc_project.State.Host", "RequestedHostTransition",
1581abf2add6SEd Tanous                 std::variant<std::string>{command});
1582cc340dd9SEd Tanous         }
1583d22c8396SJason M. Bills         else
1584d22c8396SJason M. Bills         {
1585d22c8396SJason M. Bills             crow::connections::systemBus->async_method_call(
1586d22c8396SJason M. Bills                 [asyncResp, resetType](const boost::system::error_code ec) {
1587d22c8396SJason M. Bills                     if (ec)
1588d22c8396SJason M. Bills                     {
1589d22c8396SJason M. Bills                         BMCWEB_LOG_ERROR << "D-Bus responses error: " << ec;
1590d22c8396SJason M. Bills                         if (ec.value() == boost::asio::error::invalid_argument)
1591d22c8396SJason M. Bills                         {
1592d22c8396SJason M. Bills                             messages::actionParameterNotSupported(
1593d22c8396SJason M. Bills                                 asyncResp->res, resetType, "Reset");
1594d22c8396SJason M. Bills                         }
1595d22c8396SJason M. Bills                         else
1596d22c8396SJason M. Bills                         {
1597d22c8396SJason M. Bills                             messages::internalError(asyncResp->res);
1598d22c8396SJason M. Bills                         }
1599d22c8396SJason M. Bills                         return;
1600d22c8396SJason M. Bills                     }
1601d22c8396SJason M. Bills                     messages::success(asyncResp->res);
1602d22c8396SJason M. Bills                 },
1603d22c8396SJason M. Bills                 "xyz.openbmc_project.State.Chassis",
1604d22c8396SJason M. Bills                 "/xyz/openbmc_project/state/chassis0",
1605d22c8396SJason M. Bills                 "org.freedesktop.DBus.Properties", "Set",
1606d22c8396SJason M. Bills                 "xyz.openbmc_project.State.Chassis", "RequestedPowerTransition",
1607d22c8396SJason M. Bills                 std::variant<std::string>{command});
1608d22c8396SJason M. Bills         }
1609d22c8396SJason M. Bills     }
1610bfd5b826SLakshminarayana R. Kammath     /**
1611bfd5b826SLakshminarayana R. Kammath      * Function transceives data with dbus directly.
1612bfd5b826SLakshminarayana R. Kammath      */
1613bfd5b826SLakshminarayana R. Kammath     void doNMI(const std::shared_ptr<AsyncResp> &asyncResp)
1614bfd5b826SLakshminarayana R. Kammath     {
1615bfd5b826SLakshminarayana R. Kammath         constexpr char const *serviceName =
1616bfd5b826SLakshminarayana R. Kammath             "xyz.openbmc_project.Control.Host.NMI";
1617bfd5b826SLakshminarayana R. Kammath         constexpr char const *objectPath =
1618bfd5b826SLakshminarayana R. Kammath             "/xyz/openbmc_project/control/host0/nmi";
1619bfd5b826SLakshminarayana R. Kammath         constexpr char const *interfaceName =
1620bfd5b826SLakshminarayana R. Kammath             "xyz.openbmc_project.Control.Host.NMI";
1621bfd5b826SLakshminarayana R. Kammath         constexpr char const *method = "NMI";
1622bfd5b826SLakshminarayana R. Kammath 
1623bfd5b826SLakshminarayana R. Kammath         crow::connections::systemBus->async_method_call(
1624bfd5b826SLakshminarayana R. Kammath             [asyncResp](const boost::system::error_code ec) {
1625bfd5b826SLakshminarayana R. Kammath                 if (ec)
1626bfd5b826SLakshminarayana R. Kammath                 {
1627bfd5b826SLakshminarayana R. Kammath                     BMCWEB_LOG_ERROR << " Bad D-Bus request error: " << ec;
1628bfd5b826SLakshminarayana R. Kammath                     messages::internalError(asyncResp->res);
1629bfd5b826SLakshminarayana R. Kammath                     return;
1630bfd5b826SLakshminarayana R. Kammath                 }
1631bfd5b826SLakshminarayana R. Kammath                 messages::success(asyncResp->res);
1632bfd5b826SLakshminarayana R. Kammath             },
1633bfd5b826SLakshminarayana R. Kammath             serviceName, objectPath, interfaceName, method);
1634bfd5b826SLakshminarayana R. Kammath     }
1635cc340dd9SEd Tanous };
1636cc340dd9SEd Tanous 
1637cc340dd9SEd Tanous /**
16386617338dSEd Tanous  * Systems derived class for delivering Computer Systems Schema.
1639c5b2abe0SLewanczyk, Dawid  */
16401abe55efSEd Tanous class Systems : public Node
16411abe55efSEd Tanous {
1642c5b2abe0SLewanczyk, Dawid   public:
1643c5b2abe0SLewanczyk, Dawid     /*
1644c5b2abe0SLewanczyk, Dawid      * Default Constructor
1645c5b2abe0SLewanczyk, Dawid      */
1646029573d4SEd Tanous     Systems(CrowApp &app) : Node(app, "/redfish/v1/Systems/system/")
16471abe55efSEd Tanous     {
1648c5b2abe0SLewanczyk, Dawid         entityPrivileges = {
1649c5b2abe0SLewanczyk, Dawid             {boost::beast::http::verb::get, {{"Login"}}},
1650c5b2abe0SLewanczyk, Dawid             {boost::beast::http::verb::head, {{"Login"}}},
1651c5b2abe0SLewanczyk, Dawid             {boost::beast::http::verb::patch, {{"ConfigureComponents"}}},
1652c5b2abe0SLewanczyk, Dawid             {boost::beast::http::verb::put, {{"ConfigureComponents"}}},
1653c5b2abe0SLewanczyk, Dawid             {boost::beast::http::verb::delete_, {{"ConfigureComponents"}}},
1654c5b2abe0SLewanczyk, Dawid             {boost::beast::http::verb::post, {{"ConfigureComponents"}}}};
1655c5b2abe0SLewanczyk, Dawid     }
1656c5b2abe0SLewanczyk, Dawid 
1657c5b2abe0SLewanczyk, Dawid   private:
1658c5b2abe0SLewanczyk, Dawid     /**
1659c5b2abe0SLewanczyk, Dawid      * Functions triggers appropriate requests on DBus
1660c5b2abe0SLewanczyk, Dawid      */
166155c7b7a2SEd Tanous     void doGet(crow::Response &res, const crow::Request &req,
16621abe55efSEd Tanous                const std::vector<std::string> &params) override
16631abe55efSEd Tanous     {
1664491d8ee7SSantosh Puranik         res.jsonValue["@odata.type"] = "#ComputerSystem.v1_6_0.ComputerSystem";
16650f74e643SEd Tanous         res.jsonValue["@odata.context"] =
16660f74e643SEd Tanous             "/redfish/v1/$metadata#ComputerSystem.ComputerSystem";
1667029573d4SEd Tanous         res.jsonValue["Name"] = "Computer System";
1668029573d4SEd Tanous         res.jsonValue["Id"] = "system";
16690f74e643SEd Tanous         res.jsonValue["SystemType"] = "Physical";
16700f74e643SEd Tanous         res.jsonValue["Description"] = "Computer System";
16710f74e643SEd Tanous         res.jsonValue["ProcessorSummary"]["Count"] = 0;
16720f74e643SEd Tanous         res.jsonValue["ProcessorSummary"]["Status"]["State"] = "Disabled";
16730f74e643SEd Tanous         res.jsonValue["MemorySummary"]["TotalSystemMemoryGiB"] = int(0);
16740f74e643SEd Tanous         res.jsonValue["MemorySummary"]["Status"]["State"] = "Disabled";
1675029573d4SEd Tanous         res.jsonValue["@odata.id"] = "/redfish/v1/Systems/system";
167604a258f4SEd Tanous 
1677443c2934SRapkiewicz, Pawel         res.jsonValue["Processors"] = {
1678029573d4SEd Tanous             {"@odata.id", "/redfish/v1/Systems/system/Processors"}};
1679443c2934SRapkiewicz, Pawel         res.jsonValue["Memory"] = {
1680029573d4SEd Tanous             {"@odata.id", "/redfish/v1/Systems/system/Memory"}};
1681a25aeccfSNikhil Potade         res.jsonValue["Storage"] = {
1682a25aeccfSNikhil Potade             {"@odata.id", "/redfish/v1/Systems/system/Storage"}};
1683029573d4SEd Tanous 
1684cc340dd9SEd Tanous         // TODO Need to support ForceRestart.
1685cc340dd9SEd Tanous         res.jsonValue["Actions"]["#ComputerSystem.Reset"] = {
1686cc340dd9SEd Tanous             {"target",
1687029573d4SEd Tanous              "/redfish/v1/Systems/system/Actions/ComputerSystem.Reset"},
1688cc340dd9SEd Tanous             {"ResetType@Redfish.AllowableValues",
1689d22c8396SJason M. Bills              {"On", "ForceOff", "ForceOn", "ForceRestart", "GracefulRestart",
1690bfd5b826SLakshminarayana R. Kammath               "GracefulShutdown", "PowerCycle", "Nmi"}}};
1691c5b2abe0SLewanczyk, Dawid 
1692c4bf6374SJason M. Bills         res.jsonValue["LogServices"] = {
1693029573d4SEd Tanous             {"@odata.id", "/redfish/v1/Systems/system/LogServices"}};
1694c4bf6374SJason M. Bills 
1695c5d03ff4SJennifer Lee         res.jsonValue["Links"]["ManagedBy"] = {
1696c5d03ff4SJennifer Lee             {{"@odata.id", "/redfish/v1/Managers/bmc"}}};
1697c5d03ff4SJennifer Lee 
1698c5d03ff4SJennifer Lee         res.jsonValue["Status"] = {
1699c5d03ff4SJennifer Lee             {"Health", "OK"},
1700c5d03ff4SJennifer Lee             {"State", "Enabled"},
1701c5d03ff4SJennifer Lee         };
1702a0803efaSEd Tanous         auto asyncResp = std::make_shared<AsyncResp>(res);
1703c5b2abe0SLewanczyk, Dawid 
17042ad9c2f6SJames Feist         constexpr const std::array<const char *, 3> inventoryForSystems = {
1705b49ac873SJames Feist             "xyz.openbmc_project.Inventory.Item.Dimm",
17062ad9c2f6SJames Feist             "xyz.openbmc_project.Inventory.Item.Cpu",
17072ad9c2f6SJames Feist             "xyz.openbmc_project.Inventory.Item.Drive"};
1708b49ac873SJames Feist 
1709b49ac873SJames Feist         auto health = std::make_shared<HealthPopulate>(asyncResp);
1710b49ac873SJames Feist         crow::connections::systemBus->async_method_call(
1711b49ac873SJames Feist             [health](const boost::system::error_code ec,
1712b49ac873SJames Feist                      std::vector<std::string> &resp) {
1713b49ac873SJames Feist                 if (ec)
1714b49ac873SJames Feist                 {
1715b49ac873SJames Feist                     // no inventory
1716b49ac873SJames Feist                     return;
1717b49ac873SJames Feist                 }
1718b49ac873SJames Feist 
1719b49ac873SJames Feist                 health->inventory = std::move(resp);
1720b49ac873SJames Feist             },
1721b49ac873SJames Feist             "xyz.openbmc_project.ObjectMapper",
1722b49ac873SJames Feist             "/xyz/openbmc_project/object_mapper",
1723b49ac873SJames Feist             "xyz.openbmc_project.ObjectMapper", "GetSubTreePaths", "/",
1724b49ac873SJames Feist             int32_t(0), inventoryForSystems);
1725b49ac873SJames Feist 
1726b49ac873SJames Feist         health->populate();
1727b49ac873SJames Feist 
1728c5d03ff4SJennifer Lee         getMainChassisId(asyncResp, [](const std::string &chassisId,
1729c5d03ff4SJennifer Lee                                        std::shared_ptr<AsyncResp> aRsp) {
1730c5d03ff4SJennifer Lee             aRsp->res.jsonValue["Links"]["Chassis"] = {
1731c5d03ff4SJennifer Lee                 {{"@odata.id", "/redfish/v1/Chassis/" + chassisId}}};
1732c5d03ff4SJennifer Lee         });
1733*a3002228SAppaRao Puli 
1734*a3002228SAppaRao Puli         getIndicatorLedState(asyncResp);
17355bc2dc8eSJames Feist         getComputerSystem(asyncResp, health);
17366c34de48SEd Tanous         getHostState(asyncResp);
1737491d8ee7SSantosh Puranik         getBootProperties(asyncResp);
1738adbe192aSJason M. Bills         getPCIeDeviceList(asyncResp, "PCIeDevices");
173951709ffdSYong Li         getHostWatchdogTimer(asyncResp);
1740a6349918SAppaRao Puli #ifdef BMCWEB_ENABLE_REDFISH_PROVISIONING_FEATURE
1741a6349918SAppaRao Puli         getProvisioningStatus(asyncResp);
1742a6349918SAppaRao Puli #endif
1743c5b2abe0SLewanczyk, Dawid     }
1744c5b2abe0SLewanczyk, Dawid 
174555c7b7a2SEd Tanous     void doPatch(crow::Response &res, const crow::Request &req,
17461abe55efSEd Tanous                  const std::vector<std::string> &params) override
17471abe55efSEd Tanous     {
1748cde19e5fSSantosh Puranik         std::optional<std::string> indicatorLed;
1749491d8ee7SSantosh Puranik         std::optional<nlohmann::json> bootProps;
1750c45f0082SYong Li         std::optional<nlohmann::json> wdtTimerProps;
175141352c24SSantosh Puranik         auto asyncResp = std::make_shared<AsyncResp>(res);
175241352c24SSantosh Puranik 
1753944ffaf9SJohnathan Mantey         if (!json_util::readJson(req, res, "IndicatorLED", indicatorLed, "Boot",
1754c45f0082SYong Li                                  bootProps, "WatchdogTimer", wdtTimerProps))
17556617338dSEd Tanous         {
17566617338dSEd Tanous             return;
17576617338dSEd Tanous         }
1758491d8ee7SSantosh Puranik 
1759944ffaf9SJohnathan Mantey         res.result(boost::beast::http::status::no_content);
1760c45f0082SYong Li 
1761c45f0082SYong Li         if (wdtTimerProps)
1762c45f0082SYong Li         {
1763c45f0082SYong Li             std::optional<bool> wdtEnable;
1764c45f0082SYong Li             std::optional<std::string> wdtTimeOutAction;
1765c45f0082SYong Li 
1766c45f0082SYong Li             if (!json_util::readJson(*wdtTimerProps, asyncResp->res,
1767c45f0082SYong Li                                      "FunctionEnabled", wdtEnable,
1768c45f0082SYong Li                                      "TimeoutAction", wdtTimeOutAction))
1769c45f0082SYong Li             {
1770c45f0082SYong Li                 return;
1771c45f0082SYong Li             }
1772c45f0082SYong Li             setWDTProperties(asyncResp, std::move(wdtEnable),
1773c45f0082SYong Li                              std::move(wdtTimeOutAction));
1774c45f0082SYong Li         }
1775c45f0082SYong Li 
1776491d8ee7SSantosh Puranik         if (bootProps)
1777491d8ee7SSantosh Puranik         {
1778491d8ee7SSantosh Puranik             std::optional<std::string> bootSource;
1779491d8ee7SSantosh Puranik             std::optional<std::string> bootEnable;
1780491d8ee7SSantosh Puranik 
1781491d8ee7SSantosh Puranik             if (!json_util::readJson(*bootProps, asyncResp->res,
1782491d8ee7SSantosh Puranik                                      "BootSourceOverrideTarget", bootSource,
1783491d8ee7SSantosh Puranik                                      "BootSourceOverrideEnabled", bootEnable))
1784491d8ee7SSantosh Puranik             {
1785491d8ee7SSantosh Puranik                 return;
1786491d8ee7SSantosh Puranik             }
1787491d8ee7SSantosh Puranik             setBootProperties(asyncResp, std::move(bootSource),
1788491d8ee7SSantosh Puranik                               std::move(bootEnable));
1789491d8ee7SSantosh Puranik         }
1790265c1602SJohnathan Mantey 
17919712f8acSEd Tanous         if (indicatorLed)
17926617338dSEd Tanous         {
1793*a3002228SAppaRao Puli             setIndicatorLedState(asyncResp, std::move(*indicatorLed));
17946617338dSEd Tanous         }
1795c5b2abe0SLewanczyk, Dawid     }
1796c5b2abe0SLewanczyk, Dawid };
1797c5b2abe0SLewanczyk, Dawid } // namespace redfish
1798