xref: /openbmc/bmcweb/features/redfish/lib/systems.hpp (revision b49ac87376278d6085c1d10815672c321a484f35)
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*b49ac873SJames Feist #include "health.hpp"
19c5d03ff4SJennifer Lee #include "redfish_util.hpp"
20c5d03ff4SJennifer Lee 
219712f8acSEd Tanous #include <boost/container/flat_map.hpp>
229712f8acSEd Tanous #include <node.hpp>
23cb7e1e7bSAndrew Geissler #include <utils/fw_utils.hpp>
24c5b2abe0SLewanczyk, Dawid #include <utils/json_utils.hpp>
25abf2add6SEd Tanous #include <variant>
26c5b2abe0SLewanczyk, Dawid 
271abe55efSEd Tanous namespace redfish
281abe55efSEd Tanous {
29c5b2abe0SLewanczyk, Dawid 
30c5b2abe0SLewanczyk, Dawid /**
31c5b2abe0SLewanczyk, Dawid  * @brief Retrieves computer system properties over dbus
32c5b2abe0SLewanczyk, Dawid  *
33c5b2abe0SLewanczyk, Dawid  * @param[in] aResp Shared pointer for completing asynchronous calls
34c5b2abe0SLewanczyk, Dawid  * @param[in] name  Computer system name from request
35c5b2abe0SLewanczyk, Dawid  *
36c5b2abe0SLewanczyk, Dawid  * @return None.
37c5b2abe0SLewanczyk, Dawid  */
38029573d4SEd Tanous void getComputerSystem(std::shared_ptr<AsyncResp> aResp)
391abe55efSEd Tanous {
4055c7b7a2SEd Tanous     BMCWEB_LOG_DEBUG << "Get available system components.";
4155c7b7a2SEd Tanous     crow::connections::systemBus->async_method_call(
42c5d03ff4SJennifer Lee         [aResp](
43c5b2abe0SLewanczyk, Dawid             const boost::system::error_code ec,
44c5b2abe0SLewanczyk, Dawid             const std::vector<std::pair<
456c34de48SEd Tanous                 std::string,
466c34de48SEd Tanous                 std::vector<std::pair<std::string, std::vector<std::string>>>>>
47c5b2abe0SLewanczyk, Dawid                 &subtree) {
481abe55efSEd Tanous             if (ec)
491abe55efSEd Tanous             {
5055c7b7a2SEd Tanous                 BMCWEB_LOG_DEBUG << "DBUS response error";
51f12894f8SJason M. Bills                 messages::internalError(aResp->res);
52c5b2abe0SLewanczyk, Dawid                 return;
53c5b2abe0SLewanczyk, Dawid             }
54c5b2abe0SLewanczyk, Dawid             // Iterate over all retrieved ObjectPaths.
556c34de48SEd Tanous             for (const std::pair<std::string,
566c34de48SEd Tanous                                  std::vector<std::pair<
576c34de48SEd Tanous                                      std::string, std::vector<std::string>>>>
581abe55efSEd Tanous                      &object : subtree)
591abe55efSEd Tanous             {
60c5b2abe0SLewanczyk, Dawid                 const std::string &path = object.first;
6155c7b7a2SEd Tanous                 BMCWEB_LOG_DEBUG << "Got path: " << path;
621abe55efSEd Tanous                 const std::vector<
631abe55efSEd Tanous                     std::pair<std::string, std::vector<std::string>>>
64c5b2abe0SLewanczyk, Dawid                     &connectionNames = object.second;
651abe55efSEd Tanous                 if (connectionNames.size() < 1)
661abe55efSEd Tanous                 {
67c5b2abe0SLewanczyk, Dawid                     continue;
68c5b2abe0SLewanczyk, Dawid                 }
69029573d4SEd Tanous 
706c34de48SEd Tanous                 // This is not system, so check if it's cpu, dimm, UUID or
716c34de48SEd Tanous                 // BiosVer
7204a258f4SEd Tanous                 for (const auto &connection : connectionNames)
731abe55efSEd Tanous                 {
7404a258f4SEd Tanous                     for (const auto &interfaceName : connection.second)
751abe55efSEd Tanous                     {
7604a258f4SEd Tanous                         if (interfaceName ==
7704a258f4SEd Tanous                             "xyz.openbmc_project.Inventory.Item.Dimm")
781abe55efSEd Tanous                         {
791abe55efSEd Tanous                             BMCWEB_LOG_DEBUG
8004a258f4SEd Tanous                                 << "Found Dimm, now get its properties.";
8155c7b7a2SEd Tanous                             crow::connections::systemBus->async_method_call(
82029573d4SEd Tanous                                 [aResp](const boost::system::error_code ec,
836c34de48SEd Tanous                                         const std::vector<
846c34de48SEd Tanous                                             std::pair<std::string, VariantType>>
851abe55efSEd Tanous                                             &properties) {
861abe55efSEd Tanous                                     if (ec)
871abe55efSEd Tanous                                     {
881abe55efSEd Tanous                                         BMCWEB_LOG_ERROR
896c34de48SEd Tanous                                             << "DBUS response error " << ec;
90f12894f8SJason M. Bills                                         messages::internalError(aResp->res);
91c5b2abe0SLewanczyk, Dawid                                         return;
92c5b2abe0SLewanczyk, Dawid                                     }
936c34de48SEd Tanous                                     BMCWEB_LOG_DEBUG << "Got "
946c34de48SEd Tanous                                                      << properties.size()
95c5b2abe0SLewanczyk, Dawid                                                      << "Dimm properties.";
9604a258f4SEd Tanous                                     for (const std::pair<std::string,
9704a258f4SEd Tanous                                                          VariantType>
9804a258f4SEd Tanous                                              &property : properties)
991abe55efSEd Tanous                                     {
100029573d4SEd Tanous                                         if (property.first == "MemorySizeInKb")
1011abe55efSEd Tanous                                         {
10204a258f4SEd Tanous                                             const uint64_t *value =
103029573d4SEd Tanous                                                 sdbusplus::message::variant_ns::
104029573d4SEd Tanous                                                     get_if<uint64_t>(
1051b6b96c5SEd Tanous                                                         &property.second);
10604a258f4SEd Tanous                                             if (value != nullptr)
1071abe55efSEd Tanous                                             {
1081abe55efSEd Tanous                                                 aResp->res.jsonValue
1096c34de48SEd Tanous                                                     ["TotalSystemMemoryGi"
1106c34de48SEd Tanous                                                      "B"] +=
11104a258f4SEd Tanous                                                     *value / (1024 * 1024);
112029573d4SEd Tanous                                                 aResp->res
113029573d4SEd Tanous                                                     .jsonValue["MemorySummary"]
114029573d4SEd Tanous                                                               ["Status"]
115029573d4SEd Tanous                                                               ["State"] =
1161abe55efSEd Tanous                                                     "Enabled";
117c5b2abe0SLewanczyk, Dawid                                             }
118c5b2abe0SLewanczyk, Dawid                                         }
119c5b2abe0SLewanczyk, Dawid                                     }
120c5b2abe0SLewanczyk, Dawid                                 },
12104a258f4SEd Tanous                                 connection.first, path,
1226c34de48SEd Tanous                                 "org.freedesktop.DBus.Properties", "GetAll",
1236c34de48SEd Tanous                                 "xyz.openbmc_project.Inventory.Item.Dimm");
1241abe55efSEd Tanous                         }
12504a258f4SEd Tanous                         else if (interfaceName ==
12604a258f4SEd Tanous                                  "xyz.openbmc_project.Inventory.Item.Cpu")
1271abe55efSEd Tanous                         {
1281abe55efSEd Tanous                             BMCWEB_LOG_DEBUG
12904a258f4SEd Tanous                                 << "Found Cpu, now get its properties.";
130a0803efaSEd Tanous                             crow::connections::systemBus->async_method_call(
131029573d4SEd Tanous                                 [aResp](const boost::system::error_code ec,
1326c34de48SEd Tanous                                         const std::vector<
1336c34de48SEd Tanous                                             std::pair<std::string, VariantType>>
1341abe55efSEd Tanous                                             &properties) {
1351abe55efSEd Tanous                                     if (ec)
1361abe55efSEd Tanous                                     {
1371abe55efSEd Tanous                                         BMCWEB_LOG_ERROR
1386c34de48SEd Tanous                                             << "DBUS response error " << ec;
139f12894f8SJason M. Bills                                         messages::internalError(aResp->res);
140c5b2abe0SLewanczyk, Dawid                                         return;
141c5b2abe0SLewanczyk, Dawid                                     }
1426c34de48SEd Tanous                                     BMCWEB_LOG_DEBUG << "Got "
1436c34de48SEd Tanous                                                      << properties.size()
144c5b2abe0SLewanczyk, Dawid                                                      << "Cpu properties.";
14504a258f4SEd Tanous                                     for (const auto &property : properties)
1461abe55efSEd Tanous                                     {
147029573d4SEd Tanous                                         if (property.first == "ProcessorFamily")
1481abe55efSEd Tanous                                         {
149a0803efaSEd Tanous                                             const std::string *value =
150029573d4SEd Tanous                                                 sdbusplus::message::variant_ns::
151029573d4SEd Tanous                                                     get_if<std::string>(
1521b6b96c5SEd Tanous                                                         &property.second);
1531abe55efSEd Tanous                                             if (value != nullptr)
1541abe55efSEd Tanous                                             {
155029573d4SEd Tanous                                                 nlohmann::json &procSummary =
1561abe55efSEd Tanous                                                     aResp->res.jsonValue
1576c34de48SEd Tanous                                                         ["ProcessorSumm"
15804a258f4SEd Tanous                                                          "ary"];
15904a258f4SEd Tanous                                                 nlohmann::json &procCount =
16004a258f4SEd Tanous                                                     procSummary["Count"];
16104a258f4SEd Tanous 
16204a258f4SEd Tanous                                                 procCount =
163029573d4SEd Tanous                                                     procCount.get<int>() + 1;
164029573d4SEd Tanous                                                 procSummary["Status"]["State"] =
165c5b2abe0SLewanczyk, Dawid                                                     "Enabled";
166029573d4SEd Tanous                                                 procSummary["Model"] = *value;
167c5b2abe0SLewanczyk, Dawid                                             }
168c5b2abe0SLewanczyk, Dawid                                         }
169c5b2abe0SLewanczyk, Dawid                                     }
170c5b2abe0SLewanczyk, Dawid                                 },
17104a258f4SEd Tanous                                 connection.first, path,
1726c34de48SEd Tanous                                 "org.freedesktop.DBus.Properties", "GetAll",
1736c34de48SEd Tanous                                 "xyz.openbmc_project.Inventory.Item.Cpu");
1741abe55efSEd Tanous                         }
17504a258f4SEd Tanous                         else if (interfaceName ==
17604a258f4SEd Tanous                                  "xyz.openbmc_project.Common.UUID")
1771abe55efSEd Tanous                         {
1781abe55efSEd Tanous                             BMCWEB_LOG_DEBUG
17904a258f4SEd Tanous                                 << "Found UUID, now get its properties.";
18055c7b7a2SEd Tanous                             crow::connections::systemBus->async_method_call(
181029573d4SEd Tanous                                 [aResp](const boost::system::error_code ec,
1826c34de48SEd Tanous                                         const std::vector<
1836c34de48SEd Tanous                                             std::pair<std::string, VariantType>>
1841abe55efSEd Tanous                                             &properties) {
1851abe55efSEd Tanous                                     if (ec)
1861abe55efSEd Tanous                                     {
1871abe55efSEd Tanous                                         BMCWEB_LOG_DEBUG
1886c34de48SEd Tanous                                             << "DBUS response error " << ec;
189f12894f8SJason M. Bills                                         messages::internalError(aResp->res);
190c5b2abe0SLewanczyk, Dawid                                         return;
191c5b2abe0SLewanczyk, Dawid                                     }
1926c34de48SEd Tanous                                     BMCWEB_LOG_DEBUG << "Got "
1936c34de48SEd Tanous                                                      << properties.size()
194c5b2abe0SLewanczyk, Dawid                                                      << "UUID properties.";
1951abe55efSEd Tanous                                     for (const std::pair<std::string,
19604a258f4SEd Tanous                                                          VariantType>
19704a258f4SEd Tanous                                              &property : properties)
1981abe55efSEd Tanous                                     {
19904a258f4SEd Tanous                                         if (property.first == "UUID")
2001abe55efSEd Tanous                                         {
201c5b2abe0SLewanczyk, Dawid                                             const std::string *value =
202029573d4SEd Tanous                                                 sdbusplus::message::variant_ns::
203029573d4SEd Tanous                                                     get_if<std::string>(
2041b6b96c5SEd Tanous                                                         &property.second);
20504a258f4SEd Tanous 
2061abe55efSEd Tanous                                             if (value != nullptr)
2071abe55efSEd Tanous                                             {
208029573d4SEd Tanous                                                 std::string valueStr = *value;
20904a258f4SEd Tanous                                                 if (valueStr.size() == 32)
2101abe55efSEd Tanous                                                 {
211029573d4SEd Tanous                                                     valueStr.insert(8, 1, '-');
212029573d4SEd Tanous                                                     valueStr.insert(13, 1, '-');
213029573d4SEd Tanous                                                     valueStr.insert(18, 1, '-');
214029573d4SEd Tanous                                                     valueStr.insert(23, 1, '-');
21504a258f4SEd Tanous                                                 }
216029573d4SEd Tanous                                                 BMCWEB_LOG_DEBUG << "UUID = "
21704a258f4SEd Tanous                                                                  << valueStr;
218029573d4SEd Tanous                                                 aResp->res.jsonValue["UUID"] =
21904a258f4SEd Tanous                                                     valueStr;
220c5b2abe0SLewanczyk, Dawid                                             }
221c5b2abe0SLewanczyk, Dawid                                         }
222c5b2abe0SLewanczyk, Dawid                                     }
223c5b2abe0SLewanczyk, Dawid                                 },
22404a258f4SEd Tanous                                 connection.first, path,
2256c34de48SEd Tanous                                 "org.freedesktop.DBus.Properties", "GetAll",
2261abe55efSEd Tanous                                 "xyz.openbmc_project.Common.UUID");
227c5b2abe0SLewanczyk, Dawid                         }
228029573d4SEd Tanous                         else if (interfaceName ==
229029573d4SEd Tanous                                  "xyz.openbmc_project.Inventory.Item.System")
2301abe55efSEd Tanous                         {
231029573d4SEd Tanous                             crow::connections::systemBus->async_method_call(
232029573d4SEd Tanous                                 [aResp](const boost::system::error_code ec,
233029573d4SEd Tanous                                         const std::vector<
234029573d4SEd Tanous                                             std::pair<std::string, VariantType>>
235029573d4SEd Tanous                                             &propertiesList) {
236029573d4SEd Tanous                                     if (ec)
237029573d4SEd Tanous                                     {
238e4a4b9a9SJames Feist                                         // doesn't have to include this
239e4a4b9a9SJames Feist                                         // interface
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");
279e4a4b9a9SJames Feist 
280e4a4b9a9SJames Feist                             crow::connections::systemBus->async_method_call(
281e4a4b9a9SJames Feist                                 [aResp](
282e4a4b9a9SJames Feist                                     const boost::system::error_code ec,
283e4a4b9a9SJames Feist                                     const std::variant<std::string> &property) {
284e4a4b9a9SJames Feist                                     if (ec)
285e4a4b9a9SJames Feist                                     {
286e4a4b9a9SJames Feist                                         // doesn't have to include this
287e4a4b9a9SJames Feist                                         // interface
288e4a4b9a9SJames Feist                                         return;
289e4a4b9a9SJames Feist                                     }
290e4a4b9a9SJames Feist 
291e4a4b9a9SJames Feist                                     const std::string *value =
292e4a4b9a9SJames Feist                                         std::get_if<std::string>(&property);
293e4a4b9a9SJames Feist                                     if (value != nullptr)
294e4a4b9a9SJames Feist                                     {
295e4a4b9a9SJames Feist                                         aResp->res.jsonValue["AssetTag"] =
296e4a4b9a9SJames Feist                                             *value;
297e4a4b9a9SJames Feist                                     }
298e4a4b9a9SJames Feist                                 },
299e4a4b9a9SJames Feist                                 connection.first, path,
300e4a4b9a9SJames Feist                                 "org.freedesktop.DBus.Properties", "Get",
301e4a4b9a9SJames Feist                                 "xyz.openbmc_project.Inventory.Decorator."
302e4a4b9a9SJames Feist                                 "AssetTag",
303e4a4b9a9SJames Feist                                 "AssetTag");
304029573d4SEd Tanous                         }
305029573d4SEd Tanous                     }
306029573d4SEd Tanous                 }
307c5b2abe0SLewanczyk, Dawid             }
308c5b2abe0SLewanczyk, Dawid         },
309c5b2abe0SLewanczyk, Dawid         "xyz.openbmc_project.ObjectMapper",
310c5b2abe0SLewanczyk, Dawid         "/xyz/openbmc_project/object_mapper",
311c5b2abe0SLewanczyk, Dawid         "xyz.openbmc_project.ObjectMapper", "GetSubTree",
3126617338dSEd Tanous         "/xyz/openbmc_project/inventory", int32_t(0),
3136617338dSEd Tanous         std::array<const char *, 5>{
3146617338dSEd Tanous             "xyz.openbmc_project.Inventory.Decorator.Asset",
3156617338dSEd Tanous             "xyz.openbmc_project.Inventory.Item.Cpu",
3166617338dSEd Tanous             "xyz.openbmc_project.Inventory.Item.Dimm",
3176617338dSEd Tanous             "xyz.openbmc_project.Inventory.Item.System",
3186617338dSEd Tanous             "xyz.openbmc_project.Common.UUID",
3196617338dSEd Tanous         });
320c5b2abe0SLewanczyk, Dawid }
321c5b2abe0SLewanczyk, Dawid 
322c5b2abe0SLewanczyk, Dawid /**
323c5b2abe0SLewanczyk, Dawid  * @brief Retrieves identify led group properties over dbus
324c5b2abe0SLewanczyk, Dawid  *
325491d8ee7SSantosh Puranik  * @param[in] aResp     Shared pointer for generating response message.
326c5b2abe0SLewanczyk, Dawid  * @param[in] callback  Callback for process retrieved data.
327c5b2abe0SLewanczyk, Dawid  *
328c5b2abe0SLewanczyk, Dawid  * @return None.
329c5b2abe0SLewanczyk, Dawid  */
330c5b2abe0SLewanczyk, Dawid template <typename CallbackFunc>
331a0803efaSEd Tanous void getLedGroupIdentify(std::shared_ptr<AsyncResp> aResp,
3321abe55efSEd Tanous                          CallbackFunc &&callback)
3331abe55efSEd Tanous {
33455c7b7a2SEd Tanous     BMCWEB_LOG_DEBUG << "Get led groups";
33555c7b7a2SEd Tanous     crow::connections::systemBus->async_method_call(
336c5d03ff4SJennifer Lee         [aResp,
3376617338dSEd Tanous          callback{std::move(callback)}](const boost::system::error_code &ec,
3381abe55efSEd Tanous                                         const ManagedObjectsType &resp) {
3391abe55efSEd Tanous             if (ec)
3401abe55efSEd Tanous             {
34155c7b7a2SEd Tanous                 BMCWEB_LOG_DEBUG << "DBUS response error " << ec;
342f12894f8SJason M. Bills                 messages::internalError(aResp->res);
343c5b2abe0SLewanczyk, Dawid                 return;
344c5b2abe0SLewanczyk, Dawid             }
3456c34de48SEd Tanous             BMCWEB_LOG_DEBUG << "Got " << resp.size() << "led group objects.";
3461abe55efSEd Tanous             for (const auto &objPath : resp)
3471abe55efSEd Tanous             {
348c5b2abe0SLewanczyk, Dawid                 const std::string &path = objPath.first;
3491abe55efSEd Tanous                 if (path.rfind("enclosure_identify") != std::string::npos)
3501abe55efSEd Tanous                 {
3511abe55efSEd Tanous                     for (const auto &interface : objPath.second)
3521abe55efSEd Tanous                     {
3536c34de48SEd Tanous                         if (interface.first == "xyz.openbmc_project.Led.Group")
3541abe55efSEd Tanous                         {
3551abe55efSEd Tanous                             for (const auto &property : interface.second)
3561abe55efSEd Tanous                             {
3571abe55efSEd Tanous                                 if (property.first == "Asserted")
3581abe55efSEd Tanous                                 {
359c5b2abe0SLewanczyk, Dawid                                     const bool *asserted =
360abf2add6SEd Tanous                                         std::get_if<bool>(&property.second);
3611abe55efSEd Tanous                                     if (nullptr != asserted)
3621abe55efSEd Tanous                                     {
363c5b2abe0SLewanczyk, Dawid                                         callback(*asserted, aResp);
3641abe55efSEd Tanous                                     }
3651abe55efSEd Tanous                                     else
3661abe55efSEd Tanous                                     {
367c5b2abe0SLewanczyk, Dawid                                         callback(false, aResp);
368c5b2abe0SLewanczyk, Dawid                                     }
369c5b2abe0SLewanczyk, Dawid                                 }
370c5b2abe0SLewanczyk, Dawid                             }
371c5b2abe0SLewanczyk, Dawid                         }
372c5b2abe0SLewanczyk, Dawid                     }
373c5b2abe0SLewanczyk, Dawid                 }
374c5b2abe0SLewanczyk, Dawid             }
375c5b2abe0SLewanczyk, Dawid         },
376c5b2abe0SLewanczyk, Dawid         "xyz.openbmc_project.LED.GroupManager",
3776c34de48SEd Tanous         "/xyz/openbmc_project/led/groups", "org.freedesktop.DBus.ObjectManager",
3786c34de48SEd Tanous         "GetManagedObjects");
379c5b2abe0SLewanczyk, Dawid }
380c5b2abe0SLewanczyk, Dawid 
381c5b2abe0SLewanczyk, Dawid template <typename CallbackFunc>
3826c34de48SEd Tanous void getLedIdentify(std::shared_ptr<AsyncResp> aResp, CallbackFunc &&callback)
3831abe55efSEd Tanous {
38455c7b7a2SEd Tanous     BMCWEB_LOG_DEBUG << "Get identify led properties";
38555c7b7a2SEd Tanous     crow::connections::systemBus->async_method_call(
3866617338dSEd Tanous         [aResp,
3876617338dSEd Tanous          callback{std::move(callback)}](const boost::system::error_code ec,
388c5b2abe0SLewanczyk, Dawid                                         const PropertiesType &properties) {
3891abe55efSEd Tanous             if (ec)
3901abe55efSEd Tanous             {
39155c7b7a2SEd Tanous                 BMCWEB_LOG_DEBUG << "DBUS response error " << ec;
392f12894f8SJason M. Bills                 messages::internalError(aResp->res);
393c5b2abe0SLewanczyk, Dawid                 return;
394c5b2abe0SLewanczyk, Dawid             }
3951abe55efSEd Tanous             BMCWEB_LOG_DEBUG << "Got " << properties.size()
3961abe55efSEd Tanous                              << "led properties.";
397c5b2abe0SLewanczyk, Dawid             std::string output;
3981abe55efSEd Tanous             for (const auto &property : properties)
3991abe55efSEd Tanous             {
4001abe55efSEd Tanous                 if (property.first == "State")
4011abe55efSEd Tanous                 {
402c5b2abe0SLewanczyk, Dawid                     const std::string *s =
403abf2add6SEd Tanous                         std::get_if<std::string>(&property.second);
4041abe55efSEd Tanous                     if (nullptr != s)
4051abe55efSEd Tanous                     {
40655c7b7a2SEd Tanous                         BMCWEB_LOG_DEBUG << "Identify Led State: " << *s;
407c5b2abe0SLewanczyk, Dawid                         const auto pos = s->rfind('.');
4081abe55efSEd Tanous                         if (pos != std::string::npos)
4091abe55efSEd Tanous                         {
410c5b2abe0SLewanczyk, Dawid                             auto led = s->substr(pos + 1);
4111abe55efSEd Tanous                             for (const std::pair<const char *, const char *>
4121abe55efSEd Tanous                                      &p :
4131abe55efSEd Tanous                                  std::array<
4146c34de48SEd Tanous                                      std::pair<const char *, const char *>, 3>{
4156c34de48SEd Tanous                                      {{"On", "Lit"},
416c5b2abe0SLewanczyk, Dawid                                       {"Blink", "Blinking"},
4171abe55efSEd Tanous                                       {"Off", "Off"}}})
4181abe55efSEd Tanous                             {
4191abe55efSEd Tanous                                 if (led == p.first)
4201abe55efSEd Tanous                                 {
421c5b2abe0SLewanczyk, Dawid                                     output = p.second;
422c5b2abe0SLewanczyk, Dawid                                 }
423c5b2abe0SLewanczyk, Dawid                             }
424c5b2abe0SLewanczyk, Dawid                         }
425c5b2abe0SLewanczyk, Dawid                     }
426c5b2abe0SLewanczyk, Dawid                 }
427c5b2abe0SLewanczyk, Dawid             }
428c5b2abe0SLewanczyk, Dawid             callback(output, aResp);
429c5b2abe0SLewanczyk, Dawid         },
430c5b2abe0SLewanczyk, Dawid         "xyz.openbmc_project.LED.Controller.identify",
431c5b2abe0SLewanczyk, Dawid         "/xyz/openbmc_project/led/physical/identify",
432c5b2abe0SLewanczyk, Dawid         "org.freedesktop.DBus.Properties", "GetAll",
433c5b2abe0SLewanczyk, Dawid         "xyz.openbmc_project.Led.Physical");
434c5b2abe0SLewanczyk, Dawid }
435c5b2abe0SLewanczyk, Dawid /**
436c5b2abe0SLewanczyk, Dawid  * @brief Retrieves host state properties over dbus
437c5b2abe0SLewanczyk, Dawid  *
438c5b2abe0SLewanczyk, Dawid  * @param[in] aResp     Shared pointer for completing asynchronous calls.
439c5b2abe0SLewanczyk, Dawid  *
440c5b2abe0SLewanczyk, Dawid  * @return None.
441c5b2abe0SLewanczyk, Dawid  */
442a0803efaSEd Tanous void getHostState(std::shared_ptr<AsyncResp> aResp)
4431abe55efSEd Tanous {
44455c7b7a2SEd Tanous     BMCWEB_LOG_DEBUG << "Get host information.";
44555c7b7a2SEd Tanous     crow::connections::systemBus->async_method_call(
446c5d03ff4SJennifer Lee         [aResp](const boost::system::error_code ec,
447abf2add6SEd Tanous                 const std::variant<std::string> &hostState) {
4481abe55efSEd Tanous             if (ec)
4491abe55efSEd Tanous             {
45055c7b7a2SEd Tanous                 BMCWEB_LOG_DEBUG << "DBUS response error " << ec;
451f12894f8SJason M. Bills                 messages::internalError(aResp->res);
452c5b2abe0SLewanczyk, Dawid                 return;
453c5b2abe0SLewanczyk, Dawid             }
4546617338dSEd Tanous 
455abf2add6SEd Tanous             const std::string *s = std::get_if<std::string>(&hostState);
45655c7b7a2SEd Tanous             BMCWEB_LOG_DEBUG << "Host state: " << *s;
4576617338dSEd Tanous             if (s != nullptr)
4581abe55efSEd Tanous             {
459c5b2abe0SLewanczyk, Dawid                 // Verify Host State
46094732661SAndrew Geissler                 if (*s == "xyz.openbmc_project.State.Host.HostState.Running")
4611abe55efSEd Tanous                 {
46255c7b7a2SEd Tanous                     aResp->res.jsonValue["PowerState"] = "On";
4636617338dSEd Tanous                     aResp->res.jsonValue["Status"]["State"] = "Enabled";
4641abe55efSEd Tanous                 }
4651abe55efSEd Tanous                 else
4661abe55efSEd Tanous                 {
46755c7b7a2SEd Tanous                     aResp->res.jsonValue["PowerState"] = "Off";
4686617338dSEd Tanous                     aResp->res.jsonValue["Status"]["State"] = "Disabled";
469c5b2abe0SLewanczyk, Dawid                 }
470c5b2abe0SLewanczyk, Dawid             }
471c5b2abe0SLewanczyk, Dawid         },
4726c34de48SEd Tanous         "xyz.openbmc_project.State.Host", "/xyz/openbmc_project/state/host0",
4736617338dSEd Tanous         "org.freedesktop.DBus.Properties", "Get",
4746617338dSEd Tanous         "xyz.openbmc_project.State.Host", "CurrentHostState");
475c5b2abe0SLewanczyk, Dawid }
476c5b2abe0SLewanczyk, Dawid 
477c5b2abe0SLewanczyk, Dawid /**
478491d8ee7SSantosh Puranik  * @brief Traslates boot source DBUS property value to redfish.
479491d8ee7SSantosh Puranik  *
480491d8ee7SSantosh Puranik  * @param[in] dbusSource    The boot source in DBUS speak.
481491d8ee7SSantosh Puranik  *
482491d8ee7SSantosh Puranik  * @return Returns as a string, the boot source in Redfish terms. If translation
483491d8ee7SSantosh Puranik  * cannot be done, returns an empty string.
484491d8ee7SSantosh Puranik  */
485491d8ee7SSantosh Puranik static std::string dbusToRfBootSource(const std::string &dbusSource)
486491d8ee7SSantosh Puranik {
487491d8ee7SSantosh Puranik     if (dbusSource == "xyz.openbmc_project.Control.Boot.Source.Sources.Default")
488491d8ee7SSantosh Puranik     {
489491d8ee7SSantosh Puranik         return "None";
490491d8ee7SSantosh Puranik     }
491491d8ee7SSantosh Puranik     else if (dbusSource ==
492491d8ee7SSantosh Puranik              "xyz.openbmc_project.Control.Boot.Source.Sources.Disk")
493491d8ee7SSantosh Puranik     {
494491d8ee7SSantosh Puranik         return "Hdd";
495491d8ee7SSantosh Puranik     }
496491d8ee7SSantosh Puranik     else if (dbusSource ==
497a71dc0b7SSantosh Puranik              "xyz.openbmc_project.Control.Boot.Source.Sources.ExternalMedia")
498491d8ee7SSantosh Puranik     {
499491d8ee7SSantosh Puranik         return "Cd";
500491d8ee7SSantosh Puranik     }
501491d8ee7SSantosh Puranik     else if (dbusSource ==
502491d8ee7SSantosh Puranik              "xyz.openbmc_project.Control.Boot.Source.Sources.Network")
503491d8ee7SSantosh Puranik     {
504491d8ee7SSantosh Puranik         return "Pxe";
505491d8ee7SSantosh Puranik     }
5069f16b2c1SJennifer Lee     else if (dbusSource ==
5079f16b2c1SJennifer Lee              "xyz.openbmc_project.Control.Boot.Source.Sources.Removable")
5089f16b2c1SJennifer Lee     {
5099f16b2c1SJennifer Lee         return "Usb";
5109f16b2c1SJennifer Lee     }
511491d8ee7SSantosh Puranik     else
512491d8ee7SSantosh Puranik     {
513491d8ee7SSantosh Puranik         return "";
514491d8ee7SSantosh Puranik     }
515491d8ee7SSantosh Puranik }
516491d8ee7SSantosh Puranik 
517491d8ee7SSantosh Puranik /**
518491d8ee7SSantosh Puranik  * @brief Traslates boot mode DBUS property value to redfish.
519491d8ee7SSantosh Puranik  *
520491d8ee7SSantosh Puranik  * @param[in] dbusMode    The boot mode in DBUS speak.
521491d8ee7SSantosh Puranik  *
522491d8ee7SSantosh Puranik  * @return Returns as a string, the boot mode in Redfish terms. If translation
523491d8ee7SSantosh Puranik  * cannot be done, returns an empty string.
524491d8ee7SSantosh Puranik  */
525491d8ee7SSantosh Puranik static std::string dbusToRfBootMode(const std::string &dbusMode)
526491d8ee7SSantosh Puranik {
527491d8ee7SSantosh Puranik     if (dbusMode == "xyz.openbmc_project.Control.Boot.Mode.Modes.Regular")
528491d8ee7SSantosh Puranik     {
529491d8ee7SSantosh Puranik         return "None";
530491d8ee7SSantosh Puranik     }
531491d8ee7SSantosh Puranik     else if (dbusMode == "xyz.openbmc_project.Control.Boot.Mode.Modes.Safe")
532491d8ee7SSantosh Puranik     {
533491d8ee7SSantosh Puranik         return "Diags";
534491d8ee7SSantosh Puranik     }
535491d8ee7SSantosh Puranik     else if (dbusMode == "xyz.openbmc_project.Control.Boot.Mode.Modes.Setup")
536491d8ee7SSantosh Puranik     {
537491d8ee7SSantosh Puranik         return "BiosSetup";
538491d8ee7SSantosh Puranik     }
539491d8ee7SSantosh Puranik     else
540491d8ee7SSantosh Puranik     {
541491d8ee7SSantosh Puranik         return "";
542491d8ee7SSantosh Puranik     }
543491d8ee7SSantosh Puranik }
544491d8ee7SSantosh Puranik 
545491d8ee7SSantosh Puranik /**
546491d8ee7SSantosh Puranik  * @brief Traslates boot source from Redfish to DBUS property value.
547491d8ee7SSantosh Puranik  *
548491d8ee7SSantosh Puranik  * @param[in] rfSource    The boot source in Redfish.
549491d8ee7SSantosh Puranik  *
550491d8ee7SSantosh Puranik  * @return Returns as a string, the boot source as expected by DBUS.
551491d8ee7SSantosh Puranik  * If translation cannot be done, returns an empty string.
552491d8ee7SSantosh Puranik  */
553491d8ee7SSantosh Puranik static std::string rfToDbusBootSource(const std::string &rfSource)
554491d8ee7SSantosh Puranik {
555491d8ee7SSantosh Puranik     if (rfSource == "None")
556491d8ee7SSantosh Puranik     {
557491d8ee7SSantosh Puranik         return "xyz.openbmc_project.Control.Boot.Source.Sources.Default";
558491d8ee7SSantosh Puranik     }
559491d8ee7SSantosh Puranik     else if (rfSource == "Hdd")
560491d8ee7SSantosh Puranik     {
561491d8ee7SSantosh Puranik         return "xyz.openbmc_project.Control.Boot.Source.Sources.Disk";
562491d8ee7SSantosh Puranik     }
563491d8ee7SSantosh Puranik     else if (rfSource == "Cd")
564491d8ee7SSantosh Puranik     {
565a71dc0b7SSantosh Puranik         return "xyz.openbmc_project.Control.Boot.Source.Sources.ExternalMedia";
566491d8ee7SSantosh Puranik     }
567491d8ee7SSantosh Puranik     else if (rfSource == "Pxe")
568491d8ee7SSantosh Puranik     {
569491d8ee7SSantosh Puranik         return "xyz.openbmc_project.Control.Boot.Source.Sources.Network";
570491d8ee7SSantosh Puranik     }
5719f16b2c1SJennifer Lee     else if (rfSource == "Usb")
5729f16b2c1SJennifer Lee     {
5739f16b2c1SJennifer Lee         return "xyz.openbmc_project.Control.Boot.Source.Sources.Removable";
5749f16b2c1SJennifer Lee     }
575491d8ee7SSantosh Puranik     else
576491d8ee7SSantosh Puranik     {
577491d8ee7SSantosh Puranik         return "";
578491d8ee7SSantosh Puranik     }
579491d8ee7SSantosh Puranik }
580491d8ee7SSantosh Puranik 
581491d8ee7SSantosh Puranik /**
582491d8ee7SSantosh Puranik  * @brief Traslates boot mode from Redfish to DBUS property value.
583491d8ee7SSantosh Puranik  *
584491d8ee7SSantosh Puranik  * @param[in] rfMode    The boot mode in Redfish.
585491d8ee7SSantosh Puranik  *
586491d8ee7SSantosh Puranik  * @return Returns as a string, the boot mode as expected by DBUS.
587491d8ee7SSantosh Puranik  * If translation cannot be done, returns an empty string.
588491d8ee7SSantosh Puranik  */
589491d8ee7SSantosh Puranik static std::string rfToDbusBootMode(const std::string &rfMode)
590491d8ee7SSantosh Puranik {
591491d8ee7SSantosh Puranik     if (rfMode == "None")
592491d8ee7SSantosh Puranik     {
593491d8ee7SSantosh Puranik         return "xyz.openbmc_project.Control.Boot.Mode.Modes.Regular";
594491d8ee7SSantosh Puranik     }
595491d8ee7SSantosh Puranik     else if (rfMode == "Diags")
596491d8ee7SSantosh Puranik     {
597491d8ee7SSantosh Puranik         return "xyz.openbmc_project.Control.Boot.Mode.Modes.Safe";
598491d8ee7SSantosh Puranik     }
599491d8ee7SSantosh Puranik     else if (rfMode == "BiosSetup")
600491d8ee7SSantosh Puranik     {
601491d8ee7SSantosh Puranik         return "xyz.openbmc_project.Control.Boot.Mode.Modes.Setup";
602491d8ee7SSantosh Puranik     }
603491d8ee7SSantosh Puranik     else
604491d8ee7SSantosh Puranik     {
605491d8ee7SSantosh Puranik         return "";
606491d8ee7SSantosh Puranik     }
607491d8ee7SSantosh Puranik }
608491d8ee7SSantosh Puranik 
609491d8ee7SSantosh Puranik /**
610491d8ee7SSantosh Puranik  * @brief Retrieves boot mode over DBUS and fills out the response
611491d8ee7SSantosh Puranik  *
612491d8ee7SSantosh Puranik  * @param[in] aResp         Shared pointer for generating response message.
613491d8ee7SSantosh Puranik  * @param[in] bootDbusObj   The dbus object to query for boot properties.
614491d8ee7SSantosh Puranik  *
615491d8ee7SSantosh Puranik  * @return None.
616491d8ee7SSantosh Puranik  */
617491d8ee7SSantosh Puranik static void getBootMode(std::shared_ptr<AsyncResp> aResp,
618491d8ee7SSantosh Puranik                         std::string bootDbusObj)
619491d8ee7SSantosh Puranik {
620491d8ee7SSantosh Puranik     crow::connections::systemBus->async_method_call(
621491d8ee7SSantosh Puranik         [aResp](const boost::system::error_code ec,
622491d8ee7SSantosh Puranik                 const std::variant<std::string> &bootMode) {
623491d8ee7SSantosh Puranik             if (ec)
624491d8ee7SSantosh Puranik             {
625491d8ee7SSantosh Puranik                 BMCWEB_LOG_DEBUG << "DBUS response error " << ec;
626491d8ee7SSantosh Puranik                 messages::internalError(aResp->res);
627491d8ee7SSantosh Puranik                 return;
628491d8ee7SSantosh Puranik             }
629491d8ee7SSantosh Puranik 
630491d8ee7SSantosh Puranik             const std::string *bootModeStr =
631491d8ee7SSantosh Puranik                 std::get_if<std::string>(&bootMode);
632491d8ee7SSantosh Puranik 
633491d8ee7SSantosh Puranik             if (!bootModeStr)
634491d8ee7SSantosh Puranik             {
635491d8ee7SSantosh Puranik                 messages::internalError(aResp->res);
636491d8ee7SSantosh Puranik                 return;
637491d8ee7SSantosh Puranik             }
638491d8ee7SSantosh Puranik 
639491d8ee7SSantosh Puranik             BMCWEB_LOG_DEBUG << "Boot mode: " << *bootModeStr;
640491d8ee7SSantosh Puranik 
641491d8ee7SSantosh Puranik             // TODO (Santosh): Do we need to support override mode?
642491d8ee7SSantosh Puranik             aResp->res.jsonValue["Boot"]["BootSourceOverrideMode"] = "Legacy";
643491d8ee7SSantosh Puranik             aResp->res.jsonValue["Boot"]["BootSourceOverrideTarget@Redfish."
644491d8ee7SSantosh Puranik                                          "AllowableValues"] = {
645491d8ee7SSantosh Puranik                 "None", "Pxe", "Hdd", "Cd", "Diags", "BiosSetup"};
646491d8ee7SSantosh Puranik 
647491d8ee7SSantosh Puranik             if (*bootModeStr !=
648491d8ee7SSantosh Puranik                 "xyz.openbmc_project.Control.Boot.Mode.Modes.Regular")
649491d8ee7SSantosh Puranik             {
650491d8ee7SSantosh Puranik                 auto rfMode = dbusToRfBootMode(*bootModeStr);
651491d8ee7SSantosh Puranik                 if (!rfMode.empty())
652491d8ee7SSantosh Puranik                 {
653491d8ee7SSantosh Puranik                     aResp->res.jsonValue["Boot"]["BootSourceOverrideTarget"] =
654491d8ee7SSantosh Puranik                         rfMode;
655491d8ee7SSantosh Puranik                 }
656491d8ee7SSantosh Puranik             }
657491d8ee7SSantosh Puranik 
658491d8ee7SSantosh Puranik             // If the BootSourceOverrideTarget is still "None" at the end,
659491d8ee7SSantosh Puranik             // reset the BootSourceOverrideEnabled to indicate that
660491d8ee7SSantosh Puranik             // overrides are disabled
661491d8ee7SSantosh Puranik             if (aResp->res.jsonValue["Boot"]["BootSourceOverrideTarget"] ==
662491d8ee7SSantosh Puranik                 "None")
663491d8ee7SSantosh Puranik             {
664491d8ee7SSantosh Puranik                 aResp->res.jsonValue["Boot"]["BootSourceOverrideEnabled"] =
665491d8ee7SSantosh Puranik                     "Disabled";
666491d8ee7SSantosh Puranik             }
667491d8ee7SSantosh Puranik         },
668491d8ee7SSantosh Puranik         "xyz.openbmc_project.Settings", bootDbusObj,
669491d8ee7SSantosh Puranik         "org.freedesktop.DBus.Properties", "Get",
670491d8ee7SSantosh Puranik         "xyz.openbmc_project.Control.Boot.Mode", "BootMode");
671491d8ee7SSantosh Puranik }
672491d8ee7SSantosh Puranik 
673491d8ee7SSantosh Puranik /**
674491d8ee7SSantosh Puranik  * @brief Retrieves boot source over DBUS
675491d8ee7SSantosh Puranik  *
676491d8ee7SSantosh Puranik  * @param[in] aResp         Shared pointer for generating response message.
677491d8ee7SSantosh Puranik  * @param[in] oneTimeEnable Boolean to indicate boot properties are one-time.
678491d8ee7SSantosh Puranik  *
679491d8ee7SSantosh Puranik  * @return None.
680491d8ee7SSantosh Puranik  */
681491d8ee7SSantosh Puranik static void getBootSource(std::shared_ptr<AsyncResp> aResp, bool oneTimeEnabled)
682491d8ee7SSantosh Puranik {
683491d8ee7SSantosh Puranik     std::string bootDbusObj =
684491d8ee7SSantosh Puranik         oneTimeEnabled ? "/xyz/openbmc_project/control/host0/boot/one_time"
685491d8ee7SSantosh Puranik                        : "/xyz/openbmc_project/control/host0/boot";
686491d8ee7SSantosh Puranik 
687491d8ee7SSantosh Puranik     BMCWEB_LOG_DEBUG << "Is one time: " << oneTimeEnabled;
688491d8ee7SSantosh Puranik     aResp->res.jsonValue["Boot"]["BootSourceOverrideEnabled"] =
689491d8ee7SSantosh Puranik         (oneTimeEnabled) ? "Once" : "Continuous";
690491d8ee7SSantosh Puranik 
691491d8ee7SSantosh Puranik     crow::connections::systemBus->async_method_call(
692491d8ee7SSantosh Puranik         [aResp, bootDbusObj](const boost::system::error_code ec,
693491d8ee7SSantosh Puranik                              const std::variant<std::string> &bootSource) {
694491d8ee7SSantosh Puranik             if (ec)
695491d8ee7SSantosh Puranik             {
696491d8ee7SSantosh Puranik                 BMCWEB_LOG_DEBUG << "DBUS response error " << ec;
697491d8ee7SSantosh Puranik                 messages::internalError(aResp->res);
698491d8ee7SSantosh Puranik                 return;
699491d8ee7SSantosh Puranik             }
700491d8ee7SSantosh Puranik 
701491d8ee7SSantosh Puranik             const std::string *bootSourceStr =
702491d8ee7SSantosh Puranik                 std::get_if<std::string>(&bootSource);
703491d8ee7SSantosh Puranik 
704491d8ee7SSantosh Puranik             if (!bootSourceStr)
705491d8ee7SSantosh Puranik             {
706491d8ee7SSantosh Puranik                 messages::internalError(aResp->res);
707491d8ee7SSantosh Puranik                 return;
708491d8ee7SSantosh Puranik             }
709491d8ee7SSantosh Puranik             BMCWEB_LOG_DEBUG << "Boot source: " << *bootSourceStr;
710491d8ee7SSantosh Puranik 
711491d8ee7SSantosh Puranik             auto rfSource = dbusToRfBootSource(*bootSourceStr);
712491d8ee7SSantosh Puranik             if (!rfSource.empty())
713491d8ee7SSantosh Puranik             {
714491d8ee7SSantosh Puranik                 aResp->res.jsonValue["Boot"]["BootSourceOverrideTarget"] =
715491d8ee7SSantosh Puranik                     rfSource;
716491d8ee7SSantosh Puranik             }
717491d8ee7SSantosh Puranik         },
718491d8ee7SSantosh Puranik         "xyz.openbmc_project.Settings", bootDbusObj,
719491d8ee7SSantosh Puranik         "org.freedesktop.DBus.Properties", "Get",
720491d8ee7SSantosh Puranik         "xyz.openbmc_project.Control.Boot.Source", "BootSource");
721491d8ee7SSantosh Puranik     getBootMode(std::move(aResp), std::move(bootDbusObj));
722491d8ee7SSantosh Puranik }
723491d8ee7SSantosh Puranik 
724491d8ee7SSantosh Puranik /**
725491d8ee7SSantosh Puranik  * @brief Retrieves "One time" enabled setting over DBUS and calls function to
726491d8ee7SSantosh Puranik  * get boot source and boot mode.
727491d8ee7SSantosh Puranik  *
728491d8ee7SSantosh Puranik  * @param[in] aResp     Shared pointer for generating response message.
729491d8ee7SSantosh Puranik  *
730491d8ee7SSantosh Puranik  * @return None.
731491d8ee7SSantosh Puranik  */
732491d8ee7SSantosh Puranik static void getBootProperties(std::shared_ptr<AsyncResp> aResp)
733491d8ee7SSantosh Puranik {
734491d8ee7SSantosh Puranik     BMCWEB_LOG_DEBUG << "Get boot information.";
735491d8ee7SSantosh Puranik 
736491d8ee7SSantosh Puranik     crow::connections::systemBus->async_method_call(
737c5d03ff4SJennifer Lee         [aResp](const boost::system::error_code ec,
738491d8ee7SSantosh Puranik                 const sdbusplus::message::variant<bool> &oneTime) {
739491d8ee7SSantosh Puranik             if (ec)
740491d8ee7SSantosh Puranik             {
741491d8ee7SSantosh Puranik                 BMCWEB_LOG_DEBUG << "DBUS response error " << ec;
742491d8ee7SSantosh Puranik                 messages::internalError(aResp->res);
743491d8ee7SSantosh Puranik                 return;
744491d8ee7SSantosh Puranik             }
745491d8ee7SSantosh Puranik 
746491d8ee7SSantosh Puranik             const bool *oneTimePtr = std::get_if<bool>(&oneTime);
747491d8ee7SSantosh Puranik 
748491d8ee7SSantosh Puranik             if (!oneTimePtr)
749491d8ee7SSantosh Puranik             {
750491d8ee7SSantosh Puranik                 messages::internalError(aResp->res);
751491d8ee7SSantosh Puranik                 return;
752491d8ee7SSantosh Puranik             }
753491d8ee7SSantosh Puranik             getBootSource(aResp, *oneTimePtr);
754491d8ee7SSantosh Puranik         },
755491d8ee7SSantosh Puranik         "xyz.openbmc_project.Settings",
756491d8ee7SSantosh Puranik         "/xyz/openbmc_project/control/host0/boot/one_time",
757491d8ee7SSantosh Puranik         "org.freedesktop.DBus.Properties", "Get",
758491d8ee7SSantosh Puranik         "xyz.openbmc_project.Object.Enable", "Enabled");
759491d8ee7SSantosh Puranik }
760491d8ee7SSantosh Puranik 
761491d8ee7SSantosh Puranik /**
762491d8ee7SSantosh Puranik  * @brief Sets boot properties into DBUS object(s).
763491d8ee7SSantosh Puranik  *
764491d8ee7SSantosh Puranik  * @param[in] aResp           Shared pointer for generating response message.
765491d8ee7SSantosh Puranik  * @param[in] oneTimeEnabled  Is "one-time" setting already enabled.
766491d8ee7SSantosh Puranik  * @param[in] bootSource      The boot source to set.
767491d8ee7SSantosh Puranik  * @param[in] bootEnable      The source override "enable" to set.
768491d8ee7SSantosh Puranik  *
769491d8ee7SSantosh Puranik  * @return None.
770491d8ee7SSantosh Puranik  */
771491d8ee7SSantosh Puranik static void setBootModeOrSource(std::shared_ptr<AsyncResp> aResp,
772491d8ee7SSantosh Puranik                                 bool oneTimeEnabled,
773491d8ee7SSantosh Puranik                                 std::optional<std::string> bootSource,
774491d8ee7SSantosh Puranik                                 std::optional<std::string> bootEnable)
775491d8ee7SSantosh Puranik {
776491d8ee7SSantosh Puranik     if (bootEnable && (bootEnable != "Once") && (bootEnable != "Continuous") &&
777491d8ee7SSantosh Puranik         (bootEnable != "Disabled"))
778491d8ee7SSantosh Puranik     {
779491d8ee7SSantosh Puranik         BMCWEB_LOG_DEBUG << "Unsupported value for BootSourceOverrideEnabled: "
780491d8ee7SSantosh Puranik                          << *bootEnable;
781491d8ee7SSantosh Puranik         messages::propertyValueNotInList(aResp->res, *bootEnable,
782491d8ee7SSantosh Puranik                                          "BootSourceOverrideEnabled");
783491d8ee7SSantosh Puranik         return;
784491d8ee7SSantosh Puranik     }
785491d8ee7SSantosh Puranik 
786491d8ee7SSantosh Puranik     bool oneTimeSetting = oneTimeEnabled;
787491d8ee7SSantosh Puranik     // Validate incoming parameters
788491d8ee7SSantosh Puranik     if (bootEnable)
789491d8ee7SSantosh Puranik     {
790491d8ee7SSantosh Puranik         if (*bootEnable == "Once")
791491d8ee7SSantosh Puranik         {
792491d8ee7SSantosh Puranik             oneTimeSetting = true;
793491d8ee7SSantosh Puranik         }
794491d8ee7SSantosh Puranik         else if (*bootEnable == "Continuous")
795491d8ee7SSantosh Puranik         {
796491d8ee7SSantosh Puranik             oneTimeSetting = false;
797491d8ee7SSantosh Puranik         }
798491d8ee7SSantosh Puranik         else if (*bootEnable == "Disabled")
799491d8ee7SSantosh Puranik         {
800491d8ee7SSantosh Puranik             oneTimeSetting = false;
801491d8ee7SSantosh Puranik         }
802491d8ee7SSantosh Puranik         else
803491d8ee7SSantosh Puranik         {
804491d8ee7SSantosh Puranik 
805491d8ee7SSantosh Puranik             BMCWEB_LOG_DEBUG << "Unsupported value for "
806491d8ee7SSantosh Puranik                                 "BootSourceOverrideEnabled: "
807491d8ee7SSantosh Puranik                              << *bootEnable;
808491d8ee7SSantosh Puranik             messages::propertyValueNotInList(aResp->res, *bootEnable,
809491d8ee7SSantosh Puranik                                              "BootSourceOverrideEnabled");
810491d8ee7SSantosh Puranik             return;
811491d8ee7SSantosh Puranik         }
812491d8ee7SSantosh Puranik     }
813491d8ee7SSantosh Puranik     std::string bootSourceStr;
814491d8ee7SSantosh Puranik     std::string bootModeStr;
815491d8ee7SSantosh Puranik     if (bootSource)
816491d8ee7SSantosh Puranik     {
817491d8ee7SSantosh Puranik         bootSourceStr = rfToDbusBootSource(*bootSource);
818491d8ee7SSantosh Puranik         bootModeStr = rfToDbusBootMode(*bootSource);
819491d8ee7SSantosh Puranik 
820491d8ee7SSantosh Puranik         BMCWEB_LOG_DEBUG << "DBUS boot source: " << bootSourceStr;
821491d8ee7SSantosh Puranik         BMCWEB_LOG_DEBUG << "DBUS boot mode: " << bootModeStr;
822491d8ee7SSantosh Puranik 
823491d8ee7SSantosh Puranik         if (bootSourceStr.empty() && bootModeStr.empty())
824491d8ee7SSantosh Puranik         {
825491d8ee7SSantosh Puranik             BMCWEB_LOG_DEBUG << "Invalid property value for "
826491d8ee7SSantosh Puranik                                 "BootSourceOverrideTarget: "
827491d8ee7SSantosh Puranik                              << *bootSource;
828491d8ee7SSantosh Puranik             messages::propertyValueNotInList(aResp->res, *bootSource,
829491d8ee7SSantosh Puranik                                              "BootSourceTargetOverride");
830491d8ee7SSantosh Puranik             return;
831491d8ee7SSantosh Puranik         }
832491d8ee7SSantosh Puranik     }
833491d8ee7SSantosh Puranik     const char *bootObj =
834491d8ee7SSantosh Puranik         oneTimeSetting ? "/xyz/openbmc_project/control/host0/boot/one_time"
835491d8ee7SSantosh Puranik                        : "/xyz/openbmc_project/control/host0/boot";
836491d8ee7SSantosh Puranik     // Figure out what properties to set
837491d8ee7SSantosh Puranik     if (bootEnable && (*bootEnable == "Disabled"))
838491d8ee7SSantosh Puranik     {
839491d8ee7SSantosh Puranik         BMCWEB_LOG_DEBUG << "Boot source override will be disabled";
840491d8ee7SSantosh Puranik         // Request to only turn OFF/ON enabled, if turning enabled OFF, need
841491d8ee7SSantosh Puranik         // to reset the source and mode too. If turning it ON, we only need
842491d8ee7SSantosh Puranik         // to set the enabled property
843491d8ee7SSantosh Puranik         bootSourceStr =
844491d8ee7SSantosh Puranik             "xyz.openbmc_project.Control.Boot.Source.Sources.Default";
845491d8ee7SSantosh Puranik         bootModeStr = "xyz.openbmc_project.Control.Boot.Mode.Modes.Regular";
846491d8ee7SSantosh Puranik     }
847491d8ee7SSantosh Puranik     else if (bootSource)
848491d8ee7SSantosh Puranik     {
849491d8ee7SSantosh Puranik         // Source target specified
850491d8ee7SSantosh Puranik         BMCWEB_LOG_DEBUG << "Boot source: " << *bootSource;
851491d8ee7SSantosh Puranik         // Figure out which DBUS interface and property to use
852491d8ee7SSantosh Puranik         bootSourceStr = rfToDbusBootSource(*bootSource);
853491d8ee7SSantosh Puranik         bootModeStr = rfToDbusBootMode(*bootSource);
854491d8ee7SSantosh Puranik 
855491d8ee7SSantosh Puranik         BMCWEB_LOG_DEBUG << "DBUS boot source: " << bootSourceStr;
856491d8ee7SSantosh Puranik         BMCWEB_LOG_DEBUG << "DBUS boot mode: " << bootModeStr;
857491d8ee7SSantosh Puranik 
858491d8ee7SSantosh Puranik         if (bootSourceStr.empty() && bootModeStr.empty())
859491d8ee7SSantosh Puranik         {
860491d8ee7SSantosh Puranik             BMCWEB_LOG_DEBUG << "Invalid property value for "
861491d8ee7SSantosh Puranik                                 "BootSourceOverrideTarget: "
862491d8ee7SSantosh Puranik                              << *bootSource;
863491d8ee7SSantosh Puranik             messages::propertyValueNotInList(aResp->res, *bootSource,
864491d8ee7SSantosh Puranik                                              "BootSourceTargetOverride");
865491d8ee7SSantosh Puranik             return;
866491d8ee7SSantosh Puranik         }
867491d8ee7SSantosh Puranik 
868491d8ee7SSantosh Puranik         if (!bootSourceStr.empty())
869491d8ee7SSantosh Puranik         {
870491d8ee7SSantosh Puranik             // If setting to anything other than default, also reset boot
871491d8ee7SSantosh Puranik             // mode property
872491d8ee7SSantosh Puranik             if (bootSourceStr !=
873491d8ee7SSantosh Puranik                 "xyz.openbmc_project.Control.Boot.Source.Sources.Default")
874491d8ee7SSantosh Puranik             {
875491d8ee7SSantosh Puranik                 bootModeStr =
876491d8ee7SSantosh Puranik                     "xyz.openbmc_project.Control.Boot.Mode.Modes.Regular";
877491d8ee7SSantosh Puranik             }
878491d8ee7SSantosh Puranik         }
879491d8ee7SSantosh Puranik         else // if (!bootModeStr.empty())
880491d8ee7SSantosh Puranik         {
881491d8ee7SSantosh Puranik             // If setting to anything other than default, also reset boot
882491d8ee7SSantosh Puranik             // source property
883491d8ee7SSantosh Puranik             if (bootModeStr !=
884491d8ee7SSantosh Puranik                 "xyz.openbmc_project.Control.Boot.Mode.Modes.Regular")
885491d8ee7SSantosh Puranik             {
886491d8ee7SSantosh Puranik                 bootSourceStr =
887491d8ee7SSantosh Puranik                     "xyz.openbmc_project.Control.Boot.Source.Sources.Default";
888491d8ee7SSantosh Puranik             }
889491d8ee7SSantosh Puranik         }
890491d8ee7SSantosh Puranik     }
891491d8ee7SSantosh Puranik     if (!bootSourceStr.empty())
892491d8ee7SSantosh Puranik     {
893491d8ee7SSantosh Puranik         crow::connections::systemBus->async_method_call(
894491d8ee7SSantosh Puranik             [aResp](const boost::system::error_code ec) {
895491d8ee7SSantosh Puranik                 if (ec)
896491d8ee7SSantosh Puranik                 {
897491d8ee7SSantosh Puranik                     BMCWEB_LOG_DEBUG << "DBUS response error " << ec;
898491d8ee7SSantosh Puranik                     messages::internalError(aResp->res);
899491d8ee7SSantosh Puranik                     return;
900491d8ee7SSantosh Puranik                 }
901491d8ee7SSantosh Puranik                 BMCWEB_LOG_DEBUG << "Boot source update done.";
902491d8ee7SSantosh Puranik             },
903491d8ee7SSantosh Puranik             "xyz.openbmc_project.Settings", bootObj,
904491d8ee7SSantosh Puranik             "org.freedesktop.DBus.Properties", "Set",
905491d8ee7SSantosh Puranik             "xyz.openbmc_project.Control.Boot.Source", "BootSource",
906491d8ee7SSantosh Puranik             std::variant<std::string>(bootSourceStr));
907491d8ee7SSantosh Puranik     }
908491d8ee7SSantosh Puranik     if (!bootModeStr.empty())
909491d8ee7SSantosh Puranik     {
910491d8ee7SSantosh Puranik         crow::connections::systemBus->async_method_call(
911491d8ee7SSantosh Puranik             [aResp](const boost::system::error_code ec) {
912491d8ee7SSantosh Puranik                 if (ec)
913491d8ee7SSantosh Puranik                 {
914491d8ee7SSantosh Puranik                     BMCWEB_LOG_DEBUG << "DBUS response error " << ec;
915491d8ee7SSantosh Puranik                     messages::internalError(aResp->res);
916491d8ee7SSantosh Puranik                     return;
917491d8ee7SSantosh Puranik                 }
918491d8ee7SSantosh Puranik                 BMCWEB_LOG_DEBUG << "Boot mode update done.";
919491d8ee7SSantosh Puranik             },
920491d8ee7SSantosh Puranik             "xyz.openbmc_project.Settings", bootObj,
921491d8ee7SSantosh Puranik             "org.freedesktop.DBus.Properties", "Set",
922491d8ee7SSantosh Puranik             "xyz.openbmc_project.Control.Boot.Mode", "BootMode",
923491d8ee7SSantosh Puranik             std::variant<std::string>(bootModeStr));
924491d8ee7SSantosh Puranik     }
925491d8ee7SSantosh Puranik     crow::connections::systemBus->async_method_call(
926491d8ee7SSantosh Puranik         [aResp{std::move(aResp)}](const boost::system::error_code ec) {
927491d8ee7SSantosh Puranik             if (ec)
928491d8ee7SSantosh Puranik             {
929491d8ee7SSantosh Puranik                 BMCWEB_LOG_DEBUG << "DBUS response error " << ec;
930491d8ee7SSantosh Puranik                 messages::internalError(aResp->res);
931491d8ee7SSantosh Puranik                 return;
932491d8ee7SSantosh Puranik             }
933491d8ee7SSantosh Puranik             BMCWEB_LOG_DEBUG << "Boot enable update done.";
934491d8ee7SSantosh Puranik         },
935491d8ee7SSantosh Puranik         "xyz.openbmc_project.Settings",
936491d8ee7SSantosh Puranik         "/xyz/openbmc_project/control/host0/boot/one_time",
937491d8ee7SSantosh Puranik         "org.freedesktop.DBus.Properties", "Set",
938491d8ee7SSantosh Puranik         "xyz.openbmc_project.Object.Enable", "Enabled",
939491d8ee7SSantosh Puranik         std::variant<bool>(oneTimeSetting));
940491d8ee7SSantosh Puranik }
941491d8ee7SSantosh Puranik 
942491d8ee7SSantosh Puranik /**
943491d8ee7SSantosh Puranik  * @brief Retrieves "One time" enabled setting over DBUS and calls function to
944491d8ee7SSantosh Puranik  * set boot source/boot mode properties.
945491d8ee7SSantosh Puranik  *
946491d8ee7SSantosh Puranik  * @param[in] aResp      Shared pointer for generating response message.
947491d8ee7SSantosh Puranik  * @param[in] bootSource The boot source from incoming RF request.
948491d8ee7SSantosh Puranik  * @param[in] bootEnable The boot override enable from incoming RF request.
949491d8ee7SSantosh Puranik  *
950491d8ee7SSantosh Puranik  * @return None.
951491d8ee7SSantosh Puranik  */
952491d8ee7SSantosh Puranik static void setBootProperties(std::shared_ptr<AsyncResp> aResp,
953491d8ee7SSantosh Puranik                               std::optional<std::string> bootSource,
954491d8ee7SSantosh Puranik                               std::optional<std::string> bootEnable)
955491d8ee7SSantosh Puranik {
956491d8ee7SSantosh Puranik     BMCWEB_LOG_DEBUG << "Set boot information.";
957491d8ee7SSantosh Puranik 
958491d8ee7SSantosh Puranik     crow::connections::systemBus->async_method_call(
959491d8ee7SSantosh Puranik         [aResp{std::move(aResp)}, bootSource{std::move(bootSource)},
960491d8ee7SSantosh Puranik          bootEnable{std::move(bootEnable)}](
961491d8ee7SSantosh Puranik             const boost::system::error_code ec,
962491d8ee7SSantosh Puranik             const sdbusplus::message::variant<bool> &oneTime) {
963491d8ee7SSantosh Puranik             if (ec)
964491d8ee7SSantosh Puranik             {
965491d8ee7SSantosh Puranik                 BMCWEB_LOG_DEBUG << "DBUS response error " << ec;
966491d8ee7SSantosh Puranik                 messages::internalError(aResp->res);
967491d8ee7SSantosh Puranik                 return;
968491d8ee7SSantosh Puranik             }
969491d8ee7SSantosh Puranik 
970491d8ee7SSantosh Puranik             const bool *oneTimePtr = std::get_if<bool>(&oneTime);
971491d8ee7SSantosh Puranik 
972491d8ee7SSantosh Puranik             if (!oneTimePtr)
973491d8ee7SSantosh Puranik             {
974491d8ee7SSantosh Puranik                 messages::internalError(aResp->res);
975491d8ee7SSantosh Puranik                 return;
976491d8ee7SSantosh Puranik             }
977491d8ee7SSantosh Puranik 
978491d8ee7SSantosh Puranik             BMCWEB_LOG_DEBUG << "Got one time: " << *oneTimePtr;
979491d8ee7SSantosh Puranik 
980491d8ee7SSantosh Puranik             setBootModeOrSource(aResp, *oneTimePtr, std::move(bootSource),
981491d8ee7SSantosh Puranik                                 std::move(bootEnable));
982491d8ee7SSantosh Puranik         },
983491d8ee7SSantosh Puranik         "xyz.openbmc_project.Settings",
984491d8ee7SSantosh Puranik         "/xyz/openbmc_project/control/host0/boot/one_time",
985491d8ee7SSantosh Puranik         "org.freedesktop.DBus.Properties", "Get",
986491d8ee7SSantosh Puranik         "xyz.openbmc_project.Object.Enable", "Enabled");
987491d8ee7SSantosh Puranik }
988491d8ee7SSantosh Puranik 
989491d8ee7SSantosh Puranik /**
990c5b2abe0SLewanczyk, Dawid  * SystemsCollection derived class for delivering ComputerSystems Collection
991c5b2abe0SLewanczyk, Dawid  * Schema
992c5b2abe0SLewanczyk, Dawid  */
9931abe55efSEd Tanous class SystemsCollection : public Node
9941abe55efSEd Tanous {
995c5b2abe0SLewanczyk, Dawid   public:
9961abe55efSEd Tanous     SystemsCollection(CrowApp &app) : Node(app, "/redfish/v1/Systems/")
9971abe55efSEd Tanous     {
998c5b2abe0SLewanczyk, Dawid         entityPrivileges = {
999c5b2abe0SLewanczyk, Dawid             {boost::beast::http::verb::get, {{"Login"}}},
1000c5b2abe0SLewanczyk, Dawid             {boost::beast::http::verb::head, {{"Login"}}},
1001c5b2abe0SLewanczyk, Dawid             {boost::beast::http::verb::patch, {{"ConfigureComponents"}}},
1002c5b2abe0SLewanczyk, Dawid             {boost::beast::http::verb::put, {{"ConfigureComponents"}}},
1003c5b2abe0SLewanczyk, Dawid             {boost::beast::http::verb::delete_, {{"ConfigureComponents"}}},
1004c5b2abe0SLewanczyk, Dawid             {boost::beast::http::verb::post, {{"ConfigureComponents"}}}};
1005c5b2abe0SLewanczyk, Dawid     }
1006c5b2abe0SLewanczyk, Dawid 
1007c5b2abe0SLewanczyk, Dawid   private:
100855c7b7a2SEd Tanous     void doGet(crow::Response &res, const crow::Request &req,
10091abe55efSEd Tanous                const std::vector<std::string> &params) override
10101abe55efSEd Tanous     {
10110f74e643SEd Tanous         res.jsonValue["@odata.type"] =
10120f74e643SEd Tanous             "#ComputerSystemCollection.ComputerSystemCollection";
10130f74e643SEd Tanous         res.jsonValue["@odata.id"] = "/redfish/v1/Systems";
10140f74e643SEd Tanous         res.jsonValue["@odata.context"] =
10150f74e643SEd Tanous             "/redfish/v1/"
10160f74e643SEd Tanous             "$metadata#ComputerSystemCollection.ComputerSystemCollection";
10170f74e643SEd Tanous         res.jsonValue["Name"] = "Computer System Collection";
1018029573d4SEd Tanous         res.jsonValue["Members"] = {
1019029573d4SEd Tanous             {{"@odata.id", "/redfish/v1/Systems/system"}}};
1020029573d4SEd Tanous         res.jsonValue["Members@odata.count"] = 1;
1021029573d4SEd Tanous         res.end();
1022c5b2abe0SLewanczyk, Dawid     }
1023c5b2abe0SLewanczyk, Dawid };
1024c5b2abe0SLewanczyk, Dawid 
1025c5b2abe0SLewanczyk, Dawid /**
1026cc340dd9SEd Tanous  * SystemActionsReset class supports handle POST method for Reset action.
1027cc340dd9SEd Tanous  * The class retrieves and sends data directly to D-Bus.
1028cc340dd9SEd Tanous  */
1029cc340dd9SEd Tanous class SystemActionsReset : public Node
1030cc340dd9SEd Tanous {
1031cc340dd9SEd Tanous   public:
1032cc340dd9SEd Tanous     SystemActionsReset(CrowApp &app) :
1033029573d4SEd Tanous         Node(app, "/redfish/v1/Systems/system/Actions/ComputerSystem.Reset/")
1034cc340dd9SEd Tanous     {
1035cc340dd9SEd Tanous         entityPrivileges = {
1036cc340dd9SEd Tanous             {boost::beast::http::verb::post, {{"ConfigureComponents"}}}};
1037cc340dd9SEd Tanous     }
1038cc340dd9SEd Tanous 
1039cc340dd9SEd Tanous   private:
1040cc340dd9SEd Tanous     /**
1041cc340dd9SEd Tanous      * Function handles POST method request.
1042cc340dd9SEd Tanous      * Analyzes POST body message before sends Reset request data to D-Bus.
1043cc340dd9SEd Tanous      */
1044cc340dd9SEd Tanous     void doPost(crow::Response &res, const crow::Request &req,
1045cc340dd9SEd Tanous                 const std::vector<std::string> &params) override
1046cc340dd9SEd Tanous     {
1047cc340dd9SEd Tanous         auto asyncResp = std::make_shared<AsyncResp>(res);
1048cc340dd9SEd Tanous 
10499712f8acSEd Tanous         std::string resetType;
10509712f8acSEd Tanous         if (!json_util::readJson(req, res, "ResetType", resetType))
1051cc340dd9SEd Tanous         {
1052cc340dd9SEd Tanous             return;
1053cc340dd9SEd Tanous         }
1054cc340dd9SEd Tanous 
1055d22c8396SJason M. Bills         // Get the command and host vs. chassis
1056cc340dd9SEd Tanous         std::string command;
1057d22c8396SJason M. Bills         bool hostCommand;
10589712f8acSEd Tanous         if (resetType == "On")
1059cc340dd9SEd Tanous         {
1060cc340dd9SEd Tanous             command = "xyz.openbmc_project.State.Host.Transition.On";
1061d22c8396SJason M. Bills             hostCommand = true;
1062d22c8396SJason M. Bills         }
1063d22c8396SJason M. Bills         else if (resetType == "ForceOff")
1064d22c8396SJason M. Bills         {
1065d22c8396SJason M. Bills             command = "xyz.openbmc_project.State.Chassis.Transition.Off";
1066d22c8396SJason M. Bills             hostCommand = false;
1067d22c8396SJason M. Bills         }
1068d22c8396SJason M. Bills         else if (resetType == "ForceOn")
1069d22c8396SJason M. Bills         {
1070d22c8396SJason M. Bills             command = "xyz.openbmc_project.State.Host.Transition.On";
1071d22c8396SJason M. Bills             hostCommand = true;
1072d22c8396SJason M. Bills         }
1073d22c8396SJason M. Bills         else if (resetType == "ForceRestart")
1074d22c8396SJason M. Bills         {
1075d22c8396SJason M. Bills             command = "xyz.openbmc_project.State.Chassis.Transition.Reset";
1076d22c8396SJason M. Bills             hostCommand = false;
1077cc340dd9SEd Tanous         }
10789712f8acSEd Tanous         else if (resetType == "GracefulShutdown")
1079cc340dd9SEd Tanous         {
1080cc340dd9SEd Tanous             command = "xyz.openbmc_project.State.Host.Transition.Off";
1081d22c8396SJason M. Bills             hostCommand = true;
1082cc340dd9SEd Tanous         }
10839712f8acSEd Tanous         else if (resetType == "GracefulRestart")
1084cc340dd9SEd Tanous         {
10859712f8acSEd Tanous             command = "xyz.openbmc_project.State.Host.Transition.Reboot";
1086d22c8396SJason M. Bills             hostCommand = true;
1087d22c8396SJason M. Bills         }
1088d22c8396SJason M. Bills         else if (resetType == "PowerCycle")
1089d22c8396SJason M. Bills         {
1090d22c8396SJason M. Bills             command = "xyz.openbmc_project.State.Chassis.Transition.PowerCycle";
1091d22c8396SJason M. Bills             hostCommand = false;
1092cc340dd9SEd Tanous         }
1093cc340dd9SEd Tanous         else
1094cc340dd9SEd Tanous         {
1095f12894f8SJason M. Bills             messages::actionParameterUnknown(res, "Reset", resetType);
1096cc340dd9SEd Tanous             return;
1097cc340dd9SEd Tanous         }
1098cc340dd9SEd Tanous 
1099d22c8396SJason M. Bills         if (hostCommand)
1100d22c8396SJason M. Bills         {
1101cc340dd9SEd Tanous             crow::connections::systemBus->async_method_call(
1102d22c8396SJason M. Bills                 [asyncResp, resetType](const boost::system::error_code ec) {
1103cc340dd9SEd Tanous                     if (ec)
1104cc340dd9SEd Tanous                     {
1105cc340dd9SEd Tanous                         BMCWEB_LOG_ERROR << "D-Bus responses error: " << ec;
1106d22c8396SJason M. Bills                         if (ec.value() == boost::asio::error::invalid_argument)
1107d22c8396SJason M. Bills                         {
1108d22c8396SJason M. Bills                             messages::actionParameterNotSupported(
1109d22c8396SJason M. Bills                                 asyncResp->res, resetType, "Reset");
1110d22c8396SJason M. Bills                         }
1111d22c8396SJason M. Bills                         else
1112d22c8396SJason M. Bills                         {
1113f12894f8SJason M. Bills                             messages::internalError(asyncResp->res);
1114d22c8396SJason M. Bills                         }
1115cc340dd9SEd Tanous                         return;
1116cc340dd9SEd Tanous                     }
1117f12894f8SJason M. Bills                     messages::success(asyncResp->res);
1118cc340dd9SEd Tanous                 },
1119cc340dd9SEd Tanous                 "xyz.openbmc_project.State.Host",
1120cc340dd9SEd Tanous                 "/xyz/openbmc_project/state/host0",
1121cc340dd9SEd Tanous                 "org.freedesktop.DBus.Properties", "Set",
11229712f8acSEd Tanous                 "xyz.openbmc_project.State.Host", "RequestedHostTransition",
1123abf2add6SEd Tanous                 std::variant<std::string>{command});
1124cc340dd9SEd Tanous         }
1125d22c8396SJason M. Bills         else
1126d22c8396SJason M. Bills         {
1127d22c8396SJason M. Bills             crow::connections::systemBus->async_method_call(
1128d22c8396SJason M. Bills                 [asyncResp, resetType](const boost::system::error_code ec) {
1129d22c8396SJason M. Bills                     if (ec)
1130d22c8396SJason M. Bills                     {
1131d22c8396SJason M. Bills                         BMCWEB_LOG_ERROR << "D-Bus responses error: " << ec;
1132d22c8396SJason M. Bills                         if (ec.value() == boost::asio::error::invalid_argument)
1133d22c8396SJason M. Bills                         {
1134d22c8396SJason M. Bills                             messages::actionParameterNotSupported(
1135d22c8396SJason M. Bills                                 asyncResp->res, resetType, "Reset");
1136d22c8396SJason M. Bills                         }
1137d22c8396SJason M. Bills                         else
1138d22c8396SJason M. Bills                         {
1139d22c8396SJason M. Bills                             messages::internalError(asyncResp->res);
1140d22c8396SJason M. Bills                         }
1141d22c8396SJason M. Bills                         return;
1142d22c8396SJason M. Bills                     }
1143d22c8396SJason M. Bills                     messages::success(asyncResp->res);
1144d22c8396SJason M. Bills                 },
1145d22c8396SJason M. Bills                 "xyz.openbmc_project.State.Chassis",
1146d22c8396SJason M. Bills                 "/xyz/openbmc_project/state/chassis0",
1147d22c8396SJason M. Bills                 "org.freedesktop.DBus.Properties", "Set",
1148d22c8396SJason M. Bills                 "xyz.openbmc_project.State.Chassis", "RequestedPowerTransition",
1149d22c8396SJason M. Bills                 std::variant<std::string>{command});
1150d22c8396SJason M. Bills         }
1151d22c8396SJason M. Bills     }
1152cc340dd9SEd Tanous };
1153cc340dd9SEd Tanous 
1154cc340dd9SEd Tanous /**
11556617338dSEd Tanous  * Systems derived class for delivering Computer Systems Schema.
1156c5b2abe0SLewanczyk, Dawid  */
11571abe55efSEd Tanous class Systems : public Node
11581abe55efSEd Tanous {
1159c5b2abe0SLewanczyk, Dawid   public:
1160c5b2abe0SLewanczyk, Dawid     /*
1161c5b2abe0SLewanczyk, Dawid      * Default Constructor
1162c5b2abe0SLewanczyk, Dawid      */
1163029573d4SEd Tanous     Systems(CrowApp &app) : Node(app, "/redfish/v1/Systems/system/")
11641abe55efSEd Tanous     {
1165c5b2abe0SLewanczyk, Dawid         entityPrivileges = {
1166c5b2abe0SLewanczyk, Dawid             {boost::beast::http::verb::get, {{"Login"}}},
1167c5b2abe0SLewanczyk, Dawid             {boost::beast::http::verb::head, {{"Login"}}},
1168c5b2abe0SLewanczyk, Dawid             {boost::beast::http::verb::patch, {{"ConfigureComponents"}}},
1169c5b2abe0SLewanczyk, Dawid             {boost::beast::http::verb::put, {{"ConfigureComponents"}}},
1170c5b2abe0SLewanczyk, Dawid             {boost::beast::http::verb::delete_, {{"ConfigureComponents"}}},
1171c5b2abe0SLewanczyk, Dawid             {boost::beast::http::verb::post, {{"ConfigureComponents"}}}};
1172c5b2abe0SLewanczyk, Dawid     }
1173c5b2abe0SLewanczyk, Dawid 
1174c5b2abe0SLewanczyk, Dawid   private:
1175c5b2abe0SLewanczyk, Dawid     /**
1176c5b2abe0SLewanczyk, Dawid      * Functions triggers appropriate requests on DBus
1177c5b2abe0SLewanczyk, Dawid      */
117855c7b7a2SEd Tanous     void doGet(crow::Response &res, const crow::Request &req,
11791abe55efSEd Tanous                const std::vector<std::string> &params) override
11801abe55efSEd Tanous     {
1181491d8ee7SSantosh Puranik         res.jsonValue["@odata.type"] = "#ComputerSystem.v1_6_0.ComputerSystem";
11820f74e643SEd Tanous         res.jsonValue["@odata.context"] =
11830f74e643SEd Tanous             "/redfish/v1/$metadata#ComputerSystem.ComputerSystem";
1184029573d4SEd Tanous         res.jsonValue["Name"] = "Computer System";
1185029573d4SEd Tanous         res.jsonValue["Id"] = "system";
11860f74e643SEd Tanous         res.jsonValue["SystemType"] = "Physical";
11870f74e643SEd Tanous         res.jsonValue["Description"] = "Computer System";
11880f74e643SEd Tanous         res.jsonValue["ProcessorSummary"]["Count"] = 0;
11890f74e643SEd Tanous         res.jsonValue["ProcessorSummary"]["Status"]["State"] = "Disabled";
11900f74e643SEd Tanous         res.jsonValue["MemorySummary"]["TotalSystemMemoryGiB"] = int(0);
11910f74e643SEd Tanous         res.jsonValue["MemorySummary"]["Status"]["State"] = "Disabled";
1192029573d4SEd Tanous         res.jsonValue["@odata.id"] = "/redfish/v1/Systems/system";
119304a258f4SEd Tanous 
1194443c2934SRapkiewicz, Pawel         res.jsonValue["Processors"] = {
1195029573d4SEd Tanous             {"@odata.id", "/redfish/v1/Systems/system/Processors"}};
1196443c2934SRapkiewicz, Pawel         res.jsonValue["Memory"] = {
1197029573d4SEd Tanous             {"@odata.id", "/redfish/v1/Systems/system/Memory"}};
1198029573d4SEd Tanous 
1199cc340dd9SEd Tanous         // TODO Need to support ForceRestart.
1200cc340dd9SEd Tanous         res.jsonValue["Actions"]["#ComputerSystem.Reset"] = {
1201cc340dd9SEd Tanous             {"target",
1202029573d4SEd Tanous              "/redfish/v1/Systems/system/Actions/ComputerSystem.Reset"},
1203cc340dd9SEd Tanous             {"ResetType@Redfish.AllowableValues",
1204d22c8396SJason M. Bills              {"On", "ForceOff", "ForceOn", "ForceRestart", "GracefulRestart",
1205d22c8396SJason M. Bills               "GracefulShutdown", "PowerCycle"}}};
1206c5b2abe0SLewanczyk, Dawid 
1207c4bf6374SJason M. Bills         res.jsonValue["LogServices"] = {
1208029573d4SEd Tanous             {"@odata.id", "/redfish/v1/Systems/system/LogServices"}};
1209c4bf6374SJason M. Bills 
1210c5d03ff4SJennifer Lee         res.jsonValue["Links"]["ManagedBy"] = {
1211c5d03ff4SJennifer Lee             {{"@odata.id", "/redfish/v1/Managers/bmc"}}};
1212c5d03ff4SJennifer Lee 
1213c5d03ff4SJennifer Lee         res.jsonValue["Status"] = {
1214c5d03ff4SJennifer Lee             {"Health", "OK"},
1215c5d03ff4SJennifer Lee             {"State", "Enabled"},
1216c5d03ff4SJennifer Lee         };
1217a0803efaSEd Tanous         auto asyncResp = std::make_shared<AsyncResp>(res);
1218c5b2abe0SLewanczyk, Dawid 
1219*b49ac873SJames Feist         constexpr const std::array<const char *, 2> inventoryForSystems = {
1220*b49ac873SJames Feist             "xyz.openbmc_project.Inventory.Item.Dimm",
1221*b49ac873SJames Feist             "xyz.openbmc_project.Inventory.Item.Cpu"};
1222*b49ac873SJames Feist 
1223*b49ac873SJames Feist         auto health = std::make_shared<HealthPopulate>(asyncResp);
1224*b49ac873SJames Feist         crow::connections::systemBus->async_method_call(
1225*b49ac873SJames Feist             [health](const boost::system::error_code ec,
1226*b49ac873SJames Feist                      std::vector<std::string> &resp) {
1227*b49ac873SJames Feist                 if (ec)
1228*b49ac873SJames Feist                 {
1229*b49ac873SJames Feist                     // no inventory
1230*b49ac873SJames Feist                     return;
1231*b49ac873SJames Feist                 }
1232*b49ac873SJames Feist 
1233*b49ac873SJames Feist                 health->inventory = std::move(resp);
1234*b49ac873SJames Feist             },
1235*b49ac873SJames Feist             "xyz.openbmc_project.ObjectMapper",
1236*b49ac873SJames Feist             "/xyz/openbmc_project/object_mapper",
1237*b49ac873SJames Feist             "xyz.openbmc_project.ObjectMapper", "GetSubTreePaths", "/",
1238*b49ac873SJames Feist             int32_t(0), inventoryForSystems);
1239*b49ac873SJames Feist 
1240*b49ac873SJames Feist         health->populate();
1241*b49ac873SJames Feist 
1242c5d03ff4SJennifer Lee         getMainChassisId(asyncResp, [](const std::string &chassisId,
1243c5d03ff4SJennifer Lee                                        std::shared_ptr<AsyncResp> aRsp) {
1244c5d03ff4SJennifer Lee             aRsp->res.jsonValue["Links"]["Chassis"] = {
1245c5d03ff4SJennifer Lee                 {{"@odata.id", "/redfish/v1/Chassis/" + chassisId}}};
1246c5d03ff4SJennifer Lee         });
12476c34de48SEd Tanous         getLedGroupIdentify(
1248a0803efaSEd Tanous             asyncResp,
1249c5d03ff4SJennifer Lee             [](const bool &asserted, const std::shared_ptr<AsyncResp> aRsp) {
12501abe55efSEd Tanous                 if (asserted)
12511abe55efSEd Tanous                 {
1252c5b2abe0SLewanczyk, Dawid                     // If led group is asserted, then another call is needed to
1253c5b2abe0SLewanczyk, Dawid                     // get led status
12546c34de48SEd Tanous                     getLedIdentify(
1255c5d03ff4SJennifer Lee                         aRsp, [](const std::string &ledStatus,
1256c5d03ff4SJennifer Lee                                  const std::shared_ptr<AsyncResp> aRsp) {
12571abe55efSEd Tanous                             if (!ledStatus.empty())
12581abe55efSEd Tanous                             {
1259c5d03ff4SJennifer Lee                                 aRsp->res.jsonValue["IndicatorLED"] = ledStatus;
1260c5b2abe0SLewanczyk, Dawid                             }
1261c5b2abe0SLewanczyk, Dawid                         });
12621abe55efSEd Tanous                 }
12631abe55efSEd Tanous                 else
12641abe55efSEd Tanous                 {
1265c5d03ff4SJennifer Lee                     aRsp->res.jsonValue["IndicatorLED"] = "Off";
1266c5b2abe0SLewanczyk, Dawid                 }
1267c5b2abe0SLewanczyk, Dawid             });
1268029573d4SEd Tanous         getComputerSystem(asyncResp);
12696c34de48SEd Tanous         getHostState(asyncResp);
1270491d8ee7SSantosh Puranik         getBootProperties(asyncResp);
1271c5b2abe0SLewanczyk, Dawid     }
1272c5b2abe0SLewanczyk, Dawid 
127355c7b7a2SEd Tanous     void doPatch(crow::Response &res, const crow::Request &req,
12741abe55efSEd Tanous                  const std::vector<std::string> &params) override
12751abe55efSEd Tanous     {
1276cde19e5fSSantosh Puranik         std::optional<std::string> indicatorLed;
1277491d8ee7SSantosh Puranik         std::optional<nlohmann::json> bootProps;
1278491d8ee7SSantosh Puranik         if (!json_util::readJson(req, res, "IndicatorLED", indicatorLed, "Boot",
1279491d8ee7SSantosh Puranik                                  bootProps))
12806617338dSEd Tanous         {
12816617338dSEd Tanous             return;
12826617338dSEd Tanous         }
1283491d8ee7SSantosh Puranik 
1284029573d4SEd Tanous         auto asyncResp = std::make_shared<AsyncResp>(res);
1285d573bb2aSJennifer Lee         asyncResp->res.result(boost::beast::http::status::no_content);
1286491d8ee7SSantosh Puranik 
1287491d8ee7SSantosh Puranik         if (bootProps)
1288491d8ee7SSantosh Puranik         {
1289491d8ee7SSantosh Puranik             std::optional<std::string> bootSource;
1290491d8ee7SSantosh Puranik             std::optional<std::string> bootEnable;
1291491d8ee7SSantosh Puranik 
1292491d8ee7SSantosh Puranik             if (!json_util::readJson(*bootProps, asyncResp->res,
1293491d8ee7SSantosh Puranik                                      "BootSourceOverrideTarget", bootSource,
1294491d8ee7SSantosh Puranik                                      "BootSourceOverrideEnabled", bootEnable))
1295491d8ee7SSantosh Puranik             {
1296491d8ee7SSantosh Puranik                 return;
1297491d8ee7SSantosh Puranik             }
1298491d8ee7SSantosh Puranik             setBootProperties(asyncResp, std::move(bootSource),
1299491d8ee7SSantosh Puranik                               std::move(bootEnable));
1300491d8ee7SSantosh Puranik         }
13019712f8acSEd Tanous         if (indicatorLed)
13026617338dSEd Tanous         {
13039712f8acSEd Tanous             std::string dbusLedState;
1304d573bb2aSJennifer Lee             if (*indicatorLed == "Lit")
13059712f8acSEd Tanous             {
1306d573bb2aSJennifer Lee                 dbusLedState = "xyz.openbmc_project.Led.Physical.Action.On";
13076617338dSEd Tanous             }
13085c6221acSGunnar Mills             else if (*indicatorLed == "Blinking")
13096617338dSEd Tanous             {
13105c6221acSGunnar Mills                 dbusLedState = "xyz.openbmc_project.Led.Physical.Action.Blink";
13116617338dSEd Tanous             }
13129712f8acSEd Tanous             else if (*indicatorLed == "Off")
13136617338dSEd Tanous             {
13149712f8acSEd Tanous                 dbusLedState = "xyz.openbmc_project.Led.Physical.Action.Off";
13156617338dSEd Tanous             }
13166617338dSEd Tanous             else
13176617338dSEd Tanous             {
1318a08b46ccSJason M. Bills                 messages::propertyValueNotInList(res, *indicatorLed,
1319a08b46ccSJason M. Bills                                                  "IndicatorLED");
13206617338dSEd Tanous                 return;
13216617338dSEd Tanous             }
13226617338dSEd Tanous 
1323c5b2abe0SLewanczyk, Dawid             // Update led group
132455c7b7a2SEd Tanous             BMCWEB_LOG_DEBUG << "Update led group.";
132555c7b7a2SEd Tanous             crow::connections::systemBus->async_method_call(
1326cde19e5fSSantosh Puranik                 [asyncResp](const boost::system::error_code ec) {
13271abe55efSEd Tanous                     if (ec)
13281abe55efSEd Tanous                     {
132955c7b7a2SEd Tanous                         BMCWEB_LOG_DEBUG << "DBUS response error " << ec;
1330f12894f8SJason M. Bills                         messages::internalError(asyncResp->res);
1331c5b2abe0SLewanczyk, Dawid                         return;
1332c5b2abe0SLewanczyk, Dawid                     }
133355c7b7a2SEd Tanous                     BMCWEB_LOG_DEBUG << "Led group update done.";
1334c5b2abe0SLewanczyk, Dawid                 },
1335c5b2abe0SLewanczyk, Dawid                 "xyz.openbmc_project.LED.GroupManager",
1336c5b2abe0SLewanczyk, Dawid                 "/xyz/openbmc_project/led/groups/enclosure_identify",
1337c5b2abe0SLewanczyk, Dawid                 "org.freedesktop.DBus.Properties", "Set",
1338c5b2abe0SLewanczyk, Dawid                 "xyz.openbmc_project.Led.Group", "Asserted",
1339abf2add6SEd Tanous                 std::variant<bool>(
13406617338dSEd Tanous                     (dbusLedState ==
13416617338dSEd Tanous                              "xyz.openbmc_project.Led.Physical.Action.Off"
13426617338dSEd Tanous                          ? false
13436617338dSEd Tanous                          : true)));
1344c5b2abe0SLewanczyk, Dawid             // Update identify led status
134555c7b7a2SEd Tanous             BMCWEB_LOG_DEBUG << "Update led SoftwareInventoryCollection.";
134655c7b7a2SEd Tanous             crow::connections::systemBus->async_method_call(
13476617338dSEd Tanous                 [asyncResp{std::move(asyncResp)},
13489712f8acSEd Tanous                  indicatorLed{std::move(*indicatorLed)}](
1349c5b2abe0SLewanczyk, Dawid                     const boost::system::error_code ec) {
13501abe55efSEd Tanous                     if (ec)
13511abe55efSEd Tanous                     {
135255c7b7a2SEd Tanous                         BMCWEB_LOG_DEBUG << "DBUS response error " << ec;
1353f12894f8SJason M. Bills                         messages::internalError(asyncResp->res);
1354c5b2abe0SLewanczyk, Dawid                         return;
1355c5b2abe0SLewanczyk, Dawid                     }
135655c7b7a2SEd Tanous                     BMCWEB_LOG_DEBUG << "Led state update done.";
1357c5b2abe0SLewanczyk, Dawid                 },
1358c5b2abe0SLewanczyk, Dawid                 "xyz.openbmc_project.LED.Controller.identify",
1359c5b2abe0SLewanczyk, Dawid                 "/xyz/openbmc_project/led/physical/identify",
1360c5b2abe0SLewanczyk, Dawid                 "org.freedesktop.DBus.Properties", "Set",
1361c5b2abe0SLewanczyk, Dawid                 "xyz.openbmc_project.Led.Physical", "State",
1362abf2add6SEd Tanous                 std::variant<std::string>(dbusLedState));
13636617338dSEd Tanous         }
1364c5b2abe0SLewanczyk, Dawid     }
1365c5b2abe0SLewanczyk, Dawid };
1366c5b2abe0SLewanczyk, Dawid } // namespace redfish
1367