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