blob: 1bd95267909bec94a717c8a7d3e1324ed2ee34cd [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";
18constexpr const char* MCTPService = "xyz.openbmc_project.MCTP";
19constexpr const char* MCTPInterface = "xyz.openbmc_project.MCTP.Endpoint";
Thu Nguyen90274972024-07-17 07:02:16 +000020constexpr const char* EndpointUUID = "xyz.openbmc_project.Common.UUID";
Gilbert Chen44524a52022-02-14 12:12:25 +000021constexpr 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 */
28class 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 Dixit754041d2024-02-20 06:15:49 -060035
Tom Josephfb3bc062021-08-17 07:48:11 -070036class 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 Chen44524a52022-02-14 12:12:25 +000050 * @param[in] list - initializer list to the MctpDiscoveryHandlerIntf
Tom Josephfb3bc062021-08-17 07:48:11 -070051 */
Gilbert Chen44524a52022-02-14 12:12:25 +000052 explicit MctpDiscovery(
Patrick Williamsba741d52024-05-08 02:32:10 -050053 sdbusplus::bus_t& bus,
Gilbert Chen44524a52022-02-14 12:12:25 +000054 std::initializer_list<MctpDiscoveryHandlerIntf*> list);
Tom Josephfb3bc062021-08-17 07:48:11 -070055
Tom Josephfb3bc062021-08-17 07:48:11 -070056 /** @brief reference to the systemd bus */
Patrick Williams84b790c2022-07-22 19:26:56 -050057 sdbusplus::bus_t& bus;
Tom Josephfb3bc062021-08-17 07:48:11 -070058
Tom Josephfb3bc062021-08-17 07:48:11 -070059 /** @brief Used to watch for new MCTP endpoints */
Gilbert Chen44524a52022-02-14 12:12:25 +000060 sdbusplus::bus::match_t mctpEndpointAddedSignal;
Tom Josephfb3bc062021-08-17 07:48:11 -070061
Gilbert Chen44524a52022-02-14 12:12:25 +000062 /** @brief Used to watch for the removed MCTP endpoints */
63 sdbusplus::bus::match_t mctpEndpointRemovedSignal;
Tom Josephfb3bc062021-08-17 07:48:11 -070064
Gilbert Chen44524a52022-02-14 12:12:25 +000065 /** @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 Nguyen90274972024-07-17 07:02:16 +0000128 /** @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 Josephfb3bc062021-08-17 07:48:11 -0700150 static constexpr uint8_t mctpTypePLDM = 1;
Tom Josephfb3bc062021-08-17 07:48:11 -0700151};
152
Patrick Williams6da4f912023-05-10 07:50:53 -0500153} // namespace pldm