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 { 24acb7cfb4SJennifer Lee static std::unique_ptr<sdbusplus::bus::match::match> fwUpdateMatcher; 25729dae72SJennifer Lee 261abe55efSEd Tanous class UpdateService : public Node 271abe55efSEd Tanous { 28729dae72SJennifer Lee public: 291abe55efSEd Tanous UpdateService(CrowApp &app) : Node(app, "/redfish/v1/UpdateService/") 301abe55efSEd Tanous { 31729dae72SJennifer Lee Node::json["@odata.type"] = "#UpdateService.v1_2_0.UpdateService"; 32729dae72SJennifer Lee Node::json["@odata.id"] = "/redfish/v1/UpdateService"; 33729dae72SJennifer Lee Node::json["@odata.context"] = 34729dae72SJennifer Lee "/redfish/v1/$metadata#UpdateService.UpdateService"; 35729dae72SJennifer Lee Node::json["Id"] = "UpdateService"; 36729dae72SJennifer Lee Node::json["Description"] = "Service for Software Update"; 37729dae72SJennifer Lee Node::json["Name"] = "Update Service"; 38acb7cfb4SJennifer Lee Node::json["HttpPushUri"] = "/redfish/v1/UpdateService"; 39c711bf86SEd Tanous // UpdateService cannot be disabled 40c711bf86SEd Tanous Node::json["ServiceEnabled"] = true; 416c4eb9deSJennifer Lee Node::json["FirmwareInventory"] = { 426c4eb9deSJennifer Lee {"@odata.id", "/redfish/v1/UpdateService/FirmwareInventory"}}; 43729dae72SJennifer Lee 44729dae72SJennifer Lee entityPrivileges = { 45729dae72SJennifer Lee {boost::beast::http::verb::get, {{"Login"}}}, 46729dae72SJennifer Lee {boost::beast::http::verb::head, {{"Login"}}}, 47729dae72SJennifer Lee {boost::beast::http::verb::patch, {{"ConfigureComponents"}}}, 48729dae72SJennifer Lee {boost::beast::http::verb::put, {{"ConfigureComponents"}}}, 49729dae72SJennifer Lee {boost::beast::http::verb::delete_, {{"ConfigureComponents"}}}, 50729dae72SJennifer Lee {boost::beast::http::verb::post, {{"ConfigureComponents"}}}}; 51729dae72SJennifer Lee } 52729dae72SJennifer Lee 53729dae72SJennifer Lee private: 5455c7b7a2SEd Tanous void doGet(crow::Response &res, const crow::Request &req, 551abe55efSEd Tanous const std::vector<std::string> ¶ms) override 561abe55efSEd Tanous { 5755c7b7a2SEd Tanous res.jsonValue = Node::json; 58729dae72SJennifer Lee res.end(); 59729dae72SJennifer Lee } 601abe55efSEd Tanous static void activateImage(const std::string &objPath) 611abe55efSEd Tanous { 62acb7cfb4SJennifer Lee crow::connections::systemBus->async_method_call( 63c711bf86SEd Tanous [objPath](const boost::system::error_code error_code) { 641abe55efSEd Tanous if (error_code) 651abe55efSEd Tanous { 66acb7cfb4SJennifer Lee BMCWEB_LOG_DEBUG << "error_code = " << error_code; 67acb7cfb4SJennifer Lee BMCWEB_LOG_DEBUG << "error msg = " << error_code.message(); 68acb7cfb4SJennifer Lee } 69acb7cfb4SJennifer Lee }, 70c711bf86SEd Tanous "xyz.openbmc_project.Software.BMC.Updater", objPath, 71acb7cfb4SJennifer Lee "org.freedesktop.DBus.Properties", "Set", 72acb7cfb4SJennifer Lee "xyz.openbmc_project.Software.Activation", "RequestedActivation", 73acb7cfb4SJennifer Lee sdbusplus::message::variant<std::string>( 74acb7cfb4SJennifer Lee "xyz.openbmc_project.Software.Activation.RequestedActivations." 75acb7cfb4SJennifer Lee "Active")); 76acb7cfb4SJennifer Lee } 77acb7cfb4SJennifer Lee void doPost(crow::Response &res, const crow::Request &req, 781abe55efSEd Tanous const std::vector<std::string> ¶ms) override 791abe55efSEd Tanous { 80acb7cfb4SJennifer Lee BMCWEB_LOG_DEBUG << "doPost..."; 81acb7cfb4SJennifer Lee 82acb7cfb4SJennifer Lee // Only allow one FW update at a time 831abe55efSEd Tanous if (fwUpdateMatcher != nullptr) 841abe55efSEd Tanous { 85acb7cfb4SJennifer Lee res.addHeader("Retry-After", "30"); 86acb7cfb4SJennifer Lee res.result(boost::beast::http::status::service_unavailable); 87acb7cfb4SJennifer Lee res.jsonValue = messages::serviceTemporarilyUnavailable("3"); 88acb7cfb4SJennifer Lee res.end(); 89acb7cfb4SJennifer Lee return; 90acb7cfb4SJennifer Lee } 91acb7cfb4SJennifer Lee // Make this const static so it survives outside this method 921abe55efSEd Tanous static boost::asio::deadline_timer timeout( 931abe55efSEd Tanous *req.ioService, boost::posix_time::seconds(5)); 94acb7cfb4SJennifer Lee 95acb7cfb4SJennifer Lee timeout.expires_from_now(boost::posix_time::seconds(5)); 96acb7cfb4SJennifer Lee 97acb7cfb4SJennifer Lee timeout.async_wait([&res](const boost::system::error_code &ec) { 98acb7cfb4SJennifer Lee fwUpdateMatcher = nullptr; 991abe55efSEd Tanous if (ec == boost::asio::error::operation_aborted) 1001abe55efSEd Tanous { 101acb7cfb4SJennifer Lee // expected, we were canceled before the timer completed. 102acb7cfb4SJennifer Lee return; 103acb7cfb4SJennifer Lee } 1041abe55efSEd Tanous BMCWEB_LOG_ERROR 1051abe55efSEd Tanous << "Timed out waiting for firmware object being created"; 1061abe55efSEd Tanous BMCWEB_LOG_ERROR 1071abe55efSEd Tanous << "FW image may has already been uploaded to server"; 1081abe55efSEd Tanous if (ec) 1091abe55efSEd Tanous { 110acb7cfb4SJennifer Lee BMCWEB_LOG_ERROR << "Async_wait failed" << ec; 111acb7cfb4SJennifer Lee return; 112acb7cfb4SJennifer Lee } 113acb7cfb4SJennifer Lee 114acb7cfb4SJennifer Lee res.result(boost::beast::http::status::internal_server_error); 115acb7cfb4SJennifer Lee res.jsonValue = redfish::messages::internalError(); 116acb7cfb4SJennifer Lee res.end(); 117acb7cfb4SJennifer Lee }); 118acb7cfb4SJennifer Lee 119acb7cfb4SJennifer Lee auto callback = [&res](sdbusplus::message::message &m) { 120acb7cfb4SJennifer Lee BMCWEB_LOG_DEBUG << "Match fired"; 121acb7cfb4SJennifer Lee bool flag = false; 122acb7cfb4SJennifer Lee 1231abe55efSEd Tanous if (m.is_method_error()) 1241abe55efSEd Tanous { 125acb7cfb4SJennifer Lee BMCWEB_LOG_DEBUG << "Dbus method error!!!"; 126acb7cfb4SJennifer Lee res.end(); 127acb7cfb4SJennifer Lee return; 128acb7cfb4SJennifer Lee } 129acb7cfb4SJennifer Lee std::vector<std::pair< 130acb7cfb4SJennifer Lee std::string, 1311abe55efSEd Tanous std::vector<std::pair< 1321abe55efSEd Tanous std::string, sdbusplus::message::variant<std::string>>>>> 133*3ae837c9SEd Tanous interfacesProperties; 134acb7cfb4SJennifer Lee 135c711bf86SEd Tanous sdbusplus::message::object_path objPath; 136acb7cfb4SJennifer Lee 137*3ae837c9SEd Tanous m.read(objPath, interfacesProperties); // Read in the object path 138acb7cfb4SJennifer Lee // that was just created 139c711bf86SEd Tanous // std::string str_objpath = objPath.str; // keep a copy for 140acb7cfb4SJennifer Lee // constructing response message 141c711bf86SEd Tanous BMCWEB_LOG_DEBUG << "obj path = " << objPath.str; // str_objpath; 142*3ae837c9SEd Tanous for (auto &interface : interfacesProperties) 1431abe55efSEd Tanous { 144acb7cfb4SJennifer Lee BMCWEB_LOG_DEBUG << "interface = " << interface.first; 145acb7cfb4SJennifer Lee 1461abe55efSEd Tanous if (interface.first == 1471abe55efSEd Tanous "xyz.openbmc_project.Software.Activation") 1481abe55efSEd Tanous { 1491abe55efSEd Tanous // cancel timer only when 1501abe55efSEd Tanous // xyz.openbmc_project.Software.Activation interface is 1511abe55efSEd Tanous // added 152acb7cfb4SJennifer Lee boost::system::error_code ec; 153acb7cfb4SJennifer Lee timeout.cancel(ec); 1541abe55efSEd Tanous if (ec) 1551abe55efSEd Tanous { 156acb7cfb4SJennifer Lee BMCWEB_LOG_ERROR << "error canceling timer " << ec; 157acb7cfb4SJennifer Lee } 158c711bf86SEd Tanous UpdateService::activateImage(objPath.str); // str_objpath); 159acb7cfb4SJennifer Lee res.jsonValue = redfish::messages::success(); 160acb7cfb4SJennifer Lee BMCWEB_LOG_DEBUG << "ending response"; 161acb7cfb4SJennifer Lee res.end(); 162acb7cfb4SJennifer Lee fwUpdateMatcher = nullptr; 163acb7cfb4SJennifer Lee } 164acb7cfb4SJennifer Lee } 165acb7cfb4SJennifer Lee }; 166acb7cfb4SJennifer Lee 167acb7cfb4SJennifer Lee fwUpdateMatcher = std::make_unique<sdbusplus::bus::match::match>( 168acb7cfb4SJennifer Lee *crow::connections::systemBus, 169acb7cfb4SJennifer Lee "interface='org.freedesktop.DBus.ObjectManager',type='signal'," 170acb7cfb4SJennifer Lee "member='InterfacesAdded',path='/xyz/openbmc_project/software'", 171acb7cfb4SJennifer Lee callback); 172acb7cfb4SJennifer Lee 173acb7cfb4SJennifer Lee std::string filepath( 174acb7cfb4SJennifer Lee "/tmp/images/" + 175acb7cfb4SJennifer Lee boost::uuids::to_string(boost::uuids::random_generator()())); 176acb7cfb4SJennifer Lee BMCWEB_LOG_DEBUG << "Writing file to " << filepath; 177acb7cfb4SJennifer Lee std::ofstream out(filepath, std::ofstream::out | std::ofstream::binary | 178acb7cfb4SJennifer Lee std::ofstream::trunc); 179acb7cfb4SJennifer Lee out << req.body; 180acb7cfb4SJennifer Lee out.close(); 181acb7cfb4SJennifer Lee BMCWEB_LOG_DEBUG << "file upload complete!!"; 182acb7cfb4SJennifer Lee } 183729dae72SJennifer Lee }; 184729dae72SJennifer Lee 1851abe55efSEd Tanous class SoftwareInventoryCollection : public Node 1861abe55efSEd Tanous { 187729dae72SJennifer Lee public: 188729dae72SJennifer Lee template <typename CrowApp> 1891abe55efSEd Tanous SoftwareInventoryCollection(CrowApp &app) : 1901abe55efSEd Tanous Node(app, "/redfish/v1/UpdateService/FirmwareInventory/") 1911abe55efSEd Tanous { 192729dae72SJennifer Lee Node::json["@odata.type"] = 193729dae72SJennifer Lee "#SoftwareInventoryCollection.SoftwareInventoryCollection"; 1946c4eb9deSJennifer Lee Node::json["@odata.id"] = "/redfish/v1/UpdateService/FirmwareInventory"; 195729dae72SJennifer Lee Node::json["@odata.context"] = 196729dae72SJennifer Lee "/redfish/v1/" 197729dae72SJennifer Lee "$metadata#SoftwareInventoryCollection.SoftwareInventoryCollection"; 198729dae72SJennifer Lee Node::json["Name"] = "Software Inventory Collection"; 199729dae72SJennifer Lee 200729dae72SJennifer Lee entityPrivileges = { 201729dae72SJennifer Lee {boost::beast::http::verb::get, {{"Login"}}}, 202729dae72SJennifer Lee {boost::beast::http::verb::head, {{"Login"}}}, 203729dae72SJennifer Lee {boost::beast::http::verb::patch, {{"ConfigureComponents"}}}, 204729dae72SJennifer Lee {boost::beast::http::verb::put, {{"ConfigureComponents"}}}, 205729dae72SJennifer Lee {boost::beast::http::verb::delete_, {{"ConfigureComponents"}}}, 206729dae72SJennifer Lee {boost::beast::http::verb::post, {{"ConfigureComponents"}}}}; 207729dae72SJennifer Lee } 208729dae72SJennifer Lee 209729dae72SJennifer Lee private: 21055c7b7a2SEd Tanous void doGet(crow::Response &res, const crow::Request &req, 2111abe55efSEd Tanous const std::vector<std::string> ¶ms) override 2121abe55efSEd Tanous { 213c711bf86SEd Tanous std::shared_ptr<AsyncResp> asyncResp = std::make_shared<AsyncResp>(res); 21455c7b7a2SEd Tanous res.jsonValue = Node::json; 215c711bf86SEd Tanous 216c711bf86SEd Tanous crow::connections::systemBus->async_method_call( 217c711bf86SEd Tanous [asyncResp]( 218c711bf86SEd Tanous const boost::system::error_code ec, 2196c4eb9deSJennifer Lee const std::vector<std::pair< 2201abe55efSEd Tanous std::string, std::vector<std::pair< 2211abe55efSEd Tanous std::string, std::vector<std::string>>>>> 2226c4eb9deSJennifer Lee &subtree) { 2231abe55efSEd Tanous if (ec) 2241abe55efSEd Tanous { 225c711bf86SEd Tanous asyncResp->res.result( 226c711bf86SEd Tanous boost::beast::http::status::internal_server_error); 2276c4eb9deSJennifer Lee return; 228729dae72SJennifer Lee } 229c711bf86SEd Tanous asyncResp->res.jsonValue["Members"] = nlohmann::json::array(); 230c711bf86SEd Tanous asyncResp->res.jsonValue["Members@odata.count"] = 0; 2316c4eb9deSJennifer Lee 2321abe55efSEd Tanous for (auto &obj : subtree) 2331abe55efSEd Tanous { 2341abe55efSEd Tanous const std::vector< 2351abe55efSEd Tanous std::pair<std::string, std::vector<std::string>>> 2366c4eb9deSJennifer Lee &connections = obj.second; 2376c4eb9deSJennifer Lee 2381abe55efSEd Tanous for (auto &conn : connections) 2391abe55efSEd Tanous { 240c711bf86SEd Tanous const std::string &connectionName = conn.first; 2411abe55efSEd Tanous BMCWEB_LOG_DEBUG << "connectionName = " 2421abe55efSEd Tanous << connectionName; 24355c7b7a2SEd Tanous BMCWEB_LOG_DEBUG << "obj.first = " << obj.first; 2446c4eb9deSJennifer Lee 24555c7b7a2SEd Tanous crow::connections::systemBus->async_method_call( 2461abe55efSEd Tanous [asyncResp]( 2471abe55efSEd Tanous const boost::system::error_code error_code, 248c711bf86SEd Tanous const VariantType &activation) { 2491abe55efSEd Tanous BMCWEB_LOG_DEBUG 2501abe55efSEd Tanous << "safe returned in lambda function"; 2511abe55efSEd Tanous if (error_code) 2521abe55efSEd Tanous { 253acb7cfb4SJennifer Lee asyncResp->res.result( 2541abe55efSEd Tanous boost::beast::http::status:: 2551abe55efSEd Tanous internal_server_error); 2566c4eb9deSJennifer Lee return; 2576c4eb9deSJennifer Lee } 258c711bf86SEd Tanous 259*3ae837c9SEd Tanous const std::string *swInvPurpose = 2601abe55efSEd Tanous mapbox::getPtr<const std::string>( 2611abe55efSEd Tanous activation); 262*3ae837c9SEd Tanous if (swInvPurpose == nullptr) 2631abe55efSEd Tanous { 264c711bf86SEd Tanous asyncResp->res.result( 2651abe55efSEd Tanous boost::beast::http::status:: 2661abe55efSEd Tanous internal_server_error); 267acb7cfb4SJennifer Lee return; 268acb7cfb4SJennifer Lee } 269*3ae837c9SEd Tanous std::size_t last_pos = swInvPurpose->rfind("."); 2701abe55efSEd Tanous if (last_pos == std::string::npos) 2711abe55efSEd Tanous { 272c711bf86SEd Tanous asyncResp->res.result( 2731abe55efSEd Tanous boost::beast::http::status:: 2741abe55efSEd Tanous internal_server_error); 275c711bf86SEd Tanous return; 276c711bf86SEd Tanous } 277c711bf86SEd Tanous nlohmann::json &members = 278c711bf86SEd Tanous asyncResp->res.jsonValue["Members"]; 279c711bf86SEd Tanous members.push_back( 280*3ae837c9SEd Tanous {{"@odata.id", 281*3ae837c9SEd Tanous "/redfish/v1/UpdateService/" 2821abe55efSEd Tanous "FirmwareInventory/" + 283*3ae837c9SEd Tanous swInvPurpose->substr(last_pos + 1)}}); 2841abe55efSEd Tanous asyncResp->res 2851abe55efSEd Tanous .jsonValue["Members@odata.count"] = 286c711bf86SEd Tanous members.size(); 2876c4eb9deSJennifer Lee }, 2881abe55efSEd Tanous connectionName, obj.first, 2891abe55efSEd Tanous "org.freedesktop.DBus.Properties", "Get", 2901abe55efSEd Tanous "xyz.openbmc_project.Software.Activation", 291acb7cfb4SJennifer Lee "Activation"); 2926c4eb9deSJennifer Lee } 2936c4eb9deSJennifer Lee } 294c711bf86SEd Tanous }, 295c711bf86SEd Tanous "xyz.openbmc_project.ObjectMapper", 296c711bf86SEd Tanous "/xyz/openbmc_project/object_mapper", 297c711bf86SEd Tanous "xyz.openbmc_project.ObjectMapper", "GetSubTree", 298c711bf86SEd Tanous "/xyz/openbmc_project/software", int32_t(1), 2991abe55efSEd Tanous std::array<const char *, 1>{ 3001abe55efSEd Tanous "xyz.openbmc_project.Software.Version"}); 301729dae72SJennifer Lee } 302729dae72SJennifer Lee }; 303c711bf86SEd Tanous 3041abe55efSEd Tanous class SoftwareInventory : public Node 3051abe55efSEd Tanous { 306729dae72SJennifer Lee public: 307729dae72SJennifer Lee template <typename CrowApp> 3081abe55efSEd Tanous SoftwareInventory(CrowApp &app) : 3091abe55efSEd Tanous Node(app, "/redfish/v1/UpdateService/FirmwareInventory/<str>/", 3101abe55efSEd Tanous std::string()) 3111abe55efSEd Tanous { 3121abe55efSEd Tanous Node::json["@odata.type"] = 3131abe55efSEd Tanous "#SoftwareInventory.v1_1_0.SoftwareInventory"; 314729dae72SJennifer Lee Node::json["@odata.context"] = 315729dae72SJennifer Lee "/redfish/v1/$metadata#SoftwareInventory.SoftwareInventory"; 316729dae72SJennifer Lee Node::json["Name"] = "Software Inventory"; 3176c4eb9deSJennifer Lee Node::json["Updateable"] = false; 318acb7cfb4SJennifer Lee Node::json["Status"]["Health"] = "OK"; 319acb7cfb4SJennifer Lee Node::json["Status"]["HealthRollup"] = "OK"; 320acb7cfb4SJennifer Lee Node::json["Status"]["State"] = "Enabled"; 321729dae72SJennifer Lee entityPrivileges = { 322729dae72SJennifer Lee {boost::beast::http::verb::get, {{"Login"}}}, 323729dae72SJennifer Lee {boost::beast::http::verb::head, {{"Login"}}}, 324729dae72SJennifer Lee {boost::beast::http::verb::patch, {{"ConfigureComponents"}}}, 325729dae72SJennifer Lee {boost::beast::http::verb::put, {{"ConfigureComponents"}}}, 326729dae72SJennifer Lee {boost::beast::http::verb::delete_, {{"ConfigureComponents"}}}, 327729dae72SJennifer Lee {boost::beast::http::verb::post, {{"ConfigureComponents"}}}}; 328729dae72SJennifer Lee } 329729dae72SJennifer Lee 330729dae72SJennifer Lee private: 33155c7b7a2SEd Tanous void doGet(crow::Response &res, const crow::Request &req, 3321abe55efSEd Tanous const std::vector<std::string> ¶ms) override 3331abe55efSEd Tanous { 334c711bf86SEd Tanous std::shared_ptr<AsyncResp> asyncResp = std::make_shared<AsyncResp>(res); 33555c7b7a2SEd Tanous res.jsonValue = Node::json; 3366c4eb9deSJennifer Lee 3371abe55efSEd Tanous if (params.size() != 1) 3381abe55efSEd Tanous { 339729dae72SJennifer Lee res.result(boost::beast::http::status::internal_server_error); 340acb7cfb4SJennifer Lee res.jsonValue = messages::internalError(); 341729dae72SJennifer Lee res.end(); 342729dae72SJennifer Lee return; 343729dae72SJennifer Lee } 344729dae72SJennifer Lee 345*3ae837c9SEd Tanous std::shared_ptr<std::string> swId = 346c711bf86SEd Tanous std::make_shared<std::string>(params[0]); 347c711bf86SEd Tanous 34855c7b7a2SEd Tanous res.jsonValue["@odata.id"] = 349*3ae837c9SEd Tanous "/redfish/v1/UpdateService/FirmwareInventory/" + *swId; 350c711bf86SEd Tanous 351c711bf86SEd Tanous crow::connections::systemBus->async_method_call( 352*3ae837c9SEd Tanous [asyncResp, swId]( 353c711bf86SEd Tanous const boost::system::error_code ec, 3546c4eb9deSJennifer Lee const std::vector<std::pair< 3551abe55efSEd Tanous std::string, std::vector<std::pair< 3561abe55efSEd Tanous std::string, std::vector<std::string>>>>> 3576c4eb9deSJennifer Lee &subtree) { 35855c7b7a2SEd Tanous BMCWEB_LOG_DEBUG << "doGet callback..."; 3591abe55efSEd Tanous if (ec) 3601abe55efSEd Tanous { 361c711bf86SEd Tanous asyncResp->res.result( 362c711bf86SEd Tanous boost::beast::http::status::internal_server_error); 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 { 372*3ae837c9SEd Tanous if (boost::ends_with(obj.first, *swId) != true) 3731abe55efSEd Tanous { 374acb7cfb4SJennifer Lee continue; 375acb7cfb4SJennifer Lee } 376acb7cfb4SJennifer Lee 3771abe55efSEd Tanous 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, 384*3ae837c9SEd 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 { 389c711bf86SEd Tanous asyncResp->res.result( 3901abe55efSEd Tanous boost::beast::http::status:: 3911abe55efSEd Tanous internal_server_error); 3926c4eb9deSJennifer Lee return; 3936c4eb9deSJennifer Lee } 3941abe55efSEd Tanous boost::container::flat_map< 3951abe55efSEd Tanous std::string, VariantType>::const_iterator it = 3966c4eb9deSJennifer Lee propertiesList.find("Purpose"); 3971abe55efSEd Tanous if (it == propertiesList.end()) 3981abe55efSEd Tanous { 3991abe55efSEd Tanous BMCWEB_LOG_DEBUG 4001abe55efSEd Tanous << "Can't find property \"Purpose\"!"; 401c711bf86SEd Tanous asyncResp->res.result( 4021abe55efSEd Tanous boost::beast::http::status:: 4031abe55efSEd Tanous internal_server_error); 4046c4eb9deSJennifer Lee return; 4056c4eb9deSJennifer Lee } 406*3ae837c9SEd Tanous const std::string *swInvPurpose = 407acb7cfb4SJennifer Lee mapbox::getPtr<const std::string>(it->second); 408*3ae837c9SEd Tanous if (swInvPurpose == nullptr) 4091abe55efSEd Tanous { 4101abe55efSEd Tanous BMCWEB_LOG_DEBUG 4111abe55efSEd Tanous << "wrong types for property\"Purpose\"!"; 412c711bf86SEd Tanous asyncResp->res.result( 4131abe55efSEd Tanous boost::beast::http::status:: 4141abe55efSEd Tanous internal_server_error); 415acb7cfb4SJennifer Lee return; 416acb7cfb4SJennifer Lee } 417c711bf86SEd Tanous 418*3ae837c9SEd Tanous BMCWEB_LOG_DEBUG << "swInvPurpose = " 419*3ae837c9SEd Tanous << *swInvPurpose; 420*3ae837c9SEd Tanous if (boost::ends_with(*swInvPurpose, "." + *swId)) 4211abe55efSEd Tanous { 422c711bf86SEd Tanous it = propertiesList.find("Version"); 4231abe55efSEd Tanous if (it == propertiesList.end()) 4241abe55efSEd Tanous { 4251abe55efSEd Tanous BMCWEB_LOG_DEBUG 4261abe55efSEd Tanous << "Can't find property \"Version\"!"; 427c711bf86SEd Tanous asyncResp->res.result( 4281abe55efSEd Tanous boost::beast::http::status:: 4291abe55efSEd Tanous internal_server_error); 430c711bf86SEd Tanous return; 431acb7cfb4SJennifer Lee } 432acb7cfb4SJennifer Lee 433acb7cfb4SJennifer Lee const std::string *version = 4341abe55efSEd Tanous mapbox::getPtr<const std::string>( 4351abe55efSEd Tanous it->second); 436c711bf86SEd Tanous 4371abe55efSEd Tanous if (version != nullptr) 4381abe55efSEd Tanous { 4391abe55efSEd Tanous BMCWEB_LOG_DEBUG 4401abe55efSEd Tanous << "Can't find property \"Version\"!"; 441c711bf86SEd Tanous asyncResp->res.result( 4421abe55efSEd Tanous boost::beast::http::status:: 4431abe55efSEd Tanous internal_server_error); 4446c4eb9deSJennifer Lee return; 4456c4eb9deSJennifer Lee } 446c711bf86SEd Tanous asyncResp->res.jsonValue["Version"] = *version; 447*3ae837c9SEd Tanous asyncResp->res.jsonValue["Id"] = *swId; 4486c4eb9deSJennifer Lee } 4496c4eb9deSJennifer Lee }, 450c711bf86SEd Tanous obj.second[0].first, obj.first, 451c711bf86SEd Tanous "org.freedesktop.DBus.Properties", "GetAll", 452c711bf86SEd Tanous "xyz.openbmc_project.Software.Version"); 4536c4eb9deSJennifer Lee } 454c711bf86SEd Tanous }, 455c711bf86SEd Tanous "xyz.openbmc_project.ObjectMapper", 456c711bf86SEd Tanous "/xyz/openbmc_project/object_mapper", 457c711bf86SEd Tanous "xyz.openbmc_project.ObjectMapper", "GetSubTree", 458c711bf86SEd Tanous "/xyz/openbmc_project/software", int32_t(1), 4591abe55efSEd Tanous std::array<const char *, 1>{ 4601abe55efSEd Tanous "xyz.openbmc_project.Software.Version"}); 4616c4eb9deSJennifer Lee } 462729dae72SJennifer Lee }; 463729dae72SJennifer Lee 464729dae72SJennifer Lee } // namespace redfish 465