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  * Since the byte at offset zero can never contain a
122  * string index, and a literal string index can never
123  * be zero, the combination of both <length> and
124  * <offset> being zero indicates that the entire
125  * structure is to be read.
126  */
127  if ( ( tag_len == 0 ) && ( tag_offset == 0 ) ) {
128  tag_len = sizeof ( buf );
129  } else if ( ( tag_len == 0 ) || ( tag_offset == 0 ) ) {
130  index = ( ( tag_offset == 0 ) ?
131  tag_len : buf[tag_offset] );
132  if ( ( rc = read_smbios_string ( &structure, index,
133  data, len ) ) < 0 ) {
134  return rc;
135  }
136  if ( ! setting->type )
137  setting->type = &setting_type_string;
138  return rc;
139  }
140 
141  /* Limit length */
142  if ( tag_offset > sizeof ( buf ) ) {
143  tag_len = 0;
144  } else if ( ( tag_offset + tag_len ) > sizeof ( buf ) ) {
145  tag_len = ( sizeof ( buf ) - tag_offset );
146  }
147 
148  /* Mangle UUIDs if necessary. iPXE treats UUIDs as
149  * being in network byte order (big-endian). SMBIOS
150  * specification version 2.6 states that UUIDs are
151  * stored with little-endian values in the first three
152  * fields; earlier versions did not specify an
153  * endianness. dmidecode assumes that the byte order
154  * is little-endian if and only if the SMBIOS version
155  * is 2.6 or higher; we match this behaviour.
156  */
157  raw = &buf[tag_offset];
158  if ( ( ( setting->type == &setting_type_uuid ) ||
159  ( setting->type == &setting_type_guid ) ) &&
160  ( tag_len == sizeof ( uuid ) ) &&
161  ( smbios_version() >= SMBIOS_VERSION ( 2, 6 ) ) ) {
162  DBG ( "SMBIOS detected mangled UUID\n" );
163  memcpy ( &uuid, &buf[tag_offset], sizeof ( uuid ) );
164  uuid_mangle ( &uuid );
165  raw = &uuid;
166  }
167 
168  /* Return data */
169  if ( len > tag_len )
170  len = tag_len;
171  memcpy ( data, raw, len );
172  if ( ! setting->type )
173  setting->type = &setting_type_hex;
174  return tag_len;
175  }
176 }
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
long index
Definition: bigint.h:62
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:226
unsigned char uint8_t
Definition: stdint.h:10
A setting.
Definition: settings.h:23
uint8_t data[48]
Additional event data.
Definition: ena.h:22
__be32 raw[7]
Definition: CIB_PRM.h:28
#define DBG(...)
Print a debugging message.
Definition: compiler.h:498
uint32_t len
Length.
Definition: ena.h:14
SMBIOS structure descriptor.
Definition: smbios.h:130

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 194 of file smbios_settings.c.

194  {
195  int rc;
196 
198  "smbios" ) ) != 0 ) {
199  DBG ( "SMBIOS could not register settings: %s\n",
200  strerror ( rc ) );
201  return;
202  }
203 }
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 179 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 185 of file smbios_settings.c.

Referenced by smbios_init().