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