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 |
| 3 | // SPDX-FileCopyrightText: Copyright 2018 Intel Corporation |
Jennifer Lee | 729dae7 | 2018-04-24 15:59:34 -0700 | [diff] [blame] | 4 | #pragma once |
| 5 | |
Tejas Patil | d61e519 | 2021-06-04 15:49:35 +0530 | [diff] [blame] | 6 | #include "bmcweb_config.h" |
| 7 | |
Ed Tanous | 3ccb3ad | 2023-01-13 17:40:03 -0800 | [diff] [blame] | 8 | #include "app.hpp" |
| 9 | #include "dbus_utility.hpp" |
Ed Tanous | 5b90429 | 2024-04-16 11:10:17 -0700 | [diff] [blame] | 10 | #include "error_messages.hpp" |
Ed Tanous | 757178a | 2024-04-03 14:32:38 -0700 | [diff] [blame] | 11 | #include "generated/enums/update_service.hpp" |
George Liu | 0ed80c8 | 2020-05-12 16:06:27 +0800 | [diff] [blame] | 12 | #include "multipart_parser.hpp" |
Ed Tanous | 2c6ffdb | 2023-06-28 11:28:38 -0700 | [diff] [blame] | 13 | #include "ossl_random.hpp" |
Ed Tanous | 3ccb3ad | 2023-01-13 17:40:03 -0800 | [diff] [blame] | 14 | #include "query.hpp" |
| 15 | #include "registries/privilege_registry.hpp" |
Ed Tanous | a8e884f | 2023-01-13 17:40:03 -0800 | [diff] [blame] | 16 | #include "task.hpp" |
Ed Tanous | 5b90429 | 2024-04-16 11:10:17 -0700 | [diff] [blame] | 17 | #include "task_messages.hpp" |
John Edward Broadbent | 08d81ad | 2022-05-17 20:00:23 -0700 | [diff] [blame] | 18 | #include "utils/collection.hpp" |
Ed Tanous | 3ccb3ad | 2023-01-13 17:40:03 -0800 | [diff] [blame] | 19 | #include "utils/dbus_utils.hpp" |
Ed Tanous | 5b90429 | 2024-04-16 11:10:17 -0700 | [diff] [blame] | 20 | #include "utils/json_utils.hpp" |
Ed Tanous | 3ccb3ad | 2023-01-13 17:40:03 -0800 | [diff] [blame] | 21 | #include "utils/sw_utils.hpp" |
| 22 | |
Jagpal Singh Gill | de0c960 | 2024-04-29 17:30:21 -0700 | [diff] [blame] | 23 | #include <sys/mman.h> |
| 24 | |
George Liu | e99073f | 2022-12-09 11:06:16 +0800 | [diff] [blame] | 25 | #include <boost/system/error_code.hpp> |
Ed Tanous | ef4c65b | 2023-04-24 15:28:50 -0700 | [diff] [blame] | 26 | #include <boost/url/format.hpp> |
Jonathan Doman | 1e1e598 | 2021-06-11 09:36:17 -0700 | [diff] [blame] | 27 | #include <sdbusplus/asio/property.hpp> |
Ed Tanous | 3ccb3ad | 2023-01-13 17:40:03 -0800 | [diff] [blame] | 28 | #include <sdbusplus/bus/match.hpp> |
Krzysztof Grobelny | d1bde9e | 2022-09-07 10:40:51 +0200 | [diff] [blame] | 29 | #include <sdbusplus/unpack_properties.hpp> |
Gunnar Mills | 1214b7e | 2020-06-04 10:11:30 -0500 | [diff] [blame] | 30 | |
George Liu | 2b73119 | 2023-01-11 16:27:13 +0800 | [diff] [blame] | 31 | #include <array> |
Jagpal Singh Gill | de0c960 | 2024-04-29 17:30:21 -0700 | [diff] [blame] | 32 | #include <cstddef> |
George Liu | 0ed80c8 | 2020-05-12 16:06:27 +0800 | [diff] [blame] | 33 | #include <filesystem> |
Jagpal Singh Gill | c71b6c9 | 2024-04-29 16:50:53 -0700 | [diff] [blame] | 34 | #include <functional> |
Jagpal Singh Gill | de0c960 | 2024-04-29 17:30:21 -0700 | [diff] [blame] | 35 | #include <iterator> |
Jagpal Singh Gill | ef93eab | 2024-04-17 16:06:14 -0700 | [diff] [blame] | 36 | #include <memory> |
Ed Tanous | 7cb59f6 | 2022-05-05 11:48:31 -0700 | [diff] [blame] | 37 | #include <optional> |
| 38 | #include <string> |
George Liu | 2b73119 | 2023-01-11 16:27:13 +0800 | [diff] [blame] | 39 | #include <string_view> |
Jagpal Singh Gill | de0c960 | 2024-04-29 17:30:21 -0700 | [diff] [blame] | 40 | #include <unordered_map> |
Jagpal Singh Gill | ef93eab | 2024-04-17 16:06:14 -0700 | [diff] [blame] | 41 | #include <vector> |
George Liu | 2b73119 | 2023-01-11 16:27:13 +0800 | [diff] [blame] | 42 | |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 43 | namespace redfish |
| 44 | { |
Ed Tanous | 27826b5 | 2018-10-29 11:40:58 -0700 | [diff] [blame] | 45 | |
Andrew Geissler | 0e7de46 | 2019-03-04 19:11:54 -0600 | [diff] [blame] | 46 | // Match signals added on software path |
Ed Tanous | cf9e417 | 2022-12-21 09:30:16 -0800 | [diff] [blame] | 47 | // NOLINTNEXTLINE(cppcoreguidelines-avoid-non-const-global-variables) |
Patrick Williams | 59d494e | 2022-07-22 19:26:55 -0500 | [diff] [blame] | 48 | static std::unique_ptr<sdbusplus::bus::match_t> fwUpdateMatcher; |
Ed Tanous | cf9e417 | 2022-12-21 09:30:16 -0800 | [diff] [blame] | 49 | // NOLINTNEXTLINE(cppcoreguidelines-avoid-non-const-global-variables) |
Patrick Williams | 59d494e | 2022-07-22 19:26:55 -0500 | [diff] [blame] | 50 | static std::unique_ptr<sdbusplus::bus::match_t> fwUpdateErrorMatcher; |
Andrew Geissler | 0e7de46 | 2019-03-04 19:11:54 -0600 | [diff] [blame] | 51 | // Only allow one update at a time |
Ed Tanous | cf9e417 | 2022-12-21 09:30:16 -0800 | [diff] [blame] | 52 | // NOLINTNEXTLINE(cppcoreguidelines-avoid-non-const-global-variables) |
Andrew Geissler | 0e7de46 | 2019-03-04 19:11:54 -0600 | [diff] [blame] | 53 | static bool fwUpdateInProgress = false; |
Andrew Geissler | 86adcd6 | 2019-04-18 10:58:05 -0500 | [diff] [blame] | 54 | // Timer for software available |
Ed Tanous | cf9e417 | 2022-12-21 09:30:16 -0800 | [diff] [blame] | 55 | // NOLINTNEXTLINE(cppcoreguidelines-avoid-non-const-global-variables) |
Ed Tanous | 271584a | 2019-07-09 16:24:22 -0700 | [diff] [blame] | 56 | static std::unique_ptr<boost::asio::steady_timer> fwAvailableTimer; |
Andrew Geissler | 86adcd6 | 2019-04-18 10:58:05 -0500 | [diff] [blame] | 57 | |
Jagpal Singh Gill | de0c960 | 2024-04-29 17:30:21 -0700 | [diff] [blame] | 58 | struct MemoryFileDescriptor |
| 59 | { |
| 60 | int fd = -1; |
| 61 | |
| 62 | explicit MemoryFileDescriptor(const std::string& filename) : |
| 63 | fd(memfd_create(filename.c_str(), 0)) |
| 64 | {} |
| 65 | |
| 66 | MemoryFileDescriptor(const MemoryFileDescriptor&) = default; |
| 67 | MemoryFileDescriptor(MemoryFileDescriptor&& other) noexcept : fd(other.fd) |
| 68 | { |
| 69 | other.fd = -1; |
| 70 | } |
| 71 | MemoryFileDescriptor& operator=(const MemoryFileDescriptor&) = delete; |
| 72 | MemoryFileDescriptor& operator=(MemoryFileDescriptor&&) = default; |
| 73 | |
| 74 | ~MemoryFileDescriptor() |
| 75 | { |
| 76 | if (fd != -1) |
| 77 | { |
| 78 | close(fd); |
| 79 | } |
| 80 | } |
| 81 | |
| 82 | bool rewind() const |
| 83 | { |
| 84 | if (lseek(fd, 0, SEEK_SET) == -1) |
| 85 | { |
| 86 | BMCWEB_LOG_ERROR("Failed to seek to beginning of image memfd"); |
| 87 | return false; |
| 88 | } |
| 89 | return true; |
| 90 | } |
| 91 | }; |
| 92 | |
Ed Tanous | df254f2 | 2024-04-01 13:25:46 -0700 | [diff] [blame] | 93 | inline void cleanUp() |
Andrew Geissler | 86adcd6 | 2019-04-18 10:58:05 -0500 | [diff] [blame] | 94 | { |
| 95 | fwUpdateInProgress = false; |
| 96 | fwUpdateMatcher = nullptr; |
James Feist | 4cde5d9 | 2020-06-11 10:39:55 -0700 | [diff] [blame] | 97 | fwUpdateErrorMatcher = nullptr; |
Andrew Geissler | 86adcd6 | 2019-04-18 10:58:05 -0500 | [diff] [blame] | 98 | } |
Ed Tanous | df254f2 | 2024-04-01 13:25:46 -0700 | [diff] [blame] | 99 | |
| 100 | inline void activateImage(const std::string& objPath, |
| 101 | const std::string& service) |
Andrew Geissler | 86adcd6 | 2019-04-18 10:58:05 -0500 | [diff] [blame] | 102 | { |
Ed Tanous | 62598e3 | 2023-07-17 17:06:25 -0700 | [diff] [blame] | 103 | BMCWEB_LOG_DEBUG("Activate image for {} {}", objPath, service); |
George Liu | 9ae226f | 2023-06-21 17:56:46 +0800 | [diff] [blame] | 104 | sdbusplus::asio::setProperty( |
| 105 | *crow::connections::systemBus, service, objPath, |
| 106 | "xyz.openbmc_project.Software.Activation", "RequestedActivation", |
| 107 | "xyz.openbmc_project.Software.Activation.RequestedActivations.Active", |
Ed Tanous | 8b24275 | 2023-06-27 17:17:13 -0700 | [diff] [blame] | 108 | [](const boost::system::error_code& ec) { |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 109 | if (ec) |
| 110 | { |
| 111 | BMCWEB_LOG_DEBUG("error_code = {}", ec); |
| 112 | BMCWEB_LOG_DEBUG("error msg = {}", ec.message()); |
| 113 | } |
| 114 | }); |
Andrew Geissler | 86adcd6 | 2019-04-18 10:58:05 -0500 | [diff] [blame] | 115 | } |
Andrew Geissler | 0554c98 | 2019-04-23 14:40:12 -0500 | [diff] [blame] | 116 | |
Jagpal Singh Gill | c71b6c9 | 2024-04-29 16:50:53 -0700 | [diff] [blame] | 117 | inline bool handleCreateTask(const boost::system::error_code& ec2, |
| 118 | sdbusplus::message_t& msg, |
| 119 | const std::shared_ptr<task::TaskData>& taskData) |
| 120 | { |
| 121 | if (ec2) |
| 122 | { |
| 123 | return task::completed; |
| 124 | } |
| 125 | |
| 126 | std::string iface; |
| 127 | dbus::utility::DBusPropertiesMap values; |
| 128 | |
| 129 | std::string index = std::to_string(taskData->index); |
| 130 | msg.read(iface, values); |
| 131 | |
| 132 | if (iface == "xyz.openbmc_project.Software.Activation") |
| 133 | { |
| 134 | const std::string* state = nullptr; |
| 135 | for (const auto& property : values) |
| 136 | { |
| 137 | if (property.first == "Activation") |
| 138 | { |
| 139 | state = std::get_if<std::string>(&property.second); |
| 140 | if (state == nullptr) |
| 141 | { |
| 142 | taskData->messages.emplace_back(messages::internalError()); |
| 143 | return task::completed; |
| 144 | } |
| 145 | } |
| 146 | } |
| 147 | |
| 148 | if (state == nullptr) |
| 149 | { |
| 150 | return !task::completed; |
| 151 | } |
| 152 | |
| 153 | if (state->ends_with("Invalid") || state->ends_with("Failed")) |
| 154 | { |
| 155 | taskData->state = "Exception"; |
| 156 | taskData->status = "Warning"; |
| 157 | taskData->messages.emplace_back(messages::taskAborted(index)); |
| 158 | return task::completed; |
| 159 | } |
| 160 | |
| 161 | if (state->ends_with("Staged")) |
| 162 | { |
| 163 | taskData->state = "Stopping"; |
| 164 | taskData->messages.emplace_back(messages::taskPaused(index)); |
| 165 | |
| 166 | // its staged, set a long timer to |
| 167 | // allow them time to complete the |
| 168 | // update (probably cycle the |
| 169 | // system) if this expires then |
| 170 | // task will be canceled |
| 171 | taskData->extendTimer(std::chrono::hours(5)); |
| 172 | return !task::completed; |
| 173 | } |
| 174 | |
| 175 | if (state->ends_with("Active")) |
| 176 | { |
| 177 | taskData->messages.emplace_back(messages::taskCompletedOK(index)); |
| 178 | taskData->state = "Completed"; |
| 179 | return task::completed; |
| 180 | } |
| 181 | } |
| 182 | else if (iface == "xyz.openbmc_project.Software.ActivationProgress") |
| 183 | { |
| 184 | const uint8_t* progress = nullptr; |
| 185 | for (const auto& property : values) |
| 186 | { |
| 187 | if (property.first == "Progress") |
| 188 | { |
| 189 | progress = std::get_if<uint8_t>(&property.second); |
| 190 | if (progress == nullptr) |
| 191 | { |
| 192 | taskData->messages.emplace_back(messages::internalError()); |
| 193 | return task::completed; |
| 194 | } |
| 195 | } |
| 196 | } |
| 197 | |
| 198 | if (progress == nullptr) |
| 199 | { |
| 200 | return !task::completed; |
| 201 | } |
| 202 | taskData->percentComplete = *progress; |
| 203 | taskData->messages.emplace_back( |
| 204 | messages::taskProgressChanged(index, *progress)); |
| 205 | |
| 206 | // if we're getting status updates it's |
| 207 | // still alive, update timer |
| 208 | taskData->extendTimer(std::chrono::minutes(5)); |
| 209 | } |
| 210 | |
| 211 | // as firmware update often results in a |
| 212 | // reboot, the task may never "complete" |
| 213 | // unless it is an error |
| 214 | |
| 215 | return !task::completed; |
| 216 | } |
| 217 | |
| 218 | inline void createTask(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, |
| 219 | task::Payload&& payload, |
| 220 | const sdbusplus::message::object_path& objPath) |
| 221 | { |
| 222 | std::shared_ptr<task::TaskData> task = task::TaskData::createTask( |
| 223 | std::bind_front(handleCreateTask), |
| 224 | "type='signal',interface='org.freedesktop.DBus.Properties'," |
| 225 | "member='PropertiesChanged',path='" + |
| 226 | objPath.str + "'"); |
| 227 | task->startTimer(std::chrono::minutes(5)); |
| 228 | task->populateResp(asyncResp->res); |
| 229 | task->payload.emplace(std::move(payload)); |
| 230 | } |
| 231 | |
Andrew Geissler | 0554c98 | 2019-04-23 14:40:12 -0500 | [diff] [blame] | 232 | // Note that asyncResp can be either a valid pointer or nullptr. If nullptr |
| 233 | // then no asyncResp updates will occur |
Ed Tanous | 4ff0f1f | 2024-09-04 17:27:37 -0700 | [diff] [blame] | 234 | inline void |
zhanghch05 | 8d1b46d | 2021-04-01 11:18:24 +0800 | [diff] [blame] | 235 | softwareInterfaceAdded(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, |
Patrick Williams | 59d494e | 2022-07-22 19:26:55 -0500 | [diff] [blame] | 236 | sdbusplus::message_t& m, task::Payload&& payload) |
Andrew Geissler | 86adcd6 | 2019-04-18 10:58:05 -0500 | [diff] [blame] | 237 | { |
Michael Shen | 80f79a4 | 2023-08-24 13:41:53 +0000 | [diff] [blame] | 238 | dbus::utility::DBusInterfacesMap interfacesProperties; |
Andrew Geissler | 86adcd6 | 2019-04-18 10:58:05 -0500 | [diff] [blame] | 239 | |
| 240 | sdbusplus::message::object_path objPath; |
| 241 | |
| 242 | m.read(objPath, interfacesProperties); |
| 243 | |
Ed Tanous | 62598e3 | 2023-07-17 17:06:25 -0700 | [diff] [blame] | 244 | BMCWEB_LOG_DEBUG("obj path = {}", objPath.str); |
Ed Tanous | e3eb3d6 | 2022-12-21 11:56:07 -0800 | [diff] [blame] | 245 | for (const auto& interface : interfacesProperties) |
Andrew Geissler | 86adcd6 | 2019-04-18 10:58:05 -0500 | [diff] [blame] | 246 | { |
Ed Tanous | 62598e3 | 2023-07-17 17:06:25 -0700 | [diff] [blame] | 247 | BMCWEB_LOG_DEBUG("interface = {}", interface.first); |
Andrew Geissler | 86adcd6 | 2019-04-18 10:58:05 -0500 | [diff] [blame] | 248 | |
| 249 | if (interface.first == "xyz.openbmc_project.Software.Activation") |
| 250 | { |
Andrew Geissler | 86adcd6 | 2019-04-18 10:58:05 -0500 | [diff] [blame] | 251 | // Retrieve service and activate |
George Liu | 2b73119 | 2023-01-11 16:27:13 +0800 | [diff] [blame] | 252 | constexpr std::array<std::string_view, 1> interfaces = { |
| 253 | "xyz.openbmc_project.Software.Activation"}; |
| 254 | dbus::utility::getDbusObject( |
| 255 | objPath.str, interfaces, |
Ed Tanous | a3e6589 | 2021-09-16 14:13:20 -0700 | [diff] [blame] | 256 | [objPath, asyncResp, payload(std::move(payload))]( |
Ed Tanous | 8b24275 | 2023-06-27 17:17:13 -0700 | [diff] [blame] | 257 | const boost::system::error_code& ec, |
Ed Tanous | a3e6589 | 2021-09-16 14:13:20 -0700 | [diff] [blame] | 258 | const std::vector< |
| 259 | std::pair<std::string, std::vector<std::string>>>& |
| 260 | objInfo) mutable { |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 261 | if (ec) |
Andrew Geissler | 0554c98 | 2019-04-23 14:40:12 -0500 | [diff] [blame] | 262 | { |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 263 | BMCWEB_LOG_DEBUG("error_code = {}", ec); |
| 264 | BMCWEB_LOG_DEBUG("error msg = {}", ec.message()); |
| 265 | if (asyncResp) |
| 266 | { |
| 267 | messages::internalError(asyncResp->res); |
| 268 | } |
| 269 | cleanUp(); |
| 270 | return; |
Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 271 | } |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 272 | // Ensure we only got one service back |
| 273 | if (objInfo.size() != 1) |
Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 274 | { |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 275 | BMCWEB_LOG_ERROR("Invalid Object Size {}", |
| 276 | objInfo.size()); |
| 277 | if (asyncResp) |
| 278 | { |
| 279 | messages::internalError(asyncResp->res); |
| 280 | } |
| 281 | cleanUp(); |
| 282 | return; |
Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 283 | } |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 284 | // cancel timer only when |
| 285 | // xyz.openbmc_project.Software.Activation interface |
| 286 | // is added |
| 287 | fwAvailableTimer = nullptr; |
Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 288 | |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 289 | activateImage(objPath.str, objInfo[0].first); |
| 290 | if (asyncResp) |
| 291 | { |
| 292 | createTask(asyncResp, std::move(payload), objPath); |
| 293 | } |
| 294 | fwUpdateInProgress = false; |
| 295 | }); |
Patrick Williams | 62bafc0 | 2022-09-08 17:35:35 -0500 | [diff] [blame] | 296 | |
| 297 | break; |
Andrew Geissler | 86adcd6 | 2019-04-18 10:58:05 -0500 | [diff] [blame] | 298 | } |
| 299 | } |
| 300 | } |
| 301 | |
Myung Bae | 8549b95 | 2023-08-16 15:18:19 -0400 | [diff] [blame] | 302 | inline void afterAvailbleTimerAsyncWait( |
| 303 | const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, |
| 304 | const boost::system::error_code& ec) |
| 305 | { |
| 306 | cleanUp(); |
| 307 | if (ec == boost::asio::error::operation_aborted) |
| 308 | { |
| 309 | // expected, we were canceled before the timer completed. |
| 310 | return; |
| 311 | } |
| 312 | BMCWEB_LOG_ERROR("Timed out waiting for firmware object being created"); |
| 313 | BMCWEB_LOG_ERROR("FW image may has already been uploaded to server"); |
| 314 | if (ec) |
| 315 | { |
| 316 | BMCWEB_LOG_ERROR("Async_wait failed{}", ec); |
| 317 | return; |
| 318 | } |
| 319 | if (asyncResp) |
| 320 | { |
| 321 | redfish::messages::internalError(asyncResp->res); |
| 322 | } |
| 323 | } |
| 324 | |
| 325 | inline void |
| 326 | handleUpdateErrorType(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, |
Ed Tanous | 48fb20b | 2024-11-17 11:51:13 -0800 | [diff] [blame] | 327 | const std::string& url, const std::string& type) |
Myung Bae | 8549b95 | 2023-08-16 15:18:19 -0400 | [diff] [blame] | 328 | { |
Ed Tanous | c87294a | 2024-11-16 22:17:12 -0800 | [diff] [blame] | 329 | // NOLINTBEGIN(bugprone-branch-clone) |
Myung Bae | 8549b95 | 2023-08-16 15:18:19 -0400 | [diff] [blame] | 330 | if (type == "xyz.openbmc_project.Software.Image.Error.UnTarFailure") |
| 331 | { |
Ed Tanous | 48fb20b | 2024-11-17 11:51:13 -0800 | [diff] [blame] | 332 | messages::missingOrMalformedPart(asyncResp->res); |
Myung Bae | 8549b95 | 2023-08-16 15:18:19 -0400 | [diff] [blame] | 333 | } |
| 334 | else if (type == |
| 335 | "xyz.openbmc_project.Software.Image.Error.ManifestFileFailure") |
| 336 | { |
Ed Tanous | 48fb20b | 2024-11-17 11:51:13 -0800 | [diff] [blame] | 337 | messages::missingOrMalformedPart(asyncResp->res); |
Myung Bae | 8549b95 | 2023-08-16 15:18:19 -0400 | [diff] [blame] | 338 | } |
| 339 | else if (type == "xyz.openbmc_project.Software.Image.Error.ImageFailure") |
| 340 | { |
Ed Tanous | 48fb20b | 2024-11-17 11:51:13 -0800 | [diff] [blame] | 341 | messages::missingOrMalformedPart(asyncResp->res); |
Myung Bae | 8549b95 | 2023-08-16 15:18:19 -0400 | [diff] [blame] | 342 | } |
| 343 | else if (type == "xyz.openbmc_project.Software.Version.Error.AlreadyExists") |
| 344 | { |
Ed Tanous | c87294a | 2024-11-16 22:17:12 -0800 | [diff] [blame] | 345 | messages::resourceAlreadyExists(asyncResp->res, "UpdateService", |
| 346 | "Version", "uploaded version"); |
Myung Bae | 8549b95 | 2023-08-16 15:18:19 -0400 | [diff] [blame] | 347 | } |
| 348 | else if (type == "xyz.openbmc_project.Software.Image.Error.BusyFailure") |
| 349 | { |
Ed Tanous | 48fb20b | 2024-11-17 11:51:13 -0800 | [diff] [blame] | 350 | messages::serviceTemporarilyUnavailable(asyncResp->res, url); |
Myung Bae | 8549b95 | 2023-08-16 15:18:19 -0400 | [diff] [blame] | 351 | } |
Myung Bae | 4034a65 | 2023-08-17 08:47:35 -0400 | [diff] [blame] | 352 | else if (type == "xyz.openbmc_project.Software.Version.Error.Incompatible") |
Myung Bae | 8549b95 | 2023-08-16 15:18:19 -0400 | [diff] [blame] | 353 | { |
Ed Tanous | c87294a | 2024-11-16 22:17:12 -0800 | [diff] [blame] | 354 | messages::internalError(asyncResp->res); |
Myung Bae | 4034a65 | 2023-08-17 08:47:35 -0400 | [diff] [blame] | 355 | } |
| 356 | else if (type == |
| 357 | "xyz.openbmc_project.Software.Version.Error.ExpiredAccessKey") |
| 358 | { |
Ed Tanous | c87294a | 2024-11-16 22:17:12 -0800 | [diff] [blame] | 359 | messages::internalError(asyncResp->res); |
Myung Bae | 4034a65 | 2023-08-17 08:47:35 -0400 | [diff] [blame] | 360 | } |
| 361 | else if (type == |
| 362 | "xyz.openbmc_project.Software.Version.Error.InvalidSignature") |
| 363 | { |
Ed Tanous | 48fb20b | 2024-11-17 11:51:13 -0800 | [diff] [blame] | 364 | messages::missingOrMalformedPart(asyncResp->res); |
Myung Bae | 4034a65 | 2023-08-17 08:47:35 -0400 | [diff] [blame] | 365 | } |
| 366 | else if (type == |
| 367 | "xyz.openbmc_project.Software.Image.Error.InternalFailure" || |
| 368 | type == "xyz.openbmc_project.Software.Version.Error.HostFile") |
| 369 | { |
| 370 | BMCWEB_LOG_ERROR("Software Image Error type={}", type); |
Ed Tanous | 48fb20b | 2024-11-17 11:51:13 -0800 | [diff] [blame] | 371 | messages::internalError(asyncResp->res); |
Myung Bae | 8549b95 | 2023-08-16 15:18:19 -0400 | [diff] [blame] | 372 | } |
Myung Bae | 4034a65 | 2023-08-17 08:47:35 -0400 | [diff] [blame] | 373 | else |
| 374 | { |
| 375 | // Unrelated error types. Ignored |
| 376 | BMCWEB_LOG_INFO("Non-Software-related Error type={}. Ignored", type); |
| 377 | return; |
| 378 | } |
Ed Tanous | c87294a | 2024-11-16 22:17:12 -0800 | [diff] [blame] | 379 | // NOLINTEND(bugprone-branch-clone) |
Myung Bae | 4034a65 | 2023-08-17 08:47:35 -0400 | [diff] [blame] | 380 | // Clear the timer |
| 381 | fwAvailableTimer = nullptr; |
Myung Bae | 8549b95 | 2023-08-16 15:18:19 -0400 | [diff] [blame] | 382 | } |
| 383 | |
| 384 | inline void |
| 385 | afterUpdateErrorMatcher(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, |
| 386 | const std::string& url, sdbusplus::message_t& m) |
| 387 | { |
Michael Shen | 80f79a4 | 2023-08-24 13:41:53 +0000 | [diff] [blame] | 388 | dbus::utility::DBusInterfacesMap interfacesProperties; |
Myung Bae | 8549b95 | 2023-08-16 15:18:19 -0400 | [diff] [blame] | 389 | sdbusplus::message::object_path objPath; |
| 390 | m.read(objPath, interfacesProperties); |
| 391 | BMCWEB_LOG_DEBUG("obj path = {}", objPath.str); |
| 392 | for (const std::pair<std::string, dbus::utility::DBusPropertiesMap>& |
| 393 | interface : interfacesProperties) |
| 394 | { |
| 395 | if (interface.first == "xyz.openbmc_project.Logging.Entry") |
| 396 | { |
| 397 | for (const std::pair<std::string, dbus::utility::DbusVariantType>& |
| 398 | value : interface.second) |
| 399 | { |
| 400 | if (value.first != "Message") |
| 401 | { |
| 402 | continue; |
| 403 | } |
| 404 | const std::string* type = |
| 405 | std::get_if<std::string>(&value.second); |
| 406 | if (type == nullptr) |
| 407 | { |
| 408 | // if this was our message, timeout will cover it |
| 409 | return; |
| 410 | } |
Myung Bae | 8549b95 | 2023-08-16 15:18:19 -0400 | [diff] [blame] | 411 | handleUpdateErrorType(asyncResp, url, *type); |
| 412 | } |
| 413 | } |
| 414 | } |
| 415 | } |
| 416 | |
Andrew Geissler | 0554c98 | 2019-04-23 14:40:12 -0500 | [diff] [blame] | 417 | // Note that asyncResp can be either a valid pointer or nullptr. If nullptr |
| 418 | // then no asyncResp updates will occur |
Ed Tanous | f513933 | 2024-04-03 13:25:04 -0700 | [diff] [blame] | 419 | inline void monitorForSoftwareAvailable( |
zhanghch05 | 8d1b46d | 2021-04-01 11:18:24 +0800 | [diff] [blame] | 420 | const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, |
| 421 | const crow::Request& req, const std::string& url, |
Gunnar Mills | 5d13894 | 2022-09-07 10:26:21 -0500 | [diff] [blame] | 422 | int timeoutTimeSeconds = 25) |
Andrew Geissler | 86adcd6 | 2019-04-18 10:58:05 -0500 | [diff] [blame] | 423 | { |
| 424 | // Only allow one FW update at a time |
Ed Tanous | e05aec5 | 2022-01-25 10:28:56 -0800 | [diff] [blame] | 425 | if (fwUpdateInProgress) |
Andrew Geissler | 86adcd6 | 2019-04-18 10:58:05 -0500 | [diff] [blame] | 426 | { |
Andrew Geissler | 0554c98 | 2019-04-23 14:40:12 -0500 | [diff] [blame] | 427 | if (asyncResp) |
| 428 | { |
Andrew Geissler | 0554c98 | 2019-04-23 14:40:12 -0500 | [diff] [blame] | 429 | messages::serviceTemporarilyUnavailable(asyncResp->res, "30"); |
| 430 | } |
Andrew Geissler | 86adcd6 | 2019-04-18 10:58:05 -0500 | [diff] [blame] | 431 | return; |
| 432 | } |
| 433 | |
Ed Tanous | 8e8245d | 2024-04-11 22:21:38 -0700 | [diff] [blame] | 434 | if (req.ioService == nullptr) |
| 435 | { |
| 436 | messages::internalError(asyncResp->res); |
| 437 | return; |
| 438 | } |
| 439 | |
Andrew Geissler | 0554c98 | 2019-04-23 14:40:12 -0500 | [diff] [blame] | 440 | fwAvailableTimer = |
Ed Tanous | 271584a | 2019-07-09 16:24:22 -0700 | [diff] [blame] | 441 | std::make_unique<boost::asio::steady_timer>(*req.ioService); |
Andrew Geissler | 86adcd6 | 2019-04-18 10:58:05 -0500 | [diff] [blame] | 442 | |
Ed Tanous | 271584a | 2019-07-09 16:24:22 -0700 | [diff] [blame] | 443 | fwAvailableTimer->expires_after(std::chrono::seconds(timeoutTimeSeconds)); |
Andrew Geissler | 86adcd6 | 2019-04-18 10:58:05 -0500 | [diff] [blame] | 444 | |
| 445 | fwAvailableTimer->async_wait( |
Myung Bae | 8549b95 | 2023-08-16 15:18:19 -0400 | [diff] [blame] | 446 | std::bind_front(afterAvailbleTimerAsyncWait, asyncResp)); |
| 447 | |
Ed Tanous | a3e6589 | 2021-09-16 14:13:20 -0700 | [diff] [blame] | 448 | task::Payload payload(req); |
Patrick Williams | 59d494e | 2022-07-22 19:26:55 -0500 | [diff] [blame] | 449 | auto callback = [asyncResp, payload](sdbusplus::message_t& m) mutable { |
Ed Tanous | 62598e3 | 2023-07-17 17:06:25 -0700 | [diff] [blame] | 450 | BMCWEB_LOG_DEBUG("Match fired"); |
Ed Tanous | a3e6589 | 2021-09-16 14:13:20 -0700 | [diff] [blame] | 451 | softwareInterfaceAdded(asyncResp, m, std::move(payload)); |
Andrew Geissler | 86adcd6 | 2019-04-18 10:58:05 -0500 | [diff] [blame] | 452 | }; |
| 453 | |
| 454 | fwUpdateInProgress = true; |
| 455 | |
Patrick Williams | 59d494e | 2022-07-22 19:26:55 -0500 | [diff] [blame] | 456 | fwUpdateMatcher = std::make_unique<sdbusplus::bus::match_t>( |
Andrew Geissler | 86adcd6 | 2019-04-18 10:58:05 -0500 | [diff] [blame] | 457 | *crow::connections::systemBus, |
| 458 | "interface='org.freedesktop.DBus.ObjectManager',type='signal'," |
| 459 | "member='InterfacesAdded',path='/xyz/openbmc_project/software'", |
| 460 | callback); |
James Feist | 4cde5d9 | 2020-06-11 10:39:55 -0700 | [diff] [blame] | 461 | |
Patrick Williams | 59d494e | 2022-07-22 19:26:55 -0500 | [diff] [blame] | 462 | fwUpdateErrorMatcher = std::make_unique<sdbusplus::bus::match_t>( |
James Feist | 4cde5d9 | 2020-06-11 10:39:55 -0700 | [diff] [blame] | 463 | *crow::connections::systemBus, |
Brian Ma | e1cc482 | 2021-12-01 17:05:54 +0800 | [diff] [blame] | 464 | "interface='org.freedesktop.DBus.ObjectManager',type='signal'," |
| 465 | "member='InterfacesAdded'," |
| 466 | "path='/xyz/openbmc_project/logging'", |
Myung Bae | 8549b95 | 2023-08-16 15:18:19 -0400 | [diff] [blame] | 467 | std::bind_front(afterUpdateErrorMatcher, asyncResp, url)); |
Andrew Geissler | 86adcd6 | 2019-04-18 10:58:05 -0500 | [diff] [blame] | 468 | } |
Jennifer Lee | 729dae7 | 2018-04-24 15:59:34 -0700 | [diff] [blame] | 469 | |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 470 | inline std::optional<boost::urls::url> parseSimpleUpdateUrl( |
| 471 | std::string imageURI, std::optional<std::string> transferProtocol, |
| 472 | crow::Response& res) |
Ed Tanous | f86bcc8 | 2023-08-25 09:34:07 -0700 | [diff] [blame] | 473 | { |
| 474 | if (imageURI.find("://") == std::string::npos) |
| 475 | { |
| 476 | if (imageURI.starts_with("/")) |
| 477 | { |
| 478 | messages::actionParameterValueTypeError( |
| 479 | res, imageURI, "ImageURI", "UpdateService.SimpleUpdate"); |
| 480 | return std::nullopt; |
| 481 | } |
| 482 | if (!transferProtocol) |
| 483 | { |
| 484 | messages::actionParameterValueTypeError( |
| 485 | res, imageURI, "ImageURI", "UpdateService.SimpleUpdate"); |
| 486 | return std::nullopt; |
| 487 | } |
Ed Tanous | 6a37140 | 2024-12-03 14:01:25 -0800 | [diff] [blame] | 488 | // OpenBMC currently only supports HTTPS |
| 489 | if (*transferProtocol == "HTTPS") |
Ed Tanous | e5cf777 | 2024-04-03 13:45:31 -0700 | [diff] [blame] | 490 | { |
| 491 | imageURI = "https://" + imageURI; |
| 492 | } |
Ed Tanous | 757178a | 2024-04-03 14:32:38 -0700 | [diff] [blame] | 493 | else |
Ed Tanous | f86bcc8 | 2023-08-25 09:34:07 -0700 | [diff] [blame] | 494 | { |
| 495 | messages::actionParameterNotSupported(res, "TransferProtocol", |
| 496 | *transferProtocol); |
| 497 | BMCWEB_LOG_ERROR("Request incorrect protocol parameter: {}", |
| 498 | *transferProtocol); |
| 499 | return std::nullopt; |
| 500 | } |
Ed Tanous | f86bcc8 | 2023-08-25 09:34:07 -0700 | [diff] [blame] | 501 | } |
| 502 | |
| 503 | boost::system::result<boost::urls::url> url = |
| 504 | boost::urls::parse_absolute_uri(imageURI); |
| 505 | if (!url) |
| 506 | { |
| 507 | messages::actionParameterValueTypeError(res, imageURI, "ImageURI", |
| 508 | "UpdateService.SimpleUpdate"); |
| 509 | |
| 510 | return std::nullopt; |
| 511 | } |
| 512 | url->normalize(); |
| 513 | |
Ed Tanous | 757178a | 2024-04-03 14:32:38 -0700 | [diff] [blame] | 514 | if (url->scheme() == "tftp") |
| 515 | { |
| 516 | if (url->encoded_path().size() < 2) |
| 517 | { |
| 518 | messages::actionParameterNotSupported(res, "ImageURI", |
| 519 | url->buffer()); |
| 520 | return std::nullopt; |
| 521 | } |
| 522 | } |
Ed Tanous | e5cf777 | 2024-04-03 13:45:31 -0700 | [diff] [blame] | 523 | else if (url->scheme() == "https") |
| 524 | { |
| 525 | // Empty paths default to "/" |
| 526 | if (url->encoded_path().empty()) |
| 527 | { |
| 528 | url->set_encoded_path("/"); |
| 529 | } |
| 530 | } |
Ed Tanous | 757178a | 2024-04-03 14:32:38 -0700 | [diff] [blame] | 531 | else |
Ed Tanous | f86bcc8 | 2023-08-25 09:34:07 -0700 | [diff] [blame] | 532 | { |
| 533 | messages::actionParameterNotSupported(res, "ImageURI", imageURI); |
| 534 | return std::nullopt; |
| 535 | } |
Ed Tanous | 757178a | 2024-04-03 14:32:38 -0700 | [diff] [blame] | 536 | |
| 537 | if (url->encoded_path().empty()) |
Ed Tanous | f86bcc8 | 2023-08-25 09:34:07 -0700 | [diff] [blame] | 538 | { |
Ed Tanous | 757178a | 2024-04-03 14:32:38 -0700 | [diff] [blame] | 539 | messages::actionParameterValueTypeError(res, imageURI, "ImageURI", |
| 540 | "UpdateService.SimpleUpdate"); |
Ed Tanous | f86bcc8 | 2023-08-25 09:34:07 -0700 | [diff] [blame] | 541 | return std::nullopt; |
| 542 | } |
Ed Tanous | 757178a | 2024-04-03 14:32:38 -0700 | [diff] [blame] | 543 | |
| 544 | return *url; |
Ed Tanous | f86bcc8 | 2023-08-25 09:34:07 -0700 | [diff] [blame] | 545 | } |
| 546 | |
Ed Tanous | e5cf777 | 2024-04-03 13:45:31 -0700 | [diff] [blame] | 547 | inline void doHttpsUpdate(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, |
| 548 | const boost::urls::url_view_base& url) |
| 549 | { |
| 550 | messages::actionParameterNotSupported(asyncResp->res, "ImageURI", |
| 551 | url.buffer()); |
| 552 | } |
| 553 | |
Ed Tanous | f513933 | 2024-04-03 13:25:04 -0700 | [diff] [blame] | 554 | inline void handleUpdateServiceSimpleUpdateAction( |
| 555 | crow::App& app, const crow::Request& req, |
| 556 | const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) |
Andrew Geissler | 0554c98 | 2019-04-23 14:40:12 -0500 | [diff] [blame] | 557 | { |
Ed Tanous | f513933 | 2024-04-03 13:25:04 -0700 | [diff] [blame] | 558 | if (!redfish::setUpRedfishRoute(app, req, asyncResp)) |
| 559 | { |
| 560 | return; |
| 561 | } |
| 562 | |
| 563 | std::optional<std::string> transferProtocol; |
| 564 | std::string imageURI; |
| 565 | |
| 566 | BMCWEB_LOG_DEBUG("Enter UpdateService.SimpleUpdate doPost"); |
| 567 | |
| 568 | // User can pass in both TransferProtocol and ImageURI parameters or |
| 569 | // they can pass in just the ImageURI with the transfer protocol |
| 570 | // embedded within it. |
| 571 | // 1) TransferProtocol:TFTP ImageURI:1.1.1.1/myfile.bin |
| 572 | // 2) ImageURI:tftp://1.1.1.1/myfile.bin |
| 573 | |
Myung Bae | afc474a | 2024-10-09 00:53:29 -0700 | [diff] [blame] | 574 | if (!json_util::readJsonAction( // |
| 575 | req, asyncResp->res, // |
| 576 | "ImageURI", imageURI, // |
| 577 | "TransferProtocol", transferProtocol // |
| 578 | )) |
Ed Tanous | f513933 | 2024-04-03 13:25:04 -0700 | [diff] [blame] | 579 | { |
| 580 | BMCWEB_LOG_DEBUG("Missing TransferProtocol or ImageURI parameter"); |
| 581 | return; |
| 582 | } |
| 583 | |
Ed Tanous | 757178a | 2024-04-03 14:32:38 -0700 | [diff] [blame] | 584 | std::optional<boost::urls::url> url = |
| 585 | parseSimpleUpdateUrl(imageURI, transferProtocol, asyncResp->res); |
| 586 | if (!url) |
Ed Tanous | f513933 | 2024-04-03 13:25:04 -0700 | [diff] [blame] | 587 | { |
| 588 | return; |
| 589 | } |
Jagpal Singh Gill | 4e338b2 | 2024-06-14 14:24:56 -0700 | [diff] [blame] | 590 | if (url->scheme() == "https") |
Ed Tanous | e5cf777 | 2024-04-03 13:45:31 -0700 | [diff] [blame] | 591 | { |
| 592 | doHttpsUpdate(asyncResp, *url); |
| 593 | } |
Ed Tanous | 757178a | 2024-04-03 14:32:38 -0700 | [diff] [blame] | 594 | else |
| 595 | { |
| 596 | messages::actionParameterNotSupported(asyncResp->res, "ImageURI", |
| 597 | url->buffer()); |
| 598 | return; |
| 599 | } |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 600 | |
Ed Tanous | f513933 | 2024-04-03 13:25:04 -0700 | [diff] [blame] | 601 | BMCWEB_LOG_DEBUG("Exit UpdateService.SimpleUpdate doPost"); |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 602 | } |
| 603 | |
George Liu | 0ed80c8 | 2020-05-12 16:06:27 +0800 | [diff] [blame] | 604 | inline void uploadImageFile(crow::Response& res, std::string_view body) |
| 605 | { |
Ed Tanous | 2c6ffdb | 2023-06-28 11:28:38 -0700 | [diff] [blame] | 606 | std::filesystem::path filepath("/tmp/images/" + bmcweb::getRandomUUID()); |
| 607 | |
Ed Tanous | 62598e3 | 2023-07-17 17:06:25 -0700 | [diff] [blame] | 608 | BMCWEB_LOG_DEBUG("Writing file to {}", filepath.string()); |
George Liu | 0ed80c8 | 2020-05-12 16:06:27 +0800 | [diff] [blame] | 609 | std::ofstream out(filepath, std::ofstream::out | std::ofstream::binary | |
| 610 | std::ofstream::trunc); |
| 611 | // set the permission of the file to 640 |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 612 | std::filesystem::perms permission = |
| 613 | std::filesystem::perms::owner_read | std::filesystem::perms::group_read; |
George Liu | 0ed80c8 | 2020-05-12 16:06:27 +0800 | [diff] [blame] | 614 | std::filesystem::permissions(filepath, permission); |
| 615 | out << body; |
| 616 | |
| 617 | if (out.bad()) |
| 618 | { |
| 619 | messages::internalError(res); |
| 620 | cleanUp(); |
| 621 | } |
| 622 | } |
| 623 | |
Jagpal Singh Gill | de0c960 | 2024-04-29 17:30:21 -0700 | [diff] [blame] | 624 | // Convert the Request Apply Time to the D-Bus value |
| 625 | inline bool convertApplyTime(crow::Response& res, const std::string& applyTime, |
| 626 | std::string& applyTimeNewVal) |
| 627 | { |
| 628 | if (applyTime == "Immediate") |
| 629 | { |
| 630 | applyTimeNewVal = |
Jagpal Singh Gill | 049079f | 2024-06-02 18:11:13 -0700 | [diff] [blame] | 631 | "xyz.openbmc_project.Software.ApplyTime.RequestedApplyTimes.Immediate"; |
Jagpal Singh Gill | de0c960 | 2024-04-29 17:30:21 -0700 | [diff] [blame] | 632 | } |
| 633 | else if (applyTime == "OnReset") |
| 634 | { |
| 635 | applyTimeNewVal = |
Jagpal Singh Gill | 049079f | 2024-06-02 18:11:13 -0700 | [diff] [blame] | 636 | "xyz.openbmc_project.Software.ApplyTime.RequestedApplyTimes.OnReset"; |
Jagpal Singh Gill | de0c960 | 2024-04-29 17:30:21 -0700 | [diff] [blame] | 637 | } |
| 638 | else |
| 639 | { |
| 640 | BMCWEB_LOG_WARNING( |
| 641 | "ApplyTime value {} is not in the list of acceptable values", |
| 642 | applyTime); |
| 643 | messages::propertyValueNotInList(res, applyTime, "ApplyTime"); |
| 644 | return false; |
| 645 | } |
| 646 | return true; |
| 647 | } |
| 648 | |
George Liu | 0ed80c8 | 2020-05-12 16:06:27 +0800 | [diff] [blame] | 649 | inline void setApplyTime(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, |
| 650 | const std::string& applyTime) |
| 651 | { |
| 652 | std::string applyTimeNewVal; |
Jagpal Singh Gill | 049079f | 2024-06-02 18:11:13 -0700 | [diff] [blame] | 653 | if (!convertApplyTime(asyncResp->res, applyTime, applyTimeNewVal)) |
George Liu | 0ed80c8 | 2020-05-12 16:06:27 +0800 | [diff] [blame] | 654 | { |
George Liu | 0ed80c8 | 2020-05-12 16:06:27 +0800 | [diff] [blame] | 655 | return; |
| 656 | } |
| 657 | |
Ginu George | e93abac | 2024-06-14 17:35:27 +0530 | [diff] [blame] | 658 | setDbusProperty(asyncResp, "ApplyTime", "xyz.openbmc_project.Settings", |
Ed Tanous | d02aad3 | 2024-02-13 14:43:34 -0800 | [diff] [blame] | 659 | sdbusplus::message::object_path( |
| 660 | "/xyz/openbmc_project/software/apply_time"), |
| 661 | "xyz.openbmc_project.Software.ApplyTime", |
Ginu George | e93abac | 2024-06-14 17:35:27 +0530 | [diff] [blame] | 662 | "RequestedApplyTime", applyTimeNewVal); |
George Liu | 0ed80c8 | 2020-05-12 16:06:27 +0800 | [diff] [blame] | 663 | } |
| 664 | |
Jagpal Singh Gill | ef93eab | 2024-04-17 16:06:14 -0700 | [diff] [blame] | 665 | struct MultiPartUpdateParameters |
George Liu | 0ed80c8 | 2020-05-12 16:06:27 +0800 | [diff] [blame] | 666 | { |
Jagpal Singh Gill | ef93eab | 2024-04-17 16:06:14 -0700 | [diff] [blame] | 667 | std::optional<std::string> applyTime; |
| 668 | std::string uploadData; |
Jagpal Singh Gill | de0c960 | 2024-04-29 17:30:21 -0700 | [diff] [blame] | 669 | std::vector<std::string> targets; |
Jagpal Singh Gill | ef93eab | 2024-04-17 16:06:14 -0700 | [diff] [blame] | 670 | }; |
| 671 | |
Jagpal Singh Gill | de0c960 | 2024-04-29 17:30:21 -0700 | [diff] [blame] | 672 | inline std::optional<std::string> |
| 673 | processUrl(boost::system::result<boost::urls::url_view>& url) |
| 674 | { |
| 675 | if (!url) |
| 676 | { |
| 677 | return std::nullopt; |
| 678 | } |
| 679 | if (crow::utility::readUrlSegments(*url, "redfish", "v1", "Managers", |
| 680 | BMCWEB_REDFISH_MANAGER_URI_NAME)) |
| 681 | { |
| 682 | return std::make_optional(std::string(BMCWEB_REDFISH_MANAGER_URI_NAME)); |
| 683 | } |
| 684 | if constexpr (!BMCWEB_REDFISH_UPDATESERVICE_USE_DBUS) |
| 685 | { |
| 686 | return std::nullopt; |
| 687 | } |
| 688 | std::string firmwareId; |
| 689 | if (!crow::utility::readUrlSegments(*url, "redfish", "v1", "UpdateService", |
| 690 | "FirmwareInventory", |
| 691 | std::ref(firmwareId))) |
| 692 | { |
| 693 | return std::nullopt; |
| 694 | } |
| 695 | |
| 696 | return std::make_optional(firmwareId); |
| 697 | } |
| 698 | |
Jagpal Singh Gill | ef93eab | 2024-04-17 16:06:14 -0700 | [diff] [blame] | 699 | inline std::optional<MultiPartUpdateParameters> |
| 700 | extractMultipartUpdateParameters( |
| 701 | const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, |
| 702 | MultipartParser parser) |
| 703 | { |
| 704 | MultiPartUpdateParameters multiRet; |
| 705 | for (FormPart& formpart : parser.mime_fields) |
George Liu | 0ed80c8 | 2020-05-12 16:06:27 +0800 | [diff] [blame] | 706 | { |
| 707 | boost::beast::http::fields::const_iterator it = |
| 708 | formpart.fields.find("Content-Disposition"); |
| 709 | if (it == formpart.fields.end()) |
| 710 | { |
Ed Tanous | 62598e3 | 2023-07-17 17:06:25 -0700 | [diff] [blame] | 711 | BMCWEB_LOG_ERROR("Couldn't find Content-Disposition"); |
Jagpal Singh Gill | ef93eab | 2024-04-17 16:06:14 -0700 | [diff] [blame] | 712 | return std::nullopt; |
George Liu | 0ed80c8 | 2020-05-12 16:06:27 +0800 | [diff] [blame] | 713 | } |
Ed Tanous | 62598e3 | 2023-07-17 17:06:25 -0700 | [diff] [blame] | 714 | BMCWEB_LOG_INFO("Parsing value {}", it->value()); |
George Liu | 0ed80c8 | 2020-05-12 16:06:27 +0800 | [diff] [blame] | 715 | |
| 716 | // The construction parameters of param_list must start with `;` |
| 717 | size_t index = it->value().find(';'); |
| 718 | if (index == std::string::npos) |
| 719 | { |
| 720 | continue; |
| 721 | } |
| 722 | |
Patrick Williams | 89492a1 | 2023-05-10 07:51:34 -0500 | [diff] [blame] | 723 | for (const auto& param : |
George Liu | 0ed80c8 | 2020-05-12 16:06:27 +0800 | [diff] [blame] | 724 | boost::beast::http::param_list{it->value().substr(index)}) |
| 725 | { |
| 726 | if (param.first != "name" || param.second.empty()) |
| 727 | { |
| 728 | continue; |
| 729 | } |
| 730 | |
| 731 | if (param.second == "UpdateParameters") |
| 732 | { |
Jagpal Singh Gill | ef93eab | 2024-04-17 16:06:14 -0700 | [diff] [blame] | 733 | std::vector<std::string> tempTargets; |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 734 | nlohmann::json content = |
| 735 | nlohmann::json::parse(formpart.content, nullptr, false); |
Ed Tanous | ac1e124 | 2024-07-10 22:10:14 -0700 | [diff] [blame] | 736 | if (content.is_discarded()) |
| 737 | { |
| 738 | return std::nullopt; |
| 739 | } |
Ed Tanous | 7cb59f6 | 2022-05-05 11:48:31 -0700 | [diff] [blame] | 740 | nlohmann::json::object_t* obj = |
| 741 | content.get_ptr<nlohmann::json::object_t*>(); |
| 742 | if (obj == nullptr) |
| 743 | { |
Jagpal Singh Gill | ef93eab | 2024-04-17 16:06:14 -0700 | [diff] [blame] | 744 | messages::propertyValueTypeError( |
| 745 | asyncResp->res, formpart.content, "UpdateParameters"); |
| 746 | return std::nullopt; |
Ed Tanous | 7cb59f6 | 2022-05-05 11:48:31 -0700 | [diff] [blame] | 747 | } |
| 748 | |
Myung Bae | afc474a | 2024-10-09 00:53:29 -0700 | [diff] [blame] | 749 | if (!json_util::readJsonObject( // |
| 750 | *obj, asyncResp->res, // |
| 751 | "@Redfish.OperationApplyTime", multiRet.applyTime, // |
| 752 | "Targets", tempTargets // |
| 753 | )) |
George Liu | 0ed80c8 | 2020-05-12 16:06:27 +0800 | [diff] [blame] | 754 | { |
Jagpal Singh Gill | ef93eab | 2024-04-17 16:06:14 -0700 | [diff] [blame] | 755 | return std::nullopt; |
George Liu | 0ed80c8 | 2020-05-12 16:06:27 +0800 | [diff] [blame] | 756 | } |
Jagpal Singh Gill | ef93eab | 2024-04-17 16:06:14 -0700 | [diff] [blame] | 757 | |
| 758 | for (size_t urlIndex = 0; urlIndex < tempTargets.size(); |
| 759 | urlIndex++) |
George Liu | 0ed80c8 | 2020-05-12 16:06:27 +0800 | [diff] [blame] | 760 | { |
Jagpal Singh Gill | ef93eab | 2024-04-17 16:06:14 -0700 | [diff] [blame] | 761 | const std::string& target = tempTargets[urlIndex]; |
| 762 | boost::system::result<boost::urls::url_view> url = |
| 763 | boost::urls::parse_origin_form(target); |
Jagpal Singh Gill | de0c960 | 2024-04-29 17:30:21 -0700 | [diff] [blame] | 764 | auto res = processUrl(url); |
| 765 | if (!res.has_value()) |
Jagpal Singh Gill | ef93eab | 2024-04-17 16:06:14 -0700 | [diff] [blame] | 766 | { |
| 767 | messages::propertyValueFormatError( |
| 768 | asyncResp->res, target, |
| 769 | std::format("Targets/{}", urlIndex)); |
| 770 | return std::nullopt; |
| 771 | } |
Jagpal Singh Gill | de0c960 | 2024-04-29 17:30:21 -0700 | [diff] [blame] | 772 | multiRet.targets.emplace_back(res.value()); |
George Liu | 0ed80c8 | 2020-05-12 16:06:27 +0800 | [diff] [blame] | 773 | } |
Jagpal Singh Gill | ef93eab | 2024-04-17 16:06:14 -0700 | [diff] [blame] | 774 | if (multiRet.targets.size() != 1) |
George Liu | 0ed80c8 | 2020-05-12 16:06:27 +0800 | [diff] [blame] | 775 | { |
Jagpal Singh Gill | ef93eab | 2024-04-17 16:06:14 -0700 | [diff] [blame] | 776 | messages::propertyValueFormatError( |
| 777 | asyncResp->res, multiRet.targets, "Targets"); |
| 778 | return std::nullopt; |
George Liu | 0ed80c8 | 2020-05-12 16:06:27 +0800 | [diff] [blame] | 779 | } |
George Liu | 0ed80c8 | 2020-05-12 16:06:27 +0800 | [diff] [blame] | 780 | } |
| 781 | else if (param.second == "UpdateFile") |
| 782 | { |
Jagpal Singh Gill | ef93eab | 2024-04-17 16:06:14 -0700 | [diff] [blame] | 783 | multiRet.uploadData = std::move(formpart.content); |
George Liu | 0ed80c8 | 2020-05-12 16:06:27 +0800 | [diff] [blame] | 784 | } |
| 785 | } |
| 786 | } |
| 787 | |
Jagpal Singh Gill | ef93eab | 2024-04-17 16:06:14 -0700 | [diff] [blame] | 788 | if (multiRet.uploadData.empty()) |
George Liu | 0ed80c8 | 2020-05-12 16:06:27 +0800 | [diff] [blame] | 789 | { |
Ed Tanous | 62598e3 | 2023-07-17 17:06:25 -0700 | [diff] [blame] | 790 | BMCWEB_LOG_ERROR("Upload data is NULL"); |
George Liu | 0ed80c8 | 2020-05-12 16:06:27 +0800 | [diff] [blame] | 791 | messages::propertyMissing(asyncResp->res, "UpdateFile"); |
Jagpal Singh Gill | ef93eab | 2024-04-17 16:06:14 -0700 | [diff] [blame] | 792 | return std::nullopt; |
| 793 | } |
| 794 | if (multiRet.targets.empty()) |
| 795 | { |
| 796 | messages::propertyMissing(asyncResp->res, "Targets"); |
| 797 | return std::nullopt; |
| 798 | } |
| 799 | return multiRet; |
| 800 | } |
| 801 | |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 802 | inline void handleStartUpdate( |
| 803 | const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, task::Payload payload, |
| 804 | const std::string& objectPath, const boost::system::error_code& ec, |
| 805 | const sdbusplus::message::object_path& retPath) |
Jagpal Singh Gill | de0c960 | 2024-04-29 17:30:21 -0700 | [diff] [blame] | 806 | { |
| 807 | if (ec) |
| 808 | { |
| 809 | BMCWEB_LOG_ERROR("error_code = {}", ec); |
| 810 | BMCWEB_LOG_ERROR("error msg = {}", ec.message()); |
| 811 | messages::internalError(asyncResp->res); |
| 812 | return; |
| 813 | } |
| 814 | |
Jagpal Singh Gill | 587090c | 2024-08-12 00:24:16 -0700 | [diff] [blame] | 815 | BMCWEB_LOG_INFO("Call to StartUpdate on {} Success, retPath = {}", |
| 816 | objectPath, retPath.str); |
| 817 | createTask(asyncResp, std::move(payload), retPath); |
Jagpal Singh Gill | de0c960 | 2024-04-29 17:30:21 -0700 | [diff] [blame] | 818 | } |
| 819 | |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 820 | inline void startUpdate( |
| 821 | const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, task::Payload payload, |
| 822 | const MemoryFileDescriptor& memfd, const std::string& applyTime, |
| 823 | const std::string& objectPath, const std::string& serviceName) |
Jagpal Singh Gill | de0c960 | 2024-04-29 17:30:21 -0700 | [diff] [blame] | 824 | { |
| 825 | crow::connections::systemBus->async_method_call( |
| 826 | [asyncResp, payload = std::move(payload), |
| 827 | objectPath](const boost::system::error_code& ec1, |
| 828 | const sdbusplus::message::object_path& retPath) mutable { |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 829 | handleStartUpdate(asyncResp, std::move(payload), objectPath, ec1, |
| 830 | retPath); |
| 831 | }, |
Jagpal Singh Gill | de0c960 | 2024-04-29 17:30:21 -0700 | [diff] [blame] | 832 | serviceName, objectPath, "xyz.openbmc_project.Software.Update", |
| 833 | "StartUpdate", sdbusplus::message::unix_fd(memfd.fd), applyTime); |
| 834 | } |
| 835 | |
Jagpal Singh Gill | 08f61d5 | 2024-07-17 15:17:22 -0700 | [diff] [blame] | 836 | inline void getSwInfo(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, |
| 837 | task::Payload payload, const MemoryFileDescriptor& memfd, |
| 838 | const std::string& applyTime, const std::string& target, |
| 839 | const boost::system::error_code& ec, |
| 840 | const dbus::utility::MapperGetSubTreeResponse& subtree) |
Jagpal Singh Gill | de0c960 | 2024-04-29 17:30:21 -0700 | [diff] [blame] | 841 | { |
Jagpal Singh Gill | 08f61d5 | 2024-07-17 15:17:22 -0700 | [diff] [blame] | 842 | using SwInfoMap = std::unordered_map< |
| 843 | std::string, std::pair<sdbusplus::message::object_path, std::string>>; |
Jagpal Singh Gill | de0c960 | 2024-04-29 17:30:21 -0700 | [diff] [blame] | 844 | SwInfoMap swInfoMap; |
| 845 | |
| 846 | if (ec) |
| 847 | { |
| 848 | BMCWEB_LOG_ERROR("error_code = {}", ec); |
| 849 | BMCWEB_LOG_ERROR("error msg = {}", ec.message()); |
| 850 | messages::internalError(asyncResp->res); |
| 851 | return; |
| 852 | } |
| 853 | BMCWEB_LOG_DEBUG("Found {} software version paths", subtree.size()); |
| 854 | |
Jagpal Singh Gill | 08f61d5 | 2024-07-17 15:17:22 -0700 | [diff] [blame] | 855 | for (const auto& entry : subtree) |
Jagpal Singh Gill | de0c960 | 2024-04-29 17:30:21 -0700 | [diff] [blame] | 856 | { |
Jagpal Singh Gill | 08f61d5 | 2024-07-17 15:17:22 -0700 | [diff] [blame] | 857 | sdbusplus::message::object_path path(entry.first); |
Jagpal Singh Gill | de0c960 | 2024-04-29 17:30:21 -0700 | [diff] [blame] | 858 | std::string swId = path.filename(); |
Jagpal Singh Gill | 08f61d5 | 2024-07-17 15:17:22 -0700 | [diff] [blame] | 859 | swInfoMap.emplace(swId, make_pair(path, entry.second[0].first)); |
Jagpal Singh Gill | de0c960 | 2024-04-29 17:30:21 -0700 | [diff] [blame] | 860 | } |
| 861 | |
| 862 | auto swEntry = swInfoMap.find(target); |
| 863 | if (swEntry == swInfoMap.end()) |
| 864 | { |
| 865 | BMCWEB_LOG_WARNING("No valid DBus path for Target URI {}", target); |
| 866 | messages::propertyValueFormatError(asyncResp->res, target, "Targets"); |
| 867 | return; |
| 868 | } |
| 869 | |
Jagpal Singh Gill | 08f61d5 | 2024-07-17 15:17:22 -0700 | [diff] [blame] | 870 | BMCWEB_LOG_DEBUG("Found software version path {} serviceName {}", |
| 871 | swEntry->second.first.str, swEntry->second.second); |
Jagpal Singh Gill | de0c960 | 2024-04-29 17:30:21 -0700 | [diff] [blame] | 872 | |
Jagpal Singh Gill | 08f61d5 | 2024-07-17 15:17:22 -0700 | [diff] [blame] | 873 | startUpdate(asyncResp, std::move(payload), memfd, applyTime, |
| 874 | swEntry->second.first.str, swEntry->second.second); |
| 875 | } |
| 876 | |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 877 | inline void handleBMCUpdate( |
| 878 | const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, task::Payload payload, |
| 879 | const MemoryFileDescriptor& memfd, const std::string& applyTime, |
| 880 | const boost::system::error_code& ec, |
| 881 | const dbus::utility::MapperEndPoints& functionalSoftware) |
Jagpal Singh Gill | 08f61d5 | 2024-07-17 15:17:22 -0700 | [diff] [blame] | 882 | { |
| 883 | if (ec) |
| 884 | { |
| 885 | BMCWEB_LOG_ERROR("error_code = {}", ec); |
| 886 | BMCWEB_LOG_ERROR("error msg = {}", ec.message()); |
| 887 | messages::internalError(asyncResp->res); |
| 888 | return; |
| 889 | } |
| 890 | if (functionalSoftware.size() != 1) |
| 891 | { |
| 892 | BMCWEB_LOG_ERROR("Found {} functional software endpoints", |
| 893 | functionalSoftware.size()); |
| 894 | messages::internalError(asyncResp->res); |
| 895 | return; |
| 896 | } |
| 897 | |
| 898 | startUpdate(asyncResp, std::move(payload), memfd, applyTime, |
| 899 | functionalSoftware[0], "xyz.openbmc_project.Software.Manager"); |
Jagpal Singh Gill | de0c960 | 2024-04-29 17:30:21 -0700 | [diff] [blame] | 900 | } |
| 901 | |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 902 | inline void processUpdateRequest( |
| 903 | const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, |
| 904 | task::Payload&& payload, std::string_view body, |
| 905 | const std::string& applyTime, std::vector<std::string>& targets) |
Jagpal Singh Gill | de0c960 | 2024-04-29 17:30:21 -0700 | [diff] [blame] | 906 | { |
Jagpal Singh Gill | de0c960 | 2024-04-29 17:30:21 -0700 | [diff] [blame] | 907 | MemoryFileDescriptor memfd("update-image"); |
| 908 | if (memfd.fd == -1) |
| 909 | { |
| 910 | BMCWEB_LOG_ERROR("Failed to create image memfd"); |
| 911 | messages::internalError(asyncResp->res); |
| 912 | return; |
| 913 | } |
| 914 | if (write(memfd.fd, body.data(), body.length()) != |
| 915 | static_cast<ssize_t>(body.length())) |
| 916 | { |
| 917 | BMCWEB_LOG_ERROR("Failed to write to image memfd"); |
| 918 | messages::internalError(asyncResp->res); |
| 919 | return; |
| 920 | } |
| 921 | if (!memfd.rewind()) |
| 922 | { |
| 923 | messages::internalError(asyncResp->res); |
| 924 | return; |
| 925 | } |
| 926 | |
Jagpal Singh Gill | de0c960 | 2024-04-29 17:30:21 -0700 | [diff] [blame] | 927 | if (!targets.empty() && targets[0] == BMCWEB_REDFISH_MANAGER_URI_NAME) |
| 928 | { |
Jagpal Singh Gill | 08f61d5 | 2024-07-17 15:17:22 -0700 | [diff] [blame] | 929 | dbus::utility::getAssociationEndPoints( |
Jagpal Singh Gill | 89449bb | 2024-08-12 16:17:58 -0700 | [diff] [blame] | 930 | "/xyz/openbmc_project/software/bmc/updateable", |
Jagpal Singh Gill | 08f61d5 | 2024-07-17 15:17:22 -0700 | [diff] [blame] | 931 | [asyncResp, payload = std::move(payload), memfd = std::move(memfd), |
| 932 | applyTime]( |
| 933 | const boost::system::error_code& ec, |
| 934 | const dbus::utility::MapperEndPoints& objectPaths) mutable { |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 935 | handleBMCUpdate(asyncResp, std::move(payload), memfd, applyTime, |
| 936 | ec, objectPaths); |
| 937 | }); |
Jagpal Singh Gill | de0c960 | 2024-04-29 17:30:21 -0700 | [diff] [blame] | 938 | } |
| 939 | else |
| 940 | { |
| 941 | constexpr std::array<std::string_view, 1> interfaces = { |
| 942 | "xyz.openbmc_project.Software.Version"}; |
Jagpal Singh Gill | 08f61d5 | 2024-07-17 15:17:22 -0700 | [diff] [blame] | 943 | dbus::utility::getSubTree( |
Jagpal Singh Gill | de0c960 | 2024-04-29 17:30:21 -0700 | [diff] [blame] | 944 | "/xyz/openbmc_project/software", 1, interfaces, |
| 945 | [asyncResp, payload = std::move(payload), memfd = std::move(memfd), |
Jagpal Singh Gill | 08f61d5 | 2024-07-17 15:17:22 -0700 | [diff] [blame] | 946 | applyTime, targets](const boost::system::error_code& ec, |
| 947 | const dbus::utility::MapperGetSubTreeResponse& |
| 948 | subtree) mutable { |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 949 | getSwInfo(asyncResp, std::move(payload), memfd, applyTime, |
| 950 | targets[0], ec, subtree); |
| 951 | }); |
Jagpal Singh Gill | de0c960 | 2024-04-29 17:30:21 -0700 | [diff] [blame] | 952 | } |
| 953 | } |
| 954 | |
| 955 | inline void |
Jagpal Singh Gill | ef93eab | 2024-04-17 16:06:14 -0700 | [diff] [blame] | 956 | updateMultipartContext(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, |
| 957 | const crow::Request& req, MultipartParser&& parser) |
| 958 | { |
| 959 | std::optional<MultiPartUpdateParameters> multipart = |
| 960 | extractMultipartUpdateParameters(asyncResp, std::move(parser)); |
| 961 | if (!multipart) |
| 962 | { |
George Liu | 0ed80c8 | 2020-05-12 16:06:27 +0800 | [diff] [blame] | 963 | return; |
| 964 | } |
Jagpal Singh Gill | ef93eab | 2024-04-17 16:06:14 -0700 | [diff] [blame] | 965 | if (!multipart->applyTime) |
George Liu | 0ed80c8 | 2020-05-12 16:06:27 +0800 | [diff] [blame] | 966 | { |
Jagpal Singh Gill | ef93eab | 2024-04-17 16:06:14 -0700 | [diff] [blame] | 967 | multipart->applyTime = "OnReset"; |
George Liu | 0ed80c8 | 2020-05-12 16:06:27 +0800 | [diff] [blame] | 968 | } |
| 969 | |
Jagpal Singh Gill | de0c960 | 2024-04-29 17:30:21 -0700 | [diff] [blame] | 970 | if constexpr (BMCWEB_REDFISH_UPDATESERVICE_USE_DBUS) |
| 971 | { |
Jagpal Singh Gill | 9dae4de | 2024-06-02 23:43:56 -0700 | [diff] [blame] | 972 | std::string applyTimeNewVal; |
| 973 | if (!convertApplyTime(asyncResp->res, *multipart->applyTime, |
| 974 | applyTimeNewVal)) |
| 975 | { |
| 976 | return; |
| 977 | } |
| 978 | task::Payload payload(req); |
| 979 | |
| 980 | processUpdateRequest(asyncResp, std::move(payload), |
| 981 | multipart->uploadData, applyTimeNewVal, |
| 982 | multipart->targets); |
Jagpal Singh Gill | de0c960 | 2024-04-29 17:30:21 -0700 | [diff] [blame] | 983 | } |
| 984 | else |
| 985 | { |
| 986 | setApplyTime(asyncResp, *multipart->applyTime); |
George Liu | 0ed80c8 | 2020-05-12 16:06:27 +0800 | [diff] [blame] | 987 | |
Jagpal Singh Gill | de0c960 | 2024-04-29 17:30:21 -0700 | [diff] [blame] | 988 | // Setup callback for when new software detected |
| 989 | monitorForSoftwareAvailable(asyncResp, req, |
| 990 | "/redfish/v1/UpdateService"); |
Ed Tanous | 6b54e4e | 2024-04-10 08:58:48 -0700 | [diff] [blame] | 991 | |
Jagpal Singh Gill | de0c960 | 2024-04-29 17:30:21 -0700 | [diff] [blame] | 992 | uploadImageFile(asyncResp->res, multipart->uploadData); |
| 993 | } |
George Liu | 0ed80c8 | 2020-05-12 16:06:27 +0800 | [diff] [blame] | 994 | } |
| 995 | |
Jagpal Singh Gill | 9dae4de | 2024-06-02 23:43:56 -0700 | [diff] [blame] | 996 | inline void doHTTPUpdate(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, |
| 997 | const crow::Request& req) |
| 998 | { |
| 999 | if constexpr (BMCWEB_REDFISH_UPDATESERVICE_USE_DBUS) |
| 1000 | { |
| 1001 | task::Payload payload(req); |
| 1002 | // HTTP push only supports BMC updates (with ApplyTime as immediate) for |
| 1003 | // backwards compatibility. Specific component updates will be handled |
| 1004 | // through Multipart form HTTP push. |
| 1005 | std::vector<std::string> targets; |
| 1006 | targets.emplace_back(BMCWEB_REDFISH_MANAGER_URI_NAME); |
| 1007 | |
| 1008 | processUpdateRequest( |
| 1009 | asyncResp, std::move(payload), req.body(), |
| 1010 | "xyz.openbmc_project.Software.ApplyTime.RequestedApplyTimes.Immediate", |
| 1011 | targets); |
| 1012 | } |
| 1013 | else |
| 1014 | { |
| 1015 | // Setup callback for when new software detected |
| 1016 | monitorForSoftwareAvailable(asyncResp, req, |
| 1017 | "/redfish/v1/UpdateService"); |
| 1018 | |
| 1019 | uploadImageFile(asyncResp->res, req.body()); |
| 1020 | } |
| 1021 | } |
| 1022 | |
Ed Tanous | c2051d1 | 2022-05-11 12:21:55 -0700 | [diff] [blame] | 1023 | inline void |
| 1024 | handleUpdateServicePost(App& app, const crow::Request& req, |
| 1025 | const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) |
| 1026 | { |
Carson Labrado | 3ba0007 | 2022-06-06 19:40:56 +0000 | [diff] [blame] | 1027 | if (!redfish::setUpRedfishRoute(app, req, asyncResp)) |
Ed Tanous | c2051d1 | 2022-05-11 12:21:55 -0700 | [diff] [blame] | 1028 | { |
| 1029 | return; |
| 1030 | } |
Ninad Palsule | b33a432 | 2023-06-09 09:19:18 -0500 | [diff] [blame] | 1031 | std::string_view contentType = req.getHeaderValue("Content-Type"); |
Ed Tanous | c2051d1 | 2022-05-11 12:21:55 -0700 | [diff] [blame] | 1032 | |
Ed Tanous | 62598e3 | 2023-07-17 17:06:25 -0700 | [diff] [blame] | 1033 | BMCWEB_LOG_DEBUG("doPost: contentType={}", contentType); |
Ed Tanous | c2051d1 | 2022-05-11 12:21:55 -0700 | [diff] [blame] | 1034 | |
Ninad Palsule | b33a432 | 2023-06-09 09:19:18 -0500 | [diff] [blame] | 1035 | // Make sure that content type is application/octet-stream or |
| 1036 | // multipart/form-data |
Ed Tanous | 18f8f60 | 2023-07-18 10:07:23 -0700 | [diff] [blame] | 1037 | if (bmcweb::asciiIEquals(contentType, "application/octet-stream")) |
George Liu | 0ed80c8 | 2020-05-12 16:06:27 +0800 | [diff] [blame] | 1038 | { |
Jagpal Singh Gill | 9dae4de | 2024-06-02 23:43:56 -0700 | [diff] [blame] | 1039 | doHTTPUpdate(asyncResp, req); |
George Liu | 0ed80c8 | 2020-05-12 16:06:27 +0800 | [diff] [blame] | 1040 | } |
Ninad Palsule | b33a432 | 2023-06-09 09:19:18 -0500 | [diff] [blame] | 1041 | else if (contentType.starts_with("multipart/form-data")) |
George Liu | 0ed80c8 | 2020-05-12 16:06:27 +0800 | [diff] [blame] | 1042 | { |
Ninad Palsule | b33a432 | 2023-06-09 09:19:18 -0500 | [diff] [blame] | 1043 | MultipartParser parser; |
| 1044 | |
Ninad Palsule | b33a432 | 2023-06-09 09:19:18 -0500 | [diff] [blame] | 1045 | ParserError ec = parser.parse(req); |
| 1046 | if (ec != ParserError::PARSER_SUCCESS) |
| 1047 | { |
| 1048 | // handle error |
Ed Tanous | 62598e3 | 2023-07-17 17:06:25 -0700 | [diff] [blame] | 1049 | BMCWEB_LOG_ERROR("MIME parse failed, ec : {}", |
| 1050 | static_cast<int>(ec)); |
Ninad Palsule | b33a432 | 2023-06-09 09:19:18 -0500 | [diff] [blame] | 1051 | messages::internalError(asyncResp->res); |
| 1052 | return; |
| 1053 | } |
Ed Tanous | 6b54e4e | 2024-04-10 08:58:48 -0700 | [diff] [blame] | 1054 | |
Jagpal Singh Gill | ef93eab | 2024-04-17 16:06:14 -0700 | [diff] [blame] | 1055 | updateMultipartContext(asyncResp, req, std::move(parser)); |
George Liu | 0ed80c8 | 2020-05-12 16:06:27 +0800 | [diff] [blame] | 1056 | } |
Ninad Palsule | b33a432 | 2023-06-09 09:19:18 -0500 | [diff] [blame] | 1057 | else |
| 1058 | { |
Ed Tanous | 62598e3 | 2023-07-17 17:06:25 -0700 | [diff] [blame] | 1059 | BMCWEB_LOG_DEBUG("Bad content type specified:{}", contentType); |
Ninad Palsule | b33a432 | 2023-06-09 09:19:18 -0500 | [diff] [blame] | 1060 | asyncResp->res.result(boost::beast::http::status::bad_request); |
| 1061 | } |
Ed Tanous | c2051d1 | 2022-05-11 12:21:55 -0700 | [diff] [blame] | 1062 | } |
| 1063 | |
Ed Tanous | f513933 | 2024-04-03 13:25:04 -0700 | [diff] [blame] | 1064 | inline void |
| 1065 | handleUpdateServiceGet(App& app, const crow::Request& req, |
| 1066 | const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 1067 | { |
Ed Tanous | f513933 | 2024-04-03 13:25:04 -0700 | [diff] [blame] | 1068 | if (!redfish::setUpRedfishRoute(app, req, asyncResp)) |
| 1069 | { |
| 1070 | return; |
| 1071 | } |
| 1072 | asyncResp->res.jsonValue["@odata.type"] = |
| 1073 | "#UpdateService.v1_11_1.UpdateService"; |
| 1074 | asyncResp->res.jsonValue["@odata.id"] = "/redfish/v1/UpdateService"; |
| 1075 | asyncResp->res.jsonValue["Id"] = "UpdateService"; |
| 1076 | asyncResp->res.jsonValue["Description"] = "Service for Software Update"; |
| 1077 | asyncResp->res.jsonValue["Name"] = "Update Service"; |
Ed Tanous | 4dc23f3 | 2022-05-11 11:32:19 -0700 | [diff] [blame] | 1078 | |
Ed Tanous | f513933 | 2024-04-03 13:25:04 -0700 | [diff] [blame] | 1079 | asyncResp->res.jsonValue["HttpPushUri"] = |
| 1080 | "/redfish/v1/UpdateService/update"; |
| 1081 | asyncResp->res.jsonValue["MultipartHttpPushUri"] = |
| 1082 | "/redfish/v1/UpdateService/update"; |
Ed Tanous | 4dc23f3 | 2022-05-11 11:32:19 -0700 | [diff] [blame] | 1083 | |
Ed Tanous | f513933 | 2024-04-03 13:25:04 -0700 | [diff] [blame] | 1084 | // UpdateService cannot be disabled |
| 1085 | asyncResp->res.jsonValue["ServiceEnabled"] = true; |
| 1086 | asyncResp->res.jsonValue["FirmwareInventory"]["@odata.id"] = |
| 1087 | "/redfish/v1/UpdateService/FirmwareInventory"; |
| 1088 | // Get the MaxImageSizeBytes |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 1089 | asyncResp->res.jsonValue["MaxImageSizeBytes"] = |
| 1090 | BMCWEB_HTTP_BODY_LIMIT * 1024 * 1024; |
Tejas Patil | d61e519 | 2021-06-04 15:49:35 +0530 | [diff] [blame] | 1091 | |
Ed Tanous | 6a37140 | 2024-12-03 14:01:25 -0800 | [diff] [blame] | 1092 | if constexpr (BMCWEB_REDFISH_ALLOW_SIMPLE_UPDATE) |
Ed Tanous | 25b54db | 2024-04-17 15:40:31 -0700 | [diff] [blame] | 1093 | { |
Ed Tanous | 6a37140 | 2024-12-03 14:01:25 -0800 | [diff] [blame] | 1094 | // Update Actions object. |
| 1095 | nlohmann::json& updateSvcSimpleUpdate = |
| 1096 | asyncResp->res.jsonValue["Actions"]["#UpdateService.SimpleUpdate"]; |
| 1097 | updateSvcSimpleUpdate["target"] = |
| 1098 | "/redfish/v1/UpdateService/Actions/UpdateService.SimpleUpdate"; |
Ed Tanous | 757178a | 2024-04-03 14:32:38 -0700 | [diff] [blame] | 1099 | |
Ed Tanous | 6a37140 | 2024-12-03 14:01:25 -0800 | [diff] [blame] | 1100 | nlohmann::json::array_t allowed; |
| 1101 | allowed.emplace_back(update_service::TransferProtocolType::HTTPS); |
| 1102 | updateSvcSimpleUpdate["TransferProtocol@Redfish.AllowableValues"] = |
| 1103 | std::move(allowed); |
| 1104 | } |
Ed Tanous | 757178a | 2024-04-03 14:32:38 -0700 | [diff] [blame] | 1105 | |
Ed Tanous | 539d8c6 | 2024-06-19 14:38:27 -0700 | [diff] [blame] | 1106 | asyncResp->res |
| 1107 | .jsonValue["HttpPushUriOptions"]["HttpPushUriApplyTime"]["ApplyTime"] = |
| 1108 | update_service::ApplyTime::Immediate; |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 1109 | } |
Ed Tanous | f513933 | 2024-04-03 13:25:04 -0700 | [diff] [blame] | 1110 | |
| 1111 | inline void handleUpdateServiceFirmwareInventoryCollectionGet( |
| 1112 | App& app, const crow::Request& req, |
| 1113 | const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) |
| 1114 | { |
| 1115 | if (!redfish::setUpRedfishRoute(app, req, asyncResp)) |
| 1116 | { |
| 1117 | return; |
| 1118 | } |
| 1119 | asyncResp->res.jsonValue["@odata.type"] = |
| 1120 | "#SoftwareInventoryCollection.SoftwareInventoryCollection"; |
| 1121 | asyncResp->res.jsonValue["@odata.id"] = |
| 1122 | "/redfish/v1/UpdateService/FirmwareInventory"; |
| 1123 | asyncResp->res.jsonValue["Name"] = "Software Inventory Collection"; |
| 1124 | const std::array<const std::string_view, 1> iface = { |
| 1125 | "xyz.openbmc_project.Software.Version"}; |
| 1126 | |
| 1127 | redfish::collection_util::getCollectionMembers( |
| 1128 | asyncResp, |
| 1129 | boost::urls::url("/redfish/v1/UpdateService/FirmwareInventory"), iface, |
| 1130 | "/xyz/openbmc_project/software"); |
| 1131 | } |
| 1132 | |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 1133 | /* Fill related item links (i.e. bmc, bios) in for inventory */ |
Ed Tanous | f513933 | 2024-04-03 13:25:04 -0700 | [diff] [blame] | 1134 | inline void getRelatedItems(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, |
| 1135 | const std::string& purpose) |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 1136 | { |
Willy Tu | eee0013 | 2022-06-14 14:53:17 -0700 | [diff] [blame] | 1137 | if (purpose == sw_util::bmcPurpose) |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 1138 | { |
Ed Tanous | ac106bf | 2023-06-07 09:24:59 -0700 | [diff] [blame] | 1139 | nlohmann::json& relatedItem = asyncResp->res.jsonValue["RelatedItem"]; |
Ed Tanous | 1476687 | 2022-03-15 10:44:42 -0700 | [diff] [blame] | 1140 | nlohmann::json::object_t item; |
Ed Tanous | 253f11b | 2024-05-16 09:38:31 -0700 | [diff] [blame] | 1141 | item["@odata.id"] = boost::urls::format( |
| 1142 | "/redfish/v1/Managers/{}", BMCWEB_REDFISH_MANAGER_URI_NAME); |
Patrick Williams | b2ba307 | 2023-05-12 10:27:39 -0500 | [diff] [blame] | 1143 | relatedItem.emplace_back(std::move(item)); |
Ed Tanous | ac106bf | 2023-06-07 09:24:59 -0700 | [diff] [blame] | 1144 | asyncResp->res.jsonValue["RelatedItem@odata.count"] = |
| 1145 | relatedItem.size(); |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 1146 | } |
Willy Tu | eee0013 | 2022-06-14 14:53:17 -0700 | [diff] [blame] | 1147 | else if (purpose == sw_util::biosPurpose) |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 1148 | { |
Ed Tanous | ac106bf | 2023-06-07 09:24:59 -0700 | [diff] [blame] | 1149 | nlohmann::json& relatedItem = asyncResp->res.jsonValue["RelatedItem"]; |
Ed Tanous | 1476687 | 2022-03-15 10:44:42 -0700 | [diff] [blame] | 1150 | nlohmann::json::object_t item; |
Ed Tanous | 253f11b | 2024-05-16 09:38:31 -0700 | [diff] [blame] | 1151 | item["@odata.id"] = std::format("/redfish/v1/Systems/{}/Bios", |
| 1152 | BMCWEB_REDFISH_SYSTEM_URI_NAME); |
Patrick Williams | b2ba307 | 2023-05-12 10:27:39 -0500 | [diff] [blame] | 1153 | relatedItem.emplace_back(std::move(item)); |
Ed Tanous | ac106bf | 2023-06-07 09:24:59 -0700 | [diff] [blame] | 1154 | asyncResp->res.jsonValue["RelatedItem@odata.count"] = |
| 1155 | relatedItem.size(); |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 1156 | } |
| 1157 | else |
| 1158 | { |
Carson Labrado | bf2dded | 2023-08-10 00:37:06 +0000 | [diff] [blame] | 1159 | BMCWEB_LOG_DEBUG("Unknown software purpose {}", purpose); |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 1160 | } |
| 1161 | } |
| 1162 | |
Willy Tu | af24660 | 2022-06-14 15:51:53 -0700 | [diff] [blame] | 1163 | inline void |
| 1164 | getSoftwareVersion(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, |
| 1165 | const std::string& service, const std::string& path, |
| 1166 | const std::string& swId) |
| 1167 | { |
Ed Tanous | deae6a7 | 2024-11-11 21:58:57 -0800 | [diff] [blame] | 1168 | dbus::utility::getAllProperties( |
| 1169 | service, path, "xyz.openbmc_project.Software.Version", |
Willy Tu | af24660 | 2022-06-14 15:51:53 -0700 | [diff] [blame] | 1170 | [asyncResp, |
Ed Tanous | 8b24275 | 2023-06-27 17:17:13 -0700 | [diff] [blame] | 1171 | swId](const boost::system::error_code& ec, |
Willy Tu | af24660 | 2022-06-14 15:51:53 -0700 | [diff] [blame] | 1172 | const dbus::utility::DBusPropertiesMap& propertiesList) { |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 1173 | if (ec) |
| 1174 | { |
| 1175 | messages::internalError(asyncResp->res); |
| 1176 | return; |
| 1177 | } |
Krzysztof Grobelny | d1bde9e | 2022-09-07 10:40:51 +0200 | [diff] [blame] | 1178 | |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 1179 | const std::string* swInvPurpose = nullptr; |
| 1180 | const std::string* version = nullptr; |
Krzysztof Grobelny | d1bde9e | 2022-09-07 10:40:51 +0200 | [diff] [blame] | 1181 | |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 1182 | const bool success = sdbusplus::unpackPropertiesNoThrow( |
| 1183 | dbus_utils::UnpackErrorPrinter(), propertiesList, "Purpose", |
| 1184 | swInvPurpose, "Version", version); |
Krzysztof Grobelny | d1bde9e | 2022-09-07 10:40:51 +0200 | [diff] [blame] | 1185 | |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 1186 | if (!success) |
| 1187 | { |
| 1188 | messages::internalError(asyncResp->res); |
| 1189 | return; |
| 1190 | } |
Willy Tu | af24660 | 2022-06-14 15:51:53 -0700 | [diff] [blame] | 1191 | |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 1192 | if (swInvPurpose == nullptr) |
| 1193 | { |
| 1194 | BMCWEB_LOG_DEBUG("Can't find property \"Purpose\"!"); |
| 1195 | messages::internalError(asyncResp->res); |
| 1196 | return; |
| 1197 | } |
Willy Tu | af24660 | 2022-06-14 15:51:53 -0700 | [diff] [blame] | 1198 | |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 1199 | BMCWEB_LOG_DEBUG("swInvPurpose = {}", *swInvPurpose); |
Willy Tu | af24660 | 2022-06-14 15:51:53 -0700 | [diff] [blame] | 1200 | |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 1201 | if (version == nullptr) |
| 1202 | { |
| 1203 | BMCWEB_LOG_DEBUG("Can't find property \"Version\"!"); |
Willy Tu | af24660 | 2022-06-14 15:51:53 -0700 | [diff] [blame] | 1204 | |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 1205 | messages::internalError(asyncResp->res); |
Willy Tu | af24660 | 2022-06-14 15:51:53 -0700 | [diff] [blame] | 1206 | |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 1207 | return; |
| 1208 | } |
| 1209 | asyncResp->res.jsonValue["Version"] = *version; |
| 1210 | asyncResp->res.jsonValue["Id"] = swId; |
Willy Tu | af24660 | 2022-06-14 15:51:53 -0700 | [diff] [blame] | 1211 | |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 1212 | // swInvPurpose is of format: |
| 1213 | // xyz.openbmc_project.Software.Version.VersionPurpose.ABC |
| 1214 | // Translate this to "ABC image" |
| 1215 | size_t endDesc = swInvPurpose->rfind('.'); |
| 1216 | if (endDesc == std::string::npos) |
| 1217 | { |
| 1218 | messages::internalError(asyncResp->res); |
| 1219 | return; |
| 1220 | } |
| 1221 | endDesc++; |
| 1222 | if (endDesc >= swInvPurpose->size()) |
| 1223 | { |
| 1224 | messages::internalError(asyncResp->res); |
| 1225 | return; |
| 1226 | } |
Willy Tu | af24660 | 2022-06-14 15:51:53 -0700 | [diff] [blame] | 1227 | |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 1228 | std::string formatDesc = swInvPurpose->substr(endDesc); |
| 1229 | asyncResp->res.jsonValue["Description"] = formatDesc + " image"; |
| 1230 | getRelatedItems(asyncResp, *swInvPurpose); |
| 1231 | }); |
Willy Tu | af24660 | 2022-06-14 15:51:53 -0700 | [diff] [blame] | 1232 | } |
| 1233 | |
Ed Tanous | f513933 | 2024-04-03 13:25:04 -0700 | [diff] [blame] | 1234 | inline void handleUpdateServiceFirmwareInventoryGet( |
| 1235 | App& app, const crow::Request& req, |
| 1236 | const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, |
| 1237 | const std::string& param) |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 1238 | { |
Ed Tanous | f513933 | 2024-04-03 13:25:04 -0700 | [diff] [blame] | 1239 | if (!redfish::setUpRedfishRoute(app, req, asyncResp)) |
| 1240 | { |
| 1241 | return; |
| 1242 | } |
| 1243 | std::shared_ptr<std::string> swId = std::make_shared<std::string>(param); |
| 1244 | |
| 1245 | asyncResp->res.jsonValue["@odata.id"] = boost::urls::format( |
| 1246 | "/redfish/v1/UpdateService/FirmwareInventory/{}", *swId); |
| 1247 | |
| 1248 | constexpr std::array<std::string_view, 1> interfaces = { |
| 1249 | "xyz.openbmc_project.Software.Version"}; |
| 1250 | dbus::utility::getSubTree( |
| 1251 | "/", 0, interfaces, |
| 1252 | [asyncResp, |
| 1253 | swId](const boost::system::error_code& ec, |
| 1254 | const dbus::utility::MapperGetSubTreeResponse& subtree) { |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 1255 | BMCWEB_LOG_DEBUG("doGet callback..."); |
| 1256 | if (ec) |
Ed Tanous | 45ca1b8 | 2022-03-25 13:07:27 -0700 | [diff] [blame] | 1257 | { |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 1258 | messages::internalError(asyncResp->res); |
| 1259 | return; |
Ed Tanous | 45ca1b8 | 2022-03-25 13:07:27 -0700 | [diff] [blame] | 1260 | } |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 1261 | |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 1262 | // Ensure we find our input swId, otherwise return an error |
| 1263 | bool found = false; |
| 1264 | for (const std::pair<std::string, |
| 1265 | std::vector<std::pair< |
| 1266 | std::string, std::vector<std::string>>>>& |
| 1267 | obj : subtree) |
Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 1268 | { |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 1269 | if (!obj.first.ends_with(*swId)) |
| 1270 | { |
| 1271 | continue; |
| 1272 | } |
| 1273 | |
| 1274 | if (obj.second.empty()) |
| 1275 | { |
| 1276 | continue; |
| 1277 | } |
| 1278 | |
| 1279 | found = true; |
| 1280 | sw_util::getSwStatus(asyncResp, swId, obj.second[0].first); |
| 1281 | getSoftwareVersion(asyncResp, obj.second[0].first, obj.first, |
| 1282 | *swId); |
Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 1283 | } |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 1284 | if (!found) |
| 1285 | { |
| 1286 | BMCWEB_LOG_WARNING("Input swID {} not found!", *swId); |
| 1287 | messages::resourceMissingAtURI( |
| 1288 | asyncResp->res, |
| 1289 | boost::urls::format( |
| 1290 | "/redfish/v1/UpdateService/FirmwareInventory/{}", |
| 1291 | *swId)); |
| 1292 | return; |
| 1293 | } |
| 1294 | asyncResp->res.jsonValue["@odata.type"] = |
| 1295 | "#SoftwareInventory.v1_1_0.SoftwareInventory"; |
| 1296 | asyncResp->res.jsonValue["Name"] = "Software Inventory"; |
| 1297 | asyncResp->res.jsonValue["Status"]["HealthRollup"] = |
| 1298 | resource::Health::OK; |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 1299 | |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 1300 | asyncResp->res.jsonValue["Updateable"] = false; |
| 1301 | sw_util::getSwUpdatableStatus(asyncResp, swId); |
| 1302 | }); |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 1303 | } |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 1304 | |
Ed Tanous | f513933 | 2024-04-03 13:25:04 -0700 | [diff] [blame] | 1305 | inline void requestRoutesUpdateService(App& app) |
| 1306 | { |
Ed Tanous | 6a37140 | 2024-12-03 14:01:25 -0800 | [diff] [blame] | 1307 | if constexpr (BMCWEB_REDFISH_ALLOW_SIMPLE_UPDATE) |
| 1308 | { |
| 1309 | BMCWEB_ROUTE( |
| 1310 | app, |
| 1311 | "/redfish/v1/UpdateService/Actions/UpdateService.SimpleUpdate/") |
| 1312 | .privileges(redfish::privileges::postUpdateService) |
| 1313 | .methods(boost::beast::http::verb::post)(std::bind_front( |
| 1314 | handleUpdateServiceSimpleUpdateAction, std::ref(app))); |
| 1315 | } |
Ed Tanous | f513933 | 2024-04-03 13:25:04 -0700 | [diff] [blame] | 1316 | BMCWEB_ROUTE(app, "/redfish/v1/UpdateService/FirmwareInventory/<str>/") |
| 1317 | .privileges(redfish::privileges::getSoftwareInventory) |
| 1318 | .methods(boost::beast::http::verb::get)(std::bind_front( |
| 1319 | handleUpdateServiceFirmwareInventoryGet, std::ref(app))); |
| 1320 | |
| 1321 | BMCWEB_ROUTE(app, "/redfish/v1/UpdateService/") |
| 1322 | .privileges(redfish::privileges::getUpdateService) |
| 1323 | .methods(boost::beast::http::verb::get)( |
| 1324 | std::bind_front(handleUpdateServiceGet, std::ref(app))); |
| 1325 | |
Ed Tanous | f513933 | 2024-04-03 13:25:04 -0700 | [diff] [blame] | 1326 | BMCWEB_ROUTE(app, "/redfish/v1/UpdateService/update/") |
| 1327 | .privileges(redfish::privileges::postUpdateService) |
| 1328 | .methods(boost::beast::http::verb::post)( |
| 1329 | std::bind_front(handleUpdateServicePost, std::ref(app))); |
| 1330 | |
| 1331 | BMCWEB_ROUTE(app, "/redfish/v1/UpdateService/FirmwareInventory/") |
| 1332 | .privileges(redfish::privileges::getSoftwareInventoryCollection) |
| 1333 | .methods(boost::beast::http::verb::get)(std::bind_front( |
| 1334 | handleUpdateServiceFirmwareInventoryCollectionGet, std::ref(app))); |
| 1335 | } |
| 1336 | |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 1337 | } // namespace redfish |