RFC/patch 6/6: usb: add hooks up be able to authorize/deauthorize a device from sysfs
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 1177462041 25200 # Node ID 65c5954e4e34e3f7a965cd8e402cc61bd88cb305 # Parent 79751b058ef127578c4830644d575d8f474d2f43 usb: add hooks up be able to authorize/deauthorize a device from sysfs diff -r 79751b058ef1 -r 65c5954e4e34 drivers/usb/core/devio.c --- a/drivers/usb/core/devio.c Tue Apr 24 16:53:47 2007 -0700 +++ b/drivers/usb/core/devio.c Tue Apr 24 17:47:21 2007 -0700 @@ -1592,8 +1592,62 @@ const struct file_operations usbfs_devic .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 @@ static int usbdev_add(struct usb_device "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); } diff -r 79751b058ef1 -r 65c5954e4e34 drivers/usb/core/hub.c --- a/drivers/usb/core/hub.c Tue Apr 24 16:53:47 2007 -0700 +++ b/drivers/usb/core/hub.c Tue Apr 24 17:47:21 2007 -0700 @@ -1433,6 +1433,35 @@ fail: return err; } + +int usb_deauthorize_device(struct usb_device *usb_dev) +{ + struct device *dev = &usb_dev->dev; + dev_err(dev, "FIXME: %s not yet implemented\n", __FUNCTION__); + return -ENOSYS; + + /* +simply reset the device or just force unbinds? + */ +} + + +int usb_authorize_device(struct usb_device *usb_dev) +{ + struct device *dev = &usb_dev->dev; + dev_err(dev, "FIXME: %s not yet implemented\n", __FUNCTION__); + return -ENOSYS; + + /* + +free strings before getting new ones +verify we are not authorized already +Lock parent's hub or usb_bus_list_lock if RH + + */ +} + + static int hub_port_status(struct usb_hub *hub, int port1, u16 *status, u16 *change) { diff -r 79751b058ef1 -r 65c5954e4e34 drivers/usb/core/usb.h --- a/drivers/usb/core/usb.h Tue Apr 24 16:53:47 2007 -0700 +++ b/drivers/usb/core/usb.h Tue Apr 24 17:47:21 2007 -0700 @@ -13,6 +13,8 @@ extern void usb_disable_interface (struc struct usb_interface *intf); extern void usb_release_interface_cache(struct kref *ref); extern void usb_disable_device (struct usb_device *dev, int skip_ep0); +extern int usb_deauthorize_device (struct usb_device *); +extern int usb_authorize_device (struct usb_device *); extern void usb_detect_quirks(struct usb_device *udev); extern int usb_get_device_descriptor(struct usb_device *dev, ------------------------------------------------------------------------- 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