Rashmica Gupta | c1b66f4 | 2022-12-09 16:24:45 +1100 | [diff] [blame] | 1 | #ifndef TRANSPORT_PLDM_H |
| 2 | #define TRANSPORT_PLDM_H |
| 3 | |
| 4 | #ifdef __cplusplus |
| 5 | extern "C" { |
| 6 | #endif |
| 7 | |
| 8 | #include "libpldm/base.h" |
| 9 | #include "libpldm/pldm.h" |
| 10 | #include <stddef.h> |
| 11 | |
| 12 | struct pldm_transport; |
| 13 | |
| 14 | /** |
| 15 | * @brief Waits for a PLDM event. |
| 16 | * |
| 17 | * @pre The pldm transport instance must be initialised; otherwise, |
| 18 | * PLDM_REQUESTER_INVALID_SETUP is returned. This should be called after |
| 19 | * pldm_transport_send_msg has been called. |
| 20 | * |
Andrew Jeffery | 5aa765a | 2023-05-24 16:09:16 +0930 | [diff] [blame] | 21 | * @param[in] transport - Wait until this transport instance is ready |
| 22 | * @param[in] timeout - Wait for readiness for up to timeout milliseconds. |
| 23 | * Specifying a timeout value of zero yields an immediate return. |
| 24 | * Specifying a negative value means an indefinite timeout. |
| 25 | * |
Andrew Jeffery | 3380a6c | 2023-07-12 13:57:33 +0930 | [diff] [blame] | 26 | * @return 0 if a timeout occurs, 1 if the transport becomes ready, PLDM_REQUESTER_INVALID_SETUP if |
| 27 | * transport is NULL, or PLDM_REQUESTER_POLL_FAIL on failure. |
Rashmica Gupta | c1b66f4 | 2022-12-09 16:24:45 +1100 | [diff] [blame] | 28 | */ |
Andrew Jeffery | 3380a6c | 2023-07-12 13:57:33 +0930 | [diff] [blame] | 29 | int pldm_transport_poll(struct pldm_transport *transport, int timeout); |
Rashmica Gupta | c1b66f4 | 2022-12-09 16:24:45 +1100 | [diff] [blame] | 30 | |
| 31 | /** |
| 32 | * @brief Asynchronously send a PLDM message. Control is immediately returned to |
| 33 | * the caller. |
| 34 | * |
| 35 | * @pre The pldm transport instance must be initialised; otherwise, |
| 36 | * PLDM_REQUESTER_INVALID_SETUP is returned. If the transport requires a |
| 37 | * TID to transport specific identifier mapping, this must already be set |
| 38 | * up. |
| 39 | * |
| 40 | * @param[in] ctx - pldm transport instance |
| 41 | * @param[in] tid - destination PLDM TID |
Rashmica Gupta | f1ebde4 | 2023-07-31 14:17:57 +1000 | [diff] [blame] | 42 | * @param[in] pldm_msg - caller owned pointer to PLDM msg. If this is NULL, |
| 43 | * PLDM_REQUESTER_INVALID_SETUP is returned. |
| 44 | * @param[in] msg_len - size of PLDM msg. If this is less than the minimum size |
| 45 | * of a PLDM msg PLDM_REQUESTER_NOT_REQ_MSG is returned. |
Rashmica Gupta | c1b66f4 | 2022-12-09 16:24:45 +1100 | [diff] [blame] | 46 | * Otherwise, if this is not the correct length of the PLDM msg, |
| 47 | * behaviour is undefined. |
| 48 | * |
| 49 | * @return pldm_requester_rc_t (errno may be set) |
| 50 | */ |
| 51 | pldm_requester_rc_t pldm_transport_send_msg(struct pldm_transport *transport, |
| 52 | pldm_tid_t tid, |
Rashmica Gupta | f1ebde4 | 2023-07-31 14:17:57 +1000 | [diff] [blame] | 53 | const void *pldm_msg, |
| 54 | size_t msg_len); |
Rashmica Gupta | c1b66f4 | 2022-12-09 16:24:45 +1100 | [diff] [blame] | 55 | |
| 56 | /** |
Rashmica Gupta | f1ebde4 | 2023-07-31 14:17:57 +1000 | [diff] [blame] | 57 | * @brief Asynchronously get a PLDM message. Control is immediately returned to the |
Rashmica Gupta | c1b66f4 | 2022-12-09 16:24:45 +1100 | [diff] [blame] | 58 | * caller. |
| 59 | * |
| 60 | * @pre The pldm transport instance must be initialised; otherwise, |
| 61 | * PLDM_REQUESTER_INVALID_SETUP is returned. If the transport requires a |
| 62 | * TID to transport specific identifier mapping, this must already be set |
| 63 | * up. |
| 64 | * |
| 65 | * @param[in] ctx - pldm transport instance |
Rashmica Gupta | 2457629 | 2023-07-31 14:02:41 +1000 | [diff] [blame] | 66 | * @param[out] tid - source PLDM TID |
Rashmica Gupta | f1ebde4 | 2023-07-31 14:17:57 +1000 | [diff] [blame] | 67 | * @param[out] pldm_msg - *pldm_msg will point to the received PLDM msg if |
Rashmica Gupta | c1b66f4 | 2022-12-09 16:24:45 +1100 | [diff] [blame] | 68 | * return code is PLDM_REQUESTER_SUCCESS; otherwise, NULL. On |
| 69 | * success this function allocates memory, caller to |
Rashmica Gupta | f1ebde4 | 2023-07-31 14:17:57 +1000 | [diff] [blame] | 70 | * free(*pldm_msg). |
| 71 | * @param[out] msg_len - caller owned pointer that will be made to point to |
| 72 | * the size of the PLDM msg. If NULL, |
Rashmica Gupta | c1b66f4 | 2022-12-09 16:24:45 +1100 | [diff] [blame] | 73 | * PLDM_REQUESTER_INVALID_SETUP is returned. |
| 74 | * |
| 75 | * @return pldm_requester_rc_t (errno may be set). Failure is returned if no |
Rashmica Gupta | f1ebde4 | 2023-07-31 14:17:57 +1000 | [diff] [blame] | 76 | * PLDM messages are available. |
Rashmica Gupta | c1b66f4 | 2022-12-09 16:24:45 +1100 | [diff] [blame] | 77 | * |
| 78 | */ |
| 79 | pldm_requester_rc_t pldm_transport_recv_msg(struct pldm_transport *transport, |
Rashmica Gupta | 2457629 | 2023-07-31 14:02:41 +1000 | [diff] [blame] | 80 | pldm_tid_t *tid, void **pldm_msg, |
Rashmica Gupta | f1ebde4 | 2023-07-31 14:17:57 +1000 | [diff] [blame] | 81 | size_t *msg_len); |
Rashmica Gupta | c1b66f4 | 2022-12-09 16:24:45 +1100 | [diff] [blame] | 82 | |
| 83 | /** |
| 84 | * @brief Synchronously send a PLDM request and receive the response. Control is |
| 85 | * returned to the caller once the response is received. |
| 86 | * |
Thu Nguyen | b01fb1c | 2023-05-28 09:16:46 +0700 | [diff] [blame] | 87 | * pldm_transport_send_recv() will discard messages received on the underlying transport instance |
| 88 | * that are not a response that matches the request. Do not use this function if you're attempting |
| 89 | * to use the transport instance asynchronously, as this discard behaviour will affect other |
| 90 | * responses that you may care about. |
| 91 | * |
Rashmica Gupta | c1b66f4 | 2022-12-09 16:24:45 +1100 | [diff] [blame] | 92 | * @pre The pldm transport instance must be initialised; otherwise, |
| 93 | * PLDM_REQUESTER_INVALID_SETUP is returned. If the transport requires a |
| 94 | * TID to transport specific identifier mapping, this must already be set |
| 95 | * up. |
| 96 | * |
| 97 | * @param[in] ctx - pldm transport instance with a registered transport |
| 98 | * @param[in] tid - destination PLDM TID |
| 99 | * @param[in] pldm_req_msg - caller owned pointer to PLDM request msg or async |
| 100 | * notification. If NULL, PLDM_REQUESTER_INVALID_SETUP is returned. |
| 101 | * @param[in] req_msg_len - size of PLDM request msg. If this is less than the |
| 102 | * minimum size of a PLDM msg PLDM_REQUESTER_NOT_REQ_MSG is returned. |
| 103 | * Otherwise, if this is not the correct length of the PLDM msg, |
| 104 | * behaviour is undefined. |
| 105 | * @param[out] pldm_resp_msg - *pldm_resp_msg will point to PLDM response msg if |
| 106 | * return code is PLDM_REQUESTER_SUCCESS; otherwise, NULL. On |
| 107 | * success this function allocates memory, caller to |
| 108 | * free(*pldm_resp_msg). |
| 109 | * @param[out] resp_msg_len - caller owned pointer that will be made to point to |
| 110 | * the size of the PLDM response msg. If NULL, |
| 111 | * PLDM_REQUESTER_INVALID_SETUP is returned. |
| 112 | * |
| 113 | * @return pldm_requester_rc_t (errno may be set) |
| 114 | */ |
| 115 | pldm_requester_rc_t |
| 116 | pldm_transport_send_recv_msg(struct pldm_transport *transport, pldm_tid_t tid, |
| 117 | const void *pldm_req_msg, size_t req_msg_len, |
| 118 | void **pldm_resp_msg, size_t *resp_msg_len); |
| 119 | |
| 120 | #ifdef __cplusplus |
| 121 | } |
| 122 | #endif |
| 123 | |
| 124 | #endif /* TRANSPORT_PLDM_H */ |