blob: 7e6a0b807fb6bf2664013e562310478e6dcbfccd [file] [log] [blame]
Jennifer Lee729dae72018-04-24 15:59:34 -07001/*
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 Tanous1abe55e2018-09-05 08:30:59 -070019
Jennifer Lee729dae72018-04-24 15:59:34 -070020#include <boost/container/flat_map.hpp>
Andrew Geissler87d84722019-02-28 14:28:39 -060021#include <utils/fw_utils.hpp>
Gunnar Mills1214b7e2020-06-04 10:11:30 -050022
Ed Tanousabf2add2019-01-22 16:40:12 -080023#include <variant>
Jennifer Lee729dae72018-04-24 15:59:34 -070024
Ed Tanous1abe55e2018-09-05 08:30:59 -070025namespace redfish
26{
Ed Tanous27826b52018-10-29 11:40:58 -070027
Andrew Geissler0e7de462019-03-04 19:11:54 -060028// Match signals added on software path
Jennifer Leeacb7cfb2018-06-07 16:08:15 -070029static std::unique_ptr<sdbusplus::bus::match::match> fwUpdateMatcher;
James Feist4cde5d92020-06-11 10:39:55 -070030static std::unique_ptr<sdbusplus::bus::match::match> fwUpdateErrorMatcher;
Andrew Geissler0e7de462019-03-04 19:11:54 -060031// Only allow one update at a time
32static bool fwUpdateInProgress = false;
Andrew Geissler86adcd62019-04-18 10:58:05 -050033// Timer for software available
Ed Tanous271584a2019-07-09 16:24:22 -070034static std::unique_ptr<boost::asio::steady_timer> fwAvailableTimer;
Andrew Geissler86adcd62019-04-18 10:58:05 -050035
36static void cleanUp()
37{
38 fwUpdateInProgress = false;
39 fwUpdateMatcher = nullptr;
James Feist4cde5d92020-06-11 10:39:55 -070040 fwUpdateErrorMatcher = nullptr;
Andrew Geissler86adcd62019-04-18 10:58:05 -050041}
Gunnar Mills1214b7e2020-06-04 10:11:30 -050042static void activateImage(const std::string& objPath,
43 const std::string& service)
Andrew Geissler86adcd62019-04-18 10:58:05 -050044{
45 BMCWEB_LOG_DEBUG << "Activate image for " << objPath << " " << service;
46 crow::connections::systemBus->async_method_call(
47 [](const boost::system::error_code error_code) {
48 if (error_code)
49 {
50 BMCWEB_LOG_DEBUG << "error_code = " << error_code;
51 BMCWEB_LOG_DEBUG << "error msg = " << error_code.message();
52 }
53 },
54 service, objPath, "org.freedesktop.DBus.Properties", "Set",
55 "xyz.openbmc_project.Software.Activation", "RequestedActivation",
56 std::variant<std::string>(
57 "xyz.openbmc_project.Software.Activation.RequestedActivations."
58 "Active"));
59}
Andrew Geissler0554c982019-04-23 14:40:12 -050060
61// Note that asyncResp can be either a valid pointer or nullptr. If nullptr
62// then no asyncResp updates will occur
Ed Tanousb5a76932020-09-29 16:16:58 -070063static void softwareInterfaceAdded(const std::shared_ptr<AsyncResp>& asyncResp,
Gunnar Mills1214b7e2020-06-04 10:11:30 -050064 sdbusplus::message::message& m,
65 const crow::Request& req)
Andrew Geissler86adcd62019-04-18 10:58:05 -050066{
67 std::vector<std::pair<
68 std::string,
69 std::vector<std::pair<std::string, std::variant<std::string>>>>>
70 interfacesProperties;
71
72 sdbusplus::message::object_path objPath;
73
74 m.read(objPath, interfacesProperties);
75
76 BMCWEB_LOG_DEBUG << "obj path = " << objPath.str;
Gunnar Mills1214b7e2020-06-04 10:11:30 -050077 for (auto& interface : interfacesProperties)
Andrew Geissler86adcd62019-04-18 10:58:05 -050078 {
79 BMCWEB_LOG_DEBUG << "interface = " << interface.first;
80
81 if (interface.first == "xyz.openbmc_project.Software.Activation")
82 {
83 // Found our interface, disable callbacks
84 fwUpdateMatcher = nullptr;
85
86 // Retrieve service and activate
87 crow::connections::systemBus->async_method_call(
James Feistfe306722020-03-12 16:32:08 -070088 [objPath, asyncResp,
89 req](const boost::system::error_code error_code,
90 const std::vector<std::pair<
Gunnar Mills1214b7e2020-06-04 10:11:30 -050091 std::string, std::vector<std::string>>>& objInfo) {
Andrew Geissler86adcd62019-04-18 10:58:05 -050092 if (error_code)
93 {
94 BMCWEB_LOG_DEBUG << "error_code = " << error_code;
95 BMCWEB_LOG_DEBUG << "error msg = "
96 << error_code.message();
Andrew Geissler0554c982019-04-23 14:40:12 -050097 if (asyncResp)
98 {
99 messages::internalError(asyncResp->res);
100 }
Andrew Geissler86adcd62019-04-18 10:58:05 -0500101 cleanUp();
102 return;
103 }
104 // Ensure we only got one service back
105 if (objInfo.size() != 1)
106 {
107 BMCWEB_LOG_ERROR << "Invalid Object Size "
108 << objInfo.size();
Andrew Geissler0554c982019-04-23 14:40:12 -0500109 if (asyncResp)
110 {
111 messages::internalError(asyncResp->res);
112 }
Andrew Geissler86adcd62019-04-18 10:58:05 -0500113 cleanUp();
114 return;
115 }
116 // cancel timer only when
117 // xyz.openbmc_project.Software.Activation interface
118 // is added
119 fwAvailableTimer = nullptr;
120
121 activateImage(objPath.str, objInfo[0].first);
Andrew Geissler0554c982019-04-23 14:40:12 -0500122 if (asyncResp)
123 {
James Feist32898ce2020-03-10 16:16:52 -0700124 std::shared_ptr<task::TaskData> task =
125 task::TaskData::createTask(
126 [](boost::system::error_code ec,
Gunnar Mills1214b7e2020-06-04 10:11:30 -0500127 sdbusplus::message::message& msg,
128 const std::shared_ptr<task::TaskData>&
129 taskData) {
James Feist32898ce2020-03-10 16:16:52 -0700130 if (ec)
131 {
132 return task::completed;
133 }
134
135 std::string iface;
136 boost::container::flat_map<
James Feistfd9ab9e2020-05-19 13:48:07 -0700137 std::string,
138 std::variant<std::string, uint8_t>>
James Feist32898ce2020-03-10 16:16:52 -0700139 values;
James Feist32898ce2020-03-10 16:16:52 -0700140
James Feiste5d50062020-05-11 17:29:00 -0700141 std::string index =
142 std::to_string(taskData->index);
James Feistfd9ab9e2020-05-19 13:48:07 -0700143 msg.read(iface, values);
James Feiste5d50062020-05-11 17:29:00 -0700144
James Feistfd9ab9e2020-05-19 13:48:07 -0700145 if (iface == "xyz.openbmc_project.Software."
146 "Activation")
James Feist32898ce2020-03-10 16:16:52 -0700147 {
James Feistfd9ab9e2020-05-19 13:48:07 -0700148 auto findActivation =
149 values.find("Activation");
150 if (findActivation == values.end())
151 {
152 return !task::completed;
153 }
Gunnar Mills1214b7e2020-06-04 10:11:30 -0500154 std::string* state =
James Feistfd9ab9e2020-05-19 13:48:07 -0700155 std::get_if<std::string>(
156 &(findActivation->second));
157
158 if (state == nullptr)
159 {
160 taskData->messages.emplace_back(
161 messages::internalError());
162 return task::completed;
163 }
164
165 if (boost::ends_with(*state,
166 "Invalid") ||
167 boost::ends_with(*state, "Failed"))
168 {
169 taskData->state = "Exception";
170 taskData->status = "Warning";
171 taskData->messages.emplace_back(
172 messages::taskAborted(index));
173 return task::completed;
174 }
175
176 if (boost::ends_with(*state, "Staged"))
177 {
178 taskData->state = "Stopping";
179 taskData->messages.emplace_back(
180 messages::taskPaused(index));
181
182 // its staged, set a long timer to
183 // allow them time to complete the
184 // update (probably cycle the
185 // system) if this expires then
186 // task will be cancelled
187 taskData->extendTimer(
188 std::chrono::hours(5));
189 return !task::completed;
190 }
191
192 if (boost::ends_with(*state, "Active"))
193 {
194 taskData->messages.emplace_back(
195 messages::taskCompletedOK(
196 index));
197 taskData->state = "Completed";
198 return task::completed;
199 }
James Feist32898ce2020-03-10 16:16:52 -0700200 }
James Feistfd9ab9e2020-05-19 13:48:07 -0700201 else if (iface ==
202 "xyz.openbmc_project.Software."
203 "ActivationProgress")
James Feist32898ce2020-03-10 16:16:52 -0700204 {
James Feistfd9ab9e2020-05-19 13:48:07 -0700205 auto findProgress =
206 values.find("Progress");
207 if (findProgress == values.end())
208 {
209 return !task::completed;
210 }
Gunnar Mills1214b7e2020-06-04 10:11:30 -0500211 uint8_t* progress =
James Feistfd9ab9e2020-05-19 13:48:07 -0700212 std::get_if<uint8_t>(
213 &(findProgress->second));
James Feist32898ce2020-03-10 16:16:52 -0700214
James Feistfd9ab9e2020-05-19 13:48:07 -0700215 if (progress == nullptr)
216 {
217 taskData->messages.emplace_back(
218 messages::internalError());
219 return task::completed;
220 }
James Feist32898ce2020-03-10 16:16:52 -0700221 taskData->messages.emplace_back(
James Feistfd9ab9e2020-05-19 13:48:07 -0700222 messages::taskProgressChanged(
223 index, static_cast<size_t>(
224 *progress)));
225
226 // if we're getting status updates it's
227 // still alive, update timer
228 taskData->extendTimer(
229 std::chrono::minutes(5));
James Feist32898ce2020-03-10 16:16:52 -0700230 }
231
232 // as firmware update often results in a
233 // reboot, the task may never "complete"
234 // unless it is an error
235
236 return !task::completed;
237 },
238 "type='signal',interface='org.freedesktop.DBus."
239 "Properties',"
James Feistfd9ab9e2020-05-19 13:48:07 -0700240 "member='PropertiesChanged',path='" +
James Feist32898ce2020-03-10 16:16:52 -0700241 objPath.str + "'");
242 task->startTimer(std::chrono::minutes(5));
243 task->populateResp(asyncResp->res);
James Feistfe306722020-03-12 16:32:08 -0700244 task->payload.emplace(req);
Andrew Geissler0554c982019-04-23 14:40:12 -0500245 }
Andrew Geissler86adcd62019-04-18 10:58:05 -0500246 fwUpdateInProgress = false;
247 },
248 "xyz.openbmc_project.ObjectMapper",
249 "/xyz/openbmc_project/object_mapper",
250 "xyz.openbmc_project.ObjectMapper", "GetObject", objPath.str,
Gunnar Mills1214b7e2020-06-04 10:11:30 -0500251 std::array<const char*, 1>{
Andrew Geissler86adcd62019-04-18 10:58:05 -0500252 "xyz.openbmc_project.Software.Activation"});
253 }
254 }
255}
256
Andrew Geissler0554c982019-04-23 14:40:12 -0500257// Note that asyncResp can be either a valid pointer or nullptr. If nullptr
258// then no asyncResp updates will occur
Ed Tanousb5a76932020-09-29 16:16:58 -0700259static void monitorForSoftwareAvailable(
260 const std::shared_ptr<AsyncResp>& asyncResp, const crow::Request& req,
261 const std::string& url, int timeoutTimeSeconds = 10)
Andrew Geissler86adcd62019-04-18 10:58:05 -0500262{
263 // Only allow one FW update at a time
264 if (fwUpdateInProgress != false)
265 {
Andrew Geissler0554c982019-04-23 14:40:12 -0500266 if (asyncResp)
267 {
Andrew Geissler0554c982019-04-23 14:40:12 -0500268 messages::serviceTemporarilyUnavailable(asyncResp->res, "30");
269 }
Andrew Geissler86adcd62019-04-18 10:58:05 -0500270 return;
271 }
272
Andrew Geissler0554c982019-04-23 14:40:12 -0500273 fwAvailableTimer =
Ed Tanous271584a2019-07-09 16:24:22 -0700274 std::make_unique<boost::asio::steady_timer>(*req.ioService);
Andrew Geissler86adcd62019-04-18 10:58:05 -0500275
Ed Tanous271584a2019-07-09 16:24:22 -0700276 fwAvailableTimer->expires_after(std::chrono::seconds(timeoutTimeSeconds));
Andrew Geissler86adcd62019-04-18 10:58:05 -0500277
278 fwAvailableTimer->async_wait(
Gunnar Mills1214b7e2020-06-04 10:11:30 -0500279 [asyncResp](const boost::system::error_code& ec) {
Andrew Geissler86adcd62019-04-18 10:58:05 -0500280 cleanUp();
281 if (ec == boost::asio::error::operation_aborted)
282 {
283 // expected, we were canceled before the timer completed.
284 return;
285 }
286 BMCWEB_LOG_ERROR
287 << "Timed out waiting for firmware object being created";
288 BMCWEB_LOG_ERROR
289 << "FW image may has already been uploaded to server";
290 if (ec)
291 {
292 BMCWEB_LOG_ERROR << "Async_wait failed" << ec;
293 return;
294 }
Andrew Geissler0554c982019-04-23 14:40:12 -0500295 if (asyncResp)
296 {
297 redfish::messages::internalError(asyncResp->res);
298 }
Andrew Geissler86adcd62019-04-18 10:58:05 -0500299 });
300
Gunnar Mills1214b7e2020-06-04 10:11:30 -0500301 auto callback = [asyncResp, req](sdbusplus::message::message& m) {
Andrew Geissler86adcd62019-04-18 10:58:05 -0500302 BMCWEB_LOG_DEBUG << "Match fired";
James Feistfe306722020-03-12 16:32:08 -0700303 softwareInterfaceAdded(asyncResp, m, req);
Andrew Geissler86adcd62019-04-18 10:58:05 -0500304 };
305
306 fwUpdateInProgress = true;
307
308 fwUpdateMatcher = std::make_unique<sdbusplus::bus::match::match>(
309 *crow::connections::systemBus,
310 "interface='org.freedesktop.DBus.ObjectManager',type='signal',"
311 "member='InterfacesAdded',path='/xyz/openbmc_project/software'",
312 callback);
James Feist4cde5d92020-06-11 10:39:55 -0700313
314 fwUpdateErrorMatcher = std::make_unique<sdbusplus::bus::match::match>(
315 *crow::connections::systemBus,
316 "type='signal',member='PropertiesChanged',path_namespace='/xyz/"
317 "openbmc_project/logging/entry',"
318 "arg0='xyz.openbmc_project.Logging.Entry'",
319 [asyncResp, url](sdbusplus::message::message& m) {
320 BMCWEB_LOG_DEBUG << "Error Match fired";
321 boost::container::flat_map<std::string, std::variant<std::string>>
322 values;
323 std::string objName;
324 m.read(objName, values);
325 auto find = values.find("Message");
326 if (find == values.end())
327 {
328 return;
329 }
330 std::string* type = std::get_if<std::string>(&(find->second));
331 if (type == nullptr)
332 {
333 return; // if this was our message, timeout will cover it
334 }
335 if (!boost::starts_with(*type,
336 "xyz.openbmc_project.Software.Image.Error"))
337 {
338 return;
339 }
340 if (*type ==
341 "xyz.openbmc_project.Software.Image.Error.UnTarFailure")
342 {
343 redfish::messages::invalidUpload(asyncResp->res, url,
344 "Invalid archive");
345 }
346 else if (*type == "xyz.openbmc_project.Software.Image.Error."
347 "ManifestFileFailure")
348 {
349 redfish::messages::invalidUpload(asyncResp->res, url,
350 "Invalid manifest");
351 }
352 else if (*type ==
353 "xyz.openbmc_project.Software.Image.Error.ImageFailure")
354 {
355 redfish::messages::invalidUpload(asyncResp->res, url,
356 "Invalid image format");
357 }
358 else if (*type ==
359 "xyz.openbmc_project.Software.Image.Error.BusyFailure")
360 {
361 redfish::messages::resourceExhaustion(asyncResp->res, url);
362 }
363 else
364 {
365 redfish::messages::internalError(asyncResp->res);
366 }
367 fwAvailableTimer = nullptr;
368 });
Andrew Geissler86adcd62019-04-18 10:58:05 -0500369}
Jennifer Lee729dae72018-04-24 15:59:34 -0700370
Andrew Geissler0554c982019-04-23 14:40:12 -0500371/**
372 * UpdateServiceActionsSimpleUpdate class supports handle POST method for
373 * SimpleUpdate action.
374 */
375class UpdateServiceActionsSimpleUpdate : public Node
376{
377 public:
Ed Tanous52cc1122020-07-18 13:51:21 -0700378 UpdateServiceActionsSimpleUpdate(App& app) :
Andrew Geissler0554c982019-04-23 14:40:12 -0500379 Node(app,
380 "/redfish/v1/UpdateService/Actions/UpdateService.SimpleUpdate/")
381 {
382 entityPrivileges = {
383 {boost::beast::http::verb::get, {{"Login"}}},
384 {boost::beast::http::verb::head, {{"Login"}}},
385 {boost::beast::http::verb::patch, {{"ConfigureManager"}}},
386 {boost::beast::http::verb::put, {{"ConfigureComponents"}}},
387 {boost::beast::http::verb::delete_, {{"ConfigureComponents"}}},
388 {boost::beast::http::verb::post, {{"ConfigureComponents"}}}};
389 }
390
391 private:
Gunnar Mills1214b7e2020-06-04 10:11:30 -0500392 void doPost(crow::Response& res, const crow::Request& req,
Ed Tanouscb13a392020-07-25 19:02:03 +0000393 const std::vector<std::string>&) override
Andrew Geissler0554c982019-04-23 14:40:12 -0500394 {
395 std::optional<std::string> transferProtocol;
396 std::string imageURI;
397 std::shared_ptr<AsyncResp> asyncResp = std::make_shared<AsyncResp>(res);
398
399 BMCWEB_LOG_DEBUG << "Enter UpdateService.SimpleUpdate doPost";
400
401 // User can pass in both TransferProtocol and ImageURI parameters or
Gunnar Mills4e0453b2020-07-08 14:00:30 -0500402 // they can pass in just the ImageURI with the transfer protocol
403 // embedded within it.
Andrew Geissler0554c982019-04-23 14:40:12 -0500404 // 1) TransferProtocol:TFTP ImageURI:1.1.1.1/myfile.bin
405 // 2) ImageURI:tftp://1.1.1.1/myfile.bin
406
407 if (!json_util::readJson(req, asyncResp->res, "TransferProtocol",
408 transferProtocol, "ImageURI", imageURI))
409 {
410 BMCWEB_LOG_DEBUG
411 << "Missing TransferProtocol or ImageURI parameter";
412 return;
413 }
414 if (!transferProtocol)
415 {
416 // Must be option 2
417 // Verify ImageURI has transfer protocol in it
418 size_t separator = imageURI.find(":");
419 if ((separator == std::string::npos) ||
420 ((separator + 1) > imageURI.size()))
421 {
422 messages::actionParameterValueTypeError(
423 asyncResp->res, imageURI, "ImageURI",
424 "UpdateService.SimpleUpdate");
425 BMCWEB_LOG_ERROR << "ImageURI missing transfer protocol: "
426 << imageURI;
427 return;
428 }
429 transferProtocol = imageURI.substr(0, separator);
430 // Ensure protocol is upper case for a common comparison path below
431 boost::to_upper(*transferProtocol);
432 BMCWEB_LOG_DEBUG << "Encoded transfer protocol "
433 << *transferProtocol;
434
435 // Adjust imageURI to not have the protocol on it for parsing
436 // below
437 // ex. tftp://1.1.1.1/myfile.bin -> 1.1.1.1/myfile.bin
438 imageURI = imageURI.substr(separator + 3);
439 BMCWEB_LOG_DEBUG << "Adjusted imageUri " << imageURI;
440 }
441
442 // OpenBMC currently only supports TFTP
443 if (*transferProtocol != "TFTP")
444 {
445 messages::actionParameterNotSupported(asyncResp->res,
446 "TransferProtocol",
447 "UpdateService.SimpleUpdate");
448 BMCWEB_LOG_ERROR << "Request incorrect protocol parameter: "
449 << *transferProtocol;
450 return;
451 }
452
453 // Format should be <IP or Hostname>/<file> for imageURI
454 size_t separator = imageURI.find("/");
455 if ((separator == std::string::npos) ||
456 ((separator + 1) > imageURI.size()))
457 {
458 messages::actionParameterValueTypeError(
459 asyncResp->res, imageURI, "ImageURI",
460 "UpdateService.SimpleUpdate");
461 BMCWEB_LOG_ERROR << "Invalid ImageURI: " << imageURI;
462 return;
463 }
464
465 std::string tftpServer = imageURI.substr(0, separator);
466 std::string fwFile = imageURI.substr(separator + 1);
467 BMCWEB_LOG_DEBUG << "Server: " << tftpServer + " File: " << fwFile;
468
469 // Setup callback for when new software detected
Gunnar Mills2618d5e2020-08-18 13:04:27 -0500470 // Give TFTP 10 minutes to complete
James Feist4cde5d92020-06-11 10:39:55 -0700471 monitorForSoftwareAvailable(
472 nullptr, req,
473 "/redfish/v1/UpdateService/Actions/UpdateService.SimpleUpdate",
Gunnar Mills2618d5e2020-08-18 13:04:27 -0500474 600);
Andrew Geissler0554c982019-04-23 14:40:12 -0500475
Gunnar Mills2618d5e2020-08-18 13:04:27 -0500476 // TFTP can take up to 10 minutes depending on image size and
Andrew Geissler0554c982019-04-23 14:40:12 -0500477 // connection speed. Return to caller as soon as the TFTP operation
478 // has been started. The callback above will ensure the activate
479 // is started once the download has completed
480 redfish::messages::success(asyncResp->res);
481
482 // Call TFTP service
483 crow::connections::systemBus->async_method_call(
484 [](const boost::system::error_code ec) {
485 if (ec)
486 {
487 // messages::internalError(asyncResp->res);
488 cleanUp();
489 BMCWEB_LOG_DEBUG << "error_code = " << ec;
490 BMCWEB_LOG_DEBUG << "error msg = " << ec.message();
491 }
492 else
493 {
494 BMCWEB_LOG_DEBUG << "Call to DownloaViaTFTP Success";
495 }
496 },
497 "xyz.openbmc_project.Software.Download",
498 "/xyz/openbmc_project/software", "xyz.openbmc_project.Common.TFTP",
499 "DownloadViaTFTP", fwFile, tftpServer);
500
501 BMCWEB_LOG_DEBUG << "Exit UpdateService.SimpleUpdate doPost";
502 }
503};
504
Ed Tanous1abe55e2018-09-05 08:30:59 -0700505class UpdateService : public Node
506{
507 public:
Ed Tanous52cc1122020-07-18 13:51:21 -0700508 UpdateService(App& app) : Node(app, "/redfish/v1/UpdateService/")
Ed Tanous1abe55e2018-09-05 08:30:59 -0700509 {
Ed Tanous1abe55e2018-09-05 08:30:59 -0700510 entityPrivileges = {
511 {boost::beast::http::verb::get, {{"Login"}}},
512 {boost::beast::http::verb::head, {{"Login"}}},
513 {boost::beast::http::verb::patch, {{"ConfigureComponents"}}},
514 {boost::beast::http::verb::put, {{"ConfigureComponents"}}},
515 {boost::beast::http::verb::delete_, {{"ConfigureComponents"}}},
516 {boost::beast::http::verb::post, {{"ConfigureComponents"}}}};
Jennifer Leeacb7cfb2018-06-07 16:08:15 -0700517 }
Jennifer Leeacb7cfb2018-06-07 16:08:15 -0700518
Ed Tanous1abe55e2018-09-05 08:30:59 -0700519 private:
Ed Tanouscb13a392020-07-25 19:02:03 +0000520 void doGet(crow::Response& res, const crow::Request&,
521 const std::vector<std::string>&) override
Ed Tanous1abe55e2018-09-05 08:30:59 -0700522 {
Jayashankar Padath274dfe62019-08-23 12:30:57 +0530523 std::shared_ptr<AsyncResp> aResp = std::make_shared<AsyncResp>(res);
524 res.jsonValue["@odata.type"] = "#UpdateService.v1_4_0.UpdateService";
Ed Tanous0f74e642018-11-12 15:17:05 -0800525 res.jsonValue["@odata.id"] = "/redfish/v1/UpdateService";
Ed Tanous0f74e642018-11-12 15:17:05 -0800526 res.jsonValue["Id"] = "UpdateService";
527 res.jsonValue["Description"] = "Service for Software Update";
528 res.jsonValue["Name"] = "Update Service";
529 res.jsonValue["HttpPushUri"] = "/redfish/v1/UpdateService";
530 // UpdateService cannot be disabled
531 res.jsonValue["ServiceEnabled"] = true;
532 res.jsonValue["FirmwareInventory"] = {
533 {"@odata.id", "/redfish/v1/UpdateService/FirmwareInventory"}};
Andrew Geissler0554c982019-04-23 14:40:12 -0500534#ifdef BMCWEB_INSECURE_ENABLE_REDFISH_FW_TFTP_UPDATE
535 // Update Actions object.
Gunnar Mills1214b7e2020-06-04 10:11:30 -0500536 nlohmann::json& updateSvcSimpleUpdate =
Andrew Geissler0554c982019-04-23 14:40:12 -0500537 res.jsonValue["Actions"]["#UpdateService.SimpleUpdate"];
538 updateSvcSimpleUpdate["target"] =
539 "/redfish/v1/UpdateService/Actions/UpdateService.SimpleUpdate";
540 updateSvcSimpleUpdate["TransferProtocol@Redfish.AllowableValues"] = {
541 "TFTP"};
542#endif
Jayashankar Padath274dfe62019-08-23 12:30:57 +0530543 // Get the current ApplyTime value
544 crow::connections::systemBus->async_method_call(
545 [aResp](const boost::system::error_code ec,
Gunnar Mills1214b7e2020-06-04 10:11:30 -0500546 const std::variant<std::string>& applyTime) {
Jayashankar Padath274dfe62019-08-23 12:30:57 +0530547 if (ec)
548 {
549 BMCWEB_LOG_DEBUG << "DBUS response error " << ec;
550 messages::internalError(aResp->res);
551 return;
552 }
553
Gunnar Mills1214b7e2020-06-04 10:11:30 -0500554 const std::string* s = std::get_if<std::string>(&applyTime);
Jayashankar Padath274dfe62019-08-23 12:30:57 +0530555 if (s == nullptr)
556 {
557 return;
558 }
559 // Store the ApplyTime Value
560 if (*s == "xyz.openbmc_project.Software.ApplyTime."
561 "RequestedApplyTimes.Immediate")
562 {
563 aResp->res.jsonValue["HttpPushUriOptions"]
564 ["HttpPushUriApplyTime"]["ApplyTime"] =
565 "Immediate";
566 }
567 else if (*s == "xyz.openbmc_project.Software.ApplyTime."
568 "RequestedApplyTimes.OnReset")
569 {
570 aResp->res.jsonValue["HttpPushUriOptions"]
571 ["HttpPushUriApplyTime"]["ApplyTime"] =
572 "OnReset";
573 }
574 },
575 "xyz.openbmc_project.Settings",
576 "/xyz/openbmc_project/software/apply_time",
577 "org.freedesktop.DBus.Properties", "Get",
578 "xyz.openbmc_project.Software.ApplyTime", "RequestedApplyTime");
Ed Tanous1abe55e2018-09-05 08:30:59 -0700579 }
Andrew Geissler0e7de462019-03-04 19:11:54 -0600580
Gunnar Mills1214b7e2020-06-04 10:11:30 -0500581 void doPatch(crow::Response& res, const crow::Request& req,
Ed Tanouscb13a392020-07-25 19:02:03 +0000582 const std::vector<std::string>&) override
Jayashankar Padathfa1a5a32019-05-28 23:54:37 +0530583 {
584 BMCWEB_LOG_DEBUG << "doPatch...";
585
586 std::shared_ptr<AsyncResp> asyncResp = std::make_shared<AsyncResp>(res);
Jayashankar Padathfa1a5a32019-05-28 23:54:37 +0530587
Jayashankar Padath274dfe62019-08-23 12:30:57 +0530588 std::optional<nlohmann::json> pushUriOptions;
589 if (!json_util::readJson(req, res, "HttpPushUriOptions",
590 pushUriOptions))
Jayashankar Padathfa1a5a32019-05-28 23:54:37 +0530591 {
592 return;
593 }
594
Jayashankar Padath274dfe62019-08-23 12:30:57 +0530595 if (pushUriOptions)
Jayashankar Padathfa1a5a32019-05-28 23:54:37 +0530596 {
Jayashankar Padath274dfe62019-08-23 12:30:57 +0530597 std::optional<nlohmann::json> pushUriApplyTime;
598 if (!json_util::readJson(*pushUriOptions, res,
599 "HttpPushUriApplyTime", pushUriApplyTime))
Jayashankar Padathfa1a5a32019-05-28 23:54:37 +0530600 {
Jayashankar Padath274dfe62019-08-23 12:30:57 +0530601 return;
Jayashankar Padathfa1a5a32019-05-28 23:54:37 +0530602 }
603
Jayashankar Padath274dfe62019-08-23 12:30:57 +0530604 if (pushUriApplyTime)
605 {
606 std::optional<std::string> applyTime;
607 if (!json_util::readJson(*pushUriApplyTime, res, "ApplyTime",
608 applyTime))
609 {
610 return;
611 }
612
613 if (applyTime)
614 {
615 std::string applyTimeNewVal;
616 if (applyTime == "Immediate")
Jayashankar Padathfa1a5a32019-05-28 23:54:37 +0530617 {
Jayashankar Padath274dfe62019-08-23 12:30:57 +0530618 applyTimeNewVal =
619 "xyz.openbmc_project.Software.ApplyTime."
620 "RequestedApplyTimes.Immediate";
621 }
622 else if (applyTime == "OnReset")
623 {
624 applyTimeNewVal =
625 "xyz.openbmc_project.Software.ApplyTime."
626 "RequestedApplyTimes.OnReset";
627 }
628 else
629 {
630 BMCWEB_LOG_INFO
631 << "ApplyTime value is not in the list of "
632 "acceptable values";
633 messages::propertyValueNotInList(
634 asyncResp->res, *applyTime, "ApplyTime");
Jayashankar Padathfa1a5a32019-05-28 23:54:37 +0530635 return;
636 }
Jayashankar Padath274dfe62019-08-23 12:30:57 +0530637
638 // Set the requested image apply time value
639 crow::connections::systemBus->async_method_call(
640 [asyncResp](const boost::system::error_code ec) {
641 if (ec)
642 {
643 BMCWEB_LOG_ERROR << "D-Bus responses error: "
644 << ec;
645 messages::internalError(asyncResp->res);
646 return;
647 }
648 messages::success(asyncResp->res);
649 },
650 "xyz.openbmc_project.Settings",
651 "/xyz/openbmc_project/software/apply_time",
652 "org.freedesktop.DBus.Properties", "Set",
653 "xyz.openbmc_project.Software.ApplyTime",
654 "RequestedApplyTime",
655 std::variant<std::string>{applyTimeNewVal});
656 }
657 }
Jayashankar Padathfa1a5a32019-05-28 23:54:37 +0530658 }
659 }
660
Gunnar Mills1214b7e2020-06-04 10:11:30 -0500661 void doPost(crow::Response& res, const crow::Request& req,
Ed Tanouscb13a392020-07-25 19:02:03 +0000662 const std::vector<std::string>&) override
Ed Tanous1abe55e2018-09-05 08:30:59 -0700663 {
664 BMCWEB_LOG_DEBUG << "doPost...";
Jennifer Leeacb7cfb2018-06-07 16:08:15 -0700665
Andrew Geissler0e7de462019-03-04 19:11:54 -0600666 std::shared_ptr<AsyncResp> asyncResp = std::make_shared<AsyncResp>(res);
Ed Tanous1abe55e2018-09-05 08:30:59 -0700667
Andrew Geissler86adcd62019-04-18 10:58:05 -0500668 // Setup callback for when new software detected
James Feist4cde5d92020-06-11 10:39:55 -0700669 monitorForSoftwareAvailable(asyncResp, req,
670 "/redfish/v1/UpdateService");
Ed Tanous1abe55e2018-09-05 08:30:59 -0700671
672 std::string filepath(
673 "/tmp/images/" +
674 boost::uuids::to_string(boost::uuids::random_generator()()));
675 BMCWEB_LOG_DEBUG << "Writing file to " << filepath;
676 std::ofstream out(filepath, std::ofstream::out | std::ofstream::binary |
677 std::ofstream::trunc);
678 out << req.body;
679 out.close();
680 BMCWEB_LOG_DEBUG << "file upload complete!!";
681 }
Jennifer Lee729dae72018-04-24 15:59:34 -0700682};
Ed Tanousc711bf82018-07-30 16:31:33 -0700683
Ed Tanous1abe55e2018-09-05 08:30:59 -0700684class SoftwareInventoryCollection : public Node
685{
686 public:
Ed Tanous52cc1122020-07-18 13:51:21 -0700687 SoftwareInventoryCollection(App& app) :
Ed Tanous1abe55e2018-09-05 08:30:59 -0700688 Node(app, "/redfish/v1/UpdateService/FirmwareInventory/")
689 {
Ed Tanous1abe55e2018-09-05 08:30:59 -0700690 entityPrivileges = {
691 {boost::beast::http::verb::get, {{"Login"}}},
692 {boost::beast::http::verb::head, {{"Login"}}},
693 {boost::beast::http::verb::patch, {{"ConfigureComponents"}}},
694 {boost::beast::http::verb::put, {{"ConfigureComponents"}}},
695 {boost::beast::http::verb::delete_, {{"ConfigureComponents"}}},
696 {boost::beast::http::verb::post, {{"ConfigureComponents"}}}};
Jennifer Lee729dae72018-04-24 15:59:34 -0700697 }
Jennifer Lee729dae72018-04-24 15:59:34 -0700698
Ed Tanous1abe55e2018-09-05 08:30:59 -0700699 private:
Ed Tanouscb13a392020-07-25 19:02:03 +0000700 void doGet(crow::Response& res, const crow::Request&,
701 const std::vector<std::string>&) override
Ed Tanous1abe55e2018-09-05 08:30:59 -0700702 {
703 std::shared_ptr<AsyncResp> asyncResp = std::make_shared<AsyncResp>(res);
Ed Tanous0f74e642018-11-12 15:17:05 -0800704 res.jsonValue["@odata.type"] =
705 "#SoftwareInventoryCollection.SoftwareInventoryCollection";
706 res.jsonValue["@odata.id"] =
707 "/redfish/v1/UpdateService/FirmwareInventory";
Ed Tanous0f74e642018-11-12 15:17:05 -0800708 res.jsonValue["Name"] = "Software Inventory Collection";
Ed Tanousc711bf82018-07-30 16:31:33 -0700709
Ed Tanous1abe55e2018-09-05 08:30:59 -0700710 crow::connections::systemBus->async_method_call(
711 [asyncResp](
712 const boost::system::error_code ec,
713 const std::vector<std::pair<
714 std::string, std::vector<std::pair<
Gunnar Mills1214b7e2020-06-04 10:11:30 -0500715 std::string, std::vector<std::string>>>>>&
716 subtree) {
Ed Tanous1abe55e2018-09-05 08:30:59 -0700717 if (ec)
718 {
Jason M. Billsf12894f2018-10-09 12:45:45 -0700719 messages::internalError(asyncResp->res);
Ed Tanousc711bf82018-07-30 16:31:33 -0700720 return;
Ed Tanous1abe55e2018-09-05 08:30:59 -0700721 }
722 asyncResp->res.jsonValue["Members"] = nlohmann::json::array();
723 asyncResp->res.jsonValue["Members@odata.count"] = 0;
Jennifer Lee6c4eb9d2018-05-22 10:58:31 -0700724
Gunnar Mills1214b7e2020-06-04 10:11:30 -0500725 for (auto& obj : subtree)
Ed Tanous1abe55e2018-09-05 08:30:59 -0700726 {
Jennifer Leef4b65ab2018-09-18 12:00:13 -0700727 // if can't parse fw id then return
Ed Tanous27826b52018-10-29 11:40:58 -0700728 std::size_t idPos;
729 if ((idPos = obj.first.rfind("/")) == std::string::npos)
Jennifer Leef4b65ab2018-09-18 12:00:13 -0700730 {
Jason M. Billsf12894f2018-10-09 12:45:45 -0700731 messages::internalError(asyncResp->res);
Jennifer Leef4b65ab2018-09-18 12:00:13 -0700732 BMCWEB_LOG_DEBUG << "Can't parse firmware ID!!";
733 return;
734 }
Jennifer Leef4b65ab2018-09-18 12:00:13 -0700735 std::string swId = obj.first.substr(idPos + 1);
736
Gunnar Mills1214b7e2020-06-04 10:11:30 -0500737 nlohmann::json& members =
Andrew Geisslere0dd8052019-06-18 16:05:10 -0500738 asyncResp->res.jsonValue["Members"];
739 members.push_back(
740 {{"@odata.id", "/redfish/v1/UpdateService/"
741 "FirmwareInventory/" +
742 swId}});
743 asyncResp->res.jsonValue["Members@odata.count"] =
744 members.size();
Ed Tanous1abe55e2018-09-05 08:30:59 -0700745 }
746 },
Andrew Geissler2830a9c2020-01-06 10:18:11 -0600747 // Note that only firmware levels associated with a device are
748 // stored under /xyz/openbmc_project/software therefore to ensure
749 // only real FirmwareInventory items are returned, this full object
750 // path must be used here as input to mapper
Ed Tanous1abe55e2018-09-05 08:30:59 -0700751 "xyz.openbmc_project.ObjectMapper",
752 "/xyz/openbmc_project/object_mapper",
Andrew Geissler2830a9c2020-01-06 10:18:11 -0600753 "xyz.openbmc_project.ObjectMapper", "GetSubTree",
754 "/xyz/openbmc_project/software", static_cast<int32_t>(0),
Gunnar Mills1214b7e2020-06-04 10:11:30 -0500755 std::array<const char*, 1>{"xyz.openbmc_project.Software.Version"});
Ed Tanous1abe55e2018-09-05 08:30:59 -0700756 }
Jennifer Lee729dae72018-04-24 15:59:34 -0700757};
758
Ed Tanous1abe55e2018-09-05 08:30:59 -0700759class SoftwareInventory : public Node
760{
761 public:
Ed Tanous52cc1122020-07-18 13:51:21 -0700762 SoftwareInventory(App& app) :
Ed Tanous1abe55e2018-09-05 08:30:59 -0700763 Node(app, "/redfish/v1/UpdateService/FirmwareInventory/<str>/",
764 std::string())
765 {
Ed Tanous1abe55e2018-09-05 08:30:59 -0700766 entityPrivileges = {
767 {boost::beast::http::verb::get, {{"Login"}}},
768 {boost::beast::http::verb::head, {{"Login"}}},
769 {boost::beast::http::verb::patch, {{"ConfigureComponents"}}},
770 {boost::beast::http::verb::put, {{"ConfigureComponents"}}},
771 {boost::beast::http::verb::delete_, {{"ConfigureComponents"}}},
772 {boost::beast::http::verb::post, {{"ConfigureComponents"}}}};
773 }
774
775 private:
Andrew Geissler87d84722019-02-28 14:28:39 -0600776 /* Fill related item links (i.e. bmc, bios) in for inventory */
Ed Tanousb5a76932020-09-29 16:16:58 -0700777 static void getRelatedItems(const std::shared_ptr<AsyncResp>& aResp,
Gunnar Mills1214b7e2020-06-04 10:11:30 -0500778 const std::string& purpose)
Andrew Geissler87d84722019-02-28 14:28:39 -0600779 {
780 if (purpose == fw_util::bmcPurpose)
781 {
Gunnar Mills1214b7e2020-06-04 10:11:30 -0500782 nlohmann::json& members = aResp->res.jsonValue["RelatedItem"];
Andrew Geissler87d84722019-02-28 14:28:39 -0600783 members.push_back({{"@odata.id", "/redfish/v1/Managers/bmc"}});
784 aResp->res.jsonValue["Members@odata.count"] = members.size();
785 }
786 else if (purpose == fw_util::biosPurpose)
787 {
Gunnar Mills1214b7e2020-06-04 10:11:30 -0500788 nlohmann::json& members = aResp->res.jsonValue["RelatedItem"];
Gunnar Millsf723d732020-02-26 11:20:49 -0600789 members.push_back(
790 {{"@odata.id", "/redfish/v1/Systems/system/Bios"}});
791 aResp->res.jsonValue["Members@odata.count"] = members.size();
Andrew Geissler87d84722019-02-28 14:28:39 -0600792 }
793 else
794 {
795 BMCWEB_LOG_ERROR << "Unknown software purpose " << purpose;
796 }
797 }
798
Ed Tanouscb13a392020-07-25 19:02:03 +0000799 void doGet(crow::Response& res, const crow::Request&,
Gunnar Mills1214b7e2020-06-04 10:11:30 -0500800 const std::vector<std::string>& params) override
Ed Tanous1abe55e2018-09-05 08:30:59 -0700801 {
802 std::shared_ptr<AsyncResp> asyncResp = std::make_shared<AsyncResp>(res);
Ed Tanous1abe55e2018-09-05 08:30:59 -0700803
804 if (params.size() != 1)
805 {
Jason M. Billsf12894f2018-10-09 12:45:45 -0700806 messages::internalError(res);
Ed Tanous1abe55e2018-09-05 08:30:59 -0700807 res.end();
808 return;
809 }
810
Ed Tanous3ae837c2018-08-07 14:41:19 -0700811 std::shared_ptr<std::string> swId =
Ed Tanous1abe55e2018-09-05 08:30:59 -0700812 std::make_shared<std::string>(params[0]);
813
814 res.jsonValue["@odata.id"] =
Ed Tanous3ae837c2018-08-07 14:41:19 -0700815 "/redfish/v1/UpdateService/FirmwareInventory/" + *swId;
Ed Tanous1abe55e2018-09-05 08:30:59 -0700816
817 crow::connections::systemBus->async_method_call(
Ed Tanous3ae837c2018-08-07 14:41:19 -0700818 [asyncResp, swId](
Ed Tanous1abe55e2018-09-05 08:30:59 -0700819 const boost::system::error_code ec,
820 const std::vector<std::pair<
821 std::string, std::vector<std::pair<
Gunnar Mills1214b7e2020-06-04 10:11:30 -0500822 std::string, std::vector<std::string>>>>>&
823 subtree) {
Ed Tanous1abe55e2018-09-05 08:30:59 -0700824 BMCWEB_LOG_DEBUG << "doGet callback...";
825 if (ec)
826 {
Jason M. Billsf12894f2018-10-09 12:45:45 -0700827 messages::internalError(asyncResp->res);
Ed Tanous1abe55e2018-09-05 08:30:59 -0700828 return;
829 }
830
Andrew Geissler69132282019-07-01 11:00:35 -0500831 // Ensure we find our input swId, otherwise return an error
832 bool found = false;
Ed Tanous1abe55e2018-09-05 08:30:59 -0700833 for (const std::pair<
834 std::string,
835 std::vector<
Gunnar Mills1214b7e2020-06-04 10:11:30 -0500836 std::pair<std::string, std::vector<std::string>>>>&
837 obj : subtree)
Ed Tanous1abe55e2018-09-05 08:30:59 -0700838 {
Ed Tanous3ae837c2018-08-07 14:41:19 -0700839 if (boost::ends_with(obj.first, *swId) != true)
Ed Tanous1abe55e2018-09-05 08:30:59 -0700840 {
841 continue;
842 }
843
Jennifer Leef4b65ab2018-09-18 12:00:13 -0700844 if (obj.second.size() < 1)
Ed Tanous1abe55e2018-09-05 08:30:59 -0700845 {
846 continue;
847 }
848
Andrew Geissler69132282019-07-01 11:00:35 -0500849 found = true;
Andrew Geisslere0dd8052019-06-18 16:05:10 -0500850 fw_util::getFwStatus(asyncResp, swId, obj.second[0].first);
851
Ed Tanous1abe55e2018-09-05 08:30:59 -0700852 crow::connections::systemBus->async_method_call(
853 [asyncResp,
Ed Tanous3ae837c2018-08-07 14:41:19 -0700854 swId](const boost::system::error_code error_code,
855 const boost::container::flat_map<
Gunnar Mills1214b7e2020-06-04 10:11:30 -0500856 std::string, VariantType>& propertiesList) {
Ed Tanous1abe55e2018-09-05 08:30:59 -0700857 if (error_code)
858 {
Jason M. Billsf12894f2018-10-09 12:45:45 -0700859 messages::internalError(asyncResp->res);
Ed Tanous1abe55e2018-09-05 08:30:59 -0700860 return;
861 }
862 boost::container::flat_map<
863 std::string, VariantType>::const_iterator it =
864 propertiesList.find("Purpose");
865 if (it == propertiesList.end())
866 {
867 BMCWEB_LOG_DEBUG
868 << "Can't find property \"Purpose\"!";
Jason M. Billsf12894f2018-10-09 12:45:45 -0700869 messages::propertyMissing(asyncResp->res,
870 "Purpose");
Ed Tanous1abe55e2018-09-05 08:30:59 -0700871 return;
872 }
Gunnar Mills1214b7e2020-06-04 10:11:30 -0500873 const std::string* swInvPurpose =
Ed Tanousabf2add2019-01-22 16:40:12 -0800874 std::get_if<std::string>(&it->second);
Ed Tanous3ae837c2018-08-07 14:41:19 -0700875 if (swInvPurpose == nullptr)
Ed Tanous1abe55e2018-09-05 08:30:59 -0700876 {
877 BMCWEB_LOG_DEBUG
878 << "wrong types for property\"Purpose\"!";
Jason M. Billsf12894f2018-10-09 12:45:45 -0700879 messages::propertyValueTypeError(asyncResp->res,
880 "", "Purpose");
Ed Tanous1abe55e2018-09-05 08:30:59 -0700881 return;
882 }
883
Ed Tanous3ae837c2018-08-07 14:41:19 -0700884 BMCWEB_LOG_DEBUG << "swInvPurpose = "
885 << *swInvPurpose;
Jennifer Leef4b65ab2018-09-18 12:00:13 -0700886 it = propertiesList.find("Version");
887 if (it == propertiesList.end())
Ed Tanous1abe55e2018-09-05 08:30:59 -0700888 {
Jennifer Leef4b65ab2018-09-18 12:00:13 -0700889 BMCWEB_LOG_DEBUG
890 << "Can't find property \"Version\"!";
Jason M. Billsf12894f2018-10-09 12:45:45 -0700891 messages::propertyMissing(asyncResp->res,
892 "Version");
Jennifer Leef4b65ab2018-09-18 12:00:13 -0700893 return;
Ed Tanous1abe55e2018-09-05 08:30:59 -0700894 }
Jennifer Leef4b65ab2018-09-18 12:00:13 -0700895
896 BMCWEB_LOG_DEBUG << "Version found!";
897
Gunnar Mills1214b7e2020-06-04 10:11:30 -0500898 const std::string* version =
Ed Tanousabf2add2019-01-22 16:40:12 -0800899 std::get_if<std::string>(&it->second);
Jennifer Leef4b65ab2018-09-18 12:00:13 -0700900
901 if (version == nullptr)
902 {
903 BMCWEB_LOG_DEBUG
904 << "Can't find property \"Version\"!";
Jason M. Billsf12894f2018-10-09 12:45:45 -0700905
906 messages::propertyValueTypeError(asyncResp->res,
907 "", "Version");
Jennifer Leef4b65ab2018-09-18 12:00:13 -0700908 return;
909 }
910 asyncResp->res.jsonValue["Version"] = *version;
911 asyncResp->res.jsonValue["Id"] = *swId;
Andrew Geissler54daabe2019-02-13 13:54:15 -0600912
913 // swInvPurpose is of format:
914 // xyz.openbmc_project.Software.Version.VersionPurpose.ABC
James Feiste2e96772019-10-03 10:51:43 -0700915 // Translate this to "ABC image"
Andrew Geissler54daabe2019-02-13 13:54:15 -0600916 size_t endDesc = swInvPurpose->rfind(".");
917 if (endDesc == std::string::npos)
918 {
919 messages::internalError(asyncResp->res);
920 return;
921 }
922 endDesc++;
923 if (endDesc >= swInvPurpose->size())
924 {
925 messages::internalError(asyncResp->res);
926 return;
927 }
928
929 std::string formatDesc =
930 swInvPurpose->substr(endDesc);
931 asyncResp->res.jsonValue["Description"] =
James Feiste2e96772019-10-03 10:51:43 -0700932 formatDesc + " image";
Andrew Geissler87d84722019-02-28 14:28:39 -0600933 getRelatedItems(asyncResp, *swInvPurpose);
Ed Tanous1abe55e2018-09-05 08:30:59 -0700934 },
935 obj.second[0].first, obj.first,
936 "org.freedesktop.DBus.Properties", "GetAll",
937 "xyz.openbmc_project.Software.Version");
938 }
Andrew Geissler69132282019-07-01 11:00:35 -0500939 if (!found)
940 {
941 BMCWEB_LOG_ERROR << "Input swID " + *swId + " not found!";
942 messages::resourceMissingAtURI(
943 asyncResp->res,
944 "/redfish/v1/UpdateService/FirmwareInventory/" + *swId);
945 return;
946 }
Ayushi Smriti4e68c452019-09-04 14:37:55 +0530947 asyncResp->res.jsonValue["@odata.type"] =
948 "#SoftwareInventory.v1_1_0.SoftwareInventory";
Ayushi Smriti4e68c452019-09-04 14:37:55 +0530949 asyncResp->res.jsonValue["Name"] = "Software Inventory";
Ayushi Smriti4e68c452019-09-04 14:37:55 +0530950 asyncResp->res.jsonValue["Status"]["HealthRollup"] = "OK";
AppaRao Puli3f8a7432020-01-29 02:36:32 +0530951
952 asyncResp->res.jsonValue["Updateable"] = false;
953 fw_util::getFwUpdateableStatus(asyncResp, swId);
Ed Tanous1abe55e2018-09-05 08:30:59 -0700954 },
955 "xyz.openbmc_project.ObjectMapper",
956 "/xyz/openbmc_project/object_mapper",
Ed Tanous271584a2019-07-09 16:24:22 -0700957 "xyz.openbmc_project.ObjectMapper", "GetSubTree", "/",
958 static_cast<int32_t>(0),
Gunnar Mills1214b7e2020-06-04 10:11:30 -0500959 std::array<const char*, 1>{"xyz.openbmc_project.Software.Version"});
Ed Tanous1abe55e2018-09-05 08:30:59 -0700960 }
961};
962
963} // namespace redfish