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