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 | |
| 18 | #include "node.hpp" |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 19 | |
Jennifer Lee | 729dae7 | 2018-04-24 15:59:34 -0700 | [diff] [blame] | 20 | #include <boost/container/flat_map.hpp> |
Andrew Geissler | 87d8472 | 2019-02-28 14:28:39 -0600 | [diff] [blame] | 21 | #include <utils/fw_utils.hpp> |
Ed Tanous | abf2add | 2019-01-22 16:40:12 -0800 | [diff] [blame] | 22 | #include <variant> |
Jennifer Lee | 729dae7 | 2018-04-24 15:59:34 -0700 | [diff] [blame] | 23 | |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 24 | namespace redfish |
| 25 | { |
Ed Tanous | 27826b5 | 2018-10-29 11:40:58 -0700 | [diff] [blame] | 26 | |
Andrew Geissler | 0e7de46 | 2019-03-04 19:11:54 -0600 | [diff] [blame] | 27 | // Match signals added on software path |
Jennifer Lee | acb7cfb | 2018-06-07 16:08:15 -0700 | [diff] [blame] | 28 | static std::unique_ptr<sdbusplus::bus::match::match> fwUpdateMatcher; |
Andrew Geissler | 0e7de46 | 2019-03-04 19:11:54 -0600 | [diff] [blame] | 29 | // Only allow one update at a time |
| 30 | static bool fwUpdateInProgress = false; |
Andrew Geissler | 86adcd6 | 2019-04-18 10:58:05 -0500 | [diff] [blame] | 31 | // Timer for software available |
Ed Tanous | 271584a | 2019-07-09 16:24:22 -0700 | [diff] [blame] | 32 | static std::unique_ptr<boost::asio::steady_timer> fwAvailableTimer; |
Andrew Geissler | 86adcd6 | 2019-04-18 10:58:05 -0500 | [diff] [blame] | 33 | |
| 34 | static void cleanUp() |
| 35 | { |
| 36 | fwUpdateInProgress = false; |
| 37 | fwUpdateMatcher = nullptr; |
| 38 | } |
| 39 | static void activateImage(const std::string &objPath, |
| 40 | const std::string &service) |
| 41 | { |
| 42 | BMCWEB_LOG_DEBUG << "Activate image for " << objPath << " " << service; |
| 43 | crow::connections::systemBus->async_method_call( |
| 44 | [](const boost::system::error_code error_code) { |
| 45 | if (error_code) |
| 46 | { |
| 47 | BMCWEB_LOG_DEBUG << "error_code = " << error_code; |
| 48 | BMCWEB_LOG_DEBUG << "error msg = " << error_code.message(); |
| 49 | } |
| 50 | }, |
| 51 | service, objPath, "org.freedesktop.DBus.Properties", "Set", |
| 52 | "xyz.openbmc_project.Software.Activation", "RequestedActivation", |
| 53 | std::variant<std::string>( |
| 54 | "xyz.openbmc_project.Software.Activation.RequestedActivations." |
| 55 | "Active")); |
| 56 | } |
Andrew Geissler | 0554c98 | 2019-04-23 14:40:12 -0500 | [diff] [blame] | 57 | |
| 58 | // Note that asyncResp can be either a valid pointer or nullptr. If nullptr |
| 59 | // then no asyncResp updates will occur |
Andrew Geissler | 86adcd6 | 2019-04-18 10:58:05 -0500 | [diff] [blame] | 60 | static void softwareInterfaceAdded(std::shared_ptr<AsyncResp> asyncResp, |
James Feist | fe30672 | 2020-03-12 16:32:08 -0700 | [diff] [blame] | 61 | sdbusplus::message::message &m, |
| 62 | const crow::Request &req) |
Andrew Geissler | 86adcd6 | 2019-04-18 10:58:05 -0500 | [diff] [blame] | 63 | { |
| 64 | std::vector<std::pair< |
| 65 | std::string, |
| 66 | std::vector<std::pair<std::string, std::variant<std::string>>>>> |
| 67 | interfacesProperties; |
| 68 | |
| 69 | sdbusplus::message::object_path objPath; |
| 70 | |
| 71 | m.read(objPath, interfacesProperties); |
| 72 | |
| 73 | BMCWEB_LOG_DEBUG << "obj path = " << objPath.str; |
| 74 | for (auto &interface : interfacesProperties) |
| 75 | { |
| 76 | BMCWEB_LOG_DEBUG << "interface = " << interface.first; |
| 77 | |
| 78 | if (interface.first == "xyz.openbmc_project.Software.Activation") |
| 79 | { |
| 80 | // Found our interface, disable callbacks |
| 81 | fwUpdateMatcher = nullptr; |
| 82 | |
| 83 | // Retrieve service and activate |
| 84 | crow::connections::systemBus->async_method_call( |
James Feist | fe30672 | 2020-03-12 16:32:08 -0700 | [diff] [blame] | 85 | [objPath, asyncResp, |
| 86 | req](const boost::system::error_code error_code, |
| 87 | const std::vector<std::pair< |
| 88 | std::string, std::vector<std::string>>> &objInfo) { |
Andrew Geissler | 86adcd6 | 2019-04-18 10:58:05 -0500 | [diff] [blame] | 89 | if (error_code) |
| 90 | { |
| 91 | BMCWEB_LOG_DEBUG << "error_code = " << error_code; |
| 92 | BMCWEB_LOG_DEBUG << "error msg = " |
| 93 | << error_code.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, |
| 124 | sdbusplus::message::message &msg, |
| 125 | const std::shared_ptr<task::TaskData> |
| 126 | &taskData) { |
| 127 | if (ec) |
| 128 | { |
| 129 | return task::completed; |
| 130 | } |
| 131 | |
| 132 | std::string iface; |
| 133 | boost::container::flat_map< |
| 134 | std::string, std::variant<std::string>> |
| 135 | values; |
| 136 | msg.read(iface, values); |
| 137 | auto findActivation = |
| 138 | values.find("Activation"); |
| 139 | if (findActivation == values.end()) |
| 140 | { |
| 141 | return !task::completed; |
| 142 | } |
| 143 | std::string *state = |
| 144 | std::get_if<std::string>( |
| 145 | &(findActivation->second)); |
| 146 | |
| 147 | if (state == nullptr) |
| 148 | { |
| 149 | taskData->messages.emplace_back( |
| 150 | messages::internalError()); |
| 151 | return task::completed; |
| 152 | } |
| 153 | |
James Feist | e5d5006 | 2020-05-11 17:29:00 -0700 | [diff] [blame] | 154 | std::string index = |
| 155 | std::to_string(taskData->index); |
| 156 | |
James Feist | 32898ce | 2020-03-10 16:16:52 -0700 | [diff] [blame] | 157 | if (boost::ends_with(*state, "Invalid") || |
| 158 | boost::ends_with(*state, "Failed")) |
| 159 | { |
| 160 | taskData->state = "Exception"; |
| 161 | taskData->status = "Warning"; |
| 162 | taskData->messages.emplace_back( |
James Feist | e5d5006 | 2020-05-11 17:29:00 -0700 | [diff] [blame] | 163 | messages::taskAborted(index)); |
James Feist | 32898ce | 2020-03-10 16:16:52 -0700 | [diff] [blame] | 164 | return task::completed; |
| 165 | } |
| 166 | |
| 167 | if (boost::ends_with(*state, "Staged")) |
| 168 | { |
| 169 | taskData->state = "Pending"; |
| 170 | return !task::completed; |
| 171 | } |
| 172 | |
| 173 | if (boost::ends_with(*state, "Active")) |
| 174 | { |
| 175 | taskData->messages.emplace_back( |
James Feist | e5d5006 | 2020-05-11 17:29:00 -0700 | [diff] [blame] | 176 | messages::taskCompletedOK(index)); |
James Feist | 32898ce | 2020-03-10 16:16:52 -0700 | [diff] [blame] | 177 | taskData->state = "Completed"; |
| 178 | return task::completed; |
| 179 | } |
| 180 | |
| 181 | // as firmware update often results in a |
| 182 | // reboot, the task may never "complete" |
| 183 | // unless it is an error |
| 184 | |
| 185 | return !task::completed; |
| 186 | }, |
| 187 | "type='signal',interface='org.freedesktop.DBus." |
| 188 | "Properties'," |
| 189 | "member='PropertiesChanged',arg0='xyz.openbmc_" |
| 190 | "project.Software.Activation',path='" + |
| 191 | objPath.str + "'"); |
| 192 | task->startTimer(std::chrono::minutes(5)); |
| 193 | task->populateResp(asyncResp->res); |
James Feist | fe30672 | 2020-03-12 16:32:08 -0700 | [diff] [blame] | 194 | task->payload.emplace(req); |
Andrew Geissler | 0554c98 | 2019-04-23 14:40:12 -0500 | [diff] [blame] | 195 | } |
Andrew Geissler | 86adcd6 | 2019-04-18 10:58:05 -0500 | [diff] [blame] | 196 | fwUpdateInProgress = false; |
| 197 | }, |
| 198 | "xyz.openbmc_project.ObjectMapper", |
| 199 | "/xyz/openbmc_project/object_mapper", |
| 200 | "xyz.openbmc_project.ObjectMapper", "GetObject", objPath.str, |
| 201 | std::array<const char *, 1>{ |
| 202 | "xyz.openbmc_project.Software.Activation"}); |
| 203 | } |
| 204 | } |
| 205 | } |
| 206 | |
Andrew Geissler | 0554c98 | 2019-04-23 14:40:12 -0500 | [diff] [blame] | 207 | // Note that asyncResp can be either a valid pointer or nullptr. If nullptr |
| 208 | // then no asyncResp updates will occur |
Andrew Geissler | 86adcd6 | 2019-04-18 10:58:05 -0500 | [diff] [blame] | 209 | static void monitorForSoftwareAvailable(std::shared_ptr<AsyncResp> asyncResp, |
Andrew Geissler | 0554c98 | 2019-04-23 14:40:12 -0500 | [diff] [blame] | 210 | const crow::Request &req, |
| 211 | int timeoutTimeSeconds = 5) |
Andrew Geissler | 86adcd6 | 2019-04-18 10:58:05 -0500 | [diff] [blame] | 212 | { |
| 213 | // Only allow one FW update at a time |
| 214 | if (fwUpdateInProgress != false) |
| 215 | { |
Andrew Geissler | 0554c98 | 2019-04-23 14:40:12 -0500 | [diff] [blame] | 216 | if (asyncResp) |
| 217 | { |
Andrew Geissler | 0554c98 | 2019-04-23 14:40:12 -0500 | [diff] [blame] | 218 | messages::serviceTemporarilyUnavailable(asyncResp->res, "30"); |
| 219 | } |
Andrew Geissler | 86adcd6 | 2019-04-18 10:58:05 -0500 | [diff] [blame] | 220 | return; |
| 221 | } |
| 222 | |
Andrew Geissler | 0554c98 | 2019-04-23 14:40:12 -0500 | [diff] [blame] | 223 | fwAvailableTimer = |
Ed Tanous | 271584a | 2019-07-09 16:24:22 -0700 | [diff] [blame] | 224 | std::make_unique<boost::asio::steady_timer>(*req.ioService); |
Andrew Geissler | 86adcd6 | 2019-04-18 10:58:05 -0500 | [diff] [blame] | 225 | |
Ed Tanous | 271584a | 2019-07-09 16:24:22 -0700 | [diff] [blame] | 226 | fwAvailableTimer->expires_after(std::chrono::seconds(timeoutTimeSeconds)); |
Andrew Geissler | 86adcd6 | 2019-04-18 10:58:05 -0500 | [diff] [blame] | 227 | |
| 228 | fwAvailableTimer->async_wait( |
| 229 | [asyncResp](const boost::system::error_code &ec) { |
| 230 | cleanUp(); |
| 231 | if (ec == boost::asio::error::operation_aborted) |
| 232 | { |
| 233 | // expected, we were canceled before the timer completed. |
| 234 | return; |
| 235 | } |
| 236 | BMCWEB_LOG_ERROR |
| 237 | << "Timed out waiting for firmware object being created"; |
| 238 | BMCWEB_LOG_ERROR |
| 239 | << "FW image may has already been uploaded to server"; |
| 240 | if (ec) |
| 241 | { |
| 242 | BMCWEB_LOG_ERROR << "Async_wait failed" << ec; |
| 243 | return; |
| 244 | } |
Andrew Geissler | 0554c98 | 2019-04-23 14:40:12 -0500 | [diff] [blame] | 245 | if (asyncResp) |
| 246 | { |
| 247 | redfish::messages::internalError(asyncResp->res); |
| 248 | } |
Andrew Geissler | 86adcd6 | 2019-04-18 10:58:05 -0500 | [diff] [blame] | 249 | }); |
| 250 | |
James Feist | fe30672 | 2020-03-12 16:32:08 -0700 | [diff] [blame] | 251 | auto callback = [asyncResp, req](sdbusplus::message::message &m) { |
Andrew Geissler | 86adcd6 | 2019-04-18 10:58:05 -0500 | [diff] [blame] | 252 | BMCWEB_LOG_DEBUG << "Match fired"; |
James Feist | fe30672 | 2020-03-12 16:32:08 -0700 | [diff] [blame] | 253 | softwareInterfaceAdded(asyncResp, m, req); |
Andrew Geissler | 86adcd6 | 2019-04-18 10:58:05 -0500 | [diff] [blame] | 254 | }; |
| 255 | |
| 256 | fwUpdateInProgress = true; |
| 257 | |
| 258 | fwUpdateMatcher = std::make_unique<sdbusplus::bus::match::match>( |
| 259 | *crow::connections::systemBus, |
| 260 | "interface='org.freedesktop.DBus.ObjectManager',type='signal'," |
| 261 | "member='InterfacesAdded',path='/xyz/openbmc_project/software'", |
| 262 | callback); |
| 263 | } |
Jennifer Lee | 729dae7 | 2018-04-24 15:59:34 -0700 | [diff] [blame] | 264 | |
Andrew Geissler | 0554c98 | 2019-04-23 14:40:12 -0500 | [diff] [blame] | 265 | /** |
| 266 | * UpdateServiceActionsSimpleUpdate class supports handle POST method for |
| 267 | * SimpleUpdate action. |
| 268 | */ |
| 269 | class UpdateServiceActionsSimpleUpdate : public Node |
| 270 | { |
| 271 | public: |
| 272 | UpdateServiceActionsSimpleUpdate(CrowApp &app) : |
| 273 | Node(app, |
| 274 | "/redfish/v1/UpdateService/Actions/UpdateService.SimpleUpdate/") |
| 275 | { |
| 276 | entityPrivileges = { |
| 277 | {boost::beast::http::verb::get, {{"Login"}}}, |
| 278 | {boost::beast::http::verb::head, {{"Login"}}}, |
| 279 | {boost::beast::http::verb::patch, {{"ConfigureManager"}}}, |
| 280 | {boost::beast::http::verb::put, {{"ConfigureComponents"}}}, |
| 281 | {boost::beast::http::verb::delete_, {{"ConfigureComponents"}}}, |
| 282 | {boost::beast::http::verb::post, {{"ConfigureComponents"}}}}; |
| 283 | } |
| 284 | |
| 285 | private: |
| 286 | void doPost(crow::Response &res, const crow::Request &req, |
| 287 | const std::vector<std::string> ¶ms) override |
| 288 | { |
| 289 | std::optional<std::string> transferProtocol; |
| 290 | std::string imageURI; |
| 291 | std::shared_ptr<AsyncResp> asyncResp = std::make_shared<AsyncResp>(res); |
| 292 | |
| 293 | BMCWEB_LOG_DEBUG << "Enter UpdateService.SimpleUpdate doPost"; |
| 294 | |
| 295 | // User can pass in both TransferProtocol and ImageURI parameters or |
| 296 | // they can pass in just the ImageURI with the transfer protocl embedded |
| 297 | // within it. |
| 298 | // 1) TransferProtocol:TFTP ImageURI:1.1.1.1/myfile.bin |
| 299 | // 2) ImageURI:tftp://1.1.1.1/myfile.bin |
| 300 | |
| 301 | if (!json_util::readJson(req, asyncResp->res, "TransferProtocol", |
| 302 | transferProtocol, "ImageURI", imageURI)) |
| 303 | { |
| 304 | BMCWEB_LOG_DEBUG |
| 305 | << "Missing TransferProtocol or ImageURI parameter"; |
| 306 | return; |
| 307 | } |
| 308 | if (!transferProtocol) |
| 309 | { |
| 310 | // Must be option 2 |
| 311 | // Verify ImageURI has transfer protocol in it |
| 312 | size_t separator = imageURI.find(":"); |
| 313 | if ((separator == std::string::npos) || |
| 314 | ((separator + 1) > imageURI.size())) |
| 315 | { |
| 316 | messages::actionParameterValueTypeError( |
| 317 | asyncResp->res, imageURI, "ImageURI", |
| 318 | "UpdateService.SimpleUpdate"); |
| 319 | BMCWEB_LOG_ERROR << "ImageURI missing transfer protocol: " |
| 320 | << imageURI; |
| 321 | return; |
| 322 | } |
| 323 | transferProtocol = imageURI.substr(0, separator); |
| 324 | // Ensure protocol is upper case for a common comparison path below |
| 325 | boost::to_upper(*transferProtocol); |
| 326 | BMCWEB_LOG_DEBUG << "Encoded transfer protocol " |
| 327 | << *transferProtocol; |
| 328 | |
| 329 | // Adjust imageURI to not have the protocol on it for parsing |
| 330 | // below |
| 331 | // ex. tftp://1.1.1.1/myfile.bin -> 1.1.1.1/myfile.bin |
| 332 | imageURI = imageURI.substr(separator + 3); |
| 333 | BMCWEB_LOG_DEBUG << "Adjusted imageUri " << imageURI; |
| 334 | } |
| 335 | |
| 336 | // OpenBMC currently only supports TFTP |
| 337 | if (*transferProtocol != "TFTP") |
| 338 | { |
| 339 | messages::actionParameterNotSupported(asyncResp->res, |
| 340 | "TransferProtocol", |
| 341 | "UpdateService.SimpleUpdate"); |
| 342 | BMCWEB_LOG_ERROR << "Request incorrect protocol parameter: " |
| 343 | << *transferProtocol; |
| 344 | return; |
| 345 | } |
| 346 | |
| 347 | // Format should be <IP or Hostname>/<file> for imageURI |
| 348 | size_t separator = imageURI.find("/"); |
| 349 | if ((separator == std::string::npos) || |
| 350 | ((separator + 1) > imageURI.size())) |
| 351 | { |
| 352 | messages::actionParameterValueTypeError( |
| 353 | asyncResp->res, imageURI, "ImageURI", |
| 354 | "UpdateService.SimpleUpdate"); |
| 355 | BMCWEB_LOG_ERROR << "Invalid ImageURI: " << imageURI; |
| 356 | return; |
| 357 | } |
| 358 | |
| 359 | std::string tftpServer = imageURI.substr(0, separator); |
| 360 | std::string fwFile = imageURI.substr(separator + 1); |
| 361 | BMCWEB_LOG_DEBUG << "Server: " << tftpServer + " File: " << fwFile; |
| 362 | |
| 363 | // Setup callback for when new software detected |
| 364 | // Give TFTP 2 minutes to complete |
| 365 | monitorForSoftwareAvailable(nullptr, req, 120); |
| 366 | |
| 367 | // TFTP can take up to 2 minutes depending on image size and |
| 368 | // connection speed. Return to caller as soon as the TFTP operation |
| 369 | // has been started. The callback above will ensure the activate |
| 370 | // is started once the download has completed |
| 371 | redfish::messages::success(asyncResp->res); |
| 372 | |
| 373 | // Call TFTP service |
| 374 | crow::connections::systemBus->async_method_call( |
| 375 | [](const boost::system::error_code ec) { |
| 376 | if (ec) |
| 377 | { |
| 378 | // messages::internalError(asyncResp->res); |
| 379 | cleanUp(); |
| 380 | BMCWEB_LOG_DEBUG << "error_code = " << ec; |
| 381 | BMCWEB_LOG_DEBUG << "error msg = " << ec.message(); |
| 382 | } |
| 383 | else |
| 384 | { |
| 385 | BMCWEB_LOG_DEBUG << "Call to DownloaViaTFTP Success"; |
| 386 | } |
| 387 | }, |
| 388 | "xyz.openbmc_project.Software.Download", |
| 389 | "/xyz/openbmc_project/software", "xyz.openbmc_project.Common.TFTP", |
| 390 | "DownloadViaTFTP", fwFile, tftpServer); |
| 391 | |
| 392 | BMCWEB_LOG_DEBUG << "Exit UpdateService.SimpleUpdate doPost"; |
| 393 | } |
| 394 | }; |
| 395 | |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 396 | class UpdateService : public Node |
| 397 | { |
| 398 | public: |
| 399 | UpdateService(CrowApp &app) : Node(app, "/redfish/v1/UpdateService/") |
| 400 | { |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 401 | entityPrivileges = { |
| 402 | {boost::beast::http::verb::get, {{"Login"}}}, |
| 403 | {boost::beast::http::verb::head, {{"Login"}}}, |
| 404 | {boost::beast::http::verb::patch, {{"ConfigureComponents"}}}, |
| 405 | {boost::beast::http::verb::put, {{"ConfigureComponents"}}}, |
| 406 | {boost::beast::http::verb::delete_, {{"ConfigureComponents"}}}, |
| 407 | {boost::beast::http::verb::post, {{"ConfigureComponents"}}}}; |
Jennifer Lee | acb7cfb | 2018-06-07 16:08:15 -0700 | [diff] [blame] | 408 | } |
Jennifer Lee | acb7cfb | 2018-06-07 16:08:15 -0700 | [diff] [blame] | 409 | |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 410 | private: |
| 411 | void doGet(crow::Response &res, const crow::Request &req, |
| 412 | const std::vector<std::string> ¶ms) override |
| 413 | { |
Jayashankar Padath | 274dfe6 | 2019-08-23 12:30:57 +0530 | [diff] [blame] | 414 | std::shared_ptr<AsyncResp> aResp = std::make_shared<AsyncResp>(res); |
| 415 | res.jsonValue["@odata.type"] = "#UpdateService.v1_4_0.UpdateService"; |
Ed Tanous | 0f74e64 | 2018-11-12 15:17:05 -0800 | [diff] [blame] | 416 | res.jsonValue["@odata.id"] = "/redfish/v1/UpdateService"; |
Ed Tanous | 0f74e64 | 2018-11-12 15:17:05 -0800 | [diff] [blame] | 417 | res.jsonValue["Id"] = "UpdateService"; |
| 418 | res.jsonValue["Description"] = "Service for Software Update"; |
| 419 | res.jsonValue["Name"] = "Update Service"; |
| 420 | res.jsonValue["HttpPushUri"] = "/redfish/v1/UpdateService"; |
| 421 | // UpdateService cannot be disabled |
| 422 | res.jsonValue["ServiceEnabled"] = true; |
| 423 | res.jsonValue["FirmwareInventory"] = { |
| 424 | {"@odata.id", "/redfish/v1/UpdateService/FirmwareInventory"}}; |
Andrew Geissler | 0554c98 | 2019-04-23 14:40:12 -0500 | [diff] [blame] | 425 | #ifdef BMCWEB_INSECURE_ENABLE_REDFISH_FW_TFTP_UPDATE |
| 426 | // Update Actions object. |
| 427 | nlohmann::json &updateSvcSimpleUpdate = |
| 428 | res.jsonValue["Actions"]["#UpdateService.SimpleUpdate"]; |
| 429 | updateSvcSimpleUpdate["target"] = |
| 430 | "/redfish/v1/UpdateService/Actions/UpdateService.SimpleUpdate"; |
| 431 | updateSvcSimpleUpdate["TransferProtocol@Redfish.AllowableValues"] = { |
| 432 | "TFTP"}; |
| 433 | #endif |
Jayashankar Padath | 274dfe6 | 2019-08-23 12:30:57 +0530 | [diff] [blame] | 434 | // Get the current ApplyTime value |
| 435 | crow::connections::systemBus->async_method_call( |
| 436 | [aResp](const boost::system::error_code ec, |
| 437 | const std::variant<std::string> &applyTime) { |
| 438 | if (ec) |
| 439 | { |
| 440 | BMCWEB_LOG_DEBUG << "DBUS response error " << ec; |
| 441 | messages::internalError(aResp->res); |
| 442 | return; |
| 443 | } |
| 444 | |
| 445 | const std::string *s = std::get_if<std::string>(&applyTime); |
| 446 | if (s == nullptr) |
| 447 | { |
| 448 | return; |
| 449 | } |
| 450 | // Store the ApplyTime Value |
| 451 | if (*s == "xyz.openbmc_project.Software.ApplyTime." |
| 452 | "RequestedApplyTimes.Immediate") |
| 453 | { |
| 454 | aResp->res.jsonValue["HttpPushUriOptions"] |
| 455 | ["HttpPushUriApplyTime"]["ApplyTime"] = |
| 456 | "Immediate"; |
| 457 | } |
| 458 | else if (*s == "xyz.openbmc_project.Software.ApplyTime." |
| 459 | "RequestedApplyTimes.OnReset") |
| 460 | { |
| 461 | aResp->res.jsonValue["HttpPushUriOptions"] |
| 462 | ["HttpPushUriApplyTime"]["ApplyTime"] = |
| 463 | "OnReset"; |
| 464 | } |
| 465 | }, |
| 466 | "xyz.openbmc_project.Settings", |
| 467 | "/xyz/openbmc_project/software/apply_time", |
| 468 | "org.freedesktop.DBus.Properties", "Get", |
| 469 | "xyz.openbmc_project.Software.ApplyTime", "RequestedApplyTime"); |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 470 | } |
Andrew Geissler | 0e7de46 | 2019-03-04 19:11:54 -0600 | [diff] [blame] | 471 | |
Jayashankar Padath | fa1a5a3 | 2019-05-28 23:54:37 +0530 | [diff] [blame] | 472 | void doPatch(crow::Response &res, const crow::Request &req, |
| 473 | const std::vector<std::string> ¶ms) override |
| 474 | { |
| 475 | BMCWEB_LOG_DEBUG << "doPatch..."; |
| 476 | |
| 477 | std::shared_ptr<AsyncResp> asyncResp = std::make_shared<AsyncResp>(res); |
Jayashankar Padath | fa1a5a3 | 2019-05-28 23:54:37 +0530 | [diff] [blame] | 478 | |
Jayashankar Padath | 274dfe6 | 2019-08-23 12:30:57 +0530 | [diff] [blame] | 479 | std::optional<nlohmann::json> pushUriOptions; |
| 480 | if (!json_util::readJson(req, res, "HttpPushUriOptions", |
| 481 | pushUriOptions)) |
Jayashankar Padath | fa1a5a3 | 2019-05-28 23:54:37 +0530 | [diff] [blame] | 482 | { |
| 483 | return; |
| 484 | } |
| 485 | |
Jayashankar Padath | 274dfe6 | 2019-08-23 12:30:57 +0530 | [diff] [blame] | 486 | if (pushUriOptions) |
Jayashankar Padath | fa1a5a3 | 2019-05-28 23:54:37 +0530 | [diff] [blame] | 487 | { |
Jayashankar Padath | 274dfe6 | 2019-08-23 12:30:57 +0530 | [diff] [blame] | 488 | std::optional<nlohmann::json> pushUriApplyTime; |
| 489 | if (!json_util::readJson(*pushUriOptions, res, |
| 490 | "HttpPushUriApplyTime", pushUriApplyTime)) |
Jayashankar Padath | fa1a5a3 | 2019-05-28 23:54:37 +0530 | [diff] [blame] | 491 | { |
Jayashankar Padath | 274dfe6 | 2019-08-23 12:30:57 +0530 | [diff] [blame] | 492 | return; |
Jayashankar Padath | fa1a5a3 | 2019-05-28 23:54:37 +0530 | [diff] [blame] | 493 | } |
| 494 | |
Jayashankar Padath | 274dfe6 | 2019-08-23 12:30:57 +0530 | [diff] [blame] | 495 | if (pushUriApplyTime) |
| 496 | { |
| 497 | std::optional<std::string> applyTime; |
| 498 | if (!json_util::readJson(*pushUriApplyTime, res, "ApplyTime", |
| 499 | applyTime)) |
| 500 | { |
| 501 | return; |
| 502 | } |
| 503 | |
| 504 | if (applyTime) |
| 505 | { |
| 506 | std::string applyTimeNewVal; |
| 507 | if (applyTime == "Immediate") |
Jayashankar Padath | fa1a5a3 | 2019-05-28 23:54:37 +0530 | [diff] [blame] | 508 | { |
Jayashankar Padath | 274dfe6 | 2019-08-23 12:30:57 +0530 | [diff] [blame] | 509 | applyTimeNewVal = |
| 510 | "xyz.openbmc_project.Software.ApplyTime." |
| 511 | "RequestedApplyTimes.Immediate"; |
| 512 | } |
| 513 | else if (applyTime == "OnReset") |
| 514 | { |
| 515 | applyTimeNewVal = |
| 516 | "xyz.openbmc_project.Software.ApplyTime." |
| 517 | "RequestedApplyTimes.OnReset"; |
| 518 | } |
| 519 | else |
| 520 | { |
| 521 | BMCWEB_LOG_INFO |
| 522 | << "ApplyTime value is not in the list of " |
| 523 | "acceptable values"; |
| 524 | messages::propertyValueNotInList( |
| 525 | asyncResp->res, *applyTime, "ApplyTime"); |
Jayashankar Padath | fa1a5a3 | 2019-05-28 23:54:37 +0530 | [diff] [blame] | 526 | return; |
| 527 | } |
Jayashankar Padath | 274dfe6 | 2019-08-23 12:30:57 +0530 | [diff] [blame] | 528 | |
| 529 | // Set the requested image apply time value |
| 530 | crow::connections::systemBus->async_method_call( |
| 531 | [asyncResp](const boost::system::error_code ec) { |
| 532 | if (ec) |
| 533 | { |
| 534 | BMCWEB_LOG_ERROR << "D-Bus responses error: " |
| 535 | << ec; |
| 536 | messages::internalError(asyncResp->res); |
| 537 | return; |
| 538 | } |
| 539 | messages::success(asyncResp->res); |
| 540 | }, |
| 541 | "xyz.openbmc_project.Settings", |
| 542 | "/xyz/openbmc_project/software/apply_time", |
| 543 | "org.freedesktop.DBus.Properties", "Set", |
| 544 | "xyz.openbmc_project.Software.ApplyTime", |
| 545 | "RequestedApplyTime", |
| 546 | std::variant<std::string>{applyTimeNewVal}); |
| 547 | } |
| 548 | } |
Jayashankar Padath | fa1a5a3 | 2019-05-28 23:54:37 +0530 | [diff] [blame] | 549 | } |
| 550 | } |
| 551 | |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 552 | void doPost(crow::Response &res, const crow::Request &req, |
| 553 | const std::vector<std::string> ¶ms) override |
| 554 | { |
| 555 | BMCWEB_LOG_DEBUG << "doPost..."; |
Jennifer Lee | acb7cfb | 2018-06-07 16:08:15 -0700 | [diff] [blame] | 556 | |
Andrew Geissler | 0e7de46 | 2019-03-04 19:11:54 -0600 | [diff] [blame] | 557 | std::shared_ptr<AsyncResp> asyncResp = std::make_shared<AsyncResp>(res); |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 558 | |
Andrew Geissler | 86adcd6 | 2019-04-18 10:58:05 -0500 | [diff] [blame] | 559 | // Setup callback for when new software detected |
| 560 | monitorForSoftwareAvailable(asyncResp, req); |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 561 | |
| 562 | std::string filepath( |
| 563 | "/tmp/images/" + |
| 564 | boost::uuids::to_string(boost::uuids::random_generator()())); |
| 565 | BMCWEB_LOG_DEBUG << "Writing file to " << filepath; |
| 566 | std::ofstream out(filepath, std::ofstream::out | std::ofstream::binary | |
| 567 | std::ofstream::trunc); |
| 568 | out << req.body; |
| 569 | out.close(); |
| 570 | BMCWEB_LOG_DEBUG << "file upload complete!!"; |
| 571 | } |
Jennifer Lee | 729dae7 | 2018-04-24 15:59:34 -0700 | [diff] [blame] | 572 | }; |
Ed Tanous | c711bf8 | 2018-07-30 16:31:33 -0700 | [diff] [blame] | 573 | |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 574 | class SoftwareInventoryCollection : public Node |
| 575 | { |
| 576 | public: |
| 577 | template <typename CrowApp> |
| 578 | SoftwareInventoryCollection(CrowApp &app) : |
| 579 | Node(app, "/redfish/v1/UpdateService/FirmwareInventory/") |
| 580 | { |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 581 | entityPrivileges = { |
| 582 | {boost::beast::http::verb::get, {{"Login"}}}, |
| 583 | {boost::beast::http::verb::head, {{"Login"}}}, |
| 584 | {boost::beast::http::verb::patch, {{"ConfigureComponents"}}}, |
| 585 | {boost::beast::http::verb::put, {{"ConfigureComponents"}}}, |
| 586 | {boost::beast::http::verb::delete_, {{"ConfigureComponents"}}}, |
| 587 | {boost::beast::http::verb::post, {{"ConfigureComponents"}}}}; |
Jennifer Lee | 729dae7 | 2018-04-24 15:59:34 -0700 | [diff] [blame] | 588 | } |
Jennifer Lee | 729dae7 | 2018-04-24 15:59:34 -0700 | [diff] [blame] | 589 | |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 590 | private: |
| 591 | void doGet(crow::Response &res, const crow::Request &req, |
| 592 | const std::vector<std::string> ¶ms) override |
| 593 | { |
| 594 | std::shared_ptr<AsyncResp> asyncResp = std::make_shared<AsyncResp>(res); |
Ed Tanous | 0f74e64 | 2018-11-12 15:17:05 -0800 | [diff] [blame] | 595 | res.jsonValue["@odata.type"] = |
| 596 | "#SoftwareInventoryCollection.SoftwareInventoryCollection"; |
| 597 | res.jsonValue["@odata.id"] = |
| 598 | "/redfish/v1/UpdateService/FirmwareInventory"; |
Ed Tanous | 0f74e64 | 2018-11-12 15:17:05 -0800 | [diff] [blame] | 599 | res.jsonValue["Name"] = "Software Inventory Collection"; |
Ed Tanous | c711bf8 | 2018-07-30 16:31:33 -0700 | [diff] [blame] | 600 | |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 601 | crow::connections::systemBus->async_method_call( |
| 602 | [asyncResp]( |
| 603 | const boost::system::error_code ec, |
| 604 | const std::vector<std::pair< |
| 605 | std::string, std::vector<std::pair< |
| 606 | std::string, std::vector<std::string>>>>> |
| 607 | &subtree) { |
| 608 | if (ec) |
| 609 | { |
Jason M. Bills | f12894f | 2018-10-09 12:45:45 -0700 | [diff] [blame] | 610 | messages::internalError(asyncResp->res); |
Ed Tanous | c711bf8 | 2018-07-30 16:31:33 -0700 | [diff] [blame] | 611 | return; |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 612 | } |
| 613 | asyncResp->res.jsonValue["Members"] = nlohmann::json::array(); |
| 614 | asyncResp->res.jsonValue["Members@odata.count"] = 0; |
Jennifer Lee | 6c4eb9d | 2018-05-22 10:58:31 -0700 | [diff] [blame] | 615 | |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 616 | for (auto &obj : subtree) |
| 617 | { |
Jennifer Lee | f4b65ab | 2018-09-18 12:00:13 -0700 | [diff] [blame] | 618 | // if can't parse fw id then return |
Ed Tanous | 27826b5 | 2018-10-29 11:40:58 -0700 | [diff] [blame] | 619 | std::size_t idPos; |
| 620 | if ((idPos = obj.first.rfind("/")) == std::string::npos) |
Jennifer Lee | f4b65ab | 2018-09-18 12:00:13 -0700 | [diff] [blame] | 621 | { |
Jason M. Bills | f12894f | 2018-10-09 12:45:45 -0700 | [diff] [blame] | 622 | messages::internalError(asyncResp->res); |
Jennifer Lee | f4b65ab | 2018-09-18 12:00:13 -0700 | [diff] [blame] | 623 | BMCWEB_LOG_DEBUG << "Can't parse firmware ID!!"; |
| 624 | return; |
| 625 | } |
Jennifer Lee | f4b65ab | 2018-09-18 12:00:13 -0700 | [diff] [blame] | 626 | std::string swId = obj.first.substr(idPos + 1); |
| 627 | |
Andrew Geissler | e0dd805 | 2019-06-18 16:05:10 -0500 | [diff] [blame] | 628 | nlohmann::json &members = |
| 629 | asyncResp->res.jsonValue["Members"]; |
| 630 | members.push_back( |
| 631 | {{"@odata.id", "/redfish/v1/UpdateService/" |
| 632 | "FirmwareInventory/" + |
| 633 | swId}}); |
| 634 | asyncResp->res.jsonValue["Members@odata.count"] = |
| 635 | members.size(); |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 636 | } |
| 637 | }, |
Andrew Geissler | 2830a9c | 2020-01-06 10:18:11 -0600 | [diff] [blame] | 638 | // Note that only firmware levels associated with a device are |
| 639 | // stored under /xyz/openbmc_project/software therefore to ensure |
| 640 | // only real FirmwareInventory items are returned, this full object |
| 641 | // path must be used here as input to mapper |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 642 | "xyz.openbmc_project.ObjectMapper", |
| 643 | "/xyz/openbmc_project/object_mapper", |
Andrew Geissler | 2830a9c | 2020-01-06 10:18:11 -0600 | [diff] [blame] | 644 | "xyz.openbmc_project.ObjectMapper", "GetSubTree", |
| 645 | "/xyz/openbmc_project/software", static_cast<int32_t>(0), |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 646 | std::array<const char *, 1>{ |
| 647 | "xyz.openbmc_project.Software.Version"}); |
| 648 | } |
Jennifer Lee | 729dae7 | 2018-04-24 15:59:34 -0700 | [diff] [blame] | 649 | }; |
| 650 | |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 651 | class SoftwareInventory : public Node |
| 652 | { |
| 653 | public: |
| 654 | template <typename CrowApp> |
| 655 | SoftwareInventory(CrowApp &app) : |
| 656 | Node(app, "/redfish/v1/UpdateService/FirmwareInventory/<str>/", |
| 657 | std::string()) |
| 658 | { |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 659 | entityPrivileges = { |
| 660 | {boost::beast::http::verb::get, {{"Login"}}}, |
| 661 | {boost::beast::http::verb::head, {{"Login"}}}, |
| 662 | {boost::beast::http::verb::patch, {{"ConfigureComponents"}}}, |
| 663 | {boost::beast::http::verb::put, {{"ConfigureComponents"}}}, |
| 664 | {boost::beast::http::verb::delete_, {{"ConfigureComponents"}}}, |
| 665 | {boost::beast::http::verb::post, {{"ConfigureComponents"}}}}; |
| 666 | } |
| 667 | |
| 668 | private: |
Andrew Geissler | 87d8472 | 2019-02-28 14:28:39 -0600 | [diff] [blame] | 669 | /* Fill related item links (i.e. bmc, bios) in for inventory */ |
| 670 | static void getRelatedItems(std::shared_ptr<AsyncResp> aResp, |
| 671 | const std::string &purpose) |
| 672 | { |
| 673 | if (purpose == fw_util::bmcPurpose) |
| 674 | { |
| 675 | nlohmann::json &members = aResp->res.jsonValue["RelatedItem"]; |
| 676 | members.push_back({{"@odata.id", "/redfish/v1/Managers/bmc"}}); |
| 677 | aResp->res.jsonValue["Members@odata.count"] = members.size(); |
| 678 | } |
| 679 | else if (purpose == fw_util::biosPurpose) |
| 680 | { |
Gunnar Mills | f723d73 | 2020-02-26 11:20:49 -0600 | [diff] [blame] | 681 | nlohmann::json &members = aResp->res.jsonValue["RelatedItem"]; |
| 682 | members.push_back( |
| 683 | {{"@odata.id", "/redfish/v1/Systems/system/Bios"}}); |
| 684 | aResp->res.jsonValue["Members@odata.count"] = members.size(); |
Andrew Geissler | 87d8472 | 2019-02-28 14:28:39 -0600 | [diff] [blame] | 685 | } |
| 686 | else |
| 687 | { |
| 688 | BMCWEB_LOG_ERROR << "Unknown software purpose " << purpose; |
| 689 | } |
| 690 | } |
| 691 | |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 692 | void doGet(crow::Response &res, const crow::Request &req, |
| 693 | const std::vector<std::string> ¶ms) override |
| 694 | { |
| 695 | std::shared_ptr<AsyncResp> asyncResp = std::make_shared<AsyncResp>(res); |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 696 | |
| 697 | if (params.size() != 1) |
| 698 | { |
Jason M. Bills | f12894f | 2018-10-09 12:45:45 -0700 | [diff] [blame] | 699 | messages::internalError(res); |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 700 | res.end(); |
| 701 | return; |
| 702 | } |
| 703 | |
Ed Tanous | 3ae837c | 2018-08-07 14:41:19 -0700 | [diff] [blame] | 704 | std::shared_ptr<std::string> swId = |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 705 | std::make_shared<std::string>(params[0]); |
| 706 | |
| 707 | res.jsonValue["@odata.id"] = |
Ed Tanous | 3ae837c | 2018-08-07 14:41:19 -0700 | [diff] [blame] | 708 | "/redfish/v1/UpdateService/FirmwareInventory/" + *swId; |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 709 | |
| 710 | crow::connections::systemBus->async_method_call( |
Ed Tanous | 3ae837c | 2018-08-07 14:41:19 -0700 | [diff] [blame] | 711 | [asyncResp, swId]( |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 712 | const boost::system::error_code ec, |
| 713 | const std::vector<std::pair< |
| 714 | std::string, std::vector<std::pair< |
| 715 | std::string, std::vector<std::string>>>>> |
| 716 | &subtree) { |
| 717 | BMCWEB_LOG_DEBUG << "doGet callback..."; |
| 718 | if (ec) |
| 719 | { |
Jason M. Bills | f12894f | 2018-10-09 12:45:45 -0700 | [diff] [blame] | 720 | messages::internalError(asyncResp->res); |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 721 | return; |
| 722 | } |
| 723 | |
Andrew Geissler | 6913228 | 2019-07-01 11:00:35 -0500 | [diff] [blame] | 724 | // Ensure we find our input swId, otherwise return an error |
| 725 | bool found = false; |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 726 | for (const std::pair< |
| 727 | std::string, |
| 728 | std::vector< |
| 729 | std::pair<std::string, std::vector<std::string>>>> |
| 730 | &obj : subtree) |
| 731 | { |
Ed Tanous | 3ae837c | 2018-08-07 14:41:19 -0700 | [diff] [blame] | 732 | if (boost::ends_with(obj.first, *swId) != true) |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 733 | { |
| 734 | continue; |
| 735 | } |
| 736 | |
Jennifer Lee | f4b65ab | 2018-09-18 12:00:13 -0700 | [diff] [blame] | 737 | if (obj.second.size() < 1) |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 738 | { |
| 739 | continue; |
| 740 | } |
| 741 | |
Andrew Geissler | 6913228 | 2019-07-01 11:00:35 -0500 | [diff] [blame] | 742 | found = true; |
Andrew Geissler | e0dd805 | 2019-06-18 16:05:10 -0500 | [diff] [blame] | 743 | fw_util::getFwStatus(asyncResp, swId, obj.second[0].first); |
| 744 | |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 745 | crow::connections::systemBus->async_method_call( |
| 746 | [asyncResp, |
Ed Tanous | 3ae837c | 2018-08-07 14:41:19 -0700 | [diff] [blame] | 747 | swId](const boost::system::error_code error_code, |
| 748 | const boost::container::flat_map< |
| 749 | std::string, VariantType> &propertiesList) { |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 750 | if (error_code) |
| 751 | { |
Jason M. Bills | f12894f | 2018-10-09 12:45:45 -0700 | [diff] [blame] | 752 | messages::internalError(asyncResp->res); |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 753 | return; |
| 754 | } |
| 755 | boost::container::flat_map< |
| 756 | std::string, VariantType>::const_iterator it = |
| 757 | propertiesList.find("Purpose"); |
| 758 | if (it == propertiesList.end()) |
| 759 | { |
| 760 | BMCWEB_LOG_DEBUG |
| 761 | << "Can't find property \"Purpose\"!"; |
Jason M. Bills | f12894f | 2018-10-09 12:45:45 -0700 | [diff] [blame] | 762 | messages::propertyMissing(asyncResp->res, |
| 763 | "Purpose"); |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 764 | return; |
| 765 | } |
Ed Tanous | 3ae837c | 2018-08-07 14:41:19 -0700 | [diff] [blame] | 766 | const std::string *swInvPurpose = |
Ed Tanous | abf2add | 2019-01-22 16:40:12 -0800 | [diff] [blame] | 767 | std::get_if<std::string>(&it->second); |
Ed Tanous | 3ae837c | 2018-08-07 14:41:19 -0700 | [diff] [blame] | 768 | if (swInvPurpose == nullptr) |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 769 | { |
| 770 | BMCWEB_LOG_DEBUG |
| 771 | << "wrong types for property\"Purpose\"!"; |
Jason M. Bills | f12894f | 2018-10-09 12:45:45 -0700 | [diff] [blame] | 772 | messages::propertyValueTypeError(asyncResp->res, |
| 773 | "", "Purpose"); |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 774 | return; |
| 775 | } |
| 776 | |
Ed Tanous | 3ae837c | 2018-08-07 14:41:19 -0700 | [diff] [blame] | 777 | BMCWEB_LOG_DEBUG << "swInvPurpose = " |
| 778 | << *swInvPurpose; |
Jennifer Lee | f4b65ab | 2018-09-18 12:00:13 -0700 | [diff] [blame] | 779 | it = propertiesList.find("Version"); |
| 780 | if (it == propertiesList.end()) |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 781 | { |
Jennifer Lee | f4b65ab | 2018-09-18 12:00:13 -0700 | [diff] [blame] | 782 | BMCWEB_LOG_DEBUG |
| 783 | << "Can't find property \"Version\"!"; |
Jason M. Bills | f12894f | 2018-10-09 12:45:45 -0700 | [diff] [blame] | 784 | messages::propertyMissing(asyncResp->res, |
| 785 | "Version"); |
Jennifer Lee | f4b65ab | 2018-09-18 12:00:13 -0700 | [diff] [blame] | 786 | return; |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 787 | } |
Jennifer Lee | f4b65ab | 2018-09-18 12:00:13 -0700 | [diff] [blame] | 788 | |
| 789 | BMCWEB_LOG_DEBUG << "Version found!"; |
| 790 | |
| 791 | const std::string *version = |
Ed Tanous | abf2add | 2019-01-22 16:40:12 -0800 | [diff] [blame] | 792 | std::get_if<std::string>(&it->second); |
Jennifer Lee | f4b65ab | 2018-09-18 12:00:13 -0700 | [diff] [blame] | 793 | |
| 794 | if (version == nullptr) |
| 795 | { |
| 796 | BMCWEB_LOG_DEBUG |
| 797 | << "Can't find property \"Version\"!"; |
Jason M. Bills | f12894f | 2018-10-09 12:45:45 -0700 | [diff] [blame] | 798 | |
| 799 | messages::propertyValueTypeError(asyncResp->res, |
| 800 | "", "Version"); |
Jennifer Lee | f4b65ab | 2018-09-18 12:00:13 -0700 | [diff] [blame] | 801 | return; |
| 802 | } |
| 803 | asyncResp->res.jsonValue["Version"] = *version; |
| 804 | asyncResp->res.jsonValue["Id"] = *swId; |
Andrew Geissler | 54daabe | 2019-02-13 13:54:15 -0600 | [diff] [blame] | 805 | |
| 806 | // swInvPurpose is of format: |
| 807 | // xyz.openbmc_project.Software.Version.VersionPurpose.ABC |
James Feist | e2e9677 | 2019-10-03 10:51:43 -0700 | [diff] [blame] | 808 | // Translate this to "ABC image" |
Andrew Geissler | 54daabe | 2019-02-13 13:54:15 -0600 | [diff] [blame] | 809 | size_t endDesc = swInvPurpose->rfind("."); |
| 810 | if (endDesc == std::string::npos) |
| 811 | { |
| 812 | messages::internalError(asyncResp->res); |
| 813 | return; |
| 814 | } |
| 815 | endDesc++; |
| 816 | if (endDesc >= swInvPurpose->size()) |
| 817 | { |
| 818 | messages::internalError(asyncResp->res); |
| 819 | return; |
| 820 | } |
| 821 | |
| 822 | std::string formatDesc = |
| 823 | swInvPurpose->substr(endDesc); |
| 824 | asyncResp->res.jsonValue["Description"] = |
James Feist | e2e9677 | 2019-10-03 10:51:43 -0700 | [diff] [blame] | 825 | formatDesc + " image"; |
Andrew Geissler | 87d8472 | 2019-02-28 14:28:39 -0600 | [diff] [blame] | 826 | getRelatedItems(asyncResp, *swInvPurpose); |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 827 | }, |
| 828 | obj.second[0].first, obj.first, |
| 829 | "org.freedesktop.DBus.Properties", "GetAll", |
| 830 | "xyz.openbmc_project.Software.Version"); |
| 831 | } |
Andrew Geissler | 6913228 | 2019-07-01 11:00:35 -0500 | [diff] [blame] | 832 | if (!found) |
| 833 | { |
| 834 | BMCWEB_LOG_ERROR << "Input swID " + *swId + " not found!"; |
| 835 | messages::resourceMissingAtURI( |
| 836 | asyncResp->res, |
| 837 | "/redfish/v1/UpdateService/FirmwareInventory/" + *swId); |
| 838 | return; |
| 839 | } |
Ayushi Smriti | 4e68c45 | 2019-09-04 14:37:55 +0530 | [diff] [blame] | 840 | asyncResp->res.jsonValue["@odata.type"] = |
| 841 | "#SoftwareInventory.v1_1_0.SoftwareInventory"; |
Ayushi Smriti | 4e68c45 | 2019-09-04 14:37:55 +0530 | [diff] [blame] | 842 | asyncResp->res.jsonValue["Name"] = "Software Inventory"; |
Ayushi Smriti | 4e68c45 | 2019-09-04 14:37:55 +0530 | [diff] [blame] | 843 | asyncResp->res.jsonValue["Status"]["HealthRollup"] = "OK"; |
AppaRao Puli | 3f8a743 | 2020-01-29 02:36:32 +0530 | [diff] [blame] | 844 | |
| 845 | asyncResp->res.jsonValue["Updateable"] = false; |
| 846 | fw_util::getFwUpdateableStatus(asyncResp, swId); |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 847 | }, |
| 848 | "xyz.openbmc_project.ObjectMapper", |
| 849 | "/xyz/openbmc_project/object_mapper", |
Ed Tanous | 271584a | 2019-07-09 16:24:22 -0700 | [diff] [blame] | 850 | "xyz.openbmc_project.ObjectMapper", "GetSubTree", "/", |
| 851 | static_cast<int32_t>(0), |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 852 | std::array<const char *, 1>{ |
| 853 | "xyz.openbmc_project.Software.Version"}); |
| 854 | } |
| 855 | }; |
| 856 | |
| 857 | } // namespace redfish |