Correct checkpatch findings in uefi service
UEFI service has a huge amount of checkpatch findings. This commit
eliminates them before the implementation of the new feature is
started.
Change-Id: I211c52339660cd9b0d906c52669095df322bf4aa
Signed-off-by: Gabor Toth <gabor.toth2@arm.com>
diff --git a/components/service/uefi/smm_variable/backend/test/variable_index_tests.cpp b/components/service/uefi/smm_variable/backend/test/variable_index_tests.cpp
index b9b81f9..113fcda 100644
--- a/components/service/uefi/smm_variable/backend/test/variable_index_tests.cpp
+++ b/components/service/uefi/smm_variable/backend/test/variable_index_tests.cpp
@@ -1,16 +1,15 @@
/*
- * Copyright (c) 2021-2022, Arm Limited and Contributors. All rights reserved.
+ * Copyright (c) 2021-2023, Arm Limited and Contributors. All rights reserved.
*
* SPDX-License-Identifier: BSD-3-Clause
*/
-#include <wchar.h>
-#include <string>
-#include <vector>
#include <CppUTest/TestHarness.h>
#include <service/uefi/smm_variable/backend/variable_index.h>
#include <service/uefi/smm_variable/backend/variable_index_iterator.h>
-
+#include <string>
+#include <vector>
+#include <wchar.h>
TEST_GROUP(UefiVariableIndexTests)
{
@@ -58,7 +57,6 @@
std::vector<int16_t> var_name;
for (size_t i = 0; i < string.size(); i++) {
-
var_name.push_back((int16_t)string[i]);
}
@@ -71,36 +69,23 @@
{
struct variable_info *info = NULL;
- info = variable_index_add_entry(
- &m_variable_index,
- &guid_1,
- name_1.size() * sizeof(int16_t),
- name_1.data());
+ info = variable_index_add_entry(&m_variable_index, &guid_1,
+ name_1.size() * sizeof(int16_t), name_1.data());
CHECK_TRUE(info);
- variable_index_set_variable(
- info,
- EFI_VARIABLE_BOOTSERVICE_ACCESS);
+ variable_index_set_variable(info, EFI_VARIABLE_BOOTSERVICE_ACCESS);
- info = variable_index_add_entry(
- &m_variable_index,
- &guid_2,
- name_2.size() * sizeof(int16_t),
- name_2.data());
+ info = variable_index_add_entry(&m_variable_index, &guid_2,
+ name_2.size() * sizeof(int16_t), name_2.data());
CHECK_TRUE(info);
- variable_index_set_variable(
- info,
- EFI_VARIABLE_NON_VOLATILE | EFI_VARIABLE_BOOTSERVICE_ACCESS);
+ variable_index_set_variable(info, EFI_VARIABLE_NON_VOLATILE |
+ EFI_VARIABLE_BOOTSERVICE_ACCESS);
- info = variable_index_add_entry(
- &m_variable_index,
- &guid_1,
- name_3.size() * sizeof(int16_t),
- name_3.data());
+ info = variable_index_add_entry(&m_variable_index, &guid_1,
+ name_3.size() * sizeof(int16_t), name_3.data());
CHECK_TRUE(info);
- variable_index_set_variable(
- info,
- EFI_VARIABLE_NON_VOLATILE |
- EFI_VARIABLE_RUNTIME_ACCESS | EFI_VARIABLE_BOOTSERVICE_ACCESS);
+ variable_index_set_variable(info, EFI_VARIABLE_NON_VOLATILE |
+ EFI_VARIABLE_RUNTIME_ACCESS |
+ EFI_VARIABLE_BOOTSERVICE_ACCESS);
}
static const size_t MAX_VARIABLES = 10;
@@ -119,27 +104,18 @@
struct variable_info *info = NULL;
/* Expect not to find a variable */
- info = variable_index_find(
- &m_variable_index,
- &guid_1,
- name_1.size() * sizeof(int16_t),
- name_1.data());
+ info = variable_index_find(&m_variable_index, &guid_1, name_1.size() * sizeof(int16_t),
+ name_1.data());
POINTERS_EQUAL(NULL, info);
/* Expect also find next to be rejected */
- info = variable_index_find_next(
- &m_variable_index,
- &guid_1,
- name_1.size() * sizeof(int16_t),
- name_1.data(),
- &status);
+ info = variable_index_find_next(&m_variable_index, &guid_1, name_1.size() * sizeof(int16_t),
+ name_1.data(), &status);
POINTERS_EQUAL(NULL, info);
UNSIGNED_LONGLONGS_EQUAL(EFI_INVALID_PARAMETER, status);
/* Remove should silently return */
- variable_index_clear_variable(
- &m_variable_index,
- info);
+ variable_index_clear_variable(&m_variable_index, info);
}
TEST(UefiVariableIndexTests, addWithOversizedName)
@@ -149,22 +125,16 @@
name = to_variable_name(L"a long variable name that exceeds the length limit");
- info = variable_index_add_entry(
- &m_variable_index,
- &guid_1,
- name.size() * sizeof(int16_t),
- name.data());
+ info = variable_index_add_entry(&m_variable_index, &guid_1, name.size() * sizeof(int16_t),
+ name.data());
/* Expect the add to fail because of an oversized name */
POINTERS_EQUAL(NULL, info);
name = to_variable_name(L"a long variable name that fits!");
- info = variable_index_add_entry(
- &m_variable_index,
- &guid_1,
- name.size() * sizeof(int16_t),
- name.data());
+ info = variable_index_add_entry(&m_variable_index, &guid_1, name.size() * sizeof(int16_t),
+ name.data());
/* Expect the add succeed */
CHECK_TRUE(info);
@@ -177,12 +147,8 @@
/* Expect to be able to fill the index */
for (size_t i = 0; i < MAX_VARIABLES; ++i) {
-
- info = variable_index_add_entry(
- &m_variable_index,
- &guid,
- name_1.size() * sizeof(int16_t),
- name_1.data());
+ info = variable_index_add_entry(&m_variable_index, &guid,
+ name_1.size() * sizeof(int16_t), name_1.data());
CHECK_TRUE(info);
@@ -191,16 +157,12 @@
}
/* Variable index should now be full */
- info = variable_index_add_entry(
- &m_variable_index,
- &guid,
- name_1.size() * sizeof(int16_t),
- name_1.data());
+ info = variable_index_add_entry(&m_variable_index, &guid, name_1.size() * sizeof(int16_t),
+ name_1.data());
POINTERS_EQUAL(NULL, info);
}
-
TEST(UefiVariableIndexTests, enumerateStore)
{
const struct variable_info *info = NULL;
@@ -209,49 +171,36 @@
create_variables();
- info = variable_index_find_next(
- &m_variable_index,
- &guid_1,
- null_name.size() * sizeof(int16_t),
- null_name.data(),
- &status);
+ info = variable_index_find_next(&m_variable_index, &guid_1,
+ null_name.size() * sizeof(int16_t), null_name.data(),
+ &status);
CHECK_TRUE(info);
UNSIGNED_LONGLONGS_EQUAL(EFI_SUCCESS, status);
LONGS_EQUAL(EFI_VARIABLE_BOOTSERVICE_ACCESS, info->metadata.attributes);
MEMCMP_EQUAL(&guid_1, &info->metadata.guid, sizeof(EFI_GUID));
MEMCMP_EQUAL(name_1.data(), info->metadata.name, name_1.size());
- info = variable_index_find_next(
- &m_variable_index,
- &info->metadata.guid,
- info->metadata.name_size,
- info->metadata.name,
- &status);
+ info = variable_index_find_next(&m_variable_index, &info->metadata.guid,
+ info->metadata.name_size, info->metadata.name, &status);
CHECK_TRUE(info);
UNSIGNED_LONGLONGS_EQUAL(EFI_SUCCESS, status);
- LONGS_EQUAL(EFI_VARIABLE_NON_VOLATILE | EFI_VARIABLE_BOOTSERVICE_ACCESS, info->metadata.attributes);
+ LONGS_EQUAL(EFI_VARIABLE_NON_VOLATILE | EFI_VARIABLE_BOOTSERVICE_ACCESS,
+ info->metadata.attributes);
MEMCMP_EQUAL(&guid_2, &info->metadata.guid, sizeof(EFI_GUID));
MEMCMP_EQUAL(name_2.data(), info->metadata.name, name_2.size());
- info = variable_index_find_next(
- &m_variable_index,
- &info->metadata.guid,
- info->metadata.name_size,
- info->metadata.name,
- &status);
+ info = variable_index_find_next(&m_variable_index, &info->metadata.guid,
+ info->metadata.name_size, info->metadata.name, &status);
CHECK_TRUE(info);
UNSIGNED_LONGLONGS_EQUAL(EFI_SUCCESS, status);
- LONGS_EQUAL(EFI_VARIABLE_NON_VOLATILE |
- EFI_VARIABLE_RUNTIME_ACCESS | EFI_VARIABLE_BOOTSERVICE_ACCESS, info->metadata.attributes);
+ LONGS_EQUAL(EFI_VARIABLE_NON_VOLATILE | EFI_VARIABLE_RUNTIME_ACCESS |
+ EFI_VARIABLE_BOOTSERVICE_ACCESS,
+ info->metadata.attributes);
MEMCMP_EQUAL(&guid_1, &info->metadata.guid, sizeof(EFI_GUID));
MEMCMP_EQUAL(name_3.data(), info->metadata.name, name_3.size());
- info = variable_index_find_next(
- &m_variable_index,
- &info->metadata.guid,
- info->metadata.name_size,
- info->metadata.name,
- &status);
+ info = variable_index_find_next(&m_variable_index, &info->metadata.guid,
+ info->metadata.name_size, info->metadata.name, &status);
POINTERS_EQUAL(NULL, info);
UNSIGNED_LONGLONGS_EQUAL(EFI_NOT_FOUND, status);
}
@@ -290,35 +239,24 @@
const struct variable_info *info = NULL;
std::vector<int16_t> null_name = to_variable_name(L"");
- info = variable_index_find_next(
- &m_variable_index,
- &guid_1,
- null_name.size() * sizeof(int16_t),
- null_name.data(),
- &status);
+ info = variable_index_find_next(&m_variable_index, &guid_1,
+ null_name.size() * sizeof(int16_t), null_name.data(),
+ &status);
CHECK_TRUE(info);
UNSIGNED_LONGLONGS_EQUAL(EFI_SUCCESS, status);
UNSIGNED_LONGLONGS_EQUAL(EFI_VARIABLE_NON_VOLATILE | EFI_VARIABLE_BOOTSERVICE_ACCESS,
- info->metadata.attributes);
+ info->metadata.attributes);
- info = variable_index_find_next(
- &m_variable_index,
- &info->metadata.guid,
- info->metadata.name_size,
- info->metadata.name,
- &status);
+ info = variable_index_find_next(&m_variable_index, &info->metadata.guid,
+ info->metadata.name_size, info->metadata.name, &status);
CHECK_TRUE(info);
UNSIGNED_LONGLONGS_EQUAL(EFI_SUCCESS, status);
- UNSIGNED_LONGLONGS_EQUAL(EFI_VARIABLE_NON_VOLATILE |
- EFI_VARIABLE_RUNTIME_ACCESS | EFI_VARIABLE_BOOTSERVICE_ACCESS,
- info->metadata.attributes);
+ UNSIGNED_LONGLONGS_EQUAL(EFI_VARIABLE_NON_VOLATILE | EFI_VARIABLE_RUNTIME_ACCESS |
+ EFI_VARIABLE_BOOTSERVICE_ACCESS,
+ info->metadata.attributes);
- info = variable_index_find_next(
- &m_variable_index,
- &info->metadata.guid,
- info->metadata.name_size,
- info->metadata.name,
- &status);
+ info = variable_index_find_next(&m_variable_index, &info->metadata.guid,
+ info->metadata.name_size, info->metadata.name, &status);
POINTERS_EQUAL(NULL, info);
UNSIGNED_LONGLONGS_EQUAL(EFI_NOT_FOUND, status);
}
@@ -340,7 +278,6 @@
UNSIGNED_LONGS_EQUAL(sizeof(struct variable_metadata) * 1, dump_len);
}
-
TEST(UefiVariableIndexTests, removeVariable)
{
uint8_t buffer[MAX_VARIABLES * sizeof(struct variable_metadata)];
@@ -349,15 +286,10 @@
create_variables();
/* Remove one of the NV variables */
- info = variable_index_find(
- &m_variable_index,
- &guid_2,
- name_2.size() * sizeof(int16_t),
- name_2.data());
+ info = variable_index_find(&m_variable_index, &guid_2, name_2.size() * sizeof(int16_t),
+ name_2.data());
- variable_index_clear_variable(
- &m_variable_index,
- info);
+ variable_index_clear_variable(&m_variable_index, info);
/* Expect index to be dirty and for only one NV variable to be left */
size_t dump_len = 0;
@@ -367,15 +299,10 @@
UNSIGNED_LONGS_EQUAL((sizeof(struct variable_metadata) * 1), dump_len);
/* Remove the volatile variable */
- info = variable_index_find(
- &m_variable_index,
- &guid_1,
- name_1.size() * sizeof(int16_t),
- name_1.data());
+ info = variable_index_find(&m_variable_index, &guid_1, name_1.size() * sizeof(int16_t),
+ name_1.data());
- variable_index_clear_variable(
- &m_variable_index,
- info);
+ variable_index_clear_variable(&m_variable_index, info);
/* Expect index not to be dirty because there was no change to any NV variable */
dump_len = 0;
@@ -385,15 +312,10 @@
UNSIGNED_LONGS_EQUAL((sizeof(struct variable_metadata) * 1), dump_len);
/* Remove the remaining NV variable */
- info = variable_index_find(
- &m_variable_index,
- &guid_1,
- name_3.size() * sizeof(int16_t),
- name_3.data());
+ info = variable_index_find(&m_variable_index, &guid_1, name_3.size() * sizeof(int16_t),
+ name_3.data());
- variable_index_clear_variable(
- &m_variable_index,
- info);
+ variable_index_clear_variable(&m_variable_index, info);
/* Expect index to be dirty and dump to now be empty */
dump_len = 0;
@@ -407,12 +329,9 @@
efi_status_t status = EFI_SUCCESS;
std::vector<int16_t> null_name = to_variable_name(L"");
- info = variable_index_find_next(
- &m_variable_index,
- &guid_1,
- null_name.size() * sizeof(int16_t),
- null_name.data(),
- &status);
+ info = variable_index_find_next(&m_variable_index, &guid_1,
+ null_name.size() * sizeof(int16_t), null_name.data(),
+ &status);
POINTERS_EQUAL(NULL, info);
UNSIGNED_LONGLONGS_EQUAL(EFI_NOT_FOUND, status);
}
@@ -504,10 +423,7 @@
/* Set check constraints on one of the variables */
struct variable_info *info = variable_index_find(
- &m_variable_index,
- &guid_2,
- name_2.size() * sizeof(int16_t),
- name_2.data());
+ &m_variable_index, &guid_2, name_2.size() * sizeof(int16_t), name_2.data());
CHECK_TRUE(info);
CHECK_TRUE(info->is_variable_set);
@@ -521,15 +437,10 @@
/* Remove the variable but still expect the variable to be indexed
* because of the set constraints.
*/
- variable_index_clear_variable(
- &m_variable_index,
- info);
+ variable_index_clear_variable(&m_variable_index, info);
- info = variable_index_find(
- &m_variable_index,
- &guid_2,
- name_2.size() * sizeof(int16_t),
- name_2.data());
+ info = variable_index_find(&m_variable_index, &guid_2, name_2.size() * sizeof(int16_t),
+ name_2.data());
CHECK_TRUE(info);
CHECK_FALSE(info->is_variable_set);
@@ -540,34 +451,23 @@
efi_status_t status = EFI_NOT_FOUND;
std::vector<int16_t> null_name = to_variable_name(L"");
- info = variable_index_find_next(
- &m_variable_index,
- &guid_1,
- null_name.size() * sizeof(int16_t),
- null_name.data(),
- &status);
+ info = variable_index_find_next(&m_variable_index, &guid_1,
+ null_name.size() * sizeof(int16_t), null_name.data(),
+ &status);
CHECK_TRUE(info);
UNSIGNED_LONGLONGS_EQUAL(EFI_SUCCESS, status);
UNSIGNED_LONGLONGS_EQUAL(EFI_VARIABLE_BOOTSERVICE_ACCESS, info->metadata.attributes);
- info = variable_index_find_next(
- &m_variable_index,
- &info->metadata.guid,
- info->metadata.name_size,
- info->metadata.name,
- &status);
+ info = variable_index_find_next(&m_variable_index, &info->metadata.guid,
+ info->metadata.name_size, info->metadata.name, &status);
CHECK_TRUE(info);
UNSIGNED_LONGLONGS_EQUAL(EFI_SUCCESS, status);
- UNSIGNED_LONGLONGS_EQUAL(EFI_VARIABLE_NON_VOLATILE |
- EFI_VARIABLE_RUNTIME_ACCESS | EFI_VARIABLE_BOOTSERVICE_ACCESS,
- info->metadata.attributes);
+ UNSIGNED_LONGLONGS_EQUAL(EFI_VARIABLE_NON_VOLATILE | EFI_VARIABLE_RUNTIME_ACCESS |
+ EFI_VARIABLE_BOOTSERVICE_ACCESS,
+ info->metadata.attributes);
- info = variable_index_find_next(
- &m_variable_index,
- &info->metadata.guid,
- info->metadata.name_size,
- info->metadata.name,
- &status);
+ info = variable_index_find_next(&m_variable_index, &info->metadata.guid,
+ info->metadata.name_size, info->metadata.name, &status);
CHECK_FALSE(info);
UNSIGNED_LONGLONGS_EQUAL(EFI_NOT_FOUND, status);
@@ -622,19 +522,13 @@
/* Initially expect no variable_info */
struct variable_info *info = variable_index_find(
- &m_variable_index,
- &guid_2,
- name_2.size() * sizeof(int16_t),
- name_2.data());
+ &m_variable_index, &guid_2, name_2.size() * sizeof(int16_t), name_2.data());
CHECK_FALSE(info);
/* Adding the check constraints should result in an entry being added */
- info = variable_index_add_entry(
- &m_variable_index,
- &guid_2,
- name_2.size() * sizeof(int16_t),
- name_2.data());
+ info = variable_index_add_entry(&m_variable_index, &guid_2, name_2.size() * sizeof(int16_t),
+ name_2.data());
CHECK_TRUE(info);
variable_index_set_constraints(info, &constraints);
@@ -643,7 +537,7 @@
/* Updating the variable should cause the variable to be marked as set */
variable_index_set_variable(info,
- EFI_VARIABLE_RUNTIME_ACCESS | EFI_VARIABLE_BOOTSERVICE_ACCESS);
+ EFI_VARIABLE_RUNTIME_ACCESS | EFI_VARIABLE_BOOTSERVICE_ACCESS);
CHECK_TRUE(info->is_variable_set);
CHECK_TRUE(info->is_constraints_set);
diff --git a/components/service/uefi/smm_variable/backend/test/variable_store_tests.cpp b/components/service/uefi/smm_variable/backend/test/variable_store_tests.cpp
index 3e8b6b2..2ce6ca9 100644
--- a/components/service/uefi/smm_variable/backend/test/variable_store_tests.cpp
+++ b/components/service/uefi/smm_variable/backend/test/variable_store_tests.cpp
@@ -1,15 +1,15 @@
/*
- * Copyright (c) 2021-2022, Arm Limited and Contributors. All rights reserved.
+ * Copyright (c) 2021-2023, Arm Limited and Contributors. All rights reserved.
*
* SPDX-License-Identifier: BSD-3-Clause
*/
+#include <CppUTest/TestHarness.h>
+#include <service/secure_storage/backend/mock_store/mock_store.h>
+#include <service/uefi/smm_variable/backend/uefi_variable_store.h>
+#include <string.h>
#include <string>
#include <vector>
-#include <string.h>
-#include <CppUTest/TestHarness.h>
-#include <service/uefi/smm_variable/backend/uefi_variable_store.h>
-#include <service/secure_storage/backend/mock_store/mock_store.h>
TEST_GROUP(UefiVariableStoreTests)
{
@@ -18,26 +18,18 @@
m_persistent_backend = mock_store_init(&m_persistent_store);
m_volatile_backend = mock_store_init(&m_volatile_store);
- efi_status_t status = uefi_variable_store_init(
- &m_uefi_variable_store,
- OWNER_ID,
- MAX_VARIABLES,
- m_persistent_backend,
- m_volatile_backend);
+ efi_status_t status = uefi_variable_store_init(&m_uefi_variable_store, OWNER_ID,
+ MAX_VARIABLES, m_persistent_backend,
+ m_volatile_backend);
UNSIGNED_LONGLONGS_EQUAL(EFI_SUCCESS, status);
- uefi_variable_store_set_storage_limits(
- &m_uefi_variable_store,
- EFI_VARIABLE_NON_VOLATILE,
- STORE_CAPACITY,
- MAX_VARIABLE_SIZE);
+ uefi_variable_store_set_storage_limits(&m_uefi_variable_store,
+ EFI_VARIABLE_NON_VOLATILE, STORE_CAPACITY,
+ MAX_VARIABLE_SIZE);
- uefi_variable_store_set_storage_limits(
- &m_uefi_variable_store,
- 0,
- STORE_CAPACITY,
- MAX_VARIABLE_SIZE);
+ uefi_variable_store_set_storage_limits(&m_uefi_variable_store, 0, STORE_CAPACITY,
+ MAX_VARIABLE_SIZE);
setup_common_guid();
}
@@ -69,7 +61,6 @@
std::vector<int16_t> var_name;
for (size_t i = 0; i < string.size(); i++) {
-
var_name.push_back((int16_t)string[i]);
}
@@ -79,17 +70,13 @@
return var_name;
}
- bool compare_variable_name(
- const std::wstring &expected,
- const int16_t *name,
- size_t name_size) {
-
+ bool compare_variable_name(const std::wstring &expected, const int16_t *name,
+ size_t name_size)
+ {
bool is_equal = (expected.size() + 1 <= name_size / sizeof(int16_t));
for (size_t i = 0; is_equal && i < expected.size(); i++) {
-
if (name[i] != (int16_t)expected[i]) {
-
is_equal = false;
break;
}
@@ -98,18 +85,17 @@
return is_equal;
}
- efi_status_t set_variable(
- const std::wstring &name,
- const std::string &data,
- uint32_t attributes)
+ efi_status_t set_variable(const std::wstring &name, const std::string &data,
+ uint32_t attributes)
{
std::vector<int16_t> var_name = to_variable_name(name);
size_t name_size = var_name.size() * sizeof(int16_t);
size_t data_size = data.size();
- uint8_t msg_buffer[SMM_VARIABLE_COMMUNICATE_ACCESS_VARIABLE_SIZE(name_size, data_size)];
+ uint8_t msg_buffer[SMM_VARIABLE_COMMUNICATE_ACCESS_VARIABLE_SIZE(name_size,
+ data_size)];
SMM_VARIABLE_COMMUNICATE_ACCESS_VARIABLE *access_variable =
- (SMM_VARIABLE_COMMUNICATE_ACCESS_VARIABLE*)msg_buffer;
+ (SMM_VARIABLE_COMMUNICATE_ACCESS_VARIABLE *)msg_buffer;
access_variable->Guid = m_common_guid;
access_variable->Attributes = attributes;
@@ -118,20 +104,18 @@
memcpy(access_variable->Name, var_name.data(), name_size);
access_variable->DataSize = data_size;
- memcpy(&msg_buffer[SMM_VARIABLE_COMMUNICATE_ACCESS_VARIABLE_DATA_OFFSET(access_variable)],
- data.c_str(), data_size);
+ memcpy(&msg_buffer[SMM_VARIABLE_COMMUNICATE_ACCESS_VARIABLE_DATA_OFFSET(
+ access_variable)],
+ data.c_str(), data_size);
- efi_status_t status = uefi_variable_store_set_variable(
- &m_uefi_variable_store,
- access_variable);
+ efi_status_t status =
+ uefi_variable_store_set_variable(&m_uefi_variable_store, access_variable);
return status;
}
- efi_status_t get_variable(
- const std::wstring &name,
- std::string &data,
- size_t data_len_clamp = VARIABLE_BUFFER_SIZE)
+ efi_status_t get_variable(const std::wstring &name, std::string &data,
+ size_t data_len_clamp = VARIABLE_BUFFER_SIZE)
{
std::vector<int16_t> var_name = to_variable_name(name);
size_t name_size = var_name.size() * sizeof(int16_t);
@@ -139,7 +123,7 @@
uint8_t msg_buffer[VARIABLE_BUFFER_SIZE];
SMM_VARIABLE_COMMUNICATE_ACCESS_VARIABLE *access_variable =
- (SMM_VARIABLE_COMMUNICATE_ACCESS_VARIABLE*)msg_buffer;
+ (SMM_VARIABLE_COMMUNICATE_ACCESS_VARIABLE *)msg_buffer;
access_variable->Guid = m_common_guid;
access_variable->Attributes = 0;
@@ -147,50 +131,48 @@
access_variable->NameSize = name_size;
memcpy(access_variable->Name, var_name.data(), name_size);
- size_t max_data_len = (data_len_clamp == VARIABLE_BUFFER_SIZE) ?
- VARIABLE_BUFFER_SIZE -
- SMM_VARIABLE_COMMUNICATE_ACCESS_VARIABLE_DATA_OFFSET(access_variable) :
- data_len_clamp;
+ size_t max_data_len =
+ (data_len_clamp == VARIABLE_BUFFER_SIZE) ?
+ VARIABLE_BUFFER_SIZE -
+ SMM_VARIABLE_COMMUNICATE_ACCESS_VARIABLE_DATA_OFFSET(
+ access_variable) :
+ data_len_clamp;
access_variable->DataSize = max_data_len;
efi_status_t status = uefi_variable_store_get_variable(
- &m_uefi_variable_store,
- access_variable,
- max_data_len,
- &total_size);
+ &m_uefi_variable_store, access_variable, max_data_len, &total_size);
data.clear();
if (status == EFI_SUCCESS) {
-
- const char *data_start = (const char*)(msg_buffer +
- SMM_VARIABLE_COMMUNICATE_ACCESS_VARIABLE_DATA_OFFSET(access_variable));
+ const char *data_start =
+ (const char *)(msg_buffer +
+ SMM_VARIABLE_COMMUNICATE_ACCESS_VARIABLE_DATA_OFFSET(
+ access_variable));
data = std::string(data_start, access_variable->DataSize);
UNSIGNED_LONGLONGS_EQUAL(
- SMM_VARIABLE_COMMUNICATE_ACCESS_VARIABLE_TOTAL_SIZE(access_variable),
+ SMM_VARIABLE_COMMUNICATE_ACCESS_VARIABLE_TOTAL_SIZE(
+ access_variable),
total_size);
- }
- else if (status == EFI_BUFFER_TOO_SMALL) {
-
+ } else if (status == EFI_BUFFER_TOO_SMALL) {
/* String length set to reported variable length */
data.insert(0, access_variable->DataSize, '!');
UNSIGNED_LONGLONGS_EQUAL(
- SMM_VARIABLE_COMMUNICATE_ACCESS_VARIABLE_DATA_OFFSET(access_variable),
+ SMM_VARIABLE_COMMUNICATE_ACCESS_VARIABLE_DATA_OFFSET(
+ access_variable),
total_size);
}
return status;
}
- efi_status_t query_variable_info(
- uint32_t attributes,
- size_t *max_variable_storage_size,
- size_t *remaining_variable_storage_size,
- size_t *max_variable_size)
+ efi_status_t query_variable_info(uint32_t attributes, size_t * max_variable_storage_size,
+ size_t * remaining_variable_storage_size,
+ size_t * max_variable_size)
{
SMM_VARIABLE_COMMUNICATE_QUERY_VARIABLE_INFO query;
@@ -199,12 +181,10 @@
query.MaximumVariableSize = 0;
query.Attributes = attributes;
- efi_status_t status = uefi_variable_store_query_variable_info(
- &m_uefi_variable_store,
- &query);
+ efi_status_t status =
+ uefi_variable_store_query_variable_info(&m_uefi_variable_store, &query);
if (status == EFI_SUCCESS) {
-
*max_variable_storage_size = query.MaximumVariableStorageSize;
*remaining_variable_storage_size = query.RemainingVariableStorageSize;
*max_variable_size = query.MaximumVariableSize;
@@ -213,16 +193,16 @@
return status;
}
- efi_status_t set_check_var_property(
- const std::wstring &name,
- const VAR_CHECK_VARIABLE_PROPERTY &check_property)
+ efi_status_t set_check_var_property(const std::wstring &name,
+ const VAR_CHECK_VARIABLE_PROPERTY &check_property)
{
std::vector<int16_t> var_name = to_variable_name(name);
size_t name_size = var_name.size() * sizeof(int16_t);
- uint8_t msg_buffer[SMM_VARIABLE_COMMUNICATE_VAR_CHECK_VARIABLE_PROPERTY_SIZE(name_size)];
+ uint8_t msg_buffer[SMM_VARIABLE_COMMUNICATE_VAR_CHECK_VARIABLE_PROPERTY_SIZE(
+ name_size)];
SMM_VARIABLE_COMMUNICATE_VAR_CHECK_VARIABLE_PROPERTY *check_var =
- (SMM_VARIABLE_COMMUNICATE_VAR_CHECK_VARIABLE_PROPERTY*)msg_buffer;
+ (SMM_VARIABLE_COMMUNICATE_VAR_CHECK_VARIABLE_PROPERTY *)msg_buffer;
check_var->Guid = m_common_guid;
check_var->NameSize = name_size;
@@ -231,14 +211,12 @@
check_var->VariableProperty = check_property;
efi_status_t status = uefi_variable_store_set_var_check_property(
- &m_uefi_variable_store,
- check_var);
+ &m_uefi_variable_store, check_var);
return status;
}
- void zap_stored_variable(
- const std::wstring &name)
+ void zap_stored_variable(const std::wstring &name)
{
std::vector<int16_t> var_name = to_variable_name(name);
size_t name_size = var_name.size() * sizeof(int16_t);
@@ -249,20 +227,14 @@
struct variable_index *variable_index = &m_uefi_variable_store.variable_index;
const struct variable_info *info = variable_index_find(
- variable_index,
- &m_common_guid,
- name_size,
- var_name.data());
+ variable_index, &m_common_guid, name_size, var_name.data());
if (info && (info->metadata.attributes & EFI_VARIABLE_NON_VOLATILE)) {
-
struct storage_backend *storage_backend =
m_uefi_variable_store.persistent_store.storage_backend;
- storage_backend->interface->remove(
- storage_backend->context,
- OWNER_ID,
- info->metadata.uid);
+ storage_backend->interface->remove(storage_backend->context, OWNER_ID,
+ info->metadata.uid);
}
}
@@ -274,26 +246,18 @@
/* Lose volatile store contents */
mock_store_reset(&m_volatile_store);
- efi_status_t status = uefi_variable_store_init(
- &m_uefi_variable_store,
- OWNER_ID,
- MAX_VARIABLES,
- m_persistent_backend,
- m_volatile_backend);
+ efi_status_t status = uefi_variable_store_init(&m_uefi_variable_store, OWNER_ID,
+ MAX_VARIABLES, m_persistent_backend,
+ m_volatile_backend);
UNSIGNED_LONGLONGS_EQUAL(EFI_SUCCESS, status);
- uefi_variable_store_set_storage_limits(
- &m_uefi_variable_store,
- EFI_VARIABLE_NON_VOLATILE,
- STORE_CAPACITY,
- MAX_VARIABLE_SIZE);
+ uefi_variable_store_set_storage_limits(&m_uefi_variable_store,
+ EFI_VARIABLE_NON_VOLATILE, STORE_CAPACITY,
+ MAX_VARIABLE_SIZE);
- uefi_variable_store_set_storage_limits(
- &m_uefi_variable_store,
- 0,
- STORE_CAPACITY,
- MAX_VARIABLE_SIZE);
+ uefi_variable_store_set_storage_limits(&m_uefi_variable_store, 0, STORE_CAPACITY,
+ MAX_VARIABLE_SIZE);
}
static const size_t MAX_VARIABLES = 10;
@@ -348,16 +312,14 @@
size_t remaining_variable_storage_size = 0;
size_t max_variable_size = 0;
- status = query_variable_info(
- 0,
- &max_variable_storage_size,
- &remaining_variable_storage_size,
- &max_variable_size);
+ status = query_variable_info(0, &max_variable_storage_size,
+ &remaining_variable_storage_size, &max_variable_size);
UNSIGNED_LONGLONGS_EQUAL(EFI_SUCCESS, status);
UNSIGNED_LONGLONGS_EQUAL(STORE_CAPACITY, max_variable_storage_size);
UNSIGNED_LONGLONGS_EQUAL(MAX_VARIABLE_SIZE, max_variable_size);
- UNSIGNED_LONGLONGS_EQUAL(STORE_CAPACITY - expected_output.size(), remaining_variable_storage_size);
+ UNSIGNED_LONGLONGS_EQUAL(STORE_CAPACITY - expected_output.size(),
+ remaining_variable_storage_size);
}
TEST(UefiVariableStoreTests, persistentSetGet)
@@ -367,8 +329,7 @@
std::string input_data = "quick brown fox";
std::string output_data;
- status = set_variable(var_name, input_data,
- EFI_VARIABLE_NON_VOLATILE);
+ status = set_variable(var_name, input_data, EFI_VARIABLE_NON_VOLATILE);
UNSIGNED_LONGLONGS_EQUAL(EFI_SUCCESS, status);
status = get_variable(var_name, output_data);
@@ -382,7 +343,7 @@
std::string input_data2 = " jumps over the lazy dog";
status = set_variable(var_name, input_data2,
- EFI_VARIABLE_NON_VOLATILE | EFI_VARIABLE_APPEND_WRITE);
+ EFI_VARIABLE_NON_VOLATILE | EFI_VARIABLE_APPEND_WRITE);
UNSIGNED_LONGLONGS_EQUAL(EFI_SUCCESS, status);
status = get_variable(var_name, output_data);
@@ -410,16 +371,14 @@
size_t remaining_variable_storage_size = 0;
size_t max_variable_size = 0;
- status = query_variable_info(
- EFI_VARIABLE_NON_VOLATILE,
- &max_variable_storage_size,
- &remaining_variable_storage_size,
- &max_variable_size);
+ status = query_variable_info(EFI_VARIABLE_NON_VOLATILE, &max_variable_storage_size,
+ &remaining_variable_storage_size, &max_variable_size);
UNSIGNED_LONGLONGS_EQUAL(EFI_SUCCESS, status);
UNSIGNED_LONGLONGS_EQUAL(STORE_CAPACITY, max_variable_storage_size);
UNSIGNED_LONGLONGS_EQUAL(MAX_VARIABLE_SIZE, max_variable_size);
- UNSIGNED_LONGLONGS_EQUAL(STORE_CAPACITY - expected_output.size(), remaining_variable_storage_size);
+ UNSIGNED_LONGLONGS_EQUAL(STORE_CAPACITY - expected_output.size(),
+ remaining_variable_storage_size);
}
TEST(UefiVariableStoreTests, getWithSmallBuffer)
@@ -449,7 +408,7 @@
UNSIGNED_LONGLONGS_EQUAL(input_data.size(), output_data.size());
/* Try with a non-zero length but too small buffer */
- status = get_variable(var_name, output_data, input_data.size() -1);
+ status = get_variable(var_name, output_data, input_data.size() - 1);
UNSIGNED_LONGLONGS_EQUAL(EFI_BUFFER_TOO_SMALL, status);
UNSIGNED_LONGLONGS_EQUAL(input_data.size(), output_data.size());
}
@@ -506,14 +465,12 @@
TEST(UefiVariableStoreTests, bootServiceAccess)
{
efi_status_t status = EFI_SUCCESS;
- std::wstring var_name = L"test_variable";
+ std::wstring var_name = L"test_variable";
std::string input_data = "a variable with access restricted to boot";
std::string output_data;
- status = set_variable(
- var_name,
- input_data,
- EFI_VARIABLE_NON_VOLATILE | EFI_VARIABLE_BOOTSERVICE_ACCESS);
+ status = set_variable(var_name, input_data,
+ EFI_VARIABLE_NON_VOLATILE | EFI_VARIABLE_BOOTSERVICE_ACCESS);
UNSIGNED_LONGLONGS_EQUAL(EFI_SUCCESS, status);
/* 'Reboot' */
@@ -537,7 +494,7 @@
TEST(UefiVariableStoreTests, runtimeAccess)
{
efi_status_t status = EFI_SUCCESS;
- std::wstring var_name = L"test_variable";
+ std::wstring var_name = L"test_variable";
std::string input_data = "a variable with access restricted to runtime";
std::string output_data;
@@ -545,17 +502,13 @@
* Client is reponsible for setting bootservice access whenever runtime
* access is specified. This checks the defence against invalid attributes.
*/
- status = set_variable(
- var_name,
- input_data,
- EFI_VARIABLE_NON_VOLATILE | EFI_VARIABLE_RUNTIME_ACCESS);
+ status = set_variable(var_name, input_data,
+ EFI_VARIABLE_NON_VOLATILE | EFI_VARIABLE_RUNTIME_ACCESS);
UNSIGNED_LONGLONGS_EQUAL(EFI_INVALID_PARAMETER, status);
- status = set_variable(
- var_name,
- input_data,
- EFI_VARIABLE_NON_VOLATILE |
- EFI_VARIABLE_RUNTIME_ACCESS | EFI_VARIABLE_BOOTSERVICE_ACCESS);
+ status = set_variable(var_name, input_data,
+ EFI_VARIABLE_NON_VOLATILE | EFI_VARIABLE_RUNTIME_ACCESS |
+ EFI_VARIABLE_BOOTSERVICE_ACCESS);
UNSIGNED_LONGLONGS_EQUAL(EFI_SUCCESS, status);
/* 'Reboot' */
@@ -584,79 +537,55 @@
std::string input_data = "blah blah";
/* Add some variables - a mixture of NV and volatile */
- status = set_variable(
- var_name_1,
- input_data,
- EFI_VARIABLE_NON_VOLATILE);
+ status = set_variable(var_name_1, input_data, EFI_VARIABLE_NON_VOLATILE);
UNSIGNED_LONGLONGS_EQUAL(EFI_SUCCESS, status);
- status = set_variable(
- var_name_2,
- input_data,
- 0);
+ status = set_variable(var_name_2, input_data, 0);
UNSIGNED_LONGLONGS_EQUAL(EFI_SUCCESS, status);
- status = set_variable(
- var_name_3,
- input_data,
- EFI_VARIABLE_NON_VOLATILE);
+ status = set_variable(var_name_3, input_data, EFI_VARIABLE_NON_VOLATILE);
UNSIGNED_LONGLONGS_EQUAL(EFI_SUCCESS, status);
/* Prepare to enumerate */
size_t total_len = 0;
uint8_t msg_buffer[VARIABLE_BUFFER_SIZE];
SMM_VARIABLE_COMMUNICATE_GET_NEXT_VARIABLE_NAME *next_name =
- (SMM_VARIABLE_COMMUNICATE_GET_NEXT_VARIABLE_NAME*)msg_buffer;
- size_t max_name_len = VARIABLE_BUFFER_SIZE -
- SMM_VARIABLE_COMMUNICATE_ACCESS_VARIABLE_NAME_OFFSET;
+ (SMM_VARIABLE_COMMUNICATE_GET_NEXT_VARIABLE_NAME *)msg_buffer;
+ size_t max_name_len =
+ VARIABLE_BUFFER_SIZE - SMM_VARIABLE_COMMUNICATE_ACCESS_VARIABLE_NAME_OFFSET;
/* First check handling of invalid variable name */
- std::vector<int16_t> bogus_name = to_variable_name( L"bogus_variable");
+ std::vector<int16_t> bogus_name = to_variable_name(L"bogus_variable");
size_t bogus_name_size = bogus_name.size() * sizeof(uint16_t);
next_name->Guid = m_common_guid;
next_name->NameSize = bogus_name_size;
memcpy(next_name->Name, bogus_name.data(), bogus_name_size);
- status = uefi_variable_store_get_next_variable_name(
- &m_uefi_variable_store,
- next_name,
- max_name_len,
- &total_len);
+ status = uefi_variable_store_get_next_variable_name(&m_uefi_variable_store, next_name,
+ max_name_len, &total_len);
UNSIGNED_LONGLONGS_EQUAL(EFI_INVALID_PARAMETER, status);
/* Enumerate store contents */
next_name->NameSize = sizeof(int16_t);
next_name->Name[0] = 0;
- status = uefi_variable_store_get_next_variable_name(
- &m_uefi_variable_store,
- next_name,
- max_name_len,
- &total_len);
+ status = uefi_variable_store_get_next_variable_name(&m_uefi_variable_store, next_name,
+ max_name_len, &total_len);
UNSIGNED_LONGLONGS_EQUAL(EFI_SUCCESS, status);
CHECK_TRUE(compare_variable_name(var_name_1, next_name->Name, next_name->NameSize));
- status = uefi_variable_store_get_next_variable_name(
- &m_uefi_variable_store,
- next_name,
- max_name_len,
- &total_len);
+ status = uefi_variable_store_get_next_variable_name(&m_uefi_variable_store, next_name,
+ max_name_len, &total_len);
UNSIGNED_LONGLONGS_EQUAL(EFI_SUCCESS, status);
CHECK_TRUE(compare_variable_name(var_name_2, next_name->Name, next_name->NameSize));
- status = uefi_variable_store_get_next_variable_name(
- &m_uefi_variable_store,
- next_name,
- max_name_len,
- &total_len);
+ status = uefi_variable_store_get_next_variable_name(&m_uefi_variable_store, next_name,
+ max_name_len, &total_len);
UNSIGNED_LONGLONGS_EQUAL(EFI_SUCCESS, status);
CHECK_TRUE(compare_variable_name(var_name_3, next_name->Name, next_name->NameSize));
- status = uefi_variable_store_get_next_variable_name(
- &m_uefi_variable_store,
- next_name,
- max_name_len,
- &total_len);
+ status = uefi_variable_store_get_next_variable_name(&m_uefi_variable_store, next_name,
+ max_name_len, &total_len);
UNSIGNED_LONGLONGS_EQUAL(EFI_NOT_FOUND, status);
power_cycle();
@@ -667,27 +596,18 @@
next_name->NameSize = 10 * sizeof(int16_t);
memset(next_name->Name, 0, next_name->NameSize);
- status = uefi_variable_store_get_next_variable_name(
- &m_uefi_variable_store,
- next_name,
- max_name_len,
- &total_len);
+ status = uefi_variable_store_get_next_variable_name(&m_uefi_variable_store, next_name,
+ max_name_len, &total_len);
UNSIGNED_LONGLONGS_EQUAL(EFI_SUCCESS, status);
CHECK_TRUE(compare_variable_name(var_name_1, next_name->Name, next_name->NameSize));
- status = uefi_variable_store_get_next_variable_name(
- &m_uefi_variable_store,
- next_name,
- max_name_len,
- &total_len);
+ status = uefi_variable_store_get_next_variable_name(&m_uefi_variable_store, next_name,
+ max_name_len, &total_len);
UNSIGNED_LONGLONGS_EQUAL(EFI_SUCCESS, status);
CHECK_TRUE(compare_variable_name(var_name_3, next_name->Name, next_name->NameSize));
- status = uefi_variable_store_get_next_variable_name(
- &m_uefi_variable_store,
- next_name,
- max_name_len,
- &total_len);
+ status = uefi_variable_store_get_next_variable_name(&m_uefi_variable_store, next_name,
+ max_name_len, &total_len);
UNSIGNED_LONGLONGS_EQUAL(EFI_NOT_FOUND, status);
}
@@ -700,22 +620,13 @@
std::string input_data = "blah blah";
/* Add some variables - a mixture of NV and volatile */
- status = set_variable(
- var_name_1,
- input_data,
- EFI_VARIABLE_NON_VOLATILE);
+ status = set_variable(var_name_1, input_data, EFI_VARIABLE_NON_VOLATILE);
UNSIGNED_LONGLONGS_EQUAL(EFI_SUCCESS, status);
- status = set_variable(
- var_name_2,
- input_data,
- 0);
+ status = set_variable(var_name_2, input_data, 0);
UNSIGNED_LONGLONGS_EQUAL(EFI_SUCCESS, status);
- status = set_variable(
- var_name_3,
- input_data,
- EFI_VARIABLE_NON_VOLATILE);
+ status = set_variable(var_name_3, input_data, EFI_VARIABLE_NON_VOLATILE);
UNSIGNED_LONGLONGS_EQUAL(EFI_SUCCESS, status);
/* Simulate a power failure which resulted in the
@@ -731,28 +642,22 @@
*/
uint8_t msg_buffer[VARIABLE_BUFFER_SIZE];
SMM_VARIABLE_COMMUNICATE_GET_NEXT_VARIABLE_NAME *next_name =
- (SMM_VARIABLE_COMMUNICATE_GET_NEXT_VARIABLE_NAME*)msg_buffer;
- size_t max_name_len = VARIABLE_BUFFER_SIZE -
- SMM_VARIABLE_COMMUNICATE_ACCESS_VARIABLE_NAME_OFFSET;
+ (SMM_VARIABLE_COMMUNICATE_GET_NEXT_VARIABLE_NAME *)msg_buffer;
+ size_t max_name_len =
+ VARIABLE_BUFFER_SIZE - SMM_VARIABLE_COMMUNICATE_ACCESS_VARIABLE_NAME_OFFSET;
/* Enumerate store contents */
size_t total_len = 0;
next_name->NameSize = sizeof(int16_t);
next_name->Name[0] = 0;
- status = uefi_variable_store_get_next_variable_name(
- &m_uefi_variable_store,
- next_name,
- max_name_len,
- &total_len);
+ status = uefi_variable_store_get_next_variable_name(&m_uefi_variable_store, next_name,
+ max_name_len, &total_len);
UNSIGNED_LONGLONGS_EQUAL(EFI_SUCCESS, status);
CHECK_TRUE(compare_variable_name(var_name_1, next_name->Name, next_name->NameSize));
- status = uefi_variable_store_get_next_variable_name(
- &m_uefi_variable_store,
- next_name,
- max_name_len,
- &total_len);
+ status = uefi_variable_store_get_next_variable_name(&m_uefi_variable_store, next_name,
+ max_name_len, &total_len);
UNSIGNED_LONGLONGS_EQUAL(EFI_NOT_FOUND, status);
}
@@ -763,10 +668,8 @@
std::string input_data = "blah blah";
/* Add a variable with an unsupported attribute */
- status = set_variable(
- var_name_1,
- input_data,
- EFI_VARIABLE_NON_VOLATILE | EFI_VARIABLE_AUTHENTICATED_WRITE_ACCESS);
+ status = set_variable(var_name_1, input_data,
+ EFI_VARIABLE_NON_VOLATILE | EFI_VARIABLE_AUTHENTICATED_WRITE_ACCESS);
UNSIGNED_LONGLONGS_EQUAL(EFI_UNSUPPORTED, status);
}
@@ -777,10 +680,7 @@
std::string input_data = "blah blah";
/* Add a variable */
- status = set_variable(
- var_name_1,
- input_data,
- EFI_VARIABLE_NON_VOLATILE);
+ status = set_variable(var_name_1, input_data, EFI_VARIABLE_NON_VOLATILE);
UNSIGNED_LONGLONGS_EQUAL(EFI_SUCCESS, status);
/* Apply a check to constrain to Read Only */
@@ -795,10 +695,7 @@
UNSIGNED_LONGLONGS_EQUAL(EFI_SUCCESS, status);
/* Subsequent set operations should fail */
- status = set_variable(
- var_name_1,
- input_data,
- EFI_VARIABLE_NON_VOLATILE);
+ status = set_variable(var_name_1, input_data, EFI_VARIABLE_NON_VOLATILE);
UNSIGNED_LONGLONGS_EQUAL(EFI_WRITE_PROTECTED, status);
}
@@ -809,10 +706,7 @@
std::string input_data = "blah blah";
/* Add a variable */
- status = set_variable(
- var_name_1,
- input_data,
- EFI_VARIABLE_NON_VOLATILE);
+ status = set_variable(var_name_1, input_data, EFI_VARIABLE_NON_VOLATILE);
UNSIGNED_LONGLONGS_EQUAL(EFI_SUCCESS, status);
/* Apply a check to constrain size to > 0. This should prevent removal */
@@ -827,23 +721,15 @@
UNSIGNED_LONGLONGS_EQUAL(EFI_SUCCESS, status);
/* Try and remove by setting with zero length data */
- status = set_variable(
- var_name_1,
- std::string(),
- EFI_VARIABLE_NON_VOLATILE);
+ status = set_variable(var_name_1, std::string(), EFI_VARIABLE_NON_VOLATILE);
UNSIGNED_LONGLONGS_EQUAL(EFI_INVALID_PARAMETER, status);
/* Setting with non zero data should work */
- status = set_variable(
- var_name_1,
- std::string("Good"),
- EFI_VARIABLE_NON_VOLATILE);
+ status = set_variable(var_name_1, std::string("Good"), EFI_VARIABLE_NON_VOLATILE);
UNSIGNED_LONGLONGS_EQUAL(EFI_SUCCESS, status);
/* But with data that exceeds the MaxSize */
- status = set_variable(
- var_name_1,
- std::string("A data value that exceeds the MaxSize"),
- EFI_VARIABLE_NON_VOLATILE);
+ status = set_variable(var_name_1, std::string("A data value that exceeds the MaxSize"),
+ EFI_VARIABLE_NON_VOLATILE);
UNSIGNED_LONGLONGS_EQUAL(EFI_INVALID_PARAMETER, status);
}
diff --git a/components/service/uefi/smm_variable/backend/uefi_variable_store.c b/components/service/uefi/smm_variable/backend/uefi_variable_store.c
index 16294e8..f542377 100644
--- a/components/service/uefi/smm_variable/backend/uefi_variable_store.c
+++ b/components/service/uefi/smm_variable/backend/uefi_variable_store.c
@@ -5,96 +5,76 @@
*
*/
+#include "uefi_variable_store.h"
+
#include <stdbool.h>
#include <stdlib.h>
#include <string.h>
-#include "uefi_variable_store.h"
-#include "variable_index_iterator.h"
+
#include "variable_checker.h"
+#include "variable_index_iterator.h"
/* Private functions */
-static void load_variable_index(
- struct uefi_variable_store *context);
+static void load_variable_index(struct uefi_variable_store *context);
-static efi_status_t sync_variable_index(
- struct uefi_variable_store *context);
+static efi_status_t sync_variable_index(struct uefi_variable_store *context);
-static efi_status_t check_capabilities(
- const SMM_VARIABLE_COMMUNICATE_ACCESS_VARIABLE *var);
+static efi_status_t check_capabilities(const SMM_VARIABLE_COMMUNICATE_ACCESS_VARIABLE *var);
-static efi_status_t check_access_permitted(
- const struct uefi_variable_store *context,
- const struct variable_info *info);
+static efi_status_t check_access_permitted(const struct uefi_variable_store *context,
+ const struct variable_info *info);
-static efi_status_t check_access_permitted_on_set(
- const struct uefi_variable_store *context,
- const struct variable_info *info,
- const SMM_VARIABLE_COMMUNICATE_ACCESS_VARIABLE *var);
+static efi_status_t
+check_access_permitted_on_set(const struct uefi_variable_store *context,
+ const struct variable_info *info,
+ const SMM_VARIABLE_COMMUNICATE_ACCESS_VARIABLE *var);
-static efi_status_t store_variable_data(
- struct uefi_variable_store *context,
- const struct variable_info *info,
- const SMM_VARIABLE_COMMUNICATE_ACCESS_VARIABLE *var);
+static efi_status_t store_variable_data(struct uefi_variable_store *context,
+ const struct variable_info *info,
+ const SMM_VARIABLE_COMMUNICATE_ACCESS_VARIABLE *var);
-static efi_status_t remove_variable_data(
- struct uefi_variable_store *context,
- const struct variable_info *info);
+static efi_status_t remove_variable_data(struct uefi_variable_store *context,
+ const struct variable_info *info);
-static efi_status_t load_variable_data(
- struct uefi_variable_store *context,
- const struct variable_info *info,
- SMM_VARIABLE_COMMUNICATE_ACCESS_VARIABLE *var,
- size_t max_data_len);
+static efi_status_t load_variable_data(struct uefi_variable_store *context,
+ const struct variable_info *info,
+ SMM_VARIABLE_COMMUNICATE_ACCESS_VARIABLE *var,
+ size_t max_data_len);
-static psa_status_t store_overwrite(
- struct delegate_variable_store *delegate_store,
- uint32_t client_id,
- uint64_t uid,
- size_t data_length,
- const void *data);
+static psa_status_t store_overwrite(struct delegate_variable_store *delegate_store,
+ uint32_t client_id, uint64_t uid, size_t data_length,
+ const void *data);
-static psa_status_t store_append_write(
- struct delegate_variable_store *delegate_store,
- uint32_t client_id,
- uint64_t uid,
- size_t data_length,
- const void *data);
+static psa_status_t store_append_write(struct delegate_variable_store *delegate_store,
+ uint32_t client_id, uint64_t uid, size_t data_length,
+ const void *data);
-static void purge_orphan_index_entries(
- struct uefi_variable_store *context);
+static void purge_orphan_index_entries(struct uefi_variable_store *context);
-static struct delegate_variable_store *select_delegate_store(
- struct uefi_variable_store *context,
- uint32_t attributes);
+static struct delegate_variable_store *select_delegate_store(struct uefi_variable_store *context,
+ uint32_t attributes);
-static size_t space_used(
- struct uefi_variable_store *context,
- uint32_t attributes,
- struct storage_backend *storage_backend);
+static size_t space_used(struct uefi_variable_store *context, uint32_t attributes,
+ struct storage_backend *storage_backend);
-static efi_status_t psa_to_efi_storage_status(
- psa_status_t psa_status);
+static efi_status_t psa_to_efi_storage_status(psa_status_t psa_status);
-static efi_status_t check_name_terminator(
- const int16_t *name,
- size_t name_size);
+static efi_status_t check_name_terminator(const int16_t *name, size_t name_size);
/* Private UID for storing the variable index - may be overridden at build-time */
#ifndef SMM_VARIABLE_INDEX_STORAGE_UID
-#define SMM_VARIABLE_INDEX_STORAGE_UID (1)
+#define SMM_VARIABLE_INDEX_STORAGE_UID (1)
#endif
/* Default maximum variable size -
* may be overridden using uefi_variable_store_set_storage_limits()
*/
-#define DEFAULT_MAX_VARIABLE_SIZE (2048)
+#define DEFAULT_MAX_VARIABLE_SIZE (2048)
-efi_status_t uefi_variable_store_init(
- struct uefi_variable_store *context,
- uint32_t owner_id,
- size_t max_variables,
- struct storage_backend *persistent_store,
- struct storage_backend *volatile_store)
+efi_status_t uefi_variable_store_init(struct uefi_variable_store *context, uint32_t owner_id,
+ size_t max_variables,
+ struct storage_backend *persistent_store,
+ struct storage_backend *volatile_store)
{
efi_status_t status = EFI_SUCCESS;
@@ -116,20 +96,18 @@
status = variable_index_init(&context->variable_index, max_variables);
if (status == EFI_SUCCESS) {
-
/* Allocate a buffer for synchronizing the variable index with the persistent store */
- context->index_sync_buffer_size = variable_index_max_dump_size(&context->variable_index);
+ context->index_sync_buffer_size =
+ variable_index_max_dump_size(&context->variable_index);
context->index_sync_buffer = NULL;
if (context->index_sync_buffer_size) {
-
context->index_sync_buffer = malloc(context->index_sync_buffer_size);
status = (context->index_sync_buffer) ? EFI_SUCCESS : EFI_OUT_OF_RESOURCES;
}
/* Load the variable index with NV variable info from the persistent store */
if (context->index_sync_buffer) {
-
load_variable_index(context);
purge_orphan_index_entries(context);
}
@@ -138,8 +116,7 @@
return status;
}
-void uefi_variable_store_deinit(
- struct uefi_variable_store *context)
+void uefi_variable_store_deinit(struct uefi_variable_store *context)
{
variable_index_deinit(&context->variable_index);
@@ -147,69 +124,58 @@
context->index_sync_buffer = NULL;
}
-void uefi_variable_store_set_storage_limits(
- struct uefi_variable_store *context,
- uint32_t attributes,
- size_t total_capacity,
- size_t max_variable_size)
+void uefi_variable_store_set_storage_limits(struct uefi_variable_store *context,
+ uint32_t attributes, size_t total_capacity,
+ size_t max_variable_size)
{
- struct delegate_variable_store *delegate_store = select_delegate_store(
- context,
- attributes);
+ struct delegate_variable_store *delegate_store = select_delegate_store(context, attributes);
delegate_store->total_capacity = total_capacity;
delegate_store->max_variable_size = max_variable_size;
}
-efi_status_t uefi_variable_store_set_variable(
- struct uefi_variable_store *context,
- const SMM_VARIABLE_COMMUNICATE_ACCESS_VARIABLE *var)
+efi_status_t uefi_variable_store_set_variable(struct uefi_variable_store *context,
+ const SMM_VARIABLE_COMMUNICATE_ACCESS_VARIABLE *var)
{
bool should_sync_index = false;
/* Validate incoming request */
efi_status_t status = check_name_terminator(var->Name, var->NameSize);
- if (status != EFI_SUCCESS) return status;
+ if (status != EFI_SUCCESS)
+ return status;
status = check_capabilities(var);
- if (status != EFI_SUCCESS) return status;
+ if (status != EFI_SUCCESS)
+ return status;
/* Find an existing entry in the variable index or add a new one */
- struct variable_info *info = variable_index_find(
- &context->variable_index,
- &var->Guid,
- var->NameSize,
- var->Name);
+ struct variable_info *info =
+ variable_index_find(&context->variable_index, &var->Guid, var->NameSize, var->Name);
if (!info) {
+ info = variable_index_add_entry(&context->variable_index, &var->Guid, var->NameSize,
+ var->Name);
- info = variable_index_add_entry(
- &context->variable_index,
- &var->Guid,
- var->NameSize,
- var->Name);
-
- if (!info) return EFI_OUT_OF_RESOURCES;
+ if (!info)
+ return EFI_OUT_OF_RESOURCES;
}
/* Control access */
status = check_access_permitted_on_set(context, info, var);
if (status == EFI_SUCCESS) {
-
/* Access permitted */
if (info->is_variable_set) {
-
/*
* It's a request to update to an existing variable,
* note that a variable without attributes means a
* delete variable request, similar to how EDK-2
* and EDK-2 test cases handle this.
*/
- if (!(var->Attributes) || (!(var->Attributes &
- (EFI_VARIABLE_APPEND_WRITE | EFI_VARIABLE_AUTHENTICATED_WRITE_ACCESS_MASK)) &&
- !var->DataSize)) {
-
+ if (!(var->Attributes) ||
+ (!(var->Attributes & (EFI_VARIABLE_APPEND_WRITE |
+ EFI_VARIABLE_AUTHENTICATED_WRITE_ACCESS_MASK)) &&
+ !var->DataSize)) {
/* It's a remove operation - for a remove, the variable
* data must be removed from the storage backend before
* modifying and syncing the variable index. This ensures
@@ -220,29 +186,22 @@
variable_index_clear_variable(&context->variable_index, info);
should_sync_index = (var->Attributes & EFI_VARIABLE_NON_VOLATILE);
- }
- else {
-
+ } else {
/* It's a set operation where variable data is potentially
* being overwritten or extended.
*/
- if ((var->Attributes & ~EFI_VARIABLE_APPEND_WRITE) != info->metadata.attributes) {
-
+ if ((var->Attributes & ~EFI_VARIABLE_APPEND_WRITE) !=
+ info->metadata.attributes) {
/* Modifying attributes is forbidden */
return EFI_INVALID_PARAMETER;
}
}
- }
- else {
-
+ } else {
if (var->DataSize) {
-
/* It's a request to create a new variable */
variable_index_set_variable(info, var->Attributes);
should_sync_index = (var->Attributes & EFI_VARIABLE_NON_VOLATILE);
- }
- else {
-
+ } else {
/* Attempting to remove a non-existent variable */
return EFI_NOT_FOUND;
}
@@ -258,13 +217,11 @@
* index entry.
*/
if (should_sync_index) {
-
status = sync_variable_index(context);
}
/* Store any variable data to the storage backend */
if (info->is_variable_set && (status == EFI_SUCCESS)) {
-
status = store_variable_data(context, info, var);
}
@@ -273,74 +230,63 @@
return status;
}
-efi_status_t uefi_variable_store_get_variable(
- struct uefi_variable_store *context,
- SMM_VARIABLE_COMMUNICATE_ACCESS_VARIABLE *var,
- size_t max_data_len,
- size_t *total_length)
+efi_status_t uefi_variable_store_get_variable(struct uefi_variable_store *context,
+ SMM_VARIABLE_COMMUNICATE_ACCESS_VARIABLE *var,
+ size_t max_data_len, size_t *total_length)
{
efi_status_t status = check_name_terminator(var->Name, var->NameSize);
- if (status != EFI_SUCCESS) return status;
+ if (status != EFI_SUCCESS)
+ return status;
status = EFI_NOT_FOUND;
*total_length = 0;
- const struct variable_info *info = variable_index_find(
- &context->variable_index,
- &var->Guid,
- var->NameSize,
- var->Name);
+ const struct variable_info *info =
+ variable_index_find(&context->variable_index, &var->Guid, var->NameSize, var->Name);
if (info && info->is_variable_set) {
-
/* Variable already exists */
status = check_access_permitted(context, info);
if (status == EFI_SUCCESS) {
-
status = load_variable_data(context, info, var, max_data_len);
var->Attributes = info->metadata.attributes;
if (status == EFI_SUCCESS)
- *total_length = SMM_VARIABLE_COMMUNICATE_ACCESS_VARIABLE_TOTAL_SIZE(var);
+ *total_length =
+ SMM_VARIABLE_COMMUNICATE_ACCESS_VARIABLE_TOTAL_SIZE(var);
else if (status == EFI_BUFFER_TOO_SMALL)
- *total_length = SMM_VARIABLE_COMMUNICATE_ACCESS_VARIABLE_DATA_OFFSET(var);
+ *total_length =
+ SMM_VARIABLE_COMMUNICATE_ACCESS_VARIABLE_DATA_OFFSET(var);
}
}
return status;
}
-efi_status_t uefi_variable_store_get_next_variable_name(
- struct uefi_variable_store *context,
- SMM_VARIABLE_COMMUNICATE_GET_NEXT_VARIABLE_NAME *cur,
- size_t max_name_len,
- size_t *total_length)
+efi_status_t
+uefi_variable_store_get_next_variable_name(struct uefi_variable_store *context,
+ SMM_VARIABLE_COMMUNICATE_GET_NEXT_VARIABLE_NAME *cur,
+ size_t max_name_len, size_t *total_length)
{
efi_status_t status = check_name_terminator(cur->Name, cur->NameSize);
- if (status != EFI_SUCCESS) return status;
+ if (status != EFI_SUCCESS)
+ return status;
*total_length = 0;
const struct variable_info *info = variable_index_find_next(
- &context->variable_index,
- &cur->Guid,
- cur->NameSize,
- cur->Name,
- &status);
+ &context->variable_index, &cur->Guid, cur->NameSize, cur->Name, &status);
if (info && (status == EFI_SUCCESS)) {
-
if (info->metadata.name_size <= max_name_len) {
-
cur->Guid = info->metadata.guid;
cur->NameSize = info->metadata.name_size;
memcpy(cur->Name, info->metadata.name, info->metadata.name_size);
- *total_length = SMM_VARIABLE_COMMUNICATE_GET_NEXT_VARIABLE_NAME_TOTAL_SIZE(cur);
- }
- else {
-
+ *total_length =
+ SMM_VARIABLE_COMMUNICATE_GET_NEXT_VARIABLE_NAME_TOTAL_SIZE(cur);
+ } else {
status = EFI_BUFFER_TOO_SMALL;
}
}
@@ -348,30 +294,27 @@
return status;
}
-efi_status_t uefi_variable_store_query_variable_info(
- struct uefi_variable_store *context,
- SMM_VARIABLE_COMMUNICATE_QUERY_VARIABLE_INFO *var_info)
+efi_status_t
+uefi_variable_store_query_variable_info(struct uefi_variable_store *context,
+ SMM_VARIABLE_COMMUNICATE_QUERY_VARIABLE_INFO *var_info)
{
- struct delegate_variable_store *delegate_store = select_delegate_store(
- context,
- var_info->Attributes);
+ struct delegate_variable_store *delegate_store =
+ select_delegate_store(context, var_info->Attributes);
- size_t total_used = space_used(
- context,
- var_info->Attributes,
- delegate_store->storage_backend);
+ size_t total_used =
+ space_used(context, var_info->Attributes, delegate_store->storage_backend);
var_info->MaximumVariableSize = delegate_store->max_variable_size;
var_info->MaximumVariableStorageSize = delegate_store->total_capacity;
- var_info->RemainingVariableStorageSize = (total_used < delegate_store->total_capacity) ?
- delegate_store->total_capacity - total_used :
- 0;
+ var_info->RemainingVariableStorageSize =
+ (total_used < delegate_store->total_capacity) ?
+ delegate_store->total_capacity - total_used :
+ 0;
return EFI_SUCCESS;
}
-efi_status_t uefi_variable_store_exit_boot_service(
- struct uefi_variable_store *context)
+efi_status_t uefi_variable_store_exit_boot_service(struct uefi_variable_store *context)
{
context->is_boot_service = false;
return EFI_SUCCESS;
@@ -382,24 +325,19 @@
const SMM_VARIABLE_COMMUNICATE_VAR_CHECK_VARIABLE_PROPERTY *property)
{
efi_status_t status = check_name_terminator(property->Name, property->NameSize);
- if (status != EFI_SUCCESS) return status;
+ if (status != EFI_SUCCESS)
+ return status;
/* Find in index or create a new entry */
- struct variable_info *info = variable_index_find(
- &context->variable_index,
- &property->Guid,
- property->NameSize,
- property->Name);
+ struct variable_info *info = variable_index_find(&context->variable_index, &property->Guid,
+ property->NameSize, property->Name);
if (!info) {
+ info = variable_index_add_entry(&context->variable_index, &property->Guid,
+ property->NameSize, property->Name);
- info = variable_index_add_entry(
- &context->variable_index,
- &property->Guid,
- property->NameSize,
- property->Name);
-
- if (!info) return EFI_OUT_OF_RESOURCES;
+ if (!info)
+ return EFI_OUT_OF_RESOURCES;
}
/* Applying check constraints to an existing variable that may have
@@ -408,13 +346,10 @@
*/
struct variable_constraints constraints = info->check_constraints;
- status = variable_checker_set_constraints(
- &constraints,
- info->is_constraints_set,
- &property->VariableProperty);
+ status = variable_checker_set_constraints(&constraints, info->is_constraints_set,
+ &property->VariableProperty);
if (status == EFI_SUCCESS) {
-
variable_index_set_constraints(info, &constraints);
}
@@ -428,21 +363,17 @@
SMM_VARIABLE_COMMUNICATE_VAR_CHECK_VARIABLE_PROPERTY *property)
{
efi_status_t status = check_name_terminator(property->Name, property->NameSize);
- if (status != EFI_SUCCESS) return status;
+ if (status != EFI_SUCCESS)
+ return status;
status = EFI_NOT_FOUND;
const struct variable_info *info = variable_index_find(
- &context->variable_index,
- &property->Guid,
- property->NameSize,
- property->Name);
+ &context->variable_index, &property->Guid, property->NameSize, property->Name);
if (info && info->is_constraints_set) {
-
- variable_checker_get_constraints(
- &info->check_constraints,
- &property->VariableProperty);
+ variable_checker_get_constraints(&info->check_constraints,
+ &property->VariableProperty);
status = EFI_SUCCESS;
}
@@ -450,58 +381,45 @@
return status;
}
-static void load_variable_index(
- struct uefi_variable_store *context)
+static void load_variable_index(struct uefi_variable_store *context)
{
struct storage_backend *persistent_store = context->persistent_store.storage_backend;
if (persistent_store) {
-
size_t data_len = 0;
psa_status_t psa_status = persistent_store->interface->get(
- persistent_store->context,
- context->owner_id,
- SMM_VARIABLE_INDEX_STORAGE_UID,
- 0,
- context->index_sync_buffer_size,
- context->index_sync_buffer,
- &data_len);
+ persistent_store->context, context->owner_id,
+ SMM_VARIABLE_INDEX_STORAGE_UID, 0, context->index_sync_buffer_size,
+ context->index_sync_buffer, &data_len);
if (psa_status == PSA_SUCCESS) {
-
- variable_index_restore(&context->variable_index, data_len, context->index_sync_buffer);
+ variable_index_restore(&context->variable_index, data_len,
+ context->index_sync_buffer);
}
}
}
-static efi_status_t sync_variable_index(
- struct uefi_variable_store *context)
+static efi_status_t sync_variable_index(struct uefi_variable_store *context)
{
efi_status_t status = EFI_SUCCESS;
/* Sync the varibale index to storage if anything is dirty */
size_t data_len = 0;
- bool is_dirty = variable_index_dump(
- &context->variable_index,
- context->index_sync_buffer_size,
- context->index_sync_buffer,
- &data_len);
+ bool is_dirty = variable_index_dump(&context->variable_index,
+ context->index_sync_buffer_size,
+ context->index_sync_buffer, &data_len);
if (is_dirty) {
-
- struct storage_backend *persistent_store = context->persistent_store.storage_backend;
+ struct storage_backend *persistent_store =
+ context->persistent_store.storage_backend;
if (persistent_store) {
-
psa_status_t psa_status = persistent_store->interface->set(
- persistent_store->context,
- context->owner_id,
- SMM_VARIABLE_INDEX_STORAGE_UID,
- data_len,
- context->index_sync_buffer,
- PSA_STORAGE_FLAG_NONE);
+ persistent_store->context, context->owner_id,
+ SMM_VARIABLE_INDEX_STORAGE_UID, data_len,
+ context->index_sync_buffer, PSA_STORAGE_FLAG_NONE);
status = psa_to_efi_storage_status(psa_status);
}
@@ -510,13 +428,11 @@
return status;
}
-static efi_status_t check_capabilities(
- const SMM_VARIABLE_COMMUNICATE_ACCESS_VARIABLE *var)
+static efi_status_t check_capabilities(const SMM_VARIABLE_COMMUNICATE_ACCESS_VARIABLE *var)
{
/* Check if invalid variable attributes have been requested */
if ((var->Attributes & EFI_VARIABLE_RUNTIME_ACCESS) &&
- !(var->Attributes & EFI_VARIABLE_BOOTSERVICE_ACCESS)) {
-
+ !(var->Attributes & EFI_VARIABLE_BOOTSERVICE_ACCESS)) {
/*
* Client is required to explicitly allow bootservice access for runtime
* access variables.
@@ -525,12 +441,8 @@
}
/* Check if any unsupported variable attributes have been requested */
- if (var->Attributes & ~(
- EFI_VARIABLE_NON_VOLATILE |
- EFI_VARIABLE_BOOTSERVICE_ACCESS |
- EFI_VARIABLE_RUNTIME_ACCESS |
- EFI_VARIABLE_APPEND_WRITE)) {
-
+ if (var->Attributes & ~(EFI_VARIABLE_NON_VOLATILE | EFI_VARIABLE_BOOTSERVICE_ACCESS |
+ EFI_VARIABLE_RUNTIME_ACCESS | EFI_VARIABLE_APPEND_WRITE)) {
/* An unsupported attribute has been requested */
return EFI_UNSUPPORTED;
}
@@ -538,26 +450,20 @@
return EFI_SUCCESS;
}
-static efi_status_t check_access_permitted(
- const struct uefi_variable_store *context,
- const struct variable_info *info)
+static efi_status_t check_access_permitted(const struct uefi_variable_store *context,
+ const struct variable_info *info)
{
efi_status_t status = EFI_SUCCESS;
- if (info->is_variable_set &&
- (info->metadata.attributes &
- (EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS))) {
-
+ if (info->is_variable_set && (info->metadata.attributes & (EFI_VARIABLE_BOOTSERVICE_ACCESS |
+ EFI_VARIABLE_RUNTIME_ACCESS))) {
/* Access is controlled */
status = EFI_ACCESS_DENIED;
if (context->is_boot_service) {
-
if (info->metadata.attributes & EFI_VARIABLE_BOOTSERVICE_ACCESS)
status = EFI_SUCCESS;
- }
- else {
-
+ } else {
if (info->metadata.attributes & EFI_VARIABLE_RUNTIME_ACCESS)
status = EFI_SUCCESS;
}
@@ -566,65 +472,47 @@
return status;
}
-static efi_status_t check_access_permitted_on_set(
- const struct uefi_variable_store *context,
- const struct variable_info *info,
- const SMM_VARIABLE_COMMUNICATE_ACCESS_VARIABLE *var)
+static efi_status_t
+check_access_permitted_on_set(const struct uefi_variable_store *context,
+ const struct variable_info *info,
+ const SMM_VARIABLE_COMMUNICATE_ACCESS_VARIABLE *var)
{
efi_status_t status = check_access_permitted(context, info);
if ((status == EFI_SUCCESS) && info->is_constraints_set) {
-
/* Apply check constraints */
- status = variable_checker_check_on_set(
- &info->check_constraints,
- var->Attributes,
- var->DataSize);
+ status = variable_checker_check_on_set(&info->check_constraints, var->Attributes,
+ var->DataSize);
}
return status;
}
-static efi_status_t store_variable_data(
- struct uefi_variable_store *context,
- const struct variable_info *info,
- const SMM_VARIABLE_COMMUNICATE_ACCESS_VARIABLE *var)
+static efi_status_t store_variable_data(struct uefi_variable_store *context,
+ const struct variable_info *info,
+ const SMM_VARIABLE_COMMUNICATE_ACCESS_VARIABLE *var)
{
psa_status_t psa_status = PSA_SUCCESS;
size_t data_len = var->DataSize;
- const uint8_t *data = (const uint8_t*)var +
- SMM_VARIABLE_COMMUNICATE_ACCESS_VARIABLE_DATA_OFFSET(var);
+ const uint8_t *data =
+ (const uint8_t *)var + SMM_VARIABLE_COMMUNICATE_ACCESS_VARIABLE_DATA_OFFSET(var);
- struct delegate_variable_store *delegate_store = select_delegate_store(
- context,
- info->metadata.attributes);
+ struct delegate_variable_store *delegate_store =
+ select_delegate_store(context, info->metadata.attributes);
if (delegate_store->storage_backend) {
-
if (!(var->Attributes & EFI_VARIABLE_APPEND_WRITE)) {
-
/* Create or overwrite variable data */
- psa_status = store_overwrite(
- delegate_store,
- context->owner_id,
- info->metadata.uid,
- data_len,
- data);
- }
- else {
-
+ psa_status = store_overwrite(delegate_store, context->owner_id,
+ info->metadata.uid, data_len, data);
+ } else {
/* Append new data to existing variable data */
- psa_status = store_append_write(
- delegate_store,
- context->owner_id,
- info->metadata.uid,
- data_len,
- data);
+ psa_status = store_append_write(delegate_store, context->owner_id,
+ info->metadata.uid, data_len, data);
}
}
if ((psa_status != PSA_SUCCESS) && delegate_store->is_nv) {
-
/* A storage failure has occurred so attempt to fix any
* mismatch between the variable index and stored NV variables.
*/
@@ -634,23 +522,18 @@
return psa_to_efi_storage_status(psa_status);
}
-static efi_status_t remove_variable_data(
- struct uefi_variable_store *context,
- const struct variable_info *info)
+static efi_status_t remove_variable_data(struct uefi_variable_store *context,
+ const struct variable_info *info)
{
psa_status_t psa_status = PSA_SUCCESS;
if (info->is_variable_set) {
-
- struct delegate_variable_store *delegate_store = select_delegate_store(
- context,
- info->metadata.attributes);
+ struct delegate_variable_store *delegate_store =
+ select_delegate_store(context, info->metadata.attributes);
if (delegate_store->storage_backend) {
-
psa_status = delegate_store->storage_backend->interface->remove(
- delegate_store->storage_backend->context,
- context->owner_id,
+ delegate_store->storage_backend->context, context->owner_id,
info->metadata.uid);
}
}
@@ -658,53 +541,37 @@
return psa_to_efi_storage_status(psa_status);
}
-static efi_status_t load_variable_data(
- struct uefi_variable_store *context,
- const struct variable_info *info,
- SMM_VARIABLE_COMMUNICATE_ACCESS_VARIABLE *var,
- size_t max_data_len)
+static efi_status_t load_variable_data(struct uefi_variable_store *context,
+ const struct variable_info *info,
+ SMM_VARIABLE_COMMUNICATE_ACCESS_VARIABLE *var,
+ size_t max_data_len)
{
psa_status_t psa_status = PSA_SUCCESS;
- uint8_t *data = (uint8_t*)var +
- SMM_VARIABLE_COMMUNICATE_ACCESS_VARIABLE_DATA_OFFSET(var);
+ uint8_t *data = (uint8_t *)var + SMM_VARIABLE_COMMUNICATE_ACCESS_VARIABLE_DATA_OFFSET(var);
- struct delegate_variable_store *delegate_store = select_delegate_store(
- context,
- info->metadata.attributes);
+ struct delegate_variable_store *delegate_store =
+ select_delegate_store(context, info->metadata.attributes);
if (delegate_store->storage_backend) {
-
struct psa_storage_info_t storage_info;
psa_status = delegate_store->storage_backend->interface->get_info(
- delegate_store->storage_backend->context,
- context->owner_id,
- info->metadata.uid,
- &storage_info);
+ delegate_store->storage_backend->context, context->owner_id,
+ info->metadata.uid, &storage_info);
if (psa_status == PSA_SUCCESS) {
-
- size_t get_limit = (var->DataSize < max_data_len) ?
- var->DataSize :
- max_data_len;
+ size_t get_limit = (var->DataSize < max_data_len) ? var->DataSize :
+ max_data_len;
if (get_limit >= storage_info.size) {
-
size_t got_len = 0;
psa_status = delegate_store->storage_backend->interface->get(
- delegate_store->storage_backend->context,
- context->owner_id,
- info->metadata.uid,
- 0,
- storage_info.size,
- data,
- &got_len);
+ delegate_store->storage_backend->context, context->owner_id,
+ info->metadata.uid, 0, storage_info.size, data, &got_len);
var->DataSize = got_len;
- }
- else {
-
+ } else {
var->DataSize = storage_info.size;
psa_status = PSA_ERROR_BUFFER_TOO_SMALL;
}
@@ -714,88 +581,68 @@
return psa_to_efi_storage_status(psa_status);
}
-static psa_status_t store_overwrite(
- struct delegate_variable_store *delegate_store,
- uint32_t client_id,
- uint64_t uid,
- size_t data_length,
- const void *data)
+static psa_status_t store_overwrite(struct delegate_variable_store *delegate_store,
+ uint32_t client_id, uint64_t uid, size_t data_length,
+ const void *data)
{
/* Police maximum variable size limit */
- if (data_length > delegate_store->max_variable_size) return PSA_ERROR_INVALID_ARGUMENT;
+ if (data_length > delegate_store->max_variable_size)
+ return PSA_ERROR_INVALID_ARGUMENT;
psa_status_t psa_status = delegate_store->storage_backend->interface->set(
- delegate_store->storage_backend->context,
- client_id,
- uid,
- data_length,
- data,
+ delegate_store->storage_backend->context, client_id, uid, data_length, data,
PSA_STORAGE_FLAG_NONE);
return psa_status;
}
-static psa_status_t store_append_write(
- struct delegate_variable_store *delegate_store,
- uint32_t client_id,
- uint64_t uid,
- size_t data_length,
- const void *data)
+static psa_status_t store_append_write(struct delegate_variable_store *delegate_store,
+ uint32_t client_id, uint64_t uid, size_t data_length,
+ const void *data)
{
struct psa_storage_info_t storage_info;
- if (data_length == 0) return PSA_SUCCESS;
+ if (data_length == 0)
+ return PSA_SUCCESS;
psa_status_t psa_status = delegate_store->storage_backend->interface->get_info(
- delegate_store->storage_backend->context,
- client_id,
- uid,
- &storage_info);
+ delegate_store->storage_backend->context, client_id, uid, &storage_info);
- if (psa_status != PSA_SUCCESS) return psa_status;
+ if (psa_status != PSA_SUCCESS)
+ return psa_status;
/* Determine size of appended variable */
size_t new_size = storage_info.size + data_length;
/* Defend against integer overflow */
- if (new_size < storage_info.size) return PSA_ERROR_INVALID_ARGUMENT;
+ if (new_size < storage_info.size)
+ return PSA_ERROR_INVALID_ARGUMENT;
- /* Police maximum variable size limit */
- if (new_size > delegate_store->max_variable_size) return PSA_ERROR_INVALID_ARGUMENT;
+ /* Police maximum variable size limit */
+ if (new_size > delegate_store->max_variable_size)
+ return PSA_ERROR_INVALID_ARGUMENT;
/* Storage backend doesn't support an append operation so we need
* need to read the current variable data, extend it and write it back.
*/
uint8_t *rw_buf = malloc(new_size);
- if (!rw_buf) return PSA_ERROR_INSUFFICIENT_MEMORY;
+ if (!rw_buf)
+ return PSA_ERROR_INSUFFICIENT_MEMORY;
size_t old_size = 0;
psa_status = delegate_store->storage_backend->interface->get(
- delegate_store->storage_backend->context,
- client_id,
- uid,
- 0,
- new_size,
- rw_buf,
+ delegate_store->storage_backend->context, client_id, uid, 0, new_size, rw_buf,
&old_size);
if (psa_status == PSA_SUCCESS) {
-
if ((old_size + data_length) <= new_size) {
-
/* Extend the variable data */
memcpy(&rw_buf[old_size], data, data_length);
psa_status = delegate_store->storage_backend->interface->set(
- delegate_store->storage_backend->context,
- client_id,
- uid,
- old_size + data_length,
- rw_buf,
- storage_info.flags);
- }
- else {
-
+ delegate_store->storage_backend->context, client_id, uid,
+ old_size + data_length, rw_buf, storage_info.flags);
+ } else {
/* There's a mismatch between the length obtained from
* get_info() and the subsequent length returned by get().
*/
@@ -808,8 +655,7 @@
return psa_status;
}
-static void purge_orphan_index_entries(
- struct uefi_variable_store *context)
+static void purge_orphan_index_entries(struct uefi_variable_store *context)
{
bool any_orphans = false;
struct variable_index_iterator iter;
@@ -821,22 +667,19 @@
* a power failure before an object is stored.
*/
while (!variable_index_iterator_is_done(&iter)) {
-
struct variable_info *info = variable_index_iterator_current(&iter);
- if (info->is_variable_set && (info->metadata.attributes & EFI_VARIABLE_NON_VOLATILE)) {
-
+ if (info->is_variable_set &&
+ (info->metadata.attributes & EFI_VARIABLE_NON_VOLATILE)) {
struct psa_storage_info_t storage_info;
- struct storage_backend *storage_backend = context->persistent_store.storage_backend;
+ struct storage_backend *storage_backend =
+ context->persistent_store.storage_backend;
psa_status_t psa_status = storage_backend->interface->get_info(
- storage_backend->context,
- context->owner_id,
- info->metadata.uid,
+ storage_backend->context, context->owner_id, info->metadata.uid,
&storage_info);
if (psa_status != PSA_SUCCESS) {
-
/* Detected a mismatch between the index and storage */
variable_index_clear_variable(&context->variable_index, info);
any_orphans = true;
@@ -846,48 +689,42 @@
variable_index_iterator_next(&iter);
}
- if (any_orphans) sync_variable_index(context);
+ if (any_orphans)
+ sync_variable_index(context);
}
-static struct delegate_variable_store *select_delegate_store(
- struct uefi_variable_store *context,
- uint32_t attributes)
+static struct delegate_variable_store *select_delegate_store(struct uefi_variable_store *context,
+ uint32_t attributes)
{
bool is_nv = (attributes & EFI_VARIABLE_NON_VOLATILE);
- return (is_nv) ?
- &context->persistent_store :
- &context->volatile_store;
+ return (is_nv) ? &context->persistent_store : &context->volatile_store;
}
-static size_t space_used(
- struct uefi_variable_store *context,
- uint32_t attributes,
- struct storage_backend *storage_backend)
+static size_t space_used(struct uefi_variable_store *context, uint32_t attributes,
+ struct storage_backend *storage_backend)
{
- if (!storage_backend) return 0;
+ if (!storage_backend)
+ return 0;
size_t total_used = 0;
struct variable_index_iterator iter;
variable_index_iterator_first(&iter, &context->variable_index);
while (!variable_index_iterator_is_done(&iter)) {
-
struct variable_info *info = variable_index_iterator_current(&iter);
if (info->is_variable_set &&
((info->metadata.attributes & EFI_VARIABLE_NON_VOLATILE) ==
- (attributes & EFI_VARIABLE_NON_VOLATILE))) {
-
+ (attributes & EFI_VARIABLE_NON_VOLATILE))) {
struct psa_storage_info_t storage_info;
psa_status_t psa_status = storage_backend->interface->get_info(
- storage_backend->context,
- context->owner_id,
- info->metadata.uid,
+ storage_backend->context, context->owner_id, info->metadata.uid,
&storage_info);
- if (psa_status == PSA_SUCCESS) total_used += storage_info.size;
+ if (psa_status == PSA_SUCCESS)
+ total_used += storage_info.size;
}
variable_index_iterator_next(&iter);
@@ -896,57 +733,52 @@
return total_used;
}
-static efi_status_t psa_to_efi_storage_status(
- psa_status_t psa_status)
+static efi_status_t psa_to_efi_storage_status(psa_status_t psa_status)
{
efi_status_t efi_status = EFI_DEVICE_ERROR;
- switch(psa_status)
- {
- case PSA_SUCCESS:
- efi_status = EFI_SUCCESS;
- break;
- case PSA_ERROR_NOT_PERMITTED:
- efi_status = EFI_ACCESS_DENIED;
- break;
- case PSA_ERROR_INVALID_ARGUMENT:
- efi_status = EFI_INVALID_PARAMETER;
- break;
- case PSA_ERROR_BAD_STATE:
- efi_status = EFI_NOT_READY;
- break;
- case PSA_ERROR_BUFFER_TOO_SMALL:
- efi_status = EFI_BUFFER_TOO_SMALL;
- break;
- case PSA_ERROR_DOES_NOT_EXIST:
- efi_status = EFI_NOT_FOUND;
- break;
- case PSA_ERROR_INSUFFICIENT_MEMORY:
- efi_status = EFI_OUT_OF_RESOURCES;
- break;
- case PSA_ERROR_INSUFFICIENT_STORAGE:
- efi_status = EFI_OUT_OF_RESOURCES;
- break;
- case PSA_ERROR_STORAGE_FAILURE:
- efi_status = EFI_DEVICE_ERROR;
- break;
- case PSA_STATUS_HARDWARE_FAILURE:
- efi_status = EFI_DEVICE_ERROR;
- break;
- default:
- break;
+ switch (psa_status) {
+ case PSA_SUCCESS:
+ efi_status = EFI_SUCCESS;
+ break;
+ case PSA_ERROR_NOT_PERMITTED:
+ efi_status = EFI_ACCESS_DENIED;
+ break;
+ case PSA_ERROR_INVALID_ARGUMENT:
+ efi_status = EFI_INVALID_PARAMETER;
+ break;
+ case PSA_ERROR_BAD_STATE:
+ efi_status = EFI_NOT_READY;
+ break;
+ case PSA_ERROR_BUFFER_TOO_SMALL:
+ efi_status = EFI_BUFFER_TOO_SMALL;
+ break;
+ case PSA_ERROR_DOES_NOT_EXIST:
+ efi_status = EFI_NOT_FOUND;
+ break;
+ case PSA_ERROR_INSUFFICIENT_MEMORY:
+ efi_status = EFI_OUT_OF_RESOURCES;
+ break;
+ case PSA_ERROR_INSUFFICIENT_STORAGE:
+ efi_status = EFI_OUT_OF_RESOURCES;
+ break;
+ case PSA_ERROR_STORAGE_FAILURE:
+ efi_status = EFI_DEVICE_ERROR;
+ break;
+ case PSA_STATUS_HARDWARE_FAILURE:
+ efi_status = EFI_DEVICE_ERROR;
+ break;
+ default:
+ break;
}
return efi_status;
}
-static efi_status_t check_name_terminator(
- const int16_t *name,
- size_t name_size)
+static efi_status_t check_name_terminator(const int16_t *name, size_t name_size)
{
/* Variable names must be null terminated */
- if (name_size < sizeof(int16_t) || name[name_size/sizeof (int16_t) - 1] != L'\0') {
-
+ if (name_size < sizeof(int16_t) || name[name_size / sizeof(int16_t) - 1] != L'\0') {
return EFI_INVALID_PARAMETER;
}
diff --git a/components/service/uefi/smm_variable/backend/uefi_variable_store.h b/components/service/uefi/smm_variable/backend/uefi_variable_store.h
index e4c67bb..9c80a0f 100644
--- a/components/service/uefi/smm_variable/backend/uefi_variable_store.h
+++ b/components/service/uefi/smm_variable/backend/uefi_variable_store.h
@@ -8,12 +8,13 @@
#ifndef UEFI_VARIABLE_STORE_H
#define UEFI_VARIABLE_STORE_H
-#include <stdbool.h>
-#include <stdint.h>
-#include <stddef.h>
#include <protocols/common/efi/efi_status.h>
#include <protocols/service/smm_variable/smm_variable_proto.h>
#include <service/secure_storage/backend/storage_backend.h>
+#include <stdbool.h>
+#include <stddef.h>
+#include <stdint.h>
+
#include "variable_index.h"
#ifdef __cplusplus
@@ -26,8 +27,7 @@
* A delegate_variable_store combines an association with a concrete
* storage backend and a set of limits parameters.
*/
-struct delegate_variable_store
-{
+struct delegate_variable_store {
bool is_nv;
size_t total_capacity;
size_t max_variable_size;
@@ -42,8 +42,7 @@
* by another trusted service such as the protected storage or internal trusted
* storage service.
*/
-struct uefi_variable_store
-{
+struct uefi_variable_store {
bool is_boot_service;
uint32_t owner_id;
uint8_t *index_sync_buffer;
@@ -68,20 +67,17 @@
*
* @return EFI_SUCCESS if initialized successfully
*/
-efi_status_t uefi_variable_store_init(
- struct uefi_variable_store *context,
- uint32_t owner_id,
- size_t max_variables,
- struct storage_backend *persistent_store,
- struct storage_backend *volatile_store);
+efi_status_t uefi_variable_store_init(struct uefi_variable_store *context, uint32_t owner_id,
+ size_t max_variables,
+ struct storage_backend *persistent_store,
+ struct storage_backend *volatile_store);
/**
* @brief De-initialises a uefi_variable_store
*
* @param[in] context uefi_variable_store instance
*/
-void uefi_variable_store_deinit(
- struct uefi_variable_store *context);
+void uefi_variable_store_deinit(struct uefi_variable_store *context);
/**
* @brief Set storage limits
@@ -94,11 +90,9 @@
* @param[in] total_capacity The total storage capacity in bytes
* @param[in] max_variable_size Variable size limit
*/
-void uefi_variable_store_set_storage_limits(
- struct uefi_variable_store *context,
- uint32_t attributes,
- size_t total_capacity,
- size_t max_variable_size);
+void uefi_variable_store_set_storage_limits(struct uefi_variable_store *context,
+ uint32_t attributes, size_t total_capacity,
+ size_t max_variable_size);
/**
* @brief Set variable
@@ -110,9 +104,8 @@
*
* @return EFI_SUCCESS if successful
*/
-efi_status_t uefi_variable_store_set_variable(
- struct uefi_variable_store *context,
- const SMM_VARIABLE_COMMUNICATE_ACCESS_VARIABLE *var);
+efi_status_t uefi_variable_store_set_variable(struct uefi_variable_store *context,
+ const SMM_VARIABLE_COMMUNICATE_ACCESS_VARIABLE *var);
/**
* @brief Get variable
@@ -126,11 +119,9 @@
*
* @return EFI_SUCCESS if successful
*/
-efi_status_t uefi_variable_store_get_variable(
- struct uefi_variable_store *context,
- SMM_VARIABLE_COMMUNICATE_ACCESS_VARIABLE *var,
- size_t max_data_len,
- size_t *total_length);
+efi_status_t uefi_variable_store_get_variable(struct uefi_variable_store *context,
+ SMM_VARIABLE_COMMUNICATE_ACCESS_VARIABLE *var,
+ size_t max_data_len, size_t *total_length);
/**
* @brief Get next variable name
@@ -144,11 +135,10 @@
*
* @return EFI_SUCCESS if successful
*/
-efi_status_t uefi_variable_store_get_next_variable_name(
- struct uefi_variable_store *context,
- SMM_VARIABLE_COMMUNICATE_GET_NEXT_VARIABLE_NAME *cur,
- size_t max_name_len,
- size_t *total_length);
+efi_status_t
+uefi_variable_store_get_next_variable_name(struct uefi_variable_store *context,
+ SMM_VARIABLE_COMMUNICATE_GET_NEXT_VARIABLE_NAME *cur,
+ size_t max_name_len, size_t *total_length);
/**
* @brief Query for variable info
@@ -158,9 +148,9 @@
*
* @return EFI_SUCCESS if successful
*/
-efi_status_t uefi_variable_store_query_variable_info(
- struct uefi_variable_store *context,
- SMM_VARIABLE_COMMUNICATE_QUERY_VARIABLE_INFO *var_info);
+efi_status_t
+uefi_variable_store_query_variable_info(struct uefi_variable_store *context,
+ SMM_VARIABLE_COMMUNICATE_QUERY_VARIABLE_INFO *var_info);
/**
* @brief Exit boot service
@@ -172,8 +162,7 @@
*
* @return EFI_SUCCESS if successful
*/
-efi_status_t uefi_variable_store_exit_boot_service(
- struct uefi_variable_store *context);
+efi_status_t uefi_variable_store_exit_boot_service(struct uefi_variable_store *context);
/**
* @brief Set variable check property
diff --git a/components/service/uefi/smm_variable/backend/variable_checker.c b/components/service/uefi/smm_variable/backend/variable_checker.c
index 81a6cc6..b814d93 100644
--- a/components/service/uefi/smm_variable/backend/variable_checker.c
+++ b/components/service/uefi/smm_variable/backend/variable_checker.c
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2021-2022, Arm Limited. All rights reserved.
+ * Copyright (c) 2021-2023, Arm Limited. All rights reserved.
*
* SPDX-License-Identifier: BSD-3-Clause
*
@@ -7,10 +7,9 @@
#include "variable_checker.h"
-efi_status_t variable_checker_set_constraints(
- struct variable_constraints *constraints,
- bool is_update,
- const VAR_CHECK_VARIABLE_PROPERTY *check_var_property)
+efi_status_t variable_checker_set_constraints(struct variable_constraints *constraints,
+ bool is_update,
+ const VAR_CHECK_VARIABLE_PROPERTY *check_var_property)
{
/* Sanity check input parameters */
if (check_var_property->Revision != VAR_CHECK_VARIABLE_PROPERTY_REVISION)
@@ -21,9 +20,8 @@
/* Check for an attempt to undo previously set access constraints */
if (is_update) {
-
if ((constraints->property & VAR_CHECK_VARIABLE_PROPERTY_READ_ONLY) &&
- !(check_var_property->Property & VAR_CHECK_VARIABLE_PROPERTY_READ_ONLY))
+ !(check_var_property->Property & VAR_CHECK_VARIABLE_PROPERTY_READ_ONLY))
return EFI_INVALID_PARAMETER;
}
@@ -37,9 +35,8 @@
return EFI_SUCCESS;
}
-void variable_checker_get_constraints(
- const struct variable_constraints *constraints,
- VAR_CHECK_VARIABLE_PROPERTY *check_var_property)
+void variable_checker_get_constraints(const struct variable_constraints *constraints,
+ VAR_CHECK_VARIABLE_PROPERTY *check_var_property)
{
check_var_property->Revision = constraints->revision;
check_var_property->Attributes = constraints->attributes;
@@ -48,10 +45,8 @@
check_var_property->MaxSize = constraints->max_size;
}
-efi_status_t variable_checker_check_on_set(
- const struct variable_constraints *constraints,
- uint32_t attributes,
- size_t data_size)
+efi_status_t variable_checker_check_on_set(const struct variable_constraints *constraints,
+ uint32_t attributes, size_t data_size)
{
(void)attributes;
diff --git a/components/service/uefi/smm_variable/backend/variable_checker.h b/components/service/uefi/smm_variable/backend/variable_checker.h
index cd623a3..6a5c36d 100644
--- a/components/service/uefi/smm_variable/backend/variable_checker.h
+++ b/components/service/uefi/smm_variable/backend/variable_checker.h
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2021, Arm Limited. All rights reserved.
+ * Copyright (c) 2021-2023, Arm Limited. All rights reserved.
*
* SPDX-License-Identifier: BSD-3-Clause
*
@@ -8,11 +8,11 @@
#ifndef VARIABLE_CHECKER_H
#define VARIABLE_CHECKER_H
+#include <protocols/common/efi/efi_status.h>
+#include <protocols/service/smm_variable/smm_variable_proto.h>
#include <stdbool.h>
#include <stddef.h>
#include <stdint.h>
-#include <protocols/common/efi/efi_status.h>
-#include <protocols/service/smm_variable/smm_variable_proto.h>
#ifdef __cplusplus
extern "C" {
@@ -25,13 +25,12 @@
* based on policy driven constraints, set using:
* SMM_VARIABLE_FUNCTION_VAR_CHECK_VARIABLE_PROPERTY_SET.
*/
-struct variable_constraints
-{
- uint16_t revision;
- uint16_t property;
- uint32_t attributes;
- size_t min_size;
- size_t max_size;
+struct variable_constraints {
+ uint16_t revision;
+ uint16_t property;
+ uint32_t attributes;
+ size_t min_size;
+ size_t max_size;
};
/**
@@ -43,10 +42,9 @@
*
* @return EFI_SUCCESS if check constraints set successfully
*/
-efi_status_t variable_checker_set_constraints(
- struct variable_constraints *constraints,
- bool is_update,
- const VAR_CHECK_VARIABLE_PROPERTY *check_var_property);
+efi_status_t
+variable_checker_set_constraints(struct variable_constraints *constraints, bool is_update,
+ const VAR_CHECK_VARIABLE_PROPERTY *check_var_property);
/**
* @brief Get variable check constraints
@@ -54,9 +52,8 @@
* @param[in] constraints Variable constraints to get
* @param[out] check_var_property The result
*/
-void variable_checker_get_constraints(
- const struct variable_constraints *constraints,
- VAR_CHECK_VARIABLE_PROPERTY *check_var_property);
+void variable_checker_get_constraints(const struct variable_constraints *constraints,
+ VAR_CHECK_VARIABLE_PROPERTY *check_var_property);
/**
* @brief Check if set operations is allowed
@@ -67,10 +64,8 @@
*
* @return EFI_SUCCESS if set is allowed
*/
-efi_status_t variable_checker_check_on_set(
- const struct variable_constraints *constraints,
- uint32_t attributes,
- size_t data_size);
+efi_status_t variable_checker_check_on_set(const struct variable_constraints *constraints,
+ uint32_t attributes, size_t data_size);
#ifdef __cplusplus
}
diff --git a/components/service/uefi/smm_variable/backend/variable_index.c b/components/service/uefi/smm_variable/backend/variable_index.c
index 68e4c89..c82e89c 100644
--- a/components/service/uefi/smm_variable/backend/variable_index.c
+++ b/components/service/uefi/smm_variable/backend/variable_index.c
@@ -1,19 +1,17 @@
/*
- * Copyright (c) 2021-2022, Arm Limited. All rights reserved.
+ * Copyright (c) 2021-2023, Arm Limited. All rights reserved.
*
* SPDX-License-Identifier: BSD-3-Clause
*
*/
-#include <stdlib.h>
-#include <string.h>
#include "variable_index.h"
+#include <stdlib.h>
+#include <string.h>
+
/* Private functions */
-static uint64_t name_hash(
- const EFI_GUID *guid,
- size_t name_size,
- const int16_t *name)
+static uint64_t name_hash(const EFI_GUID *guid, size_t name_size, const int16_t *name)
{
/* Using djb2 hash by Dan Bernstein */
uint64_t hash = 5381;
@@ -24,25 +22,21 @@
hash = ((hash << 5) + hash) + guid->Data3;
for (int i = 0; i < 8; ++i) {
-
hash = ((hash << 5) + hash) + guid->Data4[i];
}
/* Extend to cover name up to but not including null terminator */
for (size_t i = 0; i < name_size / sizeof(int16_t); ++i) {
-
- if (!name[i]) break;
+ if (!name[i])
+ break;
hash = ((hash << 5) + hash) + name[i];
}
return hash;
}
-static uint64_t generate_uid(
- const struct variable_index *context,
- const EFI_GUID *guid,
- size_t name_size,
- const int16_t *name)
+static uint64_t generate_uid(const struct variable_index *context, const EFI_GUID *guid,
+ size_t name_size, const int16_t *name)
{
uint64_t uid = name_hash(guid, name_size, name);
@@ -52,20 +46,15 @@
return uid;
}
-static int find_variable(
- const struct variable_index *context,
- const EFI_GUID *guid,
- size_t name_size,
- const int16_t *name)
+static int find_variable(const struct variable_index *context, const EFI_GUID *guid,
+ size_t name_size, const int16_t *name)
{
int found_pos = -1;
uint64_t uid = name_hash(guid, name_size, name);
for (size_t pos = 0; pos < context->max_variables; pos++) {
-
if ((context->entries[pos].in_use) &&
- (uid == context->entries[pos].info.metadata.uid)) {
-
+ (uid == context->entries[pos].info.metadata.uid)) {
found_pos = pos;
break;
}
@@ -74,15 +63,12 @@
return found_pos;
}
-static int find_free(
- const struct variable_index *context)
+static int find_free(const struct variable_index *context)
{
int free_pos = -1;
for (size_t pos = 0; pos < context->max_variables; pos++) {
-
if (!context->entries[pos].in_use) {
-
free_pos = pos;
break;
}
@@ -100,18 +86,16 @@
static struct variable_entry *containing_entry(const struct variable_info *info)
{
size_t info_offset = offsetof(struct variable_entry, info);
- struct variable_entry *entry = (struct variable_entry*)((uint8_t*)info - info_offset);
+ struct variable_entry *entry = (struct variable_entry *)((uint8_t *)info - info_offset);
return entry;
}
/* Public functions */
-efi_status_t variable_index_init(
- struct variable_index *context,
- size_t max_variables)
+efi_status_t variable_index_init(struct variable_index *context, size_t max_variables)
{
context->max_variables = max_variables;
- context->entries = (struct variable_entry*)
- malloc(sizeof(struct variable_entry) * max_variables);
+ context->entries =
+ (struct variable_entry *)malloc(sizeof(struct variable_entry) * max_variables);
if (context->entries) {
memset(context->entries, 0, sizeof(struct variable_entry) * max_variables);
@@ -120,65 +104,51 @@
return (context->entries) ? EFI_SUCCESS : EFI_OUT_OF_RESOURCES;
}
-void variable_index_deinit(
- struct variable_index *context)
+void variable_index_deinit(struct variable_index *context)
{
free(context->entries);
}
-size_t variable_index_max_dump_size(
- struct variable_index *context)
+size_t variable_index_max_dump_size(struct variable_index *context)
{
return sizeof(struct variable_metadata) * context->max_variables;
}
-struct variable_info *variable_index_find(
- struct variable_index *context,
- const EFI_GUID *guid,
- size_t name_size,
- const int16_t *name)
+struct variable_info *variable_index_find(struct variable_index *context, const EFI_GUID *guid,
+ size_t name_size, const int16_t *name)
{
struct variable_info *result = NULL;
int pos = find_variable(context, guid, name_size, name);
if (pos >= 0) {
-
result = &context->entries[pos].info;
}
return result;
}
-struct variable_info *variable_index_find_next(
- const struct variable_index *context,
- const EFI_GUID *guid,
- size_t name_size,
- const int16_t *name,
- efi_status_t *status)
+struct variable_info *variable_index_find_next(const struct variable_index *context,
+ const EFI_GUID *guid, size_t name_size,
+ const int16_t *name, efi_status_t *status)
{
struct variable_info *result = NULL;
*status = EFI_NOT_FOUND;
if (name_size >= sizeof(int16_t)) {
-
/*
* Name must be at least one character long to accommodate
* the mandatory null terminator.
*/
if (name[0] != 0) {
-
/* Find next from current name */
int pos = find_variable(context, guid, name_size, name);
if (pos >= 0) {
-
/* Iterate to next used entry */
++pos;
while (pos < (int)context->max_variables) {
-
if (context->entries[pos].in_use &&
- context->entries[pos].info.is_variable_set) {
-
+ context->entries[pos].info.is_variable_set) {
result = &context->entries[pos].info;
*status = EFI_SUCCESS;
break;
@@ -186,23 +156,17 @@
++pos;
}
- }
- else {
-
+ } else {
/* A non-empty name was provided but it wasn't found */
*status = EFI_INVALID_PARAMETER;
}
- }
- else {
-
+ } else {
/* Find first */
int pos = 0;
while (pos < (int)context->max_variables) {
-
if (context->entries[pos].in_use &&
- context->entries[pos].info.is_variable_set) {
-
+ context->entries[pos].info.is_variable_set) {
result = &context->entries[pos].info;
*status = EFI_SUCCESS;
break;
@@ -216,10 +180,7 @@
return result;
}
-static void set_variable_name(
- struct variable_info *info,
- size_t name_size,
- const int16_t *name)
+static void set_variable_name(struct variable_info *info, size_t name_size, const int16_t *name)
{
size_t trimmed_size = 0;
@@ -228,30 +189,25 @@
* are discarded.
*/
for (size_t i = 0; i < name_size; i++) {
-
++trimmed_size;
info->metadata.name[i] = name[i];
- if (!name[i]) break;
+ if (!name[i])
+ break;
}
info->metadata.name_size = trimmed_size * sizeof(int16_t);
}
-static struct variable_entry *add_entry(
- struct variable_index *context,
- const EFI_GUID *guid,
- size_t name_size,
- const int16_t *name)
+static struct variable_entry *add_entry(struct variable_index *context, const EFI_GUID *guid,
+ size_t name_size, const int16_t *name)
{
struct variable_entry *entry = NULL;
if (name_size <= (VARIABLE_INDEX_MAX_NAME_SIZE * sizeof(int16_t))) {
-
int pos = find_free(context);
if (pos >= 0) {
-
entry = &context->entries[pos];
struct variable_info *info = &entry->info;
@@ -272,33 +228,24 @@
return entry;
}
-struct variable_info *variable_index_add_entry(
- struct variable_index *context,
- const EFI_GUID *guid,
- size_t name_size,
- const int16_t *name)
+struct variable_info *variable_index_add_entry(struct variable_index *context, const EFI_GUID *guid,
+ size_t name_size, const int16_t *name)
{
struct variable_info *info = NULL;
struct variable_entry *entry = add_entry(context, guid, name_size, name);
if (entry) {
-
info = &entry->info;
}
return info;
}
-void variable_index_remove_unused_entry(
- struct variable_index *context,
- struct variable_info *info)
+void variable_index_remove_unused_entry(struct variable_index *context, struct variable_info *info)
{
(void)context;
- if (info &&
- !info->is_constraints_set &&
- !info->is_variable_set) {
-
+ if (info && !info->is_constraints_set && !info->is_variable_set) {
struct variable_entry *entry = containing_entry(info);
entry->in_use = false;
@@ -306,9 +253,7 @@
}
}
-void variable_index_set_variable(
- struct variable_info *info,
- uint32_t attributes)
+void variable_index_set_variable(struct variable_info *info, uint32_t attributes)
{
struct variable_entry *entry = containing_entry(info);
@@ -318,14 +263,11 @@
mark_dirty(entry);
}
-void variable_index_clear_variable(
- struct variable_index *context,
- struct variable_info *info)
+void variable_index_clear_variable(struct variable_index *context, struct variable_info *info)
{
(void)context;
if (info) {
-
struct variable_entry *entry = containing_entry(info);
mark_dirty(entry);
@@ -334,37 +276,29 @@
}
}
-void variable_index_set_constraints(
- struct variable_info *info,
- const struct variable_constraints *constraints)
+void variable_index_set_constraints(struct variable_info *info,
+ const struct variable_constraints *constraints)
{
if (info) {
-
info->check_constraints = *constraints;
info->is_constraints_set = true;
}
}
-bool variable_index_dump(
- struct variable_index *context,
- size_t buffer_size,
- uint8_t *buffer,
- size_t *data_len)
+bool variable_index_dump(struct variable_index *context, size_t buffer_size, uint8_t *buffer,
+ size_t *data_len)
{
bool any_dirty = false;
uint8_t *dump_pos = buffer;
size_t bytes_dumped = 0;
for (size_t pos = 0; pos < context->max_variables; pos++) {
-
struct variable_entry *entry = &context->entries[pos];
struct variable_metadata *metadata = &entry->info.metadata;
- if (entry->in_use &&
- entry->info.is_variable_set &&
- (metadata->attributes & EFI_VARIABLE_NON_VOLATILE) &&
- ((bytes_dumped + sizeof(struct variable_metadata)) <= buffer_size)) {
-
+ if (entry->in_use && entry->info.is_variable_set &&
+ (metadata->attributes & EFI_VARIABLE_NON_VOLATILE) &&
+ ((bytes_dumped + sizeof(struct variable_metadata)) <= buffer_size)) {
memcpy(dump_pos, metadata, sizeof(struct variable_metadata));
bytes_dumped += sizeof(struct variable_metadata);
dump_pos += sizeof(struct variable_metadata);
@@ -379,19 +313,15 @@
return any_dirty;
}
-size_t variable_index_restore(
- const struct variable_index *context,
- size_t data_len,
- const uint8_t *buffer)
+size_t variable_index_restore(const struct variable_index *context, size_t data_len,
+ const uint8_t *buffer)
{
size_t bytes_loaded = 0;
const uint8_t *load_pos = buffer;
int pos = 0;
while (bytes_loaded < data_len) {
-
if ((data_len - bytes_loaded) >= sizeof(struct variable_metadata)) {
-
struct variable_entry *entry = &context->entries[pos];
struct variable_metadata *metadata = &entry->info.metadata;
@@ -404,9 +334,7 @@
load_pos += sizeof(struct variable_metadata);
++pos;
- }
- else {
-
+ } else {
/* Not a whole number of variable_metadata structs! */
break;
}
diff --git a/components/service/uefi/smm_variable/backend/variable_index.h b/components/service/uefi/smm_variable/backend/variable_index.h
index 2f0197d..583d8df 100644
--- a/components/service/uefi/smm_variable/backend/variable_index.h
+++ b/components/service/uefi/smm_variable/backend/variable_index.h
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2021, Arm Limited. All rights reserved.
+ * Copyright (c) 2021-2023, Arm Limited. All rights reserved.
*
* SPDX-License-Identifier: BSD-3-Clause
*
@@ -8,11 +8,12 @@
#ifndef VARIABLE_INDEX_H
#define VARIABLE_INDEX_H
+#include <protocols/common/efi/efi_status.h>
+#include <protocols/service/smm_variable/smm_variable_proto.h>
#include <stdbool.h>
#include <stddef.h>
#include <stdint.h>
-#include <protocols/common/efi/efi_status.h>
-#include <protocols/service/smm_variable/smm_variable_proto.h>
+
#include "variable_checker.h"
#ifdef __cplusplus
@@ -22,20 +23,19 @@
/**
* Implementation limits
*/
-#define VARIABLE_INDEX_MAX_NAME_SIZE (32)
+#define VARIABLE_INDEX_MAX_NAME_SIZE (32)
/**
* \brief variable_metadata structure definition
*
* Holds metadata associated with stored variable.
*/
-struct variable_metadata
-{
- EFI_GUID guid;
- size_t name_size;
- int16_t name[VARIABLE_INDEX_MAX_NAME_SIZE];
- uint32_t attributes;
- uint64_t uid;
+struct variable_metadata {
+ EFI_GUID guid;
+ size_t name_size;
+ int16_t name[VARIABLE_INDEX_MAX_NAME_SIZE];
+ uint32_t attributes;
+ uint64_t uid;
};
/**
@@ -43,8 +43,7 @@
*
* Holds information about a stored variable.
*/
-struct variable_info
-{
+struct variable_info {
struct variable_metadata metadata;
struct variable_constraints check_constraints;
@@ -57,12 +56,11 @@
*
* Represents a store variable in the variable index.
*/
-struct variable_entry
-{
- struct variable_info info;
+struct variable_entry {
+ struct variable_info info;
- bool in_use;
- bool dirty;
+ bool in_use;
+ bool dirty;
};
/**
@@ -71,8 +69,7 @@
* Provides an index of stored variables to allow the uefi variable store
* contents to be enumerated.
*/
-struct variable_index
-{
+struct variable_index {
size_t max_variables;
struct variable_entry *entries;
};
@@ -85,17 +82,14 @@
*
* @return EFI_SUCCESS if initialized successfully
*/
-efi_status_t variable_index_init(
- struct variable_index *context,
- size_t max_variables);
+efi_status_t variable_index_init(struct variable_index *context, size_t max_variables);
/**
* @brief De-initialises a variable_index
*
* @param[in] context variable_index
*/
-void variable_index_deinit(
- struct variable_index *context);
+void variable_index_deinit(struct variable_index *context);
/**
* @brief Returns the maximum dump size
@@ -106,8 +100,7 @@
*
* @param[in] context variable_index
*/
-size_t variable_index_max_dump_size(
- struct variable_index *context);
+size_t variable_index_max_dump_size(struct variable_index *context);
/**
* @brief Find info about a variable
@@ -119,11 +112,8 @@
*
* @return Pointer to variable_info or NULL
*/
-struct variable_info *variable_index_find(
- struct variable_index *context,
- const EFI_GUID *guid,
- size_t name_size,
- const int16_t *name);
+struct variable_info *variable_index_find(struct variable_index *context, const EFI_GUID *guid,
+ size_t name_size, const int16_t *name);
/**
* @brief Find the next variable in the index
@@ -136,12 +126,9 @@
*
* @return Pointer to variable_info or NULL
*/
-struct variable_info *variable_index_find_next(
- const struct variable_index *context,
- const EFI_GUID *guid,
- size_t name_size,
- const int16_t *name,
- efi_status_t *status);
+struct variable_info *variable_index_find_next(const struct variable_index *context,
+ const EFI_GUID *guid, size_t name_size,
+ const int16_t *name, efi_status_t *status);
/**
* @brief Add a new entry to the index
@@ -157,11 +144,8 @@
*
* @return Pointer to variable_info or NULL
*/
-struct variable_info *variable_index_add_entry(
- struct variable_index *context,
- const EFI_GUID *guid,
- size_t name_size,
- const int16_t *name);
+struct variable_info *variable_index_add_entry(struct variable_index *context, const EFI_GUID *guid,
+ size_t name_size, const int16_t *name);
/**
* @brief Remove an unused entry from the index
@@ -171,9 +155,7 @@
* @param[in] context variable_index
* @param[in] info The variable info corresponding to the entry to remove
*/
-void variable_index_remove_unused_entry(
- struct variable_index *context,
- struct variable_info *info);
+void variable_index_remove_unused_entry(struct variable_index *context, struct variable_info *info);
/**
* @brief Set a variable to the index
@@ -183,9 +165,7 @@
* @param[in] info variable info
* @param[in] attributes The variable's attributes
*/
-void variable_index_set_variable(
- struct variable_info *info,
- uint32_t attributes);
+void variable_index_set_variable(struct variable_info *info, uint32_t attributes);
/**
* @brief Clear a variable from the index
@@ -195,9 +175,7 @@
* @param[in] context variable_index
* @param[in] info The variable info corresponding to the variable to clear
*/
-void variable_index_clear_variable(
- struct variable_index *context,
- struct variable_info *info);
+void variable_index_clear_variable(struct variable_index *context, struct variable_info *info);
/**
* @brief Set a check constraints object associated with a variavle
@@ -205,9 +183,8 @@
* @param[in] info variable info
* @param[in] constraints The check constraints
*/
-void variable_index_set_constraints(
- struct variable_info *info,
- const struct variable_constraints *constraints);
+void variable_index_set_constraints(struct variable_info *info,
+ const struct variable_constraints *constraints);
/**
* @brief Dump the serialized index contents for persistent backup
@@ -219,11 +196,8 @@
*
* @return True if there is unsaved data
*/
-bool variable_index_dump(
- struct variable_index *context,
- size_t buffer_size,
- uint8_t *buffer,
- size_t *data_len);
+bool variable_index_dump(struct variable_index *context, size_t buffer_size, uint8_t *buffer,
+ size_t *data_len);
/**
* @brief Restore the serialized index contents
@@ -237,11 +211,8 @@
*
* @return Number of bytes loaded
*/
-size_t variable_index_restore(
- const struct variable_index *context,
- size_t data_len,
- const uint8_t *buffer);
-
+size_t variable_index_restore(const struct variable_index *context, size_t data_len,
+ const uint8_t *buffer);
#ifdef __cplusplus
}
diff --git a/components/service/uefi/smm_variable/backend/variable_index_iterator.c b/components/service/uefi/smm_variable/backend/variable_index_iterator.c
index acb3bcb..eb0c118 100644
--- a/components/service/uefi/smm_variable/backend/variable_index_iterator.c
+++ b/components/service/uefi/smm_variable/backend/variable_index_iterator.c
@@ -1,51 +1,45 @@
/*
- * Copyright (c) 2021-2022, Arm Limited. All rights reserved.
+ * Copyright (c) 2021-2023, Arm Limited. All rights reserved.
*
* SPDX-License-Identifier: BSD-3-Clause
*
*/
-#include <stddef.h>
#include "variable_index_iterator.h"
-void variable_index_iterator_first(
- struct variable_index_iterator *iter,
- const struct variable_index *variable_index)
+#include <stddef.h>
+
+void variable_index_iterator_first(struct variable_index_iterator *iter,
+ const struct variable_index *variable_index)
{
iter->variable_index = variable_index;
iter->current_pos = variable_index->max_variables;
for (size_t pos = 0; pos < variable_index->max_variables; pos++) {
-
if (variable_index->entries[pos].in_use) {
-
iter->current_pos = pos;
break;
}
}
}
-bool variable_index_iterator_is_done(
- const struct variable_index_iterator *iter)
+bool variable_index_iterator_is_done(const struct variable_index_iterator *iter)
{
return iter->current_pos >= iter->variable_index->max_variables;
}
-struct variable_info *variable_index_iterator_current(
- const struct variable_index_iterator *iter)
+struct variable_info *variable_index_iterator_current(const struct variable_index_iterator *iter)
{
struct variable_info *current = NULL;
if (!variable_index_iterator_is_done(iter)) {
-
current = &iter->variable_index->entries[iter->current_pos].info;
}
return current;
}
-void variable_index_iterator_next(
- struct variable_index_iterator *iter)
+void variable_index_iterator_next(struct variable_index_iterator *iter)
{
if (iter->current_pos < iter->variable_index->max_variables) {
size_t next_pos = iter->current_pos + 1;
diff --git a/components/service/uefi/smm_variable/backend/variable_index_iterator.h b/components/service/uefi/smm_variable/backend/variable_index_iterator.h
index 7ff77c5..0e5df6f 100644
--- a/components/service/uefi/smm_variable/backend/variable_index_iterator.h
+++ b/components/service/uefi/smm_variable/backend/variable_index_iterator.h
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2021, Arm Limited. All rights reserved.
+ * Copyright (c) 2021-2023, Arm Limited. All rights reserved.
*
* SPDX-License-Identifier: BSD-3-Clause
*
@@ -9,6 +9,7 @@
#define VARIABLE_INDEX_ITERATOR_H
#include <stdbool.h>
+
#include "variable_index.h"
#ifdef __cplusplus
@@ -21,8 +22,7 @@
* Used for iterating over in-use entries held by the associated
* variable_index.
*/
-struct variable_index_iterator
-{
+struct variable_index_iterator {
const struct variable_index *variable_index;
size_t current_pos;
};
@@ -33,9 +33,8 @@
* @param[in] iter The iterator
* @param[in] variable_index The associated variable index
*/
-void variable_index_iterator_first(
- struct variable_index_iterator *iter,
- const struct variable_index *variable_index);
+void variable_index_iterator_first(struct variable_index_iterator *iter,
+ const struct variable_index *variable_index);
/**
* @brief Check if iterated beyond last entry
@@ -44,8 +43,7 @@
*
* @return True if iterating is done
*/
-bool variable_index_iterator_is_done(
- const struct variable_index_iterator *iter);
+bool variable_index_iterator_is_done(const struct variable_index_iterator *iter);
/**
* @brief Return variable info for the current position
@@ -54,17 +52,14 @@
*
* @return Pointer to variable_info or NULL
*/
-struct variable_info *variable_index_iterator_current(
- const struct variable_index_iterator *iter);
+struct variable_info *variable_index_iterator_current(const struct variable_index_iterator *iter);
/**
* @brief Iterate to next position
*
* @param[in] iter The iterator
*/
-void variable_index_iterator_next(
- struct variable_index_iterator *iter);
-
+void variable_index_iterator_next(struct variable_index_iterator *iter);
#ifdef __cplusplus
}
diff --git a/components/service/uefi/smm_variable/client/cpp/smm_variable_client.cpp b/components/service/uefi/smm_variable/client/cpp/smm_variable_client.cpp
index 704ddd0..30ca240 100644
--- a/components/service/uefi/smm_variable/client/cpp/smm_variable_client.cpp
+++ b/components/service/uefi/smm_variable/client/cpp/smm_variable_client.cpp
@@ -1,30 +1,28 @@
/*
- * Copyright (c) 2021-2022, Arm Limited and Contributors. All rights reserved.
+ * Copyright (c) 2021-2023, Arm Limited and Contributors. All rights reserved.
*
* SPDX-License-Identifier: BSD-3-Clause
*/
-#include <cstring>
-#include <protocols/rpc/common/packed-c/status.h>
#include "smm_variable_client.h"
-smm_variable_client::smm_variable_client() :
- session(NULL),
- m_err_rpc_status(RPC_SUCCESS)
-{
+#include <cstring>
+#include <protocols/rpc/common/packed-c/status.h>
+smm_variable_client::smm_variable_client()
+ : session(NULL)
+ , m_err_rpc_status(RPC_SUCCESS)
+{
}
-smm_variable_client::smm_variable_client(struct rpc_caller_session *session) :
- session(session),
- m_err_rpc_status(RPC_SUCCESS)
+smm_variable_client::smm_variable_client(struct rpc_caller_session *session)
+ : session(session)
+ , m_err_rpc_status(RPC_SUCCESS)
{
-
}
smm_variable_client::~smm_variable_client()
{
-
}
void smm_variable_client::set_caller_session(struct rpc_caller_session *session)
@@ -37,27 +35,15 @@
return m_err_rpc_status;
}
-efi_status_t smm_variable_client::set_variable(
- const EFI_GUID &guid,
- const std::wstring &name,
- const std::string &data,
- uint32_t attributes)
+efi_status_t smm_variable_client::set_variable(const EFI_GUID &guid, const std::wstring &name,
+ const std::string &data, uint32_t attributes)
{
- return set_variable(
- guid,
- name,
- data,
- attributes,
- 0, 0);
+ return set_variable(guid, name, data, attributes, 0, 0);
}
-efi_status_t smm_variable_client::set_variable(
- const EFI_GUID &guid,
- const std::wstring &name,
- const std::string &data,
- uint32_t attributes,
- size_t override_name_size,
- size_t override_data_size)
+efi_status_t smm_variable_client::set_variable(const EFI_GUID &guid, const std::wstring &name,
+ const std::string &data, uint32_t attributes,
+ size_t override_name_size, size_t override_data_size)
{
efi_status_t efi_status = EFI_NOT_READY;
@@ -72,13 +58,12 @@
call_handle = rpc_caller_session_begin(session, &req_buf, req_len, 0);
if (call_handle) {
-
uint8_t *resp_buf;
size_t resp_len;
service_status_t service_status;
SMM_VARIABLE_COMMUNICATE_ACCESS_VARIABLE *access_var =
- (SMM_VARIABLE_COMMUNICATE_ACCESS_VARIABLE*)req_buf;
+ (SMM_VARIABLE_COMMUNICATE_ACCESS_VARIABLE *)req_buf;
access_var->Guid = guid;
access_var->NameSize = name_size;
@@ -87,21 +72,21 @@
memcpy(access_var->Name, var_name.data(), name_size);
memcpy(&req_buf[SMM_VARIABLE_COMMUNICATE_ACCESS_VARIABLE_DATA_OFFSET(access_var)],
- data.data(), data_size);
+ data.data(), data_size);
/* To support invalid size testing, use overrides if set */
- if (override_name_size) access_var->NameSize = override_name_size;
- if (override_data_size) access_var->DataSize = override_data_size;
+ if (override_name_size)
+ access_var->NameSize = override_name_size;
+ if (override_data_size)
+ access_var->DataSize = override_data_size;
m_err_rpc_status = rpc_caller_session_invoke(call_handle,
- SMM_VARIABLE_FUNCTION_SET_VARIABLE, &resp_buf, &resp_len, &service_status);
+ SMM_VARIABLE_FUNCTION_SET_VARIABLE,
+ &resp_buf, &resp_len, &service_status);
if (m_err_rpc_status == RPC_SUCCESS) {
-
efi_status = service_status;
- }
- else {
-
+ } else {
efi_status = rpc_to_efi_status();
}
@@ -111,25 +96,15 @@
return efi_status;
}
-efi_status_t smm_variable_client::get_variable(
- const EFI_GUID &guid,
- const std::wstring &name,
- std::string &data)
+efi_status_t smm_variable_client::get_variable(const EFI_GUID &guid, const std::wstring &name,
+ std::string &data)
{
- return get_variable(
- guid,
- name,
- data,
- 0,
- MAX_VAR_DATA_SIZE);
+ return get_variable(guid, name, data, 0, MAX_VAR_DATA_SIZE);
}
-efi_status_t smm_variable_client::get_variable(
- const EFI_GUID &guid,
- const std::wstring &name,
- std::string &data,
- size_t override_name_size,
- size_t max_data_size)
+efi_status_t smm_variable_client::get_variable(const EFI_GUID &guid, const std::wstring &name,
+ std::string &data, size_t override_name_size,
+ size_t max_data_size)
{
efi_status_t efi_status = EFI_NOT_READY;
@@ -144,13 +119,12 @@
call_handle = rpc_caller_session_begin(session, &req_buf, req_len, resp_len);
if (call_handle) {
-
uint8_t *resp_buf;
size_t resp_len;
service_status_t service_status;
SMM_VARIABLE_COMMUNICATE_ACCESS_VARIABLE *access_var =
- (SMM_VARIABLE_COMMUNICATE_ACCESS_VARIABLE*)req_buf;
+ (SMM_VARIABLE_COMMUNICATE_ACCESS_VARIABLE *)req_buf;
access_var->Guid = guid;
access_var->NameSize = name_size;
@@ -159,41 +133,35 @@
memcpy(access_var->Name, var_name.data(), name_size);
/* To support invalid size testing, use overrides if set */
- if (override_name_size) access_var->NameSize = override_name_size;
+ if (override_name_size)
+ access_var->NameSize = override_name_size;
m_err_rpc_status = rpc_caller_session_invoke(call_handle,
- SMM_VARIABLE_FUNCTION_GET_VARIABLE, &resp_buf, &resp_len, &service_status);
+ SMM_VARIABLE_FUNCTION_GET_VARIABLE,
+ &resp_buf, &resp_len, &service_status);
if (m_err_rpc_status == RPC_SUCCESS) {
-
efi_status = service_status;
if (resp_len >= SMM_VARIABLE_COMMUNICATE_ACCESS_VARIABLE_NAME_OFFSET) {
-
- access_var = (SMM_VARIABLE_COMMUNICATE_ACCESS_VARIABLE*)resp_buf;
+ access_var = (SMM_VARIABLE_COMMUNICATE_ACCESS_VARIABLE *)resp_buf;
size_t data_size = access_var->DataSize;
- if (resp_len >=
- SMM_VARIABLE_COMMUNICATE_ACCESS_VARIABLE_TOTAL_SIZE(access_var)) {
-
+ if (resp_len >= SMM_VARIABLE_COMMUNICATE_ACCESS_VARIABLE_TOTAL_SIZE(
+ access_var)) {
if (efi_status == EFI_SUCCESS) {
-
- const char *data_start = (const char*)
- &resp_buf[
- SMM_VARIABLE_COMMUNICATE_ACCESS_VARIABLE_DATA_OFFSET(access_var)];
+ const char *data_start = (const char *)&resp_buf
+ [SMM_VARIABLE_COMMUNICATE_ACCESS_VARIABLE_DATA_OFFSET(
+ access_var)];
data.assign(data_start, data_size);
}
- }
- else if (efi_status == EFI_BUFFER_TOO_SMALL) {
-
+ } else if (efi_status == EFI_BUFFER_TOO_SMALL) {
data.clear();
data.insert(0, data_size, '!');
}
}
- }
- else {
-
+ } else {
efi_status = rpc_to_efi_status();
}
@@ -203,29 +171,21 @@
return efi_status;
}
-efi_status_t smm_variable_client::remove_variable(
- const EFI_GUID &guid,
- const std::wstring &name)
+efi_status_t smm_variable_client::remove_variable(const EFI_GUID &guid, const std::wstring &name)
{
/* Variable is removed by performing a 'set' with zero length data */
return set_variable(guid, name, std::string(), 0);
}
-efi_status_t smm_variable_client::get_next_variable_name(
- EFI_GUID &guid,
- std::wstring &name)
+efi_status_t smm_variable_client::get_next_variable_name(EFI_GUID &guid, std::wstring &name)
{
- return get_next_variable_name(
- guid,
- name,
- 0);
+ return get_next_variable_name(guid, name, 0);
}
-efi_status_t smm_variable_client::query_variable_info(
- uint32_t attributes,
- size_t *max_variable_storage_size,
- size_t *remaining_variable_storage_size,
- size_t *max_variable_size)
+efi_status_t smm_variable_client::query_variable_info(uint32_t attributes,
+ size_t *max_variable_storage_size,
+ size_t *remaining_variable_storage_size,
+ size_t *max_variable_size)
{
efi_status_t efi_status = EFI_NOT_READY;
@@ -237,49 +197,43 @@
call_handle = rpc_caller_session_begin(session, &req_buf, req_len, resp_len);
if (call_handle) {
-
uint8_t *resp_buf;
size_t resp_len;
service_status_t service_status;
SMM_VARIABLE_COMMUNICATE_QUERY_VARIABLE_INFO *query =
- (SMM_VARIABLE_COMMUNICATE_QUERY_VARIABLE_INFO*)req_buf;
+ (SMM_VARIABLE_COMMUNICATE_QUERY_VARIABLE_INFO *)req_buf;
query->Attributes = attributes;
query->MaximumVariableSize = 0;
query->MaximumVariableStorageSize = 0;
query->RemainingVariableStorageSize = 0;
- m_err_rpc_status = rpc_caller_session_invoke(call_handle,
- SMM_VARIABLE_FUNCTION_QUERY_VARIABLE_INFO, &resp_buf, &resp_len,
- &service_status);
+ m_err_rpc_status = rpc_caller_session_invoke(
+ call_handle, SMM_VARIABLE_FUNCTION_QUERY_VARIABLE_INFO, &resp_buf,
+ &resp_len, &service_status);
if (m_err_rpc_status == RPC_SUCCESS) {
-
efi_status = service_status;
if (efi_status == EFI_SUCCESS) {
+ if (resp_len >=
+ sizeof(SMM_VARIABLE_COMMUNICATE_QUERY_VARIABLE_INFO)) {
+ query = (SMM_VARIABLE_COMMUNICATE_QUERY_VARIABLE_INFO *)
+ resp_buf;
- if (resp_len >= sizeof(SMM_VARIABLE_COMMUNICATE_QUERY_VARIABLE_INFO)) {
-
- query = (SMM_VARIABLE_COMMUNICATE_QUERY_VARIABLE_INFO*)resp_buf;
-
- *max_variable_storage_size = query->MaximumVariableStorageSize;
- *remaining_variable_storage_size = query->RemainingVariableStorageSize;
+ *max_variable_storage_size =
+ query->MaximumVariableStorageSize;
+ *remaining_variable_storage_size =
+ query->RemainingVariableStorageSize;
*max_variable_size = query->MaximumVariableSize;
- }
- else {
-
+ } else {
efi_status = EFI_PROTOCOL_ERROR;
}
- }
- else {
-
+ } else {
efi_status = EFI_PROTOCOL_ERROR;
}
- }
- else {
-
+ } else {
efi_status = rpc_to_efi_status();
}
@@ -289,10 +243,8 @@
return efi_status;
}
-efi_status_t smm_variable_client::get_next_variable_name(
- EFI_GUID &guid,
- std::wstring &name,
- size_t override_name_size)
+efi_status_t smm_variable_client::get_next_variable_name(EFI_GUID &guid, std::wstring &name,
+ size_t override_name_size)
{
efi_status_t efi_status = EFI_NOT_READY;
@@ -307,13 +259,12 @@
call_handle = rpc_caller_session_begin(session, &req_buf, req_len, resp_len);
if (call_handle) {
-
uint8_t *resp_buf;
size_t resp_len;
service_status_t service_status;
SMM_VARIABLE_COMMUNICATE_GET_NEXT_VARIABLE_NAME *next_var =
- (SMM_VARIABLE_COMMUNICATE_GET_NEXT_VARIABLE_NAME*)req_buf;
+ (SMM_VARIABLE_COMMUNICATE_GET_NEXT_VARIABLE_NAME *)req_buf;
next_var->Guid = guid;
next_var->NameSize = name_size;
@@ -321,37 +272,37 @@
memcpy(next_var->Name, var_name.data(), name_size);
/* To support invalid size testing, use overrides if set */
- if (override_name_size) next_var->NameSize = override_name_size;
+ if (override_name_size)
+ next_var->NameSize = override_name_size;
- m_err_rpc_status = rpc_caller_session_invoke(call_handle,
- SMM_VARIABLE_FUNCTION_GET_NEXT_VARIABLE_NAME, &resp_buf, &resp_len,
- &service_status);
+ m_err_rpc_status = rpc_caller_session_invoke(
+ call_handle, SMM_VARIABLE_FUNCTION_GET_NEXT_VARIABLE_NAME, &resp_buf,
+ &resp_len, &service_status);
if (m_err_rpc_status == RPC_SUCCESS) {
-
efi_status = service_status;
if (efi_status == EFI_SUCCESS) {
-
efi_status = EFI_PROTOCOL_ERROR;
- if (resp_len >= SMM_VARIABLE_COMMUNICATE_GET_NEXT_VARIABLE_NAME_NAME_OFFSET) {
-
- next_var = (SMM_VARIABLE_COMMUNICATE_GET_NEXT_VARIABLE_NAME*)resp_buf;
+ if (resp_len >=
+ SMM_VARIABLE_COMMUNICATE_GET_NEXT_VARIABLE_NAME_NAME_OFFSET) {
+ next_var =
+ (SMM_VARIABLE_COMMUNICATE_GET_NEXT_VARIABLE_NAME *)
+ resp_buf;
if (resp_len >=
- SMM_VARIABLE_COMMUNICATE_GET_NEXT_VARIABLE_NAME_TOTAL_SIZE(next_var)) {
-
+ SMM_VARIABLE_COMMUNICATE_GET_NEXT_VARIABLE_NAME_TOTAL_SIZE(
+ next_var)) {
guid = next_var->Guid;
- name = from_variable_name(next_var->Name, next_var->NameSize);
+ name = from_variable_name(next_var->Name,
+ next_var->NameSize);
efi_status = EFI_SUCCESS;
}
}
}
- }
- else {
-
+ } else {
efi_status = rpc_to_efi_status();
}
@@ -371,21 +322,17 @@
call_handle = rpc_caller_session_begin(session, &req_buf, 0, 0);
if (call_handle) {
-
uint8_t *resp_buf;
size_t resp_len;
service_status_t service_status;
- m_err_rpc_status = rpc_caller_session_invoke(call_handle,
- SMM_VARIABLE_FUNCTION_EXIT_BOOT_SERVICE, &resp_buf, &resp_len,
+ m_err_rpc_status = rpc_caller_session_invoke(
+ call_handle, SMM_VARIABLE_FUNCTION_EXIT_BOOT_SERVICE, &resp_buf, &resp_len,
&service_status);
if (m_err_rpc_status == RPC_SUCCESS) {
-
efi_status = service_status;
- }
- else {
-
+ } else {
efi_status = rpc_to_efi_status();
}
@@ -395,23 +342,17 @@
return efi_status;
}
-efi_status_t smm_variable_client::set_var_check_property(
- const EFI_GUID &guid,
- const std::wstring &name,
- const VAR_CHECK_VARIABLE_PROPERTY &check_property)
+efi_status_t
+smm_variable_client::set_var_check_property(const EFI_GUID &guid, const std::wstring &name,
+ const VAR_CHECK_VARIABLE_PROPERTY &check_property)
{
- return set_var_check_property(
- guid,
- name,
- check_property,
- 0);
+ return set_var_check_property(guid, name, check_property, 0);
}
-efi_status_t smm_variable_client::set_var_check_property(
- const EFI_GUID &guid,
- const std::wstring &name,
- const VAR_CHECK_VARIABLE_PROPERTY &check_property,
- size_t override_name_size)
+efi_status_t
+smm_variable_client::set_var_check_property(const EFI_GUID &guid, const std::wstring &name,
+ const VAR_CHECK_VARIABLE_PROPERTY &check_property,
+ size_t override_name_size)
{
efi_status_t efi_status = EFI_NOT_READY;
@@ -426,13 +367,12 @@
call_handle = rpc_caller_session_begin(session, &req_buf, req_len, resp_len);
if (call_handle) {
-
uint8_t *resp_buf;
size_t resp_len;
service_status_t service_status;
SMM_VARIABLE_COMMUNICATE_VAR_CHECK_VARIABLE_PROPERTY *req_msg =
- (SMM_VARIABLE_COMMUNICATE_VAR_CHECK_VARIABLE_PROPERTY*)req_buf;
+ (SMM_VARIABLE_COMMUNICATE_VAR_CHECK_VARIABLE_PROPERTY *)req_buf;
req_msg->Guid = guid;
req_msg->NameSize = name_size;
@@ -441,18 +381,16 @@
memcpy(req_msg->Name, var_name.data(), name_size);
/* To support invalid size testing, use override if set */
- if (override_name_size) req_msg->NameSize = override_name_size;
+ if (override_name_size)
+ req_msg->NameSize = override_name_size;
- m_err_rpc_status = rpc_caller_session_invoke(call_handle,
- SMM_VARIABLE_FUNCTION_VAR_CHECK_VARIABLE_PROPERTY_SET, &resp_buf, &resp_len,
- &service_status);
+ m_err_rpc_status = rpc_caller_session_invoke(
+ call_handle, SMM_VARIABLE_FUNCTION_VAR_CHECK_VARIABLE_PROPERTY_SET,
+ &resp_buf, &resp_len, &service_status);
if (m_err_rpc_status == RPC_SUCCESS) {
-
efi_status = service_status;
- }
- else {
-
+ } else {
efi_status = rpc_to_efi_status();
}
@@ -462,23 +400,17 @@
return efi_status;
}
-efi_status_t smm_variable_client::get_var_check_property(
- const EFI_GUID &guid,
- const std::wstring &name,
- VAR_CHECK_VARIABLE_PROPERTY &check_property)
+efi_status_t
+smm_variable_client::get_var_check_property(const EFI_GUID &guid, const std::wstring &name,
+ VAR_CHECK_VARIABLE_PROPERTY &check_property)
{
- return get_var_check_property(
- guid,
- name,
- check_property,
- 0);
+ return get_var_check_property(guid, name, check_property, 0);
}
-efi_status_t smm_variable_client::get_var_check_property(
- const EFI_GUID &guid,
- const std::wstring &name,
- VAR_CHECK_VARIABLE_PROPERTY &check_property,
- size_t override_name_size)
+efi_status_t
+smm_variable_client::get_var_check_property(const EFI_GUID &guid, const std::wstring &name,
+ VAR_CHECK_VARIABLE_PROPERTY &check_property,
+ size_t override_name_size)
{
efi_status_t efi_status = EFI_NOT_READY;
@@ -493,13 +425,12 @@
call_handle = rpc_caller_session_begin(session, &req_buf, req_len, resp_len);
if (call_handle) {
-
uint8_t *resp_buf;
- size_t resp_len;
+ size_t resp_len;
service_status_t service_status;
SMM_VARIABLE_COMMUNICATE_VAR_CHECK_VARIABLE_PROPERTY *req_msg =
- (SMM_VARIABLE_COMMUNICATE_VAR_CHECK_VARIABLE_PROPERTY*)req_buf;
+ (SMM_VARIABLE_COMMUNICATE_VAR_CHECK_VARIABLE_PROPERTY *)req_buf;
req_msg->Guid = guid;
req_msg->NameSize = name_size;
@@ -507,36 +438,34 @@
memcpy(req_msg->Name, var_name.data(), name_size);
/* To support invalid size testing, use overrides if set */
- if (override_name_size) req_msg->NameSize = override_name_size;
+ if (override_name_size)
+ req_msg->NameSize = override_name_size;
- m_err_rpc_status = rpc_caller_session_invoke(call_handle,
- SMM_VARIABLE_FUNCTION_VAR_CHECK_VARIABLE_PROPERTY_GET, &resp_buf, &resp_len,
- &service_status);
+ m_err_rpc_status = rpc_caller_session_invoke(
+ call_handle, SMM_VARIABLE_FUNCTION_VAR_CHECK_VARIABLE_PROPERTY_GET,
+ &resp_buf, &resp_len, &service_status);
if (m_err_rpc_status == RPC_SUCCESS) {
-
efi_status = service_status;
if (efi_status == EFI_SUCCESS) {
-
efi_status = EFI_PROTOCOL_ERROR;
- if (resp_len >= SMM_VARIABLE_COMMUNICATE_VAR_CHECK_VARIABLE_PROPERTY_NAME_OFFSET) {
-
+ if (resp_len >=
+ SMM_VARIABLE_COMMUNICATE_VAR_CHECK_VARIABLE_PROPERTY_NAME_OFFSET) {
SMM_VARIABLE_COMMUNICATE_VAR_CHECK_VARIABLE_PROPERTY *resp_msg =
- (SMM_VARIABLE_COMMUNICATE_VAR_CHECK_VARIABLE_PROPERTY*)resp_buf;
+ (SMM_VARIABLE_COMMUNICATE_VAR_CHECK_VARIABLE_PROPERTY
+ *)resp_buf;
if (resp_len >=
- SMM_VARIABLE_COMMUNICATE_VAR_CHECK_VARIABLE_PROPERTY_TOTAL_SIZE(resp_msg)) {
-
+ SMM_VARIABLE_COMMUNICATE_VAR_CHECK_VARIABLE_PROPERTY_TOTAL_SIZE(
+ resp_msg)) {
check_property = resp_msg->VariableProperty;
efi_status = EFI_SUCCESS;
}
}
}
- }
- else {
-
+ } else {
efi_status = rpc_to_efi_status();
}
@@ -546,8 +475,7 @@
return efi_status;
}
-efi_status_t smm_variable_client::get_payload_size(
- size_t &payload_size)
+efi_status_t smm_variable_client::get_payload_size(size_t &payload_size)
{
efi_status_t efi_status = EFI_NOT_READY;
@@ -559,36 +487,29 @@
call_handle = rpc_caller_session_begin(session, &req_buf, req_len, resp_len);
if (call_handle) {
-
uint8_t *resp_buf;
size_t resp_len;
service_status_t service_status;
m_err_rpc_status = rpc_caller_session_invoke(call_handle,
- SMM_VARIABLE_FUNCTION_GET_PAYLOAD_SIZE, &resp_buf, &resp_len,
- &service_status);
+ SMM_VARIABLE_FUNCTION_GET_PAYLOAD_SIZE,
+ &resp_buf, &resp_len, &service_status);
if (m_err_rpc_status == RPC_SUCCESS) {
-
efi_status = service_status;
if (efi_status == EFI_SUCCESS) {
-
if (resp_len >= sizeof(SMM_VARIABLE_COMMUNICATE_GET_PAYLOAD_SIZE)) {
-
SMM_VARIABLE_COMMUNICATE_GET_PAYLOAD_SIZE *resp_msg =
- (SMM_VARIABLE_COMMUNICATE_GET_PAYLOAD_SIZE*)resp_buf;
+ (SMM_VARIABLE_COMMUNICATE_GET_PAYLOAD_SIZE *)
+ resp_buf;
payload_size = resp_msg->VariablePayloadSize;
- }
- else {
-
+ } else {
efi_status = EFI_PROTOCOL_ERROR;
}
}
- }
- else {
-
+ } else {
efi_status = rpc_to_efi_status();
}
@@ -602,46 +523,43 @@
{
efi_status_t efi_status = EFI_INVALID_PARAMETER;
- switch (m_err_rpc_status)
- {
- case RPC_ERROR_INTERNAL:
- efi_status = EFI_DEVICE_ERROR;
- break;
- case RPC_ERROR_INVALID_VALUE:
- efi_status = EFI_INVALID_PARAMETER;
- break;
- case RPC_ERROR_NOT_FOUND:
- efi_status = EFI_UNSUPPORTED;
- break;
- case RPC_ERROR_INVALID_STATE:
- efi_status = EFI_NOT_READY;
- break;
- case RPC_ERROR_TRANSPORT_LAYER:
- efi_status = EFI_PROTOCOL_ERROR;
- break;
- case RPC_ERROR_INVALID_REQUEST_BODY:
- efi_status = EFI_PROTOCOL_ERROR;
- break;
- case RPC_ERROR_INVALID_RESPONSE_BODY:
- efi_status = EFI_DEVICE_ERROR;
- break;
- case RPC_ERROR_RESOURCE_FAILURE:
- efi_status = EFI_OUT_OF_RESOURCES;
- break;
- default:
- break;
+ switch (m_err_rpc_status) {
+ case RPC_ERROR_INTERNAL:
+ efi_status = EFI_DEVICE_ERROR;
+ break;
+ case RPC_ERROR_INVALID_VALUE:
+ efi_status = EFI_INVALID_PARAMETER;
+ break;
+ case RPC_ERROR_NOT_FOUND:
+ efi_status = EFI_UNSUPPORTED;
+ break;
+ case RPC_ERROR_INVALID_STATE:
+ efi_status = EFI_NOT_READY;
+ break;
+ case RPC_ERROR_TRANSPORT_LAYER:
+ efi_status = EFI_PROTOCOL_ERROR;
+ break;
+ case RPC_ERROR_INVALID_REQUEST_BODY:
+ efi_status = EFI_PROTOCOL_ERROR;
+ break;
+ case RPC_ERROR_INVALID_RESPONSE_BODY:
+ efi_status = EFI_DEVICE_ERROR;
+ break;
+ case RPC_ERROR_RESOURCE_FAILURE:
+ efi_status = EFI_OUT_OF_RESOURCES;
+ break;
+ default:
+ break;
}
return efi_status;
}
-std::vector<int16_t> smm_variable_client::to_variable_name(
- const std::wstring &string)
+std::vector<int16_t> smm_variable_client::to_variable_name(const std::wstring &string)
{
std::vector<int16_t> var_name;
for (size_t i = 0; i < string.size(); i++) {
-
var_name.push_back((int16_t)string[i]);
}
@@ -650,16 +568,15 @@
return var_name;
}
-const std::wstring smm_variable_client::from_variable_name(
- const int16_t *var_name,
- size_t name_size)
+const std::wstring smm_variable_client::from_variable_name(const int16_t *var_name,
+ size_t name_size)
{
std::wstring name;
size_t num_chars = name_size / sizeof(int16_t);
for (size_t i = 0; i < num_chars; i++) {
-
- if (!var_name[i]) break; /* Reached null terminator */
+ if (!var_name[i])
+ break; /* Reached null terminator */
name.push_back((wchar_t)var_name[i]);
}
diff --git a/components/service/uefi/smm_variable/client/cpp/smm_variable_client.h b/components/service/uefi/smm_variable/client/cpp/smm_variable_client.h
index 10992ad..891a61a 100644
--- a/components/service/uefi/smm_variable/client/cpp/smm_variable_client.h
+++ b/components/service/uefi/smm_variable/client/cpp/smm_variable_client.h
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2021-2022, Arm Limited and Contributors. All rights reserved.
+ * Copyright (c) 2021-2023, Arm Limited and Contributors. All rights reserved.
*
* SPDX-License-Identifier: BSD-3-Clause
*/
@@ -8,22 +8,20 @@
#define SMM_VARIABLE_CLIENT_H
#include <cstdint>
-#include <string>
-#include <vector>
#include <protocols/common/efi/efi_status.h>
#include <protocols/service/smm_variable/smm_variable_proto.h>
-#include "components/rpc/common/caller/rpc_caller_session.h"
+#include <string>
+#include <vector>
+#include "components/rpc/common/caller/rpc_caller_session.h"
/*
* Provides a C++ client interface for accessing an instance of the smm-variable service.
* This client is intented for testing the UEFI variable store provided by the smm-variable
* service.
*/
-class smm_variable_client
-{
+class smm_variable_client {
public:
-
smm_variable_client();
smm_variable_client(struct rpc_caller_session *session);
~smm_variable_client();
@@ -32,89 +30,58 @@
int err_rpc_status() const;
/* Set a string type variable */
- efi_status_t set_variable(
- const EFI_GUID &guid,
- const std::wstring &name,
- const std::string &data,
- uint32_t attributes);
+ efi_status_t set_variable(const EFI_GUID &guid, const std::wstring &name,
+ const std::string &data, uint32_t attributes);
- efi_status_t set_variable(
- const EFI_GUID &guid,
- const std::wstring &name,
- const std::string &data,
- uint32_t attributes,
- size_t override_name_size,
- size_t override_data_size);
+ efi_status_t set_variable(const EFI_GUID &guid, const std::wstring &name,
+ const std::string &data, uint32_t attributes,
+ size_t override_name_size, size_t override_data_size);
/* Get a string type variable */
- efi_status_t get_variable(
- const EFI_GUID &guid,
- const std::wstring &name,
- std::string &data);
+ efi_status_t get_variable(const EFI_GUID &guid, const std::wstring &name,
+ std::string &data);
- efi_status_t get_variable(
- const EFI_GUID &guid,
- const std::wstring &name,
- std::string &data,
- size_t override_name_size,
- size_t max_data_size = MAX_VAR_DATA_SIZE);
+ efi_status_t get_variable(const EFI_GUID &guid, const std::wstring &name, std::string &data,
+ size_t override_name_size,
+ size_t max_data_size = MAX_VAR_DATA_SIZE);
/* Remove a variable */
- efi_status_t remove_variable(
- const EFI_GUID &guid,
- const std::wstring &name);
+ efi_status_t remove_variable(const EFI_GUID &guid, const std::wstring &name);
/* Query variable info */
- efi_status_t query_variable_info(
- uint32_t attributes,
- size_t *max_variable_storage_size,
- size_t *remaining_variable_storage_size,
- size_t *max_variable_size);
+ efi_status_t query_variable_info(uint32_t attributes, size_t *max_variable_storage_size,
+ size_t *remaining_variable_storage_size,
+ size_t *max_variable_size);
/* Get the next variable name - for enumerating store contents */
- efi_status_t get_next_variable_name(
- EFI_GUID &guid,
- std::wstring &name);
+ efi_status_t get_next_variable_name(EFI_GUID &guid, std::wstring &name);
- efi_status_t get_next_variable_name(
- EFI_GUID &guid,
- std::wstring &name,
- size_t override_name_size);
+ efi_status_t get_next_variable_name(EFI_GUID &guid, std::wstring &name,
+ size_t override_name_size);
/* Exit boot service */
efi_status_t exit_boot_service();
/* Set variable check properties */
- efi_status_t set_var_check_property(
- const EFI_GUID &guid,
- const std::wstring &name,
- const VAR_CHECK_VARIABLE_PROPERTY &check_property);
+ efi_status_t set_var_check_property(const EFI_GUID &guid, const std::wstring &name,
+ const VAR_CHECK_VARIABLE_PROPERTY &check_property);
- efi_status_t set_var_check_property(
- const EFI_GUID &guid,
- const std::wstring &name,
- const VAR_CHECK_VARIABLE_PROPERTY &check_property,
- size_t override_name_size);
+ efi_status_t set_var_check_property(const EFI_GUID &guid, const std::wstring &name,
+ const VAR_CHECK_VARIABLE_PROPERTY &check_property,
+ size_t override_name_size);
/* Get variable check properties */
- efi_status_t get_var_check_property(
- const EFI_GUID &guid,
- const std::wstring &name,
- VAR_CHECK_VARIABLE_PROPERTY &check_property);
+ efi_status_t get_var_check_property(const EFI_GUID &guid, const std::wstring &name,
+ VAR_CHECK_VARIABLE_PROPERTY &check_property);
- efi_status_t get_var_check_property(
- const EFI_GUID &guid,
- const std::wstring &name,
- VAR_CHECK_VARIABLE_PROPERTY &check_property,
- size_t override_name_size);
+ efi_status_t get_var_check_property(const EFI_GUID &guid, const std::wstring &name,
+ VAR_CHECK_VARIABLE_PROPERTY &check_property,
+ size_t override_name_size);
/* Get maximum variable payload size */
- efi_status_t get_payload_size(
- size_t &payload_size);
-
+ efi_status_t get_payload_size(size_t &payload_size);
private:
-
/* Datasize limit set by UEFI specification */
static const size_t MAX_VAR_DATA_SIZE = 65536;
diff --git a/components/service/uefi/smm_variable/frontend/mm_communicate/smm_variable_mm_service.c b/components/service/uefi/smm_variable/frontend/mm_communicate/smm_variable_mm_service.c
index 1fc6be6..b9010e2 100644
--- a/components/service/uefi/smm_variable/frontend/mm_communicate/smm_variable_mm_service.c
+++ b/components/service/uefi/smm_variable/frontend/mm_communicate/smm_variable_mm_service.c
@@ -1,12 +1,14 @@
// SPDX-License-Identifier: BSD-3-Clause
/*
- * Copyright (c) 2021, Arm Limited and Contributors. All rights reserved.
+ * Copyright (c) 2021-2023, Arm Limited and Contributors. All rights reserved.
*/
+#include "smm_variable_mm_service.h"
+
+#include <assert.h>
+
#include "protocols/common/mm/mm_smc.h"
#include "protocols/service/smm_variable/smm_variable_proto.h"
-#include "smm_variable_mm_service.h"
-#include <assert.h>
struct smm_variable_rpc_context {
struct rpc_interface *smm_variable_rpc_interface;
@@ -59,7 +61,8 @@
rpc_req.opcode = header->Function;
rpc_req.request.data = header->Data;
- rpc_req.request.data_length = mm_req->req_buf.data_length - SMM_VARIABLE_COMMUNICATE_HEADER_SIZE;
+ rpc_req.request.data_length =
+ mm_req->req_buf.data_length - SMM_VARIABLE_COMMUNICATE_HEADER_SIZE;
rpc_req.request.size = mm_req->req_buf.size - SMM_VARIABLE_COMMUNICATE_HEADER_SIZE;
rpc_req.response.data = header->Data;
@@ -81,7 +84,7 @@
}
struct mm_service_interface *smm_variable_mm_service_init(struct smm_variable_mm_service *service,
- struct rpc_service_interface *iface)
+ struct rpc_service_interface *iface)
{
assert(service != NULL);
assert(iface != NULL);
diff --git a/components/service/uefi/smm_variable/frontend/mm_communicate/test/test_smm_variable_mm_service.cpp b/components/service/uefi/smm_variable/frontend/mm_communicate/test/test_smm_variable_mm_service.cpp
index ca74884..b7114e1 100644
--- a/components/service/uefi/smm_variable/frontend/mm_communicate/test/test_smm_variable_mm_service.cpp
+++ b/components/service/uefi/smm_variable/frontend/mm_communicate/test/test_smm_variable_mm_service.cpp
@@ -1,17 +1,18 @@
// SPDX-License-Identifier: BSD-3-Clause
/*
- * Copyright (c) 2021, Arm Limited and Contributors. All rights reserved.
+ * Copyright (c) 2021-2023, Arm Limited and Contributors. All rights reserved.
*/
#include <CppUTest/TestHarness.h>
#include <CppUTestExt/MockSupport.h>
-#include <string.h>
#include <limits>
-#include "mock_assert.h"
+#include <string.h>
+
+#include "../smm_variable_mm_service.h"
#include "components/rpc/common/test/mock_rpc_interface.h"
+#include "mock_assert.h"
#include "protocols/common/mm/mm_smc.h"
#include "protocols/service/smm_variable/smm_variable_proto.h"
-#include "../smm_variable_mm_service.h"
TEST_GROUP(smm_variable_mm_service)
{
@@ -84,7 +85,7 @@
{
struct mm_service_interface *mm_service = NULL;
uint8_t buffer[128] = { 0 };
- SMM_VARIABLE_COMMUNICATE_HEADER *header = (SMM_VARIABLE_COMMUNICATE_HEADER *) buffer;
+ SMM_VARIABLE_COMMUNICATE_HEADER *header = (SMM_VARIABLE_COMMUNICATE_HEADER *)buffer;
int32_t result = 0;
mm_req.req_buf.size = sizeof(buffer);
@@ -116,7 +117,8 @@
LONGS_EQUAL(MM_RETURN_CODE_SUCCESS, result);
UNSIGNED_LONGLONGS_EQUAL(rpc_req.service_status, header->ReturnStatus);
- UNSIGNED_LONGLONGS_EQUAL(rpc_req.response.data_length + SMM_VARIABLE_COMMUNICATE_HEADER_SIZE,
+ UNSIGNED_LONGLONGS_EQUAL(rpc_req.response.data_length +
+ SMM_VARIABLE_COMMUNICATE_HEADER_SIZE,
mm_req.resp_buf.data_length);
}
@@ -124,7 +126,7 @@
{
struct mm_service_interface *mm_service = NULL;
uint8_t buffer[128] = { 0 };
- SMM_VARIABLE_COMMUNICATE_HEADER *header = (SMM_VARIABLE_COMMUNICATE_HEADER *) buffer;
+ SMM_VARIABLE_COMMUNICATE_HEADER *header = (SMM_VARIABLE_COMMUNICATE_HEADER *)buffer;
int32_t result = 0;
mm_req.req_buf.size = sizeof(buffer);
@@ -156,7 +158,8 @@
LONGS_EQUAL(MM_RETURN_CODE_SUCCESS, result);
UNSIGNED_LONGLONGS_EQUAL(rpc_req.service_status, header->ReturnStatus);
- UNSIGNED_LONGLONGS_EQUAL(rpc_req.response.data_length + SMM_VARIABLE_COMMUNICATE_HEADER_SIZE,
+ UNSIGNED_LONGLONGS_EQUAL(rpc_req.response.data_length +
+ SMM_VARIABLE_COMMUNICATE_HEADER_SIZE,
mm_req.resp_buf.data_length);
}
@@ -164,7 +167,7 @@
{
struct mm_service_interface *mm_service = NULL;
uint8_t buffer[128] = { 0 };
- SMM_VARIABLE_COMMUNICATE_HEADER *header = (SMM_VARIABLE_COMMUNICATE_HEADER *) buffer;
+ SMM_VARIABLE_COMMUNICATE_HEADER *header = (SMM_VARIABLE_COMMUNICATE_HEADER *)buffer;
int32_t result = 0;
mm_req.req_buf.size = sizeof(buffer);
@@ -184,7 +187,8 @@
rpc_req.request.data_length = 32;
rpc_req.request.data = buffer + SMM_VARIABLE_COMMUNICATE_HEADER_SIZE;
rpc_req.response.size = sizeof(buffer) - SMM_VARIABLE_COMMUNICATE_HEADER_SIZE;
- rpc_req.response.data_length = std::numeric_limits<size_t>::max() - SMM_VARIABLE_COMMUNICATE_HEADER_SIZE + 1;
+ rpc_req.response.data_length =
+ std::numeric_limits<size_t>::max() - SMM_VARIABLE_COMMUNICATE_HEADER_SIZE + 1;
rpc_req.response.data = buffer + SMM_VARIABLE_COMMUNICATE_HEADER_SIZE;
rpc_iface.receive = mock_rpc_interface_receive;
@@ -196,7 +200,8 @@
LONGS_EQUAL(MM_RETURN_CODE_NO_MEMORY, result);
UNSIGNED_LONGLONGS_EQUAL(rpc_req.service_status, header->ReturnStatus);
- UNSIGNED_LONGLONGS_EQUAL(rpc_req.response.data_length + SMM_VARIABLE_COMMUNICATE_HEADER_SIZE,
+ UNSIGNED_LONGLONGS_EQUAL(rpc_req.response.data_length +
+ SMM_VARIABLE_COMMUNICATE_HEADER_SIZE,
mm_req.resp_buf.data_length);
}
@@ -204,7 +209,7 @@
{
struct mm_service_interface *mm_service = NULL;
uint8_t buffer[128] = { 0 };
- SMM_VARIABLE_COMMUNICATE_HEADER *header = (SMM_VARIABLE_COMMUNICATE_HEADER *) buffer;
+ SMM_VARIABLE_COMMUNICATE_HEADER *header = (SMM_VARIABLE_COMMUNICATE_HEADER *)buffer;
int32_t result = 0;
mm_req.req_buf.size = sizeof(buffer);
@@ -236,7 +241,8 @@
LONGS_EQUAL(MM_RETURN_CODE_NO_MEMORY, result);
UNSIGNED_LONGLONGS_EQUAL(rpc_req.service_status, header->ReturnStatus);
- UNSIGNED_LONGLONGS_EQUAL(rpc_req.response.data_length + SMM_VARIABLE_COMMUNICATE_HEADER_SIZE,
+ UNSIGNED_LONGLONGS_EQUAL(rpc_req.response.data_length +
+ SMM_VARIABLE_COMMUNICATE_HEADER_SIZE,
mm_req.resp_buf.data_length);
}
@@ -244,22 +250,22 @@
{
struct mm_service_interface *mm_service = NULL;
uint8_t buffer[128] = { 0 };
- SMM_VARIABLE_COMMUNICATE_HEADER *header = (SMM_VARIABLE_COMMUNICATE_HEADER *) buffer;
+ SMM_VARIABLE_COMMUNICATE_HEADER *header = (SMM_VARIABLE_COMMUNICATE_HEADER *)buffer;
int32_t result = 0;
const struct {
rpc_status_t rpc_status;
int32_t mm_result;
} status_mapping[] = {
- {RPC_SUCCESS, MM_RETURN_CODE_SUCCESS},
- {RPC_ERROR_INTERNAL, MM_RETURN_CODE_INVALID_PARAMETER},
- {RPC_ERROR_INVALID_VALUE, MM_RETURN_CODE_INVALID_PARAMETER},
- {RPC_ERROR_NOT_FOUND, MM_RETURN_CODE_NOT_SUPPORTED},
- {RPC_ERROR_INVALID_STATE, MM_RETURN_CODE_INVALID_PARAMETER},
- {RPC_ERROR_TRANSPORT_LAYER, MM_RETURN_CODE_INVALID_PARAMETER},
- {RPC_ERROR_INVALID_REQUEST_BODY, MM_RETURN_CODE_INVALID_PARAMETER},
- {RPC_ERROR_INVALID_RESPONSE_BODY, MM_RETURN_CODE_INVALID_PARAMETER},
- {1, MM_RETURN_CODE_NOT_SUPPORTED}
+ { RPC_SUCCESS, MM_RETURN_CODE_SUCCESS },
+ { RPC_ERROR_INTERNAL, MM_RETURN_CODE_INVALID_PARAMETER },
+ { RPC_ERROR_INVALID_VALUE, MM_RETURN_CODE_INVALID_PARAMETER },
+ { RPC_ERROR_NOT_FOUND, MM_RETURN_CODE_NOT_SUPPORTED },
+ { RPC_ERROR_INVALID_STATE, MM_RETURN_CODE_INVALID_PARAMETER },
+ { RPC_ERROR_TRANSPORT_LAYER, MM_RETURN_CODE_INVALID_PARAMETER },
+ { RPC_ERROR_INVALID_REQUEST_BODY, MM_RETURN_CODE_INVALID_PARAMETER },
+ { RPC_ERROR_INVALID_RESPONSE_BODY, MM_RETURN_CODE_INVALID_PARAMETER },
+ { 1, MM_RETURN_CODE_NOT_SUPPORTED }
};
@@ -288,12 +294,14 @@
mm_service = smm_variable_mm_service_init(&service, &rpc_iface);
for (size_t i = 0; i < ARRAY_SIZE(status_mapping); i++) {
- expect_mock_rpc_interface_receive(&rpc_iface, &rpc_req, status_mapping[i].rpc_status);
+ expect_mock_rpc_interface_receive(&rpc_iface, &rpc_req,
+ status_mapping[i].rpc_status);
result = mm_service->receive(mm_service, &mm_req);
LONGS_EQUAL(status_mapping[i].mm_result, result);
UNSIGNED_LONGLONGS_EQUAL(rpc_req.service_status, header->ReturnStatus);
- UNSIGNED_LONGLONGS_EQUAL(rpc_req.response.data_length + SMM_VARIABLE_COMMUNICATE_HEADER_SIZE,
- mm_req.resp_buf.data_length);
+ UNSIGNED_LONGLONGS_EQUAL(rpc_req.response.data_length +
+ SMM_VARIABLE_COMMUNICATE_HEADER_SIZE,
+ mm_req.resp_buf.data_length);
}
}
diff --git a/components/service/uefi/smm_variable/provider/smm_variable_provider.c b/components/service/uefi/smm_variable/provider/smm_variable_provider.c
index f1c3c71..1875397 100644
--- a/components/service/uefi/smm_variable/provider/smm_variable_provider.c
+++ b/components/service/uefi/smm_variable/provider/smm_variable_provider.c
@@ -1,14 +1,15 @@
/*
- * Copyright (c) 2021-2022, Arm Limited and Contributors. All rights reserved.
+ * Copyright (c) 2021-2023, Arm Limited and Contributors. All rights reserved.
*
* SPDX-License-Identifier: BSD-3-Clause
*/
+#include "smm_variable_provider.h"
+
+#include <protocols/rpc/common/packed-c/status.h>
+#include <protocols/service/smm_variable/smm_variable_proto.h>
#include <stddef.h>
#include <string.h>
-#include <protocols/service/smm_variable/smm_variable_proto.h>
-#include <protocols/rpc/common/packed-c/status.h>
-#include "smm_variable_provider.h"
/* Service request handlers */
static rpc_status_t get_variable_handler(void *context, struct rpc_request *req);
@@ -22,38 +23,30 @@
/* Handler mapping table for service */
static const struct service_handler handler_table[] = {
- {SMM_VARIABLE_FUNCTION_GET_VARIABLE, get_variable_handler},
- {SMM_VARIABLE_FUNCTION_GET_NEXT_VARIABLE_NAME, get_next_variable_name_handler},
- {SMM_VARIABLE_FUNCTION_SET_VARIABLE, set_variable_handler},
- {SMM_VARIABLE_FUNCTION_QUERY_VARIABLE_INFO, query_variable_info_handler},
- {SMM_VARIABLE_FUNCTION_EXIT_BOOT_SERVICE, exit_boot_service_handler},
- {SMM_VARIABLE_FUNCTION_VAR_CHECK_VARIABLE_PROPERTY_SET, set_var_check_property_handler},
- {SMM_VARIABLE_FUNCTION_VAR_CHECK_VARIABLE_PROPERTY_GET, get_var_check_property_handler},
- {SMM_VARIABLE_FUNCTION_GET_PAYLOAD_SIZE, get_payload_size_handler}
+ { SMM_VARIABLE_FUNCTION_GET_VARIABLE, get_variable_handler },
+ { SMM_VARIABLE_FUNCTION_GET_NEXT_VARIABLE_NAME, get_next_variable_name_handler },
+ { SMM_VARIABLE_FUNCTION_SET_VARIABLE, set_variable_handler },
+ { SMM_VARIABLE_FUNCTION_QUERY_VARIABLE_INFO, query_variable_info_handler },
+ { SMM_VARIABLE_FUNCTION_EXIT_BOOT_SERVICE, exit_boot_service_handler },
+ { SMM_VARIABLE_FUNCTION_VAR_CHECK_VARIABLE_PROPERTY_SET, set_var_check_property_handler },
+ { SMM_VARIABLE_FUNCTION_VAR_CHECK_VARIABLE_PROPERTY_GET, get_var_check_property_handler },
+ { SMM_VARIABLE_FUNCTION_GET_PAYLOAD_SIZE, get_payload_size_handler }
};
-struct rpc_service_interface *smm_variable_provider_init(
- struct smm_variable_provider *context,
- uint32_t owner_id,
- size_t max_variables,
- struct storage_backend *persistent_store,
- struct storage_backend *volatile_store)
+struct rpc_service_interface *smm_variable_provider_init(struct smm_variable_provider *context,
+ uint32_t owner_id, size_t max_variables,
+ struct storage_backend *persistent_store,
+ struct storage_backend *volatile_store)
{
struct rpc_service_interface *rpc_interface = NULL;
- const struct rpc_uuid dummy_uuid = { .uuid = { 0 }};
+ const struct rpc_uuid dummy_uuid = { .uuid = { 0 } };
if (context) {
+ service_provider_init(&context->base_provider, context, &dummy_uuid, handler_table,
+ sizeof(handler_table) / sizeof(struct service_handler));
- service_provider_init(&context->base_provider, context, &dummy_uuid,
- handler_table, sizeof(handler_table)/sizeof(struct service_handler));
-
- if (uefi_variable_store_init(
- &context->variable_store,
- owner_id,
- max_variables,
- persistent_store,
- volatile_store) == EFI_SUCCESS) {
-
+ if (uefi_variable_store_init(&context->variable_store, owner_id, max_variables,
+ persistent_store, volatile_store) == EFI_SUCCESS) {
rpc_interface = service_provider_get_rpc_interface(&context->base_provider);
}
}
@@ -73,15 +66,13 @@
const struct rpc_buffer *req_buf = &req->request;
if (req_buf->data_length >= SMM_VARIABLE_COMMUNICATE_ACCESS_VARIABLE_NAME_OFFSET) {
-
const SMM_VARIABLE_COMMUNICATE_ACCESS_VARIABLE *param =
- (const SMM_VARIABLE_COMMUNICATE_ACCESS_VARIABLE*)req_buf->data;
+ (const SMM_VARIABLE_COMMUNICATE_ACCESS_VARIABLE *)req_buf->data;
- size_t max_space_for_name = req_buf->data_length -
- SMM_VARIABLE_COMMUNICATE_ACCESS_VARIABLE_NAME_OFFSET;
+ size_t max_space_for_name =
+ req_buf->data_length - SMM_VARIABLE_COMMUNICATE_ACCESS_VARIABLE_NAME_OFFSET;
if (param->NameSize <= max_space_for_name) {
-
*param_len = SMM_VARIABLE_COMMUNICATE_ACCESS_VARIABLE_DATA_OFFSET(param);
efi_status = EFI_SUCCESS;
}
@@ -97,16 +88,16 @@
const struct rpc_buffer *req_buf = &req->request;
if (req_buf->data_length >= SMM_VARIABLE_COMMUNICATE_GET_NEXT_VARIABLE_NAME_NAME_OFFSET) {
-
const SMM_VARIABLE_COMMUNICATE_GET_NEXT_VARIABLE_NAME *param =
- (const SMM_VARIABLE_COMMUNICATE_GET_NEXT_VARIABLE_NAME*)req_buf->data;
+ (const SMM_VARIABLE_COMMUNICATE_GET_NEXT_VARIABLE_NAME *)req_buf->data;
- size_t max_space_for_name = req_buf->data_length -
+ size_t max_space_for_name =
+ req_buf->data_length -
SMM_VARIABLE_COMMUNICATE_GET_NEXT_VARIABLE_NAME_NAME_OFFSET;
if (param->NameSize <= max_space_for_name) {
-
- *param_len = SMM_VARIABLE_COMMUNICATE_GET_NEXT_VARIABLE_NAME_TOTAL_SIZE(param);
+ *param_len =
+ SMM_VARIABLE_COMMUNICATE_GET_NEXT_VARIABLE_NAME_TOTAL_SIZE(param);
efi_status = EFI_SUCCESS;
}
}
@@ -120,17 +111,19 @@
*param_len = 0;
const struct rpc_buffer *req_buf = &req->request;
- if (req_buf->data_length >= SMM_VARIABLE_COMMUNICATE_VAR_CHECK_VARIABLE_PROPERTY_NAME_OFFSET) {
-
+ if (req_buf->data_length >=
+ SMM_VARIABLE_COMMUNICATE_VAR_CHECK_VARIABLE_PROPERTY_NAME_OFFSET) {
const SMM_VARIABLE_COMMUNICATE_VAR_CHECK_VARIABLE_PROPERTY *param =
- (const SMM_VARIABLE_COMMUNICATE_VAR_CHECK_VARIABLE_PROPERTY*)req_buf->data;
+ (const SMM_VARIABLE_COMMUNICATE_VAR_CHECK_VARIABLE_PROPERTY *)req_buf->data;
- size_t max_space_for_name = req_buf->data_length -
+ size_t max_space_for_name =
+ req_buf->data_length -
SMM_VARIABLE_COMMUNICATE_VAR_CHECK_VARIABLE_PROPERTY_NAME_OFFSET;
if (param->NameSize <= max_space_for_name) {
-
- *param_len = SMM_VARIABLE_COMMUNICATE_VAR_CHECK_VARIABLE_PROPERTY_TOTAL_SIZE(param);
+ *param_len =
+ SMM_VARIABLE_COMMUNICATE_VAR_CHECK_VARIABLE_PROPERTY_TOTAL_SIZE(
+ param);
efi_status = EFI_SUCCESS;
}
}
@@ -140,18 +133,16 @@
static rpc_status_t get_variable_handler(void *context, struct rpc_request *req)
{
- struct smm_variable_provider *this_instance = (struct smm_variable_provider*)context;
+ struct smm_variable_provider *this_instance = (struct smm_variable_provider *)context;
size_t param_len = 0;
efi_status_t efi_status = sanitize_access_variable_param(req, ¶m_len);
if (efi_status == EFI_SUCCESS) {
-
/* Valid access variable header parameter */
struct rpc_buffer *resp_buf = &req->response;
if (resp_buf->size >= param_len) {
-
struct rpc_buffer *req_buf = &req->request;
size_t max_data_len = resp_buf->size - param_len;
@@ -159,12 +150,9 @@
efi_status = uefi_variable_store_get_variable(
&this_instance->variable_store,
- (SMM_VARIABLE_COMMUNICATE_ACCESS_VARIABLE*)resp_buf->data,
- max_data_len,
- &resp_buf->data_length);
- }
- else {
-
+ (SMM_VARIABLE_COMMUNICATE_ACCESS_VARIABLE *)resp_buf->data,
+ max_data_len, &resp_buf->data_length);
+ } else {
/* Response buffer not big enough */
efi_status = EFI_BAD_BUFFER_SIZE;
}
@@ -175,34 +163,30 @@
return RPC_SUCCESS;
}
-static rpc_status_t get_next_variable_name_handler(void *context, struct rpc_request* req)
+static rpc_status_t get_next_variable_name_handler(void *context, struct rpc_request *req)
{
- struct smm_variable_provider *this_instance = (struct smm_variable_provider*)context;
+ struct smm_variable_provider *this_instance = (struct smm_variable_provider *)context;
size_t param_len = 0;
efi_status_t efi_status = sanitize_get_next_var_name_param(req, ¶m_len);
if (efi_status == EFI_SUCCESS) {
-
/* Valid get next variable name header */
struct rpc_buffer *resp_buf = &req->response;
if (resp_buf->size >= param_len) {
-
struct rpc_buffer *req_buf = &req->request;
- size_t max_name_len = resp_buf->size -
+ size_t max_name_len =
+ resp_buf->size -
SMM_VARIABLE_COMMUNICATE_GET_NEXT_VARIABLE_NAME_NAME_OFFSET;
memmove(resp_buf->data, req_buf->data, param_len);
efi_status = uefi_variable_store_get_next_variable_name(
&this_instance->variable_store,
- (SMM_VARIABLE_COMMUNICATE_GET_NEXT_VARIABLE_NAME*)resp_buf->data,
- max_name_len,
- &resp_buf->data_length);
- }
- else {
-
+ (SMM_VARIABLE_COMMUNICATE_GET_NEXT_VARIABLE_NAME *)resp_buf->data,
+ max_name_len, &resp_buf->data_length);
+ } else {
/* Reponse buffer not big enough */
efi_status = EFI_BAD_BUFFER_SIZE;
}
@@ -213,34 +197,30 @@
return RPC_SUCCESS;
}
-static rpc_status_t set_variable_handler(void *context, struct rpc_request* req)
+static rpc_status_t set_variable_handler(void *context, struct rpc_request *req)
{
- struct smm_variable_provider *this_instance = (struct smm_variable_provider*)context;
+ struct smm_variable_provider *this_instance = (struct smm_variable_provider *)context;
size_t param_len = 0;
efi_status_t efi_status = sanitize_access_variable_param(req, ¶m_len);
if (efi_status == EFI_SUCCESS) {
-
/* Access variable header is whole. Check that buffer length can
* accommodate the data.
*/
struct rpc_buffer *req_buf = &req->request;
const SMM_VARIABLE_COMMUNICATE_ACCESS_VARIABLE *access_var =
- (const SMM_VARIABLE_COMMUNICATE_ACCESS_VARIABLE*)req_buf->data;
+ (const SMM_VARIABLE_COMMUNICATE_ACCESS_VARIABLE *)req_buf->data;
- size_t space_for_data = req_buf->data_length -
+ size_t space_for_data =
+ req_buf->data_length -
SMM_VARIABLE_COMMUNICATE_ACCESS_VARIABLE_DATA_OFFSET(access_var);
if (access_var->DataSize <= space_for_data) {
-
efi_status = uefi_variable_store_set_variable(
- &this_instance->variable_store,
- access_var);
- }
- else {
-
+ &this_instance->variable_store, access_var);
+ } else {
/* Invalid DataSize */
efi_status = EFI_INVALID_PARAMETER;
}
@@ -251,32 +231,28 @@
return RPC_SUCCESS;
}
-static rpc_status_t query_variable_info_handler(void *context, struct rpc_request* req)
+static rpc_status_t query_variable_info_handler(void *context, struct rpc_request *req)
{
efi_status_t efi_status = EFI_INVALID_PARAMETER;
- struct smm_variable_provider *this_instance = (struct smm_variable_provider*)context;
+ struct smm_variable_provider *this_instance = (struct smm_variable_provider *)context;
const struct rpc_buffer *req_buf = &req->request;
if (req_buf->data_length >= sizeof(SMM_VARIABLE_COMMUNICATE_QUERY_VARIABLE_INFO)) {
-
struct rpc_buffer *resp_buf = &req->response;
if (resp_buf->size >= req_buf->data_length) {
-
memmove(resp_buf->data, req_buf->data, req_buf->data_length);
efi_status = uefi_variable_store_query_variable_info(
&this_instance->variable_store,
- (SMM_VARIABLE_COMMUNICATE_QUERY_VARIABLE_INFO*)resp_buf->data);
+ (SMM_VARIABLE_COMMUNICATE_QUERY_VARIABLE_INFO *)resp_buf->data);
if (efi_status == EFI_SUCCESS) {
-
- resp_buf->data_length = sizeof(SMM_VARIABLE_COMMUNICATE_QUERY_VARIABLE_INFO);
+ resp_buf->data_length =
+ sizeof(SMM_VARIABLE_COMMUNICATE_QUERY_VARIABLE_INFO);
}
- }
- else {
-
+ } else {
/* Reponse buffer not big enough */
efi_status = EFI_BAD_BUFFER_SIZE;
}
@@ -287,11 +263,12 @@
return RPC_SUCCESS;
}
-static rpc_status_t exit_boot_service_handler(void *context, struct rpc_request* req)
+static rpc_status_t exit_boot_service_handler(void *context, struct rpc_request *req)
{
- struct smm_variable_provider *this_instance = (struct smm_variable_provider*)context;
+ struct smm_variable_provider *this_instance = (struct smm_variable_provider *)context;
- efi_status_t efi_status = uefi_variable_store_exit_boot_service(&this_instance->variable_store);
+ efi_status_t efi_status =
+ uefi_variable_store_exit_boot_service(&this_instance->variable_store);
req->service_status = efi_status;
return RPC_SUCCESS;
@@ -299,22 +276,20 @@
static rpc_status_t set_var_check_property_handler(void *context, struct rpc_request *req)
{
- struct smm_variable_provider *this_instance = (struct smm_variable_provider*)context;
+ struct smm_variable_provider *this_instance = (struct smm_variable_provider *)context;
size_t param_len = 0;
efi_status_t efi_status = sanitize_var_check_property_param(req, ¶m_len);
if (efi_status == EFI_SUCCESS) {
-
/* Request parameter structue looks whole */
struct rpc_buffer *req_buf = &req->request;
const SMM_VARIABLE_COMMUNICATE_VAR_CHECK_VARIABLE_PROPERTY *check_property =
- (const SMM_VARIABLE_COMMUNICATE_VAR_CHECK_VARIABLE_PROPERTY*)req_buf->data;
+ (const SMM_VARIABLE_COMMUNICATE_VAR_CHECK_VARIABLE_PROPERTY *)req_buf->data;
efi_status = uefi_variable_store_set_var_check_property(
- &this_instance->variable_store,
- check_property);
+ &this_instance->variable_store, check_property);
}
req->service_status = efi_status;
@@ -324,28 +299,25 @@
static rpc_status_t get_var_check_property_handler(void *context, struct rpc_request *req)
{
- struct smm_variable_provider *this_instance = (struct smm_variable_provider*)context;
+ struct smm_variable_provider *this_instance = (struct smm_variable_provider *)context;
size_t param_len = 0;
efi_status_t efi_status = sanitize_var_check_property_param(req, ¶m_len);
if (efi_status == EFI_SUCCESS) {
-
/* Request parameter structue looks whole */
struct rpc_buffer *resp_buf = &req->response;
if (resp_buf->size >= param_len) {
-
struct rpc_buffer *req_buf = &req->request;
memmove(resp_buf->data, req_buf->data, param_len);
resp_buf->data_length = param_len;
efi_status = uefi_variable_store_get_var_check_property(
&this_instance->variable_store,
- (SMM_VARIABLE_COMMUNICATE_VAR_CHECK_VARIABLE_PROPERTY*)resp_buf->data);
- }
- else {
-
+ (SMM_VARIABLE_COMMUNICATE_VAR_CHECK_VARIABLE_PROPERTY *)
+ resp_buf->data);
+ } else {
/* Reponse buffer not big enough */
efi_status = EFI_BAD_BUFFER_SIZE;
}
@@ -364,21 +336,19 @@
* name is also carried in the buffer, the maximum payload size depends on the name size. This
* function therefore treats the payload as name + data.
*/
- size_t payload_size = req->request.size - SMM_VARIABLE_COMMUNICATE_ACCESS_VARIABLE_NAME_OFFSET;
+ size_t payload_size =
+ req->request.size - SMM_VARIABLE_COMMUNICATE_ACCESS_VARIABLE_NAME_OFFSET;
efi_status_t efi_status = EFI_SUCCESS;
struct rpc_buffer *resp_buf = &req->response;
if (resp_buf->size >= sizeof(SMM_VARIABLE_COMMUNICATE_GET_PAYLOAD_SIZE)) {
-
SMM_VARIABLE_COMMUNICATE_GET_PAYLOAD_SIZE *resp_msg =
- (SMM_VARIABLE_COMMUNICATE_GET_PAYLOAD_SIZE*)resp_buf->data;
+ (SMM_VARIABLE_COMMUNICATE_GET_PAYLOAD_SIZE *)resp_buf->data;
resp_msg->VariablePayloadSize = payload_size;
resp_buf->data_length = sizeof(SMM_VARIABLE_COMMUNICATE_GET_PAYLOAD_SIZE);
- }
- else {
-
+ } else {
/* Reponse buffer not big enough */
efi_status = EFI_BAD_BUFFER_SIZE;
}
diff --git a/components/service/uefi/smm_variable/provider/smm_variable_provider.h b/components/service/uefi/smm_variable/provider/smm_variable_provider.h
index 3e8ddba..e86ad82 100644
--- a/components/service/uefi/smm_variable/provider/smm_variable_provider.h
+++ b/components/service/uefi/smm_variable/provider/smm_variable_provider.h
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2021-2022, Arm Limited and Contributors. All rights reserved.
+ * Copyright (c) 2021-2023, Arm Limited and Contributors. All rights reserved.
*
* SPDX-License-Identifier: BSD-3-Clause
*/
@@ -19,8 +19,7 @@
* The smm_variable_provider is a service provider that implements an RPC interface
* for an instance of the smm_variable service.
*/
-struct smm_variable_provider
-{
+struct smm_variable_provider {
struct service_provider base_provider;
struct uefi_variable_store variable_store;
};
@@ -41,20 +40,17 @@
*
* \return An rpc_interface or NULL on failure
*/
-struct rpc_service_interface *smm_variable_provider_init(
- struct smm_variable_provider *context,
- uint32_t owner_id,
- size_t max_variables,
- struct storage_backend *persistent_store,
- struct storage_backend *volatile_store);
+struct rpc_service_interface *smm_variable_provider_init(struct smm_variable_provider *context,
+ uint32_t owner_id, size_t max_variables,
+ struct storage_backend *persistent_store,
+ struct storage_backend *volatile_store);
/**
* \brief Cleans up when the instance is no longer needed
*
* \param[in] context The instance to de-initialize
*/
-void smm_variable_provider_deinit(
- struct smm_variable_provider *context);
+void smm_variable_provider_deinit(struct smm_variable_provider *context);
#ifdef __cplusplus
} /* extern "C" */
diff --git a/components/service/uefi/smm_variable/test/service/smm_variable_attack_tests.cpp b/components/service/uefi/smm_variable/test/service/smm_variable_attack_tests.cpp
index 32e5778..0db3b8f 100644
--- a/components/service/uefi/smm_variable/test/service/smm_variable_attack_tests.cpp
+++ b/components/service/uefi/smm_variable/test/service/smm_variable_attack_tests.cpp
@@ -1,15 +1,15 @@
/*
- * Copyright (c) 2021-2022, Arm Limited and Contributors. All rights reserved.
+ * Copyright (c) 2021-2023, Arm Limited and Contributors. All rights reserved.
*
* SPDX-License-Identifier: BSD-3-Clause
*/
+#include <CppUTest/TestHarness.h>
#include <cstring>
#include <limits>
-#include <service/uefi/smm_variable/client/cpp/smm_variable_client.h>
#include <protocols/rpc/common/packed-c/encoding.h>
+#include <service/uefi/smm_variable/client/cpp/smm_variable_client.h>
#include <service_locator.h>
-#include <CppUTest/TestHarness.h>
/*
* Attack tests for the smm-variable service. Invalid parameters are sent by
@@ -24,12 +24,10 @@
service_locator_init();
- m_service_context =
- service_locator_query("sn:trustedfirmware.org:smm-variable:0");
+ m_service_context = service_locator_query("sn:trustedfirmware.org:smm-variable:0");
CHECK_TRUE(m_service_context);
- m_rpc_session =
- service_context_open(m_service_context);
+ m_rpc_session = service_context_open(m_service_context);
CHECK_TRUE(m_rpc_session);
m_client = new smm_variable_client(m_rpc_session);
@@ -81,13 +79,8 @@
std::string set_data = "UEFI variable data string";
/* Override the data size with a big but plausable length */
- efi_status = m_client->set_variable(
- m_common_guid,
- var_name,
- set_data,
- 0,
- 0,
- std::numeric_limits<uint16_t>::max());
+ efi_status = m_client->set_variable(m_common_guid, var_name, set_data, 0, 0,
+ std::numeric_limits<uint16_t>::max());
UNSIGNED_LONGLONGS_EQUAL(EFI_INVALID_PARAMETER, efi_status);
}
@@ -99,13 +92,8 @@
std::string set_data = "UEFI variable data string";
/* Override the data size with SIZE_MAX length */
- efi_status = m_client->set_variable(
- m_common_guid,
- var_name,
- set_data,
- 0,
- 0,
- std::numeric_limits<size_t>::max());
+ efi_status = m_client->set_variable(m_common_guid, var_name, set_data, 0, 0,
+ std::numeric_limits<size_t>::max());
UNSIGNED_LONGLONGS_EQUAL(EFI_INVALID_PARAMETER, efi_status);
}
@@ -117,13 +105,8 @@
std::string set_data = "UEFI variable data string";
/* Override the name size slightly too big such that name + data don't fit */
- efi_status = m_client->set_variable(
- m_common_guid,
- var_name,
- set_data,
- 0,
- (var_name.size() + 1) * sizeof(int16_t) + 1,
- 0);
+ efi_status = m_client->set_variable(m_common_guid, var_name, set_data, 0,
+ (var_name.size() + 1) * sizeof(int16_t) + 1, 0);
UNSIGNED_LONGLONGS_EQUAL(EFI_INVALID_PARAMETER, efi_status);
}
@@ -135,13 +118,8 @@
std::string set_data = "UEFI variable data string";
/* Override the name size slightly too big such that name + data don't fit */
- efi_status = m_client->set_variable(
- m_common_guid,
- var_name,
- set_data,
- 0,
- std::numeric_limits<size_t>::max(),
- 0);
+ efi_status = m_client->set_variable(m_common_guid, var_name, set_data, 0,
+ std::numeric_limits<size_t>::max(), 0);
UNSIGNED_LONGLONGS_EQUAL(EFI_INVALID_PARAMETER, efi_status);
}
@@ -153,19 +131,12 @@
std::string set_data = "UEFI variable data string";
std::string get_data;
- efi_status = m_client->set_variable(
- m_common_guid,
- var_name,
- set_data,
- 0);
+ efi_status = m_client->set_variable(m_common_guid, var_name, set_data, 0);
UNSIGNED_LONGLONGS_EQUAL(EFI_SUCCESS, efi_status);
- efi_status = m_client->get_variable(
- m_common_guid,
- var_name,
- get_data,
- (var_name.size() + 1) * sizeof(int16_t) + 1);
+ efi_status = m_client->get_variable(m_common_guid, var_name, get_data,
+ (var_name.size() + 1) * sizeof(int16_t) + 1);
UNSIGNED_LONGLONGS_EQUAL(EFI_INVALID_PARAMETER, efi_status);
@@ -181,19 +152,12 @@
std::string set_data = "UEFI variable data string";
std::string get_data;
- efi_status = m_client->set_variable(
- m_common_guid,
- var_name,
- set_data,
- 0);
+ efi_status = m_client->set_variable(m_common_guid, var_name, set_data, 0);
UNSIGNED_LONGLONGS_EQUAL(EFI_SUCCESS, efi_status);
- efi_status = m_client->get_variable(
- m_common_guid,
- var_name,
- get_data,
- std::numeric_limits<size_t>::max());
+ efi_status = m_client->get_variable(m_common_guid, var_name, get_data,
+ std::numeric_limits<size_t>::max());
UNSIGNED_LONGLONGS_EQUAL(EFI_INVALID_PARAMETER, efi_status);
@@ -209,10 +173,8 @@
EFI_GUID guid;
memset(&guid, 0, sizeof(guid));
- efi_status = m_client->get_next_variable_name(
- guid,
- var_name,
- (var_name.size() + 1) * sizeof(int16_t) + 1);
+ efi_status = m_client->get_next_variable_name(guid, var_name,
+ (var_name.size() + 1) * sizeof(int16_t) + 1);
UNSIGNED_LONGLONGS_EQUAL(EFI_INVALID_PARAMETER, efi_status);
}
@@ -226,26 +188,19 @@
memset(&guid, 0, sizeof(guid));
/* Add a variable */
- efi_status = m_client->set_variable(
- m_common_guid,
- var_name_1,
- std::string("Some data"),
- EFI_VARIABLE_NON_VOLATILE);
+ efi_status = m_client->set_variable(m_common_guid, var_name_1, std::string("Some data"),
+ EFI_VARIABLE_NON_VOLATILE);
UNSIGNED_LONGLONGS_EQUAL(EFI_SUCCESS, efi_status);
/* Initial iteration uses good name length */
- efi_status = m_client->get_next_variable_name(
- guid,
- var_name);
+ efi_status = m_client->get_next_variable_name(guid, var_name);
UNSIGNED_LONGLONGS_EQUAL(EFI_SUCCESS, efi_status);
/* Next iteration uses invalid name length */
- efi_status = m_client->get_next_variable_name(
- guid,
- var_name,
- std::numeric_limits<size_t>::max());
+ efi_status = m_client->get_next_variable_name(guid, var_name,
+ std::numeric_limits<size_t>::max());
UNSIGNED_LONGLONGS_EQUAL(EFI_INVALID_PARAMETER, efi_status);
@@ -266,11 +221,8 @@
check_property.MinSize = 0;
check_property.MaxSize = 200;
- efi_status = m_client->set_var_check_property(
- m_common_guid,
- var_name,
- check_property,
- (var_name.size() + 1) * sizeof(int16_t) + 1);
+ efi_status = m_client->set_var_check_property(m_common_guid, var_name, check_property,
+ (var_name.size() + 1) * sizeof(int16_t) + 1);
UNSIGNED_LONGLONGS_EQUAL(EFI_INVALID_PARAMETER, efi_status);
}
@@ -286,11 +238,8 @@
check_property.MinSize = 0;
check_property.MaxSize = 200;
- efi_status = m_client->set_var_check_property(
- m_common_guid,
- var_name,
- check_property,
- std::numeric_limits<size_t>::max());
+ efi_status = m_client->set_var_check_property(m_common_guid, var_name, check_property,
+ std::numeric_limits<size_t>::max());
UNSIGNED_LONGLONGS_EQUAL(EFI_INVALID_PARAMETER, efi_status);
}
@@ -301,11 +250,8 @@
VAR_CHECK_VARIABLE_PROPERTY check_property;
- efi_status = m_client->get_var_check_property(
- m_common_guid,
- var_name,
- check_property,
- (var_name.size() + 1) * sizeof(int16_t) + 1);
+ efi_status = m_client->get_var_check_property(m_common_guid, var_name, check_property,
+ (var_name.size() + 1) * sizeof(int16_t) + 1);
UNSIGNED_LONGLONGS_EQUAL(EFI_INVALID_PARAMETER, efi_status);
}
@@ -316,10 +262,7 @@
VAR_CHECK_VARIABLE_PROPERTY check_property;
- efi_status = m_client->get_var_check_property(
- m_common_guid,
- var_name,
- check_property,
- std::numeric_limits<size_t>::max());
+ efi_status = m_client->get_var_check_property(m_common_guid, var_name, check_property,
+ std::numeric_limits<size_t>::max());
UNSIGNED_LONGLONGS_EQUAL(EFI_INVALID_PARAMETER, efi_status);
}
diff --git a/components/service/uefi/smm_variable/test/service/smm_variable_service_tests.cpp b/components/service/uefi/smm_variable/test/service/smm_variable_service_tests.cpp
index b3ca761..77263f7 100644
--- a/components/service/uefi/smm_variable/test/service/smm_variable_service_tests.cpp
+++ b/components/service/uefi/smm_variable/test/service/smm_variable_service_tests.cpp
@@ -4,11 +4,11 @@
* SPDX-License-Identifier: BSD-3-Clause
*/
-#include <cstring>
-#include <service/uefi/smm_variable/client/cpp/smm_variable_client.h>
-#include <protocols/rpc/common/packed-c/encoding.h>
-#include <service_locator.h>
#include <CppUTest/TestHarness.h>
+#include <cstring>
+#include <protocols/rpc/common/packed-c/encoding.h>
+#include <service/uefi/smm_variable/client/cpp/smm_variable_client.h>
+#include <service_locator.h>
/*
* Service-level tests for the smm-variable service.
@@ -22,12 +22,10 @@
service_locator_init();
- m_service_context =
- service_locator_query("sn:trustedfirmware.org:smm-variable:0");
+ m_service_context = service_locator_query("sn:trustedfirmware.org:smm-variable:0");
CHECK_TRUE(m_service_context);
- m_rpc_session =
- service_context_open(m_service_context);
+ m_rpc_session = service_context_open(m_service_context);
CHECK_TRUE(m_rpc_session);
m_client = new smm_variable_client(m_rpc_session);
@@ -85,42 +83,29 @@
* If the boot variable already exists at the start of the
* test, indicating a subsequent test run, just return.
*/
- efi_status = m_client->get_variable(
- m_common_guid,
- boot_var_name,
- get_data);
- if (efi_status == EFI_ACCESS_DENIED) return;
+ efi_status = m_client->get_variable(m_common_guid, boot_var_name, get_data);
+ if (efi_status == EFI_ACCESS_DENIED)
+ return;
/* Add variables with runtime state access control */
- efi_status = m_client->set_variable(
- m_common_guid,
- boot_var_name,
- boot_set_data,
- EFI_VARIABLE_BOOTSERVICE_ACCESS);
+ efi_status = m_client->set_variable(m_common_guid, boot_var_name, boot_set_data,
+ EFI_VARIABLE_BOOTSERVICE_ACCESS);
UNSIGNED_LONGLONGS_EQUAL(EFI_SUCCESS, efi_status);
efi_status = m_client->set_variable(
- m_common_guid,
- runtime_var_name,
- runtime_set_data,
- EFI_VARIABLE_NON_VOLATILE |
- EFI_VARIABLE_RUNTIME_ACCESS | EFI_VARIABLE_BOOTSERVICE_ACCESS);
+ m_common_guid, runtime_var_name, runtime_set_data,
+ EFI_VARIABLE_NON_VOLATILE | EFI_VARIABLE_RUNTIME_ACCESS |
+ EFI_VARIABLE_BOOTSERVICE_ACCESS);
UNSIGNED_LONGLONGS_EQUAL(EFI_SUCCESS, efi_status);
/* Expect access to boot variable to be permitted */
- efi_status = m_client->get_variable(
- m_common_guid,
- boot_var_name,
- get_data);
+ efi_status = m_client->get_variable(m_common_guid, boot_var_name, get_data);
UNSIGNED_LONGLONGS_EQUAL(EFI_SUCCESS, efi_status);
UNSIGNED_LONGS_EQUAL(boot_set_data.size(), get_data.size());
LONGS_EQUAL(0, get_data.compare(boot_set_data));
/* Expect access to the runtime variable to also be permitted during boot */
- efi_status = m_client->get_variable(
- m_common_guid,
- runtime_var_name,
- get_data);
+ efi_status = m_client->get_variable(m_common_guid, runtime_var_name, get_data);
UNSIGNED_LONGLONGS_EQUAL(EFI_SUCCESS, efi_status);
/* Exit boot service - access should no longer be permitted */
@@ -128,17 +113,11 @@
UNSIGNED_LONGLONGS_EQUAL(EFI_SUCCESS, efi_status);
/* Access to the boot variable should now be forbidden */
- efi_status = m_client->get_variable(
- m_common_guid,
- boot_var_name,
- get_data);
+ efi_status = m_client->get_variable(m_common_guid, boot_var_name, get_data);
UNSIGNED_LONGLONGS_EQUAL(EFI_ACCESS_DENIED, efi_status);
/* Expect access to the runtime variable should still be permitted */
- efi_status = m_client->get_variable(
- m_common_guid,
- runtime_var_name,
- get_data);
+ efi_status = m_client->get_variable(m_common_guid, runtime_var_name, get_data);
UNSIGNED_LONGLONGS_EQUAL(EFI_SUCCESS, efi_status);
UNSIGNED_LONGS_EQUAL(runtime_set_data.size(), get_data.size());
LONGS_EQUAL(0, get_data.compare(runtime_set_data));
@@ -160,11 +139,9 @@
std::string set_data = "A read only variable";
/* Add a variable to the store */
- efi_status = m_client->set_variable(
- m_common_guid,
- var_name_1,
- set_data,
- EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS);
+ efi_status = m_client->set_variable(m_common_guid, var_name_1, set_data,
+ EFI_VARIABLE_BOOTSERVICE_ACCESS |
+ EFI_VARIABLE_RUNTIME_ACCESS);
UNSIGNED_LONGLONGS_EQUAL(EFI_SUCCESS, efi_status);
@@ -176,19 +153,15 @@
check_property.MinSize = 0;
check_property.MaxSize = 100;
- efi_status = m_client->set_var_check_property(
- m_common_guid,
- var_name_1,
- check_property);
+ efi_status =
+ m_client->set_var_check_property(m_common_guid, var_name_1, check_property);
UNSIGNED_LONGLONGS_EQUAL(EFI_SUCCESS, efi_status);
/* Read back the check property constraint and expect it to match the set value */
VAR_CHECK_VARIABLE_PROPERTY got_check_property;
- efi_status = m_client->get_var_check_property(
- m_common_guid,
- var_name_1,
- got_check_property);
+ efi_status = m_client->get_var_check_property(m_common_guid, var_name_1,
+ got_check_property);
UNSIGNED_LONGLONGS_EQUAL(EFI_SUCCESS, efi_status);
UNSIGNED_LONGS_EQUAL(check_property.Revision, got_check_property.Revision);
@@ -199,9 +172,7 @@
/* Attempt to modify variable */
efi_status = m_client->set_variable(
- m_common_guid,
- var_name_1,
- std::string("Different variable data"),
+ m_common_guid, var_name_1, std::string("Different variable data"),
EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS);
UNSIGNED_LONGLONGS_EQUAL(EFI_WRITE_PROTECTED, efi_status);
@@ -209,10 +180,7 @@
/* Expect to still be able to read variable */
std::string get_data;
- efi_status = m_client->get_variable(
- m_common_guid,
- var_name_1,
- get_data);
+ efi_status = m_client->get_variable(m_common_guid, var_name_1, get_data);
UNSIGNED_LONGLONGS_EQUAL(EFI_SUCCESS, efi_status);
@@ -234,18 +202,13 @@
std::string set_data = "UEFI variable data string";
std::string get_data;
- efi_status = m_client->set_variable(
- m_common_guid,
- var_name,
- set_data,
- EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS);
+ efi_status = m_client->set_variable(m_common_guid, var_name, set_data,
+ EFI_VARIABLE_BOOTSERVICE_ACCESS |
+ EFI_VARIABLE_RUNTIME_ACCESS);
UNSIGNED_LONGLONGS_EQUAL(EFI_SUCCESS, efi_status);
- efi_status = m_client->get_variable(
- m_common_guid,
- var_name,
- get_data);
+ efi_status = m_client->get_variable(m_common_guid, var_name, get_data);
UNSIGNED_LONGLONGS_EQUAL(EFI_SUCCESS, efi_status);
@@ -255,19 +218,14 @@
/* Extend the variable using an append write */
std::string append_data = " values added with append write";
- efi_status = m_client->set_variable(
- m_common_guid,
- var_name,
- append_data,
- EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS |
- EFI_VARIABLE_APPEND_WRITE);
+ efi_status = m_client->set_variable(m_common_guid, var_name, append_data,
+ EFI_VARIABLE_BOOTSERVICE_ACCESS |
+ EFI_VARIABLE_RUNTIME_ACCESS |
+ EFI_VARIABLE_APPEND_WRITE);
UNSIGNED_LONGLONGS_EQUAL(EFI_SUCCESS, efi_status);
- efi_status = m_client->get_variable(
- m_common_guid,
- var_name,
- get_data);
+ efi_status = m_client->get_variable(m_common_guid, var_name, get_data);
UNSIGNED_LONGLONGS_EQUAL(EFI_SUCCESS, efi_status);
@@ -289,19 +247,14 @@
std::string set_data = "Another UEFI variable data string";
std::string get_data;
- efi_status = m_client->set_variable(
- m_common_guid,
- var_name,
- set_data,
- EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS |
- EFI_VARIABLE_NON_VOLATILE);
+ efi_status = m_client->set_variable(m_common_guid, var_name, set_data,
+ EFI_VARIABLE_BOOTSERVICE_ACCESS |
+ EFI_VARIABLE_RUNTIME_ACCESS |
+ EFI_VARIABLE_NON_VOLATILE);
UNSIGNED_LONGLONGS_EQUAL(EFI_SUCCESS, efi_status);
- efi_status = m_client->get_variable(
- m_common_guid,
- var_name,
- get_data);
+ efi_status = m_client->get_variable(m_common_guid, var_name, get_data);
UNSIGNED_LONGLONGS_EQUAL(EFI_SUCCESS, efi_status);
@@ -312,18 +265,13 @@
std::string append_data = " values added with append write";
efi_status = m_client->set_variable(
- m_common_guid,
- var_name,
- append_data,
+ m_common_guid, var_name, append_data,
EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS |
- EFI_VARIABLE_NON_VOLATILE | EFI_VARIABLE_APPEND_WRITE);
+ EFI_VARIABLE_NON_VOLATILE | EFI_VARIABLE_APPEND_WRITE);
UNSIGNED_LONGLONGS_EQUAL(EFI_SUCCESS, efi_status);
- efi_status = m_client->get_variable(
- m_common_guid,
- var_name,
- get_data);
+ efi_status = m_client->get_variable(m_common_guid, var_name, get_data);
UNSIGNED_LONGLONGS_EQUAL(EFI_SUCCESS, efi_status);
@@ -345,21 +293,15 @@
std::string set_data = "UEFI variable data string";
std::string get_data;
- efi_status = m_client->set_variable(
- m_common_guid,
- var_name,
- set_data,
- EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS);
+ efi_status = m_client->set_variable(m_common_guid, var_name, set_data,
+ EFI_VARIABLE_BOOTSERVICE_ACCESS |
+ EFI_VARIABLE_RUNTIME_ACCESS);
UNSIGNED_LONGLONGS_EQUAL(EFI_SUCCESS, efi_status);
/* Get with the data size set to zero. This is the standard way
* to discover the variable size. */
- efi_status = m_client->get_variable(
- m_common_guid,
- var_name,
- get_data,
- 0, 0);
+ efi_status = m_client->get_variable(m_common_guid, var_name, get_data, 0, 0);
UNSIGNED_LONGLONGS_EQUAL(EFI_BUFFER_TOO_SMALL, efi_status);
UNSIGNED_LONGS_EQUAL(set_data.size(), get_data.size());
@@ -376,22 +318,16 @@
std::string set_data = "UEFI variable data string";
std::string get_data;
- efi_status = m_client->set_variable(
- m_common_guid,
- var_name,
- set_data,
- EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS |
- EFI_VARIABLE_NON_VOLATILE);
+ efi_status = m_client->set_variable(m_common_guid, var_name, set_data,
+ EFI_VARIABLE_BOOTSERVICE_ACCESS |
+ EFI_VARIABLE_RUNTIME_ACCESS |
+ EFI_VARIABLE_NON_VOLATILE);
UNSIGNED_LONGLONGS_EQUAL(EFI_SUCCESS, efi_status);
/* Get with the data size set to zero. This is the standard way
* to discover the variable size. */
- efi_status = m_client->get_variable(
- m_common_guid,
- var_name,
- get_data,
- 0, 0);
+ efi_status = m_client->get_variable(m_common_guid, var_name, get_data, 0, 0);
UNSIGNED_LONGLONGS_EQUAL(EFI_BUFFER_TOO_SMALL, efi_status);
UNSIGNED_LONGS_EQUAL(set_data.size(), get_data.size());
@@ -410,11 +346,10 @@
size_t nv_max_variable_size = 0;
size_t nv_remaining_variable_storage_size = 0;
- efi_status = m_client->query_variable_info(
- EFI_VARIABLE_NON_VOLATILE,
- &nv_max_variable_storage_size,
- &nv_remaining_variable_storage_size,
- &nv_max_variable_size);
+ efi_status = m_client->query_variable_info(EFI_VARIABLE_NON_VOLATILE,
+ &nv_max_variable_storage_size,
+ &nv_remaining_variable_storage_size,
+ &nv_max_variable_size);
UNSIGNED_LONGLONGS_EQUAL(EFI_SUCCESS, efi_status);
UNSIGNED_LONGLONGS_EQUAL(nv_max_variable_storage_size, nv_remaining_variable_storage_size);
@@ -422,11 +357,9 @@
size_t v_max_variable_size = 0;
size_t v_remaining_variable_storage_size = 0;
- efi_status = m_client->query_variable_info(
- 0,
- &v_max_variable_storage_size,
- &v_remaining_variable_storage_size,
- &v_max_variable_size);
+ efi_status = m_client->query_variable_info(0, &v_max_variable_storage_size,
+ &v_remaining_variable_storage_size,
+ &v_max_variable_size);
UNSIGNED_LONGLONGS_EQUAL(EFI_SUCCESS, efi_status);
UNSIGNED_LONGLONGS_EQUAL(v_max_variable_storage_size, v_remaining_variable_storage_size);
@@ -436,27 +369,20 @@
std::wstring var_name_3 = L"varibale_3";
std::string set_data = "Some variable data";
- efi_status = m_client->set_variable(
- m_common_guid,
- var_name_1,
- set_data,
- EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_NON_VOLATILE);
+ efi_status =
+ m_client->set_variable(m_common_guid, var_name_1, set_data,
+ EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_NON_VOLATILE);
UNSIGNED_LONGLONGS_EQUAL(EFI_SUCCESS, efi_status);
- efi_status = m_client->set_variable(
- m_common_guid,
- var_name_2,
- set_data,
- EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_NON_VOLATILE);
+ efi_status =
+ m_client->set_variable(m_common_guid, var_name_2, set_data,
+ EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_NON_VOLATILE);
UNSIGNED_LONGLONGS_EQUAL(EFI_SUCCESS, efi_status);
- efi_status = m_client->set_variable(
- m_common_guid,
- var_name_3,
- set_data,
- EFI_VARIABLE_BOOTSERVICE_ACCESS);
+ efi_status = m_client->set_variable(m_common_guid, var_name_3, set_data,
+ EFI_VARIABLE_BOOTSERVICE_ACCESS);
UNSIGNED_LONGLONGS_EQUAL(EFI_SUCCESS, efi_status);
@@ -466,26 +392,20 @@
size_t remaining_variable_storage_size = 0;
/* Check non-volatile - two variables have been added */
- efi_status = m_client->query_variable_info(
- EFI_VARIABLE_NON_VOLATILE,
- &max_variable_storage_size,
- &remaining_variable_storage_size,
- &max_variable_size);
+ efi_status =
+ m_client->query_variable_info(EFI_VARIABLE_NON_VOLATILE, &max_variable_storage_size,
+ &remaining_variable_storage_size, &max_variable_size);
UNSIGNED_LONGLONGS_EQUAL(EFI_SUCCESS, efi_status);
- UNSIGNED_LONGLONGS_EQUAL(
- (nv_remaining_variable_storage_size - set_data.size() * 2),
- remaining_variable_storage_size);
+ UNSIGNED_LONGLONGS_EQUAL((nv_remaining_variable_storage_size - set_data.size() * 2),
+ remaining_variable_storage_size);
/* Check volatile - one variables have been added */
- efi_status = m_client->query_variable_info(
- 0,
- &max_variable_storage_size,
- &remaining_variable_storage_size,
- &max_variable_size);
+ efi_status = m_client->query_variable_info(0, &max_variable_storage_size,
+ &remaining_variable_storage_size,
+ &max_variable_size);
UNSIGNED_LONGLONGS_EQUAL(EFI_SUCCESS, efi_status);
- UNSIGNED_LONGLONGS_EQUAL(
- (v_remaining_variable_storage_size - set_data.size() * 1),
- remaining_variable_storage_size);
+ UNSIGNED_LONGLONGS_EQUAL((v_remaining_variable_storage_size - set_data.size() * 1),
+ remaining_variable_storage_size);
/* Enumerate store contents - expect the values we added */
std::wstring var_name;
@@ -534,11 +454,8 @@
std::string set_data = "Initial value";
/* Add a variable to the store */
- efi_status = m_client->set_variable(
- m_common_guid,
- var_name_1,
- set_data,
- EFI_VARIABLE_BOOTSERVICE_ACCESS);
+ efi_status = m_client->set_variable(m_common_guid, var_name_1, set_data,
+ EFI_VARIABLE_BOOTSERVICE_ACCESS);
UNSIGNED_LONGLONGS_EQUAL(EFI_SUCCESS, efi_status);
@@ -550,26 +467,19 @@
check_property.MinSize = 0;
check_property.MaxSize = 20;
- efi_status = m_client->set_var_check_property(
- m_common_guid,
- var_name_1,
- check_property);
+ efi_status = m_client->set_var_check_property(m_common_guid, var_name_1, check_property);
UNSIGNED_LONGLONGS_EQUAL(EFI_SUCCESS, efi_status);
/* Attempt to set value to a size that exceeds the MaxSize constraint */
efi_status = m_client->set_variable(
- m_common_guid,
- var_name_1,
+ m_common_guid, var_name_1,
std::string("A data value that exceeds the MaxSize constraint"),
EFI_VARIABLE_BOOTSERVICE_ACCESS);
UNSIGNED_LONGLONGS_EQUAL(EFI_INVALID_PARAMETER, efi_status);
/* But setting a value that's within the constraints should work */
- efi_status = m_client->set_variable(
- m_common_guid,
- var_name_1,
- std::string("Small value"),
- EFI_VARIABLE_BOOTSERVICE_ACCESS);
+ efi_status = m_client->set_variable(m_common_guid, var_name_1, std::string("Small value"),
+ EFI_VARIABLE_BOOTSERVICE_ACCESS);
UNSIGNED_LONGLONGS_EQUAL(EFI_SUCCESS, efi_status);
/* Removing should be allowed though */
@@ -580,8 +490,7 @@
* still be set.
*/
efi_status = m_client->set_variable(
- m_common_guid,
- var_name_1,
+ m_common_guid, var_name_1,
std::string("Another try to set a value that exceeds the MaxSize constraint"),
EFI_VARIABLE_BOOTSERVICE_ACCESS);
UNSIGNED_LONGLONGS_EQUAL(EFI_INVALID_PARAMETER, efi_status);