xref: /onnv-gate/usr/src/lib/cfgadm_plugins/usb/common/cfga_usb.h (revision 7492:2387323b838f)
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
5*7492SZhigang.Lu@Sun.COM  * Common Development and Distribution License (the "License").
6*7492SZhigang.Lu@Sun.COM  * You may not use this file except in compliance with the License.
70Sstevel@tonic-gate  *
80Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
90Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
100Sstevel@tonic-gate  * See the License for the specific language governing permissions
110Sstevel@tonic-gate  * and limitations under the License.
120Sstevel@tonic-gate  *
130Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
140Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
150Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
160Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
170Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
180Sstevel@tonic-gate  *
190Sstevel@tonic-gate  * CDDL HEADER END
200Sstevel@tonic-gate  */
210Sstevel@tonic-gate /*
22*7492SZhigang.Lu@Sun.COM  * Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
23*7492SZhigang.Lu@Sun.COM  * Use is subject to license terms.
240Sstevel@tonic-gate  */
250Sstevel@tonic-gate 
260Sstevel@tonic-gate #ifndef _CFGA_USB_H
270Sstevel@tonic-gate #define	_CFGA_USB_H
280Sstevel@tonic-gate 
290Sstevel@tonic-gate 
300Sstevel@tonic-gate #ifdef __cplusplus
310Sstevel@tonic-gate extern "C" {
320Sstevel@tonic-gate #endif
330Sstevel@tonic-gate 
340Sstevel@tonic-gate #include <stdlib.h>
350Sstevel@tonic-gate #include <strings.h>
360Sstevel@tonic-gate #include <fcntl.h>
370Sstevel@tonic-gate #include <ctype.h>
380Sstevel@tonic-gate #include <unistd.h>
390Sstevel@tonic-gate #include <libintl.h>
400Sstevel@tonic-gate #include <libdevice.h>
410Sstevel@tonic-gate #include <sys/varargs.h>
420Sstevel@tonic-gate #include <sys/usb/usba.h>
430Sstevel@tonic-gate #include <sys/usb/hubd/hub.h>
440Sstevel@tonic-gate #include <sys/usb/hubd/hubd_impl.h>
450Sstevel@tonic-gate #include <libdevinfo.h>
460Sstevel@tonic-gate #include <libdevice.h>
470Sstevel@tonic-gate #include <librcm.h>
480Sstevel@tonic-gate #include <synch.h>
490Sstevel@tonic-gate #include <thread.h>
500Sstevel@tonic-gate #include <assert.h>
510Sstevel@tonic-gate 
520Sstevel@tonic-gate #define	CFGA_PLUGIN_LIB
530Sstevel@tonic-gate #include <config_admin.h>
540Sstevel@tonic-gate 
550Sstevel@tonic-gate 
560Sstevel@tonic-gate /*
570Sstevel@tonic-gate  * Debug stuff.
580Sstevel@tonic-gate  */
590Sstevel@tonic-gate #ifdef	DEBUG
60*7492SZhigang.Lu@Sun.COM #define	DPRINTF	(void) printf
610Sstevel@tonic-gate #else
620Sstevel@tonic-gate #define	DPRINTF 0 &&
630Sstevel@tonic-gate #endif /* DEBUG */
640Sstevel@tonic-gate 
650Sstevel@tonic-gate 
660Sstevel@tonic-gate /* for walking links */
670Sstevel@tonic-gate typedef struct walk_link {
680Sstevel@tonic-gate 	char *path;
690Sstevel@tonic-gate 	char len;
700Sstevel@tonic-gate 	char **linkpp;
710Sstevel@tonic-gate } walk_link_t;
720Sstevel@tonic-gate 
730Sstevel@tonic-gate 
740Sstevel@tonic-gate /*
750Sstevel@tonic-gate  * Stuff carried over for the routines borrowed from cfgadm/SCSI.
760Sstevel@tonic-gate  */
770Sstevel@tonic-gate typedef enum {
780Sstevel@tonic-gate 	UCFGA_TERMINATE = 0,
790Sstevel@tonic-gate 	UCFGA_CONTINUE
800Sstevel@tonic-gate } ucfga_recur_t;
810Sstevel@tonic-gate 
820Sstevel@tonic-gate /* Structures for tree walking code */
830Sstevel@tonic-gate typedef struct {
840Sstevel@tonic-gate 	char *phys;
850Sstevel@tonic-gate 	char *log;
860Sstevel@tonic-gate 	int ret;
870Sstevel@tonic-gate 	int match_minor;
880Sstevel@tonic-gate 	int l_errno;
890Sstevel@tonic-gate } pathm_t;
900Sstevel@tonic-gate 
910Sstevel@tonic-gate 
920Sstevel@tonic-gate #define	MATCH_MINOR_NAME	1
930Sstevel@tonic-gate #define	S_FREE(x)	(((x) != NULL) ? (free(x), (x) = NULL) : (void *)0)
940Sstevel@tonic-gate #define	GET_DYN(a)	(((a) != NULL) ? strstr((a), DYN_SEP) : (void *)0)
950Sstevel@tonic-gate 
960Sstevel@tonic-gate 
970Sstevel@tonic-gate /* Location of USB configuration file */
980Sstevel@tonic-gate #define	USBCONF_FILE	"/etc/usb/config_map.conf"
990Sstevel@tonic-gate 
1000Sstevel@tonic-gate /* Hardware options */
1010Sstevel@tonic-gate #define	OPT_DISABLE_RCM		"disable_rcm"
1020Sstevel@tonic-gate #define	FLAG_DISABLE_RCM	0x00000001	/* flags */
1030Sstevel@tonic-gate 
1040Sstevel@tonic-gate /* Return/error codes */
1050Sstevel@tonic-gate typedef enum {
1060Sstevel@tonic-gate 	UCFGA_ERR = -2,
1070Sstevel@tonic-gate 	UCFGA_LIB_ERR,
1080Sstevel@tonic-gate 	UCFGA_OK,
1090Sstevel@tonic-gate 	UCFGA_BUSY,
1100Sstevel@tonic-gate 	UCFGA_NO_REC
1110Sstevel@tonic-gate } ucfga_ret_t;
1120Sstevel@tonic-gate 
1130Sstevel@tonic-gate 
1140Sstevel@tonic-gate 
1150Sstevel@tonic-gate /* Messages */
1160Sstevel@tonic-gate 
1170Sstevel@tonic-gate typedef struct {
1180Sstevel@tonic-gate 	int		intl;		/* Flag: if 1, internationalize */
1190Sstevel@tonic-gate 	cfga_err_t	cfga_err;	/* Error code libcfgadm understands */
1200Sstevel@tonic-gate 	const char	*msgstr;
1210Sstevel@tonic-gate } msgcvt_t;
1220Sstevel@tonic-gate #define	NO_CVT			0
1230Sstevel@tonic-gate #define	CVT			1
1240Sstevel@tonic-gate 
1250Sstevel@tonic-gate #define	MSG_TBL_SZ(table)	(sizeof ((table)) / sizeof (msgcvt_t))
1260Sstevel@tonic-gate 
1270Sstevel@tonic-gate 
1280Sstevel@tonic-gate /* Error message ids (and indices into usb_error_msgs) */
1290Sstevel@tonic-gate typedef enum {
1300Sstevel@tonic-gate 
1310Sstevel@tonic-gate 	CFGA_USB_OK = 0,
1320Sstevel@tonic-gate 	CFGA_USB_UNKNOWN,
1330Sstevel@tonic-gate 	CFGA_USB_INTERNAL_ERROR,
1340Sstevel@tonic-gate 	CFGA_USB_OPTIONS,
1350Sstevel@tonic-gate 	CFGA_USB_DYNAMIC_AP,
1360Sstevel@tonic-gate 	CFGA_USB_AP,
1370Sstevel@tonic-gate 	CFGA_USB_PORT,
1380Sstevel@tonic-gate 	CFGA_USB_DEVCTL,
1390Sstevel@tonic-gate 	CFGA_USB_NOT_CONNECTED,
1400Sstevel@tonic-gate 	CFGA_USB_NOT_CONFIGURED,
1410Sstevel@tonic-gate 	CFGA_USB_ALREADY_CONNECTED,
1420Sstevel@tonic-gate 	CFGA_USB_ALREADY_CONFIGURED,
1430Sstevel@tonic-gate 	CFGA_USB_OPEN,
1440Sstevel@tonic-gate 	CFGA_USB_IOCTL,
1450Sstevel@tonic-gate 	CFGA_USB_BUSY,
1460Sstevel@tonic-gate 	CFGA_USB_ALLOC_FAIL,
1470Sstevel@tonic-gate 	CFGA_USB_OPNOTSUPP,
1480Sstevel@tonic-gate 	CFGA_USB_DEVLINK,
1490Sstevel@tonic-gate 	CFGA_USB_STATE,
1500Sstevel@tonic-gate 	CFGA_USB_CONFIG_INVAL,
1510Sstevel@tonic-gate 	CFGA_USB_PRIV,
1520Sstevel@tonic-gate 	CFGA_USB_NVLIST,
1530Sstevel@tonic-gate 	CFGA_USB_ZEROLEN,
1540Sstevel@tonic-gate 	CFGA_USB_CONFIG_FILE,
1550Sstevel@tonic-gate 	CFGA_USB_LOCK_FILE,
1560Sstevel@tonic-gate 	CFGA_USB_UNLOCK_FILE,
1570Sstevel@tonic-gate 	CFGA_USB_ONE_CONFIG,
1580Sstevel@tonic-gate 
1590Sstevel@tonic-gate 	/* RCM Errors */
1600Sstevel@tonic-gate 	CFGA_USB_RCM_HANDLE,
1610Sstevel@tonic-gate 	CFGA_USB_RCM_ONLINE,
1620Sstevel@tonic-gate 	CFGA_USB_RCM_OFFLINE,
1630Sstevel@tonic-gate 	CFGA_USB_RCM_INFO
1640Sstevel@tonic-gate 
1650Sstevel@tonic-gate } cfga_usb_ret_t;
1660Sstevel@tonic-gate 
1670Sstevel@tonic-gate 
1680Sstevel@tonic-gate /*
1690Sstevel@tonic-gate  * Given an error msg index, look up the associated string, and
1700Sstevel@tonic-gate  * convert it to the current locale if required.
1710Sstevel@tonic-gate  */
1720Sstevel@tonic-gate #define	ERR_STR(msg_idx) \
1730Sstevel@tonic-gate 		(get_msg((msg_idx), usb_error_msgs, MSG_TBL_SZ(usb_error_msgs)))
1740Sstevel@tonic-gate 
1750Sstevel@tonic-gate 
1760Sstevel@tonic-gate /* Misc text strings */
1770Sstevel@tonic-gate #define	CFGA_DEV_DIR			"/dev/cfg"
1780Sstevel@tonic-gate #define	DYN_SEP				"::"
1790Sstevel@tonic-gate #define	MINOR_SEP			":"
1800Sstevel@tonic-gate #define	PORT				"port"
1810Sstevel@tonic-gate #define	PORT_SEPERATOR			"."
1820Sstevel@tonic-gate #define	USB				"usb"
1830Sstevel@tonic-gate #define	USB_CFGADM_DEFAULT_AP_TYPE	"unknown"
1840Sstevel@tonic-gate 
1850Sstevel@tonic-gate /* these set of defines are -lav listing */
1860Sstevel@tonic-gate #define	USB_UNDEF_STR			"<undef>"
1870Sstevel@tonic-gate #define	USB_NO_CFG_STR			"<no cfg str descr>"
1880Sstevel@tonic-gate 
1890Sstevel@tonic-gate /* -x commands */
1900Sstevel@tonic-gate #define	RESET_DEVICE			"usb_reset"	/* with -x option */
1910Sstevel@tonic-gate #define	USB_CONFIG			"usb_config"	/* with -x option */
1920Sstevel@tonic-gate #define	SET_CONFIG			"config="	/* with -o option */
1930Sstevel@tonic-gate #define	SET_DRIVER			"drv="		/* with -op option */
1940Sstevel@tonic-gate 
1950Sstevel@tonic-gate /* for confirm operation */
1960Sstevel@tonic-gate #define	USB_CONFIRM_0	"the device: "
1970Sstevel@tonic-gate #define	USB_CONFIRM_1 \
1980Sstevel@tonic-gate 	"This operation will suspend activity on the USB device\nContinue"
1990Sstevel@tonic-gate 
2000Sstevel@tonic-gate /* Prototypes */
2010Sstevel@tonic-gate extern int		add_entry(char *, int, int, int, char *, char *, char *,
2020Sstevel@tonic-gate 			    char **);
2030Sstevel@tonic-gate extern cfga_usb_ret_t	do_control_ioctl(const char *, uint_t, uint_t,
2040Sstevel@tonic-gate 			    void **, size_t *);
2050Sstevel@tonic-gate 
2060Sstevel@tonic-gate 
2070Sstevel@tonic-gate #ifdef __cplusplus
2080Sstevel@tonic-gate }
2090Sstevel@tonic-gate #endif
2100Sstevel@tonic-gate 
2110Sstevel@tonic-gate #endif /* _CFGA_USB_H */
212