decode: setBiosAttributeValue: Use variable_field
Signed-off-by: John Wang <wangzqbj@inspur.com>
Change-Id: I39a02a65d95157450bb57415977c902d5e856560
diff --git a/libpldm/bios.c b/libpldm/bios.c
index c09696e..958b7c8 100644
--- a/libpldm/bios.c
+++ b/libpldm/bios.c
@@ -435,15 +435,13 @@
return PLDM_SUCCESS;
}
-int decode_set_bios_attribute_current_value_req(const struct pldm_msg *msg,
- size_t payload_length,
- uint32_t *transfer_handle,
- uint8_t *transfer_flag,
- uint8_t *attribute_data,
- size_t *attribute_length)
+int decode_set_bios_attribute_current_value_req(
+ const struct pldm_msg *msg, size_t payload_length,
+ uint32_t *transfer_handle, uint8_t *transfer_flag,
+ struct variable_field *attribute)
{
if (msg == NULL || transfer_handle == NULL || transfer_flag == NULL ||
- attribute_data == NULL || attribute_length == NULL) {
+ attribute == NULL) {
return PLDM_ERROR_INVALID_DATA;
}
if (payload_length < PLDM_SET_BIOS_ATTR_CURR_VAL_MIN_REQ_BYTES) {
@@ -454,10 +452,9 @@
(struct pldm_set_bios_attribute_current_value_req *)msg->payload;
*transfer_handle = le32toh(request->transfer_handle);
*transfer_flag = request->transfer_flag;
- *attribute_length =
+ attribute->length =
payload_length - PLDM_SET_BIOS_ATTR_CURR_VAL_MIN_REQ_BYTES;
- memcpy(attribute_data, request->attribute_data, *attribute_length);
-
+ attribute->ptr = request->attribute_data;
return PLDM_SUCCESS;
}
diff --git a/libpldm/bios.h b/libpldm/bios.h
index 065e53e..64ee683 100644
--- a/libpldm/bios.h
+++ b/libpldm/bios.h
@@ -10,6 +10,7 @@
#include <stdint.h>
#include "base.h"
+#include "utils.h"
/* Response lengths are inclusive of completion code */
#define PLDM_GET_DATE_TIME_RESP_BYTES 8
@@ -390,17 +391,16 @@
* @param[in] payload_length - Length of request message payload
* @param[out] transfer_handle - Handle to identify a BIOS table transfer
* @param[out] transfer_flag - Flag to indicate what part of the transfer
- * this request represents
- * @param[out] attribute_data - Contains current value of attribute
- * @param[out] attribute_length - Pointer to length of attribute
+ * this request represents
+ * @param[out] attribute - Struct variable_field, contains a pointer to the
+ * attribute field in the buffer of \p msg, \p msg must
+ * be valid when \p attribute is used.
* @return pldm_completion_codes
*/
-int decode_set_bios_attribute_current_value_req(const struct pldm_msg *msg,
- size_t payload_length,
- uint32_t *transfer_handle,
- uint8_t *transfer_flag,
- uint8_t *attribute_data,
- size_t *attribute_length);
+int decode_set_bios_attribute_current_value_req(
+ const struct pldm_msg *msg, size_t payload_length,
+ uint32_t *transfer_handle, uint8_t *transfer_flag,
+ struct variable_field *attribute);
/** @brief Create a PLDM response message for SetBiosAttributeCurrentValue
*
diff --git a/test/libpldm_bios_test.cpp b/test/libpldm_bios_test.cpp
index 012206a..ad07877 100644
--- a/test/libpldm_bios_test.cpp
+++ b/test/libpldm_bios_test.cpp
@@ -671,38 +671,33 @@
uint32_t retTransferHandle;
uint8_t retTransferFlag;
- uint32_t retAttributeData;
- size_t retAttributeDataLength;
+ struct variable_field attribute;
auto rc = decode_set_bios_attribute_current_value_req(
request, requestMsg.size() - hdrSize, &retTransferHandle,
- &retTransferFlag, reinterpret_cast<uint8_t*>(&retAttributeData),
- &retAttributeDataLength);
+ &retTransferFlag, &attribute);
EXPECT_EQ(rc, PLDM_SUCCESS);
EXPECT_EQ(retTransferHandle, transferHandle);
EXPECT_EQ(retTransferFlag, transferFlag);
- EXPECT_EQ(retAttributeDataLength, sizeof(attributeData));
- EXPECT_EQ(0,
- memcmp(&retAttributeData, &attributeData, sizeof(attributeData)));
+ EXPECT_EQ(attribute.length, sizeof(attributeData));
+ EXPECT_EQ(0, memcmp(attribute.ptr, &attributeData, sizeof(attributeData)));
}
TEST(SetBiosAttributeCurrentValue, testBadDecodeRequest)
{
uint32_t transferHandle = 32;
uint8_t transferFlag = PLDM_START_AND_END;
- uint32_t attributeData = 44;
- size_t attributeDataLength = sizeof(attributeData);
+ struct variable_field attribute;
std::array<uint8_t, hdrSize + PLDM_SET_BIOS_ATTR_CURR_VAL_MIN_REQ_BYTES - 1>
requestMsg{};
auto request = reinterpret_cast<struct pldm_msg*>(requestMsg.data());
auto rc = decode_set_bios_attribute_current_value_req(
- nullptr, 0, &transferHandle, &transferFlag,
- reinterpret_cast<uint8_t*>(&attributeData), &attributeDataLength);
+ nullptr, 0, &transferHandle, &transferFlag, &attribute);
EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
rc = decode_set_bios_attribute_current_value_req(
request, requestMsg.size() - hdrSize, &transferHandle, &transferFlag,
- reinterpret_cast<uint8_t*>(&attributeData), &attributeDataLength);
+ &attribute);
EXPECT_EQ(rc, PLDM_ERROR_INVALID_LENGTH);
}