blob: 06014885224592bed1856ace055f8273583c491f [file] [log] [blame]
Rashmica Gupta1ed5f7a2023-05-22 13:56:42 +10001#pragma once
2
3#include <libpldm/base.h>
4#include <libpldm/pldm.h>
5#include <poll.h>
6#include <stddef.h>
7
8struct pldm_transport_mctp_demux;
9struct pldm_transport_af_mctp;
10
11union TransportImpl
12{
13 struct pldm_transport_mctp_demux* mctp_demux;
14 struct pldm_transport_af_mctp* af_mctp;
15};
16
17/* RAII for pldm_transport */
18class PldmTransport
19{
20 public:
21 PldmTransport();
22 PldmTransport(const PldmTransport& other) = delete;
23 PldmTransport(const PldmTransport&& other) = delete;
24 PldmTransport& operator=(const PldmTransport& other) = delete;
25 PldmTransport& operator=(const PldmTransport&& other) = delete;
26 ~PldmTransport();
27
28 /** @brief Provides a file descriptor that can be polled for readiness.
29 *
30 * Readiness generally indicates that a call to recvMsg() will immediately
31 * yield a message.
32 *
33 * @return The relevant file descriptor.
34 */
35 int getEventSource() const;
36
37 /** @brief Asynchronously send a PLDM message to the specified terminus
38 *
39 * The message may be either a request or a response.
40 *
41 * @param[in] tid - The terminus ID of the message destination
42 * @param[in] tx - The encoded and framed message to send
43 * @param[in] len - The length of the buffer pointed-to by tx
44 *
45 * @return PLDM_REQUESTER_SUCCESS on success, otherwise an appropriate
46 * PLDM_REQUESTER_* error code.
47 */
48 pldm_requester_rc_t sendMsg(pldm_tid_t tid, const void* tx, size_t len);
49
50 /** @brief Asynchronously receive a PLDM message addressed to the local
51 * terminus
52 *
53 * The message may be either a request or a response.
54 *
55 * @param[out] tid - The terminus ID of the message source
56 * @param[out] rx - A pointer to the received, encoded message
57 * @param[out] len - The length of the buffer pointed-to by rx
58 *
59 * @return PLDM_REQUESTER_SUCCESS on success, otherwise an appropriate
60 * PLDM_REQUESTER_* error code.
61 */
62 pldm_requester_rc_t recvMsg(pldm_tid_t& tid, void*& rx, size_t& len);
63
64 /** @brief Synchronously exchange a request and response with the specified
65 * terminus.
66 *
67 * sendRecvMsg() is a wrapper for the non-compliant
68 * pldm_transport_send_recv_msg() API from libpldm. It is a crutch that may
69 * be used for to fulfil a PLDM request until libpldm implements a correct
70 * requester flow in accordance with the PLDM base specification (DSP0240).
71 *
72 * The implementation blocks after the request is sent until a response is
73 * received, or the upper time-bound on a PLDM exchange is reached. Control
74 * is only handed back to the caller once one of these two outcomes is
75 * achieved.
76 *
77 * @param[in] tid - The terminus ID of the endpoint with which the exchange
78 * will occur
79 * @param[in] tx - The encoded and framed message to send
80 * @param[in] txLen - The length of the buffer pointed-to by tx
81 * @param[out] rx - A pointer to the received, encoded message
82 * @param[out] rxLen - The length of the buffer pointed-to by rx
83 *
84 * @return PLDM_REQUESTER_SUCCESS on success, otherwise an appropriate
85 * PLDM_REQUESTER_* error code.
86 */
87 pldm_requester_rc_t sendRecvMsg(pldm_tid_t tid, const void* tx,
88 size_t txLen, void*& rx, size_t& rxLen);
89
90 private:
91 /** @brief A pollfd object for holding a file descriptor from the libpldm
92 * transport implementation
93 */
94 pollfd pfd;
95
96 /** @brief A union holding an appropriately-typed pointer to the selected
97 * libpldm transport implementation
98 */
99 TransportImpl impl;
100
101 /** @brief The abstract libpldm transport object for sending and receiving
102 * PLDM messages.
103 */
104 struct pldm_transport* transport;
105};