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