blob: 9c5c71e18840c68b2984497b861091d44c201a37 [file] [log] [blame]
Deepak Kodihalli9d494bb2019-11-05 01:28:43 -06001#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
11typedef uint8_t mctp_eid_t;
12
13typedef enum pldm_requester_error_codes {
14 PLDM_REQUESTER_SUCCESS = 0,
15 PLDM_REQUESTER_OPEN_FAIL = -1,
16 PLDM_REQUESTER_NOT_PLDM_MSG = -2,
17 PLDM_REQUESTER_NOT_RESP_MSG = -3,
18 PLDM_REQUESTER_NOT_REQ_MSG = -4,
19 PLDM_REQUESTER_RESP_MSG_TOO_SMALL = -5,
20 PLDM_REQUESTER_INSTANCE_ID_MISMATCH = -6,
21 PLDM_REQUESTER_SEND_FAIL = -7,
22 PLDM_REQUESTER_RECV_FAIL = -8,
23 PLDM_REQUESTER_INVALID_RECV_LEN = -9,
24} pldm_requester_rc_t;
25
26/**
27 * @brief Connect to the MCTP socket and provide an fd to it. The fd can be
28 * used to pass as input to other APIs below, or can be polled.
29 *
30 * @return fd on success, pldm_requester_rc_t on error (errno may be set)
31 */
32pldm_requester_rc_t pldm_open();
33
34/**
35 * @brief Send a PLDM request message. Wait for corresponding response message,
36 * which once received, is returned to the caller.
37 *
38 * @param[in] eid - destination MCTP eid
39 * @param[in] mctp_fd - MCTP socket fd
40 * @param[in] pldm_req_msg - caller owned pointer to PLDM request msg
41 * @param[in] req_msg_len - size of PLDM request msg
42 * @param[out] pldm_resp_msg - *pldm_resp_msg will point to PLDM response msg,
43 * this function allocates memory, caller to free(*pldm_resp_msg) on
44 * success.
45 * @param[out] resp_msg_len - caller owned pointer that will be made point to
46 * the size of the PLDM response msg.
47 *
48 * @return pldm_requester_rc_t (errno may be set)
49 */
50pldm_requester_rc_t pldm_send_recv(mctp_eid_t eid, int mctp_fd,
51 const uint8_t *pldm_req_msg,
52 size_t req_msg_len, uint8_t **pldm_resp_msg,
53 size_t *resp_msg_len);
54
55/**
56 * @brief Send a PLDM request message, don't wait for response. Essentially an
57 * async API. A user of this would typically have added the MCTP fd to an
58 * event loop for polling. Once there's data available, the user would
59 * invoke pldm_recv().
60 *
61 * @param[in] eid - destination MCTP eid
62 * @param[in] mctp_fd - MCTP socket fd
63 * @param[in] pldm_req_msg - caller owned pointer to PLDM request msg
64 * @param[in] req_msg_len - size of PLDM request msg
65 *
66 * @return pldm_requester_rc_t (errno may be set)
67 */
68pldm_requester_rc_t pldm_send(mctp_eid_t eid, int mctp_fd,
69 const uint8_t *pldm_req_msg, size_t req_msg_len);
70
71/**
72 * @brief Read MCTP socket. If there's data available, return success only if
73 * data is a PLDM response message that matches eid and instance_id.
74 *
75 * @param[in] eid - destination MCTP eid
76 * @param[in] mctp_fd - MCTP socket fd
77 * @param[in] instance_id - PLDM instance id of previously sent PLDM request msg
78 * @param[out] pldm_resp_msg - *pldm_resp_msg will point to PLDM response msg,
79 * this function allocates memory, caller to free(*pldm_resp_msg) on
80 * success.
81 * @param[out] resp_msg_len - caller owned pointer that will be made point to
82 * the size of the PLDM response msg.
83 *
84 * @return pldm_requester_rc_t (errno may be set). failure is returned even
85 * when data was read, but didn't match eid or instance_id.
86 */
87pldm_requester_rc_t pldm_recv(mctp_eid_t eid, int mctp_fd, uint8_t instance_id,
88 uint8_t **pldm_resp_msg, size_t *resp_msg_len);
89
90/**
91 * @brief Read MCTP socket. If there's data available, return success only if
92 * data is a PLDM response message.
93 *
94 * @param[in] eid - destination MCTP eid
95 * @param[in] mctp_fd - MCTP socket fd
96 * @param[out] pldm_resp_msg - *pldm_resp_msg will point to PLDM response msg,
97 * this function allocates memory, caller to free(*pldm_resp_msg) on
98 * success.
99 * @param[out] resp_msg_len - caller owned pointer that will be made point to
100 * the size of the PLDM response msg.
101 *
102 * @return pldm_requester_rc_t (errno may be set). failure is returned even
103 * when data was read, but wasn't a PLDM response message
104 */
105pldm_requester_rc_t pldm_recv_any(mctp_eid_t eid, int mctp_fd,
106 uint8_t **pldm_resp_msg,
107 size_t *resp_msg_len);
108
109#ifdef __cplusplus
110}
111#endif
112
113#endif /* MCTP_H */