| 1 |
/* SPDX-License-Identifier: LGPL-2.1-or-later */ |
| 2 |
|
| 3 |
#include "sort-util.h" |
| 4 |
#include "tpm2-event-log.h" |
| 5 |
|
| 6 |
typedef struct tpm2_log_event_type_info { |
| 7 |
uint32_t event_type; |
| 8 |
const char *name; |
| 9 |
} tpm2_log_event_type_info; |
| 10 |
|
| 11 |
static tpm2_log_event_type_info tpm2_log_event_type_table[] = { |
| 12 |
/* Unfortunately the types are defined all over the place, hence we are not using a dense table |
| 13 |
* here. |
| 14 |
* |
| 15 |
* Keep this sorted by event type, so that we can do bisection! */ |
| 16 |
{ EV_PREBOOT_CERT, "preboot-cert" }, |
| 17 |
{ EV_POST_CODE, "post-code" }, |
| 18 |
{ EV_NO_ACTION, "no-action" }, |
| 19 |
{ EV_SEPARATOR, "separator" }, |
| 20 |
{ EV_ACTION, "action" }, |
| 21 |
{ EV_EVENT_TAG, "event-tag" }, |
| 22 |
{ EV_S_CRTM_CONTENTS, "s-crtm-contents" }, |
| 23 |
{ EV_S_CRTM_VERSION, "s-crtm-version" }, |
| 24 |
{ EV_CPU_MICROCODE, "cpu-microcode" }, |
| 25 |
{ EV_PLATFORM_CONFIG_FLAGS, "platform-config-flags" }, |
| 26 |
{ EV_TABLE_OF_DEVICES, "table-of-devices" }, |
| 27 |
{ EV_COMPACT_HASH, "compact-hash" }, |
| 28 |
{ EV_IPL, "ipl" }, |
| 29 |
{ EV_IPL_PARTITION_DATA, "ipl-partition-data" }, |
| 30 |
{ EV_NONHOST_CODE, "nonhost-code" }, |
| 31 |
{ EV_NONHOST_CONFIG, "nonhost-config" }, |
| 32 |
{ EV_NONHOST_INFO, "nonhost-info" }, |
| 33 |
{ EV_OMIT_BOOT_DEVICE_EVENTS, "omit-boot-device-events" }, |
| 34 |
/* omitting EV_EFI_EVENT_BASE, since its not an event, but just a base value for other events */ |
| 35 |
{ EV_EFI_VARIABLE_DRIVER_CONFIG, "efi-variable-driver-config" }, |
| 36 |
{ EV_EFI_VARIABLE_BOOT, "efi-variable-boot" }, |
| 37 |
{ EV_EFI_BOOT_SERVICES_APPLICATION, "efi-boot-services-application" }, |
| 38 |
{ EV_EFI_BOOT_SERVICES_DRIVER, "efi-boot-services-driver" }, |
| 39 |
{ EV_EFI_RUNTIME_SERVICES_DRIVER, "efi-runtime-services-driver" }, |
| 40 |
{ EV_EFI_GPT_EVENT, "efi-gpt-event" }, |
| 41 |
{ EV_EFI_ACTION, "efi-action" }, |
| 42 |
{ EV_EFI_PLATFORM_FIRMWARE_BLOB, "efi-platform-firmware-blob" }, |
| 43 |
{ EV_EFI_HANDOFF_TABLES, "efi-handoff-tables" }, |
| 44 |
{ EV_EFI_PLATFORM_FIRMWARE_BLOB2, "efi-platform-firmware-blob2" }, |
| 45 |
{ EV_EFI_HANDOFF_TABLES2, "efi-handoff-tables" }, |
| 46 |
{ EV_EFI_VARIABLE_BOOT2, "efi-variable-boot2" }, |
| 47 |
{ EV_EFI_HCRTM_EVENT, "efi-hcrtm-event" }, |
| 48 |
{ EV_EFI_VARIABLE_AUTHORITY, "efi-variable-authority" }, |
| 49 |
{ EV_EFI_SPDM_FIRMWARE_BLOB, "efi-spdm-firmware-blob" }, |
| 50 |
{ EV_EFI_SPDM_FIRMWARE_CONFIG, "efi-spdm-firmware-config" }, |
| 51 |
}; |
| 52 |
|
| 53 |
static int tpm2_log_event_type_info_cmp(const tpm2_log_event_type_info *a, const tpm2_log_event_type_info *b) { |
| 54 |
return CMP(ASSERT_PTR(a)->event_type, ASSERT_PTR(b)->event_type); |
| 55 |
} |
| 56 |
|
| 57 |
const char* tpm2_log_event_type_to_string(uint32_t type) { |
| 58 |
|
| 59 |
tpm2_log_event_type_info *found, key = { |
| 60 |
.event_type = type, |
| 61 |
}; |
| 62 |
|
| 63 |
found = typesafe_bsearch(&key, tpm2_log_event_type_table, ELEMENTSOF(tpm2_log_event_type_table), tpm2_log_event_type_info_cmp); |
| 64 |
|
| 65 |
return found ? found->name : NULL; |
| 66 |
} |