blob: b0c629189962f89e6149fe7175b0abd406dd240d [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
182/**
183 * Chassis override class for delivering Chassis Schema
John Edward Broadbent7e860f12021-04-08 15:57:16 -0700184 * Functions triggers appropriate requests on DBus
Rapkiewicz, Pawele37f8452018-03-09 13:49:50 +0100185 */
John Edward Broadbent7e860f12021-04-08 15:57:16 -0700186inline void requestRoutesChassis(App& app)
Ed Tanous1abe55e2018-09-05 08:30:59 -0700187{
John Edward Broadbent7e860f12021-04-08 15:57:16 -0700188 BMCWEB_ROUTE(app, "/redfish/v1/Chassis/<str>/")
Ed Tanoused398212021-06-09 17:05:54 -0700189 .privileges(redfish::privileges::getChassis)
John Edward Broadbent7e860f12021-04-08 15:57:16 -0700190 .methods(
191 boost::beast::http::verb::get)([](const crow::Request&,
192 const std::shared_ptr<
193 bmcweb::AsyncResp>& asyncResp,
194 const std::string& chassisId) {
195 const std::array<const char*, 2> interfaces = {
196 "xyz.openbmc_project.Inventory.Item.Board",
197 "xyz.openbmc_project.Inventory.Item.Chassis"};
Rapkiewicz, Pawele37f8452018-03-09 13:49:50 +0100198
John Edward Broadbent7e860f12021-04-08 15:57:16 -0700199 crow::connections::systemBus->async_method_call(
200 [asyncResp, chassisId(std::string(chassisId))](
201 const boost::system::error_code ec,
202 const crow::openbmc_mapper::GetSubTreeType& subtree) {
203 if (ec)
Ed Tanous1abe55e2018-09-05 08:30:59 -0700204 {
John Edward Broadbent7e860f12021-04-08 15:57:16 -0700205 messages::internalError(asyncResp->res);
206 return;
Ed Tanousdaf36e22018-04-20 16:01:36 -0700207 }
John Edward Broadbent7e860f12021-04-08 15:57:16 -0700208 // Iterate over all retrieved ObjectPaths.
209 for (const std::pair<
210 std::string,
211 std::vector<std::pair<std::string,
212 std::vector<std::string>>>>&
213 object : subtree)
Ed Tanous1abe55e2018-09-05 08:30:59 -0700214 {
John Edward Broadbent7e860f12021-04-08 15:57:16 -0700215 const std::string& path = object.first;
216 const std::vector<
217 std::pair<std::string, std::vector<std::string>>>&
218 connectionNames = object.second;
Ed Tanouse0d918b2018-03-27 17:41:04 -0700219
John Edward Broadbent7e860f12021-04-08 15:57:16 -0700220 if (!boost::ends_with(path, chassisId))
James Feist1c8fba92019-12-20 15:12:07 -0800221 {
John Edward Broadbent7e860f12021-04-08 15:57:16 -0700222 continue;
James Feist1c8fba92019-12-20 15:12:07 -0800223 }
James Feist1c8fba92019-12-20 15:12:07 -0800224
John Edward Broadbent7e860f12021-04-08 15:57:16 -0700225 auto health =
226 std::make_shared<HealthPopulate>(asyncResp);
227
228 crow::connections::systemBus->async_method_call(
229 [health](
230 const boost::system::error_code ec2,
231 std::variant<std::vector<std::string>>& resp) {
232 if (ec2)
233 {
234 return; // no sensors = no failures
235 }
236 std::vector<std::string>* data =
237 std::get_if<std::vector<std::string>>(
238 &resp);
239 if (data == nullptr)
240 {
241 return;
242 }
243 health->inventory = std::move(*data);
244 },
245 "xyz.openbmc_project.ObjectMapper",
246 path + "/all_sensors",
247 "org.freedesktop.DBus.Properties", "Get",
248 "xyz.openbmc_project.Association", "endpoints");
249
250 health->populate();
251
252 if (connectionNames.size() < 1)
253 {
254 BMCWEB_LOG_ERROR << "Got 0 Connection names";
255 continue;
256 }
257
258 asyncResp->res.jsonValue["@odata.type"] =
259 "#Chassis.v1_14_0.Chassis";
260 asyncResp->res.jsonValue["@odata.id"] =
261 "/redfish/v1/Chassis/" + chassisId;
262 asyncResp->res.jsonValue["Name"] = "Chassis Collection";
263 asyncResp->res.jsonValue["ChassisType"] = "RackMount";
264 asyncResp->res.jsonValue["Actions"]["#Chassis.Reset"] =
265 {{"target", "/redfish/v1/Chassis/" + chassisId +
266 "/Actions/Chassis.Reset"},
267 {"@Redfish.ActionInfo", "/redfish/v1/Chassis/" +
268 chassisId +
269 "/ResetActionInfo"}};
270 asyncResp->res.jsonValue["PCIeDevices"] = {
271 {"@odata.id",
272 "/redfish/v1/Systems/system/PCIeDevices"}};
273
274 const std::string& connectionName =
275 connectionNames[0].first;
276
277 const std::vector<std::string>& interfaces2 =
278 connectionNames[0].second;
279 const std::array<const char*, 2> hasIndicatorLed = {
280 "xyz.openbmc_project.Inventory.Item.Panel",
281 "xyz.openbmc_project.Inventory.Item.Board."
282 "Motherboard"};
283
Tejas Patil476b9cc2021-06-04 17:09:14 +0530284 const std::string assetTagInterface =
285 "xyz.openbmc_project.Inventory.Decorator."
286 "AssetTag";
287 if (std::find(interfaces2.begin(), interfaces2.end(),
288 assetTagInterface) != interfaces2.end())
289 {
290 crow::connections::systemBus->async_method_call(
291 [asyncResp, chassisId(std::string(chassisId))](
292 const boost::system::error_code ec,
293 const std::variant<std::string>& property) {
294 if (ec)
295 {
296 BMCWEB_LOG_DEBUG
297 << "DBus response error for "
298 "AssetTag";
299 messages::internalError(asyncResp->res);
300 return;
301 }
302
303 const std::string* assetTag =
304 std::get_if<std::string>(&property);
305 if (assetTag == nullptr)
306 {
307 BMCWEB_LOG_DEBUG
308 << "Null value returned "
309 "for Chassis AssetTag";
310 messages::internalError(asyncResp->res);
311 return;
312 }
313 asyncResp->res.jsonValue["AssetTag"] =
314 *assetTag;
315 },
316 connectionName, path,
317 "org.freedesktop.DBus.Properties", "Get",
318 assetTagInterface, "AssetTag");
319 }
320
John Edward Broadbent7e860f12021-04-08 15:57:16 -0700321 for (const char* interface : hasIndicatorLed)
322 {
323 if (std::find(interfaces2.begin(),
324 interfaces2.end(),
325 interface) != interfaces2.end())
326 {
327 getIndicatorLedState(asyncResp);
328 getLocationIndicatorActive(asyncResp);
329 break;
330 }
331 }
332
333 const std::string locationInterface =
334 "xyz.openbmc_project.Inventory.Decorator."
335 "LocationCode";
336 if (std::find(interfaces2.begin(), interfaces2.end(),
337 locationInterface) != interfaces2.end())
338 {
339 crow::connections::systemBus->async_method_call(
340 [asyncResp, chassisId(std::string(chassisId))](
341 const boost::system::error_code ec,
342 const std::variant<std::string>& property) {
343 if (ec)
344 {
345 BMCWEB_LOG_DEBUG
346 << "DBUS response error for "
347 "Location";
348 messages::internalError(asyncResp->res);
349 return;
350 }
351
352 const std::string* value =
353 std::get_if<std::string>(&property);
354 if (value == nullptr)
355 {
356 BMCWEB_LOG_DEBUG
357 << "Null value returned "
358 "for locaton code";
359 messages::internalError(asyncResp->res);
360 return;
361 }
362 asyncResp->res
363 .jsonValue["Location"]["PartLocation"]
364 ["ServiceLabel"] = *value;
365 },
366 connectionName, path,
367 "org.freedesktop.DBus.Properties", "Get",
368 locationInterface, "LocationCode");
369 }
370
SunnySrivastava198488ad7f02020-12-03 10:27:52 -0600371 crow::connections::systemBus->async_method_call(
372 [asyncResp, chassisId(std::string(chassisId))](
John Edward Broadbent7e860f12021-04-08 15:57:16 -0700373 const boost::system::error_code /*ec2*/,
374 const std::vector<
375 std::pair<std::string, VariantType>>&
376 propertiesList) {
377 for (const std::pair<std::string, VariantType>&
378 property : propertiesList)
SunnySrivastava198488ad7f02020-12-03 10:27:52 -0600379 {
John Edward Broadbent7e860f12021-04-08 15:57:16 -0700380 // Store DBus properties that are also
381 // Redfish properties with same name and a
382 // string value
383 const std::string& propertyName =
384 property.first;
385 if ((propertyName == "PartNumber") ||
386 (propertyName == "SerialNumber") ||
387 (propertyName == "Manufacturer") ||
388 (propertyName == "Model"))
Shawn McCarney99cffd72019-03-01 10:46:20 -0600389 {
John Edward Broadbent7e860f12021-04-08 15:57:16 -0700390 const std::string* value =
391 std::get_if<std::string>(
392 &property.second);
393 if (value != nullptr)
394 {
395 asyncResp->res
396 .jsonValue[propertyName] =
397 *value;
398 }
Shawn McCarney99cffd72019-03-01 10:46:20 -0600399 }
Ed Tanous1abe55e2018-09-05 08:30:59 -0700400 }
John Edward Broadbent7e860f12021-04-08 15:57:16 -0700401 asyncResp->res.jsonValue["Name"] = chassisId;
402 asyncResp->res.jsonValue["Id"] = chassisId;
zhanghch050256b692021-06-12 10:26:52 +0800403#ifdef BMCWEB_ALLOW_DEPRECATED_POWER_THERMAL
John Edward Broadbent7e860f12021-04-08 15:57:16 -0700404 asyncResp->res.jsonValue["Thermal"] = {
405 {"@odata.id", "/redfish/v1/Chassis/" +
406 chassisId + "/Thermal"}};
407 // Power object
408 asyncResp->res.jsonValue["Power"] = {
409 {"@odata.id", "/redfish/v1/Chassis/" +
410 chassisId + "/Power"}};
zhanghch050256b692021-06-12 10:26:52 +0800411#endif
John Edward Broadbent7e860f12021-04-08 15:57:16 -0700412 // SensorCollection
413 asyncResp->res.jsonValue["Sensors"] = {
414 {"@odata.id", "/redfish/v1/Chassis/" +
415 chassisId + "/Sensors"}};
416 asyncResp->res.jsonValue["Status"] = {
417 {"State", "Enabled"},
418 };
419
420 asyncResp->res
421 .jsonValue["Links"]["ComputerSystems"] = {
422 {{"@odata.id",
423 "/redfish/v1/Systems/system"}}};
424 asyncResp->res.jsonValue["Links"]["ManagedBy"] =
425 {{{"@odata.id",
426 "/redfish/v1/Managers/bmc"}}};
427 getChassisState(asyncResp);
428 },
429 connectionName, path,
430 "org.freedesktop.DBus.Properties", "GetAll",
431 "xyz.openbmc_project.Inventory.Decorator.Asset");
Sharad Yadav2c37b4b2021-05-10 12:53:38 +0530432
433 // Chassis UUID
434 const std::string uuidInterface =
435 "xyz.openbmc_project.Common.UUID";
436 if (std::find(interfaces2.begin(), interfaces2.end(),
437 uuidInterface) != interfaces2.end())
438 {
439 crow::connections::systemBus->async_method_call(
440 [asyncResp](const boost::system::error_code ec,
441 const std::variant<std::string>&
442 chassisUUID) {
443 if (ec)
444 {
445 BMCWEB_LOG_DEBUG
446 << "DBUS response error for "
447 "UUID";
448 messages::internalError(asyncResp->res);
449 return;
450 }
451 const std::string* value =
452 std::get_if<std::string>(&chassisUUID);
453 if (value == nullptr)
454 {
455 BMCWEB_LOG_DEBUG
456 << "Null value returned "
457 "for UUID";
458 messages::internalError(asyncResp->res);
459 return;
460 }
461 asyncResp->res.jsonValue["UUID"] = *value;
462 },
463 connectionName, path,
464 "org.freedesktop.DBus.Properties", "Get",
465 uuidInterface, "UUID");
466 }
467
John Edward Broadbent7e860f12021-04-08 15:57:16 -0700468 return;
469 }
470
471 // Couldn't find an object with that name. return an error
472 messages::resourceNotFound(
473 asyncResp->res, "#Chassis.v1_14_0.Chassis", chassisId);
474 },
475 "xyz.openbmc_project.ObjectMapper",
476 "/xyz/openbmc_project/object_mapper",
477 "xyz.openbmc_project.ObjectMapper", "GetSubTree",
478 "/xyz/openbmc_project/inventory", 0, interfaces);
479
480 getPhysicalSecurityData(asyncResp);
481 });
482
483 BMCWEB_ROUTE(app, "/redfish/v1/Chassis/<str>/")
Ed Tanoused398212021-06-09 17:05:54 -0700484 .privileges(redfish::privileges::patchChassis)
John Edward Broadbent7e860f12021-04-08 15:57:16 -0700485 .methods(
486 boost::beast::http::verb::
487 patch)([](const crow::Request& req,
488 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
489 const std::string& param) {
490 std::optional<bool> locationIndicatorActive;
491 std::optional<std::string> indicatorLed;
492
493 if (param.empty())
494 {
495 return;
496 }
497
498 if (!json_util::readJson(
499 req, asyncResp->res, "LocationIndicatorActive",
500 locationIndicatorActive, "IndicatorLED", indicatorLed))
501 {
502 return;
503 }
504
505 // TODO (Gunnar): Remove IndicatorLED after enough time has passed
506 if (!locationIndicatorActive && !indicatorLed)
507 {
508 return; // delete this when we support more patch properties
509 }
510 if (indicatorLed)
511 {
512 asyncResp->res.addHeader(
513 boost::beast::http::field::warning,
514 "299 - \"IndicatorLED is deprecated. Use "
515 "LocationIndicatorActive instead.\"");
516 }
517
518 const std::array<const char*, 2> interfaces = {
519 "xyz.openbmc_project.Inventory.Item.Board",
520 "xyz.openbmc_project.Inventory.Item.Chassis"};
521
522 const std::string& chassisId = param;
523
524 crow::connections::systemBus->async_method_call(
525 [asyncResp, chassisId, locationIndicatorActive, indicatorLed](
526 const boost::system::error_code ec,
527 const crow::openbmc_mapper::GetSubTreeType& subtree) {
528 if (ec)
529 {
530 messages::internalError(asyncResp->res);
531 return;
532 }
533
534 // Iterate over all retrieved ObjectPaths.
535 for (const std::pair<
536 std::string,
537 std::vector<std::pair<std::string,
538 std::vector<std::string>>>>&
539 object : subtree)
540 {
541 const std::string& path = object.first;
542 const std::vector<
543 std::pair<std::string, std::vector<std::string>>>&
544 connectionNames = object.second;
545
546 if (!boost::ends_with(path, chassisId))
547 {
548 continue;
549 }
550
551 if (connectionNames.size() < 1)
552 {
553 BMCWEB_LOG_ERROR << "Got 0 Connection names";
554 continue;
555 }
556
557 const std::vector<std::string>& interfaces3 =
558 connectionNames[0].second;
559
560 const std::array<const char*, 2> hasIndicatorLed = {
561 "xyz.openbmc_project.Inventory.Item.Panel",
562 "xyz.openbmc_project.Inventory.Item.Board."
563 "Motherboard"};
564 bool indicatorChassis = false;
565 for (const char* interface : hasIndicatorLed)
566 {
567 if (std::find(interfaces3.begin(),
568 interfaces3.end(),
569 interface) != interfaces3.end())
570 {
571 indicatorChassis = true;
572 break;
Ed Tanous1abe55e2018-09-05 08:30:59 -0700573 }
John Edward Broadbent7e860f12021-04-08 15:57:16 -0700574 }
575 if (locationIndicatorActive)
576 {
577 if (indicatorChassis)
578 {
579 setLocationIndicatorActive(
580 asyncResp, *locationIndicatorActive);
581 }
582 else
583 {
584 messages::propertyUnknown(
585 asyncResp->res, "LocationIndicatorActive");
586 }
587 }
588 if (indicatorLed)
589 {
590 if (indicatorChassis)
591 {
592 setIndicatorLedState(asyncResp, *indicatorLed);
593 }
594 else
595 {
596 messages::propertyUnknown(asyncResp->res,
597 "IndicatorLED");
598 }
599 }
600 return;
James Feist1c8fba92019-12-20 15:12:07 -0800601 }
602
John Edward Broadbent7e860f12021-04-08 15:57:16 -0700603 messages::resourceNotFound(
604 asyncResp->res, "#Chassis.v1_14_0.Chassis", chassisId);
605 },
606 "xyz.openbmc_project.ObjectMapper",
607 "/xyz/openbmc_project/object_mapper",
608 "xyz.openbmc_project.ObjectMapper", "GetSubTree",
609 "/xyz/openbmc_project/inventory", 0, interfaces);
610 });
611}
P.K. Leedd99e042020-06-17 19:43:16 +0800612
zhanghch058d1b46d2021-04-01 11:18:24 +0800613inline void
614 doChassisPowerCycle(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp)
P.K. Leedd99e042020-06-17 19:43:16 +0800615{
Vijay Khemkac3b3c922020-09-22 23:00:12 -0700616 const char* busName = "xyz.openbmc_project.ObjectMapper";
617 const char* path = "/xyz/openbmc_project/object_mapper";
618 const char* interface = "xyz.openbmc_project.ObjectMapper";
619 const char* method = "GetSubTreePaths";
P.K. Leedd99e042020-06-17 19:43:16 +0800620
Vijay Khemkac3b3c922020-09-22 23:00:12 -0700621 const std::array<const char*, 1> interfaces = {
622 "xyz.openbmc_project.State.Chassis"};
623
624 // Use mapper to get subtree paths.
P.K. Leedd99e042020-06-17 19:43:16 +0800625 crow::connections::systemBus->async_method_call(
Vijay Khemkac3b3c922020-09-22 23:00:12 -0700626 [asyncResp](const boost::system::error_code ec,
627 const std::vector<std::string>& chassisList) {
P.K. Leedd99e042020-06-17 19:43:16 +0800628 if (ec)
629 {
Vijay Khemkac3b3c922020-09-22 23:00:12 -0700630 BMCWEB_LOG_DEBUG << "[mapper] Bad D-Bus request error: " << ec;
P.K. Leedd99e042020-06-17 19:43:16 +0800631 messages::internalError(asyncResp->res);
632 return;
633 }
634
Vijay Khemkac3b3c922020-09-22 23:00:12 -0700635 const char* processName = "xyz.openbmc_project.State.Chassis";
636 const char* interfaceName = "xyz.openbmc_project.State.Chassis";
637 const char* destProperty = "RequestedPowerTransition";
638 const std::string propertyValue =
639 "xyz.openbmc_project.State.Chassis.Transition.PowerCycle";
640 std::string objectPath =
641 "/xyz/openbmc_project/state/chassis_system0";
642
643 /* Look for system reset chassis path */
644 if ((std::find(chassisList.begin(), chassisList.end(),
645 objectPath)) == chassisList.end())
646 {
647 /* We prefer to reset the full chassis_system, but if it doesn't
648 * exist on some platforms, fall back to a host-only power reset
649 */
650 objectPath = "/xyz/openbmc_project/state/chassis0";
651 }
652
653 crow::connections::systemBus->async_method_call(
654 [asyncResp](const boost::system::error_code ec) {
655 // Use "Set" method to set the property value.
656 if (ec)
657 {
658 BMCWEB_LOG_DEBUG << "[Set] Bad D-Bus request error: "
659 << ec;
660 messages::internalError(asyncResp->res);
661 return;
662 }
663
664 messages::success(asyncResp->res);
665 },
666 processName, objectPath, "org.freedesktop.DBus.Properties",
667 "Set", interfaceName, destProperty,
668 std::variant<std::string>{propertyValue});
P.K. Leedd99e042020-06-17 19:43:16 +0800669 },
Vijay Khemkac3b3c922020-09-22 23:00:12 -0700670 busName, path, interface, method, "/", 0, interfaces);
P.K. Leedd99e042020-06-17 19:43:16 +0800671}
672
673/**
674 * ChassisResetAction class supports the POST method for the Reset
675 * action.
John Edward Broadbent7e860f12021-04-08 15:57:16 -0700676 * Function handles POST method request.
677 * Analyzes POST body before sending Reset request data to D-Bus.
P.K. Leedd99e042020-06-17 19:43:16 +0800678 */
John Edward Broadbent7e860f12021-04-08 15:57:16 -0700679
680inline void requestRoutesChassisResetAction(App& app)
P.K. Leedd99e042020-06-17 19:43:16 +0800681{
John Edward Broadbent7e860f12021-04-08 15:57:16 -0700682 BMCWEB_ROUTE(app, "/redfish/v1/Chassis/<str>/Actions/Chassis.Reset/")
Ed Tanoused398212021-06-09 17:05:54 -0700683 .privileges(redfish::privileges::postChassis)
John Edward Broadbent7e860f12021-04-08 15:57:16 -0700684 .methods(boost::beast::http::verb::post)(
685 [](const crow::Request& req,
686 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
687 const std::string&) {
688 BMCWEB_LOG_DEBUG << "Post Chassis Reset.";
P.K. Leedd99e042020-06-17 19:43:16 +0800689
John Edward Broadbent7e860f12021-04-08 15:57:16 -0700690 std::string resetType;
P.K. Leedd99e042020-06-17 19:43:16 +0800691
John Edward Broadbent7e860f12021-04-08 15:57:16 -0700692 if (!json_util::readJson(req, asyncResp->res, "ResetType",
693 resetType))
694 {
695 return;
696 }
P.K. Leedd99e042020-06-17 19:43:16 +0800697
John Edward Broadbent7e860f12021-04-08 15:57:16 -0700698 if (resetType != "PowerCycle")
699 {
700 BMCWEB_LOG_DEBUG << "Invalid property value for ResetType: "
701 << resetType;
702 messages::actionParameterNotSupported(
703 asyncResp->res, resetType, "ResetType");
P.K. Leedd99e042020-06-17 19:43:16 +0800704
John Edward Broadbent7e860f12021-04-08 15:57:16 -0700705 return;
706 }
707 doChassisPowerCycle(asyncResp);
708 });
709}
AppaRao Puli1cb1a9e2020-07-17 23:38:57 +0530710
711/**
712 * ChassisResetActionInfo derived class for delivering Chassis
713 * ResetType AllowableValues using ResetInfo schema.
714 */
John Edward Broadbent7e860f12021-04-08 15:57:16 -0700715inline void requestRoutesChassisResetActionInfo(App& app)
AppaRao Puli1cb1a9e2020-07-17 23:38:57 +0530716{
John Edward Broadbent7e860f12021-04-08 15:57:16 -0700717 BMCWEB_ROUTE(app, "/redfish/v1/Chassis/<str>/ResetActionInfo/")
Ed Tanoused398212021-06-09 17:05:54 -0700718 .privileges(redfish::privileges::getActionInfo)
John Edward Broadbent7e860f12021-04-08 15:57:16 -0700719 .methods(boost::beast::http::verb::get)(
720 [](const crow::Request&,
721 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
722 const std::string& chassisId)
AppaRao Puli1cb1a9e2020-07-17 23:38:57 +0530723
John Edward Broadbent7e860f12021-04-08 15:57:16 -0700724 {
725 asyncResp->res.jsonValue = {
726 {"@odata.type", "#ActionInfo.v1_1_2.ActionInfo"},
727 {"@odata.id",
728 "/redfish/v1/Chassis/" + chassisId + "/ResetActionInfo"},
729 {"Name", "Reset Action Info"},
730 {"Id", "ResetActionInfo"},
731 {"Parameters",
732 {{{"Name", "ResetType"},
733 {"Required", true},
734 {"DataType", "String"},
735 {"AllowableValues", {"PowerCycle"}}}}}};
736 });
737}
AppaRao Puli1cb1a9e2020-07-17 23:38:57 +0530738
Ed Tanous1abe55e2018-09-05 08:30:59 -0700739} // namespace redfish