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