Fix USB issues

Author: Alan Carvalho de Assis <acassis@gmail.com>

    Run nxstyle on .c and .h files and fix it

Author: Alin Jerpelea <alin.jerpelea@sony.com>

    drivers: usbdev: minor fix

    drivers: usbdev: usbmsc full speed not available

      Change transfer size to be based on maxpacket size.

    drivers: usbdev: Fix string ID calculation

      For *_STRBASE defines, it already unnecessary because composite device setup
      has been changed, it would be calculated by *_composite.c in board sources.

    drivers: usbdev: Fix invalid/unsupported command processing

      Mass Storage Class shall stall when invalid or unsupported commands
      has been recieved.

    drivers: usbdev: Remove unnecessary reset logic

    drivers: usbdev: Flags comparison fix

    drivers: usbdev: Descriptor type mismatch fix when dual speed is enabled
This commit is contained in:
Alin Jerpelea
2020-01-10 12:06:36 -03:00
committed by Alan Carvalho de Assis
parent 29d3ed2ec1
commit 275f4baf9f
8 changed files with 348 additions and 264 deletions

View File

@@ -593,10 +593,10 @@ static int cdcacm_recvpacket(FAR struct cdcacm_dev_s *priv,
* control when there are no watermarks. * control when there are no watermarks.
*/ */
if (nexthead == recv->tail) if (nexthead == recv->tail)
{ {
cdcuart_rxflowcontrol(&priv->serdev, recv->size - 1, true); cdcuart_rxflowcontrol(&priv->serdev, recv->size - 1, true);
} }
#endif #endif
/* If data was added to the incoming serial buffer, then wake up any /* If data was added to the incoming serial buffer, then wake up any
@@ -918,6 +918,7 @@ static int cdcacm_serialstate(FAR struct cdcacm_dev_s *priv)
} }
errout_with_flags: errout_with_flags:
/* Reset all of the "irregular" notification */ /* Reset all of the "irregular" notification */
priv->serialstate &= CDC_UART_CONSISTENT; priv->serialstate &= CDC_UART_CONSISTENT;
@@ -1177,7 +1178,7 @@ static void cdcacm_rdcomplete(FAR struct usbdev_ep_s *ep,
{ {
usbtrace(TRACE_CLSERROR(USBSER_TRACEERR_INVALIDARG), 0); usbtrace(TRACE_CLSERROR(USBSER_TRACEERR_INVALIDARG), 0);
return; return;
} }
#endif #endif
/* Extract references to private data */ /* Extract references to private data */
@@ -1253,7 +1254,7 @@ static void cdcacm_wrcomplete(FAR struct usbdev_ep_s *ep,
{ {
usbtrace(TRACE_CLSERROR(USBSER_TRACEERR_INVALIDARG), 0); usbtrace(TRACE_CLSERROR(USBSER_TRACEERR_INVALIDARG), 0);
return; return;
} }
#endif #endif
/* Extract references to our private data */ /* Extract references to our private data */
@@ -1502,7 +1503,7 @@ static void cdcacm_unbind(FAR struct usbdevclass_driver_s *driver,
{ {
usbtrace(TRACE_CLSERROR(USBSER_TRACEERR_INVALIDARG), 0); usbtrace(TRACE_CLSERROR(USBSER_TRACEERR_INVALIDARG), 0);
return; return;
} }
#endif #endif
/* Extract reference to private data */ /* Extract reference to private data */
@@ -1631,7 +1632,7 @@ static int cdcacm_setup(FAR struct usbdevclass_driver_s *driver,
{ {
usbtrace(TRACE_CLSERROR(USBSER_TRACEERR_INVALIDARG), 0); usbtrace(TRACE_CLSERROR(USBSER_TRACEERR_INVALIDARG), 0);
return -EINVAL; return -EINVAL;
} }
#endif #endif
/* Extract reference to private data */ /* Extract reference to private data */
@@ -1715,7 +1716,7 @@ static int cdcacm_setup(FAR struct usbdevclass_driver_s *driver,
{ {
#ifdef CONFIG_USBDEV_DUALSPEED #ifdef CONFIG_USBDEV_DUALSPEED
ret = cdcacm_mkcfgdesc(ctrlreq->buf, &priv->devinfo, ret = cdcacm_mkcfgdesc(ctrlreq->buf, &priv->devinfo,
dev->speed, ctrl->req); dev->speed, ctrl->value[1]);
#else #else
ret = cdcacm_mkcfgdesc(ctrlreq->buf, &priv->devinfo); ret = cdcacm_mkcfgdesc(ctrlreq->buf, &priv->devinfo);
#endif #endif
@@ -2030,7 +2031,7 @@ static void cdcacm_disconnect(FAR struct usbdevclass_driver_s *driver,
{ {
usbtrace(TRACE_CLSERROR(USBSER_TRACEERR_INVALIDARG), 0); usbtrace(TRACE_CLSERROR(USBSER_TRACEERR_INVALIDARG), 0);
return; return;
} }
#endif #endif
/* Extract reference to private data */ /* Extract reference to private data */
@@ -2094,7 +2095,7 @@ static void cdcacm_suspend(FAR struct usbdevclass_driver_s *driver,
{ {
usbtrace(TRACE_CLSERROR(USBSER_TRACEERR_INVALIDARG), 0); usbtrace(TRACE_CLSERROR(USBSER_TRACEERR_INVALIDARG), 0);
return; return;
} }
#endif #endif
/* Extract reference to private data */ /* Extract reference to private data */
@@ -2128,7 +2129,7 @@ static void cdcacm_resume(FAR struct usbdevclass_driver_s *driver,
{ {
usbtrace(TRACE_CLSERROR(USBSER_TRACEERR_INVALIDARG), 0); usbtrace(TRACE_CLSERROR(USBSER_TRACEERR_INVALIDARG), 0);
return; return;
} }
#endif #endif
/* Extract reference to private data */ /* Extract reference to private data */
@@ -2304,7 +2305,7 @@ static int cdcuart_ioctl(FAR struct file *filep, int cmd, unsigned long arg)
* called to get the data associated CDCACM_EVENT_CTRLLINE event. * called to get the data associated CDCACM_EVENT_CTRLLINE event.
*/ */
case CAIOC_GETCTRLLINE: case CAIOC_GETCTRLLINE:
{ {
FAR int *ptr = (FAR int *)((uintptr_t)arg); FAR int *ptr = (FAR int *)((uintptr_t)arg);
if (ptr != NULL) if (ptr != NULL)
@@ -2356,6 +2357,7 @@ static int cdcuart_ioctl(FAR struct file *filep, int cmd, unsigned long arg)
#ifdef CONFIG_CDCACM_OFLOWCONTROL #ifdef CONFIG_CDCACM_OFLOWCONTROL
/* Report state of output flow control */ /* Report state of output flow control */
# warning Missing logic # warning Missing logic
#endif #endif
#ifdef CONFIG_CDCACM_IFLOWCONTROL #ifdef CONFIG_CDCACM_IFLOWCONTROL
@@ -2387,6 +2389,7 @@ static int cdcuart_ioctl(FAR struct file *filep, int cmd, unsigned long arg)
#ifdef CONFIG_CDCACM_OFLOWCONTROL #ifdef CONFIG_CDCACM_OFLOWCONTROL
/* Handle changes to output flow control */ /* Handle changes to output flow control */
# warning Missing logic # warning Missing logic
#endif #endif
@@ -2422,7 +2425,6 @@ static int cdcuart_ioctl(FAR struct file *filep, int cmd, unsigned long arg)
*/ */
cdcacm_release_rxpending(priv); cdcacm_release_rxpending(priv);
} }
/* Flow control has been enabled. */ /* Flow control has been enabled. */
@@ -2671,8 +2673,8 @@ static bool cdcuart_rxflowcontrol(FAR struct uart_dev_s *dev,
#ifdef CONFIG_DEBUG_FEATURES #ifdef CONFIG_DEBUG_FEATURES
if (dev == NULL || dev->priv == NULL) if (dev == NULL || dev->priv == NULL)
{ {
usbtrace(TRACE_CLSERROR(USBSER_TRACEERR_INVALIDARG), 0); usbtrace(TRACE_CLSERROR(USBSER_TRACEERR_INVALIDARG), 0);
return false; return false;
} }
#endif #endif
@@ -2990,7 +2992,7 @@ int cdcacm_classobject(int minor, FAR struct usbdev_devinfo_s *devinfo,
/* Register the CDC/ACM TTY device */ /* Register the CDC/ACM TTY device */
sprintf(devname, CDCACM_DEVNAME_FORMAT, minor); snprintf(devname, CDCACM_DEVNAME_SIZE, CDCACM_DEVNAME_FORMAT, minor);
ret = uart_register(devname, &priv->serdev); ret = uart_register(devname, &priv->serdev);
if (ret < 0) if (ret < 0)
{ {
@@ -3145,7 +3147,7 @@ void cdcacm_uninitialize(FAR void *handle)
/* Un-register the CDC/ACM TTY device */ /* Un-register the CDC/ACM TTY device */
sprintf(devname, CDCACM_DEVNAME_FORMAT, priv->minor); snprintf(devname, CDCACM_DEVNAME_SIZE, CDCACM_DEVNAME_FORMAT, priv->minor);
ret = unregister_driver(devname); ret = unregister_driver(devname);
if (ret < 0) if (ret < 0)
{ {

View File

@@ -51,7 +51,9 @@
/**************************************************************************** /****************************************************************************
* Pre-processor Definitions * Pre-processor Definitions
****************************************************************************/ ****************************************************************************/
/* Configuration ************************************************************/ /* Configuration ************************************************************/
/* If the serial device is configured as part of a composite device than both /* If the serial device is configured as part of a composite device than both
* CONFIG_USBDEV_COMPOSITE and CONFIG_CDCACM_COMPOSITE must be defined. * CONFIG_USBDEV_COMPOSITE and CONFIG_CDCACM_COMPOSITE must be defined.
*/ */
@@ -61,7 +63,7 @@
#endif #endif
#if defined(CONFIG_CDCACM_COMPOSITE) && !defined(CONFIG_CDCACM_STRBASE) #if defined(CONFIG_CDCACM_COMPOSITE) && !defined(CONFIG_CDCACM_STRBASE)
# define CONFIG_CDCACM_STRBASE (4) # define CONFIG_CDCACM_STRBASE (0)
#endif #endif
#if defined(CONFIG_CDCACM_COMPOSITE) && !defined(CONFIG_COMPOSITE_IAD) #if defined(CONFIG_CDCACM_COMPOSITE) && !defined(CONFIG_COMPOSITE_IAD)
@@ -90,6 +92,7 @@
#endif #endif
/* Descriptors **************************************************************/ /* Descriptors **************************************************************/
/* These settings are not modifiable via the NuttX configuration */ /* These settings are not modifiable via the NuttX configuration */
#define CDC_VERSIONNO 0x0110 /* CDC version number 1.10 (BCD) */ #define CDC_VERSIONNO 0x0110 /* CDC version number 1.10 (BCD) */
@@ -169,6 +172,7 @@
#define CDCACM_EPINBULK_ATTR (USB_EP_ATTR_XFER_BULK) #define CDCACM_EPINBULK_ATTR (USB_EP_ATTR_XFER_BULK)
/* Device driver definitions ************************************************/ /* Device driver definitions ************************************************/
/* A CDC/ACM device is specific by a minor number in the range of 0-255. /* A CDC/ACM device is specific by a minor number in the range of 0-255.
* This maps to a character device at /dev/ttyACMx, x=0..255. * This maps to a character device at /dev/ttyACMx, x=0..255.
*/ */
@@ -177,6 +181,7 @@
#define CDCACM_DEVNAME_SIZE 16 #define CDCACM_DEVNAME_SIZE 16
/* Misc Macros **************************************************************/ /* Misc Macros **************************************************************/
/* MIN/MAX macros */ /* MIN/MAX macros */
#ifndef MIN #ifndef MIN

View File

@@ -58,6 +58,7 @@
****************************************************************************/ ****************************************************************************/
/* USB descriptor templates these will be copied and modified **************/ /* USB descriptor templates these will be copied and modified **************/
/* Device Descriptor. If the USB serial device is configured as part of /* Device Descriptor. If the USB serial device is configured as part of
* composite device, then the device descriptor will be provided by the * composite device, then the device descriptor will be provided by the
* composite device logic. * composite device logic.
@@ -182,27 +183,27 @@ int cdcacm_mkstrdesc(uint8_t id, struct usb_strdesc_s *strdesc)
return -EINVAL; return -EINVAL;
} }
/* The string is utf16-le. The poor man's utf-8 to utf16-le /* The string is utf16-le. The poor man's utf-8 to utf16-le
* conversion below will only handle 7-bit en-us ascii * conversion below will only handle 7-bit en-us ascii
*/ */
len = strlen(str); len = strlen(str);
if (len > (CDCACM_MAXSTRLEN / 2)) if (len > (CDCACM_MAXSTRLEN / 2))
{ {
len = (CDCACM_MAXSTRLEN / 2); len = (CDCACM_MAXSTRLEN / 2);
} }
for (i = 0, ndata = 0; i < len; i++, ndata += 2) for (i = 0, ndata = 0; i < len; i++, ndata += 2)
{ {
strdesc->data[ndata] = str[i]; strdesc->data[ndata] = str[i];
strdesc->data[ndata+1] = 0; strdesc->data[ndata + 1] = 0;
} }
strdesc->len = ndata+2; strdesc->len = ndata + 2;
strdesc->type = USB_DESC_TYPE_STRING; strdesc->type = USB_DESC_TYPE_STRING;
return strdesc->len; return strdesc->len;
#else #else
return -EINVAL; return -EINVAL;
#endif #endif
} }
@@ -388,7 +389,11 @@ int16_t cdcacm_mkcfgdesc(FAR uint8_t *buf,
#endif #endif
dest->len = USB_SIZEOF_CFGDESC; /* Descriptor length */ dest->len = USB_SIZEOF_CFGDESC; /* Descriptor length */
#ifdef CONFIG_USBDEV_DUALSPEED
dest->type = type; /* Descriptor type */
#else
dest->type = USB_DESC_TYPE_CONFIG; /* Descriptor type */ dest->type = USB_DESC_TYPE_CONFIG; /* Descriptor type */
#endif
dest->totallen[0] = LSBYTE(size); /* LS Total length */ dest->totallen[0] = LSBYTE(size); /* LS Total length */
dest->totallen[1] = MSBYTE(size); /* MS Total length */ dest->totallen[1] = MSBYTE(size); /* MS Total length */
dest->ninterfaces = CDCACM_NINTERFACES; /* Number of interfaces */ dest->ninterfaces = CDCACM_NINTERFACES; /* Number of interfaces */
@@ -515,7 +520,8 @@ int16_t cdcacm_mkcfgdesc(FAR uint8_t *buf,
if (buf != NULL) if (buf != NULL)
{ {
FAR struct cdc_callmgmt_funcdesc_s *dest = (FAR struct cdc_callmgmt_funcdesc_s *)buf; FAR struct cdc_callmgmt_funcdesc_s *dest =
(FAR struct cdc_callmgmt_funcdesc_s *)buf;
dest->size = SIZEOF_CALLMGMT_FUNCDESC; /* Descriptor length */ dest->size = SIZEOF_CALLMGMT_FUNCDESC; /* Descriptor length */
dest->type = USB_DESC_TYPE_CSINTERFACE; /* Descriptor type */ dest->type = USB_DESC_TYPE_CSINTERFACE; /* Descriptor type */
@@ -532,7 +538,9 @@ int16_t cdcacm_mkcfgdesc(FAR uint8_t *buf,
if (buf != NULL) if (buf != NULL)
{ {
cdcacm_copy_epdesc(CDCACM_EPINTIN, (struct usb_epdesc_s *)buf, devinfo, hispeed); cdcacm_copy_epdesc(CDCACM_EPINTIN, (struct usb_epdesc_s *)buf,
devinfo,
hispeed);
buf += USB_SIZEOF_EPDESC; buf += USB_SIZEOF_EPDESC;
} }
@@ -568,7 +576,9 @@ int16_t cdcacm_mkcfgdesc(FAR uint8_t *buf,
if (buf != NULL) if (buf != NULL)
{ {
cdcacm_copy_epdesc(CDCACM_EPBULKOUT, (struct usb_epdesc_s *)buf, devinfo, hispeed); cdcacm_copy_epdesc(CDCACM_EPBULKOUT, (struct usb_epdesc_s *)buf,
devinfo,
hispeed);
buf += USB_SIZEOF_EPDESC; buf += USB_SIZEOF_EPDESC;
} }
@@ -578,7 +588,9 @@ int16_t cdcacm_mkcfgdesc(FAR uint8_t *buf,
if (buf != NULL) if (buf != NULL)
{ {
cdcacm_copy_epdesc(CDCACM_EPBULKIN, (struct usb_epdesc_s *)buf, devinfo, hispeed); cdcacm_copy_epdesc(CDCACM_EPBULKIN, (struct usb_epdesc_s *)buf,
devinfo,
hispeed);
buf += USB_SIZEOF_EPDESC; buf += USB_SIZEOF_EPDESC;
} }

View File

@@ -243,10 +243,10 @@ static int composite_msftdescriptor(FAR struct composite_dev_s *priv,
size_t total_len = sizeof(struct usb_msft_os_feature_desc_s) + size_t total_len = sizeof(struct usb_msft_os_feature_desc_s) +
(response->count - 1) * (response->count - 1) *
sizeof(struct usb_msft_os_function_desc_s); sizeof(struct usb_msft_os_function_desc_s);
response->len[0] = (total_len >> 0) & 0xFF; response->len[0] = (total_len >> 0) & 0xff;
response->len[1] = (total_len >> 8) & 0xFF; response->len[1] = (total_len >> 8) & 0xff;
response->len[2] = (total_len >> 16) & 0xFF; response->len[2] = (total_len >> 16) & 0xff;
response->len[3] = (total_len >> 24) & 0xFF; response->len[3] = (total_len >> 24) & 0xff;
response->version[1] = 0x01; response->version[1] = 0x01;
response->index[0] = MSFTOSDESC_INDEX_FUNCTION; response->index[0] = MSFTOSDESC_INDEX_FUNCTION;
@@ -265,7 +265,7 @@ static int composite_msftdescriptor(FAR struct composite_dev_s *priv,
* a bit incorrect here, the interface is in ctrl->value low byte. * a bit incorrect here, the interface is in ctrl->value low byte.
* Also WinUSB driver has limitation that index[0] will not be correct if * Also WinUSB driver has limitation that index[0] will not be correct if
* trying to read descriptors using e.g. libusb xusb.exe. * trying to read descriptors using e.g. libusb xusb.exe.
*/ */
uint8_t interface = ctrl->value[0]; uint8_t interface = ctrl->value[0];
int ret = -ENOTSUP; int ret = -ENOTSUP;
@@ -281,7 +281,7 @@ static int composite_msftdescriptor(FAR struct composite_dev_s *priv,
*dispatched = true; *dispatched = true;
break; break;
} }
} }
return ret; return ret;
} }
@@ -437,7 +437,7 @@ static void composite_unbind(FAR struct usbdevclass_driver_s *driver,
{ {
usbtrace(TRACE_CLSERROR(USBCOMPOSITE_TRACEERR_INVALIDARG), 0); usbtrace(TRACE_CLSERROR(USBCOMPOSITE_TRACEERR_INVALIDARG), 0);
return; return;
} }
#endif #endif
/* Extract reference to private data */ /* Extract reference to private data */
@@ -507,7 +507,7 @@ static int composite_setup(FAR struct usbdevclass_driver_s *driver,
{ {
usbtrace(TRACE_CLSERROR(USBCOMPOSITE_TRACEERR_SETUPINVALIDARGS), 0); usbtrace(TRACE_CLSERROR(USBCOMPOSITE_TRACEERR_SETUPINVALIDARGS), 0);
return -EIO; return -EIO;
} }
#endif #endif
/* Extract a reference to private data */ /* Extract a reference to private data */
@@ -588,7 +588,8 @@ static int composite_setup(FAR struct usbdevclass_driver_s *driver,
/* value == string index. Zero is the language ID. */ /* value == string index. Zero is the language ID. */
uint8_t strid = ctrl->value[0]; uint8_t strid = ctrl->value[0];
FAR struct usb_strdesc_s *buf = (FAR struct usb_strdesc_s *)ctrlreq->buf; FAR struct usb_strdesc_s *buf =
(FAR struct usb_strdesc_s *)ctrlreq->buf;
if (strid < COMPOSITE_NSTRIDS) if (strid < COMPOSITE_NSTRIDS)
{ {
@@ -604,7 +605,8 @@ static int composite_setup(FAR struct usbdevclass_driver_s *driver,
static const uint8_t msft_response[16] = static const uint8_t msft_response[16] =
{ {
'M', 0, 'S', 0, 'F', 0, 'T', 0, '1', 0, '0', 0, '0', 0, 0xEE, 0 'M', 0, 'S', 0, 'F', 0, 'T', 0, '1', 0, '0', 0, '0', 0,
0xff, 0
}; };
buf->len = 18; buf->len = 18;
@@ -619,8 +621,8 @@ static int composite_setup(FAR struct usbdevclass_driver_s *driver,
for (i = 0; i < priv->ndevices; i++) for (i = 0; i < priv->ndevices; i++)
{ {
if (strid >= priv->device[i].compdesc.devinfo.strbase && if (strid > priv->device[i].compdesc.devinfo.strbase &&
strid < priv->device[i].compdesc.devinfo.strbase + strid <= priv->device[i].compdesc.devinfo.strbase +
priv->device[i].compdesc.devinfo.nstrings) priv->device[i].compdesc.devinfo.nstrings)
{ {
ret = priv->device[i].compdesc.mkstrdesc(strid - ret = priv->device[i].compdesc.mkstrdesc(strid -
@@ -634,7 +636,8 @@ static int composite_setup(FAR struct usbdevclass_driver_s *driver,
default: default:
{ {
usbtrace(TRACE_CLSERROR(USBCOMPOSITE_TRACEERR_GETUNKNOWNDESC), value); usbtrace(TRACE_CLSERROR(USBCOMPOSITE_TRACEERR_GETUNKNOWNDESC),
value);
} }
break; break;
} }
@@ -651,7 +654,11 @@ static int composite_setup(FAR struct usbdevclass_driver_s *driver,
for (i = 0; i < priv->ndevices; i++) for (i = 0; i < priv->ndevices; i++)
{ {
ret = CLASS_SETUP(priv->device[i].dev, dev, ctrl, dataout, outlen); ret = CLASS_SETUP(priv->device[i].dev,
dev,
ctrl,
dataout,
outlen);
} }
dispatched = true; dispatched = true;
@@ -693,7 +700,8 @@ static int composite_setup(FAR struct usbdevclass_driver_s *driver,
break; break;
default: default:
usbtrace(TRACE_CLSERROR(USBCOMPOSITE_TRACEERR_UNSUPPORTEDSTDREQ), ctrl->req); usbtrace(TRACE_CLSERROR(USBCOMPOSITE_TRACEERR_UNSUPPORTEDSTDREQ),
ctrl->req);
break; break;
} }
} }
@@ -770,7 +778,7 @@ static void composite_disconnect(FAR struct usbdevclass_driver_s *driver,
{ {
usbtrace(TRACE_CLSERROR(USBCOMPOSITE_TRACEERR_INVALIDARG), 0); usbtrace(TRACE_CLSERROR(USBCOMPOSITE_TRACEERR_INVALIDARG), 0);
return; return;
} }
#endif #endif
/* Extract reference to private data */ /* Extract reference to private data */
@@ -828,7 +836,7 @@ static void composite_suspend(FAR struct usbdevclass_driver_s *driver,
{ {
usbtrace(TRACE_CLSERROR(USBCOMPOSITE_TRACEERR_INVALIDARG), 0); usbtrace(TRACE_CLSERROR(USBCOMPOSITE_TRACEERR_INVALIDARG), 0);
return; return;
} }
#endif #endif
/* Extract reference to private data */ /* Extract reference to private data */
@@ -875,7 +883,7 @@ static void composite_resume(FAR struct usbdevclass_driver_s *driver,
{ {
usbtrace(TRACE_CLSERROR(USBCOMPOSITE_TRACEERR_INVALIDARG), 0); usbtrace(TRACE_CLSERROR(USBCOMPOSITE_TRACEERR_INVALIDARG), 0);
return; return;
} }
#endif #endif
/* Extract reference to private data */ /* Extract reference to private data */
@@ -905,6 +913,7 @@ static void composite_resume(FAR struct usbdevclass_driver_s *driver,
/**************************************************************************** /****************************************************************************
* Public Functions * Public Functions
****************************************************************************/ ****************************************************************************/
/**************************************************************************** /****************************************************************************
* Name: composite_initialize * Name: composite_initialize
* *
@@ -1050,6 +1059,7 @@ void composite_uninitialize(FAR void *handle)
usbdev_unregister(&alloc->drvr.drvr); usbdev_unregister(&alloc->drvr.drvr);
/* Free any resources used by the composite driver */ /* Free any resources used by the composite driver */
/* None */ /* None */
/* Second phase uninitialization: Clean up all memory resources */ /* Second phase uninitialization: Clean up all memory resources */
@@ -1084,7 +1094,7 @@ int composite_ep0submit(FAR struct usbdevclass_driver_s *driver,
* it becomes necessary to manage the completion callbacks. * it becomes necessary to manage the completion callbacks.
*/ */
return EP_SUBMIT(dev->ep0, ctrlreq); return EP_SUBMIT(dev->ep0, ctrlreq);
} }
#endif /* CONFIG_USBDEV_COMPOSITE */ #endif /* CONFIG_USBDEV_COMPOSITE */

View File

@@ -169,20 +169,20 @@ int composite_mkstrdesc(uint8_t id, struct usb_strdesc_s *strdesc)
return -EINVAL; return -EINVAL;
} }
/* The string is utf16-le. The poor man's utf-8 to utf16-le /* The string is utf16-le. The poor man's utf-8 to utf16-le
* conversion below will only handle 7-bit en-us ascii * conversion below will only handle 7-bit en-us ascii
*/ */
len = strlen(str); len = strlen(str);
for (i = 0, ndata = 0; i < len; i++, ndata += 2) for (i = 0, ndata = 0; i < len; i++, ndata += 2)
{ {
strdesc->data[ndata] = str[i]; strdesc->data[ndata] = str[i];
strdesc->data[ndata+1] = 0; strdesc->data[ndata + 1] = 0;
} }
strdesc->len = ndata+2; strdesc->len = ndata + 2;
strdesc->type = USB_DESC_TYPE_STRING; strdesc->type = USB_DESC_TYPE_STRING;
return strdesc->len; return strdesc->len;
} }
/**************************************************************************** /****************************************************************************
@@ -219,10 +219,15 @@ int16_t composite_mkcfgdesc(FAR struct composite_dev_s *priv, FAR uint8_t *buf)
int i; int i;
/* Configuration descriptor for the composite device */ /* Configuration descriptor for the composite device */
/* Fill in the values directly into the buf */ /* Fill in the values directly into the buf */
cfgdesc->len = USB_SIZEOF_CFGDESC; /* Descriptor length */ cfgdesc->len = USB_SIZEOF_CFGDESC; /* Descriptor length */
#ifdef CONFIG_USBDEV_DUALSPEED
cfgdesc->type = type; /* Descriptor type */
#else
cfgdesc->type = USB_DESC_TYPE_CONFIG; /* Descriptor type */ cfgdesc->type = USB_DESC_TYPE_CONFIG; /* Descriptor type */
#endif
cfgdesc->totallen[0] = LSBYTE(priv->cfgdescsize); /* Lower Byte of Total length */ cfgdesc->totallen[0] = LSBYTE(priv->cfgdescsize); /* Lower Byte of Total length */
cfgdesc->totallen[1] = MSBYTE(priv->cfgdescsize); /* High Byte of Total length */ cfgdesc->totallen[1] = MSBYTE(priv->cfgdescsize); /* High Byte of Total length */
cfgdesc->ninterfaces = priv->ninterfaces; /* Number of interfaces */ cfgdesc->ninterfaces = priv->ninterfaces; /* Number of interfaces */

View File

@@ -59,6 +59,7 @@
****************************************************************************/ ****************************************************************************/
/* Configuration ************************************************************/ /* Configuration ************************************************************/
/* If the USB mass storage device is configured as part of a composite device /* If the USB mass storage device is configured as part of a composite device
* then both CONFIG_USBDEV_COMPOSITE and CONFIG_USBMSC_COMPOSITE must be * then both CONFIG_USBDEV_COMPOSITE and CONFIG_USBMSC_COMPOSITE must be
* defined. * defined.
@@ -69,7 +70,7 @@
#endif #endif
#if defined(CONFIG_USBMSC_COMPOSITE) && !defined(CONFIG_USBMSC_STRBASE) #if defined(CONFIG_USBMSC_COMPOSITE) && !defined(CONFIG_USBMSC_STRBASE)
# define CONFIG_USBMSC_STRBASE (4) # define CONFIG_USBMSC_STRBASE (0)
#endif #endif
/* Interface IDs. If the mass storage driver is built as a component of a /* Interface IDs. If the mass storage driver is built as a component of a
@@ -360,6 +361,7 @@
/**************************************************************************** /****************************************************************************
* Public Types * Public Types
****************************************************************************/ ****************************************************************************/
/* Endpoint descriptors */ /* Endpoint descriptors */
enum usbmsc_epdesc_e enum usbmsc_epdesc_e

View File

@@ -55,6 +55,7 @@
****************************************************************************/ ****************************************************************************/
/* Descriptors **************************************************************/ /* Descriptors **************************************************************/
/* Device descriptor. If the USB mass storage device is configured as part /* Device descriptor. If the USB mass storage device is configured as part
* of a composite device, then the device descriptor will be provided by the * of a composite device, then the device descriptor will be provided by the
* composite device logic. * composite device logic.
@@ -88,7 +89,6 @@ static const struct usb_devdesc_s g_devdesc =
}; };
#endif #endif
#ifdef CONFIG_USBDEV_DUALSPEED #ifdef CONFIG_USBDEV_DUALSPEED
#ifndef CONFIG_USBMSC_COMPOSITE #ifndef CONFIG_USBMSC_COMPOSITE
static const struct usb_qualdesc_s g_qualdesc = static const struct usb_qualdesc_s g_qualdesc =
@@ -112,6 +112,7 @@ static const struct usb_qualdesc_s g_qualdesc =
/**************************************************************************** /****************************************************************************
* Public Data * Public Data
****************************************************************************/ ****************************************************************************/
/* Strings ******************************************************************/ /* Strings ******************************************************************/
#ifndef CONFIG_USBMSC_COMPOSITE #ifndef CONFIG_USBMSC_COMPOSITE
@@ -170,7 +171,8 @@ int usbmsc_mkstrdesc(uint8_t id, struct usb_strdesc_s *strdesc)
break; break;
#endif #endif
/* case USBMSC_CONFIGSTRID: */ /* case USBMSC_CONFIGSTRID: */
case USBMSC_INTERFACESTRID: case USBMSC_INTERFACESTRID:
str = CONFIG_USBMSC_CONFIGSTR; str = CONFIG_USBMSC_CONFIGSTR;
break; break;
@@ -179,25 +181,25 @@ int usbmsc_mkstrdesc(uint8_t id, struct usb_strdesc_s *strdesc)
return -EINVAL; return -EINVAL;
} }
/* The string is utf16-le. The poor man's utf-8 to utf16-le /* The string is utf16-le. The poor man's utf-8 to utf16-le
* conversion below will only handle 7-bit en-us ascii * conversion below will only handle 7-bit en-us ascii
*/ */
len = strlen(str); len = strlen(str);
if (len > (USBMSC_MAXSTRLEN / 2)) if (len > (USBMSC_MAXSTRLEN / 2))
{ {
len = (USBMSC_MAXSTRLEN / 2); len = (USBMSC_MAXSTRLEN / 2);
} }
for (i = 0, ndata = 0; i < len; i++, ndata += 2) for (i = 0, ndata = 0; i < len; i++, ndata += 2)
{ {
strdesc->data[ndata] = str[i]; strdesc->data[ndata] = str[i];
strdesc->data[ndata+1] = 0; strdesc->data[ndata + 1] = 0;
} }
strdesc->len = ndata+2; strdesc->len = ndata + 2;
strdesc->type = USB_DESC_TYPE_STRING; strdesc->type = USB_DESC_TYPE_STRING;
return strdesc->len; return strdesc->len;
} }
/**************************************************************************** /****************************************************************************
@@ -339,14 +341,18 @@ int16_t usbmsc_mkcfgdesc(uint8_t *buf,
#ifndef CONFIG_USBMSC_COMPOSITE #ifndef CONFIG_USBMSC_COMPOSITE
{ {
/* Configuration descriptor If the USB mass storage device is configured as part /* 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 * of a composite device, then the configuration descriptor will be provided
* composite device logic. * by the composite device logic.
*/ */
FAR struct usb_cfgdesc_s *dest = (FAR struct usb_cfgdesc_s *)buf; FAR struct usb_cfgdesc_s *dest = (FAR struct usb_cfgdesc_s *)buf;
dest->len = USB_SIZEOF_CFGDESC; /* Descriptor length */ dest->len = USB_SIZEOF_CFGDESC; /* Descriptor length */
#ifdef CONFIG_USBDEV_DUALSPEED
dest->type = type; /* Descriptor type */
#else
dest->type = USB_DESC_TYPE_CONFIG; /* Descriptor type */ dest->type = USB_DESC_TYPE_CONFIG; /* Descriptor type */
#endif
dest->totallen[0] = LSBYTE(SIZEOF_USBMSC_CFGDESC); /* LS Total length */ dest->totallen[0] = LSBYTE(SIZEOF_USBMSC_CFGDESC); /* LS Total length */
dest->totallen[1] = MSBYTE(SIZEOF_USBMSC_CFGDESC); /* MS Total length */ dest->totallen[1] = MSBYTE(SIZEOF_USBMSC_CFGDESC); /* MS Total length */
dest->ninterfaces = USBMSC_NINTERFACES; /* Number of interfaces */ dest->ninterfaces = USBMSC_NINTERFACES; /* Number of interfaces */

File diff suppressed because it is too large Load Diff