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