On 08/24/2015 11:09 PM, Stefan Koch wrote:
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 <[email protected]>
---
  drivers/usb/core/sysfs.c | 36 ++++++++++++++++++++++++++++++++++++
  1 file changed, 36 insertions(+)

diff --git a/drivers/usb/core/sysfs.c b/drivers/usb/core/sysfs.c
index d269738..3ddaada 100644
--- a/drivers/usb/core/sysfs.c
+++ b/drivers/usb/core/sysfs.c
@@ -926,6 +926,41 @@ 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
+ */
+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;
+
+       if (val)
+               usb_authorize_interface(intf);
+       else
+               usb_deauthorize_interface(intf);
+
+       return count;
+}

shouldn't we return error if user tries to authorize interface which is already authorized an likewise when he is trying to deauthorize interface which is not autorized?

This is a little bit phylosophical if:

cat authorized > authorized

should fail or not.

--
Krzysztof Opasiak
Samsung R&D Institute Poland
Samsung Electronics
--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html

Reply via email to