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 2004 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 #pragma ident	"%Z%%M%	%I%	%E% SMI"
28*7c478bd9Sstevel@tonic-gate 
29*7c478bd9Sstevel@tonic-gate 
30*7c478bd9Sstevel@tonic-gate #include "cfga_usb.h"
31*7c478bd9Sstevel@tonic-gate 
32*7c478bd9Sstevel@tonic-gate 
33*7c478bd9Sstevel@tonic-gate #define	MAX_FORMAT	80	/* for info table */
34*7c478bd9Sstevel@tonic-gate 
35*7c478bd9Sstevel@tonic-gate cfga_usb_ret_t		usb_rcm_offline(const char *, char **, char *,
36*7c478bd9Sstevel@tonic-gate 			    cfga_flags_t);
37*7c478bd9Sstevel@tonic-gate cfga_usb_ret_t		usb_rcm_online(const char *, char **, char *,
38*7c478bd9Sstevel@tonic-gate 			    cfga_flags_t);
39*7c478bd9Sstevel@tonic-gate cfga_usb_ret_t		usb_rcm_remove(const char *, char **, char *,
40*7c478bd9Sstevel@tonic-gate 			    cfga_flags_t);
41*7c478bd9Sstevel@tonic-gate static cfga_usb_ret_t 	usb_rcm_info_table(rcm_info_t *, char **);
42*7c478bd9Sstevel@tonic-gate static cfga_usb_ret_t 	usb_rcm_init(const char *, cfga_flags_t, char **,
43*7c478bd9Sstevel@tonic-gate 			    uint_t *);
44*7c478bd9Sstevel@tonic-gate 
45*7c478bd9Sstevel@tonic-gate 
46*7c478bd9Sstevel@tonic-gate static rcm_handle_t *rcm_handle = NULL;
47*7c478bd9Sstevel@tonic-gate static mutex_t rcm_handle_lock = DEFAULTMUTEX;
48*7c478bd9Sstevel@tonic-gate 
49*7c478bd9Sstevel@tonic-gate 
50*7c478bd9Sstevel@tonic-gate /*
51*7c478bd9Sstevel@tonic-gate  * usb_rcm_offline:
52*7c478bd9Sstevel@tonic-gate  *	Offline USB resource consumers.
53*7c478bd9Sstevel@tonic-gate  */
54*7c478bd9Sstevel@tonic-gate cfga_usb_ret_t
usb_rcm_offline(const char * rsrc,char ** errstring,char * rsrc_fixed,cfga_flags_t flags)55*7c478bd9Sstevel@tonic-gate usb_rcm_offline(const char *rsrc, char **errstring, char *rsrc_fixed,
56*7c478bd9Sstevel@tonic-gate     cfga_flags_t flags)
57*7c478bd9Sstevel@tonic-gate {
58*7c478bd9Sstevel@tonic-gate 	int		rret;
59*7c478bd9Sstevel@tonic-gate 	uint_t		rflags = 0;
60*7c478bd9Sstevel@tonic-gate 	rcm_info_t	*rinfo = NULL;
61*7c478bd9Sstevel@tonic-gate 	cfga_usb_ret_t	ret = CFGA_USB_OK;
62*7c478bd9Sstevel@tonic-gate 
63*7c478bd9Sstevel@tonic-gate 	DPRINTF("usb_rcm_offline:\n");
64*7c478bd9Sstevel@tonic-gate 
65*7c478bd9Sstevel@tonic-gate 	if ((ret = usb_rcm_init(rsrc, flags, errstring, &rflags)) !=
66*7c478bd9Sstevel@tonic-gate 	    CFGA_USB_OK) {
67*7c478bd9Sstevel@tonic-gate 
68*7c478bd9Sstevel@tonic-gate 		return (ret);
69*7c478bd9Sstevel@tonic-gate 	}
70*7c478bd9Sstevel@tonic-gate 
71*7c478bd9Sstevel@tonic-gate 	DPRINTF("usb_rcm_offline: rsrc_fixed: %s\n", rsrc_fixed);
72*7c478bd9Sstevel@tonic-gate 
73*7c478bd9Sstevel@tonic-gate 	if ((rret = rcm_request_offline(rcm_handle, rsrc_fixed, rflags, &rinfo))
74*7c478bd9Sstevel@tonic-gate 	    != RCM_SUCCESS) {
75*7c478bd9Sstevel@tonic-gate 		DPRINTF("usb_rcm_offline: rcm_request_offline failed\n");
76*7c478bd9Sstevel@tonic-gate 
77*7c478bd9Sstevel@tonic-gate 		if (rinfo) {
78*7c478bd9Sstevel@tonic-gate 			(void) usb_rcm_info_table(rinfo, errstring);
79*7c478bd9Sstevel@tonic-gate 			rcm_free_info(rinfo);
80*7c478bd9Sstevel@tonic-gate 			rinfo = NULL;
81*7c478bd9Sstevel@tonic-gate 		}
82*7c478bd9Sstevel@tonic-gate 
83*7c478bd9Sstevel@tonic-gate 		DPRINTF("usb_rcm_offline: table = %s\n", *errstring);
84*7c478bd9Sstevel@tonic-gate 
85*7c478bd9Sstevel@tonic-gate 		if (rret == RCM_FAILURE) {
86*7c478bd9Sstevel@tonic-gate 			(void) usb_rcm_online(rsrc, errstring,
87*7c478bd9Sstevel@tonic-gate 			    rsrc_fixed, flags);
88*7c478bd9Sstevel@tonic-gate 		}
89*7c478bd9Sstevel@tonic-gate 		ret = CFGA_USB_RCM_OFFLINE;
90*7c478bd9Sstevel@tonic-gate 	}
91*7c478bd9Sstevel@tonic-gate 
92*7c478bd9Sstevel@tonic-gate 	return (ret);
93*7c478bd9Sstevel@tonic-gate }
94*7c478bd9Sstevel@tonic-gate 
95*7c478bd9Sstevel@tonic-gate 
96*7c478bd9Sstevel@tonic-gate /*
97*7c478bd9Sstevel@tonic-gate  * usb_rcm_online:
98*7c478bd9Sstevel@tonic-gate  *	Online USB resource consumers that were previously offlined.
99*7c478bd9Sstevel@tonic-gate  */
100*7c478bd9Sstevel@tonic-gate cfga_usb_ret_t
usb_rcm_online(const char * rsrc,char ** errstring,char * rsrc_fixed,cfga_flags_t flags)101*7c478bd9Sstevel@tonic-gate usb_rcm_online(const char *rsrc, char **errstring, char *rsrc_fixed,
102*7c478bd9Sstevel@tonic-gate     cfga_flags_t flags)
103*7c478bd9Sstevel@tonic-gate {
104*7c478bd9Sstevel@tonic-gate 	rcm_info_t	*rinfo = NULL;
105*7c478bd9Sstevel@tonic-gate 	cfga_usb_ret_t	ret = CFGA_USB_OK;
106*7c478bd9Sstevel@tonic-gate 
107*7c478bd9Sstevel@tonic-gate 	DPRINTF("usb_rcm_online:\n");
108*7c478bd9Sstevel@tonic-gate 
109*7c478bd9Sstevel@tonic-gate 	if ((ret = usb_rcm_init(rsrc, flags, errstring, NULL)) != CFGA_USB_OK) {
110*7c478bd9Sstevel@tonic-gate 
111*7c478bd9Sstevel@tonic-gate 		return (ret);
112*7c478bd9Sstevel@tonic-gate 	}
113*7c478bd9Sstevel@tonic-gate 
114*7c478bd9Sstevel@tonic-gate 	if (rcm_notify_online(rcm_handle, rsrc_fixed, 0, &rinfo) !=
115*7c478bd9Sstevel@tonic-gate 	    RCM_SUCCESS && (rinfo != NULL)) {
116*7c478bd9Sstevel@tonic-gate 		DPRINTF("usb_rcm_online: rcm_notify_online failed\n");
117*7c478bd9Sstevel@tonic-gate 
118*7c478bd9Sstevel@tonic-gate 		(void) usb_rcm_info_table(rinfo, errstring);
119*7c478bd9Sstevel@tonic-gate 		rcm_free_info(rinfo);
120*7c478bd9Sstevel@tonic-gate 		rinfo = NULL;
121*7c478bd9Sstevel@tonic-gate 		ret = CFGA_USB_RCM_ONLINE;
122*7c478bd9Sstevel@tonic-gate 	}
123*7c478bd9Sstevel@tonic-gate 
124*7c478bd9Sstevel@tonic-gate 	return (ret);
125*7c478bd9Sstevel@tonic-gate }
126*7c478bd9Sstevel@tonic-gate 
127*7c478bd9Sstevel@tonic-gate 
128*7c478bd9Sstevel@tonic-gate /*
129*7c478bd9Sstevel@tonic-gate  * usb_rcm_remove:
130*7c478bd9Sstevel@tonic-gate  *	Remove USB resource consumers after their kernel removal.
131*7c478bd9Sstevel@tonic-gate  */
132*7c478bd9Sstevel@tonic-gate cfga_usb_ret_t
usb_rcm_remove(const char * rsrc,char ** errstring,char * rsrc_fixed,cfga_flags_t flags)133*7c478bd9Sstevel@tonic-gate usb_rcm_remove(const char *rsrc, char **errstring, char *rsrc_fixed,
134*7c478bd9Sstevel@tonic-gate     cfga_flags_t flags)
135*7c478bd9Sstevel@tonic-gate {
136*7c478bd9Sstevel@tonic-gate 	rcm_info_t	*rinfo = NULL;
137*7c478bd9Sstevel@tonic-gate 	cfga_usb_ret_t	ret = CFGA_USB_OK;
138*7c478bd9Sstevel@tonic-gate 
139*7c478bd9Sstevel@tonic-gate 	DPRINTF("usb_rcm_remove:\n");
140*7c478bd9Sstevel@tonic-gate 
141*7c478bd9Sstevel@tonic-gate 	if ((ret = usb_rcm_init(rsrc, flags, errstring, NULL)) != CFGA_USB_OK) {
142*7c478bd9Sstevel@tonic-gate 
143*7c478bd9Sstevel@tonic-gate 		return (ret);
144*7c478bd9Sstevel@tonic-gate 	}
145*7c478bd9Sstevel@tonic-gate 
146*7c478bd9Sstevel@tonic-gate 	if (rcm_notify_remove(rcm_handle, rsrc_fixed, 0, &rinfo) !=
147*7c478bd9Sstevel@tonic-gate 	    RCM_SUCCESS && (rinfo != NULL)) {
148*7c478bd9Sstevel@tonic-gate 		DPRINTF("usb_rcm_remove: rcm_notify_remove failed\n");
149*7c478bd9Sstevel@tonic-gate 
150*7c478bd9Sstevel@tonic-gate 		(void) usb_rcm_info_table(rinfo, errstring);
151*7c478bd9Sstevel@tonic-gate 		rcm_free_info(rinfo);
152*7c478bd9Sstevel@tonic-gate 		rinfo = NULL;
153*7c478bd9Sstevel@tonic-gate 		ret = CFGA_USB_RCM_ONLINE;
154*7c478bd9Sstevel@tonic-gate 	}
155*7c478bd9Sstevel@tonic-gate 
156*7c478bd9Sstevel@tonic-gate 	return (ret);
157*7c478bd9Sstevel@tonic-gate }
158*7c478bd9Sstevel@tonic-gate 
159*7c478bd9Sstevel@tonic-gate 
160*7c478bd9Sstevel@tonic-gate /*
161*7c478bd9Sstevel@tonic-gate  * usb_rcm_init:
162*7c478bd9Sstevel@tonic-gate  *	Contains common initialization code for entering a usb_rcm_xx() routine.
163*7c478bd9Sstevel@tonic-gate  */
164*7c478bd9Sstevel@tonic-gate /* ARGSUSED */
165*7c478bd9Sstevel@tonic-gate static cfga_usb_ret_t
usb_rcm_init(const char * rsrc,cfga_flags_t flags,char ** errstring,uint_t * rflags)166*7c478bd9Sstevel@tonic-gate usb_rcm_init(const char *rsrc, cfga_flags_t flags, char **errstring,
167*7c478bd9Sstevel@tonic-gate     uint_t *rflags)
168*7c478bd9Sstevel@tonic-gate {
169*7c478bd9Sstevel@tonic-gate 	DPRINTF("usb_rcm_init:\n");
170*7c478bd9Sstevel@tonic-gate 
171*7c478bd9Sstevel@tonic-gate 	/* Validate the rsrc argument */
172*7c478bd9Sstevel@tonic-gate 	if (rsrc == NULL) {
173*7c478bd9Sstevel@tonic-gate 		DPRINTF("usb_rcm_init: rsrc is NULL\n");
174*7c478bd9Sstevel@tonic-gate 		return (CFGA_USB_INTERNAL_ERROR);
175*7c478bd9Sstevel@tonic-gate 	}
176*7c478bd9Sstevel@tonic-gate 
177*7c478bd9Sstevel@tonic-gate 	/* Translate the cfgadm flags to RCM flags */
178*7c478bd9Sstevel@tonic-gate 	if (rflags && (flags & CFGA_FLAG_FORCE)) {
179*7c478bd9Sstevel@tonic-gate 		*rflags |= RCM_FORCE;
180*7c478bd9Sstevel@tonic-gate 	}
181*7c478bd9Sstevel@tonic-gate 
182*7c478bd9Sstevel@tonic-gate 	/* Get a handle for the RCM operations */
183*7c478bd9Sstevel@tonic-gate 	(void) mutex_lock(&rcm_handle_lock);
184*7c478bd9Sstevel@tonic-gate 	if (rcm_handle == NULL) {
185*7c478bd9Sstevel@tonic-gate 		if (rcm_alloc_handle(NULL, RCM_NOPID, NULL, &rcm_handle) !=
186*7c478bd9Sstevel@tonic-gate 		    RCM_SUCCESS) {
187*7c478bd9Sstevel@tonic-gate 			DPRINTF("usb_rcm_init: alloc_handle failed\n");
188*7c478bd9Sstevel@tonic-gate 			(void) mutex_unlock(&rcm_handle_lock);
189*7c478bd9Sstevel@tonic-gate 
190*7c478bd9Sstevel@tonic-gate 			return (CFGA_USB_RCM_HANDLE);
191*7c478bd9Sstevel@tonic-gate 		}
192*7c478bd9Sstevel@tonic-gate 	}
193*7c478bd9Sstevel@tonic-gate 	(void) mutex_unlock(&rcm_handle_lock);
194*7c478bd9Sstevel@tonic-gate 
195*7c478bd9Sstevel@tonic-gate 	return (CFGA_USB_OK);
196*7c478bd9Sstevel@tonic-gate }
197*7c478bd9Sstevel@tonic-gate 
198*7c478bd9Sstevel@tonic-gate 
199*7c478bd9Sstevel@tonic-gate /*
200*7c478bd9Sstevel@tonic-gate  * usb_rcm_info_table:
201*7c478bd9Sstevel@tonic-gate  *	Takes an opaque rcm_info_t pointer and a character pointer,
202*7c478bd9Sstevel@tonic-gate  *	and appends the rcm_info_t data in the form of a table to the
203*7c478bd9Sstevel@tonic-gate  *	given character pointer.
204*7c478bd9Sstevel@tonic-gate  */
205*7c478bd9Sstevel@tonic-gate static cfga_usb_ret_t
usb_rcm_info_table(rcm_info_t * rinfo,char ** table)206*7c478bd9Sstevel@tonic-gate usb_rcm_info_table(rcm_info_t *rinfo, char **table)
207*7c478bd9Sstevel@tonic-gate {
208*7c478bd9Sstevel@tonic-gate 	int i;
209*7c478bd9Sstevel@tonic-gate 	size_t w;
210*7c478bd9Sstevel@tonic-gate 	size_t width = 0;
211*7c478bd9Sstevel@tonic-gate 	size_t w_rsrc = 0;
212*7c478bd9Sstevel@tonic-gate 	size_t w_info = 0;
213*7c478bd9Sstevel@tonic-gate 	size_t table_size = 0;
214*7c478bd9Sstevel@tonic-gate 	uint_t tuples = 0;
215*7c478bd9Sstevel@tonic-gate 	rcm_info_tuple_t *tuple = NULL;
216*7c478bd9Sstevel@tonic-gate 	char *rsrc;
217*7c478bd9Sstevel@tonic-gate 	char *info;
218*7c478bd9Sstevel@tonic-gate 	char *newtable;
219*7c478bd9Sstevel@tonic-gate 	static char format[MAX_FORMAT];
220*7c478bd9Sstevel@tonic-gate 	const char *infostr;
221*7c478bd9Sstevel@tonic-gate 
222*7c478bd9Sstevel@tonic-gate 	DPRINTF("usb_rcm_info_table:\n");
223*7c478bd9Sstevel@tonic-gate 
224*7c478bd9Sstevel@tonic-gate 	/* Protect against invalid arguments */
225*7c478bd9Sstevel@tonic-gate 	if (rinfo == NULL || table == NULL) {
226*7c478bd9Sstevel@tonic-gate 		return (CFGA_USB_INTERNAL_ERROR);
227*7c478bd9Sstevel@tonic-gate 	}
228*7c478bd9Sstevel@tonic-gate 
229*7c478bd9Sstevel@tonic-gate 	/* Set localized table header strings */
230*7c478bd9Sstevel@tonic-gate 	rsrc = dgettext(TEXT_DOMAIN, "Resource");
231*7c478bd9Sstevel@tonic-gate 	info = dgettext(TEXT_DOMAIN, "Information");
232*7c478bd9Sstevel@tonic-gate 
233*7c478bd9Sstevel@tonic-gate 	/* A first pass, to size up the RCM information */
234*7c478bd9Sstevel@tonic-gate 	while (tuple = rcm_info_next(rinfo, tuple)) {
235*7c478bd9Sstevel@tonic-gate 		if ((infostr = rcm_info_info(tuple)) != NULL) {
236*7c478bd9Sstevel@tonic-gate 			tuples++;
237*7c478bd9Sstevel@tonic-gate 			if ((w = strlen(rcm_info_rsrc(tuple))) > w_rsrc)
238*7c478bd9Sstevel@tonic-gate 				w_rsrc = w;
239*7c478bd9Sstevel@tonic-gate 			if ((w = strlen(infostr)) > w_info)
240*7c478bd9Sstevel@tonic-gate 				w_info = w;
241*7c478bd9Sstevel@tonic-gate 		}
242*7c478bd9Sstevel@tonic-gate 	}
243*7c478bd9Sstevel@tonic-gate 
244*7c478bd9Sstevel@tonic-gate 	/* If nothing was sized up above, stop early */
245*7c478bd9Sstevel@tonic-gate 	if (tuples == 0) {
246*7c478bd9Sstevel@tonic-gate 		DPRINTF("usb_rcm_info_table: no tuples\n");
247*7c478bd9Sstevel@tonic-gate 
248*7c478bd9Sstevel@tonic-gate 		return (CFGA_USB_OK);
249*7c478bd9Sstevel@tonic-gate 	}
250*7c478bd9Sstevel@tonic-gate 
251*7c478bd9Sstevel@tonic-gate 	/* Adjust column widths for column headings */
252*7c478bd9Sstevel@tonic-gate 	if ((w = strlen(rsrc)) > w_rsrc) {
253*7c478bd9Sstevel@tonic-gate 		w_rsrc = w;
254*7c478bd9Sstevel@tonic-gate 	} else if ((w_rsrc - w) % 2) {
255*7c478bd9Sstevel@tonic-gate 		w_rsrc++;
256*7c478bd9Sstevel@tonic-gate 	}
257*7c478bd9Sstevel@tonic-gate 
258*7c478bd9Sstevel@tonic-gate 	if ((w = strlen(info)) > w_info) {
259*7c478bd9Sstevel@tonic-gate 		w_info = w;
260*7c478bd9Sstevel@tonic-gate 	} else if ((w_info - w) % 2) {
261*7c478bd9Sstevel@tonic-gate 		w_info++;
262*7c478bd9Sstevel@tonic-gate 	}
263*7c478bd9Sstevel@tonic-gate 
264*7c478bd9Sstevel@tonic-gate 	/*
265*7c478bd9Sstevel@tonic-gate 	 * Compute the total line width of each line,
266*7c478bd9Sstevel@tonic-gate 	 * accounting for intercolumn spacing.
267*7c478bd9Sstevel@tonic-gate 	 */
268*7c478bd9Sstevel@tonic-gate 	width = w_info + w_rsrc + 4;
269*7c478bd9Sstevel@tonic-gate 
270*7c478bd9Sstevel@tonic-gate 	/* Allocate space for the table */
271*7c478bd9Sstevel@tonic-gate 	table_size = (2 + tuples) * (width + 1) + 2;
272*7c478bd9Sstevel@tonic-gate 	if (*table == NULL) {
273*7c478bd9Sstevel@tonic-gate 		/* zero fill for the strcat() call below */
274*7c478bd9Sstevel@tonic-gate 		*table = calloc(table_size, sizeof (char));
275*7c478bd9Sstevel@tonic-gate 		if (*table == NULL) {
276*7c478bd9Sstevel@tonic-gate 			DPRINTF("usb_rcm_info_table: no table\n");
277*7c478bd9Sstevel@tonic-gate 
278*7c478bd9Sstevel@tonic-gate 			return (CFGA_USB_ALLOC_FAIL);
279*7c478bd9Sstevel@tonic-gate 		}
280*7c478bd9Sstevel@tonic-gate 	} else {
281*7c478bd9Sstevel@tonic-gate 		newtable = realloc(*table, strlen(*table) + table_size);
282*7c478bd9Sstevel@tonic-gate 		if (newtable == NULL) {
283*7c478bd9Sstevel@tonic-gate 			DPRINTF("usb_rcm_info_table: no new table\n");
284*7c478bd9Sstevel@tonic-gate 
285*7c478bd9Sstevel@tonic-gate 			return (CFGA_USB_ALLOC_FAIL);
286*7c478bd9Sstevel@tonic-gate 		} else {
287*7c478bd9Sstevel@tonic-gate 			*table = newtable;
288*7c478bd9Sstevel@tonic-gate 		}
289*7c478bd9Sstevel@tonic-gate 	}
290*7c478bd9Sstevel@tonic-gate 
291*7c478bd9Sstevel@tonic-gate 	/* Place a table header into the string */
292*7c478bd9Sstevel@tonic-gate 
293*7c478bd9Sstevel@tonic-gate 	/* The resource header */
294*7c478bd9Sstevel@tonic-gate 	(void) strcat(*table, "\n");
295*7c478bd9Sstevel@tonic-gate 	w = strlen(rsrc);
296*7c478bd9Sstevel@tonic-gate 
297*7c478bd9Sstevel@tonic-gate 	for (i = 0; i < ((w_rsrc - w) / 2); i++) {
298*7c478bd9Sstevel@tonic-gate 		(void) strcat(*table, " ");
299*7c478bd9Sstevel@tonic-gate 	}
300*7c478bd9Sstevel@tonic-gate 	(void) strcat(*table, rsrc);
301*7c478bd9Sstevel@tonic-gate 
302*7c478bd9Sstevel@tonic-gate 	for (i = 0; i < ((w_rsrc - w) / 2); i++) {
303*7c478bd9Sstevel@tonic-gate 		(void) strcat(*table, " ");
304*7c478bd9Sstevel@tonic-gate 	}
305*7c478bd9Sstevel@tonic-gate 
306*7c478bd9Sstevel@tonic-gate 	/* The information header */
307*7c478bd9Sstevel@tonic-gate 	(void) strcat(*table, "  ");
308*7c478bd9Sstevel@tonic-gate 	w = strlen(info);
309*7c478bd9Sstevel@tonic-gate 	for (i = 0; i < ((w_info - w) / 2); i++) {
310*7c478bd9Sstevel@tonic-gate 		(void) strcat(*table, " ");
311*7c478bd9Sstevel@tonic-gate 	}
312*7c478bd9Sstevel@tonic-gate 	(void) strcat(*table, info);
313*7c478bd9Sstevel@tonic-gate 
314*7c478bd9Sstevel@tonic-gate 	for (i = 0; i < ((w_info - w) / 2); i++) {
315*7c478bd9Sstevel@tonic-gate 		(void) strcat(*table, " ");
316*7c478bd9Sstevel@tonic-gate 	}
317*7c478bd9Sstevel@tonic-gate 
318*7c478bd9Sstevel@tonic-gate 	(void) strcat(*table, "\n");
319*7c478bd9Sstevel@tonic-gate 
320*7c478bd9Sstevel@tonic-gate 	/* Underline the headers */
321*7c478bd9Sstevel@tonic-gate 	for (i = 0; i < w_rsrc; i++) {
322*7c478bd9Sstevel@tonic-gate 		(void) strcat(*table, "-");
323*7c478bd9Sstevel@tonic-gate 	}
324*7c478bd9Sstevel@tonic-gate 
325*7c478bd9Sstevel@tonic-gate 	(void) strcat(*table, "  ");
326*7c478bd9Sstevel@tonic-gate 	for (i = 0; i < w_info; i++) {
327*7c478bd9Sstevel@tonic-gate 		(void) strcat(*table, "-");
328*7c478bd9Sstevel@tonic-gate 	}
329*7c478bd9Sstevel@tonic-gate 
330*7c478bd9Sstevel@tonic-gate 	(void) strcat(*table, "\n");
331*7c478bd9Sstevel@tonic-gate 
332*7c478bd9Sstevel@tonic-gate 	/* Construct the format string */
333*7c478bd9Sstevel@tonic-gate 	(void) snprintf(format, MAX_FORMAT, "%%-%ds  %%-%ds",
334*7c478bd9Sstevel@tonic-gate 	    (int)w_rsrc, (int)w_info);
335*7c478bd9Sstevel@tonic-gate 
336*7c478bd9Sstevel@tonic-gate 	/* Add the tuples to the table string */
337*7c478bd9Sstevel@tonic-gate 	tuple = NULL;
338*7c478bd9Sstevel@tonic-gate 	while ((tuple = rcm_info_next(rinfo, tuple)) != NULL) {
339*7c478bd9Sstevel@tonic-gate 		if ((infostr = rcm_info_info(tuple)) != NULL) {
340*7c478bd9Sstevel@tonic-gate 			(void) sprintf(&((*table)[strlen(*table)]),
341*7c478bd9Sstevel@tonic-gate 			    format, rcm_info_rsrc(tuple), infostr);
342*7c478bd9Sstevel@tonic-gate 			(void) strcat(*table, "\n");
343*7c478bd9Sstevel@tonic-gate 		}
344*7c478bd9Sstevel@tonic-gate 	}
345*7c478bd9Sstevel@tonic-gate 
346*7c478bd9Sstevel@tonic-gate 	return (CFGA_USB_OK);
347*7c478bd9Sstevel@tonic-gate }
348