libfru 2.1
FRU Manupulation Library
Loading...
Searching...
No Matches
Macros | Functions | Variables
fru.c File Reference

FRU information encoding functions. More...

#include "fru.h"
#include "smbios.h"
#include <ctype.h>
#include <stdio.h>
#include <stdint.h>
#include <string.h>
#include <stdlib.h>
#include <stddef.h>
#include <time.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>
#include <errno.h>
#include <inttypes.h>
#include "fru-errno.h"
Include dependency graph for fru.c:

Macros

#define _BSD_SOURCE
 
#define DEBUG(f, args...)
 
#define UUID_SIZE   16
 
#define UUID_STRLEN_NONDASHED   (UUID_SIZE * 2)
 
#define UUID_STRLEN_DASHED   (UUID_STRLEN_NONDASHED + 4)
 
#define AREA(NAME)
 

Functions

void fru_loadfield (decoded_field_t *field, const char *s, field_type_t enc)
 
bool fru_decode_data (fru_field_t *field, decoded_field_t *out)
 
int fru_area_checksum (fru_info_area_t *area)
 
fru_internal_use_area_t * fru_encode_internal_use_area (const void *data, uint8_t *blocks)
 
fru_chassis_area_t * fru_encode_chassis_info (fru_exploded_chassis_t *chassis)
 
bool fru_decode_chassis_info (const fru_chassis_area_t *area, fru_exploded_chassis_t *chassis_out)
 
fru_board_area_t * fru_encode_board_info (fru_exploded_board_t *board)
 
bool fru_decode_board_info (const fru_board_area_t *area, fru_exploded_board_t *board_out)
 
fru_product_area_t * fru_encode_product_info (fru_exploded_product_t *product)
 
union __attribute__ ((packed))
 
int fru_mr_hexstr2rec (fru_mr_rec_t **rec, const char *str, fru_mr_type_t type)
 
int fru_mr_mgmt_str2rec (fru_mr_rec_t **rec, const char *str, fru_mr_mgmt_type_t type)
 
int fru_mr_uuid2rec (fru_mr_rec_t **rec, const char *str)
 
int fru_mr_rec2uuid (char **str, fru_mr_mgmt_rec_t *mgmt, fru_flags_t flags)
 
int fru_mr_mgmt_rec2str (char **str, fru_mr_mgmt_rec_t *mgmt, fru_flags_t flags)
 
int fru_mr_rec2hexstr (char **str, fru_mr_rec_t *rec, fru_flags_t flags)
 
fru_mr_area_t * fru_encode_mr_area (fru_mr_reclist_t *reclist, size_t *total)
 
bool fru_decode_product_info (const fru_product_area_t *area, fru_exploded_product_t *product_out)
 
fru_t * fru_create (fru_area_t area[FRU_MAX_AREAS], size_t *size)
 
fru_t * find_fru_header (uint8_t *buffer, size_t size, fru_flags_t flags)
 
 AREA (chassis)
 
 AREA (board)
 
 AREA (product)
 
fru_internal_use_area_t * find_fru_internal_use_area (uint8_t *buffer, size_t *iu_size, size_t size, fru_flags_t flags)
 
fru_mr_area_t * find_fru_mr_area (uint8_t *buffer, size_t *mr_size, size_t size, fru_flags_t flags)
 
int fru_decode_mr_area (const fru_mr_area_t *area, fru_mr_reclist_t **reclist, size_t mr_size, fru_flags_t flags)
 
bool fru_decode_internal_use_area (const fru_internal_use_area_t *area, size_t area_len, char **out, fru_flags_t flags __attribute__((unused)))
 
const char * fru_enc_name_by_type (field_type_t type)
 
field_type_t fru_enc_type_by_name (const char *name)
 

Variables

 fru_uuid_t
 

Detailed Description

FRU information encoding functions.

Copyright (C) 2016-2023 Alexander Amelkin alexa.nosp@m.nder.nosp@m.@amel.nosp@m.kin..nosp@m.msk.r.nosp@m.u SPDX-License-Identifier: LGPL-2.0-or-later OR Apache-2.0

Macro Definition Documentation

◆ _BSD_SOURCE

#define _BSD_SOURCE

◆ AREA

#define AREA (   NAME)

◆ DEBUG

#define DEBUG (   f,
  args... 
)

◆ UUID_SIZE

#define UUID_SIZE   16

◆ UUID_STRLEN_DASHED

#define UUID_STRLEN_DASHED   (UUID_STRLEN_NONDASHED + 4)

◆ UUID_STRLEN_NONDASHED

#define UUID_STRLEN_NONDASHED   (UUID_SIZE * 2)

Function Documentation

◆ __attribute__()

union __attribute__ ( (packed)  )

◆ AREA() [1/3]

AREA ( board  )

◆ AREA() [2/3]

AREA ( chassis  )

◆ AREA() [3/3]

AREA ( product  )

◆ find_fru_header()

fru_t * find_fru_header ( uint8_t *  buffer,
size_t  size,
fru_flags_t  flags 
)

References FEHDRVER, FETOOSMALL, and fru_errno.

Referenced by find_fru_internal_use_area(), and find_fru_mr_area().

Here is the caller graph for this function:

◆ find_fru_internal_use_area()

fru_internal_use_area_t * find_fru_internal_use_area ( uint8_t *  buffer,
size_t *  iu_size,
size_t  size,
fru_flags_t  flags 
)

References FEAREAVER, find_fru_header(), and fru_errno.

Referenced by load_from_binary_file().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ find_fru_mr_area()

fru_mr_area_t * find_fru_mr_area ( uint8_t *  buffer,
size_t *  mr_size,
size_t  size,
fru_flags_t  flags 
)

References find_fru_header(), and fru_errno.

Referenced by load_from_binary_file().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ fru_area_checksum()

int fru_area_checksum ( fru_info_area_t *  area)

Calculate an area checksum

Calculation includes the checksum byte itself. For freshly prepared area this method returns a checksum to be stored in the last byte. For a pre-existing area this method returns zero if checksum is ok or non-zero otherwise.

◆ fru_create()

fru_t * fru_create ( fru_area_t  area[FRU_MAX_AREAS],
size_t *  size 
)

Create a FRU information file.

Parameters
[in]areaThe array of 5 areas, each may be NULL. Areas must be given in the FRU order, which is: internal use, chassis, board, product, multirecord
[out]sizeOn success, the size of the newly created FRU information buffer, in 8-byte blocks
Returns
fru_t * buffer, a newly allocated buffer containing the created FRU information file

References DEBUG, FEAREABADTYPE, and fru_errno.

Referenced by save_to_binary_file().

Here is the caller graph for this function:

◆ fru_decode_board_info()

bool fru_decode_board_info ( const fru_board_area_t *  area,
fru_exploded_board_t *  board_out 
)

Referenced by load_from_binary_file().

Here is the caller graph for this function:

◆ fru_decode_chassis_info()

bool fru_decode_chassis_info ( const fru_chassis_area_t *  area,
fru_exploded_chassis_t *  chassis_out 
)

Referenced by load_from_binary_file().

Here is the caller graph for this function:

◆ fru_decode_data()

bool fru_decode_data ( fru_field_t *  field,
decoded_field_t *  out 
)

References DEBUG, and fru_enc_name_by_type().

Here is the call graph for this function:

◆ fru_decode_internal_use_area()

bool fru_decode_internal_use_area ( const fru_internal_use_area_t *  area,
size_t  area_len,
char **  out,
fru_flags_t flags   __attribute__(unused) 
)

References fru_errno.

Referenced by load_from_binary_file().

Here is the caller graph for this function:

◆ fru_decode_mr_area()

int fru_decode_mr_area ( const fru_mr_area_t *  area,
fru_mr_reclist_t **  reclist,
size_t  mr_size,
fru_flags_t  flags 
)

References fru_errno.

Referenced by load_from_binary_file().

Here is the caller graph for this function:

◆ fru_decode_product_info()

bool fru_decode_product_info ( const fru_product_area_t *  area,
fru_exploded_product_t *  product_out 
)

Referenced by load_from_binary_file().

Here is the caller graph for this function:

◆ fru_enc_name_by_type()

const char * fru_enc_name_by_type ( field_type_t  type)

Referenced by arg_to_fieldopt(), fru_decode_data(), and save_to_text_file().

Here is the caller graph for this function:

◆ fru_enc_type_by_name()

field_type_t fru_enc_type_by_name ( const char *  name)

Referenced by arg_to_fieldopt().

Here is the caller graph for this function:

◆ fru_encode_board_info()

fru_board_area_t * fru_encode_board_info ( fru_exploded_board_t *  board)

Allocate and build a Board Information Area block.

The function will allocate a buffer of size that is a muliple of 8 bytes and is big enough to accomodate the standard area header, all the mandatory fields, all the supplied custom fields, the required padding and a checksum byte.

The mandatory fields will be encoded as fits best. The custom fields will be used as is (pre-encoded).

It is safe to free (deallocate) any arguments supplied to this function immediately after the call as all the data is copied to the new buffer.

Don't forget to free() the returned buffer when you don't need it anymore.

Parameters
[in]boardExploded board information area
Returns
fru_info_area_t *area A newly allocated buffer containing the created area

Referenced by save_to_binary_file().

Here is the caller graph for this function:

◆ fru_encode_chassis_info()

fru_chassis_area_t * fru_encode_chassis_info ( fru_exploded_chassis_t *  chassis)

Allocate and build a Chassis Information Area block.

The function will allocate a buffer of size that is a muliple of 8 bytes and is big enough to accomodate the standard area header, all the mandatory fields, all the supplied custom fields, the required padding and a checksum byte.

The mandatory fields will be encoded as fits best. The custom fields will be used as is (pre-encoded).

It is safe to free (deallocate) any arguments supplied to this function immediately after the call as all the data is copied to the new buffer.

Don't forget to free() the returned buffer when you don't need it anymore.

Parameters
[in]chassisExploded chassis info area
Returns
fru_info_area_T *area A newly allocated buffer containing the created area

References FEINVCHAS, fru_errno, and SMBIOS_CHASSIS_IS_VALID.

Referenced by save_to_binary_file().

Here is the caller graph for this function:

◆ fru_encode_internal_use_area()

fru_internal_use_area_t * fru_encode_internal_use_area ( const void *  data,
uint8_t *  blocks 
)

References FEHEXLEN, and fru_errno.

Referenced by save_to_binary_file(), and save_to_text_file().

Here is the caller graph for this function:

◆ fru_encode_mr_area()

fru_mr_area_t * fru_encode_mr_area ( fru_mr_reclist_t *  reclist,
size_t *  total 
)

References fru_errno.

Referenced by save_to_binary_file().

Here is the caller graph for this function:

◆ fru_encode_product_info()

fru_product_area_t * fru_encode_product_info ( fru_exploded_product_t *  product)

Allocate and build a Product Information Area block.

The function will allocate a buffer of size that is a muliple of 8 bytes and is big enough to accomodate the standard area header, all the mandatory fields, all the supplied custom fields, the required padding and a checksum byte.

The mandatory fields will be encoded as fits best. The custom fields will be used as is (pre-encoded).

It is safe to free (deallocate) any arguments supplied to this function immediately after the call as all the data is copied to the new buffer.

Don't forget to free() the returned buffer when you don't need it anymore.

Parameters
[in]productExploded product information area
Returns
fru_info_area_t *area A newly allocated buffer containing the created area

Referenced by save_to_binary_file().

Here is the caller graph for this function:

◆ fru_loadfield()

void fru_loadfield ( decoded_field_t *  field,
const char *  s,
field_type_t  enc 
)

Referenced by main().

Here is the caller graph for this function:

◆ fru_mr_hexstr2rec()

int fru_mr_hexstr2rec ( fru_mr_rec_t **  rec,
const char *  str,
fru_mr_type_t  type 
)

References fru_errno.

◆ fru_mr_mgmt_rec2str()

int fru_mr_mgmt_rec2str ( char **  str,
fru_mr_mgmt_rec_t *  mgmt,
fru_flags_t  flags 
)

◆ fru_mr_mgmt_str2rec()

int fru_mr_mgmt_str2rec ( fru_mr_rec_t **  rec,
const char *  str,
fru_mr_mgmt_type_t  type 
)

◆ fru_mr_rec2hexstr()

int fru_mr_rec2hexstr ( char **  str,
fru_mr_rec_t *  rec,
fru_flags_t  flags 
)

References fru_errno.

◆ fru_mr_rec2uuid()

int fru_mr_rec2uuid ( char **  str,
fru_mr_mgmt_rec_t *  mgmt,
fru_flags_t  flags 
)

◆ fru_mr_uuid2rec()

int fru_mr_uuid2rec ( fru_mr_rec_t **  rec,
const char *  str 
)

References fru_uuid_t, UUID_STRLEN_DASHED, and UUID_STRLEN_NONDASHED.

Referenced by main().

Here is the caller graph for this function:

Variable Documentation

◆ fru_uuid_t

fru_uuid_t

Referenced by fru_mr_rec2uuid(), and fru_mr_uuid2rec().