xref: /openbmc/bmcweb/features/redfish/lib/systems.hpp (revision ac7e1e0baf7fd0439b0352954d354f5f1a51e439)
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"
191c8fba97SJames Feist #include "led.hpp"
20f5c9f8bdSJason M. Bills #include "pcie.hpp"
21c5d03ff4SJennifer Lee #include "redfish_util.hpp"
22c5d03ff4SJennifer Lee 
237e860f15SJohn Edward Broadbent #include <app.hpp>
249712f8acSEd Tanous #include <boost/container/flat_map.hpp>
25ed398213SEd Tanous #include <registries/privilege_registry.hpp>
26cb7e1e7bSAndrew Geissler #include <utils/fw_utils.hpp>
27c5b2abe0SLewanczyk, Dawid #include <utils/json_utils.hpp>
281214b7e7SGunnar Mills 
29abf2add6SEd Tanous #include <variant>
30c5b2abe0SLewanczyk, Dawid 
311abe55efSEd Tanous namespace redfish
321abe55efSEd Tanous {
33c5b2abe0SLewanczyk, Dawid 
349d3ae10eSAlpana Kumari /**
359d3ae10eSAlpana Kumari  * @brief Updates the Functional State of DIMMs
369d3ae10eSAlpana Kumari  *
379d3ae10eSAlpana Kumari  * @param[in] aResp Shared pointer for completing asynchronous calls
389d3ae10eSAlpana Kumari  * @param[in] dimmState Dimm's Functional state, true/false
399d3ae10eSAlpana Kumari  *
409d3ae10eSAlpana Kumari  * @return None.
419d3ae10eSAlpana Kumari  */
428d1b46d7Szhanghch05 inline void
438d1b46d7Szhanghch05     updateDimmProperties(const std::shared_ptr<bmcweb::AsyncResp>& aResp,
449d3ae10eSAlpana Kumari                          const std::variant<bool>& dimmState)
459d3ae10eSAlpana Kumari {
469d3ae10eSAlpana Kumari     const bool* isDimmFunctional = std::get_if<bool>(&dimmState);
479d3ae10eSAlpana Kumari     if (isDimmFunctional == nullptr)
489d3ae10eSAlpana Kumari     {
499d3ae10eSAlpana Kumari         messages::internalError(aResp->res);
509d3ae10eSAlpana Kumari         return;
519d3ae10eSAlpana Kumari     }
529d3ae10eSAlpana Kumari     BMCWEB_LOG_DEBUG << "Dimm Functional: " << *isDimmFunctional;
539d3ae10eSAlpana Kumari 
549d3ae10eSAlpana Kumari     // Set it as Enabled if at least one DIMM is functional
559d3ae10eSAlpana Kumari     // Update STATE only if previous State was DISABLED and current Dimm is
569d3ae10eSAlpana Kumari     // ENABLED.
579d3ae10eSAlpana Kumari     nlohmann::json& prevMemSummary =
589d3ae10eSAlpana Kumari         aResp->res.jsonValue["MemorySummary"]["Status"]["State"];
599d3ae10eSAlpana Kumari     if (prevMemSummary == "Disabled")
609d3ae10eSAlpana Kumari     {
619d3ae10eSAlpana Kumari         if (*isDimmFunctional == true)
629d3ae10eSAlpana Kumari         {
639d3ae10eSAlpana Kumari             aResp->res.jsonValue["MemorySummary"]["Status"]["State"] =
649d3ae10eSAlpana Kumari                 "Enabled";
659d3ae10eSAlpana Kumari         }
669d3ae10eSAlpana Kumari     }
679d3ae10eSAlpana Kumari }
689d3ae10eSAlpana Kumari 
6957e8c9beSAlpana Kumari /*
7057e8c9beSAlpana Kumari  * @brief Update "ProcessorSummary" "Count" based on Cpu PresenceState
7157e8c9beSAlpana Kumari  *
7257e8c9beSAlpana Kumari  * @param[in] aResp Shared pointer for completing asynchronous calls
7357e8c9beSAlpana Kumari  * @param[in] cpuPresenceState CPU present or not
7457e8c9beSAlpana Kumari  *
7557e8c9beSAlpana Kumari  * @return None.
7657e8c9beSAlpana Kumari  */
778d1b46d7Szhanghch05 inline void
788d1b46d7Szhanghch05     modifyCpuPresenceState(const std::shared_ptr<bmcweb::AsyncResp>& aResp,
7957e8c9beSAlpana Kumari                            const std::variant<bool>& cpuPresenceState)
8057e8c9beSAlpana Kumari {
8157e8c9beSAlpana Kumari     const bool* isCpuPresent = std::get_if<bool>(&cpuPresenceState);
8257e8c9beSAlpana Kumari 
8357e8c9beSAlpana Kumari     if (isCpuPresent == nullptr)
8457e8c9beSAlpana Kumari     {
8557e8c9beSAlpana Kumari         messages::internalError(aResp->res);
8657e8c9beSAlpana Kumari         return;
8757e8c9beSAlpana Kumari     }
8857e8c9beSAlpana Kumari     BMCWEB_LOG_DEBUG << "Cpu Present: " << *isCpuPresent;
8957e8c9beSAlpana Kumari 
9057e8c9beSAlpana Kumari     if (*isCpuPresent == true)
9157e8c9beSAlpana Kumari     {
92b4b9595aSJames Feist         nlohmann::json& procCount =
93b4b9595aSJames Feist             aResp->res.jsonValue["ProcessorSummary"]["Count"];
94b4b9595aSJames Feist         auto procCountPtr =
95b4b9595aSJames Feist             procCount.get_ptr<nlohmann::json::number_integer_t*>();
96b4b9595aSJames Feist         if (procCountPtr != nullptr)
97b4b9595aSJames Feist         {
98b4b9595aSJames Feist             // shouldn't be possible to be nullptr
99b4b9595aSJames Feist             *procCountPtr += 1;
10057e8c9beSAlpana Kumari         }
101b4b9595aSJames Feist     }
10257e8c9beSAlpana Kumari }
10357e8c9beSAlpana Kumari 
10457e8c9beSAlpana Kumari /*
10557e8c9beSAlpana Kumari  * @brief Update "ProcessorSummary" "Status" "State" based on
10657e8c9beSAlpana Kumari  *        CPU Functional State
10757e8c9beSAlpana Kumari  *
10857e8c9beSAlpana Kumari  * @param[in] aResp Shared pointer for completing asynchronous calls
10957e8c9beSAlpana Kumari  * @param[in] cpuFunctionalState is CPU functional true/false
11057e8c9beSAlpana Kumari  *
11157e8c9beSAlpana Kumari  * @return None.
11257e8c9beSAlpana Kumari  */
11323a21a1cSEd Tanous inline void
1148d1b46d7Szhanghch05     modifyCpuFunctionalState(const std::shared_ptr<bmcweb::AsyncResp>& aResp,
11557e8c9beSAlpana Kumari                              const std::variant<bool>& cpuFunctionalState)
11657e8c9beSAlpana Kumari {
11757e8c9beSAlpana Kumari     const bool* isCpuFunctional = std::get_if<bool>(&cpuFunctionalState);
11857e8c9beSAlpana Kumari 
11957e8c9beSAlpana Kumari     if (isCpuFunctional == nullptr)
12057e8c9beSAlpana Kumari     {
12157e8c9beSAlpana Kumari         messages::internalError(aResp->res);
12257e8c9beSAlpana Kumari         return;
12357e8c9beSAlpana Kumari     }
12457e8c9beSAlpana Kumari     BMCWEB_LOG_DEBUG << "Cpu Functional: " << *isCpuFunctional;
12557e8c9beSAlpana Kumari 
12657e8c9beSAlpana Kumari     nlohmann::json& prevProcState =
12757e8c9beSAlpana Kumari         aResp->res.jsonValue["ProcessorSummary"]["Status"]["State"];
12857e8c9beSAlpana Kumari 
12957e8c9beSAlpana Kumari     // Set it as Enabled if at least one CPU is functional
13057e8c9beSAlpana Kumari     // Update STATE only if previous State was Non_Functional and current CPU is
13157e8c9beSAlpana Kumari     // Functional.
13257e8c9beSAlpana Kumari     if (prevProcState == "Disabled")
13357e8c9beSAlpana Kumari     {
13457e8c9beSAlpana Kumari         if (*isCpuFunctional == true)
13557e8c9beSAlpana Kumari         {
13657e8c9beSAlpana Kumari             aResp->res.jsonValue["ProcessorSummary"]["Status"]["State"] =
13757e8c9beSAlpana Kumari                 "Enabled";
13857e8c9beSAlpana Kumari         }
13957e8c9beSAlpana Kumari     }
14057e8c9beSAlpana Kumari }
14157e8c9beSAlpana Kumari 
14257e8c9beSAlpana Kumari /*
143c5b2abe0SLewanczyk, Dawid  * @brief Retrieves computer system properties over dbus
144c5b2abe0SLewanczyk, Dawid  *
145c5b2abe0SLewanczyk, Dawid  * @param[in] aResp Shared pointer for completing asynchronous calls
1468f9ee3cdSGunnar Mills  * @param[in] systemHealth  Shared HealthPopulate pointer
147c5b2abe0SLewanczyk, Dawid  *
148c5b2abe0SLewanczyk, Dawid  * @return None.
149c5b2abe0SLewanczyk, Dawid  */
150b5a76932SEd Tanous inline void
1518d1b46d7Szhanghch05     getComputerSystem(const std::shared_ptr<bmcweb::AsyncResp>& aResp,
152b5a76932SEd Tanous                       const std::shared_ptr<HealthPopulate>& systemHealth)
1531abe55efSEd Tanous {
15455c7b7a2SEd Tanous     BMCWEB_LOG_DEBUG << "Get available system components.";
1559d3ae10eSAlpana Kumari 
15655c7b7a2SEd Tanous     crow::connections::systemBus->async_method_call(
1575bc2dc8eSJames Feist         [aResp, systemHealth](
158c5b2abe0SLewanczyk, Dawid             const boost::system::error_code ec,
159c5b2abe0SLewanczyk, Dawid             const std::vector<std::pair<
1606c34de48SEd Tanous                 std::string,
1611214b7e7SGunnar Mills                 std::vector<std::pair<std::string, std::vector<std::string>>>>>&
1621214b7e7SGunnar Mills                 subtree) {
1631abe55efSEd Tanous             if (ec)
1641abe55efSEd Tanous             {
16555c7b7a2SEd Tanous                 BMCWEB_LOG_DEBUG << "DBUS response error";
166f12894f8SJason M. Bills                 messages::internalError(aResp->res);
167c5b2abe0SLewanczyk, Dawid                 return;
168c5b2abe0SLewanczyk, Dawid             }
169c5b2abe0SLewanczyk, Dawid             // Iterate over all retrieved ObjectPaths.
1706c34de48SEd Tanous             for (const std::pair<std::string,
1716c34de48SEd Tanous                                  std::vector<std::pair<
1721214b7e7SGunnar Mills                                      std::string, std::vector<std::string>>>>&
1731214b7e7SGunnar Mills                      object : subtree)
1741abe55efSEd Tanous             {
175c5b2abe0SLewanczyk, Dawid                 const std::string& path = object.first;
17655c7b7a2SEd Tanous                 BMCWEB_LOG_DEBUG << "Got path: " << path;
1771abe55efSEd Tanous                 const std::vector<
1781214b7e7SGunnar Mills                     std::pair<std::string, std::vector<std::string>>>&
1791214b7e7SGunnar Mills                     connectionNames = object.second;
1801abe55efSEd Tanous                 if (connectionNames.size() < 1)
1811abe55efSEd Tanous                 {
182c5b2abe0SLewanczyk, Dawid                     continue;
183c5b2abe0SLewanczyk, Dawid                 }
184029573d4SEd Tanous 
1855bc2dc8eSJames Feist                 auto memoryHealth = std::make_shared<HealthPopulate>(
1865bc2dc8eSJames Feist                     aResp, aResp->res.jsonValue["MemorySummary"]["Status"]);
1875bc2dc8eSJames Feist 
1885bc2dc8eSJames Feist                 auto cpuHealth = std::make_shared<HealthPopulate>(
1895bc2dc8eSJames Feist                     aResp, aResp->res.jsonValue["ProcessorSummary"]["Status"]);
1905bc2dc8eSJames Feist 
1915bc2dc8eSJames Feist                 systemHealth->children.emplace_back(memoryHealth);
1925bc2dc8eSJames Feist                 systemHealth->children.emplace_back(cpuHealth);
1935bc2dc8eSJames Feist 
1946c34de48SEd Tanous                 // This is not system, so check if it's cpu, dimm, UUID or
1956c34de48SEd Tanous                 // BiosVer
19604a258f4SEd Tanous                 for (const auto& connection : connectionNames)
1971abe55efSEd Tanous                 {
19804a258f4SEd Tanous                     for (const auto& interfaceName : connection.second)
1991abe55efSEd Tanous                     {
20004a258f4SEd Tanous                         if (interfaceName ==
20104a258f4SEd Tanous                             "xyz.openbmc_project.Inventory.Item.Dimm")
2021abe55efSEd Tanous                         {
2031abe55efSEd Tanous                             BMCWEB_LOG_DEBUG
20404a258f4SEd Tanous                                 << "Found Dimm, now get its properties.";
2059d3ae10eSAlpana Kumari 
20655c7b7a2SEd Tanous                             crow::connections::systemBus->async_method_call(
2079d3ae10eSAlpana Kumari                                 [aResp, service{connection.first},
208f23b7296SEd Tanous                                  path](const boost::system::error_code ec2,
2096c34de48SEd Tanous                                        const std::vector<
2101214b7e7SGunnar Mills                                            std::pair<std::string, VariantType>>&
2111214b7e7SGunnar Mills                                            properties) {
212cb13a392SEd Tanous                                     if (ec2)
2131abe55efSEd Tanous                                     {
2141abe55efSEd Tanous                                         BMCWEB_LOG_ERROR
215cb13a392SEd Tanous                                             << "DBUS response error " << ec2;
216f12894f8SJason M. Bills                                         messages::internalError(aResp->res);
217c5b2abe0SLewanczyk, Dawid                                         return;
218c5b2abe0SLewanczyk, Dawid                                     }
2196c34de48SEd Tanous                                     BMCWEB_LOG_DEBUG << "Got "
2206c34de48SEd Tanous                                                      << properties.size()
221c5b2abe0SLewanczyk, Dawid                                                      << " Dimm properties.";
2229d3ae10eSAlpana Kumari 
2239d3ae10eSAlpana Kumari                                     if (properties.size() > 0)
2249d3ae10eSAlpana Kumari                                     {
22504a258f4SEd Tanous                                         for (const std::pair<std::string,
2261214b7e7SGunnar Mills                                                              VariantType>&
2271214b7e7SGunnar Mills                                                  property : properties)
2281abe55efSEd Tanous                                         {
2295fd7ba65SCheng C Yang                                             if (property.first !=
2305fd7ba65SCheng C Yang                                                 "MemorySizeInKB")
2311abe55efSEd Tanous                                             {
2325fd7ba65SCheng C Yang                                                 continue;
2335fd7ba65SCheng C Yang                                             }
2345fd7ba65SCheng C Yang                                             const uint32_t* value =
2358d78b7a9SPatrick Williams                                                 std::get_if<uint32_t>(
2361b6b96c5SEd Tanous                                                     &property.second);
2375fd7ba65SCheng C Yang                                             if (value == nullptr)
2381abe55efSEd Tanous                                             {
2395fd7ba65SCheng C Yang                                                 BMCWEB_LOG_DEBUG
2405fd7ba65SCheng C Yang                                                     << "Find incorrect type of "
2415fd7ba65SCheng C Yang                                                        "MemorySize";
2425fd7ba65SCheng C Yang                                                 continue;
2435fd7ba65SCheng C Yang                                             }
2445fd7ba65SCheng C Yang                                             nlohmann::json& totalMemory =
2455fd7ba65SCheng C Yang                                                 aResp->res
2465fd7ba65SCheng C Yang                                                     .jsonValue["MemorySummar"
2475fd7ba65SCheng C Yang                                                                "y"]
2485fd7ba65SCheng C Yang                                                               ["TotalSystemMe"
2495fd7ba65SCheng C Yang                                                                "moryGiB"];
2505fd7ba65SCheng C Yang                                             uint64_t* preValue =
2515fd7ba65SCheng C Yang                                                 totalMemory
2525fd7ba65SCheng C Yang                                                     .get_ptr<uint64_t*>();
2535fd7ba65SCheng C Yang                                             if (preValue == nullptr)
2545fd7ba65SCheng C Yang                                             {
2555fd7ba65SCheng C Yang                                                 continue;
2565fd7ba65SCheng C Yang                                             }
2575fd7ba65SCheng C Yang                                             aResp->res
2585fd7ba65SCheng C Yang                                                 .jsonValue["MemorySummary"]
2596c34de48SEd Tanous                                                           ["TotalSystemMemoryGi"
2605fd7ba65SCheng C Yang                                                            "B"] =
2615fd7ba65SCheng C Yang                                                 *value / (1024 * 1024) +
2625fd7ba65SCheng C Yang                                                 *preValue;
2635fd7ba65SCheng C Yang                                             aResp->res
2645fd7ba65SCheng C Yang                                                 .jsonValue["MemorySummary"]
2659d3ae10eSAlpana Kumari                                                           ["Status"]["State"] =
2661abe55efSEd Tanous                                                 "Enabled";
267c5b2abe0SLewanczyk, Dawid                                         }
268c5b2abe0SLewanczyk, Dawid                                     }
2699d3ae10eSAlpana Kumari                                     else
2709d3ae10eSAlpana Kumari                                     {
2719d3ae10eSAlpana Kumari                                         auto getDimmProperties =
2729d3ae10eSAlpana Kumari                                             [aResp](
2739d3ae10eSAlpana Kumari                                                 const boost::system::error_code
274cb13a392SEd Tanous                                                     ec3,
2751214b7e7SGunnar Mills                                                 const std::variant<bool>&
2761214b7e7SGunnar Mills                                                     dimmState) {
277cb13a392SEd Tanous                                                 if (ec3)
2789d3ae10eSAlpana Kumari                                                 {
2799d3ae10eSAlpana Kumari                                                     BMCWEB_LOG_ERROR
2809d3ae10eSAlpana Kumari                                                         << "DBUS response "
2819d3ae10eSAlpana Kumari                                                            "error "
282cb13a392SEd Tanous                                                         << ec3;
2839d3ae10eSAlpana Kumari                                                     return;
2849d3ae10eSAlpana Kumari                                                 }
2859d3ae10eSAlpana Kumari                                                 updateDimmProperties(aResp,
2869d3ae10eSAlpana Kumari                                                                      dimmState);
2879d3ae10eSAlpana Kumari                                             };
2889d3ae10eSAlpana Kumari                                         crow::connections::systemBus
2899d3ae10eSAlpana Kumari                                             ->async_method_call(
2909d3ae10eSAlpana Kumari                                                 std::move(getDimmProperties),
2919d3ae10eSAlpana Kumari                                                 service, path,
2929d3ae10eSAlpana Kumari                                                 "org.freedesktop.DBus."
2939d3ae10eSAlpana Kumari                                                 "Properties",
2949d3ae10eSAlpana Kumari                                                 "Get",
2959d3ae10eSAlpana Kumari                                                 "xyz.openbmc_project.State."
2969d3ae10eSAlpana Kumari                                                 "Decorator.OperationalStatus",
2979d3ae10eSAlpana Kumari                                                 "Functional");
2989d3ae10eSAlpana Kumari                                     }
299c5b2abe0SLewanczyk, Dawid                                 },
30004a258f4SEd Tanous                                 connection.first, path,
3016c34de48SEd Tanous                                 "org.freedesktop.DBus.Properties", "GetAll",
3026c34de48SEd Tanous                                 "xyz.openbmc_project.Inventory.Item.Dimm");
3035bc2dc8eSJames Feist 
3045bc2dc8eSJames Feist                             memoryHealth->inventory.emplace_back(path);
3051abe55efSEd Tanous                         }
30604a258f4SEd Tanous                         else if (interfaceName ==
30704a258f4SEd Tanous                                  "xyz.openbmc_project.Inventory.Item.Cpu")
3081abe55efSEd Tanous                         {
3091abe55efSEd Tanous                             BMCWEB_LOG_DEBUG
31004a258f4SEd Tanous                                 << "Found Cpu, now get its properties.";
31157e8c9beSAlpana Kumari 
312a0803efaSEd Tanous                             crow::connections::systemBus->async_method_call(
31357e8c9beSAlpana Kumari                                 [aResp, service{connection.first},
314f23b7296SEd Tanous                                  path](const boost::system::error_code ec2,
3156c34de48SEd Tanous                                        const std::vector<
3161214b7e7SGunnar Mills                                            std::pair<std::string, VariantType>>&
3171214b7e7SGunnar Mills                                            properties) {
318cb13a392SEd Tanous                                     if (ec2)
3191abe55efSEd Tanous                                     {
3201abe55efSEd Tanous                                         BMCWEB_LOG_ERROR
321cb13a392SEd Tanous                                             << "DBUS response error " << ec2;
322f12894f8SJason M. Bills                                         messages::internalError(aResp->res);
323c5b2abe0SLewanczyk, Dawid                                         return;
324c5b2abe0SLewanczyk, Dawid                                     }
3256c34de48SEd Tanous                                     BMCWEB_LOG_DEBUG << "Got "
3266c34de48SEd Tanous                                                      << properties.size()
327c5b2abe0SLewanczyk, Dawid                                                      << " Cpu properties.";
32857e8c9beSAlpana Kumari 
32957e8c9beSAlpana Kumari                                     auto getCpuPresenceState =
33057e8c9beSAlpana Kumari                                         [aResp](
331a1978347SAli Ahmed                                             const boost::system::error_code ec3,
3321214b7e7SGunnar Mills                                             const std::variant<bool>&
3331214b7e7SGunnar Mills                                                 cpuPresenceCheck) {
334cb13a392SEd Tanous                                             if (ec3)
33557e8c9beSAlpana Kumari                                             {
33657e8c9beSAlpana Kumari                                                 BMCWEB_LOG_ERROR
337a1978347SAli Ahmed                                                     << "DBUS response error "
338cb13a392SEd Tanous                                                     << ec3;
33957e8c9beSAlpana Kumari                                                 return;
34057e8c9beSAlpana Kumari                                             }
34157e8c9beSAlpana Kumari                                             modifyCpuPresenceState(
34257e8c9beSAlpana Kumari                                                 aResp, cpuPresenceCheck);
34357e8c9beSAlpana Kumari                                         };
34457e8c9beSAlpana Kumari 
34557e8c9beSAlpana Kumari                                     auto getCpuFunctionalState =
34657e8c9beSAlpana Kumari                                         [aResp](
347a1978347SAli Ahmed                                             const boost::system::error_code ec3,
3481214b7e7SGunnar Mills                                             const std::variant<bool>&
3491214b7e7SGunnar Mills                                                 cpuFunctionalCheck) {
350cb13a392SEd Tanous                                             if (ec3)
35157e8c9beSAlpana Kumari                                             {
35257e8c9beSAlpana Kumari                                                 BMCWEB_LOG_ERROR
353a1978347SAli Ahmed                                                     << "DBUS response error "
354cb13a392SEd Tanous                                                     << ec3;
35557e8c9beSAlpana Kumari                                                 return;
35657e8c9beSAlpana Kumari                                             }
35757e8c9beSAlpana Kumari                                             modifyCpuFunctionalState(
35857e8c9beSAlpana Kumari                                                 aResp, cpuFunctionalCheck);
35957e8c9beSAlpana Kumari                                         };
360a1978347SAli Ahmed 
36157e8c9beSAlpana Kumari                                     // Get the Presence of CPU
36257e8c9beSAlpana Kumari                                     crow::connections::systemBus
36357e8c9beSAlpana Kumari                                         ->async_method_call(
36457e8c9beSAlpana Kumari                                             std::move(getCpuPresenceState),
36557e8c9beSAlpana Kumari                                             service, path,
36657e8c9beSAlpana Kumari                                             "org.freedesktop.DBus."
36757e8c9beSAlpana Kumari                                             "Properties",
36857e8c9beSAlpana Kumari                                             "Get",
36957e8c9beSAlpana Kumari                                             "xyz.openbmc_project.Inventory."
37057e8c9beSAlpana Kumari                                             "Item",
37157e8c9beSAlpana Kumari                                             "Present");
37257e8c9beSAlpana Kumari 
37357e8c9beSAlpana Kumari                                     // Get the Functional State
37457e8c9beSAlpana Kumari                                     crow::connections::systemBus
37557e8c9beSAlpana Kumari                                         ->async_method_call(
376a1978347SAli Ahmed                                             std::move(getCpuFunctionalState),
37757e8c9beSAlpana Kumari                                             service, path,
37857e8c9beSAlpana Kumari                                             "org.freedesktop.DBus."
37957e8c9beSAlpana Kumari                                             "Properties",
38057e8c9beSAlpana Kumari                                             "Get",
38157e8c9beSAlpana Kumari                                             "xyz.openbmc_project.State."
38257e8c9beSAlpana Kumari                                             "Decorator."
38357e8c9beSAlpana Kumari                                             "OperationalStatus",
38457e8c9beSAlpana Kumari                                             "Functional");
38557e8c9beSAlpana Kumari 
38657e8c9beSAlpana Kumari                                     // Get the MODEL from
38757e8c9beSAlpana Kumari                                     // xyz.openbmc_project.Inventory.Decorator.Asset
38857e8c9beSAlpana Kumari                                     // support it later as Model  is Empty
38957e8c9beSAlpana Kumari                                     // currently.
390c5b2abe0SLewanczyk, Dawid                                 },
39104a258f4SEd Tanous                                 connection.first, path,
3926c34de48SEd Tanous                                 "org.freedesktop.DBus.Properties", "GetAll",
3936c34de48SEd Tanous                                 "xyz.openbmc_project.Inventory.Item.Cpu");
3945bc2dc8eSJames Feist 
3955bc2dc8eSJames Feist                             cpuHealth->inventory.emplace_back(path);
3961abe55efSEd Tanous                         }
39704a258f4SEd Tanous                         else if (interfaceName ==
39804a258f4SEd Tanous                                  "xyz.openbmc_project.Common.UUID")
3991abe55efSEd Tanous                         {
4001abe55efSEd Tanous                             BMCWEB_LOG_DEBUG
40104a258f4SEd Tanous                                 << "Found UUID, now get its properties.";
40255c7b7a2SEd Tanous                             crow::connections::systemBus->async_method_call(
4031214b7e7SGunnar Mills                                 [aResp](
404cb13a392SEd Tanous                                     const boost::system::error_code ec3,
4056c34de48SEd Tanous                                     const std::vector<
4061214b7e7SGunnar Mills                                         std::pair<std::string, VariantType>>&
4071214b7e7SGunnar Mills                                         properties) {
408cb13a392SEd Tanous                                     if (ec3)
4091abe55efSEd Tanous                                     {
4101abe55efSEd Tanous                                         BMCWEB_LOG_DEBUG
411cb13a392SEd Tanous                                             << "DBUS response error " << ec3;
412f12894f8SJason M. Bills                                         messages::internalError(aResp->res);
413c5b2abe0SLewanczyk, Dawid                                         return;
414c5b2abe0SLewanczyk, Dawid                                     }
4156c34de48SEd Tanous                                     BMCWEB_LOG_DEBUG << "Got "
4166c34de48SEd Tanous                                                      << properties.size()
417c5b2abe0SLewanczyk, Dawid                                                      << " UUID properties.";
4181abe55efSEd Tanous                                     for (const std::pair<std::string,
4191214b7e7SGunnar Mills                                                          VariantType>&
4201214b7e7SGunnar Mills                                              property : properties)
4211abe55efSEd Tanous                                     {
42204a258f4SEd Tanous                                         if (property.first == "UUID")
4231abe55efSEd Tanous                                         {
424c5b2abe0SLewanczyk, Dawid                                             const std::string* value =
4258d78b7a9SPatrick Williams                                                 std::get_if<std::string>(
4261b6b96c5SEd Tanous                                                     &property.second);
42704a258f4SEd Tanous 
4281abe55efSEd Tanous                                             if (value != nullptr)
4291abe55efSEd Tanous                                             {
430029573d4SEd Tanous                                                 std::string valueStr = *value;
43104a258f4SEd Tanous                                                 if (valueStr.size() == 32)
4321abe55efSEd Tanous                                                 {
433029573d4SEd Tanous                                                     valueStr.insert(8, 1, '-');
434029573d4SEd Tanous                                                     valueStr.insert(13, 1, '-');
435029573d4SEd Tanous                                                     valueStr.insert(18, 1, '-');
436029573d4SEd Tanous                                                     valueStr.insert(23, 1, '-');
43704a258f4SEd Tanous                                                 }
438029573d4SEd Tanous                                                 BMCWEB_LOG_DEBUG << "UUID = "
43904a258f4SEd Tanous                                                                  << valueStr;
440029573d4SEd Tanous                                                 aResp->res.jsonValue["UUID"] =
44104a258f4SEd Tanous                                                     valueStr;
442c5b2abe0SLewanczyk, Dawid                                             }
443c5b2abe0SLewanczyk, Dawid                                         }
444c5b2abe0SLewanczyk, Dawid                                     }
445c5b2abe0SLewanczyk, Dawid                                 },
44604a258f4SEd Tanous                                 connection.first, path,
4476c34de48SEd Tanous                                 "org.freedesktop.DBus.Properties", "GetAll",
4481abe55efSEd Tanous                                 "xyz.openbmc_project.Common.UUID");
449c5b2abe0SLewanczyk, Dawid                         }
450029573d4SEd Tanous                         else if (interfaceName ==
451029573d4SEd Tanous                                  "xyz.openbmc_project.Inventory.Item.System")
4521abe55efSEd Tanous                         {
453029573d4SEd Tanous                             crow::connections::systemBus->async_method_call(
4541214b7e7SGunnar Mills                                 [aResp](
455cb13a392SEd Tanous                                     const boost::system::error_code ec2,
456029573d4SEd Tanous                                     const std::vector<
4571214b7e7SGunnar Mills                                         std::pair<std::string, VariantType>>&
4581214b7e7SGunnar Mills                                         propertiesList) {
459cb13a392SEd Tanous                                     if (ec2)
460029573d4SEd Tanous                                     {
461e4a4b9a9SJames Feist                                         // doesn't have to include this
462e4a4b9a9SJames Feist                                         // interface
463029573d4SEd Tanous                                         return;
464029573d4SEd Tanous                                     }
465698654b6SGunnar Mills                                     BMCWEB_LOG_DEBUG
466698654b6SGunnar Mills                                         << "Got " << propertiesList.size()
467029573d4SEd Tanous                                         << " properties for system";
468029573d4SEd Tanous                                     for (const std::pair<std::string,
4691214b7e7SGunnar Mills                                                          VariantType>&
4701214b7e7SGunnar Mills                                              property : propertiesList)
471029573d4SEd Tanous                                     {
472fc5afcf9Sbeccabroek                                         const std::string& propertyName =
473fc5afcf9Sbeccabroek                                             property.first;
474fc5afcf9Sbeccabroek                                         if ((propertyName == "PartNumber") ||
475fc5afcf9Sbeccabroek                                             (propertyName == "SerialNumber") ||
476fc5afcf9Sbeccabroek                                             (propertyName == "Manufacturer") ||
4775235d964SSunnySrivastava1984                                             (propertyName == "Model") ||
4785235d964SSunnySrivastava1984                                             (propertyName == "SubModel"))
479fc5afcf9Sbeccabroek                                         {
480029573d4SEd Tanous                                             const std::string* value =
481fc5afcf9Sbeccabroek                                                 std::get_if<std::string>(
482029573d4SEd Tanous                                                     &property.second);
483029573d4SEd Tanous                                             if (value != nullptr)
484029573d4SEd Tanous                                             {
485029573d4SEd Tanous                                                 aResp->res
486fc5afcf9Sbeccabroek                                                     .jsonValue[propertyName] =
487029573d4SEd Tanous                                                     *value;
488029573d4SEd Tanous                                             }
489029573d4SEd Tanous                                         }
490fc5afcf9Sbeccabroek                                     }
491c1e236a6SGunnar Mills 
492cb7e1e7bSAndrew Geissler                                     // Grab the bios version
493f97ddba7SGunnar Mills                                     fw_util::populateFirmwareInformation(
494cb7e1e7bSAndrew Geissler                                         aResp, fw_util::biosPurpose,
49572d566d9SGunnar Mills                                         "BiosVersion", false);
496029573d4SEd Tanous                                 },
497029573d4SEd Tanous                                 connection.first, path,
498029573d4SEd Tanous                                 "org.freedesktop.DBus.Properties", "GetAll",
499029573d4SEd Tanous                                 "xyz.openbmc_project.Inventory.Decorator."
500029573d4SEd Tanous                                 "Asset");
501e4a4b9a9SJames Feist 
502e4a4b9a9SJames Feist                             crow::connections::systemBus->async_method_call(
503e4a4b9a9SJames Feist                                 [aResp](
504cb13a392SEd Tanous                                     const boost::system::error_code ec2,
505e4a4b9a9SJames Feist                                     const std::variant<std::string>& property) {
506cb13a392SEd Tanous                                     if (ec2)
507e4a4b9a9SJames Feist                                     {
508e4a4b9a9SJames Feist                                         // doesn't have to include this
509e4a4b9a9SJames Feist                                         // interface
510e4a4b9a9SJames Feist                                         return;
511e4a4b9a9SJames Feist                                     }
512e4a4b9a9SJames Feist 
513e4a4b9a9SJames Feist                                     const std::string* value =
514e4a4b9a9SJames Feist                                         std::get_if<std::string>(&property);
515e4a4b9a9SJames Feist                                     if (value != nullptr)
516e4a4b9a9SJames Feist                                     {
517e4a4b9a9SJames Feist                                         aResp->res.jsonValue["AssetTag"] =
518e4a4b9a9SJames Feist                                             *value;
519e4a4b9a9SJames Feist                                     }
520e4a4b9a9SJames Feist                                 },
521e4a4b9a9SJames Feist                                 connection.first, path,
522e4a4b9a9SJames Feist                                 "org.freedesktop.DBus.Properties", "Get",
523e4a4b9a9SJames Feist                                 "xyz.openbmc_project.Inventory.Decorator."
524e4a4b9a9SJames Feist                                 "AssetTag",
525e4a4b9a9SJames Feist                                 "AssetTag");
526029573d4SEd Tanous                         }
527029573d4SEd Tanous                     }
528029573d4SEd Tanous                 }
529c5b2abe0SLewanczyk, Dawid             }
530c5b2abe0SLewanczyk, Dawid         },
531c5b2abe0SLewanczyk, Dawid         "xyz.openbmc_project.ObjectMapper",
532c5b2abe0SLewanczyk, Dawid         "/xyz/openbmc_project/object_mapper",
533c5b2abe0SLewanczyk, Dawid         "xyz.openbmc_project.ObjectMapper", "GetSubTree",
5346617338dSEd Tanous         "/xyz/openbmc_project/inventory", int32_t(0),
5356617338dSEd Tanous         std::array<const char*, 5>{
5366617338dSEd Tanous             "xyz.openbmc_project.Inventory.Decorator.Asset",
5376617338dSEd Tanous             "xyz.openbmc_project.Inventory.Item.Cpu",
5386617338dSEd Tanous             "xyz.openbmc_project.Inventory.Item.Dimm",
5396617338dSEd Tanous             "xyz.openbmc_project.Inventory.Item.System",
5406617338dSEd Tanous             "xyz.openbmc_project.Common.UUID",
5416617338dSEd Tanous         });
542c5b2abe0SLewanczyk, Dawid }
543c5b2abe0SLewanczyk, Dawid 
544c5b2abe0SLewanczyk, Dawid /**
545c5b2abe0SLewanczyk, Dawid  * @brief Retrieves host state properties over dbus
546c5b2abe0SLewanczyk, Dawid  *
547c5b2abe0SLewanczyk, Dawid  * @param[in] aResp     Shared pointer for completing asynchronous calls.
548c5b2abe0SLewanczyk, Dawid  *
549c5b2abe0SLewanczyk, Dawid  * @return None.
550c5b2abe0SLewanczyk, Dawid  */
5518d1b46d7Szhanghch05 inline void getHostState(const std::shared_ptr<bmcweb::AsyncResp>& aResp)
5521abe55efSEd Tanous {
55355c7b7a2SEd Tanous     BMCWEB_LOG_DEBUG << "Get host information.";
55455c7b7a2SEd Tanous     crow::connections::systemBus->async_method_call(
555c5d03ff4SJennifer Lee         [aResp](const boost::system::error_code ec,
556abf2add6SEd Tanous                 const std::variant<std::string>& hostState) {
5571abe55efSEd Tanous             if (ec)
5581abe55efSEd Tanous             {
55955c7b7a2SEd Tanous                 BMCWEB_LOG_DEBUG << "DBUS response error " << ec;
560f12894f8SJason M. Bills                 messages::internalError(aResp->res);
561c5b2abe0SLewanczyk, Dawid                 return;
562c5b2abe0SLewanczyk, Dawid             }
5636617338dSEd Tanous 
564abf2add6SEd Tanous             const std::string* s = std::get_if<std::string>(&hostState);
56555c7b7a2SEd Tanous             BMCWEB_LOG_DEBUG << "Host state: " << *s;
5666617338dSEd Tanous             if (s != nullptr)
5671abe55efSEd Tanous             {
568c5b2abe0SLewanczyk, Dawid                 // Verify Host State
56994732661SAndrew Geissler                 if (*s == "xyz.openbmc_project.State.Host.HostState.Running")
5701abe55efSEd Tanous                 {
57155c7b7a2SEd Tanous                     aResp->res.jsonValue["PowerState"] = "On";
5726617338dSEd Tanous                     aResp->res.jsonValue["Status"]["State"] = "Enabled";
5731abe55efSEd Tanous                 }
57483935af9SAndrew Geissler                 else if (*s == "xyz.openbmc_project.State.Host.HostState."
5758c888608SGunnar Mills                                "Quiesced")
5768c888608SGunnar Mills                 {
5778c888608SGunnar Mills                     aResp->res.jsonValue["PowerState"] = "On";
5788c888608SGunnar Mills                     aResp->res.jsonValue["Status"]["State"] = "Quiesced";
5798c888608SGunnar Mills                 }
5808c888608SGunnar Mills                 else if (*s == "xyz.openbmc_project.State.Host.HostState."
58183935af9SAndrew Geissler                                "DiagnosticMode")
58283935af9SAndrew Geissler                 {
58383935af9SAndrew Geissler                     aResp->res.jsonValue["PowerState"] = "On";
58483935af9SAndrew Geissler                     aResp->res.jsonValue["Status"]["State"] = "InTest";
58583935af9SAndrew Geissler                 }
5861a2a1437SAndrew Geissler                 else if (*s == "xyz.openbmc_project.State.Host.HostState."
5871a2a1437SAndrew Geissler                                "TransitioningToRunning")
5881a2a1437SAndrew Geissler                 {
5891a2a1437SAndrew Geissler                     aResp->res.jsonValue["PowerState"] = "PoweringOn";
59015c27bf8SNoah Brewer                     aResp->res.jsonValue["Status"]["State"] = "Starting";
5911a2a1437SAndrew Geissler                 }
5921a2a1437SAndrew Geissler                 else if (*s == "xyz.openbmc_project.State.Host.HostState."
5931a2a1437SAndrew Geissler                                "TransitioningToOff")
5941a2a1437SAndrew Geissler                 {
5951a2a1437SAndrew Geissler                     aResp->res.jsonValue["PowerState"] = "PoweringOff";
5961a2a1437SAndrew Geissler                     aResp->res.jsonValue["Status"]["State"] = "Disabled";
5971a2a1437SAndrew Geissler                 }
5981abe55efSEd Tanous                 else
5991abe55efSEd Tanous                 {
60055c7b7a2SEd Tanous                     aResp->res.jsonValue["PowerState"] = "Off";
6016617338dSEd Tanous                     aResp->res.jsonValue["Status"]["State"] = "Disabled";
602c5b2abe0SLewanczyk, Dawid                 }
603c5b2abe0SLewanczyk, Dawid             }
604c5b2abe0SLewanczyk, Dawid         },
6056c34de48SEd Tanous         "xyz.openbmc_project.State.Host", "/xyz/openbmc_project/state/host0",
6066617338dSEd Tanous         "org.freedesktop.DBus.Properties", "Get",
6076617338dSEd Tanous         "xyz.openbmc_project.State.Host", "CurrentHostState");
608c5b2abe0SLewanczyk, Dawid }
609c5b2abe0SLewanczyk, Dawid 
610c5b2abe0SLewanczyk, Dawid /**
611786d0f60SGunnar Mills  * @brief Translates boot source DBUS property value to redfish.
612491d8ee7SSantosh Puranik  *
613491d8ee7SSantosh Puranik  * @param[in] dbusSource    The boot source in DBUS speak.
614491d8ee7SSantosh Puranik  *
615491d8ee7SSantosh Puranik  * @return Returns as a string, the boot source in Redfish terms. If translation
616491d8ee7SSantosh Puranik  * cannot be done, returns an empty string.
617491d8ee7SSantosh Puranik  */
61823a21a1cSEd Tanous inline std::string dbusToRfBootSource(const std::string& dbusSource)
619491d8ee7SSantosh Puranik {
620491d8ee7SSantosh Puranik     if (dbusSource == "xyz.openbmc_project.Control.Boot.Source.Sources.Default")
621491d8ee7SSantosh Puranik     {
622491d8ee7SSantosh Puranik         return "None";
623491d8ee7SSantosh Puranik     }
6243174e4dfSEd Tanous     if (dbusSource == "xyz.openbmc_project.Control.Boot.Source.Sources.Disk")
625491d8ee7SSantosh Puranik     {
626491d8ee7SSantosh Puranik         return "Hdd";
627491d8ee7SSantosh Puranik     }
6283174e4dfSEd Tanous     if (dbusSource ==
629a71dc0b7SSantosh Puranik         "xyz.openbmc_project.Control.Boot.Source.Sources.ExternalMedia")
630491d8ee7SSantosh Puranik     {
631491d8ee7SSantosh Puranik         return "Cd";
632491d8ee7SSantosh Puranik     }
6333174e4dfSEd Tanous     if (dbusSource == "xyz.openbmc_project.Control.Boot.Source.Sources.Network")
634491d8ee7SSantosh Puranik     {
635491d8ee7SSantosh Puranik         return "Pxe";
636491d8ee7SSantosh Puranik     }
6373174e4dfSEd Tanous     if (dbusSource ==
638944ffaf9SJohnathan Mantey         "xyz.openbmc_project.Control.Boot.Source.Sources.RemovableMedia")
6399f16b2c1SJennifer Lee     {
6409f16b2c1SJennifer Lee         return "Usb";
6419f16b2c1SJennifer Lee     }
642491d8ee7SSantosh Puranik     return "";
643491d8ee7SSantosh Puranik }
644491d8ee7SSantosh Puranik 
645491d8ee7SSantosh Puranik /**
646cd9a4666SKonstantin Aladyshev  * @brief Translates boot type DBUS property value to redfish.
647cd9a4666SKonstantin Aladyshev  *
648cd9a4666SKonstantin Aladyshev  * @param[in] dbusType    The boot type in DBUS speak.
649cd9a4666SKonstantin Aladyshev  *
650cd9a4666SKonstantin Aladyshev  * @return Returns as a string, the boot type in Redfish terms. If translation
651cd9a4666SKonstantin Aladyshev  * cannot be done, returns an empty string.
652cd9a4666SKonstantin Aladyshev  */
653cd9a4666SKonstantin Aladyshev inline std::string dbusToRfBootType(const std::string& dbusType)
654cd9a4666SKonstantin Aladyshev {
655cd9a4666SKonstantin Aladyshev     if (dbusType == "xyz.openbmc_project.Control.Boot.Type.Types.Legacy")
656cd9a4666SKonstantin Aladyshev     {
657cd9a4666SKonstantin Aladyshev         return "Legacy";
658cd9a4666SKonstantin Aladyshev     }
659cd9a4666SKonstantin Aladyshev     if (dbusType == "xyz.openbmc_project.Control.Boot.Type.Types.EFI")
660cd9a4666SKonstantin Aladyshev     {
661cd9a4666SKonstantin Aladyshev         return "UEFI";
662cd9a4666SKonstantin Aladyshev     }
663cd9a4666SKonstantin Aladyshev     return "";
664cd9a4666SKonstantin Aladyshev }
665cd9a4666SKonstantin Aladyshev 
666cd9a4666SKonstantin Aladyshev /**
667786d0f60SGunnar Mills  * @brief Translates boot mode DBUS property value to redfish.
668491d8ee7SSantosh Puranik  *
669491d8ee7SSantosh Puranik  * @param[in] dbusMode    The boot mode in DBUS speak.
670491d8ee7SSantosh Puranik  *
671491d8ee7SSantosh Puranik  * @return Returns as a string, the boot mode in Redfish terms. If translation
672491d8ee7SSantosh Puranik  * cannot be done, returns an empty string.
673491d8ee7SSantosh Puranik  */
67423a21a1cSEd Tanous inline std::string dbusToRfBootMode(const std::string& dbusMode)
675491d8ee7SSantosh Puranik {
676491d8ee7SSantosh Puranik     if (dbusMode == "xyz.openbmc_project.Control.Boot.Mode.Modes.Regular")
677491d8ee7SSantosh Puranik     {
678491d8ee7SSantosh Puranik         return "None";
679491d8ee7SSantosh Puranik     }
6803174e4dfSEd Tanous     if (dbusMode == "xyz.openbmc_project.Control.Boot.Mode.Modes.Safe")
681491d8ee7SSantosh Puranik     {
682491d8ee7SSantosh Puranik         return "Diags";
683491d8ee7SSantosh Puranik     }
6843174e4dfSEd Tanous     if (dbusMode == "xyz.openbmc_project.Control.Boot.Mode.Modes.Setup")
685491d8ee7SSantosh Puranik     {
686491d8ee7SSantosh Puranik         return "BiosSetup";
687491d8ee7SSantosh Puranik     }
688491d8ee7SSantosh Puranik     return "";
689491d8ee7SSantosh Puranik }
690491d8ee7SSantosh Puranik 
691491d8ee7SSantosh Puranik /**
692786d0f60SGunnar Mills  * @brief Translates boot source from Redfish to the DBus boot paths.
693491d8ee7SSantosh Puranik  *
694491d8ee7SSantosh Puranik  * @param[in] rfSource    The boot source in Redfish.
695944ffaf9SJohnathan Mantey  * @param[out] bootSource The DBus source
696944ffaf9SJohnathan Mantey  * @param[out] bootMode   the DBus boot mode
697491d8ee7SSantosh Puranik  *
698944ffaf9SJohnathan Mantey  * @return Integer error code.
699491d8ee7SSantosh Puranik  */
7008d1b46d7Szhanghch05 inline int assignBootParameters(const std::shared_ptr<bmcweb::AsyncResp>& aResp,
701944ffaf9SJohnathan Mantey                                 const std::string& rfSource,
702944ffaf9SJohnathan Mantey                                 std::string& bootSource, std::string& bootMode)
703491d8ee7SSantosh Puranik {
704c21865c4SKonstantin Aladyshev     bootSource = "xyz.openbmc_project.Control.Boot.Source.Sources.Default";
705c21865c4SKonstantin Aladyshev     bootMode = "xyz.openbmc_project.Control.Boot.Mode.Modes.Regular";
706944ffaf9SJohnathan Mantey 
707491d8ee7SSantosh Puranik     if (rfSource == "None")
708491d8ee7SSantosh Puranik     {
709944ffaf9SJohnathan Mantey         return 0;
710491d8ee7SSantosh Puranik     }
7113174e4dfSEd Tanous     if (rfSource == "Pxe")
712491d8ee7SSantosh Puranik     {
713944ffaf9SJohnathan Mantey         bootSource = "xyz.openbmc_project.Control.Boot.Source.Sources.Network";
714944ffaf9SJohnathan Mantey     }
715944ffaf9SJohnathan Mantey     else if (rfSource == "Hdd")
716944ffaf9SJohnathan Mantey     {
717944ffaf9SJohnathan Mantey         bootSource = "xyz.openbmc_project.Control.Boot.Source.Sources.Disk";
718944ffaf9SJohnathan Mantey     }
719944ffaf9SJohnathan Mantey     else if (rfSource == "Diags")
720944ffaf9SJohnathan Mantey     {
721944ffaf9SJohnathan Mantey         bootMode = "xyz.openbmc_project.Control.Boot.Mode.Modes.Safe";
722944ffaf9SJohnathan Mantey     }
723944ffaf9SJohnathan Mantey     else if (rfSource == "Cd")
724944ffaf9SJohnathan Mantey     {
725944ffaf9SJohnathan Mantey         bootSource =
726944ffaf9SJohnathan Mantey             "xyz.openbmc_project.Control.Boot.Source.Sources.ExternalMedia";
727944ffaf9SJohnathan Mantey     }
728944ffaf9SJohnathan Mantey     else if (rfSource == "BiosSetup")
729944ffaf9SJohnathan Mantey     {
730944ffaf9SJohnathan Mantey         bootMode = "xyz.openbmc_project.Control.Boot.Mode.Modes.Setup";
731491d8ee7SSantosh Puranik     }
7329f16b2c1SJennifer Lee     else if (rfSource == "Usb")
7339f16b2c1SJennifer Lee     {
734944ffaf9SJohnathan Mantey         bootSource =
735944ffaf9SJohnathan Mantey             "xyz.openbmc_project.Control.Boot.Source.Sources.RemovableMedia";
7369f16b2c1SJennifer Lee     }
737491d8ee7SSantosh Puranik     else
738491d8ee7SSantosh Puranik     {
739944ffaf9SJohnathan Mantey         BMCWEB_LOG_DEBUG << "Invalid property value for "
740944ffaf9SJohnathan Mantey                             "BootSourceOverrideTarget: "
741944ffaf9SJohnathan Mantey                          << bootSource;
742944ffaf9SJohnathan Mantey         messages::propertyValueNotInList(aResp->res, rfSource,
743944ffaf9SJohnathan Mantey                                          "BootSourceTargetOverride");
744944ffaf9SJohnathan Mantey         return -1;
745491d8ee7SSantosh Puranik     }
746944ffaf9SJohnathan Mantey     return 0;
747491d8ee7SSantosh Puranik }
7481981771bSAli Ahmed 
749978b8803SAndrew Geissler /**
750978b8803SAndrew Geissler  * @brief Retrieves boot progress of the system
751978b8803SAndrew Geissler  *
752978b8803SAndrew Geissler  * @param[in] aResp  Shared pointer for generating response message.
753978b8803SAndrew Geissler  *
754978b8803SAndrew Geissler  * @return None.
755978b8803SAndrew Geissler  */
7568d1b46d7Szhanghch05 inline void getBootProgress(const std::shared_ptr<bmcweb::AsyncResp>& aResp)
757978b8803SAndrew Geissler {
758978b8803SAndrew Geissler     crow::connections::systemBus->async_method_call(
759978b8803SAndrew Geissler         [aResp](const boost::system::error_code ec,
760978b8803SAndrew Geissler                 const std::variant<std::string>& bootProgress) {
761978b8803SAndrew Geissler             if (ec)
762978b8803SAndrew Geissler             {
763978b8803SAndrew Geissler                 // BootProgress is an optional object so just do nothing if
764978b8803SAndrew Geissler                 // not found
765978b8803SAndrew Geissler                 return;
766978b8803SAndrew Geissler             }
767978b8803SAndrew Geissler 
768978b8803SAndrew Geissler             const std::string* bootProgressStr =
769978b8803SAndrew Geissler                 std::get_if<std::string>(&bootProgress);
770978b8803SAndrew Geissler 
771978b8803SAndrew Geissler             if (!bootProgressStr)
772978b8803SAndrew Geissler             {
773978b8803SAndrew Geissler                 // Interface implemented but property not found, return error
774978b8803SAndrew Geissler                 // for that
775978b8803SAndrew Geissler                 messages::internalError(aResp->res);
776978b8803SAndrew Geissler                 return;
777978b8803SAndrew Geissler             }
778978b8803SAndrew Geissler 
779978b8803SAndrew Geissler             BMCWEB_LOG_DEBUG << "Boot Progress: " << *bootProgressStr;
780978b8803SAndrew Geissler 
781978b8803SAndrew Geissler             // Now convert the D-Bus BootProgress to the appropriate Redfish
782978b8803SAndrew Geissler             // enum
783978b8803SAndrew Geissler             std::string rfBpLastState = "None";
784978b8803SAndrew Geissler             if (*bootProgressStr == "xyz.openbmc_project.State.Boot.Progress."
785978b8803SAndrew Geissler                                     "ProgressStages.Unspecified")
786978b8803SAndrew Geissler             {
787978b8803SAndrew Geissler                 rfBpLastState = "None";
788978b8803SAndrew Geissler             }
789978b8803SAndrew Geissler             else if (*bootProgressStr ==
790978b8803SAndrew Geissler                      "xyz.openbmc_project.State.Boot.Progress.ProgressStages."
791978b8803SAndrew Geissler                      "PrimaryProcInit")
792978b8803SAndrew Geissler             {
793978b8803SAndrew Geissler                 rfBpLastState = "PrimaryProcessorInitializationStarted";
794978b8803SAndrew Geissler             }
795978b8803SAndrew Geissler             else if (*bootProgressStr ==
796978b8803SAndrew Geissler                      "xyz.openbmc_project.State.Boot.Progress.ProgressStages."
797978b8803SAndrew Geissler                      "BusInit")
798978b8803SAndrew Geissler             {
799978b8803SAndrew Geissler                 rfBpLastState = "BusInitializationStarted";
800978b8803SAndrew Geissler             }
801978b8803SAndrew Geissler             else if (*bootProgressStr ==
802978b8803SAndrew Geissler                      "xyz.openbmc_project.State.Boot.Progress.ProgressStages."
803978b8803SAndrew Geissler                      "MemoryInit")
804978b8803SAndrew Geissler             {
805978b8803SAndrew Geissler                 rfBpLastState = "MemoryInitializationStarted";
806978b8803SAndrew Geissler             }
807978b8803SAndrew Geissler             else if (*bootProgressStr ==
808978b8803SAndrew Geissler                      "xyz.openbmc_project.State.Boot.Progress.ProgressStages."
809978b8803SAndrew Geissler                      "SecondaryProcInit")
810978b8803SAndrew Geissler             {
811978b8803SAndrew Geissler                 rfBpLastState = "SecondaryProcessorInitializationStarted";
812978b8803SAndrew Geissler             }
813978b8803SAndrew Geissler             else if (*bootProgressStr ==
814978b8803SAndrew Geissler                      "xyz.openbmc_project.State.Boot.Progress.ProgressStages."
815978b8803SAndrew Geissler                      "PCIInit")
816978b8803SAndrew Geissler             {
817978b8803SAndrew Geissler                 rfBpLastState = "PCIResourceConfigStarted";
818978b8803SAndrew Geissler             }
819978b8803SAndrew Geissler             else if (*bootProgressStr ==
820978b8803SAndrew Geissler                      "xyz.openbmc_project.State.Boot.Progress.ProgressStages."
821978b8803SAndrew Geissler                      "SystemInitComplete")
822978b8803SAndrew Geissler             {
823978b8803SAndrew Geissler                 rfBpLastState = "SystemHardwareInitializationComplete";
824978b8803SAndrew Geissler             }
825978b8803SAndrew Geissler             else if (*bootProgressStr ==
826978b8803SAndrew Geissler                      "xyz.openbmc_project.State.Boot.Progress.ProgressStages."
827978b8803SAndrew Geissler                      "OSStart")
828978b8803SAndrew Geissler             {
829978b8803SAndrew Geissler                 rfBpLastState = "OSBootStarted";
830978b8803SAndrew Geissler             }
831978b8803SAndrew Geissler             else if (*bootProgressStr ==
832978b8803SAndrew Geissler                      "xyz.openbmc_project.State.Boot.Progress.ProgressStages."
833978b8803SAndrew Geissler                      "OSRunning")
834978b8803SAndrew Geissler             {
835978b8803SAndrew Geissler                 rfBpLastState = "OSRunning";
836978b8803SAndrew Geissler             }
837978b8803SAndrew Geissler             else
838978b8803SAndrew Geissler             {
839978b8803SAndrew Geissler                 BMCWEB_LOG_DEBUG << "Unsupported D-Bus BootProgress "
840978b8803SAndrew Geissler                                  << *bootProgressStr;
841978b8803SAndrew Geissler                 // Just return the default
842978b8803SAndrew Geissler             }
843978b8803SAndrew Geissler 
844978b8803SAndrew Geissler             aResp->res.jsonValue["BootProgress"]["LastState"] = rfBpLastState;
845978b8803SAndrew Geissler         },
846978b8803SAndrew Geissler         "xyz.openbmc_project.State.Host", "/xyz/openbmc_project/state/host0",
847978b8803SAndrew Geissler         "org.freedesktop.DBus.Properties", "Get",
848978b8803SAndrew Geissler         "xyz.openbmc_project.State.Boot.Progress", "BootProgress");
849978b8803SAndrew Geissler }
850491d8ee7SSantosh Puranik 
851491d8ee7SSantosh Puranik /**
852c21865c4SKonstantin Aladyshev  * @brief Retrieves boot override type over DBUS and fills out the response
853cd9a4666SKonstantin Aladyshev  *
854cd9a4666SKonstantin Aladyshev  * @param[in] aResp         Shared pointer for generating response message.
855cd9a4666SKonstantin Aladyshev  *
856cd9a4666SKonstantin Aladyshev  * @return None.
857cd9a4666SKonstantin Aladyshev  */
858cd9a4666SKonstantin Aladyshev 
859c21865c4SKonstantin Aladyshev inline void getBootOverrideType(const std::shared_ptr<bmcweb::AsyncResp>& aResp)
860cd9a4666SKonstantin Aladyshev {
861cd9a4666SKonstantin Aladyshev     crow::connections::systemBus->async_method_call(
862cd9a4666SKonstantin Aladyshev         [aResp](const boost::system::error_code ec,
863cd9a4666SKonstantin Aladyshev                 const std::variant<std::string>& bootType) {
864cd9a4666SKonstantin Aladyshev             if (ec)
865cd9a4666SKonstantin Aladyshev             {
866cd9a4666SKonstantin Aladyshev                 // not an error, don't have to have the interface
867cd9a4666SKonstantin Aladyshev                 return;
868cd9a4666SKonstantin Aladyshev             }
869cd9a4666SKonstantin Aladyshev 
870cd9a4666SKonstantin Aladyshev             const std::string* bootTypeStr =
871cd9a4666SKonstantin Aladyshev                 std::get_if<std::string>(&bootType);
872cd9a4666SKonstantin Aladyshev 
873cd9a4666SKonstantin Aladyshev             if (!bootTypeStr)
874cd9a4666SKonstantin Aladyshev             {
875cd9a4666SKonstantin Aladyshev                 messages::internalError(aResp->res);
876cd9a4666SKonstantin Aladyshev                 return;
877cd9a4666SKonstantin Aladyshev             }
878cd9a4666SKonstantin Aladyshev 
879cd9a4666SKonstantin Aladyshev             BMCWEB_LOG_DEBUG << "Boot type: " << *bootTypeStr;
880cd9a4666SKonstantin Aladyshev 
881cd9a4666SKonstantin Aladyshev             aResp->res.jsonValue["Boot"]["BootSourceOverrideMode@Redfish."
882cd9a4666SKonstantin Aladyshev                                          "AllowableValues"] = {"Legacy",
883cd9a4666SKonstantin Aladyshev                                                                "UEFI"};
884cd9a4666SKonstantin Aladyshev 
885cd9a4666SKonstantin Aladyshev             auto rfType = dbusToRfBootType(*bootTypeStr);
886cd9a4666SKonstantin Aladyshev             if (rfType.empty())
887cd9a4666SKonstantin Aladyshev             {
888cd9a4666SKonstantin Aladyshev                 messages::internalError(aResp->res);
889cd9a4666SKonstantin Aladyshev                 return;
890cd9a4666SKonstantin Aladyshev             }
891cd9a4666SKonstantin Aladyshev 
892cd9a4666SKonstantin Aladyshev             aResp->res.jsonValue["Boot"]["BootSourceOverrideMode"] = rfType;
893cd9a4666SKonstantin Aladyshev         },
894c21865c4SKonstantin Aladyshev         "xyz.openbmc_project.Settings",
895c21865c4SKonstantin Aladyshev         "/xyz/openbmc_project/control/host0/boot",
896cd9a4666SKonstantin Aladyshev         "org.freedesktop.DBus.Properties", "Get",
897cd9a4666SKonstantin Aladyshev         "xyz.openbmc_project.Control.Boot.Type", "BootType");
898cd9a4666SKonstantin Aladyshev }
899cd9a4666SKonstantin Aladyshev 
900cd9a4666SKonstantin Aladyshev /**
901c21865c4SKonstantin Aladyshev  * @brief Retrieves boot override mode over DBUS and fills out the response
902491d8ee7SSantosh Puranik  *
903491d8ee7SSantosh Puranik  * @param[in] aResp         Shared pointer for generating response message.
904491d8ee7SSantosh Puranik  *
905491d8ee7SSantosh Puranik  * @return None.
906491d8ee7SSantosh Puranik  */
907c21865c4SKonstantin Aladyshev 
908c21865c4SKonstantin Aladyshev inline void getBootOverrideMode(const std::shared_ptr<bmcweb::AsyncResp>& aResp)
909491d8ee7SSantosh Puranik {
910491d8ee7SSantosh Puranik     crow::connections::systemBus->async_method_call(
911c21865c4SKonstantin Aladyshev         [aResp](const boost::system::error_code ec,
912491d8ee7SSantosh Puranik                 const std::variant<std::string>& bootMode) {
913491d8ee7SSantosh Puranik             if (ec)
914491d8ee7SSantosh Puranik             {
915491d8ee7SSantosh Puranik                 BMCWEB_LOG_DEBUG << "DBUS response error " << ec;
916491d8ee7SSantosh Puranik                 messages::internalError(aResp->res);
917491d8ee7SSantosh Puranik                 return;
918491d8ee7SSantosh Puranik             }
919491d8ee7SSantosh Puranik 
920491d8ee7SSantosh Puranik             const std::string* bootModeStr =
921491d8ee7SSantosh Puranik                 std::get_if<std::string>(&bootMode);
922491d8ee7SSantosh Puranik 
923491d8ee7SSantosh Puranik             if (!bootModeStr)
924491d8ee7SSantosh Puranik             {
925491d8ee7SSantosh Puranik                 messages::internalError(aResp->res);
926491d8ee7SSantosh Puranik                 return;
927491d8ee7SSantosh Puranik             }
928491d8ee7SSantosh Puranik 
929491d8ee7SSantosh Puranik             BMCWEB_LOG_DEBUG << "Boot mode: " << *bootModeStr;
930491d8ee7SSantosh Puranik 
931491d8ee7SSantosh Puranik             aResp->res.jsonValue["Boot"]["BootSourceOverrideTarget@Redfish."
932491d8ee7SSantosh Puranik                                          "AllowableValues"] = {
933944ffaf9SJohnathan Mantey                 "None", "Pxe", "Hdd", "Cd", "Diags", "BiosSetup", "Usb"};
934491d8ee7SSantosh Puranik 
935491d8ee7SSantosh Puranik             if (*bootModeStr !=
936491d8ee7SSantosh Puranik                 "xyz.openbmc_project.Control.Boot.Mode.Modes.Regular")
937491d8ee7SSantosh Puranik             {
938491d8ee7SSantosh Puranik                 auto rfMode = dbusToRfBootMode(*bootModeStr);
939491d8ee7SSantosh Puranik                 if (!rfMode.empty())
940491d8ee7SSantosh Puranik                 {
941491d8ee7SSantosh Puranik                     aResp->res.jsonValue["Boot"]["BootSourceOverrideTarget"] =
942491d8ee7SSantosh Puranik                         rfMode;
943491d8ee7SSantosh Puranik                 }
944491d8ee7SSantosh Puranik             }
945491d8ee7SSantosh Puranik         },
946c21865c4SKonstantin Aladyshev         "xyz.openbmc_project.Settings",
947c21865c4SKonstantin Aladyshev         "/xyz/openbmc_project/control/host0/boot",
948491d8ee7SSantosh Puranik         "org.freedesktop.DBus.Properties", "Get",
949491d8ee7SSantosh Puranik         "xyz.openbmc_project.Control.Boot.Mode", "BootMode");
950491d8ee7SSantosh Puranik }
951491d8ee7SSantosh Puranik 
952491d8ee7SSantosh Puranik /**
953c21865c4SKonstantin Aladyshev  * @brief Retrieves boot override source over DBUS
954491d8ee7SSantosh Puranik  *
955491d8ee7SSantosh Puranik  * @param[in] aResp         Shared pointer for generating response message.
956491d8ee7SSantosh Puranik  *
957491d8ee7SSantosh Puranik  * @return None.
958491d8ee7SSantosh Puranik  */
959c21865c4SKonstantin Aladyshev 
960c21865c4SKonstantin Aladyshev inline void
961c21865c4SKonstantin Aladyshev     getBootOverrideSource(const std::shared_ptr<bmcweb::AsyncResp>& aResp)
962491d8ee7SSantosh Puranik {
963491d8ee7SSantosh Puranik     crow::connections::systemBus->async_method_call(
964c21865c4SKonstantin Aladyshev         [aResp](const boost::system::error_code ec,
965491d8ee7SSantosh Puranik                 const std::variant<std::string>& bootSource) {
966491d8ee7SSantosh Puranik             if (ec)
967491d8ee7SSantosh Puranik             {
968491d8ee7SSantosh Puranik                 BMCWEB_LOG_DEBUG << "DBUS response error " << ec;
969491d8ee7SSantosh Puranik                 messages::internalError(aResp->res);
970491d8ee7SSantosh Puranik                 return;
971491d8ee7SSantosh Puranik             }
972491d8ee7SSantosh Puranik 
973491d8ee7SSantosh Puranik             const std::string* bootSourceStr =
974491d8ee7SSantosh Puranik                 std::get_if<std::string>(&bootSource);
975491d8ee7SSantosh Puranik 
976491d8ee7SSantosh Puranik             if (!bootSourceStr)
977491d8ee7SSantosh Puranik             {
978491d8ee7SSantosh Puranik                 messages::internalError(aResp->res);
979491d8ee7SSantosh Puranik                 return;
980491d8ee7SSantosh Puranik             }
981491d8ee7SSantosh Puranik             BMCWEB_LOG_DEBUG << "Boot source: " << *bootSourceStr;
982491d8ee7SSantosh Puranik 
983491d8ee7SSantosh Puranik             auto rfSource = dbusToRfBootSource(*bootSourceStr);
984491d8ee7SSantosh Puranik             if (!rfSource.empty())
985491d8ee7SSantosh Puranik             {
986491d8ee7SSantosh Puranik                 aResp->res.jsonValue["Boot"]["BootSourceOverrideTarget"] =
987491d8ee7SSantosh Puranik                     rfSource;
988491d8ee7SSantosh Puranik             }
989cd9a4666SKonstantin Aladyshev 
990cd9a4666SKonstantin Aladyshev             // Get BootMode as BootSourceOverrideTarget is constructed
991cd9a4666SKonstantin Aladyshev             // from both BootSource and BootMode
992c21865c4SKonstantin Aladyshev             getBootOverrideMode(aResp);
993491d8ee7SSantosh Puranik         },
994c21865c4SKonstantin Aladyshev         "xyz.openbmc_project.Settings",
995c21865c4SKonstantin Aladyshev         "/xyz/openbmc_project/control/host0/boot",
996491d8ee7SSantosh Puranik         "org.freedesktop.DBus.Properties", "Get",
997491d8ee7SSantosh Puranik         "xyz.openbmc_project.Control.Boot.Source", "BootSource");
998491d8ee7SSantosh Puranik }
999491d8ee7SSantosh Puranik 
1000491d8ee7SSantosh Puranik /**
1001c21865c4SKonstantin Aladyshev  * @brief This functions abstracts all the logic behind getting a
1002c21865c4SKonstantin Aladyshev  * "BootSourceOverrideEnabled" property from an overall boot override enable
1003c21865c4SKonstantin Aladyshev  * state
1004491d8ee7SSantosh Puranik  *
1005491d8ee7SSantosh Puranik  * @param[in] aResp     Shared pointer for generating response message.
1006491d8ee7SSantosh Puranik  *
1007491d8ee7SSantosh Puranik  * @return None.
1008491d8ee7SSantosh Puranik  */
1009491d8ee7SSantosh Puranik 
1010c21865c4SKonstantin Aladyshev inline void
1011c21865c4SKonstantin Aladyshev     processBootOverrideEnable(const std::shared_ptr<bmcweb::AsyncResp>& aResp,
1012c21865c4SKonstantin Aladyshev                               const bool bootOverrideEnableSetting)
1013c21865c4SKonstantin Aladyshev {
1014c21865c4SKonstantin Aladyshev     if (!bootOverrideEnableSetting)
1015c21865c4SKonstantin Aladyshev     {
1016c21865c4SKonstantin Aladyshev         aResp->res.jsonValue["Boot"]["BootSourceOverrideEnabled"] = "Disabled";
1017c21865c4SKonstantin Aladyshev         return;
1018c21865c4SKonstantin Aladyshev     }
1019c21865c4SKonstantin Aladyshev 
1020c21865c4SKonstantin Aladyshev     // If boot source override is enabled, we need to check 'one_time'
1021c21865c4SKonstantin Aladyshev     // property to set a correct value for the "BootSourceOverrideEnabled"
1022491d8ee7SSantosh Puranik     crow::connections::systemBus->async_method_call(
1023c5d03ff4SJennifer Lee         [aResp](const boost::system::error_code ec,
102419bd78d9SPatrick Williams                 const std::variant<bool>& oneTime) {
1025491d8ee7SSantosh Puranik             if (ec)
1026491d8ee7SSantosh Puranik             {
1027491d8ee7SSantosh Puranik                 BMCWEB_LOG_DEBUG << "DBUS response error " << ec;
1028c21865c4SKonstantin Aladyshev                 messages::internalError(aResp->res);
1029491d8ee7SSantosh Puranik                 return;
1030491d8ee7SSantosh Puranik             }
1031491d8ee7SSantosh Puranik 
1032491d8ee7SSantosh Puranik             const bool* oneTimePtr = std::get_if<bool>(&oneTime);
1033491d8ee7SSantosh Puranik 
1034491d8ee7SSantosh Puranik             if (!oneTimePtr)
1035491d8ee7SSantosh Puranik             {
1036491d8ee7SSantosh Puranik                 messages::internalError(aResp->res);
1037491d8ee7SSantosh Puranik                 return;
1038491d8ee7SSantosh Puranik             }
1039c21865c4SKonstantin Aladyshev 
1040c21865c4SKonstantin Aladyshev             bool oneTimeSetting = *oneTimePtr;
1041c21865c4SKonstantin Aladyshev 
1042c21865c4SKonstantin Aladyshev             if (oneTimeSetting)
1043c21865c4SKonstantin Aladyshev             {
1044c21865c4SKonstantin Aladyshev                 aResp->res.jsonValue["Boot"]["BootSourceOverrideEnabled"] =
1045c21865c4SKonstantin Aladyshev                     "Once";
1046c21865c4SKonstantin Aladyshev             }
1047c21865c4SKonstantin Aladyshev             else
1048c21865c4SKonstantin Aladyshev             {
1049c21865c4SKonstantin Aladyshev                 aResp->res.jsonValue["Boot"]["BootSourceOverrideEnabled"] =
1050c21865c4SKonstantin Aladyshev                     "Continuous";
1051c21865c4SKonstantin Aladyshev             }
1052491d8ee7SSantosh Puranik         },
1053491d8ee7SSantosh Puranik         "xyz.openbmc_project.Settings",
1054491d8ee7SSantosh Puranik         "/xyz/openbmc_project/control/host0/boot/one_time",
1055491d8ee7SSantosh Puranik         "org.freedesktop.DBus.Properties", "Get",
1056491d8ee7SSantosh Puranik         "xyz.openbmc_project.Object.Enable", "Enabled");
1057491d8ee7SSantosh Puranik }
1058491d8ee7SSantosh Puranik 
1059491d8ee7SSantosh Puranik /**
1060c21865c4SKonstantin Aladyshev  * @brief Retrieves boot override enable over DBUS
1061c21865c4SKonstantin Aladyshev  *
1062c21865c4SKonstantin Aladyshev  * @param[in] aResp     Shared pointer for generating response message.
1063c21865c4SKonstantin Aladyshev  *
1064c21865c4SKonstantin Aladyshev  * @return None.
1065c21865c4SKonstantin Aladyshev  */
1066c21865c4SKonstantin Aladyshev 
1067c21865c4SKonstantin Aladyshev inline void
1068c21865c4SKonstantin Aladyshev     getBootOverrideEnable(const std::shared_ptr<bmcweb::AsyncResp>& aResp)
1069c21865c4SKonstantin Aladyshev {
1070c21865c4SKonstantin Aladyshev     crow::connections::systemBus->async_method_call(
1071c21865c4SKonstantin Aladyshev         [aResp](const boost::system::error_code ec,
1072c21865c4SKonstantin Aladyshev                 const std::variant<bool>& bootOverrideEnable) {
1073c21865c4SKonstantin Aladyshev             if (ec)
1074c21865c4SKonstantin Aladyshev             {
1075c21865c4SKonstantin Aladyshev                 BMCWEB_LOG_DEBUG << "DBUS response error " << ec;
1076c21865c4SKonstantin Aladyshev                 messages::internalError(aResp->res);
1077c21865c4SKonstantin Aladyshev                 return;
1078c21865c4SKonstantin Aladyshev             }
1079c21865c4SKonstantin Aladyshev 
1080c21865c4SKonstantin Aladyshev             const bool* bootOverrideEnablePtr =
1081c21865c4SKonstantin Aladyshev                 std::get_if<bool>(&bootOverrideEnable);
1082c21865c4SKonstantin Aladyshev 
1083c21865c4SKonstantin Aladyshev             if (!bootOverrideEnablePtr)
1084c21865c4SKonstantin Aladyshev             {
1085c21865c4SKonstantin Aladyshev                 messages::internalError(aResp->res);
1086c21865c4SKonstantin Aladyshev                 return;
1087c21865c4SKonstantin Aladyshev             }
1088c21865c4SKonstantin Aladyshev 
1089c21865c4SKonstantin Aladyshev             processBootOverrideEnable(aResp, *bootOverrideEnablePtr);
1090c21865c4SKonstantin Aladyshev         },
1091c21865c4SKonstantin Aladyshev         "xyz.openbmc_project.Settings",
1092c21865c4SKonstantin Aladyshev         "/xyz/openbmc_project/control/host0/boot",
1093c21865c4SKonstantin Aladyshev         "org.freedesktop.DBus.Properties", "Get",
1094c21865c4SKonstantin Aladyshev         "xyz.openbmc_project.Object.Enable", "Enabled");
1095c21865c4SKonstantin Aladyshev }
1096c21865c4SKonstantin Aladyshev 
1097c21865c4SKonstantin Aladyshev /**
1098c21865c4SKonstantin Aladyshev  * @brief Retrieves boot source override properties
1099c21865c4SKonstantin Aladyshev  *
1100c21865c4SKonstantin Aladyshev  * @param[in] aResp     Shared pointer for generating response message.
1101c21865c4SKonstantin Aladyshev  *
1102c21865c4SKonstantin Aladyshev  * @return None.
1103c21865c4SKonstantin Aladyshev  */
1104c21865c4SKonstantin Aladyshev inline void getBootProperties(const std::shared_ptr<bmcweb::AsyncResp>& aResp)
1105c21865c4SKonstantin Aladyshev {
1106c21865c4SKonstantin Aladyshev     BMCWEB_LOG_DEBUG << "Get boot information.";
1107c21865c4SKonstantin Aladyshev 
1108c21865c4SKonstantin Aladyshev     getBootOverrideSource(aResp);
1109c21865c4SKonstantin Aladyshev     getBootOverrideType(aResp);
1110c21865c4SKonstantin Aladyshev     getBootOverrideEnable(aResp);
1111c21865c4SKonstantin Aladyshev }
1112c21865c4SKonstantin Aladyshev 
1113c21865c4SKonstantin Aladyshev /**
1114c0557e1aSGunnar Mills  * @brief Retrieves the Last Reset Time
1115c0557e1aSGunnar Mills  *
1116c0557e1aSGunnar Mills  * "Reset" is an overloaded term in Redfish, "Reset" includes power on
1117c0557e1aSGunnar Mills  * and power off. Even though this is the "system" Redfish object look at the
1118c0557e1aSGunnar Mills  * chassis D-Bus interface for the LastStateChangeTime since this has the
1119c0557e1aSGunnar Mills  * last power operation time.
1120c0557e1aSGunnar Mills  *
1121c0557e1aSGunnar Mills  * @param[in] aResp     Shared pointer for generating response message.
1122c0557e1aSGunnar Mills  *
1123c0557e1aSGunnar Mills  * @return None.
1124c0557e1aSGunnar Mills  */
11258d1b46d7Szhanghch05 inline void getLastResetTime(const std::shared_ptr<bmcweb::AsyncResp>& aResp)
1126c0557e1aSGunnar Mills {
1127c0557e1aSGunnar Mills     BMCWEB_LOG_DEBUG << "Getting System Last Reset Time";
1128c0557e1aSGunnar Mills 
1129c0557e1aSGunnar Mills     crow::connections::systemBus->async_method_call(
1130c0557e1aSGunnar Mills         [aResp](const boost::system::error_code ec,
1131c0557e1aSGunnar Mills                 std::variant<uint64_t>& lastResetTime) {
1132c0557e1aSGunnar Mills             if (ec)
1133c0557e1aSGunnar Mills             {
1134c0557e1aSGunnar Mills                 BMCWEB_LOG_DEBUG << "D-BUS response error " << ec;
1135c0557e1aSGunnar Mills                 return;
1136c0557e1aSGunnar Mills             }
1137c0557e1aSGunnar Mills 
1138c0557e1aSGunnar Mills             const uint64_t* lastResetTimePtr =
1139c0557e1aSGunnar Mills                 std::get_if<uint64_t>(&lastResetTime);
1140c0557e1aSGunnar Mills 
1141c0557e1aSGunnar Mills             if (!lastResetTimePtr)
1142c0557e1aSGunnar Mills             {
1143c0557e1aSGunnar Mills                 messages::internalError(aResp->res);
1144c0557e1aSGunnar Mills                 return;
1145c0557e1aSGunnar Mills             }
1146c0557e1aSGunnar Mills             // LastStateChangeTime is epoch time, in milliseconds
1147c0557e1aSGunnar Mills             // https://github.com/openbmc/phosphor-dbus-interfaces/blob/33e8e1dd64da53a66e888d33dc82001305cd0bf9/xyz/openbmc_project/State/Chassis.interface.yaml#L19
1148c0557e1aSGunnar Mills             time_t lastResetTimeStamp =
1149c0557e1aSGunnar Mills                 static_cast<time_t>(*lastResetTimePtr / 1000);
1150c0557e1aSGunnar Mills 
1151c0557e1aSGunnar Mills             // Convert to ISO 8601 standard
1152c0557e1aSGunnar Mills             aResp->res.jsonValue["LastResetTime"] =
1153c0557e1aSGunnar Mills                 crow::utility::getDateTime(lastResetTimeStamp);
1154c0557e1aSGunnar Mills         },
1155c0557e1aSGunnar Mills         "xyz.openbmc_project.State.Chassis",
1156c0557e1aSGunnar Mills         "/xyz/openbmc_project/state/chassis0",
1157c0557e1aSGunnar Mills         "org.freedesktop.DBus.Properties", "Get",
1158c0557e1aSGunnar Mills         "xyz.openbmc_project.State.Chassis", "LastStateChangeTime");
1159c0557e1aSGunnar Mills }
1160c0557e1aSGunnar Mills 
1161c0557e1aSGunnar Mills /**
11626bd5a8d2SGunnar Mills  * @brief Retrieves Automatic Retry properties. Known on D-Bus as AutoReboot.
11636bd5a8d2SGunnar Mills  *
11646bd5a8d2SGunnar Mills  * @param[in] aResp     Shared pointer for generating response message.
11656bd5a8d2SGunnar Mills  *
11666bd5a8d2SGunnar Mills  * @return None.
11676bd5a8d2SGunnar Mills  */
11688d1b46d7Szhanghch05 inline void getAutomaticRetry(const std::shared_ptr<bmcweb::AsyncResp>& aResp)
11696bd5a8d2SGunnar Mills {
11706bd5a8d2SGunnar Mills     BMCWEB_LOG_DEBUG << "Get Automatic Retry policy";
11716bd5a8d2SGunnar Mills 
11726bd5a8d2SGunnar Mills     crow::connections::systemBus->async_method_call(
11736bd5a8d2SGunnar Mills         [aResp](const boost::system::error_code ec,
11746bd5a8d2SGunnar Mills                 std::variant<bool>& autoRebootEnabled) {
11756bd5a8d2SGunnar Mills             if (ec)
11766bd5a8d2SGunnar Mills             {
11776bd5a8d2SGunnar Mills                 BMCWEB_LOG_DEBUG << "D-BUS response error " << ec;
11786bd5a8d2SGunnar Mills                 return;
11796bd5a8d2SGunnar Mills             }
11806bd5a8d2SGunnar Mills 
11816bd5a8d2SGunnar Mills             const bool* autoRebootEnabledPtr =
11826bd5a8d2SGunnar Mills                 std::get_if<bool>(&autoRebootEnabled);
11836bd5a8d2SGunnar Mills 
11846bd5a8d2SGunnar Mills             if (!autoRebootEnabledPtr)
11856bd5a8d2SGunnar Mills             {
11866bd5a8d2SGunnar Mills                 messages::internalError(aResp->res);
11876bd5a8d2SGunnar Mills                 return;
11886bd5a8d2SGunnar Mills             }
11896bd5a8d2SGunnar Mills 
11906bd5a8d2SGunnar Mills             BMCWEB_LOG_DEBUG << "Auto Reboot: " << *autoRebootEnabledPtr;
11916bd5a8d2SGunnar Mills             if (*autoRebootEnabledPtr == true)
11926bd5a8d2SGunnar Mills             {
11936bd5a8d2SGunnar Mills                 aResp->res.jsonValue["Boot"]["AutomaticRetryConfig"] =
11946bd5a8d2SGunnar Mills                     "RetryAttempts";
11956bd5a8d2SGunnar Mills                 // If AutomaticRetry (AutoReboot) is enabled see how many
11966bd5a8d2SGunnar Mills                 // attempts are left
11976bd5a8d2SGunnar Mills                 crow::connections::systemBus->async_method_call(
1198cb13a392SEd Tanous                     [aResp](const boost::system::error_code ec2,
11996bd5a8d2SGunnar Mills                             std::variant<uint32_t>& autoRebootAttemptsLeft) {
1200cb13a392SEd Tanous                         if (ec2)
12016bd5a8d2SGunnar Mills                         {
1202cb13a392SEd Tanous                             BMCWEB_LOG_DEBUG << "D-BUS response error " << ec2;
12036bd5a8d2SGunnar Mills                             return;
12046bd5a8d2SGunnar Mills                         }
12056bd5a8d2SGunnar Mills 
12066bd5a8d2SGunnar Mills                         const uint32_t* autoRebootAttemptsLeftPtr =
12076bd5a8d2SGunnar Mills                             std::get_if<uint32_t>(&autoRebootAttemptsLeft);
12086bd5a8d2SGunnar Mills 
12096bd5a8d2SGunnar Mills                         if (!autoRebootAttemptsLeftPtr)
12106bd5a8d2SGunnar Mills                         {
12116bd5a8d2SGunnar Mills                             messages::internalError(aResp->res);
12126bd5a8d2SGunnar Mills                             return;
12136bd5a8d2SGunnar Mills                         }
12146bd5a8d2SGunnar Mills 
12156bd5a8d2SGunnar Mills                         BMCWEB_LOG_DEBUG << "Auto Reboot Attempts Left: "
12166bd5a8d2SGunnar Mills                                          << *autoRebootAttemptsLeftPtr;
12176bd5a8d2SGunnar Mills 
12186bd5a8d2SGunnar Mills                         aResp->res
12196bd5a8d2SGunnar Mills                             .jsonValue["Boot"]
12206bd5a8d2SGunnar Mills                                       ["RemainingAutomaticRetryAttempts"] =
12216bd5a8d2SGunnar Mills                             *autoRebootAttemptsLeftPtr;
12226bd5a8d2SGunnar Mills                     },
12236bd5a8d2SGunnar Mills                     "xyz.openbmc_project.State.Host",
12246bd5a8d2SGunnar Mills                     "/xyz/openbmc_project/state/host0",
12256bd5a8d2SGunnar Mills                     "org.freedesktop.DBus.Properties", "Get",
12266bd5a8d2SGunnar Mills                     "xyz.openbmc_project.Control.Boot.RebootAttempts",
12276bd5a8d2SGunnar Mills                     "AttemptsLeft");
12286bd5a8d2SGunnar Mills             }
12296bd5a8d2SGunnar Mills             else
12306bd5a8d2SGunnar Mills             {
12316bd5a8d2SGunnar Mills                 aResp->res.jsonValue["Boot"]["AutomaticRetryConfig"] =
12326bd5a8d2SGunnar Mills                     "Disabled";
12336bd5a8d2SGunnar Mills             }
12346bd5a8d2SGunnar Mills 
12356bd5a8d2SGunnar Mills             // Not on D-Bus. Hardcoded here:
12366bd5a8d2SGunnar Mills             // https://github.com/openbmc/phosphor-state-manager/blob/1dbbef42675e94fb1f78edb87d6b11380260535a/meson_options.txt#L71
12376bd5a8d2SGunnar Mills             aResp->res.jsonValue["Boot"]["AutomaticRetryAttempts"] = 3;
123869f35306SGunnar Mills 
123969f35306SGunnar Mills             // "AutomaticRetryConfig" can be 3 values, Disabled, RetryAlways,
124069f35306SGunnar Mills             // and RetryAttempts. OpenBMC only supports Disabled and
124169f35306SGunnar Mills             // RetryAttempts.
124269f35306SGunnar Mills             aResp->res.jsonValue["Boot"]["AutomaticRetryConfig@Redfish."
124369f35306SGunnar Mills                                          "AllowableValues"] = {"Disabled",
124469f35306SGunnar Mills                                                                "RetryAttempts"};
12456bd5a8d2SGunnar Mills         },
12466bd5a8d2SGunnar Mills         "xyz.openbmc_project.Settings",
12476bd5a8d2SGunnar Mills         "/xyz/openbmc_project/control/host0/auto_reboot",
12486bd5a8d2SGunnar Mills         "org.freedesktop.DBus.Properties", "Get",
12496bd5a8d2SGunnar Mills         "xyz.openbmc_project.Control.Boot.RebootPolicy", "AutoReboot");
12506bd5a8d2SGunnar Mills }
12516bd5a8d2SGunnar Mills 
12526bd5a8d2SGunnar Mills /**
1253c6a620f2SGeorge Liu  * @brief Retrieves power restore policy over DBUS.
1254c6a620f2SGeorge Liu  *
1255c6a620f2SGeorge Liu  * @param[in] aResp     Shared pointer for generating response message.
1256c6a620f2SGeorge Liu  *
1257c6a620f2SGeorge Liu  * @return None.
1258c6a620f2SGeorge Liu  */
12598d1b46d7Szhanghch05 inline void
12608d1b46d7Szhanghch05     getPowerRestorePolicy(const std::shared_ptr<bmcweb::AsyncResp>& aResp)
1261c6a620f2SGeorge Liu {
1262c6a620f2SGeorge Liu     BMCWEB_LOG_DEBUG << "Get power restore policy";
1263c6a620f2SGeorge Liu 
1264c6a620f2SGeorge Liu     crow::connections::systemBus->async_method_call(
1265c6a620f2SGeorge Liu         [aResp](const boost::system::error_code ec,
126619bd78d9SPatrick Williams                 std::variant<std::string>& policy) {
1267c6a620f2SGeorge Liu             if (ec)
1268c6a620f2SGeorge Liu             {
1269c6a620f2SGeorge Liu                 BMCWEB_LOG_DEBUG << "DBUS response error " << ec;
1270c6a620f2SGeorge Liu                 return;
1271c6a620f2SGeorge Liu             }
1272c6a620f2SGeorge Liu 
1273c6a620f2SGeorge Liu             const boost::container::flat_map<std::string, std::string>
1274c6a620f2SGeorge Liu                 policyMaps = {
1275c6a620f2SGeorge Liu                     {"xyz.openbmc_project.Control.Power.RestorePolicy.Policy."
1276c6a620f2SGeorge Liu                      "AlwaysOn",
1277c6a620f2SGeorge Liu                      "AlwaysOn"},
1278c6a620f2SGeorge Liu                     {"xyz.openbmc_project.Control.Power.RestorePolicy.Policy."
1279c6a620f2SGeorge Liu                      "AlwaysOff",
1280c6a620f2SGeorge Liu                      "AlwaysOff"},
1281c6a620f2SGeorge Liu                     {"xyz.openbmc_project.Control.Power.RestorePolicy.Policy."
128237ec9072SGunnar Mills                      "Restore",
1283c6a620f2SGeorge Liu                      "LastState"}};
1284c6a620f2SGeorge Liu 
1285c6a620f2SGeorge Liu             const std::string* policyPtr = std::get_if<std::string>(&policy);
1286c6a620f2SGeorge Liu 
1287c6a620f2SGeorge Liu             if (!policyPtr)
1288c6a620f2SGeorge Liu             {
1289c6a620f2SGeorge Liu                 messages::internalError(aResp->res);
1290c6a620f2SGeorge Liu                 return;
1291c6a620f2SGeorge Liu             }
1292c6a620f2SGeorge Liu 
1293c6a620f2SGeorge Liu             auto policyMapsIt = policyMaps.find(*policyPtr);
1294c6a620f2SGeorge Liu             if (policyMapsIt == policyMaps.end())
1295c6a620f2SGeorge Liu             {
1296c6a620f2SGeorge Liu                 messages::internalError(aResp->res);
1297c6a620f2SGeorge Liu                 return;
1298c6a620f2SGeorge Liu             }
1299c6a620f2SGeorge Liu 
1300c6a620f2SGeorge Liu             aResp->res.jsonValue["PowerRestorePolicy"] = policyMapsIt->second;
1301c6a620f2SGeorge Liu         },
1302c6a620f2SGeorge Liu         "xyz.openbmc_project.Settings",
1303c6a620f2SGeorge Liu         "/xyz/openbmc_project/control/host0/power_restore_policy",
1304c6a620f2SGeorge Liu         "org.freedesktop.DBus.Properties", "Get",
1305c6a620f2SGeorge Liu         "xyz.openbmc_project.Control.Power.RestorePolicy",
1306c6a620f2SGeorge Liu         "PowerRestorePolicy");
1307c6a620f2SGeorge Liu }
1308c6a620f2SGeorge Liu 
1309c6a620f2SGeorge Liu /**
13101981771bSAli Ahmed  * @brief Get TrustedModuleRequiredToBoot property. Determines whether or not
13111981771bSAli Ahmed  * TPM is required for booting the host.
13121981771bSAli Ahmed  *
13131981771bSAli Ahmed  * @param[in] aResp     Shared pointer for generating response message.
13141981771bSAli Ahmed  *
13151981771bSAli Ahmed  * @return None.
13161981771bSAli Ahmed  */
13171981771bSAli Ahmed inline void getTrustedModuleRequiredToBoot(
13181981771bSAli Ahmed     const std::shared_ptr<bmcweb::AsyncResp>& aResp)
13191981771bSAli Ahmed {
13201981771bSAli Ahmed     BMCWEB_LOG_DEBUG << "Get TPM required to boot.";
13211981771bSAli Ahmed 
13221981771bSAli Ahmed     crow::connections::systemBus->async_method_call(
13231981771bSAli Ahmed         [aResp](
13241981771bSAli Ahmed             const boost::system::error_code ec,
13251981771bSAli Ahmed             std::vector<std::pair<
13261981771bSAli Ahmed                 std::string,
13271981771bSAli Ahmed                 std::vector<std::pair<std::string, std::vector<std::string>>>>>&
13281981771bSAli Ahmed                 subtree) {
13291981771bSAli Ahmed             if (ec)
13301981771bSAli Ahmed             {
13311981771bSAli Ahmed                 BMCWEB_LOG_DEBUG
13321981771bSAli Ahmed                     << "DBUS response error on TPM.Policy GetSubTree" << ec;
13331981771bSAli Ahmed                 // This is an optional D-Bus object so just return if
13341981771bSAli Ahmed                 // error occurs
13351981771bSAli Ahmed                 return;
13361981771bSAli Ahmed             }
13371981771bSAli Ahmed             if (subtree.size() == 0)
13381981771bSAli Ahmed             {
13391981771bSAli Ahmed                 // As noted above, this is an optional interface so just return
13401981771bSAli Ahmed                 // if there is no instance found
13411981771bSAli Ahmed                 return;
13421981771bSAli Ahmed             }
13431981771bSAli Ahmed 
13441981771bSAli Ahmed             /* When there is more than one TPMEnable object... */
13451981771bSAli Ahmed             if (subtree.size() > 1)
13461981771bSAli Ahmed             {
13471981771bSAli Ahmed                 BMCWEB_LOG_DEBUG
13481981771bSAli Ahmed                     << "DBUS response has more than 1 TPM Enable object:"
13491981771bSAli Ahmed                     << subtree.size();
13501981771bSAli Ahmed                 // Throw an internal Error and return
13511981771bSAli Ahmed                 messages::internalError(aResp->res);
13521981771bSAli Ahmed                 return;
13531981771bSAli Ahmed             }
13541981771bSAli Ahmed 
13551981771bSAli Ahmed             // Make sure the Dbus response map has a service and objectPath
13561981771bSAli Ahmed             // field
13571981771bSAli Ahmed             if (subtree[0].first.empty() || subtree[0].second.size() != 1)
13581981771bSAli Ahmed             {
13591981771bSAli Ahmed                 BMCWEB_LOG_DEBUG << "TPM.Policy mapper error!";
13601981771bSAli Ahmed                 messages::internalError(aResp->res);
13611981771bSAli Ahmed                 return;
13621981771bSAli Ahmed             }
13631981771bSAli Ahmed 
13641981771bSAli Ahmed             const std::string& path = subtree[0].first;
13651981771bSAli Ahmed             const std::string& serv = subtree[0].second.begin()->first;
13661981771bSAli Ahmed 
13671981771bSAli Ahmed             // Valid TPM Enable object found, now reading the current value
13681981771bSAli Ahmed             crow::connections::systemBus->async_method_call(
13691981771bSAli Ahmed                 [aResp](const boost::system::error_code ec,
13701981771bSAli Ahmed                         std::variant<bool>& tpmRequired) {
13711981771bSAli Ahmed                     if (ec)
13721981771bSAli Ahmed                     {
13731981771bSAli Ahmed                         BMCWEB_LOG_DEBUG
13741981771bSAli Ahmed                             << "D-BUS response error on TPM.Policy Get" << ec;
13751981771bSAli Ahmed                         messages::internalError(aResp->res);
13761981771bSAli Ahmed                         return;
13771981771bSAli Ahmed                     }
13781981771bSAli Ahmed 
13791981771bSAli Ahmed                     const bool* tpmRequiredVal =
13801981771bSAli Ahmed                         std::get_if<bool>(&tpmRequired);
13811981771bSAli Ahmed 
13821981771bSAli Ahmed                     if (!tpmRequiredVal)
13831981771bSAli Ahmed                     {
13841981771bSAli Ahmed                         messages::internalError(aResp->res);
13851981771bSAli Ahmed                         return;
13861981771bSAli Ahmed                     }
13871981771bSAli Ahmed 
13881981771bSAli Ahmed                     if (*tpmRequiredVal == true)
13891981771bSAli Ahmed                     {
13901981771bSAli Ahmed                         aResp->res
13911981771bSAli Ahmed                             .jsonValue["Boot"]["TrustedModuleRequiredToBoot"] =
13921981771bSAli Ahmed                             "Required";
13931981771bSAli Ahmed                     }
13941981771bSAli Ahmed                     else
13951981771bSAli Ahmed                     {
13961981771bSAli Ahmed                         aResp->res
13971981771bSAli Ahmed                             .jsonValue["Boot"]["TrustedModuleRequiredToBoot"] =
13981981771bSAli Ahmed                             "Disabled";
13991981771bSAli Ahmed                     }
14001981771bSAli Ahmed                 },
14011981771bSAli Ahmed                 serv, path, "org.freedesktop.DBus.Properties", "Get",
14021981771bSAli Ahmed                 "xyz.openbmc_project.Control.TPM.Policy", "TPMEnable");
14031981771bSAli Ahmed         },
14041981771bSAli Ahmed         "xyz.openbmc_project.ObjectMapper",
14051981771bSAli Ahmed         "/xyz/openbmc_project/object_mapper",
14061981771bSAli Ahmed         "xyz.openbmc_project.ObjectMapper", "GetSubTree", "/", int32_t(0),
14071981771bSAli Ahmed         std::array<const char*, 1>{"xyz.openbmc_project.Control.TPM.Policy"});
14081981771bSAli Ahmed }
14091981771bSAli Ahmed 
14101981771bSAli Ahmed /**
14111c05dae3SAli Ahmed  * @brief Set TrustedModuleRequiredToBoot property. Determines whether or not
14121c05dae3SAli Ahmed  * TPM is required for booting the host.
14131c05dae3SAli Ahmed  *
14141c05dae3SAli Ahmed  * @param[in] aResp         Shared pointer for generating response message.
14151c05dae3SAli Ahmed  * @param[in] tpmRequired   Value to set TPM Required To Boot property to.
14161c05dae3SAli Ahmed  *
14171c05dae3SAli Ahmed  * @return None.
14181c05dae3SAli Ahmed  */
14191c05dae3SAli Ahmed inline void setTrustedModuleRequiredToBoot(
14201c05dae3SAli Ahmed     const std::shared_ptr<bmcweb::AsyncResp>& aResp, const bool tpmRequired)
14211c05dae3SAli Ahmed {
14221c05dae3SAli Ahmed     BMCWEB_LOG_DEBUG << "Set TrustedModuleRequiredToBoot.";
14231c05dae3SAli Ahmed 
14241c05dae3SAli Ahmed     crow::connections::systemBus->async_method_call(
14251c05dae3SAli Ahmed         [aResp, tpmRequired](
14261c05dae3SAli Ahmed             const boost::system::error_code ec,
14271c05dae3SAli Ahmed             std::vector<std::pair<
14281c05dae3SAli Ahmed                 std::string,
14291c05dae3SAli Ahmed                 std::vector<std::pair<std::string, std::vector<std::string>>>>>&
14301c05dae3SAli Ahmed                 subtree) {
14311c05dae3SAli Ahmed             if (ec)
14321c05dae3SAli Ahmed             {
14331c05dae3SAli Ahmed                 BMCWEB_LOG_DEBUG
14341c05dae3SAli Ahmed                     << "DBUS response error on TPM.Policy GetSubTree" << ec;
14351c05dae3SAli Ahmed                 messages::internalError(aResp->res);
14361c05dae3SAli Ahmed                 return;
14371c05dae3SAli Ahmed             }
14381c05dae3SAli Ahmed             if (subtree.size() == 0)
14391c05dae3SAli Ahmed             {
14401c05dae3SAli Ahmed                 messages::propertyValueNotInList(aResp->res, "ComputerSystem",
14411c05dae3SAli Ahmed                                                  "TrustedModuleRequiredToBoot");
14421c05dae3SAli Ahmed                 return;
14431c05dae3SAli Ahmed             }
14441c05dae3SAli Ahmed 
14451c05dae3SAli Ahmed             /* When there is more than one TPMEnable object... */
14461c05dae3SAli Ahmed             if (subtree.size() > 1)
14471c05dae3SAli Ahmed             {
14481c05dae3SAli Ahmed                 BMCWEB_LOG_DEBUG
14491c05dae3SAli Ahmed                     << "DBUS response has more than 1 TPM Enable object:"
14501c05dae3SAli Ahmed                     << subtree.size();
14511c05dae3SAli Ahmed                 // Throw an internal Error and return
14521c05dae3SAli Ahmed                 messages::internalError(aResp->res);
14531c05dae3SAli Ahmed                 return;
14541c05dae3SAli Ahmed             }
14551c05dae3SAli Ahmed 
14561c05dae3SAli Ahmed             // Make sure the Dbus response map has a service and objectPath
14571c05dae3SAli Ahmed             // field
14581c05dae3SAli Ahmed             if (subtree[0].first.empty() || subtree[0].second.size() != 1)
14591c05dae3SAli Ahmed             {
14601c05dae3SAli Ahmed                 BMCWEB_LOG_DEBUG << "TPM.Policy mapper error!";
14611c05dae3SAli Ahmed                 messages::internalError(aResp->res);
14621c05dae3SAli Ahmed                 return;
14631c05dae3SAli Ahmed             }
14641c05dae3SAli Ahmed 
14651c05dae3SAli Ahmed             const std::string& path = subtree[0].first;
14661c05dae3SAli Ahmed             const std::string& serv = subtree[0].second.begin()->first;
14671c05dae3SAli Ahmed 
14681c05dae3SAli Ahmed             if (serv.empty())
14691c05dae3SAli Ahmed             {
14701c05dae3SAli Ahmed                 BMCWEB_LOG_DEBUG << "TPM.Policy service mapper error!";
14711c05dae3SAli Ahmed                 messages::internalError(aResp->res);
14721c05dae3SAli Ahmed                 return;
14731c05dae3SAli Ahmed             }
14741c05dae3SAli Ahmed 
14751c05dae3SAli Ahmed             // Valid TPM Enable object found, now setting the value
14761c05dae3SAli Ahmed             crow::connections::systemBus->async_method_call(
14771c05dae3SAli Ahmed                 [aResp](const boost::system::error_code ec) {
14781c05dae3SAli Ahmed                     if (ec)
14791c05dae3SAli Ahmed                     {
14801c05dae3SAli Ahmed                         BMCWEB_LOG_DEBUG << "DBUS response error: Set "
14811c05dae3SAli Ahmed                                             "TrustedModuleRequiredToBoot"
14821c05dae3SAli Ahmed                                          << ec;
14831c05dae3SAli Ahmed                         messages::internalError(aResp->res);
14841c05dae3SAli Ahmed                         return;
14851c05dae3SAli Ahmed                     }
14861c05dae3SAli Ahmed                     BMCWEB_LOG_DEBUG << "Set TrustedModuleRequiredToBoot done.";
14871c05dae3SAli Ahmed                 },
14881c05dae3SAli Ahmed                 serv, path, "org.freedesktop.DBus.Properties", "Set",
14891c05dae3SAli Ahmed                 "xyz.openbmc_project.Control.TPM.Policy", "TPMEnable",
14901c05dae3SAli Ahmed                 std::variant<bool>(tpmRequired));
14911c05dae3SAli Ahmed         },
14921c05dae3SAli Ahmed         "xyz.openbmc_project.ObjectMapper",
14931c05dae3SAli Ahmed         "/xyz/openbmc_project/object_mapper",
14941c05dae3SAli Ahmed         "xyz.openbmc_project.ObjectMapper", "GetSubTree", "/", int32_t(0),
14951c05dae3SAli Ahmed         std::array<const char*, 1>{"xyz.openbmc_project.Control.TPM.Policy"});
14961c05dae3SAli Ahmed }
14971c05dae3SAli Ahmed 
14981c05dae3SAli Ahmed /**
1499491d8ee7SSantosh Puranik  * @brief Sets boot properties into DBUS object(s).
1500491d8ee7SSantosh Puranik  *
1501491d8ee7SSantosh Puranik  * @param[in] aResp           Shared pointer for generating response message.
1502cd9a4666SKonstantin Aladyshev  * @param[in] bootType        The boot type to set.
1503cd9a4666SKonstantin Aladyshev  * @return Integer error code.
1504cd9a4666SKonstantin Aladyshev  */
1505cd9a4666SKonstantin Aladyshev inline void setBootType(const std::shared_ptr<bmcweb::AsyncResp>& aResp,
1506cd9a4666SKonstantin Aladyshev                         const std::optional<std::string>& bootType)
1507cd9a4666SKonstantin Aladyshev {
1508c21865c4SKonstantin Aladyshev     std::string bootTypeStr;
1509cd9a4666SKonstantin Aladyshev 
1510c21865c4SKonstantin Aladyshev     if (!bootType)
1511cd9a4666SKonstantin Aladyshev     {
1512c21865c4SKonstantin Aladyshev         return;
1513c21865c4SKonstantin Aladyshev     }
1514c21865c4SKonstantin Aladyshev 
1515cd9a4666SKonstantin Aladyshev     // Source target specified
1516cd9a4666SKonstantin Aladyshev     BMCWEB_LOG_DEBUG << "Boot type: " << *bootType;
1517cd9a4666SKonstantin Aladyshev     // Figure out which DBUS interface and property to use
1518cd9a4666SKonstantin Aladyshev     if (*bootType == "Legacy")
1519cd9a4666SKonstantin Aladyshev     {
1520cd9a4666SKonstantin Aladyshev         bootTypeStr = "xyz.openbmc_project.Control.Boot.Type.Types.Legacy";
1521cd9a4666SKonstantin Aladyshev     }
1522cd9a4666SKonstantin Aladyshev     else if (*bootType == "UEFI")
1523cd9a4666SKonstantin Aladyshev     {
1524cd9a4666SKonstantin Aladyshev         bootTypeStr = "xyz.openbmc_project.Control.Boot.Type.Types.EFI";
1525cd9a4666SKonstantin Aladyshev     }
1526cd9a4666SKonstantin Aladyshev     else
1527cd9a4666SKonstantin Aladyshev     {
1528cd9a4666SKonstantin Aladyshev         BMCWEB_LOG_DEBUG << "Invalid property value for "
1529cd9a4666SKonstantin Aladyshev                             "BootSourceOverrideMode: "
1530cd9a4666SKonstantin Aladyshev                          << *bootType;
1531cd9a4666SKonstantin Aladyshev         messages::propertyValueNotInList(aResp->res, *bootType,
1532cd9a4666SKonstantin Aladyshev                                          "BootSourceOverrideMode");
1533cd9a4666SKonstantin Aladyshev         return;
1534cd9a4666SKonstantin Aladyshev     }
1535cd9a4666SKonstantin Aladyshev 
1536cd9a4666SKonstantin Aladyshev     // Act on validated parameters
1537cd9a4666SKonstantin Aladyshev     BMCWEB_LOG_DEBUG << "DBUS boot type: " << bootTypeStr;
1538cd9a4666SKonstantin Aladyshev 
1539cd9a4666SKonstantin Aladyshev     crow::connections::systemBus->async_method_call(
1540c21865c4SKonstantin Aladyshev         [aResp](const boost::system::error_code ec) {
1541cd9a4666SKonstantin Aladyshev             if (ec)
1542cd9a4666SKonstantin Aladyshev             {
1543cd9a4666SKonstantin Aladyshev                 BMCWEB_LOG_DEBUG << "DBUS response error " << ec;
1544cd9a4666SKonstantin Aladyshev                 if (ec.value() == boost::asio::error::host_unreachable)
1545cd9a4666SKonstantin Aladyshev                 {
1546cd9a4666SKonstantin Aladyshev                     messages::resourceNotFound(aResp->res, "Set", "BootType");
1547cd9a4666SKonstantin Aladyshev                     return;
1548cd9a4666SKonstantin Aladyshev                 }
1549cd9a4666SKonstantin Aladyshev                 messages::internalError(aResp->res);
1550cd9a4666SKonstantin Aladyshev                 return;
1551cd9a4666SKonstantin Aladyshev             }
1552cd9a4666SKonstantin Aladyshev             BMCWEB_LOG_DEBUG << "Boot type update done.";
1553cd9a4666SKonstantin Aladyshev         },
1554c21865c4SKonstantin Aladyshev         "xyz.openbmc_project.Settings",
1555c21865c4SKonstantin Aladyshev         "/xyz/openbmc_project/control/host0/boot",
1556cd9a4666SKonstantin Aladyshev         "org.freedesktop.DBus.Properties", "Set",
1557cd9a4666SKonstantin Aladyshev         "xyz.openbmc_project.Control.Boot.Type", "BootType",
1558cd9a4666SKonstantin Aladyshev         std::variant<std::string>(bootTypeStr));
1559cd9a4666SKonstantin Aladyshev }
1560cd9a4666SKonstantin Aladyshev 
1561cd9a4666SKonstantin Aladyshev /**
1562cd9a4666SKonstantin Aladyshev  * @brief Sets boot properties into DBUS object(s).
1563cd9a4666SKonstantin Aladyshev  *
1564cd9a4666SKonstantin Aladyshev  * @param[in] aResp           Shared pointer for generating response message.
1565c21865c4SKonstantin Aladyshev  * @param[in] bootType        The boot type to set.
1566c21865c4SKonstantin Aladyshev  * @return Integer error code.
1567c21865c4SKonstantin Aladyshev  */
1568c21865c4SKonstantin Aladyshev inline void setBootEnable(const std::shared_ptr<bmcweb::AsyncResp>& aResp,
1569c21865c4SKonstantin Aladyshev                           const std::optional<std::string>& bootEnable)
1570c21865c4SKonstantin Aladyshev {
1571c21865c4SKonstantin Aladyshev     if (!bootEnable)
1572c21865c4SKonstantin Aladyshev     {
1573c21865c4SKonstantin Aladyshev         return;
1574c21865c4SKonstantin Aladyshev     }
1575c21865c4SKonstantin Aladyshev     // Source target specified
1576c21865c4SKonstantin Aladyshev     BMCWEB_LOG_DEBUG << "Boot enable: " << *bootEnable;
1577c21865c4SKonstantin Aladyshev 
1578c21865c4SKonstantin Aladyshev     bool bootOverrideEnable = false;
1579c21865c4SKonstantin Aladyshev     bool bootOverridePersistent = false;
1580c21865c4SKonstantin Aladyshev     // Figure out which DBUS interface and property to use
1581c21865c4SKonstantin Aladyshev     if (*bootEnable == "Disabled")
1582c21865c4SKonstantin Aladyshev     {
1583c21865c4SKonstantin Aladyshev         bootOverrideEnable = false;
1584c21865c4SKonstantin Aladyshev     }
1585c21865c4SKonstantin Aladyshev     else if (*bootEnable == "Once")
1586c21865c4SKonstantin Aladyshev     {
1587c21865c4SKonstantin Aladyshev         bootOverrideEnable = true;
1588c21865c4SKonstantin Aladyshev         bootOverridePersistent = false;
1589c21865c4SKonstantin Aladyshev     }
1590c21865c4SKonstantin Aladyshev     else if (*bootEnable == "Continuous")
1591c21865c4SKonstantin Aladyshev     {
1592c21865c4SKonstantin Aladyshev         bootOverrideEnable = true;
1593c21865c4SKonstantin Aladyshev         bootOverridePersistent = true;
1594c21865c4SKonstantin Aladyshev     }
1595c21865c4SKonstantin Aladyshev     else
1596c21865c4SKonstantin Aladyshev     {
1597c21865c4SKonstantin Aladyshev         BMCWEB_LOG_DEBUG << "Invalid property value for "
1598c21865c4SKonstantin Aladyshev                             "BootSourceOverrideEnabled: "
1599c21865c4SKonstantin Aladyshev                          << *bootEnable;
1600c21865c4SKonstantin Aladyshev         messages::propertyValueNotInList(aResp->res, *bootEnable,
1601c21865c4SKonstantin Aladyshev                                          "BootSourceOverrideEnabled");
1602c21865c4SKonstantin Aladyshev         return;
1603c21865c4SKonstantin Aladyshev     }
1604c21865c4SKonstantin Aladyshev 
1605c21865c4SKonstantin Aladyshev     // Act on validated parameters
1606c21865c4SKonstantin Aladyshev     BMCWEB_LOG_DEBUG << "DBUS boot override enable: " << bootOverrideEnable;
1607c21865c4SKonstantin Aladyshev 
1608c21865c4SKonstantin Aladyshev     crow::connections::systemBus->async_method_call(
1609c21865c4SKonstantin Aladyshev         [aResp](const boost::system::error_code ec) {
1610c21865c4SKonstantin Aladyshev             if (ec)
1611c21865c4SKonstantin Aladyshev             {
1612c21865c4SKonstantin Aladyshev                 BMCWEB_LOG_DEBUG << "DBUS response error " << ec;
1613c21865c4SKonstantin Aladyshev                 messages::internalError(aResp->res);
1614c21865c4SKonstantin Aladyshev                 return;
1615c21865c4SKonstantin Aladyshev             }
1616c21865c4SKonstantin Aladyshev             BMCWEB_LOG_DEBUG << "Boot override enable update done.";
1617c21865c4SKonstantin Aladyshev         },
1618c21865c4SKonstantin Aladyshev         "xyz.openbmc_project.Settings",
1619c21865c4SKonstantin Aladyshev         "/xyz/openbmc_project/control/host0/boot",
1620c21865c4SKonstantin Aladyshev         "org.freedesktop.DBus.Properties", "Set",
1621c21865c4SKonstantin Aladyshev         "xyz.openbmc_project.Object.Enable", "Enabled",
1622c21865c4SKonstantin Aladyshev         std::variant<bool>(bootOverrideEnable));
1623c21865c4SKonstantin Aladyshev 
1624c21865c4SKonstantin Aladyshev     if (!bootOverrideEnable)
1625c21865c4SKonstantin Aladyshev     {
1626c21865c4SKonstantin Aladyshev         return;
1627c21865c4SKonstantin Aladyshev     }
1628c21865c4SKonstantin Aladyshev 
1629c21865c4SKonstantin Aladyshev     // In case boot override is enabled we need to set correct value for the
1630c21865c4SKonstantin Aladyshev     // 'one_time' enable DBus interface
1631c21865c4SKonstantin Aladyshev     BMCWEB_LOG_DEBUG << "DBUS boot override persistent: "
1632c21865c4SKonstantin Aladyshev                      << bootOverridePersistent;
1633c21865c4SKonstantin Aladyshev 
1634c21865c4SKonstantin Aladyshev     crow::connections::systemBus->async_method_call(
1635c21865c4SKonstantin Aladyshev         [aResp](const boost::system::error_code ec) {
1636c21865c4SKonstantin Aladyshev             if (ec)
1637c21865c4SKonstantin Aladyshev             {
1638c21865c4SKonstantin Aladyshev                 BMCWEB_LOG_DEBUG << "DBUS response error " << ec;
1639c21865c4SKonstantin Aladyshev                 messages::internalError(aResp->res);
1640c21865c4SKonstantin Aladyshev                 return;
1641c21865c4SKonstantin Aladyshev             }
1642c21865c4SKonstantin Aladyshev             BMCWEB_LOG_DEBUG << "Boot one_time update done.";
1643c21865c4SKonstantin Aladyshev         },
1644c21865c4SKonstantin Aladyshev         "xyz.openbmc_project.Settings",
1645c21865c4SKonstantin Aladyshev         "/xyz/openbmc_project/control/host0/boot/one_time",
1646c21865c4SKonstantin Aladyshev         "org.freedesktop.DBus.Properties", "Set",
1647c21865c4SKonstantin Aladyshev         "xyz.openbmc_project.Object.Enable", "Enabled",
1648c21865c4SKonstantin Aladyshev         std::variant<bool>(!bootOverridePersistent));
1649c21865c4SKonstantin Aladyshev }
1650c21865c4SKonstantin Aladyshev 
1651c21865c4SKonstantin Aladyshev /**
1652c21865c4SKonstantin Aladyshev  * @brief Sets boot properties into DBUS object(s).
1653c21865c4SKonstantin Aladyshev  *
1654c21865c4SKonstantin Aladyshev  * @param[in] aResp           Shared pointer for generating response message.
1655491d8ee7SSantosh Puranik  * @param[in] bootSource      The boot source to set.
1656491d8ee7SSantosh Puranik  *
1657265c1602SJohnathan Mantey  * @return Integer error code.
1658491d8ee7SSantosh Puranik  */
1659cd9a4666SKonstantin Aladyshev inline void setBootModeOrSource(const std::shared_ptr<bmcweb::AsyncResp>& aResp,
1660cd9a4666SKonstantin Aladyshev                                 const std::optional<std::string>& bootSource)
1661491d8ee7SSantosh Puranik {
1662c21865c4SKonstantin Aladyshev     std::string bootSourceStr;
1663c21865c4SKonstantin Aladyshev     std::string bootModeStr;
1664944ffaf9SJohnathan Mantey 
1665c21865c4SKonstantin Aladyshev     if (!bootSource)
1666491d8ee7SSantosh Puranik     {
1667c21865c4SKonstantin Aladyshev         return;
1668c21865c4SKonstantin Aladyshev     }
1669c21865c4SKonstantin Aladyshev 
1670491d8ee7SSantosh Puranik     // Source target specified
1671491d8ee7SSantosh Puranik     BMCWEB_LOG_DEBUG << "Boot source: " << *bootSource;
1672491d8ee7SSantosh Puranik     // Figure out which DBUS interface and property to use
1673c21865c4SKonstantin Aladyshev     if (assignBootParameters(aResp, *bootSource, bootSourceStr, bootModeStr))
1674491d8ee7SSantosh Puranik     {
1675944ffaf9SJohnathan Mantey         BMCWEB_LOG_DEBUG
1676944ffaf9SJohnathan Mantey             << "Invalid property value for BootSourceOverrideTarget: "
1677491d8ee7SSantosh Puranik             << *bootSource;
1678491d8ee7SSantosh Puranik         messages::propertyValueNotInList(aResp->res, *bootSource,
1679491d8ee7SSantosh Puranik                                          "BootSourceTargetOverride");
1680491d8ee7SSantosh Puranik         return;
1681491d8ee7SSantosh Puranik     }
1682491d8ee7SSantosh Puranik 
1683944ffaf9SJohnathan Mantey     // Act on validated parameters
1684944ffaf9SJohnathan Mantey     BMCWEB_LOG_DEBUG << "DBUS boot source: " << bootSourceStr;
1685944ffaf9SJohnathan Mantey     BMCWEB_LOG_DEBUG << "DBUS boot mode: " << bootModeStr;
1686944ffaf9SJohnathan Mantey 
1687491d8ee7SSantosh Puranik     crow::connections::systemBus->async_method_call(
1688491d8ee7SSantosh Puranik         [aResp](const boost::system::error_code ec) {
1689491d8ee7SSantosh Puranik             if (ec)
1690491d8ee7SSantosh Puranik             {
1691491d8ee7SSantosh Puranik                 BMCWEB_LOG_DEBUG << "DBUS response error " << ec;
1692491d8ee7SSantosh Puranik                 messages::internalError(aResp->res);
1693491d8ee7SSantosh Puranik                 return;
1694491d8ee7SSantosh Puranik             }
1695491d8ee7SSantosh Puranik             BMCWEB_LOG_DEBUG << "Boot source update done.";
1696491d8ee7SSantosh Puranik         },
1697c21865c4SKonstantin Aladyshev         "xyz.openbmc_project.Settings",
1698c21865c4SKonstantin Aladyshev         "/xyz/openbmc_project/control/host0/boot",
1699491d8ee7SSantosh Puranik         "org.freedesktop.DBus.Properties", "Set",
1700491d8ee7SSantosh Puranik         "xyz.openbmc_project.Control.Boot.Source", "BootSource",
1701491d8ee7SSantosh Puranik         std::variant<std::string>(bootSourceStr));
1702944ffaf9SJohnathan Mantey 
1703491d8ee7SSantosh Puranik     crow::connections::systemBus->async_method_call(
1704491d8ee7SSantosh Puranik         [aResp](const boost::system::error_code ec) {
1705491d8ee7SSantosh Puranik             if (ec)
1706491d8ee7SSantosh Puranik             {
1707491d8ee7SSantosh Puranik                 BMCWEB_LOG_DEBUG << "DBUS response error " << ec;
1708491d8ee7SSantosh Puranik                 messages::internalError(aResp->res);
1709491d8ee7SSantosh Puranik                 return;
1710491d8ee7SSantosh Puranik             }
1711491d8ee7SSantosh Puranik             BMCWEB_LOG_DEBUG << "Boot mode update done.";
1712491d8ee7SSantosh Puranik         },
1713c21865c4SKonstantin Aladyshev         "xyz.openbmc_project.Settings",
1714c21865c4SKonstantin Aladyshev         "/xyz/openbmc_project/control/host0/boot",
1715491d8ee7SSantosh Puranik         "org.freedesktop.DBus.Properties", "Set",
1716491d8ee7SSantosh Puranik         "xyz.openbmc_project.Control.Boot.Mode", "BootMode",
1717491d8ee7SSantosh Puranik         std::variant<std::string>(bootModeStr));
1718cd9a4666SKonstantin Aladyshev }
1719944ffaf9SJohnathan Mantey 
1720cd9a4666SKonstantin Aladyshev /**
1721c21865c4SKonstantin Aladyshev  * @brief Sets Boot source override properties.
1722491d8ee7SSantosh Puranik  *
1723491d8ee7SSantosh Puranik  * @param[in] aResp      Shared pointer for generating response message.
1724491d8ee7SSantosh Puranik  * @param[in] bootSource The boot source from incoming RF request.
1725cd9a4666SKonstantin Aladyshev  * @param[in] bootType   The boot type from incoming RF request.
1726491d8ee7SSantosh Puranik  * @param[in] bootEnable The boot override enable from incoming RF request.
1727491d8ee7SSantosh Puranik  *
1728265c1602SJohnathan Mantey  * @return Integer error code.
1729491d8ee7SSantosh Puranik  */
1730c21865c4SKonstantin Aladyshev 
1731c21865c4SKonstantin Aladyshev inline void setBootProperties(const std::shared_ptr<bmcweb::AsyncResp>& aResp,
1732c21865c4SKonstantin Aladyshev                               const std::optional<std::string>& bootSource,
1733c21865c4SKonstantin Aladyshev                               const std::optional<std::string>& bootType,
1734c21865c4SKonstantin Aladyshev                               const std::optional<std::string>& bootEnable)
1735491d8ee7SSantosh Puranik {
1736491d8ee7SSantosh Puranik     BMCWEB_LOG_DEBUG << "Set boot information.";
1737491d8ee7SSantosh Puranik 
1738c21865c4SKonstantin Aladyshev     setBootModeOrSource(aResp, bootSource);
1739c21865c4SKonstantin Aladyshev     setBootType(aResp, bootType);
1740c21865c4SKonstantin Aladyshev     setBootEnable(aResp, bootEnable);
1741491d8ee7SSantosh Puranik }
1742491d8ee7SSantosh Puranik 
1743c6a620f2SGeorge Liu /**
174498e386ecSGunnar Mills  * @brief Sets AssetTag
174598e386ecSGunnar Mills  *
174698e386ecSGunnar Mills  * @param[in] aResp   Shared pointer for generating response message.
174798e386ecSGunnar Mills  * @param[in] assetTag  "AssetTag" from request.
174898e386ecSGunnar Mills  *
174998e386ecSGunnar Mills  * @return None.
175098e386ecSGunnar Mills  */
17518d1b46d7Szhanghch05 inline void setAssetTag(const std::shared_ptr<bmcweb::AsyncResp>& aResp,
175298e386ecSGunnar Mills                         const std::string& assetTag)
175398e386ecSGunnar Mills {
175498e386ecSGunnar Mills     crow::connections::systemBus->async_method_call(
175598e386ecSGunnar Mills         [aResp, assetTag](
175698e386ecSGunnar Mills             const boost::system::error_code ec,
175798e386ecSGunnar Mills             const std::vector<std::pair<
175898e386ecSGunnar Mills                 std::string,
175998e386ecSGunnar Mills                 std::vector<std::pair<std::string, std::vector<std::string>>>>>&
176098e386ecSGunnar Mills                 subtree) {
176198e386ecSGunnar Mills             if (ec)
176298e386ecSGunnar Mills             {
176398e386ecSGunnar Mills                 BMCWEB_LOG_DEBUG << "D-Bus response error on GetSubTree " << ec;
176498e386ecSGunnar Mills                 messages::internalError(aResp->res);
176598e386ecSGunnar Mills                 return;
176698e386ecSGunnar Mills             }
176798e386ecSGunnar Mills             if (subtree.size() == 0)
176898e386ecSGunnar Mills             {
176998e386ecSGunnar Mills                 BMCWEB_LOG_DEBUG << "Can't find system D-Bus object!";
177098e386ecSGunnar Mills                 messages::internalError(aResp->res);
177198e386ecSGunnar Mills                 return;
177298e386ecSGunnar Mills             }
177398e386ecSGunnar Mills             // Assume only 1 system D-Bus object
177498e386ecSGunnar Mills             // Throw an error if there is more than 1
177598e386ecSGunnar Mills             if (subtree.size() > 1)
177698e386ecSGunnar Mills             {
177798e386ecSGunnar Mills                 BMCWEB_LOG_DEBUG << "Found more than 1 system D-Bus object!";
177898e386ecSGunnar Mills                 messages::internalError(aResp->res);
177998e386ecSGunnar Mills                 return;
178098e386ecSGunnar Mills             }
178198e386ecSGunnar Mills             if (subtree[0].first.empty() || subtree[0].second.size() != 1)
178298e386ecSGunnar Mills             {
178398e386ecSGunnar Mills                 BMCWEB_LOG_DEBUG << "Asset Tag Set mapper error!";
178498e386ecSGunnar Mills                 messages::internalError(aResp->res);
178598e386ecSGunnar Mills                 return;
178698e386ecSGunnar Mills             }
178798e386ecSGunnar Mills 
178898e386ecSGunnar Mills             const std::string& path = subtree[0].first;
178998e386ecSGunnar Mills             const std::string& service = subtree[0].second.begin()->first;
179098e386ecSGunnar Mills 
179198e386ecSGunnar Mills             if (service.empty())
179298e386ecSGunnar Mills             {
179398e386ecSGunnar Mills                 BMCWEB_LOG_DEBUG << "Asset Tag Set service mapper error!";
179498e386ecSGunnar Mills                 messages::internalError(aResp->res);
179598e386ecSGunnar Mills                 return;
179698e386ecSGunnar Mills             }
179798e386ecSGunnar Mills 
179898e386ecSGunnar Mills             crow::connections::systemBus->async_method_call(
179998e386ecSGunnar Mills                 [aResp](const boost::system::error_code ec2) {
180098e386ecSGunnar Mills                     if (ec2)
180198e386ecSGunnar Mills                     {
180298e386ecSGunnar Mills                         BMCWEB_LOG_DEBUG
180398e386ecSGunnar Mills                             << "D-Bus response error on AssetTag Set " << ec2;
180498e386ecSGunnar Mills                         messages::internalError(aResp->res);
180598e386ecSGunnar Mills                         return;
180698e386ecSGunnar Mills                     }
180798e386ecSGunnar Mills                 },
180898e386ecSGunnar Mills                 service, path, "org.freedesktop.DBus.Properties", "Set",
180998e386ecSGunnar Mills                 "xyz.openbmc_project.Inventory.Decorator.AssetTag", "AssetTag",
181098e386ecSGunnar Mills                 std::variant<std::string>(assetTag));
181198e386ecSGunnar Mills         },
181298e386ecSGunnar Mills         "xyz.openbmc_project.ObjectMapper",
181398e386ecSGunnar Mills         "/xyz/openbmc_project/object_mapper",
181498e386ecSGunnar Mills         "xyz.openbmc_project.ObjectMapper", "GetSubTree",
181598e386ecSGunnar Mills         "/xyz/openbmc_project/inventory", int32_t(0),
181698e386ecSGunnar Mills         std::array<const char*, 1>{
181798e386ecSGunnar Mills             "xyz.openbmc_project.Inventory.Item.System"});
181898e386ecSGunnar Mills }
181998e386ecSGunnar Mills 
182098e386ecSGunnar Mills /**
182169f35306SGunnar Mills  * @brief Sets automaticRetry (Auto Reboot)
182269f35306SGunnar Mills  *
182369f35306SGunnar Mills  * @param[in] aResp   Shared pointer for generating response message.
182469f35306SGunnar Mills  * @param[in] automaticRetryConfig  "AutomaticRetryConfig" from request.
182569f35306SGunnar Mills  *
182669f35306SGunnar Mills  * @return None.
182769f35306SGunnar Mills  */
18288d1b46d7Szhanghch05 inline void setAutomaticRetry(const std::shared_ptr<bmcweb::AsyncResp>& aResp,
1829f23b7296SEd Tanous                               const std::string& automaticRetryConfig)
183069f35306SGunnar Mills {
183169f35306SGunnar Mills     BMCWEB_LOG_DEBUG << "Set Automatic Retry.";
183269f35306SGunnar Mills 
183369f35306SGunnar Mills     // OpenBMC only supports "Disabled" and "RetryAttempts".
183469f35306SGunnar Mills     bool autoRebootEnabled;
183569f35306SGunnar Mills 
183669f35306SGunnar Mills     if (automaticRetryConfig == "Disabled")
183769f35306SGunnar Mills     {
183869f35306SGunnar Mills         autoRebootEnabled = false;
183969f35306SGunnar Mills     }
184069f35306SGunnar Mills     else if (automaticRetryConfig == "RetryAttempts")
184169f35306SGunnar Mills     {
184269f35306SGunnar Mills         autoRebootEnabled = true;
184369f35306SGunnar Mills     }
184469f35306SGunnar Mills     else
184569f35306SGunnar Mills     {
184669f35306SGunnar Mills         BMCWEB_LOG_DEBUG << "Invalid property value for "
184769f35306SGunnar Mills                             "AutomaticRetryConfig: "
184869f35306SGunnar Mills                          << automaticRetryConfig;
184969f35306SGunnar Mills         messages::propertyValueNotInList(aResp->res, automaticRetryConfig,
185069f35306SGunnar Mills                                          "AutomaticRetryConfig");
185169f35306SGunnar Mills         return;
185269f35306SGunnar Mills     }
185369f35306SGunnar Mills 
185469f35306SGunnar Mills     crow::connections::systemBus->async_method_call(
185569f35306SGunnar Mills         [aResp](const boost::system::error_code ec) {
185669f35306SGunnar Mills             if (ec)
185769f35306SGunnar Mills             {
185869f35306SGunnar Mills                 messages::internalError(aResp->res);
185969f35306SGunnar Mills                 return;
186069f35306SGunnar Mills             }
186169f35306SGunnar Mills         },
186269f35306SGunnar Mills         "xyz.openbmc_project.Settings",
186369f35306SGunnar Mills         "/xyz/openbmc_project/control/host0/auto_reboot",
186469f35306SGunnar Mills         "org.freedesktop.DBus.Properties", "Set",
186569f35306SGunnar Mills         "xyz.openbmc_project.Control.Boot.RebootPolicy", "AutoReboot",
186669f35306SGunnar Mills         std::variant<bool>(autoRebootEnabled));
186769f35306SGunnar Mills }
186869f35306SGunnar Mills 
186969f35306SGunnar Mills /**
1870c6a620f2SGeorge Liu  * @brief Sets power restore policy properties.
1871c6a620f2SGeorge Liu  *
1872c6a620f2SGeorge Liu  * @param[in] aResp   Shared pointer for generating response message.
1873c6a620f2SGeorge Liu  * @param[in] policy  power restore policy properties from request.
1874c6a620f2SGeorge Liu  *
1875c6a620f2SGeorge Liu  * @return None.
1876c6a620f2SGeorge Liu  */
18778d1b46d7Szhanghch05 inline void
18788d1b46d7Szhanghch05     setPowerRestorePolicy(const std::shared_ptr<bmcweb::AsyncResp>& aResp,
18794e69c904SGunnar Mills                           const std::string& policy)
1880c6a620f2SGeorge Liu {
1881c6a620f2SGeorge Liu     BMCWEB_LOG_DEBUG << "Set power restore policy.";
1882c6a620f2SGeorge Liu 
1883c6a620f2SGeorge Liu     const boost::container::flat_map<std::string, std::string> policyMaps = {
1884c6a620f2SGeorge Liu         {"AlwaysOn", "xyz.openbmc_project.Control.Power.RestorePolicy.Policy."
1885c6a620f2SGeorge Liu                      "AlwaysOn"},
1886c6a620f2SGeorge Liu         {"AlwaysOff", "xyz.openbmc_project.Control.Power.RestorePolicy.Policy."
1887c6a620f2SGeorge Liu                       "AlwaysOff"},
1888c6a620f2SGeorge Liu         {"LastState", "xyz.openbmc_project.Control.Power.RestorePolicy.Policy."
188937ec9072SGunnar Mills                       "Restore"}};
1890c6a620f2SGeorge Liu 
1891c6a620f2SGeorge Liu     std::string powerRestorPolicy;
1892c6a620f2SGeorge Liu 
18934e69c904SGunnar Mills     auto policyMapsIt = policyMaps.find(policy);
1894c6a620f2SGeorge Liu     if (policyMapsIt == policyMaps.end())
1895c6a620f2SGeorge Liu     {
18964e69c904SGunnar Mills         messages::propertyValueNotInList(aResp->res, policy,
18974e69c904SGunnar Mills                                          "PowerRestorePolicy");
1898c6a620f2SGeorge Liu         return;
1899c6a620f2SGeorge Liu     }
1900c6a620f2SGeorge Liu 
1901c6a620f2SGeorge Liu     powerRestorPolicy = policyMapsIt->second;
1902c6a620f2SGeorge Liu 
1903c6a620f2SGeorge Liu     crow::connections::systemBus->async_method_call(
1904c6a620f2SGeorge Liu         [aResp](const boost::system::error_code ec) {
1905c6a620f2SGeorge Liu             if (ec)
1906c6a620f2SGeorge Liu             {
1907c6a620f2SGeorge Liu                 messages::internalError(aResp->res);
1908c6a620f2SGeorge Liu                 return;
1909c6a620f2SGeorge Liu             }
1910c6a620f2SGeorge Liu         },
1911c6a620f2SGeorge Liu         "xyz.openbmc_project.Settings",
1912c6a620f2SGeorge Liu         "/xyz/openbmc_project/control/host0/power_restore_policy",
1913c6a620f2SGeorge Liu         "org.freedesktop.DBus.Properties", "Set",
1914c6a620f2SGeorge Liu         "xyz.openbmc_project.Control.Power.RestorePolicy", "PowerRestorePolicy",
1915c6a620f2SGeorge Liu         std::variant<std::string>(powerRestorPolicy));
1916c6a620f2SGeorge Liu }
1917c6a620f2SGeorge Liu 
1918a6349918SAppaRao Puli #ifdef BMCWEB_ENABLE_REDFISH_PROVISIONING_FEATURE
1919a6349918SAppaRao Puli /**
1920a6349918SAppaRao Puli  * @brief Retrieves provisioning status
1921a6349918SAppaRao Puli  *
1922a6349918SAppaRao Puli  * @param[in] aResp     Shared pointer for completing asynchronous calls.
1923a6349918SAppaRao Puli  *
1924a6349918SAppaRao Puli  * @return None.
1925a6349918SAppaRao Puli  */
19268d1b46d7Szhanghch05 inline void getProvisioningStatus(std::shared_ptr<bmcweb::AsyncResp> aResp)
1927a6349918SAppaRao Puli {
1928a6349918SAppaRao Puli     BMCWEB_LOG_DEBUG << "Get OEM information.";
1929a6349918SAppaRao Puli     crow::connections::systemBus->async_method_call(
1930a6349918SAppaRao Puli         [aResp](const boost::system::error_code ec,
19311214b7e7SGunnar Mills                 const std::vector<std::pair<std::string, VariantType>>&
19321214b7e7SGunnar Mills                     propertiesList) {
1933b99fb1a9SAppaRao Puli             nlohmann::json& oemPFR =
1934b99fb1a9SAppaRao Puli                 aResp->res.jsonValue["Oem"]["OpenBmc"]["FirmwareProvisioning"];
193550626f4fSJames Feist             aResp->res.jsonValue["Oem"]["OpenBmc"]["@odata.type"] =
193650626f4fSJames Feist                 "#OemComputerSystem.OpenBmc";
193750626f4fSJames Feist             oemPFR["@odata.type"] = "#OemComputerSystem.FirmwareProvisioning";
193850626f4fSJames Feist 
1939a6349918SAppaRao Puli             if (ec)
1940a6349918SAppaRao Puli             {
1941a6349918SAppaRao Puli                 BMCWEB_LOG_DEBUG << "DBUS response error " << ec;
1942b99fb1a9SAppaRao Puli                 // not an error, don't have to have the interface
1943b99fb1a9SAppaRao Puli                 oemPFR["ProvisioningStatus"] = "NotProvisioned";
1944a6349918SAppaRao Puli                 return;
1945a6349918SAppaRao Puli             }
1946a6349918SAppaRao Puli 
1947a6349918SAppaRao Puli             const bool* provState = nullptr;
1948a6349918SAppaRao Puli             const bool* lockState = nullptr;
1949a6349918SAppaRao Puli             for (const std::pair<std::string, VariantType>& property :
1950a6349918SAppaRao Puli                  propertiesList)
1951a6349918SAppaRao Puli             {
1952a6349918SAppaRao Puli                 if (property.first == "UfmProvisioned")
1953a6349918SAppaRao Puli                 {
1954a6349918SAppaRao Puli                     provState = std::get_if<bool>(&property.second);
1955a6349918SAppaRao Puli                 }
1956a6349918SAppaRao Puli                 else if (property.first == "UfmLocked")
1957a6349918SAppaRao Puli                 {
1958a6349918SAppaRao Puli                     lockState = std::get_if<bool>(&property.second);
1959a6349918SAppaRao Puli                 }
1960a6349918SAppaRao Puli             }
1961a6349918SAppaRao Puli 
1962a6349918SAppaRao Puli             if ((provState == nullptr) || (lockState == nullptr))
1963a6349918SAppaRao Puli             {
1964a6349918SAppaRao Puli                 BMCWEB_LOG_DEBUG << "Unable to get PFR attributes.";
1965a6349918SAppaRao Puli                 messages::internalError(aResp->res);
1966a6349918SAppaRao Puli                 return;
1967a6349918SAppaRao Puli             }
1968a6349918SAppaRao Puli 
1969a6349918SAppaRao Puli             if (*provState == true)
1970a6349918SAppaRao Puli             {
1971a6349918SAppaRao Puli                 if (*lockState == true)
1972a6349918SAppaRao Puli                 {
1973a6349918SAppaRao Puli                     oemPFR["ProvisioningStatus"] = "ProvisionedAndLocked";
1974a6349918SAppaRao Puli                 }
1975a6349918SAppaRao Puli                 else
1976a6349918SAppaRao Puli                 {
1977a6349918SAppaRao Puli                     oemPFR["ProvisioningStatus"] = "ProvisionedButNotLocked";
1978a6349918SAppaRao Puli                 }
1979a6349918SAppaRao Puli             }
1980a6349918SAppaRao Puli             else
1981a6349918SAppaRao Puli             {
1982a6349918SAppaRao Puli                 oemPFR["ProvisioningStatus"] = "NotProvisioned";
1983a6349918SAppaRao Puli             }
1984a6349918SAppaRao Puli         },
1985a6349918SAppaRao Puli         "xyz.openbmc_project.PFR.Manager", "/xyz/openbmc_project/pfr",
1986a6349918SAppaRao Puli         "org.freedesktop.DBus.Properties", "GetAll",
1987a6349918SAppaRao Puli         "xyz.openbmc_project.PFR.Attributes");
1988a6349918SAppaRao Puli }
1989a6349918SAppaRao Puli #endif
1990a6349918SAppaRao Puli 
1991491d8ee7SSantosh Puranik /**
19923a2d0424SChris Cain  * @brief Translate the PowerMode to a response message.
19933a2d0424SChris Cain  *
19943a2d0424SChris Cain  * @param[in] aResp  Shared pointer for generating response message.
19953a2d0424SChris Cain  * @param[in] modeValue  PowerMode value to be translated
19963a2d0424SChris Cain  *
19973a2d0424SChris Cain  * @return None.
19983a2d0424SChris Cain  */
19993a2d0424SChris Cain inline void translatePowerMode(const std::shared_ptr<bmcweb::AsyncResp>& aResp,
20003a2d0424SChris Cain                                const std::string& modeValue)
20013a2d0424SChris Cain {
20023a2d0424SChris Cain     std::string modeString;
20033a2d0424SChris Cain 
20043a2d0424SChris Cain     if (modeValue == "xyz.openbmc_project.Control.Power.Mode."
20053a2d0424SChris Cain                      "PowerMode.Static")
20063a2d0424SChris Cain     {
20073a2d0424SChris Cain         aResp->res.jsonValue["PowerMode"] = "Static";
20083a2d0424SChris Cain     }
20093a2d0424SChris Cain     else if (modeValue == "xyz.openbmc_project.Control.Power.Mode."
20103a2d0424SChris Cain                           "PowerMode.MaximumPerformance")
20113a2d0424SChris Cain     {
20123a2d0424SChris Cain         aResp->res.jsonValue["PowerMode"] = "MaximumPerformance";
20133a2d0424SChris Cain     }
20143a2d0424SChris Cain     else if (modeValue == "xyz.openbmc_project.Control.Power.Mode."
20153a2d0424SChris Cain                           "PowerMode.PowerSaving")
20163a2d0424SChris Cain     {
20173a2d0424SChris Cain         aResp->res.jsonValue["PowerMode"] = "PowerSaving";
20183a2d0424SChris Cain     }
20193a2d0424SChris Cain     else if (modeValue == "xyz.openbmc_project.Control.Power.Mode."
20203a2d0424SChris Cain                           "PowerMode.OEM")
20213a2d0424SChris Cain     {
20223a2d0424SChris Cain         aResp->res.jsonValue["PowerMode"] = "OEM";
20233a2d0424SChris Cain     }
20243a2d0424SChris Cain     else
20253a2d0424SChris Cain     {
20263a2d0424SChris Cain         // Any other values would be invalid
20273a2d0424SChris Cain         BMCWEB_LOG_DEBUG << "PowerMode value was not valid: " << modeValue;
20283a2d0424SChris Cain         messages::internalError(aResp->res);
20293a2d0424SChris Cain     }
20303a2d0424SChris Cain }
20313a2d0424SChris Cain 
20323a2d0424SChris Cain /**
20333a2d0424SChris Cain  * @brief Retrieves system power mode
20343a2d0424SChris Cain  *
20353a2d0424SChris Cain  * @param[in] aResp  Shared pointer for generating response message.
20363a2d0424SChris Cain  *
20373a2d0424SChris Cain  * @return None.
20383a2d0424SChris Cain  */
20393a2d0424SChris Cain inline void getPowerMode(const std::shared_ptr<bmcweb::AsyncResp>& aResp)
20403a2d0424SChris Cain {
20413a2d0424SChris Cain     BMCWEB_LOG_DEBUG << "Get power mode.";
20423a2d0424SChris Cain 
20433a2d0424SChris Cain     // Get Power Mode object path:
20443a2d0424SChris Cain     crow::connections::systemBus->async_method_call(
20453a2d0424SChris Cain         [aResp](
20463a2d0424SChris Cain             const boost::system::error_code ec,
20473a2d0424SChris Cain             const std::vector<std::pair<
20483a2d0424SChris Cain                 std::string,
20493a2d0424SChris Cain                 std::vector<std::pair<std::string, std::vector<std::string>>>>>&
20503a2d0424SChris Cain                 subtree) {
20513a2d0424SChris Cain             if (ec)
20523a2d0424SChris Cain             {
20533a2d0424SChris Cain                 BMCWEB_LOG_DEBUG
20543a2d0424SChris Cain                     << "DBUS response error on Power.Mode GetSubTree " << ec;
20553a2d0424SChris Cain                 // This is an optional D-Bus object so just return if
20563a2d0424SChris Cain                 // error occurs
20573a2d0424SChris Cain                 return;
20583a2d0424SChris Cain             }
20593a2d0424SChris Cain             if (subtree.empty())
20603a2d0424SChris Cain             {
20613a2d0424SChris Cain                 // As noted above, this is an optional interface so just return
20623a2d0424SChris Cain                 // if there is no instance found
20633a2d0424SChris Cain                 return;
20643a2d0424SChris Cain             }
20653a2d0424SChris Cain             if (subtree.size() > 1)
20663a2d0424SChris Cain             {
20673a2d0424SChris Cain                 // More then one PowerMode object is not supported and is an
20683a2d0424SChris Cain                 // error
20693a2d0424SChris Cain                 BMCWEB_LOG_DEBUG
20703a2d0424SChris Cain                     << "Found more than 1 system D-Bus Power.Mode objects: "
20713a2d0424SChris Cain                     << subtree.size();
20723a2d0424SChris Cain                 messages::internalError(aResp->res);
20733a2d0424SChris Cain                 return;
20743a2d0424SChris Cain             }
20753a2d0424SChris Cain             if ((subtree[0].first.empty()) || (subtree[0].second.size() != 1))
20763a2d0424SChris Cain             {
20773a2d0424SChris Cain                 BMCWEB_LOG_DEBUG << "Power.Mode mapper error!";
20783a2d0424SChris Cain                 messages::internalError(aResp->res);
20793a2d0424SChris Cain                 return;
20803a2d0424SChris Cain             }
20813a2d0424SChris Cain             const std::string& path = subtree[0].first;
20823a2d0424SChris Cain             const std::string& service = subtree[0].second.begin()->first;
20833a2d0424SChris Cain             if (service.empty())
20843a2d0424SChris Cain             {
20853a2d0424SChris Cain                 BMCWEB_LOG_DEBUG << "Power.Mode service mapper error!";
20863a2d0424SChris Cain                 messages::internalError(aResp->res);
20873a2d0424SChris Cain                 return;
20883a2d0424SChris Cain             }
20893a2d0424SChris Cain             // Valid Power Mode object found, now read the current value
20903a2d0424SChris Cain             crow::connections::systemBus->async_method_call(
20913a2d0424SChris Cain                 [aResp](const boost::system::error_code ec,
20923a2d0424SChris Cain                         const std::variant<std::string>& pmode) {
20933a2d0424SChris Cain                     if (ec)
20943a2d0424SChris Cain                     {
20953a2d0424SChris Cain                         BMCWEB_LOG_DEBUG
20963a2d0424SChris Cain                             << "DBUS response error on PowerMode Get: " << ec;
20973a2d0424SChris Cain                         messages::internalError(aResp->res);
20983a2d0424SChris Cain                         return;
20993a2d0424SChris Cain                     }
21003a2d0424SChris Cain 
21013a2d0424SChris Cain                     const std::string* s = std::get_if<std::string>(&pmode);
21023a2d0424SChris Cain                     if (s == nullptr)
21033a2d0424SChris Cain                     {
21043a2d0424SChris Cain                         BMCWEB_LOG_DEBUG << "Unable to get PowerMode value";
21053a2d0424SChris Cain                         messages::internalError(aResp->res);
21063a2d0424SChris Cain                         return;
21073a2d0424SChris Cain                     }
21083a2d0424SChris Cain 
21093a2d0424SChris Cain                     aResp->res.jsonValue["PowerMode@Redfish.AllowableValues"] =
21103a2d0424SChris Cain                         {"Static", "MaximumPerformance", "PowerSaving"};
21113a2d0424SChris Cain 
21123a2d0424SChris Cain                     BMCWEB_LOG_DEBUG << "Current power mode: " << *s;
21133a2d0424SChris Cain                     translatePowerMode(aResp, *s);
21143a2d0424SChris Cain                 },
21153a2d0424SChris Cain                 service, path, "org.freedesktop.DBus.Properties", "Get",
21163a2d0424SChris Cain                 "xyz.openbmc_project.Control.Power.Mode", "PowerMode");
21173a2d0424SChris Cain         },
21183a2d0424SChris Cain         "xyz.openbmc_project.ObjectMapper",
21193a2d0424SChris Cain         "/xyz/openbmc_project/object_mapper",
21203a2d0424SChris Cain         "xyz.openbmc_project.ObjectMapper", "GetSubTree", "/", int32_t(0),
21213a2d0424SChris Cain         std::array<const char*, 1>{"xyz.openbmc_project.Control.Power.Mode"});
21223a2d0424SChris Cain }
21233a2d0424SChris Cain 
21243a2d0424SChris Cain /**
21253a2d0424SChris Cain  * @brief Validate the specified mode is valid and return the PowerMode
21263a2d0424SChris Cain  * name associated with that string
21273a2d0424SChris Cain  *
21283a2d0424SChris Cain  * @param[in] aResp   Shared pointer for generating response message.
21293a2d0424SChris Cain  * @param[in] modeString  String representing the desired PowerMode
21303a2d0424SChris Cain  *
21313a2d0424SChris Cain  * @return PowerMode value or empty string if mode is not valid
21323a2d0424SChris Cain  */
21333a2d0424SChris Cain inline std::string
21343a2d0424SChris Cain     validatePowerMode(const std::shared_ptr<bmcweb::AsyncResp>& aResp,
21353a2d0424SChris Cain                       const std::string& modeString)
21363a2d0424SChris Cain {
21373a2d0424SChris Cain     std::string mode;
21383a2d0424SChris Cain 
21393a2d0424SChris Cain     if (modeString == "Static")
21403a2d0424SChris Cain     {
21413a2d0424SChris Cain         mode = "xyz.openbmc_project.Control.Power.Mode.PowerMode.Static";
21423a2d0424SChris Cain     }
21433a2d0424SChris Cain     else if (modeString == "MaximumPerformance")
21443a2d0424SChris Cain     {
21453a2d0424SChris Cain         mode = "xyz.openbmc_project.Control.Power.Mode.PowerMode."
21463a2d0424SChris Cain                "MaximumPerformance";
21473a2d0424SChris Cain     }
21483a2d0424SChris Cain     else if (modeString == "PowerSaving")
21493a2d0424SChris Cain     {
21503a2d0424SChris Cain         mode = "xyz.openbmc_project.Control.Power.Mode.PowerMode.PowerSaving";
21513a2d0424SChris Cain     }
21523a2d0424SChris Cain     else
21533a2d0424SChris Cain     {
21543a2d0424SChris Cain         messages::propertyValueNotInList(aResp->res, modeString, "PowerMode");
21553a2d0424SChris Cain     }
21563a2d0424SChris Cain     return mode;
21573a2d0424SChris Cain }
21583a2d0424SChris Cain 
21593a2d0424SChris Cain /**
21603a2d0424SChris Cain  * @brief Sets system power mode.
21613a2d0424SChris Cain  *
21623a2d0424SChris Cain  * @param[in] aResp   Shared pointer for generating response message.
21633a2d0424SChris Cain  * @param[in] pmode   System power mode from request.
21643a2d0424SChris Cain  *
21653a2d0424SChris Cain  * @return None.
21663a2d0424SChris Cain  */
21673a2d0424SChris Cain inline void setPowerMode(const std::shared_ptr<bmcweb::AsyncResp>& aResp,
21683a2d0424SChris Cain                          const std::string& pmode)
21693a2d0424SChris Cain {
21703a2d0424SChris Cain     BMCWEB_LOG_DEBUG << "Set power mode.";
21713a2d0424SChris Cain 
21723a2d0424SChris Cain     std::string powerMode = validatePowerMode(aResp, pmode);
21733a2d0424SChris Cain     if (powerMode.empty())
21743a2d0424SChris Cain     {
21753a2d0424SChris Cain         return;
21763a2d0424SChris Cain     }
21773a2d0424SChris Cain 
21783a2d0424SChris Cain     // Get Power Mode object path:
21793a2d0424SChris Cain     crow::connections::systemBus->async_method_call(
21803a2d0424SChris Cain         [aResp, powerMode](
21813a2d0424SChris Cain             const boost::system::error_code ec,
21823a2d0424SChris Cain             const std::vector<std::pair<
21833a2d0424SChris Cain                 std::string,
21843a2d0424SChris Cain                 std::vector<std::pair<std::string, std::vector<std::string>>>>>&
21853a2d0424SChris Cain                 subtree) {
21863a2d0424SChris Cain             if (ec)
21873a2d0424SChris Cain             {
21883a2d0424SChris Cain                 BMCWEB_LOG_DEBUG
21893a2d0424SChris Cain                     << "DBUS response error on Power.Mode GetSubTree " << ec;
21903a2d0424SChris Cain                 // This is an optional D-Bus object, but user attempted to patch
21913a2d0424SChris Cain                 messages::internalError(aResp->res);
21923a2d0424SChris Cain                 return;
21933a2d0424SChris Cain             }
21943a2d0424SChris Cain             if (subtree.empty())
21953a2d0424SChris Cain             {
21963a2d0424SChris Cain                 // This is an optional D-Bus object, but user attempted to patch
21973a2d0424SChris Cain                 messages::resourceNotFound(aResp->res, "ComputerSystem",
21983a2d0424SChris Cain                                            "PowerMode");
21993a2d0424SChris Cain                 return;
22003a2d0424SChris Cain             }
22013a2d0424SChris Cain             if (subtree.size() > 1)
22023a2d0424SChris Cain             {
22033a2d0424SChris Cain                 // More then one PowerMode object is not supported and is an
22043a2d0424SChris Cain                 // error
22053a2d0424SChris Cain                 BMCWEB_LOG_DEBUG
22063a2d0424SChris Cain                     << "Found more than 1 system D-Bus Power.Mode objects: "
22073a2d0424SChris Cain                     << subtree.size();
22083a2d0424SChris Cain                 messages::internalError(aResp->res);
22093a2d0424SChris Cain                 return;
22103a2d0424SChris Cain             }
22113a2d0424SChris Cain             if ((subtree[0].first.empty()) || (subtree[0].second.size() != 1))
22123a2d0424SChris Cain             {
22133a2d0424SChris Cain                 BMCWEB_LOG_DEBUG << "Power.Mode mapper error!";
22143a2d0424SChris Cain                 messages::internalError(aResp->res);
22153a2d0424SChris Cain                 return;
22163a2d0424SChris Cain             }
22173a2d0424SChris Cain             const std::string& path = subtree[0].first;
22183a2d0424SChris Cain             const std::string& service = subtree[0].second.begin()->first;
22193a2d0424SChris Cain             if (service.empty())
22203a2d0424SChris Cain             {
22213a2d0424SChris Cain                 BMCWEB_LOG_DEBUG << "Power.Mode service mapper error!";
22223a2d0424SChris Cain                 messages::internalError(aResp->res);
22233a2d0424SChris Cain                 return;
22243a2d0424SChris Cain             }
22253a2d0424SChris Cain 
22263a2d0424SChris Cain             BMCWEB_LOG_DEBUG << "Setting power mode(" << powerMode << ") -> "
22273a2d0424SChris Cain                              << path;
22283a2d0424SChris Cain 
22293a2d0424SChris Cain             // Set the Power Mode property
22303a2d0424SChris Cain             crow::connections::systemBus->async_method_call(
22313a2d0424SChris Cain                 [aResp](const boost::system::error_code ec) {
22323a2d0424SChris Cain                     if (ec)
22333a2d0424SChris Cain                     {
22343a2d0424SChris Cain                         messages::internalError(aResp->res);
22353a2d0424SChris Cain                         return;
22363a2d0424SChris Cain                     }
22373a2d0424SChris Cain                 },
22383a2d0424SChris Cain                 service, path, "org.freedesktop.DBus.Properties", "Set",
22393a2d0424SChris Cain                 "xyz.openbmc_project.Control.Power.Mode", "PowerMode",
22403a2d0424SChris Cain                 std::variant<std::string>(powerMode));
22413a2d0424SChris Cain         },
22423a2d0424SChris Cain         "xyz.openbmc_project.ObjectMapper",
22433a2d0424SChris Cain         "/xyz/openbmc_project/object_mapper",
22443a2d0424SChris Cain         "xyz.openbmc_project.ObjectMapper", "GetSubTree", "/", int32_t(0),
22453a2d0424SChris Cain         std::array<const char*, 1>{"xyz.openbmc_project.Control.Power.Mode"});
22463a2d0424SChris Cain }
22473a2d0424SChris Cain 
22483a2d0424SChris Cain /**
224951709ffdSYong Li  * @brief Translates watchdog timeout action DBUS property value to redfish.
225051709ffdSYong Li  *
225151709ffdSYong Li  * @param[in] dbusAction    The watchdog timeout action in D-BUS.
225251709ffdSYong Li  *
225351709ffdSYong Li  * @return Returns as a string, the timeout action in Redfish terms. If
225451709ffdSYong Li  * translation cannot be done, returns an empty string.
225551709ffdSYong Li  */
225623a21a1cSEd Tanous inline std::string dbusToRfWatchdogAction(const std::string& dbusAction)
225751709ffdSYong Li {
225851709ffdSYong Li     if (dbusAction == "xyz.openbmc_project.State.Watchdog.Action.None")
225951709ffdSYong Li     {
226051709ffdSYong Li         return "None";
226151709ffdSYong Li     }
22623174e4dfSEd Tanous     if (dbusAction == "xyz.openbmc_project.State.Watchdog.Action.HardReset")
226351709ffdSYong Li     {
226451709ffdSYong Li         return "ResetSystem";
226551709ffdSYong Li     }
22663174e4dfSEd Tanous     if (dbusAction == "xyz.openbmc_project.State.Watchdog.Action.PowerOff")
226751709ffdSYong Li     {
226851709ffdSYong Li         return "PowerDown";
226951709ffdSYong Li     }
22703174e4dfSEd Tanous     if (dbusAction == "xyz.openbmc_project.State.Watchdog.Action.PowerCycle")
227151709ffdSYong Li     {
227251709ffdSYong Li         return "PowerCycle";
227351709ffdSYong Li     }
227451709ffdSYong Li 
227551709ffdSYong Li     return "";
227651709ffdSYong Li }
227751709ffdSYong Li 
227851709ffdSYong Li /**
2279c45f0082SYong Li  *@brief Translates timeout action from Redfish to DBUS property value.
2280c45f0082SYong Li  *
2281c45f0082SYong Li  *@param[in] rfAction The timeout action in Redfish.
2282c45f0082SYong Li  *
2283c45f0082SYong Li  *@return Returns as a string, the time_out action as expected by DBUS.
2284c45f0082SYong Li  *If translation cannot be done, returns an empty string.
2285c45f0082SYong Li  */
2286c45f0082SYong Li 
228723a21a1cSEd Tanous inline std::string rfToDbusWDTTimeOutAct(const std::string& rfAction)
2288c45f0082SYong Li {
2289c45f0082SYong Li     if (rfAction == "None")
2290c45f0082SYong Li     {
2291c45f0082SYong Li         return "xyz.openbmc_project.State.Watchdog.Action.None";
2292c45f0082SYong Li     }
22933174e4dfSEd Tanous     if (rfAction == "PowerCycle")
2294c45f0082SYong Li     {
2295c45f0082SYong Li         return "xyz.openbmc_project.State.Watchdog.Action.PowerCycle";
2296c45f0082SYong Li     }
22973174e4dfSEd Tanous     if (rfAction == "PowerDown")
2298c45f0082SYong Li     {
2299c45f0082SYong Li         return "xyz.openbmc_project.State.Watchdog.Action.PowerOff";
2300c45f0082SYong Li     }
23013174e4dfSEd Tanous     if (rfAction == "ResetSystem")
2302c45f0082SYong Li     {
2303c45f0082SYong Li         return "xyz.openbmc_project.State.Watchdog.Action.HardReset";
2304c45f0082SYong Li     }
2305c45f0082SYong Li 
2306c45f0082SYong Li     return "";
2307c45f0082SYong Li }
2308c45f0082SYong Li 
2309c45f0082SYong Li /**
231051709ffdSYong Li  * @brief Retrieves host watchdog timer properties over DBUS
231151709ffdSYong Li  *
231251709ffdSYong Li  * @param[in] aResp     Shared pointer for completing asynchronous calls.
231351709ffdSYong Li  *
231451709ffdSYong Li  * @return None.
231551709ffdSYong Li  */
23168d1b46d7Szhanghch05 inline void
23178d1b46d7Szhanghch05     getHostWatchdogTimer(const std::shared_ptr<bmcweb::AsyncResp>& aResp)
231851709ffdSYong Li {
231951709ffdSYong Li     BMCWEB_LOG_DEBUG << "Get host watchodg";
232051709ffdSYong Li     crow::connections::systemBus->async_method_call(
232151709ffdSYong Li         [aResp](const boost::system::error_code ec,
232251709ffdSYong Li                 PropertiesType& properties) {
232351709ffdSYong Li             if (ec)
232451709ffdSYong Li             {
232551709ffdSYong Li                 // watchdog service is stopped
232651709ffdSYong Li                 BMCWEB_LOG_DEBUG << "DBUS response error " << ec;
232751709ffdSYong Li                 return;
232851709ffdSYong Li             }
232951709ffdSYong Li 
233051709ffdSYong Li             BMCWEB_LOG_DEBUG << "Got " << properties.size() << " wdt prop.";
233151709ffdSYong Li 
233251709ffdSYong Li             nlohmann::json& hostWatchdogTimer =
233351709ffdSYong Li                 aResp->res.jsonValue["HostWatchdogTimer"];
233451709ffdSYong Li 
233551709ffdSYong Li             // watchdog service is running/enabled
233651709ffdSYong Li             hostWatchdogTimer["Status"]["State"] = "Enabled";
233751709ffdSYong Li 
233851709ffdSYong Li             for (const auto& property : properties)
233951709ffdSYong Li             {
234051709ffdSYong Li                 BMCWEB_LOG_DEBUG << "prop=" << property.first;
234151709ffdSYong Li                 if (property.first == "Enabled")
234251709ffdSYong Li                 {
234351709ffdSYong Li                     const bool* state = std::get_if<bool>(&property.second);
234451709ffdSYong Li 
234551709ffdSYong Li                     if (!state)
234651709ffdSYong Li                     {
234751709ffdSYong Li                         messages::internalError(aResp->res);
2348601af5edSChicago Duan                         return;
234951709ffdSYong Li                     }
235051709ffdSYong Li 
235151709ffdSYong Li                     hostWatchdogTimer["FunctionEnabled"] = *state;
235251709ffdSYong Li                 }
235351709ffdSYong Li                 else if (property.first == "ExpireAction")
235451709ffdSYong Li                 {
235551709ffdSYong Li                     const std::string* s =
235651709ffdSYong Li                         std::get_if<std::string>(&property.second);
235751709ffdSYong Li                     if (!s)
235851709ffdSYong Li                     {
235951709ffdSYong Li                         messages::internalError(aResp->res);
2360601af5edSChicago Duan                         return;
236151709ffdSYong Li                     }
236251709ffdSYong Li 
236351709ffdSYong Li                     std::string action = dbusToRfWatchdogAction(*s);
236451709ffdSYong Li                     if (action.empty())
236551709ffdSYong Li                     {
236651709ffdSYong Li                         messages::internalError(aResp->res);
2367601af5edSChicago Duan                         return;
236851709ffdSYong Li                     }
236951709ffdSYong Li                     hostWatchdogTimer["TimeoutAction"] = action;
237051709ffdSYong Li                 }
237151709ffdSYong Li             }
237251709ffdSYong Li         },
237351709ffdSYong Li         "xyz.openbmc_project.Watchdog", "/xyz/openbmc_project/watchdog/host0",
237451709ffdSYong Li         "org.freedesktop.DBus.Properties", "GetAll",
237551709ffdSYong Li         "xyz.openbmc_project.State.Watchdog");
237651709ffdSYong Li }
237751709ffdSYong Li 
237851709ffdSYong Li /**
2379c45f0082SYong Li  * @brief Sets Host WatchDog Timer properties.
2380c45f0082SYong Li  *
2381c45f0082SYong Li  * @param[in] aResp      Shared pointer for generating response message.
2382c45f0082SYong Li  * @param[in] wdtEnable  The WDTimer Enable value (true/false) from incoming
2383c45f0082SYong Li  *                       RF request.
2384c45f0082SYong Li  * @param[in] wdtTimeOutAction The WDT Timeout action, from incoming RF request.
2385c45f0082SYong Li  *
2386c45f0082SYong Li  * @return None.
2387c45f0082SYong Li  */
23888d1b46d7Szhanghch05 inline void setWDTProperties(const std::shared_ptr<bmcweb::AsyncResp>& aResp,
2389c45f0082SYong Li                              const std::optional<bool> wdtEnable,
2390c45f0082SYong Li                              const std::optional<std::string>& wdtTimeOutAction)
2391c45f0082SYong Li {
2392c45f0082SYong Li     BMCWEB_LOG_DEBUG << "Set host watchdog";
2393c45f0082SYong Li 
2394c45f0082SYong Li     if (wdtTimeOutAction)
2395c45f0082SYong Li     {
2396c45f0082SYong Li         std::string wdtTimeOutActStr = rfToDbusWDTTimeOutAct(*wdtTimeOutAction);
2397c45f0082SYong Li         // check if TimeOut Action is Valid
2398c45f0082SYong Li         if (wdtTimeOutActStr.empty())
2399c45f0082SYong Li         {
2400c45f0082SYong Li             BMCWEB_LOG_DEBUG << "Unsupported value for TimeoutAction: "
2401c45f0082SYong Li                              << *wdtTimeOutAction;
2402c45f0082SYong Li             messages::propertyValueNotInList(aResp->res, *wdtTimeOutAction,
2403c45f0082SYong Li                                              "TimeoutAction");
2404c45f0082SYong Li             return;
2405c45f0082SYong Li         }
2406c45f0082SYong Li 
2407c45f0082SYong Li         crow::connections::systemBus->async_method_call(
2408c45f0082SYong Li             [aResp](const boost::system::error_code ec) {
2409c45f0082SYong Li                 if (ec)
2410c45f0082SYong Li                 {
2411c45f0082SYong Li                     BMCWEB_LOG_DEBUG << "DBUS response error " << ec;
2412c45f0082SYong Li                     messages::internalError(aResp->res);
2413c45f0082SYong Li                     return;
2414c45f0082SYong Li                 }
2415c45f0082SYong Li             },
2416c45f0082SYong Li             "xyz.openbmc_project.Watchdog",
2417c45f0082SYong Li             "/xyz/openbmc_project/watchdog/host0",
2418c45f0082SYong Li             "org.freedesktop.DBus.Properties", "Set",
2419c45f0082SYong Li             "xyz.openbmc_project.State.Watchdog", "ExpireAction",
2420c45f0082SYong Li             std::variant<std::string>(wdtTimeOutActStr));
2421c45f0082SYong Li     }
2422c45f0082SYong Li 
2423c45f0082SYong Li     if (wdtEnable)
2424c45f0082SYong Li     {
2425c45f0082SYong Li         crow::connections::systemBus->async_method_call(
2426c45f0082SYong Li             [aResp](const boost::system::error_code ec) {
2427c45f0082SYong Li                 if (ec)
2428c45f0082SYong Li                 {
2429c45f0082SYong Li                     BMCWEB_LOG_DEBUG << "DBUS response error " << ec;
2430c45f0082SYong Li                     messages::internalError(aResp->res);
2431c45f0082SYong Li                     return;
2432c45f0082SYong Li                 }
2433c45f0082SYong Li             },
2434c45f0082SYong Li             "xyz.openbmc_project.Watchdog",
2435c45f0082SYong Li             "/xyz/openbmc_project/watchdog/host0",
2436c45f0082SYong Li             "org.freedesktop.DBus.Properties", "Set",
2437c45f0082SYong Li             "xyz.openbmc_project.State.Watchdog", "Enabled",
2438c45f0082SYong Li             std::variant<bool>(*wdtEnable));
2439c45f0082SYong Li     }
2440c45f0082SYong Li }
2441c45f0082SYong Li 
2442c45f0082SYong Li /**
2443c5b2abe0SLewanczyk, Dawid  * SystemsCollection derived class for delivering ComputerSystems Collection
2444c5b2abe0SLewanczyk, Dawid  * Schema
2445c5b2abe0SLewanczyk, Dawid  */
24467e860f15SJohn Edward Broadbent inline void requestRoutesSystemsCollection(App& app)
24471abe55efSEd Tanous {
24487e860f15SJohn Edward Broadbent     BMCWEB_ROUTE(app, "/redfish/v1/Systems/")
2449ed398213SEd Tanous         .privileges(redfish::privileges::getComputerSystemCollection)
24507e860f15SJohn Edward Broadbent         .methods(boost::beast::http::verb::get)(
24514f48d5f6SEd Tanous             [](const crow::Request& /*req*/,
24527e860f15SJohn Edward Broadbent                const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) {
24538d1b46d7Szhanghch05                 asyncResp->res.jsonValue["@odata.type"] =
24540f74e643SEd Tanous                     "#ComputerSystemCollection.ComputerSystemCollection";
24558d1b46d7Szhanghch05                 asyncResp->res.jsonValue["@odata.id"] = "/redfish/v1/Systems";
24568d1b46d7Szhanghch05                 asyncResp->res.jsonValue["Name"] = "Computer System Collection";
2457462023adSSunitha Harish 
2458462023adSSunitha Harish                 crow::connections::systemBus->async_method_call(
24594f48d5f6SEd Tanous                     [asyncResp](const boost::system::error_code ec,
2460cb13a392SEd Tanous                                 const std::variant<std::string>& /*hostName*/) {
24612c70f800SEd Tanous                         nlohmann::json& ifaceArray =
2462462023adSSunitha Harish                             asyncResp->res.jsonValue["Members"];
24632c70f800SEd Tanous                         ifaceArray = nlohmann::json::array();
24647e860f15SJohn Edward Broadbent                         auto& count =
24657e860f15SJohn Edward Broadbent                             asyncResp->res.jsonValue["Members@odata.count"];
24662c70f800SEd Tanous                         ifaceArray.push_back(
2467cb13a392SEd Tanous                             {{"@odata.id", "/redfish/v1/Systems/system"}});
246894bda602STim Lee                         count = ifaceArray.size();
2469cb13a392SEd Tanous                         if (!ec)
2470462023adSSunitha Harish                         {
2471462023adSSunitha Harish                             BMCWEB_LOG_DEBUG << "Hypervisor is available";
24722c70f800SEd Tanous                             ifaceArray.push_back(
24737e860f15SJohn Edward Broadbent                                 {{"@odata.id",
24747e860f15SJohn Edward Broadbent                                   "/redfish/v1/Systems/hypervisor"}});
24752c70f800SEd Tanous                             count = ifaceArray.size();
2476cb13a392SEd Tanous                         }
2477462023adSSunitha Harish                     },
24788e651fbfSSunitha Harish                     "xyz.openbmc_project.Settings",
24798e651fbfSSunitha Harish                     "/xyz/openbmc_project/network/hypervisor",
2480462023adSSunitha Harish                     "org.freedesktop.DBus.Properties", "Get",
24817e860f15SJohn Edward Broadbent                     "xyz.openbmc_project.Network.SystemConfiguration",
24827e860f15SJohn Edward Broadbent                     "HostName");
24837e860f15SJohn Edward Broadbent             });
2484c5b2abe0SLewanczyk, Dawid }
24857e860f15SJohn Edward Broadbent 
24867e860f15SJohn Edward Broadbent /**
24877e860f15SJohn Edward Broadbent  * Function transceives data with dbus directly.
24887e860f15SJohn Edward Broadbent  */
24894f48d5f6SEd Tanous inline void doNMI(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp)
24907e860f15SJohn Edward Broadbent {
24917e860f15SJohn Edward Broadbent     constexpr char const* serviceName = "xyz.openbmc_project.Control.Host.NMI";
24927e860f15SJohn Edward Broadbent     constexpr char const* objectPath = "/xyz/openbmc_project/control/host0/nmi";
24937e860f15SJohn Edward Broadbent     constexpr char const* interfaceName =
24947e860f15SJohn Edward Broadbent         "xyz.openbmc_project.Control.Host.NMI";
24957e860f15SJohn Edward Broadbent     constexpr char const* method = "NMI";
24967e860f15SJohn Edward Broadbent 
24977e860f15SJohn Edward Broadbent     crow::connections::systemBus->async_method_call(
24987e860f15SJohn Edward Broadbent         [asyncResp](const boost::system::error_code ec) {
24997e860f15SJohn Edward Broadbent             if (ec)
25007e860f15SJohn Edward Broadbent             {
25017e860f15SJohn Edward Broadbent                 BMCWEB_LOG_ERROR << " Bad D-Bus request error: " << ec;
25027e860f15SJohn Edward Broadbent                 messages::internalError(asyncResp->res);
25037e860f15SJohn Edward Broadbent                 return;
25047e860f15SJohn Edward Broadbent             }
25057e860f15SJohn Edward Broadbent             messages::success(asyncResp->res);
25067e860f15SJohn Edward Broadbent         },
25077e860f15SJohn Edward Broadbent         serviceName, objectPath, interfaceName, method);
25087e860f15SJohn Edward Broadbent }
2509c5b2abe0SLewanczyk, Dawid 
2510c5b2abe0SLewanczyk, Dawid /**
2511cc340dd9SEd Tanous  * SystemActionsReset class supports handle POST method for Reset action.
2512cc340dd9SEd Tanous  * The class retrieves and sends data directly to D-Bus.
2513cc340dd9SEd Tanous  */
25147e860f15SJohn Edward Broadbent inline void requestRoutesSystemActionsReset(App& app)
2515cc340dd9SEd Tanous {
2516cc340dd9SEd Tanous     /**
2517cc340dd9SEd Tanous      * Function handles POST method request.
2518cc340dd9SEd Tanous      * Analyzes POST body message before sends Reset request data to D-Bus.
2519cc340dd9SEd Tanous      */
25207e860f15SJohn Edward Broadbent     BMCWEB_ROUTE(app,
25217e860f15SJohn Edward Broadbent                  "/redfish/v1/Systems/system/Actions/ComputerSystem.Reset/")
2522ed398213SEd Tanous         .privileges(redfish::privileges::postComputerSystem)
25237e860f15SJohn Edward Broadbent         .methods(
25247e860f15SJohn Edward Broadbent             boost::beast::http::verb::
25257e860f15SJohn Edward Broadbent                 post)([](const crow::Request& req,
25267e860f15SJohn Edward Broadbent                          const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) {
25279712f8acSEd Tanous             std::string resetType;
25287e860f15SJohn Edward Broadbent             if (!json_util::readJson(req, asyncResp->res, "ResetType",
25297e860f15SJohn Edward Broadbent                                      resetType))
2530cc340dd9SEd Tanous             {
2531cc340dd9SEd Tanous                 return;
2532cc340dd9SEd Tanous             }
2533cc340dd9SEd Tanous 
2534d22c8396SJason M. Bills             // Get the command and host vs. chassis
2535cc340dd9SEd Tanous             std::string command;
2536d22c8396SJason M. Bills             bool hostCommand;
2537d4d25793SEd Tanous             if ((resetType == "On") || (resetType == "ForceOn"))
2538cc340dd9SEd Tanous             {
2539cc340dd9SEd Tanous                 command = "xyz.openbmc_project.State.Host.Transition.On";
2540d22c8396SJason M. Bills                 hostCommand = true;
2541d22c8396SJason M. Bills             }
2542d22c8396SJason M. Bills             else if (resetType == "ForceOff")
2543d22c8396SJason M. Bills             {
2544d22c8396SJason M. Bills                 command = "xyz.openbmc_project.State.Chassis.Transition.Off";
2545d22c8396SJason M. Bills                 hostCommand = false;
2546d22c8396SJason M. Bills             }
2547d22c8396SJason M. Bills             else if (resetType == "ForceRestart")
2548d22c8396SJason M. Bills             {
254986a0851aSJason M. Bills                 command =
255086a0851aSJason M. Bills                     "xyz.openbmc_project.State.Host.Transition.ForceWarmReboot";
255186a0851aSJason M. Bills                 hostCommand = true;
2552cc340dd9SEd Tanous             }
25539712f8acSEd Tanous             else if (resetType == "GracefulShutdown")
2554cc340dd9SEd Tanous             {
2555cc340dd9SEd Tanous                 command = "xyz.openbmc_project.State.Host.Transition.Off";
2556d22c8396SJason M. Bills                 hostCommand = true;
2557cc340dd9SEd Tanous             }
25589712f8acSEd Tanous             else if (resetType == "GracefulRestart")
2559cc340dd9SEd Tanous             {
25607e860f15SJohn Edward Broadbent                 command = "xyz.openbmc_project.State.Host.Transition."
25617e860f15SJohn Edward Broadbent                           "GracefulWarmReboot";
2562d22c8396SJason M. Bills                 hostCommand = true;
2563d22c8396SJason M. Bills             }
2564d22c8396SJason M. Bills             else if (resetType == "PowerCycle")
2565d22c8396SJason M. Bills             {
256686a0851aSJason M. Bills                 command = "xyz.openbmc_project.State.Host.Transition.Reboot";
256786a0851aSJason M. Bills                 hostCommand = true;
2568cc340dd9SEd Tanous             }
2569bfd5b826SLakshminarayana R. Kammath             else if (resetType == "Nmi")
2570bfd5b826SLakshminarayana R. Kammath             {
2571bfd5b826SLakshminarayana R. Kammath                 doNMI(asyncResp);
2572bfd5b826SLakshminarayana R. Kammath                 return;
2573bfd5b826SLakshminarayana R. Kammath             }
2574cc340dd9SEd Tanous             else
2575cc340dd9SEd Tanous             {
25768d1b46d7Szhanghch05                 messages::actionParameterUnknown(asyncResp->res, "Reset",
25778d1b46d7Szhanghch05                                                  resetType);
2578cc340dd9SEd Tanous                 return;
2579cc340dd9SEd Tanous             }
2580cc340dd9SEd Tanous 
2581d22c8396SJason M. Bills             if (hostCommand)
2582d22c8396SJason M. Bills             {
2583cc340dd9SEd Tanous                 crow::connections::systemBus->async_method_call(
2584d22c8396SJason M. Bills                     [asyncResp, resetType](const boost::system::error_code ec) {
2585cc340dd9SEd Tanous                         if (ec)
2586cc340dd9SEd Tanous                         {
2587cc340dd9SEd Tanous                             BMCWEB_LOG_ERROR << "D-Bus responses error: " << ec;
25887e860f15SJohn Edward Broadbent                             if (ec.value() ==
25897e860f15SJohn Edward Broadbent                                 boost::asio::error::invalid_argument)
2590d22c8396SJason M. Bills                             {
2591d22c8396SJason M. Bills                                 messages::actionParameterNotSupported(
2592d22c8396SJason M. Bills                                     asyncResp->res, resetType, "Reset");
2593d22c8396SJason M. Bills                             }
2594d22c8396SJason M. Bills                             else
2595d22c8396SJason M. Bills                             {
2596f12894f8SJason M. Bills                                 messages::internalError(asyncResp->res);
2597d22c8396SJason M. Bills                             }
2598cc340dd9SEd Tanous                             return;
2599cc340dd9SEd Tanous                         }
2600f12894f8SJason M. Bills                         messages::success(asyncResp->res);
2601cc340dd9SEd Tanous                     },
2602cc340dd9SEd Tanous                     "xyz.openbmc_project.State.Host",
2603cc340dd9SEd Tanous                     "/xyz/openbmc_project/state/host0",
2604cc340dd9SEd Tanous                     "org.freedesktop.DBus.Properties", "Set",
26059712f8acSEd Tanous                     "xyz.openbmc_project.State.Host", "RequestedHostTransition",
2606abf2add6SEd Tanous                     std::variant<std::string>{command});
2607cc340dd9SEd Tanous             }
2608d22c8396SJason M. Bills             else
2609d22c8396SJason M. Bills             {
2610d22c8396SJason M. Bills                 crow::connections::systemBus->async_method_call(
2611d22c8396SJason M. Bills                     [asyncResp, resetType](const boost::system::error_code ec) {
2612d22c8396SJason M. Bills                         if (ec)
2613d22c8396SJason M. Bills                         {
2614d22c8396SJason M. Bills                             BMCWEB_LOG_ERROR << "D-Bus responses error: " << ec;
26157e860f15SJohn Edward Broadbent                             if (ec.value() ==
26167e860f15SJohn Edward Broadbent                                 boost::asio::error::invalid_argument)
2617d22c8396SJason M. Bills                             {
2618d22c8396SJason M. Bills                                 messages::actionParameterNotSupported(
2619d22c8396SJason M. Bills                                     asyncResp->res, resetType, "Reset");
2620d22c8396SJason M. Bills                             }
2621d22c8396SJason M. Bills                             else
2622d22c8396SJason M. Bills                             {
2623d22c8396SJason M. Bills                                 messages::internalError(asyncResp->res);
2624d22c8396SJason M. Bills                             }
2625d22c8396SJason M. Bills                             return;
2626d22c8396SJason M. Bills                         }
2627d22c8396SJason M. Bills                         messages::success(asyncResp->res);
2628d22c8396SJason M. Bills                     },
2629d22c8396SJason M. Bills                     "xyz.openbmc_project.State.Chassis",
2630d22c8396SJason M. Bills                     "/xyz/openbmc_project/state/chassis0",
2631d22c8396SJason M. Bills                     "org.freedesktop.DBus.Properties", "Set",
26327e860f15SJohn Edward Broadbent                     "xyz.openbmc_project.State.Chassis",
26337e860f15SJohn Edward Broadbent                     "RequestedPowerTransition",
2634d22c8396SJason M. Bills                     std::variant<std::string>{command});
2635d22c8396SJason M. Bills             }
26367e860f15SJohn Edward Broadbent         });
2637d22c8396SJason M. Bills }
2638cc340dd9SEd Tanous 
2639cc340dd9SEd Tanous /**
26406617338dSEd Tanous  * Systems derived class for delivering Computer Systems Schema.
2641c5b2abe0SLewanczyk, Dawid  */
26427e860f15SJohn Edward Broadbent inline void requestRoutesSystems(App& app)
26431abe55efSEd Tanous {
2644c5b2abe0SLewanczyk, Dawid 
2645c5b2abe0SLewanczyk, Dawid     /**
2646c5b2abe0SLewanczyk, Dawid      * Functions triggers appropriate requests on DBus
2647c5b2abe0SLewanczyk, Dawid      */
26487e860f15SJohn Edward Broadbent     BMCWEB_ROUTE(app, "/redfish/v1/Systems/system/")
2649ed398213SEd Tanous         .privileges(redfish::privileges::getComputerSystem)
26507e860f15SJohn Edward Broadbent         .methods(
26517e860f15SJohn Edward Broadbent             boost::beast::http::verb::
26527e860f15SJohn Edward Broadbent                 get)([](const crow::Request&,
26537e860f15SJohn Edward Broadbent                         const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) {
26548d1b46d7Szhanghch05             asyncResp->res.jsonValue["@odata.type"] =
26553a2d0424SChris Cain                 "#ComputerSystem.v1_15_0.ComputerSystem";
26568d1b46d7Szhanghch05             asyncResp->res.jsonValue["Name"] = "system";
26578d1b46d7Szhanghch05             asyncResp->res.jsonValue["Id"] = "system";
26588d1b46d7Szhanghch05             asyncResp->res.jsonValue["SystemType"] = "Physical";
26598d1b46d7Szhanghch05             asyncResp->res.jsonValue["Description"] = "Computer System";
26608d1b46d7Szhanghch05             asyncResp->res.jsonValue["ProcessorSummary"]["Count"] = 0;
26618d1b46d7Szhanghch05             asyncResp->res.jsonValue["ProcessorSummary"]["Status"]["State"] =
26628d1b46d7Szhanghch05                 "Disabled";
26638d1b46d7Szhanghch05             asyncResp->res.jsonValue["MemorySummary"]["TotalSystemMemoryGiB"] =
26648d1b46d7Szhanghch05                 uint64_t(0);
26658d1b46d7Szhanghch05             asyncResp->res.jsonValue["MemorySummary"]["Status"]["State"] =
26668d1b46d7Szhanghch05                 "Disabled";
26677e860f15SJohn Edward Broadbent             asyncResp->res.jsonValue["@odata.id"] =
26687e860f15SJohn Edward Broadbent                 "/redfish/v1/Systems/system";
266904a258f4SEd Tanous 
26708d1b46d7Szhanghch05             asyncResp->res.jsonValue["Processors"] = {
2671029573d4SEd Tanous                 {"@odata.id", "/redfish/v1/Systems/system/Processors"}};
26728d1b46d7Szhanghch05             asyncResp->res.jsonValue["Memory"] = {
2673029573d4SEd Tanous                 {"@odata.id", "/redfish/v1/Systems/system/Memory"}};
26748d1b46d7Szhanghch05             asyncResp->res.jsonValue["Storage"] = {
2675a25aeccfSNikhil Potade                 {"@odata.id", "/redfish/v1/Systems/system/Storage"}};
2676029573d4SEd Tanous 
26778d1b46d7Szhanghch05             asyncResp->res.jsonValue["Actions"]["#ComputerSystem.Reset"] = {
2678cc340dd9SEd Tanous                 {"target",
2679029573d4SEd Tanous                  "/redfish/v1/Systems/system/Actions/ComputerSystem.Reset"},
26801cb1a9e6SAppaRao Puli                 {"@Redfish.ActionInfo",
26811cb1a9e6SAppaRao Puli                  "/redfish/v1/Systems/system/ResetActionInfo"}};
2682c5b2abe0SLewanczyk, Dawid 
26838d1b46d7Szhanghch05             asyncResp->res.jsonValue["LogServices"] = {
2684029573d4SEd Tanous                 {"@odata.id", "/redfish/v1/Systems/system/LogServices"}};
2685c4bf6374SJason M. Bills 
26868d1b46d7Szhanghch05             asyncResp->res.jsonValue["Bios"] = {
2687d82a3acdSCarol Wang                 {"@odata.id", "/redfish/v1/Systems/system/Bios"}};
2688d82a3acdSCarol Wang 
26898d1b46d7Szhanghch05             asyncResp->res.jsonValue["Links"]["ManagedBy"] = {
2690c5d03ff4SJennifer Lee                 {{"@odata.id", "/redfish/v1/Managers/bmc"}}};
2691c5d03ff4SJennifer Lee 
26928d1b46d7Szhanghch05             asyncResp->res.jsonValue["Status"] = {
2693c5d03ff4SJennifer Lee                 {"Health", "OK"},
2694c5d03ff4SJennifer Lee                 {"State", "Enabled"},
2695c5d03ff4SJennifer Lee             };
26960e8ac5e7SGunnar Mills 
26970e8ac5e7SGunnar Mills             // Fill in SerialConsole info
26980e8ac5e7SGunnar Mills             asyncResp->res.jsonValue["SerialConsole"]["MaxConcurrentSessions"] =
26990e8ac5e7SGunnar Mills                 15;
27000e8ac5e7SGunnar Mills             asyncResp->res.jsonValue["SerialConsole"]["IPMI"] = {
27010e8ac5e7SGunnar Mills                 {"ServiceEnabled", true},
27020e8ac5e7SGunnar Mills             };
27030e8ac5e7SGunnar Mills             // TODO (Gunnar): Should look for obmc-console-ssh@2200.service
27040e8ac5e7SGunnar Mills             asyncResp->res.jsonValue["SerialConsole"]["SSH"] = {
27050e8ac5e7SGunnar Mills                 {"ServiceEnabled", true},
27060e8ac5e7SGunnar Mills                 {"Port", 2200},
27070e8ac5e7SGunnar Mills                 // https://github.com/openbmc/docs/blob/master/console.md
27080e8ac5e7SGunnar Mills                 {"HotKeySequenceDisplay", "Press ~. to exit console"},
27090e8ac5e7SGunnar Mills             };
27100e8ac5e7SGunnar Mills 
27110e8ac5e7SGunnar Mills #ifdef BMCWEB_ENABLE_KVM
27120e8ac5e7SGunnar Mills             // Fill in GraphicalConsole info
27130e8ac5e7SGunnar Mills             asyncResp->res.jsonValue["GraphicalConsole"] = {
27140e8ac5e7SGunnar Mills                 {"ServiceEnabled", true},
27150e8ac5e7SGunnar Mills                 {"MaxConcurrentSessions", 4},
27160e8ac5e7SGunnar Mills                 {"ConnectTypesSupported", {"KVMIP"}},
27170e8ac5e7SGunnar Mills             };
27180e8ac5e7SGunnar Mills #endif // BMCWEB_ENABLE_KVM
2719e284a7c1SJames Feist             constexpr const std::array<const char*, 4> inventoryForSystems = {
2720b49ac873SJames Feist                 "xyz.openbmc_project.Inventory.Item.Dimm",
27212ad9c2f6SJames Feist                 "xyz.openbmc_project.Inventory.Item.Cpu",
2722e284a7c1SJames Feist                 "xyz.openbmc_project.Inventory.Item.Drive",
2723e284a7c1SJames Feist                 "xyz.openbmc_project.Inventory.Item.StorageController"};
2724b49ac873SJames Feist 
2725b49ac873SJames Feist             auto health = std::make_shared<HealthPopulate>(asyncResp);
2726b49ac873SJames Feist             crow::connections::systemBus->async_method_call(
2727b49ac873SJames Feist                 [health](const boost::system::error_code ec,
2728b49ac873SJames Feist                          std::vector<std::string>& resp) {
2729b49ac873SJames Feist                     if (ec)
2730b49ac873SJames Feist                     {
2731b49ac873SJames Feist                         // no inventory
2732b49ac873SJames Feist                         return;
2733b49ac873SJames Feist                     }
2734b49ac873SJames Feist 
2735b49ac873SJames Feist                     health->inventory = std::move(resp);
2736b49ac873SJames Feist                 },
2737b49ac873SJames Feist                 "xyz.openbmc_project.ObjectMapper",
2738b49ac873SJames Feist                 "/xyz/openbmc_project/object_mapper",
2739b49ac873SJames Feist                 "xyz.openbmc_project.ObjectMapper", "GetSubTreePaths", "/",
2740b49ac873SJames Feist                 int32_t(0), inventoryForSystems);
2741b49ac873SJames Feist 
2742b49ac873SJames Feist             health->populate();
2743b49ac873SJames Feist 
27448d1b46d7Szhanghch05             getMainChassisId(
27458d1b46d7Szhanghch05                 asyncResp, [](const std::string& chassisId,
27468d1b46d7Szhanghch05                               const std::shared_ptr<bmcweb::AsyncResp>& aRsp) {
2747c5d03ff4SJennifer Lee                     aRsp->res.jsonValue["Links"]["Chassis"] = {
2748c5d03ff4SJennifer Lee                         {{"@odata.id", "/redfish/v1/Chassis/" + chassisId}}};
2749c5d03ff4SJennifer Lee                 });
2750a3002228SAppaRao Puli 
27519f8bfa7cSGunnar Mills             getLocationIndicatorActive(asyncResp);
27529f8bfa7cSGunnar Mills             // TODO (Gunnar): Remove IndicatorLED after enough time has passed
2753a3002228SAppaRao Puli             getIndicatorLedState(asyncResp);
27545bc2dc8eSJames Feist             getComputerSystem(asyncResp, health);
27556c34de48SEd Tanous             getHostState(asyncResp);
2756491d8ee7SSantosh Puranik             getBootProperties(asyncResp);
2757978b8803SAndrew Geissler             getBootProgress(asyncResp);
2758adbe192aSJason M. Bills             getPCIeDeviceList(asyncResp, "PCIeDevices");
275951709ffdSYong Li             getHostWatchdogTimer(asyncResp);
2760c6a620f2SGeorge Liu             getPowerRestorePolicy(asyncResp);
27616bd5a8d2SGunnar Mills             getAutomaticRetry(asyncResp);
2762c0557e1aSGunnar Mills             getLastResetTime(asyncResp);
2763a6349918SAppaRao Puli #ifdef BMCWEB_ENABLE_REDFISH_PROVISIONING_FEATURE
2764a6349918SAppaRao Puli             getProvisioningStatus(asyncResp);
2765a6349918SAppaRao Puli #endif
27661981771bSAli Ahmed             getTrustedModuleRequiredToBoot(asyncResp);
27673a2d0424SChris Cain             getPowerMode(asyncResp);
27687e860f15SJohn Edward Broadbent         });
27697e860f15SJohn Edward Broadbent     BMCWEB_ROUTE(app, "/redfish/v1/Systems/system/")
2770ed398213SEd Tanous         .privileges(redfish::privileges::patchComputerSystem)
27717e860f15SJohn Edward Broadbent         .methods(boost::beast::http::verb::patch)(
27727e860f15SJohn Edward Broadbent             [](const crow::Request& req,
27737e860f15SJohn Edward Broadbent                const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) {
27749f8bfa7cSGunnar Mills                 std::optional<bool> locationIndicatorActive;
2775cde19e5fSSantosh Puranik                 std::optional<std::string> indicatorLed;
2776491d8ee7SSantosh Puranik                 std::optional<nlohmann::json> bootProps;
2777c45f0082SYong Li                 std::optional<nlohmann::json> wdtTimerProps;
277898e386ecSGunnar Mills                 std::optional<std::string> assetTag;
2779c6a620f2SGeorge Liu                 std::optional<std::string> powerRestorePolicy;
27803a2d0424SChris Cain                 std::optional<std::string> powerMode;
27819f8bfa7cSGunnar Mills                 if (!json_util::readJson(
27828d1b46d7Szhanghch05                         req, asyncResp->res, "IndicatorLED", indicatorLed,
27837e860f15SJohn Edward Broadbent                         "LocationIndicatorActive", locationIndicatorActive,
27847e860f15SJohn Edward Broadbent                         "Boot", bootProps, "WatchdogTimer", wdtTimerProps,
27857e860f15SJohn Edward Broadbent                         "PowerRestorePolicy", powerRestorePolicy, "AssetTag",
2786*ac7e1e0bSAli Ahmed                         assetTag, "PowerMode", powerMode))
27876617338dSEd Tanous                 {
27886617338dSEd Tanous                     return;
27896617338dSEd Tanous                 }
2790491d8ee7SSantosh Puranik 
27918d1b46d7Szhanghch05                 asyncResp->res.result(boost::beast::http::status::no_content);
2792c45f0082SYong Li 
279398e386ecSGunnar Mills                 if (assetTag)
279498e386ecSGunnar Mills                 {
279598e386ecSGunnar Mills                     setAssetTag(asyncResp, *assetTag);
279698e386ecSGunnar Mills                 }
279798e386ecSGunnar Mills 
2798c45f0082SYong Li                 if (wdtTimerProps)
2799c45f0082SYong Li                 {
2800c45f0082SYong Li                     std::optional<bool> wdtEnable;
2801c45f0082SYong Li                     std::optional<std::string> wdtTimeOutAction;
2802c45f0082SYong Li 
2803c45f0082SYong Li                     if (!json_util::readJson(*wdtTimerProps, asyncResp->res,
2804c45f0082SYong Li                                              "FunctionEnabled", wdtEnable,
2805c45f0082SYong Li                                              "TimeoutAction", wdtTimeOutAction))
2806c45f0082SYong Li                     {
2807c45f0082SYong Li                         return;
2808c45f0082SYong Li                     }
2809f23b7296SEd Tanous                     setWDTProperties(asyncResp, wdtEnable, wdtTimeOutAction);
2810c45f0082SYong Li                 }
2811c45f0082SYong Li 
2812491d8ee7SSantosh Puranik                 if (bootProps)
2813491d8ee7SSantosh Puranik                 {
2814491d8ee7SSantosh Puranik                     std::optional<std::string> bootSource;
2815cd9a4666SKonstantin Aladyshev                     std::optional<std::string> bootType;
2816491d8ee7SSantosh Puranik                     std::optional<std::string> bootEnable;
281769f35306SGunnar Mills                     std::optional<std::string> automaticRetryConfig;
2818*ac7e1e0bSAli Ahmed                     std::optional<bool> trustedModuleRequiredToBoot;
2819491d8ee7SSantosh Puranik 
282069f35306SGunnar Mills                     if (!json_util::readJson(
28217e860f15SJohn Edward Broadbent                             *bootProps, asyncResp->res,
28227e860f15SJohn Edward Broadbent                             "BootSourceOverrideTarget", bootSource,
2823cd9a4666SKonstantin Aladyshev                             "BootSourceOverrideMode", bootType,
28247e860f15SJohn Edward Broadbent                             "BootSourceOverrideEnabled", bootEnable,
2825*ac7e1e0bSAli Ahmed                             "AutomaticRetryConfig", automaticRetryConfig,
2826*ac7e1e0bSAli Ahmed                             "TrustedModuleRequiredToBoot",
2827*ac7e1e0bSAli Ahmed                             trustedModuleRequiredToBoot))
2828491d8ee7SSantosh Puranik                     {
2829491d8ee7SSantosh Puranik                         return;
2830491d8ee7SSantosh Puranik                     }
2831c21865c4SKonstantin Aladyshev 
2832cd9a4666SKonstantin Aladyshev                     if (bootSource || bootType || bootEnable)
283369f35306SGunnar Mills                     {
2834c21865c4SKonstantin Aladyshev                         setBootProperties(asyncResp, bootSource, bootType,
2835c21865c4SKonstantin Aladyshev                                           bootEnable);
2836491d8ee7SSantosh Puranik                     }
283769f35306SGunnar Mills                     if (automaticRetryConfig)
283869f35306SGunnar Mills                     {
2839f23b7296SEd Tanous                         setAutomaticRetry(asyncResp, *automaticRetryConfig);
284069f35306SGunnar Mills                     }
2841*ac7e1e0bSAli Ahmed 
2842*ac7e1e0bSAli Ahmed                     if (trustedModuleRequiredToBoot)
2843*ac7e1e0bSAli Ahmed                     {
2844*ac7e1e0bSAli Ahmed                         setTrustedModuleRequiredToBoot(
2845*ac7e1e0bSAli Ahmed                             asyncResp, *trustedModuleRequiredToBoot);
2846*ac7e1e0bSAli Ahmed                     }
284769f35306SGunnar Mills                 }
2848265c1602SJohnathan Mantey 
28499f8bfa7cSGunnar Mills                 if (locationIndicatorActive)
28509f8bfa7cSGunnar Mills                 {
28517e860f15SJohn Edward Broadbent                     setLocationIndicatorActive(asyncResp,
28527e860f15SJohn Edward Broadbent                                                *locationIndicatorActive);
28539f8bfa7cSGunnar Mills                 }
28549f8bfa7cSGunnar Mills 
28557e860f15SJohn Edward Broadbent                 // TODO (Gunnar): Remove IndicatorLED after enough time has
28567e860f15SJohn Edward Broadbent                 // passed
28579712f8acSEd Tanous                 if (indicatorLed)
28586617338dSEd Tanous                 {
2859f23b7296SEd Tanous                     setIndicatorLedState(asyncResp, *indicatorLed);
28607e860f15SJohn Edward Broadbent                     asyncResp->res.addHeader(
28617e860f15SJohn Edward Broadbent                         boost::beast::http::field::warning,
2862d6aa0093SGunnar Mills                         "299 - \"IndicatorLED is deprecated. Use "
2863d6aa0093SGunnar Mills                         "LocationIndicatorActive instead.\"");
28646617338dSEd Tanous                 }
2865c6a620f2SGeorge Liu 
2866c6a620f2SGeorge Liu                 if (powerRestorePolicy)
2867c6a620f2SGeorge Liu                 {
28684e69c904SGunnar Mills                     setPowerRestorePolicy(asyncResp, *powerRestorePolicy);
2869c6a620f2SGeorge Liu                 }
28703a2d0424SChris Cain 
28713a2d0424SChris Cain                 if (powerMode)
28723a2d0424SChris Cain                 {
28733a2d0424SChris Cain                     setPowerMode(asyncResp, *powerMode);
28743a2d0424SChris Cain                 }
28757e860f15SJohn Edward Broadbent             });
2876c5b2abe0SLewanczyk, Dawid }
28771cb1a9e6SAppaRao Puli 
28781cb1a9e6SAppaRao Puli /**
28791cb1a9e6SAppaRao Puli  * SystemResetActionInfo derived class for delivering Computer Systems
28801cb1a9e6SAppaRao Puli  * ResetType AllowableValues using ResetInfo schema.
28811cb1a9e6SAppaRao Puli  */
28827e860f15SJohn Edward Broadbent inline void requestRoutesSystemResetActionInfo(App& app)
28831cb1a9e6SAppaRao Puli {
28841cb1a9e6SAppaRao Puli 
28851cb1a9e6SAppaRao Puli     /**
28861cb1a9e6SAppaRao Puli      * Functions triggers appropriate requests on DBus
28871cb1a9e6SAppaRao Puli      */
28887e860f15SJohn Edward Broadbent     BMCWEB_ROUTE(app, "/redfish/v1/Systems/system/ResetActionInfo/")
2889ed398213SEd Tanous         .privileges(redfish::privileges::getActionInfo)
28907e860f15SJohn Edward Broadbent         .methods(boost::beast::http::verb::get)(
28917e860f15SJohn Edward Broadbent             [](const crow::Request&,
28927e860f15SJohn Edward Broadbent                const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) {
28938d1b46d7Szhanghch05                 asyncResp->res.jsonValue = {
28941cb1a9e6SAppaRao Puli                     {"@odata.type", "#ActionInfo.v1_1_2.ActionInfo"},
28951cb1a9e6SAppaRao Puli                     {"@odata.id", "/redfish/v1/Systems/system/ResetActionInfo"},
28961cb1a9e6SAppaRao Puli                     {"Name", "Reset Action Info"},
28971cb1a9e6SAppaRao Puli                     {"Id", "ResetActionInfo"},
28981cb1a9e6SAppaRao Puli                     {"Parameters",
28991cb1a9e6SAppaRao Puli                      {{{"Name", "ResetType"},
29001cb1a9e6SAppaRao Puli                        {"Required", true},
29011cb1a9e6SAppaRao Puli                        {"DataType", "String"},
29021cb1a9e6SAppaRao Puli                        {"AllowableValues",
29037e860f15SJohn Edward Broadbent                         {"On", "ForceOff", "ForceOn", "ForceRestart",
29047e860f15SJohn Edward Broadbent                          "GracefulRestart", "GracefulShutdown", "PowerCycle",
29057e860f15SJohn Edward Broadbent                          "Nmi"}}}}}};
29067e860f15SJohn Edward Broadbent             });
29071cb1a9e6SAppaRao Puli }
2908c5b2abe0SLewanczyk, Dawid } // namespace redfish
2909