bios_table: Implement find attr entry by string handle
Implement find attribute table entry by string handle
Signed-off-by: John Wang <wangzqbj@inspur.com>
Change-Id: I884043df1b75e48d737bb37b8f0f724c32bb3334
diff --git a/libpldm/bios_table.c b/libpldm/bios_table.c
index 4af4661..e4e7d96 100644
--- a/libpldm/bios_table.c
+++ b/libpldm/bios_table.c
@@ -1036,6 +1036,21 @@
&handle);
}
+static bool attr_table_string_handle_equal(const void *entry, const void *key)
+{
+ uint16_t handle = *(uint16_t *)key;
+ return pldm_bios_table_attr_entry_decode_string_handle(entry) == handle;
+}
+
+const struct pldm_bios_attr_table_entry *
+pldm_bios_table_attr_find_by_string_handle(const void *table, size_t length,
+ uint16_t handle)
+{
+ return pldm_bios_table_entry_find_from_table(
+ table, length, PLDM_BIOS_ATTR_TABLE, attr_table_string_handle_equal,
+ &handle);
+}
+
static bool attr_value_table_handle_equal(const void *entry, const void *key)
{
uint16_t handle = *(uint16_t *)key;
diff --git a/libpldm/bios_table.h b/libpldm/bios_table.h
index 66d620f..cf25757 100644
--- a/libpldm/bios_table.h
+++ b/libpldm/bios_table.h
@@ -196,6 +196,16 @@
pldm_bios_table_attr_find_by_handle(const void *table, size_t length,
uint16_t handle);
+/** @brief Find an entry in attribute table by string handle
+ * @param[in] table - The BIOS Attribute Table
+ * @param[in] length - Length of the BIOS Attribute Table
+ * @param[in] handle - The string handle
+ * @return Pointer to the entry
+ */
+const struct pldm_bios_attr_table_entry *
+pldm_bios_table_attr_find_by_string_handle(const void *table, size_t length,
+ uint16_t handle);
+
/** @struct pldm_bios_table_attr_entry_enum_info
*
* An auxiliary structure for passing parameters to @ref
diff --git a/libpldm/tests/libpldm_bios_table_test.cpp b/libpldm/tests/libpldm_bios_table_test.cpp
index b4a6022..93477de 100644
--- a/libpldm/tests/libpldm_bios_table_test.cpp
+++ b/libpldm/tests/libpldm_bios_table_test.cpp
@@ -491,7 +491,7 @@
std::vector<uint8_t> stringEntry{
1, 0, /* attr handle */
1, /* attr type */
- 12, 0, /* attr name handle */
+ 2, 0, /* attr name handle */
1, /* string type */
1, 0, /* minimum length of the string in bytes */
100, 0, /* maximum length of the string in bytes */
@@ -501,7 +501,7 @@
std::vector<uint8_t> integerEntry{
0, 0, /* attr handle */
3, /* attr type */
- 1, 0, /* attr name handle */
+ 3, 0, /* attr name handle */
1, 0, 0, 0, 0, 0, 0, 0, /* lower bound */
10, 0, 0, 0, 0, 0, 0, 0, /* upper bound */
2, 0, 0, 0, /* scalar increment */
@@ -520,6 +520,17 @@
entry = pldm_bios_table_attr_find_by_handle(table.data(), table.size(), 3);
EXPECT_EQ(entry, nullptr);
+
+ entry = pldm_bios_table_attr_find_by_string_handle(table.data(),
+ table.size(), 2);
+ EXPECT_NE(entry, nullptr);
+ p = reinterpret_cast<const uint8_t*>(entry);
+ EXPECT_THAT(std::vector<uint8_t>(p, p + stringEntry.size()),
+ ElementsAreArray(stringEntry));
+
+ entry = pldm_bios_table_attr_find_by_string_handle(table.data(),
+ table.size(), 4);
+ EXPECT_EQ(entry, nullptr);
}
TEST(AttrValTable, HeaderDecodeTest)