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> 21729dae72SJennifer Lee 221abe55efSEd Tanous namespace redfish 231abe55efSEd Tanous { 2427826b5fSEd Tanous 25acb7cfb4SJennifer Lee static std::unique_ptr<sdbusplus::bus::match::match> fwUpdateMatcher; 26729dae72SJennifer Lee 271abe55efSEd Tanous class UpdateService : public Node 281abe55efSEd Tanous { 29729dae72SJennifer Lee public: 301abe55efSEd Tanous UpdateService(CrowApp &app) : Node(app, "/redfish/v1/UpdateService/") 311abe55efSEd Tanous { 32729dae72SJennifer Lee entityPrivileges = { 33729dae72SJennifer Lee {boost::beast::http::verb::get, {{"Login"}}}, 34729dae72SJennifer Lee {boost::beast::http::verb::head, {{"Login"}}}, 35729dae72SJennifer Lee {boost::beast::http::verb::patch, {{"ConfigureComponents"}}}, 36729dae72SJennifer Lee {boost::beast::http::verb::put, {{"ConfigureComponents"}}}, 37729dae72SJennifer Lee {boost::beast::http::verb::delete_, {{"ConfigureComponents"}}}, 38729dae72SJennifer Lee {boost::beast::http::verb::post, {{"ConfigureComponents"}}}}; 39729dae72SJennifer Lee } 40729dae72SJennifer Lee 41729dae72SJennifer Lee private: 4255c7b7a2SEd Tanous void doGet(crow::Response &res, const crow::Request &req, 431abe55efSEd Tanous const std::vector<std::string> ¶ms) override 441abe55efSEd Tanous { 45*0f74e643SEd Tanous res.jsonValue["@odata.type"] = "#UpdateService.v1_2_0.UpdateService"; 46*0f74e643SEd Tanous res.jsonValue["@odata.id"] = "/redfish/v1/UpdateService"; 47*0f74e643SEd Tanous res.jsonValue["@odata.context"] = 48*0f74e643SEd Tanous "/redfish/v1/$metadata#UpdateService.UpdateService"; 49*0f74e643SEd Tanous res.jsonValue["Id"] = "UpdateService"; 50*0f74e643SEd Tanous res.jsonValue["Description"] = "Service for Software Update"; 51*0f74e643SEd Tanous res.jsonValue["Name"] = "Update Service"; 52*0f74e643SEd Tanous res.jsonValue["HttpPushUri"] = "/redfish/v1/UpdateService"; 53*0f74e643SEd Tanous // UpdateService cannot be disabled 54*0f74e643SEd Tanous res.jsonValue["ServiceEnabled"] = true; 55*0f74e643SEd Tanous res.jsonValue["FirmwareInventory"] = { 56*0f74e643SEd Tanous {"@odata.id", "/redfish/v1/UpdateService/FirmwareInventory"}}; 57729dae72SJennifer Lee res.end(); 58729dae72SJennifer Lee } 591abe55efSEd Tanous static void activateImage(const std::string &objPath) 601abe55efSEd Tanous { 61acb7cfb4SJennifer Lee crow::connections::systemBus->async_method_call( 62c711bf86SEd Tanous [objPath](const boost::system::error_code error_code) { 631abe55efSEd Tanous if (error_code) 641abe55efSEd Tanous { 65acb7cfb4SJennifer Lee BMCWEB_LOG_DEBUG << "error_code = " << error_code; 66acb7cfb4SJennifer Lee BMCWEB_LOG_DEBUG << "error msg = " << error_code.message(); 67acb7cfb4SJennifer Lee } 68acb7cfb4SJennifer Lee }, 69c711bf86SEd Tanous "xyz.openbmc_project.Software.BMC.Updater", objPath, 70acb7cfb4SJennifer Lee "org.freedesktop.DBus.Properties", "Set", 71acb7cfb4SJennifer Lee "xyz.openbmc_project.Software.Activation", "RequestedActivation", 72acb7cfb4SJennifer Lee sdbusplus::message::variant<std::string>( 73acb7cfb4SJennifer Lee "xyz.openbmc_project.Software.Activation.RequestedActivations." 74acb7cfb4SJennifer Lee "Active")); 75acb7cfb4SJennifer Lee } 76acb7cfb4SJennifer Lee void doPost(crow::Response &res, const crow::Request &req, 771abe55efSEd Tanous const std::vector<std::string> ¶ms) override 781abe55efSEd Tanous { 79acb7cfb4SJennifer Lee BMCWEB_LOG_DEBUG << "doPost..."; 80acb7cfb4SJennifer Lee 81acb7cfb4SJennifer Lee // Only allow one FW update at a time 821abe55efSEd Tanous if (fwUpdateMatcher != nullptr) 831abe55efSEd Tanous { 84acb7cfb4SJennifer Lee res.addHeader("Retry-After", "30"); 85f12894f8SJason M. Bills messages::serviceTemporarilyUnavailable(res, "3"); 86acb7cfb4SJennifer Lee res.end(); 87acb7cfb4SJennifer Lee return; 88acb7cfb4SJennifer Lee } 89acb7cfb4SJennifer Lee // Make this const static so it survives outside this method 901abe55efSEd Tanous static boost::asio::deadline_timer timeout( 911abe55efSEd Tanous *req.ioService, boost::posix_time::seconds(5)); 92acb7cfb4SJennifer Lee 93acb7cfb4SJennifer Lee timeout.expires_from_now(boost::posix_time::seconds(5)); 94acb7cfb4SJennifer Lee 95acb7cfb4SJennifer Lee timeout.async_wait([&res](const boost::system::error_code &ec) { 96acb7cfb4SJennifer Lee fwUpdateMatcher = nullptr; 971abe55efSEd Tanous if (ec == boost::asio::error::operation_aborted) 981abe55efSEd Tanous { 99acb7cfb4SJennifer Lee // expected, we were canceled before the timer completed. 100acb7cfb4SJennifer Lee return; 101acb7cfb4SJennifer Lee } 1021abe55efSEd Tanous BMCWEB_LOG_ERROR 1031abe55efSEd Tanous << "Timed out waiting for firmware object being created"; 1041abe55efSEd Tanous BMCWEB_LOG_ERROR 1051abe55efSEd Tanous << "FW image may has already been uploaded to server"; 1061abe55efSEd Tanous if (ec) 1071abe55efSEd Tanous { 108acb7cfb4SJennifer Lee BMCWEB_LOG_ERROR << "Async_wait failed" << ec; 109acb7cfb4SJennifer Lee return; 110acb7cfb4SJennifer Lee } 111acb7cfb4SJennifer Lee 112f12894f8SJason M. Bills redfish::messages::internalError(res); 113acb7cfb4SJennifer Lee res.end(); 114acb7cfb4SJennifer Lee }); 115acb7cfb4SJennifer Lee 116acb7cfb4SJennifer Lee auto callback = [&res](sdbusplus::message::message &m) { 117acb7cfb4SJennifer Lee BMCWEB_LOG_DEBUG << "Match fired"; 118acb7cfb4SJennifer Lee bool flag = false; 119acb7cfb4SJennifer Lee 1201abe55efSEd Tanous if (m.is_method_error()) 1211abe55efSEd Tanous { 122acb7cfb4SJennifer Lee BMCWEB_LOG_DEBUG << "Dbus method error!!!"; 123acb7cfb4SJennifer Lee res.end(); 124acb7cfb4SJennifer Lee return; 125acb7cfb4SJennifer Lee } 126acb7cfb4SJennifer Lee std::vector<std::pair< 127acb7cfb4SJennifer Lee std::string, 1281abe55efSEd Tanous std::vector<std::pair< 1291abe55efSEd Tanous std::string, sdbusplus::message::variant<std::string>>>>> 1303ae837c9SEd Tanous interfacesProperties; 131acb7cfb4SJennifer Lee 132c711bf86SEd Tanous sdbusplus::message::object_path objPath; 133acb7cfb4SJennifer Lee 1343ae837c9SEd Tanous m.read(objPath, interfacesProperties); // Read in the object path 135acb7cfb4SJennifer Lee // that was just created 136c711bf86SEd Tanous // std::string str_objpath = objPath.str; // keep a copy for 137acb7cfb4SJennifer Lee // constructing response message 138c711bf86SEd Tanous BMCWEB_LOG_DEBUG << "obj path = " << objPath.str; // str_objpath; 1393ae837c9SEd Tanous for (auto &interface : interfacesProperties) 1401abe55efSEd Tanous { 141acb7cfb4SJennifer Lee BMCWEB_LOG_DEBUG << "interface = " << interface.first; 142acb7cfb4SJennifer Lee 1431abe55efSEd Tanous if (interface.first == 1441abe55efSEd Tanous "xyz.openbmc_project.Software.Activation") 1451abe55efSEd Tanous { 1461abe55efSEd Tanous // cancel timer only when 1471abe55efSEd Tanous // xyz.openbmc_project.Software.Activation interface is 1481abe55efSEd Tanous // added 149acb7cfb4SJennifer Lee boost::system::error_code ec; 150acb7cfb4SJennifer Lee timeout.cancel(ec); 1511abe55efSEd Tanous if (ec) 1521abe55efSEd Tanous { 153acb7cfb4SJennifer Lee BMCWEB_LOG_ERROR << "error canceling timer " << ec; 154acb7cfb4SJennifer Lee } 155c711bf86SEd Tanous UpdateService::activateImage(objPath.str); // str_objpath); 156f12894f8SJason M. Bills redfish::messages::success(res); 157acb7cfb4SJennifer Lee BMCWEB_LOG_DEBUG << "ending response"; 158acb7cfb4SJennifer Lee res.end(); 159acb7cfb4SJennifer Lee fwUpdateMatcher = nullptr; 160acb7cfb4SJennifer Lee } 161acb7cfb4SJennifer Lee } 162acb7cfb4SJennifer Lee }; 163acb7cfb4SJennifer Lee 164acb7cfb4SJennifer Lee fwUpdateMatcher = std::make_unique<sdbusplus::bus::match::match>( 165acb7cfb4SJennifer Lee *crow::connections::systemBus, 166acb7cfb4SJennifer Lee "interface='org.freedesktop.DBus.ObjectManager',type='signal'," 167acb7cfb4SJennifer Lee "member='InterfacesAdded',path='/xyz/openbmc_project/software'", 168acb7cfb4SJennifer Lee callback); 169acb7cfb4SJennifer Lee 170acb7cfb4SJennifer Lee std::string filepath( 171acb7cfb4SJennifer Lee "/tmp/images/" + 172acb7cfb4SJennifer Lee boost::uuids::to_string(boost::uuids::random_generator()())); 173acb7cfb4SJennifer Lee BMCWEB_LOG_DEBUG << "Writing file to " << filepath; 174acb7cfb4SJennifer Lee std::ofstream out(filepath, std::ofstream::out | std::ofstream::binary | 175acb7cfb4SJennifer Lee std::ofstream::trunc); 176acb7cfb4SJennifer Lee out << req.body; 177acb7cfb4SJennifer Lee out.close(); 178acb7cfb4SJennifer Lee BMCWEB_LOG_DEBUG << "file upload complete!!"; 179acb7cfb4SJennifer Lee } 180729dae72SJennifer Lee }; 181729dae72SJennifer Lee 1821abe55efSEd Tanous class SoftwareInventoryCollection : public Node 1831abe55efSEd Tanous { 184729dae72SJennifer Lee public: 185729dae72SJennifer Lee template <typename CrowApp> 1861abe55efSEd Tanous SoftwareInventoryCollection(CrowApp &app) : 1871abe55efSEd Tanous Node(app, "/redfish/v1/UpdateService/FirmwareInventory/") 1881abe55efSEd Tanous { 189729dae72SJennifer Lee entityPrivileges = { 190729dae72SJennifer Lee {boost::beast::http::verb::get, {{"Login"}}}, 191729dae72SJennifer Lee {boost::beast::http::verb::head, {{"Login"}}}, 192729dae72SJennifer Lee {boost::beast::http::verb::patch, {{"ConfigureComponents"}}}, 193729dae72SJennifer Lee {boost::beast::http::verb::put, {{"ConfigureComponents"}}}, 194729dae72SJennifer Lee {boost::beast::http::verb::delete_, {{"ConfigureComponents"}}}, 195729dae72SJennifer Lee {boost::beast::http::verb::post, {{"ConfigureComponents"}}}}; 196729dae72SJennifer Lee } 197729dae72SJennifer Lee 198729dae72SJennifer Lee private: 19955c7b7a2SEd Tanous void doGet(crow::Response &res, const crow::Request &req, 2001abe55efSEd Tanous const std::vector<std::string> ¶ms) override 2011abe55efSEd Tanous { 202c711bf86SEd Tanous std::shared_ptr<AsyncResp> asyncResp = std::make_shared<AsyncResp>(res); 203*0f74e643SEd Tanous res.jsonValue["@odata.type"] = 204*0f74e643SEd Tanous "#SoftwareInventoryCollection.SoftwareInventoryCollection"; 205*0f74e643SEd Tanous res.jsonValue["@odata.id"] = 206*0f74e643SEd Tanous "/redfish/v1/UpdateService/FirmwareInventory"; 207*0f74e643SEd Tanous res.jsonValue["@odata.context"] = 208*0f74e643SEd Tanous "/redfish/v1/" 209*0f74e643SEd Tanous "$metadata#SoftwareInventoryCollection.SoftwareInventoryCollection"; 210*0f74e643SEd Tanous res.jsonValue["Name"] = "Software Inventory Collection"; 211c711bf86SEd Tanous 212c711bf86SEd Tanous crow::connections::systemBus->async_method_call( 213c711bf86SEd Tanous [asyncResp]( 214c711bf86SEd Tanous const boost::system::error_code ec, 2156c4eb9deSJennifer Lee const std::vector<std::pair< 2161abe55efSEd Tanous std::string, std::vector<std::pair< 2171abe55efSEd Tanous std::string, std::vector<std::string>>>>> 2186c4eb9deSJennifer Lee &subtree) { 2191abe55efSEd Tanous if (ec) 2201abe55efSEd Tanous { 221f12894f8SJason M. Bills messages::internalError(asyncResp->res); 2226c4eb9deSJennifer Lee return; 223729dae72SJennifer Lee } 224c711bf86SEd Tanous asyncResp->res.jsonValue["Members"] = nlohmann::json::array(); 225c711bf86SEd Tanous asyncResp->res.jsonValue["Members@odata.count"] = 0; 2266c4eb9deSJennifer Lee 2271abe55efSEd Tanous for (auto &obj : subtree) 2281abe55efSEd Tanous { 2291abe55efSEd Tanous const std::vector< 2301abe55efSEd Tanous std::pair<std::string, std::vector<std::string>>> 2316c4eb9deSJennifer Lee &connections = obj.second; 2326c4eb9deSJennifer Lee 233f4b65ab1SJennifer Lee // if can't parse fw id then return 23427826b5fSEd Tanous std::size_t idPos; 23527826b5fSEd Tanous if ((idPos = obj.first.rfind("/")) == std::string::npos) 236f4b65ab1SJennifer Lee { 237f12894f8SJason M. Bills messages::internalError(asyncResp->res); 238f4b65ab1SJennifer Lee BMCWEB_LOG_DEBUG << "Can't parse firmware ID!!"; 239f4b65ab1SJennifer Lee return; 240f4b65ab1SJennifer Lee } 241f4b65ab1SJennifer Lee std::string swId = obj.first.substr(idPos + 1); 242f4b65ab1SJennifer Lee 2431abe55efSEd Tanous for (auto &conn : connections) 2441abe55efSEd Tanous { 245c711bf86SEd Tanous const std::string &connectionName = conn.first; 2461abe55efSEd Tanous BMCWEB_LOG_DEBUG << "connectionName = " 2471abe55efSEd Tanous << connectionName; 24855c7b7a2SEd Tanous BMCWEB_LOG_DEBUG << "obj.first = " << obj.first; 2496c4eb9deSJennifer Lee 25055c7b7a2SEd Tanous crow::connections::systemBus->async_method_call( 251f4b65ab1SJennifer Lee [asyncResp, 252f4b65ab1SJennifer Lee swId](const boost::system::error_code error_code, 253c711bf86SEd Tanous const VariantType &activation) { 2541abe55efSEd Tanous BMCWEB_LOG_DEBUG 2551abe55efSEd Tanous << "safe returned in lambda function"; 2561abe55efSEd Tanous if (error_code) 2571abe55efSEd Tanous { 258f12894f8SJason M. Bills messages::internalError(asyncResp->res); 2596c4eb9deSJennifer Lee return; 2606c4eb9deSJennifer Lee } 261c711bf86SEd Tanous 262f4b65ab1SJennifer Lee const std::string *swActivationStatus = 2631abe55efSEd Tanous mapbox::getPtr<const std::string>( 2641abe55efSEd Tanous activation); 265f4b65ab1SJennifer Lee if (swActivationStatus == nullptr) 2661abe55efSEd Tanous { 267f12894f8SJason M. Bills messages::internalError(asyncResp->res); 268acb7cfb4SJennifer Lee return; 269acb7cfb4SJennifer Lee } 270f4b65ab1SJennifer Lee if (swActivationStatus != nullptr && 271f4b65ab1SJennifer Lee *swActivationStatus != 272f4b65ab1SJennifer Lee "xyz.openbmc_project.Software." 273f4b65ab1SJennifer Lee "Activation." 274f4b65ab1SJennifer Lee "Activations.Active") 2751abe55efSEd Tanous { 276f4b65ab1SJennifer Lee // The activation status of this software is 277f4b65ab1SJennifer Lee // not currently active, so does not need to 278f4b65ab1SJennifer Lee // be listed in the response 279c711bf86SEd Tanous return; 280c711bf86SEd Tanous } 281c711bf86SEd Tanous nlohmann::json &members = 282c711bf86SEd Tanous asyncResp->res.jsonValue["Members"]; 283c711bf86SEd Tanous members.push_back( 284f4b65ab1SJennifer Lee {{"@odata.id", "/redfish/v1/UpdateService/" 2851abe55efSEd Tanous "FirmwareInventory/" + 286f4b65ab1SJennifer Lee swId}}); 2871abe55efSEd Tanous asyncResp->res 2881abe55efSEd Tanous .jsonValue["Members@odata.count"] = 289c711bf86SEd Tanous members.size(); 2906c4eb9deSJennifer Lee }, 2911abe55efSEd Tanous connectionName, obj.first, 2921abe55efSEd Tanous "org.freedesktop.DBus.Properties", "Get", 2931abe55efSEd Tanous "xyz.openbmc_project.Software.Activation", 294acb7cfb4SJennifer Lee "Activation"); 2956c4eb9deSJennifer Lee } 2966c4eb9deSJennifer Lee } 297c711bf86SEd Tanous }, 298c711bf86SEd Tanous "xyz.openbmc_project.ObjectMapper", 299c711bf86SEd Tanous "/xyz/openbmc_project/object_mapper", 300c711bf86SEd Tanous "xyz.openbmc_project.ObjectMapper", "GetSubTree", 301c711bf86SEd Tanous "/xyz/openbmc_project/software", int32_t(1), 3021abe55efSEd Tanous std::array<const char *, 1>{ 3031abe55efSEd Tanous "xyz.openbmc_project.Software.Version"}); 304729dae72SJennifer Lee } 305729dae72SJennifer Lee }; 306c711bf86SEd Tanous 3071abe55efSEd Tanous class SoftwareInventory : public Node 3081abe55efSEd Tanous { 309729dae72SJennifer Lee public: 310729dae72SJennifer Lee template <typename CrowApp> 3111abe55efSEd Tanous SoftwareInventory(CrowApp &app) : 3121abe55efSEd Tanous Node(app, "/redfish/v1/UpdateService/FirmwareInventory/<str>/", 3131abe55efSEd Tanous std::string()) 3141abe55efSEd Tanous { 315729dae72SJennifer Lee entityPrivileges = { 316729dae72SJennifer Lee {boost::beast::http::verb::get, {{"Login"}}}, 317729dae72SJennifer Lee {boost::beast::http::verb::head, {{"Login"}}}, 318729dae72SJennifer Lee {boost::beast::http::verb::patch, {{"ConfigureComponents"}}}, 319729dae72SJennifer Lee {boost::beast::http::verb::put, {{"ConfigureComponents"}}}, 320729dae72SJennifer Lee {boost::beast::http::verb::delete_, {{"ConfigureComponents"}}}, 321729dae72SJennifer Lee {boost::beast::http::verb::post, {{"ConfigureComponents"}}}}; 322729dae72SJennifer Lee } 323729dae72SJennifer Lee 324729dae72SJennifer Lee private: 32555c7b7a2SEd Tanous void doGet(crow::Response &res, const crow::Request &req, 3261abe55efSEd Tanous const std::vector<std::string> ¶ms) override 3271abe55efSEd Tanous { 328c711bf86SEd Tanous std::shared_ptr<AsyncResp> asyncResp = std::make_shared<AsyncResp>(res); 329*0f74e643SEd Tanous res.jsonValue["@odata.type"] = 330*0f74e643SEd Tanous "#SoftwareInventory.v1_1_0.SoftwareInventory"; 331*0f74e643SEd Tanous res.jsonValue["@odata.context"] = 332*0f74e643SEd Tanous "/redfish/v1/$metadata#SoftwareInventory.SoftwareInventory"; 333*0f74e643SEd Tanous res.jsonValue["Name"] = "Software Inventory"; 334*0f74e643SEd Tanous res.jsonValue["Updateable"] = false; 335*0f74e643SEd Tanous res.jsonValue["Status"]["Health"] = "OK"; 336*0f74e643SEd Tanous res.jsonValue["Status"]["HealthRollup"] = "OK"; 337*0f74e643SEd Tanous res.jsonValue["Status"]["State"] = "Enabled"; 3386c4eb9deSJennifer Lee 3391abe55efSEd Tanous if (params.size() != 1) 3401abe55efSEd Tanous { 341f12894f8SJason M. Bills messages::internalError(res); 342729dae72SJennifer Lee res.end(); 343729dae72SJennifer Lee return; 344729dae72SJennifer Lee } 345729dae72SJennifer Lee 3463ae837c9SEd Tanous std::shared_ptr<std::string> swId = 347c711bf86SEd Tanous std::make_shared<std::string>(params[0]); 348c711bf86SEd Tanous 34955c7b7a2SEd Tanous res.jsonValue["@odata.id"] = 3503ae837c9SEd Tanous "/redfish/v1/UpdateService/FirmwareInventory/" + *swId; 351c711bf86SEd Tanous 352c711bf86SEd Tanous crow::connections::systemBus->async_method_call( 3533ae837c9SEd Tanous [asyncResp, swId]( 354c711bf86SEd Tanous const boost::system::error_code ec, 3556c4eb9deSJennifer Lee const std::vector<std::pair< 3561abe55efSEd Tanous std::string, std::vector<std::pair< 3571abe55efSEd Tanous std::string, std::vector<std::string>>>>> 3586c4eb9deSJennifer Lee &subtree) { 35955c7b7a2SEd Tanous BMCWEB_LOG_DEBUG << "doGet callback..."; 3601abe55efSEd Tanous if (ec) 3611abe55efSEd Tanous { 362f12894f8SJason M. Bills messages::internalError(asyncResp->res); 3636c4eb9deSJennifer Lee return; 3646c4eb9deSJennifer Lee } 3656c4eb9deSJennifer Lee 3661abe55efSEd Tanous for (const std::pair< 3671abe55efSEd Tanous std::string, 3681abe55efSEd Tanous std::vector< 3691abe55efSEd Tanous std::pair<std::string, std::vector<std::string>>>> 3701abe55efSEd Tanous &obj : subtree) 3711abe55efSEd Tanous { 3723ae837c9SEd Tanous if (boost::ends_with(obj.first, *swId) != true) 3731abe55efSEd Tanous { 374acb7cfb4SJennifer Lee continue; 375acb7cfb4SJennifer Lee } 376acb7cfb4SJennifer Lee 377f4b65ab1SJennifer Lee if (obj.second.size() < 1) 3781abe55efSEd Tanous { 379acb7cfb4SJennifer Lee continue; 380acb7cfb4SJennifer Lee } 3816c4eb9deSJennifer Lee 38255c7b7a2SEd Tanous crow::connections::systemBus->async_method_call( 3831abe55efSEd Tanous [asyncResp, 3843ae837c9SEd Tanous swId](const boost::system::error_code error_code, 3851abe55efSEd Tanous const boost::container::flat_map< 3861abe55efSEd Tanous std::string, VariantType> &propertiesList) { 3871abe55efSEd Tanous if (error_code) 3881abe55efSEd Tanous { 389f12894f8SJason M. Bills messages::internalError(asyncResp->res); 3906c4eb9deSJennifer Lee return; 3916c4eb9deSJennifer Lee } 3921abe55efSEd Tanous boost::container::flat_map< 3931abe55efSEd Tanous std::string, VariantType>::const_iterator it = 3946c4eb9deSJennifer Lee propertiesList.find("Purpose"); 3951abe55efSEd Tanous if (it == propertiesList.end()) 3961abe55efSEd Tanous { 3971abe55efSEd Tanous BMCWEB_LOG_DEBUG 3981abe55efSEd Tanous << "Can't find property \"Purpose\"!"; 399f12894f8SJason M. Bills messages::propertyMissing(asyncResp->res, 400f12894f8SJason M. Bills "Purpose"); 4016c4eb9deSJennifer Lee return; 4026c4eb9deSJennifer Lee } 4033ae837c9SEd Tanous const std::string *swInvPurpose = 404acb7cfb4SJennifer Lee mapbox::getPtr<const std::string>(it->second); 4053ae837c9SEd Tanous if (swInvPurpose == nullptr) 4061abe55efSEd Tanous { 4071abe55efSEd Tanous BMCWEB_LOG_DEBUG 4081abe55efSEd Tanous << "wrong types for property\"Purpose\"!"; 409f12894f8SJason M. Bills messages::propertyValueTypeError(asyncResp->res, 410f12894f8SJason M. Bills "", "Purpose"); 411acb7cfb4SJennifer Lee return; 412acb7cfb4SJennifer Lee } 413c711bf86SEd Tanous 4143ae837c9SEd Tanous BMCWEB_LOG_DEBUG << "swInvPurpose = " 4153ae837c9SEd Tanous << *swInvPurpose; 416c711bf86SEd Tanous it = propertiesList.find("Version"); 4171abe55efSEd Tanous if (it == propertiesList.end()) 4181abe55efSEd Tanous { 4191abe55efSEd Tanous BMCWEB_LOG_DEBUG 4201abe55efSEd Tanous << "Can't find property \"Version\"!"; 421f12894f8SJason M. Bills messages::propertyMissing(asyncResp->res, 422f12894f8SJason M. Bills "Version"); 423c711bf86SEd Tanous return; 424acb7cfb4SJennifer Lee } 425acb7cfb4SJennifer Lee 426f4b65ab1SJennifer Lee BMCWEB_LOG_DEBUG << "Version found!"; 427c711bf86SEd Tanous 428f4b65ab1SJennifer Lee const std::string *version = 429f4b65ab1SJennifer Lee mapbox::getPtr<const std::string>(it->second); 430f4b65ab1SJennifer Lee 431f4b65ab1SJennifer Lee if (version == nullptr) 4321abe55efSEd Tanous { 4331abe55efSEd Tanous BMCWEB_LOG_DEBUG 4341abe55efSEd Tanous << "Can't find property \"Version\"!"; 435f12894f8SJason M. Bills 436f12894f8SJason M. Bills messages::propertyValueTypeError(asyncResp->res, 437f12894f8SJason M. Bills "", "Version"); 4386c4eb9deSJennifer Lee return; 4396c4eb9deSJennifer Lee } 440c711bf86SEd Tanous asyncResp->res.jsonValue["Version"] = *version; 4413ae837c9SEd Tanous asyncResp->res.jsonValue["Id"] = *swId; 4426c4eb9deSJennifer Lee }, 443c711bf86SEd Tanous obj.second[0].first, obj.first, 444c711bf86SEd Tanous "org.freedesktop.DBus.Properties", "GetAll", 445c711bf86SEd Tanous "xyz.openbmc_project.Software.Version"); 4466c4eb9deSJennifer Lee } 447c711bf86SEd Tanous }, 448c711bf86SEd Tanous "xyz.openbmc_project.ObjectMapper", 449c711bf86SEd Tanous "/xyz/openbmc_project/object_mapper", 450c711bf86SEd Tanous "xyz.openbmc_project.ObjectMapper", "GetSubTree", 451c711bf86SEd Tanous "/xyz/openbmc_project/software", int32_t(1), 4521abe55efSEd Tanous std::array<const char *, 1>{ 4531abe55efSEd Tanous "xyz.openbmc_project.Software.Version"}); 4546c4eb9deSJennifer Lee } 455729dae72SJennifer Lee }; 456729dae72SJennifer Lee 457729dae72SJennifer Lee } // namespace redfish 458