[PATCH 2/3] usb: gadgetfs: feature - delegate get descriptor

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

 



When this feature is enabled, all GET_DESCRIPTOR control requests
will not be handled by gadgetfs, but delegated to the user mode
driver for handling.

The feature is disabled when ep0 file is opened, and can be set via
ioctl, since when enabled, it breaks compatibility with older versions,
and will break user mode drivers that expect gedgetfs to handle
GET_DESCRIPTOR requests.
---
 drivers/usb/gadget/legacy/inode.c |  8 ++++++++
 include/uapi/linux/usb/gadgetfs.h | 10 ++++++++++
 2 files changed, 18 insertions(+)

diff --git a/drivers/usb/gadget/legacy/inode.c
b/drivers/usb/gadget/legacy/inode.c
index f54200d..f8a3e75 100644
--- a/drivers/usb/gadget/legacy/inode.c
+++ b/drivers/usb/gadget/legacy/inode.c
@@ -77,6 +77,7 @@ MODULE_LICENSE ("GPL");
 
 static int ep_open(struct inode *, struct file *);
 
+static bool feature_set(struct usb_gadgetfs_features *, unsigned int);
 
 /*----------------------------------------------------------------------*/
 
@@ -177,6 +178,8 @@ static struct dev_data *dev_new (void)
     spin_lock_init (&dev->lock);
     INIT_LIST_HEAD (&dev->epfiles);
     init_waitqueue_head (&dev->wait);
+    feature_set(&dev->supported_features,
+            GADGETFS_FEATURE_DELEGATE_DESCRIPTORS);
     return dev;
 }
 
@@ -1411,6 +1414,9 @@ gadgetfs_setup (struct usb_gadget *gadget, const
struct usb_ctrlrequest *ctrl)
     case USB_REQ_GET_DESCRIPTOR:
         if (ctrl->bRequestType != USB_DIR_IN)
             goto unrecognized;
+        if (is_feature_set(&dev->enabled_features,
+                    GADGETFS_FEATURE_DELEGATE_DESCRIPTORS))
+            goto delegate;
         switch (w_value >> 8) {
 
         case USB_DT_DEVICE:
@@ -1922,6 +1928,8 @@ dev_open (struct inode *inode, struct file *fd)
         dev->ev_next = 0;
         dev->state = STATE_DEV_OPENED;
         fd->private_data = dev;
+        feature_clear(&dev->enabled_features,
+                GADGETFS_FEATURE_DELEGATE_DESCRIPTORS);
         get_dev (dev);
         value = 0;
     }
diff --git a/include/uapi/linux/usb/gadgetfs.h
b/include/uapi/linux/usb/gadgetfs.h
index 9d304e0..c6f957e 100644
--- a/include/uapi/linux/usb/gadgetfs.h
+++ b/include/uapi/linux/usb/gadgetfs.h
@@ -87,6 +87,16 @@ struct usb_gadgetfs_event {
 
 
 
+/* Gadgetfs features */
+
+/*
+ * delegate all GET_DESCRIPTOR requests to user mode driver.
+ * enabling this feature means that the user mode driver must handle
+ * all GET_DEACRIPTOR requests.
+ */
+#define GADGETFS_FEATURE_DELEGATE_DESCRIPTORS    0
+
+
 struct usb_gadgetfs_features {
      uint64_t bitmap[4];
 };
-- 
2.5.0

-- 
Binyamin Sharet,
Cisco, STARE-C

--
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