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 (c) 1999-2000 by Sun Microsystems, Inc.
24*0Sstevel@tonic-gate  * All rights reserved.
25*0Sstevel@tonic-gate  */
26*0Sstevel@tonic-gate 
27*0Sstevel@tonic-gate #pragma ident	"%Z%%M%	%I%	%E% SMI"
28*0Sstevel@tonic-gate 
29*0Sstevel@tonic-gate /*
30*0Sstevel@tonic-gate  * This plugin creates the PICL nodes and properties specified in
31*0Sstevel@tonic-gate  * configuration file.
32*0Sstevel@tonic-gate  * It is used to create the FRU tree for a platform.
33*0Sstevel@tonic-gate  * The configuration file for FRU tree is called "piclfrutree.conf".
34*0Sstevel@tonic-gate  */
35*0Sstevel@tonic-gate 
36*0Sstevel@tonic-gate 
37*0Sstevel@tonic-gate #include <stdio.h>
38*0Sstevel@tonic-gate #include <fcntl.h>
39*0Sstevel@tonic-gate #include <unistd.h>
40*0Sstevel@tonic-gate #include <stdlib.h>
41*0Sstevel@tonic-gate #include <errno.h>
42*0Sstevel@tonic-gate #include <string.h>
43*0Sstevel@tonic-gate #include <syslog.h>
44*0Sstevel@tonic-gate #include <alloca.h>
45*0Sstevel@tonic-gate #include <limits.h>
46*0Sstevel@tonic-gate #include <sys/utsname.h>
47*0Sstevel@tonic-gate #include <sys/systeminfo.h>
48*0Sstevel@tonic-gate #include <sys/stat.h>
49*0Sstevel@tonic-gate #include <libintl.h>
50*0Sstevel@tonic-gate #include <picl.h>
51*0Sstevel@tonic-gate #include <picltree.h>
52*0Sstevel@tonic-gate #include "picld_pluginutil.h"
53*0Sstevel@tonic-gate 
54*0Sstevel@tonic-gate #define	EM_FAIL	gettext("SUNW_piclfrutree PICL plugin module failed")
55*0Sstevel@tonic-gate 
56*0Sstevel@tonic-gate static	void	piclfrutree_register(void);
57*0Sstevel@tonic-gate static	void	piclfrutree_init(void);
58*0Sstevel@tonic-gate static	void	piclfrutree_fini(void);
59*0Sstevel@tonic-gate 
60*0Sstevel@tonic-gate #define	FRUTREE_CONFFILE_NAME		"piclfrutree.conf"
61*0Sstevel@tonic-gate 
62*0Sstevel@tonic-gate #pragma	init(piclfrutree_register)
63*0Sstevel@tonic-gate 
64*0Sstevel@tonic-gate static picld_plugin_reg_t  my_reg_info = {
65*0Sstevel@tonic-gate 	PICLD_PLUGIN_VERSION_1,
66*0Sstevel@tonic-gate 	PICLD_PLUGIN_NON_CRITICAL,
67*0Sstevel@tonic-gate 	"SUNW_piclfrutree",
68*0Sstevel@tonic-gate 	piclfrutree_init,
69*0Sstevel@tonic-gate 	piclfrutree_fini
70*0Sstevel@tonic-gate };
71*0Sstevel@tonic-gate 
72*0Sstevel@tonic-gate static void
piclfrutree_register(void)73*0Sstevel@tonic-gate piclfrutree_register(void)
74*0Sstevel@tonic-gate {
75*0Sstevel@tonic-gate 	(void) picld_plugin_register(&my_reg_info);
76*0Sstevel@tonic-gate }
77*0Sstevel@tonic-gate 
78*0Sstevel@tonic-gate /*
79*0Sstevel@tonic-gate  * Search for the frutree config file from the platform specific
80*0Sstevel@tonic-gate  * directory to the common directory.
81*0Sstevel@tonic-gate  *
82*0Sstevel@tonic-gate  * The size of outfilename must be PATH_MAX
83*0Sstevel@tonic-gate  */
84*0Sstevel@tonic-gate static int
get_config_file(char * outfilename)85*0Sstevel@tonic-gate get_config_file(char *outfilename)
86*0Sstevel@tonic-gate {
87*0Sstevel@tonic-gate 	char	nmbuf[SYS_NMLN];
88*0Sstevel@tonic-gate 	char	pname[PATH_MAX];
89*0Sstevel@tonic-gate 
90*0Sstevel@tonic-gate 	if (sysinfo(SI_PLATFORM, nmbuf, sizeof (nmbuf)) != -1) {
91*0Sstevel@tonic-gate 		(void) snprintf(pname, PATH_MAX, PICLD_PLAT_PLUGIN_DIRF, nmbuf);
92*0Sstevel@tonic-gate 		(void) strlcat(pname, FRUTREE_CONFFILE_NAME, PATH_MAX);
93*0Sstevel@tonic-gate 		if (access(pname, R_OK) == 0) {
94*0Sstevel@tonic-gate 			(void) strlcpy(outfilename, pname, PATH_MAX);
95*0Sstevel@tonic-gate 			return (0);
96*0Sstevel@tonic-gate 		}
97*0Sstevel@tonic-gate 	}
98*0Sstevel@tonic-gate 
99*0Sstevel@tonic-gate 	if (sysinfo(SI_MACHINE, nmbuf, sizeof (nmbuf)) != -1) {
100*0Sstevel@tonic-gate 		(void) snprintf(pname, PATH_MAX, PICLD_PLAT_PLUGIN_DIRF, nmbuf);
101*0Sstevel@tonic-gate 		(void) strlcat(pname, FRUTREE_CONFFILE_NAME, PATH_MAX);
102*0Sstevel@tonic-gate 		if (access(pname, R_OK) == 0) {
103*0Sstevel@tonic-gate 			(void) strlcpy(outfilename, pname, PATH_MAX);
104*0Sstevel@tonic-gate 			return (0);
105*0Sstevel@tonic-gate 		}
106*0Sstevel@tonic-gate 	}
107*0Sstevel@tonic-gate 
108*0Sstevel@tonic-gate 	(void) snprintf(pname, PATH_MAX, "%s/%s", PICLD_COMMON_PLUGIN_DIR,
109*0Sstevel@tonic-gate 	    FRUTREE_CONFFILE_NAME);
110*0Sstevel@tonic-gate 
111*0Sstevel@tonic-gate 	if (access(pname, R_OK) == 0) {
112*0Sstevel@tonic-gate 		(void) strlcpy(outfilename, pname, PATH_MAX);
113*0Sstevel@tonic-gate 		return (0);
114*0Sstevel@tonic-gate 	}
115*0Sstevel@tonic-gate 
116*0Sstevel@tonic-gate 	return (-1);
117*0Sstevel@tonic-gate }
118*0Sstevel@tonic-gate 
119*0Sstevel@tonic-gate static void
piclfrutree_init(void)120*0Sstevel@tonic-gate piclfrutree_init(void)
121*0Sstevel@tonic-gate {
122*0Sstevel@tonic-gate 	char		fullfilename[PATH_MAX];
123*0Sstevel@tonic-gate 	picl_nodehdl_t	rooth;
124*0Sstevel@tonic-gate 
125*0Sstevel@tonic-gate 	if (get_config_file(fullfilename) < 0)
126*0Sstevel@tonic-gate 		return;
127*0Sstevel@tonic-gate 
128*0Sstevel@tonic-gate 	if (ptree_get_root(&rooth) != PICL_SUCCESS)
129*0Sstevel@tonic-gate 		return;
130*0Sstevel@tonic-gate 
131*0Sstevel@tonic-gate 	if (picld_pluginutil_parse_config_file(rooth, fullfilename) !=
132*0Sstevel@tonic-gate 	    PICL_SUCCESS)
133*0Sstevel@tonic-gate 		syslog(LOG_ERR, EM_FAIL);
134*0Sstevel@tonic-gate }
135*0Sstevel@tonic-gate 
136*0Sstevel@tonic-gate static void
piclfrutree_fini(void)137*0Sstevel@tonic-gate piclfrutree_fini(void)
138*0Sstevel@tonic-gate {
139*0Sstevel@tonic-gate }
140