51#define LIBFRU_MAJOR 3L
52#define LIBFRU_MINOR 1L
53#define LIBFRU_SUBMINOR 0L
65#define LIBFRU_VERSION (LIBFRU_MAJOR << 16 | \
81#define fru__zfree(buf) do { \
88#define FRU__BIT(x) (1 << (x))
94#define FRU__TYPE_BINARY 0x00
95#define FRU__TYPE_BCDPLUS 0x01
96#define FRU__TYPE_ASCII_6BIT 0x02
97#define FRU__TYPE_TEXT 0x03
99#define FRU__TYPE_BITS_MASK 0xC0
100#define FRU__FIELDLEN(x) ((size_t)(((x) & ~FRU__TYPE_BITS_MASK)))
105#define FRU__FIELDMAXLEN FRU__FIELDLEN(UINT8_MAX)
115#define FRU_MAX(a, b) (((intmax_t)((a) + 0LL) > (intmax_t)((b) + 0LL)) ? (a) : (b))
116#define FRU_MIN(a, b) (((intmax_t)((a) + 0LL) > (intmax_t)((b) + 0LL)) ? (b) : (a))
136#define FRU_FIELDMAXARRAY ((2 * FRU__FIELDMAXLEN) + 1)
146#define FRU_INFO_AREAS 3
147#define FRU_FIRST_INFO_AREA FRU_CHASSIS_INFO
148#define FRU_LAST_INFO_AREA FRU_PRODUCT_INFO
150#define FRU_IS_INFO_AREA(atype) (FRU_FIRST_INFO_AREA <= (atype) \
151 && (atype) <= FRU_LAST_INFO_AREA)
157#define FRU_ATYPE_TO_INFOIDX(atype) (FRU_IS_INFO_AREA(atype) ? (int)((atype) - FRU_FIRST_INFO_AREA) : -1)
163#define FRU_INFOIDX_TO_ATYPE(idx) (((idx) >= 0 && (idx) < FRU_INFO_AREAS) \
164 ? (fru_area_type_t)((idx) + FRU_FIRST_INFO_AREA) \
165 : (fru_area_type_t)(-1))
184#define FRU_INFOIDX(a) FRU_ATYPE_TO_INFOIDX(FRU_##a##_INFO)
202#define FRU_FOREACH_INFOIDX(it) for ((it) = 0; (it) <= FRU_INFO_AREAS; (it)++)
223#define FRU_FOREACH_INFOFIELD(fru, atype, f, idx) \
224 for (size_t idx = FRU_LIST_HEAD; \
225 (f = fru_getfield(fru, atype, idx)); \
247#define FRU_FOREACH_INFOCUSTOM(fru, atype, f, idx) \
248 for (size_t idx = FRU_LIST_HEAD; \
249 (f = fru_get_custom(fru, atype, idx)); \
307#define FRU_REAL_FE(t) ((t) - FRU_FE_BASE)
314#define FRU_FE_FROMREAL(t) ((t) + FRU_FE_BASE)
321#define FRU_FE_IS_REAL(t) (FRU_FE_MIN <= (t) && (t) <= FRU_FE_MAX)
328#define FRU_FIELD_IS_REAL_ENC(f) ((f) && FRU_FE_IS_REAL((f)->enc))
335#define FRU_FIELD_IS_AUTO_ENC(f) ((f) && FRU_FE_AUTO == ((f)->enc))
498#define FRU_MAX_FIELD_COUNT FRU_PROD_FIELD_COUNT
530#define FRU_IS_VALID_AREA(atype) (FRU_MIN_AREA <= (atype) && (atype) <= FRU_MAX_AREA)
556#define FRU_FOREACH_AREA(it) for ((it) = FRU_MIN_AREA; (it) <= FRU_MAX_AREA; (it)++)
612#define FRU_ATYPE_HAS_TYPE(atype) (FRU_CHASSIS_INFO == (atype))
614#define FRU_ATYPE_HAS_LANG(atype) (FRU_BOARD_INFO == (atype) || FRU_PRODUCT_INFO == (atype))
686 const char *
string);
802 const char *
string);
866#define FRU_ARRAY_SZ(a) (sizeof(a) / sizeof((a)[0]))
890#define FRU_LIST_HEAD 0
892#define FRU_LIST_TAIL INT_MAX
918#define FRU_IS_APOS_VALID(pos) (FRU_APOS_LAST <= (pos) && (pos) <= FRU_APOS_MAX)
990 const char * filename,
1043#define fru_free(fru) do { fru_wipe(fru); fru__zfree(fru); } while(0)
1246#define FRU_MR_IS_VALID_TYPE(t) (FRU_MR_MIN <= (t) && (t) <= FRU_MR_MAX)
1249#define FRU_MR_OEM_COUNT (FRU_MR_OEM_END - FRU_MR_OEM_START + 1)
1252#define FRU_MR_OEM(n) (FRU_MR_OEM_START + (n))
1255#define FRU__FILE_MRR_MAXDATA (UINT8_MAX)
1258#define FRU__FILE_MRR_OEM_MFGID_LEN 3
1269#define FRU_MRR_OEM_MAXDATA \
1270 ((FRU__FILE_MRR_MAXDATA - FRU__FILE_MRR_OEM_MFGID_LEN) * 2 + 1)
1275#define FRU_MRR_RAW_MAXDATA \
1276 (FRU__FILE_MRR_MAXDATA * 2 + 1)
1298#define FRU_MR_MGMT_IS_SUBTYPE_VALID(mt) ((mt) >= FRU_MR_MGMT_MIN && (mt) <= FRU_MR_MGMT_MAX)
1304#define FRU_MR_MGMT_SUBTYPE_TO_IDX(mt) (FRU_MR_MGMT_IS_SUBTYPE_VALID(mt) \
1305 ? (int)((mt) - FRU_MR_MGMT_MIN) \
1311#define FRU_MR_MGMT_IDX_TO_SUBTYPE(i) (((i) >= 0 && (i) <= FRU_MR_MGMT_MAX) \
1312 ? ((i) + FRU_MR_MGMT_MIN) \
1313 : FRU_MR_MGMT_INVALID)
1327#define FRU__FILE_MR_MGMT_HDR_LEN (sizeof(uint8_t))
1330#define FRU__FILE_MR_MGMT_MAXDATA \
1331 (FRU__FILE_MRR_MAXDATA - FRU__FILE_MR_MGMT_HDR_LEN)
1346#define FRU_MR_MGMT_MAXDATA (FRU__FILE_MR_MGMT_MAXDATA)
#define FRU_FIELDMAXARRAY
For C-string allocation.
Definition fru.h:136
fru_board_field_t
Indices of mandatory fields in Board Info Area.
Definition fru.h:445
fru_lang_t
Language code definitions as per IPMI FRU Specification, Table 15-1.
Definition fru.h:407
@ FRU_BOARD_MFG
Definition fru.h:446
@ FRU_BOARD_SERIAL
Definition fru.h:448
@ FRU_BOARD_PARTNO
Definition fru.h:449
@ FRU_BOARD_FIELD_COUNT
Definition fru.h:451
@ FRU_BOARD_FILE
Definition fru.h:450
@ FRU_BOARD_PRODNAME
Definition fru.h:447
@ FRU_LANG_ENGLISH
English language code.
Definition fru.h:409
@ FRU_LANG_DEFAULT
Default Language code, implies English as per Table 15-1.
Definition fru.h:408
fru_chassis_field_t
Indices of mandatory fields in Chassis Info Area.
Definition fru.h:387
@ FRU_CHASSIS_SERIAL
Definition fru.h:389
@ FRU_CHASSIS_PARTNO
Definition fru.h:388
@ FRU_CHASSIS_FIELD_COUNT
Definition fru.h:390
fru_flags_t
Debug flags to FRU decoding functions.
Definition fru.h:625
bool fru_savefile(const char *fname, const fru_t *fru)
Encode a FRU info structure into a binary file.
fru_area_position_t
Define FRU area position in the binary file.
Definition fru.h:905
bool fru_savebuffer(void **bufptr, size_t *size, const fru_t *fru)
Encode a FRU info structure into a binary buffer.
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.
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.
fru_area_type_t
FRU area types.
Definition fru.h:519
fru_t * fru_init(fru_t *fru)
Initialize/allocate a fru structure.
void fru_wipe(fru_t *fru)
Wipe the contents of a fru_t structure.
bool fru_move_area(fru_t *fru, fru_area_type_t area, fru_area_position_t after)
Move an enabled/present area.
@ FRU_IGNRDCKSUM
Ignore record data checksum for multirecord area.
Definition fru.h:636
@ FRU_IGNMRDATALEN
Ignore invalid MR record data length where possible.
Definition fru.h:646
@ FRU_IGNACKSUM
Ignore area checksum.
Definition fru.h:633
@ FRU_IGNFHCKSUM
Ignore FRU header checksum.
Definition fru.h:628
@ FRU_IGNRVER
Ignore record version for multirecord area.
Definition fru.h:631
@ FRU_IGNBIG
Don't fail on binary file load if the file is bigger than 64K, attempt to load it anyway (may be dang...
Definition fru.h:641
@ FRU_IGNFVER
Ignore FRU version in FRU header.
Definition fru.h:627
@ FRU_IGNAVER
Ignore area version.
Definition fru.h:630
@ FRU_NOFLAGS
No flags, operate normally.
Definition fru.h:626
@ FRU_IGNMRVER
Ignore invalid MR record version where possible.
Definition fru.h:645
@ FRU_IGNRHCKSUM
Ignore record header checksum for multirecord area.
Definition fru.h:634
@ FRU_IGNAEOF
Ignore no end-of-fields marker in info areas.
Definition fru.h:644
@ FRU_IGNRNOEOL
Ignore absence of EOL-flagged MR area record, use any previous valid records.
Definition fru.h:638
@ FRU_IGNFDCKSUM
Ignore FRU data checksum.
Definition fru.h:629
@ FRU_APOS_FIRST
Put an area first in the order.
Definition fru.h:907
@ FRU_AFTER_BOARD
Put an area after Board Info Area.
Definition fru.h:913
@ FRU_AFTER_INTERNAL
Put an area after Internal Use Area.
Definition fru.h:910
@ FRU_AFTER_PRODUCT
Put an area after Product Info Area.
Definition fru.h:914
@ FRU_APOS_AUTO
Position an area automatically as per the default order given in FRU Spec.
Definition fru.h:908
@ FRU_APOS_LAST
Put an area last in the order.
Definition fru.h:906
@ FRU_APOS_MAX
Maximum 'real' position.
Definition fru.h:916
@ FRU_AFTER_MR
Put an area after Multirecord Area.
Definition fru.h:915
@ FRU_APOS_MIN
Minimum 'real' position.
Definition fru.h:911
@ FRU_AFTER_CHASSIS
Put an area after Chassis Info Area.
Definition fru.h:912
@ FRU_BOARD_INFO
Board information area.
Definition fru.h:523
@ FRU_INTERNAL_USE
Internal use area.
Definition fru.h:520
@ FRU_MR
Multirecord area.
Definition fru.h:525
@ FRU_MAX_AREA
Maximum area type (equals FRU_MR)
Definition fru.h:526
@ FRU_TOTAL_AREAS
Maximum total count of areas in a FRU file.
Definition fru.h:527
@ FRU_PRODUCT_INFO
Product information area.
Definition fru.h:524
@ FRU_CHASSIS_INFO
Chassis information area.
Definition fru.h:522
@ FRU_MIN_AREA
Minimum area type (equals FRU_INTERNAL_USE)
Definition fru.h:521
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,...
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.
void * fru_custom_t
A list of custom fields of an info area.
Definition fru.h:356
fru_field_enc_t
Field encoding type.
Definition fru.h:265
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_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.
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_FE_AUTO
When saving, detect the encoding automatically based on the character range of fru_field_t....
Definition fru.h:289
@ FRU_FE_BINARY
Encode the field as binary, the value is a hex string (e.g., 1337C0DE)
Definition fru.h:273
@ FRU_FE_TOTALCOUNT
Total count of all field encodings (including the extensions)
Definition fru.h:295
@ FRU_FE_MAX
Maximim valid 'real' field encoding, equals FRU_FE_TEXT.
Definition fru.h:287
@ FRU_FE_PRESERVE
Preserve the field encoding as it was, fail if impossible.
Definition fru.h:292
@ FRU_FE_BASE
Base encoding, starting at which all the binary FRU file field encodings are mapped.
Definition fru.h:271
@ FRU_FE_EMPTY
The field is empty.
Definition fru.h:266
@ FRU_FE_UNKNOWN
Field encoding couldn't be detected or wasn't set.
Definition fru.h:291
@ FRU_FE_TEXT
Encode the field as plain text (ASCII+Latin1).
Definition fru.h:284
@ FRU_FE_6BITASCII
Encode the field as 6-bit ASCII, the value may only contain characters per Table 13-1 of IPMI FRU Spe...
Definition fru.h:280
@ FRU_FE_BCDPLUS
Encode the field as BCD+, the value may only contain digits 0-9, space, dash, or period.
Definition fru.h:277
@ FRU_FE_MIN
The minumum non-auto (real) encoding, equals FRU_FE_BINARY.
Definition fru.h:275
@ FRU_FE_REALCOUNT
Total count of standard field encodings (not including the extensions)
Definition fru.h:297
bool fru_delete_internal(fru_t *fru)
Delete internal use area from FRU structure.
bool fru_set_internal_hexstring(fru_t *fru, const void *hexstr)
Set internal use area from a hex string.
bool fru_set_internal_binary(fru_t *fru, const void *buffer, size_t size)
Set internal use area from binary buffer.
#define FRU_MRR_RAW_MAXDATA
Maximum length of Custom/Raw MR record data in decoded form (NUL-terminated hex string)
Definition fru.h:1275
fru_mr_rec_t * fru_get_mr(const fru_t *fru, size_t index)
Get a multirecord area record at the given index.
#define FRU_MR_MGMT_MAXDATA
Maximum length of data in MR Management Access record.
Definition fru.h:1346
fru_nvme_ff_t
NVMe Form-Factor, see NVMe-MI Spec rev 1.2b, Figure 160.
Definition fru.h:1320
fru_mr_type_t
MultiRecord Area Record Types (Table 16-2)
Definition fru.h:1214
void * fru_mr_t
A pointer to multi-record area descriptor.
Definition fru.h:506
bool fru_replace_mr(fru_t *fru, size_t index, fru_mr_rec_t *rec)
Replace a multirecord area record at the given index.
#define FRU_MRR_OEM_MAXDATA
Maximum length of OEM MR record data in decoded form (NUL-terminated hex string)
Definition fru.h:1269
fru_mr_mgmt_type_t
Management Access Record subtypes (Table 18-6)
Definition fru.h:1281
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_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_delete_mr(fru_t *fru, size_t index)
Delete a multirecord area record at the given index.
@ FRU_NVME_FF_UNKNOWN
Definition fru.h:1321
@ FRU_MR_ECR
Extended Compatibility Record.
Definition fru.h:1221
@ FRU_MR_RAW
The raw type.
Definition fru.h:1239
@ FRU_MR_DC_OUT
DC Output.
Definition fru.h:1217
@ FRU_MR_PSU_INFO
PSU Information.
Definition fru.h:1216
@ FRU_MR_DC_LOAD
DC Load.
Definition fru.h:1218
@ FRU_MR_NVME_PCIE_PORT
NVMe PCIe Port.
Definition fru.h:1231
@ FRU_MR_ASF_FIXED_SMBUS
ASF Fixed SMBus Addresses.
Definition fru.h:1223
@ FRU_MR_OEM_END
End of OEM range.
Definition fru.h:1237
@ FRU_MR_NVME
NVMe Information.
Definition fru.h:1230
@ FRU_MR_BCR
Base Compatibility Record.
Definition fru.h:1220
@ FRU_MR_NVME_RSVD_F
Reserved.
Definition fru.h:1234
@ FRU_MR_MIN
The minimum valid MR record type that can be saved.
Definition fru.h:1215
@ FRU_MR_EXT_DC_OUT
Extended DC Output.
Definition fru.h:1227
@ FRU_MR_MGMT_ACCESS
Management Access Record.
Definition fru.h:1219
@ FRU_MR_EMPTY
MR Record is empty, will be skipped during saving.
Definition fru.h:1242
@ FRU_MR_TYPE_COUNT
Total number of MR record types (including 'raw')
Definition fru.h:1240
@ FRU_MR_ASF_LEGACY_ALERTS
ASF Lecacy-Device Alerts.
Definition fru.h:1224
@ FRU_MR_OEM_START
Start of OEM range.
Definition fru.h:1236
@ FRU_MR_ASF_REMOTE_CTRL
ASF Remote Control.
Definition fru.h:1225
@ FRU_MR_MAX
The maximum valid MR record type that can be saved.
Definition fru.h:1238
@ FRU_MR_NVME_RSVD_E
Reserved.
Definition fru.h:1233
@ FRU_MR_ANY
Any MR Record type, for use with fru_find_mr() only.
Definition fru.h:1241
@ FRU_MR_EXT_DC_LOAD
Extended DC Load.
Definition fru.h:1228
@ FRU_MR_NVME_TOPOLOGY
NVMe Topolgy.
Definition fru.h:1232
@ FRU_MR_MGMT_SYS_NAME
System Name.
Definition fru.h:1285
@ FRU_MR_MGMT_MIN
The minimum valid (real) subtype.
Definition fru.h:1283
@ FRU_MR_MGMT_INVALID
Invalid subtype, do not use.
Definition fru.h:1282
@ FRU_MR_MGMT_SYS_UUID
System Unique ID.
Definition fru.h:1290
@ FRU_MR_MGMT_INDEX_COUNT
The count of 0-based indices of valid subtypes, can be used as an array dimension.
Definition fru.h:1292
@ FRU_MR_MGMT_COMPONENT_URL
Component URL.
Definition fru.h:1287
@ FRU_MR_MGMT_MAX
The maximum valid subtype.
Definition fru.h:1291
@ FRU_MR_MGMT_COMPONENT_NAME
Component Name.
Definition fru.h:1288
@ FRU_MR_MGMT_SYS_PING
System Ping Address.
Definition fru.h:1286
@ FRU_MR_MGMT_SYS_URL
System URL.
Definition fru.h:1284
@ FRU_MR_MGMT_COMPONENT_PING
Component Ping Address.
Definition fru.h:1289
fru_prod_field_t
Indices of mandatory fields in Product Info Area.
Definition fru.h:483
@ FRU_PROD_NAME
Definition fru.h:485
@ FRU_PROD_FILE
Definition fru.h:490
@ FRU_PROD_FIELD_COUNT
Definition fru.h:491
@ FRU_PROD_ASSET
Definition fru.h:489
@ FRU_PROD_SERIAL
Definition fru.h:488
@ FRU_PROD_MFG
Definition fru.h:484
@ FRU_PROD_MODELPN
Definition fru.h:486
@ FRU_PROD_VERSION
Definition fru.h:487
int16_t fru_hex2byte(const char *hex)
Convert 2 first bytes of hex string into a binary byte.
The exploded representation of board info area.
Definition fru.h:420
fru_field_t serial
Board serial number.
Definition fru.h:432
fru_field_t pname
Board product name.
Definition fru.h:431
fru_field_t file
FRU File ID.
Definition fru.h:434
fru_field_t mfg
Board manufacturer name.
Definition fru.h:430
fru_lang_t lang
Language code.
Definition fru.h:421
bool tv_auto
On save, use current date/time.
Definition fru.h:423
fru_custom_t cust
List of custom fields.
Definition fru.h:435
fru_field_t pn
Board part number.
Definition fru.h:433
The exploded representation of chassis info area.
Definition fru.h:373
uint8_t type
Chassis type as per SMBIOS specification.
Definition fru.h:374
fru_field_t pn
Part Number.
Definition fru.h:375
fru_custom_t cust
List of custom fields.
Definition fru.h:377
fru_field_t serial
Serial Number.
Definition fru.h:376
A generic input (decoded) field structure.
Definition fru.h:347
fru_field_enc_t enc
The encoding of the field.
Definition fru.h:348
MultiRecord area record type.
Definition fru.h:1377
fru_field_enc_t enc
OEM data encoding.
Definition fru.h:1485
uint8_t p1v8_max
Definition fru.h:1456
uint8_t p3v3_init
Definition fru.h:1457
uint8_t p12v_init
Definition fru.h:1462
uint8_t p12v_max
Definition fru.h:1463
uint8_t p3v3_aux_max
Definition fru.h:1459
uint8_t p5v_max
Definition fru.h:1461
fru_mr_type_t type
Record Type.
Definition fru.h:1378
uint32_t mfg_id
Manufacturer ID, 24 bits.
Definition fru.h:1483
uint8_t type
The actual record Type.
Definition fru.h:1504
uint8_t p5v_init
Definition fru.h:1460
fru_nvme_ff_t formfactor
Form-Factor as per NVMe-MI 1.2b Figure 160.
Definition fru.h:1454
uint8_t ptherm_max
Definition fru.h:1464
uint64_t capacity_lo
Total capacity, higher 8 bytes, 13:6 of 13, host-endian.
Definition fru.h:1465
uint8_t p1v8_init
Definition fru.h:1455
uint8_t p3v3_max
Definition fru.h:1458
uint32_t capacity_mid
Total capacity, middle 4 bytes, 5:2 of 13, host-endian.
Definition fru.h:1466
fru_mr_mgmt_type_t subtype
Management Access Record subtype.
Definition fru.h:1403
uint8_t capacity_hi
Total capacity, middle 4 bytes, 1 of 13.
Definition fru.h:1467
The exploded representation of product info area.
Definition fru.h:464
fru_field_t file
FRU File ID.
Definition fru.h:472
fru_field_t serial
Product serial number.
Definition fru.h:470
fru_field_t mfg
Product manufacturer.
Definition fru.h:466
fru_lang_t lang
Definition fru.h:465
fru_field_t atag
Product asset tag.
Definition fru.h:471
fru_field_t pn
Product part number.
Definition fru.h:468
fru_field_t pname
Product name.
Definition fru.h:467
fru_field_t ver
Product version.
Definition fru.h:469
fru_custom_t cust
List of custom fields.
Definition fru.h:473
Exploded/decoded FRU data structure.
Definition fru.h:574
char * internal
Internal use area as a hex string.
Definition fru.h:601
fru_mr_t mr
The multi-record area descriptor.
Definition fru.h:605
fru_board_t board
The board information structure.
Definition fru.h:603
fru_chassis_t chassis
The chassis information structure.
Definition fru.h:602
fru_product_t product
The product information structure.
Definition fru.h:604