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