libpldm: Implement encode/decode for GetBIOSAttributeCurrentValueByHandle

The GetBIOSAttributeCurrentValueByHandle command is used to get the
current value of the BIOS attribute by AttributeNameHandle.
The spec of GetBIOSAttributeCurrentValueByHandle command refers to
DSP0247_1.0.0: 8.8.

Signed-off-by: Adair Li <lichao.lc01@inspur.com>
Change-Id: Ic87408b0c02fd686033907f197130543ed7515c5
diff --git a/libpldm/bios.c b/libpldm/bios.c
index 958b7c8..151ba29 100644
--- a/libpldm/bios.c
+++ b/libpldm/bios.c
@@ -321,6 +321,66 @@
 	return PLDM_SUCCESS;
 }
 
+int encode_get_bios_attribute_current_value_by_handle_req(
+    uint8_t instance_id, uint32_t transfer_handle, uint8_t transfer_op_flag,
+    uint16_t attribute_handle, struct pldm_msg *msg)
+{
+	struct pldm_header_info header = {0};
+
+	if (msg == NULL) {
+		return PLDM_ERROR_INVALID_DATA;
+	}
+
+	header.msg_type = PLDM_REQUEST;
+	header.instance = instance_id;
+	header.pldm_type = PLDM_BIOS;
+	header.command = PLDM_GET_BIOS_ATTRIBUTE_CURRENT_VALUE_BY_HANDLE;
+	pack_pldm_header(&header, &(msg->hdr));
+
+	struct pldm_get_bios_attribute_current_value_by_handle_req *request =
+	    (struct pldm_get_bios_attribute_current_value_by_handle_req *)
+		msg->payload;
+
+	request->transfer_handle = htole32(transfer_handle);
+	request->transfer_op_flag = transfer_op_flag;
+	request->attribute_handle = htole16(attribute_handle);
+	return PLDM_SUCCESS;
+}
+
+int decode_get_bios_attribute_current_value_by_handle_resp(
+    const struct pldm_msg *msg, size_t payload_length, uint8_t *completion_code,
+    uint32_t *next_transfer_handle, uint8_t *transfer_flag,
+    struct variable_field *attribute_data)
+{
+	if (msg == NULL || transfer_flag == NULL ||
+	    next_transfer_handle == NULL || completion_code == NULL) {
+		return PLDM_ERROR_INVALID_DATA;
+	}
+
+	struct pldm_get_bios_attribute_current_value_by_handle_resp *response =
+	    (struct pldm_get_bios_attribute_current_value_by_handle_resp *)
+		msg->payload;
+
+	*completion_code = response->completion_code;
+
+	if (PLDM_SUCCESS != *completion_code) {
+		return PLDM_SUCCESS;
+	}
+
+	if (payload_length <=
+	    PLDM_GET_BIOS_ATTR_CURR_VAL_BY_HANDLE_MIN_RESP_BYTES) {
+		return PLDM_ERROR_INVALID_LENGTH;
+	}
+
+	*next_transfer_handle = le32toh(response->next_transfer_handle);
+	*transfer_flag = response->transfer_flag;
+
+	attribute_data->ptr = response->attribute_data;
+	attribute_data->length = payload_length - sizeof(*response) + 1;
+
+	return PLDM_SUCCESS;
+}
+
 int decode_get_bios_attribute_current_value_by_handle_req(
     const struct pldm_msg *msg, size_t payload_length,
     uint32_t *transfer_handle, uint8_t *transfer_op_flag,