Loading...
Searching...
No Matches
fru.h File Reference

Header for FRU information helper functions. More...

`#include <limits.h>`
`#include <stdbool.h>`
`#include <stdint.h>`
`#include <stdlib.h>`
`#include <sys/time.h>`
`#include <sys/types.h>`
Include dependency graph for fru.h:

Go to the source code of this file.

## Data Structures

struct | fru_field_t
| A generic input (decoded) field structure. More...
struct | fru_chassis_t
| The exploded representation of chassis info area. More...
struct | fru_board_t
| The exploded representation of board info area. More...
struct | fru_product_t
| The exploded representation of product info area. More...
struct | fru_t
| Exploded/decoded FRU data structure. More...
struct | fru_mr_rec_t
| MultiRecord area record type. More...

## Macros

#define | LIBFRU_MAJOR
| Major component of the library version.
#define | LIBFRU_MINOR
| Minor component of the library version.
#define | LIBFRU_SUBMINOR
| Subminor component of the library version.
#define | LIBFRU_VERSION
| Integer representation of the library version.
#define | FRU_MAX(a, b)
| Return the maximum of a and b.
#define | FRU_MIN(a, b)
| Return the minimum of a and b.
#define | FRU_FIELDMAXARRAY
| For C-string allocation.
#define | FRU_INFO_AREAS
| Number of standard 'info' areas.
#define | FRU_FIRST_INFO_AREA
| Index of the first 'info' area.
#define | FRU_LAST_INFO_AREA
| Index of the first 'info' area.
#define | FRU_IS_INFO_AREA(atype)
| Check if atype is an information area type.
#define | FRU_ATYPE_TO_INFOIDX(atype)
| Convert an area type atype into an information area index or to -1 if atype is not an info area type.
#define | FRU_INFOIDX_TO_ATYPE(idx)
| Convert an info area index idx into a full-range area type or to (fru_area_type_t)(-1) if idx was invalid.
#define | FRU_INFOIDX(a)
| Get the info area index from an area type enum name.
#define | FRU_FOREACH_INFOIDX(it)
| Iterate through all info area indices using it as an iterator.
#define | FRU_FOREACH_INFOFIELD(fru, atype, f, idx)
| Iterate through all info area standard fields within the given atype info area of the given fru.
#define | FRU_FOREACH_INFOCUSTOM(fru, atype, f, idx)
| Iterate through all info area custom fields within the given atype info area of the given fru.
#define | FRU_REAL_FE(t)
| Convert a fru_field_enc_t value to an index to a FRU_FE_REALCOUNT-sized array.
#define | FRU_FE_FROMREAL(t)
| Convert an index to a FRU_FE_REALCOUNT-sized array to a fru_field_enc_t value.
#define | FRU_FE_IS_REAL(t)
| Check if t is a 'real' encoding type?
#define | FRU_FIELD_IS_REAL_ENC(f)
| Check if field f is non-NULL and has a real encoding.
#define | FRU_FIELD_IS_AUTO_ENC(f)
| Check if field f is non-NULL and has an auto encoding.
#define | FRU_MAX_FIELD_COUNT
| Max mandatory field count among all info areas.
#define | FRU_IS_VALID_AREA(atype)
| Check if atype is any valid area type.
#define | FRU_FOREACH_AREA(it)
| Iterate through all area types using it as an iterator.
#define | FRU_ATYPE_HAS_TYPE(atype)
| Check if the area has a 'type' field.
#define | FRU_ATYPE_HAS_LANG(atype)
| Check if the area has a 'lang' field.
#define | FRU_ARRAY_SZ(a)
| A convenience macro to get the size of an array in elements.
#define | FRU_LIST_HEAD
| Add entry at the head of the list, used by fru_add_mr() and alike.
#define | FRU_LIST_TAIL
| Add entry at the end of the list, used by fru_add_mr() and alike.
#define | FRU_IS_APOS_VALID(pos)
#define | fru_free(fru)
| Deallocate a dynamically allocated fru structure.
#define | FRU_MR_IS_VALID_TYPE(t)
| The FRU_MR_RAW is not considered a valid type, must be checked separately.
#define | FRU_MR_OEM_COUNT
| The total number of possible OEM types to Multirecord area records.
#define | FRU_MR_OEM(n)
| An OEM Multirecord area type, make sure that n is less than FRU_MR_OEM_COUNT.
#define | FRU_MRR_OEM_MAXDATA
| Maximum length of OEM MR record data in decoded form (NUL-terminated hex string).
#define | FRU_MRR_RAW_MAXDATA
| Maximum length of Custom/Raw MR record data in decoded form (NUL-terminated hex string).
#define | FRU_MR_MGMT_IS_SUBTYPE_VALID(mt)
| Is the MR management access record subtype mt valid?
#define | FRU_MR_MGMT_SUBTYPE_TO_IDX(mt)
| Convert a valid MR Management Access Record subtype into a 0-based index or into -1 if mt is not a valid subtype.
#define | FRU_MR_MGMT_IDX_TO_SUBTYPE(i)
| Convert a valid 0-based index into an MR Management Access Record subtype or to FRU_MR_MGMT_INVALID if the result would not be a valid subtype.
#define | FRU_MR_MGMT_MAXDATA
| Maximum length of data in MR Management Access record.

## Typedefs

typedef void * | fru_custom_t
| A list of custom fields of an info area.
typedef void * | fru_mr_t
| A pointer to multi-record area descriptor.

## Enumerations

enum | fru_field_enc_t { FRU_FE_EMPTY , FRU_FE_BASE , FRU_FE_BINARY , FRU_FE_MIN , FRU_FE_BCDPLUS , FRU_FE_6BITASCII , FRU_FE_TEXT , FRU_FE_MAX , FRU_FE_AUTO , FRU_FE_UNKNOWN , FRU_FE_PRESERVE , FRU_FE_TOTALCOUNT , FRU_FE_REALCOUNT }
| Field encoding type. More...
enum | fru_chassis_field_t { FRU_CHASSIS_PARTNO , FRU_CHASSIS_SERIAL , FRU_CHASSIS_FIELD_COUNT }
| Indices of mandatory fields in Chassis Info Area. More...
enum | fru_lang_t { FRU_LANG_DEFAULT , FRU_LANG_ENGLISH }
| Language code definitions as per IPMI FRU Specification, Table 15-1. More...
enum | fru_board_field_t { FRU_BOARD_MFG , FRU_BOARD_PRODNAME , FRU_BOARD_SERIAL , FRU_BOARD_PARTNO , FRU_BOARD_FILE , FRU_BOARD_FIELD_COUNT }
| Indices of mandatory fields in Board Info Area. More...
enum | fru_prod_field_t { FRU_PROD_MFG , FRU_PROD_NAME , FRU_PROD_MODELPN , FRU_PROD_VERSION , FRU_PROD_SERIAL , FRU_PROD_ASSET , FRU_PROD_FILE , FRU_PROD_FIELD_COUNT }
| Indices of mandatory fields in Product Info Area. More...
enum | fru_area_type_t { FRU_INTERNAL_USE , FRU_MIN_AREA , FRU_CHASSIS_INFO , FRU_BOARD_INFO , FRU_PRODUCT_INFO , FRU_MR , FRU_MAX_AREA , FRU_TOTAL_AREAS }
| FRU area types. More...
enum | fru_flags_t { FRU_NOFLAGS , FRU_IGNFVER , FRU_IGNFHCKSUM , FRU_IGNFDCKSUM , FRU_IGNAVER , FRU_IGNRVER , FRU_IGNACKSUM , FRU_IGNRHCKSUM , FRU_IGNRDCKSUM , FRU_IGNRNOEOL , FRU_IGNBIG , FRU_IGNAEOF , FRU_IGNMRVER , FRU_IGNMRDATALEN }
| Debug flags to FRU decoding functions. More...
enum | fru_area_position_t { FRU_APOS_LAST , FRU_APOS_FIRST , FRU_APOS_AUTO , FRU_AFTER_INTERNAL , FRU_APOS_MIN , FRU_AFTER_CHASSIS , FRU_AFTER_BOARD , FRU_AFTER_PRODUCT , FRU_AFTER_MR , FRU_APOS_MAX }
| Define FRU area position in the binary file. More...

enum

fru_mr_type_t {
FRU_MR_MIN ,
FRU_MR_PSU_INFO ,
FRU_MR_DC_OUT ,
FRU_MR_DC_LOAD ,
FRU_MR_MGMT_ACCESS ,
FRU_MR_BCR ,
FRU_MR_ECR ,
FRU_MR_ASF_FIXED_SMBUS ,
FRU_MR_ASF_LEGACY_ALERTS ,
FRU_MR_ASF_REMOTE_CTRL ,
FRU_MR_EXT_DC_OUT ,
FRU_MR_EXT_DC_LOAD ,
FRU_MR_NVME ,
FRU_MR_NVME_PCIE_PORT ,
FRU_MR_NVME_TOPOLOGY ,
FRU_MR_NVME_RSVD_E ,
FRU_MR_NVME_RSVD_F ,
FRU_MR_OEM_START ,
FRU_MR_OEM_END ,
FRU_MR_MAX ,
FRU_MR_RAW ,
FRU_MR_TYPE_COUNT ,
FRU_MR_ANY ,
FRU_MR_EMPTY
}

| MultiRecord Area Record Types (Table 16-2). More...
enum | fru_mr_mgmt_type_t { FRU_MR_MGMT_INVALID , FRU_MR_MGMT_MIN , FRU_MR_MGMT_SYS_URL , FRU_MR_MGMT_SYS_NAME , FRU_MR_MGMT_SYS_PING , FRU_MR_MGMT_COMPONENT_URL , FRU_MR_MGMT_COMPONENT_NAME , FRU_MR_MGMT_COMPONENT_PING , FRU_MR_MGMT_SYS_UUID , FRU_MR_MGMT_MAX , FRU_MR_MGMT_INDEX_COUNT }
| Management Access Record subtypes (Table 18-6). More...
enum | fru_nvme_ff_t { FRU_NVME_FF_UNKNOWN }
| NVMe Form-Factor, see NVMe-MI Spec rev 1.2b, Figure 160. More...

## Functions

bool | fru_setfield (fru_field_t *field, fru_field_enc_t encoding, const char *string)
| Copy string to the given field, perform length check according to selected encoding, truncate if needed.
bool | fru_setfield_binary (fru_field_t *field, const void *buf, size_t size)
| Copy a binary input buffer into the given field, perform length check, truncate if needed.
fru_field_t * | fru_getfield (const fru_t *fru, fru_area_type_t atype, size_t index)
| Get a pointer to a mandatory field in the info area of the given type in the given fru structure.
fru_field_t * | fru_add_custom (fru_t *fru, fru_area_type_t atype, size_t index, fru_field_enc_t encoding, const char *string)
| Add a custom field to the given area type in the given fru structure.
fru_field_t * | fru_get_custom (const fru_t *fru, fru_area_type_t atype, size_t index)
| Get a pointer to a custom data field in the area of the given type in the given fru structure.
bool | fru_delete_custom (fru_t *fru, fru_area_type_t atype, size_t index)
| Delete a custom data field in the area of the given type in the given fru structure.
int16_t | fru_hex2byte (const char *hex)
| Convert 2 first bytes of hex string into a binary byte.
fru_t * | fru_init (fru_t *fru)
| Initialize/allocate a fru structure.
fru_t * | fru_loadfile (fru_t *fru, const char *filename, fru_flags_t flags)
| Load FRU information from a binary file.
fru_t * | fru_loadbuffer (fru_t *fru, const void *buf, size_t size, fru_flags_t flags)
| Load FRU information from a binary file.
void | fru_wipe (fru_t *fru)
| Wipe the contents of a fru_t structure.
bool | fru_enable_area (fru_t *fru, fru_area_type_t area, fru_area_position_t after)
| Enable a previously disabled / non-present area.
bool | fru_disable_area (fru_t *fru, fru_area_type_t atype)
| Disable a previously enabled / present area.
bool | fru_move_area (fru_t *fru, fru_area_type_t area, fru_area_position_t after)
| Move an enabled/present area.
bool | fru_savebuffer (void **bufptr, size_t *size, const fru_t *fru)
| Encode a FRU info structure into a binary buffer.
bool | fru_savefile (const char *fname, const fru_t *fru)
| Encode a FRU info structure into a binary file.
fru_mr_rec_t * | fru_add_mr (fru_t *fru, size_t index, fru_mr_rec_t *rec)
| Add a multirecord area record.
fru_mr_rec_t * | fru_get_mr (const fru_t *fru, size_t index)
| Get a multirecord area record at the given index.
fru_mr_rec_t * | fru_find_mr (const fru_t *fru, fru_mr_type_t type, size_t *index)
| Find a multirecord area record of the given type or at the given index.
bool | fru_replace_mr (fru_t *fru, size_t index, fru_mr_rec_t *rec)
| Replace a multirecord area record at the given index.
bool | fru_delete_mr (fru_t *fru, size_t index)
| Delete a multirecord area record at the given index.
bool | fru_set_internal_binary (fru_t *fru, const void *buffer, size_t size)
| Set internal use area from binary buffer.
bool | fru_set_internal_hexstring (fru_t *fru, const void *hexstr)
| Set internal use area from a hex string.
bool | fru_delete_internal (fru_t *fru)
| Delete internal use area from FRU structure.

## Detailed Description

Header for FRU information helper functions.

Copyright
  Copyright (C) 2016-2024 Alexander Amelkin alexa.nosp@m.nder.nosp@m.@amel.nosp@m.kin..nosp@m.msk.r.nosp@m.u

SPDX-License-Identifier: GPL-2.0-or-later OR Apache-2.0

## Macro Definition Documentation

## FRU_FIELDMAXARRAY

#define FRU_FIELDMAXARRAY

For C-string allocation.

You probably don't need to directly use this, prefer using `fru_field_t` type:

fru_field_t field;
if (strlen(mystring) >= sizeof(field.val)) {
// Smells like buffer overflow
}
fru_field_t
A generic input (decoded) field structure.
Definition fru.h:347
fru_field_t::val
char val[FRU_FIELDMAXARRAY]
The decoded C-string representation of the field value.
Definition fru.h:352

Better yet, use fru_set_field() that performs the required checks itself.

## FRU_MAX

#define FRU_MAX | ( |  | a,
|  |  | b )

Return the maximum of a and b.

## FRU_MIN

#define FRU_MIN | ( |  | a,
|  |  | b )

Return the minimum of a and b.