usb: gadget: f_fs: add capability for dfu run-time descriptor
RFC 1/1 usb: gadget: f_fs: add capability for dfu run-time descriptor
Add the ability for FunctionFS driver to be able to create DFU Run-Time descriptors.
Signed-off-by David Sands <[email protected]>
--- drivers/usb/gadget/function/f_fs.c | 12 ++++++++++-- include/uapi/linux/usb/ch9.h | 4 ++++ include/uapi/linux/usb/functionfs.h | 10 ++++++++++ 3 files changed, 24 insertions(+), 2 deletions(-)
drivers/usb/gadget/function/f_fs.c +10 -2
@@ -2049,7 +2049,7 @@ typedef int (*ffs_os_desc_callback)(enum ffs_os_desc_type entity,static int __must_check ffs_do_single_desc (char *data,unsigned len,ffs_entity_callback entity, -void *priv,int *current_class) +void *priv,int *current_class,int *current_subclass) {struct usb_descriptor_header *_ds = (void *)data;u8 length;
@@ -2108,6 +2108,7 @@ static int __must_check ffs_do_single_desc(char *data, unsigned len,if (ds->iInterface)__entity (STRING , ds->iInterface); *current_class = ds->bInterfaceClass; + *current_subclass = ds->bInterfaceSubClass; }break ;
@@ -2132,6 +2133,12 @@ static int __must_check ffs_do_single_desc(char *data, unsigned len,if (length !=sizeof (struct ccid_descriptor )) goto inv_length;break ; + }else if (*current_class ==USB_CLASS_APP_SPEC && + *current_subclass ==USB_SUBCLASS_DFU ) { +pr_vdebug ("dfu functional descriptor\n" ); +if (length !=sizeof (struct usb_dfu_functional_descriptor )) + goto inv_length; +break ; }else {pr_vdebug ("unknown descriptor: %d for class %d\n" , _ds->bDescriptorType, *current_class);
@@ -2194,6 +2201,7 @@ static int __must_check ffs_do_descs(unsigned count, char *data, unsigned len,const unsigned _len = len;unsigned long num =0 ;int current_class =-1 ; +int current_subclass =-1 ;ENTER ();
@@ -2215,7 +2223,7 @@ static int __must_check ffs_do_descs(unsigned count, char *data, unsigned len,return _len - len; ret =ffs_do_single_desc (data, len, entity, priv, - ¤t_class); + ¤t_class, ¤t_subclass);if (ret <0 ) {pr_debug ("%s returns %d\n" , __func__, ret);return ret;
include/uapi/linux/usb/ch9.h +4 -0
@@ -266,6 +266,9 @@ struct usb_ctrlrequest {/* From the USB 3.1 spec */ #define USB_DT_SSP_ISOC_ENDPOINT_COMP 0x31 +/* From USB Device Firmware Upgrade Specification, Revision 1.1 */ +#define USB_DT_DFU_FUNCTIONAL 0x21 +/* Conventional codes for class-specific descriptors. The convention is * defined in the USB "Common Class" Spec (3.11). Individual class specs * are authoritative for their usage, not the "common class" writeup.
@@ -335,6 +338,7 @@ struct usb_device_descriptor {#define USB_CLASS_VENDOR_SPEC 0xff#define USB_SUBCLASS_VENDOR_SPEC 0xff +#define USB_SUBCLASS_DFU 0x01/*-------------------------------------------------------------------------*/
include/uapi/linux/usb/functionfs.h +10 -0
@@ -37,6 +37,16 @@ struct usb_endpoint_descriptor_no_audio {__u8 bInterval; } __attribute__((packed)); +/* DFU Functional descriptor */ +struct usb_dfu_functional_descriptor { +__u8 bLength; +__u8 bDescriptorType; +__u8 bmAttributes; +__le16 wDetachTimeOut; +__le16 wTransferSize; +__le16 bcdDFUVersion; +} __attribute__ ((packed)); +struct usb_functionfs_descs_head_v2 {__le32 magic;__le32 length;
Signature · 1 line
2.34.1
Greg KH
maintainerQuoted 9 lines · David Sands
Add the ability for FunctionFS driver to be able to create DFU Run-Time descriptors.
Signed-off-by David Sands <[email protected]>--- drivers/usb/gadget/function/f_fs.c | 12 ++++++++++-- include/uapi/linux/usb/ch9.h | 4 ++++ include/uapi/linux/usb/functionfs.h | 10 ++++++++++ 3 files changed, 24 insertions(+), 2 deletions(-)
Ah, DFU, bad memories (hint, my name is on that spec...)
Why is this a RFC? What needs to be done on this to make it "real"?
Quoted 79 lines
drivers/usb/gadget/function/f_fs.c +10
-2@@ -2049,7 +2049,7 @@ typedef int (*ffs_os_desc_callback)(enum ffs_os_desc_type entity,static int __must_check ffs_do_single_desc (char *data,unsigned len,ffs_entity_callback entity, -void *priv,int *current_class) +void *priv,int *current_class,int *current_subclass) {struct usb_descriptor_header *_ds = (void *)data;u8 length;@@ -2108,6 +2108,7 @@ static int __must_check ffs_do_single_desc(char *data, unsigned len,if (ds->iInterface)__entity (STRING , ds->iInterface); *current_class = ds->bInterfaceClass; + *current_subclass = ds->bInterfaceSubClass; }break ;@@ -2132,6 +2133,12 @@ static int __must_check ffs_do_single_desc(char *data, unsigned len,if (length !=sizeof (struct ccid_descriptor )) goto inv_length;break ; + }else if (*current_class ==USB_CLASS_APP_SPEC && + *current_subclass ==USB_SUBCLASS_DFU ) { +pr_vdebug ("dfu functional descriptor\n" ); +if (length !=sizeof (struct usb_dfu_functional_descriptor )) + goto inv_length; +break ; }else {pr_vdebug ("unknown descriptor: %d for class %d\n" , _ds->bDescriptorType, *current_class);@@ -2194,6 +2201,7 @@ static int __must_check ffs_do_descs(unsigned count, char *data, unsigned len,const unsigned _len = len;unsigned long num =0 ;int current_class =-1 ; +int current_subclass =-1 ;ENTER ();@@ -2215,7 +2223,7 @@ static int __must_check ffs_do_descs(unsigned count, char *data, unsigned len,return _len - len; ret =ffs_do_single_desc (data, len, entity, priv, - ¤t_class); + ¤t_class, ¤t_subclass);if (ret <0 ) {pr_debug ("%s returns %d\n" , __func__, ret);return ret;include/uapi/linux/usb/ch9.h +4
-0@@ -266,6 +266,9 @@ struct usb_ctrlrequest {/* From the USB 3.1 spec */ #define USB_DT_SSP_ISOC_ENDPOINT_COMP 0x31 +/* From USB Device Firmware Upgrade Specification, Revision 1.1 */ +#define USB_DT_DFU_FUNCTIONAL 0x21 +/* Conventional codes for class-specific descriptors. The convention is * defined in the USB "Common Class" Spec (3.11). Individual class specs * are authoritative for their usage, not the "common class" writeup. @@ -335,6 +338,7 @@ struct usb_device_descriptor {#define USB_CLASS_VENDOR_SPEC 0xff#define USB_SUBCLASS_VENDOR_SPEC 0xff +#define USB_SUBCLASS_DFU 0x01/*-------------------------------------------------------------------------*/ include/uapi/linux/usb/functionfs.h +0
-0
include/uapi/linux/usb/functionfs.h struct usb_endpoint_descriptor_no_audio { · line 44
Quoted 8 lines
include/uapi/linux/usb/functionfs.h +5
-0@@ -37,6 +37,16 @@ struct usb_endpoint_descriptor_no_audio {__u8 bInterval; } __attribute__((packed)); +/* DFU Functional descriptor */ +struct usb_dfu_functional_descriptor { +__u8 bLength; +__u8 bDescriptorType; +__u8 bmAttributes;
Did you forget bEndpointAddress?
I can't remember if that is needed or not, but without it, it's an odd layout of this structure.
thanks,
greg k-h