Tom Joseph | fb3bc06 | 2021-08-17 07:48:11 -0700 | [diff] [blame] | 1 | #pragma once |
| 2 | |
Gilbert Chen | 44524a5 | 2022-02-14 12:12:25 +0000 | [diff] [blame] | 3 | #include "common/types.hpp" |
| 4 | #include "common/utils.hpp" |
| 5 | |
| 6 | #include <libpldm/pldm.h> |
Tom Joseph | fb3bc06 | 2021-08-17 07:48:11 -0700 | [diff] [blame] | 7 | |
| 8 | #include <sdbusplus/bus/match.hpp> |
| 9 | |
Gilbert Chen | 44524a5 | 2022-02-14 12:12:25 +0000 | [diff] [blame] | 10 | #include <filesystem> |
| 11 | #include <initializer_list> |
| 12 | #include <vector> |
| 13 | |
Tom Joseph | fb3bc06 | 2021-08-17 07:48:11 -0700 | [diff] [blame] | 14 | namespace pldm |
| 15 | { |
| 16 | |
Gilbert Chen | 44524a5 | 2022-02-14 12:12:25 +0000 | [diff] [blame] | 17 | const std::string emptyUUID = "00000000-0000-0000-0000-000000000000"; |
| 18 | constexpr const char* MCTPService = "xyz.openbmc_project.MCTP"; |
| 19 | constexpr const char* MCTPInterface = "xyz.openbmc_project.MCTP.Endpoint"; |
Thu Nguyen | 9027497 | 2024-07-17 07:02:16 +0000 | [diff] [blame] | 20 | constexpr const char* EndpointUUID = "xyz.openbmc_project.Common.UUID"; |
Gilbert Chen | 44524a5 | 2022-02-14 12:12:25 +0000 | [diff] [blame] | 21 | constexpr const char* MCTPPath = "/xyz/openbmc_project/mctp"; |
| 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; |
| 33 | virtual ~MctpDiscoveryHandlerIntf() {} |
| 34 | }; |
Riya Dixit | 754041d | 2024-02-20 06:15:49 -0600 | [diff] [blame] | 35 | |
Tom Joseph | fb3bc06 | 2021-08-17 07:48:11 -0700 | [diff] [blame] | 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 |
Gilbert Chen | 44524a5 | 2022-02-14 12:12:25 +0000 | [diff] [blame] | 50 | * @param[in] list - initializer list to the MctpDiscoveryHandlerIntf |
Tom Joseph | fb3bc06 | 2021-08-17 07:48:11 -0700 | [diff] [blame] | 51 | */ |
Gilbert Chen | 44524a5 | 2022-02-14 12:12:25 +0000 | [diff] [blame] | 52 | explicit MctpDiscovery( |
Patrick Williams | ba741d5 | 2024-05-08 02:32:10 -0500 | [diff] [blame] | 53 | sdbusplus::bus_t& bus, |
Gilbert Chen | 44524a5 | 2022-02-14 12:12:25 +0000 | [diff] [blame] | 54 | std::initializer_list<MctpDiscoveryHandlerIntf*> list); |
Tom Joseph | fb3bc06 | 2021-08-17 07:48:11 -0700 | [diff] [blame] | 55 | |
Tom Joseph | fb3bc06 | 2021-08-17 07:48:11 -0700 | [diff] [blame] | 56 | /** @brief reference to the systemd bus */ |
Patrick Williams | 84b790c | 2022-07-22 19:26:56 -0500 | [diff] [blame] | 57 | sdbusplus::bus_t& bus; |
Tom Joseph | fb3bc06 | 2021-08-17 07:48:11 -0700 | [diff] [blame] | 58 | |
Tom Joseph | fb3bc06 | 2021-08-17 07:48:11 -0700 | [diff] [blame] | 59 | /** @brief Used to watch for new MCTP endpoints */ |
Gilbert Chen | 44524a5 | 2022-02-14 12:12:25 +0000 | [diff] [blame] | 60 | sdbusplus::bus::match_t mctpEndpointAddedSignal; |
Tom Joseph | fb3bc06 | 2021-08-17 07:48:11 -0700 | [diff] [blame] | 61 | |
Gilbert Chen | 44524a5 | 2022-02-14 12:12:25 +0000 | [diff] [blame] | 62 | /** @brief Used to watch for the removed MCTP endpoints */ |
| 63 | sdbusplus::bus::match_t mctpEndpointRemovedSignal; |
Tom Joseph | fb3bc06 | 2021-08-17 07:48:11 -0700 | [diff] [blame] | 64 | |
Gilbert Chen | 44524a5 | 2022-02-14 12:12:25 +0000 | [diff] [blame] | 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: |
Thu Nguyen | 9027497 | 2024-07-17 07:02:16 +0000 | [diff] [blame] | 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 | |
Tom Joseph | fb3bc06 | 2021-08-17 07:48:11 -0700 | [diff] [blame] | 150 | static constexpr uint8_t mctpTypePLDM = 1; |
Tom Joseph | fb3bc06 | 2021-08-17 07:48:11 -0700 | [diff] [blame] | 151 | }; |
| 152 | |
Patrick Williams | 6da4f91 | 2023-05-10 07:50:53 -0500 | [diff] [blame] | 153 | } // namespace pldm |