Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 1 | #ifndef MCTP_H |
| 2 | #define MCTP_H |
| 3 | |
| 4 | #ifdef __cplusplus |
| 5 | extern "C" { |
| 6 | #endif |
| 7 | |
| 8 | #include <stddef.h> |
| 9 | #include <stdint.h> |
| 10 | |
Rashmica Gupta | c1b66f4 | 2022-12-09 16:24:45 +1100 | [diff] [blame] | 11 | /* Delete when deleting old api */ |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 12 | typedef uint8_t mctp_eid_t; |
| 13 | |
| 14 | typedef 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 Gupta | c1b66f4 | 2022-12-09 16:24:45 +1100 | [diff] [blame] | 25 | PLDM_REQUESTER_SETUP_FAIL = -10, |
| 26 | PLDM_REQUESTER_INVALID_SETUP = -11, |
| 27 | PLDM_REQUESTER_POLL_FAIL = -12, |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 28 | } pldm_requester_rc_t; |
| 29 | |
Rashmica Gupta | c1b66f4 | 2022-12-09 16:24:45 +1100 | [diff] [blame] | 30 | /* ------ Old API ---- deprecated */ |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 31 | /** |
| 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 Jeffery | 319304f | 2023-04-05 13:53:18 +0930 | [diff] [blame] | 37 | pldm_requester_rc_t pldm_open(void); |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 38 | |
| 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 | */ |
| 55 | pldm_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 | */ |
| 73 | pldm_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 | */ |
| 92 | pldm_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 | */ |
| 110 | pldm_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 Jeffery | 5fb9680 | 2023-06-29 11:13:27 +0930 | [diff] [blame] | 114 | /** |
| 115 | * @brief Shutdown the MCTP socket |
| 116 | */ |
| 117 | void pldm_close(void); |
| 118 | |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 119 | #ifdef __cplusplus |
| 120 | } |
| 121 | #endif |
| 122 | |
| 123 | #endif /* MCTP_H */ |