xref: /openbmc/bmcweb/features/redfish/lib/update_service.hpp (revision e2e9677006af28da6abeea4f0d7130809ad70786)
1729dae72SJennifer Lee /*
2729dae72SJennifer Lee // Copyright (c) 2018 Intel Corporation
3729dae72SJennifer Lee //
4729dae72SJennifer Lee // Licensed under the Apache License, Version 2.0 (the "License");
5729dae72SJennifer Lee // you may not use this file except in compliance with the License.
6729dae72SJennifer Lee // You may obtain a copy of the License at
7729dae72SJennifer Lee //
8729dae72SJennifer Lee //      http://www.apache.org/licenses/LICENSE-2.0
9729dae72SJennifer Lee //
10729dae72SJennifer Lee // Unless required by applicable law or agreed to in writing, software
11729dae72SJennifer Lee // distributed under the License is distributed on an "AS IS" BASIS,
12729dae72SJennifer Lee // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13729dae72SJennifer Lee // See the License for the specific language governing permissions and
14729dae72SJennifer Lee // limitations under the License.
15729dae72SJennifer Lee */
16729dae72SJennifer Lee #pragma once
17729dae72SJennifer Lee 
18729dae72SJennifer Lee #include "node.hpp"
191abe55efSEd Tanous 
20729dae72SJennifer Lee #include <boost/container/flat_map.hpp>
2187d84729SAndrew Geissler #include <utils/fw_utils.hpp>
22abf2add6SEd Tanous #include <variant>
23729dae72SJennifer Lee 
241abe55efSEd Tanous namespace redfish
251abe55efSEd Tanous {
2627826b5fSEd Tanous 
270e7de46fSAndrew Geissler // Match signals added on software path
28acb7cfb4SJennifer Lee static std::unique_ptr<sdbusplus::bus::match::match> fwUpdateMatcher;
290e7de46fSAndrew Geissler // Only allow one update at a time
300e7de46fSAndrew Geissler static bool fwUpdateInProgress = false;
3186adcd6dSAndrew Geissler // Timer for software available
3286adcd6dSAndrew Geissler static std::unique_ptr<boost::asio::deadline_timer> fwAvailableTimer;
3386adcd6dSAndrew Geissler 
3486adcd6dSAndrew Geissler static void cleanUp()
3586adcd6dSAndrew Geissler {
3686adcd6dSAndrew Geissler     fwUpdateInProgress = false;
3786adcd6dSAndrew Geissler     fwUpdateMatcher = nullptr;
3886adcd6dSAndrew Geissler }
3986adcd6dSAndrew Geissler static void activateImage(const std::string &objPath,
4086adcd6dSAndrew Geissler                           const std::string &service)
4186adcd6dSAndrew Geissler {
4286adcd6dSAndrew Geissler     BMCWEB_LOG_DEBUG << "Activate image for " << objPath << " " << service;
4386adcd6dSAndrew Geissler     crow::connections::systemBus->async_method_call(
4486adcd6dSAndrew Geissler         [](const boost::system::error_code error_code) {
4586adcd6dSAndrew Geissler             if (error_code)
4686adcd6dSAndrew Geissler             {
4786adcd6dSAndrew Geissler                 BMCWEB_LOG_DEBUG << "error_code = " << error_code;
4886adcd6dSAndrew Geissler                 BMCWEB_LOG_DEBUG << "error msg = " << error_code.message();
4986adcd6dSAndrew Geissler             }
5086adcd6dSAndrew Geissler         },
5186adcd6dSAndrew Geissler         service, objPath, "org.freedesktop.DBus.Properties", "Set",
5286adcd6dSAndrew Geissler         "xyz.openbmc_project.Software.Activation", "RequestedActivation",
5386adcd6dSAndrew Geissler         std::variant<std::string>(
5486adcd6dSAndrew Geissler             "xyz.openbmc_project.Software.Activation.RequestedActivations."
5586adcd6dSAndrew Geissler             "Active"));
5686adcd6dSAndrew Geissler }
570554c984SAndrew Geissler 
580554c984SAndrew Geissler // Note that asyncResp can be either a valid pointer or nullptr. If nullptr
590554c984SAndrew Geissler // then no asyncResp updates will occur
6086adcd6dSAndrew Geissler static void softwareInterfaceAdded(std::shared_ptr<AsyncResp> asyncResp,
6186adcd6dSAndrew Geissler                                    sdbusplus::message::message &m)
6286adcd6dSAndrew Geissler {
6386adcd6dSAndrew Geissler     std::vector<std::pair<
6486adcd6dSAndrew Geissler         std::string,
6586adcd6dSAndrew Geissler         std::vector<std::pair<std::string, std::variant<std::string>>>>>
6686adcd6dSAndrew Geissler         interfacesProperties;
6786adcd6dSAndrew Geissler 
6886adcd6dSAndrew Geissler     sdbusplus::message::object_path objPath;
6986adcd6dSAndrew Geissler 
7086adcd6dSAndrew Geissler     m.read(objPath, interfacesProperties);
7186adcd6dSAndrew Geissler 
7286adcd6dSAndrew Geissler     BMCWEB_LOG_DEBUG << "obj path = " << objPath.str;
7386adcd6dSAndrew Geissler     for (auto &interface : interfacesProperties)
7486adcd6dSAndrew Geissler     {
7586adcd6dSAndrew Geissler         BMCWEB_LOG_DEBUG << "interface = " << interface.first;
7686adcd6dSAndrew Geissler 
7786adcd6dSAndrew Geissler         if (interface.first == "xyz.openbmc_project.Software.Activation")
7886adcd6dSAndrew Geissler         {
7986adcd6dSAndrew Geissler             // Found our interface, disable callbacks
8086adcd6dSAndrew Geissler             fwUpdateMatcher = nullptr;
8186adcd6dSAndrew Geissler 
8286adcd6dSAndrew Geissler             // Retrieve service and activate
8386adcd6dSAndrew Geissler             crow::connections::systemBus->async_method_call(
8486adcd6dSAndrew Geissler                 [objPath, asyncResp](
8586adcd6dSAndrew Geissler                     const boost::system::error_code error_code,
8686adcd6dSAndrew Geissler                     const std::vector<std::pair<
8786adcd6dSAndrew Geissler                         std::string, std::vector<std::string>>> &objInfo) {
8886adcd6dSAndrew Geissler                     if (error_code)
8986adcd6dSAndrew Geissler                     {
9086adcd6dSAndrew Geissler                         BMCWEB_LOG_DEBUG << "error_code = " << error_code;
9186adcd6dSAndrew Geissler                         BMCWEB_LOG_DEBUG << "error msg = "
9286adcd6dSAndrew Geissler                                          << error_code.message();
930554c984SAndrew Geissler                         if (asyncResp)
940554c984SAndrew Geissler                         {
9586adcd6dSAndrew Geissler                             messages::internalError(asyncResp->res);
960554c984SAndrew Geissler                         }
9786adcd6dSAndrew Geissler                         cleanUp();
9886adcd6dSAndrew Geissler                         return;
9986adcd6dSAndrew Geissler                     }
10086adcd6dSAndrew Geissler                     // Ensure we only got one service back
10186adcd6dSAndrew Geissler                     if (objInfo.size() != 1)
10286adcd6dSAndrew Geissler                     {
10386adcd6dSAndrew Geissler                         BMCWEB_LOG_ERROR << "Invalid Object Size "
10486adcd6dSAndrew Geissler                                          << objInfo.size();
1050554c984SAndrew Geissler                         if (asyncResp)
1060554c984SAndrew Geissler                         {
10786adcd6dSAndrew Geissler                             messages::internalError(asyncResp->res);
1080554c984SAndrew Geissler                         }
10986adcd6dSAndrew Geissler                         cleanUp();
11086adcd6dSAndrew Geissler                         return;
11186adcd6dSAndrew Geissler                     }
11286adcd6dSAndrew Geissler                     // cancel timer only when
11386adcd6dSAndrew Geissler                     // xyz.openbmc_project.Software.Activation interface
11486adcd6dSAndrew Geissler                     // is added
11586adcd6dSAndrew Geissler                     fwAvailableTimer = nullptr;
11686adcd6dSAndrew Geissler 
11786adcd6dSAndrew Geissler                     activateImage(objPath.str, objInfo[0].first);
1180554c984SAndrew Geissler                     if (asyncResp)
1190554c984SAndrew Geissler                     {
12086adcd6dSAndrew Geissler                         redfish::messages::success(asyncResp->res);
1210554c984SAndrew Geissler                     }
12286adcd6dSAndrew Geissler                     fwUpdateInProgress = false;
12386adcd6dSAndrew Geissler                 },
12486adcd6dSAndrew Geissler                 "xyz.openbmc_project.ObjectMapper",
12586adcd6dSAndrew Geissler                 "/xyz/openbmc_project/object_mapper",
12686adcd6dSAndrew Geissler                 "xyz.openbmc_project.ObjectMapper", "GetObject", objPath.str,
12786adcd6dSAndrew Geissler                 std::array<const char *, 1>{
12886adcd6dSAndrew Geissler                     "xyz.openbmc_project.Software.Activation"});
12986adcd6dSAndrew Geissler         }
13086adcd6dSAndrew Geissler     }
13186adcd6dSAndrew Geissler }
13286adcd6dSAndrew Geissler 
1330554c984SAndrew Geissler // Note that asyncResp can be either a valid pointer or nullptr. If nullptr
1340554c984SAndrew Geissler // then no asyncResp updates will occur
13586adcd6dSAndrew Geissler static void monitorForSoftwareAvailable(std::shared_ptr<AsyncResp> asyncResp,
1360554c984SAndrew Geissler                                         const crow::Request &req,
1370554c984SAndrew Geissler                                         int timeoutTimeSeconds = 5)
13886adcd6dSAndrew Geissler {
13986adcd6dSAndrew Geissler     // Only allow one FW update at a time
14086adcd6dSAndrew Geissler     if (fwUpdateInProgress != false)
14186adcd6dSAndrew Geissler     {
1420554c984SAndrew Geissler         if (asyncResp)
1430554c984SAndrew Geissler         {
14486adcd6dSAndrew Geissler             asyncResp->res.addHeader("Retry-After", "30");
14586adcd6dSAndrew Geissler             messages::serviceTemporarilyUnavailable(asyncResp->res, "30");
1460554c984SAndrew Geissler         }
14786adcd6dSAndrew Geissler         return;
14886adcd6dSAndrew Geissler     }
14986adcd6dSAndrew Geissler 
1500554c984SAndrew Geissler     fwAvailableTimer =
1510554c984SAndrew Geissler         std::make_unique<boost::asio::deadline_timer>(*req.ioService);
15286adcd6dSAndrew Geissler 
1530554c984SAndrew Geissler     fwAvailableTimer->expires_from_now(
1540554c984SAndrew Geissler         boost::posix_time::seconds(timeoutTimeSeconds));
15586adcd6dSAndrew Geissler 
15686adcd6dSAndrew Geissler     fwAvailableTimer->async_wait(
15786adcd6dSAndrew Geissler         [asyncResp](const boost::system::error_code &ec) {
15886adcd6dSAndrew Geissler             cleanUp();
15986adcd6dSAndrew Geissler             if (ec == boost::asio::error::operation_aborted)
16086adcd6dSAndrew Geissler             {
16186adcd6dSAndrew Geissler                 // expected, we were canceled before the timer completed.
16286adcd6dSAndrew Geissler                 return;
16386adcd6dSAndrew Geissler             }
16486adcd6dSAndrew Geissler             BMCWEB_LOG_ERROR
16586adcd6dSAndrew Geissler                 << "Timed out waiting for firmware object being created";
16686adcd6dSAndrew Geissler             BMCWEB_LOG_ERROR
16786adcd6dSAndrew Geissler                 << "FW image may has already been uploaded to server";
16886adcd6dSAndrew Geissler             if (ec)
16986adcd6dSAndrew Geissler             {
17086adcd6dSAndrew Geissler                 BMCWEB_LOG_ERROR << "Async_wait failed" << ec;
17186adcd6dSAndrew Geissler                 return;
17286adcd6dSAndrew Geissler             }
1730554c984SAndrew Geissler             if (asyncResp)
1740554c984SAndrew Geissler             {
17586adcd6dSAndrew Geissler                 redfish::messages::internalError(asyncResp->res);
1760554c984SAndrew Geissler             }
17786adcd6dSAndrew Geissler         });
17886adcd6dSAndrew Geissler 
17986adcd6dSAndrew Geissler     auto callback = [asyncResp](sdbusplus::message::message &m) {
18086adcd6dSAndrew Geissler         BMCWEB_LOG_DEBUG << "Match fired";
18186adcd6dSAndrew Geissler         softwareInterfaceAdded(asyncResp, m);
18286adcd6dSAndrew Geissler     };
18386adcd6dSAndrew Geissler 
18486adcd6dSAndrew Geissler     fwUpdateInProgress = true;
18586adcd6dSAndrew Geissler 
18686adcd6dSAndrew Geissler     fwUpdateMatcher = std::make_unique<sdbusplus::bus::match::match>(
18786adcd6dSAndrew Geissler         *crow::connections::systemBus,
18886adcd6dSAndrew Geissler         "interface='org.freedesktop.DBus.ObjectManager',type='signal',"
18986adcd6dSAndrew Geissler         "member='InterfacesAdded',path='/xyz/openbmc_project/software'",
19086adcd6dSAndrew Geissler         callback);
19186adcd6dSAndrew Geissler }
192729dae72SJennifer Lee 
1930554c984SAndrew Geissler /**
1940554c984SAndrew Geissler  * UpdateServiceActionsSimpleUpdate class supports handle POST method for
1950554c984SAndrew Geissler  * SimpleUpdate action.
1960554c984SAndrew Geissler  */
1970554c984SAndrew Geissler class UpdateServiceActionsSimpleUpdate : public Node
1980554c984SAndrew Geissler {
1990554c984SAndrew Geissler   public:
2000554c984SAndrew Geissler     UpdateServiceActionsSimpleUpdate(CrowApp &app) :
2010554c984SAndrew Geissler         Node(app,
2020554c984SAndrew Geissler              "/redfish/v1/UpdateService/Actions/UpdateService.SimpleUpdate/")
2030554c984SAndrew Geissler     {
2040554c984SAndrew Geissler         entityPrivileges = {
2050554c984SAndrew Geissler             {boost::beast::http::verb::get, {{"Login"}}},
2060554c984SAndrew Geissler             {boost::beast::http::verb::head, {{"Login"}}},
2070554c984SAndrew Geissler             {boost::beast::http::verb::patch, {{"ConfigureManager"}}},
2080554c984SAndrew Geissler             {boost::beast::http::verb::put, {{"ConfigureComponents"}}},
2090554c984SAndrew Geissler             {boost::beast::http::verb::delete_, {{"ConfigureComponents"}}},
2100554c984SAndrew Geissler             {boost::beast::http::verb::post, {{"ConfigureComponents"}}}};
2110554c984SAndrew Geissler     }
2120554c984SAndrew Geissler 
2130554c984SAndrew Geissler   private:
2140554c984SAndrew Geissler     void doPost(crow::Response &res, const crow::Request &req,
2150554c984SAndrew Geissler                 const std::vector<std::string> &params) override
2160554c984SAndrew Geissler     {
2170554c984SAndrew Geissler         std::optional<std::string> transferProtocol;
2180554c984SAndrew Geissler         std::string imageURI;
2190554c984SAndrew Geissler         std::shared_ptr<AsyncResp> asyncResp = std::make_shared<AsyncResp>(res);
2200554c984SAndrew Geissler 
2210554c984SAndrew Geissler         BMCWEB_LOG_DEBUG << "Enter UpdateService.SimpleUpdate doPost";
2220554c984SAndrew Geissler 
2230554c984SAndrew Geissler         // User can pass in both TransferProtocol and ImageURI parameters or
2240554c984SAndrew Geissler         // they can pass in just the ImageURI with the transfer protocl embedded
2250554c984SAndrew Geissler         // within it.
2260554c984SAndrew Geissler         // 1) TransferProtocol:TFTP ImageURI:1.1.1.1/myfile.bin
2270554c984SAndrew Geissler         // 2) ImageURI:tftp://1.1.1.1/myfile.bin
2280554c984SAndrew Geissler 
2290554c984SAndrew Geissler         if (!json_util::readJson(req, asyncResp->res, "TransferProtocol",
2300554c984SAndrew Geissler                                  transferProtocol, "ImageURI", imageURI))
2310554c984SAndrew Geissler         {
2320554c984SAndrew Geissler             BMCWEB_LOG_DEBUG
2330554c984SAndrew Geissler                 << "Missing TransferProtocol or ImageURI parameter";
2340554c984SAndrew Geissler             return;
2350554c984SAndrew Geissler         }
2360554c984SAndrew Geissler         if (!transferProtocol)
2370554c984SAndrew Geissler         {
2380554c984SAndrew Geissler             // Must be option 2
2390554c984SAndrew Geissler             // Verify ImageURI has transfer protocol in it
2400554c984SAndrew Geissler             size_t separator = imageURI.find(":");
2410554c984SAndrew Geissler             if ((separator == std::string::npos) ||
2420554c984SAndrew Geissler                 ((separator + 1) > imageURI.size()))
2430554c984SAndrew Geissler             {
2440554c984SAndrew Geissler                 messages::actionParameterValueTypeError(
2450554c984SAndrew Geissler                     asyncResp->res, imageURI, "ImageURI",
2460554c984SAndrew Geissler                     "UpdateService.SimpleUpdate");
2470554c984SAndrew Geissler                 BMCWEB_LOG_ERROR << "ImageURI missing transfer protocol: "
2480554c984SAndrew Geissler                                  << imageURI;
2490554c984SAndrew Geissler                 return;
2500554c984SAndrew Geissler             }
2510554c984SAndrew Geissler             transferProtocol = imageURI.substr(0, separator);
2520554c984SAndrew Geissler             // Ensure protocol is upper case for a common comparison path below
2530554c984SAndrew Geissler             boost::to_upper(*transferProtocol);
2540554c984SAndrew Geissler             BMCWEB_LOG_DEBUG << "Encoded transfer protocol "
2550554c984SAndrew Geissler                              << *transferProtocol;
2560554c984SAndrew Geissler 
2570554c984SAndrew Geissler             // Adjust imageURI to not have the protocol on it for parsing
2580554c984SAndrew Geissler             // below
2590554c984SAndrew Geissler             // ex. tftp://1.1.1.1/myfile.bin -> 1.1.1.1/myfile.bin
2600554c984SAndrew Geissler             imageURI = imageURI.substr(separator + 3);
2610554c984SAndrew Geissler             BMCWEB_LOG_DEBUG << "Adjusted imageUri " << imageURI;
2620554c984SAndrew Geissler         }
2630554c984SAndrew Geissler 
2640554c984SAndrew Geissler         // OpenBMC currently only supports TFTP
2650554c984SAndrew Geissler         if (*transferProtocol != "TFTP")
2660554c984SAndrew Geissler         {
2670554c984SAndrew Geissler             messages::actionParameterNotSupported(asyncResp->res,
2680554c984SAndrew Geissler                                                   "TransferProtocol",
2690554c984SAndrew Geissler                                                   "UpdateService.SimpleUpdate");
2700554c984SAndrew Geissler             BMCWEB_LOG_ERROR << "Request incorrect protocol parameter: "
2710554c984SAndrew Geissler                              << *transferProtocol;
2720554c984SAndrew Geissler             return;
2730554c984SAndrew Geissler         }
2740554c984SAndrew Geissler 
2750554c984SAndrew Geissler         // Format should be <IP or Hostname>/<file> for imageURI
2760554c984SAndrew Geissler         size_t separator = imageURI.find("/");
2770554c984SAndrew Geissler         if ((separator == std::string::npos) ||
2780554c984SAndrew Geissler             ((separator + 1) > imageURI.size()))
2790554c984SAndrew Geissler         {
2800554c984SAndrew Geissler             messages::actionParameterValueTypeError(
2810554c984SAndrew Geissler                 asyncResp->res, imageURI, "ImageURI",
2820554c984SAndrew Geissler                 "UpdateService.SimpleUpdate");
2830554c984SAndrew Geissler             BMCWEB_LOG_ERROR << "Invalid ImageURI: " << imageURI;
2840554c984SAndrew Geissler             return;
2850554c984SAndrew Geissler         }
2860554c984SAndrew Geissler 
2870554c984SAndrew Geissler         std::string tftpServer = imageURI.substr(0, separator);
2880554c984SAndrew Geissler         std::string fwFile = imageURI.substr(separator + 1);
2890554c984SAndrew Geissler         BMCWEB_LOG_DEBUG << "Server: " << tftpServer + " File: " << fwFile;
2900554c984SAndrew Geissler 
2910554c984SAndrew Geissler         // Setup callback for when new software detected
2920554c984SAndrew Geissler         // Give TFTP 2 minutes to complete
2930554c984SAndrew Geissler         monitorForSoftwareAvailable(nullptr, req, 120);
2940554c984SAndrew Geissler 
2950554c984SAndrew Geissler         // TFTP can take up to 2 minutes depending on image size and
2960554c984SAndrew Geissler         // connection speed. Return to caller as soon as the TFTP operation
2970554c984SAndrew Geissler         // has been started. The callback above will ensure the activate
2980554c984SAndrew Geissler         // is started once the download has completed
2990554c984SAndrew Geissler         redfish::messages::success(asyncResp->res);
3000554c984SAndrew Geissler 
3010554c984SAndrew Geissler         // Call TFTP service
3020554c984SAndrew Geissler         crow::connections::systemBus->async_method_call(
3030554c984SAndrew Geissler             [](const boost::system::error_code ec) {
3040554c984SAndrew Geissler                 if (ec)
3050554c984SAndrew Geissler                 {
3060554c984SAndrew Geissler                     // messages::internalError(asyncResp->res);
3070554c984SAndrew Geissler                     cleanUp();
3080554c984SAndrew Geissler                     BMCWEB_LOG_DEBUG << "error_code = " << ec;
3090554c984SAndrew Geissler                     BMCWEB_LOG_DEBUG << "error msg = " << ec.message();
3100554c984SAndrew Geissler                 }
3110554c984SAndrew Geissler                 else
3120554c984SAndrew Geissler                 {
3130554c984SAndrew Geissler                     BMCWEB_LOG_DEBUG << "Call to DownloaViaTFTP Success";
3140554c984SAndrew Geissler                 }
3150554c984SAndrew Geissler             },
3160554c984SAndrew Geissler             "xyz.openbmc_project.Software.Download",
3170554c984SAndrew Geissler             "/xyz/openbmc_project/software", "xyz.openbmc_project.Common.TFTP",
3180554c984SAndrew Geissler             "DownloadViaTFTP", fwFile, tftpServer);
3190554c984SAndrew Geissler 
3200554c984SAndrew Geissler         BMCWEB_LOG_DEBUG << "Exit UpdateService.SimpleUpdate doPost";
3210554c984SAndrew Geissler     }
3220554c984SAndrew Geissler };
3230554c984SAndrew Geissler 
3241abe55efSEd Tanous class UpdateService : public Node
3251abe55efSEd Tanous {
326729dae72SJennifer Lee   public:
3271abe55efSEd Tanous     UpdateService(CrowApp &app) : Node(app, "/redfish/v1/UpdateService/")
3281abe55efSEd Tanous     {
329729dae72SJennifer Lee         entityPrivileges = {
330729dae72SJennifer Lee             {boost::beast::http::verb::get, {{"Login"}}},
331729dae72SJennifer Lee             {boost::beast::http::verb::head, {{"Login"}}},
332729dae72SJennifer Lee             {boost::beast::http::verb::patch, {{"ConfigureComponents"}}},
333729dae72SJennifer Lee             {boost::beast::http::verb::put, {{"ConfigureComponents"}}},
334729dae72SJennifer Lee             {boost::beast::http::verb::delete_, {{"ConfigureComponents"}}},
335729dae72SJennifer Lee             {boost::beast::http::verb::post, {{"ConfigureComponents"}}}};
336729dae72SJennifer Lee     }
337729dae72SJennifer Lee 
338729dae72SJennifer Lee   private:
33955c7b7a2SEd Tanous     void doGet(crow::Response &res, const crow::Request &req,
3401abe55efSEd Tanous                const std::vector<std::string> &params) override
3411abe55efSEd Tanous     {
3420f74e643SEd Tanous         res.jsonValue["@odata.type"] = "#UpdateService.v1_2_0.UpdateService";
3430f74e643SEd Tanous         res.jsonValue["@odata.id"] = "/redfish/v1/UpdateService";
3440f74e643SEd Tanous         res.jsonValue["@odata.context"] =
3450f74e643SEd Tanous             "/redfish/v1/$metadata#UpdateService.UpdateService";
3460f74e643SEd Tanous         res.jsonValue["Id"] = "UpdateService";
3470f74e643SEd Tanous         res.jsonValue["Description"] = "Service for Software Update";
3480f74e643SEd Tanous         res.jsonValue["Name"] = "Update Service";
3490f74e643SEd Tanous         res.jsonValue["HttpPushUri"] = "/redfish/v1/UpdateService";
3500f74e643SEd Tanous         // UpdateService cannot be disabled
3510f74e643SEd Tanous         res.jsonValue["ServiceEnabled"] = true;
3520f74e643SEd Tanous         res.jsonValue["FirmwareInventory"] = {
3530f74e643SEd Tanous             {"@odata.id", "/redfish/v1/UpdateService/FirmwareInventory"}};
3540554c984SAndrew Geissler #ifdef BMCWEB_INSECURE_ENABLE_REDFISH_FW_TFTP_UPDATE
3550554c984SAndrew Geissler         // Update Actions object.
3560554c984SAndrew Geissler         nlohmann::json &updateSvcSimpleUpdate =
3570554c984SAndrew Geissler             res.jsonValue["Actions"]["#UpdateService.SimpleUpdate"];
3580554c984SAndrew Geissler         updateSvcSimpleUpdate["target"] =
3590554c984SAndrew Geissler             "/redfish/v1/UpdateService/Actions/UpdateService.SimpleUpdate";
3600554c984SAndrew Geissler         updateSvcSimpleUpdate["TransferProtocol@Redfish.AllowableValues"] = {
3610554c984SAndrew Geissler             "TFTP"};
3620554c984SAndrew Geissler #endif
363729dae72SJennifer Lee         res.end();
364729dae72SJennifer Lee     }
3650e7de46fSAndrew Geissler 
366fa1a5a38SJayashankar Padath     void doPatch(crow::Response &res, const crow::Request &req,
367fa1a5a38SJayashankar Padath                  const std::vector<std::string> &params) override
368fa1a5a38SJayashankar Padath     {
369fa1a5a38SJayashankar Padath         BMCWEB_LOG_DEBUG << "doPatch...";
370fa1a5a38SJayashankar Padath 
371fa1a5a38SJayashankar Padath         std::shared_ptr<AsyncResp> asyncResp = std::make_shared<AsyncResp>(res);
372fa1a5a38SJayashankar Padath         std::string applyTime;
373fa1a5a38SJayashankar Padath 
374fa1a5a38SJayashankar Padath         if (!json_util::readJson(req, res, "ApplyTime", applyTime))
375fa1a5a38SJayashankar Padath         {
376fa1a5a38SJayashankar Padath             return;
377fa1a5a38SJayashankar Padath         }
378fa1a5a38SJayashankar Padath 
379fa1a5a38SJayashankar Padath         if ((applyTime == "Immediate") || (applyTime == "OnReset"))
380fa1a5a38SJayashankar Padath         {
381fa1a5a38SJayashankar Padath             std::string applyTimeNewVal;
382fa1a5a38SJayashankar Padath             if (applyTime == "Immediate")
383fa1a5a38SJayashankar Padath             {
384fa1a5a38SJayashankar Padath                 applyTimeNewVal = "xyz.openbmc_project.Software.ApplyTime."
385fa1a5a38SJayashankar Padath                                   "RequestedApplyTimes.Immediate";
386fa1a5a38SJayashankar Padath             }
387fa1a5a38SJayashankar Padath             else
388fa1a5a38SJayashankar Padath             {
389fa1a5a38SJayashankar Padath                 applyTimeNewVal = "xyz.openbmc_project.Software.ApplyTime."
390fa1a5a38SJayashankar Padath                                   "RequestedApplyTimes.OnReset";
391fa1a5a38SJayashankar Padath             }
392fa1a5a38SJayashankar Padath 
393fa1a5a38SJayashankar Padath             // Set the requested image apply time value
394fa1a5a38SJayashankar Padath             crow::connections::systemBus->async_method_call(
395fa1a5a38SJayashankar Padath                 [asyncResp](const boost::system::error_code ec) {
396fa1a5a38SJayashankar Padath                     if (ec)
397fa1a5a38SJayashankar Padath                     {
398fa1a5a38SJayashankar Padath                         BMCWEB_LOG_ERROR << "D-Bus responses error: " << ec;
399fa1a5a38SJayashankar Padath                         messages::internalError(asyncResp->res);
400fa1a5a38SJayashankar Padath                         return;
401fa1a5a38SJayashankar Padath                     }
402fa1a5a38SJayashankar Padath                     messages::success(asyncResp->res);
403fa1a5a38SJayashankar Padath                 },
404fa1a5a38SJayashankar Padath                 "xyz.openbmc_project.Settings",
405fa1a5a38SJayashankar Padath                 "/xyz/openbmc_project/software/apply_time",
406fa1a5a38SJayashankar Padath                 "org.freedesktop.DBus.Properties", "Set",
407fa1a5a38SJayashankar Padath                 "xyz.openbmc_project.Software.ApplyTime", "RequestedApplyTime",
408fa1a5a38SJayashankar Padath                 std::variant<std::string>{applyTimeNewVal});
409fa1a5a38SJayashankar Padath         }
410fa1a5a38SJayashankar Padath         else
411fa1a5a38SJayashankar Padath         {
412fa1a5a38SJayashankar Padath             BMCWEB_LOG_INFO << "ApplyTime value is not in the list of "
413fa1a5a38SJayashankar Padath                                "acceptable values";
414fa1a5a38SJayashankar Padath             messages::propertyValueNotInList(asyncResp->res, applyTime,
415fa1a5a38SJayashankar Padath                                              "ApplyTime");
416fa1a5a38SJayashankar Padath         }
417fa1a5a38SJayashankar Padath     }
418fa1a5a38SJayashankar Padath 
419acb7cfb4SJennifer Lee     void doPost(crow::Response &res, const crow::Request &req,
4201abe55efSEd Tanous                 const std::vector<std::string> &params) override
4211abe55efSEd Tanous     {
422acb7cfb4SJennifer Lee         BMCWEB_LOG_DEBUG << "doPost...";
423acb7cfb4SJennifer Lee 
4240e7de46fSAndrew Geissler         std::shared_ptr<AsyncResp> asyncResp = std::make_shared<AsyncResp>(res);
425acb7cfb4SJennifer Lee 
42686adcd6dSAndrew Geissler         // Setup callback for when new software detected
42786adcd6dSAndrew Geissler         monitorForSoftwareAvailable(asyncResp, req);
428acb7cfb4SJennifer Lee 
429acb7cfb4SJennifer Lee         std::string filepath(
430acb7cfb4SJennifer Lee             "/tmp/images/" +
431acb7cfb4SJennifer Lee             boost::uuids::to_string(boost::uuids::random_generator()()));
432acb7cfb4SJennifer Lee         BMCWEB_LOG_DEBUG << "Writing file to " << filepath;
433acb7cfb4SJennifer Lee         std::ofstream out(filepath, std::ofstream::out | std::ofstream::binary |
434acb7cfb4SJennifer Lee                                         std::ofstream::trunc);
435acb7cfb4SJennifer Lee         out << req.body;
436acb7cfb4SJennifer Lee         out.close();
437acb7cfb4SJennifer Lee         BMCWEB_LOG_DEBUG << "file upload complete!!";
438acb7cfb4SJennifer Lee     }
439729dae72SJennifer Lee };
440729dae72SJennifer Lee 
4411abe55efSEd Tanous class SoftwareInventoryCollection : public Node
4421abe55efSEd Tanous {
443729dae72SJennifer Lee   public:
444729dae72SJennifer Lee     template <typename CrowApp>
4451abe55efSEd Tanous     SoftwareInventoryCollection(CrowApp &app) :
4461abe55efSEd Tanous         Node(app, "/redfish/v1/UpdateService/FirmwareInventory/")
4471abe55efSEd Tanous     {
448729dae72SJennifer Lee         entityPrivileges = {
449729dae72SJennifer Lee             {boost::beast::http::verb::get, {{"Login"}}},
450729dae72SJennifer Lee             {boost::beast::http::verb::head, {{"Login"}}},
451729dae72SJennifer Lee             {boost::beast::http::verb::patch, {{"ConfigureComponents"}}},
452729dae72SJennifer Lee             {boost::beast::http::verb::put, {{"ConfigureComponents"}}},
453729dae72SJennifer Lee             {boost::beast::http::verb::delete_, {{"ConfigureComponents"}}},
454729dae72SJennifer Lee             {boost::beast::http::verb::post, {{"ConfigureComponents"}}}};
455729dae72SJennifer Lee     }
456729dae72SJennifer Lee 
457729dae72SJennifer Lee   private:
45855c7b7a2SEd Tanous     void doGet(crow::Response &res, const crow::Request &req,
4591abe55efSEd Tanous                const std::vector<std::string> &params) override
4601abe55efSEd Tanous     {
461c711bf86SEd Tanous         std::shared_ptr<AsyncResp> asyncResp = std::make_shared<AsyncResp>(res);
4620f74e643SEd Tanous         res.jsonValue["@odata.type"] =
4630f74e643SEd Tanous             "#SoftwareInventoryCollection.SoftwareInventoryCollection";
4640f74e643SEd Tanous         res.jsonValue["@odata.id"] =
4650f74e643SEd Tanous             "/redfish/v1/UpdateService/FirmwareInventory";
4660f74e643SEd Tanous         res.jsonValue["@odata.context"] =
4670f74e643SEd Tanous             "/redfish/v1/"
4680f74e643SEd Tanous             "$metadata#SoftwareInventoryCollection.SoftwareInventoryCollection";
4690f74e643SEd Tanous         res.jsonValue["Name"] = "Software Inventory Collection";
470c711bf86SEd Tanous 
471c711bf86SEd Tanous         crow::connections::systemBus->async_method_call(
472c711bf86SEd Tanous             [asyncResp](
473c711bf86SEd Tanous                 const boost::system::error_code ec,
4746c4eb9deSJennifer Lee                 const std::vector<std::pair<
4751abe55efSEd Tanous                     std::string, std::vector<std::pair<
4761abe55efSEd Tanous                                      std::string, std::vector<std::string>>>>>
4776c4eb9deSJennifer Lee                     &subtree) {
4781abe55efSEd Tanous                 if (ec)
4791abe55efSEd Tanous                 {
480f12894f8SJason M. Bills                     messages::internalError(asyncResp->res);
4816c4eb9deSJennifer Lee                     return;
482729dae72SJennifer Lee                 }
483c711bf86SEd Tanous                 asyncResp->res.jsonValue["Members"] = nlohmann::json::array();
484c711bf86SEd Tanous                 asyncResp->res.jsonValue["Members@odata.count"] = 0;
4856c4eb9deSJennifer Lee 
4861abe55efSEd Tanous                 for (auto &obj : subtree)
4871abe55efSEd Tanous                 {
4881abe55efSEd Tanous                     const std::vector<
4891abe55efSEd Tanous                         std::pair<std::string, std::vector<std::string>>>
4906c4eb9deSJennifer Lee                         &connections = obj.second;
4916c4eb9deSJennifer Lee 
492f4b65ab1SJennifer Lee                     // if can't parse fw id then return
49327826b5fSEd Tanous                     std::size_t idPos;
49427826b5fSEd Tanous                     if ((idPos = obj.first.rfind("/")) == std::string::npos)
495f4b65ab1SJennifer Lee                     {
496f12894f8SJason M. Bills                         messages::internalError(asyncResp->res);
497f4b65ab1SJennifer Lee                         BMCWEB_LOG_DEBUG << "Can't parse firmware ID!!";
498f4b65ab1SJennifer Lee                         return;
499f4b65ab1SJennifer Lee                     }
500f4b65ab1SJennifer Lee                     std::string swId = obj.first.substr(idPos + 1);
501f4b65ab1SJennifer Lee 
502c711bf86SEd Tanous                     nlohmann::json &members =
503c711bf86SEd Tanous                         asyncResp->res.jsonValue["Members"];
504c711bf86SEd Tanous                     members.push_back(
505f4b65ab1SJennifer Lee                         {{"@odata.id", "/redfish/v1/UpdateService/"
5061abe55efSEd Tanous                                        "FirmwareInventory/" +
507f4b65ab1SJennifer Lee                                            swId}});
508e0dd8057SAndrew Geissler                     asyncResp->res.jsonValue["Members@odata.count"] =
509c711bf86SEd Tanous                         members.size();
5106c4eb9deSJennifer Lee                 }
511c711bf86SEd Tanous             },
512c711bf86SEd Tanous             "xyz.openbmc_project.ObjectMapper",
513c711bf86SEd Tanous             "/xyz/openbmc_project/object_mapper",
514c711bf86SEd Tanous             "xyz.openbmc_project.ObjectMapper", "GetSubTree",
515c711bf86SEd Tanous             "/xyz/openbmc_project/software", int32_t(1),
5161abe55efSEd Tanous             std::array<const char *, 1>{
5171abe55efSEd Tanous                 "xyz.openbmc_project.Software.Version"});
518729dae72SJennifer Lee     }
519729dae72SJennifer Lee };
520c711bf86SEd Tanous 
5211abe55efSEd Tanous class SoftwareInventory : public Node
5221abe55efSEd Tanous {
523729dae72SJennifer Lee   public:
524729dae72SJennifer Lee     template <typename CrowApp>
5251abe55efSEd Tanous     SoftwareInventory(CrowApp &app) :
5261abe55efSEd Tanous         Node(app, "/redfish/v1/UpdateService/FirmwareInventory/<str>/",
5271abe55efSEd Tanous              std::string())
5281abe55efSEd Tanous     {
529729dae72SJennifer Lee         entityPrivileges = {
530729dae72SJennifer Lee             {boost::beast::http::verb::get, {{"Login"}}},
531729dae72SJennifer Lee             {boost::beast::http::verb::head, {{"Login"}}},
532729dae72SJennifer Lee             {boost::beast::http::verb::patch, {{"ConfigureComponents"}}},
533729dae72SJennifer Lee             {boost::beast::http::verb::put, {{"ConfigureComponents"}}},
534729dae72SJennifer Lee             {boost::beast::http::verb::delete_, {{"ConfigureComponents"}}},
535729dae72SJennifer Lee             {boost::beast::http::verb::post, {{"ConfigureComponents"}}}};
536729dae72SJennifer Lee     }
537729dae72SJennifer Lee 
538729dae72SJennifer Lee   private:
53987d84729SAndrew Geissler     /* Fill related item links (i.e. bmc, bios) in for inventory */
54087d84729SAndrew Geissler     static void getRelatedItems(std::shared_ptr<AsyncResp> aResp,
54187d84729SAndrew Geissler                                 const std::string &purpose)
54287d84729SAndrew Geissler     {
54387d84729SAndrew Geissler         if (purpose == fw_util::bmcPurpose)
54487d84729SAndrew Geissler         {
54587d84729SAndrew Geissler             nlohmann::json &members = aResp->res.jsonValue["RelatedItem"];
54687d84729SAndrew Geissler             members.push_back({{"@odata.id", "/redfish/v1/Managers/bmc"}});
54787d84729SAndrew Geissler             aResp->res.jsonValue["Members@odata.count"] = members.size();
54887d84729SAndrew Geissler         }
54987d84729SAndrew Geissler         else if (purpose == fw_util::biosPurpose)
55087d84729SAndrew Geissler         {
55187d84729SAndrew Geissler             // TODO(geissonator) Need BIOS schema support added for this
55287d84729SAndrew Geissler             //                   to be valid
55387d84729SAndrew Geissler             // nlohmann::json &members = aResp->res.jsonValue["RelatedItem"];
55487d84729SAndrew Geissler             // members.push_back(
55587d84729SAndrew Geissler             //    {{"@odata.id", "/redfish/v1/Systems/system/BIOS"}});
55687d84729SAndrew Geissler             // aResp->res.jsonValue["Members@odata.count"] = members.size();
55787d84729SAndrew Geissler         }
55887d84729SAndrew Geissler         else
55987d84729SAndrew Geissler         {
56087d84729SAndrew Geissler             BMCWEB_LOG_ERROR << "Unknown software purpose " << purpose;
56187d84729SAndrew Geissler         }
56287d84729SAndrew Geissler     }
56387d84729SAndrew Geissler 
56455c7b7a2SEd Tanous     void doGet(crow::Response &res, const crow::Request &req,
5651abe55efSEd Tanous                const std::vector<std::string> &params) override
5661abe55efSEd Tanous     {
567c711bf86SEd Tanous         std::shared_ptr<AsyncResp> asyncResp = std::make_shared<AsyncResp>(res);
5686c4eb9deSJennifer Lee 
5691abe55efSEd Tanous         if (params.size() != 1)
5701abe55efSEd Tanous         {
571f12894f8SJason M. Bills             messages::internalError(res);
572729dae72SJennifer Lee             res.end();
573729dae72SJennifer Lee             return;
574729dae72SJennifer Lee         }
575729dae72SJennifer Lee 
5763ae837c9SEd Tanous         std::shared_ptr<std::string> swId =
577c711bf86SEd Tanous             std::make_shared<std::string>(params[0]);
578c711bf86SEd Tanous 
57955c7b7a2SEd Tanous         res.jsonValue["@odata.id"] =
5803ae837c9SEd Tanous             "/redfish/v1/UpdateService/FirmwareInventory/" + *swId;
581c711bf86SEd Tanous 
582c711bf86SEd Tanous         crow::connections::systemBus->async_method_call(
5833ae837c9SEd Tanous             [asyncResp, swId](
584c711bf86SEd Tanous                 const boost::system::error_code ec,
5856c4eb9deSJennifer Lee                 const std::vector<std::pair<
5861abe55efSEd Tanous                     std::string, std::vector<std::pair<
5871abe55efSEd Tanous                                      std::string, std::vector<std::string>>>>>
5886c4eb9deSJennifer Lee                     &subtree) {
58955c7b7a2SEd Tanous                 BMCWEB_LOG_DEBUG << "doGet callback...";
5901abe55efSEd Tanous                 if (ec)
5911abe55efSEd Tanous                 {
592f12894f8SJason M. Bills                     messages::internalError(asyncResp->res);
5936c4eb9deSJennifer Lee                     return;
5946c4eb9deSJennifer Lee                 }
5956c4eb9deSJennifer Lee 
5966913228dSAndrew Geissler                 // Ensure we find our input swId, otherwise return an error
5976913228dSAndrew Geissler                 bool found = false;
5981abe55efSEd Tanous                 for (const std::pair<
5991abe55efSEd Tanous                          std::string,
6001abe55efSEd Tanous                          std::vector<
6011abe55efSEd Tanous                              std::pair<std::string, std::vector<std::string>>>>
6021abe55efSEd Tanous                          &obj : subtree)
6031abe55efSEd Tanous                 {
6043ae837c9SEd Tanous                     if (boost::ends_with(obj.first, *swId) != true)
6051abe55efSEd Tanous                     {
606acb7cfb4SJennifer Lee                         continue;
607acb7cfb4SJennifer Lee                     }
608acb7cfb4SJennifer Lee 
609f4b65ab1SJennifer Lee                     if (obj.second.size() < 1)
6101abe55efSEd Tanous                     {
611acb7cfb4SJennifer Lee                         continue;
612acb7cfb4SJennifer Lee                     }
6136c4eb9deSJennifer Lee 
6146913228dSAndrew Geissler                     found = true;
615e0dd8057SAndrew Geissler                     fw_util::getFwStatus(asyncResp, swId, obj.second[0].first);
616e0dd8057SAndrew Geissler 
61755c7b7a2SEd Tanous                     crow::connections::systemBus->async_method_call(
6181abe55efSEd Tanous                         [asyncResp,
6193ae837c9SEd Tanous                          swId](const boost::system::error_code error_code,
6201abe55efSEd Tanous                                const boost::container::flat_map<
6211abe55efSEd Tanous                                    std::string, VariantType> &propertiesList) {
6221abe55efSEd Tanous                             if (error_code)
6231abe55efSEd Tanous                             {
624f12894f8SJason M. Bills                                 messages::internalError(asyncResp->res);
6256c4eb9deSJennifer Lee                                 return;
6266c4eb9deSJennifer Lee                             }
6271abe55efSEd Tanous                             boost::container::flat_map<
6281abe55efSEd Tanous                                 std::string, VariantType>::const_iterator it =
6296c4eb9deSJennifer Lee                                 propertiesList.find("Purpose");
6301abe55efSEd Tanous                             if (it == propertiesList.end())
6311abe55efSEd Tanous                             {
6321abe55efSEd Tanous                                 BMCWEB_LOG_DEBUG
6331abe55efSEd Tanous                                     << "Can't find property \"Purpose\"!";
634f12894f8SJason M. Bills                                 messages::propertyMissing(asyncResp->res,
635f12894f8SJason M. Bills                                                           "Purpose");
6366c4eb9deSJennifer Lee                                 return;
6376c4eb9deSJennifer Lee                             }
6383ae837c9SEd Tanous                             const std::string *swInvPurpose =
639abf2add6SEd Tanous                                 std::get_if<std::string>(&it->second);
6403ae837c9SEd Tanous                             if (swInvPurpose == nullptr)
6411abe55efSEd Tanous                             {
6421abe55efSEd Tanous                                 BMCWEB_LOG_DEBUG
6431abe55efSEd Tanous                                     << "wrong types for property\"Purpose\"!";
644f12894f8SJason M. Bills                                 messages::propertyValueTypeError(asyncResp->res,
645f12894f8SJason M. Bills                                                                  "", "Purpose");
646acb7cfb4SJennifer Lee                                 return;
647acb7cfb4SJennifer Lee                             }
648c711bf86SEd Tanous 
6493ae837c9SEd Tanous                             BMCWEB_LOG_DEBUG << "swInvPurpose = "
6503ae837c9SEd Tanous                                              << *swInvPurpose;
651c711bf86SEd Tanous                             it = propertiesList.find("Version");
6521abe55efSEd Tanous                             if (it == propertiesList.end())
6531abe55efSEd Tanous                             {
6541abe55efSEd Tanous                                 BMCWEB_LOG_DEBUG
6551abe55efSEd Tanous                                     << "Can't find property \"Version\"!";
656f12894f8SJason M. Bills                                 messages::propertyMissing(asyncResp->res,
657f12894f8SJason M. Bills                                                           "Version");
658c711bf86SEd Tanous                                 return;
659acb7cfb4SJennifer Lee                             }
660acb7cfb4SJennifer Lee 
661f4b65ab1SJennifer Lee                             BMCWEB_LOG_DEBUG << "Version found!";
662c711bf86SEd Tanous 
663f4b65ab1SJennifer Lee                             const std::string *version =
664abf2add6SEd Tanous                                 std::get_if<std::string>(&it->second);
665f4b65ab1SJennifer Lee 
666f4b65ab1SJennifer Lee                             if (version == nullptr)
6671abe55efSEd Tanous                             {
6681abe55efSEd Tanous                                 BMCWEB_LOG_DEBUG
6691abe55efSEd Tanous                                     << "Can't find property \"Version\"!";
670f12894f8SJason M. Bills 
671f12894f8SJason M. Bills                                 messages::propertyValueTypeError(asyncResp->res,
672f12894f8SJason M. Bills                                                                  "", "Version");
6736c4eb9deSJennifer Lee                                 return;
6746c4eb9deSJennifer Lee                             }
675c711bf86SEd Tanous                             asyncResp->res.jsonValue["Version"] = *version;
6763ae837c9SEd Tanous                             asyncResp->res.jsonValue["Id"] = *swId;
67754daabe7SAndrew Geissler 
67854daabe7SAndrew Geissler                             // swInvPurpose is of format:
67954daabe7SAndrew Geissler                             // xyz.openbmc_project.Software.Version.VersionPurpose.ABC
680*e2e96770SJames Feist                             // Translate this to "ABC image"
68154daabe7SAndrew Geissler                             size_t endDesc = swInvPurpose->rfind(".");
68254daabe7SAndrew Geissler                             if (endDesc == std::string::npos)
68354daabe7SAndrew Geissler                             {
68454daabe7SAndrew Geissler                                 messages::internalError(asyncResp->res);
68554daabe7SAndrew Geissler                                 return;
68654daabe7SAndrew Geissler                             }
68754daabe7SAndrew Geissler                             endDesc++;
68854daabe7SAndrew Geissler                             if (endDesc >= swInvPurpose->size())
68954daabe7SAndrew Geissler                             {
69054daabe7SAndrew Geissler                                 messages::internalError(asyncResp->res);
69154daabe7SAndrew Geissler                                 return;
69254daabe7SAndrew Geissler                             }
69354daabe7SAndrew Geissler 
69454daabe7SAndrew Geissler                             std::string formatDesc =
69554daabe7SAndrew Geissler                                 swInvPurpose->substr(endDesc);
69654daabe7SAndrew Geissler                             asyncResp->res.jsonValue["Description"] =
697*e2e96770SJames Feist                                 formatDesc + " image";
69887d84729SAndrew Geissler                             getRelatedItems(asyncResp, *swInvPurpose);
6996c4eb9deSJennifer Lee                         },
700c711bf86SEd Tanous                         obj.second[0].first, obj.first,
701c711bf86SEd Tanous                         "org.freedesktop.DBus.Properties", "GetAll",
702c711bf86SEd Tanous                         "xyz.openbmc_project.Software.Version");
7036c4eb9deSJennifer Lee                 }
7046913228dSAndrew Geissler                 if (!found)
7056913228dSAndrew Geissler                 {
7066913228dSAndrew Geissler                     BMCWEB_LOG_ERROR << "Input swID " + *swId + " not found!";
7076913228dSAndrew Geissler                     messages::resourceMissingAtURI(
7086913228dSAndrew Geissler                         asyncResp->res,
7096913228dSAndrew Geissler                         "/redfish/v1/UpdateService/FirmwareInventory/" + *swId);
7106913228dSAndrew Geissler                     return;
7116913228dSAndrew Geissler                 }
7124e68c45bSAyushi Smriti                 asyncResp->res.jsonValue["@odata.type"] =
7134e68c45bSAyushi Smriti                     "#SoftwareInventory.v1_1_0.SoftwareInventory";
7144e68c45bSAyushi Smriti                 asyncResp->res.jsonValue["@odata.context"] =
7154e68c45bSAyushi Smriti                     "/redfish/v1/$metadata#SoftwareInventory.SoftwareInventory";
7164e68c45bSAyushi Smriti                 asyncResp->res.jsonValue["Name"] = "Software Inventory";
7174e68c45bSAyushi Smriti                 asyncResp->res.jsonValue["Updateable"] = false;
7184e68c45bSAyushi Smriti                 asyncResp->res.jsonValue["Status"]["Health"] = "OK";
7194e68c45bSAyushi Smriti                 asyncResp->res.jsonValue["Status"]["HealthRollup"] = "OK";
720c711bf86SEd Tanous             },
721c711bf86SEd Tanous             "xyz.openbmc_project.ObjectMapper",
722c711bf86SEd Tanous             "/xyz/openbmc_project/object_mapper",
723c711bf86SEd Tanous             "xyz.openbmc_project.ObjectMapper", "GetSubTree",
724c711bf86SEd Tanous             "/xyz/openbmc_project/software", int32_t(1),
7251abe55efSEd Tanous             std::array<const char *, 1>{
7261abe55efSEd Tanous                 "xyz.openbmc_project.Software.Version"});
7276c4eb9deSJennifer Lee     }
728729dae72SJennifer Lee };
729729dae72SJennifer Lee 
730729dae72SJennifer Lee } // namespace redfish
731