xref: /illumos-gate/usr/src/cmd/hal/hald/solaris/devinfo_usb.c (revision 33efde4275d24731ef87927237b0ffb0630b6b2d)
1 /***************************************************************************
2  *
3  * devinfo_usb.h : USB devices
4  *
5  * Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
6  * Use is subject to license terms.
7  *
8  * Licensed under the Academic Free License version 2.1
9  *
10  **************************************************************************/
11 
12 #ifdef HAVE_CONFIG_H
13 #  include <config.h>
14 #endif
15 
16 #include <stdio.h>
17 #include <string.h>
18 #include <libdevinfo.h>
19 #include <unistd.h>
20 #include <dirent.h>
21 #include <sys/types.h>
22 #include <sys/mkdev.h>
23 #include <sys/stat.h>
24 #include <sys/usb/usbai.h>
25 
26 #include "../osspec.h"
27 #include "../logger.h"
28 #include "../hald.h"
29 #include "../hald_dbus.h"
30 #include "../device_info.h"
31 #include "../util.h"
32 #include "../ids.h"
33 #include "hotplug.h"
34 #include "devinfo.h"
35 #include "devinfo_usb.h"
36 
37 static HalDevice *devinfo_usb_if_add(HalDevice *d, di_node_t node, gchar *devfs_path,
38 				     gchar *if_devfs_path, int ifnum);
39 static HalDevice *devinfo_usb_scsa2usb_add(HalDevice *d, di_node_t node);
40 static HalDevice *devinfo_usb_printer_add(HalDevice *usbd, di_node_t node);
41 static HalDevice *devinfo_usb_input_add(HalDevice *usbd, di_node_t node);
42 static HalDevice *devinfo_usb_video4linux_add(HalDevice *usbd, di_node_t node);
43 const gchar *devinfo_printer_prnio_get_prober(HalDevice *d, int *timeout);
44 const gchar *devinfo_keyboard_get_prober(HalDevice *d, int *timeout);
45 static void set_usb_properties(HalDevice *d, di_node_t node, gchar *devfs_path, char *driver_name);
46 
47 DevinfoDevHandler devinfo_usb_handler = {
48 	devinfo_usb_add,
49 	NULL,
50 	NULL,
51 	NULL,
52 	NULL,
53 	NULL
54 };
55 
56 DevinfoDevHandler devinfo_usb_printer_handler = {
57 	devinfo_usb_add,
58 	NULL,
59 	NULL,
60 	NULL,
61 	NULL,
62 	devinfo_printer_prnio_get_prober
63 };
64 
65 DevinfoDevHandler devinfo_usb_keyboard_handler = {
66 	devinfo_usb_add,
67 	NULL,
68 	NULL,
69 	NULL,
70 	NULL,
71 	devinfo_keyboard_get_prober
72 };
73 
74 static gboolean
is_usb_node(di_node_t node)75 is_usb_node(di_node_t node)
76 {
77 	int rc;
78 	char *s;
79 
80 	/*
81 	 * USB device nodes will have "compatible" propety values that
82 	 * begins with "usb".
83 	 */
84 	rc = di_prop_lookup_strings(DDI_DEV_T_ANY, node, "compatible", &s);
85 	while (rc-- > 0) {
86 		if (strncmp(s, "usb", 3) == 0) {
87 			return (TRUE);
88 		}
89 		s += (strlen(s) + 1);
90 	}
91 
92 	return (FALSE);
93 }
94 
95 static char *
get_usb_devlink(char * devfs_path,const char * dir_name)96 get_usb_devlink(char *devfs_path, const char *dir_name)
97 {
98 	char *result = NULL;
99 	DIR *dp;
100 
101 	if ((dp = opendir(dir_name)) != NULL) {
102 		struct dirent *ep;
103 
104 		while ((ep = readdir(dp)) != NULL) {
105 			char path[MAXPATHLEN], lpath[MAXPATHLEN];
106 
107 			strncpy(path, dir_name, strlen(dir_name));
108 			strncat(path, ep->d_name, strlen(ep->d_name));
109 			memset(lpath, 0, sizeof (lpath));
110 			if ((readlink(path, lpath, sizeof (lpath)) > 0) &&
111 			    (strstr(lpath, devfs_path) != NULL)) {
112 				result = strdup(path);
113 				break;
114 			}
115 			memset(path, 0, sizeof (path));
116 		}
117 		closedir(dp);
118 	}
119 
120 	return (result);
121 }
122 
123 HalDevice *
devinfo_usb_add(HalDevice * parent,di_node_t node,char * devfs_path,char * device_type)124 devinfo_usb_add(HalDevice *parent, di_node_t node, char *devfs_path, char *device_type)
125 {
126 	HalDevice *d, *nd = NULL;
127 	char	*s;
128 	int	*i;
129 	char	*driver_name, *binding_name;
130 	char	if_devfs_path[HAL_PATH_MAX];
131 	di_devlink_handle_t hdl;
132 	double	k;
133 
134 	if (is_usb_node(node) == FALSE) {
135 		return (NULL);
136 	}
137 
138 	driver_name = di_driver_name (node);
139 
140 	if (di_prop_lookup_ints (DDI_DEV_T_ANY, node, "interface", &i) < 0) {
141 		/* It is a USB device node. */
142 
143 		d = hal_device_new ();
144 
145 		devinfo_set_default_properties (d, parent, node, devfs_path);
146 		hal_device_property_set_string (d, "info.subsystem", "usb_device");
147 		PROP_STR(d, node, s, "usb-product-name", "info.product");
148 		PROP_STR(d, node, s, "usb-product-name", "usb_device.product");
149 		PROP_STR(d, node, s, "usb-vendor-name", "usb_device.vendor");
150 		PROP_INT(d, node, i, "usb-vendor-id", "usb_device.vendor_id");
151 		PROP_INT(d, node, i, "usb-product-id", "usb_device.product_id");
152 		PROP_INT(d, node, i, "usb-revision-id", "usb_device.device_revision_bcd");
153 		PROP_STR(d, node, s, "usb-serialno", "usb_device.serial");
154 		PROP_INT(d, node, i, "usb-port-count", "usb_device.num_ports");
155 		PROP_INT(d, node, i, "usb-num-configs", "usb_device.num_configurations");
156 		PROP_INT(d, node, i, "assigned-address", "usb_device.bus_number");
157 
158 		if  (di_prop_lookup_ints (DDI_DEV_T_ANY, node, "usb-release", &i) > 0) {
159 			k = (double)bcd(*i);
160 			hal_device_property_set_double (d, "usb_device.version", k / 100);
161 		}
162 
163 		if (di_prop_lookup_ints (DDI_DEV_T_ANY, node, "low-speed", &i) >= 0) {
164 			k = 1.5;
165 		} else if (di_prop_lookup_ints (DDI_DEV_T_ANY, node, "high-speed", &i) >= 0) {
166 			k = 480.0;
167 		} else {
168 			/* It is the full speed device. */
169 			k = 12.0;
170 		}
171 		hal_device_property_set_double (d, "usb_device.speed", k);
172 
173 		set_usb_properties (d, node, devfs_path, driver_name);
174 
175 		/* wait for the ugen node's creation */
176 		if ((driver_name != NULL) && (strcmp (driver_name, "usb_mid") == 0)) {
177 			if (hdl = di_devlink_init (devfs_path, DI_MAKE_LINK)) {
178 				di_devlink_fini (&hdl);
179 			}
180 		}
181 
182 		devinfo_add_enqueue (d, devfs_path, &devinfo_usb_handler);
183 
184 		/* add to TDL so preprobing callouts and prober can access it */
185 		hal_device_store_add (hald_get_tdl (), d);
186 
187 		if (((binding_name = di_binding_name (node)) != NULL) &&
188 		    (strncmp (binding_name, "usbif,", sizeof ("usbif,") - 1) == 0)) {
189 
190 			snprintf (if_devfs_path, sizeof (if_devfs_path), "%s:if%d",
191 			    devfs_path, 0);
192 			if ((nd = devinfo_usb_if_add (d, node, if_devfs_path,
193 			    if_devfs_path, 0)) != NULL) {
194 				d = nd;
195 				nd = NULL;
196 				devfs_path = if_devfs_path;
197 			}
198 		}
199 	} else {
200 		/* It is a USB interface node or IA node. */
201 		int *j;
202 
203 		if (di_prop_lookup_ints (DDI_DEV_T_ANY, node, "interface-count", &j) > 0) {
204 			/*
205 			 * The USB IA node properties are not defined in
206 			 * HAL spec so far. So IA node udi has "ia" sign
207 			 * now, different from the IF node udi with "if".
208 			 */
209 			snprintf (if_devfs_path, sizeof (if_devfs_path),
210 			    "%s:ia%d", devfs_path, *i);
211 		} else {
212 			snprintf (if_devfs_path, sizeof (if_devfs_path),
213 			    "%s:if%d", devfs_path, *i);
214 		}
215 
216 		d = devinfo_usb_if_add (parent, node, devfs_path, if_devfs_path, *i);
217 	}
218 
219 	/* driver specific */
220 	if (driver_name != NULL) {
221 		if (strcmp (driver_name, "scsa2usb") == 0) {
222 			nd = devinfo_usb_scsa2usb_add (d, node);
223 		} else if (strcmp (driver_name, "usbprn") == 0) {
224 			nd = devinfo_usb_printer_add (d, node);
225 		} else if (strcmp(driver_name, "hid") == 0) {
226 			if (hdl = di_devlink_init(devfs_path, DI_MAKE_LINK)) {
227 				di_devlink_fini(&hdl);
228 			}
229 			nd = devinfo_usb_input_add(d, node);
230 		} else if (strcmp(driver_name, "usbvc") == 0) {
231 			if (hdl = di_devlink_init(devfs_path, DI_MAKE_LINK)) {
232 				di_devlink_fini(&hdl);
233 			}
234 			nd = devinfo_usb_video4linux_add(d, node);
235 		}
236 	}
237 
238 	if (nd != NULL) {
239 		return (nd);
240 	} else {
241 		return (d);
242 	}
243 }
244 
245 
246 static void
set_usb_properties(HalDevice * d,di_node_t node,gchar * devfs_path,char * driver_name)247 set_usb_properties(HalDevice *d, di_node_t node, gchar *devfs_path, char *driver_name)
248 {
249 	usb_dev_descr_t	*dev_descrp = NULL;	/* device descriptor */
250 	usb_cfg_descr_t	*cfg_descrp = NULL;	/* configuration descriptor */
251 	unsigned char	*rdata = NULL;
252 	char *p;
253 	int i = 0;
254 
255 	hal_device_property_set_int (d, "usb_device.port_number",
256 	    atoi (devfs_path + strlen (devfs_path) -1));
257 
258 	if (di_prop_lookup_bytes (DDI_DEV_T_ANY, node, "usb-dev-descriptor",
259 	    &rdata) > 0) {
260 		dev_descrp = (usb_dev_descr_t *)rdata;
261 
262 		if (dev_descrp != NULL) {
263 			hal_device_property_set_int (d, "usb_device.device_class",
264 			    dev_descrp->bDeviceClass);
265 			hal_device_property_set_int (d, "usb_device.device_subclass",
266 			    dev_descrp->bDeviceSubClass);
267 			hal_device_property_set_int (d, "usb_device.device_protocol",
268 			    dev_descrp->bDeviceProtocol);
269 		}
270 	}
271 
272 	if (di_prop_lookup_bytes (DDI_DEV_T_ANY, node, "usb-raw-cfg-descriptors",
273 	    &rdata) > 0) {
274 		cfg_descrp = (usb_cfg_descr_t *)(rdata);
275 
276 		if (cfg_descrp != NULL) {
277 			hal_device_property_set_int (d, "usb_device.configuration_value",
278 			    cfg_descrp->bConfigurationValue);
279 			hal_device_property_set_int (d, "usb_device.max_power",
280 			    cfg_descrp->bMaxPower);
281 			hal_device_property_set_int (d, "usb_device.num_interfaces",
282 			    cfg_descrp->bNumInterfaces);
283 			hal_device_property_set_bool (d, "usb_device.can_wake_up",
284 			    (cfg_descrp->bmAttributes & 0x20) ? TRUE : FALSE);
285 			hal_device_property_set_bool (d, "usb_device.is_self_powered",
286 			    (cfg_descrp->bmAttributes & 0x40) ? TRUE : FALSE);
287 		}
288 	}
289 
290 	/* get the node's usb tree level by counting hub numbers */
291 	do {
292 		if (p = strstr (devfs_path, "/hub@")) {
293 			devfs_path = p + strlen ("/hub@");
294 			i ++;
295 		}
296 	} while (p != NULL);
297 
298 	if ((driver_name != NULL) && (strcmp (driver_name, "hubd") == 0) && (i > 0))
299 		i --;
300 
301 	hal_device_property_set_int (d, "usb_device.level_number", i);
302 }
303 
304 
305 static usb_if_descr_t *
parse_usb_if_descr(di_node_t node,int ifnum)306 parse_usb_if_descr(di_node_t node, int ifnum)
307 {
308 	unsigned char	*rdata = NULL;
309 	usb_if_descr_t	*if_descrp=NULL;	/* interface descriptor */
310 	di_node_t	tmp_node = DI_NODE_NIL;
311 	uint8_t num, length, type;
312 	int rlen;
313 	gchar *devpath = NULL;
314 
315 	if ((rlen = di_prop_lookup_bytes (DDI_DEV_T_ANY, node,
316 	     "usb-raw-cfg-descriptors", &rdata)) < 0) {
317 
318 		char *p;
319 		int i;
320 
321 		if ((devpath = di_devfs_path (node)) == NULL)
322 			goto out;
323 
324 		/* Look up its parent that may be a USB IA or USB mid. */
325 		for (i = 0; i < 2; i++) {
326 			p = strrchr (devpath, '/');
327 			if (p == NULL)
328 				goto out;
329 			*p = '\0';
330 
331 			if ((tmp_node = di_init (devpath, DINFOCPYALL)) == DI_NODE_NIL)
332 				goto out;
333 
334 			if ((rlen = di_prop_lookup_bytes (DDI_DEV_T_ANY, tmp_node,
335 			     "usb-raw-cfg-descriptors", &rdata)) > 0)
336 				break;
337 
338 			di_fini (tmp_node);
339 		}
340 	}
341 
342 	if (rdata == NULL)
343 		goto out;
344 
345 	do {
346 		length = (uint8_t)*rdata;
347 		type = (uint8_t)*(rdata + 1);
348 		if (type == USB_DESCR_TYPE_IF) {
349 			num = (uint8_t)*(rdata + 2);
350 			if (num == ifnum) {
351 				if_descrp = (usb_if_descr_t *)rdata;
352 				break;
353 			}
354 		}
355 		rdata += length;
356 		rlen -= length;
357 	} while ((length > 0 ) && (rlen > 0));
358 
359 out:
360 	if (devpath != NULL)
361 		di_devfs_path_free (devpath);
362 	if (tmp_node != DI_NODE_NIL)
363 		di_fini (tmp_node);
364 	return (if_descrp);
365 }
366 
367 
368 static HalDevice *
devinfo_usb_if_add(HalDevice * parent,di_node_t node,gchar * devfs_path,gchar * if_devfs_path,int ifnum)369 devinfo_usb_if_add(HalDevice *parent, di_node_t node, gchar *devfs_path,
370 		   gchar *if_devfs_path, int ifnum)
371 {
372 	HalDevice	*d = NULL;
373 	char		udi[HAL_PATH_MAX];
374 	const char	*parent_info;
375 	usb_if_descr_t	*if_descrp=NULL;	/* interface descriptor */
376 
377 	d = hal_device_new ();
378 
379 	devinfo_set_default_properties (d, parent, node, if_devfs_path);
380 
381 	/* Set the existed physical device path. */
382 	hal_device_property_set_string (d, "solaris.devfs_path", devfs_path);
383 	hal_device_property_set_string (d, "info.subsystem", "usb");
384 	hal_device_property_set_string (d, "info.product", "USB Device Interface");
385 
386 	/* Set usb interface properties to interface node. */
387 	if (strstr (if_devfs_path, ":ia") == NULL) {
388 		if_descrp = parse_usb_if_descr (node, ifnum);
389 
390 		if (if_descrp != NULL) {
391 			hal_device_property_set_int (d, "usb.interface.class",
392 			    if_descrp->bInterfaceClass);
393 			hal_device_property_set_int (d, "usb.interface.subclass",
394 			    if_descrp->bInterfaceSubClass);
395 			hal_device_property_set_int (d, "usb.interface.protocol",
396 			    if_descrp->bInterfaceProtocol);
397 			hal_device_property_set_int (d, "usb.interface.number",
398 			    if_descrp->bInterfaceNumber);
399 		}
400 	}
401 
402 	/* copy parent's usb_device.* properties */
403 	parent_info = hal_device_property_get_string (parent, "info.subsystem");
404 	if (parent_info != NULL) {
405 		if (strcmp (parent_info, "usb_device") == 0) {
406 			hal_device_merge_with_rewrite (d, parent, "usb.", "usb_device.");
407 		} else if (strcmp (parent_info, "usb") == 0) {
408 			/* for the case that the parent is IA node */
409 			hal_device_merge_with_rewrite (d, parent, "usb.", "usb.");
410 		}
411 	}
412 
413 	devinfo_add_enqueue (d, devfs_path, &devinfo_usb_handler);
414 
415 	/* add to TDL so preprobing callouts and prober can access it */
416 	hal_device_store_add (hald_get_tdl (), d);
417 
418 	return (d);
419 }
420 
421 
422 static void
get_dev_link_path(di_node_t node,char * nodetype,char * re,char ** devlink,char ** minor_path,char ** minor_name)423 get_dev_link_path(di_node_t node, char *nodetype, char *re, char **devlink, char **minor_path, char **minor_name)
424 {
425 	di_devlink_handle_t devlink_hdl;
426 	int	major;
427 	di_minor_t minor;
428 	dev_t	devt;
429 
430 	*devlink = NULL;
431 	*minor_path = NULL;
432 	*minor_name = NULL;
433 
434 	if ((devlink_hdl = di_devlink_init(NULL, 0)) == NULL) {
435 		return;
436 	}
437 
438 	major = di_driver_major(node);
439 	minor = DI_MINOR_NIL;
440 	while ((minor = di_minor_next(node, minor)) != DI_MINOR_NIL) {
441 		devt = di_minor_devt(minor);
442 		if (major != major(devt)) {
443 			continue;
444 		}
445 
446 		if (di_minor_type(minor) != DDM_MINOR) {
447 			continue;
448 		}
449 
450 		if ((*minor_path = di_devfs_minor_path(minor)) == NULL) {
451 			continue;
452 		}
453 
454 		if (strcmp(di_minor_nodetype(minor), nodetype) == 0) {
455 			*devlink = get_devlink(devlink_hdl, re, *minor_path);
456 			/*
457 			 * During hotplugging, devlink could be NULL for usb
458 			 * devices due to devlink database has not yet been
459 			 * updated when hal try to read from it although the
460 			 * actually dev link path has been created. In such a
461 			 * situation, we will read the devlink name from
462 			 * /dev/usb directory.
463 			 */
464 			if ((*devlink == NULL) && (re != NULL) &&
465 			    ((strstr(re, "hid") != NULL) || (strstr(re, "video") != NULL))) {
466 				*devlink = get_usb_devlink(*minor_path, "/dev/usb/");
467 			}
468 
469 			if (*devlink != NULL) {
470 				*minor_name = di_minor_name(minor);
471 				break;
472 			}
473 		}
474 
475 		di_devfs_path_free (*minor_path);
476 		*minor_path = NULL;
477 	}
478 	di_devlink_fini (&devlink_hdl);
479 }
480 
481 static HalDevice *
devinfo_usb_video4linux_add(HalDevice * usbd,di_node_t node)482 devinfo_usb_video4linux_add(HalDevice *usbd, di_node_t node)
483 {
484 	HalDevice *d = NULL;
485 	int	major;
486 	di_minor_t minor;
487 	dev_t	devt;
488 	char	*devlink = NULL;
489 	char	*dev_videolink = NULL;
490 	char	*minor_path = NULL;
491 	char	*minor_name = NULL;
492 	char	udi[HAL_PATH_MAX];
493 	char	*s;
494 
495 	get_dev_link_path(node, "usb_video",
496 	    "^usb/video[0-9]+",  &devlink, &minor_path, &minor_name);
497 
498 	if ((minor_path == NULL) || (devlink == NULL)) {
499 
500 		goto out;
501 	}
502 
503 	HAL_DEBUG(("devlink %s, minor_name %s", devlink, minor_name));
504 	if (strcmp(minor_name, "usbvc") != 0) {
505 
506 		goto out;
507 	}
508 
509 	d = hal_device_new();
510 
511 	devinfo_set_default_properties(d, usbd, node, minor_path);
512 	hal_device_property_set_string(d, "info.subsystem", "video4linux");
513 	hal_device_property_set_string(d, "info.category", "video4linux");
514 
515 	hal_device_add_capability(d, "video4linux");
516 
517 	/* Get logic link under /dev (/dev/video+) */
518 	dev_videolink = get_usb_devlink(strstr(devlink, "usb"), "/dev/");
519 
520 	hal_device_property_set_string(d, "video4linux.device", dev_videolink);
521 
522 	hal_util_compute_udi(hald_get_gdl(), udi, sizeof (udi),
523 	    "%s_video4linux", hal_device_get_udi(usbd));
524 
525 	hal_device_set_udi(d, udi);
526 	hal_device_property_set_string(d, "info.udi", udi);
527 	PROP_STR(d, node, s, "usb-product-name", "info.product");
528 
529 	devinfo_add_enqueue(d, minor_path, &devinfo_usb_handler);
530 
531 
532 out:
533 	if (devlink) {
534 		free(devlink);
535 	}
536 
537 	if (minor_path) {
538 		di_devfs_path_free(minor_path);
539 	}
540 
541 	return (d);
542 }
543 
544 static HalDevice *
devinfo_usb_input_add(HalDevice * usbd,di_node_t node)545 devinfo_usb_input_add(HalDevice *usbd, di_node_t node)
546 {
547 	HalDevice *d = NULL;
548 	int	major;
549 	di_minor_t minor;
550 	dev_t	devt;
551 	char	*devlink = NULL;
552 	char	*minor_path = NULL;
553 	char	*minor_name = NULL;
554 	char	udi[HAL_PATH_MAX];
555 
556 	get_dev_link_path(node, "ddi_pseudo",
557 	    "^usb/hid[0-9]+",  &devlink, &minor_path, &minor_name);
558 
559 	if ((minor_path == NULL) || (devlink == NULL)) {
560 
561 		goto out;
562 	}
563 
564 	HAL_DEBUG(("devlink %s, minor_name %s", devlink, minor_name));
565 	if ((strcmp(minor_name, "keyboard") != 0) &&
566 	    (strcmp(minor_name, "mouse") != 0)) {
567 
568 		goto out;
569 	}
570 
571 	d = hal_device_new();
572 
573 	devinfo_set_default_properties(d, usbd, node, minor_path);
574 	hal_device_property_set_string(d, "info.subsystem", "input");
575 	hal_device_property_set_string(d, "info.category", "input");
576 
577 	hal_device_add_capability(d, "input");
578 
579 	if (strcmp(minor_name, "keyboard") == 0) {
580 		hal_device_add_capability(d, "input.keyboard");
581 		hal_device_add_capability(d, "input.keys");
582 		hal_device_add_capability(d, "button");
583 	} else if (strcmp(minor_name, "mouse") == 0) {
584 		hal_device_add_capability (d, "input.mouse");
585 	}
586 
587 	hal_device_property_set_string(d, "input.device", devlink);
588 	hal_device_property_set_string(d, "input.originating_device",
589 	    hal_device_get_udi(usbd));
590 
591 	hal_util_compute_udi(hald_get_gdl(), udi, sizeof (udi),
592 	    "%s_logicaldev_input", hal_device_get_udi(usbd));
593 
594 	hal_device_set_udi(d, udi);
595 	hal_device_property_set_string(d, "info.udi", udi);
596 
597 	if (strcmp(minor_name, "keyboard") == 0) {
598 		devinfo_add_enqueue(d, minor_path, &devinfo_usb_keyboard_handler);
599 	} else {
600 		devinfo_add_enqueue(d, minor_path, &devinfo_usb_handler);
601 	}
602 
603 	/* add to TDL so preprobing callouts and prober can access it */
604 	hal_device_store_add(hald_get_tdl(), d);
605 
606 out:
607 	if (devlink) {
608 		free(devlink);
609 	}
610 
611 	if (minor_path) {
612 		di_devfs_path_free(minor_path);
613 	}
614 
615 	return (d);
616 }
617 
618 static HalDevice *
devinfo_usb_scsa2usb_add(HalDevice * usbd,di_node_t node)619 devinfo_usb_scsa2usb_add(HalDevice *usbd, di_node_t node)
620 {
621 	HalDevice *d = NULL;
622 	di_devlink_handle_t devlink_hdl;
623 	int	major;
624 	di_minor_t minor;
625 	dev_t	devt;
626 	char	*minor_path = NULL;
627 	char	*minor_name = NULL;
628 	char	*devlink = NULL;
629 	char	udi[HAL_PATH_MAX];
630 
631 	get_dev_link_path(node, "ddi_ctl:devctl:scsi",
632 	    "^usb/mass-storage[0-9]+", &devlink, &minor_path, &minor_name);
633 
634 	if ((devlink == NULL) || (minor_path == NULL)) {
635 		goto out;
636 	}
637 
638 	d = hal_device_new ();
639 
640 	devinfo_set_default_properties (d, usbd, node, minor_path);
641 	hal_device_property_set_string (d, "scsi_host.solaris.device", devlink);
642 	hal_device_property_set_string (d, "info.category", "scsi_host");
643 	hal_device_property_set_int (d, "scsi_host.host", 0);
644 
645 	hal_util_compute_udi (hald_get_gdl (), udi, sizeof (udi),
646 	    "%s/scsi_host%d", hal_device_get_udi (usbd),
647 	    hal_device_property_get_int (d, "scsi_host.host"));
648 	hal_device_set_udi (d, udi);
649 	hal_device_property_set_string (d, "info.udi", udi);
650 	hal_device_property_set_string (d, "info.product", "SCSI Host Adapter");
651 
652 	devinfo_add_enqueue (d, minor_path, &devinfo_usb_handler);
653 
654 out:
655 	if (devlink) {
656 		free(devlink);
657 	}
658 	if (minor_path) {
659 		di_devfs_path_free (minor_path);
660 	}
661 
662 	return (d);
663 }
664 
665 static HalDevice *
devinfo_usb_printer_add(HalDevice * parent,di_node_t node)666 devinfo_usb_printer_add(HalDevice *parent, di_node_t node)
667 {
668 	char *properties[] = { "vendor", "product", "serial", NULL };
669 	int i;
670 	HalDevice *d = NULL;
671 	char	udi[HAL_PATH_MAX];
672 	char *s;
673 	char *devlink = NULL, *minor_path = NULL, *minor_name = NULL;
674 	const char	*subsystem;
675 
676 	get_dev_link_path(node, "ddi_printer", "printers/.+", &devlink, &minor_path, &minor_name);
677 
678 	if ((devlink == NULL) || (minor_path == NULL)) {
679 		goto out;
680 	}
681 
682 	d = hal_device_new ();
683 
684 	devinfo_set_default_properties (d, parent, node, minor_path);
685 	hal_device_property_set_string (d, "info.category", "printer");
686 	hal_device_add_capability (d, "printer");
687 
688 	/* add printer properties */
689 	hal_device_property_set_string (d, "printer.device", devlink);
690 
691 	/* copy parent's selected usb* properties to printer properties */
692 	subsystem = hal_device_property_get_string (parent, "info.subsystem");
693 	for (i = 0; properties[i] != NULL; i++) {
694 		char src[32], dst[32]; /* "subsystem.property" names */
695 
696 		snprintf(src, sizeof (src), "%s.%s", subsystem, properties[i]);
697 		snprintf(dst, sizeof (dst), "printer.%s", properties[i]);
698 		hal_device_copy_property(parent, src, d, dst);
699 	}
700 
701 	devinfo_add_enqueue (d, minor_path, &devinfo_usb_printer_handler);
702 
703 out:
704 	if (devlink) {
705 		free(devlink);
706 	}
707 	if (minor_path) {
708 		di_devfs_path_free (minor_path);
709 	}
710 
711 	return (d);
712 }
713 
714 const gchar *
devinfo_printer_prnio_get_prober(HalDevice * d,int * timeout)715 devinfo_printer_prnio_get_prober (HalDevice *d, int *timeout)
716 {
717 	*timeout = 5 * 1000;	/* 5 second timeout */
718 	return ("hald-probe-printer");
719 }
720 
721 const gchar *
devinfo_keyboard_get_prober(HalDevice * d,int * timeout)722 devinfo_keyboard_get_prober(HalDevice *d, int *timeout)
723 {
724 	*timeout = 5 * 1000;	/* 5 second timeout */
725 	return ("hald-probe-xkb");
726 }
727