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"; |
| 20 | constexpr const char* MCTPPath = "/xyz/openbmc_project/mctp"; |
| 21 | |
| 22 | /** @class MctpDiscoveryHandlerIntf |
| 23 | * |
| 24 | * This abstract class defines the APIs for MctpDiscovery class has common |
| 25 | * interface to execute function from different Manager Classes |
| 26 | */ |
| 27 | class MctpDiscoveryHandlerIntf |
| 28 | { |
| 29 | public: |
| 30 | virtual void handleMctpEndpoints(const MctpInfos& mctpInfos) = 0; |
| 31 | virtual void handleRemovedMctpEndpoints(const MctpInfos& mctpInfos) = 0; |
| 32 | virtual ~MctpDiscoveryHandlerIntf() {} |
| 33 | }; |
Riya Dixit | 754041d | 2024-02-20 06:15:49 -0600 | [diff] [blame] | 34 | |
Tom Joseph | fb3bc06 | 2021-08-17 07:48:11 -0700 | [diff] [blame] | 35 | class MctpDiscovery |
| 36 | { |
| 37 | public: |
| 38 | MctpDiscovery() = delete; |
| 39 | MctpDiscovery(const MctpDiscovery&) = delete; |
| 40 | MctpDiscovery(MctpDiscovery&&) = delete; |
| 41 | MctpDiscovery& operator=(const MctpDiscovery&) = delete; |
| 42 | MctpDiscovery& operator=(MctpDiscovery&&) = delete; |
| 43 | ~MctpDiscovery() = default; |
| 44 | |
| 45 | /** @brief Constructs the MCTP Discovery object to handle discovery of |
| 46 | * MCTP enabled devices |
| 47 | * |
| 48 | * @param[in] bus - reference to systemd bus |
Gilbert Chen | 44524a5 | 2022-02-14 12:12:25 +0000 | [diff] [blame] | 49 | * @param[in] list - initializer list to the MctpDiscoveryHandlerIntf |
Tom Joseph | fb3bc06 | 2021-08-17 07:48:11 -0700 | [diff] [blame] | 50 | */ |
Gilbert Chen | 44524a5 | 2022-02-14 12:12:25 +0000 | [diff] [blame] | 51 | explicit MctpDiscovery( |
Patrick Williams | ba741d5 | 2024-05-08 02:32:10 -0500 | [diff] [blame] | 52 | sdbusplus::bus_t& bus, |
Gilbert Chen | 44524a5 | 2022-02-14 12:12:25 +0000 | [diff] [blame] | 53 | std::initializer_list<MctpDiscoveryHandlerIntf*> list); |
Tom Joseph | fb3bc06 | 2021-08-17 07:48:11 -0700 | [diff] [blame] | 54 | |
Tom Joseph | fb3bc06 | 2021-08-17 07:48:11 -0700 | [diff] [blame] | 55 | /** @brief reference to the systemd bus */ |
Patrick Williams | 84b790c | 2022-07-22 19:26:56 -0500 | [diff] [blame] | 56 | sdbusplus::bus_t& bus; |
Tom Joseph | fb3bc06 | 2021-08-17 07:48:11 -0700 | [diff] [blame] | 57 | |
Tom Joseph | fb3bc06 | 2021-08-17 07:48:11 -0700 | [diff] [blame] | 58 | /** @brief Used to watch for new MCTP endpoints */ |
Gilbert Chen | 44524a5 | 2022-02-14 12:12:25 +0000 | [diff] [blame] | 59 | sdbusplus::bus::match_t mctpEndpointAddedSignal; |
Tom Joseph | fb3bc06 | 2021-08-17 07:48:11 -0700 | [diff] [blame] | 60 | |
Gilbert Chen | 44524a5 | 2022-02-14 12:12:25 +0000 | [diff] [blame] | 61 | /** @brief Used to watch for the removed MCTP endpoints */ |
| 62 | sdbusplus::bus::match_t mctpEndpointRemovedSignal; |
Tom Joseph | fb3bc06 | 2021-08-17 07:48:11 -0700 | [diff] [blame] | 63 | |
Gilbert Chen | 44524a5 | 2022-02-14 12:12:25 +0000 | [diff] [blame] | 64 | /** @brief List of handlers need to notify when new MCTP |
| 65 | * Endpoint is Added/Removed */ |
| 66 | std::vector<MctpDiscoveryHandlerIntf*> handlers; |
| 67 | |
| 68 | /** @brief The existing MCTP endpoints */ |
| 69 | MctpInfos existingMctpInfos; |
| 70 | |
| 71 | /** @brief Callback function when MCTP endpoints addedInterface |
| 72 | * D-Bus signal raised. |
| 73 | * |
| 74 | * @param[in] msg - Data associated with subscribed signal |
| 75 | */ |
| 76 | void discoverEndpoints(sdbusplus::message_t& msg); |
| 77 | |
| 78 | /** @brief Callback function when MCTP endpoint removedInterface |
| 79 | * D-Bus signal raised. |
| 80 | * |
| 81 | * @param[in] msg - Data associated with subscribed signal |
| 82 | */ |
| 83 | void removeEndpoints(sdbusplus::message_t& msg); |
| 84 | |
| 85 | /** @brief Helper function to invoke registered handlers for |
| 86 | * the added MCTP endpoints |
| 87 | * |
| 88 | * @param[in] mctpInfos - information of discovered MCTP endpoints |
| 89 | */ |
| 90 | void handleMctpEndpoints(const MctpInfos& mctpInfos); |
| 91 | |
| 92 | /** @brief Helper function to invoke registered handlers for |
| 93 | * the removed MCTP endpoints |
| 94 | * |
| 95 | * @param[in] mctpInfos - information of removed MCTP endpoints |
| 96 | */ |
| 97 | void handleRemovedMctpEndpoints(const MctpInfos& mctpInfos); |
| 98 | |
| 99 | /** @brief Get list of MctpInfos in MCTP control interface. |
| 100 | * |
| 101 | * @param[in] mctpInfos - information of discovered MCTP endpoints |
| 102 | */ |
| 103 | void getMctpInfos(MctpInfos& mctpInfos); |
| 104 | |
| 105 | /** @brief Get list of new MctpInfos in addedInterace D-Bus signal message. |
| 106 | * |
| 107 | * @param[in] msg - addedInterace D-Bus signal message |
| 108 | * @param[in] mctpInfos - information of added MCTP endpoints |
| 109 | */ |
| 110 | void getAddedMctpInfos(sdbusplus::message_t& msg, MctpInfos& mctpInfos); |
| 111 | |
| 112 | /** @brief Add new MctpInfos to existingMctpInfos. |
| 113 | * |
| 114 | * @param[in] mctpInfos - information of new MCTP endpoints |
| 115 | */ |
| 116 | void addToExistingMctpInfos(const MctpInfos& mctpInfos); |
| 117 | |
| 118 | /** @brief Erase the removed MCTP endpoint from existingMctpInfos. |
| 119 | * |
| 120 | * @param[in] mctpInfos - the remaining MCTP endpoints |
| 121 | * @param[out] removedInfos - the removed MCTP endpoints |
| 122 | */ |
| 123 | void removeFromExistingMctpInfos(MctpInfos& mctpInfos, |
| 124 | MctpInfos& removedInfos); |
| 125 | |
| 126 | private: |
Tom Joseph | fb3bc06 | 2021-08-17 07:48:11 -0700 | [diff] [blame] | 127 | static constexpr uint8_t mctpTypePLDM = 1; |
Tom Joseph | fb3bc06 | 2021-08-17 07:48:11 -0700 | [diff] [blame] | 128 | }; |
| 129 | |
Patrick Williams | 6da4f91 | 2023-05-10 07:50:53 -0500 | [diff] [blame] | 130 | } // namespace pldm |