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