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"; |
Thu Nguyen | ef16cde | 2024-07-09 05:56:57 +0000 | [diff] [blame] | 18 | constexpr const char* MCTPService = "au.com.codeconstruct.MCTP1"; |
Gilbert Chen | 44524a5 | 2022-02-14 12:12:25 +0000 | [diff] [blame] | 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"; |
Thu Nguyen | ef16cde | 2024-07-09 05:56:57 +0000 | [diff] [blame] | 21 | constexpr const char* MCTPPath = "/au/com/codeconstruct/mctp1"; |
Chau Ly | 75e0042 | 2024-03-19 12:33:08 +0000 | [diff] [blame] | 22 | constexpr const char* MCTPInterfaceCC = "au.com.codeconstruct.MCTP.Endpoint1"; |
| 23 | constexpr const char* MCTPConnectivityProp = "Connectivity"; |
Gilbert Chen | 44524a5 | 2022-02-14 12:12:25 +0000 | [diff] [blame] | 24 | |
| 25 | /** @class MctpDiscoveryHandlerIntf |
| 26 | * |
| 27 | * This abstract class defines the APIs for MctpDiscovery class has common |
| 28 | * interface to execute function from different Manager Classes |
| 29 | */ |
| 30 | class MctpDiscoveryHandlerIntf |
| 31 | { |
| 32 | public: |
| 33 | virtual void handleMctpEndpoints(const MctpInfos& mctpInfos) = 0; |
| 34 | virtual void handleRemovedMctpEndpoints(const MctpInfos& mctpInfos) = 0; |
Chau Ly | 75e0042 | 2024-03-19 12:33:08 +0000 | [diff] [blame] | 35 | virtual void updateMctpEndpointAvailability(const MctpInfo& mctpInfo, |
| 36 | Availability availability) = 0; |
Thu Nguyen | 38e12aa | 2025-01-21 22:47:56 +0000 | [diff] [blame] | 37 | /** @brief Get Active EIDs. |
| 38 | * |
| 39 | * @param[in] addr - MCTP address of terminus |
| 40 | * @param[in] terminiNames - MCTP terminus name |
| 41 | */ |
| 42 | virtual std::optional<mctp_eid_t> getActiveEidByName( |
| 43 | const std::string& terminusName) = 0; |
| 44 | |
Gilbert Chen | 44524a5 | 2022-02-14 12:12:25 +0000 | [diff] [blame] | 45 | virtual ~MctpDiscoveryHandlerIntf() {} |
| 46 | }; |
Riya Dixit | 754041d | 2024-02-20 06:15:49 -0600 | [diff] [blame] | 47 | |
Tom Joseph | fb3bc06 | 2021-08-17 07:48:11 -0700 | [diff] [blame] | 48 | class MctpDiscovery |
| 49 | { |
| 50 | public: |
| 51 | MctpDiscovery() = delete; |
| 52 | MctpDiscovery(const MctpDiscovery&) = delete; |
| 53 | MctpDiscovery(MctpDiscovery&&) = delete; |
| 54 | MctpDiscovery& operator=(const MctpDiscovery&) = delete; |
| 55 | MctpDiscovery& operator=(MctpDiscovery&&) = delete; |
| 56 | ~MctpDiscovery() = default; |
| 57 | |
| 58 | /** @brief Constructs the MCTP Discovery object to handle discovery of |
| 59 | * MCTP enabled devices |
| 60 | * |
| 61 | * @param[in] bus - reference to systemd bus |
Gilbert Chen | 44524a5 | 2022-02-14 12:12:25 +0000 | [diff] [blame] | 62 | * @param[in] list - initializer list to the MctpDiscoveryHandlerIntf |
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 | explicit MctpDiscovery( |
Patrick Williams | ba741d5 | 2024-05-08 02:32:10 -0500 | [diff] [blame] | 65 | sdbusplus::bus_t& bus, |
Gilbert Chen | 44524a5 | 2022-02-14 12:12:25 +0000 | [diff] [blame] | 66 | std::initializer_list<MctpDiscoveryHandlerIntf*> list); |
Tom Joseph | fb3bc06 | 2021-08-17 07:48:11 -0700 | [diff] [blame] | 67 | |
Tom Joseph | fb3bc06 | 2021-08-17 07:48:11 -0700 | [diff] [blame] | 68 | /** @brief reference to the systemd bus */ |
Patrick Williams | 84b790c | 2022-07-22 19:26:56 -0500 | [diff] [blame] | 69 | sdbusplus::bus_t& bus; |
Tom Joseph | fb3bc06 | 2021-08-17 07:48:11 -0700 | [diff] [blame] | 70 | |
Tom Joseph | fb3bc06 | 2021-08-17 07:48:11 -0700 | [diff] [blame] | 71 | /** @brief Used to watch for new MCTP endpoints */ |
Gilbert Chen | 44524a5 | 2022-02-14 12:12:25 +0000 | [diff] [blame] | 72 | sdbusplus::bus::match_t mctpEndpointAddedSignal; |
Tom Joseph | fb3bc06 | 2021-08-17 07:48:11 -0700 | [diff] [blame] | 73 | |
Gilbert Chen | 44524a5 | 2022-02-14 12:12:25 +0000 | [diff] [blame] | 74 | /** @brief Used to watch for the removed MCTP endpoints */ |
| 75 | sdbusplus::bus::match_t mctpEndpointRemovedSignal; |
Tom Joseph | fb3bc06 | 2021-08-17 07:48:11 -0700 | [diff] [blame] | 76 | |
Chau Ly | 75e0042 | 2024-03-19 12:33:08 +0000 | [diff] [blame] | 77 | /** @brief Used to watch for new MCTP endpoints */ |
| 78 | sdbusplus::bus::match_t mctpEndpointPropChangedSignal; |
| 79 | |
Gilbert Chen | 44524a5 | 2022-02-14 12:12:25 +0000 | [diff] [blame] | 80 | /** @brief List of handlers need to notify when new MCTP |
| 81 | * Endpoint is Added/Removed */ |
| 82 | std::vector<MctpDiscoveryHandlerIntf*> handlers; |
| 83 | |
| 84 | /** @brief The existing MCTP endpoints */ |
| 85 | MctpInfos existingMctpInfos; |
| 86 | |
Chau Ly | 75e0042 | 2024-03-19 12:33:08 +0000 | [diff] [blame] | 87 | /** @brief Callback function when the propertiesChanged D-Bus |
| 88 | * signal is triggered for MCTP endpoint's properties. |
| 89 | * |
| 90 | * @param[in] msg - Data associated with subscribed signal |
| 91 | */ |
| 92 | void propertiesChangedCb(sdbusplus::message_t& msg); |
| 93 | |
Gilbert Chen | 44524a5 | 2022-02-14 12:12:25 +0000 | [diff] [blame] | 94 | /** @brief Callback function when MCTP endpoints addedInterface |
| 95 | * D-Bus signal raised. |
| 96 | * |
| 97 | * @param[in] msg - Data associated with subscribed signal |
| 98 | */ |
| 99 | void discoverEndpoints(sdbusplus::message_t& msg); |
| 100 | |
| 101 | /** @brief Callback function when MCTP endpoint removedInterface |
| 102 | * D-Bus signal raised. |
| 103 | * |
| 104 | * @param[in] msg - Data associated with subscribed signal |
| 105 | */ |
| 106 | void removeEndpoints(sdbusplus::message_t& msg); |
| 107 | |
| 108 | /** @brief Helper function to invoke registered handlers for |
| 109 | * the added MCTP endpoints |
| 110 | * |
| 111 | * @param[in] mctpInfos - information of discovered MCTP endpoints |
| 112 | */ |
| 113 | void handleMctpEndpoints(const MctpInfos& mctpInfos); |
| 114 | |
| 115 | /** @brief Helper function to invoke registered handlers for |
| 116 | * the removed MCTP endpoints |
| 117 | * |
| 118 | * @param[in] mctpInfos - information of removed MCTP endpoints |
| 119 | */ |
| 120 | void handleRemovedMctpEndpoints(const MctpInfos& mctpInfos); |
| 121 | |
Chau Ly | 75e0042 | 2024-03-19 12:33:08 +0000 | [diff] [blame] | 122 | /** @brief Helper function to invoke registered handlers for |
| 123 | * updating the availability status of the MCTP endpoint |
| 124 | * |
| 125 | * @param[in] mctpInfo - information of the target endpoint |
| 126 | * @param[in] availability - new availability status |
| 127 | */ |
| 128 | void updateMctpEndpointAvailability(const MctpInfo& mctpInfo, |
| 129 | Availability availability); |
| 130 | |
Gilbert Chen | 44524a5 | 2022-02-14 12:12:25 +0000 | [diff] [blame] | 131 | /** @brief Get list of MctpInfos in MCTP control interface. |
| 132 | * |
Chau Ly | 75e0042 | 2024-03-19 12:33:08 +0000 | [diff] [blame] | 133 | * @param[in] mctpInfoMap - information of discovered MCTP endpoints |
| 134 | * and the availability status of each endpoint |
Gilbert Chen | 44524a5 | 2022-02-14 12:12:25 +0000 | [diff] [blame] | 135 | */ |
Chau Ly | 75e0042 | 2024-03-19 12:33:08 +0000 | [diff] [blame] | 136 | void getMctpInfos(std::map<MctpInfo, Availability>& mctpInfoMap); |
Gilbert Chen | 44524a5 | 2022-02-14 12:12:25 +0000 | [diff] [blame] | 137 | |
| 138 | /** @brief Get list of new MctpInfos in addedInterace D-Bus signal message. |
| 139 | * |
| 140 | * @param[in] msg - addedInterace D-Bus signal message |
| 141 | * @param[in] mctpInfos - information of added MCTP endpoints |
| 142 | */ |
| 143 | void getAddedMctpInfos(sdbusplus::message_t& msg, MctpInfos& mctpInfos); |
| 144 | |
| 145 | /** @brief Add new MctpInfos to existingMctpInfos. |
| 146 | * |
| 147 | * @param[in] mctpInfos - information of new MCTP endpoints |
| 148 | */ |
| 149 | void addToExistingMctpInfos(const MctpInfos& mctpInfos); |
| 150 | |
| 151 | /** @brief Erase the removed MCTP endpoint from existingMctpInfos. |
| 152 | * |
| 153 | * @param[in] mctpInfos - the remaining MCTP endpoints |
| 154 | * @param[out] removedInfos - the removed MCTP endpoints |
| 155 | */ |
| 156 | void removeFromExistingMctpInfos(MctpInfos& mctpInfos, |
| 157 | MctpInfos& removedInfos); |
| 158 | |
| 159 | private: |
Thu Nguyen | 9027497 | 2024-07-17 07:02:16 +0000 | [diff] [blame] | 160 | /** @brief Get MCTP Endpoint D-Bus Properties in the |
| 161 | * `xyz.openbmc_project.MCTP.Endpoint` D-Bus interface |
| 162 | * |
| 163 | * @param[in] service - the MCTP service name |
| 164 | * @param[in] path - the MCTP endpoints object path |
| 165 | * |
| 166 | * @return tuple of Network Index, Endpoint ID and MCTP message types |
| 167 | */ |
| 168 | MctpEndpointProps getMctpEndpointProps(const std::string& service, |
| 169 | const std::string& path); |
| 170 | |
| 171 | /** @brief Get Endpoint UUID from `UUID` D-Bus property in the |
| 172 | * `xyz.openbmc_project.Common.UUID` D-Bus interface. |
| 173 | * |
| 174 | * @param[in] service - the MCTP service name |
| 175 | * @param[in] path - the MCTP endpoints object path |
| 176 | * |
| 177 | * @return Endpoint UUID |
| 178 | */ |
| 179 | UUID getEndpointUUIDProp(const std::string& service, |
| 180 | const std::string& path); |
| 181 | |
Chau Ly | 75e0042 | 2024-03-19 12:33:08 +0000 | [diff] [blame] | 182 | /** @brief Get Endpoint Availability status from `Connectivity` D-Bus |
| 183 | * property in the `au.com.codeconstruct.MCTP.Endpoint1` D-Bus |
| 184 | * interface. |
| 185 | * |
| 186 | * @param[in] path - the MCTP endpoints object path |
| 187 | * |
| 188 | * @return Availability status: true if active false if inactive |
| 189 | */ |
| 190 | Availability getEndpointConnectivityProp(const std::string& path); |
| 191 | |
Tom Joseph | fb3bc06 | 2021-08-17 07:48:11 -0700 | [diff] [blame] | 192 | static constexpr uint8_t mctpTypePLDM = 1; |
Tom Joseph | fb3bc06 | 2021-08-17 07:48:11 -0700 | [diff] [blame] | 193 | }; |
| 194 | |
Patrick Williams | 6da4f91 | 2023-05-10 07:50:53 -0500 | [diff] [blame] | 195 | } // namespace pldm |