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 | { |
Riya Dixit | 754041d | 2024-02-20 06:15:49 -0600 | [diff] [blame] | 23 | pldm::utils::ObjectValueTree objects; |
Tom Joseph | fb3bc06 | 2021-08-17 07:48:11 -0700 | [diff] [blame] | 24 | |
| 25 | try |
| 26 | { |
Riya Dixit | 754041d | 2024-02-20 06:15:49 -0600 | [diff] [blame] | 27 | objects = pldm::utils::DBusHandler::getManagedObj(MCTPService, |
| 28 | MCTPPath); |
Tom Joseph | fb3bc06 | 2021-08-17 07:48:11 -0700 | [diff] [blame] | 29 | } |
| 30 | catch (const std::exception& e) |
| 31 | { |
Kamalkumar Patel | 58cbcaf | 2023-10-06 03:48:25 -0500 | [diff] [blame] | 32 | error("Failed to call the D-Bus Method: {ERROR}", "ERROR", e); |
Tom Joseph | fb3bc06 | 2021-08-17 07:48:11 -0700 | [diff] [blame] | 33 | return; |
| 34 | } |
| 35 | |
| 36 | std::vector<mctp_eid_t> eids; |
| 37 | |
| 38 | for (const auto& [objectPath, interfaces] : objects) |
| 39 | { |
| 40 | for (const auto& [intfName, properties] : interfaces) |
| 41 | { |
| 42 | if (intfName == mctpEndpointIntfName) |
| 43 | { |
| 44 | if (properties.contains("EID") && |
| 45 | properties.contains("SupportedMessageTypes")) |
| 46 | { |
Delphine CC Chiu | c00594e | 2023-04-19 11:13:17 +0800 | [diff] [blame] | 47 | auto eid = std::get<mctp_eid_t>(properties.at("EID")); |
Tom Joseph | fb3bc06 | 2021-08-17 07:48:11 -0700 | [diff] [blame] | 48 | auto types = std::get<std::vector<uint8_t>>( |
| 49 | properties.at("SupportedMessageTypes")); |
| 50 | if (std::find(types.begin(), types.end(), mctpTypePLDM) != |
| 51 | types.end()) |
| 52 | { |
| 53 | eids.emplace_back(eid); |
| 54 | } |
| 55 | } |
| 56 | } |
| 57 | } |
| 58 | } |
| 59 | |
| 60 | if (eids.size() && fwManager) |
| 61 | { |
| 62 | fwManager->handleMCTPEndpoints(eids); |
| 63 | } |
| 64 | } |
| 65 | |
Patrick Williams | 84b790c | 2022-07-22 19:26:56 -0500 | [diff] [blame] | 66 | void MctpDiscovery::dicoverEndpoints(sdbusplus::message_t& msg) |
Tom Joseph | fb3bc06 | 2021-08-17 07:48:11 -0700 | [diff] [blame] | 67 | { |
| 68 | constexpr std::string_view mctpEndpointIntfName{ |
| 69 | "xyz.openbmc_project.MCTP.Endpoint"}; |
| 70 | std::vector<mctp_eid_t> eids; |
| 71 | |
| 72 | sdbusplus::message::object_path objPath; |
| 73 | std::map<std::string, std::map<std::string, dbus::Value>> interfaces; |
| 74 | msg.read(objPath, interfaces); |
| 75 | |
| 76 | for (const auto& [intfName, properties] : interfaces) |
| 77 | { |
| 78 | if (intfName == mctpEndpointIntfName) |
| 79 | { |
| 80 | if (properties.contains("EID") && |
| 81 | properties.contains("SupportedMessageTypes")) |
| 82 | { |
Dung Cao | 66794d0 | 2023-10-25 04:06:23 +0000 | [diff] [blame] | 83 | auto eid = std::get<mctp_eid_t>(properties.at("EID")); |
Tom Joseph | fb3bc06 | 2021-08-17 07:48:11 -0700 | [diff] [blame] | 84 | auto types = std::get<std::vector<uint8_t>>( |
| 85 | properties.at("SupportedMessageTypes")); |
| 86 | if (std::find(types.begin(), types.end(), mctpTypePLDM) != |
| 87 | types.end()) |
| 88 | { |
| 89 | eids.emplace_back(eid); |
| 90 | } |
| 91 | } |
| 92 | } |
| 93 | } |
| 94 | |
| 95 | if (eids.size() && fwManager) |
| 96 | { |
| 97 | fwManager->handleMCTPEndpoints(eids); |
| 98 | } |
| 99 | } |
| 100 | |
Andrew Jeffery | 27a022c | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 101 | } // namespace pldm |