[PATCH 1/2] usb: Add support for indicating port visibility

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

 



Userspace may want to make policy decisions based on whether or not a
given USB port is externally visible. Add a per-device member and support
for exposing it in sysfs. Information sources to populate it will be
added later.

Signed-off-by: Matthew Garrett <mjg@xxxxxxxxxx>
---
 drivers/usb/core/sysfs.c |   23 +++++++++++++++++++++++
 include/linux/usb.h      |    8 ++++++++
 2 files changed, 31 insertions(+), 0 deletions(-)

diff --git a/drivers/usb/core/sysfs.c b/drivers/usb/core/sysfs.c
index cf05b97..de7ecb8 100644
--- a/drivers/usb/core/sysfs.c
+++ b/drivers/usb/core/sysfs.c
@@ -230,6 +230,28 @@ show_urbnum(struct device *dev, struct device_attribute *attr, char *buf)
 }
 static DEVICE_ATTR(urbnum, S_IRUGO, show_urbnum, NULL);
 
+static ssize_t
+show_visibility(struct device *dev, struct device_attribute *attr, char *buf)
+{
+	struct usb_device *udev;
+	char *state;
+
+	udev = to_usb_device(dev);
+
+	switch (udev->visible) {
+	case USB_DEVICE_VISIBILITY_VISIBLE:
+		state = "visible";
+		break;
+	case USB_DEVICE_VISIBILITY_HIDDEN:
+		state = "hidden";
+		break;
+	default:
+		state = "unknown";
+	}
+
+	return sprintf(buf, "%s\n", state);
+}
+static DEVICE_ATTR(visibility, S_IRUGO, show_visibility, NULL);
 
 #ifdef	CONFIG_PM
 
@@ -569,6 +591,7 @@ static struct attribute *dev_attrs[] = {
 	&dev_attr_avoid_reset_quirk.attr,
 	&dev_attr_authorized.attr,
 	&dev_attr_remove.attr,
+	&dev_attr_visibility.attr,
 	NULL,
 };
 static struct attribute_group dev_attr_grp = {
diff --git a/include/linux/usb.h b/include/linux/usb.h
index 73c7df4..57f50ff 100644
--- a/include/linux/usb.h
+++ b/include/linux/usb.h
@@ -366,6 +366,12 @@ struct usb_bus {
 
 struct usb_tt;
 
+enum usb_device_visibility {
+	USB_DEVICE_VISIBILITY_UNKNOWN = 0,
+	USB_DEVICE_VISIBILITY_VISIBLE,
+	USB_DEVICE_VISIBILITY_HIDDEN,
+};
+
 /**
  * struct usb_device - kernel's representation of a USB device
  * @devnum: device number; address on a USB bus
@@ -418,6 +424,7 @@ struct usb_tt;
  * @wusb_dev: if this is a Wireless USB device, link to the WUSB
  *	specific data for the device.
  * @slot_id: Slot ID assigned by xHCI
+ * @visible: Externally available port
  *
  * Notes:
  * Usbcore drivers should not set usbdev->state directly.  Instead use
@@ -491,6 +498,7 @@ struct usb_device {
 #endif
 	struct wusb_dev *wusb_dev;
 	int slot_id;
+	enum usb_device_visibility visible;
 };
 #define	to_usb_device(d) container_of(d, struct usb_device, dev)
 
-- 
1.7.6.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