Jennifer Lee | 729dae7 | 2018-04-24 15:59:34 -0700 | [diff] [blame] | 1 | /* |
| 2 | // Copyright (c) 2018 Intel Corporation |
| 3 | // |
| 4 | // Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | // you may not use this file except in compliance with the License. |
| 6 | // You may obtain a copy of the License at |
| 7 | // |
| 8 | // http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | // |
| 10 | // Unless required by applicable law or agreed to in writing, software |
| 11 | // distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | // See the License for the specific language governing permissions and |
| 14 | // limitations under the License. |
| 15 | */ |
| 16 | #pragma once |
| 17 | |
Tejas Patil | d61e519 | 2021-06-04 15:49:35 +0530 | [diff] [blame] | 18 | #include "bmcweb_config.h" |
| 19 | |
Ed Tanous | 3ccb3ad | 2023-01-13 17:40:03 -0800 | [diff] [blame] | 20 | #include "app.hpp" |
| 21 | #include "dbus_utility.hpp" |
George Liu | 0ed80c8 | 2020-05-12 16:06:27 +0800 | [diff] [blame] | 22 | #include "multipart_parser.hpp" |
Ed Tanous | 2c6ffdb | 2023-06-28 11:28:38 -0700 | [diff] [blame] | 23 | #include "ossl_random.hpp" |
Ed Tanous | 3ccb3ad | 2023-01-13 17:40:03 -0800 | [diff] [blame] | 24 | #include "query.hpp" |
| 25 | #include "registries/privilege_registry.hpp" |
Ed Tanous | a8e884f | 2023-01-13 17:40:03 -0800 | [diff] [blame] | 26 | #include "task.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" |
| 29 | #include "utils/sw_utils.hpp" |
| 30 | |
George Liu | e99073f | 2022-12-09 11:06:16 +0800 | [diff] [blame] | 31 | #include <boost/system/error_code.hpp> |
Ed Tanous | ef4c65b | 2023-04-24 15:28:50 -0700 | [diff] [blame] | 32 | #include <boost/url/format.hpp> |
Jonathan Doman | 1e1e598 | 2021-06-11 09:36:17 -0700 | [diff] [blame] | 33 | #include <sdbusplus/asio/property.hpp> |
Ed Tanous | 3ccb3ad | 2023-01-13 17:40:03 -0800 | [diff] [blame] | 34 | #include <sdbusplus/bus/match.hpp> |
Krzysztof Grobelny | d1bde9e | 2022-09-07 10:40:51 +0200 | [diff] [blame] | 35 | #include <sdbusplus/unpack_properties.hpp> |
Gunnar Mills | 1214b7e | 2020-06-04 10:11:30 -0500 | [diff] [blame] | 36 | |
George Liu | 2b73119 | 2023-01-11 16:27:13 +0800 | [diff] [blame] | 37 | #include <array> |
George Liu | 0ed80c8 | 2020-05-12 16:06:27 +0800 | [diff] [blame] | 38 | #include <filesystem> |
George Liu | 2b73119 | 2023-01-11 16:27:13 +0800 | [diff] [blame] | 39 | #include <string_view> |
| 40 | |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 41 | namespace redfish |
| 42 | { |
Ed Tanous | 27826b5 | 2018-10-29 11:40:58 -0700 | [diff] [blame] | 43 | |
Andrew Geissler | 0e7de46 | 2019-03-04 19:11:54 -0600 | [diff] [blame] | 44 | // Match signals added on software path |
Ed Tanous | cf9e417 | 2022-12-21 09:30:16 -0800 | [diff] [blame] | 45 | // NOLINTNEXTLINE(cppcoreguidelines-avoid-non-const-global-variables) |
Patrick Williams | 59d494e | 2022-07-22 19:26:55 -0500 | [diff] [blame] | 46 | static std::unique_ptr<sdbusplus::bus::match_t> fwUpdateMatcher; |
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> fwUpdateErrorMatcher; |
Andrew Geissler | 0e7de46 | 2019-03-04 19:11:54 -0600 | [diff] [blame] | 49 | // Only allow one update at a time |
Ed Tanous | cf9e417 | 2022-12-21 09:30:16 -0800 | [diff] [blame] | 50 | // NOLINTNEXTLINE(cppcoreguidelines-avoid-non-const-global-variables) |
Andrew Geissler | 0e7de46 | 2019-03-04 19:11:54 -0600 | [diff] [blame] | 51 | static bool fwUpdateInProgress = false; |
Andrew Geissler | 86adcd6 | 2019-04-18 10:58:05 -0500 | [diff] [blame] | 52 | // Timer for software available |
Ed Tanous | cf9e417 | 2022-12-21 09:30:16 -0800 | [diff] [blame] | 53 | // NOLINTNEXTLINE(cppcoreguidelines-avoid-non-const-global-variables) |
Ed Tanous | 271584a | 2019-07-09 16:24:22 -0700 | [diff] [blame] | 54 | static std::unique_ptr<boost::asio::steady_timer> fwAvailableTimer; |
Andrew Geissler | 86adcd6 | 2019-04-18 10:58:05 -0500 | [diff] [blame] | 55 | |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 56 | inline static void cleanUp() |
Andrew Geissler | 86adcd6 | 2019-04-18 10:58:05 -0500 | [diff] [blame] | 57 | { |
| 58 | fwUpdateInProgress = false; |
| 59 | fwUpdateMatcher = nullptr; |
James Feist | 4cde5d9 | 2020-06-11 10:39:55 -0700 | [diff] [blame] | 60 | fwUpdateErrorMatcher = nullptr; |
Andrew Geissler | 86adcd6 | 2019-04-18 10:58:05 -0500 | [diff] [blame] | 61 | } |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 62 | inline static void activateImage(const std::string& objPath, |
| 63 | const std::string& service) |
Andrew Geissler | 86adcd6 | 2019-04-18 10:58:05 -0500 | [diff] [blame] | 64 | { |
Ed Tanous | 62598e3 | 2023-07-17 17:06:25 -0700 | [diff] [blame] | 65 | BMCWEB_LOG_DEBUG("Activate image for {} {}", objPath, service); |
George Liu | 9ae226f | 2023-06-21 17:56:46 +0800 | [diff] [blame] | 66 | sdbusplus::asio::setProperty( |
| 67 | *crow::connections::systemBus, service, objPath, |
| 68 | "xyz.openbmc_project.Software.Activation", "RequestedActivation", |
| 69 | "xyz.openbmc_project.Software.Activation.RequestedActivations.Active", |
Ed Tanous | 8b24275 | 2023-06-27 17:17:13 -0700 | [diff] [blame] | 70 | [](const boost::system::error_code& ec) { |
| 71 | if (ec) |
Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 72 | { |
Ed Tanous | 62598e3 | 2023-07-17 17:06:25 -0700 | [diff] [blame] | 73 | BMCWEB_LOG_DEBUG("error_code = {}", ec); |
| 74 | BMCWEB_LOG_DEBUG("error msg = {}", ec.message()); |
Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 75 | } |
Patrick Williams | 5a39f77 | 2023-10-20 11:20:21 -0500 | [diff] [blame] | 76 | }); |
Andrew Geissler | 86adcd6 | 2019-04-18 10:58:05 -0500 | [diff] [blame] | 77 | } |
Andrew Geissler | 0554c98 | 2019-04-23 14:40:12 -0500 | [diff] [blame] | 78 | |
| 79 | // Note that asyncResp can be either a valid pointer or nullptr. If nullptr |
| 80 | // then no asyncResp updates will occur |
zhanghch05 | 8d1b46d | 2021-04-01 11:18:24 +0800 | [diff] [blame] | 81 | static void |
| 82 | softwareInterfaceAdded(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, |
Patrick Williams | 59d494e | 2022-07-22 19:26:55 -0500 | [diff] [blame] | 83 | sdbusplus::message_t& m, task::Payload&& payload) |
Andrew Geissler | 86adcd6 | 2019-04-18 10:58:05 -0500 | [diff] [blame] | 84 | { |
Michael Shen | 80f79a4 | 2023-08-24 13:41:53 +0000 | [diff] [blame] | 85 | dbus::utility::DBusInterfacesMap interfacesProperties; |
Andrew Geissler | 86adcd6 | 2019-04-18 10:58:05 -0500 | [diff] [blame] | 86 | |
| 87 | sdbusplus::message::object_path objPath; |
| 88 | |
| 89 | m.read(objPath, interfacesProperties); |
| 90 | |
Ed Tanous | 62598e3 | 2023-07-17 17:06:25 -0700 | [diff] [blame] | 91 | BMCWEB_LOG_DEBUG("obj path = {}", objPath.str); |
Ed Tanous | e3eb3d6 | 2022-12-21 11:56:07 -0800 | [diff] [blame] | 92 | for (const auto& interface : interfacesProperties) |
Andrew Geissler | 86adcd6 | 2019-04-18 10:58:05 -0500 | [diff] [blame] | 93 | { |
Ed Tanous | 62598e3 | 2023-07-17 17:06:25 -0700 | [diff] [blame] | 94 | BMCWEB_LOG_DEBUG("interface = {}", interface.first); |
Andrew Geissler | 86adcd6 | 2019-04-18 10:58:05 -0500 | [diff] [blame] | 95 | |
| 96 | if (interface.first == "xyz.openbmc_project.Software.Activation") |
| 97 | { |
Andrew Geissler | 86adcd6 | 2019-04-18 10:58:05 -0500 | [diff] [blame] | 98 | // Retrieve service and activate |
George Liu | 2b73119 | 2023-01-11 16:27:13 +0800 | [diff] [blame] | 99 | constexpr std::array<std::string_view, 1> interfaces = { |
| 100 | "xyz.openbmc_project.Software.Activation"}; |
| 101 | dbus::utility::getDbusObject( |
| 102 | objPath.str, interfaces, |
Ed Tanous | a3e6589 | 2021-09-16 14:13:20 -0700 | [diff] [blame] | 103 | [objPath, asyncResp, payload(std::move(payload))]( |
Ed Tanous | 8b24275 | 2023-06-27 17:17:13 -0700 | [diff] [blame] | 104 | const boost::system::error_code& ec, |
Ed Tanous | a3e6589 | 2021-09-16 14:13:20 -0700 | [diff] [blame] | 105 | const std::vector< |
| 106 | std::pair<std::string, std::vector<std::string>>>& |
| 107 | objInfo) mutable { |
Ed Tanous | 8b24275 | 2023-06-27 17:17:13 -0700 | [diff] [blame] | 108 | if (ec) |
Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 109 | { |
Ed Tanous | 62598e3 | 2023-07-17 17:06:25 -0700 | [diff] [blame] | 110 | BMCWEB_LOG_DEBUG("error_code = {}", ec); |
| 111 | BMCWEB_LOG_DEBUG("error msg = {}", ec.message()); |
Andrew Geissler | 0554c98 | 2019-04-23 14:40:12 -0500 | [diff] [blame] | 112 | if (asyncResp) |
| 113 | { |
Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 114 | messages::internalError(asyncResp->res); |
| 115 | } |
| 116 | cleanUp(); |
| 117 | return; |
| 118 | } |
| 119 | // Ensure we only got one service back |
| 120 | if (objInfo.size() != 1) |
| 121 | { |
Ed Tanous | 62598e3 | 2023-07-17 17:06:25 -0700 | [diff] [blame] | 122 | BMCWEB_LOG_ERROR("Invalid Object Size {}", objInfo.size()); |
Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 123 | if (asyncResp) |
| 124 | { |
| 125 | messages::internalError(asyncResp->res); |
| 126 | } |
| 127 | cleanUp(); |
| 128 | return; |
| 129 | } |
| 130 | // cancel timer only when |
| 131 | // xyz.openbmc_project.Software.Activation interface |
| 132 | // is added |
| 133 | fwAvailableTimer = nullptr; |
| 134 | |
| 135 | activateImage(objPath.str, objInfo[0].first); |
| 136 | if (asyncResp) |
| 137 | { |
| 138 | std::shared_ptr<task::TaskData> task = |
| 139 | task::TaskData::createTask( |
Ed Tanous | 8b24275 | 2023-06-27 17:17:13 -0700 | [diff] [blame] | 140 | [](const boost::system::error_code& ec2, |
Patrick Williams | 59d494e | 2022-07-22 19:26:55 -0500 | [diff] [blame] | 141 | sdbusplus::message_t& msg, |
Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 142 | const std::shared_ptr<task::TaskData>& |
| 143 | taskData) { |
Ed Tanous | 8b24275 | 2023-06-27 17:17:13 -0700 | [diff] [blame] | 144 | if (ec2) |
Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 145 | { |
| 146 | return task::completed; |
| 147 | } |
| 148 | |
| 149 | std::string iface; |
| 150 | dbus::utility::DBusPropertiesMap values; |
| 151 | |
| 152 | std::string index = std::to_string(taskData->index); |
| 153 | msg.read(iface, values); |
| 154 | |
| 155 | if (iface == "xyz.openbmc_project.Software.Activation") |
| 156 | { |
Gayathri Leburu | 0fb5b50 | 2022-11-17 04:51:55 +0000 | [diff] [blame] | 157 | const std::string* state = nullptr; |
Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 158 | for (const auto& property : values) |
| 159 | { |
| 160 | if (property.first == "Activation") |
| 161 | { |
Gayathri Leburu | 0fb5b50 | 2022-11-17 04:51:55 +0000 | [diff] [blame] | 162 | state = std::get_if<std::string>( |
| 163 | &property.second); |
| 164 | if (state == nullptr) |
James Feist | 32898ce | 2020-03-10 16:16:52 -0700 | [diff] [blame] | 165 | { |
Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 166 | taskData->messages.emplace_back( |
| 167 | messages::internalError()); |
James Feist | 32898ce | 2020-03-10 16:16:52 -0700 | [diff] [blame] | 168 | return task::completed; |
| 169 | } |
Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 170 | } |
| 171 | } |
James Feist | 32898ce | 2020-03-10 16:16:52 -0700 | [diff] [blame] | 172 | |
Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 173 | if (state == nullptr) |
| 174 | { |
| 175 | return !task::completed; |
| 176 | } |
James Feist | 32898ce | 2020-03-10 16:16:52 -0700 | [diff] [blame] | 177 | |
Ed Tanous | 11ba397 | 2022-07-11 09:50:41 -0700 | [diff] [blame] | 178 | if (state->ends_with("Invalid") || |
| 179 | state->ends_with("Failed")) |
Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 180 | { |
| 181 | taskData->state = "Exception"; |
| 182 | taskData->status = "Warning"; |
| 183 | taskData->messages.emplace_back( |
| 184 | messages::taskAborted(index)); |
| 185 | return task::completed; |
| 186 | } |
James Feist | e5d5006 | 2020-05-11 17:29:00 -0700 | [diff] [blame] | 187 | |
Ed Tanous | 11ba397 | 2022-07-11 09:50:41 -0700 | [diff] [blame] | 188 | if (state->ends_with("Staged")) |
Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 189 | { |
| 190 | taskData->state = "Stopping"; |
| 191 | taskData->messages.emplace_back( |
| 192 | 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 |
Ed Tanous | 8ece0e4 | 2024-01-02 13:16:50 -0800 | [diff] [blame] | 198 | // task will be canceled |
Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 199 | taskData->extendTimer(std::chrono::hours(5)); |
| 200 | return !task::completed; |
| 201 | } |
| 202 | |
Ed Tanous | 11ba397 | 2022-07-11 09:50:41 -0700 | [diff] [blame] | 203 | if (state->ends_with("Active")) |
Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 204 | { |
| 205 | taskData->messages.emplace_back( |
| 206 | messages::taskCompletedOK(index)); |
| 207 | taskData->state = "Completed"; |
| 208 | return task::completed; |
| 209 | } |
| 210 | } |
| 211 | else if ( |
| 212 | iface == |
| 213 | "xyz.openbmc_project.Software.ActivationProgress") |
| 214 | { |
Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 215 | const uint8_t* progress = nullptr; |
| 216 | for (const auto& property : values) |
| 217 | { |
| 218 | if (property.first == "Progress") |
| 219 | { |
Gayathri Leburu | 0fb5b50 | 2022-11-17 04:51:55 +0000 | [diff] [blame] | 220 | progress = |
| 221 | std::get_if<uint8_t>(&property.second); |
| 222 | if (progress == nullptr) |
James Feist | 32898ce | 2020-03-10 16:16:52 -0700 | [diff] [blame] | 223 | { |
James Feist | 32898ce | 2020-03-10 16:16:52 -0700 | [diff] [blame] | 224 | taskData->messages.emplace_back( |
Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 225 | messages::internalError()); |
| 226 | return task::completed; |
James Feist | 32898ce | 2020-03-10 16:16:52 -0700 | [diff] [blame] | 227 | } |
Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 228 | } |
| 229 | } |
James Feist | 32898ce | 2020-03-10 16:16:52 -0700 | [diff] [blame] | 230 | |
Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 231 | if (progress == nullptr) |
| 232 | { |
| 233 | return !task::completed; |
| 234 | } |
Gayathri Leburu | 0fb5b50 | 2022-11-17 04:51:55 +0000 | [diff] [blame] | 235 | taskData->percentComplete = *progress; |
Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 236 | taskData->messages.emplace_back( |
Gayathri Leburu | 0fb5b50 | 2022-11-17 04:51:55 +0000 | [diff] [blame] | 237 | messages::taskProgressChanged(index, |
| 238 | *progress)); |
James Feist | 32898ce | 2020-03-10 16:16:52 -0700 | [diff] [blame] | 239 | |
Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 240 | // if we're getting status updates it's |
| 241 | // still alive, update timer |
| 242 | taskData->extendTimer(std::chrono::minutes(5)); |
| 243 | } |
| 244 | |
| 245 | // as firmware update often results in a |
| 246 | // reboot, the task may never "complete" |
| 247 | // unless it is an error |
| 248 | |
| 249 | return !task::completed; |
Patrick Williams | 5a39f77 | 2023-10-20 11:20:21 -0500 | [diff] [blame] | 250 | }, |
Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 251 | "type='signal',interface='org.freedesktop.DBus.Properties'," |
| 252 | "member='PropertiesChanged',path='" + |
| 253 | objPath.str + "'"); |
| 254 | task->startTimer(std::chrono::minutes(5)); |
| 255 | task->populateResp(asyncResp->res); |
| 256 | task->payload.emplace(std::move(payload)); |
| 257 | } |
| 258 | fwUpdateInProgress = false; |
Patrick Williams | 5a39f77 | 2023-10-20 11:20:21 -0500 | [diff] [blame] | 259 | }); |
Patrick Williams | 62bafc0 | 2022-09-08 17:35:35 -0500 | [diff] [blame] | 260 | |
| 261 | break; |
Andrew Geissler | 86adcd6 | 2019-04-18 10:58:05 -0500 | [diff] [blame] | 262 | } |
| 263 | } |
| 264 | } |
| 265 | |
Myung Bae | 8549b95 | 2023-08-16 15:18:19 -0400 | [diff] [blame] | 266 | inline void afterAvailbleTimerAsyncWait( |
| 267 | const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, |
| 268 | const boost::system::error_code& ec) |
| 269 | { |
| 270 | cleanUp(); |
| 271 | if (ec == boost::asio::error::operation_aborted) |
| 272 | { |
| 273 | // expected, we were canceled before the timer completed. |
| 274 | return; |
| 275 | } |
| 276 | BMCWEB_LOG_ERROR("Timed out waiting for firmware object being created"); |
| 277 | BMCWEB_LOG_ERROR("FW image may has already been uploaded to server"); |
| 278 | if (ec) |
| 279 | { |
| 280 | BMCWEB_LOG_ERROR("Async_wait failed{}", ec); |
| 281 | return; |
| 282 | } |
| 283 | if (asyncResp) |
| 284 | { |
| 285 | redfish::messages::internalError(asyncResp->res); |
| 286 | } |
| 287 | } |
| 288 | |
| 289 | inline void |
| 290 | handleUpdateErrorType(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, |
| 291 | const std::string& url, const std::string& type) |
| 292 | { |
| 293 | if (type == "xyz.openbmc_project.Software.Image.Error.UnTarFailure") |
| 294 | { |
| 295 | redfish::messages::invalidUpload(asyncResp->res, url, |
| 296 | "Invalid archive"); |
| 297 | } |
| 298 | else if (type == |
| 299 | "xyz.openbmc_project.Software.Image.Error.ManifestFileFailure") |
| 300 | { |
| 301 | redfish::messages::invalidUpload(asyncResp->res, url, |
| 302 | "Invalid manifest"); |
| 303 | } |
| 304 | else if (type == "xyz.openbmc_project.Software.Image.Error.ImageFailure") |
| 305 | { |
| 306 | redfish::messages::invalidUpload(asyncResp->res, url, |
| 307 | "Invalid image format"); |
| 308 | } |
| 309 | else if (type == "xyz.openbmc_project.Software.Version.Error.AlreadyExists") |
| 310 | { |
| 311 | redfish::messages::invalidUpload(asyncResp->res, url, |
| 312 | "Image version already exists"); |
| 313 | |
| 314 | redfish::messages::resourceAlreadyExists( |
| 315 | asyncResp->res, "UpdateService", "Version", "uploaded version"); |
| 316 | } |
| 317 | else if (type == "xyz.openbmc_project.Software.Image.Error.BusyFailure") |
| 318 | { |
| 319 | redfish::messages::resourceExhaustion(asyncResp->res, url); |
| 320 | } |
Myung Bae | 4034a65 | 2023-08-17 08:47:35 -0400 | [diff] [blame] | 321 | else if (type == "xyz.openbmc_project.Software.Version.Error.Incompatible") |
Myung Bae | 8549b95 | 2023-08-16 15:18:19 -0400 | [diff] [blame] | 322 | { |
Myung Bae | 4034a65 | 2023-08-17 08:47:35 -0400 | [diff] [blame] | 323 | redfish::messages::invalidUpload(asyncResp->res, url, |
| 324 | "Incompatible image version"); |
| 325 | } |
| 326 | else if (type == |
| 327 | "xyz.openbmc_project.Software.Version.Error.ExpiredAccessKey") |
| 328 | { |
| 329 | redfish::messages::invalidUpload(asyncResp->res, url, |
| 330 | "Update Access Key Expired"); |
| 331 | } |
| 332 | else if (type == |
| 333 | "xyz.openbmc_project.Software.Version.Error.InvalidSignature") |
| 334 | { |
| 335 | redfish::messages::invalidUpload(asyncResp->res, url, |
| 336 | "Invalid image signature"); |
| 337 | } |
| 338 | else if (type == |
| 339 | "xyz.openbmc_project.Software.Image.Error.InternalFailure" || |
| 340 | type == "xyz.openbmc_project.Software.Version.Error.HostFile") |
| 341 | { |
| 342 | BMCWEB_LOG_ERROR("Software Image Error type={}", type); |
Myung Bae | 8549b95 | 2023-08-16 15:18:19 -0400 | [diff] [blame] | 343 | redfish::messages::internalError(asyncResp->res); |
| 344 | } |
Myung Bae | 4034a65 | 2023-08-17 08:47:35 -0400 | [diff] [blame] | 345 | else |
| 346 | { |
| 347 | // Unrelated error types. Ignored |
| 348 | BMCWEB_LOG_INFO("Non-Software-related Error type={}. Ignored", type); |
| 349 | return; |
| 350 | } |
| 351 | // Clear the timer |
| 352 | fwAvailableTimer = nullptr; |
Myung Bae | 8549b95 | 2023-08-16 15:18:19 -0400 | [diff] [blame] | 353 | } |
| 354 | |
| 355 | inline void |
| 356 | afterUpdateErrorMatcher(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, |
| 357 | const std::string& url, sdbusplus::message_t& m) |
| 358 | { |
Michael Shen | 80f79a4 | 2023-08-24 13:41:53 +0000 | [diff] [blame] | 359 | dbus::utility::DBusInterfacesMap interfacesProperties; |
Myung Bae | 8549b95 | 2023-08-16 15:18:19 -0400 | [diff] [blame] | 360 | sdbusplus::message::object_path objPath; |
| 361 | m.read(objPath, interfacesProperties); |
| 362 | BMCWEB_LOG_DEBUG("obj path = {}", objPath.str); |
| 363 | for (const std::pair<std::string, dbus::utility::DBusPropertiesMap>& |
| 364 | interface : interfacesProperties) |
| 365 | { |
| 366 | if (interface.first == "xyz.openbmc_project.Logging.Entry") |
| 367 | { |
| 368 | for (const std::pair<std::string, dbus::utility::DbusVariantType>& |
| 369 | value : interface.second) |
| 370 | { |
| 371 | if (value.first != "Message") |
| 372 | { |
| 373 | continue; |
| 374 | } |
| 375 | const std::string* type = |
| 376 | std::get_if<std::string>(&value.second); |
| 377 | if (type == nullptr) |
| 378 | { |
| 379 | // if this was our message, timeout will cover it |
| 380 | return; |
| 381 | } |
Myung Bae | 8549b95 | 2023-08-16 15:18:19 -0400 | [diff] [blame] | 382 | handleUpdateErrorType(asyncResp, url, *type); |
| 383 | } |
| 384 | } |
| 385 | } |
| 386 | } |
| 387 | |
Andrew Geissler | 0554c98 | 2019-04-23 14:40:12 -0500 | [diff] [blame] | 388 | // Note that asyncResp can be either a valid pointer or nullptr. If nullptr |
| 389 | // then no asyncResp updates will occur |
Ed Tanous | b5a7693 | 2020-09-29 16:16:58 -0700 | [diff] [blame] | 390 | static void monitorForSoftwareAvailable( |
zhanghch05 | 8d1b46d | 2021-04-01 11:18:24 +0800 | [diff] [blame] | 391 | const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, |
| 392 | const crow::Request& req, const std::string& url, |
Gunnar Mills | 5d13894 | 2022-09-07 10:26:21 -0500 | [diff] [blame] | 393 | int timeoutTimeSeconds = 25) |
Andrew Geissler | 86adcd6 | 2019-04-18 10:58:05 -0500 | [diff] [blame] | 394 | { |
| 395 | // Only allow one FW update at a time |
Ed Tanous | e05aec5 | 2022-01-25 10:28:56 -0800 | [diff] [blame] | 396 | if (fwUpdateInProgress) |
Andrew Geissler | 86adcd6 | 2019-04-18 10:58:05 -0500 | [diff] [blame] | 397 | { |
Andrew Geissler | 0554c98 | 2019-04-23 14:40:12 -0500 | [diff] [blame] | 398 | if (asyncResp) |
| 399 | { |
Andrew Geissler | 0554c98 | 2019-04-23 14:40:12 -0500 | [diff] [blame] | 400 | messages::serviceTemporarilyUnavailable(asyncResp->res, "30"); |
| 401 | } |
Andrew Geissler | 86adcd6 | 2019-04-18 10:58:05 -0500 | [diff] [blame] | 402 | return; |
| 403 | } |
| 404 | |
Andrew Geissler | 0554c98 | 2019-04-23 14:40:12 -0500 | [diff] [blame] | 405 | fwAvailableTimer = |
Ed Tanous | 271584a | 2019-07-09 16:24:22 -0700 | [diff] [blame] | 406 | std::make_unique<boost::asio::steady_timer>(*req.ioService); |
Andrew Geissler | 86adcd6 | 2019-04-18 10:58:05 -0500 | [diff] [blame] | 407 | |
Ed Tanous | 271584a | 2019-07-09 16:24:22 -0700 | [diff] [blame] | 408 | fwAvailableTimer->expires_after(std::chrono::seconds(timeoutTimeSeconds)); |
Andrew Geissler | 86adcd6 | 2019-04-18 10:58:05 -0500 | [diff] [blame] | 409 | |
| 410 | fwAvailableTimer->async_wait( |
Myung Bae | 8549b95 | 2023-08-16 15:18:19 -0400 | [diff] [blame] | 411 | std::bind_front(afterAvailbleTimerAsyncWait, asyncResp)); |
| 412 | |
Ed Tanous | a3e6589 | 2021-09-16 14:13:20 -0700 | [diff] [blame] | 413 | task::Payload payload(req); |
Patrick Williams | 59d494e | 2022-07-22 19:26:55 -0500 | [diff] [blame] | 414 | auto callback = [asyncResp, payload](sdbusplus::message_t& m) mutable { |
Ed Tanous | 62598e3 | 2023-07-17 17:06:25 -0700 | [diff] [blame] | 415 | BMCWEB_LOG_DEBUG("Match fired"); |
Ed Tanous | a3e6589 | 2021-09-16 14:13:20 -0700 | [diff] [blame] | 416 | softwareInterfaceAdded(asyncResp, m, std::move(payload)); |
Andrew Geissler | 86adcd6 | 2019-04-18 10:58:05 -0500 | [diff] [blame] | 417 | }; |
| 418 | |
| 419 | fwUpdateInProgress = true; |
| 420 | |
Patrick Williams | 59d494e | 2022-07-22 19:26:55 -0500 | [diff] [blame] | 421 | fwUpdateMatcher = std::make_unique<sdbusplus::bus::match_t>( |
Andrew Geissler | 86adcd6 | 2019-04-18 10:58:05 -0500 | [diff] [blame] | 422 | *crow::connections::systemBus, |
| 423 | "interface='org.freedesktop.DBus.ObjectManager',type='signal'," |
| 424 | "member='InterfacesAdded',path='/xyz/openbmc_project/software'", |
| 425 | callback); |
James Feist | 4cde5d9 | 2020-06-11 10:39:55 -0700 | [diff] [blame] | 426 | |
Patrick Williams | 59d494e | 2022-07-22 19:26:55 -0500 | [diff] [blame] | 427 | fwUpdateErrorMatcher = std::make_unique<sdbusplus::bus::match_t>( |
James Feist | 4cde5d9 | 2020-06-11 10:39:55 -0700 | [diff] [blame] | 428 | *crow::connections::systemBus, |
Brian Ma | e1cc482 | 2021-12-01 17:05:54 +0800 | [diff] [blame] | 429 | "interface='org.freedesktop.DBus.ObjectManager',type='signal'," |
| 430 | "member='InterfacesAdded'," |
| 431 | "path='/xyz/openbmc_project/logging'", |
Myung Bae | 8549b95 | 2023-08-16 15:18:19 -0400 | [diff] [blame] | 432 | std::bind_front(afterUpdateErrorMatcher, asyncResp, url)); |
Andrew Geissler | 86adcd6 | 2019-04-18 10:58:05 -0500 | [diff] [blame] | 433 | } |
Jennifer Lee | 729dae7 | 2018-04-24 15:59:34 -0700 | [diff] [blame] | 434 | |
Ed Tanous | f86bcc8 | 2023-08-25 09:34:07 -0700 | [diff] [blame] | 435 | struct TftpUrl |
| 436 | { |
| 437 | std::string fwFile; |
| 438 | std::string tftpServer; |
| 439 | }; |
| 440 | |
| 441 | inline std::optional<TftpUrl> |
| 442 | parseTftpUrl(std::string imageURI, |
| 443 | std::optional<std::string> transferProtocol, |
| 444 | crow::Response& res) |
| 445 | { |
| 446 | if (imageURI.find("://") == std::string::npos) |
| 447 | { |
| 448 | if (imageURI.starts_with("/")) |
| 449 | { |
| 450 | messages::actionParameterValueTypeError( |
| 451 | res, imageURI, "ImageURI", "UpdateService.SimpleUpdate"); |
| 452 | return std::nullopt; |
| 453 | } |
| 454 | if (!transferProtocol) |
| 455 | { |
| 456 | messages::actionParameterValueTypeError( |
| 457 | res, imageURI, "ImageURI", "UpdateService.SimpleUpdate"); |
| 458 | return std::nullopt; |
| 459 | } |
| 460 | // OpenBMC currently only supports TFTP |
| 461 | if (*transferProtocol != "TFTP") |
| 462 | { |
| 463 | messages::actionParameterNotSupported(res, "TransferProtocol", |
| 464 | *transferProtocol); |
| 465 | BMCWEB_LOG_ERROR("Request incorrect protocol parameter: {}", |
| 466 | *transferProtocol); |
| 467 | return std::nullopt; |
| 468 | } |
| 469 | imageURI = "tftp://" + imageURI; |
| 470 | } |
| 471 | |
| 472 | boost::system::result<boost::urls::url> url = |
| 473 | boost::urls::parse_absolute_uri(imageURI); |
| 474 | if (!url) |
| 475 | { |
| 476 | messages::actionParameterValueTypeError(res, imageURI, "ImageURI", |
| 477 | "UpdateService.SimpleUpdate"); |
| 478 | |
| 479 | return std::nullopt; |
| 480 | } |
| 481 | url->normalize(); |
| 482 | |
| 483 | if (url->scheme() != "tftp") |
| 484 | { |
| 485 | messages::actionParameterNotSupported(res, "ImageURI", imageURI); |
| 486 | return std::nullopt; |
| 487 | } |
| 488 | std::string path(url->encoded_path()); |
| 489 | if (path.size() < 2) |
| 490 | { |
| 491 | messages::actionParameterNotSupported(res, "ImageURI", imageURI); |
| 492 | return std::nullopt; |
| 493 | } |
| 494 | path.erase(0, 1); |
| 495 | std::string host(url->encoded_host_and_port()); |
| 496 | return TftpUrl{path, host}; |
| 497 | } |
| 498 | |
Andrew Geissler | 0554c98 | 2019-04-23 14:40:12 -0500 | [diff] [blame] | 499 | /** |
| 500 | * UpdateServiceActionsSimpleUpdate class supports handle POST method for |
| 501 | * SimpleUpdate action. |
| 502 | */ |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 503 | inline void requestRoutesUpdateServiceActionsSimpleUpdate(App& app) |
Andrew Geissler | 0554c98 | 2019-04-23 14:40:12 -0500 | [diff] [blame] | 504 | { |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 505 | BMCWEB_ROUTE( |
| 506 | app, "/redfish/v1/UpdateService/Actions/UpdateService.SimpleUpdate/") |
Ed Tanous | ed39821 | 2021-06-09 17:05:54 -0700 | [diff] [blame] | 507 | .privileges(redfish::privileges::postUpdateService) |
Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 508 | .methods(boost::beast::http::verb::post)( |
| 509 | [&app](const crow::Request& req, |
| 510 | const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) { |
Carson Labrado | 3ba0007 | 2022-06-06 19:40:56 +0000 | [diff] [blame] | 511 | if (!redfish::setUpRedfishRoute(app, req, asyncResp)) |
Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 512 | { |
| 513 | return; |
| 514 | } |
Ed Tanous | 45ca1b8 | 2022-03-25 13:07:27 -0700 | [diff] [blame] | 515 | |
Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 516 | std::optional<std::string> transferProtocol; |
| 517 | std::string imageURI; |
Andrew Geissler | 0554c98 | 2019-04-23 14:40:12 -0500 | [diff] [blame] | 518 | |
Ed Tanous | 62598e3 | 2023-07-17 17:06:25 -0700 | [diff] [blame] | 519 | BMCWEB_LOG_DEBUG("Enter UpdateService.SimpleUpdate doPost"); |
Andrew Geissler | 0554c98 | 2019-04-23 14:40:12 -0500 | [diff] [blame] | 520 | |
Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 521 | // User can pass in both TransferProtocol and ImageURI parameters or |
| 522 | // they can pass in just the ImageURI with the transfer protocol |
| 523 | // embedded within it. |
| 524 | // 1) TransferProtocol:TFTP ImageURI:1.1.1.1/myfile.bin |
| 525 | // 2) ImageURI:tftp://1.1.1.1/myfile.bin |
Andrew Geissler | 0554c98 | 2019-04-23 14:40:12 -0500 | [diff] [blame] | 526 | |
Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 527 | if (!json_util::readJsonAction(req, asyncResp->res, "TransferProtocol", |
| 528 | transferProtocol, "ImageURI", imageURI)) |
| 529 | { |
Ed Tanous | 62598e3 | 2023-07-17 17:06:25 -0700 | [diff] [blame] | 530 | BMCWEB_LOG_DEBUG("Missing TransferProtocol or ImageURI parameter"); |
Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 531 | return; |
| 532 | } |
Ed Tanous | f86bcc8 | 2023-08-25 09:34:07 -0700 | [diff] [blame] | 533 | std::optional<TftpUrl> ret = parseTftpUrl(imageURI, transferProtocol, |
| 534 | asyncResp->res); |
| 535 | if (!ret) |
Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 536 | { |
Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 537 | return; |
| 538 | } |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 539 | |
Ed Tanous | f86bcc8 | 2023-08-25 09:34:07 -0700 | [diff] [blame] | 540 | BMCWEB_LOG_DEBUG("Server: {} File: {}", ret->tftpServer, ret->fwFile); |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 541 | |
Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 542 | // Setup callback for when new software detected |
| 543 | // Give TFTP 10 minutes to complete |
| 544 | monitorForSoftwareAvailable( |
| 545 | asyncResp, req, |
| 546 | "/redfish/v1/UpdateService/Actions/UpdateService.SimpleUpdate", |
| 547 | 600); |
| 548 | |
| 549 | // TFTP can take up to 10 minutes depending on image size and |
| 550 | // connection speed. Return to caller as soon as the TFTP operation |
| 551 | // has been started. The callback above will ensure the activate |
| 552 | // is started once the download has completed |
| 553 | redfish::messages::success(asyncResp->res); |
| 554 | |
| 555 | // Call TFTP service |
| 556 | crow::connections::systemBus->async_method_call( |
Ed Tanous | 5e7e2dc | 2023-02-16 10:37:01 -0800 | [diff] [blame] | 557 | [](const boost::system::error_code& ec) { |
Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 558 | if (ec) |
| 559 | { |
| 560 | // messages::internalError(asyncResp->res); |
| 561 | cleanUp(); |
Ed Tanous | 62598e3 | 2023-07-17 17:06:25 -0700 | [diff] [blame] | 562 | BMCWEB_LOG_DEBUG("error_code = {}", ec); |
| 563 | BMCWEB_LOG_DEBUG("error msg = {}", ec.message()); |
Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 564 | } |
| 565 | else |
| 566 | { |
Ed Tanous | 62598e3 | 2023-07-17 17:06:25 -0700 | [diff] [blame] | 567 | BMCWEB_LOG_DEBUG("Call to DownloaViaTFTP Success"); |
Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 568 | } |
Patrick Williams | 5a39f77 | 2023-10-20 11:20:21 -0500 | [diff] [blame] | 569 | }, |
Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 570 | "xyz.openbmc_project.Software.Download", |
| 571 | "/xyz/openbmc_project/software", "xyz.openbmc_project.Common.TFTP", |
Ed Tanous | f86bcc8 | 2023-08-25 09:34:07 -0700 | [diff] [blame] | 572 | "DownloadViaTFTP", ret->fwFile, ret->tftpServer); |
Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 573 | |
Ed Tanous | 62598e3 | 2023-07-17 17:06:25 -0700 | [diff] [blame] | 574 | BMCWEB_LOG_DEBUG("Exit UpdateService.SimpleUpdate doPost"); |
Patrick Williams | 5a39f77 | 2023-10-20 11:20:21 -0500 | [diff] [blame] | 575 | }); |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 576 | } |
| 577 | |
George Liu | 0ed80c8 | 2020-05-12 16:06:27 +0800 | [diff] [blame] | 578 | inline void uploadImageFile(crow::Response& res, std::string_view body) |
| 579 | { |
Ed Tanous | 2c6ffdb | 2023-06-28 11:28:38 -0700 | [diff] [blame] | 580 | std::filesystem::path filepath("/tmp/images/" + bmcweb::getRandomUUID()); |
| 581 | |
Ed Tanous | 62598e3 | 2023-07-17 17:06:25 -0700 | [diff] [blame] | 582 | BMCWEB_LOG_DEBUG("Writing file to {}", filepath.string()); |
George Liu | 0ed80c8 | 2020-05-12 16:06:27 +0800 | [diff] [blame] | 583 | std::ofstream out(filepath, std::ofstream::out | std::ofstream::binary | |
| 584 | std::ofstream::trunc); |
| 585 | // set the permission of the file to 640 |
Patrick Williams | 89492a1 | 2023-05-10 07:51:34 -0500 | [diff] [blame] | 586 | std::filesystem::perms permission = std::filesystem::perms::owner_read | |
| 587 | std::filesystem::perms::group_read; |
George Liu | 0ed80c8 | 2020-05-12 16:06:27 +0800 | [diff] [blame] | 588 | std::filesystem::permissions(filepath, permission); |
| 589 | out << body; |
| 590 | |
| 591 | if (out.bad()) |
| 592 | { |
| 593 | messages::internalError(res); |
| 594 | cleanUp(); |
| 595 | } |
| 596 | } |
| 597 | |
| 598 | inline void setApplyTime(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, |
| 599 | const std::string& applyTime) |
| 600 | { |
| 601 | std::string applyTimeNewVal; |
| 602 | if (applyTime == "Immediate") |
| 603 | { |
| 604 | applyTimeNewVal = |
| 605 | "xyz.openbmc_project.Software.ApplyTime.RequestedApplyTimes.Immediate"; |
| 606 | } |
| 607 | else if (applyTime == "OnReset") |
| 608 | { |
| 609 | applyTimeNewVal = |
| 610 | "xyz.openbmc_project.Software.ApplyTime.RequestedApplyTimes.OnReset"; |
| 611 | } |
| 612 | else |
| 613 | { |
Ed Tanous | 62598e3 | 2023-07-17 17:06:25 -0700 | [diff] [blame] | 614 | BMCWEB_LOG_INFO( |
| 615 | "ApplyTime value is not in the list of acceptable values"); |
George Liu | 0ed80c8 | 2020-05-12 16:06:27 +0800 | [diff] [blame] | 616 | messages::propertyValueNotInList(asyncResp->res, applyTime, |
| 617 | "ApplyTime"); |
| 618 | return; |
| 619 | } |
| 620 | |
| 621 | // Set the requested image apply time value |
George Liu | 9ae226f | 2023-06-21 17:56:46 +0800 | [diff] [blame] | 622 | sdbusplus::asio::setProperty( |
| 623 | *crow::connections::systemBus, "xyz.openbmc_project.Settings", |
George Liu | 0ed80c8 | 2020-05-12 16:06:27 +0800 | [diff] [blame] | 624 | "/xyz/openbmc_project/software/apply_time", |
George Liu | 0ed80c8 | 2020-05-12 16:06:27 +0800 | [diff] [blame] | 625 | "xyz.openbmc_project.Software.ApplyTime", "RequestedApplyTime", |
George Liu | 9ae226f | 2023-06-21 17:56:46 +0800 | [diff] [blame] | 626 | applyTimeNewVal, [asyncResp](const boost::system::error_code& ec) { |
Patrick Williams | 5a39f77 | 2023-10-20 11:20:21 -0500 | [diff] [blame] | 627 | if (ec) |
| 628 | { |
| 629 | BMCWEB_LOG_ERROR("D-Bus responses error: {}", ec); |
| 630 | messages::internalError(asyncResp->res); |
| 631 | return; |
| 632 | } |
| 633 | messages::success(asyncResp->res); |
| 634 | }); |
George Liu | 0ed80c8 | 2020-05-12 16:06:27 +0800 | [diff] [blame] | 635 | } |
| 636 | |
| 637 | inline void |
| 638 | updateMultipartContext(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, |
| 639 | const MultipartParser& parser) |
| 640 | { |
| 641 | const std::string* uploadData = nullptr; |
| 642 | std::optional<std::string> applyTime = "OnReset"; |
| 643 | bool targetFound = false; |
| 644 | for (const FormPart& formpart : parser.mime_fields) |
| 645 | { |
| 646 | boost::beast::http::fields::const_iterator it = |
| 647 | formpart.fields.find("Content-Disposition"); |
| 648 | if (it == formpart.fields.end()) |
| 649 | { |
Ed Tanous | 62598e3 | 2023-07-17 17:06:25 -0700 | [diff] [blame] | 650 | BMCWEB_LOG_ERROR("Couldn't find Content-Disposition"); |
George Liu | 0ed80c8 | 2020-05-12 16:06:27 +0800 | [diff] [blame] | 651 | return; |
| 652 | } |
Ed Tanous | 62598e3 | 2023-07-17 17:06:25 -0700 | [diff] [blame] | 653 | BMCWEB_LOG_INFO("Parsing value {}", it->value()); |
George Liu | 0ed80c8 | 2020-05-12 16:06:27 +0800 | [diff] [blame] | 654 | |
| 655 | // The construction parameters of param_list must start with `;` |
| 656 | size_t index = it->value().find(';'); |
| 657 | if (index == std::string::npos) |
| 658 | { |
| 659 | continue; |
| 660 | } |
| 661 | |
Patrick Williams | 89492a1 | 2023-05-10 07:51:34 -0500 | [diff] [blame] | 662 | for (const auto& param : |
George Liu | 0ed80c8 | 2020-05-12 16:06:27 +0800 | [diff] [blame] | 663 | boost::beast::http::param_list{it->value().substr(index)}) |
| 664 | { |
| 665 | if (param.first != "name" || param.second.empty()) |
| 666 | { |
| 667 | continue; |
| 668 | } |
| 669 | |
| 670 | if (param.second == "UpdateParameters") |
| 671 | { |
| 672 | std::vector<std::string> targets; |
| 673 | nlohmann::json content = |
| 674 | nlohmann::json::parse(formpart.content); |
| 675 | if (!json_util::readJson(content, asyncResp->res, "Targets", |
| 676 | targets, "@Redfish.OperationApplyTime", |
| 677 | applyTime)) |
| 678 | { |
| 679 | return; |
| 680 | } |
| 681 | if (targets.size() != 1) |
| 682 | { |
| 683 | messages::propertyValueFormatError(asyncResp->res, |
| 684 | "Targets", ""); |
| 685 | return; |
| 686 | } |
| 687 | if (targets[0] != "/redfish/v1/Managers/bmc") |
| 688 | { |
| 689 | messages::propertyValueNotInList(asyncResp->res, |
| 690 | "Targets/0", targets[0]); |
| 691 | return; |
| 692 | } |
| 693 | targetFound = true; |
| 694 | } |
| 695 | else if (param.second == "UpdateFile") |
| 696 | { |
| 697 | uploadData = &(formpart.content); |
| 698 | } |
| 699 | } |
| 700 | } |
| 701 | |
| 702 | if (uploadData == nullptr) |
| 703 | { |
Ed Tanous | 62598e3 | 2023-07-17 17:06:25 -0700 | [diff] [blame] | 704 | BMCWEB_LOG_ERROR("Upload data is NULL"); |
George Liu | 0ed80c8 | 2020-05-12 16:06:27 +0800 | [diff] [blame] | 705 | messages::propertyMissing(asyncResp->res, "UpdateFile"); |
| 706 | return; |
| 707 | } |
| 708 | if (!targetFound) |
| 709 | { |
| 710 | messages::propertyMissing(asyncResp->res, "targets"); |
| 711 | return; |
| 712 | } |
| 713 | |
| 714 | setApplyTime(asyncResp, *applyTime); |
| 715 | |
| 716 | uploadImageFile(asyncResp->res, *uploadData); |
| 717 | } |
| 718 | |
Ed Tanous | c2051d1 | 2022-05-11 12:21:55 -0700 | [diff] [blame] | 719 | inline void |
| 720 | handleUpdateServicePost(App& app, const crow::Request& req, |
| 721 | const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) |
| 722 | { |
Carson Labrado | 3ba0007 | 2022-06-06 19:40:56 +0000 | [diff] [blame] | 723 | if (!redfish::setUpRedfishRoute(app, req, asyncResp)) |
Ed Tanous | c2051d1 | 2022-05-11 12:21:55 -0700 | [diff] [blame] | 724 | { |
| 725 | return; |
| 726 | } |
Ninad Palsule | b33a432 | 2023-06-09 09:19:18 -0500 | [diff] [blame] | 727 | std::string_view contentType = req.getHeaderValue("Content-Type"); |
Ed Tanous | c2051d1 | 2022-05-11 12:21:55 -0700 | [diff] [blame] | 728 | |
Ed Tanous | 62598e3 | 2023-07-17 17:06:25 -0700 | [diff] [blame] | 729 | BMCWEB_LOG_DEBUG("doPost: contentType={}", contentType); |
Ed Tanous | c2051d1 | 2022-05-11 12:21:55 -0700 | [diff] [blame] | 730 | |
Ninad Palsule | b33a432 | 2023-06-09 09:19:18 -0500 | [diff] [blame] | 731 | // Make sure that content type is application/octet-stream or |
| 732 | // multipart/form-data |
Ed Tanous | 18f8f60 | 2023-07-18 10:07:23 -0700 | [diff] [blame] | 733 | if (bmcweb::asciiIEquals(contentType, "application/octet-stream")) |
George Liu | 0ed80c8 | 2020-05-12 16:06:27 +0800 | [diff] [blame] | 734 | { |
Ninad Palsule | b33a432 | 2023-06-09 09:19:18 -0500 | [diff] [blame] | 735 | // Setup callback for when new software detected |
| 736 | monitorForSoftwareAvailable(asyncResp, req, |
| 737 | "/redfish/v1/UpdateService"); |
| 738 | |
George Liu | 0ed80c8 | 2020-05-12 16:06:27 +0800 | [diff] [blame] | 739 | uploadImageFile(asyncResp->res, req.body()); |
George Liu | 0ed80c8 | 2020-05-12 16:06:27 +0800 | [diff] [blame] | 740 | } |
Ninad Palsule | b33a432 | 2023-06-09 09:19:18 -0500 | [diff] [blame] | 741 | else if (contentType.starts_with("multipart/form-data")) |
George Liu | 0ed80c8 | 2020-05-12 16:06:27 +0800 | [diff] [blame] | 742 | { |
Ninad Palsule | b33a432 | 2023-06-09 09:19:18 -0500 | [diff] [blame] | 743 | MultipartParser parser; |
| 744 | |
| 745 | // Setup callback for when new software detected |
| 746 | monitorForSoftwareAvailable(asyncResp, req, |
| 747 | "/redfish/v1/UpdateService"); |
| 748 | |
| 749 | ParserError ec = parser.parse(req); |
| 750 | if (ec != ParserError::PARSER_SUCCESS) |
| 751 | { |
| 752 | // handle error |
Ed Tanous | 62598e3 | 2023-07-17 17:06:25 -0700 | [diff] [blame] | 753 | BMCWEB_LOG_ERROR("MIME parse failed, ec : {}", |
| 754 | static_cast<int>(ec)); |
Ninad Palsule | b33a432 | 2023-06-09 09:19:18 -0500 | [diff] [blame] | 755 | messages::internalError(asyncResp->res); |
| 756 | return; |
| 757 | } |
| 758 | updateMultipartContext(asyncResp, parser); |
George Liu | 0ed80c8 | 2020-05-12 16:06:27 +0800 | [diff] [blame] | 759 | } |
Ninad Palsule | b33a432 | 2023-06-09 09:19:18 -0500 | [diff] [blame] | 760 | else |
| 761 | { |
Ed Tanous | 62598e3 | 2023-07-17 17:06:25 -0700 | [diff] [blame] | 762 | BMCWEB_LOG_DEBUG("Bad content type specified:{}", contentType); |
Ninad Palsule | b33a432 | 2023-06-09 09:19:18 -0500 | [diff] [blame] | 763 | asyncResp->res.result(boost::beast::http::status::bad_request); |
| 764 | } |
Ed Tanous | c2051d1 | 2022-05-11 12:21:55 -0700 | [diff] [blame] | 765 | } |
| 766 | |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 767 | inline void requestRoutesUpdateService(App& app) |
| 768 | { |
| 769 | BMCWEB_ROUTE(app, "/redfish/v1/UpdateService/") |
Ed Tanous | ed39821 | 2021-06-09 17:05:54 -0700 | [diff] [blame] | 770 | .privileges(redfish::privileges::getUpdateService) |
Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 771 | .methods(boost::beast::http::verb::get)( |
| 772 | [&app](const crow::Request& req, |
| 773 | const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) { |
Carson Labrado | 3ba0007 | 2022-06-06 19:40:56 +0000 | [diff] [blame] | 774 | if (!redfish::setUpRedfishRoute(app, req, asyncResp)) |
Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 775 | { |
| 776 | return; |
| 777 | } |
| 778 | asyncResp->res.jsonValue["@odata.type"] = |
George Liu | 0ed80c8 | 2020-05-12 16:06:27 +0800 | [diff] [blame] | 779 | "#UpdateService.v1_11_1.UpdateService"; |
Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 780 | asyncResp->res.jsonValue["@odata.id"] = "/redfish/v1/UpdateService"; |
| 781 | asyncResp->res.jsonValue["Id"] = "UpdateService"; |
| 782 | asyncResp->res.jsonValue["Description"] = "Service for Software Update"; |
| 783 | asyncResp->res.jsonValue["Name"] = "Update Service"; |
Ed Tanous | 4dc23f3 | 2022-05-11 11:32:19 -0700 | [diff] [blame] | 784 | |
Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 785 | asyncResp->res.jsonValue["HttpPushUri"] = |
| 786 | "/redfish/v1/UpdateService/update"; |
George Liu | 0ed80c8 | 2020-05-12 16:06:27 +0800 | [diff] [blame] | 787 | asyncResp->res.jsonValue["MultipartHttpPushUri"] = |
| 788 | "/redfish/v1/UpdateService/update"; |
Ed Tanous | 4dc23f3 | 2022-05-11 11:32:19 -0700 | [diff] [blame] | 789 | |
Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 790 | // UpdateService cannot be disabled |
| 791 | asyncResp->res.jsonValue["ServiceEnabled"] = true; |
| 792 | asyncResp->res.jsonValue["FirmwareInventory"]["@odata.id"] = |
| 793 | "/redfish/v1/UpdateService/FirmwareInventory"; |
| 794 | // Get the MaxImageSizeBytes |
| 795 | asyncResp->res.jsonValue["MaxImageSizeBytes"] = |
| 796 | bmcwebHttpReqBodyLimitMb * 1024 * 1024; |
Tejas Patil | d61e519 | 2021-06-04 15:49:35 +0530 | [diff] [blame] | 797 | |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 798 | #ifdef BMCWEB_INSECURE_ENABLE_REDFISH_FW_TFTP_UPDATE |
Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 799 | // Update Actions object. |
| 800 | nlohmann::json& updateSvcSimpleUpdate = |
| 801 | asyncResp->res.jsonValue["Actions"]["#UpdateService.SimpleUpdate"]; |
| 802 | updateSvcSimpleUpdate["target"] = |
| 803 | "/redfish/v1/UpdateService/Actions/UpdateService.SimpleUpdate"; |
| 804 | updateSvcSimpleUpdate["TransferProtocol@Redfish.AllowableValues"] = { |
| 805 | "TFTP"}; |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 806 | #endif |
Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 807 | // Get the current ApplyTime value |
| 808 | sdbusplus::asio::getProperty<std::string>( |
| 809 | *crow::connections::systemBus, "xyz.openbmc_project.Settings", |
| 810 | "/xyz/openbmc_project/software/apply_time", |
| 811 | "xyz.openbmc_project.Software.ApplyTime", "RequestedApplyTime", |
Ed Tanous | 5e7e2dc | 2023-02-16 10:37:01 -0800 | [diff] [blame] | 812 | [asyncResp](const boost::system::error_code& ec, |
Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 813 | const std::string& applyTime) { |
| 814 | if (ec) |
| 815 | { |
Ed Tanous | 62598e3 | 2023-07-17 17:06:25 -0700 | [diff] [blame] | 816 | BMCWEB_LOG_DEBUG("DBUS response error {}", ec); |
Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 817 | messages::internalError(asyncResp->res); |
| 818 | return; |
| 819 | } |
Jayashankar Padath | 274dfe6 | 2019-08-23 12:30:57 +0530 | [diff] [blame] | 820 | |
Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 821 | // Store the ApplyTime Value |
| 822 | if (applyTime == "xyz.openbmc_project.Software.ApplyTime." |
| 823 | "RequestedApplyTimes.Immediate") |
| 824 | { |
| 825 | asyncResp->res.jsonValue["HttpPushUriOptions"] |
| 826 | ["HttpPushUriApplyTime"]["ApplyTime"] = |
| 827 | "Immediate"; |
| 828 | } |
| 829 | else if (applyTime == "xyz.openbmc_project.Software.ApplyTime." |
| 830 | "RequestedApplyTimes.OnReset") |
| 831 | { |
| 832 | asyncResp->res.jsonValue["HttpPushUriOptions"] |
| 833 | ["HttpPushUriApplyTime"]["ApplyTime"] = |
| 834 | "OnReset"; |
| 835 | } |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 836 | }); |
Patrick Williams | 5a39f77 | 2023-10-20 11:20:21 -0500 | [diff] [blame] | 837 | }); |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 838 | BMCWEB_ROUTE(app, "/redfish/v1/UpdateService/") |
Ed Tanous | ed39821 | 2021-06-09 17:05:54 -0700 | [diff] [blame] | 839 | .privileges(redfish::privileges::patchUpdateService) |
Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 840 | .methods(boost::beast::http::verb::patch)( |
| 841 | [&app](const crow::Request& req, |
| 842 | const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) { |
Carson Labrado | 3ba0007 | 2022-06-06 19:40:56 +0000 | [diff] [blame] | 843 | if (!redfish::setUpRedfishRoute(app, req, asyncResp)) |
Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 844 | { |
| 845 | return; |
| 846 | } |
Ed Tanous | 62598e3 | 2023-07-17 17:06:25 -0700 | [diff] [blame] | 847 | BMCWEB_LOG_DEBUG("doPatch..."); |
Jayashankar Padath | fa1a5a3 | 2019-05-28 23:54:37 +0530 | [diff] [blame] | 848 | |
Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 849 | std::optional<nlohmann::json> pushUriOptions; |
| 850 | if (!json_util::readJsonPatch(req, asyncResp->res, "HttpPushUriOptions", |
| 851 | pushUriOptions)) |
| 852 | { |
| 853 | return; |
| 854 | } |
| 855 | |
| 856 | if (pushUriOptions) |
| 857 | { |
| 858 | std::optional<nlohmann::json> pushUriApplyTime; |
| 859 | if (!json_util::readJson(*pushUriOptions, asyncResp->res, |
| 860 | "HttpPushUriApplyTime", pushUriApplyTime)) |
George Liu | 0fda0f1 | 2021-11-16 10:06:17 +0800 | [diff] [blame] | 861 | { |
| 862 | return; |
| 863 | } |
| 864 | |
Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 865 | if (pushUriApplyTime) |
George Liu | 0fda0f1 | 2021-11-16 10:06:17 +0800 | [diff] [blame] | 866 | { |
Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 867 | std::optional<std::string> applyTime; |
| 868 | if (!json_util::readJson(*pushUriApplyTime, asyncResp->res, |
| 869 | "ApplyTime", applyTime)) |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 870 | { |
Ed Tanous | c711bf8 | 2018-07-30 16:31:33 -0700 | [diff] [blame] | 871 | return; |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 872 | } |
Jennifer Lee | 6c4eb9d | 2018-05-22 10:58:31 -0700 | [diff] [blame] | 873 | |
Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 874 | if (applyTime) |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 875 | { |
George Liu | 0ed80c8 | 2020-05-12 16:06:27 +0800 | [diff] [blame] | 876 | setApplyTime(asyncResp, *applyTime); |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 877 | } |
George Liu | 0fda0f1 | 2021-11-16 10:06:17 +0800 | [diff] [blame] | 878 | } |
Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 879 | } |
Patrick Williams | 5a39f77 | 2023-10-20 11:20:21 -0500 | [diff] [blame] | 880 | }); |
Ed Tanous | c2051d1 | 2022-05-11 12:21:55 -0700 | [diff] [blame] | 881 | |
Ed Tanous | 4dc23f3 | 2022-05-11 11:32:19 -0700 | [diff] [blame] | 882 | BMCWEB_ROUTE(app, "/redfish/v1/UpdateService/update/") |
| 883 | .privileges(redfish::privileges::postUpdateService) |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 884 | .methods(boost::beast::http::verb::post)( |
Ed Tanous | c2051d1 | 2022-05-11 12:21:55 -0700 | [diff] [blame] | 885 | std::bind_front(handleUpdateServicePost, std::ref(app))); |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 886 | } |
| 887 | |
| 888 | inline void requestRoutesSoftwareInventoryCollection(App& app) |
| 889 | { |
| 890 | BMCWEB_ROUTE(app, "/redfish/v1/UpdateService/FirmwareInventory/") |
Ed Tanous | ed39821 | 2021-06-09 17:05:54 -0700 | [diff] [blame] | 891 | .privileges(redfish::privileges::getSoftwareInventoryCollection) |
Ed Tanous | 1476687 | 2022-03-15 10:44:42 -0700 | [diff] [blame] | 892 | .methods(boost::beast::http::verb::get)( |
| 893 | [&app](const crow::Request& req, |
| 894 | const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) { |
Carson Labrado | 3ba0007 | 2022-06-06 19:40:56 +0000 | [diff] [blame] | 895 | if (!redfish::setUpRedfishRoute(app, req, asyncResp)) |
Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 896 | { |
| 897 | return; |
| 898 | } |
| 899 | asyncResp->res.jsonValue["@odata.type"] = |
| 900 | "#SoftwareInventoryCollection.SoftwareInventoryCollection"; |
| 901 | asyncResp->res.jsonValue["@odata.id"] = |
| 902 | "/redfish/v1/UpdateService/FirmwareInventory"; |
| 903 | asyncResp->res.jsonValue["Name"] = "Software Inventory Collection"; |
John Edward Broadbent | 08d81ad | 2022-05-17 20:00:23 -0700 | [diff] [blame] | 904 | const std::array<const std::string_view, 1> iface = { |
George Liu | e99073f | 2022-12-09 11:06:16 +0800 | [diff] [blame] | 905 | "xyz.openbmc_project.Software.Version"}; |
Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 906 | |
John Edward Broadbent | 08d81ad | 2022-05-17 20:00:23 -0700 | [diff] [blame] | 907 | redfish::collection_util::getCollectionMembers( |
| 908 | asyncResp, |
| 909 | boost::urls::url("/redfish/v1/UpdateService/FirmwareInventory"), |
| 910 | iface, "/xyz/openbmc_project/software"); |
Patrick Williams | 5a39f77 | 2023-10-20 11:20:21 -0500 | [diff] [blame] | 911 | }); |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 912 | } |
| 913 | /* Fill related item links (i.e. bmc, bios) in for inventory */ |
| 914 | inline static void |
Ed Tanous | ac106bf | 2023-06-07 09:24:59 -0700 | [diff] [blame] | 915 | getRelatedItems(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 916 | const std::string& purpose) |
| 917 | { |
Willy Tu | eee0013 | 2022-06-14 14:53:17 -0700 | [diff] [blame] | 918 | if (purpose == sw_util::bmcPurpose) |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 919 | { |
Ed Tanous | ac106bf | 2023-06-07 09:24:59 -0700 | [diff] [blame] | 920 | nlohmann::json& relatedItem = asyncResp->res.jsonValue["RelatedItem"]; |
Ed Tanous | 1476687 | 2022-03-15 10:44:42 -0700 | [diff] [blame] | 921 | nlohmann::json::object_t item; |
| 922 | item["@odata.id"] = "/redfish/v1/Managers/bmc"; |
Patrick Williams | b2ba307 | 2023-05-12 10:27:39 -0500 | [diff] [blame] | 923 | relatedItem.emplace_back(std::move(item)); |
Ed Tanous | ac106bf | 2023-06-07 09:24:59 -0700 | [diff] [blame] | 924 | asyncResp->res.jsonValue["RelatedItem@odata.count"] = |
| 925 | relatedItem.size(); |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 926 | } |
Willy Tu | eee0013 | 2022-06-14 14:53:17 -0700 | [diff] [blame] | 927 | else if (purpose == sw_util::biosPurpose) |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 928 | { |
Ed Tanous | ac106bf | 2023-06-07 09:24:59 -0700 | [diff] [blame] | 929 | nlohmann::json& relatedItem = asyncResp->res.jsonValue["RelatedItem"]; |
Ed Tanous | 1476687 | 2022-03-15 10:44:42 -0700 | [diff] [blame] | 930 | nlohmann::json::object_t item; |
| 931 | item["@odata.id"] = "/redfish/v1/Systems/system/Bios"; |
Patrick Williams | b2ba307 | 2023-05-12 10:27:39 -0500 | [diff] [blame] | 932 | relatedItem.emplace_back(std::move(item)); |
Ed Tanous | ac106bf | 2023-06-07 09:24:59 -0700 | [diff] [blame] | 933 | asyncResp->res.jsonValue["RelatedItem@odata.count"] = |
| 934 | relatedItem.size(); |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 935 | } |
| 936 | else |
| 937 | { |
Carson Labrado | bf2dded | 2023-08-10 00:37:06 +0000 | [diff] [blame] | 938 | BMCWEB_LOG_DEBUG("Unknown software purpose {}", purpose); |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 939 | } |
| 940 | } |
| 941 | |
Willy Tu | af24660 | 2022-06-14 15:51:53 -0700 | [diff] [blame] | 942 | inline void |
| 943 | getSoftwareVersion(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, |
| 944 | const std::string& service, const std::string& path, |
| 945 | const std::string& swId) |
| 946 | { |
Krzysztof Grobelny | d1bde9e | 2022-09-07 10:40:51 +0200 | [diff] [blame] | 947 | sdbusplus::asio::getAllProperties( |
| 948 | *crow::connections::systemBus, service, path, |
| 949 | "xyz.openbmc_project.Software.Version", |
Willy Tu | af24660 | 2022-06-14 15:51:53 -0700 | [diff] [blame] | 950 | [asyncResp, |
Ed Tanous | 8b24275 | 2023-06-27 17:17:13 -0700 | [diff] [blame] | 951 | swId](const boost::system::error_code& ec, |
Willy Tu | af24660 | 2022-06-14 15:51:53 -0700 | [diff] [blame] | 952 | const dbus::utility::DBusPropertiesMap& propertiesList) { |
Ed Tanous | 8b24275 | 2023-06-27 17:17:13 -0700 | [diff] [blame] | 953 | if (ec) |
Willy Tu | af24660 | 2022-06-14 15:51:53 -0700 | [diff] [blame] | 954 | { |
| 955 | messages::internalError(asyncResp->res); |
| 956 | return; |
| 957 | } |
Krzysztof Grobelny | d1bde9e | 2022-09-07 10:40:51 +0200 | [diff] [blame] | 958 | |
Willy Tu | af24660 | 2022-06-14 15:51:53 -0700 | [diff] [blame] | 959 | const std::string* swInvPurpose = nullptr; |
| 960 | const std::string* version = nullptr; |
Krzysztof Grobelny | d1bde9e | 2022-09-07 10:40:51 +0200 | [diff] [blame] | 961 | |
| 962 | const bool success = sdbusplus::unpackPropertiesNoThrow( |
| 963 | dbus_utils::UnpackErrorPrinter(), propertiesList, "Purpose", |
| 964 | swInvPurpose, "Version", version); |
| 965 | |
| 966 | if (!success) |
Willy Tu | af24660 | 2022-06-14 15:51:53 -0700 | [diff] [blame] | 967 | { |
Krzysztof Grobelny | d1bde9e | 2022-09-07 10:40:51 +0200 | [diff] [blame] | 968 | messages::internalError(asyncResp->res); |
| 969 | return; |
Willy Tu | af24660 | 2022-06-14 15:51:53 -0700 | [diff] [blame] | 970 | } |
| 971 | |
| 972 | if (swInvPurpose == nullptr) |
| 973 | { |
Ed Tanous | 62598e3 | 2023-07-17 17:06:25 -0700 | [diff] [blame] | 974 | BMCWEB_LOG_DEBUG("Can't find property \"Purpose\"!"); |
Willy Tu | af24660 | 2022-06-14 15:51:53 -0700 | [diff] [blame] | 975 | messages::internalError(asyncResp->res); |
| 976 | return; |
| 977 | } |
| 978 | |
Ed Tanous | 62598e3 | 2023-07-17 17:06:25 -0700 | [diff] [blame] | 979 | BMCWEB_LOG_DEBUG("swInvPurpose = {}", *swInvPurpose); |
Willy Tu | af24660 | 2022-06-14 15:51:53 -0700 | [diff] [blame] | 980 | |
| 981 | if (version == nullptr) |
| 982 | { |
Ed Tanous | 62598e3 | 2023-07-17 17:06:25 -0700 | [diff] [blame] | 983 | BMCWEB_LOG_DEBUG("Can't find property \"Version\"!"); |
Willy Tu | af24660 | 2022-06-14 15:51:53 -0700 | [diff] [blame] | 984 | |
| 985 | messages::internalError(asyncResp->res); |
| 986 | |
| 987 | return; |
| 988 | } |
| 989 | asyncResp->res.jsonValue["Version"] = *version; |
| 990 | asyncResp->res.jsonValue["Id"] = swId; |
| 991 | |
| 992 | // swInvPurpose is of format: |
| 993 | // xyz.openbmc_project.Software.Version.VersionPurpose.ABC |
| 994 | // Translate this to "ABC image" |
| 995 | size_t endDesc = swInvPurpose->rfind('.'); |
| 996 | if (endDesc == std::string::npos) |
| 997 | { |
| 998 | messages::internalError(asyncResp->res); |
| 999 | return; |
| 1000 | } |
| 1001 | endDesc++; |
| 1002 | if (endDesc >= swInvPurpose->size()) |
| 1003 | { |
| 1004 | messages::internalError(asyncResp->res); |
| 1005 | return; |
| 1006 | } |
| 1007 | |
| 1008 | std::string formatDesc = swInvPurpose->substr(endDesc); |
| 1009 | asyncResp->res.jsonValue["Description"] = formatDesc + " image"; |
| 1010 | getRelatedItems(asyncResp, *swInvPurpose); |
Patrick Williams | 5a39f77 | 2023-10-20 11:20:21 -0500 | [diff] [blame] | 1011 | }); |
Willy Tu | af24660 | 2022-06-14 15:51:53 -0700 | [diff] [blame] | 1012 | } |
| 1013 | |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 1014 | inline void requestRoutesSoftwareInventory(App& app) |
| 1015 | { |
| 1016 | BMCWEB_ROUTE(app, "/redfish/v1/UpdateService/FirmwareInventory/<str>/") |
Ed Tanous | ed39821 | 2021-06-09 17:05:54 -0700 | [diff] [blame] | 1017 | .privileges(redfish::privileges::getSoftwareInventory) |
Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 1018 | .methods(boost::beast::http::verb::get)( |
| 1019 | [&app](const crow::Request& req, |
| 1020 | const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, |
| 1021 | const std::string& param) { |
Carson Labrado | 3ba0007 | 2022-06-06 19:40:56 +0000 | [diff] [blame] | 1022 | if (!redfish::setUpRedfishRoute(app, req, asyncResp)) |
Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 1023 | { |
| 1024 | return; |
| 1025 | } |
| 1026 | std::shared_ptr<std::string> swId = |
| 1027 | std::make_shared<std::string>(param); |
| 1028 | |
Ed Tanous | ef4c65b | 2023-04-24 15:28:50 -0700 | [diff] [blame] | 1029 | asyncResp->res.jsonValue["@odata.id"] = boost::urls::format( |
| 1030 | "/redfish/v1/UpdateService/FirmwareInventory/{}", *swId); |
Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 1031 | |
George Liu | e99073f | 2022-12-09 11:06:16 +0800 | [diff] [blame] | 1032 | constexpr std::array<std::string_view, 1> interfaces = { |
| 1033 | "xyz.openbmc_project.Software.Version"}; |
| 1034 | dbus::utility::getSubTree( |
| 1035 | "/", 0, interfaces, |
Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 1036 | [asyncResp, |
George Liu | e99073f | 2022-12-09 11:06:16 +0800 | [diff] [blame] | 1037 | swId](const boost::system::error_code& ec, |
Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 1038 | const dbus::utility::MapperGetSubTreeResponse& subtree) { |
Ed Tanous | 62598e3 | 2023-07-17 17:06:25 -0700 | [diff] [blame] | 1039 | BMCWEB_LOG_DEBUG("doGet callback..."); |
Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 1040 | if (ec) |
Ed Tanous | 45ca1b8 | 2022-03-25 13:07:27 -0700 | [diff] [blame] | 1041 | { |
Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 1042 | messages::internalError(asyncResp->res); |
Ed Tanous | 45ca1b8 | 2022-03-25 13:07:27 -0700 | [diff] [blame] | 1043 | return; |
| 1044 | } |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 1045 | |
Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 1046 | // Ensure we find our input swId, otherwise return an error |
| 1047 | bool found = false; |
| 1048 | for (const std::pair<std::string, |
| 1049 | std::vector<std::pair< |
| 1050 | std::string, std::vector<std::string>>>>& |
| 1051 | obj : subtree) |
| 1052 | { |
Ed Tanous | 11ba397 | 2022-07-11 09:50:41 -0700 | [diff] [blame] | 1053 | if (!obj.first.ends_with(*swId)) |
Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 1054 | { |
| 1055 | continue; |
| 1056 | } |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 1057 | |
Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 1058 | if (obj.second.empty()) |
| 1059 | { |
| 1060 | continue; |
| 1061 | } |
| 1062 | |
| 1063 | found = true; |
Willy Tu | eee0013 | 2022-06-14 14:53:17 -0700 | [diff] [blame] | 1064 | sw_util::getSwStatus(asyncResp, swId, obj.second[0].first); |
Willy Tu | af24660 | 2022-06-14 15:51:53 -0700 | [diff] [blame] | 1065 | getSoftwareVersion(asyncResp, obj.second[0].first, obj.first, |
| 1066 | *swId); |
Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 1067 | } |
| 1068 | if (!found) |
| 1069 | { |
Ed Tanous | 62598e3 | 2023-07-17 17:06:25 -0700 | [diff] [blame] | 1070 | BMCWEB_LOG_WARNING("Input swID {} not found!", *swId); |
Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 1071 | messages::resourceMissingAtURI( |
Ed Tanous | ef4c65b | 2023-04-24 15:28:50 -0700 | [diff] [blame] | 1072 | asyncResp->res, |
| 1073 | boost::urls::format( |
| 1074 | "/redfish/v1/UpdateService/FirmwareInventory/{}", |
| 1075 | *swId)); |
Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 1076 | return; |
| 1077 | } |
| 1078 | asyncResp->res.jsonValue["@odata.type"] = |
| 1079 | "#SoftwareInventory.v1_1_0.SoftwareInventory"; |
| 1080 | asyncResp->res.jsonValue["Name"] = "Software Inventory"; |
| 1081 | asyncResp->res.jsonValue["Status"]["HealthRollup"] = "OK"; |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 1082 | |
Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 1083 | asyncResp->res.jsonValue["Updateable"] = false; |
Willy Tu | eee0013 | 2022-06-14 14:53:17 -0700 | [diff] [blame] | 1084 | sw_util::getSwUpdatableStatus(asyncResp, swId); |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 1085 | }); |
Patrick Williams | 5a39f77 | 2023-10-20 11:20:21 -0500 | [diff] [blame] | 1086 | }); |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 1087 | } |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 1088 | |
| 1089 | } // namespace redfish |