iPXE
Macros | Functions | Variables
smbios_settings.c File Reference
#include <stdint.h>
#include <string.h>
#include <errno.h>
#include <ipxe/settings.h>
#include <ipxe/init.h>
#include <ipxe/uuid.h>
#include <ipxe/smbios.h>

Go to the source code of this file.

Macros

#define SMBIOS_RAW_TAG(_type, _structure, _field)
 Construct SMBIOS raw-data tag. More...
 
#define SMBIOS_STRING_TAG(_type, _structure, _field)
 Construct SMBIOS string tag. More...
 

Functions

 FILE_LICENCE (GPL2_OR_LATER_OR_UBDL)
 
static int smbios_applies (struct settings *settings __unused, const struct setting *setting)
 Check applicability of SMBIOS setting. More...
 
static int smbios_fetch (struct settings *settings __unused, struct setting *setting, void *data, size_t len)
 Fetch value of SMBIOS setting. More...
 
static void smbios_init (void)
 Initialise SMBIOS settings. More...
 
struct init_fn smbios_init_fn __init_fn (INIT_NORMAL)
 SMBIOS settings initialiser. More...
 
const struct setting uuid_setting __setting (SETTING_HOST, uuid)
 UUID setting obtained via SMBIOS. More...
 
const struct setting manufacturer_setting __setting (SETTING_HOST_EXTRA, manufacturer)
 Manufacturer name setting. More...
 
const struct setting product_setting __setting (SETTING_HOST_EXTRA, product)
 Product name setting. More...
 
const struct setting serial_setting __setting (SETTING_HOST_EXTRA, serial)
 Serial number setting. More...
 
const struct setting asset_setting __setting (SETTING_HOST_EXTRA, asset)
 Asset tag setting. More...
 
const struct setting board_serial_setting __setting (SETTING_HOST_EXTRA, board-serial)
 Board serial number setting (may differ from chassis serial number) More...
 

Variables

static const struct settings_scope smbios_settings_scope
 SMBIOS settings scope. More...
 
static struct settings_operations smbios_settings_operations
 SMBIOS settings operations. More...
 
static struct settings smbios_settings
 SMBIOS settings. More...
 

Macro Definition Documentation

◆ SMBIOS_RAW_TAG

#define SMBIOS_RAW_TAG (   _type,
  _structure,
  _field 
)
Value:
( ( (_type) << 16 ) | \
( offsetof ( _structure, _field ) << 8 ) | \
( sizeof ( ( ( _structure * ) 0 )->_field ) ) )
#define offsetof(type, field)
Get offset of a field within a structure.
Definition: stddef.h:24

Construct SMBIOS raw-data tag.

Parameters
_typeSMBIOS structure type number
_structureSMBIOS structure data type
_fieldField within SMBIOS structure data type
Return values
tagSMBIOS setting tag

Definition at line 45 of file smbios_settings.c.

◆ SMBIOS_STRING_TAG

#define SMBIOS_STRING_TAG (   _type,
  _structure,
  _field 
)
Value:
( ( (_type) << 16 ) | \
( offsetof ( _structure, _field ) << 8 ) )
#define offsetof(type, field)
Get offset of a field within a structure.
Definition: stddef.h:24

Construct SMBIOS string tag.

Parameters
_typeSMBIOS structure type number
_structureSMBIOS structure data type
_fieldField within SMBIOS structure data type
Return values
tagSMBIOS setting tag

Definition at line 58 of file smbios_settings.c.

Function Documentation

◆ FILE_LICENCE()

FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL  )

◆ smbios_applies()

static int smbios_applies ( struct settings *settings  __unused,
const struct setting setting 
)
static

Check applicability of SMBIOS setting.

Parameters
settingsSettings block
settingSetting
Return values
appliesSetting applies within this settings block

Definition at line 69 of file smbios_settings.c.

70  {
71 
72  return ( setting->scope == &smbios_settings_scope );
73 }
A setting.
Definition: settings.h:23
static const struct settings_scope smbios_settings_scope
SMBIOS settings scope.
const struct settings_scope * scope
Setting scope (or NULL)
Definition: settings.h:49

References setting::scope, and smbios_settings_scope.

◆ smbios_fetch()

static int smbios_fetch ( struct settings *settings  __unused,
struct setting setting,
void *  data,
size_t  len 
)
static

Fetch value of SMBIOS setting.

Parameters
settingsSettings block, or NULL to search all blocks
settingSetting to fetch
dataBuffer to fill with setting data
lenLength of buffer
Return values
lenLength of setting data, or negative error

Definition at line 84 of file smbios_settings.c.

86  {
87  struct smbios_structure structure;
88  unsigned int tag_instance;
89  unsigned int tag_type;
90  unsigned int tag_offset;
91  unsigned int tag_len;
92  int rc;
93 
94  /* Split tag into instance, type, offset and length */
95  tag_instance = ( ( setting->tag >> 24 ) & 0xff );
96  tag_type = ( ( setting->tag >> 16 ) & 0xff );
97  tag_offset = ( ( setting->tag >> 8 ) & 0xff );
98  tag_len = ( setting->tag & 0xff );
99 
100  /* Find SMBIOS structure */
101  if ( ( rc = find_smbios_structure ( tag_type, tag_instance,
102  &structure ) ) != 0 )
103  return rc;
104 
105  {
106  uint8_t buf[structure.header.len];
107  const void *raw;
108  union uuid uuid;
109  unsigned int index;
110 
111  /* Read SMBIOS structure */
112  if ( ( rc = read_smbios_structure ( &structure, buf,
113  sizeof ( buf ) ) ) != 0 )
114  return rc;
115 
116  /* A <length> of zero indicates that the byte at
117  * <offset> contains a string index. An <offset> of
118  * zero indicates that the <length> contains a literal
119  * string index.
120  */
121  if ( ( tag_len == 0 ) || ( tag_offset == 0 ) ) {
122  index = ( ( tag_offset == 0 ) ?
123  tag_len : buf[tag_offset] );
124  if ( ( rc = read_smbios_string ( &structure, index,
125  data, len ) ) < 0 ) {
126  return rc;
127  }
128  if ( ! setting->type )
129  setting->type = &setting_type_string;
130  return rc;
131  }
132 
133  /* Mangle UUIDs if necessary. iPXE treats UUIDs as
134  * being in network byte order (big-endian). SMBIOS
135  * specification version 2.6 states that UUIDs are
136  * stored with little-endian values in the first three
137  * fields; earlier versions did not specify an
138  * endianness. dmidecode assumes that the byte order
139  * is little-endian if and only if the SMBIOS version
140  * is 2.6 or higher; we match this behaviour.
141  */
142  raw = &buf[tag_offset];
143  if ( ( ( setting->type == &setting_type_uuid ) ||
144  ( setting->type == &setting_type_guid ) ) &&
145  ( tag_len == sizeof ( uuid ) ) &&
146  ( smbios_version() >= SMBIOS_VERSION ( 2, 6 ) ) ) {
147  DBG ( "SMBIOS detected mangled UUID\n" );
148  memcpy ( &uuid, &buf[tag_offset], sizeof ( uuid ) );
149  uuid_mangle ( &uuid );
150  raw = &uuid;
151  }
152 
153  /* Return data */
154  if ( len > tag_len )
155  len = tag_len;
156  memcpy ( data, raw, len );
157  if ( ! setting->type )
158  setting->type = &setting_type_hex;
159  return tag_len;
160  }
161 }
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
A universally unique ID.
Definition: uuid.h:15
int read_smbios_structure(struct smbios_structure *structure, void *data, size_t len)
Copy SMBIOS structure.
Definition: smbios.c:241
static void uuid_mangle(union uuid *uuid)
Change UUID endianness.
Definition: uuid.h:43
uint64_t tag
Setting tag, if applicable.
Definition: settings.h:43
void * memcpy(void *dest, const void *src, size_t len) __nonnull
int find_smbios_structure(unsigned int type, unsigned int instance, struct smbios_structure *structure)
Find specific structure type within SMBIOS.
Definition: smbios.c:170
uint8_t uuid[16]
UUID.
Definition: smbios.h:22
int smbios_version(void)
Get SMBIOS version.
Definition: smbios.c:299
int read_smbios_string(struct smbios_structure *structure, unsigned int index, void *data, size_t len)
Find indexed string within SMBIOS structure.
Definition: smbios.c:261
const struct setting_type * type
Setting type.
Definition: settings.h:36
#define SMBIOS_VERSION(major, minor)
Calculate SMBIOS version.
Definition: smbios.h:225
unsigned char uint8_t
Definition: stdint.h:10
A setting.
Definition: settings.h:23
uint32_t len
Length.
Definition: ena.h:14
uint8_t data[48]
Additional event data.
Definition: ena.h:22
__be32 raw[7]
Definition: CIB_PRM.h:28
uint64_t index
Index of the first segment within the content.
Definition: pccrc.h:21
#define DBG(...)
Print a debugging message.
Definition: compiler.h:498
SMBIOS structure descriptor.
Definition: smbios.h:129

References data, DBG, find_smbios_structure(), smbios_structure::header, index, len, smbios_header::len, memcpy(), raw, rc, read_smbios_string(), read_smbios_structure(), SMBIOS_VERSION, smbios_version(), setting::tag, setting::type, uuid, and uuid_mangle().

◆ smbios_init()

static void smbios_init ( void  )
static

Initialise SMBIOS settings.

Definition at line 179 of file smbios_settings.c.

179  {
180  int rc;
181 
183  "smbios" ) ) != 0 ) {
184  DBG ( "SMBIOS could not register settings: %s\n",
185  strerror ( rc ) );
186  return;
187  }
188 }
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
static struct settings smbios_settings
SMBIOS settings.
char * strerror(int errno)
Retrieve string representation of error number.
Definition: strerror.c:78
int register_settings(struct settings *settings, struct settings *parent, const char *name)
Register settings block.
Definition: settings.c:475
#define DBG(...)
Print a debugging message.
Definition: compiler.h:498
#define NULL
NULL pointer (VOID *)
Definition: Base.h:321

References DBG, NULL, rc, register_settings(), smbios_settings, and strerror().

◆ __init_fn()

struct init_fn smbios_init_fn __init_fn ( INIT_NORMAL  )

SMBIOS settings initialiser.

◆ __setting() [1/6]

const struct setting uuid_setting __setting ( SETTING_HOST  ,
uuid   
)

UUID setting obtained via SMBIOS.

◆ __setting() [2/6]

const struct setting manufacturer_setting __setting ( SETTING_HOST_EXTRA  ,
manufacturer   
)

Manufacturer name setting.

◆ __setting() [3/6]

const struct setting product_setting __setting ( SETTING_HOST_EXTRA  ,
product   
)

Product name setting.

◆ __setting() [4/6]

const struct setting serial_setting __setting ( SETTING_HOST_EXTRA  ,
serial   
)

Serial number setting.

◆ __setting() [5/6]

const struct setting asset_setting __setting ( SETTING_HOST_EXTRA  ,
asset   
)

Asset tag setting.

◆ __setting() [6/6]

const struct setting board_serial_setting __setting ( SETTING_HOST_EXTRA  ,
board-  serial 
)

Board serial number setting (may differ from chassis serial number)

Variable Documentation

◆ smbios_settings_scope

const struct settings_scope smbios_settings_scope
static

SMBIOS settings scope.

Definition at line 35 of file smbios_settings.c.

Referenced by smbios_applies().

◆ smbios_settings_operations

struct settings_operations smbios_settings_operations
static
Initial value:
= {
.applies = smbios_applies,
.fetch = smbios_fetch,
}
static int smbios_fetch(struct settings *settings __unused, struct setting *setting, void *data, size_t len)
Fetch value of SMBIOS setting.
static int smbios_applies(struct settings *settings __unused, const struct setting *setting)
Check applicability of SMBIOS setting.

SMBIOS settings operations.

Definition at line 164 of file smbios_settings.c.

◆ smbios_settings

struct settings smbios_settings
static
Initial value:
= {
.refcnt = NULL,
.default_scope = &smbios_settings_scope,
}
static struct settings smbios_settings
SMBIOS settings.
struct list_head siblings
Sibling settings blocks.
Definition: settings.h:140
struct list_head children
Child settings blocks.
Definition: settings.h:142
static struct settings_operations smbios_settings_operations
SMBIOS settings operations.
static const struct settings_scope smbios_settings_scope
SMBIOS settings scope.
#define LIST_HEAD_INIT(list)
Initialise a static list head.
Definition: list.h:30
#define NULL
NULL pointer (VOID *)
Definition: Base.h:321

SMBIOS settings.

Definition at line 170 of file smbios_settings.c.

Referenced by smbios_init().