blob: 6b84acb161edea24821309fc8b3f2b039e451e9a [file] [log] [blame]
Andrew Jeffery9c766792022-08-10 23:12:49 +09301#ifndef MCTP_H
2#define MCTP_H
3
4#ifdef __cplusplus
5extern "C" {
6#endif
7
8#include <stddef.h>
9#include <stdint.h>
10
Rashmica Guptac1b66f42022-12-09 16:24:45 +110011/* Delete when deleting old api */
Andrew Jeffery9c766792022-08-10 23:12:49 +093012typedef uint8_t mctp_eid_t;
13
14typedef enum pldm_requester_error_codes {
15 PLDM_REQUESTER_SUCCESS = 0,
16 PLDM_REQUESTER_OPEN_FAIL = -1,
17 PLDM_REQUESTER_NOT_PLDM_MSG = -2,
18 PLDM_REQUESTER_NOT_RESP_MSG = -3,
19 PLDM_REQUESTER_NOT_REQ_MSG = -4,
20 PLDM_REQUESTER_RESP_MSG_TOO_SMALL = -5,
21 PLDM_REQUESTER_INSTANCE_ID_MISMATCH = -6,
22 PLDM_REQUESTER_SEND_FAIL = -7,
23 PLDM_REQUESTER_RECV_FAIL = -8,
24 PLDM_REQUESTER_INVALID_RECV_LEN = -9,
Rashmica Guptac1b66f42022-12-09 16:24:45 +110025 PLDM_REQUESTER_SETUP_FAIL = -10,
26 PLDM_REQUESTER_INVALID_SETUP = -11,
27 PLDM_REQUESTER_POLL_FAIL = -12,
Thu Nguyenf56e4dc2023-07-24 10:39:47 +070028 PLDM_REQUESTER_TRANSPORT_BUSY = -13,
Andrew Jeffery9c766792022-08-10 23:12:49 +093029} pldm_requester_rc_t;
30
Rashmica Guptac1b66f42022-12-09 16:24:45 +110031/* ------ Old API ---- deprecated */
Andrew Jeffery9c766792022-08-10 23:12:49 +093032/**
33 * @brief Connect to the MCTP socket and provide an fd to it. The fd can be
34 * used to pass as input to other APIs below, or can be polled.
35 *
36 * @return fd on success, pldm_requester_rc_t on error (errno may be set)
37 */
Andrew Jeffery319304f2023-04-05 13:53:18 +093038pldm_requester_rc_t pldm_open(void);
Andrew Jeffery9c766792022-08-10 23:12:49 +093039
40/**
41 * @brief Send a PLDM request message. Wait for corresponding response message,
42 * which once received, is returned to the caller.
43 *
44 * @param[in] eid - destination MCTP eid
45 * @param[in] mctp_fd - MCTP socket fd
46 * @param[in] pldm_req_msg - caller owned pointer to PLDM request msg
47 * @param[in] req_msg_len - size of PLDM request msg
48 * @param[out] pldm_resp_msg - *pldm_resp_msg will point to PLDM response msg,
49 * this function allocates memory, caller to free(*pldm_resp_msg) on
50 * success.
51 * @param[out] resp_msg_len - caller owned pointer that will be made point to
52 * the size of the PLDM response msg.
53 *
54 * @return pldm_requester_rc_t (errno may be set)
55 */
56pldm_requester_rc_t pldm_send_recv(mctp_eid_t eid, int mctp_fd,
57 const uint8_t *pldm_req_msg,
58 size_t req_msg_len, uint8_t **pldm_resp_msg,
59 size_t *resp_msg_len);
60
61/**
62 * @brief Send a PLDM request message, don't wait for response. Essentially an
63 * async API. A user of this would typically have added the MCTP fd to an
64 * event loop for polling. Once there's data available, the user would
65 * invoke pldm_recv().
66 *
67 * @param[in] eid - destination MCTP eid
68 * @param[in] mctp_fd - MCTP socket fd
69 * @param[in] pldm_req_msg - caller owned pointer to PLDM request msg
70 * @param[in] req_msg_len - size of PLDM request msg
71 *
72 * @return pldm_requester_rc_t (errno may be set)
73 */
74pldm_requester_rc_t pldm_send(mctp_eid_t eid, int mctp_fd,
75 const uint8_t *pldm_req_msg, size_t req_msg_len);
76
77/**
78 * @brief Read MCTP socket. If there's data available, return success only if
79 * data is a PLDM response message that matches eid and instance_id.
80 *
81 * @param[in] eid - destination MCTP eid
82 * @param[in] mctp_fd - MCTP socket fd
83 * @param[in] instance_id - PLDM instance id of previously sent PLDM request msg
84 * @param[out] pldm_resp_msg - *pldm_resp_msg will point to PLDM response msg,
85 * this function allocates memory, caller to free(*pldm_resp_msg) on
86 * success.
87 * @param[out] resp_msg_len - caller owned pointer that will be made point to
88 * the size of the PLDM response msg.
89 *
90 * @return pldm_requester_rc_t (errno may be set). failure is returned even
91 * when data was read, but didn't match eid or instance_id.
92 */
93pldm_requester_rc_t pldm_recv(mctp_eid_t eid, int mctp_fd, uint8_t instance_id,
94 uint8_t **pldm_resp_msg, size_t *resp_msg_len);
95
96/**
97 * @brief Read MCTP socket. If there's data available, return success only if
98 * data is a PLDM response message.
99 *
100 * @param[in] eid - destination MCTP eid
101 * @param[in] mctp_fd - MCTP socket fd
102 * @param[out] pldm_resp_msg - *pldm_resp_msg will point to PLDM response msg,
103 * this function allocates memory, caller to free(*pldm_resp_msg) on
104 * success.
105 * @param[out] resp_msg_len - caller owned pointer that will be made point to
106 * the size of the PLDM response msg.
107 *
108 * @return pldm_requester_rc_t (errno may be set). failure is returned even
109 * when data was read, but wasn't a PLDM response message
110 */
111pldm_requester_rc_t pldm_recv_any(mctp_eid_t eid, int mctp_fd,
112 uint8_t **pldm_resp_msg,
113 size_t *resp_msg_len);
114
Andrew Jeffery5fb96802023-06-29 11:13:27 +0930115/**
116 * @brief Shutdown the MCTP socket
117 */
118void pldm_close(void);
119
Andrew Jeffery9c766792022-08-10 23:12:49 +0930120#ifdef __cplusplus
121}
122#endif
123
124#endif /* MCTP_H */