1 /* SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later */ 2 #ifndef MCTP_H 3 #define MCTP_H 4 5 #ifdef __cplusplus 6 extern "C" { 7 #endif 8 9 #include <stddef.h> 10 #include <stdint.h> 11 12 /* Delete when deleting old api */ 13 typedef uint8_t mctp_eid_t; 14 15 typedef 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, 26 PLDM_REQUESTER_SETUP_FAIL = -10, 27 PLDM_REQUESTER_INVALID_SETUP = -11, 28 PLDM_REQUESTER_POLL_FAIL = -12, 29 PLDM_REQUESTER_TRANSPORT_BUSY = -13, 30 } pldm_requester_rc_t; 31 32 /* ------ Old API ---- deprecated */ 33 /** 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 */ 39 pldm_requester_rc_t pldm_open(void); 40 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 */ 57 pldm_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 */ 75 pldm_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 */ 94 pldm_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 */ 112 pldm_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 116 /** 117 * @brief Shutdown the MCTP socket 118 */ 119 void pldm_close(void); 120 121 #ifdef __cplusplus 122 } 123 #endif 124 125 #endif /* MCTP_H */ 126