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 | |
Ed Tanous | 3ccb3ad | 2023-01-13 17:40:03 -0800 | [diff] [blame] | 18 | #include "app.hpp" |
George Liu | 7a1dbc4 | 2022-12-07 16:03:22 +0800 | [diff] [blame] | 19 | #include "dbus_utility.hpp" |
James Feist | 1c8fba9 | 2019-12-20 15:12:07 -0800 | [diff] [blame] | 20 | #include "led.hpp" |
Ed Tanous | 3ccb3ad | 2023-01-13 17:40:03 -0800 | [diff] [blame] | 21 | #include "query.hpp" |
Chau Ly | 7164bc6 | 2023-10-15 14:55:30 +0000 | [diff] [blame] | 22 | #include "redfish_util.hpp" |
Ed Tanous | 3ccb3ad | 2023-01-13 17:40:03 -0800 | [diff] [blame] | 23 | #include "registries/privilege_registry.hpp" |
| 24 | #include "utils/collection.hpp" |
| 25 | #include "utils/dbus_utils.hpp" |
Nan Zhou | cf7eba0 | 2022-07-21 23:53:20 +0000 | [diff] [blame] | 26 | #include "utils/json_utils.hpp" |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 27 | |
George Liu | e99073f | 2022-12-09 11:06:16 +0800 | [diff] [blame] | 28 | #include <boost/system/error_code.hpp> |
Ed Tanous | ef4c65b | 2023-04-24 15:28:50 -0700 | [diff] [blame] | 29 | #include <boost/url/format.hpp> |
Jonathan Doman | 1e1e598 | 2021-06-11 09:36:17 -0700 | [diff] [blame] | 30 | #include <sdbusplus/asio/property.hpp> |
Andrew Geissler | fc903b3 | 2023-05-31 14:15:42 -0400 | [diff] [blame] | 31 | #include <sdbusplus/message.hpp> |
Krzysztof Grobelny | 86d89ed | 2022-08-29 14:49:20 +0200 | [diff] [blame] | 32 | #include <sdbusplus/unpack_properties.hpp> |
Gunnar Mills | 1214b7e | 2020-06-04 10:11:30 -0500 | [diff] [blame] | 33 | |
George Liu | 7a1dbc4 | 2022-12-07 16:03:22 +0800 | [diff] [blame] | 34 | #include <array> |
Ed Tanous | 3544d2a | 2023-08-06 18:12:20 -0700 | [diff] [blame] | 35 | #include <ranges> |
George Liu | 7a1dbc4 | 2022-12-07 16:03:22 +0800 | [diff] [blame] | 36 | #include <string_view> |
| 37 | |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 38 | namespace redfish |
| 39 | { |
Rapkiewicz, Pawel | e37f845 | 2018-03-09 13:49:50 +0100 | [diff] [blame] | 40 | |
| 41 | /** |
Willy Tu | 5e577bc | 2022-07-26 00:41:55 +0000 | [diff] [blame] | 42 | * @brief Retrieves resources over dbus to link to the chassis |
| 43 | * |
| 44 | * @param[in] asyncResp - Shared pointer for completing asynchronous |
| 45 | * calls |
| 46 | * @param[in] path - Chassis dbus path to look for the storage. |
| 47 | * |
| 48 | * Calls the Association endpoints on the path + "/storage" and add the link of |
| 49 | * json["Links"]["Storage@odata.count"] = |
| 50 | * {"@odata.id", "/redfish/v1/Storage/" + resourceId} |
| 51 | * |
| 52 | * @return None. |
| 53 | */ |
| 54 | inline void getStorageLink(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, |
| 55 | const sdbusplus::message::object_path& path) |
| 56 | { |
| 57 | sdbusplus::asio::getProperty<std::vector<std::string>>( |
| 58 | *crow::connections::systemBus, "xyz.openbmc_project.ObjectMapper", |
| 59 | (path / "storage").str, "xyz.openbmc_project.Association", "endpoints", |
Willy Tu | d4b054c | 2023-06-12 15:18:45 -0700 | [diff] [blame] | 60 | [asyncResp](const boost::system::error_code& ec, |
Willy Tu | 5e577bc | 2022-07-26 00:41:55 +0000 | [diff] [blame] | 61 | const std::vector<std::string>& storageList) { |
| 62 | if (ec) |
| 63 | { |
Ed Tanous | 62598e3 | 2023-07-17 17:06:25 -0700 | [diff] [blame] | 64 | BMCWEB_LOG_DEBUG("getStorageLink got DBUS response error"); |
Willy Tu | 5e577bc | 2022-07-26 00:41:55 +0000 | [diff] [blame] | 65 | return; |
| 66 | } |
| 67 | |
| 68 | nlohmann::json::array_t storages; |
| 69 | for (const std::string& storagePath : storageList) |
| 70 | { |
| 71 | std::string id = |
| 72 | sdbusplus::message::object_path(storagePath).filename(); |
| 73 | if (id.empty()) |
| 74 | { |
| 75 | continue; |
| 76 | } |
| 77 | |
| 78 | nlohmann::json::object_t storage; |
| 79 | storage["@odata.id"] = boost::urls::format( |
| 80 | "/redfish/v1/Systems/system/Storage/{}", id); |
| 81 | storages.emplace_back(std::move(storage)); |
| 82 | } |
| 83 | asyncResp->res.jsonValue["Links"]["Storage@odata.count"] = |
| 84 | storages.size(); |
| 85 | asyncResp->res.jsonValue["Links"]["Storage"] = std::move(storages); |
Patrick Williams | 5a39f77 | 2023-10-20 11:20:21 -0500 | [diff] [blame] | 86 | }); |
Willy Tu | 5e577bc | 2022-07-26 00:41:55 +0000 | [diff] [blame] | 87 | } |
| 88 | |
| 89 | /** |
Gunnar Mills | beeca0a | 2019-02-14 16:30:45 -0600 | [diff] [blame] | 90 | * @brief Retrieves chassis state properties over dbus |
| 91 | * |
Ed Tanous | ac106bf | 2023-06-07 09:24:59 -0700 | [diff] [blame] | 92 | * @param[in] asyncResp - Shared pointer for completing asynchronous calls. |
Gunnar Mills | beeca0a | 2019-02-14 16:30:45 -0600 | [diff] [blame] | 93 | * |
| 94 | * @return None. |
| 95 | */ |
Ed Tanous | ac106bf | 2023-06-07 09:24:59 -0700 | [diff] [blame] | 96 | inline void getChassisState(std::shared_ptr<bmcweb::AsyncResp> asyncResp) |
Gunnar Mills | beeca0a | 2019-02-14 16:30:45 -0600 | [diff] [blame] | 97 | { |
Jonathan Doman | 1e1e598 | 2021-06-11 09:36:17 -0700 | [diff] [blame] | 98 | // crow::connections::systemBus->async_method_call( |
| 99 | sdbusplus::asio::getProperty<std::string>( |
| 100 | *crow::connections::systemBus, "xyz.openbmc_project.State.Chassis", |
| 101 | "/xyz/openbmc_project/state/chassis0", |
| 102 | "xyz.openbmc_project.State.Chassis", "CurrentPowerState", |
Ed Tanous | ac106bf | 2023-06-07 09:24:59 -0700 | [diff] [blame] | 103 | [asyncResp{std::move(asyncResp)}](const boost::system::error_code& ec, |
| 104 | const std::string& chassisState) { |
Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 105 | if (ec) |
| 106 | { |
| 107 | if (ec == boost::system::errc::host_unreachable) |
Gunnar Mills | beeca0a | 2019-02-14 16:30:45 -0600 | [diff] [blame] | 108 | { |
Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 109 | // Service not available, no error, just don't return |
| 110 | // chassis state info |
Ed Tanous | 62598e3 | 2023-07-17 17:06:25 -0700 | [diff] [blame] | 111 | BMCWEB_LOG_DEBUG("Service not available {}", ec); |
Gunnar Mills | beeca0a | 2019-02-14 16:30:45 -0600 | [diff] [blame] | 112 | return; |
| 113 | } |
Ed Tanous | 62598e3 | 2023-07-17 17:06:25 -0700 | [diff] [blame] | 114 | BMCWEB_LOG_DEBUG("DBUS response error {}", ec); |
Ed Tanous | ac106bf | 2023-06-07 09:24:59 -0700 | [diff] [blame] | 115 | messages::internalError(asyncResp->res); |
Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 116 | return; |
| 117 | } |
Gunnar Mills | beeca0a | 2019-02-14 16:30:45 -0600 | [diff] [blame] | 118 | |
Ed Tanous | 62598e3 | 2023-07-17 17:06:25 -0700 | [diff] [blame] | 119 | BMCWEB_LOG_DEBUG("Chassis state: {}", chassisState); |
Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 120 | // Verify Chassis State |
| 121 | if (chassisState == "xyz.openbmc_project.State.Chassis.PowerState.On") |
| 122 | { |
Ed Tanous | ac106bf | 2023-06-07 09:24:59 -0700 | [diff] [blame] | 123 | asyncResp->res.jsonValue["PowerState"] = "On"; |
| 124 | asyncResp->res.jsonValue["Status"]["State"] = "Enabled"; |
Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 125 | } |
| 126 | else if (chassisState == |
| 127 | "xyz.openbmc_project.State.Chassis.PowerState.Off") |
| 128 | { |
Ed Tanous | ac106bf | 2023-06-07 09:24:59 -0700 | [diff] [blame] | 129 | asyncResp->res.jsonValue["PowerState"] = "Off"; |
| 130 | asyncResp->res.jsonValue["Status"]["State"] = "StandbyOffline"; |
Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 131 | } |
Patrick Williams | 5a39f77 | 2023-10-20 11:20:21 -0500 | [diff] [blame] | 132 | }); |
Gunnar Mills | beeca0a | 2019-02-14 16:30:45 -0600 | [diff] [blame] | 133 | } |
| 134 | |
Qiang XU | c181942 | 2019-02-27 13:51:32 +0800 | [diff] [blame] | 135 | /** |
| 136 | * Retrieves physical security properties over dbus |
| 137 | */ |
Chau Ly | 7164bc6 | 2023-10-15 14:55:30 +0000 | [diff] [blame] | 138 | inline void handlePhysicalSecurityGetSubTree( |
| 139 | const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, |
| 140 | const boost::system::error_code& ec, |
| 141 | const dbus::utility::MapperGetSubTreeResponse& subtree) |
Qiang XU | c181942 | 2019-02-27 13:51:32 +0800 | [diff] [blame] | 142 | { |
Chau Ly | 7164bc6 | 2023-10-15 14:55:30 +0000 | [diff] [blame] | 143 | if (ec) |
| 144 | { |
| 145 | // do not add err msg in redfish response, because this is not |
| 146 | // mandatory property |
| 147 | BMCWEB_LOG_INFO("DBUS error: no matched iface {}", ec); |
| 148 | return; |
| 149 | } |
| 150 | // Iterate over all retrieved ObjectPaths. |
| 151 | for (const auto& object : subtree) |
| 152 | { |
| 153 | if (!object.second.empty()) |
Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 154 | { |
Ed Tanous | 89144a3 | 2024-04-08 17:27:04 -0700 | [diff] [blame] | 155 | const auto& service = object.second.front(); |
Chau Ly | 7164bc6 | 2023-10-15 14:55:30 +0000 | [diff] [blame] | 156 | |
| 157 | BMCWEB_LOG_DEBUG("Get intrusion status by service "); |
| 158 | |
| 159 | sdbusplus::asio::getProperty<std::string>( |
| 160 | *crow::connections::systemBus, service.first, object.first, |
| 161 | "xyz.openbmc_project.Chassis.Intrusion", "Status", |
| 162 | [asyncResp](const boost::system::error_code& ec1, |
| 163 | const std::string& value) { |
| 164 | if (ec1) |
| 165 | { |
| 166 | // do not add err msg in redfish response, because this is |
| 167 | // not |
| 168 | // mandatory property |
| 169 | BMCWEB_LOG_ERROR("DBUS response error {}", ec1); |
| 170 | return; |
| 171 | } |
| 172 | asyncResp->res |
| 173 | .jsonValue["PhysicalSecurity"]["IntrusionSensorNumber"] = 1; |
| 174 | asyncResp->res |
| 175 | .jsonValue["PhysicalSecurity"]["IntrusionSensor"] = value; |
| 176 | }); |
| 177 | |
Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 178 | return; |
| 179 | } |
Chau Ly | 7164bc6 | 2023-10-15 14:55:30 +0000 | [diff] [blame] | 180 | } |
Qiang XU | c181942 | 2019-02-27 13:51:32 +0800 | [diff] [blame] | 181 | } |
| 182 | |
Nan Zhou | cf7eba0 | 2022-07-21 23:53:20 +0000 | [diff] [blame] | 183 | inline void handleChassisCollectionGet( |
| 184 | App& app, const crow::Request& req, |
| 185 | const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) |
| 186 | { |
| 187 | if (!redfish::setUpRedfishRoute(app, req, asyncResp)) |
| 188 | { |
| 189 | return; |
| 190 | } |
| 191 | asyncResp->res.jsonValue["@odata.type"] = |
| 192 | "#ChassisCollection.ChassisCollection"; |
| 193 | asyncResp->res.jsonValue["@odata.id"] = "/redfish/v1/Chassis"; |
| 194 | asyncResp->res.jsonValue["Name"] = "Chassis Collection"; |
| 195 | |
George Liu | 7a1dbc4 | 2022-12-07 16:03:22 +0800 | [diff] [blame] | 196 | constexpr std::array<std::string_view, 2> interfaces{ |
| 197 | "xyz.openbmc_project.Inventory.Item.Board", |
| 198 | "xyz.openbmc_project.Inventory.Item.Chassis"}; |
Nan Zhou | cf7eba0 | 2022-07-21 23:53:20 +0000 | [diff] [blame] | 199 | collection_util::getCollectionMembers( |
Lakshmi Yadlapati | 36b5f1e | 2023-09-26 23:53:28 -0500 | [diff] [blame] | 200 | asyncResp, boost::urls::url("/redfish/v1/Chassis"), interfaces, |
| 201 | "/xyz/openbmc_project/inventory"); |
Nan Zhou | cf7eba0 | 2022-07-21 23:53:20 +0000 | [diff] [blame] | 202 | } |
| 203 | |
Jie Yang | a561749 | 2021-06-29 12:59:14 -0700 | [diff] [blame] | 204 | inline void getChassisContainedBy( |
| 205 | const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, |
| 206 | const std::string& chassisId, const boost::system::error_code& ec, |
| 207 | const dbus::utility::MapperEndPoints& upstreamChassisPaths) |
| 208 | { |
| 209 | if (ec) |
| 210 | { |
| 211 | if (ec.value() != EBADR) |
| 212 | { |
Ed Tanous | 62598e3 | 2023-07-17 17:06:25 -0700 | [diff] [blame] | 213 | BMCWEB_LOG_ERROR("DBUS response error {}", ec); |
Jie Yang | a561749 | 2021-06-29 12:59:14 -0700 | [diff] [blame] | 214 | messages::internalError(asyncResp->res); |
| 215 | } |
| 216 | return; |
| 217 | } |
| 218 | if (upstreamChassisPaths.empty()) |
| 219 | { |
| 220 | return; |
| 221 | } |
| 222 | if (upstreamChassisPaths.size() > 1) |
| 223 | { |
Ed Tanous | 8ece0e4 | 2024-01-02 13:16:50 -0800 | [diff] [blame] | 224 | BMCWEB_LOG_ERROR("{} is contained by multiple chassis", chassisId); |
Jie Yang | a561749 | 2021-06-29 12:59:14 -0700 | [diff] [blame] | 225 | messages::internalError(asyncResp->res); |
| 226 | return; |
| 227 | } |
| 228 | |
| 229 | sdbusplus::message::object_path upstreamChassisPath( |
| 230 | upstreamChassisPaths[0]); |
| 231 | std::string upstreamChassis = upstreamChassisPath.filename(); |
| 232 | if (upstreamChassis.empty()) |
| 233 | { |
Ed Tanous | 62598e3 | 2023-07-17 17:06:25 -0700 | [diff] [blame] | 234 | BMCWEB_LOG_WARNING("Malformed upstream Chassis path {} on {}", |
| 235 | upstreamChassisPath.str, chassisId); |
Jie Yang | a561749 | 2021-06-29 12:59:14 -0700 | [diff] [blame] | 236 | return; |
| 237 | } |
| 238 | |
| 239 | asyncResp->res.jsonValue["Links"]["ContainedBy"]["@odata.id"] = |
| 240 | boost::urls::format("/redfish/v1/Chassis/{}", upstreamChassis); |
| 241 | } |
| 242 | |
| 243 | inline void getChassisContains( |
| 244 | const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, |
| 245 | const std::string& chassisId, const boost::system::error_code& ec, |
| 246 | const dbus::utility::MapperEndPoints& downstreamChassisPaths) |
| 247 | { |
| 248 | if (ec) |
| 249 | { |
| 250 | if (ec.value() != EBADR) |
| 251 | { |
Ed Tanous | 62598e3 | 2023-07-17 17:06:25 -0700 | [diff] [blame] | 252 | BMCWEB_LOG_ERROR("DBUS response error {}", ec); |
Jie Yang | a561749 | 2021-06-29 12:59:14 -0700 | [diff] [blame] | 253 | messages::internalError(asyncResp->res); |
| 254 | } |
| 255 | return; |
| 256 | } |
| 257 | if (downstreamChassisPaths.empty()) |
| 258 | { |
| 259 | return; |
| 260 | } |
| 261 | nlohmann::json& jValue = asyncResp->res.jsonValue["Links"]["Contains"]; |
| 262 | if (!jValue.is_array()) |
| 263 | { |
| 264 | // Create the array if it was empty |
| 265 | jValue = nlohmann::json::array(); |
| 266 | } |
| 267 | for (const auto& p : downstreamChassisPaths) |
| 268 | { |
| 269 | sdbusplus::message::object_path downstreamChassisPath(p); |
| 270 | std::string downstreamChassis = downstreamChassisPath.filename(); |
| 271 | if (downstreamChassis.empty()) |
| 272 | { |
Ed Tanous | 62598e3 | 2023-07-17 17:06:25 -0700 | [diff] [blame] | 273 | BMCWEB_LOG_WARNING("Malformed downstream Chassis path {} on {}", |
| 274 | downstreamChassisPath.str, chassisId); |
Jie Yang | a561749 | 2021-06-29 12:59:14 -0700 | [diff] [blame] | 275 | continue; |
| 276 | } |
| 277 | nlohmann::json link; |
| 278 | link["@odata.id"] = boost::urls::format("/redfish/v1/Chassis/{}", |
| 279 | downstreamChassis); |
| 280 | jValue.push_back(std::move(link)); |
| 281 | } |
| 282 | asyncResp->res.jsonValue["Links"]["Contains@odata.count"] = jValue.size(); |
| 283 | } |
| 284 | |
| 285 | inline void |
| 286 | getChassisConnectivity(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, |
| 287 | const std::string& chassisId, |
| 288 | const std::string& chassisPath) |
| 289 | { |
Ed Tanous | 62598e3 | 2023-07-17 17:06:25 -0700 | [diff] [blame] | 290 | BMCWEB_LOG_DEBUG("Get chassis connectivity"); |
Jie Yang | a561749 | 2021-06-29 12:59:14 -0700 | [diff] [blame] | 291 | |
| 292 | dbus::utility::getAssociationEndPoints( |
| 293 | chassisPath + "/contained_by", |
| 294 | std::bind_front(getChassisContainedBy, asyncResp, chassisId)); |
| 295 | |
| 296 | dbus::utility::getAssociationEndPoints( |
| 297 | chassisPath + "/containing", |
| 298 | std::bind_front(getChassisContains, asyncResp, chassisId)); |
| 299 | } |
| 300 | |
Rapkiewicz, Pawel | e37f845 | 2018-03-09 13:49:50 +0100 | [diff] [blame] | 301 | /** |
Rapkiewicz, Pawel | e37f845 | 2018-03-09 13:49:50 +0100 | [diff] [blame] | 302 | * ChassisCollection derived class for delivering Chassis Collection Schema |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 303 | * Functions triggers appropriate requests on DBus |
Rapkiewicz, Pawel | e37f845 | 2018-03-09 13:49:50 +0100 | [diff] [blame] | 304 | */ |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 305 | inline void requestRoutesChassisCollection(App& app) |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 306 | { |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 307 | BMCWEB_ROUTE(app, "/redfish/v1/Chassis/") |
Ed Tanous | ed39821 | 2021-06-09 17:05:54 -0700 | [diff] [blame] | 308 | .privileges(redfish::privileges::getChassisCollection) |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 309 | .methods(boost::beast::http::verb::get)( |
Nan Zhou | cf7eba0 | 2022-07-21 23:53:20 +0000 | [diff] [blame] | 310 | std::bind_front(handleChassisCollectionGet, std::ref(app))); |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 311 | } |
Rapkiewicz, Pawel | e37f845 | 2018-03-09 13:49:50 +0100 | [diff] [blame] | 312 | |
Willy Tu | 308f70c | 2021-09-28 20:24:52 -0700 | [diff] [blame] | 313 | inline void |
| 314 | getChassisLocationCode(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, |
| 315 | const std::string& connectionName, |
| 316 | const std::string& path) |
| 317 | { |
Jonathan Doman | 1e1e598 | 2021-06-11 09:36:17 -0700 | [diff] [blame] | 318 | sdbusplus::asio::getProperty<std::string>( |
| 319 | *crow::connections::systemBus, connectionName, path, |
| 320 | "xyz.openbmc_project.Inventory.Decorator.LocationCode", "LocationCode", |
Ed Tanous | 5e7e2dc | 2023-02-16 10:37:01 -0800 | [diff] [blame] | 321 | [asyncResp](const boost::system::error_code& ec, |
Jonathan Doman | 1e1e598 | 2021-06-11 09:36:17 -0700 | [diff] [blame] | 322 | const std::string& property) { |
Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 323 | if (ec) |
| 324 | { |
Ed Tanous | 62598e3 | 2023-07-17 17:06:25 -0700 | [diff] [blame] | 325 | BMCWEB_LOG_ERROR("DBUS response error for Location"); |
Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 326 | messages::internalError(asyncResp->res); |
| 327 | return; |
| 328 | } |
Willy Tu | 308f70c | 2021-09-28 20:24:52 -0700 | [diff] [blame] | 329 | |
Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 330 | asyncResp->res.jsonValue["Location"]["PartLocation"]["ServiceLabel"] = |
| 331 | property; |
Patrick Williams | 5a39f77 | 2023-10-20 11:20:21 -0500 | [diff] [blame] | 332 | }); |
Willy Tu | 308f70c | 2021-09-28 20:24:52 -0700 | [diff] [blame] | 333 | } |
| 334 | |
| 335 | inline void getChassisUUID(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, |
| 336 | const std::string& connectionName, |
| 337 | const std::string& path) |
| 338 | { |
Jonathan Doman | 1e1e598 | 2021-06-11 09:36:17 -0700 | [diff] [blame] | 339 | sdbusplus::asio::getProperty<std::string>( |
| 340 | *crow::connections::systemBus, connectionName, path, |
| 341 | "xyz.openbmc_project.Common.UUID", "UUID", |
Ed Tanous | 5e7e2dc | 2023-02-16 10:37:01 -0800 | [diff] [blame] | 342 | [asyncResp](const boost::system::error_code& ec, |
Jonathan Doman | 1e1e598 | 2021-06-11 09:36:17 -0700 | [diff] [blame] | 343 | const std::string& chassisUUID) { |
Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 344 | if (ec) |
| 345 | { |
Ed Tanous | 62598e3 | 2023-07-17 17:06:25 -0700 | [diff] [blame] | 346 | BMCWEB_LOG_ERROR("DBUS response error for UUID"); |
Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 347 | messages::internalError(asyncResp->res); |
| 348 | return; |
| 349 | } |
| 350 | asyncResp->res.jsonValue["UUID"] = chassisUUID; |
Patrick Williams | 5a39f77 | 2023-10-20 11:20:21 -0500 | [diff] [blame] | 351 | }); |
Willy Tu | 308f70c | 2021-09-28 20:24:52 -0700 | [diff] [blame] | 352 | } |
| 353 | |
Chau Ly | 7164bc6 | 2023-10-15 14:55:30 +0000 | [diff] [blame] | 354 | inline void handleDecoratorAssetProperties( |
| 355 | const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, |
| 356 | const std::string& chassisId, const std::string& path, |
| 357 | const dbus::utility::DBusPropertiesMap& propertiesList) |
| 358 | { |
| 359 | const std::string* partNumber = nullptr; |
| 360 | const std::string* serialNumber = nullptr; |
| 361 | const std::string* manufacturer = nullptr; |
| 362 | const std::string* model = nullptr; |
| 363 | const std::string* sparePartNumber = nullptr; |
| 364 | |
| 365 | const bool success = sdbusplus::unpackPropertiesNoThrow( |
| 366 | dbus_utils::UnpackErrorPrinter(), propertiesList, "PartNumber", |
| 367 | partNumber, "SerialNumber", serialNumber, "Manufacturer", manufacturer, |
| 368 | "Model", model, "SparePartNumber", sparePartNumber); |
| 369 | |
| 370 | if (!success) |
| 371 | { |
| 372 | messages::internalError(asyncResp->res); |
| 373 | return; |
| 374 | } |
| 375 | |
| 376 | if (partNumber != nullptr) |
| 377 | { |
| 378 | asyncResp->res.jsonValue["PartNumber"] = *partNumber; |
| 379 | } |
| 380 | |
| 381 | if (serialNumber != nullptr) |
| 382 | { |
| 383 | asyncResp->res.jsonValue["SerialNumber"] = *serialNumber; |
| 384 | } |
| 385 | |
| 386 | if (manufacturer != nullptr) |
| 387 | { |
| 388 | asyncResp->res.jsonValue["Manufacturer"] = *manufacturer; |
| 389 | } |
| 390 | |
| 391 | if (model != nullptr) |
| 392 | { |
| 393 | asyncResp->res.jsonValue["Model"] = *model; |
| 394 | } |
| 395 | |
| 396 | // SparePartNumber is optional on D-Bus |
| 397 | // so skip if it is empty |
| 398 | if (sparePartNumber != nullptr && !sparePartNumber->empty()) |
| 399 | { |
| 400 | asyncResp->res.jsonValue["SparePartNumber"] = *sparePartNumber; |
| 401 | } |
| 402 | |
| 403 | asyncResp->res.jsonValue["Name"] = chassisId; |
| 404 | asyncResp->res.jsonValue["Id"] = chassisId; |
| 405 | #ifdef BMCWEB_ALLOW_DEPRECATED_POWER_THERMAL |
| 406 | asyncResp->res.jsonValue["Thermal"]["@odata.id"] = |
| 407 | boost::urls::format("/redfish/v1/Chassis/{}/Thermal", chassisId); |
| 408 | // Power object |
| 409 | asyncResp->res.jsonValue["Power"]["@odata.id"] = |
| 410 | boost::urls::format("/redfish/v1/Chassis/{}/Power", chassisId); |
| 411 | #endif |
| 412 | #ifdef BMCWEB_NEW_POWERSUBSYSTEM_THERMALSUBSYSTEM |
| 413 | asyncResp->res.jsonValue["ThermalSubsystem"]["@odata.id"] = |
| 414 | boost::urls::format("/redfish/v1/Chassis/{}/ThermalSubsystem", |
| 415 | chassisId); |
| 416 | asyncResp->res.jsonValue["PowerSubsystem"]["@odata.id"] = |
| 417 | boost::urls::format("/redfish/v1/Chassis/{}/PowerSubsystem", chassisId); |
| 418 | asyncResp->res.jsonValue["EnvironmentMetrics"]["@odata.id"] = |
| 419 | boost::urls::format("/redfish/v1/Chassis/{}/EnvironmentMetrics", |
| 420 | chassisId); |
| 421 | #endif |
| 422 | // SensorCollection |
| 423 | asyncResp->res.jsonValue["Sensors"]["@odata.id"] = |
| 424 | boost::urls::format("/redfish/v1/Chassis/{}/Sensors", chassisId); |
| 425 | asyncResp->res.jsonValue["Status"]["State"] = "Enabled"; |
| 426 | |
| 427 | nlohmann::json::array_t computerSystems; |
| 428 | nlohmann::json::object_t system; |
| 429 | system["@odata.id"] = "/redfish/v1/Systems/system"; |
| 430 | computerSystems.emplace_back(std::move(system)); |
| 431 | asyncResp->res.jsonValue["Links"]["ComputerSystems"] = |
| 432 | std::move(computerSystems); |
| 433 | |
| 434 | nlohmann::json::array_t managedBy; |
| 435 | nlohmann::json::object_t manager; |
| 436 | manager["@odata.id"] = "/redfish/v1/Managers/bmc"; |
| 437 | managedBy.emplace_back(std::move(manager)); |
| 438 | asyncResp->res.jsonValue["Links"]["ManagedBy"] = std::move(managedBy); |
| 439 | getChassisState(asyncResp); |
| 440 | getStorageLink(asyncResp, path); |
| 441 | } |
| 442 | |
| 443 | inline void handleChassisGetSubTree( |
| 444 | const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, |
| 445 | const std::string& chassisId, const boost::system::error_code& ec, |
| 446 | const dbus::utility::MapperGetSubTreeResponse& subtree) |
| 447 | { |
| 448 | if (ec) |
| 449 | { |
| 450 | BMCWEB_LOG_ERROR("DBUS response error {}", ec); |
| 451 | messages::internalError(asyncResp->res); |
| 452 | return; |
| 453 | } |
| 454 | // Iterate over all retrieved ObjectPaths. |
| 455 | for (const std::pair< |
| 456 | std::string, |
| 457 | std::vector<std::pair<std::string, std::vector<std::string>>>>& |
| 458 | object : subtree) |
| 459 | { |
| 460 | const std::string& path = object.first; |
| 461 | const std::vector<std::pair<std::string, std::vector<std::string>>>& |
| 462 | connectionNames = object.second; |
| 463 | |
| 464 | sdbusplus::message::object_path objPath(path); |
| 465 | if (objPath.filename() != chassisId) |
| 466 | { |
| 467 | continue; |
| 468 | } |
| 469 | |
| 470 | getChassisConnectivity(asyncResp, chassisId, path); |
| 471 | |
Chau Ly | 7164bc6 | 2023-10-15 14:55:30 +0000 | [diff] [blame] | 472 | if (connectionNames.empty()) |
| 473 | { |
| 474 | BMCWEB_LOG_ERROR("Got 0 Connection names"); |
| 475 | continue; |
| 476 | } |
| 477 | |
| 478 | asyncResp->res.jsonValue["@odata.type"] = "#Chassis.v1_22_0.Chassis"; |
| 479 | asyncResp->res.jsonValue["@odata.id"] = |
| 480 | boost::urls::format("/redfish/v1/Chassis/{}", chassisId); |
| 481 | asyncResp->res.jsonValue["Name"] = "Chassis Collection"; |
| 482 | asyncResp->res.jsonValue["ChassisType"] = "RackMount"; |
| 483 | asyncResp->res.jsonValue["Actions"]["#Chassis.Reset"]["target"] = |
| 484 | boost::urls::format("/redfish/v1/Chassis/{}/Actions/Chassis.Reset", |
| 485 | chassisId); |
| 486 | asyncResp->res |
| 487 | .jsonValue["Actions"]["#Chassis.Reset"]["@Redfish.ActionInfo"] = |
| 488 | boost::urls::format("/redfish/v1/Chassis/{}/ResetActionInfo", |
| 489 | chassisId); |
Chau Ly | 7164bc6 | 2023-10-15 14:55:30 +0000 | [diff] [blame] | 490 | dbus::utility::getAssociationEndPoints( |
| 491 | path + "/drive", |
| 492 | [asyncResp, chassisId](const boost::system::error_code& ec3, |
| 493 | const dbus::utility::MapperEndPoints& resp) { |
| 494 | if (ec3 || resp.empty()) |
| 495 | { |
| 496 | return; // no drives = no failures |
| 497 | } |
| 498 | |
| 499 | nlohmann::json reference; |
| 500 | reference["@odata.id"] = |
| 501 | boost::urls::format("/redfish/v1/Chassis/{}/Drives", chassisId); |
| 502 | asyncResp->res.jsonValue["Drives"] = std::move(reference); |
| 503 | }); |
| 504 | |
| 505 | const std::string& connectionName = connectionNames[0].first; |
| 506 | |
| 507 | const std::vector<std::string>& interfaces2 = connectionNames[0].second; |
George Liu | e5ae9c1 | 2021-11-16 10:31:23 +0800 | [diff] [blame] | 508 | const std::array<const char*, 3> hasIndicatorLed = { |
| 509 | "xyz.openbmc_project.Inventory.Item.Chassis", |
Chau Ly | 7164bc6 | 2023-10-15 14:55:30 +0000 | [diff] [blame] | 510 | "xyz.openbmc_project.Inventory.Item.Panel", |
| 511 | "xyz.openbmc_project.Inventory.Item.Board.Motherboard"}; |
| 512 | |
| 513 | const std::string assetTagInterface = |
| 514 | "xyz.openbmc_project.Inventory.Decorator.AssetTag"; |
| 515 | const std::string replaceableInterface = |
| 516 | "xyz.openbmc_project.Inventory.Decorator.Replaceable"; |
Carson Labrado | b4d593f | 2024-02-16 22:34:32 +0000 | [diff] [blame] | 517 | const std::string revisionInterface = |
| 518 | "xyz.openbmc_project.Inventory.Decorator.Revision"; |
Chau Ly | 7164bc6 | 2023-10-15 14:55:30 +0000 | [diff] [blame] | 519 | for (const auto& interface : interfaces2) |
| 520 | { |
| 521 | if (interface == assetTagInterface) |
| 522 | { |
| 523 | sdbusplus::asio::getProperty<std::string>( |
| 524 | *crow::connections::systemBus, connectionName, path, |
| 525 | assetTagInterface, "AssetTag", |
| 526 | [asyncResp, chassisId](const boost::system::error_code& ec2, |
| 527 | const std::string& property) { |
| 528 | if (ec2) |
| 529 | { |
| 530 | BMCWEB_LOG_ERROR("DBus response error for AssetTag: {}", |
| 531 | ec2); |
| 532 | messages::internalError(asyncResp->res); |
| 533 | return; |
| 534 | } |
| 535 | asyncResp->res.jsonValue["AssetTag"] = property; |
| 536 | }); |
| 537 | } |
| 538 | else if (interface == replaceableInterface) |
| 539 | { |
| 540 | sdbusplus::asio::getProperty<bool>( |
| 541 | *crow::connections::systemBus, connectionName, path, |
| 542 | replaceableInterface, "HotPluggable", |
| 543 | [asyncResp, chassisId](const boost::system::error_code& ec2, |
| 544 | const bool property) { |
| 545 | if (ec2) |
| 546 | { |
| 547 | BMCWEB_LOG_ERROR( |
| 548 | "DBus response error for HotPluggable: {}", ec2); |
| 549 | messages::internalError(asyncResp->res); |
| 550 | return; |
| 551 | } |
| 552 | asyncResp->res.jsonValue["HotPluggable"] = property; |
| 553 | }); |
| 554 | } |
Carson Labrado | b4d593f | 2024-02-16 22:34:32 +0000 | [diff] [blame] | 555 | else if (interface == revisionInterface) |
| 556 | { |
| 557 | sdbusplus::asio::getProperty<std::string>( |
| 558 | *crow::connections::systemBus, connectionName, path, |
| 559 | revisionInterface, "Version", |
| 560 | [asyncResp, chassisId](const boost::system::error_code& ec2, |
| 561 | const std::string& property) { |
| 562 | if (ec2) |
| 563 | { |
| 564 | BMCWEB_LOG_ERROR("DBus response error for Version: {}", |
| 565 | ec2); |
| 566 | messages::internalError(asyncResp->res); |
| 567 | return; |
| 568 | } |
| 569 | asyncResp->res.jsonValue["Version"] = property; |
| 570 | }); |
| 571 | } |
Chau Ly | 7164bc6 | 2023-10-15 14:55:30 +0000 | [diff] [blame] | 572 | } |
| 573 | |
| 574 | for (const char* interface : hasIndicatorLed) |
| 575 | { |
| 576 | if (std::ranges::find(interfaces2, interface) != interfaces2.end()) |
| 577 | { |
| 578 | getIndicatorLedState(asyncResp); |
| 579 | getSystemLocationIndicatorActive(asyncResp); |
| 580 | break; |
| 581 | } |
| 582 | } |
| 583 | |
| 584 | sdbusplus::asio::getAllProperties( |
| 585 | *crow::connections::systemBus, connectionName, path, |
| 586 | "xyz.openbmc_project.Inventory.Decorator.Asset", |
| 587 | [asyncResp, chassisId, |
| 588 | path](const boost::system::error_code&, |
| 589 | const dbus::utility::DBusPropertiesMap& propertiesList) { |
| 590 | handleDecoratorAssetProperties(asyncResp, chassisId, path, |
| 591 | propertiesList); |
| 592 | }); |
| 593 | |
| 594 | for (const auto& interface : interfaces2) |
| 595 | { |
| 596 | if (interface == "xyz.openbmc_project.Common.UUID") |
| 597 | { |
| 598 | getChassisUUID(asyncResp, connectionName, path); |
| 599 | } |
| 600 | else if (interface == |
| 601 | "xyz.openbmc_project.Inventory.Decorator.LocationCode") |
| 602 | { |
| 603 | getChassisLocationCode(asyncResp, connectionName, path); |
| 604 | } |
| 605 | } |
| 606 | |
| 607 | return; |
| 608 | } |
| 609 | |
| 610 | // Couldn't find an object with that name. return an error |
| 611 | messages::resourceNotFound(asyncResp->res, "Chassis", chassisId); |
| 612 | } |
| 613 | |
Nan Zhou | cf7eba0 | 2022-07-21 23:53:20 +0000 | [diff] [blame] | 614 | inline void |
| 615 | handleChassisGet(App& app, const crow::Request& req, |
| 616 | const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, |
| 617 | const std::string& chassisId) |
| 618 | { |
| 619 | if (!redfish::setUpRedfishRoute(app, req, asyncResp)) |
| 620 | { |
| 621 | return; |
| 622 | } |
George Liu | e99073f | 2022-12-09 11:06:16 +0800 | [diff] [blame] | 623 | constexpr std::array<std::string_view, 2> interfaces = { |
Nan Zhou | cf7eba0 | 2022-07-21 23:53:20 +0000 | [diff] [blame] | 624 | "xyz.openbmc_project.Inventory.Item.Board", |
| 625 | "xyz.openbmc_project.Inventory.Item.Chassis"}; |
| 626 | |
George Liu | e99073f | 2022-12-09 11:06:16 +0800 | [diff] [blame] | 627 | dbus::utility::getSubTree( |
| 628 | "/xyz/openbmc_project/inventory", 0, interfaces, |
Chau Ly | 7164bc6 | 2023-10-15 14:55:30 +0000 | [diff] [blame] | 629 | std::bind_front(handleChassisGetSubTree, asyncResp, chassisId)); |
Nan Zhou | cf7eba0 | 2022-07-21 23:53:20 +0000 | [diff] [blame] | 630 | |
Chau Ly | 7164bc6 | 2023-10-15 14:55:30 +0000 | [diff] [blame] | 631 | constexpr std::array<std::string_view, 1> interfaces2 = { |
| 632 | "xyz.openbmc_project.Chassis.Intrusion"}; |
Nan Zhou | cf7eba0 | 2022-07-21 23:53:20 +0000 | [diff] [blame] | 633 | |
Chau Ly | 7164bc6 | 2023-10-15 14:55:30 +0000 | [diff] [blame] | 634 | dbus::utility::getSubTree( |
| 635 | "/xyz/openbmc_project", 0, interfaces2, |
| 636 | std::bind_front(handlePhysicalSecurityGetSubTree, asyncResp)); |
Nan Zhou | cf7eba0 | 2022-07-21 23:53:20 +0000 | [diff] [blame] | 637 | } |
| 638 | |
| 639 | inline void |
| 640 | handleChassisPatch(App& app, const crow::Request& req, |
| 641 | const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, |
| 642 | const std::string& param) |
| 643 | { |
| 644 | if (!redfish::setUpRedfishRoute(app, req, asyncResp)) |
| 645 | { |
| 646 | return; |
| 647 | } |
| 648 | std::optional<bool> locationIndicatorActive; |
| 649 | std::optional<std::string> indicatorLed; |
| 650 | |
| 651 | if (param.empty()) |
| 652 | { |
| 653 | return; |
| 654 | } |
| 655 | |
| 656 | if (!json_util::readJsonPatch( |
| 657 | req, asyncResp->res, "LocationIndicatorActive", |
| 658 | locationIndicatorActive, "IndicatorLED", indicatorLed)) |
| 659 | { |
| 660 | return; |
| 661 | } |
| 662 | |
| 663 | // TODO (Gunnar): Remove IndicatorLED after enough time has passed |
| 664 | if (!locationIndicatorActive && !indicatorLed) |
| 665 | { |
| 666 | return; // delete this when we support more patch properties |
| 667 | } |
| 668 | if (indicatorLed) |
| 669 | { |
| 670 | asyncResp->res.addHeader( |
| 671 | boost::beast::http::field::warning, |
| 672 | "299 - \"IndicatorLED is deprecated. Use LocationIndicatorActive instead.\""); |
| 673 | } |
| 674 | |
George Liu | e99073f | 2022-12-09 11:06:16 +0800 | [diff] [blame] | 675 | constexpr std::array<std::string_view, 2> interfaces = { |
Nan Zhou | cf7eba0 | 2022-07-21 23:53:20 +0000 | [diff] [blame] | 676 | "xyz.openbmc_project.Inventory.Item.Board", |
| 677 | "xyz.openbmc_project.Inventory.Item.Chassis"}; |
| 678 | |
| 679 | const std::string& chassisId = param; |
| 680 | |
George Liu | e99073f | 2022-12-09 11:06:16 +0800 | [diff] [blame] | 681 | dbus::utility::getSubTree( |
| 682 | "/xyz/openbmc_project/inventory", 0, interfaces, |
Nan Zhou | cf7eba0 | 2022-07-21 23:53:20 +0000 | [diff] [blame] | 683 | [asyncResp, chassisId, locationIndicatorActive, |
Ed Tanous | 5e7e2dc | 2023-02-16 10:37:01 -0800 | [diff] [blame] | 684 | indicatorLed](const boost::system::error_code& ec, |
Nan Zhou | cf7eba0 | 2022-07-21 23:53:20 +0000 | [diff] [blame] | 685 | const dbus::utility::MapperGetSubTreeResponse& subtree) { |
| 686 | if (ec) |
| 687 | { |
Ed Tanous | 62598e3 | 2023-07-17 17:06:25 -0700 | [diff] [blame] | 688 | BMCWEB_LOG_ERROR("DBUS response error {}", ec); |
Nan Zhou | cf7eba0 | 2022-07-21 23:53:20 +0000 | [diff] [blame] | 689 | messages::internalError(asyncResp->res); |
| 690 | return; |
| 691 | } |
| 692 | |
| 693 | // Iterate over all retrieved ObjectPaths. |
| 694 | for (const std::pair< |
| 695 | std::string, |
| 696 | std::vector<std::pair<std::string, std::vector<std::string>>>>& |
| 697 | object : subtree) |
| 698 | { |
| 699 | const std::string& path = object.first; |
| 700 | const std::vector<std::pair<std::string, std::vector<std::string>>>& |
| 701 | connectionNames = object.second; |
| 702 | |
| 703 | sdbusplus::message::object_path objPath(path); |
| 704 | if (objPath.filename() != chassisId) |
| 705 | { |
| 706 | continue; |
| 707 | } |
| 708 | |
| 709 | if (connectionNames.empty()) |
| 710 | { |
Ed Tanous | 62598e3 | 2023-07-17 17:06:25 -0700 | [diff] [blame] | 711 | BMCWEB_LOG_ERROR("Got 0 Connection names"); |
Nan Zhou | cf7eba0 | 2022-07-21 23:53:20 +0000 | [diff] [blame] | 712 | continue; |
| 713 | } |
| 714 | |
| 715 | const std::vector<std::string>& interfaces3 = |
| 716 | connectionNames[0].second; |
| 717 | |
George Liu | e5ae9c1 | 2021-11-16 10:31:23 +0800 | [diff] [blame] | 718 | const std::array<const char*, 3> hasIndicatorLed = { |
| 719 | "xyz.openbmc_project.Inventory.Item.Chassis", |
Nan Zhou | cf7eba0 | 2022-07-21 23:53:20 +0000 | [diff] [blame] | 720 | "xyz.openbmc_project.Inventory.Item.Panel", |
| 721 | "xyz.openbmc_project.Inventory.Item.Board.Motherboard"}; |
| 722 | bool indicatorChassis = false; |
| 723 | for (const char* interface : hasIndicatorLed) |
| 724 | { |
Ed Tanous | 3544d2a | 2023-08-06 18:12:20 -0700 | [diff] [blame] | 725 | if (std::ranges::find(interfaces3, interface) != |
| 726 | interfaces3.end()) |
Nan Zhou | cf7eba0 | 2022-07-21 23:53:20 +0000 | [diff] [blame] | 727 | { |
| 728 | indicatorChassis = true; |
| 729 | break; |
| 730 | } |
| 731 | } |
| 732 | if (locationIndicatorActive) |
| 733 | { |
| 734 | if (indicatorChassis) |
| 735 | { |
George Liu | 59a17e4 | 2022-10-08 09:27:47 +0800 | [diff] [blame] | 736 | setSystemLocationIndicatorActive(asyncResp, |
| 737 | *locationIndicatorActive); |
Nan Zhou | cf7eba0 | 2022-07-21 23:53:20 +0000 | [diff] [blame] | 738 | } |
| 739 | else |
| 740 | { |
| 741 | messages::propertyUnknown(asyncResp->res, |
| 742 | "LocationIndicatorActive"); |
| 743 | } |
| 744 | } |
| 745 | if (indicatorLed) |
| 746 | { |
| 747 | if (indicatorChassis) |
| 748 | { |
| 749 | setIndicatorLedState(asyncResp, *indicatorLed); |
| 750 | } |
| 751 | else |
| 752 | { |
| 753 | messages::propertyUnknown(asyncResp->res, "IndicatorLED"); |
| 754 | } |
| 755 | } |
| 756 | return; |
| 757 | } |
| 758 | |
Jiaqing Zhao | d8a5d5d | 2022-08-05 16:21:51 +0800 | [diff] [blame] | 759 | messages::resourceNotFound(asyncResp->res, "Chassis", chassisId); |
Patrick Williams | 5a39f77 | 2023-10-20 11:20:21 -0500 | [diff] [blame] | 760 | }); |
Nan Zhou | cf7eba0 | 2022-07-21 23:53:20 +0000 | [diff] [blame] | 761 | } |
| 762 | |
Rapkiewicz, Pawel | e37f845 | 2018-03-09 13:49:50 +0100 | [diff] [blame] | 763 | /** |
| 764 | * Chassis override class for delivering Chassis Schema |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 765 | * Functions triggers appropriate requests on DBus |
Rapkiewicz, Pawel | e37f845 | 2018-03-09 13:49:50 +0100 | [diff] [blame] | 766 | */ |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 767 | inline void requestRoutesChassis(App& app) |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 768 | { |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 769 | BMCWEB_ROUTE(app, "/redfish/v1/Chassis/<str>/") |
Ed Tanous | ed39821 | 2021-06-09 17:05:54 -0700 | [diff] [blame] | 770 | .privileges(redfish::privileges::getChassis) |
Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 771 | .methods(boost::beast::http::verb::get)( |
Nan Zhou | cf7eba0 | 2022-07-21 23:53:20 +0000 | [diff] [blame] | 772 | std::bind_front(handleChassisGet, std::ref(app))); |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 773 | |
| 774 | BMCWEB_ROUTE(app, "/redfish/v1/Chassis/<str>/") |
Ed Tanous | ed39821 | 2021-06-09 17:05:54 -0700 | [diff] [blame] | 775 | .privileges(redfish::privileges::patchChassis) |
Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 776 | .methods(boost::beast::http::verb::patch)( |
Nan Zhou | cf7eba0 | 2022-07-21 23:53:20 +0000 | [diff] [blame] | 777 | std::bind_front(handleChassisPatch, std::ref(app))); |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 778 | } |
P.K. Lee | dd99e04 | 2020-06-17 19:43:16 +0800 | [diff] [blame] | 779 | |
zhanghch05 | 8d1b46d | 2021-04-01 11:18:24 +0800 | [diff] [blame] | 780 | inline void |
| 781 | doChassisPowerCycle(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) |
P.K. Lee | dd99e04 | 2020-06-17 19:43:16 +0800 | [diff] [blame] | 782 | { |
George Liu | 7a1dbc4 | 2022-12-07 16:03:22 +0800 | [diff] [blame] | 783 | constexpr std::array<std::string_view, 1> interfaces = { |
Vijay Khemka | c3b3c92 | 2020-09-22 23:00:12 -0700 | [diff] [blame] | 784 | "xyz.openbmc_project.State.Chassis"}; |
| 785 | |
| 786 | // Use mapper to get subtree paths. |
George Liu | 7a1dbc4 | 2022-12-07 16:03:22 +0800 | [diff] [blame] | 787 | dbus::utility::getSubTreePaths( |
| 788 | "/", 0, interfaces, |
Ed Tanous | b9d36b4 | 2022-02-26 21:42:46 -0800 | [diff] [blame] | 789 | [asyncResp]( |
George Liu | 7a1dbc4 | 2022-12-07 16:03:22 +0800 | [diff] [blame] | 790 | const boost::system::error_code& ec, |
Ed Tanous | b9d36b4 | 2022-02-26 21:42:46 -0800 | [diff] [blame] | 791 | const dbus::utility::MapperGetSubTreePathsResponse& chassisList) { |
Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 792 | if (ec) |
| 793 | { |
Ed Tanous | 62598e3 | 2023-07-17 17:06:25 -0700 | [diff] [blame] | 794 | BMCWEB_LOG_ERROR("[mapper] Bad D-Bus request error: {}", ec); |
Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 795 | messages::internalError(asyncResp->res); |
| 796 | return; |
| 797 | } |
| 798 | |
| 799 | const char* processName = "xyz.openbmc_project.State.Chassis"; |
| 800 | const char* interfaceName = "xyz.openbmc_project.State.Chassis"; |
| 801 | const char* destProperty = "RequestedPowerTransition"; |
| 802 | const std::string propertyValue = |
| 803 | "xyz.openbmc_project.State.Chassis.Transition.PowerCycle"; |
| 804 | std::string objectPath = "/xyz/openbmc_project/state/chassis_system0"; |
| 805 | |
| 806 | /* Look for system reset chassis path */ |
Ed Tanous | 3544d2a | 2023-08-06 18:12:20 -0700 | [diff] [blame] | 807 | if ((std::ranges::find(chassisList, objectPath)) == chassisList.end()) |
Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 808 | { |
| 809 | /* We prefer to reset the full chassis_system, but if it doesn't |
| 810 | * exist on some platforms, fall back to a host-only power reset |
| 811 | */ |
| 812 | objectPath = "/xyz/openbmc_project/state/chassis0"; |
| 813 | } |
| 814 | |
Ed Tanous | d02aad3 | 2024-02-13 14:43:34 -0800 | [diff] [blame] | 815 | setDbusProperty(asyncResp, processName, objectPath, interfaceName, |
| 816 | destProperty, "ResetType", propertyValue); |
Patrick Williams | 5a39f77 | 2023-10-20 11:20:21 -0500 | [diff] [blame] | 817 | }); |
P.K. Lee | dd99e04 | 2020-06-17 19:43:16 +0800 | [diff] [blame] | 818 | } |
| 819 | |
Nan Zhou | cf7eba0 | 2022-07-21 23:53:20 +0000 | [diff] [blame] | 820 | inline void handleChassisResetActionInfoPost( |
| 821 | App& app, const crow::Request& req, |
| 822 | const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, |
| 823 | const std::string& /*chassisId*/) |
| 824 | { |
| 825 | if (!redfish::setUpRedfishRoute(app, req, asyncResp)) |
| 826 | { |
| 827 | return; |
| 828 | } |
Ed Tanous | 62598e3 | 2023-07-17 17:06:25 -0700 | [diff] [blame] | 829 | BMCWEB_LOG_DEBUG("Post Chassis Reset."); |
Nan Zhou | cf7eba0 | 2022-07-21 23:53:20 +0000 | [diff] [blame] | 830 | |
| 831 | std::string resetType; |
| 832 | |
| 833 | if (!json_util::readJsonAction(req, asyncResp->res, "ResetType", resetType)) |
| 834 | { |
| 835 | return; |
| 836 | } |
| 837 | |
| 838 | if (resetType != "PowerCycle") |
| 839 | { |
Ed Tanous | 62598e3 | 2023-07-17 17:06:25 -0700 | [diff] [blame] | 840 | BMCWEB_LOG_DEBUG("Invalid property value for ResetType: {}", resetType); |
Nan Zhou | cf7eba0 | 2022-07-21 23:53:20 +0000 | [diff] [blame] | 841 | messages::actionParameterNotSupported(asyncResp->res, resetType, |
| 842 | "ResetType"); |
| 843 | |
| 844 | return; |
| 845 | } |
| 846 | doChassisPowerCycle(asyncResp); |
| 847 | } |
| 848 | |
P.K. Lee | dd99e04 | 2020-06-17 19:43:16 +0800 | [diff] [blame] | 849 | /** |
| 850 | * ChassisResetAction class supports the POST method for the Reset |
| 851 | * action. |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 852 | * Function handles POST method request. |
| 853 | * Analyzes POST body before sending Reset request data to D-Bus. |
P.K. Lee | dd99e04 | 2020-06-17 19:43:16 +0800 | [diff] [blame] | 854 | */ |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 855 | |
| 856 | inline void requestRoutesChassisResetAction(App& app) |
P.K. Lee | dd99e04 | 2020-06-17 19:43:16 +0800 | [diff] [blame] | 857 | { |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 858 | BMCWEB_ROUTE(app, "/redfish/v1/Chassis/<str>/Actions/Chassis.Reset/") |
Ed Tanous | ed39821 | 2021-06-09 17:05:54 -0700 | [diff] [blame] | 859 | .privileges(redfish::privileges::postChassis) |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 860 | .methods(boost::beast::http::verb::post)( |
Nan Zhou | cf7eba0 | 2022-07-21 23:53:20 +0000 | [diff] [blame] | 861 | std::bind_front(handleChassisResetActionInfoPost, std::ref(app))); |
| 862 | } |
P.K. Lee | dd99e04 | 2020-06-17 19:43:16 +0800 | [diff] [blame] | 863 | |
Nan Zhou | cf7eba0 | 2022-07-21 23:53:20 +0000 | [diff] [blame] | 864 | inline void handleChassisResetActionInfoGet( |
| 865 | App& app, const crow::Request& req, |
| 866 | const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, |
| 867 | const std::string& chassisId) |
| 868 | { |
| 869 | if (!redfish::setUpRedfishRoute(app, req, asyncResp)) |
| 870 | { |
| 871 | return; |
| 872 | } |
| 873 | asyncResp->res.jsonValue["@odata.type"] = "#ActionInfo.v1_1_2.ActionInfo"; |
Ed Tanous | ef4c65b | 2023-04-24 15:28:50 -0700 | [diff] [blame] | 874 | asyncResp->res.jsonValue["@odata.id"] = boost::urls::format( |
| 875 | "/redfish/v1/Chassis/{}/ResetActionInfo", chassisId); |
Nan Zhou | cf7eba0 | 2022-07-21 23:53:20 +0000 | [diff] [blame] | 876 | asyncResp->res.jsonValue["Name"] = "Reset Action Info"; |
P.K. Lee | dd99e04 | 2020-06-17 19:43:16 +0800 | [diff] [blame] | 877 | |
Nan Zhou | cf7eba0 | 2022-07-21 23:53:20 +0000 | [diff] [blame] | 878 | asyncResp->res.jsonValue["Id"] = "ResetActionInfo"; |
| 879 | nlohmann::json::array_t parameters; |
| 880 | nlohmann::json::object_t parameter; |
| 881 | parameter["Name"] = "ResetType"; |
| 882 | parameter["Required"] = true; |
| 883 | parameter["DataType"] = "String"; |
| 884 | nlohmann::json::array_t allowed; |
Patrick Williams | ad53954 | 2023-05-12 10:10:08 -0500 | [diff] [blame] | 885 | allowed.emplace_back("PowerCycle"); |
Nan Zhou | cf7eba0 | 2022-07-21 23:53:20 +0000 | [diff] [blame] | 886 | parameter["AllowableValues"] = std::move(allowed); |
Patrick Williams | ad53954 | 2023-05-12 10:10:08 -0500 | [diff] [blame] | 887 | parameters.emplace_back(std::move(parameter)); |
P.K. Lee | dd99e04 | 2020-06-17 19:43:16 +0800 | [diff] [blame] | 888 | |
Nan Zhou | cf7eba0 | 2022-07-21 23:53:20 +0000 | [diff] [blame] | 889 | asyncResp->res.jsonValue["Parameters"] = std::move(parameters); |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 890 | } |
AppaRao Puli | 1cb1a9e | 2020-07-17 23:38:57 +0530 | [diff] [blame] | 891 | |
| 892 | /** |
| 893 | * ChassisResetActionInfo derived class for delivering Chassis |
| 894 | * ResetType AllowableValues using ResetInfo schema. |
| 895 | */ |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 896 | inline void requestRoutesChassisResetActionInfo(App& app) |
AppaRao Puli | 1cb1a9e | 2020-07-17 23:38:57 +0530 | [diff] [blame] | 897 | { |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 898 | BMCWEB_ROUTE(app, "/redfish/v1/Chassis/<str>/ResetActionInfo/") |
Ed Tanous | ed39821 | 2021-06-09 17:05:54 -0700 | [diff] [blame] | 899 | .privileges(redfish::privileges::getActionInfo) |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 900 | .methods(boost::beast::http::verb::get)( |
Nan Zhou | cf7eba0 | 2022-07-21 23:53:20 +0000 | [diff] [blame] | 901 | std::bind_front(handleChassisResetActionInfoGet, std::ref(app))); |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 902 | } |
AppaRao Puli | 1cb1a9e | 2020-07-17 23:38:57 +0530 | [diff] [blame] | 903 | |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 904 | } // namespace redfish |