xref: /openbmc/phosphor-debug-collector/host-transport-extensions/pldm/common/pldm_utils.hpp (revision ceba1f07c434d8d766e9f12f6adc26170d22ec1a)
1 // SPDX-License-Identifier: Apache-2.0
2 
3 #pragma once
4 
5 #include <libpldm/instance-id.h>
6 #include <libpldm/pldm.h>
7 #include <libpldm/transport.h>
8 
9 namespace phosphor
10 {
11 namespace dump
12 {
13 namespace pldm
14 {
15 extern struct pldm_transport* pldmTransport;
16 
17 class PLDMInstanceManager
18 {
19   public:
20     PLDMInstanceManager(const PLDMInstanceManager&) = delete;
21     PLDMInstanceManager& operator=(const PLDMInstanceManager&) = delete;
22 
23     PLDMInstanceManager();
24     ~PLDMInstanceManager();
25 
26   private:
27     /**
28      * @brief Instantiates an instance ID database object
29      *
30      * @return void
31      **/
32     void initPLDMInstanceIdDb();
33 
34     /**
35      * @brief Destroys an instance ID database object
36      *
37      * @return void
38      **/
39     void destroyPLDMInstanceIdDb();
40 };
41 
42 /**
43  * @brief setup PLDM transport for sending and receiving messages
44  *
45  * @param[in] eid - MCTP endpoint ID
46  * @return file descriptor on success and throw
47  *         exception (xyz::openbmc_project::Common::Error::NotAllowed) on
48  *         failures.
49  */
50 int openPLDM(mctp_eid_t eid);
51 
52 /** @brief Opens the MCTP socket for sending and receiving messages.
53  *
54  * @param[in] eid - MCTP endpoint ID
55  */
56 int openMctpDemuxTransport(mctp_eid_t eid);
57 
58 /** @brief Close the PLDM file */
59 void pldmClose();
60 
61 /**
62  * @brief Returns the PLDM instance ID to use for PLDM commands
63  *
64  * @param[in] tid - the terminus ID the instance ID is associated with
65  *
66  * @return pldm_instance_id_t - The instance ID
67  **/
68 pldm_instance_id_t getPLDMInstanceID(uint8_t tid);
69 
70 /**
71  * @brief Free the PLDM instance ID
72  *
73  * @param[in] tid - the terminus ID the instance ID is associated with
74  * @param[in] instanceID - The PLDM instance ID
75  *
76  * @return void
77  **/
78 void freePLDMInstanceID(pldm_instance_id_t instanceID, uint8_t tid);
79 
80 } // namespace pldm
81 } // namespace dump
82 } // namespace phosphor
83