libpldm: Implement requester flow for SetBIOSTable
For the requester, need to encode request data and send responder,
waiting for recive responder data to decode, so need to implement
encode/decode(Requester flow only) for SetBIOSTable.
Tested: the unit tests functions have been added to check these APIs.
Signed-off-by: George Liu <liuxiwei@inspur.com>
Change-Id: I410c64b8bbc8d37c9b5baa5d95bbff94f25bd7be
diff --git a/libpldm/bios.c b/libpldm/bios.c
index 151ba29..bae2d37 100644
--- a/libpldm/bios.c
+++ b/libpldm/bios.c
@@ -544,3 +544,65 @@
return PLDM_SUCCESS;
}
+
+int encode_set_bios_table_req(uint8_t instance_id, uint32_t transfer_handle,
+ uint8_t transfer_flag, uint8_t table_type,
+ const uint8_t *table_data, size_t table_length,
+ struct pldm_msg *msg, size_t payload_length)
+{
+ int rc = PLDM_SUCCESS;
+
+ if (msg == NULL || table_data == NULL) {
+ return PLDM_ERROR_INVALID_DATA;
+ }
+
+ if (PLDM_SET_BIOS_TABLE_MIN_REQ_BYTES + table_length !=
+ payload_length) {
+ return PLDM_ERROR_INVALID_LENGTH;
+ }
+
+ struct pldm_header_info header = {0};
+ header.instance = instance_id;
+ header.msg_type = PLDM_REQUEST;
+ header.pldm_type = PLDM_BIOS;
+ header.command = PLDM_SET_BIOS_TABLE;
+
+ if ((rc = pack_pldm_header(&header, &(msg->hdr))) > PLDM_SUCCESS) {
+ return rc;
+ }
+
+ struct pldm_set_bios_table_req *request =
+ (struct pldm_set_bios_table_req *)msg->payload;
+ request->transfer_handle = htole32(transfer_handle);
+ request->transfer_flag = transfer_flag;
+ request->table_type = table_type;
+ memcpy(request->table_data, table_data, table_length);
+
+ return PLDM_SUCCESS;
+}
+
+int decode_set_bios_table_resp(const struct pldm_msg *msg,
+ size_t payload_length, uint8_t *completion_code,
+ uint32_t *next_transfer_handle)
+{
+ if (msg == NULL || completion_code == NULL ||
+ next_transfer_handle == NULL) {
+ return PLDM_ERROR_INVALID_DATA;
+ }
+
+ *completion_code = msg->payload[0];
+ if (PLDM_SUCCESS != *completion_code) {
+ return PLDM_SUCCESS;
+ }
+
+ if (payload_length != PLDM_SET_BIOS_TABLE_RESP_BYTES) {
+ return PLDM_ERROR_INVALID_LENGTH;
+ }
+
+ struct pldm_set_bios_table_resp *response =
+ (struct pldm_set_bios_table_resp *)msg->payload;
+
+ *next_transfer_handle = le32toh(response->next_transfer_handle);
+
+ return PLDM_SUCCESS;
+}