blob: d16af75953db2fe88a924428f3f13fe3cbc5c28b [file] [log] [blame]
Gilbert Chen6c7fed42022-02-22 15:40:17 +00001#pragma once
2
Dung Caob6d39432024-06-05 03:46:47 +00003#include "libpldm/fru.h"
Gilbert Chen6c7fed42022-02-22 15:40:17 +00004#include "libpldm/platform.h"
5#include "libpldm/pldm.h"
6
7#include "terminus.hpp"
8#include "terminus_manager.hpp"
9
Gilbert Chende2a1322022-05-24 15:35:21 +010010#include <vector>
11
Gilbert Chen6c7fed42022-02-22 15:40:17 +000012namespace pldm
13{
14
15namespace platform_mc
16{
17
18/**
19 * @brief PlatformManager
20 *
21 * PlatformManager class manages the actions outlined in the platform spec.
22 */
23class PlatformManager
24{
25 public:
26 PlatformManager() = delete;
27 PlatformManager(const PlatformManager&) = delete;
28 PlatformManager(PlatformManager&&) = delete;
29 PlatformManager& operator=(const PlatformManager&) = delete;
30 PlatformManager& operator=(PlatformManager&&) = delete;
31 ~PlatformManager() = default;
32
33 explicit PlatformManager(TerminusManager& terminusManager,
34 TerminiMapper& termini) :
Patrick Williams16c2a0a2024-08-16 15:20:59 -040035 terminusManager(terminusManager), termini(termini)
Gilbert Chen6c7fed42022-02-22 15:40:17 +000036 {}
37
38 /** @brief Initialize terminus which supports PLDM Type 2
39 *
40 * @return coroutine return_value - PLDM completion code
41 */
42 exec::task<int> initTerminus();
43
Thu Nguyen51d66b52024-08-06 09:15:55 +000044 /** @brief Helper to get the supported event messages and set event receiver
45 *
46 * @param[in] tid - Destination TID
47 * @return coroutine return_value - PLDM completion code
48 */
49 exec::task<int> configEventReceiver(pldm_tid_t tid);
50
Gilbert Chen6c7fed42022-02-22 15:40:17 +000051 private:
Gilbert Chende2a1322022-05-24 15:35:21 +010052 /** @brief Fetch all PDRs from terminus.
53 *
54 * @param[in] terminus - The terminus object to store fetched PDRs
55 * @return coroutine return_value - PLDM completion code
56 */
57 exec::task<int> getPDRs(std::shared_ptr<Terminus> terminus);
58
59 /** @brief Fetch PDR from terminus
60 *
61 * @param[in] tid - Destination TID
62 * @param[in] recordHndl - Record handle
63 * @param[in] dataTransferHndl - Data transfer handle
64 * @param[in] transferOpFlag - Transfer Operation Flag
65 * @param[in] requstCnt - Request Count of data
66 * @param[in] recordChgNum - Record change number
67 * @param[out] nextRecordHndl - Next record handle
68 * @param[out] nextDataTransferHndl - Next data transfer handle
69 * @param[out] transferFlag - Transfer flag
70 * @param[out] responseCnt - Response count of record data
71 * @param[out] recordData - Returned record data
72 * @param[out] transferCrc - CRC value when record data is last part of PDR
73 * @return coroutine return_value - PLDM completion code
74 */
75 exec::task<int>
76 getPDR(const pldm_tid_t tid, const uint32_t recordHndl,
77 const uint32_t dataTransferHndl, const uint8_t transferOpFlag,
78 const uint16_t requestCnt, const uint16_t recordChgNum,
79 uint32_t& nextRecordHndl, uint32_t& nextDataTransferHndl,
80 uint8_t& transferFlag, uint16_t& responseCnt,
81 std::vector<uint8_t>& recordData, uint8_t& transferCrc);
82
83 /** @brief get PDR repository information.
84 *
85 * @param[in] tid - Destination TID
86 * @param[out] repositoryState - the state of repository
87 * @param[out] recordCount - number of records
88 * @param[out] repositorySize - repository size
89 * @param[out] largestRecordSize - largest record size
90 * *
91 * @return coroutine return_value - PLDM completion code
92 */
Patrick Williams16c2a0a2024-08-16 15:20:59 -040093 exec::task<int> getPDRRepositoryInfo(
94 const pldm_tid_t tid, uint8_t& repositoryState, uint32_t& recordCount,
95 uint32_t& repositorySize, uint32_t& largestRecordSize);
Gilbert Chende2a1322022-05-24 15:35:21 +010096
Thu Nguyen51d66b52024-08-06 09:15:55 +000097 /** @brief Send setEventReceiver command to destination EID.
98 *
99 * @param[in] tid - Destination TID
100 * @param[in] eventMessageGlobalEnable - Enable/disable event message
101 * generation from the terminus
102 * @param[in] eventReceiverEid - The EID of eventReceiver that terminus
103 * should send event message to
104 * @param[in] protocolType - Provided in the request to help the responder
105 * verify that the content of the eventReceiverAddressInfo field
106 * @param[in] heartbeatTimer - Amount of time in seconds after each
107 * elapsing of which the terminus shall emit a heartbeat event.
108 * @return coroutine return_value - PLDM completion code
109 */
110 exec::task<int> setEventReceiver(
111 pldm_tid_t tid,
112 pldm_event_message_global_enable eventMessageGlobalEnable,
113 pldm_transport_protocol_type protocolType, uint16_t heartbeatTimer);
114
Gilbert Chen77e6fe72024-08-06 09:23:30 +0000115 /** @brief send eventMessageBufferSize
116 * @param[in] tid - Destination TID
117 * @param[in] receiverMaxBufferSize
118 * @param[out] terminusBufferSize
119 * @return coroutine return_value - PLDM completion code
120 */
121 exec::task<int> eventMessageBufferSize(pldm_tid_t tid,
122 uint16_t receiverMaxBufferSize,
123 uint16_t& terminusBufferSize);
124
Thu Nguyen51d66b52024-08-06 09:15:55 +0000125 /** @brief send eventMessageSupported
126 * @param[in] tid - Destination TID
127 * @param[in] formatVersion - version of the event format
128 * @param[out] synchronyConfiguration - messaging style most recently
129 * configured via the setEventReceiver command
130 * @param[out] synchronyConfigurationSupported - event messaging styles
131 * supported by the terminus
132 * @param[out] numerEventClassReturned - number of eventClass enumerated
133 * bytes
134 * @param[out] eventClass - vector of eventClass the device can generate
135 * @return coroutine return_value - PLDM completion code
136 */
137 exec::task<int> eventMessageSupported(
138 pldm_tid_t tid, uint8_t formatVersion, uint8_t& synchronyConfiguration,
139 bitfield8_t& synchronyConfigurationSupported,
140 uint8_t& numerEventClassReturned, std::vector<uint8_t>& eventClass);
141
Dung Caob6d39432024-06-05 03:46:47 +0000142 /** @brief Get FRU Record Tables from remote MCTP Endpoint
143 *
144 * @param[in] tid - Destination TID
145 * @param[in] total - Total number of record in table
146 * @param[out] fruData - Returned fru record table data
147 */
148 exec::task<int> getFRURecordTables(pldm_tid_t tid, const uint16_t& total,
149 std::vector<uint8_t>& fruData);
150
151 /** @brief Fetch FRU Record Data from terminus
152 *
153 * @param[in] tid - Destination TID
154 * @param[in] dataTransferHndl - Data transfer handle
155 * @param[in] transferOpFlag - Transfer Operation Flag
156 * @param[out] nextDataTransferHndl - Next data transfer handle
157 * @param[out] transferFlag - Transfer flag
158 * @param[out] responseCnt - Response count of record data
159 * @param[out] recordData - Returned record data
160 *
161 * @return coroutine return_value - PLDM completion code
162 */
163 exec::task<int> getFRURecordTable(
164 pldm_tid_t tid, const uint32_t dataTransferHndl,
165 const uint8_t transferOpFlag, uint32_t* nextDataTransferHndl,
166 uint8_t* transferFlag, size_t* responseCnt,
167 std::vector<uint8_t>& recordData);
168
169 /** @brief Get FRU Record Table Metadata from remote MCTP Endpoint
170 *
171 * @param[in] tid - Destination TID
172 * @param[out] total - Total number of record in table
173 */
174 exec::task<int> getFRURecordTableMetadata(pldm_tid_t tid, uint16_t* total);
175
176 /** @brief Parse record data from FRU table
177 *
178 * @param[in] tid - Destination TID
179 * @param[in] fruData - pointer to FRU record table
180 * @param[in] fruLen - FRU table length
181 */
182 void updateInventoryWithFru(pldm_tid_t tid, const uint8_t* fruData,
183 const size_t fruLen);
184
Gilbert Chen6c7fed42022-02-22 15:40:17 +0000185 /** reference of TerminusManager for sending PLDM request to terminus*/
186 TerminusManager& terminusManager;
187
188 /** @brief Managed termini list */
189 TerminiMapper& termini;
190};
191} // namespace platform_mc
192} // namespace pldm