blob: 643d1ce3748fdef6b418db963c98480c924c371b [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";
20constexpr 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 */
27class 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 Dixit754041d2024-02-20 06:15:49 -060034
Tom Josephfb3bc062021-08-17 07:48:11 -070035class 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 Chen44524a52022-02-14 12:12:25 +000049 * @param[in] list - initializer list to the MctpDiscoveryHandlerIntf
Tom Josephfb3bc062021-08-17 07:48:11 -070050 */
Gilbert Chen44524a52022-02-14 12:12:25 +000051 explicit MctpDiscovery(
Patrick Williamsba741d52024-05-08 02:32:10 -050052 sdbusplus::bus_t& bus,
Gilbert Chen44524a52022-02-14 12:12:25 +000053 std::initializer_list<MctpDiscoveryHandlerIntf*> list);
Tom Josephfb3bc062021-08-17 07:48:11 -070054
Tom Josephfb3bc062021-08-17 07:48:11 -070055 /** @brief reference to the systemd bus */
Patrick Williams84b790c2022-07-22 19:26:56 -050056 sdbusplus::bus_t& bus;
Tom Josephfb3bc062021-08-17 07:48:11 -070057
Tom Josephfb3bc062021-08-17 07:48:11 -070058 /** @brief Used to watch for new MCTP endpoints */
Gilbert Chen44524a52022-02-14 12:12:25 +000059 sdbusplus::bus::match_t mctpEndpointAddedSignal;
Tom Josephfb3bc062021-08-17 07:48:11 -070060
Gilbert Chen44524a52022-02-14 12:12:25 +000061 /** @brief Used to watch for the removed MCTP endpoints */
62 sdbusplus::bus::match_t mctpEndpointRemovedSignal;
Tom Josephfb3bc062021-08-17 07:48:11 -070063
Gilbert Chen44524a52022-02-14 12:12:25 +000064 /** @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 Josephfb3bc062021-08-17 07:48:11 -0700127 static constexpr uint8_t mctpTypePLDM = 1;
Tom Josephfb3bc062021-08-17 07:48:11 -0700128};
129
Patrick Williams6da4f912023-05-10 07:50:53 -0500130} // namespace pldm