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