Module Name:    src
Committed By:   msaitoh
Date:           Mon Nov 16 14:45:03 UTC 2015

Modified Files:
        src/sys/dev/usb [netbsd-7]: usb_subr.c

Log Message:
Pull up following revision(s) (requested by joerg in ticket #1032):
        sys/dev/usb/usb_subr.c: revision 1.204
Attach serial number as property to all USB devices having one.


To generate a diff of this commit:
cvs rdiff -u -r1.196 -r1.196.4.1 src/sys/dev/usb/usb_subr.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/dev/usb/usb_subr.c
diff -u src/sys/dev/usb/usb_subr.c:1.196 src/sys/dev/usb/usb_subr.c:1.196.4.1
--- src/sys/dev/usb/usb_subr.c:1.196	Mon Feb 17 07:34:21 2014
+++ src/sys/dev/usb/usb_subr.c	Mon Nov 16 14:45:03 2015
@@ -1,4 +1,4 @@
-/*	$NetBSD: usb_subr.c,v 1.196 2014/02/17 07:34:21 skrll Exp $	*/
+/*	$NetBSD: usb_subr.c,v 1.196.4.1 2015/11/16 14:45:03 msaitoh Exp $	*/
 /*	$FreeBSD: src/sys/dev/usb/usb_subr.c,v 1.18 1999/11/17 22:33:47 n_hibma Exp $	*/
 
 /*
@@ -32,7 +32,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: usb_subr.c,v 1.196 2014/02/17 07:34:21 skrll Exp $");
+__KERNEL_RCSID(0, "$NetBSD: usb_subr.c,v 1.196.4.1 2015/11/16 14:45:03 msaitoh Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_compat_netbsd.h"
@@ -828,6 +828,24 @@ usbd_attach_roothub(device_t parent, usb
 	return (USBD_NORMAL_COMPLETION);
 }
 
+static void
+usbd_serialnumber(device_t dv, usbd_device_handle dev)
+{
+	usb_device_descriptor_t *dd = &dev->ddesc;
+	char *serialnumber;
+
+	serialnumber = malloc(USB_MAX_ENCODED_STRING_LEN, M_USB, M_NOWAIT);
+	if (serialnumber == NULL)
+		return;
+	serialnumber[0] = '\0';
+	(void)usbd_get_string(dev, dd->iSerialNumber, serialnumber);
+	if (serialnumber[0]) {
+		prop_dictionary_set_cstring(device_properties(dv),
+		    "serialnumber", serialnumber);
+	}
+	free(serialnumber, M_USB);
+}
+
 static usbd_status
 usbd_attachwholedevice(device_t parent, usbd_device_handle dev, int port,
 	int usegeneric)
@@ -864,6 +882,7 @@ usbd_attachwholedevice(device_t parent, 
 		dev->subdevs[0] = dv;
 		dev->subdevlen = 1;
 		dev->nifaces_claimed = 1; /* XXX */
+		usbd_serialnumber(dv, dev);
 	}
 	return (USBD_NORMAL_COMPLETION);
 }
@@ -924,6 +943,9 @@ usbd_attachinterfaces(device_t parent, u
 					 usbd_ifprint, config_stdsubmatch);
 		if (!dv)
 			continue;
+
+		usbd_serialnumber(dv, dev);
+
 		ifaces[i] = 0; /* claim */
 		/* account for ifaces claimed by the driver behind our back */
 		for (j = 0; j < nifaces; j++) {

Reply via email to