1099543e4SBrad Bishop // SPDX-License-Identifier: Apache-2.0 2099543e4SBrad Bishop 3099543e4SBrad Bishop /**@file functions.cpp*/ 4099543e4SBrad Bishop 556f538caSAdriana Kobylak #include "config.h" 656f538caSAdriana Kobylak 7099543e4SBrad Bishop #include "functions.hpp" 8099543e4SBrad Bishop 9ae0998f1SAdriana Kobylak #include <nlohmann/json.hpp> 1056f538caSAdriana Kobylak #include <phosphor-logging/log.hpp> 11099543e4SBrad Bishop #include <sdbusplus/bus.hpp> 12099543e4SBrad Bishop #include <sdbusplus/bus/match.hpp> 13c79fa915SAdriana Kobylak #include <sdbusplus/exception.hpp> 14099543e4SBrad Bishop #include <sdbusplus/message.hpp> 15099543e4SBrad Bishop #include <sdeventplus/event.hpp> 16099543e4SBrad Bishop 17099543e4SBrad Bishop #include <filesystem> 18ae0998f1SAdriana Kobylak #include <fstream> 19099543e4SBrad Bishop #include <functional> 20099543e4SBrad Bishop #include <iostream> 21099543e4SBrad Bishop #include <map> 22099543e4SBrad Bishop #include <memory> 23099543e4SBrad Bishop #include <string> 24099543e4SBrad Bishop #include <variant> 25099543e4SBrad Bishop #include <vector> 26099543e4SBrad Bishop 27099543e4SBrad Bishop namespace functions 28099543e4SBrad Bishop { 29099543e4SBrad Bishop namespace process_hostfirmware 30099543e4SBrad Bishop { 31099543e4SBrad Bishop 3256f538caSAdriana Kobylak using namespace phosphor::logging; 33*ebf67bf7SAdriana Kobylak using InterfacesPropertiesMap = 34*ebf67bf7SAdriana Kobylak std::map<std::string, 35*ebf67bf7SAdriana Kobylak std::map<std::string, std::variant<std::vector<std::string>>>>; 36*ebf67bf7SAdriana Kobylak using ManagedObjectType = 37*ebf67bf7SAdriana Kobylak std::map<sdbusplus::message::object_path, InterfacesPropertiesMap>; 3856f538caSAdriana Kobylak 39099543e4SBrad Bishop /** 40fd4a6088SAdriana Kobylak * @brief GetObject function to find the service given an object path. 41fd4a6088SAdriana Kobylak * It is used to determine if a service is running, so there is no need 42fd4a6088SAdriana Kobylak * to specify interfaces as a parameter to constrain the search. 43fd4a6088SAdriana Kobylak */ 44fd4a6088SAdriana Kobylak std::string getObject(sdbusplus::bus::bus& bus, const std::string& path) 45fd4a6088SAdriana Kobylak { 46fd4a6088SAdriana Kobylak auto method = bus.new_method_call(MAPPER_BUSNAME, MAPPER_PATH, 47fd4a6088SAdriana Kobylak MAPPER_BUSNAME, "GetObject"); 48fd4a6088SAdriana Kobylak method.append(path); 49fd4a6088SAdriana Kobylak std::vector<std::string> interfaces; 50fd4a6088SAdriana Kobylak method.append(interfaces); 51fd4a6088SAdriana Kobylak 52fd4a6088SAdriana Kobylak std::vector<std::pair<std::string, std::vector<std::string>>> response; 53fd4a6088SAdriana Kobylak 54fd4a6088SAdriana Kobylak try 55fd4a6088SAdriana Kobylak { 56fd4a6088SAdriana Kobylak auto reply = bus.call(method); 57fd4a6088SAdriana Kobylak reply.read(response); 58fd4a6088SAdriana Kobylak if (response.empty()) 59fd4a6088SAdriana Kobylak { 60fd4a6088SAdriana Kobylak return std::string{}; 61fd4a6088SAdriana Kobylak } 62fd4a6088SAdriana Kobylak } 63fd4a6088SAdriana Kobylak catch (const sdbusplus::exception::SdBusError& e) 64fd4a6088SAdriana Kobylak { 65fd4a6088SAdriana Kobylak return std::string{}; 66fd4a6088SAdriana Kobylak } 67fd4a6088SAdriana Kobylak return response[0].first; 68fd4a6088SAdriana Kobylak } 69fd4a6088SAdriana Kobylak 70fd4a6088SAdriana Kobylak /** 71*ebf67bf7SAdriana Kobylak * @brief Returns the managed objects for a given service 72*ebf67bf7SAdriana Kobylak */ 73*ebf67bf7SAdriana Kobylak ManagedObjectType getManagedObjects(sdbusplus::bus::bus& bus, 74*ebf67bf7SAdriana Kobylak const std::string& service) 75*ebf67bf7SAdriana Kobylak { 76*ebf67bf7SAdriana Kobylak auto method = bus.new_method_call(service.c_str(), "/", 77*ebf67bf7SAdriana Kobylak "org.freedesktop.DBus.ObjectManager", 78*ebf67bf7SAdriana Kobylak "GetManagedObjects"); 79*ebf67bf7SAdriana Kobylak 80*ebf67bf7SAdriana Kobylak ManagedObjectType objects; 81*ebf67bf7SAdriana Kobylak 82*ebf67bf7SAdriana Kobylak try 83*ebf67bf7SAdriana Kobylak { 84*ebf67bf7SAdriana Kobylak auto reply = bus.call(method); 85*ebf67bf7SAdriana Kobylak reply.read(objects); 86*ebf67bf7SAdriana Kobylak } 87*ebf67bf7SAdriana Kobylak catch (const sdbusplus::exception::SdBusError& e) 88*ebf67bf7SAdriana Kobylak { 89*ebf67bf7SAdriana Kobylak return ManagedObjectType{}; 90*ebf67bf7SAdriana Kobylak } 91*ebf67bf7SAdriana Kobylak return objects; 92*ebf67bf7SAdriana Kobylak } 93*ebf67bf7SAdriana Kobylak 94*ebf67bf7SAdriana Kobylak /** 95099543e4SBrad Bishop * @brief Issue callbacks safely 96099543e4SBrad Bishop * 97099543e4SBrad Bishop * std::function can be empty, so this wrapper method checks for that prior to 98099543e4SBrad Bishop * calling it to avoid std::bad_function_call 99099543e4SBrad Bishop * 100099543e4SBrad Bishop * @tparam Sig the types of the std::function arguments 101099543e4SBrad Bishop * @tparam Args the deduced argument types 102099543e4SBrad Bishop * @param[in] callback the callback being wrapped 103099543e4SBrad Bishop * @param[in] args the callback arguments 104099543e4SBrad Bishop */ 105099543e4SBrad Bishop template <typename... Sig, typename... Args> 106099543e4SBrad Bishop void makeCallback(const std::function<void(Sig...)>& callback, Args&&... args) 107099543e4SBrad Bishop { 108099543e4SBrad Bishop if (callback) 109099543e4SBrad Bishop { 110099543e4SBrad Bishop callback(std::forward<Args>(args)...); 111099543e4SBrad Bishop } 112099543e4SBrad Bishop } 113099543e4SBrad Bishop 114099543e4SBrad Bishop /** 115099543e4SBrad Bishop * @brief Get file extensions for IBMCompatibleSystem 116099543e4SBrad Bishop * 117099543e4SBrad Bishop * IBM host firmware can be deployed as blobs (files) in a filesystem. Host 118099543e4SBrad Bishop * firmware blobs for different values of 119099543e4SBrad Bishop * xyz.openbmc_project.Configuration.IBMCompatibleSystem are packaged with 120099543e4SBrad Bishop * different filename extensions. getExtensionsForIbmCompatibleSystem 121099543e4SBrad Bishop * maintains the mapping from a given value of 122099543e4SBrad Bishop * xyz.openbmc_project.Configuration.IBMCompatibleSystem to an array of 123099543e4SBrad Bishop * filename extensions. 124099543e4SBrad Bishop * 125099543e4SBrad Bishop * If a mapping is found getExtensionsForIbmCompatibleSystem returns true and 126099543e4SBrad Bishop * the extensions parameter is reset with the map entry. If no mapping is 127099543e4SBrad Bishop * found getExtensionsForIbmCompatibleSystem returns false and extensions is 128099543e4SBrad Bishop * unmodified. 129099543e4SBrad Bishop * 130099543e4SBrad Bishop * @param[in] extensionMap a map of 131099543e4SBrad Bishop * xyz.openbmc_project.Configuration.IBMCompatibleSystem to host firmware blob 132099543e4SBrad Bishop * file extensions. 133099543e4SBrad Bishop * @param[in] ibmCompatibleSystem The names property of an instance of 134099543e4SBrad Bishop * xyz.openbmc_project.Configuration.IBMCompatibleSystem 135099543e4SBrad Bishop * @param[out] extentions the host firmware blob file extensions 136099543e4SBrad Bishop * @return true if an entry was found, otherwise false 137099543e4SBrad Bishop */ 138099543e4SBrad Bishop bool getExtensionsForIbmCompatibleSystem( 139099543e4SBrad Bishop const std::map<std::string, std::vector<std::string>>& extensionMap, 140099543e4SBrad Bishop const std::vector<std::string>& ibmCompatibleSystem, 141099543e4SBrad Bishop std::vector<std::string>& extensions) 142099543e4SBrad Bishop { 143099543e4SBrad Bishop for (const auto& system : ibmCompatibleSystem) 144099543e4SBrad Bishop { 145099543e4SBrad Bishop auto extensionMapIterator = extensionMap.find(system); 146099543e4SBrad Bishop if (extensionMapIterator != extensionMap.end()) 147099543e4SBrad Bishop { 148099543e4SBrad Bishop extensions = extensionMapIterator->second; 149099543e4SBrad Bishop return true; 150099543e4SBrad Bishop } 151099543e4SBrad Bishop } 152099543e4SBrad Bishop 153099543e4SBrad Bishop return false; 154099543e4SBrad Bishop } 155099543e4SBrad Bishop 156099543e4SBrad Bishop /** 157099543e4SBrad Bishop * @brief Write host firmware well-known name 158099543e4SBrad Bishop * 159099543e4SBrad Bishop * A wrapper around std::filesystem::create_symlink that avoids EEXIST by 160099543e4SBrad Bishop * deleting any pre-existing file. 161099543e4SBrad Bishop * 162099543e4SBrad Bishop * @param[in] linkTarget The link target argument to 163099543e4SBrad Bishop * std::filesystem::create_symlink 164099543e4SBrad Bishop * @param[in] linkPath The link path argument to std::filesystem::create_symlink 165099543e4SBrad Bishop * @param[in] errorCallback A callback made in the event of filesystem errors. 166099543e4SBrad Bishop */ 167099543e4SBrad Bishop void writeLink(const std::filesystem::path& linkTarget, 168099543e4SBrad Bishop const std::filesystem::path& linkPath, 169099543e4SBrad Bishop const ErrorCallbackType& errorCallback) 170099543e4SBrad Bishop { 171099543e4SBrad Bishop std::error_code ec; 172099543e4SBrad Bishop 173099543e4SBrad Bishop // remove files with the same name as the symlink to be created, 174099543e4SBrad Bishop // otherwise symlink will fail with EEXIST. 175099543e4SBrad Bishop if (!std::filesystem::remove(linkPath, ec)) 176099543e4SBrad Bishop { 177099543e4SBrad Bishop if (ec) 178099543e4SBrad Bishop { 179099543e4SBrad Bishop makeCallback(errorCallback, linkPath, ec); 180099543e4SBrad Bishop return; 181099543e4SBrad Bishop } 182099543e4SBrad Bishop } 183099543e4SBrad Bishop 184099543e4SBrad Bishop std::filesystem::create_symlink(linkTarget, linkPath, ec); 185099543e4SBrad Bishop if (ec) 186099543e4SBrad Bishop { 187099543e4SBrad Bishop makeCallback(errorCallback, linkPath, ec); 188099543e4SBrad Bishop return; 189099543e4SBrad Bishop } 190099543e4SBrad Bishop } 191099543e4SBrad Bishop 192099543e4SBrad Bishop /** 193099543e4SBrad Bishop * @brief Find host firmware blob files that need well-known names 194099543e4SBrad Bishop * 195099543e4SBrad Bishop * The IBM host firmware runtime looks for data and/or additional code while 196099543e4SBrad Bishop * bootstraping in files with well-known names. findLinks uses the provided 197099543e4SBrad Bishop * extensions argument to find host firmware blob files that require a 198099543e4SBrad Bishop * well-known name. When a blob is found, issue the provided callback 199099543e4SBrad Bishop * (typically a function that will write a symlink). 200099543e4SBrad Bishop * 201099543e4SBrad Bishop * @param[in] hostFirmwareDirectory The directory in which findLinks should 202099543e4SBrad Bishop * look for host firmware blob files that need well-known names. 203099543e4SBrad Bishop * @param[in] extentions The extensions of the firmware blob files denote a 204099543e4SBrad Bishop * host firmware blob file requires a well-known name. 205099543e4SBrad Bishop * @param[in] errorCallback A callback made in the event of filesystem errors. 206099543e4SBrad Bishop * @param[in] linkCallback A callback made when host firmware blob files 207099543e4SBrad Bishop * needing a well known name are found. 208099543e4SBrad Bishop */ 209099543e4SBrad Bishop void findLinks(const std::filesystem::path& hostFirmwareDirectory, 210099543e4SBrad Bishop const std::vector<std::string>& extensions, 211099543e4SBrad Bishop const ErrorCallbackType& errorCallback, 212099543e4SBrad Bishop const LinkCallbackType& linkCallback) 213099543e4SBrad Bishop { 214099543e4SBrad Bishop std::error_code ec; 215099543e4SBrad Bishop std::filesystem::directory_iterator directoryIterator(hostFirmwareDirectory, 216099543e4SBrad Bishop ec); 217099543e4SBrad Bishop if (ec) 218099543e4SBrad Bishop { 219099543e4SBrad Bishop makeCallback(errorCallback, hostFirmwareDirectory, ec); 220099543e4SBrad Bishop return; 221099543e4SBrad Bishop } 222099543e4SBrad Bishop 223fdc91fa0SAdriana Kobylak // Create a symlink from HBB to the corresponding LID file if it exists 224fdc91fa0SAdriana Kobylak static const auto hbbLid = "81e0065a.lid"; 225fdc91fa0SAdriana Kobylak auto hbbLidPath = hostFirmwareDirectory / hbbLid; 226fdc91fa0SAdriana Kobylak if (std::filesystem::exists(hbbLidPath)) 227fdc91fa0SAdriana Kobylak { 228fdc91fa0SAdriana Kobylak static const auto hbbName = "HBB"; 229fdc91fa0SAdriana Kobylak auto hbbLinkPath = hostFirmwareDirectory / hbbName; 230fdc91fa0SAdriana Kobylak makeCallback(linkCallback, hbbLid, hbbLinkPath, errorCallback); 231fdc91fa0SAdriana Kobylak } 232fdc91fa0SAdriana Kobylak 233099543e4SBrad Bishop for (; directoryIterator != std::filesystem::end(directoryIterator); 234099543e4SBrad Bishop directoryIterator.increment(ec)) 235099543e4SBrad Bishop { 236099543e4SBrad Bishop const auto& file = directoryIterator->path(); 237099543e4SBrad Bishop if (ec) 238099543e4SBrad Bishop { 239099543e4SBrad Bishop makeCallback(errorCallback, file, ec); 240099543e4SBrad Bishop // quit here if the increment call failed otherwise the loop may 241099543e4SBrad Bishop // never finish 242099543e4SBrad Bishop break; 243099543e4SBrad Bishop } 244099543e4SBrad Bishop 245099543e4SBrad Bishop if (std::find(extensions.begin(), extensions.end(), file.extension()) == 246099543e4SBrad Bishop extensions.end()) 247099543e4SBrad Bishop { 248099543e4SBrad Bishop // this file doesn't have an extension or doesn't match any of the 249099543e4SBrad Bishop // provided extensions. 250099543e4SBrad Bishop continue; 251099543e4SBrad Bishop } 252099543e4SBrad Bishop 253099543e4SBrad Bishop auto linkPath(file.parent_path().append( 254099543e4SBrad Bishop static_cast<const std::string&>(file.stem()))); 255099543e4SBrad Bishop 256099543e4SBrad Bishop makeCallback(linkCallback, file.filename(), linkPath, errorCallback); 257099543e4SBrad Bishop } 258099543e4SBrad Bishop } 259099543e4SBrad Bishop 260099543e4SBrad Bishop /** 261ae0998f1SAdriana Kobylak * @brief Parse the elements json file and construct a string with the data to 262ae0998f1SAdriana Kobylak * be used to update the bios attribute table. 263ae0998f1SAdriana Kobylak * 264ae0998f1SAdriana Kobylak * @param[in] elementsJsonFilePath - The path to the host firmware json file. 265ae0998f1SAdriana Kobylak * @param[in] extensions - The extensions of the firmware blob files. 26653a27395SAdriana Kobylak */ 267ae0998f1SAdriana Kobylak std::string getBiosAttrStr(const std::filesystem::path& elementsJsonFilePath, 268ae0998f1SAdriana Kobylak const std::vector<std::string>& extensions) 26956f538caSAdriana Kobylak { 27056f538caSAdriana Kobylak std::string biosAttrStr{}; 27156f538caSAdriana Kobylak 272ae0998f1SAdriana Kobylak std::ifstream jsonFile(elementsJsonFilePath.c_str()); 273ae0998f1SAdriana Kobylak if (!jsonFile) 274ae0998f1SAdriana Kobylak { 275ae0998f1SAdriana Kobylak return {}; 276ae0998f1SAdriana Kobylak } 277ae0998f1SAdriana Kobylak 278ae0998f1SAdriana Kobylak std::map<std::string, std::string> attr; 279ae0998f1SAdriana Kobylak auto data = nlohmann::json::parse(jsonFile, nullptr, false); 280ae0998f1SAdriana Kobylak if (data.is_discarded()) 281ae0998f1SAdriana Kobylak { 282ae0998f1SAdriana Kobylak log<level::ERR>("Error parsing JSON file", 283ae0998f1SAdriana Kobylak entry("FILE=%s", elementsJsonFilePath.c_str())); 284ae0998f1SAdriana Kobylak return {}; 285ae0998f1SAdriana Kobylak } 286ae0998f1SAdriana Kobylak 287ae0998f1SAdriana Kobylak // .get requires a non-const iterator 288ae0998f1SAdriana Kobylak for (auto& iter : data["lids"]) 289ae0998f1SAdriana Kobylak { 290ae0998f1SAdriana Kobylak std::string name{}; 291ae0998f1SAdriana Kobylak std::string lid{}; 292ae0998f1SAdriana Kobylak 293ae0998f1SAdriana Kobylak try 294ae0998f1SAdriana Kobylak { 295ae0998f1SAdriana Kobylak name = iter["element_name"].get<std::string>(); 296ae0998f1SAdriana Kobylak lid = iter["short_lid_name"].get<std::string>(); 297ae0998f1SAdriana Kobylak } 298ae0998f1SAdriana Kobylak catch (std::exception& e) 299ae0998f1SAdriana Kobylak { 300ae0998f1SAdriana Kobylak // Possibly the element or lid name field was not found 301ae0998f1SAdriana Kobylak log<level::ERR>("Error reading JSON field", 302ae0998f1SAdriana Kobylak entry("FILE=%s", elementsJsonFilePath.c_str()), 303ae0998f1SAdriana Kobylak entry("ERROR=%s", e.what())); 304ae0998f1SAdriana Kobylak continue; 305ae0998f1SAdriana Kobylak } 306ae0998f1SAdriana Kobylak 307ae0998f1SAdriana Kobylak // The elements with the ipl extension have higher priority. Therefore 308ae0998f1SAdriana Kobylak // Use operator[] to overwrite value if an entry for it already exists. 309ae0998f1SAdriana Kobylak // Ex: if the JSON contains an entry A.P10 followed by A.P10.iplTime, 310ae0998f1SAdriana Kobylak // the lid value for the latter one will be overwrite the value of the 311ae0998f1SAdriana Kobylak // first one. 312ae0998f1SAdriana Kobylak constexpr auto iplExtension = ".iplTime"; 313ae0998f1SAdriana Kobylak std::filesystem::path path(name); 314ae0998f1SAdriana Kobylak if (path.extension() == iplExtension) 315ae0998f1SAdriana Kobylak { 316ae0998f1SAdriana Kobylak // Some elements have an additional extension, ex: .P10.iplTime 317ae0998f1SAdriana Kobylak // Strip off the ipl extension with stem(), then check if there is 318ae0998f1SAdriana Kobylak // an additional extension with extension(). 319ae0998f1SAdriana Kobylak if (!path.stem().extension().empty()) 320ae0998f1SAdriana Kobylak { 321ae0998f1SAdriana Kobylak // Check if the extension matches the extensions for this system 322ae0998f1SAdriana Kobylak if (std::find(extensions.begin(), extensions.end(), 323ae0998f1SAdriana Kobylak path.stem().extension()) == extensions.end()) 324ae0998f1SAdriana Kobylak { 325ae0998f1SAdriana Kobylak continue; 326ae0998f1SAdriana Kobylak } 327ae0998f1SAdriana Kobylak } 328ae0998f1SAdriana Kobylak // Get the element name without extensions by calling stem() twice 329ae0998f1SAdriana Kobylak // since stem() returns the base name if no periods are found. 330ae0998f1SAdriana Kobylak // Therefore both "element.P10" and "element.P10.iplTime" would 331ae0998f1SAdriana Kobylak // become "element". 332ae0998f1SAdriana Kobylak attr[path.stem().stem()] = lid; 333ae0998f1SAdriana Kobylak continue; 334ae0998f1SAdriana Kobylak } 335ae0998f1SAdriana Kobylak 336ae0998f1SAdriana Kobylak // Process all other extensions. The extension should match the list of 337ae0998f1SAdriana Kobylak // supported extensions for this system. Use .insert() to only add 338ae0998f1SAdriana Kobylak // entries that do not exist, so to not overwrite the values that may 339ae0998f1SAdriana Kobylak // had been added that had the ipl extension. 340ae0998f1SAdriana Kobylak if (std::find(extensions.begin(), extensions.end(), path.extension()) != 341ae0998f1SAdriana Kobylak extensions.end()) 342ae0998f1SAdriana Kobylak { 343ae0998f1SAdriana Kobylak attr.insert({path.stem(), lid}); 344ae0998f1SAdriana Kobylak } 345ae0998f1SAdriana Kobylak } 346ae0998f1SAdriana Kobylak for (const auto& a : attr) 347ae0998f1SAdriana Kobylak { 348ae0998f1SAdriana Kobylak // Build the bios attribute string with format: 349ae0998f1SAdriana Kobylak // "element1=lid1,element2=lid2,elementN=lidN," 350ae0998f1SAdriana Kobylak biosAttrStr += a.first + "=" + a.second + ","; 351ae0998f1SAdriana Kobylak } 352ae0998f1SAdriana Kobylak 353ae0998f1SAdriana Kobylak return biosAttrStr; 354ae0998f1SAdriana Kobylak } 355ae0998f1SAdriana Kobylak 356ae0998f1SAdriana Kobylak /** 357ae0998f1SAdriana Kobylak * @brief Set the bios attribute table with details of the host firmware data 358ae0998f1SAdriana Kobylak * for this system. 359ae0998f1SAdriana Kobylak * 360ae0998f1SAdriana Kobylak * @param[in] elementsJsonFilePath - The path to the host firmware json file. 361ae0998f1SAdriana Kobylak * @param[in] extentions - The extensions of the firmware blob files. 362ae0998f1SAdriana Kobylak */ 363ae0998f1SAdriana Kobylak void setBiosAttr(const std::filesystem::path& elementsJsonFilePath, 364ae0998f1SAdriana Kobylak const std::vector<std::string>& extensions) 365ae0998f1SAdriana Kobylak { 366ae0998f1SAdriana Kobylak auto biosAttrStr = getBiosAttrStr(elementsJsonFilePath, extensions); 367ae0998f1SAdriana Kobylak 36856f538caSAdriana Kobylak constexpr auto biosConfigPath = "/xyz/openbmc_project/bios_config/manager"; 36956f538caSAdriana Kobylak constexpr auto biosConfigIntf = "xyz.openbmc_project.BIOSConfig.Manager"; 37056f538caSAdriana Kobylak constexpr auto dbusAttrName = "hb_lid_ids"; 37156f538caSAdriana Kobylak constexpr auto dbusAttrType = 37256f538caSAdriana Kobylak "xyz.openbmc_project.BIOSConfig.Manager.AttributeType.String"; 37356f538caSAdriana Kobylak 37456f538caSAdriana Kobylak using PendingAttributesType = std::vector<std::pair< 37556f538caSAdriana Kobylak std::string, std::tuple<std::string, std::variant<std::string>>>>; 37656f538caSAdriana Kobylak PendingAttributesType pendingAttributes; 37756f538caSAdriana Kobylak pendingAttributes.emplace_back(std::make_pair( 37856f538caSAdriana Kobylak dbusAttrName, std::make_tuple(dbusAttrType, biosAttrStr))); 37956f538caSAdriana Kobylak 38056f538caSAdriana Kobylak auto bus = sdbusplus::bus::new_default(); 38156f538caSAdriana Kobylak auto method = bus.new_method_call(MAPPER_BUSNAME, MAPPER_PATH, 38256f538caSAdriana Kobylak MAPPER_INTERFACE, "GetObject"); 38356f538caSAdriana Kobylak method.append(biosConfigPath, std::vector<std::string>({biosConfigIntf})); 38456f538caSAdriana Kobylak std::vector<std::pair<std::string, std::vector<std::string>>> response; 38556f538caSAdriana Kobylak try 38656f538caSAdriana Kobylak { 38756f538caSAdriana Kobylak auto reply = bus.call(method); 38856f538caSAdriana Kobylak reply.read(response); 38956f538caSAdriana Kobylak if (response.empty()) 39056f538caSAdriana Kobylak { 39156f538caSAdriana Kobylak log<level::ERR>("Error reading mapper response", 39256f538caSAdriana Kobylak entry("PATH=%s", biosConfigPath), 39356f538caSAdriana Kobylak entry("INTERFACE=%s", biosConfigIntf)); 39456f538caSAdriana Kobylak return; 39556f538caSAdriana Kobylak } 39656f538caSAdriana Kobylak auto method = bus.new_method_call((response.begin()->first).c_str(), 39756f538caSAdriana Kobylak biosConfigPath, 39856f538caSAdriana Kobylak SYSTEMD_PROPERTY_INTERFACE, "Set"); 39956f538caSAdriana Kobylak method.append(biosConfigIntf, "PendingAttributes", 40056f538caSAdriana Kobylak std::variant<PendingAttributesType>(pendingAttributes)); 40156f538caSAdriana Kobylak bus.call(method); 40256f538caSAdriana Kobylak } 40356f538caSAdriana Kobylak catch (const sdbusplus::exception::SdBusError& e) 40456f538caSAdriana Kobylak { 40556f538caSAdriana Kobylak log<level::ERR>("Error setting the bios attribute", 40656f538caSAdriana Kobylak entry("ERROR=%s", e.what()), 40756f538caSAdriana Kobylak entry("ATTRIBUTE=%s", dbusAttrName)); 40856f538caSAdriana Kobylak return; 40956f538caSAdriana Kobylak } 41056f538caSAdriana Kobylak } 41153a27395SAdriana Kobylak 41253a27395SAdriana Kobylak /** 413099543e4SBrad Bishop * @brief Make callbacks on 414099543e4SBrad Bishop * xyz.openbmc_project.Configuration.IBMCompatibleSystem instances. 415099543e4SBrad Bishop * 416099543e4SBrad Bishop * Look for an instance of 417099543e4SBrad Bishop * xyz.openbmc_project.Configuration.IBMCompatibleSystem in the provided 418099543e4SBrad Bishop * argument and if found, issue the provided callback. 419099543e4SBrad Bishop * 420099543e4SBrad Bishop * @param[in] interfacesAndProperties the interfaces in which to look for an 421099543e4SBrad Bishop * instance of xyz.openbmc_project.Configuration.IBMCompatibleSystem 422099543e4SBrad Bishop * @param[in] callback the user callback to make if 423099543e4SBrad Bishop * xyz.openbmc_project.Configuration.IBMCompatibleSystem is found in 424099543e4SBrad Bishop * interfacesAndProperties 425099543e4SBrad Bishop * @return true if interfacesAndProperties contained an instance of 426099543e4SBrad Bishop * xyz.openbmc_project.Configuration.IBMCompatibleSystem, false otherwise 427099543e4SBrad Bishop */ 428099543e4SBrad Bishop bool maybeCall(const std::map<std::string, 429099543e4SBrad Bishop std::map<std::string, 430099543e4SBrad Bishop std::variant<std::vector<std::string>>>>& 431099543e4SBrad Bishop interfacesAndProperties, 432099543e4SBrad Bishop const MaybeCallCallbackType& callback) 433099543e4SBrad Bishop { 434099543e4SBrad Bishop using namespace std::string_literals; 435099543e4SBrad Bishop 436099543e4SBrad Bishop static const auto interfaceName = 437099543e4SBrad Bishop "xyz.openbmc_project.Configuration.IBMCompatibleSystem"s; 438099543e4SBrad Bishop auto interfaceIterator = interfacesAndProperties.find(interfaceName); 439099543e4SBrad Bishop if (interfaceIterator == interfacesAndProperties.cend()) 440099543e4SBrad Bishop { 441099543e4SBrad Bishop // IBMCompatibleSystem interface not found, so instruct the caller to 442099543e4SBrad Bishop // keep waiting or try again later. 443099543e4SBrad Bishop return false; 444099543e4SBrad Bishop } 445099543e4SBrad Bishop auto propertyIterator = interfaceIterator->second.find("Names"s); 446099543e4SBrad Bishop if (propertyIterator == interfaceIterator->second.cend()) 447099543e4SBrad Bishop { 448099543e4SBrad Bishop // The interface exists but the property doesn't. This is a bug in the 449099543e4SBrad Bishop // IBMCompatibleSystem implementation. The caller should not try 450099543e4SBrad Bishop // again. 451099543e4SBrad Bishop std::cerr << "Names property not implemented on " << interfaceName 452099543e4SBrad Bishop << "\n"; 453099543e4SBrad Bishop return true; 454099543e4SBrad Bishop } 455099543e4SBrad Bishop 456099543e4SBrad Bishop const auto& ibmCompatibleSystem = 457099543e4SBrad Bishop std::get<std::vector<std::string>>(propertyIterator->second); 458099543e4SBrad Bishop if (callback) 459099543e4SBrad Bishop { 460099543e4SBrad Bishop callback(ibmCompatibleSystem); 461099543e4SBrad Bishop } 462099543e4SBrad Bishop 463099543e4SBrad Bishop // IBMCompatibleSystem found and callback issued. 464099543e4SBrad Bishop return true; 465099543e4SBrad Bishop } 466099543e4SBrad Bishop 467099543e4SBrad Bishop /** 468099543e4SBrad Bishop * @brief Make callbacks on 469099543e4SBrad Bishop * xyz.openbmc_project.Configuration.IBMCompatibleSystem instances. 470099543e4SBrad Bishop * 471099543e4SBrad Bishop * Look for an instance of 472099543e4SBrad Bishop * xyz.openbmc_project.Configuration.IBMCompatibleSystem in the provided 473099543e4SBrad Bishop * argument and if found, issue the provided callback. 474099543e4SBrad Bishop * 475099543e4SBrad Bishop * @param[in] message the DBus message in which to look for an instance of 476099543e4SBrad Bishop * xyz.openbmc_project.Configuration.IBMCompatibleSystem 477099543e4SBrad Bishop * @param[in] callback the user callback to make if 478099543e4SBrad Bishop * xyz.openbmc_project.Configuration.IBMCompatibleSystem is found in 479099543e4SBrad Bishop * message 480099543e4SBrad Bishop * @return true if message contained an instance of 481099543e4SBrad Bishop * xyz.openbmc_project.Configuration.IBMCompatibleSystem, false otherwise 482099543e4SBrad Bishop */ 483099543e4SBrad Bishop bool maybeCallMessage(sdbusplus::message::message& message, 484099543e4SBrad Bishop const MaybeCallCallbackType& callback) 485099543e4SBrad Bishop { 486099543e4SBrad Bishop std::map<std::string, 487099543e4SBrad Bishop std::map<std::string, std::variant<std::vector<std::string>>>> 488099543e4SBrad Bishop interfacesAndProperties; 489099543e4SBrad Bishop sdbusplus::message::object_path _; 490099543e4SBrad Bishop message.read(_, interfacesAndProperties); 491099543e4SBrad Bishop return maybeCall(interfacesAndProperties, callback); 492099543e4SBrad Bishop } 493099543e4SBrad Bishop 494099543e4SBrad Bishop /** 495099543e4SBrad Bishop * @brief Determine system support for host firmware well-known names. 496099543e4SBrad Bishop * 497099543e4SBrad Bishop * Using the provided extensionMap and 498099543e4SBrad Bishop * xyz.openbmc_project.Configuration.IBMCompatibleSystem, determine if 499099543e4SBrad Bishop * well-known names for host firmare blob files are necessary and if so, create 500099543e4SBrad Bishop * them. 501099543e4SBrad Bishop * 502099543e4SBrad Bishop * @param[in] extensionMap a map of 503099543e4SBrad Bishop * xyz.openbmc_project.Configuration.IBMCompatibleSystem to host firmware blob 504099543e4SBrad Bishop * file extensions. 505099543e4SBrad Bishop * @param[in] hostFirmwareDirectory The directory in which findLinks should 506099543e4SBrad Bishop * look for host firmware blob files that need well-known names. 507099543e4SBrad Bishop * @param[in] ibmCompatibleSystem The names property of an instance of 508099543e4SBrad Bishop * xyz.openbmc_project.Configuration.IBMCompatibleSystem 509099543e4SBrad Bishop * @param[in] errorCallback A callback made in the event of filesystem errors. 510099543e4SBrad Bishop */ 511099543e4SBrad Bishop void maybeMakeLinks( 512099543e4SBrad Bishop const std::map<std::string, std::vector<std::string>>& extensionMap, 513099543e4SBrad Bishop const std::filesystem::path& hostFirmwareDirectory, 514099543e4SBrad Bishop const std::vector<std::string>& ibmCompatibleSystem, 515099543e4SBrad Bishop const ErrorCallbackType& errorCallback) 516099543e4SBrad Bishop { 517099543e4SBrad Bishop std::vector<std::string> extensions; 518099543e4SBrad Bishop if (getExtensionsForIbmCompatibleSystem(extensionMap, ibmCompatibleSystem, 519099543e4SBrad Bishop extensions)) 520099543e4SBrad Bishop { 521099543e4SBrad Bishop findLinks(hostFirmwareDirectory, extensions, errorCallback, writeLink); 522099543e4SBrad Bishop } 523099543e4SBrad Bishop } 524099543e4SBrad Bishop 525099543e4SBrad Bishop /** 52653a27395SAdriana Kobylak * @brief Determine system support for updating the bios attribute table. 52753a27395SAdriana Kobylak * 52853a27395SAdriana Kobylak * Using the provided extensionMap and 52953a27395SAdriana Kobylak * xyz.openbmc_project.Configuration.IBMCompatibleSystem, determine if the bios 53053a27395SAdriana Kobylak * attribute table needs to be updated. 53153a27395SAdriana Kobylak * 53253a27395SAdriana Kobylak * @param[in] extensionMap a map of 53353a27395SAdriana Kobylak * xyz.openbmc_project.Configuration.IBMCompatibleSystem to host firmware blob 53453a27395SAdriana Kobylak * file extensions. 535ae0998f1SAdriana Kobylak * @param[in] elementsJsonFilePath The file path to the json file 53653a27395SAdriana Kobylak * @param[in] ibmCompatibleSystem The names property of an instance of 53753a27395SAdriana Kobylak * xyz.openbmc_project.Configuration.IBMCompatibleSystem 53853a27395SAdriana Kobylak */ 53953a27395SAdriana Kobylak void maybeSetBiosAttr( 54053a27395SAdriana Kobylak const std::map<std::string, std::vector<std::string>>& extensionMap, 541ae0998f1SAdriana Kobylak const std::filesystem::path& elementsJsonFilePath, 54253a27395SAdriana Kobylak const std::vector<std::string>& ibmCompatibleSystem) 54353a27395SAdriana Kobylak { 54453a27395SAdriana Kobylak std::vector<std::string> extensions; 54553a27395SAdriana Kobylak if (getExtensionsForIbmCompatibleSystem(extensionMap, ibmCompatibleSystem, 54653a27395SAdriana Kobylak extensions)) 54753a27395SAdriana Kobylak { 548ae0998f1SAdriana Kobylak setBiosAttr(elementsJsonFilePath, extensions); 54953a27395SAdriana Kobylak } 55053a27395SAdriana Kobylak } 55153a27395SAdriana Kobylak 55253a27395SAdriana Kobylak /** 553099543e4SBrad Bishop * @brief process host firmware 554099543e4SBrad Bishop * 555099543e4SBrad Bishop * Allocate a callback context and register for DBus.ObjectManager Interfaces 556099543e4SBrad Bishop * added signals from entity manager. 557099543e4SBrad Bishop * 558099543e4SBrad Bishop * Check the current entity manager object tree for a 559099543e4SBrad Bishop * xyz.openbmc_project.Configuration.IBMCompatibleSystem instance (entity 560099543e4SBrad Bishop * manager will be dbus activated if it is not running). If one is found, 561099543e4SBrad Bishop * determine if symlinks need to be created and create them. Instruct the 562099543e4SBrad Bishop * program event loop to exit. 563099543e4SBrad Bishop * 564099543e4SBrad Bishop * If no instance of xyz.openbmc_project.Configuration.IBMCompatibleSystem is 565099543e4SBrad Bishop * found return the callback context to main, where the program will sleep 566099543e4SBrad Bishop * until the callback is invoked one or more times and instructs the program 567099543e4SBrad Bishop * event loop to exit when 568099543e4SBrad Bishop * xyz.openbmc_project.Configuration.IBMCompatibleSystem is added. 569099543e4SBrad Bishop * 570099543e4SBrad Bishop * @param[in] bus a DBus client connection 571099543e4SBrad Bishop * @param[in] extensionMap a map of 572099543e4SBrad Bishop * xyz.openbmc_project.Configuration.IBMCompatibleSystem to host firmware blob 573099543e4SBrad Bishop * file extensions. 574099543e4SBrad Bishop * @param[in] hostFirmwareDirectory The directory in which processHostFirmware 575099543e4SBrad Bishop * should look for blob files. 576099543e4SBrad Bishop * @param[in] errorCallback A callback made in the event of filesystem errors. 577099543e4SBrad Bishop * @param[in] loop a program event loop 578099543e4SBrad Bishop * @return nullptr if an instance of 579099543e4SBrad Bishop * xyz.openbmc_project.Configuration.IBMCompatibleSystem is found, otherwise a 580099543e4SBrad Bishop * pointer to an sdbusplus match object. 581099543e4SBrad Bishop */ 582099543e4SBrad Bishop std::shared_ptr<void> processHostFirmware( 583099543e4SBrad Bishop sdbusplus::bus::bus& bus, 584099543e4SBrad Bishop std::map<std::string, std::vector<std::string>> extensionMap, 585099543e4SBrad Bishop std::filesystem::path hostFirmwareDirectory, 586099543e4SBrad Bishop ErrorCallbackType errorCallback, sdeventplus::Event& loop) 587099543e4SBrad Bishop { 588099543e4SBrad Bishop // ownership of extensionMap, hostFirmwareDirectory and errorCallback can't 589099543e4SBrad Bishop // be transfered to the match callback because they are needed in the non 590099543e4SBrad Bishop // async part of this function below, so they need to be moved to the heap. 591099543e4SBrad Bishop auto pExtensionMap = 592099543e4SBrad Bishop std::make_shared<decltype(extensionMap)>(std::move(extensionMap)); 593099543e4SBrad Bishop auto pHostFirmwareDirectory = 594099543e4SBrad Bishop std::make_shared<decltype(hostFirmwareDirectory)>( 595099543e4SBrad Bishop std::move(hostFirmwareDirectory)); 596099543e4SBrad Bishop auto pErrorCallback = 597099543e4SBrad Bishop std::make_shared<decltype(errorCallback)>(std::move(errorCallback)); 598099543e4SBrad Bishop 599099543e4SBrad Bishop // register for a callback in case the IBMCompatibleSystem interface has 600099543e4SBrad Bishop // not yet been published by entity manager. 601099543e4SBrad Bishop auto interfacesAddedMatch = std::make_shared<sdbusplus::bus::match::match>( 602099543e4SBrad Bishop bus, 603099543e4SBrad Bishop sdbusplus::bus::match::rules::interfacesAdded() + 604099543e4SBrad Bishop sdbusplus::bus::match::rules::sender( 605099543e4SBrad Bishop "xyz.openbmc_project.EntityManager"), 606099543e4SBrad Bishop [pExtensionMap, pHostFirmwareDirectory, pErrorCallback, 607099543e4SBrad Bishop &loop](auto& message) { 608099543e4SBrad Bishop // bind the extension map, host firmware directory, and error 609099543e4SBrad Bishop // callback to the maybeMakeLinks function. 610099543e4SBrad Bishop auto maybeMakeLinksWithArgsBound = 611099543e4SBrad Bishop std::bind(maybeMakeLinks, std::cref(*pExtensionMap), 612099543e4SBrad Bishop std::cref(*pHostFirmwareDirectory), 613099543e4SBrad Bishop std::placeholders::_1, std::cref(*pErrorCallback)); 614099543e4SBrad Bishop 615099543e4SBrad Bishop // if the InterfacesAdded message contains an an instance of 616099543e4SBrad Bishop // xyz.openbmc_project.Configuration.IBMCompatibleSystem, check to 617099543e4SBrad Bishop // see if links are necessary on this system and if so, create 618099543e4SBrad Bishop // them. 619099543e4SBrad Bishop if (maybeCallMessage(message, maybeMakeLinksWithArgsBound)) 620099543e4SBrad Bishop { 621099543e4SBrad Bishop // The IBMCompatibleSystem interface was found and the links 622099543e4SBrad Bishop // were created if applicable. Instruct the event loop / 623099543e4SBrad Bishop // subcommand to exit. 624099543e4SBrad Bishop loop.exit(0); 625099543e4SBrad Bishop } 626099543e4SBrad Bishop }); 627099543e4SBrad Bishop 628099543e4SBrad Bishop // now that we'll get a callback in the event of an InterfacesAdded signal 629099543e4SBrad Bishop // (potentially containing 630099543e4SBrad Bishop // xyz.openbmc_project.Configuration.IBMCompatibleSystem), activate entity 631099543e4SBrad Bishop // manager if it isn't running and enumerate its objects 632099543e4SBrad Bishop auto getManagedObjects = bus.new_method_call( 633099543e4SBrad Bishop "xyz.openbmc_project.EntityManager", "/", 634099543e4SBrad Bishop "org.freedesktop.DBus.ObjectManager", "GetManagedObjects"); 635099543e4SBrad Bishop std::map<std::string, 636099543e4SBrad Bishop std::map<std::string, std::variant<std::vector<std::string>>>> 637099543e4SBrad Bishop interfacesAndProperties; 638099543e4SBrad Bishop std::map<sdbusplus::message::object_path, decltype(interfacesAndProperties)> 639099543e4SBrad Bishop objects; 640c79fa915SAdriana Kobylak try 641c79fa915SAdriana Kobylak { 642c79fa915SAdriana Kobylak auto reply = bus.call(getManagedObjects); 643099543e4SBrad Bishop reply.read(objects); 644c79fa915SAdriana Kobylak } 645c79fa915SAdriana Kobylak catch (const sdbusplus::exception::SdBusError& e) 646c79fa915SAdriana Kobylak { 647c79fa915SAdriana Kobylak // Error querying the EntityManager interface. Return the match to have 648c79fa915SAdriana Kobylak // the callback run if/when the interface appears in D-Bus. 649c79fa915SAdriana Kobylak return interfacesAddedMatch; 650c79fa915SAdriana Kobylak } 651099543e4SBrad Bishop 652099543e4SBrad Bishop // bind the extension map, host firmware directory, and error callback to 653099543e4SBrad Bishop // the maybeMakeLinks function. 654099543e4SBrad Bishop auto maybeMakeLinksWithArgsBound = 655099543e4SBrad Bishop std::bind(maybeMakeLinks, std::cref(*pExtensionMap), 656099543e4SBrad Bishop std::cref(*pHostFirmwareDirectory), std::placeholders::_1, 657099543e4SBrad Bishop std::cref(*pErrorCallback)); 658099543e4SBrad Bishop 659099543e4SBrad Bishop for (const auto& pair : objects) 660099543e4SBrad Bishop { 661099543e4SBrad Bishop std::tie(std::ignore, interfacesAndProperties) = pair; 662099543e4SBrad Bishop // if interfacesAndProperties contains an an instance of 663099543e4SBrad Bishop // xyz.openbmc_project.Configuration.IBMCompatibleSystem, check to see 664099543e4SBrad Bishop // if links are necessary on this system and if so, create them 665099543e4SBrad Bishop if (maybeCall(interfacesAndProperties, maybeMakeLinksWithArgsBound)) 666099543e4SBrad Bishop { 667099543e4SBrad Bishop // The IBMCompatibleSystem interface is already on the bus and the 668099543e4SBrad Bishop // links were created if applicable. Instruct the event loop to 669099543e4SBrad Bishop // exit. 670099543e4SBrad Bishop loop.exit(0); 671099543e4SBrad Bishop // The match object isn't needed anymore, so destroy it on return. 672099543e4SBrad Bishop return nullptr; 673099543e4SBrad Bishop } 674099543e4SBrad Bishop } 675099543e4SBrad Bishop 676099543e4SBrad Bishop // The IBMCompatibleSystem interface has not yet been published. Move 677099543e4SBrad Bishop // ownership of the match callback to the caller. 678099543e4SBrad Bishop return interfacesAddedMatch; 679099543e4SBrad Bishop } 68053a27395SAdriana Kobylak 68153a27395SAdriana Kobylak /** 68253a27395SAdriana Kobylak * @brief Update the Bios Attribute Table 68353a27395SAdriana Kobylak * 68453a27395SAdriana Kobylak * If an instance of xyz.openbmc_project.Configuration.IBMCompatibleSystem is 68553a27395SAdriana Kobylak * found, update the Bios Attribute Table with the appropriate host firmware 68653a27395SAdriana Kobylak * data. 68753a27395SAdriana Kobylak * 68853a27395SAdriana Kobylak * @param[in] bus - D-Bus client connection. 68953a27395SAdriana Kobylak * @param[in] extensionMap - Map of IBMCompatibleSystem names and host firmware 69053a27395SAdriana Kobylak * file extensions. 691ae0998f1SAdriana Kobylak * @param[in] elementsJsonFilePath - The Path to the json file 69253a27395SAdriana Kobylak * @param[in] loop - Program event loop. 69353a27395SAdriana Kobylak * @return nullptr 69453a27395SAdriana Kobylak */ 695*ebf67bf7SAdriana Kobylak std::vector<std::shared_ptr<void>> updateBiosAttrTable( 69653a27395SAdriana Kobylak sdbusplus::bus::bus& bus, 69753a27395SAdriana Kobylak std::map<std::string, std::vector<std::string>> extensionMap, 698ae0998f1SAdriana Kobylak std::filesystem::path elementsJsonFilePath, sdeventplus::Event& loop) 69953a27395SAdriana Kobylak { 700d0379ea5SAdriana Kobylak constexpr auto pldmPath = "/xyz/openbmc_project/pldm"; 701*ebf67bf7SAdriana Kobylak constexpr auto entityManagerServiceName = 702*ebf67bf7SAdriana Kobylak "xyz.openbmc_project.EntityManager"; 703d0379ea5SAdriana Kobylak 70453a27395SAdriana Kobylak auto pExtensionMap = 70553a27395SAdriana Kobylak std::make_shared<decltype(extensionMap)>(std::move(extensionMap)); 706ae0998f1SAdriana Kobylak auto pElementsJsonFilePath = 707ae0998f1SAdriana Kobylak std::make_shared<decltype(elementsJsonFilePath)>( 708ae0998f1SAdriana Kobylak std::move(elementsJsonFilePath)); 70953a27395SAdriana Kobylak 710d0379ea5SAdriana Kobylak // Entity Manager is needed to get the list of supported extensions. Add a 711d0379ea5SAdriana Kobylak // match to monitor interfaces added in case it's not running yet. 712d0379ea5SAdriana Kobylak auto maybeSetAttrWithArgsBound = 713d0379ea5SAdriana Kobylak std::bind(maybeSetBiosAttr, std::cref(*pExtensionMap), 714d0379ea5SAdriana Kobylak std::cref(*pElementsJsonFilePath), std::placeholders::_1); 715d0379ea5SAdriana Kobylak 716*ebf67bf7SAdriana Kobylak std::vector<std::shared_ptr<void>> matches; 717*ebf67bf7SAdriana Kobylak matches.emplace_back(std::make_shared<sdbusplus::bus::match::match>( 718d0379ea5SAdriana Kobylak bus, 719d0379ea5SAdriana Kobylak sdbusplus::bus::match::rules::interfacesAdded() + 720d0379ea5SAdriana Kobylak sdbusplus::bus::match::rules::sender( 721d0379ea5SAdriana Kobylak "xyz.openbmc_project.EntityManager"), 722d0379ea5SAdriana Kobylak [pldmPath, pExtensionMap, pElementsJsonFilePath, 723d0379ea5SAdriana Kobylak maybeSetAttrWithArgsBound, &loop](auto& message) { 724d0379ea5SAdriana Kobylak auto bus = sdbusplus::bus::new_default(); 725fd4a6088SAdriana Kobylak auto pldmObject = getObject(bus, pldmPath); 726fd4a6088SAdriana Kobylak if (pldmObject.empty()) 727fd4a6088SAdriana Kobylak { 728d0379ea5SAdriana Kobylak return; 729d0379ea5SAdriana Kobylak } 730d0379ea5SAdriana Kobylak if (maybeCallMessage(message, maybeSetAttrWithArgsBound)) 731d0379ea5SAdriana Kobylak { 732fd4a6088SAdriana Kobylak loop.exit(0); 733d0379ea5SAdriana Kobylak } 734*ebf67bf7SAdriana Kobylak })); 735*ebf67bf7SAdriana Kobylak matches.emplace_back(std::make_shared<sdbusplus::bus::match::match>( 736*ebf67bf7SAdriana Kobylak bus, 737*ebf67bf7SAdriana Kobylak sdbusplus::bus::match::rules::nameOwnerChanged() + 738*ebf67bf7SAdriana Kobylak sdbusplus::bus::match::rules::arg0namespace( 739*ebf67bf7SAdriana Kobylak "xyz.openbmc_project.PLDM"), 740*ebf67bf7SAdriana Kobylak [pExtensionMap, pElementsJsonFilePath, maybeSetAttrWithArgsBound, 741*ebf67bf7SAdriana Kobylak &loop](auto& message) { 742*ebf67bf7SAdriana Kobylak std::string name; 743*ebf67bf7SAdriana Kobylak std::string oldOwner; 744*ebf67bf7SAdriana Kobylak std::string newOwner; 745*ebf67bf7SAdriana Kobylak message.read(name, oldOwner, newOwner); 746*ebf67bf7SAdriana Kobylak 747*ebf67bf7SAdriana Kobylak if (newOwner.empty()) 748*ebf67bf7SAdriana Kobylak { 749*ebf67bf7SAdriana Kobylak return; 750*ebf67bf7SAdriana Kobylak } 751*ebf67bf7SAdriana Kobylak 752*ebf67bf7SAdriana Kobylak auto bus = sdbusplus::bus::new_default(); 753*ebf67bf7SAdriana Kobylak InterfacesPropertiesMap interfacesAndProperties; 754*ebf67bf7SAdriana Kobylak auto objects = getManagedObjects(bus, entityManagerServiceName); 755*ebf67bf7SAdriana Kobylak for (const auto& pair : objects) 756*ebf67bf7SAdriana Kobylak { 757*ebf67bf7SAdriana Kobylak std::tie(std::ignore, interfacesAndProperties) = pair; 758*ebf67bf7SAdriana Kobylak if (maybeCall(interfacesAndProperties, 759*ebf67bf7SAdriana Kobylak maybeSetAttrWithArgsBound)) 760*ebf67bf7SAdriana Kobylak { 761*ebf67bf7SAdriana Kobylak loop.exit(0); 762*ebf67bf7SAdriana Kobylak } 763*ebf67bf7SAdriana Kobylak } 764*ebf67bf7SAdriana Kobylak })); 765d0379ea5SAdriana Kobylak 766d0379ea5SAdriana Kobylak // The BIOS attribute table can only be updated if PLDM is running because 767d0379ea5SAdriana Kobylak // PLDM is the one that exposes this property. Return if it's not running. 768d0379ea5SAdriana Kobylak auto pldmObject = getObject(bus, pldmPath); 769d0379ea5SAdriana Kobylak if (pldmObject.empty()) 770d0379ea5SAdriana Kobylak { 771*ebf67bf7SAdriana Kobylak return matches; 772fd4a6088SAdriana Kobylak } 773fd4a6088SAdriana Kobylak 774*ebf67bf7SAdriana Kobylak InterfacesPropertiesMap interfacesAndProperties; 775*ebf67bf7SAdriana Kobylak auto objects = getManagedObjects(bus, entityManagerServiceName); 77653a27395SAdriana Kobylak for (const auto& pair : objects) 77753a27395SAdriana Kobylak { 77853a27395SAdriana Kobylak std::tie(std::ignore, interfacesAndProperties) = pair; 77953a27395SAdriana Kobylak if (maybeCall(interfacesAndProperties, maybeSetAttrWithArgsBound)) 78053a27395SAdriana Kobylak { 781d0379ea5SAdriana Kobylak loop.exit(0); 782*ebf67bf7SAdriana Kobylak return {}; 78353a27395SAdriana Kobylak } 78453a27395SAdriana Kobylak } 78553a27395SAdriana Kobylak 786*ebf67bf7SAdriana Kobylak return matches; 78753a27395SAdriana Kobylak } 78853a27395SAdriana Kobylak 789099543e4SBrad Bishop } // namespace process_hostfirmware 790099543e4SBrad Bishop } // namespace functions 791