1*0Sstevel@tonic-gate /* 2*0Sstevel@tonic-gate * CDDL HEADER START 3*0Sstevel@tonic-gate * 4*0Sstevel@tonic-gate * The contents of this file are subject to the terms of the 5*0Sstevel@tonic-gate * Common Development and Distribution License, Version 1.0 only 6*0Sstevel@tonic-gate * (the "License"). You may not use this file except in compliance 7*0Sstevel@tonic-gate * with the License. 8*0Sstevel@tonic-gate * 9*0Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 10*0Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing. 11*0Sstevel@tonic-gate * See the License for the specific language governing permissions 12*0Sstevel@tonic-gate * and limitations under the License. 13*0Sstevel@tonic-gate * 14*0Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each 15*0Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 16*0Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the 17*0Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying 18*0Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner] 19*0Sstevel@tonic-gate * 20*0Sstevel@tonic-gate * CDDL HEADER END 21*0Sstevel@tonic-gate */ 22*0Sstevel@tonic-gate /* 23*0Sstevel@tonic-gate * Copyright 2000-2002 Sun Microsystems, Inc. All rights reserved. 24*0Sstevel@tonic-gate * Use is subject to license terms. 25*0Sstevel@tonic-gate */ 26*0Sstevel@tonic-gate 27*0Sstevel@tonic-gate #ifndef _LIBFRU_H 28*0Sstevel@tonic-gate #define _LIBFRU_H 29*0Sstevel@tonic-gate 30*0Sstevel@tonic-gate #pragma ident "%Z%%M% %I% %E% SMI" 31*0Sstevel@tonic-gate 32*0Sstevel@tonic-gate #ifdef __cplusplus 33*0Sstevel@tonic-gate extern "C" { 34*0Sstevel@tonic-gate #endif 35*0Sstevel@tonic-gate 36*0Sstevel@tonic-gate #include <sys/types.h> 37*0Sstevel@tonic-gate 38*0Sstevel@tonic-gate #define LIBFRU_VERSION 1 39*0Sstevel@tonic-gate 40*0Sstevel@tonic-gate /* fru errno return types */ 41*0Sstevel@tonic-gate typedef enum 42*0Sstevel@tonic-gate { 43*0Sstevel@tonic-gate FRU_SUCCESS = 0, 44*0Sstevel@tonic-gate FRU_NODENOTFOUND, 45*0Sstevel@tonic-gate FRU_IOERROR, 46*0Sstevel@tonic-gate FRU_NOREGDEF, 47*0Sstevel@tonic-gate FRU_NOTCONTAINER, 48*0Sstevel@tonic-gate FRU_INVALHANDLE, 49*0Sstevel@tonic-gate FRU_INVALSEG, 50*0Sstevel@tonic-gate FRU_INVALPATH, 51*0Sstevel@tonic-gate FRU_INVALELEMENT, 52*0Sstevel@tonic-gate FRU_INVALDATASIZE, 53*0Sstevel@tonic-gate FRU_DUPSEG, 54*0Sstevel@tonic-gate FRU_NOTFIELD, 55*0Sstevel@tonic-gate FRU_NOSPACE, 56*0Sstevel@tonic-gate FRU_DATANOTFOUND, 57*0Sstevel@tonic-gate FRU_ITERFULL, 58*0Sstevel@tonic-gate FRU_INVALPERM, 59*0Sstevel@tonic-gate FRU_NOTSUP, 60*0Sstevel@tonic-gate FRU_ELEMNOTTAGGED, 61*0Sstevel@tonic-gate FRU_CONTFAILED, 62*0Sstevel@tonic-gate FRU_SEGCORRUPT, 63*0Sstevel@tonic-gate FRU_DATACORRUPT, 64*0Sstevel@tonic-gate FRU_FAILURE, 65*0Sstevel@tonic-gate FRU_WALK_TERMINATE 66*0Sstevel@tonic-gate 67*0Sstevel@tonic-gate } fru_errno_t; 68*0Sstevel@tonic-gate 69*0Sstevel@tonic-gate /* 70*0Sstevel@tonic-gate * Structures for libfru.c 71*0Sstevel@tonic-gate */ 72*0Sstevel@tonic-gate 73*0Sstevel@tonic-gate /* Fru Display Types */ 74*0Sstevel@tonic-gate typedef enum { FDISP_Binary = 0, FDISP_Octal, FDISP_Hex, FDISP_Decimal, 75*0Sstevel@tonic-gate FDISP_String, FDISP_Time, FDISP_UNDEFINED 76*0Sstevel@tonic-gate } fru_displaytype_t; 77*0Sstevel@tonic-gate 78*0Sstevel@tonic-gate /* Fru Data Types */ 79*0Sstevel@tonic-gate typedef enum { FDTYPE_Binary = 0, FDTYPE_ByteArray, FDTYPE_ASCII, 80*0Sstevel@tonic-gate FDTYPE_Unicode, FDTYPE_Record, FDTYPE_Enumeration, 81*0Sstevel@tonic-gate FDTYPE_UNDEFINED 82*0Sstevel@tonic-gate } fru_datatype_t; 83*0Sstevel@tonic-gate 84*0Sstevel@tonic-gate /* Fru Which Type */ 85*0Sstevel@tonic-gate typedef enum { FRU_No = 0, FRU_Yes, FRU_WHICH_UNDEFINED } fru_which_t; 86*0Sstevel@tonic-gate 87*0Sstevel@tonic-gate /* Fru Iteration Types */ 88*0Sstevel@tonic-gate typedef enum { FRU_FIFO = 0, FRU_Circular, 89*0Sstevel@tonic-gate FRU_Linear, FRU_LIFO, FRU_NOT_ITERATED } fru_itertype_t; 90*0Sstevel@tonic-gate 91*0Sstevel@tonic-gate /* Fru Handle Type */ 92*0Sstevel@tonic-gate typedef uint64_t fru_nodehdl_t; 93*0Sstevel@tonic-gate 94*0Sstevel@tonic-gate /* Node Types */ 95*0Sstevel@tonic-gate typedef enum 96*0Sstevel@tonic-gate { 97*0Sstevel@tonic-gate FRU_NODE_UNKNOWN, 98*0Sstevel@tonic-gate FRU_NODE_LOCATION, 99*0Sstevel@tonic-gate FRU_NODE_FRU, 100*0Sstevel@tonic-gate FRU_NODE_CONTAINER 101*0Sstevel@tonic-gate } fru_node_t; 102*0Sstevel@tonic-gate 103*0Sstevel@tonic-gate /* Sting list */ 104*0Sstevel@tonic-gate typedef struct { 105*0Sstevel@tonic-gate unsigned int num; 106*0Sstevel@tonic-gate char **strs; 107*0Sstevel@tonic-gate } fru_strlist_t; 108*0Sstevel@tonic-gate 109*0Sstevel@tonic-gate typedef union 110*0Sstevel@tonic-gate { 111*0Sstevel@tonic-gate uint32_t raw_data; 112*0Sstevel@tonic-gate struct 113*0Sstevel@tonic-gate { 114*0Sstevel@tonic-gate unsigned encrypted : 1; 115*0Sstevel@tonic-gate unsigned ignore_checksum : 1; 116*0Sstevel@tonic-gate unsigned opaque : 1; 117*0Sstevel@tonic-gate unsigned fixed : 1; 118*0Sstevel@tonic-gate unsigned unused : 13; 119*0Sstevel@tonic-gate unsigned field_perm : 3; 120*0Sstevel@tonic-gate unsigned domain_perm : 3; 121*0Sstevel@tonic-gate unsigned operations_perm : 3; 122*0Sstevel@tonic-gate unsigned engineering_perm : 3; 123*0Sstevel@tonic-gate unsigned repair_perm : 3; 124*0Sstevel@tonic-gate } field; 125*0Sstevel@tonic-gate } fru_segdesc_t; 126*0Sstevel@tonic-gate 127*0Sstevel@tonic-gate #define FRU_SEGDESC_PERM_DELETE_MASK (1<<0) 128*0Sstevel@tonic-gate #define FRU_SEGDESC_PERM_WRITE_MASK (1<<1) 129*0Sstevel@tonic-gate #define FRU_SEGDESC_PERM_READ_MASK (1<<2) 130*0Sstevel@tonic-gate #define FRU_SEGDESC_PERM_RW_MASK ((1<<2) | (1<<1)) 131*0Sstevel@tonic-gate #define FRU_SEGDESC_PERM_RD_MASK ((1<<2) | (1<<0)) 132*0Sstevel@tonic-gate #define FRU_SEGDESC_PERM_WD_MASK ((1<<1) | (1<<0)) 133*0Sstevel@tonic-gate #define FRU_SEGDESC_PERM_RWD_MASK ((1<<0) | (1<<1) | (1<<2)) 134*0Sstevel@tonic-gate 135*0Sstevel@tonic-gate #define FRU_SEGDESC_ALL_RO_MASK 0x000036db 136*0Sstevel@tonic-gate 137*0Sstevel@tonic-gate #define FRU_SEGDESC_FIXED_MASK (1<<28) 138*0Sstevel@tonic-gate #define FRU_SEGDESC_OPAQUE_MASK (1<<29) 139*0Sstevel@tonic-gate #define FRU_SEGDESC_IGNORECHECKSUM_MASK (1<<30) 140*0Sstevel@tonic-gate #define FRU_SEGDESC_ENCRYPTED_MASK (1<<31) 141*0Sstevel@tonic-gate 142*0Sstevel@tonic-gate /* segment descriptor field perm. */ 143*0Sstevel@tonic-gate #define SEGMENT_READ 4 144*0Sstevel@tonic-gate #define SEGMENT_WRITE 2 145*0Sstevel@tonic-gate #define SEGMENT_DELETE 1 146*0Sstevel@tonic-gate 147*0Sstevel@tonic-gate typedef union 148*0Sstevel@tonic-gate { 149*0Sstevel@tonic-gate uint32_t all_bits; 150*0Sstevel@tonic-gate struct 151*0Sstevel@tonic-gate { 152*0Sstevel@tonic-gate uint32_t read_only : 1; 153*0Sstevel@tonic-gate unsigned : 7; 154*0Sstevel@tonic-gate unsigned : 8; 155*0Sstevel@tonic-gate unsigned : 8; 156*0Sstevel@tonic-gate unsigned : 8; 157*0Sstevel@tonic-gate } field; 158*0Sstevel@tonic-gate } fru_seg_hwdesc_t; 159*0Sstevel@tonic-gate 160*0Sstevel@tonic-gate #define FRU_SEGNAMELEN 2 161*0Sstevel@tonic-gate typedef struct { 162*0Sstevel@tonic-gate uint32_t version; 163*0Sstevel@tonic-gate char name[FRU_SEGNAMELEN + 1]; /* +1 to include '\0' byte. */ 164*0Sstevel@tonic-gate fru_segdesc_t desc; 165*0Sstevel@tonic-gate uint32_t size; 166*0Sstevel@tonic-gate uint32_t address; /* used for fixed segments (0 otherwise) */ 167*0Sstevel@tonic-gate fru_seg_hwdesc_t hw_desc; 168*0Sstevel@tonic-gate } fru_segdef_t; 169*0Sstevel@tonic-gate 170*0Sstevel@tonic-gate /* Fru enumerations */ 171*0Sstevel@tonic-gate typedef struct { 172*0Sstevel@tonic-gate uint64_t value; 173*0Sstevel@tonic-gate char *text; 174*0Sstevel@tonic-gate } fru_enum_t; 175*0Sstevel@tonic-gate 176*0Sstevel@tonic-gate /* Element/Field level operations */ 177*0Sstevel@tonic-gate #define FRU_ELEMDEF_REV 1 178*0Sstevel@tonic-gate typedef struct { 179*0Sstevel@tonic-gate uint32_t version; 180*0Sstevel@tonic-gate fru_datatype_t data_type; 181*0Sstevel@tonic-gate fru_which_t tagged; 182*0Sstevel@tonic-gate size_t data_length; /* in Bytes or Bits depending on data_type */ 183*0Sstevel@tonic-gate fru_displaytype_t disp_type; 184*0Sstevel@tonic-gate fru_which_t purgeable; 185*0Sstevel@tonic-gate fru_which_t relocatable; 186*0Sstevel@tonic-gate unsigned int enum_count; /* number of enum values in table */ 187*0Sstevel@tonic-gate fru_enum_t *enum_table; /* enum strings or sub-elements depending on */ 188*0Sstevel@tonic-gate /* the data_type */ 189*0Sstevel@tonic-gate unsigned int iteration_count; 190*0Sstevel@tonic-gate fru_itertype_t iteration_type; 191*0Sstevel@tonic-gate char *example_string; 192*0Sstevel@tonic-gate } fru_elemdef_t; 193*0Sstevel@tonic-gate 194*0Sstevel@tonic-gate /* Data Source operations */ 195*0Sstevel@tonic-gate fru_errno_t fru_open_data_source(const char *name, ...); 196*0Sstevel@tonic-gate fru_errno_t fru_close_data_source(void); 197*0Sstevel@tonic-gate 198*0Sstevel@tonic-gate /* Tree operations */ 199*0Sstevel@tonic-gate fru_errno_t fru_get_root(fru_nodehdl_t *handle); 200*0Sstevel@tonic-gate fru_errno_t fru_get_child(fru_nodehdl_t handle, fru_nodehdl_t *child); 201*0Sstevel@tonic-gate fru_errno_t fru_get_peer(fru_nodehdl_t handle, fru_nodehdl_t *peer); 202*0Sstevel@tonic-gate fru_errno_t fru_get_parent(fru_nodehdl_t handle, fru_nodehdl_t *parent); 203*0Sstevel@tonic-gate 204*0Sstevel@tonic-gate /* Node information functions */ 205*0Sstevel@tonic-gate fru_errno_t fru_get_name_from_hdl(fru_nodehdl_t handle, char **name); 206*0Sstevel@tonic-gate fru_errno_t fru_get_node_type(fru_nodehdl_t handle, fru_node_t *type); 207*0Sstevel@tonic-gate 208*0Sstevel@tonic-gate /* Segment Operations */ 209*0Sstevel@tonic-gate fru_errno_t fru_list_segments(fru_nodehdl_t container, fru_strlist_t *list); 210*0Sstevel@tonic-gate fru_errno_t fru_create_segment(fru_nodehdl_t container, fru_segdef_t *def); 211*0Sstevel@tonic-gate fru_errno_t fru_remove_segment(fru_nodehdl_t container, const char *seg_name); 212*0Sstevel@tonic-gate fru_errno_t fru_get_segment_def(fru_nodehdl_t container, const char *seg_name, 213*0Sstevel@tonic-gate fru_segdef_t *definition); 214*0Sstevel@tonic-gate fru_errno_t fru_list_elems_in(fru_nodehdl_t container, const char *seg_name, 215*0Sstevel@tonic-gate fru_strlist_t *list); 216*0Sstevel@tonic-gate 217*0Sstevel@tonic-gate /* Data operations */ 218*0Sstevel@tonic-gate fru_errno_t fru_read_field(fru_nodehdl_t container, 219*0Sstevel@tonic-gate char **seg_name, /* IN/OUT */ 220*0Sstevel@tonic-gate unsigned int instance, 221*0Sstevel@tonic-gate const char *field_path, 222*0Sstevel@tonic-gate void **data, 223*0Sstevel@tonic-gate size_t *data_len, 224*0Sstevel@tonic-gate char **found_path); 225*0Sstevel@tonic-gate fru_errno_t fru_update_field(fru_nodehdl_t container, 226*0Sstevel@tonic-gate char *seg_name, 227*0Sstevel@tonic-gate unsigned int instance, 228*0Sstevel@tonic-gate const char *field_path, 229*0Sstevel@tonic-gate void *data, 230*0Sstevel@tonic-gate size_t length); 231*0Sstevel@tonic-gate fru_errno_t fru_get_num_iterations(fru_nodehdl_t container, 232*0Sstevel@tonic-gate char **seg_name, /* IN/OUT */ 233*0Sstevel@tonic-gate unsigned int instance, 234*0Sstevel@tonic-gate const char *iter_path, 235*0Sstevel@tonic-gate int *num_there, 236*0Sstevel@tonic-gate char **found_path); 237*0Sstevel@tonic-gate 238*0Sstevel@tonic-gate /* Tagged Element operations */ 239*0Sstevel@tonic-gate fru_errno_t fru_add_element(fru_nodehdl_t container, const char *seg_name, 240*0Sstevel@tonic-gate const char *element); 241*0Sstevel@tonic-gate fru_errno_t fru_delete_element(fru_nodehdl_t container, const char *seg_name, 242*0Sstevel@tonic-gate unsigned int instance, const char *element); 243*0Sstevel@tonic-gate 244*0Sstevel@tonic-gate /* General library support */ 245*0Sstevel@tonic-gate fru_errno_t fru_get_definition(const char *element_name, 246*0Sstevel@tonic-gate fru_elemdef_t *definition); 247*0Sstevel@tonic-gate fru_errno_t fru_get_registry(fru_strlist_t *list); 248*0Sstevel@tonic-gate fru_errno_t fru_get_tagged_parents(const char *elem_name, 249*0Sstevel@tonic-gate fru_strlist_t *parents); 250*0Sstevel@tonic-gate 251*0Sstevel@tonic-gate /* Structure destroy functions */ 252*0Sstevel@tonic-gate fru_errno_t fru_destroy_strlist(fru_strlist_t *list); 253*0Sstevel@tonic-gate fru_errno_t fru_destroy_elemdef(fru_elemdef_t *def); 254*0Sstevel@tonic-gate 255*0Sstevel@tonic-gate /* Enum to String Conversions */ 256*0Sstevel@tonic-gate const char *fru_strerror(fru_errno_t errnum); 257*0Sstevel@tonic-gate const char *get_displaytype_str(fru_displaytype_t e); 258*0Sstevel@tonic-gate const char *get_datatype_str(fru_datatype_t e); 259*0Sstevel@tonic-gate const char *get_which_str(fru_which_t e); 260*0Sstevel@tonic-gate const char *get_itertype_str(fru_itertype_t e); 261*0Sstevel@tonic-gate 262*0Sstevel@tonic-gate #ifdef __cplusplus 263*0Sstevel@tonic-gate } 264*0Sstevel@tonic-gate #endif 265*0Sstevel@tonic-gate 266*0Sstevel@tonic-gate #endif /* _LIBFRU_H */ 267