blob: 6bd3168421a59fec5d46d6df0f0de39a8937b891 [file] [log] [blame]
Tom Josephfb3bc062021-08-17 07:48:11 -07001#pragma once
2
Gilbert Chen44524a52022-02-14 12:12:25 +00003#include "common/types.hpp"
4#include "common/utils.hpp"
5
6#include <libpldm/pldm.h>
Tom Josephfb3bc062021-08-17 07:48:11 -07007
8#include <sdbusplus/bus/match.hpp>
9
Gilbert Chen44524a52022-02-14 12:12:25 +000010#include <filesystem>
11#include <initializer_list>
12#include <vector>
13
Tom Josephfb3bc062021-08-17 07:48:11 -070014namespace pldm
15{
16
Gilbert Chen44524a52022-02-14 12:12:25 +000017const std::string emptyUUID = "00000000-0000-0000-0000-000000000000";
Thu Nguyenef16cde2024-07-09 05:56:57 +000018constexpr const char* MCTPService = "au.com.codeconstruct.MCTP1";
Gilbert Chen44524a52022-02-14 12:12:25 +000019constexpr const char* MCTPInterface = "xyz.openbmc_project.MCTP.Endpoint";
Thu Nguyen90274972024-07-17 07:02:16 +000020constexpr const char* EndpointUUID = "xyz.openbmc_project.Common.UUID";
Thu Nguyenef16cde2024-07-09 05:56:57 +000021constexpr const char* MCTPPath = "/au/com/codeconstruct/mctp1";
Chau Ly75e00422024-03-19 12:33:08 +000022constexpr const char* MCTPInterfaceCC = "au.com.codeconstruct.MCTP.Endpoint1";
23constexpr const char* MCTPConnectivityProp = "Connectivity";
Gilbert Chen44524a52022-02-14 12:12:25 +000024
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 */
30class MctpDiscoveryHandlerIntf
31{
32 public:
33 virtual void handleMctpEndpoints(const MctpInfos& mctpInfos) = 0;
34 virtual void handleRemovedMctpEndpoints(const MctpInfos& mctpInfos) = 0;
Chau Ly75e00422024-03-19 12:33:08 +000035 virtual void updateMctpEndpointAvailability(const MctpInfo& mctpInfo,
36 Availability availability) = 0;
Gilbert Chen44524a52022-02-14 12:12:25 +000037 virtual ~MctpDiscoveryHandlerIntf() {}
38};
Riya Dixit754041d2024-02-20 06:15:49 -060039
Tom Josephfb3bc062021-08-17 07:48:11 -070040class MctpDiscovery
41{
42 public:
43 MctpDiscovery() = delete;
44 MctpDiscovery(const MctpDiscovery&) = delete;
45 MctpDiscovery(MctpDiscovery&&) = delete;
46 MctpDiscovery& operator=(const MctpDiscovery&) = delete;
47 MctpDiscovery& operator=(MctpDiscovery&&) = delete;
48 ~MctpDiscovery() = default;
49
50 /** @brief Constructs the MCTP Discovery object to handle discovery of
51 * MCTP enabled devices
52 *
53 * @param[in] bus - reference to systemd bus
Gilbert Chen44524a52022-02-14 12:12:25 +000054 * @param[in] list - initializer list to the MctpDiscoveryHandlerIntf
Tom Josephfb3bc062021-08-17 07:48:11 -070055 */
Gilbert Chen44524a52022-02-14 12:12:25 +000056 explicit MctpDiscovery(
Patrick Williamsba741d52024-05-08 02:32:10 -050057 sdbusplus::bus_t& bus,
Gilbert Chen44524a52022-02-14 12:12:25 +000058 std::initializer_list<MctpDiscoveryHandlerIntf*> list);
Tom Josephfb3bc062021-08-17 07:48:11 -070059
Tom Josephfb3bc062021-08-17 07:48:11 -070060 /** @brief reference to the systemd bus */
Patrick Williams84b790c2022-07-22 19:26:56 -050061 sdbusplus::bus_t& bus;
Tom Josephfb3bc062021-08-17 07:48:11 -070062
Tom Josephfb3bc062021-08-17 07:48:11 -070063 /** @brief Used to watch for new MCTP endpoints */
Gilbert Chen44524a52022-02-14 12:12:25 +000064 sdbusplus::bus::match_t mctpEndpointAddedSignal;
Tom Josephfb3bc062021-08-17 07:48:11 -070065
Gilbert Chen44524a52022-02-14 12:12:25 +000066 /** @brief Used to watch for the removed MCTP endpoints */
67 sdbusplus::bus::match_t mctpEndpointRemovedSignal;
Tom Josephfb3bc062021-08-17 07:48:11 -070068
Chau Ly75e00422024-03-19 12:33:08 +000069 /** @brief Used to watch for new MCTP endpoints */
70 sdbusplus::bus::match_t mctpEndpointPropChangedSignal;
71
Gilbert Chen44524a52022-02-14 12:12:25 +000072 /** @brief List of handlers need to notify when new MCTP
73 * Endpoint is Added/Removed */
74 std::vector<MctpDiscoveryHandlerIntf*> handlers;
75
76 /** @brief The existing MCTP endpoints */
77 MctpInfos existingMctpInfos;
78
Chau Ly75e00422024-03-19 12:33:08 +000079 /** @brief Callback function when the propertiesChanged D-Bus
80 * signal is triggered for MCTP endpoint's properties.
81 *
82 * @param[in] msg - Data associated with subscribed signal
83 */
84 void propertiesChangedCb(sdbusplus::message_t& msg);
85
Gilbert Chen44524a52022-02-14 12:12:25 +000086 /** @brief Callback function when MCTP endpoints addedInterface
87 * D-Bus signal raised.
88 *
89 * @param[in] msg - Data associated with subscribed signal
90 */
91 void discoverEndpoints(sdbusplus::message_t& msg);
92
93 /** @brief Callback function when MCTP endpoint removedInterface
94 * D-Bus signal raised.
95 *
96 * @param[in] msg - Data associated with subscribed signal
97 */
98 void removeEndpoints(sdbusplus::message_t& msg);
99
100 /** @brief Helper function to invoke registered handlers for
101 * the added MCTP endpoints
102 *
103 * @param[in] mctpInfos - information of discovered MCTP endpoints
104 */
105 void handleMctpEndpoints(const MctpInfos& mctpInfos);
106
107 /** @brief Helper function to invoke registered handlers for
108 * the removed MCTP endpoints
109 *
110 * @param[in] mctpInfos - information of removed MCTP endpoints
111 */
112 void handleRemovedMctpEndpoints(const MctpInfos& mctpInfos);
113
Chau Ly75e00422024-03-19 12:33:08 +0000114 /** @brief Helper function to invoke registered handlers for
115 * updating the availability status of the MCTP endpoint
116 *
117 * @param[in] mctpInfo - information of the target endpoint
118 * @param[in] availability - new availability status
119 */
120 void updateMctpEndpointAvailability(const MctpInfo& mctpInfo,
121 Availability availability);
122
Gilbert Chen44524a52022-02-14 12:12:25 +0000123 /** @brief Get list of MctpInfos in MCTP control interface.
124 *
Chau Ly75e00422024-03-19 12:33:08 +0000125 * @param[in] mctpInfoMap - information of discovered MCTP endpoints
126 * and the availability status of each endpoint
Gilbert Chen44524a52022-02-14 12:12:25 +0000127 */
Chau Ly75e00422024-03-19 12:33:08 +0000128 void getMctpInfos(std::map<MctpInfo, Availability>& mctpInfoMap);
Gilbert Chen44524a52022-02-14 12:12:25 +0000129
130 /** @brief Get list of new MctpInfos in addedInterace D-Bus signal message.
131 *
132 * @param[in] msg - addedInterace D-Bus signal message
133 * @param[in] mctpInfos - information of added MCTP endpoints
134 */
135 void getAddedMctpInfos(sdbusplus::message_t& msg, MctpInfos& mctpInfos);
136
137 /** @brief Add new MctpInfos to existingMctpInfos.
138 *
139 * @param[in] mctpInfos - information of new MCTP endpoints
140 */
141 void addToExistingMctpInfos(const MctpInfos& mctpInfos);
142
143 /** @brief Erase the removed MCTP endpoint from existingMctpInfos.
144 *
145 * @param[in] mctpInfos - the remaining MCTP endpoints
146 * @param[out] removedInfos - the removed MCTP endpoints
147 */
148 void removeFromExistingMctpInfos(MctpInfos& mctpInfos,
149 MctpInfos& removedInfos);
150
151 private:
Thu Nguyen90274972024-07-17 07:02:16 +0000152 /** @brief Get MCTP Endpoint D-Bus Properties in the
153 * `xyz.openbmc_project.MCTP.Endpoint` D-Bus interface
154 *
155 * @param[in] service - the MCTP service name
156 * @param[in] path - the MCTP endpoints object path
157 *
158 * @return tuple of Network Index, Endpoint ID and MCTP message types
159 */
160 MctpEndpointProps getMctpEndpointProps(const std::string& service,
161 const std::string& path);
162
163 /** @brief Get Endpoint UUID from `UUID` D-Bus property in the
164 * `xyz.openbmc_project.Common.UUID` D-Bus interface.
165 *
166 * @param[in] service - the MCTP service name
167 * @param[in] path - the MCTP endpoints object path
168 *
169 * @return Endpoint UUID
170 */
171 UUID getEndpointUUIDProp(const std::string& service,
172 const std::string& path);
173
Chau Ly75e00422024-03-19 12:33:08 +0000174 /** @brief Get Endpoint Availability status from `Connectivity` D-Bus
175 * property in the `au.com.codeconstruct.MCTP.Endpoint1` D-Bus
176 * interface.
177 *
178 * @param[in] path - the MCTP endpoints object path
179 *
180 * @return Availability status: true if active false if inactive
181 */
182 Availability getEndpointConnectivityProp(const std::string& path);
183
Tom Josephfb3bc062021-08-17 07:48:11 -0700184 static constexpr uint8_t mctpTypePLDM = 1;
Tom Josephfb3bc062021-08-17 07:48:11 -0700185};
186
Patrick Williams6da4f912023-05-10 07:50:53 -0500187} // namespace pldm