blob: c64d27c3352bcf4639c4604b9fc270d4e84d82c2 [file] [log] [blame]
Rapkiewicz, Pawele37f8452018-03-09 13:49:50 +01001/*
2// Copyright (c) 2018 Intel Corporation
3//
4// Licensed under the Apache License, Version 2.0 (the "License");
5// you may not use this file except in compliance with the License.
6// You may obtain a copy of the License at
7//
8// http://www.apache.org/licenses/LICENSE-2.0
9//
10// Unless required by applicable law or agreed to in writing, software
11// distributed under the License is distributed on an "AS IS" BASIS,
12// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13// See the License for the specific language governing permissions and
14// limitations under the License.
15*/
16#pragma once
17
Ed Tanous3ccb3ad2023-01-13 17:40:03 -080018#include "app.hpp"
George Liu7a1dbc42022-12-07 16:03:22 +080019#include "dbus_utility.hpp"
James Feistb49ac872019-05-21 15:12:01 -070020#include "health.hpp"
James Feist1c8fba92019-12-20 15:12:07 -080021#include "led.hpp"
Ed Tanous3ccb3ad2023-01-13 17:40:03 -080022#include "query.hpp"
23#include "registries/privilege_registry.hpp"
24#include "utils/collection.hpp"
25#include "utils/dbus_utils.hpp"
Nan Zhoucf7eba02022-07-21 23:53:20 +000026#include "utils/json_utils.hpp"
Ed Tanous1abe55e2018-09-05 08:30:59 -070027
George Liue99073f2022-12-09 11:06:16 +080028#include <boost/system/error_code.hpp>
Jonathan Doman1e1e5982021-06-11 09:36:17 -070029#include <sdbusplus/asio/property.hpp>
Krzysztof Grobelny86d89ed2022-08-29 14:49:20 +020030#include <sdbusplus/unpack_properties.hpp>
Gunnar Mills1214b7e2020-06-04 10:11:30 -050031
George Liu7a1dbc42022-12-07 16:03:22 +080032#include <array>
33#include <string_view>
34
Ed Tanous1abe55e2018-09-05 08:30:59 -070035namespace redfish
36{
Rapkiewicz, Pawele37f8452018-03-09 13:49:50 +010037
38/**
Gunnar Millsbeeca0a2019-02-14 16:30:45 -060039 * @brief Retrieves chassis state properties over dbus
40 *
41 * @param[in] aResp - Shared pointer for completing asynchronous calls.
42 *
43 * @return None.
44 */
zhanghch058d1b46d2021-04-01 11:18:24 +080045inline void getChassisState(std::shared_ptr<bmcweb::AsyncResp> aResp)
Gunnar Millsbeeca0a2019-02-14 16:30:45 -060046{
Jonathan Doman1e1e5982021-06-11 09:36:17 -070047 // crow::connections::systemBus->async_method_call(
48 sdbusplus::asio::getProperty<std::string>(
49 *crow::connections::systemBus, "xyz.openbmc_project.State.Chassis",
50 "/xyz/openbmc_project/state/chassis0",
51 "xyz.openbmc_project.State.Chassis", "CurrentPowerState",
Ed Tanous5e7e2dc2023-02-16 10:37:01 -080052 [aResp{std::move(aResp)}](const boost::system::error_code& ec,
Jonathan Doman1e1e5982021-06-11 09:36:17 -070053 const std::string& chassisState) {
Ed Tanous002d39b2022-05-31 08:59:27 -070054 if (ec)
55 {
56 if (ec == boost::system::errc::host_unreachable)
Gunnar Millsbeeca0a2019-02-14 16:30:45 -060057 {
Ed Tanous002d39b2022-05-31 08:59:27 -070058 // Service not available, no error, just don't return
59 // chassis state info
60 BMCWEB_LOG_DEBUG << "Service not available " << ec;
Gunnar Millsbeeca0a2019-02-14 16:30:45 -060061 return;
62 }
Ed Tanous002d39b2022-05-31 08:59:27 -070063 BMCWEB_LOG_DEBUG << "DBUS response error " << ec;
64 messages::internalError(aResp->res);
65 return;
66 }
Gunnar Millsbeeca0a2019-02-14 16:30:45 -060067
Ed Tanous002d39b2022-05-31 08:59:27 -070068 BMCWEB_LOG_DEBUG << "Chassis state: " << chassisState;
69 // Verify Chassis State
70 if (chassisState == "xyz.openbmc_project.State.Chassis.PowerState.On")
71 {
72 aResp->res.jsonValue["PowerState"] = "On";
73 aResp->res.jsonValue["Status"]["State"] = "Enabled";
74 }
75 else if (chassisState ==
76 "xyz.openbmc_project.State.Chassis.PowerState.Off")
77 {
78 aResp->res.jsonValue["PowerState"] = "Off";
79 aResp->res.jsonValue["Status"]["State"] = "StandbyOffline";
80 }
Jonathan Doman1e1e5982021-06-11 09:36:17 -070081 });
Gunnar Millsbeeca0a2019-02-14 16:30:45 -060082}
83
zhanghch058d1b46d2021-04-01 11:18:24 +080084inline void getIntrusionByService(std::shared_ptr<bmcweb::AsyncResp> aResp,
Ed Tanous23a21a12020-07-25 04:45:05 +000085 const std::string& service,
86 const std::string& objPath)
Qiang XUc1819422019-02-27 13:51:32 +080087{
88 BMCWEB_LOG_DEBUG << "Get intrusion status by service \n";
89
Jonathan Doman1e1e5982021-06-11 09:36:17 -070090 sdbusplus::asio::getProperty<std::string>(
91 *crow::connections::systemBus, service, objPath,
92 "xyz.openbmc_project.Chassis.Intrusion", "Status",
Ed Tanous5e7e2dc2023-02-16 10:37:01 -080093 [aResp{std::move(aResp)}](const boost::system::error_code& ec,
Jonathan Doman1e1e5982021-06-11 09:36:17 -070094 const std::string& value) {
Ed Tanous002d39b2022-05-31 08:59:27 -070095 if (ec)
96 {
97 // do not add err msg in redfish response, because this is not
98 // mandatory property
99 BMCWEB_LOG_ERROR << "DBUS response error " << ec << "\n";
100 return;
101 }
Qiang XUc1819422019-02-27 13:51:32 +0800102
Ed Tanous002d39b2022-05-31 08:59:27 -0700103 aResp->res.jsonValue["PhysicalSecurity"]["IntrusionSensorNumber"] = 1;
104 aResp->res.jsonValue["PhysicalSecurity"]["IntrusionSensor"] = value;
Jonathan Doman1e1e5982021-06-11 09:36:17 -0700105 });
Qiang XUc1819422019-02-27 13:51:32 +0800106}
107
108/**
109 * Retrieves physical security properties over dbus
110 */
zhanghch058d1b46d2021-04-01 11:18:24 +0800111inline void getPhysicalSecurityData(std::shared_ptr<bmcweb::AsyncResp> aResp)
Qiang XUc1819422019-02-27 13:51:32 +0800112{
George Liue99073f2022-12-09 11:06:16 +0800113 constexpr std::array<std::string_view, 1> interfaces = {
114 "xyz.openbmc_project.Chassis.Intrusion"};
115 dbus::utility::getSubTree(
116 "/xyz/openbmc_project/Intrusion", 1, interfaces,
Qiang XUc1819422019-02-27 13:51:32 +0800117 [aResp{std::move(aResp)}](
George Liue99073f2022-12-09 11:06:16 +0800118 const boost::system::error_code& ec,
Ed Tanousb9d36b42022-02-26 21:42:46 -0800119 const dbus::utility::MapperGetSubTreeResponse& subtree) {
Ed Tanous002d39b2022-05-31 08:59:27 -0700120 if (ec)
121 {
122 // do not add err msg in redfish response, because this is not
123 // mandatory property
124 BMCWEB_LOG_INFO << "DBUS error: no matched iface " << ec << "\n";
125 return;
126 }
127 // Iterate over all retrieved ObjectPaths.
128 for (const auto& object : subtree)
129 {
Patrick Williams840a9ff2023-05-12 10:18:43 -0500130 if (!object.second.empty())
Qiang XUc1819422019-02-27 13:51:32 +0800131 {
Patrick Williams840a9ff2023-05-12 10:18:43 -0500132 const auto service = object.second.front();
Ed Tanous002d39b2022-05-31 08:59:27 -0700133 getIntrusionByService(aResp, service.first, object.first);
Qiang XUc1819422019-02-27 13:51:32 +0800134 return;
135 }
Ed Tanous002d39b2022-05-31 08:59:27 -0700136 }
George Liue99073f2022-12-09 11:06:16 +0800137 });
Qiang XUc1819422019-02-27 13:51:32 +0800138}
139
Nan Zhoucf7eba02022-07-21 23:53:20 +0000140inline void handleChassisCollectionGet(
141 App& app, const crow::Request& req,
142 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp)
143{
144 if (!redfish::setUpRedfishRoute(app, req, asyncResp))
145 {
146 return;
147 }
148 asyncResp->res.jsonValue["@odata.type"] =
149 "#ChassisCollection.ChassisCollection";
150 asyncResp->res.jsonValue["@odata.id"] = "/redfish/v1/Chassis";
151 asyncResp->res.jsonValue["Name"] = "Chassis Collection";
152
George Liu7a1dbc42022-12-07 16:03:22 +0800153 constexpr std::array<std::string_view, 2> interfaces{
154 "xyz.openbmc_project.Inventory.Item.Board",
155 "xyz.openbmc_project.Inventory.Item.Chassis"};
Nan Zhoucf7eba02022-07-21 23:53:20 +0000156 collection_util::getCollectionMembers(
George Liu7a1dbc42022-12-07 16:03:22 +0800157 asyncResp, boost::urls::url("/redfish/v1/Chassis"), interfaces);
Nan Zhoucf7eba02022-07-21 23:53:20 +0000158}
159
Rapkiewicz, Pawele37f8452018-03-09 13:49:50 +0100160/**
Rapkiewicz, Pawele37f8452018-03-09 13:49:50 +0100161 * ChassisCollection derived class for delivering Chassis Collection Schema
John Edward Broadbent7e860f12021-04-08 15:57:16 -0700162 * Functions triggers appropriate requests on DBus
Rapkiewicz, Pawele37f8452018-03-09 13:49:50 +0100163 */
John Edward Broadbent7e860f12021-04-08 15:57:16 -0700164inline void requestRoutesChassisCollection(App& app)
Ed Tanous1abe55e2018-09-05 08:30:59 -0700165{
John Edward Broadbent7e860f12021-04-08 15:57:16 -0700166 BMCWEB_ROUTE(app, "/redfish/v1/Chassis/")
Ed Tanoused398212021-06-09 17:05:54 -0700167 .privileges(redfish::privileges::getChassisCollection)
John Edward Broadbent7e860f12021-04-08 15:57:16 -0700168 .methods(boost::beast::http::verb::get)(
Nan Zhoucf7eba02022-07-21 23:53:20 +0000169 std::bind_front(handleChassisCollectionGet, std::ref(app)));
John Edward Broadbent7e860f12021-04-08 15:57:16 -0700170}
Rapkiewicz, Pawele37f8452018-03-09 13:49:50 +0100171
Willy Tu308f70c2021-09-28 20:24:52 -0700172inline void
173 getChassisLocationCode(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
174 const std::string& connectionName,
175 const std::string& path)
176{
Jonathan Doman1e1e5982021-06-11 09:36:17 -0700177 sdbusplus::asio::getProperty<std::string>(
178 *crow::connections::systemBus, connectionName, path,
179 "xyz.openbmc_project.Inventory.Decorator.LocationCode", "LocationCode",
Ed Tanous5e7e2dc2023-02-16 10:37:01 -0800180 [asyncResp](const boost::system::error_code& ec,
Jonathan Doman1e1e5982021-06-11 09:36:17 -0700181 const std::string& property) {
Ed Tanous002d39b2022-05-31 08:59:27 -0700182 if (ec)
183 {
184 BMCWEB_LOG_DEBUG << "DBUS response error for Location";
185 messages::internalError(asyncResp->res);
186 return;
187 }
Willy Tu308f70c2021-09-28 20:24:52 -0700188
Ed Tanous002d39b2022-05-31 08:59:27 -0700189 asyncResp->res.jsonValue["Location"]["PartLocation"]["ServiceLabel"] =
190 property;
Jonathan Doman1e1e5982021-06-11 09:36:17 -0700191 });
Willy Tu308f70c2021-09-28 20:24:52 -0700192}
193
194inline void getChassisUUID(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
195 const std::string& connectionName,
196 const std::string& path)
197{
Jonathan Doman1e1e5982021-06-11 09:36:17 -0700198 sdbusplus::asio::getProperty<std::string>(
199 *crow::connections::systemBus, connectionName, path,
200 "xyz.openbmc_project.Common.UUID", "UUID",
Ed Tanous5e7e2dc2023-02-16 10:37:01 -0800201 [asyncResp](const boost::system::error_code& ec,
Jonathan Doman1e1e5982021-06-11 09:36:17 -0700202 const std::string& chassisUUID) {
Ed Tanous002d39b2022-05-31 08:59:27 -0700203 if (ec)
204 {
205 BMCWEB_LOG_DEBUG << "DBUS response error for UUID";
206 messages::internalError(asyncResp->res);
207 return;
208 }
209 asyncResp->res.jsonValue["UUID"] = chassisUUID;
Jonathan Doman1e1e5982021-06-11 09:36:17 -0700210 });
Willy Tu308f70c2021-09-28 20:24:52 -0700211}
212
Nan Zhoucf7eba02022-07-21 23:53:20 +0000213inline void
214 handleChassisGet(App& app, const crow::Request& req,
215 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
216 const std::string& chassisId)
217{
218 if (!redfish::setUpRedfishRoute(app, req, asyncResp))
219 {
220 return;
221 }
George Liue99073f2022-12-09 11:06:16 +0800222 constexpr std::array<std::string_view, 2> interfaces = {
Nan Zhoucf7eba02022-07-21 23:53:20 +0000223 "xyz.openbmc_project.Inventory.Item.Board",
224 "xyz.openbmc_project.Inventory.Item.Chassis"};
225
George Liue99073f2022-12-09 11:06:16 +0800226 dbus::utility::getSubTree(
227 "/xyz/openbmc_project/inventory", 0, interfaces,
Nan Zhoucf7eba02022-07-21 23:53:20 +0000228 [asyncResp, chassisId(std::string(chassisId))](
George Liue99073f2022-12-09 11:06:16 +0800229 const boost::system::error_code& ec,
Nan Zhoucf7eba02022-07-21 23:53:20 +0000230 const dbus::utility::MapperGetSubTreeResponse& subtree) {
231 if (ec)
232 {
233 messages::internalError(asyncResp->res);
234 return;
235 }
236 // Iterate over all retrieved ObjectPaths.
237 for (const std::pair<
238 std::string,
239 std::vector<std::pair<std::string, std::vector<std::string>>>>&
240 object : subtree)
241 {
242 const std::string& path = object.first;
243 const std::vector<std::pair<std::string, std::vector<std::string>>>&
244 connectionNames = object.second;
245
246 sdbusplus::message::object_path objPath(path);
247 if (objPath.filename() != chassisId)
248 {
249 continue;
250 }
251
252 auto health = std::make_shared<HealthPopulate>(asyncResp);
253
George Liu6c3e9452023-03-03 13:55:29 +0800254 dbus::utility::getAssociationEndPoints(
255 path + "/all_sensors",
Ed Tanous5e7e2dc2023-02-16 10:37:01 -0800256 [health](const boost::system::error_code& ec2,
George Liu6c3e9452023-03-03 13:55:29 +0800257 const dbus::utility::MapperEndPoints& resp) {
Nan Zhoucf7eba02022-07-21 23:53:20 +0000258 if (ec2)
259 {
260 return; // no sensors = no failures
261 }
262 health->inventory = resp;
263 });
264
265 health->populate();
266
267 if (connectionNames.empty())
268 {
269 BMCWEB_LOG_ERROR << "Got 0 Connection names";
270 continue;
271 }
272
273 asyncResp->res.jsonValue["@odata.type"] =
Logananth Sundararaj523d4862023-01-24 11:56:28 +0530274 "#Chassis.v1_22_0.Chassis";
Nan Zhoucf7eba02022-07-21 23:53:20 +0000275 asyncResp->res.jsonValue["@odata.id"] =
Willy Tueddfc432022-09-26 16:46:38 +0000276 crow::utility::urlFromPieces("redfish", "v1", "Chassis",
277 chassisId);
Nan Zhoucf7eba02022-07-21 23:53:20 +0000278 asyncResp->res.jsonValue["Name"] = "Chassis Collection";
279 asyncResp->res.jsonValue["ChassisType"] = "RackMount";
280 asyncResp->res.jsonValue["Actions"]["#Chassis.Reset"]["target"] =
Willy Tueddfc432022-09-26 16:46:38 +0000281 crow::utility::urlFromPieces("redfish", "v1", "Chassis",
282 chassisId, "Actions",
283 "Chassis.Reset");
Nan Zhoucf7eba02022-07-21 23:53:20 +0000284 asyncResp->res
285 .jsonValue["Actions"]["#Chassis.Reset"]["@Redfish.ActionInfo"] =
Willy Tueddfc432022-09-26 16:46:38 +0000286 crow::utility::urlFromPieces("redfish", "v1", "Chassis",
287 chassisId, "ResetActionInfo");
Nan Zhoucf7eba02022-07-21 23:53:20 +0000288 asyncResp->res.jsonValue["PCIeDevices"]["@odata.id"] =
Willy Tueddfc432022-09-26 16:46:38 +0000289 crow::utility::urlFromPieces("redfish", "v1", "Systems",
290 "system", "PCIeDevices");
Nan Zhoucf7eba02022-07-21 23:53:20 +0000291
George Liu6c3e9452023-03-03 13:55:29 +0800292 dbus::utility::getAssociationEndPoints(
293 path + "/drive",
294 [asyncResp,
295 chassisId](const boost::system::error_code& ec3,
296 const dbus::utility::MapperEndPoints& resp) {
Nan Zhoucf7eba02022-07-21 23:53:20 +0000297 if (ec3 || resp.empty())
298 {
299 return; // no drives = no failures
300 }
301
302 nlohmann::json reference;
John Edward Broadbenta0cb40c2022-06-29 17:27:38 -0700303 reference["@odata.id"] = crow::utility::urlFromPieces(
Nan Zhoucf7eba02022-07-21 23:53:20 +0000304 "redfish", "v1", "Chassis", chassisId, "Drives");
305 asyncResp->res.jsonValue["Drives"] = std::move(reference);
306 });
307
308 const std::string& connectionName = connectionNames[0].first;
309
310 const std::vector<std::string>& interfaces2 =
311 connectionNames[0].second;
312 const std::array<const char*, 2> hasIndicatorLed = {
313 "xyz.openbmc_project.Inventory.Item.Panel",
314 "xyz.openbmc_project.Inventory.Item.Board.Motherboard"};
315
316 const std::string assetTagInterface =
317 "xyz.openbmc_project.Inventory.Decorator.AssetTag";
Logananth Sundararaj523d4862023-01-24 11:56:28 +0530318 const std::string replaceableInterface =
319 "xyz.openbmc_project.Inventory.Decorator.Replaceable";
320 for (const auto& interface : interfaces2)
Nan Zhoucf7eba02022-07-21 23:53:20 +0000321 {
Logananth Sundararaj523d4862023-01-24 11:56:28 +0530322 if (interface == assetTagInterface)
323 {
324 sdbusplus::asio::getProperty<std::string>(
325 *crow::connections::systemBus, connectionName, path,
326 assetTagInterface, "AssetTag",
327 [asyncResp,
328 chassisId](const boost::system::error_code& ec2,
329 const std::string& property) {
330 if (ec2)
331 {
332 BMCWEB_LOG_ERROR
333 << "DBus response error for AssetTag: " << ec2;
334 messages::internalError(asyncResp->res);
335 return;
336 }
337 asyncResp->res.jsonValue["AssetTag"] = property;
338 });
339 }
340 else if (interface == replaceableInterface)
341 {
342 sdbusplus::asio::getProperty<bool>(
343 *crow::connections::systemBus, connectionName, path,
344 replaceableInterface, "HotPluggable",
345 [asyncResp,
346 chassisId](const boost::system::error_code& ec2,
347 const bool property) {
348 if (ec2)
349 {
350 BMCWEB_LOG_ERROR
351 << "DBus response error for HotPluggable: "
352 << ec2;
353 messages::internalError(asyncResp->res);
354 return;
355 }
356 asyncResp->res.jsonValue["HotPluggable"] = property;
357 });
358 }
Nan Zhoucf7eba02022-07-21 23:53:20 +0000359 }
360
361 for (const char* interface : hasIndicatorLed)
362 {
363 if (std::find(interfaces2.begin(), interfaces2.end(),
364 interface) != interfaces2.end())
365 {
366 getIndicatorLedState(asyncResp);
367 getLocationIndicatorActive(asyncResp);
368 break;
369 }
370 }
371
Krzysztof Grobelny86d89ed2022-08-29 14:49:20 +0200372 sdbusplus::asio::getAllProperties(
373 *crow::connections::systemBus, connectionName, path,
374 "xyz.openbmc_project.Inventory.Decorator.Asset",
Nan Zhoucf7eba02022-07-21 23:53:20 +0000375 [asyncResp, chassisId(std::string(chassisId))](
Ed Tanous5e7e2dc2023-02-16 10:37:01 -0800376 const boost::system::error_code& /*ec2*/,
Nan Zhoucf7eba02022-07-21 23:53:20 +0000377 const dbus::utility::DBusPropertiesMap& propertiesList) {
Krzysztof Grobelny86d89ed2022-08-29 14:49:20 +0200378 const std::string* partNumber = nullptr;
379 const std::string* serialNumber = nullptr;
380 const std::string* manufacturer = nullptr;
381 const std::string* model = nullptr;
382 const std::string* sparePartNumber = nullptr;
383
384 const bool success = sdbusplus::unpackPropertiesNoThrow(
385 dbus_utils::UnpackErrorPrinter(), propertiesList,
386 "PartNumber", partNumber, "SerialNumber", serialNumber,
387 "Manufacturer", manufacturer, "Model", model,
388 "SparePartNumber", sparePartNumber);
389
390 if (!success)
Nan Zhoucf7eba02022-07-21 23:53:20 +0000391 {
Krzysztof Grobelny86d89ed2022-08-29 14:49:20 +0200392 messages::internalError(asyncResp->res);
393 return;
Nan Zhoucf7eba02022-07-21 23:53:20 +0000394 }
Krzysztof Grobelny86d89ed2022-08-29 14:49:20 +0200395
396 if (partNumber != nullptr)
397 {
398 asyncResp->res.jsonValue["PartNumber"] = *partNumber;
399 }
400
401 if (serialNumber != nullptr)
402 {
403 asyncResp->res.jsonValue["SerialNumber"] = *serialNumber;
404 }
405
406 if (manufacturer != nullptr)
407 {
408 asyncResp->res.jsonValue["Manufacturer"] = *manufacturer;
409 }
410
411 if (model != nullptr)
412 {
413 asyncResp->res.jsonValue["Model"] = *model;
414 }
415
416 // SparePartNumber is optional on D-Bus
417 // so skip if it is empty
418 if (sparePartNumber != nullptr && !sparePartNumber->empty())
419 {
420 asyncResp->res.jsonValue["SparePartNumber"] =
421 *sparePartNumber;
422 }
423
Nan Zhoucf7eba02022-07-21 23:53:20 +0000424 asyncResp->res.jsonValue["Name"] = chassisId;
425 asyncResp->res.jsonValue["Id"] = chassisId;
426#ifdef BMCWEB_ALLOW_DEPRECATED_POWER_THERMAL
427 asyncResp->res.jsonValue["Thermal"]["@odata.id"] =
Willy Tueddfc432022-09-26 16:46:38 +0000428 crow::utility::urlFromPieces("redfish", "v1", "Chassis",
429 chassisId, "Thermal");
Nan Zhoucf7eba02022-07-21 23:53:20 +0000430 // Power object
431 asyncResp->res.jsonValue["Power"]["@odata.id"] =
Willy Tueddfc432022-09-26 16:46:38 +0000432 crow::utility::urlFromPieces("redfish", "v1", "Chassis",
433 chassisId, "Power");
Nan Zhoucf7eba02022-07-21 23:53:20 +0000434#endif
Xiaochao Ma29739632021-03-02 15:53:13 +0800435#ifdef BMCWEB_NEW_POWERSUBSYSTEM_THERMALSUBSYSTEM
436 asyncResp->res.jsonValue["ThermalSubsystem"]["@odata.id"] =
437 crow::utility::urlFromPieces("redfish", "v1", "Chassis",
438 chassisId, "ThermalSubsystem");
Chicago Duan77b36432021-02-05 15:48:26 +0800439 asyncResp->res.jsonValue["PowerSubsystem"]["@odata.id"] =
440 crow::utility::urlFromPieces("redfish", "v1", "Chassis",
441 chassisId, "PowerSubsystem");
Albert Zhang4ca3ec32021-06-13 14:39:38 +0800442 asyncResp->res.jsonValue["EnvironmentMetrics"]["@odata.id"] =
443 crow::utility::urlFromPieces("redfish", "v1", "Chassis",
444 chassisId,
445 "EnvironmentMetrics");
Xiaochao Ma29739632021-03-02 15:53:13 +0800446#endif
Nan Zhoucf7eba02022-07-21 23:53:20 +0000447 // SensorCollection
448 asyncResp->res.jsonValue["Sensors"]["@odata.id"] =
Willy Tueddfc432022-09-26 16:46:38 +0000449 crow::utility::urlFromPieces("redfish", "v1", "Chassis",
450 chassisId, "Sensors");
Nan Zhoucf7eba02022-07-21 23:53:20 +0000451 asyncResp->res.jsonValue["Status"]["State"] = "Enabled";
452
453 nlohmann::json::array_t computerSystems;
454 nlohmann::json::object_t system;
455 system["@odata.id"] = "/redfish/v1/Systems/system";
456 computerSystems.push_back(std::move(system));
457 asyncResp->res.jsonValue["Links"]["ComputerSystems"] =
458 std::move(computerSystems);
459
460 nlohmann::json::array_t managedBy;
461 nlohmann::json::object_t manager;
462 manager["@odata.id"] = "/redfish/v1/Managers/bmc";
463 managedBy.push_back(std::move(manager));
464 asyncResp->res.jsonValue["Links"]["ManagedBy"] =
465 std::move(managedBy);
466 getChassisState(asyncResp);
Krzysztof Grobelny86d89ed2022-08-29 14:49:20 +0200467 });
Nan Zhoucf7eba02022-07-21 23:53:20 +0000468
469 for (const auto& interface : interfaces2)
470 {
471 if (interface == "xyz.openbmc_project.Common.UUID")
472 {
473 getChassisUUID(asyncResp, connectionName, path);
474 }
475 else if (interface ==
476 "xyz.openbmc_project.Inventory.Decorator.LocationCode")
477 {
478 getChassisLocationCode(asyncResp, connectionName, path);
479 }
480 }
481
482 return;
483 }
484
485 // Couldn't find an object with that name. return an error
Jiaqing Zhaod8a5d5d2022-08-05 16:21:51 +0800486 messages::resourceNotFound(asyncResp->res, "Chassis", chassisId);
George Liue99073f2022-12-09 11:06:16 +0800487 });
Nan Zhoucf7eba02022-07-21 23:53:20 +0000488
489 getPhysicalSecurityData(asyncResp);
490}
491
492inline void
493 handleChassisPatch(App& app, const crow::Request& req,
494 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
495 const std::string& param)
496{
497 if (!redfish::setUpRedfishRoute(app, req, asyncResp))
498 {
499 return;
500 }
501 std::optional<bool> locationIndicatorActive;
502 std::optional<std::string> indicatorLed;
503
504 if (param.empty())
505 {
506 return;
507 }
508
509 if (!json_util::readJsonPatch(
510 req, asyncResp->res, "LocationIndicatorActive",
511 locationIndicatorActive, "IndicatorLED", indicatorLed))
512 {
513 return;
514 }
515
516 // TODO (Gunnar): Remove IndicatorLED after enough time has passed
517 if (!locationIndicatorActive && !indicatorLed)
518 {
519 return; // delete this when we support more patch properties
520 }
521 if (indicatorLed)
522 {
523 asyncResp->res.addHeader(
524 boost::beast::http::field::warning,
525 "299 - \"IndicatorLED is deprecated. Use LocationIndicatorActive instead.\"");
526 }
527
George Liue99073f2022-12-09 11:06:16 +0800528 constexpr std::array<std::string_view, 2> interfaces = {
Nan Zhoucf7eba02022-07-21 23:53:20 +0000529 "xyz.openbmc_project.Inventory.Item.Board",
530 "xyz.openbmc_project.Inventory.Item.Chassis"};
531
532 const std::string& chassisId = param;
533
George Liue99073f2022-12-09 11:06:16 +0800534 dbus::utility::getSubTree(
535 "/xyz/openbmc_project/inventory", 0, interfaces,
Nan Zhoucf7eba02022-07-21 23:53:20 +0000536 [asyncResp, chassisId, locationIndicatorActive,
Ed Tanous5e7e2dc2023-02-16 10:37:01 -0800537 indicatorLed](const boost::system::error_code& ec,
Nan Zhoucf7eba02022-07-21 23:53:20 +0000538 const dbus::utility::MapperGetSubTreeResponse& subtree) {
539 if (ec)
540 {
541 messages::internalError(asyncResp->res);
542 return;
543 }
544
545 // Iterate over all retrieved ObjectPaths.
546 for (const std::pair<
547 std::string,
548 std::vector<std::pair<std::string, std::vector<std::string>>>>&
549 object : subtree)
550 {
551 const std::string& path = object.first;
552 const std::vector<std::pair<std::string, std::vector<std::string>>>&
553 connectionNames = object.second;
554
555 sdbusplus::message::object_path objPath(path);
556 if (objPath.filename() != chassisId)
557 {
558 continue;
559 }
560
561 if (connectionNames.empty())
562 {
563 BMCWEB_LOG_ERROR << "Got 0 Connection names";
564 continue;
565 }
566
567 const std::vector<std::string>& interfaces3 =
568 connectionNames[0].second;
569
570 const std::array<const char*, 2> hasIndicatorLed = {
571 "xyz.openbmc_project.Inventory.Item.Panel",
572 "xyz.openbmc_project.Inventory.Item.Board.Motherboard"};
573 bool indicatorChassis = false;
574 for (const char* interface : hasIndicatorLed)
575 {
576 if (std::find(interfaces3.begin(), interfaces3.end(),
577 interface) != interfaces3.end())
578 {
579 indicatorChassis = true;
580 break;
581 }
582 }
583 if (locationIndicatorActive)
584 {
585 if (indicatorChassis)
586 {
587 setLocationIndicatorActive(asyncResp,
588 *locationIndicatorActive);
589 }
590 else
591 {
592 messages::propertyUnknown(asyncResp->res,
593 "LocationIndicatorActive");
594 }
595 }
596 if (indicatorLed)
597 {
598 if (indicatorChassis)
599 {
600 setIndicatorLedState(asyncResp, *indicatorLed);
601 }
602 else
603 {
604 messages::propertyUnknown(asyncResp->res, "IndicatorLED");
605 }
606 }
607 return;
608 }
609
Jiaqing Zhaod8a5d5d2022-08-05 16:21:51 +0800610 messages::resourceNotFound(asyncResp->res, "Chassis", chassisId);
George Liue99073f2022-12-09 11:06:16 +0800611 });
Nan Zhoucf7eba02022-07-21 23:53:20 +0000612}
613
Rapkiewicz, Pawele37f8452018-03-09 13:49:50 +0100614/**
615 * Chassis override class for delivering Chassis Schema
John Edward Broadbent7e860f12021-04-08 15:57:16 -0700616 * Functions triggers appropriate requests on DBus
Rapkiewicz, Pawele37f8452018-03-09 13:49:50 +0100617 */
John Edward Broadbent7e860f12021-04-08 15:57:16 -0700618inline void requestRoutesChassis(App& app)
Ed Tanous1abe55e2018-09-05 08:30:59 -0700619{
John Edward Broadbent7e860f12021-04-08 15:57:16 -0700620 BMCWEB_ROUTE(app, "/redfish/v1/Chassis/<str>/")
Ed Tanoused398212021-06-09 17:05:54 -0700621 .privileges(redfish::privileges::getChassis)
Ed Tanous002d39b2022-05-31 08:59:27 -0700622 .methods(boost::beast::http::verb::get)(
Nan Zhoucf7eba02022-07-21 23:53:20 +0000623 std::bind_front(handleChassisGet, std::ref(app)));
John Edward Broadbent7e860f12021-04-08 15:57:16 -0700624
625 BMCWEB_ROUTE(app, "/redfish/v1/Chassis/<str>/")
Ed Tanoused398212021-06-09 17:05:54 -0700626 .privileges(redfish::privileges::patchChassis)
Ed Tanous002d39b2022-05-31 08:59:27 -0700627 .methods(boost::beast::http::verb::patch)(
Nan Zhoucf7eba02022-07-21 23:53:20 +0000628 std::bind_front(handleChassisPatch, std::ref(app)));
John Edward Broadbent7e860f12021-04-08 15:57:16 -0700629}
P.K. Leedd99e042020-06-17 19:43:16 +0800630
zhanghch058d1b46d2021-04-01 11:18:24 +0800631inline void
632 doChassisPowerCycle(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp)
P.K. Leedd99e042020-06-17 19:43:16 +0800633{
George Liu7a1dbc42022-12-07 16:03:22 +0800634 constexpr std::array<std::string_view, 1> interfaces = {
Vijay Khemkac3b3c922020-09-22 23:00:12 -0700635 "xyz.openbmc_project.State.Chassis"};
636
637 // Use mapper to get subtree paths.
George Liu7a1dbc42022-12-07 16:03:22 +0800638 dbus::utility::getSubTreePaths(
639 "/", 0, interfaces,
Ed Tanousb9d36b42022-02-26 21:42:46 -0800640 [asyncResp](
George Liu7a1dbc42022-12-07 16:03:22 +0800641 const boost::system::error_code& ec,
Ed Tanousb9d36b42022-02-26 21:42:46 -0800642 const dbus::utility::MapperGetSubTreePathsResponse& chassisList) {
Ed Tanous002d39b2022-05-31 08:59:27 -0700643 if (ec)
644 {
645 BMCWEB_LOG_DEBUG << "[mapper] Bad D-Bus request error: " << ec;
646 messages::internalError(asyncResp->res);
647 return;
648 }
649
650 const char* processName = "xyz.openbmc_project.State.Chassis";
651 const char* interfaceName = "xyz.openbmc_project.State.Chassis";
652 const char* destProperty = "RequestedPowerTransition";
653 const std::string propertyValue =
654 "xyz.openbmc_project.State.Chassis.Transition.PowerCycle";
655 std::string objectPath = "/xyz/openbmc_project/state/chassis_system0";
656
657 /* Look for system reset chassis path */
658 if ((std::find(chassisList.begin(), chassisList.end(), objectPath)) ==
659 chassisList.end())
660 {
661 /* We prefer to reset the full chassis_system, but if it doesn't
662 * exist on some platforms, fall back to a host-only power reset
663 */
664 objectPath = "/xyz/openbmc_project/state/chassis0";
665 }
666
667 crow::connections::systemBus->async_method_call(
Ed Tanous5e7e2dc2023-02-16 10:37:01 -0800668 [asyncResp](const boost::system::error_code& ec2) {
Ed Tanous002d39b2022-05-31 08:59:27 -0700669 // Use "Set" method to set the property value.
Ed Tanous8a592812022-06-04 09:06:59 -0700670 if (ec2)
P.K. Leedd99e042020-06-17 19:43:16 +0800671 {
Ed Tanous8a592812022-06-04 09:06:59 -0700672 BMCWEB_LOG_DEBUG << "[Set] Bad D-Bus request error: " << ec2;
P.K. Leedd99e042020-06-17 19:43:16 +0800673 messages::internalError(asyncResp->res);
674 return;
675 }
676
Ed Tanous002d39b2022-05-31 08:59:27 -0700677 messages::success(asyncResp->res);
678 },
679 processName, objectPath, "org.freedesktop.DBus.Properties", "Set",
680 interfaceName, destProperty,
681 dbus::utility::DbusVariantType{propertyValue});
George Liu7a1dbc42022-12-07 16:03:22 +0800682 });
P.K. Leedd99e042020-06-17 19:43:16 +0800683}
684
Nan Zhoucf7eba02022-07-21 23:53:20 +0000685inline void handleChassisResetActionInfoPost(
686 App& app, const crow::Request& req,
687 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
688 const std::string& /*chassisId*/)
689{
690 if (!redfish::setUpRedfishRoute(app, req, asyncResp))
691 {
692 return;
693 }
694 BMCWEB_LOG_DEBUG << "Post Chassis Reset.";
695
696 std::string resetType;
697
698 if (!json_util::readJsonAction(req, asyncResp->res, "ResetType", resetType))
699 {
700 return;
701 }
702
703 if (resetType != "PowerCycle")
704 {
705 BMCWEB_LOG_DEBUG << "Invalid property value for ResetType: "
706 << resetType;
707 messages::actionParameterNotSupported(asyncResp->res, resetType,
708 "ResetType");
709
710 return;
711 }
712 doChassisPowerCycle(asyncResp);
713}
714
P.K. Leedd99e042020-06-17 19:43:16 +0800715/**
716 * ChassisResetAction class supports the POST method for the Reset
717 * action.
John Edward Broadbent7e860f12021-04-08 15:57:16 -0700718 * Function handles POST method request.
719 * Analyzes POST body before sending Reset request data to D-Bus.
P.K. Leedd99e042020-06-17 19:43:16 +0800720 */
John Edward Broadbent7e860f12021-04-08 15:57:16 -0700721
722inline void requestRoutesChassisResetAction(App& app)
P.K. Leedd99e042020-06-17 19:43:16 +0800723{
John Edward Broadbent7e860f12021-04-08 15:57:16 -0700724 BMCWEB_ROUTE(app, "/redfish/v1/Chassis/<str>/Actions/Chassis.Reset/")
Ed Tanoused398212021-06-09 17:05:54 -0700725 .privileges(redfish::privileges::postChassis)
John Edward Broadbent7e860f12021-04-08 15:57:16 -0700726 .methods(boost::beast::http::verb::post)(
Nan Zhoucf7eba02022-07-21 23:53:20 +0000727 std::bind_front(handleChassisResetActionInfoPost, std::ref(app)));
728}
P.K. Leedd99e042020-06-17 19:43:16 +0800729
Nan Zhoucf7eba02022-07-21 23:53:20 +0000730inline void handleChassisResetActionInfoGet(
731 App& app, const crow::Request& req,
732 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
733 const std::string& chassisId)
734{
735 if (!redfish::setUpRedfishRoute(app, req, asyncResp))
736 {
737 return;
738 }
739 asyncResp->res.jsonValue["@odata.type"] = "#ActionInfo.v1_1_2.ActionInfo";
Willy Tueddfc432022-09-26 16:46:38 +0000740 asyncResp->res.jsonValue["@odata.id"] = crow::utility::urlFromPieces(
741 "redfish", "v1", "Chassis", chassisId, "ResetActionInfo");
Nan Zhoucf7eba02022-07-21 23:53:20 +0000742 asyncResp->res.jsonValue["Name"] = "Reset Action Info";
P.K. Leedd99e042020-06-17 19:43:16 +0800743
Nan Zhoucf7eba02022-07-21 23:53:20 +0000744 asyncResp->res.jsonValue["Id"] = "ResetActionInfo";
745 nlohmann::json::array_t parameters;
746 nlohmann::json::object_t parameter;
747 parameter["Name"] = "ResetType";
748 parameter["Required"] = true;
749 parameter["DataType"] = "String";
750 nlohmann::json::array_t allowed;
751 allowed.push_back("PowerCycle");
752 parameter["AllowableValues"] = std::move(allowed);
753 parameters.push_back(std::move(parameter));
P.K. Leedd99e042020-06-17 19:43:16 +0800754
Nan Zhoucf7eba02022-07-21 23:53:20 +0000755 asyncResp->res.jsonValue["Parameters"] = std::move(parameters);
John Edward Broadbent7e860f12021-04-08 15:57:16 -0700756}
AppaRao Puli1cb1a9e2020-07-17 23:38:57 +0530757
758/**
759 * ChassisResetActionInfo derived class for delivering Chassis
760 * ResetType AllowableValues using ResetInfo schema.
761 */
John Edward Broadbent7e860f12021-04-08 15:57:16 -0700762inline void requestRoutesChassisResetActionInfo(App& app)
AppaRao Puli1cb1a9e2020-07-17 23:38:57 +0530763{
John Edward Broadbent7e860f12021-04-08 15:57:16 -0700764 BMCWEB_ROUTE(app, "/redfish/v1/Chassis/<str>/ResetActionInfo/")
Ed Tanoused398212021-06-09 17:05:54 -0700765 .privileges(redfish::privileges::getActionInfo)
John Edward Broadbent7e860f12021-04-08 15:57:16 -0700766 .methods(boost::beast::http::verb::get)(
Nan Zhoucf7eba02022-07-21 23:53:20 +0000767 std::bind_front(handleChassisResetActionInfoGet, std::ref(app)));
John Edward Broadbent7e860f12021-04-08 15:57:16 -0700768}
AppaRao Puli1cb1a9e2020-07-17 23:38:57 +0530769
Ed Tanous1abe55e2018-09-05 08:30:59 -0700770} // namespace redfish