Rapkiewicz, Pawel | e37f845 | 2018-03-09 13:49:50 +0100 | [diff] [blame] | 1 | /* |
| 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 Feist | b49ac87 | 2019-05-21 15:12:01 -0700 | [diff] [blame] | 18 | #include "health.hpp" |
James Feist | 1c8fba9 | 2019-12-20 15:12:07 -0800 | [diff] [blame] | 19 | #include "led.hpp" |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 20 | |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 21 | #include <app.hpp> |
Ed Tanous | 168e20c | 2021-12-13 14:39:53 -0800 | [diff] [blame] | 22 | #include <dbus_utility.hpp> |
Ed Tanous | 45ca1b8 | 2022-03-25 13:07:27 -0700 | [diff] [blame] | 23 | #include <query.hpp> |
Ed Tanous | ed39821 | 2021-06-09 17:05:54 -0700 | [diff] [blame] | 24 | #include <registries/privilege_registry.hpp> |
Jonathan Doman | 1e1e598 | 2021-06-11 09:36:17 -0700 | [diff] [blame] | 25 | #include <sdbusplus/asio/property.hpp> |
Gunnar Mills | 02f6ff1 | 2020-10-14 15:59:58 -0500 | [diff] [blame] | 26 | #include <utils/collection.hpp> |
Gunnar Mills | 1214b7e | 2020-06-04 10:11:30 -0500 | [diff] [blame] | 27 | |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 28 | namespace redfish |
| 29 | { |
Rapkiewicz, Pawel | e37f845 | 2018-03-09 13:49:50 +0100 | [diff] [blame] | 30 | |
| 31 | /** |
Gunnar Mills | beeca0a | 2019-02-14 16:30:45 -0600 | [diff] [blame] | 32 | * @brief Retrieves chassis state properties over dbus |
| 33 | * |
| 34 | * @param[in] aResp - Shared pointer for completing asynchronous calls. |
| 35 | * |
| 36 | * @return None. |
| 37 | */ |
zhanghch05 | 8d1b46d | 2021-04-01 11:18:24 +0800 | [diff] [blame] | 38 | inline void getChassisState(std::shared_ptr<bmcweb::AsyncResp> aResp) |
Gunnar Mills | beeca0a | 2019-02-14 16:30:45 -0600 | [diff] [blame] | 39 | { |
Jonathan Doman | 1e1e598 | 2021-06-11 09:36:17 -0700 | [diff] [blame] | 40 | // crow::connections::systemBus->async_method_call( |
| 41 | sdbusplus::asio::getProperty<std::string>( |
| 42 | *crow::connections::systemBus, "xyz.openbmc_project.State.Chassis", |
| 43 | "/xyz/openbmc_project/state/chassis0", |
| 44 | "xyz.openbmc_project.State.Chassis", "CurrentPowerState", |
| 45 | [aResp{std::move(aResp)}](const boost::system::error_code ec, |
| 46 | const std::string& chassisState) { |
Gunnar Mills | beeca0a | 2019-02-14 16:30:45 -0600 | [diff] [blame] | 47 | if (ec) |
| 48 | { |
Carson Labrado | a6e5e0a | 2022-02-15 00:26:03 +0000 | [diff] [blame] | 49 | if (ec == boost::system::errc::host_unreachable) |
| 50 | { |
| 51 | // Service not available, no error, just don't return |
| 52 | // chassis state info |
| 53 | BMCWEB_LOG_DEBUG << "Service not available " << ec; |
| 54 | return; |
| 55 | } |
Gunnar Mills | beeca0a | 2019-02-14 16:30:45 -0600 | [diff] [blame] | 56 | BMCWEB_LOG_DEBUG << "DBUS response error " << ec; |
| 57 | messages::internalError(aResp->res); |
| 58 | return; |
| 59 | } |
| 60 | |
Jonathan Doman | 1e1e598 | 2021-06-11 09:36:17 -0700 | [diff] [blame] | 61 | BMCWEB_LOG_DEBUG << "Chassis state: " << chassisState; |
| 62 | // Verify Chassis State |
| 63 | if (chassisState == |
| 64 | "xyz.openbmc_project.State.Chassis.PowerState.On") |
Gunnar Mills | beeca0a | 2019-02-14 16:30:45 -0600 | [diff] [blame] | 65 | { |
Jonathan Doman | 1e1e598 | 2021-06-11 09:36:17 -0700 | [diff] [blame] | 66 | aResp->res.jsonValue["PowerState"] = "On"; |
| 67 | aResp->res.jsonValue["Status"]["State"] = "Enabled"; |
Gunnar Mills | beeca0a | 2019-02-14 16:30:45 -0600 | [diff] [blame] | 68 | } |
Jonathan Doman | 1e1e598 | 2021-06-11 09:36:17 -0700 | [diff] [blame] | 69 | else if (chassisState == |
| 70 | "xyz.openbmc_project.State.Chassis.PowerState.Off") |
| 71 | { |
| 72 | aResp->res.jsonValue["PowerState"] = "Off"; |
| 73 | aResp->res.jsonValue["Status"]["State"] = "StandbyOffline"; |
| 74 | } |
| 75 | }); |
Gunnar Mills | beeca0a | 2019-02-14 16:30:45 -0600 | [diff] [blame] | 76 | } |
| 77 | |
zhanghch05 | 8d1b46d | 2021-04-01 11:18:24 +0800 | [diff] [blame] | 78 | inline void getIntrusionByService(std::shared_ptr<bmcweb::AsyncResp> aResp, |
Ed Tanous | 23a21a1 | 2020-07-25 04:45:05 +0000 | [diff] [blame] | 79 | const std::string& service, |
| 80 | const std::string& objPath) |
Qiang XU | c181942 | 2019-02-27 13:51:32 +0800 | [diff] [blame] | 81 | { |
| 82 | BMCWEB_LOG_DEBUG << "Get intrusion status by service \n"; |
| 83 | |
Jonathan Doman | 1e1e598 | 2021-06-11 09:36:17 -0700 | [diff] [blame] | 84 | sdbusplus::asio::getProperty<std::string>( |
| 85 | *crow::connections::systemBus, service, objPath, |
| 86 | "xyz.openbmc_project.Chassis.Intrusion", "Status", |
Qiang XU | c181942 | 2019-02-27 13:51:32 +0800 | [diff] [blame] | 87 | [aResp{std::move(aResp)}](const boost::system::error_code ec, |
Jonathan Doman | 1e1e598 | 2021-06-11 09:36:17 -0700 | [diff] [blame] | 88 | const std::string& value) { |
Qiang XU | c181942 | 2019-02-27 13:51:32 +0800 | [diff] [blame] | 89 | if (ec) |
| 90 | { |
Gunnar Mills | 4e0453b | 2020-07-08 14:00:30 -0500 | [diff] [blame] | 91 | // do not add err msg in redfish response, because this is not |
Qiang XU | c181942 | 2019-02-27 13:51:32 +0800 | [diff] [blame] | 92 | // mandatory property |
| 93 | BMCWEB_LOG_ERROR << "DBUS response error " << ec << "\n"; |
| 94 | return; |
| 95 | } |
| 96 | |
Ed Tanous | 1476687 | 2022-03-15 10:44:42 -0700 | [diff] [blame] | 97 | aResp->res.jsonValue["PhysicalSecurity"]["IntrusionSensorNumber"] = |
| 98 | 1; |
| 99 | aResp->res.jsonValue["PhysicalSecurity"]["IntrusionSensor"] = value; |
Jonathan Doman | 1e1e598 | 2021-06-11 09:36:17 -0700 | [diff] [blame] | 100 | }); |
Qiang XU | c181942 | 2019-02-27 13:51:32 +0800 | [diff] [blame] | 101 | } |
| 102 | |
| 103 | /** |
| 104 | * Retrieves physical security properties over dbus |
| 105 | */ |
zhanghch05 | 8d1b46d | 2021-04-01 11:18:24 +0800 | [diff] [blame] | 106 | inline void getPhysicalSecurityData(std::shared_ptr<bmcweb::AsyncResp> aResp) |
Qiang XU | c181942 | 2019-02-27 13:51:32 +0800 | [diff] [blame] | 107 | { |
| 108 | crow::connections::systemBus->async_method_call( |
| 109 | [aResp{std::move(aResp)}]( |
| 110 | const boost::system::error_code ec, |
Ed Tanous | b9d36b4 | 2022-02-26 21:42:46 -0800 | [diff] [blame] | 111 | const dbus::utility::MapperGetSubTreeResponse& subtree) { |
Qiang XU | c181942 | 2019-02-27 13:51:32 +0800 | [diff] [blame] | 112 | if (ec) |
| 113 | { |
Gunnar Mills | 4e0453b | 2020-07-08 14:00:30 -0500 | [diff] [blame] | 114 | // do not add err msg in redfish response, because this is not |
Qiang XU | c181942 | 2019-02-27 13:51:32 +0800 | [diff] [blame] | 115 | // mandatory property |
Andrew Geissler | 54fbf17 | 2021-11-11 15:59:30 -0600 | [diff] [blame] | 116 | BMCWEB_LOG_INFO << "DBUS error: no matched iface " << ec |
| 117 | << "\n"; |
Qiang XU | c181942 | 2019-02-27 13:51:32 +0800 | [diff] [blame] | 118 | return; |
| 119 | } |
| 120 | // Iterate over all retrieved ObjectPaths. |
Gunnar Mills | 1214b7e | 2020-06-04 10:11:30 -0500 | [diff] [blame] | 121 | for (const auto& object : subtree) |
Qiang XU | c181942 | 2019-02-27 13:51:32 +0800 | [diff] [blame] | 122 | { |
Gunnar Mills | 1214b7e | 2020-06-04 10:11:30 -0500 | [diff] [blame] | 123 | for (const auto& service : object.second) |
Qiang XU | c181942 | 2019-02-27 13:51:32 +0800 | [diff] [blame] | 124 | { |
| 125 | getIntrusionByService(aResp, service.first, object.first); |
| 126 | return; |
| 127 | } |
| 128 | } |
| 129 | }, |
| 130 | "xyz.openbmc_project.ObjectMapper", |
| 131 | "/xyz/openbmc_project/object_mapper", |
| 132 | "xyz.openbmc_project.ObjectMapper", "GetSubTree", |
Ed Tanous | 271584a | 2019-07-09 16:24:22 -0700 | [diff] [blame] | 133 | "/xyz/openbmc_project/Intrusion", 1, |
Gunnar Mills | 1214b7e | 2020-06-04 10:11:30 -0500 | [diff] [blame] | 134 | std::array<const char*, 1>{"xyz.openbmc_project.Chassis.Intrusion"}); |
Qiang XU | c181942 | 2019-02-27 13:51:32 +0800 | [diff] [blame] | 135 | } |
| 136 | |
Rapkiewicz, Pawel | e37f845 | 2018-03-09 13:49:50 +0100 | [diff] [blame] | 137 | /** |
Rapkiewicz, Pawel | e37f845 | 2018-03-09 13:49:50 +0100 | [diff] [blame] | 138 | * ChassisCollection derived class for delivering Chassis Collection Schema |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 139 | * Functions triggers appropriate requests on DBus |
Rapkiewicz, Pawel | e37f845 | 2018-03-09 13:49:50 +0100 | [diff] [blame] | 140 | */ |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 141 | inline void requestRoutesChassisCollection(App& app) |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 142 | { |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 143 | BMCWEB_ROUTE(app, "/redfish/v1/Chassis/") |
Ed Tanous | ed39821 | 2021-06-09 17:05:54 -0700 | [diff] [blame] | 144 | .privileges(redfish::privileges::getChassisCollection) |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 145 | .methods(boost::beast::http::verb::get)( |
Ed Tanous | 45ca1b8 | 2022-03-25 13:07:27 -0700 | [diff] [blame] | 146 | [&app](const crow::Request& req, |
| 147 | const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) { |
| 148 | if (!redfish::setUpRedfishRoute(app, req, asyncResp->res)) |
| 149 | { |
| 150 | return; |
| 151 | } |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 152 | asyncResp->res.jsonValue["@odata.type"] = |
| 153 | "#ChassisCollection.ChassisCollection"; |
| 154 | asyncResp->res.jsonValue["@odata.id"] = "/redfish/v1/Chassis"; |
| 155 | asyncResp->res.jsonValue["Name"] = "Chassis Collection"; |
Rapkiewicz, Pawel | e37f845 | 2018-03-09 13:49:50 +0100 | [diff] [blame] | 156 | |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 157 | collection_util::getCollectionMembers( |
| 158 | asyncResp, "/redfish/v1/Chassis", |
| 159 | {"xyz.openbmc_project.Inventory.Item.Board", |
| 160 | "xyz.openbmc_project.Inventory.Item.Chassis"}); |
| 161 | }); |
| 162 | } |
Rapkiewicz, Pawel | e37f845 | 2018-03-09 13:49:50 +0100 | [diff] [blame] | 163 | |
Willy Tu | 308f70c | 2021-09-28 20:24:52 -0700 | [diff] [blame] | 164 | inline void |
| 165 | getChassisLocationCode(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, |
| 166 | const std::string& connectionName, |
| 167 | const std::string& path) |
| 168 | { |
Jonathan Doman | 1e1e598 | 2021-06-11 09:36:17 -0700 | [diff] [blame] | 169 | sdbusplus::asio::getProperty<std::string>( |
| 170 | *crow::connections::systemBus, connectionName, path, |
| 171 | "xyz.openbmc_project.Inventory.Decorator.LocationCode", "LocationCode", |
Willy Tu | 308f70c | 2021-09-28 20:24:52 -0700 | [diff] [blame] | 172 | [asyncResp](const boost::system::error_code ec, |
Jonathan Doman | 1e1e598 | 2021-06-11 09:36:17 -0700 | [diff] [blame] | 173 | const std::string& property) { |
Willy Tu | 308f70c | 2021-09-28 20:24:52 -0700 | [diff] [blame] | 174 | if (ec) |
| 175 | { |
George Liu | 0fda0f1 | 2021-11-16 10:06:17 +0800 | [diff] [blame] | 176 | BMCWEB_LOG_DEBUG << "DBUS response error for Location"; |
Willy Tu | 308f70c | 2021-09-28 20:24:52 -0700 | [diff] [blame] | 177 | messages::internalError(asyncResp->res); |
| 178 | return; |
| 179 | } |
| 180 | |
Willy Tu | 308f70c | 2021-09-28 20:24:52 -0700 | [diff] [blame] | 181 | asyncResp->res |
Jonathan Doman | 1e1e598 | 2021-06-11 09:36:17 -0700 | [diff] [blame] | 182 | .jsonValue["Location"]["PartLocation"]["ServiceLabel"] = |
| 183 | property; |
| 184 | }); |
Willy Tu | 308f70c | 2021-09-28 20:24:52 -0700 | [diff] [blame] | 185 | } |
| 186 | |
| 187 | inline void getChassisUUID(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, |
| 188 | const std::string& connectionName, |
| 189 | const std::string& path) |
| 190 | { |
Jonathan Doman | 1e1e598 | 2021-06-11 09:36:17 -0700 | [diff] [blame] | 191 | sdbusplus::asio::getProperty<std::string>( |
| 192 | *crow::connections::systemBus, connectionName, path, |
| 193 | "xyz.openbmc_project.Common.UUID", "UUID", |
Willy Tu | 308f70c | 2021-09-28 20:24:52 -0700 | [diff] [blame] | 194 | [asyncResp](const boost::system::error_code ec, |
Jonathan Doman | 1e1e598 | 2021-06-11 09:36:17 -0700 | [diff] [blame] | 195 | const std::string& chassisUUID) { |
Willy Tu | 308f70c | 2021-09-28 20:24:52 -0700 | [diff] [blame] | 196 | if (ec) |
| 197 | { |
George Liu | 0fda0f1 | 2021-11-16 10:06:17 +0800 | [diff] [blame] | 198 | BMCWEB_LOG_DEBUG << "DBUS response error for UUID"; |
Willy Tu | 308f70c | 2021-09-28 20:24:52 -0700 | [diff] [blame] | 199 | messages::internalError(asyncResp->res); |
| 200 | return; |
| 201 | } |
Jonathan Doman | 1e1e598 | 2021-06-11 09:36:17 -0700 | [diff] [blame] | 202 | asyncResp->res.jsonValue["UUID"] = chassisUUID; |
| 203 | }); |
Willy Tu | 308f70c | 2021-09-28 20:24:52 -0700 | [diff] [blame] | 204 | } |
| 205 | |
Rapkiewicz, Pawel | e37f845 | 2018-03-09 13:49:50 +0100 | [diff] [blame] | 206 | /** |
| 207 | * Chassis override class for delivering Chassis Schema |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 208 | * Functions triggers appropriate requests on DBus |
Rapkiewicz, Pawel | e37f845 | 2018-03-09 13:49:50 +0100 | [diff] [blame] | 209 | */ |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 210 | inline void requestRoutesChassis(App& app) |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 211 | { |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 212 | BMCWEB_ROUTE(app, "/redfish/v1/Chassis/<str>/") |
Ed Tanous | ed39821 | 2021-06-09 17:05:54 -0700 | [diff] [blame] | 213 | .privileges(redfish::privileges::getChassis) |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 214 | .methods( |
Ed Tanous | 45ca1b8 | 2022-03-25 13:07:27 -0700 | [diff] [blame] | 215 | boost::beast::http::verb:: |
| 216 | get)([&app](const crow::Request& req, |
| 217 | const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, |
| 218 | const std::string& chassisId) { |
| 219 | if (!redfish::setUpRedfishRoute(app, req, asyncResp->res)) |
| 220 | { |
| 221 | return; |
| 222 | } |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 223 | const std::array<const char*, 2> interfaces = { |
| 224 | "xyz.openbmc_project.Inventory.Item.Board", |
| 225 | "xyz.openbmc_project.Inventory.Item.Chassis"}; |
Rapkiewicz, Pawel | e37f845 | 2018-03-09 13:49:50 +0100 | [diff] [blame] | 226 | |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 227 | crow::connections::systemBus->async_method_call( |
| 228 | [asyncResp, chassisId(std::string(chassisId))]( |
| 229 | const boost::system::error_code ec, |
Ed Tanous | b9d36b4 | 2022-02-26 21:42:46 -0800 | [diff] [blame] | 230 | const dbus::utility::MapperGetSubTreeResponse& subtree) { |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 231 | if (ec) |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 232 | { |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 233 | messages::internalError(asyncResp->res); |
| 234 | return; |
Ed Tanous | daf36e2 | 2018-04-20 16:01:36 -0700 | [diff] [blame] | 235 | } |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 236 | // Iterate over all retrieved ObjectPaths. |
| 237 | for (const std::pair< |
| 238 | std::string, |
| 239 | std::vector<std::pair<std::string, |
| 240 | std::vector<std::string>>>>& |
| 241 | object : subtree) |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 242 | { |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 243 | const std::string& path = object.first; |
| 244 | const std::vector< |
| 245 | std::pair<std::string, std::vector<std::string>>>& |
| 246 | connectionNames = object.second; |
Ed Tanous | e0d918b | 2018-03-27 17:41:04 -0700 | [diff] [blame] | 247 | |
George Liu | 997093e | 2021-11-17 17:43:45 +0800 | [diff] [blame] | 248 | sdbusplus::message::object_path objPath(path); |
| 249 | if (objPath.filename() != chassisId) |
James Feist | 1c8fba9 | 2019-12-20 15:12:07 -0800 | [diff] [blame] | 250 | { |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 251 | continue; |
James Feist | 1c8fba9 | 2019-12-20 15:12:07 -0800 | [diff] [blame] | 252 | } |
James Feist | 1c8fba9 | 2019-12-20 15:12:07 -0800 | [diff] [blame] | 253 | |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 254 | auto health = |
| 255 | std::make_shared<HealthPopulate>(asyncResp); |
| 256 | |
Jonathan Doman | 1e1e598 | 2021-06-11 09:36:17 -0700 | [diff] [blame] | 257 | sdbusplus::asio::getProperty<std::vector<std::string>>( |
| 258 | *crow::connections::systemBus, |
| 259 | "xyz.openbmc_project.ObjectMapper", |
| 260 | path + "/all_sensors", |
| 261 | "xyz.openbmc_project.Association", "endpoints", |
Ed Tanous | 168e20c | 2021-12-13 14:39:53 -0800 | [diff] [blame] | 262 | [health](const boost::system::error_code ec2, |
Jonathan Doman | 1e1e598 | 2021-06-11 09:36:17 -0700 | [diff] [blame] | 263 | const std::vector<std::string>& resp) { |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 264 | if (ec2) |
| 265 | { |
| 266 | return; // no sensors = no failures |
| 267 | } |
Jonathan Doman | 1e1e598 | 2021-06-11 09:36:17 -0700 | [diff] [blame] | 268 | health->inventory = resp; |
| 269 | }); |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 270 | |
| 271 | health->populate(); |
| 272 | |
Ed Tanous | 26f6976 | 2022-01-25 09:49:11 -0800 | [diff] [blame] | 273 | if (connectionNames.empty()) |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 274 | { |
| 275 | BMCWEB_LOG_ERROR << "Got 0 Connection names"; |
| 276 | continue; |
| 277 | } |
| 278 | |
| 279 | asyncResp->res.jsonValue["@odata.type"] = |
Gunnar Mills | 5ac5a2f | 2022-01-04 12:26:41 -0600 | [diff] [blame] | 280 | "#Chassis.v1_16_0.Chassis"; |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 281 | asyncResp->res.jsonValue["@odata.id"] = |
| 282 | "/redfish/v1/Chassis/" + chassisId; |
| 283 | asyncResp->res.jsonValue["Name"] = "Chassis Collection"; |
| 284 | asyncResp->res.jsonValue["ChassisType"] = "RackMount"; |
Ed Tanous | 1476687 | 2022-03-15 10:44:42 -0700 | [diff] [blame] | 285 | asyncResp->res |
| 286 | .jsonValue["Actions"]["#Chassis.Reset"]["target"] = |
| 287 | "/redfish/v1/Chassis/" + chassisId + |
| 288 | "/Actions/Chassis.Reset"; |
| 289 | asyncResp->res.jsonValue["Actions"]["#Chassis.Reset"] |
| 290 | ["@Redfish.ActionInfo"] = |
| 291 | "/redfish/v1/Chassis/" + chassisId + |
| 292 | "/ResetActionInfo"; |
| 293 | asyncResp->res.jsonValue["PCIeDevices"]["@odata.id"] = |
| 294 | "/redfish/v1/Systems/system/PCIeDevices"; |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 295 | |
| 296 | const std::string& connectionName = |
| 297 | connectionNames[0].first; |
| 298 | |
| 299 | const std::vector<std::string>& interfaces2 = |
| 300 | connectionNames[0].second; |
| 301 | const std::array<const char*, 2> hasIndicatorLed = { |
| 302 | "xyz.openbmc_project.Inventory.Item.Panel", |
George Liu | 0fda0f1 | 2021-11-16 10:06:17 +0800 | [diff] [blame] | 303 | "xyz.openbmc_project.Inventory.Item.Board.Motherboard"}; |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 304 | |
Tejas Patil | 476b9cc | 2021-06-04 17:09:14 +0530 | [diff] [blame] | 305 | const std::string assetTagInterface = |
George Liu | 0fda0f1 | 2021-11-16 10:06:17 +0800 | [diff] [blame] | 306 | "xyz.openbmc_project.Inventory.Decorator.AssetTag"; |
Tejas Patil | 476b9cc | 2021-06-04 17:09:14 +0530 | [diff] [blame] | 307 | if (std::find(interfaces2.begin(), interfaces2.end(), |
| 308 | assetTagInterface) != interfaces2.end()) |
| 309 | { |
Jonathan Doman | 1e1e598 | 2021-06-11 09:36:17 -0700 | [diff] [blame] | 310 | sdbusplus::asio::getProperty<std::string>( |
| 311 | *crow::connections::systemBus, connectionName, |
| 312 | path, assetTagInterface, "AssetTag", |
Tejas Patil | 476b9cc | 2021-06-04 17:09:14 +0530 | [diff] [blame] | 313 | [asyncResp, chassisId(std::string(chassisId))]( |
| 314 | const boost::system::error_code ec, |
Jonathan Doman | 1e1e598 | 2021-06-11 09:36:17 -0700 | [diff] [blame] | 315 | const std::string& property) { |
Tejas Patil | 476b9cc | 2021-06-04 17:09:14 +0530 | [diff] [blame] | 316 | if (ec) |
| 317 | { |
| 318 | BMCWEB_LOG_DEBUG |
George Liu | 0fda0f1 | 2021-11-16 10:06:17 +0800 | [diff] [blame] | 319 | << "DBus response error for AssetTag"; |
Tejas Patil | 476b9cc | 2021-06-04 17:09:14 +0530 | [diff] [blame] | 320 | messages::internalError(asyncResp->res); |
| 321 | return; |
| 322 | } |
Tejas Patil | 476b9cc | 2021-06-04 17:09:14 +0530 | [diff] [blame] | 323 | asyncResp->res.jsonValue["AssetTag"] = |
Jonathan Doman | 1e1e598 | 2021-06-11 09:36:17 -0700 | [diff] [blame] | 324 | property; |
| 325 | }); |
Tejas Patil | 476b9cc | 2021-06-04 17:09:14 +0530 | [diff] [blame] | 326 | } |
| 327 | |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 328 | for (const char* interface : hasIndicatorLed) |
| 329 | { |
| 330 | if (std::find(interfaces2.begin(), |
| 331 | interfaces2.end(), |
| 332 | interface) != interfaces2.end()) |
| 333 | { |
| 334 | getIndicatorLedState(asyncResp); |
| 335 | getLocationIndicatorActive(asyncResp); |
| 336 | break; |
| 337 | } |
| 338 | } |
| 339 | |
SunnySrivastava1984 | 88ad7f0 | 2020-12-03 10:27:52 -0600 | [diff] [blame] | 340 | crow::connections::systemBus->async_method_call( |
| 341 | [asyncResp, chassisId(std::string(chassisId))]( |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 342 | const boost::system::error_code /*ec2*/, |
Ed Tanous | b9d36b4 | 2022-02-26 21:42:46 -0800 | [diff] [blame] | 343 | const dbus::utility::DBusPropertiesMap& |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 344 | propertiesList) { |
Ed Tanous | 168e20c | 2021-12-13 14:39:53 -0800 | [diff] [blame] | 345 | for (const std::pair< |
| 346 | std::string, |
| 347 | dbus::utility::DbusVariantType>& |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 348 | property : propertiesList) |
SunnySrivastava1984 | 88ad7f0 | 2020-12-03 10:27:52 -0600 | [diff] [blame] | 349 | { |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 350 | // Store DBus properties that are also |
| 351 | // Redfish properties with same name and a |
| 352 | // string value |
| 353 | const std::string& propertyName = |
| 354 | property.first; |
| 355 | if ((propertyName == "PartNumber") || |
| 356 | (propertyName == "SerialNumber") || |
| 357 | (propertyName == "Manufacturer") || |
Alpana Kumari | caa11f7 | 2021-11-09 12:16:18 -0600 | [diff] [blame] | 358 | (propertyName == "Model") || |
| 359 | (propertyName == "SparePartNumber")) |
Shawn McCarney | 99cffd7 | 2019-03-01 10:46:20 -0600 | [diff] [blame] | 360 | { |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 361 | const std::string* value = |
| 362 | std::get_if<std::string>( |
| 363 | &property.second); |
Alpana Kumari | caa11f7 | 2021-11-09 12:16:18 -0600 | [diff] [blame] | 364 | if (value == nullptr) |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 365 | { |
Alpana Kumari | caa11f7 | 2021-11-09 12:16:18 -0600 | [diff] [blame] | 366 | BMCWEB_LOG_ERROR |
| 367 | << "Null value returned for " |
| 368 | << propertyName; |
| 369 | messages::internalError( |
| 370 | asyncResp->res); |
| 371 | return; |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 372 | } |
Alpana Kumari | caa11f7 | 2021-11-09 12:16:18 -0600 | [diff] [blame] | 373 | // SparePartNumber is optional on D-Bus |
| 374 | // so skip if it is empty |
| 375 | if (propertyName == "SparePartNumber") |
| 376 | { |
Ed Tanous | 26f6976 | 2022-01-25 09:49:11 -0800 | [diff] [blame] | 377 | if (value->empty()) |
Alpana Kumari | caa11f7 | 2021-11-09 12:16:18 -0600 | [diff] [blame] | 378 | { |
| 379 | continue; |
| 380 | } |
| 381 | } |
| 382 | asyncResp->res.jsonValue[propertyName] = |
| 383 | *value; |
Shawn McCarney | 99cffd7 | 2019-03-01 10:46:20 -0600 | [diff] [blame] | 384 | } |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 385 | } |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 386 | asyncResp->res.jsonValue["Name"] = chassisId; |
| 387 | asyncResp->res.jsonValue["Id"] = chassisId; |
zhanghch05 | 0256b69 | 2021-06-12 10:26:52 +0800 | [diff] [blame] | 388 | #ifdef BMCWEB_ALLOW_DEPRECATED_POWER_THERMAL |
Ed Tanous | 1476687 | 2022-03-15 10:44:42 -0700 | [diff] [blame] | 389 | asyncResp->res |
| 390 | .jsonValue["Thermal"]["@odata.id"] = |
| 391 | "/redfish/v1/Chassis/" + chassisId + |
| 392 | "/Thermal"; |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 393 | // Power object |
Ed Tanous | 1476687 | 2022-03-15 10:44:42 -0700 | [diff] [blame] | 394 | asyncResp->res.jsonValue["Power"]["@odata.id"] = |
| 395 | "/redfish/v1/Chassis/" + chassisId + |
| 396 | "/Power"; |
zhanghch05 | 0256b69 | 2021-06-12 10:26:52 +0800 | [diff] [blame] | 397 | #endif |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 398 | // SensorCollection |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 399 | asyncResp->res |
Ed Tanous | 1476687 | 2022-03-15 10:44:42 -0700 | [diff] [blame] | 400 | .jsonValue["Sensors"]["@odata.id"] = |
| 401 | "/redfish/v1/Chassis/" + chassisId + |
| 402 | "/Sensors"; |
| 403 | asyncResp->res.jsonValue["Status"]["State"] = |
| 404 | "Enabled"; |
| 405 | |
| 406 | nlohmann::json::array_t computerSystems; |
| 407 | nlohmann::json::object_t system; |
| 408 | system["@odata.id"] = |
| 409 | "/redfish/v1/Systems/system"; |
| 410 | computerSystems.push_back(std::move(system)); |
| 411 | asyncResp->res |
| 412 | .jsonValue["Links"]["ComputerSystems"] = |
| 413 | std::move(computerSystems); |
| 414 | |
| 415 | nlohmann::json::array_t managedBy; |
| 416 | nlohmann::json::object_t manager; |
| 417 | manager["@odata.id"] = |
| 418 | "/redfish/v1/Managers/bmc"; |
| 419 | managedBy.push_back(std::move(manager)); |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 420 | asyncResp->res.jsonValue["Links"]["ManagedBy"] = |
Ed Tanous | 1476687 | 2022-03-15 10:44:42 -0700 | [diff] [blame] | 421 | std::move(managedBy); |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 422 | getChassisState(asyncResp); |
| 423 | }, |
| 424 | connectionName, path, |
| 425 | "org.freedesktop.DBus.Properties", "GetAll", |
| 426 | "xyz.openbmc_project.Inventory.Decorator.Asset"); |
Sharad Yadav | 2c37b4b | 2021-05-10 12:53:38 +0530 | [diff] [blame] | 427 | |
Willy Tu | 308f70c | 2021-09-28 20:24:52 -0700 | [diff] [blame] | 428 | for (const auto& interface : interfaces2) |
Sharad Yadav | 2c37b4b | 2021-05-10 12:53:38 +0530 | [diff] [blame] | 429 | { |
Willy Tu | 308f70c | 2021-09-28 20:24:52 -0700 | [diff] [blame] | 430 | if (interface == "xyz.openbmc_project.Common.UUID") |
| 431 | { |
| 432 | getChassisUUID(asyncResp, connectionName, path); |
| 433 | } |
George Liu | 0fda0f1 | 2021-11-16 10:06:17 +0800 | [diff] [blame] | 434 | else if ( |
| 435 | interface == |
| 436 | "xyz.openbmc_project.Inventory.Decorator.LocationCode") |
Willy Tu | 308f70c | 2021-09-28 20:24:52 -0700 | [diff] [blame] | 437 | { |
| 438 | getChassisLocationCode(asyncResp, |
| 439 | connectionName, path); |
| 440 | } |
Sharad Yadav | 2c37b4b | 2021-05-10 12:53:38 +0530 | [diff] [blame] | 441 | } |
| 442 | |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 443 | return; |
| 444 | } |
| 445 | |
| 446 | // Couldn't find an object with that name. return an error |
| 447 | messages::resourceNotFound( |
Gunnar Mills | 5ac5a2f | 2022-01-04 12:26:41 -0600 | [diff] [blame] | 448 | asyncResp->res, "#Chassis.v1_16_0.Chassis", chassisId); |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 449 | }, |
| 450 | "xyz.openbmc_project.ObjectMapper", |
| 451 | "/xyz/openbmc_project/object_mapper", |
| 452 | "xyz.openbmc_project.ObjectMapper", "GetSubTree", |
| 453 | "/xyz/openbmc_project/inventory", 0, interfaces); |
| 454 | |
| 455 | getPhysicalSecurityData(asyncResp); |
| 456 | }); |
| 457 | |
| 458 | BMCWEB_ROUTE(app, "/redfish/v1/Chassis/<str>/") |
Ed Tanous | ed39821 | 2021-06-09 17:05:54 -0700 | [diff] [blame] | 459 | .privileges(redfish::privileges::patchChassis) |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 460 | .methods( |
| 461 | boost::beast::http::verb:: |
Ed Tanous | 45ca1b8 | 2022-03-25 13:07:27 -0700 | [diff] [blame] | 462 | patch)([&app]( |
| 463 | const crow::Request& req, |
| 464 | const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, |
| 465 | const std::string& param) { |
| 466 | if (!redfish::setUpRedfishRoute(app, req, asyncResp->res)) |
| 467 | { |
| 468 | return; |
| 469 | } |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 470 | std::optional<bool> locationIndicatorActive; |
| 471 | std::optional<std::string> indicatorLed; |
| 472 | |
| 473 | if (param.empty()) |
| 474 | { |
| 475 | return; |
| 476 | } |
| 477 | |
Willy Tu | 15ed678 | 2021-12-14 11:03:16 -0800 | [diff] [blame] | 478 | if (!json_util::readJsonPatch( |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 479 | req, asyncResp->res, "LocationIndicatorActive", |
| 480 | locationIndicatorActive, "IndicatorLED", indicatorLed)) |
| 481 | { |
| 482 | return; |
| 483 | } |
| 484 | |
| 485 | // TODO (Gunnar): Remove IndicatorLED after enough time has passed |
| 486 | if (!locationIndicatorActive && !indicatorLed) |
| 487 | { |
| 488 | return; // delete this when we support more patch properties |
| 489 | } |
| 490 | if (indicatorLed) |
| 491 | { |
| 492 | asyncResp->res.addHeader( |
| 493 | boost::beast::http::field::warning, |
George Liu | 0fda0f1 | 2021-11-16 10:06:17 +0800 | [diff] [blame] | 494 | "299 - \"IndicatorLED is deprecated. Use LocationIndicatorActive instead.\""); |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 495 | } |
| 496 | |
| 497 | const std::array<const char*, 2> interfaces = { |
| 498 | "xyz.openbmc_project.Inventory.Item.Board", |
| 499 | "xyz.openbmc_project.Inventory.Item.Chassis"}; |
| 500 | |
| 501 | const std::string& chassisId = param; |
| 502 | |
| 503 | crow::connections::systemBus->async_method_call( |
| 504 | [asyncResp, chassisId, locationIndicatorActive, indicatorLed]( |
| 505 | const boost::system::error_code ec, |
Ed Tanous | b9d36b4 | 2022-02-26 21:42:46 -0800 | [diff] [blame] | 506 | const dbus::utility::MapperGetSubTreeResponse& subtree) { |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 507 | if (ec) |
| 508 | { |
| 509 | messages::internalError(asyncResp->res); |
| 510 | return; |
| 511 | } |
| 512 | |
| 513 | // Iterate over all retrieved ObjectPaths. |
| 514 | for (const std::pair< |
| 515 | std::string, |
| 516 | std::vector<std::pair<std::string, |
| 517 | std::vector<std::string>>>>& |
| 518 | object : subtree) |
| 519 | { |
| 520 | const std::string& path = object.first; |
| 521 | const std::vector< |
| 522 | std::pair<std::string, std::vector<std::string>>>& |
| 523 | connectionNames = object.second; |
| 524 | |
George Liu | 997093e | 2021-11-17 17:43:45 +0800 | [diff] [blame] | 525 | sdbusplus::message::object_path objPath(path); |
| 526 | if (objPath.filename() != chassisId) |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 527 | { |
| 528 | continue; |
| 529 | } |
| 530 | |
Ed Tanous | 26f6976 | 2022-01-25 09:49:11 -0800 | [diff] [blame] | 531 | if (connectionNames.empty()) |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 532 | { |
| 533 | BMCWEB_LOG_ERROR << "Got 0 Connection names"; |
| 534 | continue; |
| 535 | } |
| 536 | |
| 537 | const std::vector<std::string>& interfaces3 = |
| 538 | connectionNames[0].second; |
| 539 | |
| 540 | const std::array<const char*, 2> hasIndicatorLed = { |
| 541 | "xyz.openbmc_project.Inventory.Item.Panel", |
George Liu | 0fda0f1 | 2021-11-16 10:06:17 +0800 | [diff] [blame] | 542 | "xyz.openbmc_project.Inventory.Item.Board.Motherboard"}; |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 543 | bool indicatorChassis = false; |
| 544 | for (const char* interface : hasIndicatorLed) |
| 545 | { |
| 546 | if (std::find(interfaces3.begin(), |
| 547 | interfaces3.end(), |
| 548 | interface) != interfaces3.end()) |
| 549 | { |
| 550 | indicatorChassis = true; |
| 551 | break; |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 552 | } |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 553 | } |
| 554 | if (locationIndicatorActive) |
| 555 | { |
| 556 | if (indicatorChassis) |
| 557 | { |
| 558 | setLocationIndicatorActive( |
| 559 | asyncResp, *locationIndicatorActive); |
| 560 | } |
| 561 | else |
| 562 | { |
| 563 | messages::propertyUnknown( |
| 564 | asyncResp->res, "LocationIndicatorActive"); |
| 565 | } |
| 566 | } |
| 567 | if (indicatorLed) |
| 568 | { |
| 569 | if (indicatorChassis) |
| 570 | { |
| 571 | setIndicatorLedState(asyncResp, *indicatorLed); |
| 572 | } |
| 573 | else |
| 574 | { |
| 575 | messages::propertyUnknown(asyncResp->res, |
| 576 | "IndicatorLED"); |
| 577 | } |
| 578 | } |
| 579 | return; |
James Feist | 1c8fba9 | 2019-12-20 15:12:07 -0800 | [diff] [blame] | 580 | } |
| 581 | |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 582 | messages::resourceNotFound( |
| 583 | asyncResp->res, "#Chassis.v1_14_0.Chassis", chassisId); |
| 584 | }, |
| 585 | "xyz.openbmc_project.ObjectMapper", |
| 586 | "/xyz/openbmc_project/object_mapper", |
| 587 | "xyz.openbmc_project.ObjectMapper", "GetSubTree", |
| 588 | "/xyz/openbmc_project/inventory", 0, interfaces); |
| 589 | }); |
| 590 | } |
P.K. Lee | dd99e04 | 2020-06-17 19:43:16 +0800 | [diff] [blame] | 591 | |
zhanghch05 | 8d1b46d | 2021-04-01 11:18:24 +0800 | [diff] [blame] | 592 | inline void |
| 593 | doChassisPowerCycle(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) |
P.K. Lee | dd99e04 | 2020-06-17 19:43:16 +0800 | [diff] [blame] | 594 | { |
Vijay Khemka | c3b3c92 | 2020-09-22 23:00:12 -0700 | [diff] [blame] | 595 | const char* busName = "xyz.openbmc_project.ObjectMapper"; |
| 596 | const char* path = "/xyz/openbmc_project/object_mapper"; |
| 597 | const char* interface = "xyz.openbmc_project.ObjectMapper"; |
| 598 | const char* method = "GetSubTreePaths"; |
P.K. Lee | dd99e04 | 2020-06-17 19:43:16 +0800 | [diff] [blame] | 599 | |
Vijay Khemka | c3b3c92 | 2020-09-22 23:00:12 -0700 | [diff] [blame] | 600 | const std::array<const char*, 1> interfaces = { |
| 601 | "xyz.openbmc_project.State.Chassis"}; |
| 602 | |
| 603 | // Use mapper to get subtree paths. |
P.K. Lee | dd99e04 | 2020-06-17 19:43:16 +0800 | [diff] [blame] | 604 | crow::connections::systemBus->async_method_call( |
Ed Tanous | b9d36b4 | 2022-02-26 21:42:46 -0800 | [diff] [blame] | 605 | [asyncResp]( |
| 606 | const boost::system::error_code ec, |
| 607 | const dbus::utility::MapperGetSubTreePathsResponse& chassisList) { |
P.K. Lee | dd99e04 | 2020-06-17 19:43:16 +0800 | [diff] [blame] | 608 | if (ec) |
| 609 | { |
Vijay Khemka | c3b3c92 | 2020-09-22 23:00:12 -0700 | [diff] [blame] | 610 | BMCWEB_LOG_DEBUG << "[mapper] Bad D-Bus request error: " << ec; |
P.K. Lee | dd99e04 | 2020-06-17 19:43:16 +0800 | [diff] [blame] | 611 | messages::internalError(asyncResp->res); |
| 612 | return; |
| 613 | } |
| 614 | |
Vijay Khemka | c3b3c92 | 2020-09-22 23:00:12 -0700 | [diff] [blame] | 615 | const char* processName = "xyz.openbmc_project.State.Chassis"; |
| 616 | const char* interfaceName = "xyz.openbmc_project.State.Chassis"; |
| 617 | const char* destProperty = "RequestedPowerTransition"; |
| 618 | const std::string propertyValue = |
| 619 | "xyz.openbmc_project.State.Chassis.Transition.PowerCycle"; |
| 620 | std::string objectPath = |
| 621 | "/xyz/openbmc_project/state/chassis_system0"; |
| 622 | |
| 623 | /* Look for system reset chassis path */ |
| 624 | if ((std::find(chassisList.begin(), chassisList.end(), |
| 625 | objectPath)) == chassisList.end()) |
| 626 | { |
| 627 | /* We prefer to reset the full chassis_system, but if it doesn't |
| 628 | * exist on some platforms, fall back to a host-only power reset |
| 629 | */ |
| 630 | objectPath = "/xyz/openbmc_project/state/chassis0"; |
| 631 | } |
| 632 | |
| 633 | crow::connections::systemBus->async_method_call( |
| 634 | [asyncResp](const boost::system::error_code ec) { |
| 635 | // Use "Set" method to set the property value. |
| 636 | if (ec) |
| 637 | { |
| 638 | BMCWEB_LOG_DEBUG << "[Set] Bad D-Bus request error: " |
| 639 | << ec; |
| 640 | messages::internalError(asyncResp->res); |
| 641 | return; |
| 642 | } |
| 643 | |
| 644 | messages::success(asyncResp->res); |
| 645 | }, |
| 646 | processName, objectPath, "org.freedesktop.DBus.Properties", |
| 647 | "Set", interfaceName, destProperty, |
Ed Tanous | 168e20c | 2021-12-13 14:39:53 -0800 | [diff] [blame] | 648 | dbus::utility::DbusVariantType{propertyValue}); |
P.K. Lee | dd99e04 | 2020-06-17 19:43:16 +0800 | [diff] [blame] | 649 | }, |
Vijay Khemka | c3b3c92 | 2020-09-22 23:00:12 -0700 | [diff] [blame] | 650 | busName, path, interface, method, "/", 0, interfaces); |
P.K. Lee | dd99e04 | 2020-06-17 19:43:16 +0800 | [diff] [blame] | 651 | } |
| 652 | |
| 653 | /** |
| 654 | * ChassisResetAction class supports the POST method for the Reset |
| 655 | * action. |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 656 | * Function handles POST method request. |
| 657 | * Analyzes POST body before sending Reset request data to D-Bus. |
P.K. Lee | dd99e04 | 2020-06-17 19:43:16 +0800 | [diff] [blame] | 658 | */ |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 659 | |
| 660 | inline void requestRoutesChassisResetAction(App& app) |
P.K. Lee | dd99e04 | 2020-06-17 19:43:16 +0800 | [diff] [blame] | 661 | { |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 662 | BMCWEB_ROUTE(app, "/redfish/v1/Chassis/<str>/Actions/Chassis.Reset/") |
Ed Tanous | ed39821 | 2021-06-09 17:05:54 -0700 | [diff] [blame] | 663 | .privileges(redfish::privileges::postChassis) |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 664 | .methods(boost::beast::http::verb::post)( |
Ed Tanous | 45ca1b8 | 2022-03-25 13:07:27 -0700 | [diff] [blame] | 665 | [&app](const crow::Request& req, |
| 666 | const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, |
| 667 | const std::string&) { |
| 668 | if (!redfish::setUpRedfishRoute(app, req, asyncResp->res)) |
| 669 | { |
| 670 | return; |
| 671 | } |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 672 | BMCWEB_LOG_DEBUG << "Post Chassis Reset."; |
P.K. Lee | dd99e04 | 2020-06-17 19:43:16 +0800 | [diff] [blame] | 673 | |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 674 | std::string resetType; |
P.K. Lee | dd99e04 | 2020-06-17 19:43:16 +0800 | [diff] [blame] | 675 | |
Willy Tu | 15ed678 | 2021-12-14 11:03:16 -0800 | [diff] [blame] | 676 | if (!json_util::readJsonAction(req, asyncResp->res, "ResetType", |
| 677 | resetType)) |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 678 | { |
| 679 | return; |
| 680 | } |
P.K. Lee | dd99e04 | 2020-06-17 19:43:16 +0800 | [diff] [blame] | 681 | |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 682 | if (resetType != "PowerCycle") |
| 683 | { |
| 684 | BMCWEB_LOG_DEBUG << "Invalid property value for ResetType: " |
| 685 | << resetType; |
| 686 | messages::actionParameterNotSupported( |
| 687 | asyncResp->res, resetType, "ResetType"); |
P.K. Lee | dd99e04 | 2020-06-17 19:43:16 +0800 | [diff] [blame] | 688 | |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 689 | return; |
| 690 | } |
| 691 | doChassisPowerCycle(asyncResp); |
| 692 | }); |
| 693 | } |
AppaRao Puli | 1cb1a9e | 2020-07-17 23:38:57 +0530 | [diff] [blame] | 694 | |
| 695 | /** |
| 696 | * ChassisResetActionInfo derived class for delivering Chassis |
| 697 | * ResetType AllowableValues using ResetInfo schema. |
| 698 | */ |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 699 | inline void requestRoutesChassisResetActionInfo(App& app) |
AppaRao Puli | 1cb1a9e | 2020-07-17 23:38:57 +0530 | [diff] [blame] | 700 | { |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 701 | BMCWEB_ROUTE(app, "/redfish/v1/Chassis/<str>/ResetActionInfo/") |
Ed Tanous | ed39821 | 2021-06-09 17:05:54 -0700 | [diff] [blame] | 702 | .privileges(redfish::privileges::getActionInfo) |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 703 | .methods(boost::beast::http::verb::get)( |
Ed Tanous | 45ca1b8 | 2022-03-25 13:07:27 -0700 | [diff] [blame] | 704 | [&app](const crow::Request& req, |
| 705 | const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, |
| 706 | const std::string& chassisId) { |
| 707 | if (!redfish::setUpRedfishRoute(app, req, asyncResp->res)) |
| 708 | { |
| 709 | return; |
| 710 | } |
Ed Tanous | 1476687 | 2022-03-15 10:44:42 -0700 | [diff] [blame] | 711 | asyncResp->res.jsonValue["@odata.type"] = |
| 712 | "#ActionInfo.v1_1_2.ActionInfo"; |
| 713 | asyncResp->res.jsonValue["@odata.id"] = |
| 714 | "/redfish/v1/Chassis/" + chassisId + "/ResetActionInfo"; |
| 715 | asyncResp->res.jsonValue["Name"] = "Reset Action Info"; |
| 716 | |
| 717 | asyncResp->res.jsonValue["Id"] = "ResetActionInfo"; |
| 718 | nlohmann::json::object_t parameters; |
| 719 | parameters["Name"] = "ResetType"; |
| 720 | parameters["Required"] = true; |
| 721 | parameters["DataType"] = "String"; |
| 722 | nlohmann::json::array_t allowed; |
| 723 | allowed.push_back("PowerCycle"); |
| 724 | parameters["AllowableValues"] = std::move(allowed); |
| 725 | asyncResp->res.jsonValue["Parameters"] = std::move(parameters); |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 726 | }); |
| 727 | } |
AppaRao Puli | 1cb1a9e | 2020-07-17 23:38:57 +0530 | [diff] [blame] | 728 | |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 729 | } // namespace redfish |