libfru 2.1
FRU Manupulation Library
|
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"
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 | |
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
#define _BSD_SOURCE |
#define AREA | ( | NAME | ) |
#define DEBUG | ( | f, | |
args... | |||
) |
#define UUID_SIZE 16 |
#define UUID_STRLEN_DASHED (UUID_STRLEN_NONDASHED + 4) |
#define UUID_STRLEN_NONDASHED (UUID_SIZE * 2) |
union __attribute__ | ( | (packed) | ) |
AREA | ( | board | ) |
AREA | ( | chassis | ) |
AREA | ( | product | ) |
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().
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().
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().
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_t * fru_create | ( | fru_area_t | area[FRU_MAX_AREAS], |
size_t * | size | ||
) |
Create a FRU information file.
[in] | area | The 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] | size | On success, the size of the newly created FRU information buffer, in 8-byte blocks |
References DEBUG, FEAREABADTYPE, and fru_errno.
Referenced by save_to_binary_file().
bool fru_decode_board_info | ( | const fru_board_area_t * | area, |
fru_exploded_board_t * | board_out | ||
) |
bool fru_decode_chassis_info | ( | const fru_chassis_area_t * | area, |
fru_exploded_chassis_t * | chassis_out | ||
) |
bool fru_decode_data | ( | fru_field_t * | field, |
decoded_field_t * | out | ||
) |
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().
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().
bool fru_decode_product_info | ( | const fru_product_area_t * | area, |
fru_exploded_product_t * | product_out | ||
) |
const char * fru_enc_name_by_type | ( | field_type_t | type | ) |
Referenced by arg_to_fieldopt(), fru_decode_data(), and save_to_text_file().
field_type_t fru_enc_type_by_name | ( | const char * | name | ) |
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.
[in] | board | Exploded board information area |
Referenced by save_to_binary_file().
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.
[in] | chassis | Exploded chassis info area |
References FEINVCHAS, fru_errno, and SMBIOS_CHASSIS_IS_VALID.
Referenced by save_to_binary_file().
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().
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().
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.
[in] | product | Exploded product information area |
Referenced by save_to_binary_file().
void fru_loadfield | ( | decoded_field_t * | field, |
const char * | s, | ||
field_type_t | enc | ||
) |
int fru_mr_hexstr2rec | ( | fru_mr_rec_t ** | rec, |
const char * | str, | ||
fru_mr_type_t | type | ||
) |
References fru_errno.
int fru_mr_mgmt_rec2str | ( | char ** | str, |
fru_mr_mgmt_rec_t * | mgmt, | ||
fru_flags_t | flags | ||
) |
References FEMRMGMTSIZE, FEMRMGMTTYPE, fru_errno, and MGMT_TYPE_ID.
int fru_mr_mgmt_str2rec | ( | fru_mr_rec_t ** | rec, |
const char * | str, | ||
fru_mr_mgmt_type_t | type | ||
) |
int fru_mr_rec2hexstr | ( | char ** | str, |
fru_mr_rec_t * | rec, | ||
fru_flags_t | flags | ||
) |
References fru_errno.
int fru_mr_rec2uuid | ( | char ** | str, |
fru_mr_mgmt_rec_t * | mgmt, | ||
fru_flags_t | flags | ||
) |
References fru_errno, fru_uuid_t, UUID_SIZE, and UUID_STRLEN_NONDASHED.
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().
fru_uuid_t |
Referenced by fru_mr_rec2uuid(), and fru_mr_uuid2rec().