1 #pragma once
2 
3 #include "libpldm/platform.h"
4 #include "libpldm/pldm.h"
5 
6 #include "terminus.hpp"
7 #include "terminus_manager.hpp"
8 
9 #include <vector>
10 
11 namespace pldm
12 {
13 
14 namespace platform_mc
15 {
16 
17 /**
18  * @brief PlatformManager
19  *
20  * PlatformManager class manages the actions outlined in the platform spec.
21  */
22 class PlatformManager
23 {
24   public:
25     PlatformManager() = delete;
26     PlatformManager(const PlatformManager&) = delete;
27     PlatformManager(PlatformManager&&) = delete;
28     PlatformManager& operator=(const PlatformManager&) = delete;
29     PlatformManager& operator=(PlatformManager&&) = delete;
30     ~PlatformManager() = default;
31 
32     explicit PlatformManager(TerminusManager& terminusManager,
33                              TerminiMapper& termini) :
34         terminusManager(terminusManager), termini(termini)
35     {}
36 
37     /** @brief Initialize terminus which supports PLDM Type 2
38      *
39      *  @return coroutine return_value - PLDM completion code
40      */
41     exec::task<int> initTerminus();
42 
43     /** @brief Helper to get the supported event messages and set event receiver
44      *
45      *  @param[in] tid - Destination TID
46      *  @return coroutine return_value - PLDM completion code
47      */
48     exec::task<int> configEventReceiver(pldm_tid_t tid);
49 
50   private:
51     /** @brief Fetch all PDRs from terminus.
52      *
53      *  @param[in] terminus - The terminus object to store fetched PDRs
54      *  @return coroutine return_value - PLDM completion code
55      */
56     exec::task<int> getPDRs(std::shared_ptr<Terminus> terminus);
57 
58     /** @brief Fetch PDR from terminus
59      *
60      *  @param[in] tid - Destination TID
61      *  @param[in] recordHndl - Record handle
62      *  @param[in] dataTransferHndl - Data transfer handle
63      *  @param[in] transferOpFlag - Transfer Operation Flag
64      *  @param[in] requstCnt - Request Count of data
65      *  @param[in] recordChgNum - Record change number
66      *  @param[out] nextRecordHndl - Next record handle
67      *  @param[out] nextDataTransferHndl - Next data transfer handle
68      *  @param[out] transferFlag - Transfer flag
69      *  @param[out] responseCnt - Response count of record data
70      *  @param[out] recordData - Returned record data
71      *  @param[out] transferCrc - CRC value when record data is last part of PDR
72      *  @return coroutine return_value - PLDM completion code
73      */
74     exec::task<int>
75         getPDR(const pldm_tid_t tid, const uint32_t recordHndl,
76                const uint32_t dataTransferHndl, const uint8_t transferOpFlag,
77                const uint16_t requestCnt, const uint16_t recordChgNum,
78                uint32_t& nextRecordHndl, uint32_t& nextDataTransferHndl,
79                uint8_t& transferFlag, uint16_t& responseCnt,
80                std::vector<uint8_t>& recordData, uint8_t& transferCrc);
81 
82     /** @brief get PDR repository information.
83      *
84      *  @param[in] tid - Destination TID
85      *  @param[out] repositoryState - the state of repository
86      *  @param[out] recordCount - number of records
87      *  @param[out] repositorySize - repository size
88      *  @param[out] largestRecordSize - largest record size
89      * *
90      *  @return coroutine return_value - PLDM completion code
91      */
92     exec::task<int> getPDRRepositoryInfo(
93         const pldm_tid_t tid, uint8_t& repositoryState, uint32_t& recordCount,
94         uint32_t& repositorySize, uint32_t& largestRecordSize);
95 
96     /** @brief Send setEventReceiver command to destination EID.
97      *
98      *  @param[in] tid - Destination TID
99      *  @param[in] eventMessageGlobalEnable - Enable/disable event message
100      *             generation from the terminus
101      *  @param[in] eventReceiverEid - The EID of eventReceiver that terminus
102      *             should send event message to
103      *  @param[in] protocolType - Provided in the request to help the responder
104      *             verify that the content of the eventReceiverAddressInfo field
105      *  @param[in] heartbeatTimer - Amount of time in seconds after each
106      *             elapsing of which the terminus shall emit a heartbeat event.
107      *  @return coroutine return_value - PLDM completion code
108      */
109     exec::task<int> setEventReceiver(
110         pldm_tid_t tid,
111         pldm_event_message_global_enable eventMessageGlobalEnable,
112         pldm_transport_protocol_type protocolType, uint16_t heartbeatTimer);
113 
114     /** @brief  send eventMessageSupported
115      *  @param[in] tid - Destination TID
116      *  @param[in] formatVersion - version of the event format
117      *  @param[out] synchronyConfiguration - messaging style most recently
118      *              configured via the setEventReceiver command
119      *  @param[out] synchronyConfigurationSupported - event messaging styles
120      *              supported by the terminus
121      *  @param[out] numerEventClassReturned - number of eventClass enumerated
122      *              bytes
123      *  @param[out] eventClass - vector of eventClass the device can generate
124      *  @return coroutine return_value - PLDM completion code
125      */
126     exec::task<int> eventMessageSupported(
127         pldm_tid_t tid, uint8_t formatVersion, uint8_t& synchronyConfiguration,
128         bitfield8_t& synchronyConfigurationSupported,
129         uint8_t& numerEventClassReturned, std::vector<uint8_t>& eventClass);
130 
131     /** reference of TerminusManager for sending PLDM request to terminus*/
132     TerminusManager& terminusManager;
133 
134     /** @brief Managed termini list */
135     TerminiMapper& termini;
136 };
137 } // namespace platform_mc
138 } // namespace pldm
139