aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorInaky Perez-Gonzalez <inaky@linux.intel.com>2007-07-31 23:34:07 -0400
committerGreg Kroah-Hartman <gregkh@suse.de>2007-10-12 17:55:08 -0400
commite03f2e8a530e0ed46af43093e23a70b7c7215263 (patch)
tree69bc76da836e9953ab78c3aae22dac89fe7a21f8
parent93993a0a3e528357ae4b9b0eb82fd4b428ebbf64 (diff)
usb: hook up device authorization to sysfs
Makes it possible to control the authorization of USB devices through sysfs's /sys/usb/devices/*/authorize. Update: per Adrian Bunk's suggestion, make dev_attr_authorized_default static Signed-off-by: Inaky Perez-Gonzalez <inaky@linux.intel.com> Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
-rw-r--r--drivers/usb/core/sysfs.c39
1 files changed, 39 insertions, 0 deletions
diff --git a/drivers/usb/core/sysfs.c b/drivers/usb/core/sysfs.c
index 2ab222be8fd1..e02590297d31 100644
--- a/drivers/usb/core/sysfs.c
+++ b/drivers/usb/core/sysfs.c
@@ -413,6 +413,44 @@ usb_descriptor_attr(bDeviceProtocol, "%02x\n")
413usb_descriptor_attr(bNumConfigurations, "%d\n") 413usb_descriptor_attr(bNumConfigurations, "%d\n")
414usb_descriptor_attr(bMaxPacketSize0, "%d\n") 414usb_descriptor_attr(bMaxPacketSize0, "%d\n")
415 415
416
417
418/* show if the device is authorized (1) or not (0) */
419static ssize_t usb_dev_authorized_show(struct device *dev,
420 struct device_attribute *attr,
421 char *buf)
422{
423 struct usb_device *usb_dev = to_usb_device(dev);
424 return snprintf(buf, PAGE_SIZE, "%u\n", usb_dev->authorized);
425}
426
427
428/*
429 * Authorize a device to be used in the system
430 *
431 * Writing a 0 deauthorizes the device, writing a 1 authorizes it.
432 */
433static ssize_t usb_dev_authorized_store(struct device *dev,
434 struct device_attribute *attr,
435 const char *buf, size_t size)
436{
437 ssize_t result;
438 struct usb_device *usb_dev = to_usb_device(dev);
439 unsigned val;
440 result = sscanf(buf, "%u\n", &val);
441 if (result != 1)
442 result = -EINVAL;
443 else if (val == 0)
444 result = usb_deauthorize_device(usb_dev);
445 else
446 result = usb_authorize_device(usb_dev);
447 return result < 0? result : size;
448}
449
450static DEVICE_ATTR(authorized, 0644,
451 usb_dev_authorized_show, usb_dev_authorized_store);
452
453
416static struct attribute *dev_attrs[] = { 454static struct attribute *dev_attrs[] = {
417 /* current configuration's attributes */ 455 /* current configuration's attributes */
418 &dev_attr_configuration.attr, 456 &dev_attr_configuration.attr,
@@ -435,6 +473,7 @@ static struct attribute *dev_attrs[] = {
435 &dev_attr_version.attr, 473 &dev_attr_version.attr,
436 &dev_attr_maxchild.attr, 474 &dev_attr_maxchild.attr,
437 &dev_attr_quirks.attr, 475 &dev_attr_quirks.attr,
476 &dev_attr_authorized.attr,
438 NULL, 477 NULL,
439}; 478};
440static struct attribute_group dev_attr_grp = { 479static struct attribute_group dev_attr_grp = {