xref: /openbmc/bmcweb/features/redfish/lib/update_service.hpp (revision 271584ab78b4c1926f766aa26ddfde7da329059f)
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
32*271584abSEd Tanous static std::unique_ptr<boost::asio::steady_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 =
151*271584abSEd Tanous         std::make_unique<boost::asio::steady_timer>(*req.ioService);
15286adcd6dSAndrew Geissler 
153*271584abSEd Tanous     fwAvailableTimer->expires_after(std::chrono::seconds(timeoutTimeSeconds));
15486adcd6dSAndrew Geissler 
15586adcd6dSAndrew Geissler     fwAvailableTimer->async_wait(
15686adcd6dSAndrew Geissler         [asyncResp](const boost::system::error_code &ec) {
15786adcd6dSAndrew Geissler             cleanUp();
15886adcd6dSAndrew Geissler             if (ec == boost::asio::error::operation_aborted)
15986adcd6dSAndrew Geissler             {
16086adcd6dSAndrew Geissler                 // expected, we were canceled before the timer completed.
16186adcd6dSAndrew Geissler                 return;
16286adcd6dSAndrew Geissler             }
16386adcd6dSAndrew Geissler             BMCWEB_LOG_ERROR
16486adcd6dSAndrew Geissler                 << "Timed out waiting for firmware object being created";
16586adcd6dSAndrew Geissler             BMCWEB_LOG_ERROR
16686adcd6dSAndrew Geissler                 << "FW image may has already been uploaded to server";
16786adcd6dSAndrew Geissler             if (ec)
16886adcd6dSAndrew Geissler             {
16986adcd6dSAndrew Geissler                 BMCWEB_LOG_ERROR << "Async_wait failed" << ec;
17086adcd6dSAndrew Geissler                 return;
17186adcd6dSAndrew Geissler             }
1720554c984SAndrew Geissler             if (asyncResp)
1730554c984SAndrew Geissler             {
17486adcd6dSAndrew Geissler                 redfish::messages::internalError(asyncResp->res);
1750554c984SAndrew Geissler             }
17686adcd6dSAndrew Geissler         });
17786adcd6dSAndrew Geissler 
17886adcd6dSAndrew Geissler     auto callback = [asyncResp](sdbusplus::message::message &m) {
17986adcd6dSAndrew Geissler         BMCWEB_LOG_DEBUG << "Match fired";
18086adcd6dSAndrew Geissler         softwareInterfaceAdded(asyncResp, m);
18186adcd6dSAndrew Geissler     };
18286adcd6dSAndrew Geissler 
18386adcd6dSAndrew Geissler     fwUpdateInProgress = true;
18486adcd6dSAndrew Geissler 
18586adcd6dSAndrew Geissler     fwUpdateMatcher = std::make_unique<sdbusplus::bus::match::match>(
18686adcd6dSAndrew Geissler         *crow::connections::systemBus,
18786adcd6dSAndrew Geissler         "interface='org.freedesktop.DBus.ObjectManager',type='signal',"
18886adcd6dSAndrew Geissler         "member='InterfacesAdded',path='/xyz/openbmc_project/software'",
18986adcd6dSAndrew Geissler         callback);
19086adcd6dSAndrew Geissler }
191729dae72SJennifer Lee 
1920554c984SAndrew Geissler /**
1930554c984SAndrew Geissler  * UpdateServiceActionsSimpleUpdate class supports handle POST method for
1940554c984SAndrew Geissler  * SimpleUpdate action.
1950554c984SAndrew Geissler  */
1960554c984SAndrew Geissler class UpdateServiceActionsSimpleUpdate : public Node
1970554c984SAndrew Geissler {
1980554c984SAndrew Geissler   public:
1990554c984SAndrew Geissler     UpdateServiceActionsSimpleUpdate(CrowApp &app) :
2000554c984SAndrew Geissler         Node(app,
2010554c984SAndrew Geissler              "/redfish/v1/UpdateService/Actions/UpdateService.SimpleUpdate/")
2020554c984SAndrew Geissler     {
2030554c984SAndrew Geissler         entityPrivileges = {
2040554c984SAndrew Geissler             {boost::beast::http::verb::get, {{"Login"}}},
2050554c984SAndrew Geissler             {boost::beast::http::verb::head, {{"Login"}}},
2060554c984SAndrew Geissler             {boost::beast::http::verb::patch, {{"ConfigureManager"}}},
2070554c984SAndrew Geissler             {boost::beast::http::verb::put, {{"ConfigureComponents"}}},
2080554c984SAndrew Geissler             {boost::beast::http::verb::delete_, {{"ConfigureComponents"}}},
2090554c984SAndrew Geissler             {boost::beast::http::verb::post, {{"ConfigureComponents"}}}};
2100554c984SAndrew Geissler     }
2110554c984SAndrew Geissler 
2120554c984SAndrew Geissler   private:
2130554c984SAndrew Geissler     void doPost(crow::Response &res, const crow::Request &req,
2140554c984SAndrew Geissler                 const std::vector<std::string> &params) override
2150554c984SAndrew Geissler     {
2160554c984SAndrew Geissler         std::optional<std::string> transferProtocol;
2170554c984SAndrew Geissler         std::string imageURI;
2180554c984SAndrew Geissler         std::shared_ptr<AsyncResp> asyncResp = std::make_shared<AsyncResp>(res);
2190554c984SAndrew Geissler 
2200554c984SAndrew Geissler         BMCWEB_LOG_DEBUG << "Enter UpdateService.SimpleUpdate doPost";
2210554c984SAndrew Geissler 
2220554c984SAndrew Geissler         // User can pass in both TransferProtocol and ImageURI parameters or
2230554c984SAndrew Geissler         // they can pass in just the ImageURI with the transfer protocl embedded
2240554c984SAndrew Geissler         // within it.
2250554c984SAndrew Geissler         // 1) TransferProtocol:TFTP ImageURI:1.1.1.1/myfile.bin
2260554c984SAndrew Geissler         // 2) ImageURI:tftp://1.1.1.1/myfile.bin
2270554c984SAndrew Geissler 
2280554c984SAndrew Geissler         if (!json_util::readJson(req, asyncResp->res, "TransferProtocol",
2290554c984SAndrew Geissler                                  transferProtocol, "ImageURI", imageURI))
2300554c984SAndrew Geissler         {
2310554c984SAndrew Geissler             BMCWEB_LOG_DEBUG
2320554c984SAndrew Geissler                 << "Missing TransferProtocol or ImageURI parameter";
2330554c984SAndrew Geissler             return;
2340554c984SAndrew Geissler         }
2350554c984SAndrew Geissler         if (!transferProtocol)
2360554c984SAndrew Geissler         {
2370554c984SAndrew Geissler             // Must be option 2
2380554c984SAndrew Geissler             // Verify ImageURI has transfer protocol in it
2390554c984SAndrew Geissler             size_t separator = imageURI.find(":");
2400554c984SAndrew Geissler             if ((separator == std::string::npos) ||
2410554c984SAndrew Geissler                 ((separator + 1) > imageURI.size()))
2420554c984SAndrew Geissler             {
2430554c984SAndrew Geissler                 messages::actionParameterValueTypeError(
2440554c984SAndrew Geissler                     asyncResp->res, imageURI, "ImageURI",
2450554c984SAndrew Geissler                     "UpdateService.SimpleUpdate");
2460554c984SAndrew Geissler                 BMCWEB_LOG_ERROR << "ImageURI missing transfer protocol: "
2470554c984SAndrew Geissler                                  << imageURI;
2480554c984SAndrew Geissler                 return;
2490554c984SAndrew Geissler             }
2500554c984SAndrew Geissler             transferProtocol = imageURI.substr(0, separator);
2510554c984SAndrew Geissler             // Ensure protocol is upper case for a common comparison path below
2520554c984SAndrew Geissler             boost::to_upper(*transferProtocol);
2530554c984SAndrew Geissler             BMCWEB_LOG_DEBUG << "Encoded transfer protocol "
2540554c984SAndrew Geissler                              << *transferProtocol;
2550554c984SAndrew Geissler 
2560554c984SAndrew Geissler             // Adjust imageURI to not have the protocol on it for parsing
2570554c984SAndrew Geissler             // below
2580554c984SAndrew Geissler             // ex. tftp://1.1.1.1/myfile.bin -> 1.1.1.1/myfile.bin
2590554c984SAndrew Geissler             imageURI = imageURI.substr(separator + 3);
2600554c984SAndrew Geissler             BMCWEB_LOG_DEBUG << "Adjusted imageUri " << imageURI;
2610554c984SAndrew Geissler         }
2620554c984SAndrew Geissler 
2630554c984SAndrew Geissler         // OpenBMC currently only supports TFTP
2640554c984SAndrew Geissler         if (*transferProtocol != "TFTP")
2650554c984SAndrew Geissler         {
2660554c984SAndrew Geissler             messages::actionParameterNotSupported(asyncResp->res,
2670554c984SAndrew Geissler                                                   "TransferProtocol",
2680554c984SAndrew Geissler                                                   "UpdateService.SimpleUpdate");
2690554c984SAndrew Geissler             BMCWEB_LOG_ERROR << "Request incorrect protocol parameter: "
2700554c984SAndrew Geissler                              << *transferProtocol;
2710554c984SAndrew Geissler             return;
2720554c984SAndrew Geissler         }
2730554c984SAndrew Geissler 
2740554c984SAndrew Geissler         // Format should be <IP or Hostname>/<file> for imageURI
2750554c984SAndrew Geissler         size_t separator = imageURI.find("/");
2760554c984SAndrew Geissler         if ((separator == std::string::npos) ||
2770554c984SAndrew Geissler             ((separator + 1) > imageURI.size()))
2780554c984SAndrew Geissler         {
2790554c984SAndrew Geissler             messages::actionParameterValueTypeError(
2800554c984SAndrew Geissler                 asyncResp->res, imageURI, "ImageURI",
2810554c984SAndrew Geissler                 "UpdateService.SimpleUpdate");
2820554c984SAndrew Geissler             BMCWEB_LOG_ERROR << "Invalid ImageURI: " << imageURI;
2830554c984SAndrew Geissler             return;
2840554c984SAndrew Geissler         }
2850554c984SAndrew Geissler 
2860554c984SAndrew Geissler         std::string tftpServer = imageURI.substr(0, separator);
2870554c984SAndrew Geissler         std::string fwFile = imageURI.substr(separator + 1);
2880554c984SAndrew Geissler         BMCWEB_LOG_DEBUG << "Server: " << tftpServer + " File: " << fwFile;
2890554c984SAndrew Geissler 
2900554c984SAndrew Geissler         // Setup callback for when new software detected
2910554c984SAndrew Geissler         // Give TFTP 2 minutes to complete
2920554c984SAndrew Geissler         monitorForSoftwareAvailable(nullptr, req, 120);
2930554c984SAndrew Geissler 
2940554c984SAndrew Geissler         // TFTP can take up to 2 minutes depending on image size and
2950554c984SAndrew Geissler         // connection speed. Return to caller as soon as the TFTP operation
2960554c984SAndrew Geissler         // has been started. The callback above will ensure the activate
2970554c984SAndrew Geissler         // is started once the download has completed
2980554c984SAndrew Geissler         redfish::messages::success(asyncResp->res);
2990554c984SAndrew Geissler 
3000554c984SAndrew Geissler         // Call TFTP service
3010554c984SAndrew Geissler         crow::connections::systemBus->async_method_call(
3020554c984SAndrew Geissler             [](const boost::system::error_code ec) {
3030554c984SAndrew Geissler                 if (ec)
3040554c984SAndrew Geissler                 {
3050554c984SAndrew Geissler                     // messages::internalError(asyncResp->res);
3060554c984SAndrew Geissler                     cleanUp();
3070554c984SAndrew Geissler                     BMCWEB_LOG_DEBUG << "error_code = " << ec;
3080554c984SAndrew Geissler                     BMCWEB_LOG_DEBUG << "error msg = " << ec.message();
3090554c984SAndrew Geissler                 }
3100554c984SAndrew Geissler                 else
3110554c984SAndrew Geissler                 {
3120554c984SAndrew Geissler                     BMCWEB_LOG_DEBUG << "Call to DownloaViaTFTP Success";
3130554c984SAndrew Geissler                 }
3140554c984SAndrew Geissler             },
3150554c984SAndrew Geissler             "xyz.openbmc_project.Software.Download",
3160554c984SAndrew Geissler             "/xyz/openbmc_project/software", "xyz.openbmc_project.Common.TFTP",
3170554c984SAndrew Geissler             "DownloadViaTFTP", fwFile, tftpServer);
3180554c984SAndrew Geissler 
3190554c984SAndrew Geissler         BMCWEB_LOG_DEBUG << "Exit UpdateService.SimpleUpdate doPost";
3200554c984SAndrew Geissler     }
3210554c984SAndrew Geissler };
3220554c984SAndrew Geissler 
3231abe55efSEd Tanous class UpdateService : public Node
3241abe55efSEd Tanous {
325729dae72SJennifer Lee   public:
3261abe55efSEd Tanous     UpdateService(CrowApp &app) : Node(app, "/redfish/v1/UpdateService/")
3271abe55efSEd Tanous     {
328729dae72SJennifer Lee         entityPrivileges = {
329729dae72SJennifer Lee             {boost::beast::http::verb::get, {{"Login"}}},
330729dae72SJennifer Lee             {boost::beast::http::verb::head, {{"Login"}}},
331729dae72SJennifer Lee             {boost::beast::http::verb::patch, {{"ConfigureComponents"}}},
332729dae72SJennifer Lee             {boost::beast::http::verb::put, {{"ConfigureComponents"}}},
333729dae72SJennifer Lee             {boost::beast::http::verb::delete_, {{"ConfigureComponents"}}},
334729dae72SJennifer Lee             {boost::beast::http::verb::post, {{"ConfigureComponents"}}}};
335729dae72SJennifer Lee     }
336729dae72SJennifer Lee 
337729dae72SJennifer Lee   private:
33855c7b7a2SEd Tanous     void doGet(crow::Response &res, const crow::Request &req,
3391abe55efSEd Tanous                const std::vector<std::string> &params) override
3401abe55efSEd Tanous     {
3410f74e643SEd Tanous         res.jsonValue["@odata.type"] = "#UpdateService.v1_2_0.UpdateService";
3420f74e643SEd Tanous         res.jsonValue["@odata.id"] = "/redfish/v1/UpdateService";
3430f74e643SEd Tanous         res.jsonValue["@odata.context"] =
3440f74e643SEd Tanous             "/redfish/v1/$metadata#UpdateService.UpdateService";
3450f74e643SEd Tanous         res.jsonValue["Id"] = "UpdateService";
3460f74e643SEd Tanous         res.jsonValue["Description"] = "Service for Software Update";
3470f74e643SEd Tanous         res.jsonValue["Name"] = "Update Service";
3480f74e643SEd Tanous         res.jsonValue["HttpPushUri"] = "/redfish/v1/UpdateService";
3490f74e643SEd Tanous         // UpdateService cannot be disabled
3500f74e643SEd Tanous         res.jsonValue["ServiceEnabled"] = true;
3510f74e643SEd Tanous         res.jsonValue["FirmwareInventory"] = {
3520f74e643SEd Tanous             {"@odata.id", "/redfish/v1/UpdateService/FirmwareInventory"}};
3530554c984SAndrew Geissler #ifdef BMCWEB_INSECURE_ENABLE_REDFISH_FW_TFTP_UPDATE
3540554c984SAndrew Geissler         // Update Actions object.
3550554c984SAndrew Geissler         nlohmann::json &updateSvcSimpleUpdate =
3560554c984SAndrew Geissler             res.jsonValue["Actions"]["#UpdateService.SimpleUpdate"];
3570554c984SAndrew Geissler         updateSvcSimpleUpdate["target"] =
3580554c984SAndrew Geissler             "/redfish/v1/UpdateService/Actions/UpdateService.SimpleUpdate";
3590554c984SAndrew Geissler         updateSvcSimpleUpdate["TransferProtocol@Redfish.AllowableValues"] = {
3600554c984SAndrew Geissler             "TFTP"};
3610554c984SAndrew Geissler #endif
362729dae72SJennifer Lee         res.end();
363729dae72SJennifer Lee     }
3640e7de46fSAndrew Geissler 
365fa1a5a38SJayashankar Padath     void doPatch(crow::Response &res, const crow::Request &req,
366fa1a5a38SJayashankar Padath                  const std::vector<std::string> &params) override
367fa1a5a38SJayashankar Padath     {
368fa1a5a38SJayashankar Padath         BMCWEB_LOG_DEBUG << "doPatch...";
369fa1a5a38SJayashankar Padath 
370fa1a5a38SJayashankar Padath         std::shared_ptr<AsyncResp> asyncResp = std::make_shared<AsyncResp>(res);
371fa1a5a38SJayashankar Padath         std::string applyTime;
372fa1a5a38SJayashankar Padath 
373fa1a5a38SJayashankar Padath         if (!json_util::readJson(req, res, "ApplyTime", applyTime))
374fa1a5a38SJayashankar Padath         {
375fa1a5a38SJayashankar Padath             return;
376fa1a5a38SJayashankar Padath         }
377fa1a5a38SJayashankar Padath 
378fa1a5a38SJayashankar Padath         if ((applyTime == "Immediate") || (applyTime == "OnReset"))
379fa1a5a38SJayashankar Padath         {
380fa1a5a38SJayashankar Padath             std::string applyTimeNewVal;
381fa1a5a38SJayashankar Padath             if (applyTime == "Immediate")
382fa1a5a38SJayashankar Padath             {
383fa1a5a38SJayashankar Padath                 applyTimeNewVal = "xyz.openbmc_project.Software.ApplyTime."
384fa1a5a38SJayashankar Padath                                   "RequestedApplyTimes.Immediate";
385fa1a5a38SJayashankar Padath             }
386fa1a5a38SJayashankar Padath             else
387fa1a5a38SJayashankar Padath             {
388fa1a5a38SJayashankar Padath                 applyTimeNewVal = "xyz.openbmc_project.Software.ApplyTime."
389fa1a5a38SJayashankar Padath                                   "RequestedApplyTimes.OnReset";
390fa1a5a38SJayashankar Padath             }
391fa1a5a38SJayashankar Padath 
392fa1a5a38SJayashankar Padath             // Set the requested image apply time value
393fa1a5a38SJayashankar Padath             crow::connections::systemBus->async_method_call(
394fa1a5a38SJayashankar Padath                 [asyncResp](const boost::system::error_code ec) {
395fa1a5a38SJayashankar Padath                     if (ec)
396fa1a5a38SJayashankar Padath                     {
397fa1a5a38SJayashankar Padath                         BMCWEB_LOG_ERROR << "D-Bus responses error: " << ec;
398fa1a5a38SJayashankar Padath                         messages::internalError(asyncResp->res);
399fa1a5a38SJayashankar Padath                         return;
400fa1a5a38SJayashankar Padath                     }
401fa1a5a38SJayashankar Padath                     messages::success(asyncResp->res);
402fa1a5a38SJayashankar Padath                 },
403fa1a5a38SJayashankar Padath                 "xyz.openbmc_project.Settings",
404fa1a5a38SJayashankar Padath                 "/xyz/openbmc_project/software/apply_time",
405fa1a5a38SJayashankar Padath                 "org.freedesktop.DBus.Properties", "Set",
406fa1a5a38SJayashankar Padath                 "xyz.openbmc_project.Software.ApplyTime", "RequestedApplyTime",
407fa1a5a38SJayashankar Padath                 std::variant<std::string>{applyTimeNewVal});
408fa1a5a38SJayashankar Padath         }
409fa1a5a38SJayashankar Padath         else
410fa1a5a38SJayashankar Padath         {
411fa1a5a38SJayashankar Padath             BMCWEB_LOG_INFO << "ApplyTime value is not in the list of "
412fa1a5a38SJayashankar Padath                                "acceptable values";
413fa1a5a38SJayashankar Padath             messages::propertyValueNotInList(asyncResp->res, applyTime,
414fa1a5a38SJayashankar Padath                                              "ApplyTime");
415fa1a5a38SJayashankar Padath         }
416fa1a5a38SJayashankar Padath     }
417fa1a5a38SJayashankar Padath 
418acb7cfb4SJennifer Lee     void doPost(crow::Response &res, const crow::Request &req,
4191abe55efSEd Tanous                 const std::vector<std::string> &params) override
4201abe55efSEd Tanous     {
421acb7cfb4SJennifer Lee         BMCWEB_LOG_DEBUG << "doPost...";
422acb7cfb4SJennifer Lee 
4230e7de46fSAndrew Geissler         std::shared_ptr<AsyncResp> asyncResp = std::make_shared<AsyncResp>(res);
424acb7cfb4SJennifer Lee 
42586adcd6dSAndrew Geissler         // Setup callback for when new software detected
42686adcd6dSAndrew Geissler         monitorForSoftwareAvailable(asyncResp, req);
427acb7cfb4SJennifer Lee 
428acb7cfb4SJennifer Lee         std::string filepath(
429acb7cfb4SJennifer Lee             "/tmp/images/" +
430acb7cfb4SJennifer Lee             boost::uuids::to_string(boost::uuids::random_generator()()));
431acb7cfb4SJennifer Lee         BMCWEB_LOG_DEBUG << "Writing file to " << filepath;
432acb7cfb4SJennifer Lee         std::ofstream out(filepath, std::ofstream::out | std::ofstream::binary |
433acb7cfb4SJennifer Lee                                         std::ofstream::trunc);
434acb7cfb4SJennifer Lee         out << req.body;
435acb7cfb4SJennifer Lee         out.close();
436acb7cfb4SJennifer Lee         BMCWEB_LOG_DEBUG << "file upload complete!!";
437acb7cfb4SJennifer Lee     }
438729dae72SJennifer Lee };
439729dae72SJennifer Lee 
4401abe55efSEd Tanous class SoftwareInventoryCollection : public Node
4411abe55efSEd Tanous {
442729dae72SJennifer Lee   public:
443729dae72SJennifer Lee     template <typename CrowApp>
4441abe55efSEd Tanous     SoftwareInventoryCollection(CrowApp &app) :
4451abe55efSEd Tanous         Node(app, "/redfish/v1/UpdateService/FirmwareInventory/")
4461abe55efSEd Tanous     {
447729dae72SJennifer Lee         entityPrivileges = {
448729dae72SJennifer Lee             {boost::beast::http::verb::get, {{"Login"}}},
449729dae72SJennifer Lee             {boost::beast::http::verb::head, {{"Login"}}},
450729dae72SJennifer Lee             {boost::beast::http::verb::patch, {{"ConfigureComponents"}}},
451729dae72SJennifer Lee             {boost::beast::http::verb::put, {{"ConfigureComponents"}}},
452729dae72SJennifer Lee             {boost::beast::http::verb::delete_, {{"ConfigureComponents"}}},
453729dae72SJennifer Lee             {boost::beast::http::verb::post, {{"ConfigureComponents"}}}};
454729dae72SJennifer Lee     }
455729dae72SJennifer Lee 
456729dae72SJennifer Lee   private:
45755c7b7a2SEd Tanous     void doGet(crow::Response &res, const crow::Request &req,
4581abe55efSEd Tanous                const std::vector<std::string> &params) override
4591abe55efSEd Tanous     {
460c711bf86SEd Tanous         std::shared_ptr<AsyncResp> asyncResp = std::make_shared<AsyncResp>(res);
4610f74e643SEd Tanous         res.jsonValue["@odata.type"] =
4620f74e643SEd Tanous             "#SoftwareInventoryCollection.SoftwareInventoryCollection";
4630f74e643SEd Tanous         res.jsonValue["@odata.id"] =
4640f74e643SEd Tanous             "/redfish/v1/UpdateService/FirmwareInventory";
4650f74e643SEd Tanous         res.jsonValue["@odata.context"] =
4660f74e643SEd Tanous             "/redfish/v1/"
4670f74e643SEd Tanous             "$metadata#SoftwareInventoryCollection.SoftwareInventoryCollection";
4680f74e643SEd Tanous         res.jsonValue["Name"] = "Software Inventory Collection";
469c711bf86SEd Tanous 
470c711bf86SEd Tanous         crow::connections::systemBus->async_method_call(
471c711bf86SEd Tanous             [asyncResp](
472c711bf86SEd Tanous                 const boost::system::error_code ec,
4736c4eb9deSJennifer Lee                 const std::vector<std::pair<
4741abe55efSEd Tanous                     std::string, std::vector<std::pair<
4751abe55efSEd Tanous                                      std::string, std::vector<std::string>>>>>
4766c4eb9deSJennifer Lee                     &subtree) {
4771abe55efSEd Tanous                 if (ec)
4781abe55efSEd Tanous                 {
479f12894f8SJason M. Bills                     messages::internalError(asyncResp->res);
4806c4eb9deSJennifer Lee                     return;
481729dae72SJennifer Lee                 }
482c711bf86SEd Tanous                 asyncResp->res.jsonValue["Members"] = nlohmann::json::array();
483c711bf86SEd Tanous                 asyncResp->res.jsonValue["Members@odata.count"] = 0;
4846c4eb9deSJennifer Lee 
4851abe55efSEd Tanous                 for (auto &obj : subtree)
4861abe55efSEd Tanous                 {
487f4b65ab1SJennifer Lee                     // if can't parse fw id then return
48827826b5fSEd Tanous                     std::size_t idPos;
48927826b5fSEd Tanous                     if ((idPos = obj.first.rfind("/")) == std::string::npos)
490f4b65ab1SJennifer Lee                     {
491f12894f8SJason M. Bills                         messages::internalError(asyncResp->res);
492f4b65ab1SJennifer Lee                         BMCWEB_LOG_DEBUG << "Can't parse firmware ID!!";
493f4b65ab1SJennifer Lee                         return;
494f4b65ab1SJennifer Lee                     }
495f4b65ab1SJennifer Lee                     std::string swId = obj.first.substr(idPos + 1);
496f4b65ab1SJennifer Lee 
497c711bf86SEd Tanous                     nlohmann::json &members =
498c711bf86SEd Tanous                         asyncResp->res.jsonValue["Members"];
499c711bf86SEd Tanous                     members.push_back(
500f4b65ab1SJennifer Lee                         {{"@odata.id", "/redfish/v1/UpdateService/"
5011abe55efSEd Tanous                                        "FirmwareInventory/" +
502f4b65ab1SJennifer Lee                                            swId}});
503e0dd8057SAndrew Geissler                     asyncResp->res.jsonValue["Members@odata.count"] =
504c711bf86SEd Tanous                         members.size();
5056c4eb9deSJennifer Lee                 }
506c711bf86SEd Tanous             },
507c711bf86SEd Tanous             "xyz.openbmc_project.ObjectMapper",
508c711bf86SEd Tanous             "/xyz/openbmc_project/object_mapper",
509*271584abSEd Tanous             "xyz.openbmc_project.ObjectMapper", "GetSubTree", "/",
510*271584abSEd Tanous             static_cast<int32_t>(0),
5111abe55efSEd Tanous             std::array<const char *, 1>{
5121abe55efSEd Tanous                 "xyz.openbmc_project.Software.Version"});
513729dae72SJennifer Lee     }
514729dae72SJennifer Lee };
515c711bf86SEd Tanous 
5161abe55efSEd Tanous class SoftwareInventory : public Node
5171abe55efSEd Tanous {
518729dae72SJennifer Lee   public:
519729dae72SJennifer Lee     template <typename CrowApp>
5201abe55efSEd Tanous     SoftwareInventory(CrowApp &app) :
5211abe55efSEd Tanous         Node(app, "/redfish/v1/UpdateService/FirmwareInventory/<str>/",
5221abe55efSEd Tanous              std::string())
5231abe55efSEd Tanous     {
524729dae72SJennifer Lee         entityPrivileges = {
525729dae72SJennifer Lee             {boost::beast::http::verb::get, {{"Login"}}},
526729dae72SJennifer Lee             {boost::beast::http::verb::head, {{"Login"}}},
527729dae72SJennifer Lee             {boost::beast::http::verb::patch, {{"ConfigureComponents"}}},
528729dae72SJennifer Lee             {boost::beast::http::verb::put, {{"ConfigureComponents"}}},
529729dae72SJennifer Lee             {boost::beast::http::verb::delete_, {{"ConfigureComponents"}}},
530729dae72SJennifer Lee             {boost::beast::http::verb::post, {{"ConfigureComponents"}}}};
531729dae72SJennifer Lee     }
532729dae72SJennifer Lee 
533729dae72SJennifer Lee   private:
53487d84729SAndrew Geissler     /* Fill related item links (i.e. bmc, bios) in for inventory */
53587d84729SAndrew Geissler     static void getRelatedItems(std::shared_ptr<AsyncResp> aResp,
53687d84729SAndrew Geissler                                 const std::string &purpose)
53787d84729SAndrew Geissler     {
53887d84729SAndrew Geissler         if (purpose == fw_util::bmcPurpose)
53987d84729SAndrew Geissler         {
54087d84729SAndrew Geissler             nlohmann::json &members = aResp->res.jsonValue["RelatedItem"];
54187d84729SAndrew Geissler             members.push_back({{"@odata.id", "/redfish/v1/Managers/bmc"}});
54287d84729SAndrew Geissler             aResp->res.jsonValue["Members@odata.count"] = members.size();
54387d84729SAndrew Geissler         }
54487d84729SAndrew Geissler         else if (purpose == fw_util::biosPurpose)
54587d84729SAndrew Geissler         {
54687d84729SAndrew Geissler             // TODO(geissonator) Need BIOS schema support added for this
54787d84729SAndrew Geissler             //                   to be valid
54887d84729SAndrew Geissler             // nlohmann::json &members = aResp->res.jsonValue["RelatedItem"];
54987d84729SAndrew Geissler             // members.push_back(
55087d84729SAndrew Geissler             //    {{"@odata.id", "/redfish/v1/Systems/system/BIOS"}});
55187d84729SAndrew Geissler             // aResp->res.jsonValue["Members@odata.count"] = members.size();
55287d84729SAndrew Geissler         }
55387d84729SAndrew Geissler         else
55487d84729SAndrew Geissler         {
55587d84729SAndrew Geissler             BMCWEB_LOG_ERROR << "Unknown software purpose " << purpose;
55687d84729SAndrew Geissler         }
55787d84729SAndrew Geissler     }
55887d84729SAndrew Geissler 
55955c7b7a2SEd Tanous     void doGet(crow::Response &res, const crow::Request &req,
5601abe55efSEd Tanous                const std::vector<std::string> &params) override
5611abe55efSEd Tanous     {
562c711bf86SEd Tanous         std::shared_ptr<AsyncResp> asyncResp = std::make_shared<AsyncResp>(res);
5636c4eb9deSJennifer Lee 
5641abe55efSEd Tanous         if (params.size() != 1)
5651abe55efSEd Tanous         {
566f12894f8SJason M. Bills             messages::internalError(res);
567729dae72SJennifer Lee             res.end();
568729dae72SJennifer Lee             return;
569729dae72SJennifer Lee         }
570729dae72SJennifer Lee 
5713ae837c9SEd Tanous         std::shared_ptr<std::string> swId =
572c711bf86SEd Tanous             std::make_shared<std::string>(params[0]);
573c711bf86SEd Tanous 
57455c7b7a2SEd Tanous         res.jsonValue["@odata.id"] =
5753ae837c9SEd Tanous             "/redfish/v1/UpdateService/FirmwareInventory/" + *swId;
576c711bf86SEd Tanous 
577c711bf86SEd Tanous         crow::connections::systemBus->async_method_call(
5783ae837c9SEd Tanous             [asyncResp, swId](
579c711bf86SEd Tanous                 const boost::system::error_code ec,
5806c4eb9deSJennifer Lee                 const std::vector<std::pair<
5811abe55efSEd Tanous                     std::string, std::vector<std::pair<
5821abe55efSEd Tanous                                      std::string, std::vector<std::string>>>>>
5836c4eb9deSJennifer Lee                     &subtree) {
58455c7b7a2SEd Tanous                 BMCWEB_LOG_DEBUG << "doGet callback...";
5851abe55efSEd Tanous                 if (ec)
5861abe55efSEd Tanous                 {
587f12894f8SJason M. Bills                     messages::internalError(asyncResp->res);
5886c4eb9deSJennifer Lee                     return;
5896c4eb9deSJennifer Lee                 }
5906c4eb9deSJennifer Lee 
5916913228dSAndrew Geissler                 // Ensure we find our input swId, otherwise return an error
5926913228dSAndrew Geissler                 bool found = false;
5931abe55efSEd Tanous                 for (const std::pair<
5941abe55efSEd Tanous                          std::string,
5951abe55efSEd Tanous                          std::vector<
5961abe55efSEd Tanous                              std::pair<std::string, std::vector<std::string>>>>
5971abe55efSEd Tanous                          &obj : subtree)
5981abe55efSEd Tanous                 {
5993ae837c9SEd Tanous                     if (boost::ends_with(obj.first, *swId) != true)
6001abe55efSEd Tanous                     {
601acb7cfb4SJennifer Lee                         continue;
602acb7cfb4SJennifer Lee                     }
603acb7cfb4SJennifer Lee 
604f4b65ab1SJennifer Lee                     if (obj.second.size() < 1)
6051abe55efSEd Tanous                     {
606acb7cfb4SJennifer Lee                         continue;
607acb7cfb4SJennifer Lee                     }
6086c4eb9deSJennifer Lee 
6096913228dSAndrew Geissler                     found = true;
610e0dd8057SAndrew Geissler                     fw_util::getFwStatus(asyncResp, swId, obj.second[0].first);
611e0dd8057SAndrew Geissler 
61255c7b7a2SEd Tanous                     crow::connections::systemBus->async_method_call(
6131abe55efSEd Tanous                         [asyncResp,
6143ae837c9SEd Tanous                          swId](const boost::system::error_code error_code,
6151abe55efSEd Tanous                                const boost::container::flat_map<
6161abe55efSEd Tanous                                    std::string, VariantType> &propertiesList) {
6171abe55efSEd Tanous                             if (error_code)
6181abe55efSEd Tanous                             {
619f12894f8SJason M. Bills                                 messages::internalError(asyncResp->res);
6206c4eb9deSJennifer Lee                                 return;
6216c4eb9deSJennifer Lee                             }
6221abe55efSEd Tanous                             boost::container::flat_map<
6231abe55efSEd Tanous                                 std::string, VariantType>::const_iterator it =
6246c4eb9deSJennifer Lee                                 propertiesList.find("Purpose");
6251abe55efSEd Tanous                             if (it == propertiesList.end())
6261abe55efSEd Tanous                             {
6271abe55efSEd Tanous                                 BMCWEB_LOG_DEBUG
6281abe55efSEd Tanous                                     << "Can't find property \"Purpose\"!";
629f12894f8SJason M. Bills                                 messages::propertyMissing(asyncResp->res,
630f12894f8SJason M. Bills                                                           "Purpose");
6316c4eb9deSJennifer Lee                                 return;
6326c4eb9deSJennifer Lee                             }
6333ae837c9SEd Tanous                             const std::string *swInvPurpose =
634abf2add6SEd Tanous                                 std::get_if<std::string>(&it->second);
6353ae837c9SEd Tanous                             if (swInvPurpose == nullptr)
6361abe55efSEd Tanous                             {
6371abe55efSEd Tanous                                 BMCWEB_LOG_DEBUG
6381abe55efSEd Tanous                                     << "wrong types for property\"Purpose\"!";
639f12894f8SJason M. Bills                                 messages::propertyValueTypeError(asyncResp->res,
640f12894f8SJason M. Bills                                                                  "", "Purpose");
641acb7cfb4SJennifer Lee                                 return;
642acb7cfb4SJennifer Lee                             }
643c711bf86SEd Tanous 
6443ae837c9SEd Tanous                             BMCWEB_LOG_DEBUG << "swInvPurpose = "
6453ae837c9SEd Tanous                                              << *swInvPurpose;
646c711bf86SEd Tanous                             it = propertiesList.find("Version");
6471abe55efSEd Tanous                             if (it == propertiesList.end())
6481abe55efSEd Tanous                             {
6491abe55efSEd Tanous                                 BMCWEB_LOG_DEBUG
6501abe55efSEd Tanous                                     << "Can't find property \"Version\"!";
651f12894f8SJason M. Bills                                 messages::propertyMissing(asyncResp->res,
652f12894f8SJason M. Bills                                                           "Version");
653c711bf86SEd Tanous                                 return;
654acb7cfb4SJennifer Lee                             }
655acb7cfb4SJennifer Lee 
656f4b65ab1SJennifer Lee                             BMCWEB_LOG_DEBUG << "Version found!";
657c711bf86SEd Tanous 
658f4b65ab1SJennifer Lee                             const std::string *version =
659abf2add6SEd Tanous                                 std::get_if<std::string>(&it->second);
660f4b65ab1SJennifer Lee 
661f4b65ab1SJennifer Lee                             if (version == nullptr)
6621abe55efSEd Tanous                             {
6631abe55efSEd Tanous                                 BMCWEB_LOG_DEBUG
6641abe55efSEd Tanous                                     << "Can't find property \"Version\"!";
665f12894f8SJason M. Bills 
666f12894f8SJason M. Bills                                 messages::propertyValueTypeError(asyncResp->res,
667f12894f8SJason M. Bills                                                                  "", "Version");
6686c4eb9deSJennifer Lee                                 return;
6696c4eb9deSJennifer Lee                             }
670c711bf86SEd Tanous                             asyncResp->res.jsonValue["Version"] = *version;
6713ae837c9SEd Tanous                             asyncResp->res.jsonValue["Id"] = *swId;
67254daabe7SAndrew Geissler 
67354daabe7SAndrew Geissler                             // swInvPurpose is of format:
67454daabe7SAndrew Geissler                             // xyz.openbmc_project.Software.Version.VersionPurpose.ABC
675e2e96770SJames Feist                             // Translate this to "ABC image"
67654daabe7SAndrew Geissler                             size_t endDesc = swInvPurpose->rfind(".");
67754daabe7SAndrew Geissler                             if (endDesc == std::string::npos)
67854daabe7SAndrew Geissler                             {
67954daabe7SAndrew Geissler                                 messages::internalError(asyncResp->res);
68054daabe7SAndrew Geissler                                 return;
68154daabe7SAndrew Geissler                             }
68254daabe7SAndrew Geissler                             endDesc++;
68354daabe7SAndrew Geissler                             if (endDesc >= swInvPurpose->size())
68454daabe7SAndrew Geissler                             {
68554daabe7SAndrew Geissler                                 messages::internalError(asyncResp->res);
68654daabe7SAndrew Geissler                                 return;
68754daabe7SAndrew Geissler                             }
68854daabe7SAndrew Geissler 
68954daabe7SAndrew Geissler                             std::string formatDesc =
69054daabe7SAndrew Geissler                                 swInvPurpose->substr(endDesc);
69154daabe7SAndrew Geissler                             asyncResp->res.jsonValue["Description"] =
692e2e96770SJames Feist                                 formatDesc + " image";
69387d84729SAndrew Geissler                             getRelatedItems(asyncResp, *swInvPurpose);
6946c4eb9deSJennifer Lee                         },
695c711bf86SEd Tanous                         obj.second[0].first, obj.first,
696c711bf86SEd Tanous                         "org.freedesktop.DBus.Properties", "GetAll",
697c711bf86SEd Tanous                         "xyz.openbmc_project.Software.Version");
6986c4eb9deSJennifer Lee                 }
6996913228dSAndrew Geissler                 if (!found)
7006913228dSAndrew Geissler                 {
7016913228dSAndrew Geissler                     BMCWEB_LOG_ERROR << "Input swID " + *swId + " not found!";
7026913228dSAndrew Geissler                     messages::resourceMissingAtURI(
7036913228dSAndrew Geissler                         asyncResp->res,
7046913228dSAndrew Geissler                         "/redfish/v1/UpdateService/FirmwareInventory/" + *swId);
7056913228dSAndrew Geissler                     return;
7066913228dSAndrew Geissler                 }
7074e68c45bSAyushi Smriti                 asyncResp->res.jsonValue["@odata.type"] =
7084e68c45bSAyushi Smriti                     "#SoftwareInventory.v1_1_0.SoftwareInventory";
7094e68c45bSAyushi Smriti                 asyncResp->res.jsonValue["@odata.context"] =
7104e68c45bSAyushi Smriti                     "/redfish/v1/$metadata#SoftwareInventory.SoftwareInventory";
7114e68c45bSAyushi Smriti                 asyncResp->res.jsonValue["Name"] = "Software Inventory";
7124e68c45bSAyushi Smriti                 asyncResp->res.jsonValue["Updateable"] = false;
7134e68c45bSAyushi Smriti                 asyncResp->res.jsonValue["Status"]["Health"] = "OK";
7144e68c45bSAyushi Smriti                 asyncResp->res.jsonValue["Status"]["HealthRollup"] = "OK";
715c711bf86SEd Tanous             },
716c711bf86SEd Tanous             "xyz.openbmc_project.ObjectMapper",
717c711bf86SEd Tanous             "/xyz/openbmc_project/object_mapper",
718*271584abSEd Tanous             "xyz.openbmc_project.ObjectMapper", "GetSubTree", "/",
719*271584abSEd Tanous             static_cast<int32_t>(0),
7201abe55efSEd Tanous             std::array<const char *, 1>{
7211abe55efSEd Tanous                 "xyz.openbmc_project.Software.Version"});
7226c4eb9deSJennifer Lee     }
723729dae72SJennifer Lee };
724729dae72SJennifer Lee 
725729dae72SJennifer Lee } // namespace redfish
726