Tom Joseph | fb3bc06 | 2021-08-17 07:48:11 -0700 | [diff] [blame] | 1 | #include "mctp_endpoint_discovery.hpp" |
| 2 | |
Tom Joseph | fb3bc06 | 2021-08-17 07:48:11 -0700 | [diff] [blame] | 3 | #include "common/types.hpp" |
| 4 | #include "common/utils.hpp" |
| 5 | |
| 6 | #include <algorithm> |
| 7 | #include <map> |
| 8 | #include <string> |
| 9 | #include <string_view> |
| 10 | #include <vector> |
| 11 | |
| 12 | namespace pldm |
| 13 | { |
Patrick Williams | 84b790c | 2022-07-22 19:26:56 -0500 | [diff] [blame] | 14 | MctpDiscovery::MctpDiscovery(sdbusplus::bus_t& bus, |
Tom Joseph | fb3bc06 | 2021-08-17 07:48:11 -0700 | [diff] [blame] | 15 | fw_update::Manager* fwManager) : |
| 16 | bus(bus), |
| 17 | fwManager(fwManager), |
| 18 | mctpEndpointSignal(bus, |
| 19 | sdbusplus::bus::match::rules::interfacesAdded( |
| 20 | "/xyz/openbmc_project/mctp"), |
| 21 | std::bind_front(&MctpDiscovery::dicoverEndpoints, this)) |
| 22 | { |
| 23 | dbus::ObjectValueTree objects; |
| 24 | |
| 25 | try |
| 26 | { |
| 27 | auto method = bus.new_method_call( |
Delphine CC Chiu | c00594e | 2023-04-19 11:13:17 +0800 | [diff] [blame] | 28 | "xyz.openbmc_project.MCTP", "/xyz/openbmc_project/mctp", |
Tom Joseph | fb3bc06 | 2021-08-17 07:48:11 -0700 | [diff] [blame] | 29 | "org.freedesktop.DBus.ObjectManager", "GetManagedObjects"); |
vkaverap@in.ibm.com | 91a092f | 2023-09-18 23:39:44 -0500 | [diff] [blame] | 30 | auto reply = bus.call(method, dbusTimeout); |
Tom Joseph | fb3bc06 | 2021-08-17 07:48:11 -0700 | [diff] [blame] | 31 | reply.read(objects); |
| 32 | } |
| 33 | catch (const std::exception& e) |
| 34 | { |
| 35 | return; |
| 36 | } |
| 37 | |
| 38 | std::vector<mctp_eid_t> eids; |
| 39 | |
| 40 | for (const auto& [objectPath, interfaces] : objects) |
| 41 | { |
| 42 | for (const auto& [intfName, properties] : interfaces) |
| 43 | { |
| 44 | if (intfName == mctpEndpointIntfName) |
| 45 | { |
| 46 | if (properties.contains("EID") && |
| 47 | properties.contains("SupportedMessageTypes")) |
| 48 | { |
Delphine CC Chiu | c00594e | 2023-04-19 11:13:17 +0800 | [diff] [blame] | 49 | auto eid = std::get<mctp_eid_t>(properties.at("EID")); |
Tom Joseph | fb3bc06 | 2021-08-17 07:48:11 -0700 | [diff] [blame] | 50 | auto types = std::get<std::vector<uint8_t>>( |
| 51 | properties.at("SupportedMessageTypes")); |
| 52 | if (std::find(types.begin(), types.end(), mctpTypePLDM) != |
| 53 | types.end()) |
| 54 | { |
| 55 | eids.emplace_back(eid); |
| 56 | } |
| 57 | } |
| 58 | } |
| 59 | } |
| 60 | } |
| 61 | |
| 62 | if (eids.size() && fwManager) |
| 63 | { |
| 64 | fwManager->handleMCTPEndpoints(eids); |
| 65 | } |
| 66 | } |
| 67 | |
Patrick Williams | 84b790c | 2022-07-22 19:26:56 -0500 | [diff] [blame] | 68 | void MctpDiscovery::dicoverEndpoints(sdbusplus::message_t& msg) |
Tom Joseph | fb3bc06 | 2021-08-17 07:48:11 -0700 | [diff] [blame] | 69 | { |
| 70 | constexpr std::string_view mctpEndpointIntfName{ |
| 71 | "xyz.openbmc_project.MCTP.Endpoint"}; |
| 72 | std::vector<mctp_eid_t> eids; |
| 73 | |
| 74 | sdbusplus::message::object_path objPath; |
| 75 | std::map<std::string, std::map<std::string, dbus::Value>> interfaces; |
| 76 | msg.read(objPath, interfaces); |
| 77 | |
| 78 | for (const auto& [intfName, properties] : interfaces) |
| 79 | { |
| 80 | if (intfName == mctpEndpointIntfName) |
| 81 | { |
| 82 | if (properties.contains("EID") && |
| 83 | properties.contains("SupportedMessageTypes")) |
| 84 | { |
Dung Cao | 66794d0 | 2023-10-25 04:06:23 +0000 | [diff] [blame] | 85 | auto eid = std::get<mctp_eid_t>(properties.at("EID")); |
Tom Joseph | fb3bc06 | 2021-08-17 07:48:11 -0700 | [diff] [blame] | 86 | auto types = std::get<std::vector<uint8_t>>( |
| 87 | properties.at("SupportedMessageTypes")); |
| 88 | if (std::find(types.begin(), types.end(), mctpTypePLDM) != |
| 89 | types.end()) |
| 90 | { |
| 91 | eids.emplace_back(eid); |
| 92 | } |
| 93 | } |
| 94 | } |
| 95 | } |
| 96 | |
| 97 | if (eids.size() && fwManager) |
| 98 | { |
| 99 | fwManager->handleMCTPEndpoints(eids); |
| 100 | } |
| 101 | } |
| 102 | |
Andrew Jeffery | 27a022c | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 103 | } // namespace pldm |