| Ed Tanous | 40e9b92 | 2024-09-10 13:50:16 -0700 | [diff] [blame] | 1 | // SPDX-License-Identifier: Apache-2.0 |
| 2 | // SPDX-FileCopyrightText: Copyright OpenBMC Authors |
| George Liu | 9516f41 | 2022-09-29 17:21:41 +0800 | [diff] [blame] | 3 | #pragma once |
| 4 | |
| 5 | #include "app.hpp" |
| Ed Tanous | d785720 | 2025-01-28 15:32:26 -0800 | [diff] [blame] | 6 | #include "async_resp.hpp" |
| George Liu | 9516f41 | 2022-09-29 17:21:41 +0800 | [diff] [blame] | 7 | #include "dbus_utility.hpp" |
| 8 | #include "error_messages.hpp" |
| Ed Tanous | 539d8c6 | 2024-06-19 14:38:27 -0700 | [diff] [blame] | 9 | #include "generated/enums/resource.hpp" |
| Ed Tanous | d785720 | 2025-01-28 15:32:26 -0800 | [diff] [blame] | 10 | #include "http_request.hpp" |
| Myung Bae | 1da1ff5 | 2024-08-20 11:34:59 -0500 | [diff] [blame] | 11 | #include "led.hpp" |
| Ed Tanous | d785720 | 2025-01-28 15:32:26 -0800 | [diff] [blame] | 12 | #include "logging.hpp" |
| George Liu | 9516f41 | 2022-09-29 17:21:41 +0800 | [diff] [blame] | 13 | #include "query.hpp" |
| 14 | #include "registries/privilege_registry.hpp" |
| Myung Bae | f7e62c1 | 2025-09-07 14:02:08 -0500 | [diff] [blame] | 15 | #include "utils/asset_utils.hpp" |
| George Liu | 9516f41 | 2022-09-29 17:21:41 +0800 | [diff] [blame] | 16 | #include "utils/chassis_utils.hpp" |
| Ed Tanous | 177612a | 2025-02-14 15:16:09 -0800 | [diff] [blame] | 17 | #include "utils/dbus_utils.hpp" |
| Myung Bae | 1da1ff5 | 2024-08-20 11:34:59 -0500 | [diff] [blame] | 18 | #include "utils/json_utils.hpp" |
| George Liu | 9516f41 | 2022-09-29 17:21:41 +0800 | [diff] [blame] | 19 | |
| Ed Tanous | d785720 | 2025-01-28 15:32:26 -0800 | [diff] [blame] | 20 | #include <asm-generic/errno.h> |
| 21 | |
| 22 | #include <boost/beast/http/field.hpp> |
| 23 | #include <boost/beast/http/verb.hpp> |
| Albert Zhang | 9f1ae5a | 2021-06-10 14:41:48 +0800 | [diff] [blame] | 24 | #include <boost/system/error_code.hpp> |
| George Liu | 9516f41 | 2022-09-29 17:21:41 +0800 | [diff] [blame] | 25 | #include <boost/url/format.hpp> |
| Ed Tanous | d785720 | 2025-01-28 15:32:26 -0800 | [diff] [blame] | 26 | #include <nlohmann/json.hpp> |
| 27 | #include <sdbusplus/unpack_properties.hpp> |
| George Liu | 9516f41 | 2022-09-29 17:21:41 +0800 | [diff] [blame] | 28 | |
| Ed Tanous | d785720 | 2025-01-28 15:32:26 -0800 | [diff] [blame] | 29 | #include <array> |
| George Liu | 9516f41 | 2022-09-29 17:21:41 +0800 | [diff] [blame] | 30 | #include <functional> |
| 31 | #include <memory> |
| 32 | #include <optional> |
| 33 | #include <string> |
| 34 | #include <string_view> |
| Ed Tanous | d785720 | 2025-01-28 15:32:26 -0800 | [diff] [blame] | 35 | #include <utility> |
| George Liu | 9516f41 | 2022-09-29 17:21:41 +0800 | [diff] [blame] | 36 | |
| 37 | namespace redfish |
| 38 | { |
| 39 | constexpr std::array<std::string_view, 1> fanInterface = { |
| 40 | "xyz.openbmc_project.Inventory.Item.Fan"}; |
| 41 | |
| Patrick Williams | 504af5a | 2025-02-03 14:29:03 -0500 | [diff] [blame] | 42 | inline void updateFanList( |
| 43 | const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, |
| 44 | const std::string& chassisId, |
| 45 | const dbus::utility::MapperGetSubTreePathsResponse& fanPaths) |
| George Liu | 9516f41 | 2022-09-29 17:21:41 +0800 | [diff] [blame] | 46 | { |
| 47 | nlohmann::json& fanList = asyncResp->res.jsonValue["Members"]; |
| 48 | for (const std::string& fanPath : fanPaths) |
| 49 | { |
| 50 | std::string fanName = |
| 51 | sdbusplus::message::object_path(fanPath).filename(); |
| 52 | if (fanName.empty()) |
| 53 | { |
| 54 | continue; |
| 55 | } |
| 56 | |
| 57 | nlohmann::json item = nlohmann::json::object(); |
| 58 | item["@odata.id"] = boost::urls::format( |
| 59 | "/redfish/v1/Chassis/{}/ThermalSubsystem/Fans/{}", chassisId, |
| 60 | fanName); |
| 61 | |
| 62 | fanList.emplace_back(std::move(item)); |
| 63 | } |
| 64 | asyncResp->res.jsonValue["Members@odata.count"] = fanList.size(); |
| 65 | } |
| 66 | |
| 67 | inline void getFanPaths( |
| 68 | const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, |
| Ed Tanous | d547d8d | 2024-03-16 18:04:41 -0700 | [diff] [blame] | 69 | const std::string& validChassisPath, |
| George Liu | 9516f41 | 2022-09-29 17:21:41 +0800 | [diff] [blame] | 70 | const std::function<void(const dbus::utility::MapperGetSubTreePathsResponse& |
| 71 | fanPaths)>& callback) |
| 72 | { |
| Ed Tanous | d547d8d | 2024-03-16 18:04:41 -0700 | [diff] [blame] | 73 | sdbusplus::message::object_path endpointPath{validChassisPath}; |
| George Liu | 9516f41 | 2022-09-29 17:21:41 +0800 | [diff] [blame] | 74 | endpointPath /= "cooled_by"; |
| 75 | |
| 76 | dbus::utility::getAssociatedSubTreePaths( |
| 77 | endpointPath, |
| 78 | sdbusplus::message::object_path("/xyz/openbmc_project/inventory"), 0, |
| 79 | fanInterface, |
| 80 | [asyncResp, callback]( |
| 81 | const boost::system::error_code& ec, |
| 82 | const dbus::utility::MapperGetSubTreePathsResponse& subtreePaths) { |
| Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 83 | if (ec) |
| George Liu | 9516f41 | 2022-09-29 17:21:41 +0800 | [diff] [blame] | 84 | { |
| Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 85 | if (ec.value() != EBADR) |
| 86 | { |
| 87 | BMCWEB_LOG_ERROR( |
| 88 | "DBUS response error for getAssociatedSubTreePaths {}", |
| 89 | ec.value()); |
| 90 | messages::internalError(asyncResp->res); |
| 91 | } |
| 92 | return; |
| George Liu | 9516f41 | 2022-09-29 17:21:41 +0800 | [diff] [blame] | 93 | } |
| Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 94 | callback(subtreePaths); |
| 95 | }); |
| George Liu | 9516f41 | 2022-09-29 17:21:41 +0800 | [diff] [blame] | 96 | } |
| 97 | |
| 98 | inline void doFanCollection(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, |
| 99 | const std::string& chassisId, |
| 100 | const std::optional<std::string>& validChassisPath) |
| 101 | { |
| 102 | if (!validChassisPath) |
| 103 | { |
| 104 | messages::resourceNotFound(asyncResp->res, "Chassis", chassisId); |
| 105 | return; |
| 106 | } |
| 107 | |
| 108 | asyncResp->res.addHeader( |
| 109 | boost::beast::http::field::link, |
| 110 | "</redfish/v1/JsonSchemas/FanCollection/FanCollection.json>; rel=describedby"); |
| 111 | asyncResp->res.jsonValue["@odata.type"] = "#FanCollection.FanCollection"; |
| 112 | asyncResp->res.jsonValue["@odata.id"] = boost::urls::format( |
| 113 | "/redfish/v1/Chassis/{}/ThermalSubsystem/Fans", chassisId); |
| 114 | asyncResp->res.jsonValue["Name"] = "Fan Collection"; |
| 115 | asyncResp->res.jsonValue["Description"] = |
| 116 | "The collection of Fan resource instances " + chassisId; |
| 117 | asyncResp->res.jsonValue["Members"] = nlohmann::json::array(); |
| 118 | asyncResp->res.jsonValue["Members@odata.count"] = 0; |
| 119 | |
| Ed Tanous | d547d8d | 2024-03-16 18:04:41 -0700 | [diff] [blame] | 120 | getFanPaths(asyncResp, *validChassisPath, |
| George Liu | 9516f41 | 2022-09-29 17:21:41 +0800 | [diff] [blame] | 121 | std::bind_front(updateFanList, asyncResp, chassisId)); |
| 122 | } |
| 123 | |
| Patrick Williams | 504af5a | 2025-02-03 14:29:03 -0500 | [diff] [blame] | 124 | inline void handleFanCollectionHead( |
| 125 | App& app, const crow::Request& req, |
| 126 | const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, |
| 127 | const std::string& chassisId) |
| George Liu | 9516f41 | 2022-09-29 17:21:41 +0800 | [diff] [blame] | 128 | { |
| 129 | if (!redfish::setUpRedfishRoute(app, req, asyncResp)) |
| 130 | { |
| 131 | return; |
| 132 | } |
| 133 | |
| 134 | redfish::chassis_utils::getValidChassisPath( |
| 135 | asyncResp, chassisId, |
| 136 | [asyncResp, |
| 137 | chassisId](const std::optional<std::string>& validChassisPath) { |
| Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 138 | if (!validChassisPath) |
| 139 | { |
| 140 | messages::resourceNotFound(asyncResp->res, "Chassis", |
| 141 | chassisId); |
| 142 | return; |
| 143 | } |
| 144 | asyncResp->res.addHeader( |
| 145 | boost::beast::http::field::link, |
| 146 | "</redfish/v1/JsonSchemas/FanCollection/FanCollection.json>; rel=describedby"); |
| 147 | }); |
| George Liu | 9516f41 | 2022-09-29 17:21:41 +0800 | [diff] [blame] | 148 | } |
| 149 | |
| Patrick Williams | 504af5a | 2025-02-03 14:29:03 -0500 | [diff] [blame] | 150 | inline void handleFanCollectionGet( |
| 151 | App& app, const crow::Request& req, |
| 152 | const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, |
| 153 | const std::string& chassisId) |
| George Liu | 9516f41 | 2022-09-29 17:21:41 +0800 | [diff] [blame] | 154 | { |
| 155 | if (!redfish::setUpRedfishRoute(app, req, asyncResp)) |
| 156 | { |
| 157 | return; |
| 158 | } |
| 159 | |
| 160 | redfish::chassis_utils::getValidChassisPath( |
| 161 | asyncResp, chassisId, |
| 162 | std::bind_front(doFanCollection, asyncResp, chassisId)); |
| 163 | } |
| 164 | |
| George Liu | e4e5423 | 2022-09-30 09:08:11 +0800 | [diff] [blame] | 165 | inline bool checkFanId(const std::string& fanPath, const std::string& fanId) |
| 166 | { |
| 167 | std::string fanName = sdbusplus::message::object_path(fanPath).filename(); |
| 168 | |
| 169 | return !(fanName.empty() || fanName != fanId); |
| 170 | } |
| 171 | |
| Ed Tanous | 4ff0f1f | 2024-09-04 17:27:37 -0700 | [diff] [blame] | 172 | inline void handleFanPath( |
| George Liu | e4e5423 | 2022-09-30 09:08:11 +0800 | [diff] [blame] | 173 | const std::string& fanId, |
| 174 | const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, |
| 175 | const dbus::utility::MapperGetSubTreePathsResponse& fanPaths, |
| 176 | const std::function<void(const std::string& fanPath, |
| 177 | const std::string& service)>& callback) |
| 178 | { |
| 179 | for (const auto& fanPath : fanPaths) |
| 180 | { |
| 181 | if (!checkFanId(fanPath, fanId)) |
| 182 | { |
| 183 | continue; |
| 184 | } |
| 185 | dbus::utility::getDbusObject( |
| 186 | fanPath, fanInterface, |
| 187 | [fanPath, asyncResp, |
| 188 | callback](const boost::system::error_code& ec, |
| 189 | const dbus::utility::MapperGetObject& object) { |
| Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 190 | if (ec || object.empty()) |
| 191 | { |
| 192 | BMCWEB_LOG_ERROR("DBUS response error on getDbusObject {}", |
| 193 | ec.value()); |
| 194 | messages::internalError(asyncResp->res); |
| 195 | return; |
| 196 | } |
| 197 | callback(fanPath, object.begin()->first); |
| 198 | }); |
| George Liu | e4e5423 | 2022-09-30 09:08:11 +0800 | [diff] [blame] | 199 | |
| 200 | return; |
| 201 | } |
| Ed Tanous | 62598e3 | 2023-07-17 17:06:25 -0700 | [diff] [blame] | 202 | BMCWEB_LOG_WARNING("Fan not found {}", fanId); |
| George Liu | e4e5423 | 2022-09-30 09:08:11 +0800 | [diff] [blame] | 203 | messages::resourceNotFound(asyncResp->res, "Fan", fanId); |
| 204 | } |
| 205 | |
| Myung Bae | 1da1ff5 | 2024-08-20 11:34:59 -0500 | [diff] [blame] | 206 | inline void getValidFanObject( |
| George Liu | e4e5423 | 2022-09-30 09:08:11 +0800 | [diff] [blame] | 207 | const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, |
| 208 | const std::string& validChassisPath, const std::string& fanId, |
| 209 | const std::function<void(const std::string& fanPath, |
| 210 | const std::string& service)>& callback) |
| 211 | { |
| 212 | getFanPaths( |
| 213 | asyncResp, validChassisPath, |
| 214 | [fanId, asyncResp, callback]( |
| 215 | const dbus::utility::MapperGetSubTreePathsResponse& fanPaths) { |
| Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 216 | handleFanPath(fanId, asyncResp, fanPaths, callback); |
| 217 | }); |
| George Liu | e4e5423 | 2022-09-30 09:08:11 +0800 | [diff] [blame] | 218 | } |
| 219 | |
| 220 | inline void addFanCommonProperties(crow::Response& resp, |
| 221 | const std::string& chassisId, |
| 222 | const std::string& fanId) |
| 223 | { |
| 224 | resp.addHeader(boost::beast::http::field::link, |
| 225 | "</redfish/v1/JsonSchemas/Fan/Fan.json>; rel=describedby"); |
| 226 | resp.jsonValue["@odata.type"] = "#Fan.v1_3_0.Fan"; |
| 227 | resp.jsonValue["Name"] = "Fan"; |
| 228 | resp.jsonValue["Id"] = fanId; |
| 229 | resp.jsonValue["@odata.id"] = boost::urls::format( |
| 230 | "/redfish/v1/Chassis/{}/ThermalSubsystem/Fans/{}", chassisId, fanId); |
| Ed Tanous | 539d8c6 | 2024-06-19 14:38:27 -0700 | [diff] [blame] | 231 | resp.jsonValue["Status"]["State"] = resource::State::Enabled; |
| 232 | resp.jsonValue["Status"]["Health"] = resource::Health::OK; |
| Albert Zhang | 9f1ae5a | 2021-06-10 14:41:48 +0800 | [diff] [blame] | 233 | } |
| 234 | |
| 235 | inline void getFanHealth(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, |
| 236 | const std::string& fanPath, const std::string& service) |
| 237 | { |
| Ed Tanous | deae6a7 | 2024-11-11 21:58:57 -0800 | [diff] [blame] | 238 | dbus::utility::getProperty<bool>( |
| 239 | service, fanPath, |
| Albert Zhang | 9f1ae5a | 2021-06-10 14:41:48 +0800 | [diff] [blame] | 240 | "xyz.openbmc_project.State.Decorator.OperationalStatus", "Functional", |
| 241 | [asyncResp](const boost::system::error_code& ec, const bool value) { |
| Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 242 | if (ec) |
| Albert Zhang | 9f1ae5a | 2021-06-10 14:41:48 +0800 | [diff] [blame] | 243 | { |
| Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 244 | if (ec.value() != EBADR) |
| 245 | { |
| 246 | BMCWEB_LOG_ERROR("DBUS response error for Health {}", |
| 247 | ec.value()); |
| 248 | messages::internalError(asyncResp->res); |
| 249 | } |
| 250 | return; |
| Albert Zhang | 9f1ae5a | 2021-06-10 14:41:48 +0800 | [diff] [blame] | 251 | } |
| Albert Zhang | 9f1ae5a | 2021-06-10 14:41:48 +0800 | [diff] [blame] | 252 | |
| Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 253 | if (!value) |
| 254 | { |
| 255 | asyncResp->res.jsonValue["Status"]["Health"] = |
| 256 | resource::Health::Critical; |
| 257 | } |
| 258 | }); |
| Albert Zhang | 9f1ae5a | 2021-06-10 14:41:48 +0800 | [diff] [blame] | 259 | } |
| 260 | |
| 261 | inline void getFanState(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, |
| 262 | const std::string& fanPath, const std::string& service) |
| 263 | { |
| Ed Tanous | deae6a7 | 2024-11-11 21:58:57 -0800 | [diff] [blame] | 264 | dbus::utility::getProperty<bool>( |
| 265 | service, fanPath, "xyz.openbmc_project.Inventory.Item", "Present", |
| Albert Zhang | 9f1ae5a | 2021-06-10 14:41:48 +0800 | [diff] [blame] | 266 | [asyncResp](const boost::system::error_code& ec, const bool value) { |
| Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 267 | if (ec) |
| Albert Zhang | 9f1ae5a | 2021-06-10 14:41:48 +0800 | [diff] [blame] | 268 | { |
| Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 269 | if (ec.value() != EBADR) |
| 270 | { |
| 271 | BMCWEB_LOG_ERROR("DBUS response error for State {}", |
| 272 | ec.value()); |
| 273 | messages::internalError(asyncResp->res); |
| 274 | } |
| 275 | return; |
| Albert Zhang | 9f1ae5a | 2021-06-10 14:41:48 +0800 | [diff] [blame] | 276 | } |
| Albert Zhang | 9f1ae5a | 2021-06-10 14:41:48 +0800 | [diff] [blame] | 277 | |
| Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 278 | if (!value) |
| 279 | { |
| 280 | asyncResp->res.jsonValue["Status"]["State"] = |
| 281 | resource::State::Absent; |
| 282 | } |
| 283 | }); |
| George Liu | e4e5423 | 2022-09-30 09:08:11 +0800 | [diff] [blame] | 284 | } |
| 285 | |
| Ed Tanous | fc3edfd | 2023-07-20 12:41:30 -0700 | [diff] [blame] | 286 | inline void getFanLocation(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, |
| George Liu | 4a2e485 | 2022-10-04 16:13:44 +0800 | [diff] [blame] | 287 | const std::string& fanPath, |
| 288 | const std::string& service) |
| 289 | { |
| Ed Tanous | deae6a7 | 2024-11-11 21:58:57 -0800 | [diff] [blame] | 290 | dbus::utility::getProperty<std::string>( |
| 291 | service, fanPath, |
| George Liu | 4a2e485 | 2022-10-04 16:13:44 +0800 | [diff] [blame] | 292 | "xyz.openbmc_project.Inventory.Decorator.LocationCode", "LocationCode", |
| Ed Tanous | fc3edfd | 2023-07-20 12:41:30 -0700 | [diff] [blame] | 293 | [asyncResp](const boost::system::error_code& ec, |
| 294 | const std::string& property) { |
| Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 295 | if (ec) |
| George Liu | 4a2e485 | 2022-10-04 16:13:44 +0800 | [diff] [blame] | 296 | { |
| Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 297 | if (ec.value() != EBADR) |
| 298 | { |
| 299 | BMCWEB_LOG_ERROR("DBUS response error for Location{}", |
| 300 | ec.value()); |
| 301 | messages::internalError(asyncResp->res); |
| 302 | } |
| 303 | return; |
| George Liu | 4a2e485 | 2022-10-04 16:13:44 +0800 | [diff] [blame] | 304 | } |
| Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 305 | asyncResp->res |
| 306 | .jsonValue["Location"]["PartLocation"]["ServiceLabel"] = |
| 307 | property; |
| 308 | }); |
| George Liu | 4a2e485 | 2022-10-04 16:13:44 +0800 | [diff] [blame] | 309 | } |
| 310 | |
| Myung Bae | 1da1ff5 | 2024-08-20 11:34:59 -0500 | [diff] [blame] | 311 | inline void afterGetValidFanObject( |
| Patrick Williams | 504af5a | 2025-02-03 14:29:03 -0500 | [diff] [blame] | 312 | const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, |
| 313 | const std::string& chassisId, const std::string& fanId, |
| 314 | const std::string& fanPath, const std::string& service) |
| George Liu | e4e5423 | 2022-09-30 09:08:11 +0800 | [diff] [blame] | 315 | { |
| George Liu | e4e5423 | 2022-09-30 09:08:11 +0800 | [diff] [blame] | 316 | addFanCommonProperties(asyncResp->res, chassisId, fanId); |
| Albert Zhang | 9f1ae5a | 2021-06-10 14:41:48 +0800 | [diff] [blame] | 317 | getFanState(asyncResp, fanPath, service); |
| 318 | getFanHealth(asyncResp, fanPath, service); |
| Myung Bae | f7e62c1 | 2025-09-07 14:02:08 -0500 | [diff] [blame] | 319 | asset_utils::getAssetInfo(asyncResp, service, fanPath, ""_json_pointer, |
| 320 | true); |
| George Liu | 4a2e485 | 2022-10-04 16:13:44 +0800 | [diff] [blame] | 321 | getFanLocation(asyncResp, fanPath, service); |
| Myung Bae | 1da1ff5 | 2024-08-20 11:34:59 -0500 | [diff] [blame] | 322 | getLocationIndicatorActive(asyncResp, fanPath); |
| George Liu | e4e5423 | 2022-09-30 09:08:11 +0800 | [diff] [blame] | 323 | } |
| 324 | |
| 325 | inline void doFanGet(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, |
| 326 | const std::string& chassisId, const std::string& fanId, |
| 327 | const std::optional<std::string>& validChassisPath) |
| 328 | { |
| 329 | if (!validChassisPath) |
| 330 | { |
| 331 | messages::resourceNotFound(asyncResp->res, "Chassis", chassisId); |
| 332 | return; |
| 333 | } |
| 334 | |
| Myung Bae | 1da1ff5 | 2024-08-20 11:34:59 -0500 | [diff] [blame] | 335 | getValidFanObject( |
| George Liu | e4e5423 | 2022-09-30 09:08:11 +0800 | [diff] [blame] | 336 | asyncResp, *validChassisPath, fanId, |
| Myung Bae | 1da1ff5 | 2024-08-20 11:34:59 -0500 | [diff] [blame] | 337 | std::bind_front(afterGetValidFanObject, asyncResp, chassisId, fanId)); |
| George Liu | e4e5423 | 2022-09-30 09:08:11 +0800 | [diff] [blame] | 338 | } |
| 339 | |
| 340 | inline void handleFanHead(App& app, const crow::Request& req, |
| 341 | const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, |
| 342 | const std::string& chassisId, |
| 343 | const std::string& fanId) |
| 344 | { |
| 345 | if (!redfish::setUpRedfishRoute(app, req, asyncResp)) |
| 346 | { |
| 347 | return; |
| 348 | } |
| 349 | |
| 350 | redfish::chassis_utils::getValidChassisPath( |
| 351 | asyncResp, chassisId, |
| 352 | [asyncResp, chassisId, |
| 353 | fanId](const std::optional<std::string>& validChassisPath) { |
| Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 354 | if (!validChassisPath) |
| 355 | { |
| 356 | messages::resourceNotFound(asyncResp->res, "Chassis", |
| 357 | chassisId); |
| 358 | return; |
| 359 | } |
| Myung Bae | 1da1ff5 | 2024-08-20 11:34:59 -0500 | [diff] [blame] | 360 | getValidFanObject( |
| Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 361 | asyncResp, *validChassisPath, fanId, |
| 362 | [asyncResp](const std::string&, const std::string&) { |
| 363 | asyncResp->res.addHeader( |
| 364 | boost::beast::http::field::link, |
| 365 | "</redfish/v1/JsonSchemas/Fan/Fan.json>; rel=describedby"); |
| 366 | }); |
| George Liu | e4e5423 | 2022-09-30 09:08:11 +0800 | [diff] [blame] | 367 | }); |
| George Liu | e4e5423 | 2022-09-30 09:08:11 +0800 | [diff] [blame] | 368 | } |
| 369 | |
| 370 | inline void handleFanGet(App& app, const crow::Request& req, |
| 371 | const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, |
| 372 | const std::string& chassisId, const std::string& fanId) |
| 373 | { |
| 374 | if (!redfish::setUpRedfishRoute(app, req, asyncResp)) |
| 375 | { |
| 376 | return; |
| 377 | } |
| 378 | |
| 379 | redfish::chassis_utils::getValidChassisPath( |
| 380 | asyncResp, chassisId, |
| 381 | std::bind_front(doFanGet, asyncResp, chassisId, fanId)); |
| 382 | } |
| 383 | |
| Myung Bae | 1da1ff5 | 2024-08-20 11:34:59 -0500 | [diff] [blame] | 384 | inline void handleSetFanPathById( |
| 385 | const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, |
| 386 | const std::string& chassisId, const std::string& fanId, |
| 387 | bool locationIndicatorActive, const boost::system::error_code& ec, |
| 388 | const dbus::utility::MapperGetSubTreePathsResponse& fanPaths) |
| 389 | { |
| 390 | if (ec) |
| 391 | { |
| 392 | if (ec.value() == boost::system::errc::io_error) |
| 393 | { |
| 394 | BMCWEB_LOG_WARNING("Chassis {} not found", chassisId); |
| 395 | messages::resourceNotFound(asyncResp->res, "Chassis", chassisId); |
| 396 | return; |
| 397 | } |
| 398 | |
| 399 | BMCWEB_LOG_ERROR("DBUS response error {}", ec.value()); |
| 400 | messages::internalError(asyncResp->res); |
| 401 | return; |
| 402 | } |
| 403 | |
| 404 | for (const auto& fanPath : fanPaths) |
| 405 | { |
| 406 | if (checkFanId(fanPath, fanId)) |
| 407 | { |
| 408 | setLocationIndicatorActive(asyncResp, fanPath, |
| 409 | locationIndicatorActive); |
| 410 | return; |
| 411 | } |
| 412 | } |
| 413 | BMCWEB_LOG_WARNING("Fan {} not found", fanId); |
| 414 | messages::resourceNotFound(asyncResp->res, "Fan", fanId); |
| 415 | } |
| 416 | |
| 417 | inline void handleFanPatch(App& app, const crow::Request& req, |
| 418 | const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, |
| 419 | const std::string& chassisId, |
| 420 | const std::string& fanId) |
| 421 | { |
| 422 | if (!redfish::setUpRedfishRoute(app, req, asyncResp)) |
| 423 | { |
| 424 | return; |
| 425 | } |
| 426 | |
| 427 | std::optional<bool> locationIndicatorActive; |
| 428 | if (!json_util::readJsonPatch(req, asyncResp->res, |
| 429 | "LocationIndicatorActive", |
| 430 | locationIndicatorActive)) |
| 431 | { |
| 432 | return; |
| 433 | } |
| 434 | |
| 435 | if (locationIndicatorActive) |
| 436 | { |
| 437 | dbus::utility::getAssociatedSubTreePathsById( |
| 438 | chassisId, "/xyz/openbmc_project/inventory", chassisInterfaces, |
| 439 | "cooled_by", fanInterface, |
| 440 | [asyncResp, chassisId, fanId, locationIndicatorActive]( |
| 441 | const boost::system::error_code& ec, |
| 442 | const dbus::utility::MapperGetSubTreePathsResponse& |
| 443 | subtreePaths) { |
| 444 | handleSetFanPathById(asyncResp, chassisId, fanId, |
| 445 | *locationIndicatorActive, ec, |
| 446 | subtreePaths); |
| 447 | }); |
| 448 | } |
| 449 | } |
| 450 | |
| George Liu | e4e5423 | 2022-09-30 09:08:11 +0800 | [diff] [blame] | 451 | inline void requestRoutesFan(App& app) |
| 452 | { |
| Christopher Meis | 99353a9 | 2025-09-26 08:54:40 +0200 | [diff] [blame] | 453 | BMCWEB_ROUTE(app, "/redfish/v1/Chassis/<str>/ThermalSubsystem/Fans/") |
| 454 | .privileges(redfish::privileges::headFanCollection) |
| 455 | .methods(boost::beast::http::verb::head)( |
| 456 | std::bind_front(handleFanCollectionHead, std::ref(app))); |
| 457 | |
| 458 | BMCWEB_ROUTE(app, "/redfish/v1/Chassis/<str>/ThermalSubsystem/Fans/") |
| 459 | .privileges(redfish::privileges::getFanCollection) |
| 460 | .methods(boost::beast::http::verb::get)( |
| 461 | std::bind_front(handleFanCollectionGet, std::ref(app))); |
| 462 | |
| George Liu | e4e5423 | 2022-09-30 09:08:11 +0800 | [diff] [blame] | 463 | BMCWEB_ROUTE(app, "/redfish/v1/Chassis/<str>/ThermalSubsystem/Fans/<str>/") |
| 464 | .privileges(redfish::privileges::headFan) |
| 465 | .methods(boost::beast::http::verb::head)( |
| 466 | std::bind_front(handleFanHead, std::ref(app))); |
| 467 | |
| 468 | BMCWEB_ROUTE(app, "/redfish/v1/Chassis/<str>/ThermalSubsystem/Fans/<str>/") |
| 469 | .privileges(redfish::privileges::getFan) |
| 470 | .methods(boost::beast::http::verb::get)( |
| 471 | std::bind_front(handleFanGet, std::ref(app))); |
| Myung Bae | 1da1ff5 | 2024-08-20 11:34:59 -0500 | [diff] [blame] | 472 | |
| 473 | BMCWEB_ROUTE(app, "/redfish/v1/Chassis/<str>/ThermalSubsystem/Fans/<str>/") |
| 474 | .privileges(redfish::privileges::patchFan) |
| 475 | .methods(boost::beast::http::verb::patch)( |
| 476 | std::bind_front(handleFanPatch, std::ref(app))); |
| George Liu | e4e5423 | 2022-09-30 09:08:11 +0800 | [diff] [blame] | 477 | } |
| 478 | |
| George Liu | 9516f41 | 2022-09-29 17:21:41 +0800 | [diff] [blame] | 479 | } // namespace redfish |