1 #pragma once 2 3 #include "common/types.hpp" 4 #include "common/utils.hpp" 5 6 #include <libpldm/pldm.h> 7 8 #include <sdbusplus/bus/match.hpp> 9 10 #include <filesystem> 11 #include <initializer_list> 12 #include <vector> 13 14 namespace pldm 15 { 16 17 const std::string emptyUUID = "00000000-0000-0000-0000-000000000000"; 18 constexpr const char* MCTPService = "au.com.codeconstruct.MCTP1"; 19 constexpr const char* MCTPInterface = "xyz.openbmc_project.MCTP.Endpoint"; 20 constexpr const char* EndpointUUID = "xyz.openbmc_project.Common.UUID"; 21 constexpr const char* MCTPPath = "/au/com/codeconstruct/mctp1"; 22 23 /** @class MctpDiscoveryHandlerIntf 24 * 25 * This abstract class defines the APIs for MctpDiscovery class has common 26 * interface to execute function from different Manager Classes 27 */ 28 class MctpDiscoveryHandlerIntf 29 { 30 public: 31 virtual void handleMctpEndpoints(const MctpInfos& mctpInfos) = 0; 32 virtual void handleRemovedMctpEndpoints(const MctpInfos& mctpInfos) = 0; ~MctpDiscoveryHandlerIntf()33 virtual ~MctpDiscoveryHandlerIntf() {} 34 }; 35 36 class MctpDiscovery 37 { 38 public: 39 MctpDiscovery() = delete; 40 MctpDiscovery(const MctpDiscovery&) = delete; 41 MctpDiscovery(MctpDiscovery&&) = delete; 42 MctpDiscovery& operator=(const MctpDiscovery&) = delete; 43 MctpDiscovery& operator=(MctpDiscovery&&) = delete; 44 ~MctpDiscovery() = default; 45 46 /** @brief Constructs the MCTP Discovery object to handle discovery of 47 * MCTP enabled devices 48 * 49 * @param[in] bus - reference to systemd bus 50 * @param[in] list - initializer list to the MctpDiscoveryHandlerIntf 51 */ 52 explicit MctpDiscovery( 53 sdbusplus::bus_t& bus, 54 std::initializer_list<MctpDiscoveryHandlerIntf*> list); 55 56 /** @brief reference to the systemd bus */ 57 sdbusplus::bus_t& bus; 58 59 /** @brief Used to watch for new MCTP endpoints */ 60 sdbusplus::bus::match_t mctpEndpointAddedSignal; 61 62 /** @brief Used to watch for the removed MCTP endpoints */ 63 sdbusplus::bus::match_t mctpEndpointRemovedSignal; 64 65 /** @brief List of handlers need to notify when new MCTP 66 * Endpoint is Added/Removed */ 67 std::vector<MctpDiscoveryHandlerIntf*> handlers; 68 69 /** @brief The existing MCTP endpoints */ 70 MctpInfos existingMctpInfos; 71 72 /** @brief Callback function when MCTP endpoints addedInterface 73 * D-Bus signal raised. 74 * 75 * @param[in] msg - Data associated with subscribed signal 76 */ 77 void discoverEndpoints(sdbusplus::message_t& msg); 78 79 /** @brief Callback function when MCTP endpoint removedInterface 80 * D-Bus signal raised. 81 * 82 * @param[in] msg - Data associated with subscribed signal 83 */ 84 void removeEndpoints(sdbusplus::message_t& msg); 85 86 /** @brief Helper function to invoke registered handlers for 87 * the added MCTP endpoints 88 * 89 * @param[in] mctpInfos - information of discovered MCTP endpoints 90 */ 91 void handleMctpEndpoints(const MctpInfos& mctpInfos); 92 93 /** @brief Helper function to invoke registered handlers for 94 * the removed MCTP endpoints 95 * 96 * @param[in] mctpInfos - information of removed MCTP endpoints 97 */ 98 void handleRemovedMctpEndpoints(const MctpInfos& mctpInfos); 99 100 /** @brief Get list of MctpInfos in MCTP control interface. 101 * 102 * @param[in] mctpInfos - information of discovered MCTP endpoints 103 */ 104 void getMctpInfos(MctpInfos& mctpInfos); 105 106 /** @brief Get list of new MctpInfos in addedInterace D-Bus signal message. 107 * 108 * @param[in] msg - addedInterace D-Bus signal message 109 * @param[in] mctpInfos - information of added MCTP endpoints 110 */ 111 void getAddedMctpInfos(sdbusplus::message_t& msg, MctpInfos& mctpInfos); 112 113 /** @brief Add new MctpInfos to existingMctpInfos. 114 * 115 * @param[in] mctpInfos - information of new MCTP endpoints 116 */ 117 void addToExistingMctpInfos(const MctpInfos& mctpInfos); 118 119 /** @brief Erase the removed MCTP endpoint from existingMctpInfos. 120 * 121 * @param[in] mctpInfos - the remaining MCTP endpoints 122 * @param[out] removedInfos - the removed MCTP endpoints 123 */ 124 void removeFromExistingMctpInfos(MctpInfos& mctpInfos, 125 MctpInfos& removedInfos); 126 127 private: 128 /** @brief Get MCTP Endpoint D-Bus Properties in the 129 * `xyz.openbmc_project.MCTP.Endpoint` D-Bus interface 130 * 131 * @param[in] service - the MCTP service name 132 * @param[in] path - the MCTP endpoints object path 133 * 134 * @return tuple of Network Index, Endpoint ID and MCTP message types 135 */ 136 MctpEndpointProps getMctpEndpointProps(const std::string& service, 137 const std::string& path); 138 139 /** @brief Get Endpoint UUID from `UUID` D-Bus property in the 140 * `xyz.openbmc_project.Common.UUID` D-Bus interface. 141 * 142 * @param[in] service - the MCTP service name 143 * @param[in] path - the MCTP endpoints object path 144 * 145 * @return Endpoint UUID 146 */ 147 UUID getEndpointUUIDProp(const std::string& service, 148 const std::string& path); 149 150 static constexpr uint8_t mctpTypePLDM = 1; 151 }; 152 153 } // namespace pldm 154