libpldm: implement responder flow for SetBIOSTable

For the responder, need to encode responder data and send requester,
waiting for recive requester data to decode, so need to implement
encode/decode(Responder 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: I74b736adc3c78a8197eadfa66804971b57ca42fd
diff --git a/libpldm/bios.c b/libpldm/bios.c
index bae2d37..6dbc0b0 100644
--- a/libpldm/bios.c
+++ b/libpldm/bios.c
@@ -606,3 +606,55 @@
 
 	return PLDM_SUCCESS;
 }
+
+int encode_set_bios_table_resp(uint8_t instance_id, uint8_t completion_code,
+			       uint32_t next_transfer_handle,
+			       struct pldm_msg *msg)
+{
+	int rc = PLDM_SUCCESS;
+
+	if (msg == NULL) {
+		return PLDM_ERROR_INVALID_DATA;
+	}
+
+	struct pldm_header_info header = {0};
+	header.instance = instance_id;
+	header.msg_type = PLDM_RESPONSE;
+	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_resp *response =
+	    (struct pldm_set_bios_table_resp *)msg->payload;
+	response->completion_code = completion_code;
+	response->next_transfer_handle = htole32(next_transfer_handle);
+
+	return PLDM_SUCCESS;
+}
+
+int decode_set_bios_table_req(const struct pldm_msg *msg, size_t payload_length,
+			      uint32_t *transfer_handle, uint8_t *transfer_flag,
+			      uint8_t *table_type, struct variable_field *table)
+{
+	if (msg == NULL || transfer_handle == NULL || transfer_flag == NULL ||
+	    table_type == NULL || table == NULL) {
+		return PLDM_ERROR_INVALID_DATA;
+	}
+
+	if (payload_length < PLDM_SET_BIOS_TABLE_MIN_REQ_BYTES) {
+		return PLDM_ERROR_INVALID_LENGTH;
+	}
+
+	struct pldm_set_bios_table_req *request =
+	    (struct pldm_set_bios_table_req *)msg->payload;
+	*transfer_handle = le32toh(request->transfer_handle);
+	*transfer_flag = request->transfer_flag;
+	*table_type = request->table_type;
+	table->length = payload_length - PLDM_SET_BIOS_TABLE_MIN_REQ_BYTES;
+	table->ptr = request->table_data;
+
+	return PLDM_SUCCESS;
+}