blob: cd26849c653d6559d4878399d6aa5c03c6f8c770 [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"
Rapkiewicz, Pawele37f8452018-03-09 13:49:50 +010020#include "node.hpp"
Ed Tanous1abe55e2018-09-05 08:30:59 -070021
Rapkiewicz, Pawele37f8452018-03-09 13:49:50 +010022#include <boost/container/flat_map.hpp>
Gunnar Mills02f6ff12020-10-14 15:59:58 -050023#include <utils/collection.hpp>
Gunnar Mills1214b7e2020-06-04 10:11:30 -050024
Ed Tanousabf2add2019-01-22 16:40:12 -080025#include <variant>
Rapkiewicz, Pawele37f8452018-03-09 13:49:50 +010026
Ed Tanous1abe55e2018-09-05 08:30:59 -070027namespace redfish
28{
Rapkiewicz, Pawele37f8452018-03-09 13:49:50 +010029
30/**
Gunnar Millsbeeca0a2019-02-14 16:30:45 -060031 * @brief Retrieves chassis state properties over dbus
32 *
33 * @param[in] aResp - Shared pointer for completing asynchronous calls.
34 *
35 * @return None.
36 */
Ed Tanous23a21a12020-07-25 04:45:05 +000037inline void getChassisState(std::shared_ptr<AsyncResp> aResp)
Gunnar Millsbeeca0a2019-02-14 16:30:45 -060038{
39 crow::connections::systemBus->async_method_call(
40 [aResp{std::move(aResp)}](
41 const boost::system::error_code ec,
Gunnar Mills1214b7e2020-06-04 10:11:30 -050042 const std::variant<std::string>& chassisState) {
Gunnar Millsbeeca0a2019-02-14 16:30:45 -060043 if (ec)
44 {
45 BMCWEB_LOG_DEBUG << "DBUS response error " << ec;
46 messages::internalError(aResp->res);
47 return;
48 }
49
Gunnar Mills1214b7e2020-06-04 10:11:30 -050050 const std::string* s = std::get_if<std::string>(&chassisState);
Gunnar Millsbeeca0a2019-02-14 16:30:45 -060051 BMCWEB_LOG_DEBUG << "Chassis state: " << *s;
52 if (s != nullptr)
53 {
54 // Verify Chassis State
55 if (*s == "xyz.openbmc_project.State.Chassis.PowerState.On")
56 {
57 aResp->res.jsonValue["PowerState"] = "On";
58 aResp->res.jsonValue["Status"]["State"] = "Enabled";
59 }
60 else if (*s ==
61 "xyz.openbmc_project.State.Chassis.PowerState.Off")
62 {
63 aResp->res.jsonValue["PowerState"] = "Off";
64 aResp->res.jsonValue["Status"]["State"] = "StandbyOffline";
65 }
66 }
67 },
68 "xyz.openbmc_project.State.Chassis",
69 "/xyz/openbmc_project/state/chassis0",
70 "org.freedesktop.DBus.Properties", "Get",
71 "xyz.openbmc_project.State.Chassis", "CurrentPowerState");
72}
73
74/**
Rapkiewicz, Pawele37f8452018-03-09 13:49:50 +010075 * DBus types primitives for several generic DBus interfaces
76 * TODO(Pawel) consider move this to separate file into boost::dbus
77 */
Ed Tanous55c7b7a2018-05-22 15:27:24 -070078// Note, this is not a very useful Variant, but because it isn't used to get
Ed Tanousaa2e59c2018-04-12 12:17:20 -070079// values, it should be as simple as possible
80// TODO(ed) invent a nullvariant type
Cheng C Yang5fd7ba62019-11-28 15:58:08 +080081using VariantType = std::variant<bool, std::string, uint64_t, uint32_t>;
Ed Tanousaa2e59c2018-04-12 12:17:20 -070082using ManagedObjectsType = std::vector<std::pair<
83 sdbusplus::message::object_path,
84 std::vector<std::pair<std::string,
85 std::vector<std::pair<std::string, VariantType>>>>>>;
Rapkiewicz, Pawele37f8452018-03-09 13:49:50 +010086
Ed Tanousaa2e59c2018-04-12 12:17:20 -070087using PropertiesType = boost::container::flat_map<std::string, VariantType>;
Rapkiewicz, Pawele37f8452018-03-09 13:49:50 +010088
Ed Tanous23a21a12020-07-25 04:45:05 +000089inline void getIntrusionByService(std::shared_ptr<AsyncResp> aResp,
90 const std::string& service,
91 const std::string& objPath)
Qiang XUc1819422019-02-27 13:51:32 +080092{
93 BMCWEB_LOG_DEBUG << "Get intrusion status by service \n";
94
95 crow::connections::systemBus->async_method_call(
96 [aResp{std::move(aResp)}](const boost::system::error_code ec,
Gunnar Mills1214b7e2020-06-04 10:11:30 -050097 const std::variant<std::string>& value) {
Qiang XUc1819422019-02-27 13:51:32 +080098 if (ec)
99 {
Gunnar Mills4e0453b2020-07-08 14:00:30 -0500100 // do not add err msg in redfish response, because this is not
Qiang XUc1819422019-02-27 13:51:32 +0800101 // mandatory property
102 BMCWEB_LOG_ERROR << "DBUS response error " << ec << "\n";
103 return;
104 }
105
Gunnar Mills1214b7e2020-06-04 10:11:30 -0500106 const std::string* status = std::get_if<std::string>(&value);
Qiang XUc1819422019-02-27 13:51:32 +0800107
108 if (status == nullptr)
109 {
110 BMCWEB_LOG_ERROR << "intrusion status read error \n";
111 return;
112 }
113
114 aResp->res.jsonValue["PhysicalSecurity"] = {
115 {"IntrusionSensorNumber", 1}, {"IntrusionSensor", *status}};
116 },
117 service, objPath, "org.freedesktop.DBus.Properties", "Get",
118 "xyz.openbmc_project.Chassis.Intrusion", "Status");
119}
120
121/**
122 * Retrieves physical security properties over dbus
123 */
Ed Tanous23a21a12020-07-25 04:45:05 +0000124inline void getPhysicalSecurityData(std::shared_ptr<AsyncResp> aResp)
Qiang XUc1819422019-02-27 13:51:32 +0800125{
126 crow::connections::systemBus->async_method_call(
127 [aResp{std::move(aResp)}](
128 const boost::system::error_code ec,
129 const std::vector<std::pair<
130 std::string,
Gunnar Mills1214b7e2020-06-04 10:11:30 -0500131 std::vector<std::pair<std::string, std::vector<std::string>>>>>&
132 subtree) {
Qiang XUc1819422019-02-27 13:51:32 +0800133 if (ec)
134 {
Gunnar Mills4e0453b2020-07-08 14:00:30 -0500135 // do not add err msg in redfish response, because this is not
Qiang XUc1819422019-02-27 13:51:32 +0800136 // mandatory property
137 BMCWEB_LOG_ERROR << "DBUS error: no matched iface " << ec
138 << "\n";
139 return;
140 }
141 // Iterate over all retrieved ObjectPaths.
Gunnar Mills1214b7e2020-06-04 10:11:30 -0500142 for (const auto& object : subtree)
Qiang XUc1819422019-02-27 13:51:32 +0800143 {
Gunnar Mills1214b7e2020-06-04 10:11:30 -0500144 for (const auto& service : object.second)
Qiang XUc1819422019-02-27 13:51:32 +0800145 {
146 getIntrusionByService(aResp, service.first, object.first);
147 return;
148 }
149 }
150 },
151 "xyz.openbmc_project.ObjectMapper",
152 "/xyz/openbmc_project/object_mapper",
153 "xyz.openbmc_project.ObjectMapper", "GetSubTree",
Ed Tanous271584a2019-07-09 16:24:22 -0700154 "/xyz/openbmc_project/Intrusion", 1,
Gunnar Mills1214b7e2020-06-04 10:11:30 -0500155 std::array<const char*, 1>{"xyz.openbmc_project.Chassis.Intrusion"});
Qiang XUc1819422019-02-27 13:51:32 +0800156}
157
Rapkiewicz, Pawele37f8452018-03-09 13:49:50 +0100158/**
Rapkiewicz, Pawele37f8452018-03-09 13:49:50 +0100159 * ChassisCollection derived class for delivering Chassis Collection Schema
160 */
Ed Tanous1abe55e2018-09-05 08:30:59 -0700161class ChassisCollection : public Node
162{
163 public:
Ed Tanous52cc1122020-07-18 13:51:21 -0700164 ChassisCollection(App& app) : Node(app, "/redfish/v1/Chassis/")
Ed Tanous1abe55e2018-09-05 08:30:59 -0700165 {
Ed Tanous1abe55e2018-09-05 08:30:59 -0700166 entityPrivileges = {
167 {boost::beast::http::verb::get, {{"Login"}}},
168 {boost::beast::http::verb::head, {{"Login"}}},
169 {boost::beast::http::verb::patch, {{"ConfigureComponents"}}},
170 {boost::beast::http::verb::put, {{"ConfigureComponents"}}},
171 {boost::beast::http::verb::delete_, {{"ConfigureComponents"}}},
172 {boost::beast::http::verb::post, {{"ConfigureComponents"}}}};
173 }
Rapkiewicz, Pawele37f8452018-03-09 13:49:50 +0100174
Ed Tanous1abe55e2018-09-05 08:30:59 -0700175 private:
176 /**
177 * Functions triggers appropriate requests on DBus
178 */
Ed Tanouscb13a392020-07-25 19:02:03 +0000179 void doGet(crow::Response& res, const crow::Request&,
180 const std::vector<std::string>&) override
Ed Tanous1abe55e2018-09-05 08:30:59 -0700181 {
Ed Tanous0f74e642018-11-12 15:17:05 -0800182 res.jsonValue["@odata.type"] = "#ChassisCollection.ChassisCollection";
183 res.jsonValue["@odata.id"] = "/redfish/v1/Chassis";
Ed Tanous0f74e642018-11-12 15:17:05 -0800184 res.jsonValue["Name"] = "Chassis Collection";
185
Ed Tanous62d5e2e2018-09-05 16:17:25 -0700186 auto asyncResp = std::make_shared<AsyncResp>(res);
Rapkiewicz, Pawele37f8452018-03-09 13:49:50 +0100187
Gunnar Mills02f6ff12020-10-14 15:59:58 -0500188 collection_util::getCollectionMembers(
189 asyncResp, "/redfish/v1/Chassis",
190 {"xyz.openbmc_project.Inventory.Item.Board",
191 "xyz.openbmc_project.Inventory.Item.Chassis"});
Ed Tanous62d5e2e2018-09-05 16:17:25 -0700192 }
Rapkiewicz, Pawele37f8452018-03-09 13:49:50 +0100193};
194
195/**
196 * Chassis override class for delivering Chassis Schema
197 */
Ed Tanous1abe55e2018-09-05 08:30:59 -0700198class Chassis : public Node
199{
200 public:
Ed Tanous52cc1122020-07-18 13:51:21 -0700201 Chassis(App& app) : Node(app, "/redfish/v1/Chassis/<str>/", std::string())
Ed Tanous1abe55e2018-09-05 08:30:59 -0700202 {
Ed Tanous1abe55e2018-09-05 08:30:59 -0700203 entityPrivileges = {
204 {boost::beast::http::verb::get, {{"Login"}}},
205 {boost::beast::http::verb::head, {{"Login"}}},
206 {boost::beast::http::verb::patch, {{"ConfigureComponents"}}},
207 {boost::beast::http::verb::put, {{"ConfigureComponents"}}},
208 {boost::beast::http::verb::delete_, {{"ConfigureComponents"}}},
209 {boost::beast::http::verb::post, {{"ConfigureComponents"}}}};
Rapkiewicz, Pawele37f8452018-03-09 13:49:50 +0100210 }
Rapkiewicz, Pawele37f8452018-03-09 13:49:50 +0100211
Ed Tanous1abe55e2018-09-05 08:30:59 -0700212 private:
213 /**
214 * Functions triggers appropriate requests on DBus
215 */
Ed Tanouscb13a392020-07-25 19:02:03 +0000216 void doGet(crow::Response& res, const crow::Request&,
Gunnar Mills1214b7e2020-06-04 10:11:30 -0500217 const std::vector<std::string>& params) override
Ed Tanous1abe55e2018-09-05 08:30:59 -0700218 {
Gunnar Mills1214b7e2020-06-04 10:11:30 -0500219 const std::array<const char*, 2> interfaces = {
Gunnar Mills734bfe92019-01-21 16:33:50 -0600220 "xyz.openbmc_project.Inventory.Item.Board",
Shawn McCarneyadc4f0d2019-07-24 09:21:50 -0500221 "xyz.openbmc_project.Inventory.Item.Chassis"};
Gunnar Mills734bfe92019-01-21 16:33:50 -0600222
Ed Tanous1abe55e2018-09-05 08:30:59 -0700223 // Check if there is required param, truly entering this shall be
224 // impossible.
225 if (params.size() != 1)
226 {
Jason M. Billsf12894f2018-10-09 12:45:45 -0700227 messages::internalError(res);
Ed Tanousdaf36e22018-04-20 16:01:36 -0700228 res.end();
229 return;
Ed Tanous1abe55e2018-09-05 08:30:59 -0700230 }
Gunnar Mills1214b7e2020-06-04 10:11:30 -0500231 const std::string& chassisId = params[0];
Ed Tanouse0d918b2018-03-27 17:41:04 -0700232
Ed Tanous62d5e2e2018-09-05 16:17:25 -0700233 auto asyncResp = std::make_shared<AsyncResp>(res);
Ed Tanous1abe55e2018-09-05 08:30:59 -0700234 crow::connections::systemBus->async_method_call(
Ed Tanous62d5e2e2018-09-05 16:17:25 -0700235 [asyncResp, chassisId(std::string(chassisId))](
236 const boost::system::error_code ec,
Gunnar Mills1214b7e2020-06-04 10:11:30 -0500237 const crow::openbmc_mapper::GetSubTreeType& subtree) {
Ed Tanous62d5e2e2018-09-05 16:17:25 -0700238 if (ec)
Ed Tanous1abe55e2018-09-05 08:30:59 -0700239 {
Jason M. Billsf12894f2018-10-09 12:45:45 -0700240 messages::internalError(asyncResp->res);
Ed Tanous1abe55e2018-09-05 08:30:59 -0700241 return;
242 }
243 // Iterate over all retrieved ObjectPaths.
244 for (const std::pair<
245 std::string,
246 std::vector<
Gunnar Mills1214b7e2020-06-04 10:11:30 -0500247 std::pair<std::string, std::vector<std::string>>>>&
248 object : subtree)
Ed Tanous1abe55e2018-09-05 08:30:59 -0700249 {
Gunnar Mills1214b7e2020-06-04 10:11:30 -0500250 const std::string& path = object.first;
Ed Tanous1abe55e2018-09-05 08:30:59 -0700251 const std::vector<
Gunnar Mills1214b7e2020-06-04 10:11:30 -0500252 std::pair<std::string, std::vector<std::string>>>&
253 connectionNames = object.second;
Ed Tanouse0d918b2018-03-27 17:41:04 -0700254
Ed Tanous1abe55e2018-09-05 08:30:59 -0700255 if (!boost::ends_with(path, chassisId))
256 {
257 continue;
Ed Tanousdaf36e22018-04-20 16:01:36 -0700258 }
Shawn McCarney26f03892019-05-03 13:20:24 -0500259
James Feistb49ac872019-05-21 15:12:01 -0700260 auto health = std::make_shared<HealthPopulate>(asyncResp);
261
262 crow::connections::systemBus->async_method_call(
Ed Tanous23a21a12020-07-25 04:45:05 +0000263 [health](const boost::system::error_code ec2,
Gunnar Mills1214b7e2020-06-04 10:11:30 -0500264 std::variant<std::vector<std::string>>& resp) {
Ed Tanous23a21a12020-07-25 04:45:05 +0000265 if (ec2)
James Feistb49ac872019-05-21 15:12:01 -0700266 {
267 return; // no sensors = no failures
268 }
Gunnar Mills1214b7e2020-06-04 10:11:30 -0500269 std::vector<std::string>* data =
James Feistb49ac872019-05-21 15:12:01 -0700270 std::get_if<std::vector<std::string>>(&resp);
271 if (data == nullptr)
272 {
273 return;
274 }
275 health->inventory = std::move(*data);
276 },
277 "xyz.openbmc_project.ObjectMapper",
278 path + "/all_sensors",
279 "org.freedesktop.DBus.Properties", "Get",
280 "xyz.openbmc_project.Association", "endpoints");
281
282 health->populate();
283
Ed Tanous1abe55e2018-09-05 08:30:59 -0700284 if (connectionNames.size() < 1)
285 {
James Feist1c8fba92019-12-20 15:12:07 -0800286 BMCWEB_LOG_ERROR << "Got 0 Connection names";
Ed Tanous1abe55e2018-09-05 08:30:59 -0700287 continue;
288 }
Ed Tanouse0d918b2018-03-27 17:41:04 -0700289
Johnathan Mantey49c53ac2019-05-02 09:22:38 -0700290 asyncResp->res.jsonValue["@odata.type"] =
Gunnar Mills9f8bfa72020-09-28 13:45:19 -0500291 "#Chassis.v1_14_0.Chassis";
Johnathan Mantey49c53ac2019-05-02 09:22:38 -0700292 asyncResp->res.jsonValue["@odata.id"] =
293 "/redfish/v1/Chassis/" + chassisId;
Johnathan Mantey49c53ac2019-05-02 09:22:38 -0700294 asyncResp->res.jsonValue["Name"] = "Chassis Collection";
295 asyncResp->res.jsonValue["ChassisType"] = "RackMount";
P.K. Leedd99e042020-06-17 19:43:16 +0800296 asyncResp->res.jsonValue["Actions"]["#Chassis.Reset"] = {
297 {"target", "/redfish/v1/Chassis/" + chassisId +
298 "/Actions/Chassis.Reset"},
AppaRao Puli1cb1a9e2020-07-17 23:38:57 +0530299 {"@Redfish.ActionInfo", "/redfish/v1/Chassis/" +
300 chassisId +
301 "/ResetActionInfo"}};
Jason M. Billsadbe1922019-10-14 15:44:35 -0700302 asyncResp->res.jsonValue["PCIeDevices"] = {
303 {"@odata.id",
304 "/redfish/v1/Systems/system/PCIeDevices"}};
Johnathan Mantey49c53ac2019-05-02 09:22:38 -0700305
Gunnar Mills1214b7e2020-06-04 10:11:30 -0500306 const std::string& connectionName =
Johnathan Mantey49c53ac2019-05-02 09:22:38 -0700307 connectionNames[0].first;
James Feist1c8fba92019-12-20 15:12:07 -0800308
Ed Tanous23a21a12020-07-25 04:45:05 +0000309 const std::vector<std::string>& interfaces2 =
James Feist1c8fba92019-12-20 15:12:07 -0800310 connectionNames[0].second;
Gunnar Mills1214b7e2020-06-04 10:11:30 -0500311 const std::array<const char*, 2> hasIndicatorLed = {
James Feist1c8fba92019-12-20 15:12:07 -0800312 "xyz.openbmc_project.Inventory.Item.Panel",
313 "xyz.openbmc_project.Inventory.Item.Board.Motherboard"};
314
Gunnar Mills1214b7e2020-06-04 10:11:30 -0500315 for (const char* interface : hasIndicatorLed)
James Feist1c8fba92019-12-20 15:12:07 -0800316 {
Ed Tanous23a21a12020-07-25 04:45:05 +0000317 if (std::find(interfaces2.begin(), interfaces2.end(),
318 interface) != interfaces2.end())
James Feist1c8fba92019-12-20 15:12:07 -0800319 {
320 getIndicatorLedState(asyncResp);
Gunnar Mills9f8bfa72020-09-28 13:45:19 -0500321 getLocationIndicatorActive(asyncResp);
James Feist1c8fba92019-12-20 15:12:07 -0800322 break;
323 }
324 }
325
Ed Tanous1abe55e2018-09-05 08:30:59 -0700326 crow::connections::systemBus->async_method_call(
Ed Tanous62d5e2e2018-09-05 16:17:25 -0700327 [asyncResp, chassisId(std::string(chassisId))](
Ed Tanous90728b52020-08-19 09:06:34 -0700328 const boost::system::error_code /*ec2*/,
Ed Tanous1abe55e2018-09-05 08:30:59 -0700329 const std::vector<std::pair<
Gunnar Mills1214b7e2020-06-04 10:11:30 -0500330 std::string, VariantType>>& propertiesList) {
331 for (const std::pair<std::string, VariantType>&
332 property : propertiesList)
Ed Tanous1abe55e2018-09-05 08:30:59 -0700333 {
Shawn McCarney99cffd72019-03-01 10:46:20 -0600334 // Store DBus properties that are also Redfish
335 // properties with same name and a string value
Gunnar Mills1214b7e2020-06-04 10:11:30 -0500336 const std::string& propertyName =
Shawn McCarney99cffd72019-03-01 10:46:20 -0600337 property.first;
338 if ((propertyName == "PartNumber") ||
339 (propertyName == "SerialNumber") ||
340 (propertyName == "Manufacturer") ||
341 (propertyName == "Model"))
Ed Tanous1abe55e2018-09-05 08:30:59 -0700342 {
Gunnar Mills1214b7e2020-06-04 10:11:30 -0500343 const std::string* value =
Shawn McCarney99cffd72019-03-01 10:46:20 -0600344 std::get_if<std::string>(
345 &property.second);
346 if (value != nullptr)
347 {
348 asyncResp->res.jsonValue[propertyName] =
349 *value;
350 }
Ed Tanous1abe55e2018-09-05 08:30:59 -0700351 }
352 }
Ed Tanous62d5e2e2018-09-05 16:17:25 -0700353 asyncResp->res.jsonValue["Name"] = chassisId;
354 asyncResp->res.jsonValue["Id"] = chassisId;
355 asyncResp->res.jsonValue["Thermal"] = {
Ed Tanous1abe55e2018-09-05 08:30:59 -0700356 {"@odata.id", "/redfish/v1/Chassis/" +
357 chassisId + "/Thermal"}};
Ed Tanous2474adf2018-09-05 16:31:16 -0700358 // Power object
359 asyncResp->res.jsonValue["Power"] = {
360 {"@odata.id", "/redfish/v1/Chassis/" +
361 chassisId + "/Power"}};
Anthony Wilson95a3eca2019-06-11 10:44:47 -0500362 // SensorCollection
363 asyncResp->res.jsonValue["Sensors"] = {
364 {"@odata.id", "/redfish/v1/Chassis/" +
365 chassisId + "/Sensors"}};
Ed Tanous029573d2019-02-01 10:57:49 -0800366 asyncResp->res.jsonValue["Status"] = {
Ed Tanous029573d2019-02-01 10:57:49 -0800367 {"State", "Enabled"},
368 };
Ed Tanous2474adf2018-09-05 16:31:16 -0700369
Ed Tanous029573d2019-02-01 10:57:49 -0800370 asyncResp->res
371 .jsonValue["Links"]["ComputerSystems"] = {
372 {{"@odata.id", "/redfish/v1/Systems/system"}}};
373 asyncResp->res.jsonValue["Links"]["ManagedBy"] = {
374 {{"@odata.id", "/redfish/v1/Managers/bmc"}}};
Gunnar Millsbeeca0a2019-02-14 16:30:45 -0600375 getChassisState(asyncResp);
Ed Tanous1abe55e2018-09-05 08:30:59 -0700376 },
377 connectionName, path, "org.freedesktop.DBus.Properties",
378 "GetAll",
379 "xyz.openbmc_project.Inventory.Decorator.Asset");
Ed Tanous1abe55e2018-09-05 08:30:59 -0700380 return;
381 }
Ed Tanouse0d918b2018-03-27 17:41:04 -0700382
Ed Tanous1abe55e2018-09-05 08:30:59 -0700383 // Couldn't find an object with that name. return an error
Jason M. Billsf12894f2018-10-09 12:45:45 -0700384 messages::resourceNotFound(
Gunnar Mills9f8bfa72020-09-28 13:45:19 -0500385 asyncResp->res, "#Chassis.v1_14_0.Chassis", chassisId);
Ed Tanous1abe55e2018-09-05 08:30:59 -0700386 },
387 "xyz.openbmc_project.ObjectMapper",
388 "/xyz/openbmc_project/object_mapper",
389 "xyz.openbmc_project.ObjectMapper", "GetSubTree",
Ed Tanous271584a2019-07-09 16:24:22 -0700390 "/xyz/openbmc_project/inventory", 0, interfaces);
Qiang XUc1819422019-02-27 13:51:32 +0800391
392 getPhysicalSecurityData(asyncResp);
Ed Tanous1abe55e2018-09-05 08:30:59 -0700393 }
James Feist1c8fba92019-12-20 15:12:07 -0800394
Gunnar Mills1214b7e2020-06-04 10:11:30 -0500395 void doPatch(crow::Response& res, const crow::Request& req,
396 const std::vector<std::string>& params) override
James Feist1c8fba92019-12-20 15:12:07 -0800397 {
Gunnar Mills9f8bfa72020-09-28 13:45:19 -0500398 std::optional<bool> locationIndicatorActive;
James Feist1c8fba92019-12-20 15:12:07 -0800399 std::optional<std::string> indicatorLed;
400 auto asyncResp = std::make_shared<AsyncResp>(res);
401
402 if (params.size() != 1)
403 {
404 return;
405 }
406
Gunnar Mills9f8bfa72020-09-28 13:45:19 -0500407 if (!json_util::readJson(req, res, "LocationIndicatorActive",
408 locationIndicatorActive, "IndicatorLED",
409 indicatorLed))
James Feist1c8fba92019-12-20 15:12:07 -0800410 {
411 return;
412 }
413
Gunnar Mills9f8bfa72020-09-28 13:45:19 -0500414 // TODO (Gunnar): Remove IndicatorLED after enough time has passed
415 if (!locationIndicatorActive && !indicatorLed)
James Feist1c8fba92019-12-20 15:12:07 -0800416 {
417 return; // delete this when we support more patch properties
418 }
419
Gunnar Mills1214b7e2020-06-04 10:11:30 -0500420 const std::array<const char*, 2> interfaces = {
James Feist1c8fba92019-12-20 15:12:07 -0800421 "xyz.openbmc_project.Inventory.Item.Board",
422 "xyz.openbmc_project.Inventory.Item.Chassis"};
423
Gunnar Mills1214b7e2020-06-04 10:11:30 -0500424 const std::string& chassisId = params[0];
James Feist1c8fba92019-12-20 15:12:07 -0800425
426 crow::connections::systemBus->async_method_call(
Gunnar Mills9f8bfa72020-09-28 13:45:19 -0500427 [asyncResp, chassisId, locationIndicatorActive, indicatorLed](
James Feist1c8fba92019-12-20 15:12:07 -0800428 const boost::system::error_code ec,
Gunnar Mills1214b7e2020-06-04 10:11:30 -0500429 const crow::openbmc_mapper::GetSubTreeType& subtree) {
James Feist1c8fba92019-12-20 15:12:07 -0800430 if (ec)
431 {
432 messages::internalError(asyncResp->res);
433 return;
434 }
435
436 // Iterate over all retrieved ObjectPaths.
437 for (const std::pair<
438 std::string,
439 std::vector<
Gunnar Mills1214b7e2020-06-04 10:11:30 -0500440 std::pair<std::string, std::vector<std::string>>>>&
441 object : subtree)
James Feist1c8fba92019-12-20 15:12:07 -0800442 {
Gunnar Mills1214b7e2020-06-04 10:11:30 -0500443 const std::string& path = object.first;
James Feist1c8fba92019-12-20 15:12:07 -0800444 const std::vector<
Gunnar Mills1214b7e2020-06-04 10:11:30 -0500445 std::pair<std::string, std::vector<std::string>>>&
446 connectionNames = object.second;
James Feist1c8fba92019-12-20 15:12:07 -0800447
448 if (!boost::ends_with(path, chassisId))
449 {
450 continue;
451 }
452
453 if (connectionNames.size() < 1)
454 {
455 BMCWEB_LOG_ERROR << "Got 0 Connection names";
456 continue;
457 }
458
Ed Tanous23a21a12020-07-25 04:45:05 +0000459 const std::vector<std::string>& interfaces3 =
James Feist1c8fba92019-12-20 15:12:07 -0800460 connectionNames[0].second;
461
Gunnar Mills9f8bfa72020-09-28 13:45:19 -0500462 const std::array<const char*, 2> hasIndicatorLed = {
463 "xyz.openbmc_project.Inventory.Item.Panel",
464 "xyz.openbmc_project.Inventory.Item.Board."
465 "Motherboard"};
466 bool indicatorChassis = false;
467 for (const char* interface : hasIndicatorLed)
468 {
469 if (std::find(interfaces3.begin(), interfaces3.end(),
470 interface) != interfaces3.end())
471 {
472 indicatorChassis = true;
473 break;
474 }
475 }
476 if (locationIndicatorActive)
477 {
478 if (indicatorChassis)
479 {
480 setLocationIndicatorActive(
481 asyncResp, *locationIndicatorActive);
482 }
483 else
484 {
485 messages::propertyUnknown(
486 asyncResp->res, "LocationIndicatorActive");
487 }
488 }
James Feist1c8fba92019-12-20 15:12:07 -0800489 if (indicatorLed)
490 {
James Feist1c8fba92019-12-20 15:12:07 -0800491 if (indicatorChassis)
492 {
Ed Tanousf23b7292020-10-15 09:41:17 -0700493 setIndicatorLedState(asyncResp, *indicatorLed);
James Feist1c8fba92019-12-20 15:12:07 -0800494 }
495 else
496 {
497 messages::propertyUnknown(asyncResp->res,
498 "IndicatorLED");
499 }
500 }
501 return;
502 }
503
504 messages::resourceNotFound(
Gunnar Mills9f8bfa72020-09-28 13:45:19 -0500505 asyncResp->res, "#Chassis.v1_14_0.Chassis", chassisId);
James Feist1c8fba92019-12-20 15:12:07 -0800506 },
507 "xyz.openbmc_project.ObjectMapper",
508 "/xyz/openbmc_project/object_mapper",
509 "xyz.openbmc_project.ObjectMapper", "GetSubTree",
510 "/xyz/openbmc_project/inventory", 0, interfaces);
511 }
Ed Tanous62d5e2e2018-09-05 16:17:25 -0700512};
P.K. Leedd99e042020-06-17 19:43:16 +0800513
Ed Tanousb5a76932020-09-29 16:16:58 -0700514inline void doChassisPowerCycle(const std::shared_ptr<AsyncResp>& asyncResp)
P.K. Leedd99e042020-06-17 19:43:16 +0800515{
Vijay Khemkac3b3c922020-09-22 23:00:12 -0700516 const char* busName = "xyz.openbmc_project.ObjectMapper";
517 const char* path = "/xyz/openbmc_project/object_mapper";
518 const char* interface = "xyz.openbmc_project.ObjectMapper";
519 const char* method = "GetSubTreePaths";
P.K. Leedd99e042020-06-17 19:43:16 +0800520
Vijay Khemkac3b3c922020-09-22 23:00:12 -0700521 const std::array<const char*, 1> interfaces = {
522 "xyz.openbmc_project.State.Chassis"};
523
524 // Use mapper to get subtree paths.
P.K. Leedd99e042020-06-17 19:43:16 +0800525 crow::connections::systemBus->async_method_call(
Vijay Khemkac3b3c922020-09-22 23:00:12 -0700526 [asyncResp](const boost::system::error_code ec,
527 const std::vector<std::string>& chassisList) {
P.K. Leedd99e042020-06-17 19:43:16 +0800528 if (ec)
529 {
Vijay Khemkac3b3c922020-09-22 23:00:12 -0700530 BMCWEB_LOG_DEBUG << "[mapper] Bad D-Bus request error: " << ec;
P.K. Leedd99e042020-06-17 19:43:16 +0800531 messages::internalError(asyncResp->res);
532 return;
533 }
534
Vijay Khemkac3b3c922020-09-22 23:00:12 -0700535 const char* processName = "xyz.openbmc_project.State.Chassis";
536 const char* interfaceName = "xyz.openbmc_project.State.Chassis";
537 const char* destProperty = "RequestedPowerTransition";
538 const std::string propertyValue =
539 "xyz.openbmc_project.State.Chassis.Transition.PowerCycle";
540 std::string objectPath =
541 "/xyz/openbmc_project/state/chassis_system0";
542
543 /* Look for system reset chassis path */
544 if ((std::find(chassisList.begin(), chassisList.end(),
545 objectPath)) == chassisList.end())
546 {
547 /* We prefer to reset the full chassis_system, but if it doesn't
548 * exist on some platforms, fall back to a host-only power reset
549 */
550 objectPath = "/xyz/openbmc_project/state/chassis0";
551 }
552
553 crow::connections::systemBus->async_method_call(
554 [asyncResp](const boost::system::error_code ec) {
555 // Use "Set" method to set the property value.
556 if (ec)
557 {
558 BMCWEB_LOG_DEBUG << "[Set] Bad D-Bus request error: "
559 << ec;
560 messages::internalError(asyncResp->res);
561 return;
562 }
563
564 messages::success(asyncResp->res);
565 },
566 processName, objectPath, "org.freedesktop.DBus.Properties",
567 "Set", interfaceName, destProperty,
568 std::variant<std::string>{propertyValue});
P.K. Leedd99e042020-06-17 19:43:16 +0800569 },
Vijay Khemkac3b3c922020-09-22 23:00:12 -0700570 busName, path, interface, method, "/", 0, interfaces);
P.K. Leedd99e042020-06-17 19:43:16 +0800571}
572
573/**
574 * ChassisResetAction class supports the POST method for the Reset
575 * action.
576 */
577class ChassisResetAction : public Node
578{
579 public:
Ed Tanous52cc1122020-07-18 13:51:21 -0700580 ChassisResetAction(App& app) :
P.K. Leedd99e042020-06-17 19:43:16 +0800581 Node(app, "/redfish/v1/Chassis/<str>/Actions/Chassis.Reset/",
582 std::string())
583 {
584 entityPrivileges = {
585 {boost::beast::http::verb::post, {{"ConfigureComponents"}}}};
586 }
587
588 private:
589 /**
590 * Function handles POST method request.
591 * Analyzes POST body before sending Reset request data to D-Bus.
592 */
593 void doPost(crow::Response& res, const crow::Request& req,
Ed Tanouscb13a392020-07-25 19:02:03 +0000594 const std::vector<std::string>&) override
P.K. Leedd99e042020-06-17 19:43:16 +0800595 {
596 BMCWEB_LOG_DEBUG << "Post Chassis Reset.";
597
598 std::string resetType;
599 auto asyncResp = std::make_shared<AsyncResp>(res);
600
601 if (!json_util::readJson(req, asyncResp->res, "ResetType", resetType))
602 {
603 return;
604 }
605
606 if (resetType != "PowerCycle")
607 {
608 BMCWEB_LOG_DEBUG << "Invalid property value for ResetType: "
609 << resetType;
610 messages::actionParameterNotSupported(asyncResp->res, resetType,
611 "ResetType");
612
613 return;
614 }
615 doChassisPowerCycle(asyncResp);
616 }
617};
AppaRao Puli1cb1a9e2020-07-17 23:38:57 +0530618
619/**
620 * ChassisResetActionInfo derived class for delivering Chassis
621 * ResetType AllowableValues using ResetInfo schema.
622 */
623class ChassisResetActionInfo : public Node
624{
625 public:
626 /*
627 * Default Constructor
628 */
Ed Tanous52cc1122020-07-18 13:51:21 -0700629 ChassisResetActionInfo(App& app) :
AppaRao Puli1cb1a9e2020-07-17 23:38:57 +0530630 Node(app, "/redfish/v1/Chassis/<str>/ResetActionInfo/", std::string())
631 {
632 entityPrivileges = {
633 {boost::beast::http::verb::get, {{"Login"}}},
634 {boost::beast::http::verb::head, {{"Login"}}},
635 {boost::beast::http::verb::patch, {{"ConfigureComponents"}}},
636 {boost::beast::http::verb::put, {{"ConfigureComponents"}}},
637 {boost::beast::http::verb::delete_, {{"ConfigureComponents"}}},
638 {boost::beast::http::verb::post, {{"ConfigureComponents"}}}};
639 }
640
641 private:
642 /**
643 * Functions triggers appropriate requests on DBus
644 */
Ed Tanouscb13a392020-07-25 19:02:03 +0000645 void doGet(crow::Response& res, const crow::Request&,
AppaRao Puli1cb1a9e2020-07-17 23:38:57 +0530646 const std::vector<std::string>& params) override
647 {
648 if (params.size() != 1)
649 {
650 messages::internalError(res);
651 res.end();
652 return;
653 }
654 const std::string& chassisId = params[0];
655
656 res.jsonValue = {{"@odata.type", "#ActionInfo.v1_1_2.ActionInfo"},
657 {"@odata.id", "/redfish/v1/Chassis/" + chassisId +
658 "/ResetActionInfo"},
659 {"Name", "Reset Action Info"},
660 {"Id", "ResetActionInfo"},
661 {"Parameters",
662 {{{"Name", "ResetType"},
663 {"Required", true},
664 {"DataType", "String"},
665 {"AllowableValues", {"PowerCycle"}}}}}};
666 res.end();
667 }
668};
669
Ed Tanous1abe55e2018-09-05 08:30:59 -0700670} // namespace redfish