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