blob: bc50ee563c9ca0ac40c9175f9e29fabd654f3f76 [file] [log] [blame]
Tom Josephfb3bc062021-08-17 07:48:11 -07001#include "mctp_endpoint_discovery.hpp"
2
Tom Josephfb3bc062021-08-17 07:48:11 -07003#include "common/types.hpp"
4#include "common/utils.hpp"
5
George Liuc453e162022-12-21 17:16:23 +08006#include <libpldm/pldm.h>
7
Tom Josephfb3bc062021-08-17 07:48:11 -07008#include <algorithm>
9#include <map>
10#include <string>
11#include <string_view>
12#include <vector>
13
14namespace pldm
15{
Patrick Williams84b790c2022-07-22 19:26:56 -050016MctpDiscovery::MctpDiscovery(sdbusplus::bus_t& bus,
Tom Josephfb3bc062021-08-17 07:48:11 -070017 fw_update::Manager* fwManager) :
18 bus(bus),
19 fwManager(fwManager),
20 mctpEndpointSignal(bus,
21 sdbusplus::bus::match::rules::interfacesAdded(
22 "/xyz/openbmc_project/mctp"),
23 std::bind_front(&MctpDiscovery::dicoverEndpoints, this))
24{
25 dbus::ObjectValueTree objects;
26
27 try
28 {
29 auto method = bus.new_method_call(
Delphine CC Chiuc00594e2023-04-19 11:13:17 +080030 "xyz.openbmc_project.MCTP", "/xyz/openbmc_project/mctp",
Tom Josephfb3bc062021-08-17 07:48:11 -070031 "org.freedesktop.DBus.ObjectManager", "GetManagedObjects");
vkaverap@in.ibm.com91a092f2023-09-18 23:39:44 -050032 auto reply = bus.call(method, dbusTimeout);
Tom Josephfb3bc062021-08-17 07:48:11 -070033 reply.read(objects);
34 }
35 catch (const std::exception& e)
36 {
37 return;
38 }
39
40 std::vector<mctp_eid_t> eids;
41
42 for (const auto& [objectPath, interfaces] : objects)
43 {
44 for (const auto& [intfName, properties] : interfaces)
45 {
46 if (intfName == mctpEndpointIntfName)
47 {
48 if (properties.contains("EID") &&
49 properties.contains("SupportedMessageTypes"))
50 {
Delphine CC Chiuc00594e2023-04-19 11:13:17 +080051 auto eid = std::get<mctp_eid_t>(properties.at("EID"));
Tom Josephfb3bc062021-08-17 07:48:11 -070052 auto types = std::get<std::vector<uint8_t>>(
53 properties.at("SupportedMessageTypes"));
54 if (std::find(types.begin(), types.end(), mctpTypePLDM) !=
55 types.end())
56 {
57 eids.emplace_back(eid);
58 }
59 }
60 }
61 }
62 }
63
64 if (eids.size() && fwManager)
65 {
66 fwManager->handleMCTPEndpoints(eids);
67 }
68}
69
Patrick Williams84b790c2022-07-22 19:26:56 -050070void MctpDiscovery::dicoverEndpoints(sdbusplus::message_t& msg)
Tom Josephfb3bc062021-08-17 07:48:11 -070071{
72 constexpr std::string_view mctpEndpointIntfName{
73 "xyz.openbmc_project.MCTP.Endpoint"};
74 std::vector<mctp_eid_t> eids;
75
76 sdbusplus::message::object_path objPath;
77 std::map<std::string, std::map<std::string, dbus::Value>> interfaces;
78 msg.read(objPath, interfaces);
79
80 for (const auto& [intfName, properties] : interfaces)
81 {
82 if (intfName == mctpEndpointIntfName)
83 {
84 if (properties.contains("EID") &&
85 properties.contains("SupportedMessageTypes"))
86 {
87 auto eid = std::get<size_t>(properties.at("EID"));
88 auto types = std::get<std::vector<uint8_t>>(
89 properties.at("SupportedMessageTypes"));
90 if (std::find(types.begin(), types.end(), mctpTypePLDM) !=
91 types.end())
92 {
93 eids.emplace_back(eid);
94 }
95 }
96 }
97 }
98
99 if (eids.size() && fwManager)
100 {
101 fwManager->handleMCTPEndpoints(eids);
102 }
103}
104
Andrew Jeffery27a022c2022-08-10 23:12:49 +0930105} // namespace pldm