blob: 6d99313b4784b917a340a98fdc44d8f5f4da3ad6 [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
James Feistb49ac872019-05-21 15:12:01 -070018#include "health.hpp"
James Feist1c8fba92019-12-20 15:12:07 -080019#include "led.hpp"
Ed Tanous1abe55e2018-09-05 08:30:59 -070020
John Edward Broadbent7e860f12021-04-08 15:57:16 -070021#include <app.hpp>
Rapkiewicz, Pawele37f8452018-03-09 13:49:50 +010022#include <boost/container/flat_map.hpp>
Ed Tanoused398212021-06-09 17:05:54 -070023#include <registries/privilege_registry.hpp>
Gunnar Mills02f6ff12020-10-14 15:59:58 -050024#include <utils/collection.hpp>
Gunnar Mills1214b7e2020-06-04 10:11:30 -050025
Ed Tanousabf2add2019-01-22 16:40:12 -080026#include <variant>
Rapkiewicz, Pawele37f8452018-03-09 13:49:50 +010027
Ed Tanous1abe55e2018-09-05 08:30:59 -070028namespace redfish
29{
Rapkiewicz, Pawele37f8452018-03-09 13:49:50 +010030
31/**
Gunnar Millsbeeca0a2019-02-14 16:30:45 -060032 * @brief Retrieves chassis state properties over dbus
33 *
34 * @param[in] aResp - Shared pointer for completing asynchronous calls.
35 *
36 * @return None.
37 */
zhanghch058d1b46d2021-04-01 11:18:24 +080038inline void getChassisState(std::shared_ptr<bmcweb::AsyncResp> aResp)
Gunnar Millsbeeca0a2019-02-14 16:30:45 -060039{
40 crow::connections::systemBus->async_method_call(
41 [aResp{std::move(aResp)}](
42 const boost::system::error_code ec,
Gunnar Mills1214b7e2020-06-04 10:11:30 -050043 const std::variant<std::string>& chassisState) {
Gunnar Millsbeeca0a2019-02-14 16:30:45 -060044 if (ec)
45 {
46 BMCWEB_LOG_DEBUG << "DBUS response error " << ec;
47 messages::internalError(aResp->res);
48 return;
49 }
50
Gunnar Mills1214b7e2020-06-04 10:11:30 -050051 const std::string* s = std::get_if<std::string>(&chassisState);
Gunnar Millsbeeca0a2019-02-14 16:30:45 -060052 BMCWEB_LOG_DEBUG << "Chassis state: " << *s;
53 if (s != nullptr)
54 {
55 // Verify Chassis State
56 if (*s == "xyz.openbmc_project.State.Chassis.PowerState.On")
57 {
58 aResp->res.jsonValue["PowerState"] = "On";
59 aResp->res.jsonValue["Status"]["State"] = "Enabled";
60 }
61 else if (*s ==
62 "xyz.openbmc_project.State.Chassis.PowerState.Off")
63 {
64 aResp->res.jsonValue["PowerState"] = "Off";
65 aResp->res.jsonValue["Status"]["State"] = "StandbyOffline";
66 }
67 }
68 },
69 "xyz.openbmc_project.State.Chassis",
70 "/xyz/openbmc_project/state/chassis0",
71 "org.freedesktop.DBus.Properties", "Get",
72 "xyz.openbmc_project.State.Chassis", "CurrentPowerState");
73}
74
75/**
Rapkiewicz, Pawele37f8452018-03-09 13:49:50 +010076 * DBus types primitives for several generic DBus interfaces
77 * TODO(Pawel) consider move this to separate file into boost::dbus
78 */
Ed Tanous55c7b7a2018-05-22 15:27:24 -070079// Note, this is not a very useful Variant, but because it isn't used to get
Ed Tanousaa2e59c2018-04-12 12:17:20 -070080// values, it should be as simple as possible
81// TODO(ed) invent a nullvariant type
Cheng C Yang5fd7ba62019-11-28 15:58:08 +080082using VariantType = std::variant<bool, std::string, uint64_t, uint32_t>;
Ed Tanousaa2e59c2018-04-12 12:17:20 -070083using ManagedObjectsType = std::vector<std::pair<
84 sdbusplus::message::object_path,
85 std::vector<std::pair<std::string,
86 std::vector<std::pair<std::string, VariantType>>>>>>;
Rapkiewicz, Pawele37f8452018-03-09 13:49:50 +010087
Ed Tanousaa2e59c2018-04-12 12:17:20 -070088using PropertiesType = boost::container::flat_map<std::string, VariantType>;
Rapkiewicz, Pawele37f8452018-03-09 13:49:50 +010089
zhanghch058d1b46d2021-04-01 11:18:24 +080090inline void getIntrusionByService(std::shared_ptr<bmcweb::AsyncResp> aResp,
Ed Tanous23a21a12020-07-25 04:45:05 +000091 const std::string& service,
92 const std::string& objPath)
Qiang XUc1819422019-02-27 13:51:32 +080093{
94 BMCWEB_LOG_DEBUG << "Get intrusion status by service \n";
95
96 crow::connections::systemBus->async_method_call(
97 [aResp{std::move(aResp)}](const boost::system::error_code ec,
Gunnar Mills1214b7e2020-06-04 10:11:30 -050098 const std::variant<std::string>& value) {
Qiang XUc1819422019-02-27 13:51:32 +080099 if (ec)
100 {
Gunnar Mills4e0453b2020-07-08 14:00:30 -0500101 // do not add err msg in redfish response, because this is not
Qiang XUc1819422019-02-27 13:51:32 +0800102 // mandatory property
103 BMCWEB_LOG_ERROR << "DBUS response error " << ec << "\n";
104 return;
105 }
106
Gunnar Mills1214b7e2020-06-04 10:11:30 -0500107 const std::string* status = std::get_if<std::string>(&value);
Qiang XUc1819422019-02-27 13:51:32 +0800108
109 if (status == nullptr)
110 {
111 BMCWEB_LOG_ERROR << "intrusion status read error \n";
112 return;
113 }
114
115 aResp->res.jsonValue["PhysicalSecurity"] = {
116 {"IntrusionSensorNumber", 1}, {"IntrusionSensor", *status}};
117 },
118 service, objPath, "org.freedesktop.DBus.Properties", "Get",
119 "xyz.openbmc_project.Chassis.Intrusion", "Status");
120}
121
122/**
123 * Retrieves physical security properties over dbus
124 */
zhanghch058d1b46d2021-04-01 11:18:24 +0800125inline void getPhysicalSecurityData(std::shared_ptr<bmcweb::AsyncResp> aResp)
Qiang XUc1819422019-02-27 13:51:32 +0800126{
127 crow::connections::systemBus->async_method_call(
128 [aResp{std::move(aResp)}](
129 const boost::system::error_code ec,
130 const std::vector<std::pair<
131 std::string,
Gunnar Mills1214b7e2020-06-04 10:11:30 -0500132 std::vector<std::pair<std::string, std::vector<std::string>>>>>&
133 subtree) {
Qiang XUc1819422019-02-27 13:51:32 +0800134 if (ec)
135 {
Gunnar Mills4e0453b2020-07-08 14:00:30 -0500136 // do not add err msg in redfish response, because this is not
Qiang XUc1819422019-02-27 13:51:32 +0800137 // mandatory property
Andrew Geissler54fbf172021-11-11 15:59:30 -0600138 BMCWEB_LOG_INFO << "DBUS error: no matched iface " << ec
139 << "\n";
Qiang XUc1819422019-02-27 13:51:32 +0800140 return;
141 }
142 // Iterate over all retrieved ObjectPaths.
Gunnar Mills1214b7e2020-06-04 10:11:30 -0500143 for (const auto& object : subtree)
Qiang XUc1819422019-02-27 13:51:32 +0800144 {
Gunnar Mills1214b7e2020-06-04 10:11:30 -0500145 for (const auto& service : object.second)
Qiang XUc1819422019-02-27 13:51:32 +0800146 {
147 getIntrusionByService(aResp, service.first, object.first);
148 return;
149 }
150 }
151 },
152 "xyz.openbmc_project.ObjectMapper",
153 "/xyz/openbmc_project/object_mapper",
154 "xyz.openbmc_project.ObjectMapper", "GetSubTree",
Ed Tanous271584a2019-07-09 16:24:22 -0700155 "/xyz/openbmc_project/Intrusion", 1,
Gunnar Mills1214b7e2020-06-04 10:11:30 -0500156 std::array<const char*, 1>{"xyz.openbmc_project.Chassis.Intrusion"});
Qiang XUc1819422019-02-27 13:51:32 +0800157}
158
Rapkiewicz, Pawele37f8452018-03-09 13:49:50 +0100159/**
Rapkiewicz, Pawele37f8452018-03-09 13:49:50 +0100160 * ChassisCollection derived class for delivering Chassis Collection Schema
John Edward Broadbent7e860f12021-04-08 15:57:16 -0700161 * Functions triggers appropriate requests on DBus
Rapkiewicz, Pawele37f8452018-03-09 13:49:50 +0100162 */
John Edward Broadbent7e860f12021-04-08 15:57:16 -0700163inline void requestRoutesChassisCollection(App& app)
Ed Tanous1abe55e2018-09-05 08:30:59 -0700164{
John Edward Broadbent7e860f12021-04-08 15:57:16 -0700165 BMCWEB_ROUTE(app, "/redfish/v1/Chassis/")
Ed Tanoused398212021-06-09 17:05:54 -0700166 .privileges(redfish::privileges::getChassisCollection)
John Edward Broadbent7e860f12021-04-08 15:57:16 -0700167 .methods(boost::beast::http::verb::get)(
168 [](const crow::Request&,
169 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) {
170 asyncResp->res.jsonValue["@odata.type"] =
171 "#ChassisCollection.ChassisCollection";
172 asyncResp->res.jsonValue["@odata.id"] = "/redfish/v1/Chassis";
173 asyncResp->res.jsonValue["Name"] = "Chassis Collection";
Rapkiewicz, Pawele37f8452018-03-09 13:49:50 +0100174
John Edward Broadbent7e860f12021-04-08 15:57:16 -0700175 collection_util::getCollectionMembers(
176 asyncResp, "/redfish/v1/Chassis",
177 {"xyz.openbmc_project.Inventory.Item.Board",
178 "xyz.openbmc_project.Inventory.Item.Chassis"});
179 });
180}
Rapkiewicz, Pawele37f8452018-03-09 13:49:50 +0100181
Willy Tu308f70c2021-09-28 20:24:52 -0700182inline void
183 getChassisLocationCode(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
184 const std::string& connectionName,
185 const std::string& path)
186{
187 crow::connections::systemBus->async_method_call(
188 [asyncResp](const boost::system::error_code ec,
189 const std::variant<std::string>& property) {
190 if (ec)
191 {
George Liu0fda0f12021-11-16 10:06:17 +0800192 BMCWEB_LOG_DEBUG << "DBUS response error for Location";
Willy Tu308f70c2021-09-28 20:24:52 -0700193 messages::internalError(asyncResp->res);
194 return;
195 }
196
197 const std::string* value = std::get_if<std::string>(&property);
198 if (value == nullptr)
199 {
George Liu0fda0f12021-11-16 10:06:17 +0800200 BMCWEB_LOG_DEBUG << "Null value returned for locaton code";
Willy Tu308f70c2021-09-28 20:24:52 -0700201 messages::internalError(asyncResp->res);
202 return;
203 }
204 asyncResp->res
205 .jsonValue["Location"]["PartLocation"]["ServiceLabel"] = *value;
206 },
207 connectionName, path, "org.freedesktop.DBus.Properties", "Get",
208 "xyz.openbmc_project.Inventory.Decorator.LocationCode", "LocationCode");
209}
210
211inline void getChassisUUID(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
212 const std::string& connectionName,
213 const std::string& path)
214{
215 crow::connections::systemBus->async_method_call(
216 [asyncResp](const boost::system::error_code ec,
217 const std::variant<std::string>& chassisUUID) {
218 if (ec)
219 {
George Liu0fda0f12021-11-16 10:06:17 +0800220 BMCWEB_LOG_DEBUG << "DBUS response error for UUID";
Willy Tu308f70c2021-09-28 20:24:52 -0700221 messages::internalError(asyncResp->res);
222 return;
223 }
224 const std::string* value = std::get_if<std::string>(&chassisUUID);
225 if (value == nullptr)
226 {
George Liu0fda0f12021-11-16 10:06:17 +0800227 BMCWEB_LOG_DEBUG << "Null value returned for UUID";
Willy Tu308f70c2021-09-28 20:24:52 -0700228 messages::internalError(asyncResp->res);
229 return;
230 }
231 asyncResp->res.jsonValue["UUID"] = *value;
232 },
233 connectionName, path, "org.freedesktop.DBus.Properties", "Get",
234 "xyz.openbmc_project.Common.UUID", "UUID");
235}
236
Rapkiewicz, Pawele37f8452018-03-09 13:49:50 +0100237/**
238 * Chassis override class for delivering Chassis Schema
John Edward Broadbent7e860f12021-04-08 15:57:16 -0700239 * Functions triggers appropriate requests on DBus
Rapkiewicz, Pawele37f8452018-03-09 13:49:50 +0100240 */
John Edward Broadbent7e860f12021-04-08 15:57:16 -0700241inline void requestRoutesChassis(App& app)
Ed Tanous1abe55e2018-09-05 08:30:59 -0700242{
John Edward Broadbent7e860f12021-04-08 15:57:16 -0700243 BMCWEB_ROUTE(app, "/redfish/v1/Chassis/<str>/")
Ed Tanoused398212021-06-09 17:05:54 -0700244 .privileges(redfish::privileges::getChassis)
John Edward Broadbent7e860f12021-04-08 15:57:16 -0700245 .methods(
246 boost::beast::http::verb::get)([](const crow::Request&,
247 const std::shared_ptr<
248 bmcweb::AsyncResp>& asyncResp,
249 const std::string& chassisId) {
250 const std::array<const char*, 2> interfaces = {
251 "xyz.openbmc_project.Inventory.Item.Board",
252 "xyz.openbmc_project.Inventory.Item.Chassis"};
Rapkiewicz, Pawele37f8452018-03-09 13:49:50 +0100253
John Edward Broadbent7e860f12021-04-08 15:57:16 -0700254 crow::connections::systemBus->async_method_call(
255 [asyncResp, chassisId(std::string(chassisId))](
256 const boost::system::error_code ec,
257 const crow::openbmc_mapper::GetSubTreeType& subtree) {
258 if (ec)
Ed Tanous1abe55e2018-09-05 08:30:59 -0700259 {
John Edward Broadbent7e860f12021-04-08 15:57:16 -0700260 messages::internalError(asyncResp->res);
261 return;
Ed Tanousdaf36e22018-04-20 16:01:36 -0700262 }
John Edward Broadbent7e860f12021-04-08 15:57:16 -0700263 // Iterate over all retrieved ObjectPaths.
264 for (const std::pair<
265 std::string,
266 std::vector<std::pair<std::string,
267 std::vector<std::string>>>>&
268 object : subtree)
Ed Tanous1abe55e2018-09-05 08:30:59 -0700269 {
John Edward Broadbent7e860f12021-04-08 15:57:16 -0700270 const std::string& path = object.first;
271 const std::vector<
272 std::pair<std::string, std::vector<std::string>>>&
273 connectionNames = object.second;
Ed Tanouse0d918b2018-03-27 17:41:04 -0700274
George Liu997093e2021-11-17 17:43:45 +0800275 sdbusplus::message::object_path objPath(path);
276 if (objPath.filename() != chassisId)
James Feist1c8fba92019-12-20 15:12:07 -0800277 {
John Edward Broadbent7e860f12021-04-08 15:57:16 -0700278 continue;
James Feist1c8fba92019-12-20 15:12:07 -0800279 }
James Feist1c8fba92019-12-20 15:12:07 -0800280
John Edward Broadbent7e860f12021-04-08 15:57:16 -0700281 auto health =
282 std::make_shared<HealthPopulate>(asyncResp);
283
284 crow::connections::systemBus->async_method_call(
285 [health](
286 const boost::system::error_code ec2,
287 std::variant<std::vector<std::string>>& resp) {
288 if (ec2)
289 {
290 return; // no sensors = no failures
291 }
292 std::vector<std::string>* data =
293 std::get_if<std::vector<std::string>>(
294 &resp);
295 if (data == nullptr)
296 {
297 return;
298 }
299 health->inventory = std::move(*data);
300 },
301 "xyz.openbmc_project.ObjectMapper",
302 path + "/all_sensors",
303 "org.freedesktop.DBus.Properties", "Get",
304 "xyz.openbmc_project.Association", "endpoints");
305
306 health->populate();
307
308 if (connectionNames.size() < 1)
309 {
310 BMCWEB_LOG_ERROR << "Got 0 Connection names";
311 continue;
312 }
313
314 asyncResp->res.jsonValue["@odata.type"] =
315 "#Chassis.v1_14_0.Chassis";
316 asyncResp->res.jsonValue["@odata.id"] =
317 "/redfish/v1/Chassis/" + chassisId;
318 asyncResp->res.jsonValue["Name"] = "Chassis Collection";
319 asyncResp->res.jsonValue["ChassisType"] = "RackMount";
320 asyncResp->res.jsonValue["Actions"]["#Chassis.Reset"] =
321 {{"target", "/redfish/v1/Chassis/" + chassisId +
322 "/Actions/Chassis.Reset"},
323 {"@Redfish.ActionInfo", "/redfish/v1/Chassis/" +
324 chassisId +
325 "/ResetActionInfo"}};
326 asyncResp->res.jsonValue["PCIeDevices"] = {
327 {"@odata.id",
328 "/redfish/v1/Systems/system/PCIeDevices"}};
329
330 const std::string& connectionName =
331 connectionNames[0].first;
332
333 const std::vector<std::string>& interfaces2 =
334 connectionNames[0].second;
335 const std::array<const char*, 2> hasIndicatorLed = {
336 "xyz.openbmc_project.Inventory.Item.Panel",
George Liu0fda0f12021-11-16 10:06:17 +0800337 "xyz.openbmc_project.Inventory.Item.Board.Motherboard"};
John Edward Broadbent7e860f12021-04-08 15:57:16 -0700338
Tejas Patil476b9cc2021-06-04 17:09:14 +0530339 const std::string assetTagInterface =
George Liu0fda0f12021-11-16 10:06:17 +0800340 "xyz.openbmc_project.Inventory.Decorator.AssetTag";
Tejas Patil476b9cc2021-06-04 17:09:14 +0530341 if (std::find(interfaces2.begin(), interfaces2.end(),
342 assetTagInterface) != interfaces2.end())
343 {
344 crow::connections::systemBus->async_method_call(
345 [asyncResp, chassisId(std::string(chassisId))](
346 const boost::system::error_code ec,
347 const std::variant<std::string>& property) {
348 if (ec)
349 {
350 BMCWEB_LOG_DEBUG
George Liu0fda0f12021-11-16 10:06:17 +0800351 << "DBus response error for AssetTag";
Tejas Patil476b9cc2021-06-04 17:09:14 +0530352 messages::internalError(asyncResp->res);
353 return;
354 }
355
356 const std::string* assetTag =
357 std::get_if<std::string>(&property);
358 if (assetTag == nullptr)
359 {
360 BMCWEB_LOG_DEBUG
George Liu0fda0f12021-11-16 10:06:17 +0800361 << "Null value returned for Chassis AssetTag";
Tejas Patil476b9cc2021-06-04 17:09:14 +0530362 messages::internalError(asyncResp->res);
363 return;
364 }
365 asyncResp->res.jsonValue["AssetTag"] =
366 *assetTag;
367 },
368 connectionName, path,
369 "org.freedesktop.DBus.Properties", "Get",
370 assetTagInterface, "AssetTag");
371 }
372
John Edward Broadbent7e860f12021-04-08 15:57:16 -0700373 for (const char* interface : hasIndicatorLed)
374 {
375 if (std::find(interfaces2.begin(),
376 interfaces2.end(),
377 interface) != interfaces2.end())
378 {
379 getIndicatorLedState(asyncResp);
380 getLocationIndicatorActive(asyncResp);
381 break;
382 }
383 }
384
SunnySrivastava198488ad7f02020-12-03 10:27:52 -0600385 crow::connections::systemBus->async_method_call(
386 [asyncResp, chassisId(std::string(chassisId))](
John Edward Broadbent7e860f12021-04-08 15:57:16 -0700387 const boost::system::error_code /*ec2*/,
388 const std::vector<
389 std::pair<std::string, VariantType>>&
390 propertiesList) {
391 for (const std::pair<std::string, VariantType>&
392 property : propertiesList)
SunnySrivastava198488ad7f02020-12-03 10:27:52 -0600393 {
John Edward Broadbent7e860f12021-04-08 15:57:16 -0700394 // Store DBus properties that are also
395 // Redfish properties with same name and a
396 // string value
397 const std::string& propertyName =
398 property.first;
399 if ((propertyName == "PartNumber") ||
400 (propertyName == "SerialNumber") ||
401 (propertyName == "Manufacturer") ||
Alpana Kumaricaa11f72021-11-09 12:16:18 -0600402 (propertyName == "Model") ||
403 (propertyName == "SparePartNumber"))
Shawn McCarney99cffd72019-03-01 10:46:20 -0600404 {
John Edward Broadbent7e860f12021-04-08 15:57:16 -0700405 const std::string* value =
406 std::get_if<std::string>(
407 &property.second);
Alpana Kumaricaa11f72021-11-09 12:16:18 -0600408 if (value == nullptr)
John Edward Broadbent7e860f12021-04-08 15:57:16 -0700409 {
Alpana Kumaricaa11f72021-11-09 12:16:18 -0600410 BMCWEB_LOG_ERROR
411 << "Null value returned for "
412 << propertyName;
413 messages::internalError(
414 asyncResp->res);
415 return;
John Edward Broadbent7e860f12021-04-08 15:57:16 -0700416 }
Alpana Kumaricaa11f72021-11-09 12:16:18 -0600417 // SparePartNumber is optional on D-Bus
418 // so skip if it is empty
419 if (propertyName == "SparePartNumber")
420 {
421 if (*value == "")
422 {
423 continue;
424 }
425 }
426 asyncResp->res.jsonValue[propertyName] =
427 *value;
Shawn McCarney99cffd72019-03-01 10:46:20 -0600428 }
Ed Tanous1abe55e2018-09-05 08:30:59 -0700429 }
John Edward Broadbent7e860f12021-04-08 15:57:16 -0700430 asyncResp->res.jsonValue["Name"] = chassisId;
431 asyncResp->res.jsonValue["Id"] = chassisId;
zhanghch050256b692021-06-12 10:26:52 +0800432#ifdef BMCWEB_ALLOW_DEPRECATED_POWER_THERMAL
John Edward Broadbent7e860f12021-04-08 15:57:16 -0700433 asyncResp->res.jsonValue["Thermal"] = {
434 {"@odata.id", "/redfish/v1/Chassis/" +
435 chassisId + "/Thermal"}};
436 // Power object
437 asyncResp->res.jsonValue["Power"] = {
438 {"@odata.id", "/redfish/v1/Chassis/" +
439 chassisId + "/Power"}};
zhanghch050256b692021-06-12 10:26:52 +0800440#endif
John Edward Broadbent7e860f12021-04-08 15:57:16 -0700441 // SensorCollection
442 asyncResp->res.jsonValue["Sensors"] = {
443 {"@odata.id", "/redfish/v1/Chassis/" +
444 chassisId + "/Sensors"}};
445 asyncResp->res.jsonValue["Status"] = {
446 {"State", "Enabled"},
447 };
448
449 asyncResp->res
450 .jsonValue["Links"]["ComputerSystems"] = {
451 {{"@odata.id",
452 "/redfish/v1/Systems/system"}}};
453 asyncResp->res.jsonValue["Links"]["ManagedBy"] =
454 {{{"@odata.id",
455 "/redfish/v1/Managers/bmc"}}};
456 getChassisState(asyncResp);
457 },
458 connectionName, path,
459 "org.freedesktop.DBus.Properties", "GetAll",
460 "xyz.openbmc_project.Inventory.Decorator.Asset");
Sharad Yadav2c37b4b2021-05-10 12:53:38 +0530461
Willy Tu308f70c2021-09-28 20:24:52 -0700462 for (const auto& interface : interfaces2)
Sharad Yadav2c37b4b2021-05-10 12:53:38 +0530463 {
Willy Tu308f70c2021-09-28 20:24:52 -0700464 if (interface == "xyz.openbmc_project.Common.UUID")
465 {
466 getChassisUUID(asyncResp, connectionName, path);
467 }
George Liu0fda0f12021-11-16 10:06:17 +0800468 else if (
469 interface ==
470 "xyz.openbmc_project.Inventory.Decorator.LocationCode")
Willy Tu308f70c2021-09-28 20:24:52 -0700471 {
472 getChassisLocationCode(asyncResp,
473 connectionName, path);
474 }
Sharad Yadav2c37b4b2021-05-10 12:53:38 +0530475 }
476
John Edward Broadbent7e860f12021-04-08 15:57:16 -0700477 return;
478 }
479
480 // Couldn't find an object with that name. return an error
481 messages::resourceNotFound(
482 asyncResp->res, "#Chassis.v1_14_0.Chassis", chassisId);
483 },
484 "xyz.openbmc_project.ObjectMapper",
485 "/xyz/openbmc_project/object_mapper",
486 "xyz.openbmc_project.ObjectMapper", "GetSubTree",
487 "/xyz/openbmc_project/inventory", 0, interfaces);
488
489 getPhysicalSecurityData(asyncResp);
490 });
491
492 BMCWEB_ROUTE(app, "/redfish/v1/Chassis/<str>/")
Ed Tanoused398212021-06-09 17:05:54 -0700493 .privileges(redfish::privileges::patchChassis)
John Edward Broadbent7e860f12021-04-08 15:57:16 -0700494 .methods(
495 boost::beast::http::verb::
496 patch)([](const crow::Request& req,
497 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
498 const std::string& param) {
499 std::optional<bool> locationIndicatorActive;
500 std::optional<std::string> indicatorLed;
501
502 if (param.empty())
503 {
504 return;
505 }
506
507 if (!json_util::readJson(
508 req, asyncResp->res, "LocationIndicatorActive",
509 locationIndicatorActive, "IndicatorLED", indicatorLed))
510 {
511 return;
512 }
513
514 // TODO (Gunnar): Remove IndicatorLED after enough time has passed
515 if (!locationIndicatorActive && !indicatorLed)
516 {
517 return; // delete this when we support more patch properties
518 }
519 if (indicatorLed)
520 {
521 asyncResp->res.addHeader(
522 boost::beast::http::field::warning,
George Liu0fda0f12021-11-16 10:06:17 +0800523 "299 - \"IndicatorLED is deprecated. Use LocationIndicatorActive instead.\"");
John Edward Broadbent7e860f12021-04-08 15:57:16 -0700524 }
525
526 const std::array<const char*, 2> interfaces = {
527 "xyz.openbmc_project.Inventory.Item.Board",
528 "xyz.openbmc_project.Inventory.Item.Chassis"};
529
530 const std::string& chassisId = param;
531
532 crow::connections::systemBus->async_method_call(
533 [asyncResp, chassisId, locationIndicatorActive, indicatorLed](
534 const boost::system::error_code ec,
535 const crow::openbmc_mapper::GetSubTreeType& subtree) {
536 if (ec)
537 {
538 messages::internalError(asyncResp->res);
539 return;
540 }
541
542 // Iterate over all retrieved ObjectPaths.
543 for (const std::pair<
544 std::string,
545 std::vector<std::pair<std::string,
546 std::vector<std::string>>>>&
547 object : subtree)
548 {
549 const std::string& path = object.first;
550 const std::vector<
551 std::pair<std::string, std::vector<std::string>>>&
552 connectionNames = object.second;
553
George Liu997093e2021-11-17 17:43:45 +0800554 sdbusplus::message::object_path objPath(path);
555 if (objPath.filename() != chassisId)
John Edward Broadbent7e860f12021-04-08 15:57:16 -0700556 {
557 continue;
558 }
559
560 if (connectionNames.size() < 1)
561 {
562 BMCWEB_LOG_ERROR << "Got 0 Connection names";
563 continue;
564 }
565
566 const std::vector<std::string>& interfaces3 =
567 connectionNames[0].second;
568
569 const std::array<const char*, 2> hasIndicatorLed = {
570 "xyz.openbmc_project.Inventory.Item.Panel",
George Liu0fda0f12021-11-16 10:06:17 +0800571 "xyz.openbmc_project.Inventory.Item.Board.Motherboard"};
John Edward Broadbent7e860f12021-04-08 15:57:16 -0700572 bool indicatorChassis = false;
573 for (const char* interface : hasIndicatorLed)
574 {
575 if (std::find(interfaces3.begin(),
576 interfaces3.end(),
577 interface) != interfaces3.end())
578 {
579 indicatorChassis = true;
580 break;
Ed Tanous1abe55e2018-09-05 08:30:59 -0700581 }
John Edward Broadbent7e860f12021-04-08 15:57:16 -0700582 }
583 if (locationIndicatorActive)
584 {
585 if (indicatorChassis)
586 {
587 setLocationIndicatorActive(
588 asyncResp, *locationIndicatorActive);
589 }
590 else
591 {
592 messages::propertyUnknown(
593 asyncResp->res, "LocationIndicatorActive");
594 }
595 }
596 if (indicatorLed)
597 {
598 if (indicatorChassis)
599 {
600 setIndicatorLedState(asyncResp, *indicatorLed);
601 }
602 else
603 {
604 messages::propertyUnknown(asyncResp->res,
605 "IndicatorLED");
606 }
607 }
608 return;
James Feist1c8fba92019-12-20 15:12:07 -0800609 }
610
John Edward Broadbent7e860f12021-04-08 15:57:16 -0700611 messages::resourceNotFound(
612 asyncResp->res, "#Chassis.v1_14_0.Chassis", chassisId);
613 },
614 "xyz.openbmc_project.ObjectMapper",
615 "/xyz/openbmc_project/object_mapper",
616 "xyz.openbmc_project.ObjectMapper", "GetSubTree",
617 "/xyz/openbmc_project/inventory", 0, interfaces);
618 });
619}
P.K. Leedd99e042020-06-17 19:43:16 +0800620
zhanghch058d1b46d2021-04-01 11:18:24 +0800621inline void
622 doChassisPowerCycle(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp)
P.K. Leedd99e042020-06-17 19:43:16 +0800623{
Vijay Khemkac3b3c922020-09-22 23:00:12 -0700624 const char* busName = "xyz.openbmc_project.ObjectMapper";
625 const char* path = "/xyz/openbmc_project/object_mapper";
626 const char* interface = "xyz.openbmc_project.ObjectMapper";
627 const char* method = "GetSubTreePaths";
P.K. Leedd99e042020-06-17 19:43:16 +0800628
Vijay Khemkac3b3c922020-09-22 23:00:12 -0700629 const std::array<const char*, 1> interfaces = {
630 "xyz.openbmc_project.State.Chassis"};
631
632 // Use mapper to get subtree paths.
P.K. Leedd99e042020-06-17 19:43:16 +0800633 crow::connections::systemBus->async_method_call(
Vijay Khemkac3b3c922020-09-22 23:00:12 -0700634 [asyncResp](const boost::system::error_code ec,
635 const std::vector<std::string>& chassisList) {
P.K. Leedd99e042020-06-17 19:43:16 +0800636 if (ec)
637 {
Vijay Khemkac3b3c922020-09-22 23:00:12 -0700638 BMCWEB_LOG_DEBUG << "[mapper] Bad D-Bus request error: " << ec;
P.K. Leedd99e042020-06-17 19:43:16 +0800639 messages::internalError(asyncResp->res);
640 return;
641 }
642
Vijay Khemkac3b3c922020-09-22 23:00:12 -0700643 const char* processName = "xyz.openbmc_project.State.Chassis";
644 const char* interfaceName = "xyz.openbmc_project.State.Chassis";
645 const char* destProperty = "RequestedPowerTransition";
646 const std::string propertyValue =
647 "xyz.openbmc_project.State.Chassis.Transition.PowerCycle";
648 std::string objectPath =
649 "/xyz/openbmc_project/state/chassis_system0";
650
651 /* Look for system reset chassis path */
652 if ((std::find(chassisList.begin(), chassisList.end(),
653 objectPath)) == chassisList.end())
654 {
655 /* We prefer to reset the full chassis_system, but if it doesn't
656 * exist on some platforms, fall back to a host-only power reset
657 */
658 objectPath = "/xyz/openbmc_project/state/chassis0";
659 }
660
661 crow::connections::systemBus->async_method_call(
662 [asyncResp](const boost::system::error_code ec) {
663 // Use "Set" method to set the property value.
664 if (ec)
665 {
666 BMCWEB_LOG_DEBUG << "[Set] Bad D-Bus request error: "
667 << ec;
668 messages::internalError(asyncResp->res);
669 return;
670 }
671
672 messages::success(asyncResp->res);
673 },
674 processName, objectPath, "org.freedesktop.DBus.Properties",
675 "Set", interfaceName, destProperty,
676 std::variant<std::string>{propertyValue});
P.K. Leedd99e042020-06-17 19:43:16 +0800677 },
Vijay Khemkac3b3c922020-09-22 23:00:12 -0700678 busName, path, interface, method, "/", 0, interfaces);
P.K. Leedd99e042020-06-17 19:43:16 +0800679}
680
681/**
682 * ChassisResetAction class supports the POST method for the Reset
683 * action.
John Edward Broadbent7e860f12021-04-08 15:57:16 -0700684 * Function handles POST method request.
685 * Analyzes POST body before sending Reset request data to D-Bus.
P.K. Leedd99e042020-06-17 19:43:16 +0800686 */
John Edward Broadbent7e860f12021-04-08 15:57:16 -0700687
688inline void requestRoutesChassisResetAction(App& app)
P.K. Leedd99e042020-06-17 19:43:16 +0800689{
John Edward Broadbent7e860f12021-04-08 15:57:16 -0700690 BMCWEB_ROUTE(app, "/redfish/v1/Chassis/<str>/Actions/Chassis.Reset/")
Ed Tanoused398212021-06-09 17:05:54 -0700691 .privileges(redfish::privileges::postChassis)
John Edward Broadbent7e860f12021-04-08 15:57:16 -0700692 .methods(boost::beast::http::verb::post)(
693 [](const crow::Request& req,
694 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
695 const std::string&) {
696 BMCWEB_LOG_DEBUG << "Post Chassis Reset.";
P.K. Leedd99e042020-06-17 19:43:16 +0800697
John Edward Broadbent7e860f12021-04-08 15:57:16 -0700698 std::string resetType;
P.K. Leedd99e042020-06-17 19:43:16 +0800699
John Edward Broadbent7e860f12021-04-08 15:57:16 -0700700 if (!json_util::readJson(req, asyncResp->res, "ResetType",
701 resetType))
702 {
703 return;
704 }
P.K. Leedd99e042020-06-17 19:43:16 +0800705
John Edward Broadbent7e860f12021-04-08 15:57:16 -0700706 if (resetType != "PowerCycle")
707 {
708 BMCWEB_LOG_DEBUG << "Invalid property value for ResetType: "
709 << resetType;
710 messages::actionParameterNotSupported(
711 asyncResp->res, resetType, "ResetType");
P.K. Leedd99e042020-06-17 19:43:16 +0800712
John Edward Broadbent7e860f12021-04-08 15:57:16 -0700713 return;
714 }
715 doChassisPowerCycle(asyncResp);
716 });
717}
AppaRao Puli1cb1a9e2020-07-17 23:38:57 +0530718
719/**
720 * ChassisResetActionInfo derived class for delivering Chassis
721 * ResetType AllowableValues using ResetInfo schema.
722 */
John Edward Broadbent7e860f12021-04-08 15:57:16 -0700723inline void requestRoutesChassisResetActionInfo(App& app)
AppaRao Puli1cb1a9e2020-07-17 23:38:57 +0530724{
John Edward Broadbent7e860f12021-04-08 15:57:16 -0700725 BMCWEB_ROUTE(app, "/redfish/v1/Chassis/<str>/ResetActionInfo/")
Ed Tanoused398212021-06-09 17:05:54 -0700726 .privileges(redfish::privileges::getActionInfo)
John Edward Broadbent7e860f12021-04-08 15:57:16 -0700727 .methods(boost::beast::http::verb::get)(
728 [](const crow::Request&,
729 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
730 const std::string& chassisId)
AppaRao Puli1cb1a9e2020-07-17 23:38:57 +0530731
John Edward Broadbent7e860f12021-04-08 15:57:16 -0700732 {
733 asyncResp->res.jsonValue = {
734 {"@odata.type", "#ActionInfo.v1_1_2.ActionInfo"},
735 {"@odata.id",
736 "/redfish/v1/Chassis/" + chassisId + "/ResetActionInfo"},
737 {"Name", "Reset Action Info"},
738 {"Id", "ResetActionInfo"},
739 {"Parameters",
740 {{{"Name", "ResetType"},
741 {"Required", true},
742 {"DataType", "String"},
743 {"AllowableValues", {"PowerCycle"}}}}}};
744 });
745}
AppaRao Puli1cb1a9e2020-07-17 23:38:57 +0530746
Ed Tanous1abe55e2018-09-05 08:30:59 -0700747} // namespace redfish