blob: 660ff0230edd22baca01ec09dfa40bf8691d4a21 [file] [log] [blame]
Rashmica Guptac1b66f42022-12-09 16:24:45 +11001#ifndef TRANSPORT_PLDM_H
2#define TRANSPORT_PLDM_H
3
4#ifdef __cplusplus
5extern "C" {
6#endif
7
8#include "libpldm/base.h"
9#include "libpldm/pldm.h"
10#include <stddef.h>
11
12struct pldm_transport;
13
14/**
15 * @brief Waits for a PLDM event.
16 *
17 * @pre The pldm transport instance must be initialised; otherwise,
18 * PLDM_REQUESTER_INVALID_SETUP is returned. This should be called after
19 * pldm_transport_send_msg has been called.
20 *
Andrew Jeffery5aa765a2023-05-24 16:09:16 +093021 * @param[in] transport - Wait until this transport instance is ready
22 * @param[in] timeout - Wait for readiness for up to timeout milliseconds.
23 * Specifying a timeout value of zero yields an immediate return.
24 * Specifying a negative value means an indefinite timeout.
25 *
Andrew Jeffery3380a6c2023-07-12 13:57:33 +093026 * @return 0 if a timeout occurs, 1 if the transport becomes ready, PLDM_REQUESTER_INVALID_SETUP if
27 * transport is NULL, or PLDM_REQUESTER_POLL_FAIL on failure.
Rashmica Guptac1b66f42022-12-09 16:24:45 +110028 */
Andrew Jeffery3380a6c2023-07-12 13:57:33 +093029int pldm_transport_poll(struct pldm_transport *transport, int timeout);
Rashmica Guptac1b66f42022-12-09 16:24:45 +110030
31/**
32 * @brief Asynchronously send a PLDM message. Control is immediately returned to
33 * the caller.
34 *
35 * @pre The pldm transport instance must be initialised; otherwise,
36 * PLDM_REQUESTER_INVALID_SETUP is returned. If the transport requires a
37 * TID to transport specific identifier mapping, this must already be set
38 * up.
39 *
40 * @param[in] ctx - pldm transport instance
41 * @param[in] tid - destination PLDM TID
Rashmica Guptaf1ebde42023-07-31 14:17:57 +100042 * @param[in] pldm_msg - caller owned pointer to PLDM msg. If this is NULL,
43 * PLDM_REQUESTER_INVALID_SETUP is returned.
44 * @param[in] msg_len - size of PLDM msg. If this is less than the minimum size
45 * of a PLDM msg PLDM_REQUESTER_NOT_REQ_MSG is returned.
Rashmica Guptac1b66f42022-12-09 16:24:45 +110046 * Otherwise, if this is not the correct length of the PLDM msg,
47 * behaviour is undefined.
48 *
49 * @return pldm_requester_rc_t (errno may be set)
50 */
51pldm_requester_rc_t pldm_transport_send_msg(struct pldm_transport *transport,
52 pldm_tid_t tid,
Rashmica Guptaf1ebde42023-07-31 14:17:57 +100053 const void *pldm_msg,
54 size_t msg_len);
Rashmica Guptac1b66f42022-12-09 16:24:45 +110055
56/**
Rashmica Guptaf1ebde42023-07-31 14:17:57 +100057 * @brief Asynchronously get a PLDM message. Control is immediately returned to the
Rashmica Guptac1b66f42022-12-09 16:24:45 +110058 * caller.
59 *
60 * @pre The pldm transport instance must be initialised; otherwise,
61 * PLDM_REQUESTER_INVALID_SETUP is returned. If the transport requires a
62 * TID to transport specific identifier mapping, this must already be set
63 * up.
64 *
65 * @param[in] ctx - pldm transport instance
Rashmica Gupta24576292023-07-31 14:02:41 +100066 * @param[out] tid - source PLDM TID
Rashmica Guptaf1ebde42023-07-31 14:17:57 +100067 * @param[out] pldm_msg - *pldm_msg will point to the received PLDM msg if
Rashmica Guptac1b66f42022-12-09 16:24:45 +110068 * return code is PLDM_REQUESTER_SUCCESS; otherwise, NULL. On
69 * success this function allocates memory, caller to
Rashmica Guptaf1ebde42023-07-31 14:17:57 +100070 * free(*pldm_msg).
71 * @param[out] msg_len - caller owned pointer that will be made to point to
72 * the size of the PLDM msg. If NULL,
Rashmica Guptac1b66f42022-12-09 16:24:45 +110073 * PLDM_REQUESTER_INVALID_SETUP is returned.
74 *
75 * @return pldm_requester_rc_t (errno may be set). Failure is returned if no
Rashmica Guptaf1ebde42023-07-31 14:17:57 +100076 * PLDM messages are available.
Rashmica Guptac1b66f42022-12-09 16:24:45 +110077 *
78 */
79pldm_requester_rc_t pldm_transport_recv_msg(struct pldm_transport *transport,
Rashmica Gupta24576292023-07-31 14:02:41 +100080 pldm_tid_t *tid, void **pldm_msg,
Rashmica Guptaf1ebde42023-07-31 14:17:57 +100081 size_t *msg_len);
Rashmica Guptac1b66f42022-12-09 16:24:45 +110082
83/**
84 * @brief Synchronously send a PLDM request and receive the response. Control is
85 * returned to the caller once the response is received.
86 *
Thu Nguyenb01fb1c2023-05-28 09:16:46 +070087 * pldm_transport_send_recv() will discard messages received on the underlying transport instance
88 * that are not a response that matches the request. Do not use this function if you're attempting
89 * to use the transport instance asynchronously, as this discard behaviour will affect other
90 * responses that you may care about.
91 *
Rashmica Guptac1b66f42022-12-09 16:24:45 +110092 * @pre The pldm transport instance must be initialised; otherwise,
93 * PLDM_REQUESTER_INVALID_SETUP is returned. If the transport requires a
94 * TID to transport specific identifier mapping, this must already be set
95 * up.
96 *
97 * @param[in] ctx - pldm transport instance with a registered transport
98 * @param[in] tid - destination PLDM TID
99 * @param[in] pldm_req_msg - caller owned pointer to PLDM request msg or async
100 * notification. If NULL, PLDM_REQUESTER_INVALID_SETUP is returned.
101 * @param[in] req_msg_len - size of PLDM request msg. If this is less than the
102 * minimum size of a PLDM msg PLDM_REQUESTER_NOT_REQ_MSG is returned.
103 * Otherwise, if this is not the correct length of the PLDM msg,
104 * behaviour is undefined.
105 * @param[out] pldm_resp_msg - *pldm_resp_msg will point to PLDM response msg if
106 * return code is PLDM_REQUESTER_SUCCESS; otherwise, NULL. On
107 * success this function allocates memory, caller to
108 * free(*pldm_resp_msg).
109 * @param[out] resp_msg_len - caller owned pointer that will be made to point to
110 * the size of the PLDM response msg. If NULL,
111 * PLDM_REQUESTER_INVALID_SETUP is returned.
112 *
113 * @return pldm_requester_rc_t (errno may be set)
114 */
115pldm_requester_rc_t
116pldm_transport_send_recv_msg(struct pldm_transport *transport, pldm_tid_t tid,
117 const void *pldm_req_msg, size_t req_msg_len,
118 void **pldm_resp_msg, size_t *resp_msg_len);
119
120#ifdef __cplusplus
121}
122#endif
123
124#endif /* TRANSPORT_PLDM_H */