usb: Fix issue with the calculation descriptor length error
Signed-off-by: yangsong8 <yangsong8@xiaomi.com>
This commit is contained in:
parent
366ede9530
commit
0beceeb745
|
@ -338,7 +338,9 @@ int cdcacm_copy_epdesc(enum cdcacm_epdesc_e epid,
|
|||
#endif
|
||||
|
||||
#ifdef CONFIG_USBDEV_SUPERSPEED
|
||||
if (speed == USB_SPEED_SUPER || speed == USB_SPEED_SUPER_PLUS)
|
||||
if (speed == USB_SPEED_SUPER ||
|
||||
speed == USB_SPEED_SUPER_PLUS ||
|
||||
speed == USB_SPEED_UNKNOWN)
|
||||
{
|
||||
len += sizeof(struct usb_ss_epcompdesc_s);
|
||||
}
|
||||
|
|
|
@ -1247,7 +1247,9 @@ static int cdcecm_mkepdesc(int epidx,
|
|||
int len = sizeof(struct usb_epdesc_s);
|
||||
|
||||
#ifdef CONFIG_USBDEV_SUPERSPEED
|
||||
if (speed == USB_SPEED_SUPER || speed == USB_SPEED_SUPER_PLUS)
|
||||
if (speed == USB_SPEED_SUPER ||
|
||||
speed == USB_SPEED_SUPER_PLUS ||
|
||||
speed == USB_SPEED_UNKNOWN)
|
||||
{
|
||||
/* Maximum packet size (super speed) */
|
||||
|
||||
|
@ -1341,7 +1343,9 @@ static int16_t cdcecm_mkcfgdesc(FAR uint8_t *desc,
|
|||
FAR struct usbdev_devinfo_s *devinfo,
|
||||
uint8_t speed, uint8_t type)
|
||||
{
|
||||
#ifndef CONFIG_CDCECM_COMPOSITE
|
||||
FAR struct usb_cfgdesc_s *cfgdesc = NULL;
|
||||
#endif
|
||||
int16_t len = 0;
|
||||
int ret;
|
||||
|
||||
|
@ -1542,11 +1546,13 @@ static int16_t cdcecm_mkcfgdesc(FAR uint8_t *desc,
|
|||
|
||||
len += ret;
|
||||
|
||||
#ifndef CONFIG_CDCECM_COMPOSITE
|
||||
if (cfgdesc)
|
||||
{
|
||||
cfgdesc->totallen[0] = LSBYTE(len);
|
||||
cfgdesc->totallen[1] = MSBYTE(len);
|
||||
}
|
||||
#endif
|
||||
|
||||
DEBUGASSERT(len <= CDCECM_MXDESCLEN);
|
||||
return len;
|
||||
|
|
|
@ -2017,7 +2017,9 @@ static int cdcncm_mkepdesc(int epidx, FAR struct usb_epdesc_s *epdesc,
|
|||
int len = sizeof(struct usb_epdesc_s);
|
||||
|
||||
#ifdef CONFIG_USBDEV_SUPERSPEED
|
||||
if (speed == USB_SPEED_SUPER || speed == USB_SPEED_SUPER_PLUS)
|
||||
if (speed == USB_SPEED_SUPER ||
|
||||
speed == USB_SPEED_SUPER_PLUS ||
|
||||
speed == USB_SPEED_UNKNOWN)
|
||||
{
|
||||
/* Maximum packet size (super speed) */
|
||||
|
||||
|
@ -2111,7 +2113,9 @@ static int16_t cdcnm_mkcfgdesc(FAR uint8_t *desc,
|
|||
FAR struct usbdev_devinfo_s *devinfo,
|
||||
uint8_t speed, uint8_t type, bool isncm)
|
||||
{
|
||||
#ifndef CONFIG_CDCNCM_COMPOSITE
|
||||
FAR struct usb_cfgdesc_s *cfgdesc = NULL;
|
||||
#endif
|
||||
int16_t len = 0;
|
||||
int ret;
|
||||
|
||||
|
@ -2360,11 +2364,13 @@ static int16_t cdcnm_mkcfgdesc(FAR uint8_t *desc,
|
|||
|
||||
len += ret;
|
||||
|
||||
#ifndef CONFIG_CDCNCM_COMPOSITE
|
||||
if (cfgdesc)
|
||||
{
|
||||
cfgdesc->totallen[0] = LSBYTE(len);
|
||||
cfgdesc->totallen[1] = MSBYTE(len);
|
||||
}
|
||||
#endif
|
||||
|
||||
DEBUGASSERT(len <= CDCECM_MXDESCLEN);
|
||||
return len;
|
||||
|
|
|
@ -137,7 +137,9 @@ int usbdev_copy_epdesc(FAR struct usb_epdesc_s *epdesc,
|
|||
int len = sizeof(struct usb_epdesc_s);
|
||||
|
||||
#ifdef CONFIG_USBDEV_SUPERSPEED
|
||||
if (speed == USB_SPEED_SUPER || speed == USB_SPEED_SUPER_PLUS)
|
||||
if (speed == USB_SPEED_SUPER ||
|
||||
speed == USB_SPEED_SUPER_PLUS ||
|
||||
speed == USB_SPEED_UNKNOWN)
|
||||
{
|
||||
len += sizeof(struct usb_ss_epcompdesc_s);
|
||||
}
|
||||
|
|
|
@ -309,15 +309,14 @@
|
|||
|
||||
/* Configuration descriptor size */
|
||||
|
||||
#ifndef CONFIG_USBMSC_COMPOSITE
|
||||
|
||||
/* The size of the config descriptor: (9 + 9 + 2*7) = 32 */
|
||||
#if defined(CONFIG_USBDEV_COMPOSITE) && defined(CONFIG_USBMSC_COMPOSITE)
|
||||
/* The size of the config descriptor: (9 + 2*7 + 2*6) = 35 */
|
||||
|
||||
# define SIZEOF_USBMSC_CFGDESC \
|
||||
(USB_SIZEOF_CFGDESC + USB_SIZEOF_IFDESC + USBMSC_NENDPOINTS * USB_SIZEOF_EPDESC)
|
||||
(USB_SIZEOF_IFDESC + USBMSC_NENDPOINTS * USB_SIZEOF_EPDESC + \
|
||||
USBMSC_NENDPOINTS * USB_SIZEOF_SS_EPCOMPDESC)
|
||||
|
||||
#else
|
||||
|
||||
/* The size of the config descriptor: (9 + 2*7) = 23 */
|
||||
|
||||
# define SIZEOF_USBMSC_CFGDESC \
|
||||
|
|
|
@ -404,12 +404,15 @@ int16_t usbmsc_mkcfgdesc(uint8_t *buf,
|
|||
FAR struct usbdev_devinfo_s *devinfo,
|
||||
uint8_t speed, uint8_t type)
|
||||
{
|
||||
#ifndef CONFIG_USBMSC_COMPOSITE
|
||||
FAR struct usb_cfgdesc_s *cfgdesc = NULL;
|
||||
#endif
|
||||
int16_t totallen = 0;
|
||||
int ret;
|
||||
|
||||
/* Check for switches between high and full speed */
|
||||
|
||||
if (type == USB_DESC_TYPE_OTHERSPEEDCONFIG && speed != USB_SPEED_HIGH)
|
||||
if (type == USB_DESC_TYPE_OTHERSPEEDCONFIG && speed < USB_SPEED_SUPER)
|
||||
{
|
||||
speed = speed == USB_SPEED_HIGH ? USB_SPEED_FULL : USB_SPEED_HIGH;
|
||||
}
|
||||
|
@ -422,75 +425,73 @@ int16_t usbmsc_mkcfgdesc(uint8_t *buf,
|
|||
*/
|
||||
|
||||
#ifndef CONFIG_USBMSC_COMPOSITE
|
||||
{
|
||||
/* Configuration descriptor If the USB mass storage device is
|
||||
* configured as part of a composite device, then the configuration
|
||||
* descriptor will be provided by the composite device logic.
|
||||
*/
|
||||
/* Configuration descriptor If the USB mass storage device is
|
||||
* configured as part of a composite device, then the configuration
|
||||
* descriptor will be provided by the composite device logic.
|
||||
*/
|
||||
|
||||
FAR struct usb_cfgdesc_s *dest = (FAR struct usb_cfgdesc_s *)buf;
|
||||
cfgdesc = (FAR struct usb_cfgdesc_s *)buf;
|
||||
|
||||
dest->len = USB_SIZEOF_CFGDESC; /* Descriptor length */
|
||||
dest->type = type; /* Descriptor type */
|
||||
dest->totallen[0] = LSBYTE(SIZEOF_USBMSC_CFGDESC); /* LS Total length */
|
||||
dest->totallen[1] = MSBYTE(SIZEOF_USBMSC_CFGDESC); /* MS Total length */
|
||||
dest->ninterfaces = USBMSC_NINTERFACES; /* Number of interfaces */
|
||||
dest->cfgvalue = USBMSC_CONFIGID; /* Configuration value */
|
||||
dest->icfg = USBMSC_CONFIGSTRID; /* Configuration */
|
||||
dest->attr = USB_CONFIG_ATTR_ONE | /* Attributes */
|
||||
USBMSC_SELFPOWERED |
|
||||
USBMSC_REMOTEWAKEUP;
|
||||
dest->mxpower = (CONFIG_USBDEV_MAXPOWER + 1) / 2; /* Max power (mA/2) */
|
||||
cfgdesc->len = USB_SIZEOF_CFGDESC; /* Descriptor length */
|
||||
cfgdesc->type = type; /* Descriptor type */
|
||||
cfgdesc->ninterfaces = USBMSC_NINTERFACES; /* Number of interfaces */
|
||||
cfgdesc->cfgvalue = USBMSC_CONFIGID; /* Configuration value */
|
||||
cfgdesc->icfg = USBMSC_CONFIGSTRID; /* Configuration */
|
||||
cfgdesc->attr = USB_CONFIG_ATTR_ONE | /* Attributes */
|
||||
USBMSC_SELFPOWERED |
|
||||
USBMSC_REMOTEWAKEUP;
|
||||
cfgdesc->mxpower = (CONFIG_USBDEV_MAXPOWER + 1) / 2; /* Max power (mA/2) */
|
||||
|
||||
buf += sizeof(struct usb_cfgdesc_s);
|
||||
totallen += sizeof(struct usb_cfgdesc_s);
|
||||
}
|
||||
buf += sizeof(struct usb_cfgdesc_s);
|
||||
totallen += sizeof(struct usb_cfgdesc_s);
|
||||
#endif
|
||||
|
||||
/* Copy the canned interface descriptor */
|
||||
|
||||
{
|
||||
/* Single interface descriptor */
|
||||
/* Single interface descriptor */
|
||||
|
||||
FAR struct usb_ifdesc_s * dest = (struct usb_ifdesc_s *)buf;
|
||||
FAR struct usb_ifdesc_s * dest = (struct usb_ifdesc_s *)buf;
|
||||
|
||||
dest->len = USB_SIZEOF_IFDESC; /* Descriptor length */
|
||||
dest->type = USB_DESC_TYPE_INTERFACE; /* Descriptor type */
|
||||
dest->ifno = devinfo->ifnobase; /* Interface number */
|
||||
dest->alt = USBMSC_ALTINTERFACEID; /* Alternate setting */
|
||||
dest->neps = USBMSC_NENDPOINTS; /* Number of endpoints */
|
||||
dest->classid = USB_CLASS_MASS_STORAGE; /* Interface class */
|
||||
dest->subclass = USBMSC_SUBCLASS_SCSI; /* Interface sub-class */
|
||||
dest->protocol = USBMSC_PROTO_BULKONLY; /* Interface protocol */
|
||||
dest->iif = devinfo->strbase + USBMSC_INTERFACESTRID; /* iInterface */
|
||||
dest->len = USB_SIZEOF_IFDESC; /* Descriptor length */
|
||||
dest->type = USB_DESC_TYPE_INTERFACE; /* Descriptor type */
|
||||
dest->ifno = devinfo->ifnobase; /* Interface number */
|
||||
dest->alt = USBMSC_ALTINTERFACEID; /* Alternate setting */
|
||||
dest->neps = USBMSC_NENDPOINTS; /* Number of endpoints */
|
||||
dest->classid = USB_CLASS_MASS_STORAGE; /* Interface class */
|
||||
dest->subclass = USBMSC_SUBCLASS_SCSI; /* Interface sub-class */
|
||||
dest->protocol = USBMSC_PROTO_BULKONLY; /* Interface protocol */
|
||||
dest->iif = devinfo->strbase + USBMSC_INTERFACESTRID; /* iInterface */
|
||||
|
||||
buf += sizeof(struct usb_ifdesc_s);
|
||||
totallen += sizeof(struct usb_ifdesc_s);
|
||||
}
|
||||
buf += sizeof(struct usb_ifdesc_s);
|
||||
totallen += sizeof(struct usb_ifdesc_s);
|
||||
|
||||
/* Make the two endpoint configurations */
|
||||
|
||||
/* Bulk IN endpoint descriptor */
|
||||
|
||||
{
|
||||
ret = usbmsc_copy_epdesc(USBMSC_EPBULKIN,
|
||||
(FAR struct usb_epdesc_s *)buf,
|
||||
devinfo, speed);
|
||||
ret = usbmsc_copy_epdesc(USBMSC_EPBULKIN,
|
||||
(FAR struct usb_epdesc_s *)buf,
|
||||
devinfo, speed);
|
||||
|
||||
buf += ret;
|
||||
totallen += ret;
|
||||
}
|
||||
buf += ret;
|
||||
totallen += ret;
|
||||
|
||||
/* Bulk OUT endpoint descriptor */
|
||||
|
||||
{
|
||||
ret = usbmsc_copy_epdesc(USBMSC_EPBULKOUT,
|
||||
(FAR struct usb_epdesc_s *)buf, devinfo,
|
||||
speed);
|
||||
ret = usbmsc_copy_epdesc(USBMSC_EPBULKOUT,
|
||||
(FAR struct usb_epdesc_s *)buf,
|
||||
devinfo, speed);
|
||||
|
||||
buf += ret;
|
||||
totallen += ret;
|
||||
buf += ret;
|
||||
totallen += ret;
|
||||
|
||||
#ifndef CONFIG_USBMSC_COMPOSITE
|
||||
if (cfgdesc)
|
||||
{
|
||||
cfgdesc->totallen[0] = LSBYTE(totallen);
|
||||
cfgdesc->totallen[1] = MSBYTE(totallen);
|
||||
}
|
||||
#endif
|
||||
|
||||
return totallen;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue