Internal constants and parser helpers for lazybios implementation files. More...
#include "lazybios/lazybios.h"#include <stdarg.h>#include <stdio.h>#include <stdlib.h>#include <string.h>Go to the source code of this file.
Data Structures | |
| struct | lazybiosEntryInspection |
Functions | |
| const uint8_t * | DMINext (const uint8_t *p, const uint8_t *end) |
| Locates the next SMBIOS structure in a DMI table. | |
| const char * | DMIString (const uint8_t *p, uint8_t length, uint8_t index, const uint8_t *end) |
| Copies a string from an SMBIOS structure's string-set. | |
| static void | lazybios_log_internal (const char *prefix, const char *fmt,...) |
| size_t | lazybiosCountStructsByType (const lazybiosDMI_t *DMIData, uint8_t target_type) |
| Counts SMBIOS structures having a specified type identifier. | |
| static void | lazybiosDecoderAppend (char *buf, size_t buf_len, size_t *len, const char *fmt,...) |
| Appends formatted text to a decoder output buffer. | |
| static char * | lazybiosDup (const char *src) |
| Duplicates a NUL-terminated string with malloc. | |
| LAZYBIOS_WARN_UNUSED int | lazybiosFile (lazybiosCTX_t *ctx, const char *entry_path, const char *dmi_path) |
| Loads an SMBIOS entry point and DMI table from separate files. | |
| int | lazybiosFindSMBIOSEntryPoint (const uint8_t *image, size_t image_len, size_t *entry_offset, size_t *entry_len) |
| Finds a valid SMBIOS entry point within a memory image. | |
| int | lazybiosGetSingleFileLayout (const uint8_t *entry_data, size_t available, size_t file_len, size_t *entry_len, size_t *table_offset, size_t *table_len) |
| Determines the entry-point and table layout in a combined dump file. | |
| int | lazybiosGetSMBIOSTableLocation (const uint8_t *entry_data, size_t available, size_t *entry_len, uint64_t *table_address, size_t *table_len) |
| Extracts an SMBIOS table address and length from an entry point. | |
| int | lazybiosInspectEntryPoint (const uint8_t *entry_data, size_t available, lazybiosEntryInspection *inspection) |
| Inspects and validates an SMBIOS 2.x or 3.x entry point. | |
| int | lazybiosLoadRawBuffers (lazybiosCTX_t *ctx, const uint8_t *entry_data, size_t entry_len, const uint8_t *dmi_data, size_t dmi_len) |
| Copies validated raw entry-point and DMI-table buffers into a context. | |
| int | lazybiosLoadWindowsRawSMBIOSData (lazybiosCTX_t *ctx, const uint8_t *raw_data, size_t raw_len) |
| Loads the Windows raw SMBIOS table format into a context. | |
| int | lazybiosParseEntry (lazybiosCTX_t *ctx, const uint8_t *entry_buf, size_t buf_len) |
| Validates and identifies an SMBIOS entry point. | |
| LAZYBIOS_WARN_UNUSED int | lazybiosSingleFile (lazybiosCTX_t *ctx, const char *bin_path) |
| Loads SMBIOS entry point and DMI data from one merged file. | |
Internal constants and parser helpers for lazybios implementation files.
Definition in file lazybios_internal.h.
| #define DEV_MEM "/dev/mem" |
Absolute path to the physical memory device.
Definition at line 151 of file lazybios_internal.h.
| #define LAZYBIOS_CLAMP_STRUCTURE_LENGTH | ( | len, | |
| p, | |||
| end ) |
Clamps a structure length against available buffer boundaries.
Definition at line 264 of file lazybios_internal.h.
| #define LAZYBIOS_DECODER_BUF_SIZE 1024 |
Scratch buffer size for the file-local decoders.
The longest decoding in the corpus is a Type 0 characteristics list at just over 500 bytes, so this leaves generous headroom; the decoded text is copied to an exact-sized allocation afterwards.
Definition at line 122 of file lazybios_internal.h.
| #define LAZYBIOS_MARK_ABSENT | ( | record, | |
| field ) |
Marks a parsed structure field as absent.
Definition at line 254 of file lazybios_internal.h.
| #define LAZYBIOS_MARK_PRESENT | ( | record, | |
| field ) |
Marks a parsed structure field as present and valid.
Definition at line 249 of file lazybios_internal.h.
| #define LAZYBIOS_MARK_UNREACHABLE | ( | record, | |
| field ) |
Marks a parsed structure field as unreachable (structure too short for newer spec version).
Definition at line 259 of file lazybios_internal.h.
| #define lb_dbg | ( | ... | ) |
Definition at line 63 of file lazybios_internal.h.
| #define lb_log | ( | ... | ) |
Definition at line 62 of file lazybios_internal.h.
| #define LINUX_SYSFS_DMI_TABLE "/sys/firmware/dmi/tables/DMI" |
Absolute path to the Linux sysfs DMI table.
Definition at line 148 of file lazybios_internal.h.
| #define LINUX_SYSFS_SMBIOS_ENTRY "/sys/firmware/dmi/tables/smbios_entry_point" |
Absolute path to the Linux sysfs SMBIOS entry point.
Definition at line 145 of file lazybios_internal.h.
| #define READSTR | ( | record, | |
| field, | |||
| len, | |||
| offset, | |||
| p, | |||
| end ) |
Definition at line 350 of file lazybios_internal.h.
| #define READU16 | ( | record, | |
| field, | |||
| len, | |||
| offset, | |||
| p ) |
Definition at line 374 of file lazybios_internal.h.
| #define READU32 | ( | record, | |
| field, | |||
| len, | |||
| offset, | |||
| p ) |
Definition at line 384 of file lazybios_internal.h.
| #define READU64 | ( | record, | |
| field, | |||
| len, | |||
| offset, | |||
| p ) |
Definition at line 394 of file lazybios_internal.h.
| #define READU8 | ( | record, | |
| field, | |||
| len, | |||
| offset, | |||
| p ) |
Definition at line 364 of file lazybios_internal.h.
| #define SMBIOS2_ANCHOR "_SM_" |
Definition at line 226 of file lazybios_internal.h.
| #define SMBIOS2_ANCHOR_OFFSET 0x00 |
Definition at line 228 of file lazybios_internal.h.
| #define SMBIOS2_ANCHOR_SIZE 4 |
Definition at line 244 of file lazybios_internal.h.
| #define SMBIOS2_BCD_REVISION_OFFSET 0x1E |
Definition at line 241 of file lazybios_internal.h.
| #define SMBIOS2_CHECKSUM_OFFSET 0x04 |
Definition at line 229 of file lazybios_internal.h.
| #define SMBIOS2_ENTRY_POINT_LENGTH 0x1F |
Definition at line 242 of file lazybios_internal.h.
| #define SMBIOS2_ENTRY_POINT_LENGTH_V21 0x1E |
Definition at line 243 of file lazybios_internal.h.
| #define SMBIOS2_FORMATTED_AREA_OFFSET 0x0B |
Definition at line 235 of file lazybios_internal.h.
| #define SMBIOS2_FORMATTED_AREA_SIZE 5 |
Definition at line 246 of file lazybios_internal.h.
| #define SMBIOS2_INTERMEDIATE_ANCHOR "_DMI_" |
Definition at line 227 of file lazybios_internal.h.
| #define SMBIOS2_INTERMEDIATE_ANCHOR_OFFSET 0x10 |
Definition at line 236 of file lazybios_internal.h.
| #define SMBIOS2_INTERMEDIATE_ANCHOR_SIZE 5 |
Definition at line 245 of file lazybios_internal.h.
| #define SMBIOS2_INTERMEDIATE_CHECKSUM_OFFSET 0x15 |
Definition at line 237 of file lazybios_internal.h.
| #define SMBIOS2_LENGTH_OFFSET 0x05 |
Definition at line 230 of file lazybios_internal.h.
| #define SMBIOS2_MAJOR_OFFSET 0x06 |
Definition at line 231 of file lazybios_internal.h.
| #define SMBIOS2_MAX_STRUCTURE_SIZE_OFFSET 0x08 |
Definition at line 233 of file lazybios_internal.h.
| #define SMBIOS2_MINOR_OFFSET 0x07 |
Definition at line 232 of file lazybios_internal.h.
| #define SMBIOS2_REVISION_OFFSET 0x0A |
Definition at line 234 of file lazybios_internal.h.
| #define SMBIOS2_STRUCTURE_COUNT_OFFSET 0x1C |
Definition at line 240 of file lazybios_internal.h.
| #define SMBIOS2_TABLE_ADDRESS_OFFSET 0x18 |
Definition at line 239 of file lazybios_internal.h.
| #define SMBIOS2_TABLE_LENGTH_OFFSET 0x16 |
Definition at line 238 of file lazybios_internal.h.
| #define SMBIOS3_ANCHOR "_SM3_" |
Definition at line 212 of file lazybios_internal.h.
| #define SMBIOS3_ANCHOR_OFFSET 0x00 |
Definition at line 213 of file lazybios_internal.h.
| #define SMBIOS3_ANCHOR_SIZE 5 |
Definition at line 224 of file lazybios_internal.h.
| #define SMBIOS3_CHECKSUM_OFFSET 0x05 |
Definition at line 214 of file lazybios_internal.h.
| #define SMBIOS3_DOCREV_OFFSET 0x09 |
Definition at line 218 of file lazybios_internal.h.
| #define SMBIOS3_ENTRY_POINT_LENGTH 0x18 |
Definition at line 223 of file lazybios_internal.h.
| #define SMBIOS3_LENGTH_OFFSET 0x06 |
Definition at line 215 of file lazybios_internal.h.
| #define SMBIOS3_MAJOR_OFFSET 0x07 |
Definition at line 216 of file lazybios_internal.h.
| #define SMBIOS3_MINOR_OFFSET 0x08 |
Definition at line 217 of file lazybios_internal.h.
| #define SMBIOS3_RESERVED_OFFSET 0x0B |
Definition at line 220 of file lazybios_internal.h.
| #define SMBIOS3_REVISION_OFFSET 0x0A |
Definition at line 219 of file lazybios_internal.h.
| #define SMBIOS3_TABLE_ADDRESS_OFFSET 0x10 |
Definition at line 222 of file lazybios_internal.h.
| #define SMBIOS3_TABLE_MAX_SIZE_OFFSET 0x0C |
Definition at line 221 of file lazybios_internal.h.
| #define SMBIOS_HEADER_SIZE 4 |
Size of an SMBIOS structure header (type, length, handle).
Definition at line 142 of file lazybios_internal.h.
| #define SMBIOS_OEM_DELL_TYPE177 177 |
Definition at line 207 of file lazybios_internal.h.
| #define SMBIOS_OEM_DELL_TYPE212 212 |
Definition at line 208 of file lazybios_internal.h.
| #define SMBIOS_OEM_DELL_TYPE218 218 |
Definition at line 209 of file lazybios_internal.h.
| #define SMBIOS_OEM_HP_TYPE204 204 |
Definition at line 203 of file lazybios_internal.h.
| #define SMBIOS_TYPE_32BIT_MEMORY_ERROR_INFORMATION 18 |
Definition at line 171 of file lazybios_internal.h.
| #define SMBIOS_TYPE_64BIT_MEMORY_ERROR_INFORMATION 33 |
Definition at line 186 of file lazybios_internal.h.
| #define SMBIOS_TYPE_ADDITIONAL_INFORMATION 40 |
Definition at line 193 of file lazybios_internal.h.
| #define SMBIOS_TYPE_BASEBOARD 2 |
Definition at line 155 of file lazybios_internal.h.
| #define SMBIOS_TYPE_BIOS 0 |
Definition at line 153 of file lazybios_internal.h.
| #define SMBIOS_TYPE_BOOT_INTEGRITY_SERVICES_ENTRY_POINT 31 |
Definition at line 184 of file lazybios_internal.h.
| #define SMBIOS_TYPE_BUILT_IN_POINTING_DEVICE 21 |
Definition at line 174 of file lazybios_internal.h.
| #define SMBIOS_TYPE_CACHES 7 |
Definition at line 160 of file lazybios_internal.h.
| #define SMBIOS_TYPE_CHASSIS 3 |
Definition at line 156 of file lazybios_internal.h.
| #define SMBIOS_TYPE_COOLING_DEVICE 27 |
Definition at line 180 of file lazybios_internal.h.
| #define SMBIOS_TYPE_ELECTRICAL_CURRENT_PROBE 29 |
Definition at line 182 of file lazybios_internal.h.
| #define SMBIOS_TYPE_END 127 |
Definition at line 200 of file lazybios_internal.h.
| #define SMBIOS_TYPE_FIRMWARE_INVENTORY_INFORMATION 45 |
Definition at line 198 of file lazybios_internal.h.
| #define SMBIOS_TYPE_FIRMWARE_LANGUAGE_INFORMATION 13 |
Definition at line 166 of file lazybios_internal.h.
| #define SMBIOS_TYPE_GROUP_ASSOCIATIONS 14 |
Definition at line 167 of file lazybios_internal.h.
| #define SMBIOS_TYPE_HARDWARE_SECURITY 24 |
Definition at line 177 of file lazybios_internal.h.
| #define SMBIOS_TYPE_IPMI_DEVICE_INFORMATION 38 |
Definition at line 191 of file lazybios_internal.h.
| #define SMBIOS_TYPE_MANAGEMENT_CONTROLLER_HOST_INTERFACE 42 |
Definition at line 195 of file lazybios_internal.h.
| #define SMBIOS_TYPE_MANAGEMENT_DEVICE 34 |
Definition at line 187 of file lazybios_internal.h.
| #define SMBIOS_TYPE_MANAGEMENT_DEVICE_COMPONENT 35 |
Definition at line 188 of file lazybios_internal.h.
| #define SMBIOS_TYPE_MANAGEMENT_DEVICE_THRESHOLD_DATA 36 |
Definition at line 189 of file lazybios_internal.h.
| #define SMBIOS_TYPE_MEMORY_ARRAY_MAPPED_ADDRESS 19 |
Definition at line 172 of file lazybios_internal.h.
| #define SMBIOS_TYPE_MEMORY_CHANNEL 37 |
Definition at line 190 of file lazybios_internal.h.
| #define SMBIOS_TYPE_MEMORY_CONTROLLER 5 |
Definition at line 158 of file lazybios_internal.h.
| #define SMBIOS_TYPE_MEMORY_DEVICE 17 |
Definition at line 170 of file lazybios_internal.h.
| #define SMBIOS_TYPE_MEMORY_DEVICE_MAPPED_ADDRESS 20 |
Definition at line 173 of file lazybios_internal.h.
| #define SMBIOS_TYPE_MEMORY_MODULE 6 |
Definition at line 159 of file lazybios_internal.h.
| #define SMBIOS_TYPE_OEM_STRINGS 11 |
Definition at line 164 of file lazybios_internal.h.
| #define SMBIOS_TYPE_ONBOARD_DEVICES 10 |
Definition at line 163 of file lazybios_internal.h.
| #define SMBIOS_TYPE_ONBOARD_DEVICES_EXTENDED_INFORMATION 41 |
Definition at line 194 of file lazybios_internal.h.
| #define SMBIOS_TYPE_OUT_OF_BAND_REMOTE_ACCESS 30 |
Definition at line 183 of file lazybios_internal.h.
| #define SMBIOS_TYPE_PHYSICAL_MEMORY_ARRAY 16 |
Definition at line 169 of file lazybios_internal.h.
| #define SMBIOS_TYPE_PORT_CONNECTOR 8 |
Definition at line 161 of file lazybios_internal.h.
| #define SMBIOS_TYPE_PORTABLE_BATTERY 22 |
Definition at line 175 of file lazybios_internal.h.
| #define SMBIOS_TYPE_PROCESSOR 4 |
Definition at line 157 of file lazybios_internal.h.
| #define SMBIOS_TYPE_PROCESSOR_ADDITIONAL_INFORMATION 44 |
Definition at line 197 of file lazybios_internal.h.
| #define SMBIOS_TYPE_STRING_PROPERTY 46 |
Definition at line 199 of file lazybios_internal.h.
| #define SMBIOS_TYPE_SYSTEM 1 |
Definition at line 154 of file lazybios_internal.h.
| #define SMBIOS_TYPE_SYSTEM_BOOT_INFORMATION 32 |
Definition at line 185 of file lazybios_internal.h.
| #define SMBIOS_TYPE_SYSTEM_CONFIGURATION_OPTIONS 12 |
Definition at line 165 of file lazybios_internal.h.
| #define SMBIOS_TYPE_SYSTEM_EVENT_LOG 15 |
Definition at line 168 of file lazybios_internal.h.
| #define SMBIOS_TYPE_SYSTEM_POWER_CONTROLS 25 |
Definition at line 178 of file lazybios_internal.h.
| #define SMBIOS_TYPE_SYSTEM_POWER_SUPPLY 39 |
Definition at line 192 of file lazybios_internal.h.
| #define SMBIOS_TYPE_SYSTEM_RESET 23 |
Definition at line 176 of file lazybios_internal.h.
| #define SMBIOS_TYPE_SYSTEM_SLOTS 9 |
Definition at line 162 of file lazybios_internal.h.
| #define SMBIOS_TYPE_TEMPERATURE_PROBE 28 |
Definition at line 181 of file lazybios_internal.h.
| #define SMBIOS_TYPE_TPM_DEVICE 43 |
Definition at line 196 of file lazybios_internal.h.
| #define SMBIOS_TYPE_VOLTAGE_PROBE 26 |
Definition at line 179 of file lazybios_internal.h.
| const uint8_t * DMINext | ( | const uint8_t * | p, |
| const uint8_t * | end ) |
| const char * DMIString | ( | const uint8_t * | p, |
| uint8_t | length, | ||
| uint8_t | index, | ||
| const uint8_t * | end ) |
Copies a string from an SMBIOS structure's string-set.
| p | Start of the SMBIOS structure. |
| length | Length of the structure's formatted section. |
| index | One-based index of the requested string. |
| end | Address of the next structure, as returned by DMINext, which is two bytes past this structure's string-set terminator. |
References DMIString(), index, and length.
Referenced by DMIString().
|
inlinestatic |
Definition at line 43 of file lazybios_internal.h.
References fmt, and lazybios_log_internal().
Referenced by lazybios_log_internal().
| size_t lazybiosCountStructsByType | ( | const lazybiosDMI_t * | DMIData, |
| uint8_t | target_type ) |
Counts SMBIOS structures having a specified type identifier.
| DMIData | Raw DMI table container to inspect. |
| target_type | SMBIOS structure type identifier to count. |
References lazybiosCountStructsByType().
Referenced by lazybiosCountStructsByType().
|
inlinestatic |
Appends formatted text to a decoder output buffer.
snprintf returns the length the output would have had, so accumulating its return value lets the running length run past the buffer: the next append then writes at buf + len with a wrapped-around buf_len - len. This keeps *len at the number of bytes actually written, never above buf_len - 1, so later appends and the trailing-separator trim stay inside the buffer.
| buf | Output buffer, may be NULL only when buf_len is zero. |
| buf_len | Capacity of buf in bytes. |
| len | Running output length, updated in place. |
| fmt | printf-style format for the text to append. |
Definition at line 85 of file lazybios_internal.h.
References fmt, and lazybiosDecoderAppend().
Referenced by lazybiosDecoderAppend().
|
inlinestatic |
Duplicates a NUL-terminated string with malloc.
strdup is POSIX rather than C99, so the parsers use this when storing a decoded string that the record owns.
| src | String to copy, may be NULL. |
Definition at line 133 of file lazybios_internal.h.
References lazybiosDup().
Referenced by lazybiosDup().
| LAZYBIOS_WARN_UNUSED int lazybiosFile | ( | lazybiosCTX_t * | ctx, |
| const char * | entry_path, | ||
| const char * | dmi_path ) |
Loads an SMBIOS entry point and DMI table from separate files.
| ctx | Context that receives the loaded data. |
| entry_path | Path to the raw SMBIOS entry point file. |
| dmi_path | Path to the raw DMI structure table file. |
References LAZYBIOS_WARN_UNUSED, and lazybiosFile().
Referenced by lazybiosFile().
| int lazybiosFindSMBIOSEntryPoint | ( | const uint8_t * | image, |
| size_t | image_len, | ||
| size_t * | entry_offset, | ||
| size_t * | entry_len ) |
Finds a valid SMBIOS entry point within a memory image.
References lazybiosFindSMBIOSEntryPoint().
Referenced by lazybiosFindSMBIOSEntryPoint().
| int lazybiosGetSingleFileLayout | ( | const uint8_t * | entry_data, |
| size_t | available, | ||
| size_t | file_len, | ||
| size_t * | entry_len, | ||
| size_t * | table_offset, | ||
| size_t * | table_len ) |
Determines the entry-point and table layout in a combined dump file.
References lazybiosGetSingleFileLayout().
Referenced by lazybiosGetSingleFileLayout().
| int lazybiosGetSMBIOSTableLocation | ( | const uint8_t * | entry_data, |
| size_t | available, | ||
| size_t * | entry_len, | ||
| uint64_t * | table_address, | ||
| size_t * | table_len ) |
Extracts an SMBIOS table address and length from an entry point.
References lazybiosGetSMBIOSTableLocation().
Referenced by lazybiosGetSMBIOSTableLocation().
| int lazybiosInspectEntryPoint | ( | const uint8_t * | entry_data, |
| size_t | available, | ||
| lazybiosEntryInspection * | inspection ) |
Inspects and validates an SMBIOS 2.x or 3.x entry point.
References lazybiosInspectEntryPoint().
Referenced by lazybiosInspectEntryPoint().
| int lazybiosLoadRawBuffers | ( | lazybiosCTX_t * | ctx, |
| const uint8_t * | entry_data, | ||
| size_t | entry_len, | ||
| const uint8_t * | dmi_data, | ||
| size_t | dmi_len ) |
Copies validated raw entry-point and DMI-table buffers into a context.
References lazybiosLoadRawBuffers().
Referenced by lazybiosLoadRawBuffers().
| int lazybiosLoadWindowsRawSMBIOSData | ( | lazybiosCTX_t * | ctx, |
| const uint8_t * | raw_data, | ||
| size_t | raw_len ) |
Loads the Windows raw SMBIOS table format into a context.
References lazybiosLoadWindowsRawSMBIOSData().
Referenced by lazybiosLoadWindowsRawSMBIOSData().
| int lazybiosParseEntry | ( | lazybiosCTX_t * | ctx, |
| const uint8_t * | entry_buf, | ||
| size_t | buf_len ) |
Validates and identifies an SMBIOS entry point.
| ctx | Context whose entry tag and tagged union are updated. |
| entry_buf | Buffer containing an SMBIOS 2.x or 3.x entry point. |
| buf_len | Length of entry_buf in bytes. |
References lazybiosParseEntry().
Referenced by lazybiosParseEntry().
| LAZYBIOS_WARN_UNUSED int lazybiosSingleFile | ( | lazybiosCTX_t * | ctx, |
| const char * | bin_path ) |
Loads SMBIOS entry point and DMI data from one merged file.
| ctx | Context that receives the loaded data. |
| bin_path | Path to a file containing the entry point and DMI table, either concatenated or separated by an advertised file-relative offset. |
References LAZYBIOS_WARN_UNUSED, and lazybiosSingleFile().
Referenced by lazybiosSingleFile().