#include "mctp_endpoint_discovery.hpp" #include "common/types.hpp" #include "common/utils.hpp" #include #include #include #include #include #include namespace pldm { MctpDiscovery::MctpDiscovery(sdbusplus::bus_t& bus, fw_update::Manager* fwManager) : bus(bus), fwManager(fwManager), mctpEndpointSignal(bus, sdbusplus::bus::match::rules::interfacesAdded( "/xyz/openbmc_project/mctp"), std::bind_front(&MctpDiscovery::dicoverEndpoints, this)) { dbus::ObjectValueTree objects; try { auto method = bus.new_method_call( "xyz.openbmc_project.MCTP.Control", "/xyz/openbmc_project/mctp", "org.freedesktop.DBus.ObjectManager", "GetManagedObjects"); auto reply = bus.call( method, std::chrono::duration_cast(sec(DBUS_TIMEOUT)).count()); reply.read(objects); } catch (const std::exception& e) { return; } std::vector eids; for (const auto& [objectPath, interfaces] : objects) { for (const auto& [intfName, properties] : interfaces) { if (intfName == mctpEndpointIntfName) { if (properties.contains("EID") && properties.contains("SupportedMessageTypes")) { auto eid = std::get(properties.at("EID")); auto types = std::get>( properties.at("SupportedMessageTypes")); if (std::find(types.begin(), types.end(), mctpTypePLDM) != types.end()) { eids.emplace_back(eid); } } } } } if (eids.size() && fwManager) { fwManager->handleMCTPEndpoints(eids); } } void MctpDiscovery::dicoverEndpoints(sdbusplus::message_t& msg) { constexpr std::string_view mctpEndpointIntfName{ "xyz.openbmc_project.MCTP.Endpoint"}; std::vector eids; sdbusplus::message::object_path objPath; std::map> interfaces; msg.read(objPath, interfaces); for (const auto& [intfName, properties] : interfaces) { if (intfName == mctpEndpointIntfName) { if (properties.contains("EID") && properties.contains("SupportedMessageTypes")) { auto eid = std::get(properties.at("EID")); auto types = std::get>( properties.at("SupportedMessageTypes")); if (std::find(types.begin(), types.end(), mctpTypePLDM) != types.end()) { eids.emplace_back(eid); } } } } if (eids.size() && fwManager) { fwManager->handleMCTPEndpoints(eids); } } } // namespace pldm