xref: /illumos-gate/usr/src/lib/cfgadm_plugins/usb/common/cfga_usb.h (revision 24da5b34f49324ed742a340010ed5bd3d4e06625)
1 /*
2  * CDDL HEADER START
3  *
4  * The contents of this file are subject to the terms of the
5  * Common Development and Distribution License, Version 1.0 only
6  * (the "License").  You may not use this file except in compliance
7  * with the License.
8  *
9  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10  * or http://www.opensolaris.org/os/licensing.
11  * See the License for the specific language governing permissions
12  * and limitations under the License.
13  *
14  * When distributing Covered Code, include this CDDL HEADER in each
15  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16  * If applicable, add the following below this CDDL HEADER, with the
17  * fields enclosed by brackets "[]" replaced with your own identifying
18  * information: Portions Copyright [yyyy] [name of copyright owner]
19  *
20  * CDDL HEADER END
21  */
22 /*
23  * Copyright (c) 2001 by Sun Microsystems, Inc.
24  * All rights reserved.
25  */
26 
27 #ifndef _CFGA_USB_H
28 #define	_CFGA_USB_H
29 
30 #pragma ident	"%Z%%M%	%I%	%E% SMI"
31 
32 #ifdef __cplusplus
33 extern "C" {
34 #endif
35 
36 #include <stdlib.h>
37 #include <strings.h>
38 #include <fcntl.h>
39 #include <ctype.h>
40 #include <unistd.h>
41 #include <libintl.h>
42 #include <libdevice.h>
43 #include <sys/varargs.h>
44 #include <sys/usb/usba.h>
45 #include <sys/usb/hubd/hub.h>
46 #include <sys/usb/hubd/hubd_impl.h>
47 #include <libdevinfo.h>
48 #include <libdevice.h>
49 #include <librcm.h>
50 #include <synch.h>
51 #include <thread.h>
52 #include <assert.h>
53 
54 #define	CFGA_PLUGIN_LIB
55 #include <config_admin.h>
56 
57 
58 /*
59  * Debug stuff.
60  */
61 #ifdef	DEBUG
62 #define	DPRINTF	printf
63 #else
64 #define	DPRINTF 0 &&
65 #endif /* DEBUG */
66 
67 
68 /* for walking links */
69 typedef struct walk_link {
70 	char *path;
71 	char len;
72 	char **linkpp;
73 } walk_link_t;
74 
75 
76 /*
77  * Stuff carried over for the routines borrowed from cfgadm/SCSI.
78  */
79 typedef enum {
80 	UCFGA_TERMINATE = 0,
81 	UCFGA_CONTINUE
82 } ucfga_recur_t;
83 
84 /* Structures for tree walking code */
85 typedef struct {
86 	char *phys;
87 	char *log;
88 	int ret;
89 	int match_minor;
90 	int l_errno;
91 } pathm_t;
92 
93 
94 #define	MATCH_MINOR_NAME	1
95 #define	S_FREE(x)	(((x) != NULL) ? (free(x), (x) = NULL) : (void *)0)
96 #define	GET_DYN(a)	(((a) != NULL) ? strstr((a), DYN_SEP) : (void *)0)
97 
98 
99 /* Location of USB configuration file */
100 #define	USBCONF_FILE	"/etc/usb/config_map.conf"
101 
102 /* Hardware options */
103 #define	OPT_DISABLE_RCM		"disable_rcm"
104 #define	FLAG_DISABLE_RCM	0x00000001	/* flags */
105 
106 /* Return/error codes */
107 typedef enum {
108 	UCFGA_ERR = -2,
109 	UCFGA_LIB_ERR,
110 	UCFGA_OK,
111 	UCFGA_BUSY,
112 	UCFGA_NO_REC
113 } ucfga_ret_t;
114 
115 
116 
117 /* Messages */
118 
119 typedef struct {
120 	int		intl;		/* Flag: if 1, internationalize */
121 	cfga_err_t	cfga_err;	/* Error code libcfgadm understands */
122 	const char	*msgstr;
123 } msgcvt_t;
124 #define	NO_CVT			0
125 #define	CVT			1
126 
127 #define	MSG_TBL_SZ(table)	(sizeof ((table)) / sizeof (msgcvt_t))
128 
129 
130 /* Error message ids (and indices into usb_error_msgs) */
131 typedef enum {
132 
133 	CFGA_USB_OK = 0,
134 	CFGA_USB_UNKNOWN,
135 	CFGA_USB_INTERNAL_ERROR,
136 	CFGA_USB_OPTIONS,
137 	CFGA_USB_DYNAMIC_AP,
138 	CFGA_USB_AP,
139 	CFGA_USB_PORT,
140 	CFGA_USB_DEVCTL,
141 	CFGA_USB_NOT_CONNECTED,
142 	CFGA_USB_NOT_CONFIGURED,
143 	CFGA_USB_ALREADY_CONNECTED,
144 	CFGA_USB_ALREADY_CONFIGURED,
145 	CFGA_USB_OPEN,
146 	CFGA_USB_IOCTL,
147 	CFGA_USB_BUSY,
148 	CFGA_USB_ALLOC_FAIL,
149 	CFGA_USB_OPNOTSUPP,
150 	CFGA_USB_DEVLINK,
151 	CFGA_USB_STATE,
152 	CFGA_USB_CONFIG_INVAL,
153 	CFGA_USB_PRIV,
154 	CFGA_USB_NVLIST,
155 	CFGA_USB_ZEROLEN,
156 	CFGA_USB_CONFIG_FILE,
157 	CFGA_USB_LOCK_FILE,
158 	CFGA_USB_UNLOCK_FILE,
159 	CFGA_USB_ONE_CONFIG,
160 
161 	/* RCM Errors */
162 	CFGA_USB_RCM_HANDLE,
163 	CFGA_USB_RCM_ONLINE,
164 	CFGA_USB_RCM_OFFLINE,
165 	CFGA_USB_RCM_INFO
166 
167 } cfga_usb_ret_t;
168 
169 
170 /*
171  * Given an error msg index, look up the associated string, and
172  * convert it to the current locale if required.
173  */
174 #define	ERR_STR(msg_idx) \
175 		(get_msg((msg_idx), usb_error_msgs, MSG_TBL_SZ(usb_error_msgs)))
176 
177 
178 /* Misc text strings */
179 #define	CFGA_DEV_DIR			"/dev/cfg"
180 #define	DYN_SEP				"::"
181 #define	MINOR_SEP			":"
182 #define	PORT				"port"
183 #define	PORT_SEPERATOR			"."
184 #define	USB				"usb"
185 #define	USB_CFGADM_DEFAULT_AP_TYPE	"unknown"
186 
187 /* these set of defines are -lav listing */
188 #define	USB_UNDEF_STR			"<undef>"
189 #define	USB_NO_CFG_STR			"<no cfg str descr>"
190 
191 /* -x commands */
192 #define	RESET_DEVICE			"usb_reset"	/* with -x option */
193 #define	USB_CONFIG			"usb_config"	/* with -x option */
194 #define	SET_CONFIG			"config="	/* with -o option */
195 #define	SET_DRIVER			"drv="		/* with -op option */
196 
197 /* for confirm operation */
198 #define	USB_CONFIRM_0	"the device: "
199 #define	USB_CONFIRM_1 \
200 	"This operation will suspend activity on the USB device\nContinue"
201 
202 /* Prototypes */
203 extern int		add_entry(char *, int, int, int, char *, char *, char *,
204 			    char **);
205 extern cfga_usb_ret_t	do_control_ioctl(const char *, uint_t, uint_t,
206 			    void **, size_t *);
207 
208 
209 #ifdef __cplusplus
210 }
211 #endif
212 
213 #endif /* _CFGA_USB_H */
214