[PATCH v2 6/5] usb: Add usb interface authorization: second SysFS part for usb interface authorization attribute.

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



To allow (1) or deny (0) interfaces a mask or interface attributes could written.
For interfaces that belongs together use the mask for authorization.
As default each bit has the initial value of the default authorization bit.
Entry: /sys/bus/usb/devices/*-*:*.*/interface_authorized

Signed-off-by: Stefan Koch <skoch@xxxxxxx>
---
 drivers/usb/core/sysfs.c | 55 ++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 55 insertions(+)

diff --git a/drivers/usb/core/sysfs.c b/drivers/usb/core/sysfs.c
index afa0799e..54e2e8e 100644
--- a/drivers/usb/core/sysfs.c
+++ b/drivers/usb/core/sysfs.c
@@ -995,6 +995,60 @@ static ssize_t supports_autosuspend_show(struct device *dev,
 }
 static DEVICE_ATTR_RO(supports_autosuspend);
 
+/*
+ * show authorization status of usb interface
+ * 1 is authorized, 0 is not authorized
+ */
+static ssize_t interface_authorized_show(struct device *dev,
+		struct device_attribute *attr, char *buf)
+{
+	struct usb_interface *intf = to_usb_interface(dev);
+
+	if (!intf)
+		return -ENODEV;
+
+	return sprintf(buf, "%u\n", intf->authorized);
+}
+
+/*
+ * 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);
+	struct usb_device *usb_pdev = NULL;
+	int rc = 0;
+	unsigned val = 0;
+	unsigned intf_nr = 0;
+	u32 mask = 0;
+
+	if (!dev->parent || !intf || !intf->cur_altsetting)
+		return -ENODEV;
+
+	usb_pdev = to_usb_device(dev->parent);
+
+	if (!usb_pdev)
+		return -ENODEV;
+
+	mask = usb_pdev->mask;
+	intf_nr = intf->cur_altsetting->desc.bInterfaceNumber;
+
+	if (sscanf(buf, "%u\n", &val) != 1)
+		return -EINVAL;
+
+	if (val == 0)
+		mask &= ~(1 << intf_nr);
+	else if (val == 1)
+		mask |= (1 << intf_nr);
+
+	rc = usb_device_set_mask(dev->parent, mask);
+
+	return rc < 0 ? rc : count;
+}
+static DEVICE_ATTR_RW(interface_authorized);
+
 static struct attribute *intf_attrs[] = {
 	&dev_attr_bInterfaceNumber.attr,
 	&dev_attr_bAlternateSetting.attr,
@@ -1004,6 +1058,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 majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html




[Index of Archives]     [Linux Media]     [Linux Input]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]     [Old Linux USB Devel Archive]

  Powered by Linux