xref: /onnv-gate/usr/src/lib/libfru/include/libfru.h (revision 488:f9dc33424f0b)
10Sstevel@tonic-gate /*
20Sstevel@tonic-gate  * CDDL HEADER START
30Sstevel@tonic-gate  *
40Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
50Sstevel@tonic-gate  * Common Development and Distribution License, Version 1.0 only
60Sstevel@tonic-gate  * (the "License").  You may not use this file except in compliance
70Sstevel@tonic-gate  * with the License.
80Sstevel@tonic-gate  *
90Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
100Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
110Sstevel@tonic-gate  * See the License for the specific language governing permissions
120Sstevel@tonic-gate  * and limitations under the License.
130Sstevel@tonic-gate  *
140Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
150Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
160Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
170Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
180Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
190Sstevel@tonic-gate  *
200Sstevel@tonic-gate  * CDDL HEADER END
210Sstevel@tonic-gate  */
220Sstevel@tonic-gate /*
23*488Skmohan  * Copyright 2005 Sun Microsystems, Inc.  All rights reserved.
240Sstevel@tonic-gate  * Use is subject to license terms.
250Sstevel@tonic-gate  */
260Sstevel@tonic-gate 
270Sstevel@tonic-gate #ifndef	_LIBFRU_H
280Sstevel@tonic-gate #define	_LIBFRU_H
290Sstevel@tonic-gate 
300Sstevel@tonic-gate #pragma ident	"%Z%%M%	%I%	%E% SMI"
310Sstevel@tonic-gate 
320Sstevel@tonic-gate #ifdef __cplusplus
330Sstevel@tonic-gate extern "C" {
340Sstevel@tonic-gate #endif
350Sstevel@tonic-gate 
360Sstevel@tonic-gate #include <sys/types.h>
370Sstevel@tonic-gate 
380Sstevel@tonic-gate #define	LIBFRU_VERSION 1
390Sstevel@tonic-gate 
400Sstevel@tonic-gate /* fru errno return types */
410Sstevel@tonic-gate typedef enum
420Sstevel@tonic-gate {
430Sstevel@tonic-gate 	FRU_SUCCESS = 0,
440Sstevel@tonic-gate 	FRU_NODENOTFOUND,
450Sstevel@tonic-gate 	FRU_IOERROR,
460Sstevel@tonic-gate 	FRU_NOREGDEF,
470Sstevel@tonic-gate 	FRU_NOTCONTAINER,
480Sstevel@tonic-gate 	FRU_INVALHANDLE,
490Sstevel@tonic-gate 	FRU_INVALSEG,
500Sstevel@tonic-gate 	FRU_INVALPATH,
510Sstevel@tonic-gate 	FRU_INVALELEMENT,
520Sstevel@tonic-gate 	FRU_INVALDATASIZE,
530Sstevel@tonic-gate 	FRU_DUPSEG,
540Sstevel@tonic-gate 	FRU_NOTFIELD,
550Sstevel@tonic-gate 	FRU_NOSPACE,
560Sstevel@tonic-gate 	FRU_DATANOTFOUND,
570Sstevel@tonic-gate 	FRU_ITERFULL,
580Sstevel@tonic-gate 	FRU_INVALPERM,
590Sstevel@tonic-gate 	FRU_NOTSUP,
600Sstevel@tonic-gate 	FRU_ELEMNOTTAGGED,
610Sstevel@tonic-gate 	FRU_CONTFAILED,
620Sstevel@tonic-gate 	FRU_SEGCORRUPT,
630Sstevel@tonic-gate 	FRU_DATACORRUPT,
640Sstevel@tonic-gate 	FRU_FAILURE,
650Sstevel@tonic-gate 	FRU_WALK_TERMINATE
660Sstevel@tonic-gate 
670Sstevel@tonic-gate } fru_errno_t;
680Sstevel@tonic-gate 
690Sstevel@tonic-gate /*
700Sstevel@tonic-gate  * Structures for libfru.c
710Sstevel@tonic-gate  */
720Sstevel@tonic-gate 
730Sstevel@tonic-gate /* Fru Display Types */
740Sstevel@tonic-gate typedef enum { FDISP_Binary = 0, FDISP_Octal, FDISP_Hex, FDISP_Decimal,
75*488Skmohan 	FDISP_String, FDISP_Time, FDISP_MSGID, FDISP_UUID, FDISP_UNDEFINED
760Sstevel@tonic-gate } fru_displaytype_t;
770Sstevel@tonic-gate 
780Sstevel@tonic-gate /* Fru Data Types */
790Sstevel@tonic-gate typedef enum { FDTYPE_Binary = 0, FDTYPE_ByteArray, FDTYPE_ASCII,
800Sstevel@tonic-gate 		FDTYPE_Unicode, FDTYPE_Record, FDTYPE_Enumeration,
810Sstevel@tonic-gate 		FDTYPE_UNDEFINED
820Sstevel@tonic-gate } fru_datatype_t;
830Sstevel@tonic-gate 
840Sstevel@tonic-gate /* Fru Which Type */
850Sstevel@tonic-gate typedef enum { FRU_No = 0, FRU_Yes, FRU_WHICH_UNDEFINED } fru_which_t;
860Sstevel@tonic-gate 
870Sstevel@tonic-gate /* Fru Iteration Types */
880Sstevel@tonic-gate typedef enum { FRU_FIFO = 0, FRU_Circular,
890Sstevel@tonic-gate 		FRU_Linear, FRU_LIFO, FRU_NOT_ITERATED } fru_itertype_t;
900Sstevel@tonic-gate 
910Sstevel@tonic-gate /* Fru Handle Type */
920Sstevel@tonic-gate typedef uint64_t fru_nodehdl_t;
930Sstevel@tonic-gate 
940Sstevel@tonic-gate /* Node Types */
950Sstevel@tonic-gate typedef enum
960Sstevel@tonic-gate {
970Sstevel@tonic-gate 	FRU_NODE_UNKNOWN,
980Sstevel@tonic-gate 	FRU_NODE_LOCATION,
990Sstevel@tonic-gate 	FRU_NODE_FRU,
1000Sstevel@tonic-gate 	FRU_NODE_CONTAINER
1010Sstevel@tonic-gate } fru_node_t;
1020Sstevel@tonic-gate 
1030Sstevel@tonic-gate /* Sting list */
1040Sstevel@tonic-gate typedef struct {
1050Sstevel@tonic-gate 	unsigned int num;
1060Sstevel@tonic-gate 	char **strs;
1070Sstevel@tonic-gate } fru_strlist_t;
1080Sstevel@tonic-gate 
1090Sstevel@tonic-gate typedef union
1100Sstevel@tonic-gate {
1110Sstevel@tonic-gate 	uint32_t raw_data;
1120Sstevel@tonic-gate 	struct
1130Sstevel@tonic-gate 	{
1140Sstevel@tonic-gate 		unsigned encrypted : 1;
1150Sstevel@tonic-gate 		unsigned ignore_checksum : 1;
1160Sstevel@tonic-gate 		unsigned opaque : 1;
1170Sstevel@tonic-gate 		unsigned fixed : 1;
1180Sstevel@tonic-gate 		unsigned unused : 13;
1190Sstevel@tonic-gate 		unsigned field_perm : 3;
1200Sstevel@tonic-gate 		unsigned domain_perm : 3;
1210Sstevel@tonic-gate 		unsigned operations_perm : 3;
1220Sstevel@tonic-gate 		unsigned engineering_perm : 3;
1230Sstevel@tonic-gate 		unsigned repair_perm : 3;
1240Sstevel@tonic-gate 	} field;
1250Sstevel@tonic-gate } fru_segdesc_t;
1260Sstevel@tonic-gate 
1270Sstevel@tonic-gate #define	FRU_SEGDESC_PERM_DELETE_MASK (1<<0)
1280Sstevel@tonic-gate #define	FRU_SEGDESC_PERM_WRITE_MASK (1<<1)
1290Sstevel@tonic-gate #define	FRU_SEGDESC_PERM_READ_MASK (1<<2)
1300Sstevel@tonic-gate #define	FRU_SEGDESC_PERM_RW_MASK ((1<<2) | (1<<1))
1310Sstevel@tonic-gate #define	FRU_SEGDESC_PERM_RD_MASK ((1<<2) | (1<<0))
1320Sstevel@tonic-gate #define	FRU_SEGDESC_PERM_WD_MASK ((1<<1) | (1<<0))
1330Sstevel@tonic-gate #define	FRU_SEGDESC_PERM_RWD_MASK ((1<<0) | (1<<1) | (1<<2))
1340Sstevel@tonic-gate 
1350Sstevel@tonic-gate #define	FRU_SEGDESC_ALL_RO_MASK 0x000036db
1360Sstevel@tonic-gate 
1370Sstevel@tonic-gate #define	FRU_SEGDESC_FIXED_MASK (1<<28)
1380Sstevel@tonic-gate #define	FRU_SEGDESC_OPAQUE_MASK (1<<29)
1390Sstevel@tonic-gate #define	FRU_SEGDESC_IGNORECHECKSUM_MASK (1<<30)
1400Sstevel@tonic-gate #define	FRU_SEGDESC_ENCRYPTED_MASK (1<<31)
1410Sstevel@tonic-gate 
1420Sstevel@tonic-gate /* segment descriptor field perm. */
1430Sstevel@tonic-gate #define	SEGMENT_READ	4
1440Sstevel@tonic-gate #define	SEGMENT_WRITE	2
1450Sstevel@tonic-gate #define	SEGMENT_DELETE	1
1460Sstevel@tonic-gate 
1470Sstevel@tonic-gate typedef union
1480Sstevel@tonic-gate {
1490Sstevel@tonic-gate 	uint32_t all_bits;
1500Sstevel@tonic-gate 	struct
1510Sstevel@tonic-gate 	{
1520Sstevel@tonic-gate 		uint32_t read_only : 1;
1530Sstevel@tonic-gate 		unsigned : 7;
1540Sstevel@tonic-gate 		unsigned : 8;
1550Sstevel@tonic-gate 		unsigned : 8;
1560Sstevel@tonic-gate 		unsigned : 8;
1570Sstevel@tonic-gate 	} field;
1580Sstevel@tonic-gate } fru_seg_hwdesc_t;
1590Sstevel@tonic-gate 
1600Sstevel@tonic-gate #define	FRU_SEGNAMELEN 2
1610Sstevel@tonic-gate typedef struct {
1620Sstevel@tonic-gate 	uint32_t version;
1630Sstevel@tonic-gate 	char name[FRU_SEGNAMELEN + 1]; /* +1 to include '\0' byte. */
1640Sstevel@tonic-gate 	fru_segdesc_t desc;
1650Sstevel@tonic-gate 	uint32_t size;
1660Sstevel@tonic-gate 	uint32_t address; /* used for fixed segments (0 otherwise) */
1670Sstevel@tonic-gate 	fru_seg_hwdesc_t hw_desc;
1680Sstevel@tonic-gate } fru_segdef_t;
1690Sstevel@tonic-gate 
1700Sstevel@tonic-gate /* Fru enumerations */
1710Sstevel@tonic-gate typedef struct {
1720Sstevel@tonic-gate 	uint64_t value;
1730Sstevel@tonic-gate 	char *text;
1740Sstevel@tonic-gate } fru_enum_t;
1750Sstevel@tonic-gate 
1760Sstevel@tonic-gate /* Element/Field level operations */
1770Sstevel@tonic-gate #define	FRU_ELEMDEF_REV 1
1780Sstevel@tonic-gate typedef struct {
1790Sstevel@tonic-gate 	uint32_t version;
1800Sstevel@tonic-gate 	fru_datatype_t data_type;
1810Sstevel@tonic-gate 	fru_which_t tagged;
1820Sstevel@tonic-gate 	size_t data_length; /* in Bytes or Bits depending on data_type */
1830Sstevel@tonic-gate 	fru_displaytype_t disp_type;
1840Sstevel@tonic-gate 	fru_which_t purgeable;
1850Sstevel@tonic-gate 	fru_which_t relocatable;
1860Sstevel@tonic-gate 	unsigned int enum_count; /* number of enum values in table */
1870Sstevel@tonic-gate 	fru_enum_t *enum_table; /* enum strings or sub-elements depending on */
1880Sstevel@tonic-gate 					/* the data_type */
1890Sstevel@tonic-gate 	unsigned int iteration_count;
1900Sstevel@tonic-gate 	fru_itertype_t iteration_type;
1910Sstevel@tonic-gate 	char *example_string;
1920Sstevel@tonic-gate } fru_elemdef_t;
1930Sstevel@tonic-gate 
1940Sstevel@tonic-gate /* Data Source operations */
1950Sstevel@tonic-gate fru_errno_t fru_open_data_source(const char *name, ...);
1960Sstevel@tonic-gate fru_errno_t fru_close_data_source(void);
1970Sstevel@tonic-gate 
1980Sstevel@tonic-gate /* Tree operations */
1990Sstevel@tonic-gate fru_errno_t fru_get_root(fru_nodehdl_t *handle);
2000Sstevel@tonic-gate fru_errno_t fru_get_child(fru_nodehdl_t handle, fru_nodehdl_t *child);
2010Sstevel@tonic-gate fru_errno_t fru_get_peer(fru_nodehdl_t handle, fru_nodehdl_t *peer);
2020Sstevel@tonic-gate fru_errno_t fru_get_parent(fru_nodehdl_t handle, fru_nodehdl_t *parent);
2030Sstevel@tonic-gate 
2040Sstevel@tonic-gate /* Node information functions */
2050Sstevel@tonic-gate fru_errno_t fru_get_name_from_hdl(fru_nodehdl_t handle, char **name);
2060Sstevel@tonic-gate fru_errno_t fru_get_node_type(fru_nodehdl_t handle, fru_node_t *type);
2070Sstevel@tonic-gate 
2080Sstevel@tonic-gate /* Segment Operations */
2090Sstevel@tonic-gate fru_errno_t fru_list_segments(fru_nodehdl_t container, fru_strlist_t *list);
2100Sstevel@tonic-gate fru_errno_t fru_create_segment(fru_nodehdl_t container, fru_segdef_t *def);
2110Sstevel@tonic-gate fru_errno_t fru_remove_segment(fru_nodehdl_t container, const char *seg_name);
2120Sstevel@tonic-gate fru_errno_t fru_get_segment_def(fru_nodehdl_t container, const char *seg_name,
2130Sstevel@tonic-gate 				fru_segdef_t *definition);
2140Sstevel@tonic-gate fru_errno_t fru_list_elems_in(fru_nodehdl_t container, const char *seg_name,
2150Sstevel@tonic-gate 				fru_strlist_t *list);
2160Sstevel@tonic-gate 
2170Sstevel@tonic-gate /* Data operations */
2180Sstevel@tonic-gate fru_errno_t fru_read_field(fru_nodehdl_t container,
2190Sstevel@tonic-gate 			char **seg_name, /* IN/OUT */
2200Sstevel@tonic-gate 			unsigned int   instance,
2210Sstevel@tonic-gate 			const char *field_path,
2220Sstevel@tonic-gate 			void **data,
2230Sstevel@tonic-gate 			size_t *data_len,
2240Sstevel@tonic-gate 			char **found_path);
2250Sstevel@tonic-gate fru_errno_t fru_update_field(fru_nodehdl_t container,
2260Sstevel@tonic-gate 				char *seg_name,
2270Sstevel@tonic-gate 				unsigned int instance,
2280Sstevel@tonic-gate 				const char *field_path,
2290Sstevel@tonic-gate 				void *data,
2300Sstevel@tonic-gate 				size_t length);
2310Sstevel@tonic-gate fru_errno_t fru_get_num_iterations(fru_nodehdl_t container,
2320Sstevel@tonic-gate 					char **seg_name, /* IN/OUT */
2330Sstevel@tonic-gate 					unsigned int instance,
2340Sstevel@tonic-gate 					const char *iter_path,
2350Sstevel@tonic-gate 					int *num_there,
2360Sstevel@tonic-gate 					char **found_path);
2370Sstevel@tonic-gate 
2380Sstevel@tonic-gate /* Tagged Element operations */
2390Sstevel@tonic-gate fru_errno_t fru_add_element(fru_nodehdl_t container, const char *seg_name,
2400Sstevel@tonic-gate 				const char *element);
2410Sstevel@tonic-gate fru_errno_t fru_delete_element(fru_nodehdl_t container, const char *seg_name,
2420Sstevel@tonic-gate 				unsigned int instance, const char *element);
2430Sstevel@tonic-gate 
2440Sstevel@tonic-gate /* General library support */
2450Sstevel@tonic-gate fru_errno_t fru_get_definition(const char *element_name,
2460Sstevel@tonic-gate 				fru_elemdef_t *definition);
2470Sstevel@tonic-gate fru_errno_t fru_get_registry(fru_strlist_t *list);
2480Sstevel@tonic-gate fru_errno_t fru_get_tagged_parents(const char *elem_name,
2490Sstevel@tonic-gate 				fru_strlist_t *parents);
2500Sstevel@tonic-gate 
2510Sstevel@tonic-gate /* Structure destroy functions */
2520Sstevel@tonic-gate fru_errno_t fru_destroy_strlist(fru_strlist_t *list);
2530Sstevel@tonic-gate fru_errno_t fru_destroy_elemdef(fru_elemdef_t *def);
2540Sstevel@tonic-gate 
2550Sstevel@tonic-gate /* Enum to String Conversions */
2560Sstevel@tonic-gate const char *fru_strerror(fru_errno_t errnum);
2570Sstevel@tonic-gate const char *get_displaytype_str(fru_displaytype_t e);
2580Sstevel@tonic-gate const char *get_datatype_str(fru_datatype_t e);
2590Sstevel@tonic-gate const char *get_which_str(fru_which_t e);
2600Sstevel@tonic-gate const char *get_itertype_str(fru_itertype_t e);
2610Sstevel@tonic-gate 
2620Sstevel@tonic-gate #ifdef	__cplusplus
2630Sstevel@tonic-gate }
2640Sstevel@tonic-gate #endif
2650Sstevel@tonic-gate 
2660Sstevel@tonic-gate #endif /* _LIBFRU_H */
267