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