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 <sk...@suse.de>
---
 drivers/usb/core/sysfs.c | 43 +++++++++++++++++++++++++++++++++++++++++--
 1 file changed, 41 insertions(+), 2 deletions(-)

diff --git a/drivers/usb/core/sysfs.c b/drivers/usb/core/sysfs.c
index d269738..b11105e 100644
--- a/drivers/usb/core/sysfs.c
+++ b/drivers/usb/core/sysfs.c
@@ -633,8 +633,6 @@ static ssize_t authorized_show(struct device *dev,
 
 /*
  * Authorize a device to be used in the system
- *
- * Writing a 0 deauthorizes the device, writing a 1 authorizes it.
  */
 static ssize_t authorized_store(struct device *dev,
                                struct device_attribute *attr, const char *buf,
@@ -926,6 +924,46 @@ static ssize_t supports_autosuspend_show(struct device 
*dev,
 }
 static DEVICE_ATTR_RO(supports_autosuspend);
 
+/*
+ * interface_authorized_show - show authorization status of an USB interface
+ * 1 is authorized, 0 is deauthorized
+ */
+static ssize_t interface_authorized_show(struct device *dev,
+               struct device_attribute *attr, char *buf)
+{
+       struct usb_interface *intf = to_usb_interface(dev);
+
+       return sprintf(buf, "%u\n", intf->authorized);
+}
+
+/*
+ * interface_authorized_store - authorize or deauthorize an USB interface
+ * 1 is to authorize, 0 is to deauthorize
+ */
+static ssize_t interface_authorized_store(struct device *dev,
+               struct device_attribute *attr, const char *buf, size_t count)
+{
+       struct usb_interface *intf = to_usb_interface(dev);
+       bool val;
+
+       if (strtobool(buf, &val) != 0)
+               return -EINVAL;
+
+       switch (val) {
+       case false:
+               usb_deauthorize_interface(intf);
+               break;
+       case true:
+               usb_authorize_interface(intf);
+               break;
+       }
+
+       return count;
+}
+static struct device_attribute dev_attr_interface_authorized =
+               __ATTR(authorized, S_IRUGO | S_IWUSR,
+               interface_authorized_show, interface_authorized_store);
+
 static struct attribute *intf_attrs[] = {
        &dev_attr_bInterfaceNumber.attr,
        &dev_attr_bAlternateSetting.attr,
@@ -935,6 +973,7 @@ static struct attribute *intf_attrs[] = {
        &dev_attr_bInterfaceProtocol.attr,
        &dev_attr_modalias.attr,
        &dev_attr_supports_autosuspend.attr,
+       &dev_attr_interface_authorized.attr,
        NULL,
 };
 static struct attribute_group intf_attr_grp = {
-- 
2.1.4

--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

Reply via email to