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*1124Skmohan * 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 #pragma ident "%Z%%M% %I% %E% SMI"
280Sstevel@tonic-gate
290Sstevel@tonic-gate #include <alloca.h>
300Sstevel@tonic-gate #include <picl.h>
310Sstevel@tonic-gate #include <picltree.h>
320Sstevel@tonic-gate
330Sstevel@tonic-gate #include <string.h>
340Sstevel@tonic-gate #include <stdlib.h>
350Sstevel@tonic-gate #include <stdarg.h>
360Sstevel@tonic-gate #include <stdio.h>
370Sstevel@tonic-gate
380Sstevel@tonic-gate #include "picldefs.h"
390Sstevel@tonic-gate #include "fru_data.h"
400Sstevel@tonic-gate
410Sstevel@tonic-gate #include "libfruds.h"
420Sstevel@tonic-gate #include "libfrup.h"
430Sstevel@tonic-gate
440Sstevel@tonic-gate #define FRU_LABEL_PADDING 10
450Sstevel@tonic-gate
460Sstevel@tonic-gate /* ========================================================================= */
470Sstevel@tonic-gate #define TREEHDL_TO_PICLHDL(treehdl) ((picl_nodehdl_t)treehdl)
480Sstevel@tonic-gate #define PICLHDL_TO_TREEHDL(piclhdl) ((fru_treehdl_t)piclhdl)
490Sstevel@tonic-gate
500Sstevel@tonic-gate #define TREESEGHDL_TO_PICLHDL(treeseghdl) ((picl_nodehdl_t)treeseghdl)
510Sstevel@tonic-gate #define PICLHDL_TO_TREESEGHDL(piclhdl) ((fru_treeseghdl_t)piclhdl)
520Sstevel@tonic-gate
530Sstevel@tonic-gate /* Cache of the root node for quick checks */
540Sstevel@tonic-gate static picl_nodehdl_t picl_root_node;
550Sstevel@tonic-gate
560Sstevel@tonic-gate /* ========================================================================= */
570Sstevel@tonic-gate /*
580Sstevel@tonic-gate * Map the PICL errors the plugin would give me to FRU errors
590Sstevel@tonic-gate */
600Sstevel@tonic-gate static fru_errno_t
map_plugin_err(int picl_err)610Sstevel@tonic-gate map_plugin_err(int picl_err)
620Sstevel@tonic-gate {
630Sstevel@tonic-gate switch (picl_err) {
640Sstevel@tonic-gate case PICL_SUCCESS:
650Sstevel@tonic-gate return (FRU_SUCCESS);
660Sstevel@tonic-gate case PICL_PERMDENIED:
670Sstevel@tonic-gate return (FRU_INVALPERM);
680Sstevel@tonic-gate case PICL_PROPEXISTS:
690Sstevel@tonic-gate return (FRU_DUPSEG);
700Sstevel@tonic-gate case PICL_NOSPACE:
710Sstevel@tonic-gate return (FRU_NOSPACE);
72*1124Skmohan case PICL_NORESPONSE:
73*1124Skmohan return (FRU_NORESPONSE);
74*1124Skmohan case PICL_PROPNOTFOUND:
75*1124Skmohan return (FRU_NODENOTFOUND);
76*1124Skmohan case PICL_ENDOFLIST:
77*1124Skmohan return (FRU_DATANOTFOUND);
780Sstevel@tonic-gate }
790Sstevel@tonic-gate return (FRU_IOERROR);
800Sstevel@tonic-gate }
810Sstevel@tonic-gate
820Sstevel@tonic-gate /* ========================================================================= */
830Sstevel@tonic-gate /*
840Sstevel@tonic-gate * cause a refresh of the sub-nodes by writing anything to the container
850Sstevel@tonic-gate * property of the node.
860Sstevel@tonic-gate */
870Sstevel@tonic-gate static fru_errno_t
update_data_nodes(picl_nodehdl_t handle)880Sstevel@tonic-gate update_data_nodes(picl_nodehdl_t handle)
890Sstevel@tonic-gate {
900Sstevel@tonic-gate uint32_t container = FRUDATA_DELETE_TAG_KEY;
910Sstevel@tonic-gate int picl_err = PICL_SUCCESS;
920Sstevel@tonic-gate
930Sstevel@tonic-gate if ((picl_err = ptree_update_propval_by_name(handle,
940Sstevel@tonic-gate PICL_PROP_CONTAINER, (void *)&container,
950Sstevel@tonic-gate sizeof (container))) != PICL_SUCCESS) {
960Sstevel@tonic-gate return (map_plugin_err(picl_err));
970Sstevel@tonic-gate }
980Sstevel@tonic-gate
990Sstevel@tonic-gate return (FRU_SUCCESS);
1000Sstevel@tonic-gate }
1010Sstevel@tonic-gate
1020Sstevel@tonic-gate /* ========================================================================= */
1030Sstevel@tonic-gate /*
1040Sstevel@tonic-gate * picl like function which gets a string property with the proper length
1050Sstevel@tonic-gate * NOTE: returns picl errno values NOT fru_errno_t
1060Sstevel@tonic-gate */
1070Sstevel@tonic-gate static int
get_strprop_by_name(picl_nodehdl_t handle,char * prop_name,char ** string)1080Sstevel@tonic-gate get_strprop_by_name(picl_nodehdl_t handle, char *prop_name, char **string)
1090Sstevel@tonic-gate {
1100Sstevel@tonic-gate int picl_err = PICL_SUCCESS;
1110Sstevel@tonic-gate picl_prophdl_t proph;
1120Sstevel@tonic-gate
1130Sstevel@tonic-gate size_t buf_size = 0;
1140Sstevel@tonic-gate char *tmp_buf = NULL;
1150Sstevel@tonic-gate
1160Sstevel@tonic-gate ptree_propinfo_t prop_info;
1170Sstevel@tonic-gate
1180Sstevel@tonic-gate if ((picl_err = ptree_get_prop_by_name(handle, prop_name, &proph))
1190Sstevel@tonic-gate != PICL_SUCCESS) {
1200Sstevel@tonic-gate return (picl_err);
1210Sstevel@tonic-gate }
1220Sstevel@tonic-gate if ((picl_err = ptree_get_propinfo(proph, &prop_info))
1230Sstevel@tonic-gate != PICL_SUCCESS) {
1240Sstevel@tonic-gate return (picl_err);
1250Sstevel@tonic-gate }
1260Sstevel@tonic-gate buf_size = prop_info.piclinfo.size;
1270Sstevel@tonic-gate
1280Sstevel@tonic-gate tmp_buf = malloc((sizeof (*tmp_buf) * buf_size));
1290Sstevel@tonic-gate if (tmp_buf == NULL) {
1300Sstevel@tonic-gate return (PICL_FAILURE);
1310Sstevel@tonic-gate }
1320Sstevel@tonic-gate
1330Sstevel@tonic-gate if ((picl_err = ptree_get_propval(proph, tmp_buf, buf_size))
1340Sstevel@tonic-gate != PICL_SUCCESS) {
1350Sstevel@tonic-gate free(tmp_buf);
1360Sstevel@tonic-gate return (picl_err);
1370Sstevel@tonic-gate }
1380Sstevel@tonic-gate
1390Sstevel@tonic-gate *string = tmp_buf;
1400Sstevel@tonic-gate return (PICL_SUCCESS);
1410Sstevel@tonic-gate }
1420Sstevel@tonic-gate
1430Sstevel@tonic-gate /* ========================================================================= */
1440Sstevel@tonic-gate static fru_errno_t
fpt_get_name_from_hdl(fru_treehdl_t node,char ** name)1450Sstevel@tonic-gate fpt_get_name_from_hdl(fru_treehdl_t node, char **name)
1460Sstevel@tonic-gate {
1470Sstevel@tonic-gate int picl_err = PICL_SUCCESS;
1480Sstevel@tonic-gate char *tmp_name = NULL;
1490Sstevel@tonic-gate char *label = NULL;
1500Sstevel@tonic-gate picl_nodehdl_t handle = TREEHDL_TO_PICLHDL(node);
1510Sstevel@tonic-gate
1520Sstevel@tonic-gate /* get the name */
1530Sstevel@tonic-gate if ((picl_err = get_strprop_by_name(handle, PICL_PROP_NAME,
1540Sstevel@tonic-gate &tmp_name)) != PICL_SUCCESS) {
155*1124Skmohan return (map_plugin_err(picl_err));
1560Sstevel@tonic-gate }
1570Sstevel@tonic-gate
1580Sstevel@tonic-gate /* get the label, if any */
1590Sstevel@tonic-gate if ((picl_err = get_strprop_by_name(handle, PICL_PROP_LABEL,
1600Sstevel@tonic-gate &label)) != PICL_SUCCESS) {
1610Sstevel@tonic-gate if (picl_err != PICL_PROPNOTFOUND) {
1620Sstevel@tonic-gate free(tmp_name);
163*1124Skmohan return (map_plugin_err(picl_err));
1640Sstevel@tonic-gate }
1650Sstevel@tonic-gate /* else PICL_PROPNOTFOUND is OK because not all nodes */
1660Sstevel@tonic-gate /* will have a label. */
1670Sstevel@tonic-gate }
1680Sstevel@tonic-gate
1690Sstevel@tonic-gate /* construct the name as nessecary */
1700Sstevel@tonic-gate if (label == NULL) {
1710Sstevel@tonic-gate *name = strdup(tmp_name);
1720Sstevel@tonic-gate } else {
1730Sstevel@tonic-gate size_t buf_size = strlen(tmp_name) + strlen(label) +
1740Sstevel@tonic-gate FRU_LABEL_PADDING;
1750Sstevel@tonic-gate char *tmp = malloc(buf_size);
1760Sstevel@tonic-gate if (tmp == NULL) {
1770Sstevel@tonic-gate free(tmp_name);
1780Sstevel@tonic-gate free(label);
1790Sstevel@tonic-gate return (FRU_FAILURE);
1800Sstevel@tonic-gate }
1810Sstevel@tonic-gate snprintf(tmp, buf_size, "%s?%s=%s", tmp_name,
1820Sstevel@tonic-gate PICL_PROP_LABEL, label);
1830Sstevel@tonic-gate *name = tmp;
1840Sstevel@tonic-gate }
1850Sstevel@tonic-gate
1860Sstevel@tonic-gate free(tmp_name);
1870Sstevel@tonic-gate free(label);
1880Sstevel@tonic-gate return (FRU_SUCCESS);
1890Sstevel@tonic-gate }
1900Sstevel@tonic-gate
1910Sstevel@tonic-gate /* ========================================================================= */
1920Sstevel@tonic-gate /* compare the node name to the name passed */
1930Sstevel@tonic-gate static fru_errno_t
cmp_node_name(picl_nodehdl_t node,const char * name)1940Sstevel@tonic-gate cmp_node_name(picl_nodehdl_t node, const char *name)
1950Sstevel@tonic-gate {
1960Sstevel@tonic-gate char *node_name = NULL;
1970Sstevel@tonic-gate
1980Sstevel@tonic-gate if (get_strprop_by_name(node, PICL_PROP_NAME, &node_name)
1990Sstevel@tonic-gate != PICL_SUCCESS) {
2000Sstevel@tonic-gate return (FRU_FAILURE);
2010Sstevel@tonic-gate }
2020Sstevel@tonic-gate
2030Sstevel@tonic-gate if (strcmp(node_name, name) == 0) {
2040Sstevel@tonic-gate free(node_name);
2050Sstevel@tonic-gate return (FRU_SUCCESS);
2060Sstevel@tonic-gate }
2070Sstevel@tonic-gate
2080Sstevel@tonic-gate free(node_name);
2090Sstevel@tonic-gate return (FRU_FAILURE);
2100Sstevel@tonic-gate }
2110Sstevel@tonic-gate
2120Sstevel@tonic-gate /* ========================================================================= */
2130Sstevel@tonic-gate /* compare the node class name to the name passed */
2140Sstevel@tonic-gate static fru_errno_t
cmp_class_name(picl_nodehdl_t node,const char * name)2150Sstevel@tonic-gate cmp_class_name(picl_nodehdl_t node, const char *name)
2160Sstevel@tonic-gate {
2170Sstevel@tonic-gate char *class_name = NULL;
2180Sstevel@tonic-gate
2190Sstevel@tonic-gate if (get_strprop_by_name(node, PICL_PROP_CLASSNAME, &class_name)
2200Sstevel@tonic-gate != PICL_SUCCESS) {
2210Sstevel@tonic-gate return (FRU_FAILURE);
2220Sstevel@tonic-gate }
2230Sstevel@tonic-gate
2240Sstevel@tonic-gate if (strcmp(class_name, name) == 0) {
2250Sstevel@tonic-gate free(class_name);
2260Sstevel@tonic-gate return (FRU_SUCCESS);
2270Sstevel@tonic-gate }
2280Sstevel@tonic-gate
2290Sstevel@tonic-gate free(class_name);
2300Sstevel@tonic-gate return (FRU_FAILURE);
2310Sstevel@tonic-gate }
2320Sstevel@tonic-gate
2330Sstevel@tonic-gate
2340Sstevel@tonic-gate /* ========================================================================= */
2350Sstevel@tonic-gate /* get the "frutree" root node */
2360Sstevel@tonic-gate static fru_errno_t
fpt_get_root(fru_treehdl_t * node)2370Sstevel@tonic-gate fpt_get_root(fru_treehdl_t *node)
2380Sstevel@tonic-gate {
2390Sstevel@tonic-gate picl_nodehdl_t picl_node;
2400Sstevel@tonic-gate int picl_err = PICL_SUCCESS;
2410Sstevel@tonic-gate
2420Sstevel@tonic-gate picl_err = ptree_get_root(&picl_node);
2430Sstevel@tonic-gate if ((picl_err = ptree_get_propval_by_name(picl_node, PICL_PROP_CHILD,
2440Sstevel@tonic-gate (void *)&picl_node, sizeof (picl_node)))
2450Sstevel@tonic-gate != PICL_SUCCESS) {
246*1124Skmohan return (map_plugin_err(picl_err));
2470Sstevel@tonic-gate }
2480Sstevel@tonic-gate
2490Sstevel@tonic-gate while (cmp_node_name(picl_node, PICL_NODE_FRUTREE)
2500Sstevel@tonic-gate != FRU_SUCCESS) {
2510Sstevel@tonic-gate
2520Sstevel@tonic-gate if ((picl_err = ptree_get_propval_by_name(picl_node,
2530Sstevel@tonic-gate PICL_PROP_PEER, (void *)&picl_node,
2540Sstevel@tonic-gate sizeof (picl_node))) == PICL_PROPNOTFOUND) {
2550Sstevel@tonic-gate return (FRU_NODENOTFOUND);
2560Sstevel@tonic-gate } else if (picl_err != PICL_SUCCESS) {
257*1124Skmohan return (map_plugin_err(picl_err));
2580Sstevel@tonic-gate }
2590Sstevel@tonic-gate }
2600Sstevel@tonic-gate
2610Sstevel@tonic-gate picl_root_node = picl_node;
2620Sstevel@tonic-gate *node = PICLHDL_TO_TREEHDL(picl_node);
2630Sstevel@tonic-gate return (FRU_SUCCESS);
2640Sstevel@tonic-gate }
2650Sstevel@tonic-gate
2660Sstevel@tonic-gate /* ========================================================================= */
2670Sstevel@tonic-gate static fru_errno_t
fpt_get_peer(fru_treehdl_t sibling,fru_treehdl_t * peer)2680Sstevel@tonic-gate fpt_get_peer(fru_treehdl_t sibling, fru_treehdl_t *peer)
2690Sstevel@tonic-gate {
2700Sstevel@tonic-gate int rc = PICL_SUCCESS;
2710Sstevel@tonic-gate picl_nodehdl_t handle = TREEHDL_TO_PICLHDL(sibling);
2720Sstevel@tonic-gate picl_nodehdl_t picl_peer;
2730Sstevel@tonic-gate
2740Sstevel@tonic-gate rc = ptree_get_propval_by_name(handle, PICL_PROP_PEER,
2750Sstevel@tonic-gate (void *)&picl_peer, sizeof (picl_peer));
2760Sstevel@tonic-gate if (rc != PICL_SUCCESS) {
277*1124Skmohan return (map_plugin_err(rc));
2780Sstevel@tonic-gate }
2790Sstevel@tonic-gate
2800Sstevel@tonic-gate *peer = PICLHDL_TO_TREEHDL(picl_peer);
2810Sstevel@tonic-gate return (FRU_SUCCESS);
2820Sstevel@tonic-gate }
2830Sstevel@tonic-gate
2840Sstevel@tonic-gate /* ========================================================================= */
2850Sstevel@tonic-gate static fru_errno_t
fpt_get_child(fru_treehdl_t handle,fru_treehdl_t * child)2860Sstevel@tonic-gate fpt_get_child(fru_treehdl_t handle, fru_treehdl_t *child)
2870Sstevel@tonic-gate {
2880Sstevel@tonic-gate picl_nodehdl_t p_child;
2890Sstevel@tonic-gate int rc = ptree_get_propval_by_name(TREEHDL_TO_PICLHDL(handle),
2900Sstevel@tonic-gate PICL_PROP_CHILD, (void *)&p_child, sizeof (p_child));
2910Sstevel@tonic-gate if (rc != PICL_SUCCESS) {
292*1124Skmohan return (map_plugin_err(rc));
2930Sstevel@tonic-gate }
2940Sstevel@tonic-gate
2950Sstevel@tonic-gate *child = PICLHDL_TO_TREEHDL(p_child);
2960Sstevel@tonic-gate return (FRU_SUCCESS);
2970Sstevel@tonic-gate }
2980Sstevel@tonic-gate
2990Sstevel@tonic-gate /* ========================================================================= */
3000Sstevel@tonic-gate static fru_errno_t
fpt_get_parent(fru_treehdl_t handle,fru_treehdl_t * parent)3010Sstevel@tonic-gate fpt_get_parent(fru_treehdl_t handle, fru_treehdl_t *parent)
3020Sstevel@tonic-gate {
3030Sstevel@tonic-gate int rc = PICL_SUCCESS;
3040Sstevel@tonic-gate picl_nodehdl_t p_parent;
3050Sstevel@tonic-gate
3060Sstevel@tonic-gate /* do not allow the libfru users to see the parent of the root */
3070Sstevel@tonic-gate if (TREEHDL_TO_PICLHDL(handle) == picl_root_node) {
3080Sstevel@tonic-gate return (FRU_NODENOTFOUND);
3090Sstevel@tonic-gate }
3100Sstevel@tonic-gate
3110Sstevel@tonic-gate rc = ptree_get_propval_by_name(TREEHDL_TO_PICLHDL(handle),
3120Sstevel@tonic-gate PICL_PROP_PARENT, (void *)&p_parent, sizeof (p_parent));
3130Sstevel@tonic-gate if (rc != PICL_SUCCESS) {
314*1124Skmohan return (map_plugin_err(rc));
3150Sstevel@tonic-gate }
3160Sstevel@tonic-gate
3170Sstevel@tonic-gate *parent = PICLHDL_TO_TREEHDL(p_parent);
3180Sstevel@tonic-gate return (FRU_SUCCESS);
3190Sstevel@tonic-gate }
3200Sstevel@tonic-gate
3210Sstevel@tonic-gate /* ========================================================================= */
3220Sstevel@tonic-gate static fru_errno_t
fpt_get_node_type(fru_treehdl_t node,fru_node_t * type)3230Sstevel@tonic-gate fpt_get_node_type(fru_treehdl_t node, fru_node_t *type)
3240Sstevel@tonic-gate {
325*1124Skmohan int rc = PICL_SUCCESS;
3260Sstevel@tonic-gate char picl_class[PICL_PROPNAMELEN_MAX];
3270Sstevel@tonic-gate picl_nodehdl_t handle = TREEHDL_TO_PICLHDL(node);
3280Sstevel@tonic-gate
329*1124Skmohan if ((rc = ptree_get_propval_by_name(handle, PICL_PROP_CLASSNAME,
330*1124Skmohan picl_class, sizeof (picl_class))) != PICL_SUCCESS) {
331*1124Skmohan return (map_plugin_err(rc));
3320Sstevel@tonic-gate }
3330Sstevel@tonic-gate
3340Sstevel@tonic-gate if (strcmp(picl_class, PICL_CLASS_LOCATION) == 0) {
3350Sstevel@tonic-gate *type = FRU_NODE_LOCATION;
3360Sstevel@tonic-gate return (FRU_SUCCESS);
3370Sstevel@tonic-gate } else if (strcmp(picl_class, PICL_CLASS_FRU) == 0) {
3380Sstevel@tonic-gate picl_prophdl_t proph;
3390Sstevel@tonic-gate
3400Sstevel@tonic-gate /* check for the CONTAINER_PROP property which indicates */
3410Sstevel@tonic-gate /* there is data for this node. (ie fru is a container) */
3420Sstevel@tonic-gate if (ptree_get_prop_by_name(handle,
3430Sstevel@tonic-gate PICL_PROP_CONTAINER, &proph) == PICL_SUCCESS) {
3440Sstevel@tonic-gate *type = FRU_NODE_CONTAINER;
3450Sstevel@tonic-gate return (FRU_SUCCESS);
3460Sstevel@tonic-gate }
3470Sstevel@tonic-gate *type = FRU_NODE_FRU;
3480Sstevel@tonic-gate return (FRU_SUCCESS);
3490Sstevel@tonic-gate }
3500Sstevel@tonic-gate
3510Sstevel@tonic-gate *type = FRU_NODE_UNKNOWN;
3520Sstevel@tonic-gate return (FRU_SUCCESS);
3530Sstevel@tonic-gate }
3540Sstevel@tonic-gate
3550Sstevel@tonic-gate /* ========================================================================= */
3560Sstevel@tonic-gate /* find the next section or return NODENOTFOUND */
3570Sstevel@tonic-gate static fru_errno_t
find_next_section(picl_nodehdl_t current,picl_nodehdl_t * next)3580Sstevel@tonic-gate find_next_section(picl_nodehdl_t current, picl_nodehdl_t *next)
3590Sstevel@tonic-gate {
3600Sstevel@tonic-gate picl_nodehdl_t rc_next;
3610Sstevel@tonic-gate
3620Sstevel@tonic-gate if (ptree_get_propval_by_name(current, PICL_PROP_PEER,
3630Sstevel@tonic-gate (void *)&rc_next, sizeof (rc_next)) != PICL_SUCCESS) {
3640Sstevel@tonic-gate return (FRU_NODENOTFOUND);
3650Sstevel@tonic-gate }
3660Sstevel@tonic-gate
3670Sstevel@tonic-gate /* Make sure this is a "Section" node */
3680Sstevel@tonic-gate if (cmp_class_name(rc_next, PICL_CLASS_SECTION)
3690Sstevel@tonic-gate == FRU_SUCCESS) {
3700Sstevel@tonic-gate *next = rc_next;
3710Sstevel@tonic-gate return (FRU_SUCCESS);
3720Sstevel@tonic-gate }
3730Sstevel@tonic-gate
3740Sstevel@tonic-gate /* and if this is not good keep trying to find a peer which */
3750Sstevel@tonic-gate /* is a section */
3760Sstevel@tonic-gate return (find_next_section(rc_next, next));
3770Sstevel@tonic-gate }
3780Sstevel@tonic-gate
3790Sstevel@tonic-gate /* ========================================================================= */
3800Sstevel@tonic-gate /* find the first section or return NODENOTFOUND */
3810Sstevel@tonic-gate static fru_errno_t
find_first_section(picl_nodehdl_t parent,picl_nodehdl_t * section)3820Sstevel@tonic-gate find_first_section(picl_nodehdl_t parent, picl_nodehdl_t *section)
3830Sstevel@tonic-gate {
3840Sstevel@tonic-gate picl_nodehdl_t rc_section;
3850Sstevel@tonic-gate
3860Sstevel@tonic-gate if (ptree_get_propval_by_name(parent, PICL_PROP_CHILD,
3870Sstevel@tonic-gate (void *)&rc_section, sizeof (rc_section)) != PICL_SUCCESS) {
3880Sstevel@tonic-gate return (FRU_NODENOTFOUND);
3890Sstevel@tonic-gate }
3900Sstevel@tonic-gate
3910Sstevel@tonic-gate /* Make sure this is a "Section" node */
3920Sstevel@tonic-gate if (cmp_class_name(rc_section, PICL_CLASS_SECTION)
3930Sstevel@tonic-gate == FRU_SUCCESS) {
3940Sstevel@tonic-gate *section = rc_section;
3950Sstevel@tonic-gate return (FRU_SUCCESS);
3960Sstevel@tonic-gate }
3970Sstevel@tonic-gate
3980Sstevel@tonic-gate /* and if this is not good keep trying to find a peer which */
3990Sstevel@tonic-gate /* is a section */
4000Sstevel@tonic-gate return (find_next_section(rc_section, section));
4010Sstevel@tonic-gate }
4020Sstevel@tonic-gate
4030Sstevel@tonic-gate /* ========================================================================= */
4040Sstevel@tonic-gate /*
4050Sstevel@tonic-gate * Find the handle of the segment node "segment".
4060Sstevel@tonic-gate * also returns the hardware description of this segment. (read from the
4070Sstevel@tonic-gate * section this was found in.)
4080Sstevel@tonic-gate * If the ign_cor_flg is set this will still succeed even if the segment is
4090Sstevel@tonic-gate * corrupt, otherwise it will return FRU_SEGCORRUPT for corrupt segments
4100Sstevel@tonic-gate */
4110Sstevel@tonic-gate #define IGN_CORRUPT_YES 1
4120Sstevel@tonic-gate #define IGN_CORRUPT_NO 0
4130Sstevel@tonic-gate static fru_errno_t
get_segment_node(picl_nodehdl_t handle,const char * segment,picl_nodehdl_t * seg_hdl,fru_seg_hwdesc_t * hw_desc,int ign_cor_flg)4140Sstevel@tonic-gate get_segment_node(picl_nodehdl_t handle, const char *segment,
4150Sstevel@tonic-gate picl_nodehdl_t *seg_hdl, fru_seg_hwdesc_t *hw_desc, int ign_cor_flg)
4160Sstevel@tonic-gate {
4170Sstevel@tonic-gate fru_errno_t err = FRU_SUCCESS;
4180Sstevel@tonic-gate picl_nodehdl_t sect_node;
4190Sstevel@tonic-gate
4200Sstevel@tonic-gate if ((err = update_data_nodes(handle)) != FRU_SUCCESS) {
4210Sstevel@tonic-gate return (err);
4220Sstevel@tonic-gate }
4230Sstevel@tonic-gate
4240Sstevel@tonic-gate if ((err = find_first_section(handle, §_node)) != FRU_SUCCESS) {
4250Sstevel@tonic-gate return (err);
4260Sstevel@tonic-gate }
4270Sstevel@tonic-gate
4280Sstevel@tonic-gate /* while there are sections. */
4290Sstevel@tonic-gate while (err == FRU_SUCCESS) {
4300Sstevel@tonic-gate uint32_t num_segs = 0;
4310Sstevel@tonic-gate int rc = PICL_SUCCESS;
4320Sstevel@tonic-gate picl_nodehdl_t seg_node;
4330Sstevel@tonic-gate
4340Sstevel@tonic-gate /* do this just in case the Segments have not been built. */
4350Sstevel@tonic-gate if ((rc = ptree_get_propval_by_name(sect_node,
4360Sstevel@tonic-gate PICL_PROP_NUM_SEGMENTS,
4370Sstevel@tonic-gate (void *)&num_segs,
4380Sstevel@tonic-gate sizeof (num_segs))) != PICL_SUCCESS) {
4390Sstevel@tonic-gate return (map_plugin_err(rc));
4400Sstevel@tonic-gate }
4410Sstevel@tonic-gate
4420Sstevel@tonic-gate /* while there are segments. */
4430Sstevel@tonic-gate rc = ptree_get_propval_by_name(sect_node, PICL_PROP_CHILD,
4440Sstevel@tonic-gate (void *)&seg_node, sizeof (seg_node));
4450Sstevel@tonic-gate while (rc == PICL_SUCCESS) {
4460Sstevel@tonic-gate char name[PICL_PROPNAMELEN_MAX];
4470Sstevel@tonic-gate ptree_get_propval_by_name(seg_node, PICL_PROP_NAME,
4480Sstevel@tonic-gate name, sizeof (name));
4490Sstevel@tonic-gate if (strcmp(segment, name) == 0) {
4500Sstevel@tonic-gate int dummy = 0;
4510Sstevel@tonic-gate int protection = 0;
4520Sstevel@tonic-gate /* NUM_TAGS prop exists iff segment is OK */
4530Sstevel@tonic-gate if ((ign_cor_flg == IGN_CORRUPT_NO) &&
4540Sstevel@tonic-gate (ptree_get_propval_by_name(seg_node,
4550Sstevel@tonic-gate PICL_PROP_NUM_TAGS,
4560Sstevel@tonic-gate (void *)&dummy,
4570Sstevel@tonic-gate sizeof (dummy)) != PICL_SUCCESS)) {
4580Sstevel@tonic-gate return (FRU_SEGCORRUPT);
4590Sstevel@tonic-gate }
4600Sstevel@tonic-gate /* get the HW protections of this section. */
461*1124Skmohan if ((rc = ptree_get_propval_by_name(sect_node,
4620Sstevel@tonic-gate PICL_PROP_PROTECTED,
4630Sstevel@tonic-gate (void *)&protection,
464*1124Skmohan sizeof (protection)))
465*1124Skmohan != PICL_SUCCESS) {
466*1124Skmohan return (map_plugin_err(rc));
4670Sstevel@tonic-gate }
4680Sstevel@tonic-gate hw_desc->all_bits = 0;
4690Sstevel@tonic-gate hw_desc->field.read_only = protection;
4700Sstevel@tonic-gate
4710Sstevel@tonic-gate *seg_hdl = seg_node;
4720Sstevel@tonic-gate return (FRU_SUCCESS);
4730Sstevel@tonic-gate }
4740Sstevel@tonic-gate rc = ptree_get_propval_by_name(seg_node, PICL_PROP_PEER,
4750Sstevel@tonic-gate (void *)&seg_node, sizeof (seg_node));
4760Sstevel@tonic-gate }
4770Sstevel@tonic-gate
4780Sstevel@tonic-gate /* Peer property not found is ok */
4790Sstevel@tonic-gate if (rc != PICL_PROPNOTFOUND) {
480*1124Skmohan return (map_plugin_err(rc));
4810Sstevel@tonic-gate }
4820Sstevel@tonic-gate
4830Sstevel@tonic-gate err = find_next_section(sect_node, §_node);
4840Sstevel@tonic-gate }
4850Sstevel@tonic-gate
4860Sstevel@tonic-gate return (FRU_INVALSEG);
4870Sstevel@tonic-gate }
4880Sstevel@tonic-gate
4890Sstevel@tonic-gate /* ========================================================================= */
4900Sstevel@tonic-gate /*
4910Sstevel@tonic-gate * For the section handle passed add to list all the segment names found.
4920Sstevel@tonic-gate * Also incriments total by the number found.
4930Sstevel@tonic-gate */
4940Sstevel@tonic-gate static fru_errno_t
add_segs_for_section(picl_nodehdl_t section,fru_strlist_t * list)4950Sstevel@tonic-gate add_segs_for_section(picl_nodehdl_t section, fru_strlist_t *list)
4960Sstevel@tonic-gate {
4970Sstevel@tonic-gate int num_segments = 0;
4980Sstevel@tonic-gate int rc = PICL_SUCCESS;
4990Sstevel@tonic-gate
5000Sstevel@tonic-gate if ((rc = ptree_get_propval_by_name(section,
5010Sstevel@tonic-gate PICL_PROP_NUM_SEGMENTS,
5020Sstevel@tonic-gate (void *)&num_segments,
5030Sstevel@tonic-gate sizeof (num_segments))) != PICL_SUCCESS) {
5040Sstevel@tonic-gate fru_destroy_strlist(list);
5050Sstevel@tonic-gate return (map_plugin_err(rc));
5060Sstevel@tonic-gate }
5070Sstevel@tonic-gate
5080Sstevel@tonic-gate if (num_segments != 0) {
5090Sstevel@tonic-gate picl_nodehdl_t seg_node;
5100Sstevel@tonic-gate int total_space = list->num + num_segments;
5110Sstevel@tonic-gate
5120Sstevel@tonic-gate list->strs = realloc(list->strs,
5130Sstevel@tonic-gate (sizeof (*(list->strs)) * (total_space)));
5140Sstevel@tonic-gate if (list->strs == NULL) {
5150Sstevel@tonic-gate return (FRU_FAILURE);
5160Sstevel@tonic-gate }
5170Sstevel@tonic-gate
5180Sstevel@tonic-gate /* get the first segment */
5190Sstevel@tonic-gate rc = ptree_get_propval_by_name(section,
5200Sstevel@tonic-gate PICL_PROP_CHILD, (void *)&seg_node,
5210Sstevel@tonic-gate sizeof (seg_node));
5220Sstevel@tonic-gate
5230Sstevel@tonic-gate /* while there are more segments. */
5240Sstevel@tonic-gate while (rc == PICL_SUCCESS) {
5250Sstevel@tonic-gate char name[FRU_SEGNAMELEN +1];
5260Sstevel@tonic-gate
5270Sstevel@tonic-gate if ((rc = ptree_get_propval_by_name(seg_node,
5280Sstevel@tonic-gate PICL_PROP_NAME, name,
5290Sstevel@tonic-gate sizeof (name))) != PICL_SUCCESS) {
5300Sstevel@tonic-gate break;
5310Sstevel@tonic-gate }
5320Sstevel@tonic-gate
5330Sstevel@tonic-gate /* check array bounds */
5340Sstevel@tonic-gate if (list->num >= total_space) {
5350Sstevel@tonic-gate /* PICL reported incorrect number of segs */
5360Sstevel@tonic-gate return (FRU_IOERROR);
5370Sstevel@tonic-gate }
5380Sstevel@tonic-gate list->strs[(list->num)++] = strdup(name);
5390Sstevel@tonic-gate
5400Sstevel@tonic-gate rc = ptree_get_propval_by_name(seg_node,
5410Sstevel@tonic-gate PICL_PROP_PEER, (void *)&seg_node,
5420Sstevel@tonic-gate sizeof (seg_node));
5430Sstevel@tonic-gate }
5440Sstevel@tonic-gate
5450Sstevel@tonic-gate /* Peer property not found is ok */
5460Sstevel@tonic-gate if (rc != PICL_PROPNOTFOUND) {
547*1124Skmohan return (map_plugin_err(rc));
5480Sstevel@tonic-gate }
5490Sstevel@tonic-gate
5500Sstevel@tonic-gate }
5510Sstevel@tonic-gate return (FRU_SUCCESS);
5520Sstevel@tonic-gate }
5530Sstevel@tonic-gate
5540Sstevel@tonic-gate /* ========================================================================= */
5550Sstevel@tonic-gate static fru_errno_t
fpt_get_seg_list(fru_treehdl_t handle,fru_strlist_t * list)5560Sstevel@tonic-gate fpt_get_seg_list(fru_treehdl_t handle, fru_strlist_t *list)
5570Sstevel@tonic-gate {
5580Sstevel@tonic-gate fru_errno_t err;
5590Sstevel@tonic-gate picl_nodehdl_t sect_node;
5600Sstevel@tonic-gate fru_strlist_t rc_list;
5610Sstevel@tonic-gate rc_list.num = 0;
5620Sstevel@tonic-gate rc_list.strs = NULL;
5630Sstevel@tonic-gate
5640Sstevel@tonic-gate if ((err = update_data_nodes(TREEHDL_TO_PICLHDL(handle)))
5650Sstevel@tonic-gate != FRU_SUCCESS) {
5660Sstevel@tonic-gate return (err);
5670Sstevel@tonic-gate }
5680Sstevel@tonic-gate
5690Sstevel@tonic-gate if ((err = find_first_section(TREEHDL_TO_PICLHDL(handle), §_node))
5700Sstevel@tonic-gate != FRU_SUCCESS) {
5710Sstevel@tonic-gate return (err);
5720Sstevel@tonic-gate }
5730Sstevel@tonic-gate
5740Sstevel@tonic-gate /* while there are sections. */
5750Sstevel@tonic-gate while (err == FRU_SUCCESS) {
5760Sstevel@tonic-gate if ((err = add_segs_for_section(sect_node, &rc_list))
5770Sstevel@tonic-gate != FRU_SUCCESS) {
5780Sstevel@tonic-gate fru_destroy_strlist(&rc_list);
5790Sstevel@tonic-gate return (err);
5800Sstevel@tonic-gate }
5810Sstevel@tonic-gate err = find_next_section(sect_node, §_node);
5820Sstevel@tonic-gate }
5830Sstevel@tonic-gate
5840Sstevel@tonic-gate list->num = rc_list.num;
5850Sstevel@tonic-gate list->strs = rc_list.strs;
5860Sstevel@tonic-gate
5870Sstevel@tonic-gate return (FRU_SUCCESS);
5880Sstevel@tonic-gate }
5890Sstevel@tonic-gate
5900Sstevel@tonic-gate /* ========================================================================= */
5910Sstevel@tonic-gate static fru_errno_t
fpt_get_seg_def(fru_treehdl_t handle,const char * seg_name,fru_segdef_t * def)5920Sstevel@tonic-gate fpt_get_seg_def(fru_treehdl_t handle, const char *seg_name, fru_segdef_t *def)
5930Sstevel@tonic-gate {
5940Sstevel@tonic-gate fru_errno_t err = FRU_SUCCESS;
5950Sstevel@tonic-gate picl_nodehdl_t seg_node;
5960Sstevel@tonic-gate fru_seg_hwdesc_t hw_desc;
5970Sstevel@tonic-gate
5980Sstevel@tonic-gate fru_segdesc_t desc;
5990Sstevel@tonic-gate uint32_t size;
6000Sstevel@tonic-gate uint32_t address;
6010Sstevel@tonic-gate /* LINTED */
6020Sstevel@tonic-gate int picl_err = PICL_SUCCESS;
6030Sstevel@tonic-gate
6040Sstevel@tonic-gate if ((err = get_segment_node(TREEHDL_TO_PICLHDL(handle), seg_name,
6050Sstevel@tonic-gate &seg_node, &hw_desc, IGN_CORRUPT_YES)) != FRU_SUCCESS)
6060Sstevel@tonic-gate return (err);
6070Sstevel@tonic-gate
6080Sstevel@tonic-gate if ((picl_err = ptree_get_propval_by_name(seg_node,
6090Sstevel@tonic-gate PICL_PROP_DESCRIPTOR,
6100Sstevel@tonic-gate &desc, sizeof (desc))) != PICL_SUCCESS) {
611*1124Skmohan return (map_plugin_err(picl_err));
6120Sstevel@tonic-gate }
6130Sstevel@tonic-gate
6140Sstevel@tonic-gate if ((picl_err = ptree_get_propval_by_name(seg_node,
6150Sstevel@tonic-gate PICL_PROP_LENGTH,
6160Sstevel@tonic-gate &size, sizeof (size))) != PICL_SUCCESS) {
617*1124Skmohan return (map_plugin_err(picl_err));
6180Sstevel@tonic-gate }
6190Sstevel@tonic-gate
6200Sstevel@tonic-gate if ((picl_err = ptree_get_propval_by_name(seg_node,
6210Sstevel@tonic-gate PICL_PROP_OFFSET,
6220Sstevel@tonic-gate &address, sizeof (address))) != PICL_SUCCESS) {
623*1124Skmohan return (map_plugin_err(picl_err));
6240Sstevel@tonic-gate }
6250Sstevel@tonic-gate
6260Sstevel@tonic-gate def->version = LIBFRU_VERSION;
6270Sstevel@tonic-gate strlcpy(def->name, seg_name, FRU_SEGNAMELEN+1);
6280Sstevel@tonic-gate def->desc = desc;
6290Sstevel@tonic-gate def->size = size;
6300Sstevel@tonic-gate def->address = address;
6310Sstevel@tonic-gate def->hw_desc = hw_desc;
6320Sstevel@tonic-gate
6330Sstevel@tonic-gate return (FRU_SUCCESS);
6340Sstevel@tonic-gate }
6350Sstevel@tonic-gate
6360Sstevel@tonic-gate /* ========================================================================= */
6370Sstevel@tonic-gate static fru_errno_t
fpt_add_seg(fru_treehdl_t handle,fru_segdef_t * def)6380Sstevel@tonic-gate fpt_add_seg(fru_treehdl_t handle, fru_segdef_t *def)
6390Sstevel@tonic-gate {
6400Sstevel@tonic-gate fru_errno_t err = FRU_SUCCESS;
6410Sstevel@tonic-gate int picl_err = PICL_SUCCESS;
6420Sstevel@tonic-gate picl_nodehdl_t section;
6430Sstevel@tonic-gate
6440Sstevel@tonic-gate /*
6450Sstevel@tonic-gate * for every section which has a ADD_SEGMENT_PROP try and add the segment
6460Sstevel@tonic-gate */
6470Sstevel@tonic-gate if ((err = find_first_section(TREEHDL_TO_PICLHDL(handle), §ion))
6480Sstevel@tonic-gate != FRU_SUCCESS) {
6490Sstevel@tonic-gate return (err);
6500Sstevel@tonic-gate }
6510Sstevel@tonic-gate do {
6520Sstevel@tonic-gate fru_segdef_t dummy;
6530Sstevel@tonic-gate if ((picl_err = ptree_get_propval_by_name(section,
6540Sstevel@tonic-gate PICL_PROP_ADD_SEGMENT, &dummy, sizeof (dummy)))
6550Sstevel@tonic-gate == PICL_SUCCESS) {
6560Sstevel@tonic-gate
6570Sstevel@tonic-gate picl_err = ptree_update_propval_by_name(section,
6580Sstevel@tonic-gate PICL_PROP_ADD_SEGMENT, def, sizeof (*def));
6590Sstevel@tonic-gate
6600Sstevel@tonic-gate return (map_plugin_err(picl_err));
6610Sstevel@tonic-gate }
6620Sstevel@tonic-gate } while (find_next_section(section, §ion) == FRU_SUCCESS);
6630Sstevel@tonic-gate
6640Sstevel@tonic-gate return (map_plugin_err(picl_err));
6650Sstevel@tonic-gate }
6660Sstevel@tonic-gate
6670Sstevel@tonic-gate /* ========================================================================= */
6680Sstevel@tonic-gate static fru_errno_t
fpt_delete_seg(fru_treehdl_t handle,const char * seg_name)6690Sstevel@tonic-gate fpt_delete_seg(fru_treehdl_t handle, const char *seg_name)
6700Sstevel@tonic-gate {
6710Sstevel@tonic-gate picl_nodehdl_t seg_hdl;
6720Sstevel@tonic-gate fru_seg_hwdesc_t hw_desc;
6730Sstevel@tonic-gate fru_errno_t err;
6740Sstevel@tonic-gate
6750Sstevel@tonic-gate int dead_flag = FRUDATA_DELETE_TAG_KEY;
6760Sstevel@tonic-gate int rc = PICL_SUCCESS;
6770Sstevel@tonic-gate
6780Sstevel@tonic-gate if ((err = get_segment_node(TREEHDL_TO_PICLHDL(handle), seg_name,
6790Sstevel@tonic-gate &seg_hdl, &hw_desc, IGN_CORRUPT_YES)) != FRU_SUCCESS) {
6800Sstevel@tonic-gate return (err);
6810Sstevel@tonic-gate }
6820Sstevel@tonic-gate
6830Sstevel@tonic-gate rc = ptree_update_propval_by_name(seg_hdl, PICL_PROP_DELETE_SEGMENT,
6840Sstevel@tonic-gate &dead_flag, sizeof (dead_flag));
6850Sstevel@tonic-gate return (map_plugin_err(rc));
6860Sstevel@tonic-gate }
6870Sstevel@tonic-gate
6880Sstevel@tonic-gate /* ========================================================================= */
6890Sstevel@tonic-gate static fru_errno_t
fpt_add_tag_to_seg(fru_treehdl_t handle,const char * seg_name,fru_tag_t tag,uint8_t * data,size_t data_len)6900Sstevel@tonic-gate fpt_add_tag_to_seg(fru_treehdl_t handle, const char *seg_name,
6910Sstevel@tonic-gate fru_tag_t tag, uint8_t *data, size_t data_len)
6920Sstevel@tonic-gate {
6930Sstevel@tonic-gate fru_errno_t err = FRU_SUCCESS;
6940Sstevel@tonic-gate picl_nodehdl_t segHdl;
6950Sstevel@tonic-gate fru_seg_hwdesc_t hw_desc;
6960Sstevel@tonic-gate int picl_err = PICL_SUCCESS;
6970Sstevel@tonic-gate size_t buf_size = 0;
6980Sstevel@tonic-gate uint8_t *buffer = NULL;
6990Sstevel@tonic-gate picl_prophdl_t add_prop;
7000Sstevel@tonic-gate ptree_propinfo_t add_prop_info;
7010Sstevel@tonic-gate
7020Sstevel@tonic-gate if ((err = get_segment_node(TREEHDL_TO_PICLHDL(handle), seg_name,
7030Sstevel@tonic-gate &segHdl, &hw_desc, IGN_CORRUPT_NO)) != FRU_SUCCESS) {
7040Sstevel@tonic-gate return (err);
7050Sstevel@tonic-gate }
7060Sstevel@tonic-gate
7070Sstevel@tonic-gate /* get the length of the buffer required. */
7080Sstevel@tonic-gate if ((picl_err = ptree_get_prop_by_name(segHdl,
7090Sstevel@tonic-gate PICL_PROP_ADD_PACKET,
7100Sstevel@tonic-gate &add_prop)) != PICL_SUCCESS) {
711*1124Skmohan return (map_plugin_err(picl_err));
7120Sstevel@tonic-gate }
7130Sstevel@tonic-gate
7140Sstevel@tonic-gate if ((picl_err = ptree_get_propinfo(add_prop, &add_prop_info))
7150Sstevel@tonic-gate != PICL_SUCCESS) {
716*1124Skmohan return (map_plugin_err(picl_err));
7170Sstevel@tonic-gate }
7180Sstevel@tonic-gate buf_size = add_prop_info.piclinfo.size;
7190Sstevel@tonic-gate
7200Sstevel@tonic-gate if (data_len >= (buf_size - get_tag_size(get_tag_type(&tag)))) {
7210Sstevel@tonic-gate return (FRU_NOSPACE);
7220Sstevel@tonic-gate }
7230Sstevel@tonic-gate
7240Sstevel@tonic-gate buffer = malloc(buf_size);
7250Sstevel@tonic-gate if (buffer == NULL) {
7260Sstevel@tonic-gate return (FRU_FAILURE);
7270Sstevel@tonic-gate }
7280Sstevel@tonic-gate /* write the tag and data into the buffer */
7290Sstevel@tonic-gate memcpy(buffer, &tag, get_tag_size(get_tag_type(&tag)));
7300Sstevel@tonic-gate memcpy((void *)(buffer+get_tag_size(get_tag_type(&tag))),
7310Sstevel@tonic-gate data, data_len);
7320Sstevel@tonic-gate
7330Sstevel@tonic-gate picl_err = ptree_update_propval(add_prop, buffer, buf_size);
7340Sstevel@tonic-gate free(buffer);
7350Sstevel@tonic-gate return (map_plugin_err(picl_err));
7360Sstevel@tonic-gate }
7370Sstevel@tonic-gate
7380Sstevel@tonic-gate /* ========================================================================= */
7390Sstevel@tonic-gate static fru_errno_t
fpt_get_tag_list(fru_treehdl_t handle,const char * seg_name,fru_tag_t ** tags,int * number)7400Sstevel@tonic-gate fpt_get_tag_list(fru_treehdl_t handle, const char *seg_name,
7410Sstevel@tonic-gate fru_tag_t **tags, int *number)
7420Sstevel@tonic-gate {
7430Sstevel@tonic-gate picl_nodehdl_t seg_node;
7440Sstevel@tonic-gate fru_seg_hwdesc_t hw_desc;
7450Sstevel@tonic-gate fru_errno_t err = FRU_SUCCESS;
7460Sstevel@tonic-gate picl_prophdl_t tagTable;
7470Sstevel@tonic-gate int picl_err = PICL_SUCCESS;
7480Sstevel@tonic-gate unsigned int total_tags = 0;
7490Sstevel@tonic-gate
7500Sstevel@tonic-gate /* return variables */
7510Sstevel@tonic-gate fru_tag_t *rc_tags = NULL;
7520Sstevel@tonic-gate unsigned int rc_num = 0;
7530Sstevel@tonic-gate
7540Sstevel@tonic-gate if ((err = get_segment_node(TREEHDL_TO_PICLHDL(handle), seg_name,
7550Sstevel@tonic-gate &seg_node, &hw_desc, IGN_CORRUPT_NO)) != FRU_SUCCESS) {
7560Sstevel@tonic-gate return (err);
7570Sstevel@tonic-gate }
7580Sstevel@tonic-gate
7590Sstevel@tonic-gate /* get the number of tags and allocate array for them */
7600Sstevel@tonic-gate if ((picl_err = ptree_get_propval_by_name(seg_node,
7610Sstevel@tonic-gate PICL_PROP_NUM_TAGS,
7620Sstevel@tonic-gate (void *)&total_tags,
7630Sstevel@tonic-gate sizeof (total_tags))) != PICL_SUCCESS) {
764*1124Skmohan return (map_plugin_err(picl_err));
7650Sstevel@tonic-gate }
7660Sstevel@tonic-gate
7670Sstevel@tonic-gate if (total_tags == 0) {
7680Sstevel@tonic-gate *tags = rc_tags;
7690Sstevel@tonic-gate *number = rc_num;
7700Sstevel@tonic-gate return (FRU_SUCCESS);
7710Sstevel@tonic-gate }
7720Sstevel@tonic-gate
7730Sstevel@tonic-gate rc_tags = malloc((sizeof (*rc_tags) * total_tags));
7740Sstevel@tonic-gate if (rc_tags == NULL) {
7750Sstevel@tonic-gate return (FRU_FAILURE);
7760Sstevel@tonic-gate }
7770Sstevel@tonic-gate
7780Sstevel@tonic-gate /* go through the tagTable and fill in the array */
7790Sstevel@tonic-gate if ((picl_err = ptree_get_propval_by_name(seg_node,
7800Sstevel@tonic-gate PICL_PROP_PACKET_TABLE,
7810Sstevel@tonic-gate &tagTable, sizeof (tagTable))) != PICL_SUCCESS) {
7820Sstevel@tonic-gate free(rc_tags);
783*1124Skmohan return (map_plugin_err(picl_err));
7840Sstevel@tonic-gate }
7850Sstevel@tonic-gate picl_err = ptree_get_next_by_col(tagTable, &tagTable);
7860Sstevel@tonic-gate while (picl_err == PICL_SUCCESS) {
7870Sstevel@tonic-gate /* check array bounds */
7880Sstevel@tonic-gate if (rc_num >= total_tags) {
7890Sstevel@tonic-gate free(rc_tags);
7900Sstevel@tonic-gate return (FRU_FAILURE);
7910Sstevel@tonic-gate }
7920Sstevel@tonic-gate /* fill in the array */
7930Sstevel@tonic-gate if ((picl_err = ptree_get_propval(tagTable,
7940Sstevel@tonic-gate (void *)&(rc_tags[rc_num++]),
7950Sstevel@tonic-gate sizeof (fru_tag_t))) != PICL_SUCCESS) {
7960Sstevel@tonic-gate free(rc_tags);
797*1124Skmohan return (map_plugin_err(picl_err));
7980Sstevel@tonic-gate }
7990Sstevel@tonic-gate /* get the next tag */
8000Sstevel@tonic-gate picl_err = ptree_get_next_by_col(tagTable, &tagTable);
8010Sstevel@tonic-gate }
8020Sstevel@tonic-gate
8030Sstevel@tonic-gate if (picl_err == PICL_ENDOFLIST) {
8040Sstevel@tonic-gate *tags = rc_tags;
8050Sstevel@tonic-gate *number = rc_num;
8060Sstevel@tonic-gate return (FRU_SUCCESS);
8070Sstevel@tonic-gate }
808*1124Skmohan return (map_plugin_err(picl_err));
8090Sstevel@tonic-gate }
8100Sstevel@tonic-gate
8110Sstevel@tonic-gate /* ========================================================================= */
8120Sstevel@tonic-gate /*
8130Sstevel@tonic-gate * From the handle, segment name, tag, and instance of the tag get me:
8140Sstevel@tonic-gate * segHdl: The segment handle for this segment.
8150Sstevel@tonic-gate * tagHdl: tag property handle in the tag table for this instance "tag"
8160Sstevel@tonic-gate */
8170Sstevel@tonic-gate static fru_errno_t
get_tag_handle(picl_nodehdl_t handle,const char * segment,fru_tag_t tag,int instance,picl_nodehdl_t * segHdl,picl_prophdl_t * tagHdl)8180Sstevel@tonic-gate get_tag_handle(picl_nodehdl_t handle, const char *segment,
8190Sstevel@tonic-gate fru_tag_t tag, int instance,
8200Sstevel@tonic-gate picl_nodehdl_t *segHdl,
8210Sstevel@tonic-gate picl_prophdl_t *tagHdl)
8220Sstevel@tonic-gate {
8230Sstevel@tonic-gate fru_seg_hwdesc_t hw_desc;
8240Sstevel@tonic-gate fru_errno_t err;
8250Sstevel@tonic-gate picl_prophdl_t tagTable = 0;
8260Sstevel@tonic-gate int picl_err = PICL_SUCCESS;
8270Sstevel@tonic-gate picl_nodehdl_t tmp_seg;
8280Sstevel@tonic-gate
8290Sstevel@tonic-gate fru_tag_t foundTag;
8300Sstevel@tonic-gate
8310Sstevel@tonic-gate if ((err = get_segment_node(TREEHDL_TO_PICLHDL(handle), segment,
8320Sstevel@tonic-gate &tmp_seg, &hw_desc, IGN_CORRUPT_NO)) != FRU_SUCCESS) {
8330Sstevel@tonic-gate return (err);
8340Sstevel@tonic-gate }
8350Sstevel@tonic-gate
8360Sstevel@tonic-gate foundTag.raw_data = 0;
8370Sstevel@tonic-gate if ((picl_err = ptree_get_propval_by_name(tmp_seg,
8380Sstevel@tonic-gate PICL_PROP_PACKET_TABLE,
8390Sstevel@tonic-gate &tagTable, sizeof (tagTable))) != PICL_SUCCESS) {
840*1124Skmohan return (map_plugin_err(picl_err));
8410Sstevel@tonic-gate }
8420Sstevel@tonic-gate
8430Sstevel@tonic-gate picl_err = ptree_get_next_by_col(tagTable, &tagTable);
8440Sstevel@tonic-gate while ((picl_err != PICL_ENDOFLIST) &&
8450Sstevel@tonic-gate (picl_err == PICL_SUCCESS)) {
8460Sstevel@tonic-gate if ((picl_err = ptree_get_propval(tagTable, (void *)&foundTag,
8470Sstevel@tonic-gate sizeof (foundTag))) != PICL_SUCCESS) {
848*1124Skmohan return (map_plugin_err(picl_err));
8490Sstevel@tonic-gate }
8500Sstevel@tonic-gate if ((tags_equal(tag, foundTag) == 1) && (instance-- == 0)) {
8510Sstevel@tonic-gate *segHdl = tmp_seg;
8520Sstevel@tonic-gate *tagHdl = tagTable;
8530Sstevel@tonic-gate return (FRU_SUCCESS);
8540Sstevel@tonic-gate }
8550Sstevel@tonic-gate picl_err = ptree_get_next_by_col(tagTable, &tagTable);
8560Sstevel@tonic-gate }
8570Sstevel@tonic-gate
858*1124Skmohan return (map_plugin_err(picl_err));
8590Sstevel@tonic-gate }
8600Sstevel@tonic-gate
8610Sstevel@tonic-gate /* ========================================================================= */
8620Sstevel@tonic-gate static fru_errno_t
fpt_get_tag_data(fru_treehdl_t handle,const char * seg_name,fru_tag_t tag,int instance,uint8_t ** data,size_t * data_len)8630Sstevel@tonic-gate fpt_get_tag_data(fru_treehdl_t handle, const char *seg_name,
8640Sstevel@tonic-gate fru_tag_t tag, int instance,
8650Sstevel@tonic-gate uint8_t **data, size_t *data_len)
8660Sstevel@tonic-gate {
8670Sstevel@tonic-gate fru_errno_t err = FRU_SUCCESS;
8680Sstevel@tonic-gate int picl_err = PICL_SUCCESS;
8690Sstevel@tonic-gate uint8_t *buffer;
8700Sstevel@tonic-gate int buf_len = 0;
8710Sstevel@tonic-gate
8720Sstevel@tonic-gate picl_nodehdl_t seg;
8730Sstevel@tonic-gate picl_prophdl_t tagHdl;
8740Sstevel@tonic-gate
8750Sstevel@tonic-gate if ((err = get_tag_handle(TREEHDL_TO_PICLHDL(handle), seg_name,
8760Sstevel@tonic-gate tag, instance, &seg, &tagHdl)) != FRU_SUCCESS) {
8770Sstevel@tonic-gate return (err);
8780Sstevel@tonic-gate }
8790Sstevel@tonic-gate
8800Sstevel@tonic-gate if ((picl_err = ptree_get_next_by_row(tagHdl, &tagHdl))
8810Sstevel@tonic-gate != PICL_SUCCESS) {
882*1124Skmohan return (map_plugin_err(picl_err));
8830Sstevel@tonic-gate }
8840Sstevel@tonic-gate
8850Sstevel@tonic-gate buf_len = get_payload_length(&tag);
8860Sstevel@tonic-gate buffer = malloc(buf_len);
8870Sstevel@tonic-gate if (buffer == NULL) {
8880Sstevel@tonic-gate return (FRU_FAILURE);
8890Sstevel@tonic-gate }
8900Sstevel@tonic-gate
8910Sstevel@tonic-gate if ((picl_err = ptree_get_propval(tagHdl, buffer, buf_len))
8920Sstevel@tonic-gate != PICL_SUCCESS) {
8930Sstevel@tonic-gate free(buffer);
8940Sstevel@tonic-gate return (map_plugin_err(picl_err));
8950Sstevel@tonic-gate }
8960Sstevel@tonic-gate
8970Sstevel@tonic-gate *data = buffer;
8980Sstevel@tonic-gate *data_len = buf_len;
8990Sstevel@tonic-gate return (FRU_SUCCESS);
9000Sstevel@tonic-gate }
9010Sstevel@tonic-gate
9020Sstevel@tonic-gate /* ========================================================================= */
9030Sstevel@tonic-gate static fru_errno_t
fpt_set_tag_data(fru_treehdl_t handle,const char * seg_name,fru_tag_t tag,int instance,uint8_t * data,size_t data_len)9040Sstevel@tonic-gate fpt_set_tag_data(fru_treehdl_t handle, const char *seg_name,
9050Sstevel@tonic-gate fru_tag_t tag, int instance,
9060Sstevel@tonic-gate uint8_t *data, size_t data_len)
9070Sstevel@tonic-gate {
9080Sstevel@tonic-gate fru_errno_t rc = FRU_SUCCESS;
9090Sstevel@tonic-gate int picl_err = PICL_SUCCESS;
9100Sstevel@tonic-gate
9110Sstevel@tonic-gate picl_nodehdl_t seg;
9120Sstevel@tonic-gate picl_prophdl_t tagHdl;
9130Sstevel@tonic-gate
9140Sstevel@tonic-gate if ((rc = get_tag_handle(TREEHDL_TO_PICLHDL(handle), seg_name,
9150Sstevel@tonic-gate tag, instance, &seg, &tagHdl)) != FRU_SUCCESS) {
9160Sstevel@tonic-gate return (rc);
9170Sstevel@tonic-gate }
9180Sstevel@tonic-gate
9190Sstevel@tonic-gate if ((picl_err = ptree_get_next_by_row(tagHdl, &tagHdl))
9200Sstevel@tonic-gate != PICL_SUCCESS) {
921*1124Skmohan return (map_plugin_err(picl_err));
9220Sstevel@tonic-gate }
9230Sstevel@tonic-gate
9240Sstevel@tonic-gate if ((picl_err = ptree_update_propval(tagHdl, data, data_len))
9250Sstevel@tonic-gate != PICL_SUCCESS) {
9260Sstevel@tonic-gate return (map_plugin_err(picl_err));
9270Sstevel@tonic-gate }
9280Sstevel@tonic-gate
9290Sstevel@tonic-gate return (FRU_SUCCESS);
9300Sstevel@tonic-gate }
9310Sstevel@tonic-gate
9320Sstevel@tonic-gate /* ========================================================================= */
9330Sstevel@tonic-gate static fru_errno_t
fpt_delete_tag(fru_treehdl_t handle,const char * seg_name,fru_tag_t tag,int instance)9340Sstevel@tonic-gate fpt_delete_tag(fru_treehdl_t handle, const char *seg_name, fru_tag_t tag,
9350Sstevel@tonic-gate int instance)
9360Sstevel@tonic-gate {
9370Sstevel@tonic-gate fru_errno_t rc = FRU_SUCCESS;
9380Sstevel@tonic-gate int picl_err = PICL_SUCCESS;
9390Sstevel@tonic-gate
9400Sstevel@tonic-gate picl_nodehdl_t segHdl;
9410Sstevel@tonic-gate picl_prophdl_t tagHdl;
9420Sstevel@tonic-gate
9430Sstevel@tonic-gate /* get tag handle */
9440Sstevel@tonic-gate if ((rc = get_tag_handle(TREEHDL_TO_PICLHDL(handle), seg_name,
9450Sstevel@tonic-gate tag, instance, &segHdl, &tagHdl)) != FRU_SUCCESS) {
9460Sstevel@tonic-gate return (rc);
9470Sstevel@tonic-gate }
9480Sstevel@tonic-gate
9490Sstevel@tonic-gate /* set up key */
9500Sstevel@tonic-gate tag.raw_data &= FRUDATA_DELETE_TAG_MASK;
9510Sstevel@tonic-gate tag.raw_data |= FRUDATA_DELETE_TAG_KEY;
9520Sstevel@tonic-gate
9530Sstevel@tonic-gate /* Write back */
9540Sstevel@tonic-gate picl_err = ptree_update_propval(tagHdl, (void *)&(tag.raw_data),
9550Sstevel@tonic-gate sizeof (tag.raw_data));
9560Sstevel@tonic-gate return (map_plugin_err(picl_err));
9570Sstevel@tonic-gate }
9580Sstevel@tonic-gate
9590Sstevel@tonic-gate /* ========================================================================= */
9600Sstevel@tonic-gate static fru_errno_t
fpt_for_each_segment(fru_treehdl_t treenode,int (* function)(fru_treeseghdl_t segment,void * args),void * args)9610Sstevel@tonic-gate fpt_for_each_segment(fru_treehdl_t treenode,
9620Sstevel@tonic-gate int (*function)(fru_treeseghdl_t segment, void *args),
9630Sstevel@tonic-gate void *args)
9640Sstevel@tonic-gate {
9650Sstevel@tonic-gate int num_segments = 0, status;
9660Sstevel@tonic-gate
9670Sstevel@tonic-gate fru_errno_t saved_status = FRU_SUCCESS;
9680Sstevel@tonic-gate
9690Sstevel@tonic-gate picl_nodehdl_t container = TREEHDL_TO_PICLHDL(treenode),
9700Sstevel@tonic-gate section, segment;
9710Sstevel@tonic-gate
9720Sstevel@tonic-gate
9730Sstevel@tonic-gate if ((status = update_data_nodes(container)) != FRU_SUCCESS)
9740Sstevel@tonic-gate return (status);
9750Sstevel@tonic-gate
9760Sstevel@tonic-gate /* process each section */
9770Sstevel@tonic-gate for (status = ptree_get_propval_by_name(container, PICL_PROP_CHILD,
9780Sstevel@tonic-gate §ion, sizeof (section));
9790Sstevel@tonic-gate status == PICL_SUCCESS;
9800Sstevel@tonic-gate status = ptree_get_propval_by_name(section, PICL_PROP_PEER,
9810Sstevel@tonic-gate §ion,
9820Sstevel@tonic-gate sizeof (section))) {
9830Sstevel@tonic-gate
9840Sstevel@tonic-gate if (cmp_class_name(section, PICL_CLASS_SECTION) != FRU_SUCCESS)
9850Sstevel@tonic-gate continue;
9860Sstevel@tonic-gate
9870Sstevel@tonic-gate if ((status = ptree_get_propval_by_name(section,
9880Sstevel@tonic-gate PICL_PROP_NUM_SEGMENTS,
9890Sstevel@tonic-gate &num_segments,
9900Sstevel@tonic-gate sizeof (num_segments)))
9910Sstevel@tonic-gate == PICL_PROPNOTFOUND) {
9920Sstevel@tonic-gate continue;
9930Sstevel@tonic-gate } else if (status != PICL_SUCCESS) {
9940Sstevel@tonic-gate saved_status = map_plugin_err(status);
9950Sstevel@tonic-gate continue;
9960Sstevel@tonic-gate } else if (num_segments == 0) {
9970Sstevel@tonic-gate continue;
9980Sstevel@tonic-gate }
9990Sstevel@tonic-gate
10000Sstevel@tonic-gate /* process each segment */
10010Sstevel@tonic-gate for (status = ptree_get_propval_by_name(section,
10020Sstevel@tonic-gate PICL_PROP_CHILD,
10030Sstevel@tonic-gate &segment,
10040Sstevel@tonic-gate sizeof (segment));
10050Sstevel@tonic-gate status == PICL_SUCCESS;
10060Sstevel@tonic-gate status = ptree_get_propval_by_name(segment,
10070Sstevel@tonic-gate PICL_PROP_PEER,
10080Sstevel@tonic-gate &segment,
10090Sstevel@tonic-gate sizeof (segment))) {
10100Sstevel@tonic-gate
10110Sstevel@tonic-gate if (cmp_class_name(segment, PICL_CLASS_SEGMENT)
10120Sstevel@tonic-gate != FRU_SUCCESS) continue;
10130Sstevel@tonic-gate
10140Sstevel@tonic-gate if ((status = function(PICLHDL_TO_TREESEGHDL(segment),
10150Sstevel@tonic-gate args))
10160Sstevel@tonic-gate != FRU_SUCCESS) return (status);
10170Sstevel@tonic-gate }
10180Sstevel@tonic-gate
10190Sstevel@tonic-gate if (status != PICL_PROPNOTFOUND)
10200Sstevel@tonic-gate saved_status = map_plugin_err(status);
10210Sstevel@tonic-gate }
10220Sstevel@tonic-gate
10230Sstevel@tonic-gate if (status != PICL_PROPNOTFOUND)
10240Sstevel@tonic-gate saved_status = map_plugin_err(status);
10250Sstevel@tonic-gate
10260Sstevel@tonic-gate return (saved_status);
10270Sstevel@tonic-gate }
10280Sstevel@tonic-gate
10290Sstevel@tonic-gate /* ========================================================================= */
10300Sstevel@tonic-gate static fru_errno_t
fpt_get_segment_name(fru_treeseghdl_t segment,char ** name)10310Sstevel@tonic-gate fpt_get_segment_name(fru_treeseghdl_t segment, char **name)
10320Sstevel@tonic-gate {
10330Sstevel@tonic-gate char *propval;
10340Sstevel@tonic-gate
10350Sstevel@tonic-gate int status;
10360Sstevel@tonic-gate
10370Sstevel@tonic-gate picl_prophdl_t proph = 0;
10380Sstevel@tonic-gate
10390Sstevel@tonic-gate ptree_propinfo_t propinfo;
10400Sstevel@tonic-gate
10410Sstevel@tonic-gate
1042*1124Skmohan if ((status = ptree_get_prop_by_name(TREESEGHDL_TO_PICLHDL(segment),
1043*1124Skmohan PICL_PROP_NAME, &proph))
10440Sstevel@tonic-gate != PICL_SUCCESS)
1045*1124Skmohan return (map_plugin_err(status));
10460Sstevel@tonic-gate
10470Sstevel@tonic-gate if (ptree_get_propinfo(proph, &propinfo) != PICL_SUCCESS)
1048*1124Skmohan return (map_plugin_err(status));
10490Sstevel@tonic-gate
10500Sstevel@tonic-gate if (propinfo.piclinfo.size == 0)
10510Sstevel@tonic-gate return (FRU_INVALDATASIZE);
10520Sstevel@tonic-gate
10530Sstevel@tonic-gate if ((propval = malloc(propinfo.piclinfo.size)) == NULL)
10540Sstevel@tonic-gate return (FRU_NOSPACE);
10550Sstevel@tonic-gate
10560Sstevel@tonic-gate if ((status = ptree_get_propval(proph, propval, propinfo.piclinfo.size))
10570Sstevel@tonic-gate != PICL_SUCCESS) {
10580Sstevel@tonic-gate free(propval);
10590Sstevel@tonic-gate return (map_plugin_err(status));
10600Sstevel@tonic-gate }
10610Sstevel@tonic-gate
10620Sstevel@tonic-gate *name = propval;
10630Sstevel@tonic-gate
10640Sstevel@tonic-gate return (FRU_SUCCESS);
10650Sstevel@tonic-gate }
10660Sstevel@tonic-gate
10670Sstevel@tonic-gate /* ========================================================================= */
10680Sstevel@tonic-gate static fru_errno_t
fpt_for_each_packet(fru_treeseghdl_t treesegment,int (* function)(fru_tag_t * tag,uint8_t * payload,size_t length,void * args),void * args)10690Sstevel@tonic-gate fpt_for_each_packet(fru_treeseghdl_t treesegment,
10700Sstevel@tonic-gate int (*function)(fru_tag_t *tag, uint8_t *payload,
10710Sstevel@tonic-gate size_t length,
10720Sstevel@tonic-gate void *args),
10730Sstevel@tonic-gate void *args)
10740Sstevel@tonic-gate {
10750Sstevel@tonic-gate int status;
10760Sstevel@tonic-gate
10770Sstevel@tonic-gate uint8_t *payload;
10780Sstevel@tonic-gate
10790Sstevel@tonic-gate picl_nodehdl_t segment = TREESEGHDL_TO_PICLHDL(treesegment);
10800Sstevel@tonic-gate
10810Sstevel@tonic-gate picl_prophdl_t packet, payloadh = 0;
10820Sstevel@tonic-gate
10830Sstevel@tonic-gate ptree_propinfo_t propinfo;
10840Sstevel@tonic-gate
10850Sstevel@tonic-gate fru_segdesc_t descriptor;
10860Sstevel@tonic-gate
10870Sstevel@tonic-gate fru_tag_t tag;
10880Sstevel@tonic-gate
10890Sstevel@tonic-gate
10900Sstevel@tonic-gate if ((status = ptree_get_propval_by_name(segment, PICL_PROP_DESCRIPTOR,
10910Sstevel@tonic-gate &descriptor,
10920Sstevel@tonic-gate sizeof (descriptor)))
10930Sstevel@tonic-gate != PICL_SUCCESS) return (map_plugin_err(status));
10940Sstevel@tonic-gate
10950Sstevel@tonic-gate if (descriptor.field.opaque)
10960Sstevel@tonic-gate return (FRU_SUCCESS);
10970Sstevel@tonic-gate
10980Sstevel@tonic-gate if (descriptor.field.encrypted && (encrypt_func == NULL))
10990Sstevel@tonic-gate return (FRU_SUCCESS);
11000Sstevel@tonic-gate
11010Sstevel@tonic-gate if ((status = ptree_get_propval_by_name(segment, PICL_PROP_PACKET_TABLE,
11020Sstevel@tonic-gate &packet, sizeof (packet)))
11030Sstevel@tonic-gate == PICL_PROPNOTFOUND)
11040Sstevel@tonic-gate return (FRU_SUCCESS);
11050Sstevel@tonic-gate else if (status != PICL_SUCCESS)
11060Sstevel@tonic-gate return (map_plugin_err(status));
11070Sstevel@tonic-gate
11080Sstevel@tonic-gate while ((status = ptree_get_next_by_col(packet, &packet))
11090Sstevel@tonic-gate == PICL_SUCCESS) {
11100Sstevel@tonic-gate if (((status = ptree_get_propval(packet, &tag, sizeof (tag)))
11110Sstevel@tonic-gate != PICL_SUCCESS) ||
11120Sstevel@tonic-gate ((status = ptree_get_next_by_row(packet, &payloadh))
11130Sstevel@tonic-gate != PICL_SUCCESS) ||
11140Sstevel@tonic-gate ((status = ptree_get_propinfo(payloadh, &propinfo))
11150Sstevel@tonic-gate != PICL_SUCCESS))
11160Sstevel@tonic-gate return (map_plugin_err(status));
11170Sstevel@tonic-gate
11180Sstevel@tonic-gate if (propinfo.piclinfo.size > 0) {
11190Sstevel@tonic-gate payload = alloca(propinfo.piclinfo.size);
11200Sstevel@tonic-gate if ((status = ptree_get_propval(payloadh, payload,
11210Sstevel@tonic-gate propinfo.piclinfo.size))
11220Sstevel@tonic-gate != PICL_SUCCESS) return (map_plugin_err(status));
11230Sstevel@tonic-gate } else {
11240Sstevel@tonic-gate payload = NULL;
11250Sstevel@tonic-gate }
11260Sstevel@tonic-gate
11270Sstevel@tonic-gate if ((descriptor.field.encrypted) &&
11280Sstevel@tonic-gate ((status = encrypt_func(FRU_DECRYPT, payload,
11290Sstevel@tonic-gate propinfo.piclinfo.size))
11300Sstevel@tonic-gate != FRU_SUCCESS)) return status;
11310Sstevel@tonic-gate
11320Sstevel@tonic-gate if ((status = function(&tag, payload, propinfo.piclinfo.size,
11330Sstevel@tonic-gate args))
11340Sstevel@tonic-gate != FRU_SUCCESS) return (status);
11350Sstevel@tonic-gate }
11360Sstevel@tonic-gate
11370Sstevel@tonic-gate if (status == PICL_ENDOFLIST)
11380Sstevel@tonic-gate return (FRU_SUCCESS);
11390Sstevel@tonic-gate else
11400Sstevel@tonic-gate return (map_plugin_err(status));
11410Sstevel@tonic-gate }
11420Sstevel@tonic-gate
11430Sstevel@tonic-gate /* ========================================================================= */
11440Sstevel@tonic-gate /* ARGSUSED0 */
11450Sstevel@tonic-gate static fru_errno_t
initialize(int argc,char ** argv)11460Sstevel@tonic-gate initialize(int argc, char **argv)
11470Sstevel@tonic-gate {
11480Sstevel@tonic-gate return (FRU_SUCCESS);
11490Sstevel@tonic-gate }
11500Sstevel@tonic-gate
11510Sstevel@tonic-gate /* ========================================================================= */
11520Sstevel@tonic-gate static fru_errno_t
shutdown(void)11530Sstevel@tonic-gate shutdown(void)
11540Sstevel@tonic-gate {
11550Sstevel@tonic-gate return (FRU_SUCCESS);
11560Sstevel@tonic-gate }
11570Sstevel@tonic-gate
11580Sstevel@tonic-gate /* ========================================================================= */
11590Sstevel@tonic-gate /* object for libfru to link to */
11600Sstevel@tonic-gate fru_datasource_t data_source =
11610Sstevel@tonic-gate {
11620Sstevel@tonic-gate LIBFRU_DS_VER,
11630Sstevel@tonic-gate initialize,
11640Sstevel@tonic-gate shutdown,
11650Sstevel@tonic-gate fpt_get_root,
11660Sstevel@tonic-gate fpt_get_child,
11670Sstevel@tonic-gate fpt_get_peer,
11680Sstevel@tonic-gate fpt_get_parent,
11690Sstevel@tonic-gate fpt_get_name_from_hdl,
11700Sstevel@tonic-gate fpt_get_node_type,
11710Sstevel@tonic-gate fpt_get_seg_list,
11720Sstevel@tonic-gate fpt_get_seg_def,
11730Sstevel@tonic-gate fpt_add_seg,
11740Sstevel@tonic-gate fpt_delete_seg,
11750Sstevel@tonic-gate fpt_for_each_segment,
11760Sstevel@tonic-gate fpt_get_segment_name,
11770Sstevel@tonic-gate fpt_add_tag_to_seg,
11780Sstevel@tonic-gate fpt_get_tag_list,
11790Sstevel@tonic-gate fpt_get_tag_data,
11800Sstevel@tonic-gate fpt_set_tag_data,
11810Sstevel@tonic-gate fpt_delete_tag,
11820Sstevel@tonic-gate fpt_for_each_packet
11830Sstevel@tonic-gate };
1184