xref: /openbmc/bmcweb/features/redfish/lib/systems.hpp (revision c5d03ff4737b1f4e4eb7e59f533d6c5a1faeeab5)
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 
18*c5d03ff4SJennifer Lee #include "redfish_util.hpp"
19*c5d03ff4SJennifer Lee 
209712f8acSEd Tanous #include <boost/container/flat_map.hpp>
219712f8acSEd Tanous #include <node.hpp>
22cb7e1e7bSAndrew Geissler #include <utils/fw_utils.hpp>
23c5b2abe0SLewanczyk, Dawid #include <utils/json_utils.hpp>
24abf2add6SEd Tanous #include <variant>
25c5b2abe0SLewanczyk, Dawid 
261abe55efSEd Tanous namespace redfish
271abe55efSEd Tanous {
28c5b2abe0SLewanczyk, Dawid 
29c5b2abe0SLewanczyk, Dawid /**
30c5b2abe0SLewanczyk, Dawid  * @brief Retrieves computer system properties over dbus
31c5b2abe0SLewanczyk, Dawid  *
32c5b2abe0SLewanczyk, Dawid  * @param[in] aResp Shared pointer for completing asynchronous calls
33c5b2abe0SLewanczyk, Dawid  * @param[in] name  Computer system name from request
34c5b2abe0SLewanczyk, Dawid  *
35c5b2abe0SLewanczyk, Dawid  * @return None.
36c5b2abe0SLewanczyk, Dawid  */
37029573d4SEd Tanous void getComputerSystem(std::shared_ptr<AsyncResp> aResp)
381abe55efSEd Tanous {
3955c7b7a2SEd Tanous     BMCWEB_LOG_DEBUG << "Get available system components.";
4055c7b7a2SEd Tanous     crow::connections::systemBus->async_method_call(
41*c5d03ff4SJennifer Lee         [aResp](
42c5b2abe0SLewanczyk, Dawid             const boost::system::error_code ec,
43c5b2abe0SLewanczyk, Dawid             const std::vector<std::pair<
446c34de48SEd Tanous                 std::string,
456c34de48SEd Tanous                 std::vector<std::pair<std::string, std::vector<std::string>>>>>
46c5b2abe0SLewanczyk, Dawid                 &subtree) {
471abe55efSEd Tanous             if (ec)
481abe55efSEd Tanous             {
4955c7b7a2SEd Tanous                 BMCWEB_LOG_DEBUG << "DBUS response error";
50f12894f8SJason M. Bills                 messages::internalError(aResp->res);
51c5b2abe0SLewanczyk, Dawid                 return;
52c5b2abe0SLewanczyk, Dawid             }
53c5b2abe0SLewanczyk, Dawid             // Iterate over all retrieved ObjectPaths.
546c34de48SEd Tanous             for (const std::pair<std::string,
556c34de48SEd Tanous                                  std::vector<std::pair<
566c34de48SEd Tanous                                      std::string, std::vector<std::string>>>>
571abe55efSEd Tanous                      &object : subtree)
581abe55efSEd Tanous             {
59c5b2abe0SLewanczyk, Dawid                 const std::string &path = object.first;
6055c7b7a2SEd Tanous                 BMCWEB_LOG_DEBUG << "Got path: " << path;
611abe55efSEd Tanous                 const std::vector<
621abe55efSEd Tanous                     std::pair<std::string, std::vector<std::string>>>
63c5b2abe0SLewanczyk, Dawid                     &connectionNames = object.second;
641abe55efSEd Tanous                 if (connectionNames.size() < 1)
651abe55efSEd Tanous                 {
66c5b2abe0SLewanczyk, Dawid                     continue;
67c5b2abe0SLewanczyk, Dawid                 }
68029573d4SEd Tanous 
696c34de48SEd Tanous                 // This is not system, so check if it's cpu, dimm, UUID or
706c34de48SEd Tanous                 // BiosVer
7104a258f4SEd Tanous                 for (const auto &connection : connectionNames)
721abe55efSEd Tanous                 {
7304a258f4SEd Tanous                     for (const auto &interfaceName : connection.second)
741abe55efSEd Tanous                     {
7504a258f4SEd Tanous                         if (interfaceName ==
7604a258f4SEd Tanous                             "xyz.openbmc_project.Inventory.Item.Dimm")
771abe55efSEd Tanous                         {
781abe55efSEd Tanous                             BMCWEB_LOG_DEBUG
7904a258f4SEd Tanous                                 << "Found Dimm, now get its properties.";
8055c7b7a2SEd Tanous                             crow::connections::systemBus->async_method_call(
81029573d4SEd Tanous                                 [aResp](const boost::system::error_code ec,
826c34de48SEd Tanous                                         const std::vector<
836c34de48SEd Tanous                                             std::pair<std::string, VariantType>>
841abe55efSEd Tanous                                             &properties) {
851abe55efSEd Tanous                                     if (ec)
861abe55efSEd Tanous                                     {
871abe55efSEd Tanous                                         BMCWEB_LOG_ERROR
886c34de48SEd Tanous                                             << "DBUS response error " << ec;
89f12894f8SJason M. Bills                                         messages::internalError(aResp->res);
90c5b2abe0SLewanczyk, Dawid                                         return;
91c5b2abe0SLewanczyk, Dawid                                     }
926c34de48SEd Tanous                                     BMCWEB_LOG_DEBUG << "Got "
936c34de48SEd Tanous                                                      << properties.size()
94c5b2abe0SLewanczyk, Dawid                                                      << "Dimm properties.";
9504a258f4SEd Tanous                                     for (const std::pair<std::string,
9604a258f4SEd Tanous                                                          VariantType>
9704a258f4SEd Tanous                                              &property : properties)
981abe55efSEd Tanous                                     {
99029573d4SEd Tanous                                         if (property.first == "MemorySizeInKb")
1001abe55efSEd Tanous                                         {
10104a258f4SEd Tanous                                             const uint64_t *value =
102029573d4SEd Tanous                                                 sdbusplus::message::variant_ns::
103029573d4SEd Tanous                                                     get_if<uint64_t>(
1041b6b96c5SEd Tanous                                                         &property.second);
10504a258f4SEd Tanous                                             if (value != nullptr)
1061abe55efSEd Tanous                                             {
1071abe55efSEd Tanous                                                 aResp->res.jsonValue
1086c34de48SEd Tanous                                                     ["TotalSystemMemoryGi"
1096c34de48SEd Tanous                                                      "B"] +=
11004a258f4SEd Tanous                                                     *value / (1024 * 1024);
111029573d4SEd Tanous                                                 aResp->res
112029573d4SEd Tanous                                                     .jsonValue["MemorySummary"]
113029573d4SEd Tanous                                                               ["Status"]
114029573d4SEd Tanous                                                               ["State"] =
1151abe55efSEd Tanous                                                     "Enabled";
116c5b2abe0SLewanczyk, Dawid                                             }
117c5b2abe0SLewanczyk, Dawid                                         }
118c5b2abe0SLewanczyk, Dawid                                     }
119c5b2abe0SLewanczyk, Dawid                                 },
12004a258f4SEd Tanous                                 connection.first, path,
1216c34de48SEd Tanous                                 "org.freedesktop.DBus.Properties", "GetAll",
1226c34de48SEd Tanous                                 "xyz.openbmc_project.Inventory.Item.Dimm");
1231abe55efSEd Tanous                         }
12404a258f4SEd Tanous                         else if (interfaceName ==
12504a258f4SEd Tanous                                  "xyz.openbmc_project.Inventory.Item.Cpu")
1261abe55efSEd Tanous                         {
1271abe55efSEd Tanous                             BMCWEB_LOG_DEBUG
12804a258f4SEd Tanous                                 << "Found Cpu, now get its properties.";
129a0803efaSEd Tanous                             crow::connections::systemBus->async_method_call(
130029573d4SEd Tanous                                 [aResp](const boost::system::error_code ec,
1316c34de48SEd Tanous                                         const std::vector<
1326c34de48SEd Tanous                                             std::pair<std::string, VariantType>>
1331abe55efSEd Tanous                                             &properties) {
1341abe55efSEd Tanous                                     if (ec)
1351abe55efSEd Tanous                                     {
1361abe55efSEd Tanous                                         BMCWEB_LOG_ERROR
1376c34de48SEd Tanous                                             << "DBUS response error " << ec;
138f12894f8SJason M. Bills                                         messages::internalError(aResp->res);
139c5b2abe0SLewanczyk, Dawid                                         return;
140c5b2abe0SLewanczyk, Dawid                                     }
1416c34de48SEd Tanous                                     BMCWEB_LOG_DEBUG << "Got "
1426c34de48SEd Tanous                                                      << properties.size()
143c5b2abe0SLewanczyk, Dawid                                                      << "Cpu properties.";
14404a258f4SEd Tanous                                     for (const auto &property : properties)
1451abe55efSEd Tanous                                     {
146029573d4SEd Tanous                                         if (property.first == "ProcessorFamily")
1471abe55efSEd Tanous                                         {
148a0803efaSEd Tanous                                             const std::string *value =
149029573d4SEd Tanous                                                 sdbusplus::message::variant_ns::
150029573d4SEd Tanous                                                     get_if<std::string>(
1511b6b96c5SEd Tanous                                                         &property.second);
1521abe55efSEd Tanous                                             if (value != nullptr)
1531abe55efSEd Tanous                                             {
154029573d4SEd Tanous                                                 nlohmann::json &procSummary =
1551abe55efSEd Tanous                                                     aResp->res.jsonValue
1566c34de48SEd Tanous                                                         ["ProcessorSumm"
15704a258f4SEd Tanous                                                          "ary"];
15804a258f4SEd Tanous                                                 nlohmann::json &procCount =
15904a258f4SEd Tanous                                                     procSummary["Count"];
16004a258f4SEd Tanous 
16104a258f4SEd Tanous                                                 procCount =
162029573d4SEd Tanous                                                     procCount.get<int>() + 1;
163029573d4SEd Tanous                                                 procSummary["Status"]["State"] =
164c5b2abe0SLewanczyk, Dawid                                                     "Enabled";
165029573d4SEd Tanous                                                 procSummary["Model"] = *value;
166c5b2abe0SLewanczyk, Dawid                                             }
167c5b2abe0SLewanczyk, Dawid                                         }
168c5b2abe0SLewanczyk, Dawid                                     }
169c5b2abe0SLewanczyk, Dawid                                 },
17004a258f4SEd Tanous                                 connection.first, path,
1716c34de48SEd Tanous                                 "org.freedesktop.DBus.Properties", "GetAll",
1726c34de48SEd Tanous                                 "xyz.openbmc_project.Inventory.Item.Cpu");
1731abe55efSEd Tanous                         }
17404a258f4SEd Tanous                         else if (interfaceName ==
17504a258f4SEd Tanous                                  "xyz.openbmc_project.Common.UUID")
1761abe55efSEd Tanous                         {
1771abe55efSEd Tanous                             BMCWEB_LOG_DEBUG
17804a258f4SEd Tanous                                 << "Found UUID, now get its properties.";
17955c7b7a2SEd Tanous                             crow::connections::systemBus->async_method_call(
180029573d4SEd Tanous                                 [aResp](const boost::system::error_code ec,
1816c34de48SEd Tanous                                         const std::vector<
1826c34de48SEd Tanous                                             std::pair<std::string, VariantType>>
1831abe55efSEd Tanous                                             &properties) {
1841abe55efSEd Tanous                                     if (ec)
1851abe55efSEd Tanous                                     {
1861abe55efSEd Tanous                                         BMCWEB_LOG_DEBUG
1876c34de48SEd Tanous                                             << "DBUS response error " << ec;
188f12894f8SJason M. Bills                                         messages::internalError(aResp->res);
189c5b2abe0SLewanczyk, Dawid                                         return;
190c5b2abe0SLewanczyk, Dawid                                     }
1916c34de48SEd Tanous                                     BMCWEB_LOG_DEBUG << "Got "
1926c34de48SEd Tanous                                                      << properties.size()
193c5b2abe0SLewanczyk, Dawid                                                      << "UUID properties.";
1941abe55efSEd Tanous                                     for (const std::pair<std::string,
19504a258f4SEd Tanous                                                          VariantType>
19604a258f4SEd Tanous                                              &property : properties)
1971abe55efSEd Tanous                                     {
19804a258f4SEd Tanous                                         if (property.first == "UUID")
1991abe55efSEd Tanous                                         {
200c5b2abe0SLewanczyk, Dawid                                             const std::string *value =
201029573d4SEd Tanous                                                 sdbusplus::message::variant_ns::
202029573d4SEd Tanous                                                     get_if<std::string>(
2031b6b96c5SEd Tanous                                                         &property.second);
20404a258f4SEd Tanous 
2051abe55efSEd Tanous                                             if (value != nullptr)
2061abe55efSEd Tanous                                             {
207029573d4SEd Tanous                                                 std::string valueStr = *value;
20804a258f4SEd Tanous                                                 if (valueStr.size() == 32)
2091abe55efSEd Tanous                                                 {
210029573d4SEd Tanous                                                     valueStr.insert(8, 1, '-');
211029573d4SEd Tanous                                                     valueStr.insert(13, 1, '-');
212029573d4SEd Tanous                                                     valueStr.insert(18, 1, '-');
213029573d4SEd Tanous                                                     valueStr.insert(23, 1, '-');
21404a258f4SEd Tanous                                                 }
215029573d4SEd Tanous                                                 BMCWEB_LOG_DEBUG << "UUID = "
21604a258f4SEd Tanous                                                                  << valueStr;
217029573d4SEd Tanous                                                 aResp->res.jsonValue["UUID"] =
21804a258f4SEd Tanous                                                     valueStr;
219c5b2abe0SLewanczyk, Dawid                                             }
220c5b2abe0SLewanczyk, Dawid                                         }
221c5b2abe0SLewanczyk, Dawid                                     }
222c5b2abe0SLewanczyk, Dawid                                 },
22304a258f4SEd Tanous                                 connection.first, path,
2246c34de48SEd Tanous                                 "org.freedesktop.DBus.Properties", "GetAll",
2251abe55efSEd Tanous                                 "xyz.openbmc_project.Common.UUID");
226c5b2abe0SLewanczyk, Dawid                         }
227029573d4SEd Tanous                         else if (interfaceName ==
228029573d4SEd Tanous                                  "xyz.openbmc_project.Inventory.Item.System")
2291abe55efSEd Tanous                         {
230029573d4SEd Tanous                             crow::connections::systemBus->async_method_call(
231029573d4SEd Tanous                                 [aResp](const boost::system::error_code ec,
232029573d4SEd Tanous                                         const std::vector<
233029573d4SEd Tanous                                             std::pair<std::string, VariantType>>
234029573d4SEd Tanous                                             &propertiesList) {
235029573d4SEd Tanous                                     if (ec)
236029573d4SEd Tanous                                     {
237029573d4SEd Tanous                                         BMCWEB_LOG_ERROR
238029573d4SEd Tanous                                             << "DBUS response error: " << ec;
239f12894f8SJason M. Bills                                         messages::internalError(aResp->res);
240029573d4SEd Tanous                                         return;
241029573d4SEd Tanous                                     }
242029573d4SEd Tanous                                     BMCWEB_LOG_DEBUG << "Got "
243029573d4SEd Tanous                                                      << propertiesList.size()
244029573d4SEd Tanous                                                      << "properties for system";
245029573d4SEd Tanous                                     for (const std::pair<std::string,
246029573d4SEd Tanous                                                          VariantType>
247029573d4SEd Tanous                                              &property : propertiesList)
248029573d4SEd Tanous                                     {
249fc5afcf9Sbeccabroek                                         const std::string &propertyName =
250fc5afcf9Sbeccabroek                                             property.first;
251fc5afcf9Sbeccabroek                                         if ((propertyName == "PartNumber") ||
252fc5afcf9Sbeccabroek                                             (propertyName == "SerialNumber") ||
253fc5afcf9Sbeccabroek                                             (propertyName == "Manufacturer") ||
254fc5afcf9Sbeccabroek                                             (propertyName == "Model"))
255fc5afcf9Sbeccabroek                                         {
256029573d4SEd Tanous                                             const std::string *value =
257fc5afcf9Sbeccabroek                                                 std::get_if<std::string>(
258029573d4SEd Tanous                                                     &property.second);
259029573d4SEd Tanous                                             if (value != nullptr)
260029573d4SEd Tanous                                             {
261029573d4SEd Tanous                                                 aResp->res
262fc5afcf9Sbeccabroek                                                     .jsonValue[propertyName] =
263029573d4SEd Tanous                                                     *value;
264029573d4SEd Tanous                                             }
265029573d4SEd Tanous                                         }
266fc5afcf9Sbeccabroek                                     }
267029573d4SEd Tanous                                     aResp->res.jsonValue["Name"] = "system";
268029573d4SEd Tanous                                     aResp->res.jsonValue["Id"] =
269029573d4SEd Tanous                                         aResp->res.jsonValue["SerialNumber"];
270cb7e1e7bSAndrew Geissler                                     // Grab the bios version
271cb7e1e7bSAndrew Geissler                                     fw_util::getActiveFwVersion(
272cb7e1e7bSAndrew Geissler                                         aResp, fw_util::biosPurpose,
273cb7e1e7bSAndrew Geissler                                         "BiosVersion");
274029573d4SEd Tanous                                 },
275029573d4SEd Tanous                                 connection.first, path,
276029573d4SEd Tanous                                 "org.freedesktop.DBus.Properties", "GetAll",
277029573d4SEd Tanous                                 "xyz.openbmc_project.Inventory.Decorator."
278029573d4SEd Tanous                                 "Asset");
279029573d4SEd Tanous                         }
280029573d4SEd Tanous                     }
281029573d4SEd Tanous                 }
282c5b2abe0SLewanczyk, Dawid             }
283c5b2abe0SLewanczyk, Dawid         },
284c5b2abe0SLewanczyk, Dawid         "xyz.openbmc_project.ObjectMapper",
285c5b2abe0SLewanczyk, Dawid         "/xyz/openbmc_project/object_mapper",
286c5b2abe0SLewanczyk, Dawid         "xyz.openbmc_project.ObjectMapper", "GetSubTree",
2876617338dSEd Tanous         "/xyz/openbmc_project/inventory", int32_t(0),
2886617338dSEd Tanous         std::array<const char *, 5>{
2896617338dSEd Tanous             "xyz.openbmc_project.Inventory.Decorator.Asset",
2906617338dSEd Tanous             "xyz.openbmc_project.Inventory.Item.Cpu",
2916617338dSEd Tanous             "xyz.openbmc_project.Inventory.Item.Dimm",
2926617338dSEd Tanous             "xyz.openbmc_project.Inventory.Item.System",
2936617338dSEd Tanous             "xyz.openbmc_project.Common.UUID",
2946617338dSEd Tanous         });
295c5b2abe0SLewanczyk, Dawid }
296c5b2abe0SLewanczyk, Dawid 
297c5b2abe0SLewanczyk, Dawid /**
298c5b2abe0SLewanczyk, Dawid  * @brief Retrieves identify led group properties over dbus
299c5b2abe0SLewanczyk, Dawid  *
300491d8ee7SSantosh Puranik  * @param[in] aResp     Shared pointer for generating response message.
301c5b2abe0SLewanczyk, Dawid  * @param[in] callback  Callback for process retrieved data.
302c5b2abe0SLewanczyk, Dawid  *
303c5b2abe0SLewanczyk, Dawid  * @return None.
304c5b2abe0SLewanczyk, Dawid  */
305c5b2abe0SLewanczyk, Dawid template <typename CallbackFunc>
306a0803efaSEd Tanous void getLedGroupIdentify(std::shared_ptr<AsyncResp> aResp,
3071abe55efSEd Tanous                          CallbackFunc &&callback)
3081abe55efSEd Tanous {
30955c7b7a2SEd Tanous     BMCWEB_LOG_DEBUG << "Get led groups";
31055c7b7a2SEd Tanous     crow::connections::systemBus->async_method_call(
311*c5d03ff4SJennifer Lee         [aResp,
3126617338dSEd Tanous          callback{std::move(callback)}](const boost::system::error_code &ec,
3131abe55efSEd Tanous                                         const ManagedObjectsType &resp) {
3141abe55efSEd Tanous             if (ec)
3151abe55efSEd Tanous             {
31655c7b7a2SEd Tanous                 BMCWEB_LOG_DEBUG << "DBUS response error " << ec;
317f12894f8SJason M. Bills                 messages::internalError(aResp->res);
318c5b2abe0SLewanczyk, Dawid                 return;
319c5b2abe0SLewanczyk, Dawid             }
3206c34de48SEd Tanous             BMCWEB_LOG_DEBUG << "Got " << resp.size() << "led group objects.";
3211abe55efSEd Tanous             for (const auto &objPath : resp)
3221abe55efSEd Tanous             {
323c5b2abe0SLewanczyk, Dawid                 const std::string &path = objPath.first;
3241abe55efSEd Tanous                 if (path.rfind("enclosure_identify") != std::string::npos)
3251abe55efSEd Tanous                 {
3261abe55efSEd Tanous                     for (const auto &interface : objPath.second)
3271abe55efSEd Tanous                     {
3286c34de48SEd Tanous                         if (interface.first == "xyz.openbmc_project.Led.Group")
3291abe55efSEd Tanous                         {
3301abe55efSEd Tanous                             for (const auto &property : interface.second)
3311abe55efSEd Tanous                             {
3321abe55efSEd Tanous                                 if (property.first == "Asserted")
3331abe55efSEd Tanous                                 {
334c5b2abe0SLewanczyk, Dawid                                     const bool *asserted =
335abf2add6SEd Tanous                                         std::get_if<bool>(&property.second);
3361abe55efSEd Tanous                                     if (nullptr != asserted)
3371abe55efSEd Tanous                                     {
338c5b2abe0SLewanczyk, Dawid                                         callback(*asserted, aResp);
3391abe55efSEd Tanous                                     }
3401abe55efSEd Tanous                                     else
3411abe55efSEd Tanous                                     {
342c5b2abe0SLewanczyk, Dawid                                         callback(false, aResp);
343c5b2abe0SLewanczyk, Dawid                                     }
344c5b2abe0SLewanczyk, Dawid                                 }
345c5b2abe0SLewanczyk, Dawid                             }
346c5b2abe0SLewanczyk, Dawid                         }
347c5b2abe0SLewanczyk, Dawid                     }
348c5b2abe0SLewanczyk, Dawid                 }
349c5b2abe0SLewanczyk, Dawid             }
350c5b2abe0SLewanczyk, Dawid         },
351c5b2abe0SLewanczyk, Dawid         "xyz.openbmc_project.LED.GroupManager",
3526c34de48SEd Tanous         "/xyz/openbmc_project/led/groups", "org.freedesktop.DBus.ObjectManager",
3536c34de48SEd Tanous         "GetManagedObjects");
354c5b2abe0SLewanczyk, Dawid }
355c5b2abe0SLewanczyk, Dawid 
356c5b2abe0SLewanczyk, Dawid template <typename CallbackFunc>
3576c34de48SEd Tanous void getLedIdentify(std::shared_ptr<AsyncResp> aResp, CallbackFunc &&callback)
3581abe55efSEd Tanous {
35955c7b7a2SEd Tanous     BMCWEB_LOG_DEBUG << "Get identify led properties";
36055c7b7a2SEd Tanous     crow::connections::systemBus->async_method_call(
3616617338dSEd Tanous         [aResp,
3626617338dSEd Tanous          callback{std::move(callback)}](const boost::system::error_code ec,
363c5b2abe0SLewanczyk, Dawid                                         const PropertiesType &properties) {
3641abe55efSEd Tanous             if (ec)
3651abe55efSEd Tanous             {
36655c7b7a2SEd Tanous                 BMCWEB_LOG_DEBUG << "DBUS response error " << ec;
367f12894f8SJason M. Bills                 messages::internalError(aResp->res);
368c5b2abe0SLewanczyk, Dawid                 return;
369c5b2abe0SLewanczyk, Dawid             }
3701abe55efSEd Tanous             BMCWEB_LOG_DEBUG << "Got " << properties.size()
3711abe55efSEd Tanous                              << "led properties.";
372c5b2abe0SLewanczyk, Dawid             std::string output;
3731abe55efSEd Tanous             for (const auto &property : properties)
3741abe55efSEd Tanous             {
3751abe55efSEd Tanous                 if (property.first == "State")
3761abe55efSEd Tanous                 {
377c5b2abe0SLewanczyk, Dawid                     const std::string *s =
378abf2add6SEd Tanous                         std::get_if<std::string>(&property.second);
3791abe55efSEd Tanous                     if (nullptr != s)
3801abe55efSEd Tanous                     {
38155c7b7a2SEd Tanous                         BMCWEB_LOG_DEBUG << "Identify Led State: " << *s;
382c5b2abe0SLewanczyk, Dawid                         const auto pos = s->rfind('.');
3831abe55efSEd Tanous                         if (pos != std::string::npos)
3841abe55efSEd Tanous                         {
385c5b2abe0SLewanczyk, Dawid                             auto led = s->substr(pos + 1);
3861abe55efSEd Tanous                             for (const std::pair<const char *, const char *>
3871abe55efSEd Tanous                                      &p :
3881abe55efSEd Tanous                                  std::array<
3896c34de48SEd Tanous                                      std::pair<const char *, const char *>, 3>{
3906c34de48SEd Tanous                                      {{"On", "Lit"},
391c5b2abe0SLewanczyk, Dawid                                       {"Blink", "Blinking"},
3921abe55efSEd Tanous                                       {"Off", "Off"}}})
3931abe55efSEd Tanous                             {
3941abe55efSEd Tanous                                 if (led == p.first)
3951abe55efSEd Tanous                                 {
396c5b2abe0SLewanczyk, Dawid                                     output = p.second;
397c5b2abe0SLewanczyk, Dawid                                 }
398c5b2abe0SLewanczyk, Dawid                             }
399c5b2abe0SLewanczyk, Dawid                         }
400c5b2abe0SLewanczyk, Dawid                     }
401c5b2abe0SLewanczyk, Dawid                 }
402c5b2abe0SLewanczyk, Dawid             }
403c5b2abe0SLewanczyk, Dawid             callback(output, aResp);
404c5b2abe0SLewanczyk, Dawid         },
405c5b2abe0SLewanczyk, Dawid         "xyz.openbmc_project.LED.Controller.identify",
406c5b2abe0SLewanczyk, Dawid         "/xyz/openbmc_project/led/physical/identify",
407c5b2abe0SLewanczyk, Dawid         "org.freedesktop.DBus.Properties", "GetAll",
408c5b2abe0SLewanczyk, Dawid         "xyz.openbmc_project.Led.Physical");
409c5b2abe0SLewanczyk, Dawid }
410c5b2abe0SLewanczyk, Dawid /**
411c5b2abe0SLewanczyk, Dawid  * @brief Retrieves host state properties over dbus
412c5b2abe0SLewanczyk, Dawid  *
413c5b2abe0SLewanczyk, Dawid  * @param[in] aResp     Shared pointer for completing asynchronous calls.
414c5b2abe0SLewanczyk, Dawid  *
415c5b2abe0SLewanczyk, Dawid  * @return None.
416c5b2abe0SLewanczyk, Dawid  */
417a0803efaSEd Tanous void getHostState(std::shared_ptr<AsyncResp> aResp)
4181abe55efSEd Tanous {
41955c7b7a2SEd Tanous     BMCWEB_LOG_DEBUG << "Get host information.";
42055c7b7a2SEd Tanous     crow::connections::systemBus->async_method_call(
421*c5d03ff4SJennifer Lee         [aResp](const boost::system::error_code ec,
422abf2add6SEd Tanous                 const std::variant<std::string> &hostState) {
4231abe55efSEd Tanous             if (ec)
4241abe55efSEd Tanous             {
42555c7b7a2SEd Tanous                 BMCWEB_LOG_DEBUG << "DBUS response error " << ec;
426f12894f8SJason M. Bills                 messages::internalError(aResp->res);
427c5b2abe0SLewanczyk, Dawid                 return;
428c5b2abe0SLewanczyk, Dawid             }
4296617338dSEd Tanous 
430abf2add6SEd Tanous             const std::string *s = std::get_if<std::string>(&hostState);
43155c7b7a2SEd Tanous             BMCWEB_LOG_DEBUG << "Host state: " << *s;
4326617338dSEd Tanous             if (s != nullptr)
4331abe55efSEd Tanous             {
434c5b2abe0SLewanczyk, Dawid                 // Verify Host State
43594732661SAndrew Geissler                 if (*s == "xyz.openbmc_project.State.Host.HostState.Running")
4361abe55efSEd Tanous                 {
43755c7b7a2SEd Tanous                     aResp->res.jsonValue["PowerState"] = "On";
4386617338dSEd Tanous                     aResp->res.jsonValue["Status"]["State"] = "Enabled";
4391abe55efSEd Tanous                 }
4401abe55efSEd Tanous                 else
4411abe55efSEd Tanous                 {
44255c7b7a2SEd Tanous                     aResp->res.jsonValue["PowerState"] = "Off";
4436617338dSEd Tanous                     aResp->res.jsonValue["Status"]["State"] = "Disabled";
444c5b2abe0SLewanczyk, Dawid                 }
445c5b2abe0SLewanczyk, Dawid             }
446c5b2abe0SLewanczyk, Dawid         },
4476c34de48SEd Tanous         "xyz.openbmc_project.State.Host", "/xyz/openbmc_project/state/host0",
4486617338dSEd Tanous         "org.freedesktop.DBus.Properties", "Get",
4496617338dSEd Tanous         "xyz.openbmc_project.State.Host", "CurrentHostState");
450c5b2abe0SLewanczyk, Dawid }
451c5b2abe0SLewanczyk, Dawid 
452c5b2abe0SLewanczyk, Dawid /**
453491d8ee7SSantosh Puranik  * @brief Traslates boot source DBUS property value to redfish.
454491d8ee7SSantosh Puranik  *
455491d8ee7SSantosh Puranik  * @param[in] dbusSource    The boot source in DBUS speak.
456491d8ee7SSantosh Puranik  *
457491d8ee7SSantosh Puranik  * @return Returns as a string, the boot source in Redfish terms. If translation
458491d8ee7SSantosh Puranik  * cannot be done, returns an empty string.
459491d8ee7SSantosh Puranik  */
460491d8ee7SSantosh Puranik static std::string dbusToRfBootSource(const std::string &dbusSource)
461491d8ee7SSantosh Puranik {
462491d8ee7SSantosh Puranik     if (dbusSource == "xyz.openbmc_project.Control.Boot.Source.Sources.Default")
463491d8ee7SSantosh Puranik     {
464491d8ee7SSantosh Puranik         return "None";
465491d8ee7SSantosh Puranik     }
466491d8ee7SSantosh Puranik     else if (dbusSource ==
467491d8ee7SSantosh Puranik              "xyz.openbmc_project.Control.Boot.Source.Sources.Disk")
468491d8ee7SSantosh Puranik     {
469491d8ee7SSantosh Puranik         return "Hdd";
470491d8ee7SSantosh Puranik     }
471491d8ee7SSantosh Puranik     else if (dbusSource ==
472a71dc0b7SSantosh Puranik              "xyz.openbmc_project.Control.Boot.Source.Sources.ExternalMedia")
473491d8ee7SSantosh Puranik     {
474491d8ee7SSantosh Puranik         return "Cd";
475491d8ee7SSantosh Puranik     }
476491d8ee7SSantosh Puranik     else if (dbusSource ==
477491d8ee7SSantosh Puranik              "xyz.openbmc_project.Control.Boot.Source.Sources.Network")
478491d8ee7SSantosh Puranik     {
479491d8ee7SSantosh Puranik         return "Pxe";
480491d8ee7SSantosh Puranik     }
4819f16b2c1SJennifer Lee     else if (dbusSource ==
4829f16b2c1SJennifer Lee              "xyz.openbmc_project.Control.Boot.Source.Sources.Removable")
4839f16b2c1SJennifer Lee     {
4849f16b2c1SJennifer Lee         return "Usb";
4859f16b2c1SJennifer Lee     }
486491d8ee7SSantosh Puranik     else
487491d8ee7SSantosh Puranik     {
488491d8ee7SSantosh Puranik         return "";
489491d8ee7SSantosh Puranik     }
490491d8ee7SSantosh Puranik }
491491d8ee7SSantosh Puranik 
492491d8ee7SSantosh Puranik /**
493491d8ee7SSantosh Puranik  * @brief Traslates boot mode DBUS property value to redfish.
494491d8ee7SSantosh Puranik  *
495491d8ee7SSantosh Puranik  * @param[in] dbusMode    The boot mode in DBUS speak.
496491d8ee7SSantosh Puranik  *
497491d8ee7SSantosh Puranik  * @return Returns as a string, the boot mode in Redfish terms. If translation
498491d8ee7SSantosh Puranik  * cannot be done, returns an empty string.
499491d8ee7SSantosh Puranik  */
500491d8ee7SSantosh Puranik static std::string dbusToRfBootMode(const std::string &dbusMode)
501491d8ee7SSantosh Puranik {
502491d8ee7SSantosh Puranik     if (dbusMode == "xyz.openbmc_project.Control.Boot.Mode.Modes.Regular")
503491d8ee7SSantosh Puranik     {
504491d8ee7SSantosh Puranik         return "None";
505491d8ee7SSantosh Puranik     }
506491d8ee7SSantosh Puranik     else if (dbusMode == "xyz.openbmc_project.Control.Boot.Mode.Modes.Safe")
507491d8ee7SSantosh Puranik     {
508491d8ee7SSantosh Puranik         return "Diags";
509491d8ee7SSantosh Puranik     }
510491d8ee7SSantosh Puranik     else if (dbusMode == "xyz.openbmc_project.Control.Boot.Mode.Modes.Setup")
511491d8ee7SSantosh Puranik     {
512491d8ee7SSantosh Puranik         return "BiosSetup";
513491d8ee7SSantosh Puranik     }
514491d8ee7SSantosh Puranik     else
515491d8ee7SSantosh Puranik     {
516491d8ee7SSantosh Puranik         return "";
517491d8ee7SSantosh Puranik     }
518491d8ee7SSantosh Puranik }
519491d8ee7SSantosh Puranik 
520491d8ee7SSantosh Puranik /**
521491d8ee7SSantosh Puranik  * @brief Traslates boot source from Redfish to DBUS property value.
522491d8ee7SSantosh Puranik  *
523491d8ee7SSantosh Puranik  * @param[in] rfSource    The boot source in Redfish.
524491d8ee7SSantosh Puranik  *
525491d8ee7SSantosh Puranik  * @return Returns as a string, the boot source as expected by DBUS.
526491d8ee7SSantosh Puranik  * If translation cannot be done, returns an empty string.
527491d8ee7SSantosh Puranik  */
528491d8ee7SSantosh Puranik static std::string rfToDbusBootSource(const std::string &rfSource)
529491d8ee7SSantosh Puranik {
530491d8ee7SSantosh Puranik     if (rfSource == "None")
531491d8ee7SSantosh Puranik     {
532491d8ee7SSantosh Puranik         return "xyz.openbmc_project.Control.Boot.Source.Sources.Default";
533491d8ee7SSantosh Puranik     }
534491d8ee7SSantosh Puranik     else if (rfSource == "Hdd")
535491d8ee7SSantosh Puranik     {
536491d8ee7SSantosh Puranik         return "xyz.openbmc_project.Control.Boot.Source.Sources.Disk";
537491d8ee7SSantosh Puranik     }
538491d8ee7SSantosh Puranik     else if (rfSource == "Cd")
539491d8ee7SSantosh Puranik     {
540a71dc0b7SSantosh Puranik         return "xyz.openbmc_project.Control.Boot.Source.Sources.ExternalMedia";
541491d8ee7SSantosh Puranik     }
542491d8ee7SSantosh Puranik     else if (rfSource == "Pxe")
543491d8ee7SSantosh Puranik     {
544491d8ee7SSantosh Puranik         return "xyz.openbmc_project.Control.Boot.Source.Sources.Network";
545491d8ee7SSantosh Puranik     }
5469f16b2c1SJennifer Lee     else if (rfSource == "Usb")
5479f16b2c1SJennifer Lee     {
5489f16b2c1SJennifer Lee         return "xyz.openbmc_project.Control.Boot.Source.Sources.Removable";
5499f16b2c1SJennifer Lee     }
550491d8ee7SSantosh Puranik     else
551491d8ee7SSantosh Puranik     {
552491d8ee7SSantosh Puranik         return "";
553491d8ee7SSantosh Puranik     }
554491d8ee7SSantosh Puranik }
555491d8ee7SSantosh Puranik 
556491d8ee7SSantosh Puranik /**
557491d8ee7SSantosh Puranik  * @brief Traslates boot mode from Redfish to DBUS property value.
558491d8ee7SSantosh Puranik  *
559491d8ee7SSantosh Puranik  * @param[in] rfMode    The boot mode in Redfish.
560491d8ee7SSantosh Puranik  *
561491d8ee7SSantosh Puranik  * @return Returns as a string, the boot mode as expected by DBUS.
562491d8ee7SSantosh Puranik  * If translation cannot be done, returns an empty string.
563491d8ee7SSantosh Puranik  */
564491d8ee7SSantosh Puranik static std::string rfToDbusBootMode(const std::string &rfMode)
565491d8ee7SSantosh Puranik {
566491d8ee7SSantosh Puranik     if (rfMode == "None")
567491d8ee7SSantosh Puranik     {
568491d8ee7SSantosh Puranik         return "xyz.openbmc_project.Control.Boot.Mode.Modes.Regular";
569491d8ee7SSantosh Puranik     }
570491d8ee7SSantosh Puranik     else if (rfMode == "Diags")
571491d8ee7SSantosh Puranik     {
572491d8ee7SSantosh Puranik         return "xyz.openbmc_project.Control.Boot.Mode.Modes.Safe";
573491d8ee7SSantosh Puranik     }
574491d8ee7SSantosh Puranik     else if (rfMode == "BiosSetup")
575491d8ee7SSantosh Puranik     {
576491d8ee7SSantosh Puranik         return "xyz.openbmc_project.Control.Boot.Mode.Modes.Setup";
577491d8ee7SSantosh Puranik     }
578491d8ee7SSantosh Puranik     else
579491d8ee7SSantosh Puranik     {
580491d8ee7SSantosh Puranik         return "";
581491d8ee7SSantosh Puranik     }
582491d8ee7SSantosh Puranik }
583491d8ee7SSantosh Puranik 
584491d8ee7SSantosh Puranik /**
585491d8ee7SSantosh Puranik  * @brief Retrieves boot mode over DBUS and fills out the response
586491d8ee7SSantosh Puranik  *
587491d8ee7SSantosh Puranik  * @param[in] aResp         Shared pointer for generating response message.
588491d8ee7SSantosh Puranik  * @param[in] bootDbusObj   The dbus object to query for boot properties.
589491d8ee7SSantosh Puranik  *
590491d8ee7SSantosh Puranik  * @return None.
591491d8ee7SSantosh Puranik  */
592491d8ee7SSantosh Puranik static void getBootMode(std::shared_ptr<AsyncResp> aResp,
593491d8ee7SSantosh Puranik                         std::string bootDbusObj)
594491d8ee7SSantosh Puranik {
595491d8ee7SSantosh Puranik     crow::connections::systemBus->async_method_call(
596491d8ee7SSantosh Puranik         [aResp](const boost::system::error_code ec,
597491d8ee7SSantosh Puranik                 const std::variant<std::string> &bootMode) {
598491d8ee7SSantosh Puranik             if (ec)
599491d8ee7SSantosh Puranik             {
600491d8ee7SSantosh Puranik                 BMCWEB_LOG_DEBUG << "DBUS response error " << ec;
601491d8ee7SSantosh Puranik                 messages::internalError(aResp->res);
602491d8ee7SSantosh Puranik                 return;
603491d8ee7SSantosh Puranik             }
604491d8ee7SSantosh Puranik 
605491d8ee7SSantosh Puranik             const std::string *bootModeStr =
606491d8ee7SSantosh Puranik                 std::get_if<std::string>(&bootMode);
607491d8ee7SSantosh Puranik 
608491d8ee7SSantosh Puranik             if (!bootModeStr)
609491d8ee7SSantosh Puranik             {
610491d8ee7SSantosh Puranik                 messages::internalError(aResp->res);
611491d8ee7SSantosh Puranik                 return;
612491d8ee7SSantosh Puranik             }
613491d8ee7SSantosh Puranik 
614491d8ee7SSantosh Puranik             BMCWEB_LOG_DEBUG << "Boot mode: " << *bootModeStr;
615491d8ee7SSantosh Puranik 
616491d8ee7SSantosh Puranik             // TODO (Santosh): Do we need to support override mode?
617491d8ee7SSantosh Puranik             aResp->res.jsonValue["Boot"]["BootSourceOverrideMode"] = "Legacy";
618491d8ee7SSantosh Puranik             aResp->res.jsonValue["Boot"]["BootSourceOverrideTarget@Redfish."
619491d8ee7SSantosh Puranik                                          "AllowableValues"] = {
620491d8ee7SSantosh Puranik                 "None", "Pxe", "Hdd", "Cd", "Diags", "BiosSetup"};
621491d8ee7SSantosh Puranik 
622491d8ee7SSantosh Puranik             if (*bootModeStr !=
623491d8ee7SSantosh Puranik                 "xyz.openbmc_project.Control.Boot.Mode.Modes.Regular")
624491d8ee7SSantosh Puranik             {
625491d8ee7SSantosh Puranik                 auto rfMode = dbusToRfBootMode(*bootModeStr);
626491d8ee7SSantosh Puranik                 if (!rfMode.empty())
627491d8ee7SSantosh Puranik                 {
628491d8ee7SSantosh Puranik                     aResp->res.jsonValue["Boot"]["BootSourceOverrideTarget"] =
629491d8ee7SSantosh Puranik                         rfMode;
630491d8ee7SSantosh Puranik                 }
631491d8ee7SSantosh Puranik             }
632491d8ee7SSantosh Puranik 
633491d8ee7SSantosh Puranik             // If the BootSourceOverrideTarget is still "None" at the end,
634491d8ee7SSantosh Puranik             // reset the BootSourceOverrideEnabled to indicate that
635491d8ee7SSantosh Puranik             // overrides are disabled
636491d8ee7SSantosh Puranik             if (aResp->res.jsonValue["Boot"]["BootSourceOverrideTarget"] ==
637491d8ee7SSantosh Puranik                 "None")
638491d8ee7SSantosh Puranik             {
639491d8ee7SSantosh Puranik                 aResp->res.jsonValue["Boot"]["BootSourceOverrideEnabled"] =
640491d8ee7SSantosh Puranik                     "Disabled";
641491d8ee7SSantosh Puranik             }
642491d8ee7SSantosh Puranik         },
643491d8ee7SSantosh Puranik         "xyz.openbmc_project.Settings", bootDbusObj,
644491d8ee7SSantosh Puranik         "org.freedesktop.DBus.Properties", "Get",
645491d8ee7SSantosh Puranik         "xyz.openbmc_project.Control.Boot.Mode", "BootMode");
646491d8ee7SSantosh Puranik }
647491d8ee7SSantosh Puranik 
648491d8ee7SSantosh Puranik /**
649491d8ee7SSantosh Puranik  * @brief Retrieves boot source over DBUS
650491d8ee7SSantosh Puranik  *
651491d8ee7SSantosh Puranik  * @param[in] aResp         Shared pointer for generating response message.
652491d8ee7SSantosh Puranik  * @param[in] oneTimeEnable Boolean to indicate boot properties are one-time.
653491d8ee7SSantosh Puranik  *
654491d8ee7SSantosh Puranik  * @return None.
655491d8ee7SSantosh Puranik  */
656491d8ee7SSantosh Puranik static void getBootSource(std::shared_ptr<AsyncResp> aResp, bool oneTimeEnabled)
657491d8ee7SSantosh Puranik {
658491d8ee7SSantosh Puranik     std::string bootDbusObj =
659491d8ee7SSantosh Puranik         oneTimeEnabled ? "/xyz/openbmc_project/control/host0/boot/one_time"
660491d8ee7SSantosh Puranik                        : "/xyz/openbmc_project/control/host0/boot";
661491d8ee7SSantosh Puranik 
662491d8ee7SSantosh Puranik     BMCWEB_LOG_DEBUG << "Is one time: " << oneTimeEnabled;
663491d8ee7SSantosh Puranik     aResp->res.jsonValue["Boot"]["BootSourceOverrideEnabled"] =
664491d8ee7SSantosh Puranik         (oneTimeEnabled) ? "Once" : "Continuous";
665491d8ee7SSantosh Puranik 
666491d8ee7SSantosh Puranik     crow::connections::systemBus->async_method_call(
667491d8ee7SSantosh Puranik         [aResp, bootDbusObj](const boost::system::error_code ec,
668491d8ee7SSantosh Puranik                              const std::variant<std::string> &bootSource) {
669491d8ee7SSantosh Puranik             if (ec)
670491d8ee7SSantosh Puranik             {
671491d8ee7SSantosh Puranik                 BMCWEB_LOG_DEBUG << "DBUS response error " << ec;
672491d8ee7SSantosh Puranik                 messages::internalError(aResp->res);
673491d8ee7SSantosh Puranik                 return;
674491d8ee7SSantosh Puranik             }
675491d8ee7SSantosh Puranik 
676491d8ee7SSantosh Puranik             const std::string *bootSourceStr =
677491d8ee7SSantosh Puranik                 std::get_if<std::string>(&bootSource);
678491d8ee7SSantosh Puranik 
679491d8ee7SSantosh Puranik             if (!bootSourceStr)
680491d8ee7SSantosh Puranik             {
681491d8ee7SSantosh Puranik                 messages::internalError(aResp->res);
682491d8ee7SSantosh Puranik                 return;
683491d8ee7SSantosh Puranik             }
684491d8ee7SSantosh Puranik             BMCWEB_LOG_DEBUG << "Boot source: " << *bootSourceStr;
685491d8ee7SSantosh Puranik 
686491d8ee7SSantosh Puranik             auto rfSource = dbusToRfBootSource(*bootSourceStr);
687491d8ee7SSantosh Puranik             if (!rfSource.empty())
688491d8ee7SSantosh Puranik             {
689491d8ee7SSantosh Puranik                 aResp->res.jsonValue["Boot"]["BootSourceOverrideTarget"] =
690491d8ee7SSantosh Puranik                     rfSource;
691491d8ee7SSantosh Puranik             }
692491d8ee7SSantosh Puranik         },
693491d8ee7SSantosh Puranik         "xyz.openbmc_project.Settings", bootDbusObj,
694491d8ee7SSantosh Puranik         "org.freedesktop.DBus.Properties", "Get",
695491d8ee7SSantosh Puranik         "xyz.openbmc_project.Control.Boot.Source", "BootSource");
696491d8ee7SSantosh Puranik     getBootMode(std::move(aResp), std::move(bootDbusObj));
697491d8ee7SSantosh Puranik }
698491d8ee7SSantosh Puranik 
699491d8ee7SSantosh Puranik /**
700491d8ee7SSantosh Puranik  * @brief Retrieves "One time" enabled setting over DBUS and calls function to
701491d8ee7SSantosh Puranik  * get boot source and boot mode.
702491d8ee7SSantosh Puranik  *
703491d8ee7SSantosh Puranik  * @param[in] aResp     Shared pointer for generating response message.
704491d8ee7SSantosh Puranik  *
705491d8ee7SSantosh Puranik  * @return None.
706491d8ee7SSantosh Puranik  */
707491d8ee7SSantosh Puranik static void getBootProperties(std::shared_ptr<AsyncResp> aResp)
708491d8ee7SSantosh Puranik {
709491d8ee7SSantosh Puranik     BMCWEB_LOG_DEBUG << "Get boot information.";
710491d8ee7SSantosh Puranik 
711491d8ee7SSantosh Puranik     crow::connections::systemBus->async_method_call(
712*c5d03ff4SJennifer Lee         [aResp](const boost::system::error_code ec,
713491d8ee7SSantosh Puranik                 const sdbusplus::message::variant<bool> &oneTime) {
714491d8ee7SSantosh Puranik             if (ec)
715491d8ee7SSantosh Puranik             {
716491d8ee7SSantosh Puranik                 BMCWEB_LOG_DEBUG << "DBUS response error " << ec;
717491d8ee7SSantosh Puranik                 messages::internalError(aResp->res);
718491d8ee7SSantosh Puranik                 return;
719491d8ee7SSantosh Puranik             }
720491d8ee7SSantosh Puranik 
721491d8ee7SSantosh Puranik             const bool *oneTimePtr = std::get_if<bool>(&oneTime);
722491d8ee7SSantosh Puranik 
723491d8ee7SSantosh Puranik             if (!oneTimePtr)
724491d8ee7SSantosh Puranik             {
725491d8ee7SSantosh Puranik                 messages::internalError(aResp->res);
726491d8ee7SSantosh Puranik                 return;
727491d8ee7SSantosh Puranik             }
728491d8ee7SSantosh Puranik             getBootSource(aResp, *oneTimePtr);
729491d8ee7SSantosh Puranik         },
730491d8ee7SSantosh Puranik         "xyz.openbmc_project.Settings",
731491d8ee7SSantosh Puranik         "/xyz/openbmc_project/control/host0/boot/one_time",
732491d8ee7SSantosh Puranik         "org.freedesktop.DBus.Properties", "Get",
733491d8ee7SSantosh Puranik         "xyz.openbmc_project.Object.Enable", "Enabled");
734491d8ee7SSantosh Puranik }
735491d8ee7SSantosh Puranik 
736491d8ee7SSantosh Puranik /**
737491d8ee7SSantosh Puranik  * @brief Sets boot properties into DBUS object(s).
738491d8ee7SSantosh Puranik  *
739491d8ee7SSantosh Puranik  * @param[in] aResp           Shared pointer for generating response message.
740491d8ee7SSantosh Puranik  * @param[in] oneTimeEnabled  Is "one-time" setting already enabled.
741491d8ee7SSantosh Puranik  * @param[in] bootSource      The boot source to set.
742491d8ee7SSantosh Puranik  * @param[in] bootEnable      The source override "enable" to set.
743491d8ee7SSantosh Puranik  *
744491d8ee7SSantosh Puranik  * @return None.
745491d8ee7SSantosh Puranik  */
746491d8ee7SSantosh Puranik static void setBootModeOrSource(std::shared_ptr<AsyncResp> aResp,
747491d8ee7SSantosh Puranik                                 bool oneTimeEnabled,
748491d8ee7SSantosh Puranik                                 std::optional<std::string> bootSource,
749491d8ee7SSantosh Puranik                                 std::optional<std::string> bootEnable)
750491d8ee7SSantosh Puranik {
751491d8ee7SSantosh Puranik     if (bootEnable && (bootEnable != "Once") && (bootEnable != "Continuous") &&
752491d8ee7SSantosh Puranik         (bootEnable != "Disabled"))
753491d8ee7SSantosh Puranik     {
754491d8ee7SSantosh Puranik         BMCWEB_LOG_DEBUG << "Unsupported value for BootSourceOverrideEnabled: "
755491d8ee7SSantosh Puranik                          << *bootEnable;
756491d8ee7SSantosh Puranik         messages::propertyValueNotInList(aResp->res, *bootEnable,
757491d8ee7SSantosh Puranik                                          "BootSourceOverrideEnabled");
758491d8ee7SSantosh Puranik         return;
759491d8ee7SSantosh Puranik     }
760491d8ee7SSantosh Puranik 
761491d8ee7SSantosh Puranik     bool oneTimeSetting = oneTimeEnabled;
762491d8ee7SSantosh Puranik     // Validate incoming parameters
763491d8ee7SSantosh Puranik     if (bootEnable)
764491d8ee7SSantosh Puranik     {
765491d8ee7SSantosh Puranik         if (*bootEnable == "Once")
766491d8ee7SSantosh Puranik         {
767491d8ee7SSantosh Puranik             oneTimeSetting = true;
768491d8ee7SSantosh Puranik         }
769491d8ee7SSantosh Puranik         else if (*bootEnable == "Continuous")
770491d8ee7SSantosh Puranik         {
771491d8ee7SSantosh Puranik             oneTimeSetting = false;
772491d8ee7SSantosh Puranik         }
773491d8ee7SSantosh Puranik         else if (*bootEnable == "Disabled")
774491d8ee7SSantosh Puranik         {
775491d8ee7SSantosh Puranik             oneTimeSetting = false;
776491d8ee7SSantosh Puranik         }
777491d8ee7SSantosh Puranik         else
778491d8ee7SSantosh Puranik         {
779491d8ee7SSantosh Puranik 
780491d8ee7SSantosh Puranik             BMCWEB_LOG_DEBUG << "Unsupported value for "
781491d8ee7SSantosh Puranik                                 "BootSourceOverrideEnabled: "
782491d8ee7SSantosh Puranik                              << *bootEnable;
783491d8ee7SSantosh Puranik             messages::propertyValueNotInList(aResp->res, *bootEnable,
784491d8ee7SSantosh Puranik                                              "BootSourceOverrideEnabled");
785491d8ee7SSantosh Puranik             return;
786491d8ee7SSantosh Puranik         }
787491d8ee7SSantosh Puranik     }
788491d8ee7SSantosh Puranik     std::string bootSourceStr;
789491d8ee7SSantosh Puranik     std::string bootModeStr;
790491d8ee7SSantosh Puranik     if (bootSource)
791491d8ee7SSantosh Puranik     {
792491d8ee7SSantosh Puranik         bootSourceStr = rfToDbusBootSource(*bootSource);
793491d8ee7SSantosh Puranik         bootModeStr = rfToDbusBootMode(*bootSource);
794491d8ee7SSantosh Puranik 
795491d8ee7SSantosh Puranik         BMCWEB_LOG_DEBUG << "DBUS boot source: " << bootSourceStr;
796491d8ee7SSantosh Puranik         BMCWEB_LOG_DEBUG << "DBUS boot mode: " << bootModeStr;
797491d8ee7SSantosh Puranik 
798491d8ee7SSantosh Puranik         if (bootSourceStr.empty() && bootModeStr.empty())
799491d8ee7SSantosh Puranik         {
800491d8ee7SSantosh Puranik             BMCWEB_LOG_DEBUG << "Invalid property value for "
801491d8ee7SSantosh Puranik                                 "BootSourceOverrideTarget: "
802491d8ee7SSantosh Puranik                              << *bootSource;
803491d8ee7SSantosh Puranik             messages::propertyValueNotInList(aResp->res, *bootSource,
804491d8ee7SSantosh Puranik                                              "BootSourceTargetOverride");
805491d8ee7SSantosh Puranik             return;
806491d8ee7SSantosh Puranik         }
807491d8ee7SSantosh Puranik     }
808491d8ee7SSantosh Puranik     const char *bootObj =
809491d8ee7SSantosh Puranik         oneTimeSetting ? "/xyz/openbmc_project/control/host0/boot/one_time"
810491d8ee7SSantosh Puranik                        : "/xyz/openbmc_project/control/host0/boot";
811491d8ee7SSantosh Puranik     // Figure out what properties to set
812491d8ee7SSantosh Puranik     if (bootEnable && (*bootEnable == "Disabled"))
813491d8ee7SSantosh Puranik     {
814491d8ee7SSantosh Puranik         BMCWEB_LOG_DEBUG << "Boot source override will be disabled";
815491d8ee7SSantosh Puranik         // Request to only turn OFF/ON enabled, if turning enabled OFF, need
816491d8ee7SSantosh Puranik         // to reset the source and mode too. If turning it ON, we only need
817491d8ee7SSantosh Puranik         // to set the enabled property
818491d8ee7SSantosh Puranik         bootSourceStr =
819491d8ee7SSantosh Puranik             "xyz.openbmc_project.Control.Boot.Source.Sources.Default";
820491d8ee7SSantosh Puranik         bootModeStr = "xyz.openbmc_project.Control.Boot.Mode.Modes.Regular";
821491d8ee7SSantosh Puranik     }
822491d8ee7SSantosh Puranik     else if (bootSource)
823491d8ee7SSantosh Puranik     {
824491d8ee7SSantosh Puranik         // Source target specified
825491d8ee7SSantosh Puranik         BMCWEB_LOG_DEBUG << "Boot source: " << *bootSource;
826491d8ee7SSantosh Puranik         // Figure out which DBUS interface and property to use
827491d8ee7SSantosh Puranik         bootSourceStr = rfToDbusBootSource(*bootSource);
828491d8ee7SSantosh Puranik         bootModeStr = rfToDbusBootMode(*bootSource);
829491d8ee7SSantosh Puranik 
830491d8ee7SSantosh Puranik         BMCWEB_LOG_DEBUG << "DBUS boot source: " << bootSourceStr;
831491d8ee7SSantosh Puranik         BMCWEB_LOG_DEBUG << "DBUS boot mode: " << bootModeStr;
832491d8ee7SSantosh Puranik 
833491d8ee7SSantosh Puranik         if (bootSourceStr.empty() && bootModeStr.empty())
834491d8ee7SSantosh Puranik         {
835491d8ee7SSantosh Puranik             BMCWEB_LOG_DEBUG << "Invalid property value for "
836491d8ee7SSantosh Puranik                                 "BootSourceOverrideTarget: "
837491d8ee7SSantosh Puranik                              << *bootSource;
838491d8ee7SSantosh Puranik             messages::propertyValueNotInList(aResp->res, *bootSource,
839491d8ee7SSantosh Puranik                                              "BootSourceTargetOverride");
840491d8ee7SSantosh Puranik             return;
841491d8ee7SSantosh Puranik         }
842491d8ee7SSantosh Puranik 
843491d8ee7SSantosh Puranik         if (!bootSourceStr.empty())
844491d8ee7SSantosh Puranik         {
845491d8ee7SSantosh Puranik             // If setting to anything other than default, also reset boot
846491d8ee7SSantosh Puranik             // mode property
847491d8ee7SSantosh Puranik             if (bootSourceStr !=
848491d8ee7SSantosh Puranik                 "xyz.openbmc_project.Control.Boot.Source.Sources.Default")
849491d8ee7SSantosh Puranik             {
850491d8ee7SSantosh Puranik                 bootModeStr =
851491d8ee7SSantosh Puranik                     "xyz.openbmc_project.Control.Boot.Mode.Modes.Regular";
852491d8ee7SSantosh Puranik             }
853491d8ee7SSantosh Puranik         }
854491d8ee7SSantosh Puranik         else // if (!bootModeStr.empty())
855491d8ee7SSantosh Puranik         {
856491d8ee7SSantosh Puranik             // If setting to anything other than default, also reset boot
857491d8ee7SSantosh Puranik             // source property
858491d8ee7SSantosh Puranik             if (bootModeStr !=
859491d8ee7SSantosh Puranik                 "xyz.openbmc_project.Control.Boot.Mode.Modes.Regular")
860491d8ee7SSantosh Puranik             {
861491d8ee7SSantosh Puranik                 bootSourceStr =
862491d8ee7SSantosh Puranik                     "xyz.openbmc_project.Control.Boot.Source.Sources.Default";
863491d8ee7SSantosh Puranik             }
864491d8ee7SSantosh Puranik         }
865491d8ee7SSantosh Puranik     }
866491d8ee7SSantosh Puranik     if (!bootSourceStr.empty())
867491d8ee7SSantosh Puranik     {
868491d8ee7SSantosh Puranik         crow::connections::systemBus->async_method_call(
869491d8ee7SSantosh Puranik             [aResp](const boost::system::error_code ec) {
870491d8ee7SSantosh Puranik                 if (ec)
871491d8ee7SSantosh Puranik                 {
872491d8ee7SSantosh Puranik                     BMCWEB_LOG_DEBUG << "DBUS response error " << ec;
873491d8ee7SSantosh Puranik                     messages::internalError(aResp->res);
874491d8ee7SSantosh Puranik                     return;
875491d8ee7SSantosh Puranik                 }
876491d8ee7SSantosh Puranik                 BMCWEB_LOG_DEBUG << "Boot source update done.";
877491d8ee7SSantosh Puranik             },
878491d8ee7SSantosh Puranik             "xyz.openbmc_project.Settings", bootObj,
879491d8ee7SSantosh Puranik             "org.freedesktop.DBus.Properties", "Set",
880491d8ee7SSantosh Puranik             "xyz.openbmc_project.Control.Boot.Source", "BootSource",
881491d8ee7SSantosh Puranik             std::variant<std::string>(bootSourceStr));
882491d8ee7SSantosh Puranik     }
883491d8ee7SSantosh Puranik     if (!bootModeStr.empty())
884491d8ee7SSantosh Puranik     {
885491d8ee7SSantosh Puranik         crow::connections::systemBus->async_method_call(
886491d8ee7SSantosh Puranik             [aResp](const boost::system::error_code ec) {
887491d8ee7SSantosh Puranik                 if (ec)
888491d8ee7SSantosh Puranik                 {
889491d8ee7SSantosh Puranik                     BMCWEB_LOG_DEBUG << "DBUS response error " << ec;
890491d8ee7SSantosh Puranik                     messages::internalError(aResp->res);
891491d8ee7SSantosh Puranik                     return;
892491d8ee7SSantosh Puranik                 }
893491d8ee7SSantosh Puranik                 BMCWEB_LOG_DEBUG << "Boot mode update done.";
894491d8ee7SSantosh Puranik             },
895491d8ee7SSantosh Puranik             "xyz.openbmc_project.Settings", bootObj,
896491d8ee7SSantosh Puranik             "org.freedesktop.DBus.Properties", "Set",
897491d8ee7SSantosh Puranik             "xyz.openbmc_project.Control.Boot.Mode", "BootMode",
898491d8ee7SSantosh Puranik             std::variant<std::string>(bootModeStr));
899491d8ee7SSantosh Puranik     }
900491d8ee7SSantosh Puranik     crow::connections::systemBus->async_method_call(
901491d8ee7SSantosh Puranik         [aResp{std::move(aResp)}](const boost::system::error_code ec) {
902491d8ee7SSantosh Puranik             if (ec)
903491d8ee7SSantosh Puranik             {
904491d8ee7SSantosh Puranik                 BMCWEB_LOG_DEBUG << "DBUS response error " << ec;
905491d8ee7SSantosh Puranik                 messages::internalError(aResp->res);
906491d8ee7SSantosh Puranik                 return;
907491d8ee7SSantosh Puranik             }
908491d8ee7SSantosh Puranik             BMCWEB_LOG_DEBUG << "Boot enable update done.";
909491d8ee7SSantosh Puranik         },
910491d8ee7SSantosh Puranik         "xyz.openbmc_project.Settings",
911491d8ee7SSantosh Puranik         "/xyz/openbmc_project/control/host0/boot/one_time",
912491d8ee7SSantosh Puranik         "org.freedesktop.DBus.Properties", "Set",
913491d8ee7SSantosh Puranik         "xyz.openbmc_project.Object.Enable", "Enabled",
914491d8ee7SSantosh Puranik         std::variant<bool>(oneTimeSetting));
915491d8ee7SSantosh Puranik }
916491d8ee7SSantosh Puranik 
917491d8ee7SSantosh Puranik /**
918491d8ee7SSantosh Puranik  * @brief Retrieves "One time" enabled setting over DBUS and calls function to
919491d8ee7SSantosh Puranik  * set boot source/boot mode properties.
920491d8ee7SSantosh Puranik  *
921491d8ee7SSantosh Puranik  * @param[in] aResp      Shared pointer for generating response message.
922491d8ee7SSantosh Puranik  * @param[in] bootSource The boot source from incoming RF request.
923491d8ee7SSantosh Puranik  * @param[in] bootEnable The boot override enable from incoming RF request.
924491d8ee7SSantosh Puranik  *
925491d8ee7SSantosh Puranik  * @return None.
926491d8ee7SSantosh Puranik  */
927491d8ee7SSantosh Puranik static void setBootProperties(std::shared_ptr<AsyncResp> aResp,
928491d8ee7SSantosh Puranik                               std::optional<std::string> bootSource,
929491d8ee7SSantosh Puranik                               std::optional<std::string> bootEnable)
930491d8ee7SSantosh Puranik {
931491d8ee7SSantosh Puranik     BMCWEB_LOG_DEBUG << "Set boot information.";
932491d8ee7SSantosh Puranik 
933491d8ee7SSantosh Puranik     crow::connections::systemBus->async_method_call(
934491d8ee7SSantosh Puranik         [aResp{std::move(aResp)}, bootSource{std::move(bootSource)},
935491d8ee7SSantosh Puranik          bootEnable{std::move(bootEnable)}](
936491d8ee7SSantosh Puranik             const boost::system::error_code ec,
937491d8ee7SSantosh Puranik             const sdbusplus::message::variant<bool> &oneTime) {
938491d8ee7SSantosh Puranik             if (ec)
939491d8ee7SSantosh Puranik             {
940491d8ee7SSantosh Puranik                 BMCWEB_LOG_DEBUG << "DBUS response error " << ec;
941491d8ee7SSantosh Puranik                 messages::internalError(aResp->res);
942491d8ee7SSantosh Puranik                 return;
943491d8ee7SSantosh Puranik             }
944491d8ee7SSantosh Puranik 
945491d8ee7SSantosh Puranik             const bool *oneTimePtr = std::get_if<bool>(&oneTime);
946491d8ee7SSantosh Puranik 
947491d8ee7SSantosh Puranik             if (!oneTimePtr)
948491d8ee7SSantosh Puranik             {
949491d8ee7SSantosh Puranik                 messages::internalError(aResp->res);
950491d8ee7SSantosh Puranik                 return;
951491d8ee7SSantosh Puranik             }
952491d8ee7SSantosh Puranik 
953491d8ee7SSantosh Puranik             BMCWEB_LOG_DEBUG << "Got one time: " << *oneTimePtr;
954491d8ee7SSantosh Puranik 
955491d8ee7SSantosh Puranik             setBootModeOrSource(aResp, *oneTimePtr, std::move(bootSource),
956491d8ee7SSantosh Puranik                                 std::move(bootEnable));
957491d8ee7SSantosh Puranik         },
958491d8ee7SSantosh Puranik         "xyz.openbmc_project.Settings",
959491d8ee7SSantosh Puranik         "/xyz/openbmc_project/control/host0/boot/one_time",
960491d8ee7SSantosh Puranik         "org.freedesktop.DBus.Properties", "Get",
961491d8ee7SSantosh Puranik         "xyz.openbmc_project.Object.Enable", "Enabled");
962491d8ee7SSantosh Puranik }
963491d8ee7SSantosh Puranik 
964491d8ee7SSantosh Puranik /**
965c5b2abe0SLewanczyk, Dawid  * SystemsCollection derived class for delivering ComputerSystems Collection
966c5b2abe0SLewanczyk, Dawid  * Schema
967c5b2abe0SLewanczyk, Dawid  */
9681abe55efSEd Tanous class SystemsCollection : public Node
9691abe55efSEd Tanous {
970c5b2abe0SLewanczyk, Dawid   public:
9711abe55efSEd Tanous     SystemsCollection(CrowApp &app) : Node(app, "/redfish/v1/Systems/")
9721abe55efSEd Tanous     {
973c5b2abe0SLewanczyk, Dawid         entityPrivileges = {
974c5b2abe0SLewanczyk, Dawid             {boost::beast::http::verb::get, {{"Login"}}},
975c5b2abe0SLewanczyk, Dawid             {boost::beast::http::verb::head, {{"Login"}}},
976c5b2abe0SLewanczyk, Dawid             {boost::beast::http::verb::patch, {{"ConfigureComponents"}}},
977c5b2abe0SLewanczyk, Dawid             {boost::beast::http::verb::put, {{"ConfigureComponents"}}},
978c5b2abe0SLewanczyk, Dawid             {boost::beast::http::verb::delete_, {{"ConfigureComponents"}}},
979c5b2abe0SLewanczyk, Dawid             {boost::beast::http::verb::post, {{"ConfigureComponents"}}}};
980c5b2abe0SLewanczyk, Dawid     }
981c5b2abe0SLewanczyk, Dawid 
982c5b2abe0SLewanczyk, Dawid   private:
98355c7b7a2SEd Tanous     void doGet(crow::Response &res, const crow::Request &req,
9841abe55efSEd Tanous                const std::vector<std::string> &params) override
9851abe55efSEd Tanous     {
9860f74e643SEd Tanous         res.jsonValue["@odata.type"] =
9870f74e643SEd Tanous             "#ComputerSystemCollection.ComputerSystemCollection";
9880f74e643SEd Tanous         res.jsonValue["@odata.id"] = "/redfish/v1/Systems";
9890f74e643SEd Tanous         res.jsonValue["@odata.context"] =
9900f74e643SEd Tanous             "/redfish/v1/"
9910f74e643SEd Tanous             "$metadata#ComputerSystemCollection.ComputerSystemCollection";
9920f74e643SEd Tanous         res.jsonValue["Name"] = "Computer System Collection";
993029573d4SEd Tanous         res.jsonValue["Members"] = {
994029573d4SEd Tanous             {{"@odata.id", "/redfish/v1/Systems/system"}}};
995029573d4SEd Tanous         res.jsonValue["Members@odata.count"] = 1;
996029573d4SEd Tanous         res.end();
997c5b2abe0SLewanczyk, Dawid     }
998c5b2abe0SLewanczyk, Dawid };
999c5b2abe0SLewanczyk, Dawid 
1000c5b2abe0SLewanczyk, Dawid /**
1001cc340dd9SEd Tanous  * SystemActionsReset class supports handle POST method for Reset action.
1002cc340dd9SEd Tanous  * The class retrieves and sends data directly to D-Bus.
1003cc340dd9SEd Tanous  */
1004cc340dd9SEd Tanous class SystemActionsReset : public Node
1005cc340dd9SEd Tanous {
1006cc340dd9SEd Tanous   public:
1007cc340dd9SEd Tanous     SystemActionsReset(CrowApp &app) :
1008029573d4SEd Tanous         Node(app, "/redfish/v1/Systems/system/Actions/ComputerSystem.Reset/")
1009cc340dd9SEd Tanous     {
1010cc340dd9SEd Tanous         entityPrivileges = {
1011cc340dd9SEd Tanous             {boost::beast::http::verb::post, {{"ConfigureComponents"}}}};
1012cc340dd9SEd Tanous     }
1013cc340dd9SEd Tanous 
1014cc340dd9SEd Tanous   private:
1015cc340dd9SEd Tanous     /**
1016cc340dd9SEd Tanous      * Function handles POST method request.
1017cc340dd9SEd Tanous      * Analyzes POST body message before sends Reset request data to D-Bus.
1018cc340dd9SEd Tanous      */
1019cc340dd9SEd Tanous     void doPost(crow::Response &res, const crow::Request &req,
1020cc340dd9SEd Tanous                 const std::vector<std::string> &params) override
1021cc340dd9SEd Tanous     {
1022cc340dd9SEd Tanous         auto asyncResp = std::make_shared<AsyncResp>(res);
1023cc340dd9SEd Tanous 
10249712f8acSEd Tanous         std::string resetType;
10259712f8acSEd Tanous         if (!json_util::readJson(req, res, "ResetType", resetType))
1026cc340dd9SEd Tanous         {
1027cc340dd9SEd Tanous             return;
1028cc340dd9SEd Tanous         }
1029cc340dd9SEd Tanous 
1030d22c8396SJason M. Bills         // Get the command and host vs. chassis
1031cc340dd9SEd Tanous         std::string command;
1032d22c8396SJason M. Bills         bool hostCommand;
10339712f8acSEd Tanous         if (resetType == "On")
1034cc340dd9SEd Tanous         {
1035cc340dd9SEd Tanous             command = "xyz.openbmc_project.State.Host.Transition.On";
1036d22c8396SJason M. Bills             hostCommand = true;
1037d22c8396SJason M. Bills         }
1038d22c8396SJason M. Bills         else if (resetType == "ForceOff")
1039d22c8396SJason M. Bills         {
1040d22c8396SJason M. Bills             command = "xyz.openbmc_project.State.Chassis.Transition.Off";
1041d22c8396SJason M. Bills             hostCommand = false;
1042d22c8396SJason M. Bills         }
1043d22c8396SJason M. Bills         else if (resetType == "ForceOn")
1044d22c8396SJason M. Bills         {
1045d22c8396SJason M. Bills             command = "xyz.openbmc_project.State.Host.Transition.On";
1046d22c8396SJason M. Bills             hostCommand = true;
1047d22c8396SJason M. Bills         }
1048d22c8396SJason M. Bills         else if (resetType == "ForceRestart")
1049d22c8396SJason M. Bills         {
1050d22c8396SJason M. Bills             command = "xyz.openbmc_project.State.Chassis.Transition.Reset";
1051d22c8396SJason M. Bills             hostCommand = false;
1052cc340dd9SEd Tanous         }
10539712f8acSEd Tanous         else if (resetType == "GracefulShutdown")
1054cc340dd9SEd Tanous         {
1055cc340dd9SEd Tanous             command = "xyz.openbmc_project.State.Host.Transition.Off";
1056d22c8396SJason M. Bills             hostCommand = true;
1057cc340dd9SEd Tanous         }
10589712f8acSEd Tanous         else if (resetType == "GracefulRestart")
1059cc340dd9SEd Tanous         {
10609712f8acSEd Tanous             command = "xyz.openbmc_project.State.Host.Transition.Reboot";
1061d22c8396SJason M. Bills             hostCommand = true;
1062d22c8396SJason M. Bills         }
1063d22c8396SJason M. Bills         else if (resetType == "PowerCycle")
1064d22c8396SJason M. Bills         {
1065d22c8396SJason M. Bills             command = "xyz.openbmc_project.State.Chassis.Transition.PowerCycle";
1066d22c8396SJason M. Bills             hostCommand = false;
1067cc340dd9SEd Tanous         }
1068cc340dd9SEd Tanous         else
1069cc340dd9SEd Tanous         {
1070f12894f8SJason M. Bills             messages::actionParameterUnknown(res, "Reset", resetType);
1071cc340dd9SEd Tanous             return;
1072cc340dd9SEd Tanous         }
1073cc340dd9SEd Tanous 
1074d22c8396SJason M. Bills         if (hostCommand)
1075d22c8396SJason M. Bills         {
1076cc340dd9SEd Tanous             crow::connections::systemBus->async_method_call(
1077d22c8396SJason M. Bills                 [asyncResp, resetType](const boost::system::error_code ec) {
1078cc340dd9SEd Tanous                     if (ec)
1079cc340dd9SEd Tanous                     {
1080cc340dd9SEd Tanous                         BMCWEB_LOG_ERROR << "D-Bus responses error: " << ec;
1081d22c8396SJason M. Bills                         if (ec.value() == boost::asio::error::invalid_argument)
1082d22c8396SJason M. Bills                         {
1083d22c8396SJason M. Bills                             messages::actionParameterNotSupported(
1084d22c8396SJason M. Bills                                 asyncResp->res, resetType, "Reset");
1085d22c8396SJason M. Bills                         }
1086d22c8396SJason M. Bills                         else
1087d22c8396SJason M. Bills                         {
1088f12894f8SJason M. Bills                             messages::internalError(asyncResp->res);
1089d22c8396SJason M. Bills                         }
1090cc340dd9SEd Tanous                         return;
1091cc340dd9SEd Tanous                     }
1092f12894f8SJason M. Bills                     messages::success(asyncResp->res);
1093cc340dd9SEd Tanous                 },
1094cc340dd9SEd Tanous                 "xyz.openbmc_project.State.Host",
1095cc340dd9SEd Tanous                 "/xyz/openbmc_project/state/host0",
1096cc340dd9SEd Tanous                 "org.freedesktop.DBus.Properties", "Set",
10979712f8acSEd Tanous                 "xyz.openbmc_project.State.Host", "RequestedHostTransition",
1098abf2add6SEd Tanous                 std::variant<std::string>{command});
1099cc340dd9SEd Tanous         }
1100d22c8396SJason M. Bills         else
1101d22c8396SJason M. Bills         {
1102d22c8396SJason M. Bills             crow::connections::systemBus->async_method_call(
1103d22c8396SJason M. Bills                 [asyncResp, resetType](const boost::system::error_code ec) {
1104d22c8396SJason M. Bills                     if (ec)
1105d22c8396SJason M. Bills                     {
1106d22c8396SJason M. Bills                         BMCWEB_LOG_ERROR << "D-Bus responses error: " << ec;
1107d22c8396SJason M. Bills                         if (ec.value() == boost::asio::error::invalid_argument)
1108d22c8396SJason M. Bills                         {
1109d22c8396SJason M. Bills                             messages::actionParameterNotSupported(
1110d22c8396SJason M. Bills                                 asyncResp->res, resetType, "Reset");
1111d22c8396SJason M. Bills                         }
1112d22c8396SJason M. Bills                         else
1113d22c8396SJason M. Bills                         {
1114d22c8396SJason M. Bills                             messages::internalError(asyncResp->res);
1115d22c8396SJason M. Bills                         }
1116d22c8396SJason M. Bills                         return;
1117d22c8396SJason M. Bills                     }
1118d22c8396SJason M. Bills                     messages::success(asyncResp->res);
1119d22c8396SJason M. Bills                 },
1120d22c8396SJason M. Bills                 "xyz.openbmc_project.State.Chassis",
1121d22c8396SJason M. Bills                 "/xyz/openbmc_project/state/chassis0",
1122d22c8396SJason M. Bills                 "org.freedesktop.DBus.Properties", "Set",
1123d22c8396SJason M. Bills                 "xyz.openbmc_project.State.Chassis", "RequestedPowerTransition",
1124d22c8396SJason M. Bills                 std::variant<std::string>{command});
1125d22c8396SJason M. Bills         }
1126d22c8396SJason M. Bills     }
1127cc340dd9SEd Tanous };
1128cc340dd9SEd Tanous 
1129cc340dd9SEd Tanous /**
11306617338dSEd Tanous  * Systems derived class for delivering Computer Systems Schema.
1131c5b2abe0SLewanczyk, Dawid  */
11321abe55efSEd Tanous class Systems : public Node
11331abe55efSEd Tanous {
1134c5b2abe0SLewanczyk, Dawid   public:
1135c5b2abe0SLewanczyk, Dawid     /*
1136c5b2abe0SLewanczyk, Dawid      * Default Constructor
1137c5b2abe0SLewanczyk, Dawid      */
1138029573d4SEd Tanous     Systems(CrowApp &app) : Node(app, "/redfish/v1/Systems/system/")
11391abe55efSEd Tanous     {
1140c5b2abe0SLewanczyk, Dawid         entityPrivileges = {
1141c5b2abe0SLewanczyk, Dawid             {boost::beast::http::verb::get, {{"Login"}}},
1142c5b2abe0SLewanczyk, Dawid             {boost::beast::http::verb::head, {{"Login"}}},
1143c5b2abe0SLewanczyk, Dawid             {boost::beast::http::verb::patch, {{"ConfigureComponents"}}},
1144c5b2abe0SLewanczyk, Dawid             {boost::beast::http::verb::put, {{"ConfigureComponents"}}},
1145c5b2abe0SLewanczyk, Dawid             {boost::beast::http::verb::delete_, {{"ConfigureComponents"}}},
1146c5b2abe0SLewanczyk, Dawid             {boost::beast::http::verb::post, {{"ConfigureComponents"}}}};
1147c5b2abe0SLewanczyk, Dawid     }
1148c5b2abe0SLewanczyk, Dawid 
1149c5b2abe0SLewanczyk, Dawid   private:
1150c5b2abe0SLewanczyk, Dawid     /**
1151c5b2abe0SLewanczyk, Dawid      * Functions triggers appropriate requests on DBus
1152c5b2abe0SLewanczyk, Dawid      */
115355c7b7a2SEd Tanous     void doGet(crow::Response &res, const crow::Request &req,
11541abe55efSEd Tanous                const std::vector<std::string> &params) override
11551abe55efSEd Tanous     {
1156491d8ee7SSantosh Puranik         res.jsonValue["@odata.type"] = "#ComputerSystem.v1_6_0.ComputerSystem";
11570f74e643SEd Tanous         res.jsonValue["@odata.context"] =
11580f74e643SEd Tanous             "/redfish/v1/$metadata#ComputerSystem.ComputerSystem";
1159029573d4SEd Tanous         res.jsonValue["Name"] = "Computer System";
1160029573d4SEd Tanous         res.jsonValue["Id"] = "system";
11610f74e643SEd Tanous         res.jsonValue["SystemType"] = "Physical";
11620f74e643SEd Tanous         res.jsonValue["Description"] = "Computer System";
11630f74e643SEd Tanous         res.jsonValue["ProcessorSummary"]["Count"] = 0;
11640f74e643SEd Tanous         res.jsonValue["ProcessorSummary"]["Status"]["State"] = "Disabled";
11650f74e643SEd Tanous         res.jsonValue["MemorySummary"]["TotalSystemMemoryGiB"] = int(0);
11660f74e643SEd Tanous         res.jsonValue["MemorySummary"]["Status"]["State"] = "Disabled";
1167029573d4SEd Tanous         res.jsonValue["@odata.id"] = "/redfish/v1/Systems/system";
116804a258f4SEd Tanous 
1169443c2934SRapkiewicz, Pawel         res.jsonValue["Processors"] = {
1170029573d4SEd Tanous             {"@odata.id", "/redfish/v1/Systems/system/Processors"}};
1171443c2934SRapkiewicz, Pawel         res.jsonValue["Memory"] = {
1172029573d4SEd Tanous             {"@odata.id", "/redfish/v1/Systems/system/Memory"}};
1173029573d4SEd Tanous 
1174cc340dd9SEd Tanous         // TODO Need to support ForceRestart.
1175cc340dd9SEd Tanous         res.jsonValue["Actions"]["#ComputerSystem.Reset"] = {
1176cc340dd9SEd Tanous             {"target",
1177029573d4SEd Tanous              "/redfish/v1/Systems/system/Actions/ComputerSystem.Reset"},
1178cc340dd9SEd Tanous             {"ResetType@Redfish.AllowableValues",
1179d22c8396SJason M. Bills              {"On", "ForceOff", "ForceOn", "ForceRestart", "GracefulRestart",
1180d22c8396SJason M. Bills               "GracefulShutdown", "PowerCycle"}}};
1181c5b2abe0SLewanczyk, Dawid 
1182c4bf6374SJason M. Bills         res.jsonValue["LogServices"] = {
1183029573d4SEd Tanous             {"@odata.id", "/redfish/v1/Systems/system/LogServices"}};
1184c4bf6374SJason M. Bills 
1185*c5d03ff4SJennifer Lee         res.jsonValue["Links"]["ManagedBy"] = {
1186*c5d03ff4SJennifer Lee             {{"@odata.id", "/redfish/v1/Managers/bmc"}}};
1187*c5d03ff4SJennifer Lee 
1188*c5d03ff4SJennifer Lee         res.jsonValue["Status"] = {
1189*c5d03ff4SJennifer Lee             {"Health", "OK"},
1190*c5d03ff4SJennifer Lee             {"State", "Enabled"},
1191*c5d03ff4SJennifer Lee         };
1192a0803efaSEd Tanous         auto asyncResp = std::make_shared<AsyncResp>(res);
1193c5b2abe0SLewanczyk, Dawid 
1194*c5d03ff4SJennifer Lee         crow::connections::systemBus->async_method_call(
1195*c5d03ff4SJennifer Lee             [asyncResp](const boost::system::error_code ec,
1196*c5d03ff4SJennifer Lee                         const VariantType &biosId) {
1197*c5d03ff4SJennifer Lee                 if (ec)
1198*c5d03ff4SJennifer Lee                 {
1199*c5d03ff4SJennifer Lee                     BMCWEB_LOG_ERROR << ec;
1200*c5d03ff4SJennifer Lee                     messages::internalError(asyncResp->res);
1201*c5d03ff4SJennifer Lee                     return;
1202*c5d03ff4SJennifer Lee                 }
1203*c5d03ff4SJennifer Lee                 const std::string *strBiosId =
1204*c5d03ff4SJennifer Lee                     std::get_if<std::string>(&biosId);
1205*c5d03ff4SJennifer Lee                 if (strBiosId != nullptr)
1206*c5d03ff4SJennifer Lee                 {
1207*c5d03ff4SJennifer Lee                     BMCWEB_LOG_DEBUG << "bios ver. = " << strBiosId;
1208*c5d03ff4SJennifer Lee                     asyncResp->res.jsonValue["BiosVersion"] = *strBiosId;
1209*c5d03ff4SJennifer Lee                 }
1210*c5d03ff4SJennifer Lee             },
1211*c5d03ff4SJennifer Lee             "xyz.openbmc_project.Settings", "/xyz/openbmc_project/bios",
1212*c5d03ff4SJennifer Lee             "org.freedesktop.DBus.Properties", "Get",
1213*c5d03ff4SJennifer Lee             "xyz.openbmc_project.Inventory.Item.Bios", "BiosId");
1214*c5d03ff4SJennifer Lee 
1215*c5d03ff4SJennifer Lee         getMainChassisId(asyncResp, [](const std::string &chassisId,
1216*c5d03ff4SJennifer Lee                                        std::shared_ptr<AsyncResp> aRsp) {
1217*c5d03ff4SJennifer Lee             aRsp->res.jsonValue["Links"]["Chassis"] = {
1218*c5d03ff4SJennifer Lee                 {{"@odata.id", "/redfish/v1/Chassis/" + chassisId}}};
1219*c5d03ff4SJennifer Lee         });
12206c34de48SEd Tanous         getLedGroupIdentify(
1221a0803efaSEd Tanous             asyncResp,
1222*c5d03ff4SJennifer Lee             [](const bool &asserted, const std::shared_ptr<AsyncResp> aRsp) {
12231abe55efSEd Tanous                 if (asserted)
12241abe55efSEd Tanous                 {
1225c5b2abe0SLewanczyk, Dawid                     // If led group is asserted, then another call is needed to
1226c5b2abe0SLewanczyk, Dawid                     // get led status
12276c34de48SEd Tanous                     getLedIdentify(
1228*c5d03ff4SJennifer Lee                         aRsp, [](const std::string &ledStatus,
1229*c5d03ff4SJennifer Lee                                  const std::shared_ptr<AsyncResp> aRsp) {
12301abe55efSEd Tanous                             if (!ledStatus.empty())
12311abe55efSEd Tanous                             {
1232*c5d03ff4SJennifer Lee                                 aRsp->res.jsonValue["IndicatorLED"] = ledStatus;
1233c5b2abe0SLewanczyk, Dawid                             }
1234c5b2abe0SLewanczyk, Dawid                         });
12351abe55efSEd Tanous                 }
12361abe55efSEd Tanous                 else
12371abe55efSEd Tanous                 {
1238*c5d03ff4SJennifer Lee                     aRsp->res.jsonValue["IndicatorLED"] = "Off";
1239c5b2abe0SLewanczyk, Dawid                 }
1240c5b2abe0SLewanczyk, Dawid             });
1241029573d4SEd Tanous         getComputerSystem(asyncResp);
12426c34de48SEd Tanous         getHostState(asyncResp);
1243491d8ee7SSantosh Puranik         getBootProperties(asyncResp);
1244c5b2abe0SLewanczyk, Dawid     }
1245c5b2abe0SLewanczyk, Dawid 
124655c7b7a2SEd Tanous     void doPatch(crow::Response &res, const crow::Request &req,
12471abe55efSEd Tanous                  const std::vector<std::string> &params) override
12481abe55efSEd Tanous     {
1249cde19e5fSSantosh Puranik         std::optional<std::string> indicatorLed;
1250491d8ee7SSantosh Puranik         std::optional<nlohmann::json> bootProps;
1251491d8ee7SSantosh Puranik         if (!json_util::readJson(req, res, "IndicatorLED", indicatorLed, "Boot",
1252491d8ee7SSantosh Puranik                                  bootProps))
12536617338dSEd Tanous         {
12546617338dSEd Tanous             return;
12556617338dSEd Tanous         }
1256491d8ee7SSantosh Puranik 
1257029573d4SEd Tanous         auto asyncResp = std::make_shared<AsyncResp>(res);
1258d573bb2aSJennifer Lee         asyncResp->res.result(boost::beast::http::status::no_content);
1259491d8ee7SSantosh Puranik 
1260491d8ee7SSantosh Puranik         if (bootProps)
1261491d8ee7SSantosh Puranik         {
1262491d8ee7SSantosh Puranik             std::optional<std::string> bootSource;
1263491d8ee7SSantosh Puranik             std::optional<std::string> bootEnable;
1264491d8ee7SSantosh Puranik 
1265491d8ee7SSantosh Puranik             if (!json_util::readJson(*bootProps, asyncResp->res,
1266491d8ee7SSantosh Puranik                                      "BootSourceOverrideTarget", bootSource,
1267491d8ee7SSantosh Puranik                                      "BootSourceOverrideEnabled", bootEnable))
1268491d8ee7SSantosh Puranik             {
1269491d8ee7SSantosh Puranik                 return;
1270491d8ee7SSantosh Puranik             }
1271491d8ee7SSantosh Puranik             setBootProperties(asyncResp, std::move(bootSource),
1272491d8ee7SSantosh Puranik                               std::move(bootEnable));
1273491d8ee7SSantosh Puranik         }
12749712f8acSEd Tanous         if (indicatorLed)
12756617338dSEd Tanous         {
12769712f8acSEd Tanous             std::string dbusLedState;
1277d573bb2aSJennifer Lee             if (*indicatorLed == "Lit")
12789712f8acSEd Tanous             {
1279d573bb2aSJennifer Lee                 dbusLedState = "xyz.openbmc_project.Led.Physical.Action.On";
12806617338dSEd Tanous             }
12815c6221acSGunnar Mills             else if (*indicatorLed == "Blinking")
12826617338dSEd Tanous             {
12835c6221acSGunnar Mills                 dbusLedState = "xyz.openbmc_project.Led.Physical.Action.Blink";
12846617338dSEd Tanous             }
12859712f8acSEd Tanous             else if (*indicatorLed == "Off")
12866617338dSEd Tanous             {
12879712f8acSEd Tanous                 dbusLedState = "xyz.openbmc_project.Led.Physical.Action.Off";
12886617338dSEd Tanous             }
12896617338dSEd Tanous             else
12906617338dSEd Tanous             {
1291a08b46ccSJason M. Bills                 messages::propertyValueNotInList(res, *indicatorLed,
1292a08b46ccSJason M. Bills                                                  "IndicatorLED");
12936617338dSEd Tanous                 return;
12946617338dSEd Tanous             }
12956617338dSEd Tanous 
1296c5b2abe0SLewanczyk, Dawid             // Update led group
129755c7b7a2SEd Tanous             BMCWEB_LOG_DEBUG << "Update led group.";
129855c7b7a2SEd Tanous             crow::connections::systemBus->async_method_call(
1299cde19e5fSSantosh Puranik                 [asyncResp](const boost::system::error_code ec) {
13001abe55efSEd Tanous                     if (ec)
13011abe55efSEd Tanous                     {
130255c7b7a2SEd Tanous                         BMCWEB_LOG_DEBUG << "DBUS response error " << ec;
1303f12894f8SJason M. Bills                         messages::internalError(asyncResp->res);
1304c5b2abe0SLewanczyk, Dawid                         return;
1305c5b2abe0SLewanczyk, Dawid                     }
130655c7b7a2SEd Tanous                     BMCWEB_LOG_DEBUG << "Led group update done.";
1307c5b2abe0SLewanczyk, Dawid                 },
1308c5b2abe0SLewanczyk, Dawid                 "xyz.openbmc_project.LED.GroupManager",
1309c5b2abe0SLewanczyk, Dawid                 "/xyz/openbmc_project/led/groups/enclosure_identify",
1310c5b2abe0SLewanczyk, Dawid                 "org.freedesktop.DBus.Properties", "Set",
1311c5b2abe0SLewanczyk, Dawid                 "xyz.openbmc_project.Led.Group", "Asserted",
1312abf2add6SEd Tanous                 std::variant<bool>(
13136617338dSEd Tanous                     (dbusLedState ==
13146617338dSEd Tanous                              "xyz.openbmc_project.Led.Physical.Action.Off"
13156617338dSEd Tanous                          ? false
13166617338dSEd Tanous                          : true)));
1317c5b2abe0SLewanczyk, Dawid             // Update identify led status
131855c7b7a2SEd Tanous             BMCWEB_LOG_DEBUG << "Update led SoftwareInventoryCollection.";
131955c7b7a2SEd Tanous             crow::connections::systemBus->async_method_call(
13206617338dSEd Tanous                 [asyncResp{std::move(asyncResp)},
13219712f8acSEd Tanous                  indicatorLed{std::move(*indicatorLed)}](
1322c5b2abe0SLewanczyk, Dawid                     const boost::system::error_code ec) {
13231abe55efSEd Tanous                     if (ec)
13241abe55efSEd Tanous                     {
132555c7b7a2SEd Tanous                         BMCWEB_LOG_DEBUG << "DBUS response error " << ec;
1326f12894f8SJason M. Bills                         messages::internalError(asyncResp->res);
1327c5b2abe0SLewanczyk, Dawid                         return;
1328c5b2abe0SLewanczyk, Dawid                     }
132955c7b7a2SEd Tanous                     BMCWEB_LOG_DEBUG << "Led state update done.";
1330c5b2abe0SLewanczyk, Dawid                 },
1331c5b2abe0SLewanczyk, Dawid                 "xyz.openbmc_project.LED.Controller.identify",
1332c5b2abe0SLewanczyk, Dawid                 "/xyz/openbmc_project/led/physical/identify",
1333c5b2abe0SLewanczyk, Dawid                 "org.freedesktop.DBus.Properties", "Set",
1334c5b2abe0SLewanczyk, Dawid                 "xyz.openbmc_project.Led.Physical", "State",
1335abf2add6SEd Tanous                 std::variant<std::string>(dbusLedState));
13366617338dSEd Tanous         }
1337c5b2abe0SLewanczyk, Dawid     }
1338c5b2abe0SLewanczyk, Dawid };
1339c5b2abe0SLewanczyk, Dawid } // namespace redfish
1340