[PATCH v2 2/2] 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.

The feature availability is protected by Kconfig
USB_GADGETFS_ALLOW_DELEGATE_DESCRIPTOR (depends on EXPERT) so
that a user mode driver will not enable it by mistake.

Signed-off-by: Binyamin Sharet <bsharet@xxxxxxxxx>
---
 drivers/usb/gadget/legacy/Kconfig | 12 ++++++++++++
 drivers/usb/gadget/legacy/inode.c | 17 +++++++++++++++++
 include/uapi/linux/usb/gadgetfs.h |  5 +++++
 3 files changed, 34 insertions(+)

diff --git a/drivers/usb/gadget/legacy/Kconfig
b/drivers/usb/gadget/legacy/Kconfig
index 0b36878..bbedead 100644
--- a/drivers/usb/gadget/legacy/Kconfig
+++ b/drivers/usb/gadget/legacy/Kconfig
@@ -184,6 +184,18 @@ config USB_GADGETFS
       Say "y" to link the driver statically, or "m" to build a
       dynamically linked module called "gadgetfs".
 
+config USB_GADGETFS_ALLOW_DELEGATE_DESCRIPTORS
+    bool "Delegate get descriptor requests to user"
+    depends on USB_GADGETFS && EXPERT
+    default n
+    help
+      This feature allows to enable delegation of GET_DESCRIPTOR
+      requests in GadgetFS.
+      Enabling the request delegation is done through ioctl calls on
+      the control endpoint file descriptor. Once enabled, all
+      GET_DESCRIPTOR requests will be delegated to user mode, and will
+      not be handled by GadgetFS.
+
 config USB_FUNCTIONFS
     tristate "Function Filesystem"
     select USB_LIBCOMPOSITE
diff --git a/drivers/usb/gadget/legacy/inode.c
b/drivers/usb/gadget/legacy/inode.c
index ba2f6f4..b5ef210 100644
--- a/drivers/usb/gadget/legacy/inode.c
+++ b/drivers/usb/gadget/legacy/inode.c
@@ -182,6 +182,11 @@ static struct dev_data *dev_new (void)
     feature_set(&dev->supported_features,
             GADGETFS_FEATURE_FEATURES0_SUPPORTED);
 
+#ifdef CONFIG_USB_GADGETFS_ALLOW_DELEGATE_DESCRIPTORS
+    feature_set(&dev->supported_features,
+            GADGETFS_FEATURE_DELEGATE_DESCRIPTORS);
+#endif
+
     return dev;
 }
 
@@ -1461,6 +1466,13 @@ gadgetfs_setup (struct usb_gadget *gadget, const
struct usb_ctrlrequest *ctrl)
     case USB_REQ_GET_DESCRIPTOR:
         if (ctrl->bRequestType != USB_DIR_IN)
             goto unrecognized;
+
+#ifdef CONFIG_USB_GADGETFS_ALLOW_DELEGATE_DESCRIPTORS
+        if (feature_is_set(&dev->enabled_features,
+                    GADGETFS_FEATURE_DELEGATE_DESCRIPTORS))
+            goto delegate;
+#endif
+
         switch (w_value >> 8) {
 
         case USB_DT_DEVICE:
@@ -1975,6 +1987,11 @@ dev_open (struct inode *inode, struct file *fd)
         feature_set(&dev->enabled_features,
                 GADGETFS_FEATURE_FEATURES0_SUPPORTED);
 
+#ifdef CONFIG_USB_GADGETFS_ALLOW_DELEGATE_DESCRIPTORS
+        feature_clear(&dev->enabled_features,
+                GADGETFS_FEATURE_DELEGATE_DESCRIPTORS);
+#endif
+
         get_dev (dev);
         value = 0;
     }
diff --git a/include/uapi/linux/usb/gadgetfs.h
b/include/uapi/linux/usb/gadgetfs.h
index 3abe3d3..b72c13a 100644
--- a/include/uapi/linux/usb/gadgetfs.h
+++ b/include/uapi/linux/usb/gadgetfs.h
@@ -93,6 +93,11 @@ enum usb_gadgetfs_feature_bits {
      * This should always be on
      */
     GADGETFS_FEATURE_FEATURES0_SUPPORTED,
+    /* delegate all GET_DESCRIPTOR requests to user mode driver.
+     * enabling this feature means that the user mode driver must
+     * handle all GET_DEACRIPTOR requests.
+     */
+    GADGETFS_FEATURE_DELEGATE_DESCRIPTORS,
     /* reserved features.
      * any new feature should be added BEFORE this one.
      */
-- 
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