base: GetTID responder implementation
A pldm terminus is defined as the point of communication termination
for PLDM messages and the PLDM functions associated with those messages.
The Terminus ID(TID) is a value that identifies a PLDM terminus.
This commit assignes 1 to the BMC as the TID.
Signed-off-by: John Wang <wangzqbj@inspur.com>
Change-Id: I7adb0e1274f326fe6cf148771f230f530c9a567c
diff --git a/libpldm/base.c b/libpldm/base.c
index 36df1b0..5927ba1 100644
--- a/libpldm/base.c
+++ b/libpldm/base.c
@@ -322,3 +322,48 @@
return PLDM_SUCCESS;
}
+
+int encode_get_tid_resp(uint8_t instance_id, uint8_t completion_code,
+ uint8_t tid, struct pldm_msg *msg)
+{
+ if (msg == NULL) {
+ return PLDM_ERROR_INVALID_DATA;
+ }
+
+ struct pldm_get_tid_resp *response =
+ (struct pldm_get_tid_resp *)msg->payload;
+
+ response->completion_code = completion_code;
+ struct pldm_header_info header = {0};
+ header.instance = instance_id;
+ header.msg_type = PLDM_RESPONSE;
+ header.command = PLDM_GET_TID;
+ pack_pldm_header(&header, &(msg->hdr));
+
+ response->tid = tid;
+
+ return PLDM_SUCCESS;
+}
+
+int decode_get_tid_resp(const struct pldm_msg *msg, size_t payload_length,
+ uint8_t *completion_code, uint8_t *tid)
+{
+ if (msg == NULL || tid == NULL || completion_code == NULL) {
+ return PLDM_ERROR_INVALID_DATA;
+ }
+
+ if (payload_length != PLDM_GET_TID_RESP_BYTES) {
+ return PLDM_ERROR_INVALID_LENGTH;
+ }
+
+ struct pldm_get_tid_resp *response =
+ (struct pldm_get_tid_resp *)msg->payload;
+ *completion_code = response->completion_code;
+ if (PLDM_SUCCESS != *completion_code) {
+ return PLDM_SUCCESS;
+ };
+
+ *tid = response->tid;
+
+ return PLDM_SUCCESS;
+}
diff --git a/libpldm/base.h b/libpldm/base.h
index f15ca7e..d30a300 100644
--- a/libpldm/base.h
+++ b/libpldm/base.h
@@ -23,6 +23,7 @@
/** @brief PLDM Commands
*/
enum pldm_supported_commands {
+ PLDM_GET_TID = 0x2,
PLDM_GET_PLDM_VERSION = 0x3,
PLDM_GET_PLDM_TYPES = 0x4,
PLDM_GET_PLDM_COMMANDS = 0x5
@@ -73,6 +74,7 @@
/* Response lengths are inclusive of completion code */
#define PLDM_GET_TYPES_RESP_BYTES 9
+#define PLDM_GET_TID_RESP_BYTES 2
#define PLDM_GET_COMMANDS_RESP_BYTES 33
/* Response data has only one version and does not contain the checksum */
#define PLDM_GET_VERSION_RESP_BYTES 10
@@ -181,6 +183,16 @@
uint8_t version_data[1]; //!< PLDM GetVersion version field
} __attribute__((packed));
+/** @struct pldm_get_tid_resp
+ *
+ * Structure representing PLDM get tid response.
+ */
+
+struct pldm_get_tid_resp {
+ uint8_t completion_code; //!< completion code
+ uint8_t tid; //!< PLDM GetTID TID field
+} __attribute__((packed));
+
/**
* @brief Populate the PLDM message with the PLDM header.The caller of this API
* allocates buffer for the PLDM header when forming the PLDM message.
@@ -292,6 +304,19 @@
uint32_t *next_transfer_handle,
uint8_t *transfer_flag, ver32_t *version);
+/* GetTID */
+
+/** @brief Decode a GetTID response message
+ *
+ * @param[in] msg - Response message
+ * @param[in] payload_length - Length of response message payload
+ * @param[out] completion_code - Pointer to response msg's PLDM completion code
+ * @param[out] tid - Pointer to the terminus id
+ * @return pldm_completion_codes
+ */
+int decode_get_tid_resp(const struct pldm_msg *msg, size_t payload_length,
+ uint8_t *completion_code, uint8_t *tid);
+
/* Responder */
/* GetPLDMTypes */
@@ -371,6 +396,21 @@
uint32_t *transfer_handle, uint8_t *transfer_opflag,
uint8_t *type);
+/* GetTID */
+
+/** @brief Create a PLDM response message for GetTID
+ *
+ * @param[in] instance_id - Message's instance id
+ * @param[in] completion_code - PLDM completion code
+ * @param[in] tid - Terminus ID
+ * @param[in,out] msg - Message will be written to this
+ * @return pldm_completion_codes
+ * @note Caller is responsible for memory alloc and dealloc of param
+ * 'msg.payload'
+ */
+int encode_get_tid_resp(uint8_t instance_id, uint8_t completion_code,
+ uint8_t tid, struct pldm_msg *msg);
+
#ifdef __cplusplus
}
#endif