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