Makes it possible to control the authorization of USB devices through sysfs's /sys/class/usb_dev/*/authorize.
Signed-off-by: Inaky Perez-Gonzalez <[EMAIL PROTECTED]> --- drivers/usb/core/devio.c | 64 +++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 62 insertions(+), 2 deletions(-) Index: linux.hg/drivers/usb/core/devio.c =================================================================== --- linux.hg.orig/drivers/usb/core/devio.c 2007-05-23 19:45:56.000000000 -0700 +++ linux.hg/drivers/usb/core/devio.c 2007-05-23 19:54:39.000000000 -0700 @@ -1592,8 +1592,62 @@ .release = usbdev_release, }; + +/* show if the device is authorized (1) or not (0) */ +static +ssize_t usb_dev_authorized_show(struct device *dev, + struct device_attribute *attr, + char *buf) +{ + struct usb_device *usb_dev = dev->platform_data; + return snprintf(buf, PAGE_SIZE, "%u\n", usb_dev->authorized); +} + + +/* + * Authorize a device to be used in the system + * + * Writing a 0 deauthorizes the device, writing a 1 authorizes it. + */ +static +ssize_t usb_dev_authorized_store(struct device *dev, + struct device_attribute *attr, + const char *buf, size_t size) +{ + ssize_t result; + struct usb_device *usb_dev = dev->platform_data; + unsigned val; + result = sscanf(buf, "%u\n", &val); + if (result != 1) + result = -EINVAL; + else if (val == 0) + result = usb_deauthorize_device(usb_dev); + else + result = usb_authorize_device(usb_dev); + return result < 0? result : size; +} + +DEVICE_ATTR(authorized, 0644, + usb_dev_authorized_show, usb_dev_authorized_store); + + +/* Group all the USB bus attributes */ +static +struct attribute *usb_dev_attrs[] = { + &dev_attr_authorized.attr, + NULL, +}; + +static +struct attribute_group usb_dev_attr_group = { + .name = NULL, /* we want them in the same directory */ + .attrs = usb_dev_attrs, +}; + + static int usbdev_add(struct usb_device *dev) { + int result; int minor = ((dev->bus->busnum-1) * 128) + (dev->devnum-1); dev->usbfs_dev = device_create(usb_device_class, &dev->dev, @@ -1601,13 +1655,19 @@ "usbdev%d.%d", dev->bus->busnum, dev->devnum); if (IS_ERR(dev->usbfs_dev)) return PTR_ERR(dev->usbfs_dev); - dev->usbfs_dev->platform_data = dev; - return 0; + result = sysfs_create_group(&dev->usbfs_dev->kobj, &usb_dev_attr_group); + if (result < 0) { + printk(KERN_ERR "Cannot register USB device attributes: %d\n", + result); + device_unregister(dev->usbfs_dev); + } + return result; } static void usbdev_remove(struct usb_device *dev) { + sysfs_remove_group(&dev->usbfs_dev->kobj, &usb_dev_attr_group); device_unregister(dev->usbfs_dev); } -- Inaky ------------------------------------------------------------------------- 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/ _______________________________________________ linux-usb-devel@lists.sourceforge.net To unsubscribe, use the last form field at: https://lists.sourceforge.net/lists/listinfo/linux-usb-devel