xref: /openbmc/bmcweb/features/redfish/lib/chassis.hpp (revision 51dab2a7284b0f7adf2296e4165bdf8a63e73b7d)
1e37f8451SRapkiewicz, Pawel /*
2e37f8451SRapkiewicz, Pawel // Copyright (c) 2018 Intel Corporation
3e37f8451SRapkiewicz, Pawel //
4e37f8451SRapkiewicz, Pawel // Licensed under the Apache License, Version 2.0 (the "License");
5e37f8451SRapkiewicz, Pawel // you may not use this file except in compliance with the License.
6e37f8451SRapkiewicz, Pawel // You may obtain a copy of the License at
7e37f8451SRapkiewicz, Pawel //
8e37f8451SRapkiewicz, Pawel //      http://www.apache.org/licenses/LICENSE-2.0
9e37f8451SRapkiewicz, Pawel //
10e37f8451SRapkiewicz, Pawel // Unless required by applicable law or agreed to in writing, software
11e37f8451SRapkiewicz, Pawel // distributed under the License is distributed on an "AS IS" BASIS,
12e37f8451SRapkiewicz, Pawel // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13e37f8451SRapkiewicz, Pawel // See the License for the specific language governing permissions and
14e37f8451SRapkiewicz, Pawel // limitations under the License.
15e37f8451SRapkiewicz, Pawel */
16e37f8451SRapkiewicz, Pawel #pragma once
17e37f8451SRapkiewicz, Pawel 
1813451e39SWilly Tu #include "bmcweb_config.h"
1913451e39SWilly Tu 
203ccb3adbSEd Tanous #include "app.hpp"
217a1dbc48SGeorge Liu #include "dbus_utility.hpp"
22b49ac873SJames Feist #include "health.hpp"
231c8fba97SJames Feist #include "led.hpp"
243ccb3adbSEd Tanous #include "query.hpp"
253ccb3adbSEd Tanous #include "registries/privilege_registry.hpp"
263ccb3adbSEd Tanous #include "utils/collection.hpp"
273ccb3adbSEd Tanous #include "utils/dbus_utils.hpp"
28cf7eba09SNan Zhou #include "utils/json_utils.hpp"
291abe55efSEd Tanous 
30e99073f5SGeorge Liu #include <boost/system/error_code.hpp>
31ef4c65b7SEd Tanous #include <boost/url/format.hpp>
321e1e598dSJonathan Doman #include <sdbusplus/asio/property.hpp>
3386d89ed7SKrzysztof Grobelny #include <sdbusplus/unpack_properties.hpp>
341214b7e7SGunnar Mills 
357a1dbc48SGeorge Liu #include <array>
367a1dbc48SGeorge Liu #include <string_view>
377a1dbc48SGeorge Liu 
381abe55efSEd Tanous namespace redfish
391abe55efSEd Tanous {
40e37f8451SRapkiewicz, Pawel 
41e37f8451SRapkiewicz, Pawel /**
42beeca0aeSGunnar Mills  * @brief Retrieves chassis state properties over dbus
43beeca0aeSGunnar Mills  *
44beeca0aeSGunnar Mills  * @param[in] aResp - Shared pointer for completing asynchronous calls.
45beeca0aeSGunnar Mills  *
46beeca0aeSGunnar Mills  * @return None.
47beeca0aeSGunnar Mills  */
488d1b46d7Szhanghch05 inline void getChassisState(std::shared_ptr<bmcweb::AsyncResp> aResp)
49beeca0aeSGunnar Mills {
501e1e598dSJonathan Doman     // crow::connections::systemBus->async_method_call(
511e1e598dSJonathan Doman     sdbusplus::asio::getProperty<std::string>(
521e1e598dSJonathan Doman         *crow::connections::systemBus, "xyz.openbmc_project.State.Chassis",
531e1e598dSJonathan Doman         "/xyz/openbmc_project/state/chassis0",
541e1e598dSJonathan Doman         "xyz.openbmc_project.State.Chassis", "CurrentPowerState",
555e7e2dc5SEd Tanous         [aResp{std::move(aResp)}](const boost::system::error_code& ec,
561e1e598dSJonathan Doman                                   const std::string& chassisState) {
57beeca0aeSGunnar Mills         if (ec)
58beeca0aeSGunnar Mills         {
59a6e5e0abSCarson Labrado             if (ec == boost::system::errc::host_unreachable)
60a6e5e0abSCarson Labrado             {
61a6e5e0abSCarson Labrado                 // Service not available, no error, just don't return
62a6e5e0abSCarson Labrado                 // chassis state info
63a6e5e0abSCarson Labrado                 BMCWEB_LOG_DEBUG << "Service not available " << ec;
64a6e5e0abSCarson Labrado                 return;
65a6e5e0abSCarson Labrado             }
66*51dab2a7SAndrew Geissler             BMCWEB_LOG_ERROR << "DBUS response error " << ec;
67beeca0aeSGunnar Mills             messages::internalError(aResp->res);
68beeca0aeSGunnar Mills             return;
69beeca0aeSGunnar Mills         }
70beeca0aeSGunnar Mills 
711e1e598dSJonathan Doman         BMCWEB_LOG_DEBUG << "Chassis state: " << chassisState;
72beeca0aeSGunnar Mills         // Verify Chassis State
73002d39b4SEd Tanous         if (chassisState == "xyz.openbmc_project.State.Chassis.PowerState.On")
74beeca0aeSGunnar Mills         {
75beeca0aeSGunnar Mills             aResp->res.jsonValue["PowerState"] = "On";
76beeca0aeSGunnar Mills             aResp->res.jsonValue["Status"]["State"] = "Enabled";
77beeca0aeSGunnar Mills         }
781e1e598dSJonathan Doman         else if (chassisState ==
79beeca0aeSGunnar Mills                  "xyz.openbmc_project.State.Chassis.PowerState.Off")
80beeca0aeSGunnar Mills         {
81beeca0aeSGunnar Mills             aResp->res.jsonValue["PowerState"] = "Off";
82beeca0aeSGunnar Mills             aResp->res.jsonValue["Status"]["State"] = "StandbyOffline";
83beeca0aeSGunnar Mills         }
841e1e598dSJonathan Doman         });
85beeca0aeSGunnar Mills }
86beeca0aeSGunnar Mills 
878d1b46d7Szhanghch05 inline void getIntrusionByService(std::shared_ptr<bmcweb::AsyncResp> aResp,
88c181942fSQiang XU                                   const std::string& service,
89c181942fSQiang XU                                   const std::string& objPath)
90c181942fSQiang XU {
91c181942fSQiang XU     BMCWEB_LOG_DEBUG << "Get intrusion status by service \n";
92c181942fSQiang XU 
931e1e598dSJonathan Doman     sdbusplus::asio::getProperty<std::string>(
941e1e598dSJonathan Doman         *crow::connections::systemBus, service, objPath,
951e1e598dSJonathan Doman         "xyz.openbmc_project.Chassis.Intrusion", "Status",
965e7e2dc5SEd Tanous         [aResp{std::move(aResp)}](const boost::system::error_code& ec,
971e1e598dSJonathan Doman                                   const std::string& value) {
98c181942fSQiang XU         if (ec)
99c181942fSQiang XU         {
1004e0453b1SGunnar Mills             // do not add err msg in redfish response, because this is not
101c181942fSQiang XU             //     mandatory property
102c181942fSQiang XU             BMCWEB_LOG_ERROR << "DBUS response error " << ec << "\n";
103c181942fSQiang XU             return;
104c181942fSQiang XU         }
105c181942fSQiang XU 
106002d39b4SEd Tanous         aResp->res.jsonValue["PhysicalSecurity"]["IntrusionSensorNumber"] = 1;
1071476687dSEd Tanous         aResp->res.jsonValue["PhysicalSecurity"]["IntrusionSensor"] = value;
1081e1e598dSJonathan Doman         });
109c181942fSQiang XU }
110c181942fSQiang XU 
111c181942fSQiang XU /**
112c181942fSQiang XU  * Retrieves physical security properties over dbus
113c181942fSQiang XU  */
1148d1b46d7Szhanghch05 inline void getPhysicalSecurityData(std::shared_ptr<bmcweb::AsyncResp> aResp)
115c181942fSQiang XU {
116e99073f5SGeorge Liu     constexpr std::array<std::string_view, 1> interfaces = {
117e99073f5SGeorge Liu         "xyz.openbmc_project.Chassis.Intrusion"};
118e99073f5SGeorge Liu     dbus::utility::getSubTree(
119e99073f5SGeorge Liu         "/xyz/openbmc_project/Intrusion", 1, interfaces,
120c181942fSQiang XU         [aResp{std::move(aResp)}](
121e99073f5SGeorge Liu             const boost::system::error_code& ec,
122b9d36b47SEd Tanous             const dbus::utility::MapperGetSubTreeResponse& subtree) {
123c181942fSQiang XU         if (ec)
124c181942fSQiang XU         {
1254e0453b1SGunnar Mills             // do not add err msg in redfish response, because this is not
126c181942fSQiang XU             //     mandatory property
127002d39b4SEd Tanous             BMCWEB_LOG_INFO << "DBUS error: no matched iface " << ec << "\n";
128c181942fSQiang XU             return;
129c181942fSQiang XU         }
130c181942fSQiang XU         // Iterate over all retrieved ObjectPaths.
131c181942fSQiang XU         for (const auto& object : subtree)
132c181942fSQiang XU         {
133840a9ffcSPatrick Williams             if (!object.second.empty())
134c181942fSQiang XU             {
135840a9ffcSPatrick Williams                 const auto service = object.second.front();
136c181942fSQiang XU                 getIntrusionByService(aResp, service.first, object.first);
137c181942fSQiang XU                 return;
138c181942fSQiang XU             }
139c181942fSQiang XU         }
140e99073f5SGeorge Liu         });
141c181942fSQiang XU }
142c181942fSQiang XU 
143cf7eba09SNan Zhou inline void handleChassisCollectionGet(
144cf7eba09SNan Zhou     App& app, const crow::Request& req,
145cf7eba09SNan Zhou     const std::shared_ptr<bmcweb::AsyncResp>& asyncResp)
1461abe55efSEd Tanous {
1473ba00073SCarson Labrado     if (!redfish::setUpRedfishRoute(app, req, asyncResp))
14845ca1b86SEd Tanous     {
14945ca1b86SEd Tanous         return;
15045ca1b86SEd Tanous     }
1518d1b46d7Szhanghch05     asyncResp->res.jsonValue["@odata.type"] =
1528d1b46d7Szhanghch05         "#ChassisCollection.ChassisCollection";
1538d1b46d7Szhanghch05     asyncResp->res.jsonValue["@odata.id"] = "/redfish/v1/Chassis";
1548d1b46d7Szhanghch05     asyncResp->res.jsonValue["Name"] = "Chassis Collection";
155e37f8451SRapkiewicz, Pawel 
1567a1dbc48SGeorge Liu     constexpr std::array<std::string_view, 2> interfaces{
1577a1dbc48SGeorge Liu         "xyz.openbmc_project.Inventory.Item.Board",
1587a1dbc48SGeorge Liu         "xyz.openbmc_project.Inventory.Item.Chassis"};
15902f6ff19SGunnar Mills     collection_util::getCollectionMembers(
1607a1dbc48SGeorge Liu         asyncResp, boost::urls::url("/redfish/v1/Chassis"), interfaces);
161cf7eba09SNan Zhou }
162cf7eba09SNan Zhou 
163cf7eba09SNan Zhou /**
164cf7eba09SNan Zhou  * ChassisCollection derived class for delivering Chassis Collection Schema
165cf7eba09SNan Zhou  *  Functions triggers appropriate requests on DBus
166cf7eba09SNan Zhou  */
167cf7eba09SNan Zhou inline void requestRoutesChassisCollection(App& app)
168cf7eba09SNan Zhou {
169cf7eba09SNan Zhou     BMCWEB_ROUTE(app, "/redfish/v1/Chassis/")
170cf7eba09SNan Zhou         .privileges(redfish::privileges::getChassisCollection)
171cf7eba09SNan Zhou         .methods(boost::beast::http::verb::get)(
172cf7eba09SNan Zhou             std::bind_front(handleChassisCollectionGet, std::ref(app)));
17362d5e2e4SEd Tanous }
174e37f8451SRapkiewicz, Pawel 
175308f70c7SWilly Tu inline void
176308f70c7SWilly Tu     getChassisLocationCode(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
177308f70c7SWilly Tu                            const std::string& connectionName,
178308f70c7SWilly Tu                            const std::string& path)
179308f70c7SWilly Tu {
1801e1e598dSJonathan Doman     sdbusplus::asio::getProperty<std::string>(
1811e1e598dSJonathan Doman         *crow::connections::systemBus, connectionName, path,
1821e1e598dSJonathan Doman         "xyz.openbmc_project.Inventory.Decorator.LocationCode", "LocationCode",
1835e7e2dc5SEd Tanous         [asyncResp](const boost::system::error_code& ec,
1841e1e598dSJonathan Doman                     const std::string& property) {
185308f70c7SWilly Tu         if (ec)
186308f70c7SWilly Tu         {
187*51dab2a7SAndrew Geissler             BMCWEB_LOG_ERROR << "DBUS response error for Location";
188308f70c7SWilly Tu             messages::internalError(asyncResp->res);
189308f70c7SWilly Tu             return;
190308f70c7SWilly Tu         }
191308f70c7SWilly Tu 
192002d39b4SEd Tanous         asyncResp->res.jsonValue["Location"]["PartLocation"]["ServiceLabel"] =
1931e1e598dSJonathan Doman             property;
1941e1e598dSJonathan Doman         });
195308f70c7SWilly Tu }
196308f70c7SWilly Tu 
197308f70c7SWilly Tu inline void getChassisUUID(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
198308f70c7SWilly Tu                            const std::string& connectionName,
199308f70c7SWilly Tu                            const std::string& path)
200308f70c7SWilly Tu {
2011e1e598dSJonathan Doman     sdbusplus::asio::getProperty<std::string>(
2021e1e598dSJonathan Doman         *crow::connections::systemBus, connectionName, path,
2031e1e598dSJonathan Doman         "xyz.openbmc_project.Common.UUID", "UUID",
2045e7e2dc5SEd Tanous         [asyncResp](const boost::system::error_code& ec,
2051e1e598dSJonathan Doman                     const std::string& chassisUUID) {
206308f70c7SWilly Tu         if (ec)
207308f70c7SWilly Tu         {
208*51dab2a7SAndrew Geissler             BMCWEB_LOG_ERROR << "DBUS response error for UUID";
209308f70c7SWilly Tu             messages::internalError(asyncResp->res);
210308f70c7SWilly Tu             return;
211308f70c7SWilly Tu         }
2121e1e598dSJonathan Doman         asyncResp->res.jsonValue["UUID"] = chassisUUID;
2131e1e598dSJonathan Doman         });
214308f70c7SWilly Tu }
215308f70c7SWilly Tu 
216cf7eba09SNan Zhou inline void
217cf7eba09SNan Zhou     handleChassisGet(App& app, const crow::Request& req,
21845ca1b86SEd Tanous                      const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
219cf7eba09SNan Zhou                      const std::string& chassisId)
220cf7eba09SNan Zhou {
2213ba00073SCarson Labrado     if (!redfish::setUpRedfishRoute(app, req, asyncResp))
22245ca1b86SEd Tanous     {
22345ca1b86SEd Tanous         return;
22445ca1b86SEd Tanous     }
225e99073f5SGeorge Liu     constexpr std::array<std::string_view, 2> interfaces = {
226734bfe90SGunnar Mills         "xyz.openbmc_project.Inventory.Item.Board",
227adc4f0dbSShawn McCarney         "xyz.openbmc_project.Inventory.Item.Chassis"};
228734bfe90SGunnar Mills 
229e99073f5SGeorge Liu     dbus::utility::getSubTree(
230e99073f5SGeorge Liu         "/xyz/openbmc_project/inventory", 0, interfaces,
23162d5e2e4SEd Tanous         [asyncResp, chassisId(std::string(chassisId))](
232e99073f5SGeorge Liu             const boost::system::error_code& ec,
233b9d36b47SEd Tanous             const dbus::utility::MapperGetSubTreeResponse& subtree) {
23462d5e2e4SEd Tanous         if (ec)
2351abe55efSEd Tanous         {
236*51dab2a7SAndrew Geissler             BMCWEB_LOG_ERROR << "DBUS response error " << ec;
237f12894f8SJason M. Bills             messages::internalError(asyncResp->res);
238daf36e2eSEd Tanous             return;
239daf36e2eSEd Tanous         }
240daf36e2eSEd Tanous         // Iterate over all retrieved ObjectPaths.
241cf7eba09SNan Zhou         for (const std::pair<
242cf7eba09SNan Zhou                  std::string,
243cf7eba09SNan Zhou                  std::vector<std::pair<std::string, std::vector<std::string>>>>&
2441214b7e7SGunnar Mills                  object : subtree)
2451abe55efSEd Tanous         {
246daf36e2eSEd Tanous             const std::string& path = object.first;
247cf7eba09SNan Zhou             const std::vector<std::pair<std::string, std::vector<std::string>>>&
2481214b7e7SGunnar Mills                 connectionNames = object.second;
2497e860f15SJohn Edward Broadbent 
250997093ebSGeorge Liu             sdbusplus::message::object_path objPath(path);
251997093ebSGeorge Liu             if (objPath.filename() != chassisId)
2521abe55efSEd Tanous             {
253daf36e2eSEd Tanous                 continue;
254daf36e2eSEd Tanous             }
25526f03899SShawn McCarney 
256002d39b4SEd Tanous             auto health = std::make_shared<HealthPopulate>(asyncResp);
257b49ac873SJames Feist 
25813451e39SWilly Tu             if constexpr (bmcwebEnableHealthPopulate)
25913451e39SWilly Tu             {
2606c3e9451SGeorge Liu                 dbus::utility::getAssociationEndPoints(
2616c3e9451SGeorge Liu                     path + "/all_sensors",
2625e7e2dc5SEd Tanous                     [health](const boost::system::error_code& ec2,
2636c3e9451SGeorge Liu                              const dbus::utility::MapperEndPoints& resp) {
26423a21a1cSEd Tanous                     if (ec2)
265b49ac873SJames Feist                     {
266b49ac873SJames Feist                         return; // no sensors = no failures
267b49ac873SJames Feist                     }
2681e1e598dSJonathan Doman                     health->inventory = resp;
2691e1e598dSJonathan Doman                     });
270b49ac873SJames Feist 
271b49ac873SJames Feist                 health->populate();
27213451e39SWilly Tu             }
273b49ac873SJames Feist 
27426f6976fSEd Tanous             if (connectionNames.empty())
2751abe55efSEd Tanous             {
2761c8fba97SJames Feist                 BMCWEB_LOG_ERROR << "Got 0 Connection names";
277e0d918bcSEd Tanous                 continue;
278daf36e2eSEd Tanous             }
279e0d918bcSEd Tanous 
28049c53ac9SJohnathan Mantey             asyncResp->res.jsonValue["@odata.type"] =
281523d4868SLogananth Sundararaj                 "#Chassis.v1_22_0.Chassis";
28249c53ac9SJohnathan Mantey             asyncResp->res.jsonValue["@odata.id"] =
283ef4c65b7SEd Tanous                 boost::urls::format("/redfish/v1/Chassis/{}", chassisId);
28449c53ac9SJohnathan Mantey             asyncResp->res.jsonValue["Name"] = "Chassis Collection";
28549c53ac9SJohnathan Mantey             asyncResp->res.jsonValue["ChassisType"] = "RackMount";
286cf7eba09SNan Zhou             asyncResp->res.jsonValue["Actions"]["#Chassis.Reset"]["target"] =
287ef4c65b7SEd Tanous                 boost::urls::format(
288ef4c65b7SEd Tanous                     "/redfish/v1/Chassis/{}/Actions/Chassis.Reset", chassisId);
2891476687dSEd Tanous             asyncResp->res
290cf7eba09SNan Zhou                 .jsonValue["Actions"]["#Chassis.Reset"]["@Redfish.ActionInfo"] =
291ef4c65b7SEd Tanous                 boost::urls::format("/redfish/v1/Chassis/{}/ResetActionInfo",
292ef4c65b7SEd Tanous                                     chassisId);
2931476687dSEd Tanous             asyncResp->res.jsonValue["PCIeDevices"]["@odata.id"] =
294ef4c65b7SEd Tanous                 "/redfish/v1/Systems/system/PCIeDevices";
29549c53ac9SJohnathan Mantey 
2966c3e9451SGeorge Liu             dbus::utility::getAssociationEndPoints(
2976c3e9451SGeorge Liu                 path + "/drive",
2986c3e9451SGeorge Liu                 [asyncResp,
2996c3e9451SGeorge Liu                  chassisId](const boost::system::error_code& ec3,
3006c3e9451SGeorge Liu                             const dbus::utility::MapperEndPoints& resp) {
30192903bd4SJohn Edward Broadbent                 if (ec3 || resp.empty())
30292903bd4SJohn Edward Broadbent                 {
30392903bd4SJohn Edward Broadbent                     return; // no drives = no failures
30492903bd4SJohn Edward Broadbent                 }
30592903bd4SJohn Edward Broadbent 
30692903bd4SJohn Edward Broadbent                 nlohmann::json reference;
307ef4c65b7SEd Tanous                 reference["@odata.id"] = boost::urls::format(
308ef4c65b7SEd Tanous                     "/redfish/v1/Chassis/{}/Drives", chassisId);
30992903bd4SJohn Edward Broadbent                 asyncResp->res.jsonValue["Drives"] = std::move(reference);
31092903bd4SJohn Edward Broadbent                 });
31192903bd4SJohn Edward Broadbent 
312002d39b4SEd Tanous             const std::string& connectionName = connectionNames[0].first;
3131c8fba97SJames Feist 
31423a21a1cSEd Tanous             const std::vector<std::string>& interfaces2 =
3151c8fba97SJames Feist                 connectionNames[0].second;
3161c8fba97SJames Feist             const std::array<const char*, 2> hasIndicatorLed = {
3171c8fba97SJames Feist                 "xyz.openbmc_project.Inventory.Item.Panel",
3180fda0f12SGeorge Liu                 "xyz.openbmc_project.Inventory.Item.Board.Motherboard"};
3191c8fba97SJames Feist 
320476b9cc5STejas Patil             const std::string assetTagInterface =
3210fda0f12SGeorge Liu                 "xyz.openbmc_project.Inventory.Decorator.AssetTag";
322523d4868SLogananth Sundararaj             const std::string replaceableInterface =
323523d4868SLogananth Sundararaj                 "xyz.openbmc_project.Inventory.Decorator.Replaceable";
324523d4868SLogananth Sundararaj             for (const auto& interface : interfaces2)
325523d4868SLogananth Sundararaj             {
326523d4868SLogananth Sundararaj                 if (interface == assetTagInterface)
327476b9cc5STejas Patil                 {
3281e1e598dSJonathan Doman                     sdbusplus::asio::getProperty<std::string>(
329002d39b4SEd Tanous                         *crow::connections::systemBus, connectionName, path,
330002d39b4SEd Tanous                         assetTagInterface, "AssetTag",
331523d4868SLogananth Sundararaj                         [asyncResp,
332523d4868SLogananth Sundararaj                          chassisId](const boost::system::error_code& ec2,
3331e1e598dSJonathan Doman                                     const std::string& property) {
3348a592810SEd Tanous                         if (ec2)
335476b9cc5STejas Patil                         {
336523d4868SLogananth Sundararaj                             BMCWEB_LOG_ERROR
337523d4868SLogananth Sundararaj                                 << "DBus response error for AssetTag: " << ec2;
338476b9cc5STejas Patil                             messages::internalError(asyncResp->res);
339476b9cc5STejas Patil                             return;
340476b9cc5STejas Patil                         }
341002d39b4SEd Tanous                         asyncResp->res.jsonValue["AssetTag"] = property;
3421e1e598dSJonathan Doman                         });
343476b9cc5STejas Patil                 }
344523d4868SLogananth Sundararaj                 else if (interface == replaceableInterface)
345523d4868SLogananth Sundararaj                 {
346523d4868SLogananth Sundararaj                     sdbusplus::asio::getProperty<bool>(
347523d4868SLogananth Sundararaj                         *crow::connections::systemBus, connectionName, path,
348523d4868SLogananth Sundararaj                         replaceableInterface, "HotPluggable",
349523d4868SLogananth Sundararaj                         [asyncResp,
350523d4868SLogananth Sundararaj                          chassisId](const boost::system::error_code& ec2,
351523d4868SLogananth Sundararaj                                     const bool property) {
352523d4868SLogananth Sundararaj                         if (ec2)
353523d4868SLogananth Sundararaj                         {
354523d4868SLogananth Sundararaj                             BMCWEB_LOG_ERROR
355523d4868SLogananth Sundararaj                                 << "DBus response error for HotPluggable: "
356523d4868SLogananth Sundararaj                                 << ec2;
357523d4868SLogananth Sundararaj                             messages::internalError(asyncResp->res);
358523d4868SLogananth Sundararaj                             return;
359523d4868SLogananth Sundararaj                         }
360523d4868SLogananth Sundararaj                         asyncResp->res.jsonValue["HotPluggable"] = property;
361523d4868SLogananth Sundararaj                         });
362523d4868SLogananth Sundararaj                 }
363523d4868SLogananth Sundararaj             }
364476b9cc5STejas Patil 
3651c8fba97SJames Feist             for (const char* interface : hasIndicatorLed)
3661c8fba97SJames Feist             {
367002d39b4SEd Tanous                 if (std::find(interfaces2.begin(), interfaces2.end(),
36823a21a1cSEd Tanous                               interface) != interfaces2.end())
3691c8fba97SJames Feist                 {
3701c8fba97SJames Feist                     getIndicatorLedState(asyncResp);
3719f8bfa7cSGunnar Mills                     getLocationIndicatorActive(asyncResp);
3721c8fba97SJames Feist                     break;
3731c8fba97SJames Feist                 }
3741c8fba97SJames Feist             }
3751c8fba97SJames Feist 
37686d89ed7SKrzysztof Grobelny             sdbusplus::asio::getAllProperties(
37786d89ed7SKrzysztof Grobelny                 *crow::connections::systemBus, connectionName, path,
37886d89ed7SKrzysztof Grobelny                 "xyz.openbmc_project.Inventory.Decorator.Asset",
37962d5e2e4SEd Tanous                 [asyncResp, chassisId(std::string(chassisId))](
3805e7e2dc5SEd Tanous                     const boost::system::error_code& /*ec2*/,
381cf7eba09SNan Zhou                     const dbus::utility::DBusPropertiesMap& propertiesList) {
38286d89ed7SKrzysztof Grobelny                 const std::string* partNumber = nullptr;
38386d89ed7SKrzysztof Grobelny                 const std::string* serialNumber = nullptr;
38486d89ed7SKrzysztof Grobelny                 const std::string* manufacturer = nullptr;
38586d89ed7SKrzysztof Grobelny                 const std::string* model = nullptr;
38686d89ed7SKrzysztof Grobelny                 const std::string* sparePartNumber = nullptr;
38786d89ed7SKrzysztof Grobelny 
38886d89ed7SKrzysztof Grobelny                 const bool success = sdbusplus::unpackPropertiesNoThrow(
38986d89ed7SKrzysztof Grobelny                     dbus_utils::UnpackErrorPrinter(), propertiesList,
39086d89ed7SKrzysztof Grobelny                     "PartNumber", partNumber, "SerialNumber", serialNumber,
39186d89ed7SKrzysztof Grobelny                     "Manufacturer", manufacturer, "Model", model,
39286d89ed7SKrzysztof Grobelny                     "SparePartNumber", sparePartNumber);
39386d89ed7SKrzysztof Grobelny 
39486d89ed7SKrzysztof Grobelny                 if (!success)
3951abe55efSEd Tanous                 {
396002d39b4SEd Tanous                     messages::internalError(asyncResp->res);
397caa11f7aSAlpana Kumari                     return;
398daf36e2eSEd Tanous                 }
39986d89ed7SKrzysztof Grobelny 
40086d89ed7SKrzysztof Grobelny                 if (partNumber != nullptr)
40186d89ed7SKrzysztof Grobelny                 {
40286d89ed7SKrzysztof Grobelny                     asyncResp->res.jsonValue["PartNumber"] = *partNumber;
40386d89ed7SKrzysztof Grobelny                 }
40486d89ed7SKrzysztof Grobelny 
40586d89ed7SKrzysztof Grobelny                 if (serialNumber != nullptr)
40686d89ed7SKrzysztof Grobelny                 {
40786d89ed7SKrzysztof Grobelny                     asyncResp->res.jsonValue["SerialNumber"] = *serialNumber;
40886d89ed7SKrzysztof Grobelny                 }
40986d89ed7SKrzysztof Grobelny 
41086d89ed7SKrzysztof Grobelny                 if (manufacturer != nullptr)
41186d89ed7SKrzysztof Grobelny                 {
41286d89ed7SKrzysztof Grobelny                     asyncResp->res.jsonValue["Manufacturer"] = *manufacturer;
41386d89ed7SKrzysztof Grobelny                 }
41486d89ed7SKrzysztof Grobelny 
41586d89ed7SKrzysztof Grobelny                 if (model != nullptr)
41686d89ed7SKrzysztof Grobelny                 {
41786d89ed7SKrzysztof Grobelny                     asyncResp->res.jsonValue["Model"] = *model;
41886d89ed7SKrzysztof Grobelny                 }
41986d89ed7SKrzysztof Grobelny 
420caa11f7aSAlpana Kumari                 // SparePartNumber is optional on D-Bus
421caa11f7aSAlpana Kumari                 // so skip if it is empty
42286d89ed7SKrzysztof Grobelny                 if (sparePartNumber != nullptr && !sparePartNumber->empty())
423caa11f7aSAlpana Kumari                 {
42486d89ed7SKrzysztof Grobelny                     asyncResp->res.jsonValue["SparePartNumber"] =
42586d89ed7SKrzysztof Grobelny                         *sparePartNumber;
426caa11f7aSAlpana Kumari                 }
42786d89ed7SKrzysztof Grobelny 
42862d5e2e4SEd Tanous                 asyncResp->res.jsonValue["Name"] = chassisId;
42962d5e2e4SEd Tanous                 asyncResp->res.jsonValue["Id"] = chassisId;
4300256b694Szhanghch05 #ifdef BMCWEB_ALLOW_DEPRECATED_POWER_THERMAL
431002d39b4SEd Tanous                 asyncResp->res.jsonValue["Thermal"]["@odata.id"] =
432ef4c65b7SEd Tanous                     boost::urls::format("/redfish/v1/Chassis/{}/Thermal",
433ef4c65b7SEd Tanous                                         chassisId);
4342474adfaSEd Tanous                 // Power object
4351476687dSEd Tanous                 asyncResp->res.jsonValue["Power"]["@odata.id"] =
436ef4c65b7SEd Tanous                     boost::urls::format("/redfish/v1/Chassis/{}/Power",
437ef4c65b7SEd Tanous                                         chassisId);
4380256b694Szhanghch05 #endif
4392973963eSXiaochao Ma #ifdef BMCWEB_NEW_POWERSUBSYSTEM_THERMALSUBSYSTEM
4402973963eSXiaochao Ma                 asyncResp->res.jsonValue["ThermalSubsystem"]["@odata.id"] =
441ef4c65b7SEd Tanous                     boost::urls::format(
442ef4c65b7SEd Tanous                         "/redfish/v1/Chassis/{}/ThermalSubsystem", chassisId);
44377b36437SChicago Duan                 asyncResp->res.jsonValue["PowerSubsystem"]["@odata.id"] =
444ef4c65b7SEd Tanous                     boost::urls::format("/redfish/v1/Chassis/{}/PowerSubsystem",
445ef4c65b7SEd Tanous                                         chassisId);
4464ca3ec3cSAlbert Zhang                 asyncResp->res.jsonValue["EnvironmentMetrics"]["@odata.id"] =
447ef4c65b7SEd Tanous                     boost::urls::format(
448ef4c65b7SEd Tanous                         "/redfish/v1/Chassis/{}/EnvironmentMetrics", chassisId);
4492973963eSXiaochao Ma #endif
45095a3ecadSAnthony Wilson                 // SensorCollection
451002d39b4SEd Tanous                 asyncResp->res.jsonValue["Sensors"]["@odata.id"] =
452ef4c65b7SEd Tanous                     boost::urls::format("/redfish/v1/Chassis/{}/Sensors",
453ef4c65b7SEd Tanous                                         chassisId);
454002d39b4SEd Tanous                 asyncResp->res.jsonValue["Status"]["State"] = "Enabled";
4551476687dSEd Tanous 
4561476687dSEd Tanous                 nlohmann::json::array_t computerSystems;
4571476687dSEd Tanous                 nlohmann::json::object_t system;
458002d39b4SEd Tanous                 system["@odata.id"] = "/redfish/v1/Systems/system";
459ad539545SPatrick Williams                 computerSystems.emplace_back(std::move(system));
460002d39b4SEd Tanous                 asyncResp->res.jsonValue["Links"]["ComputerSystems"] =
4611476687dSEd Tanous                     std::move(computerSystems);
4621476687dSEd Tanous 
4631476687dSEd Tanous                 nlohmann::json::array_t managedBy;
4641476687dSEd Tanous                 nlohmann::json::object_t manager;
465002d39b4SEd Tanous                 manager["@odata.id"] = "/redfish/v1/Managers/bmc";
466ad539545SPatrick Williams                 managedBy.emplace_back(std::move(manager));
4677e860f15SJohn Edward Broadbent                 asyncResp->res.jsonValue["Links"]["ManagedBy"] =
4681476687dSEd Tanous                     std::move(managedBy);
469beeca0aeSGunnar Mills                 getChassisState(asyncResp);
47086d89ed7SKrzysztof Grobelny                 });
4712c37b4b0SSharad Yadav 
472308f70c7SWilly Tu             for (const auto& interface : interfaces2)
4732c37b4b0SSharad Yadav             {
474308f70c7SWilly Tu                 if (interface == "xyz.openbmc_project.Common.UUID")
4752c37b4b0SSharad Yadav                 {
476308f70c7SWilly Tu                     getChassisUUID(asyncResp, connectionName, path);
4772c37b4b0SSharad Yadav                 }
478cf7eba09SNan Zhou                 else if (interface ==
4790fda0f12SGeorge Liu                          "xyz.openbmc_project.Inventory.Decorator.LocationCode")
4802c37b4b0SSharad Yadav                 {
481002d39b4SEd Tanous                     getChassisLocationCode(asyncResp, connectionName, path);
4822c37b4b0SSharad Yadav                 }
4832c37b4b0SSharad Yadav             }
4842c37b4b0SSharad Yadav 
485daf36e2eSEd Tanous             return;
486daf36e2eSEd Tanous         }
487e0d918bcSEd Tanous 
488daf36e2eSEd Tanous         // Couldn't find an object with that name.  return an error
489d8a5d5d8SJiaqing Zhao         messages::resourceNotFound(asyncResp->res, "Chassis", chassisId);
490e99073f5SGeorge Liu         });
491c181942fSQiang XU 
492c181942fSQiang XU     getPhysicalSecurityData(asyncResp);
493cf7eba09SNan Zhou }
4941c8fba97SJames Feist 
495cf7eba09SNan Zhou inline void
496cf7eba09SNan Zhou     handleChassisPatch(App& app, const crow::Request& req,
4977e860f15SJohn Edward Broadbent                        const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
498cf7eba09SNan Zhou                        const std::string& param)
499cf7eba09SNan Zhou {
5003ba00073SCarson Labrado     if (!redfish::setUpRedfishRoute(app, req, asyncResp))
50145ca1b86SEd Tanous     {
50245ca1b86SEd Tanous         return;
50345ca1b86SEd Tanous     }
5049f8bfa7cSGunnar Mills     std::optional<bool> locationIndicatorActive;
5051c8fba97SJames Feist     std::optional<std::string> indicatorLed;
5061c8fba97SJames Feist 
5077e860f15SJohn Edward Broadbent     if (param.empty())
5081c8fba97SJames Feist     {
5091c8fba97SJames Feist         return;
5101c8fba97SJames Feist     }
5111c8fba97SJames Feist 
51215ed6780SWilly Tu     if (!json_util::readJsonPatch(
5137e860f15SJohn Edward Broadbent             req, asyncResp->res, "LocationIndicatorActive",
5147e860f15SJohn Edward Broadbent             locationIndicatorActive, "IndicatorLED", indicatorLed))
5151c8fba97SJames Feist     {
5161c8fba97SJames Feist         return;
5171c8fba97SJames Feist     }
5181c8fba97SJames Feist 
5199f8bfa7cSGunnar Mills     // TODO (Gunnar): Remove IndicatorLED after enough time has passed
5209f8bfa7cSGunnar Mills     if (!locationIndicatorActive && !indicatorLed)
5211c8fba97SJames Feist     {
5221c8fba97SJames Feist         return; // delete this when we support more patch properties
5231c8fba97SJames Feist     }
524d6aa0093SGunnar Mills     if (indicatorLed)
525d6aa0093SGunnar Mills     {
5267e860f15SJohn Edward Broadbent         asyncResp->res.addHeader(
5277e860f15SJohn Edward Broadbent             boost::beast::http::field::warning,
5280fda0f12SGeorge Liu             "299 - \"IndicatorLED is deprecated. Use LocationIndicatorActive instead.\"");
529d6aa0093SGunnar Mills     }
5301c8fba97SJames Feist 
531e99073f5SGeorge Liu     constexpr std::array<std::string_view, 2> interfaces = {
5321c8fba97SJames Feist         "xyz.openbmc_project.Inventory.Item.Board",
5331c8fba97SJames Feist         "xyz.openbmc_project.Inventory.Item.Chassis"};
5341c8fba97SJames Feist 
5357e860f15SJohn Edward Broadbent     const std::string& chassisId = param;
5361c8fba97SJames Feist 
537e99073f5SGeorge Liu     dbus::utility::getSubTree(
538e99073f5SGeorge Liu         "/xyz/openbmc_project/inventory", 0, interfaces,
539cf7eba09SNan Zhou         [asyncResp, chassisId, locationIndicatorActive,
5405e7e2dc5SEd Tanous          indicatorLed](const boost::system::error_code& ec,
541b9d36b47SEd Tanous                        const dbus::utility::MapperGetSubTreeResponse& subtree) {
5421c8fba97SJames Feist         if (ec)
5431c8fba97SJames Feist         {
544*51dab2a7SAndrew Geissler             BMCWEB_LOG_ERROR << "DBUS response error " << ec;
5451c8fba97SJames Feist             messages::internalError(asyncResp->res);
5461c8fba97SJames Feist             return;
5471c8fba97SJames Feist         }
5481c8fba97SJames Feist 
5491c8fba97SJames Feist         // Iterate over all retrieved ObjectPaths.
550cf7eba09SNan Zhou         for (const std::pair<
551cf7eba09SNan Zhou                  std::string,
552cf7eba09SNan Zhou                  std::vector<std::pair<std::string, std::vector<std::string>>>>&
5531214b7e7SGunnar Mills                  object : subtree)
5541c8fba97SJames Feist         {
5551c8fba97SJames Feist             const std::string& path = object.first;
556cf7eba09SNan Zhou             const std::vector<std::pair<std::string, std::vector<std::string>>>&
5571214b7e7SGunnar Mills                 connectionNames = object.second;
5581c8fba97SJames Feist 
559997093ebSGeorge Liu             sdbusplus::message::object_path objPath(path);
560997093ebSGeorge Liu             if (objPath.filename() != chassisId)
5611c8fba97SJames Feist             {
5621c8fba97SJames Feist                 continue;
5631c8fba97SJames Feist             }
5641c8fba97SJames Feist 
56526f6976fSEd Tanous             if (connectionNames.empty())
5661c8fba97SJames Feist             {
5671c8fba97SJames Feist                 BMCWEB_LOG_ERROR << "Got 0 Connection names";
5681c8fba97SJames Feist                 continue;
5691c8fba97SJames Feist             }
5701c8fba97SJames Feist 
57123a21a1cSEd Tanous             const std::vector<std::string>& interfaces3 =
5721c8fba97SJames Feist                 connectionNames[0].second;
5731c8fba97SJames Feist 
5741c8fba97SJames Feist             const std::array<const char*, 2> hasIndicatorLed = {
5751c8fba97SJames Feist                 "xyz.openbmc_project.Inventory.Item.Panel",
5760fda0f12SGeorge Liu                 "xyz.openbmc_project.Inventory.Item.Board.Motherboard"};
5771c8fba97SJames Feist             bool indicatorChassis = false;
5781c8fba97SJames Feist             for (const char* interface : hasIndicatorLed)
5791c8fba97SJames Feist             {
580002d39b4SEd Tanous                 if (std::find(interfaces3.begin(), interfaces3.end(),
58123a21a1cSEd Tanous                               interface) != interfaces3.end())
5821c8fba97SJames Feist                 {
5831c8fba97SJames Feist                     indicatorChassis = true;
5841c8fba97SJames Feist                     break;
5851c8fba97SJames Feist                 }
5861c8fba97SJames Feist             }
5879f8bfa7cSGunnar Mills             if (locationIndicatorActive)
5889f8bfa7cSGunnar Mills             {
5899f8bfa7cSGunnar Mills                 if (indicatorChassis)
5909f8bfa7cSGunnar Mills                 {
591002d39b4SEd Tanous                     setLocationIndicatorActive(asyncResp,
592002d39b4SEd Tanous                                                *locationIndicatorActive);
5939f8bfa7cSGunnar Mills                 }
5949f8bfa7cSGunnar Mills                 else
5959f8bfa7cSGunnar Mills                 {
596002d39b4SEd Tanous                     messages::propertyUnknown(asyncResp->res,
597002d39b4SEd Tanous                                               "LocationIndicatorActive");
5989f8bfa7cSGunnar Mills                 }
5999f8bfa7cSGunnar Mills             }
6009f8bfa7cSGunnar Mills             if (indicatorLed)
6019f8bfa7cSGunnar Mills             {
6021c8fba97SJames Feist                 if (indicatorChassis)
6031c8fba97SJames Feist                 {
604f23b7296SEd Tanous                     setIndicatorLedState(asyncResp, *indicatorLed);
6051c8fba97SJames Feist                 }
6061c8fba97SJames Feist                 else
6071c8fba97SJames Feist                 {
608cf7eba09SNan Zhou                     messages::propertyUnknown(asyncResp->res, "IndicatorLED");
6091c8fba97SJames Feist                 }
6101c8fba97SJames Feist             }
6111c8fba97SJames Feist             return;
6121c8fba97SJames Feist         }
6131c8fba97SJames Feist 
614d8a5d5d8SJiaqing Zhao         messages::resourceNotFound(asyncResp->res, "Chassis", chassisId);
615e99073f5SGeorge Liu         });
616cf7eba09SNan Zhou }
617cf7eba09SNan Zhou 
618cf7eba09SNan Zhou /**
619cf7eba09SNan Zhou  * Chassis override class for delivering Chassis Schema
620cf7eba09SNan Zhou  * Functions triggers appropriate requests on DBus
621cf7eba09SNan Zhou  */
622cf7eba09SNan Zhou inline void requestRoutesChassis(App& app)
623cf7eba09SNan Zhou {
624cf7eba09SNan Zhou     BMCWEB_ROUTE(app, "/redfish/v1/Chassis/<str>/")
625cf7eba09SNan Zhou         .privileges(redfish::privileges::getChassis)
626cf7eba09SNan Zhou         .methods(boost::beast::http::verb::get)(
627cf7eba09SNan Zhou             std::bind_front(handleChassisGet, std::ref(app)));
628cf7eba09SNan Zhou 
629cf7eba09SNan Zhou     BMCWEB_ROUTE(app, "/redfish/v1/Chassis/<str>/")
630cf7eba09SNan Zhou         .privileges(redfish::privileges::patchChassis)
631cf7eba09SNan Zhou         .methods(boost::beast::http::verb::patch)(
632cf7eba09SNan Zhou             std::bind_front(handleChassisPatch, std::ref(app)));
6331c8fba97SJames Feist }
634dd99e04bSP.K. Lee 
6358d1b46d7Szhanghch05 inline void
6368d1b46d7Szhanghch05     doChassisPowerCycle(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp)
637dd99e04bSP.K. Lee {
6387a1dbc48SGeorge Liu     constexpr std::array<std::string_view, 1> interfaces = {
639c3b3c92aSVijay Khemka         "xyz.openbmc_project.State.Chassis"};
640c3b3c92aSVijay Khemka 
641c3b3c92aSVijay Khemka     // Use mapper to get subtree paths.
6427a1dbc48SGeorge Liu     dbus::utility::getSubTreePaths(
6437a1dbc48SGeorge Liu         "/", 0, interfaces,
644b9d36b47SEd Tanous         [asyncResp](
6457a1dbc48SGeorge Liu             const boost::system::error_code& ec,
646b9d36b47SEd Tanous             const dbus::utility::MapperGetSubTreePathsResponse& chassisList) {
647c3b3c92aSVijay Khemka         if (ec)
648c3b3c92aSVijay Khemka         {
649*51dab2a7SAndrew Geissler             BMCWEB_LOG_ERROR << "[mapper] Bad D-Bus request error: " << ec;
650c3b3c92aSVijay Khemka             messages::internalError(asyncResp->res);
651c3b3c92aSVijay Khemka             return;
652c3b3c92aSVijay Khemka         }
653c3b3c92aSVijay Khemka 
654dd99e04bSP.K. Lee         const char* processName = "xyz.openbmc_project.State.Chassis";
655dd99e04bSP.K. Lee         const char* interfaceName = "xyz.openbmc_project.State.Chassis";
656dd99e04bSP.K. Lee         const char* destProperty = "RequestedPowerTransition";
657dd99e04bSP.K. Lee         const std::string propertyValue =
658dd99e04bSP.K. Lee             "xyz.openbmc_project.State.Chassis.Transition.PowerCycle";
659002d39b4SEd Tanous         std::string objectPath = "/xyz/openbmc_project/state/chassis_system0";
660c3b3c92aSVijay Khemka 
661c3b3c92aSVijay Khemka         /* Look for system reset chassis path */
662002d39b4SEd Tanous         if ((std::find(chassisList.begin(), chassisList.end(), objectPath)) ==
663002d39b4SEd Tanous             chassisList.end())
664c3b3c92aSVijay Khemka         {
665c3b3c92aSVijay Khemka             /* We prefer to reset the full chassis_system, but if it doesn't
666c3b3c92aSVijay Khemka              * exist on some platforms, fall back to a host-only power reset
667c3b3c92aSVijay Khemka              */
668c3b3c92aSVijay Khemka             objectPath = "/xyz/openbmc_project/state/chassis0";
669c3b3c92aSVijay Khemka         }
670dd99e04bSP.K. Lee 
671dd99e04bSP.K. Lee         crow::connections::systemBus->async_method_call(
6725e7e2dc5SEd Tanous             [asyncResp](const boost::system::error_code& ec2) {
673dd99e04bSP.K. Lee             // Use "Set" method to set the property value.
6748a592810SEd Tanous             if (ec2)
675dd99e04bSP.K. Lee             {
676*51dab2a7SAndrew Geissler                 BMCWEB_LOG_ERROR << "[Set] Bad D-Bus request error: " << ec2;
677dd99e04bSP.K. Lee                 messages::internalError(asyncResp->res);
678dd99e04bSP.K. Lee                 return;
679dd99e04bSP.K. Lee             }
680dd99e04bSP.K. Lee 
681dd99e04bSP.K. Lee             messages::success(asyncResp->res);
682dd99e04bSP.K. Lee             },
683002d39b4SEd Tanous             processName, objectPath, "org.freedesktop.DBus.Properties", "Set",
684002d39b4SEd Tanous             interfaceName, destProperty,
685168e20c1SEd Tanous             dbus::utility::DbusVariantType{propertyValue});
6867a1dbc48SGeorge Liu         });
687dd99e04bSP.K. Lee }
688dd99e04bSP.K. Lee 
689cf7eba09SNan Zhou inline void handleChassisResetActionInfoPost(
690cf7eba09SNan Zhou     App& app, const crow::Request& req,
6917e860f15SJohn Edward Broadbent     const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
692cf7eba09SNan Zhou     const std::string& /*chassisId*/)
693cf7eba09SNan Zhou {
6943ba00073SCarson Labrado     if (!redfish::setUpRedfishRoute(app, req, asyncResp))
69545ca1b86SEd Tanous     {
69645ca1b86SEd Tanous         return;
69745ca1b86SEd Tanous     }
698dd99e04bSP.K. Lee     BMCWEB_LOG_DEBUG << "Post Chassis Reset.";
699dd99e04bSP.K. Lee 
700dd99e04bSP.K. Lee     std::string resetType;
701dd99e04bSP.K. Lee 
702cf7eba09SNan Zhou     if (!json_util::readJsonAction(req, asyncResp->res, "ResetType", resetType))
703dd99e04bSP.K. Lee     {
704dd99e04bSP.K. Lee         return;
705dd99e04bSP.K. Lee     }
706dd99e04bSP.K. Lee 
707dd99e04bSP.K. Lee     if (resetType != "PowerCycle")
708dd99e04bSP.K. Lee     {
709dd99e04bSP.K. Lee         BMCWEB_LOG_DEBUG << "Invalid property value for ResetType: "
710dd99e04bSP.K. Lee                          << resetType;
711002d39b4SEd Tanous         messages::actionParameterNotSupported(asyncResp->res, resetType,
712002d39b4SEd Tanous                                               "ResetType");
713dd99e04bSP.K. Lee 
714dd99e04bSP.K. Lee         return;
715dd99e04bSP.K. Lee     }
716dd99e04bSP.K. Lee     doChassisPowerCycle(asyncResp);
717dd99e04bSP.K. Lee }
7181cb1a9e6SAppaRao Puli 
7191cb1a9e6SAppaRao Puli /**
720cf7eba09SNan Zhou  * ChassisResetAction class supports the POST method for the Reset
721cf7eba09SNan Zhou  * action.
722cf7eba09SNan Zhou  * Function handles POST method request.
723cf7eba09SNan Zhou  * Analyzes POST body before sending Reset request data to D-Bus.
7241cb1a9e6SAppaRao Puli  */
725cf7eba09SNan Zhou 
726cf7eba09SNan Zhou inline void requestRoutesChassisResetAction(App& app)
7271cb1a9e6SAppaRao Puli {
728cf7eba09SNan Zhou     BMCWEB_ROUTE(app, "/redfish/v1/Chassis/<str>/Actions/Chassis.Reset/")
729cf7eba09SNan Zhou         .privileges(redfish::privileges::postChassis)
730cf7eba09SNan Zhou         .methods(boost::beast::http::verb::post)(
731cf7eba09SNan Zhou             std::bind_front(handleChassisResetActionInfoPost, std::ref(app)));
732cf7eba09SNan Zhou }
733cf7eba09SNan Zhou 
734cf7eba09SNan Zhou inline void handleChassisResetActionInfoGet(
735cf7eba09SNan Zhou     App& app, const crow::Request& req,
7367e860f15SJohn Edward Broadbent     const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
737cf7eba09SNan Zhou     const std::string& chassisId)
738cf7eba09SNan Zhou {
7393ba00073SCarson Labrado     if (!redfish::setUpRedfishRoute(app, req, asyncResp))
7401cb1a9e6SAppaRao Puli     {
74145ca1b86SEd Tanous         return;
74245ca1b86SEd Tanous     }
743cf7eba09SNan Zhou     asyncResp->res.jsonValue["@odata.type"] = "#ActionInfo.v1_1_2.ActionInfo";
744ef4c65b7SEd Tanous     asyncResp->res.jsonValue["@odata.id"] = boost::urls::format(
745ef4c65b7SEd Tanous         "/redfish/v1/Chassis/{}/ResetActionInfo", chassisId);
7461476687dSEd Tanous     asyncResp->res.jsonValue["Name"] = "Reset Action Info";
7471476687dSEd Tanous 
7481476687dSEd Tanous     asyncResp->res.jsonValue["Id"] = "ResetActionInfo";
7495b9e95a1SNan Zhou     nlohmann::json::array_t parameters;
7505b9e95a1SNan Zhou     nlohmann::json::object_t parameter;
7515b9e95a1SNan Zhou     parameter["Name"] = "ResetType";
7525b9e95a1SNan Zhou     parameter["Required"] = true;
7535b9e95a1SNan Zhou     parameter["DataType"] = "String";
7541476687dSEd Tanous     nlohmann::json::array_t allowed;
755ad539545SPatrick Williams     allowed.emplace_back("PowerCycle");
7565b9e95a1SNan Zhou     parameter["AllowableValues"] = std::move(allowed);
757ad539545SPatrick Williams     parameters.emplace_back(std::move(parameter));
7585b9e95a1SNan Zhou 
7591476687dSEd Tanous     asyncResp->res.jsonValue["Parameters"] = std::move(parameters);
760cf7eba09SNan Zhou }
761cf7eba09SNan Zhou 
762cf7eba09SNan Zhou /**
763cf7eba09SNan Zhou  * ChassisResetActionInfo derived class for delivering Chassis
764cf7eba09SNan Zhou  * ResetType AllowableValues using ResetInfo schema.
765cf7eba09SNan Zhou  */
766cf7eba09SNan Zhou inline void requestRoutesChassisResetActionInfo(App& app)
767cf7eba09SNan Zhou {
768cf7eba09SNan Zhou     BMCWEB_ROUTE(app, "/redfish/v1/Chassis/<str>/ResetActionInfo/")
769cf7eba09SNan Zhou         .privileges(redfish::privileges::getActionInfo)
770cf7eba09SNan Zhou         .methods(boost::beast::http::verb::get)(
771cf7eba09SNan Zhou             std::bind_front(handleChassisResetActionInfoGet, std::ref(app)));
7721cb1a9e6SAppaRao Puli }
7731cb1a9e6SAppaRao Puli 
774e37f8451SRapkiewicz, Pawel } // namespace redfish
775