RFC/patch 2/6: wusb: unauth devices don't query descriptors

Inaky Perez-Gonzalez <[email protected]>
Newsgroups gmane.linux.usb.devel
Organization Intel Corporation
Message-ID <[email protected]>
# HG changeset patch
# User Inaky Perez-Gonzalez <[email protected]>
# Date 1177378641 25200
# Node ID 862192faf844ea7c9ed50e7b189019ef601324a2
# Parent  caf1be8549a3874d10978af31930b587566dd4f1
wusb: unauth devices don't query descriptors

This patch introduces 'struct usb_device'->wusb that is set to one for
WUSB devices.

When we have a WUSB device that is still not authorized, then we don't
read string descriptors and configuration descriptors, as that will be
rejected by the device.

Signed-off-by: Inaky Perez-Gonzalez <[email protected]>

diff -r caf1be8549a3 -r 862192faf844 drivers/usb/core/config.c
--- a/drivers/usb/core/config.c	Mon Apr 23 18:36:25 2007 -0700
+++ b/drivers/usb/core/config.c	Mon Apr 23 18:37:21 2007 -0700
@@ -429,8 +429,16 @@ void usb_destroy_configuration(struct us
 }
 
 
-// hub-only!! ... and only in reset path, or usb_new_device()
-// (used by real hubs and virtual root hubs)
+/*
+ * Get the USB config descriptors, cache and parse'em
+ *
+ * hub-only!! ... and only in reset path, or usb_new_device()
+ * (used by real hubs and virtual root hubs)
+ *
+ * NOTE: if this is a WUSB device and is not authorized, we skip the
+ *       whole thing. A non-authorized USB device has no
+ *       configurations. 
+ */
 int usb_get_configuration(struct usb_device *dev)
 {
 	struct device *ddev = &dev->dev;
@@ -467,7 +475,11 @@ int usb_get_configuration(struct usb_dev
 		goto err2;
 	desc = (struct usb_config_descriptor *)buffer;
 
-	for (cfgno = 0; cfgno < ncfg; cfgno++) {
+	cfgno = 0;
+	result = 0;
+	if (dev->wusb == 1 && dev->authorized == 0)
+		goto wusb_not_authorized;
+	for (; cfgno < ncfg; cfgno++) {
 		/* We grab just the first descriptor so we know how long
 		 * the whole configuration is */
 		result = usb_get_descriptor(dev, USB_DT_CONFIG, cfgno,
@@ -521,6 +533,7 @@ int usb_get_configuration(struct usb_dev
 
 err:
 	kfree(buffer);
+wusb_not_authorized:
 	dev->descriptor.bNumConfigurations = cfgno;
 err2:
 	if (result == -ENOMEM)
diff -r caf1be8549a3 -r 862192faf844 drivers/usb/core/hub.c
--- a/drivers/usb/core/hub.c	Mon Apr 23 18:36:25 2007 -0700
+++ b/drivers/usb/core/hub.c	Mon Apr 23 18:37:21 2007 -0700
@@ -1276,6 +1276,9 @@ static int __usb_port_suspend(struct usb
  * This call is synchronous, and may not be used in an interrupt context.
  *
  * Only the hub driver or root-hub registrar should ever call this.
+ *
+ * If the device is WUSB, we don't attempt to read the string
+ * descriptors, as they will be errored out by the device. 
  */
 int usb_new_device(struct usb_device *udev)
 {
@@ -1291,18 +1294,24 @@ int usb_new_device(struct usb_device *ud
 		goto fail;
 	}
 
-	/* read the standard strings and cache them if present */
-	udev->product = usb_cache_string(udev, udev->descriptor.iProduct);
-	udev->manufacturer = usb_cache_string(udev,
-			udev->descriptor.iManufacturer);
-	udev->serial = usb_cache_string(udev, udev->descriptor.iSerialNumber);
-
+	if (udev->wusb == 1 && udev->authorized == 0) {
+		/* read the standard strings and cache them if present */
+		udev->product = usb_cache_string(udev, udev->descriptor.iProduct);
+		udev->manufacturer = usb_cache_string(udev,
+						      udev->descriptor.iManufacturer);
+		udev->serial = usb_cache_string(udev, udev->descriptor.iSerialNumber);		
+	}
+	else {
+		udev->product = kstrdup("n/a (unauthorized)\n", GFP_KERNEL);
+		udev->manufacturer = kstrdup("n/a (unauthorized)\n", GFP_KERNEL);
+		udev->serial = kstrdup("n/a (unauthorized)\n", GFP_KERNEL);
+	}
 	/* Tell the world! */
 	dev_dbg(&udev->dev, "new device strings: Mfr=%d, Product=%d, "
-			"SerialNumber=%d\n",
-			udev->descriptor.iManufacturer,
-			udev->descriptor.iProduct,
-			udev->descriptor.iSerialNumber);
+		"SerialNumber=%d\n",
+		udev->descriptor.iManufacturer,
+		udev->descriptor.iProduct,
+		udev->descriptor.iSerialNumber);
 	show_string(udev, "Product", udev->product);
 	show_string(udev, "Manufacturer", udev->manufacturer);
 	show_string(udev, "SerialNumber", udev->serial);
@@ -1467,6 +1476,7 @@ static int hub_port_wait_reset(struct us
 			if (hub_is_wusb(hub)) {
 				udev->speed = USB_SPEED_VARIABLE;
  				udev->authorized = 0;
+ 				udev->wusb = 1;
 			}
 			else if (portstatus & USB_PORT_STAT_HIGH_SPEED)
 				udev->speed = USB_SPEED_HIGH;
diff -r caf1be8549a3 -r 862192faf844 include/linux/usb.h
--- a/include/linux/usb.h	Mon Apr 23 18:36:25 2007 -0700
+++ b/include/linux/usb.h	Mon Apr 23 18:37:21 2007 -0700
@@ -371,6 +371,7 @@ struct usb_device {
 	unsigned discon_suspended:1;	/* Disconnected while suspended */
 	unsigned have_langid:1;		/* whether string_langid is valid */
 	unsigned authorized:1;		/* Policy has determined we can use it */
+	unsigned wusb:1;		/* Device is Wireless USB */
 	int string_langid;		/* language ID for strings */
 
 	/* static strings from the device */

-------------------------------------------------------------------------
This SF.net email is sponsored by DB2 Express
Download DB2 Express C - the FREE version of DB2 express and take
control of your XML. No limits. Just data. Click to get it now.
http://sourceforge.net/powerbar/db2/
_______________________________________________
[email protected]
To unsubscribe, use the last form field at:
https://lists.sourceforge.net/lists/listinfo/linux-usb-devel
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.