diff options
author | Stefan Koch <stefan.koch10@gmail.com> | 2015-08-25 15:10:09 -0400 |
---|---|---|
committer | Greg Kroah-Hartman <gregkh@linuxfoundation.org> | 2015-09-22 15:08:40 -0400 |
commit | 310d2b4124c073a2057ef9d952d4d938e9b1dfd9 (patch) | |
tree | ba1af5e7d6898c41eec055f741e372732bbdaacc | |
parent | b3910cef3968b2456cdd6c33b1f5e33904319f22 (diff) |
usb: interface authorization: SysFS part of USB interface authorization
This introduces an attribute for each interface to
authorize (1) or deauthorize (0) it:
/sys/bus/usb/devices/INTERFACE/authorized
Signed-off-by: Stefan Koch <stefan.koch10@gmail.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
-rw-r--r-- | drivers/usb/core/sysfs.c | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/drivers/usb/core/sysfs.c b/drivers/usb/core/sysfs.c index cfc68c11c3f5..d9ec2de6c4cf 100644 --- a/drivers/usb/core/sysfs.c +++ b/drivers/usb/core/sysfs.c | |||
@@ -957,6 +957,41 @@ static ssize_t supports_autosuspend_show(struct device *dev, | |||
957 | } | 957 | } |
958 | static DEVICE_ATTR_RO(supports_autosuspend); | 958 | static DEVICE_ATTR_RO(supports_autosuspend); |
959 | 959 | ||
960 | /* | ||
961 | * interface_authorized_show - show authorization status of an USB interface | ||
962 | * 1 is authorized, 0 is deauthorized | ||
963 | */ | ||
964 | static ssize_t interface_authorized_show(struct device *dev, | ||
965 | struct device_attribute *attr, char *buf) | ||
966 | { | ||
967 | struct usb_interface *intf = to_usb_interface(dev); | ||
968 | |||
969 | return sprintf(buf, "%u\n", intf->authorized); | ||
970 | } | ||
971 | |||
972 | /* | ||
973 | * interface_authorized_store - authorize or deauthorize an USB interface | ||
974 | */ | ||
975 | static ssize_t interface_authorized_store(struct device *dev, | ||
976 | struct device_attribute *attr, const char *buf, size_t count) | ||
977 | { | ||
978 | struct usb_interface *intf = to_usb_interface(dev); | ||
979 | bool val; | ||
980 | |||
981 | if (strtobool(buf, &val) != 0) | ||
982 | return -EINVAL; | ||
983 | |||
984 | if (val) | ||
985 | usb_authorize_interface(intf); | ||
986 | else | ||
987 | usb_deauthorize_interface(intf); | ||
988 | |||
989 | return count; | ||
990 | } | ||
991 | static struct device_attribute dev_attr_interface_authorized = | ||
992 | __ATTR(authorized, S_IRUGO | S_IWUSR, | ||
993 | interface_authorized_show, interface_authorized_store); | ||
994 | |||
960 | static struct attribute *intf_attrs[] = { | 995 | static struct attribute *intf_attrs[] = { |
961 | &dev_attr_bInterfaceNumber.attr, | 996 | &dev_attr_bInterfaceNumber.attr, |
962 | &dev_attr_bAlternateSetting.attr, | 997 | &dev_attr_bAlternateSetting.attr, |
@@ -966,6 +1001,7 @@ static struct attribute *intf_attrs[] = { | |||
966 | &dev_attr_bInterfaceProtocol.attr, | 1001 | &dev_attr_bInterfaceProtocol.attr, |
967 | &dev_attr_modalias.attr, | 1002 | &dev_attr_modalias.attr, |
968 | &dev_attr_supports_autosuspend.attr, | 1003 | &dev_attr_supports_autosuspend.attr, |
1004 | &dev_attr_interface_authorized.attr, | ||
969 | NULL, | 1005 | NULL, |
970 | }; | 1006 | }; |
971 | static struct attribute_group intf_attr_grp = { | 1007 | static struct attribute_group intf_attr_grp = { |