blob: d7e2a0e0fc5cc1db0c6a1006ec65edf0689751c6 [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,
Andrew Jeffery9c766792022-08-10 23:12:49 +093028} pldm_requester_rc_t;
29
Rashmica Guptac1b66f42022-12-09 16:24:45 +110030/* ------ Old API ---- deprecated */
Andrew Jeffery9c766792022-08-10 23:12:49 +093031/**
32 * @brief Connect to the MCTP socket and provide an fd to it. The fd can be
33 * used to pass as input to other APIs below, or can be polled.
34 *
35 * @return fd on success, pldm_requester_rc_t on error (errno may be set)
36 */
Andrew Jeffery319304f2023-04-05 13:53:18 +093037pldm_requester_rc_t pldm_open(void);
Andrew Jeffery9c766792022-08-10 23:12:49 +093038
39/**
40 * @brief Send a PLDM request message. Wait for corresponding response message,
41 * which once received, is returned to the caller.
42 *
43 * @param[in] eid - destination MCTP eid
44 * @param[in] mctp_fd - MCTP socket fd
45 * @param[in] pldm_req_msg - caller owned pointer to PLDM request msg
46 * @param[in] req_msg_len - size of PLDM request msg
47 * @param[out] pldm_resp_msg - *pldm_resp_msg will point to PLDM response msg,
48 * this function allocates memory, caller to free(*pldm_resp_msg) on
49 * success.
50 * @param[out] resp_msg_len - caller owned pointer that will be made point to
51 * the size of the PLDM response msg.
52 *
53 * @return pldm_requester_rc_t (errno may be set)
54 */
55pldm_requester_rc_t pldm_send_recv(mctp_eid_t eid, int mctp_fd,
56 const uint8_t *pldm_req_msg,
57 size_t req_msg_len, uint8_t **pldm_resp_msg,
58 size_t *resp_msg_len);
59
60/**
61 * @brief Send a PLDM request message, don't wait for response. Essentially an
62 * async API. A user of this would typically have added the MCTP fd to an
63 * event loop for polling. Once there's data available, the user would
64 * invoke pldm_recv().
65 *
66 * @param[in] eid - destination MCTP eid
67 * @param[in] mctp_fd - MCTP socket fd
68 * @param[in] pldm_req_msg - caller owned pointer to PLDM request msg
69 * @param[in] req_msg_len - size of PLDM request msg
70 *
71 * @return pldm_requester_rc_t (errno may be set)
72 */
73pldm_requester_rc_t pldm_send(mctp_eid_t eid, int mctp_fd,
74 const uint8_t *pldm_req_msg, size_t req_msg_len);
75
76/**
77 * @brief Read MCTP socket. If there's data available, return success only if
78 * data is a PLDM response message that matches eid and instance_id.
79 *
80 * @param[in] eid - destination MCTP eid
81 * @param[in] mctp_fd - MCTP socket fd
82 * @param[in] instance_id - PLDM instance id of previously sent PLDM request msg
83 * @param[out] pldm_resp_msg - *pldm_resp_msg will point to PLDM response msg,
84 * this function allocates memory, caller to free(*pldm_resp_msg) on
85 * success.
86 * @param[out] resp_msg_len - caller owned pointer that will be made point to
87 * the size of the PLDM response msg.
88 *
89 * @return pldm_requester_rc_t (errno may be set). failure is returned even
90 * when data was read, but didn't match eid or instance_id.
91 */
92pldm_requester_rc_t pldm_recv(mctp_eid_t eid, int mctp_fd, uint8_t instance_id,
93 uint8_t **pldm_resp_msg, size_t *resp_msg_len);
94
95/**
96 * @brief Read MCTP socket. If there's data available, return success only if
97 * data is a PLDM response message.
98 *
99 * @param[in] eid - destination MCTP eid
100 * @param[in] mctp_fd - MCTP socket fd
101 * @param[out] pldm_resp_msg - *pldm_resp_msg will point to PLDM response msg,
102 * this function allocates memory, caller to free(*pldm_resp_msg) on
103 * success.
104 * @param[out] resp_msg_len - caller owned pointer that will be made point to
105 * the size of the PLDM response msg.
106 *
107 * @return pldm_requester_rc_t (errno may be set). failure is returned even
108 * when data was read, but wasn't a PLDM response message
109 */
110pldm_requester_rc_t pldm_recv_any(mctp_eid_t eid, int mctp_fd,
111 uint8_t **pldm_resp_msg,
112 size_t *resp_msg_len);
113
Andrew Jeffery5fb96802023-06-29 11:13:27 +0930114/**
115 * @brief Shutdown the MCTP socket
116 */
117void pldm_close(void);
118
Andrew Jeffery9c766792022-08-10 23:12:49 +0930119#ifdef __cplusplus
120}
121#endif
122
123#endif /* MCTP_H */