2011-09-27 22:11:14 +02:00
|
|
|
/****************************************************************************
|
2012-04-23 18:49:15 +02:00
|
|
|
* drivers/usbdev/cdcacm_desc.c
|
2011-09-27 22:11:14 +02:00
|
|
|
*
|
2012-01-24 22:51:26 +01:00
|
|
|
* Copyright (C) 2011-2012 Gregory Nutt. All rights reserved.
|
|
|
|
* Author: Gregory Nutt <gnutt@nuttx.org>
|
2011-09-27 22:11:14 +02:00
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
*
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in
|
|
|
|
* the documentation and/or other materials provided with the
|
|
|
|
* distribution.
|
|
|
|
* 3. Neither the name NuttX nor the names of its contributors may be
|
|
|
|
* used to endorse or promote products derived from this software
|
|
|
|
* without specific prior written permission.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
|
|
|
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
|
|
|
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
|
|
|
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
|
|
|
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
|
|
|
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
|
|
|
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
|
|
|
|
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
|
|
|
|
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
|
|
|
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
|
|
|
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
|
|
|
* POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Included Files
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
#include <nuttx/config.h>
|
|
|
|
|
|
|
|
#include <sys/types.h>
|
|
|
|
#include <stdint.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <errno.h>
|
|
|
|
#include <debug.h>
|
|
|
|
|
|
|
|
#include <nuttx/usb/usb.h>
|
|
|
|
#include <nuttx/usb/cdc.h>
|
2012-01-26 00:04:17 +01:00
|
|
|
#include <nuttx/usb/cdcacm.h>
|
2011-09-27 22:11:14 +02:00
|
|
|
#include <nuttx/usb/usbdev_trace.h>
|
|
|
|
|
2012-01-24 22:51:26 +01:00
|
|
|
#include "cdcacm.h"
|
2011-09-27 22:11:14 +02:00
|
|
|
|
|
|
|
/****************************************************************************
|
2012-01-24 22:51:26 +01:00
|
|
|
* Pre-processor Definitions
|
2011-09-27 22:11:14 +02:00
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Private Types
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
/* Describes one description in the group of descriptors forming the
|
|
|
|
* total configuration descriptor.
|
|
|
|
*/
|
|
|
|
|
|
|
|
struct cfgdecsc_group_s
|
|
|
|
{
|
|
|
|
uint16_t descsize; /* Size of the descriptor in bytes */
|
|
|
|
uint16_t hsepsize; /* High speed max packet size */
|
|
|
|
FAR void *desc; /* A pointer to the descriptor */
|
|
|
|
};
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Private Function Prototypes
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Private Data
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
/* USB descriptor templates these will be copied and modified **************/
|
2012-01-24 22:51:26 +01:00
|
|
|
/* 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 logic.
|
|
|
|
*/
|
2011-09-27 22:11:14 +02:00
|
|
|
|
2012-01-26 00:04:17 +01:00
|
|
|
#ifndef CONFIG_CDCACM_COMPOSITE
|
2011-09-27 22:11:14 +02:00
|
|
|
static const struct usb_devdesc_s g_devdesc =
|
|
|
|
{
|
|
|
|
USB_SIZEOF_DEVDESC, /* len */
|
|
|
|
USB_DESC_TYPE_DEVICE, /* type */
|
|
|
|
{ /* usb */
|
|
|
|
LSBYTE(0x0200),
|
|
|
|
MSBYTE(0x0200)
|
|
|
|
},
|
|
|
|
USB_CLASS_CDC, /* class */
|
|
|
|
CDC_SUBCLASS_NONE, /* subclass */
|
|
|
|
CDC_PROTO_NONE, /* protocol */
|
2012-01-26 00:04:17 +01:00
|
|
|
CONFIG_CDCACM_EP0MAXPACKET, /* maxpacketsize */
|
2011-09-27 22:11:14 +02:00
|
|
|
{
|
2012-01-26 00:04:17 +01:00
|
|
|
LSBYTE(CONFIG_CDCACM_VENDORID), /* vendor */
|
|
|
|
MSBYTE(CONFIG_CDCACM_VENDORID)
|
2011-09-27 22:11:14 +02:00
|
|
|
},
|
|
|
|
{
|
2012-01-26 00:04:17 +01:00
|
|
|
LSBYTE(CONFIG_CDCACM_PRODUCTID), /* product */
|
|
|
|
MSBYTE(CONFIG_CDCACM_PRODUCTID)
|
2011-09-27 22:11:14 +02:00
|
|
|
},
|
|
|
|
{
|
2012-01-26 00:04:17 +01:00
|
|
|
LSBYTE(CDCACM_VERSIONNO), /* device */
|
|
|
|
MSBYTE(CDCACM_VERSIONNO)
|
2011-09-27 22:11:14 +02:00
|
|
|
},
|
2012-01-26 00:04:17 +01:00
|
|
|
CDCACM_MANUFACTURERSTRID, /* imfgr */
|
|
|
|
CDCACM_PRODUCTSTRID, /* iproduct */
|
|
|
|
CDCACM_SERIALSTRID, /* serno */
|
|
|
|
CDCACM_NCONFIGS /* nconfigs */
|
2011-09-27 22:11:14 +02:00
|
|
|
};
|
2012-01-24 22:51:26 +01:00
|
|
|
#endif
|
2011-09-27 22:11:14 +02:00
|
|
|
|
2012-01-24 22:51:26 +01:00
|
|
|
/* Configuration descriptor. If the USB serial device is configured as part of
|
|
|
|
* composite device, then the configuration descriptor will be provided by the
|
|
|
|
* composite device logic.
|
|
|
|
*/
|
2011-09-27 22:11:14 +02:00
|
|
|
|
2012-01-26 00:04:17 +01:00
|
|
|
#ifndef CONFIG_CDCACM_COMPOSITE
|
2011-09-27 22:11:14 +02:00
|
|
|
static const struct usb_cfgdesc_s g_cfgdesc =
|
|
|
|
{
|
|
|
|
USB_SIZEOF_CFGDESC, /* len */
|
|
|
|
USB_DESC_TYPE_CONFIG, /* type */
|
|
|
|
{
|
2012-01-26 00:04:17 +01:00
|
|
|
LSBYTE(SIZEOF_CDCACM_CFGDESC), /* LS totallen */
|
|
|
|
MSBYTE(SIZEOF_CDCACM_CFGDESC) /* MS totallen */
|
2011-09-27 22:11:14 +02:00
|
|
|
},
|
2012-01-26 00:04:17 +01:00
|
|
|
CDCACM_NINTERFACES, /* ninterfaces */
|
|
|
|
CDCACM_CONFIGID, /* cfgvalue */
|
|
|
|
CDCACM_CONFIGSTRID, /* icfg */
|
2011-09-27 22:11:14 +02:00
|
|
|
USB_CONFIG_ATTR_ONE|SELFPOWERED|REMOTEWAKEUP, /* attr */
|
|
|
|
(CONFIG_USBDEV_MAXPOWER + 1) / 2 /* mxpower */
|
|
|
|
};
|
2012-01-24 22:51:26 +01:00
|
|
|
#endif
|
2011-09-27 22:11:14 +02:00
|
|
|
|
2012-01-27 17:25:57 +01:00
|
|
|
/* Interface association descriptor */
|
|
|
|
|
|
|
|
#if defined(CONFIG_CDCACM_COMPOSITE) && defined(CONFIG_COMPOSITE_IAD)
|
|
|
|
static const struct usb_iaddesc_s g_iaddesc =
|
|
|
|
{
|
|
|
|
USB_SIZEOF_IADDESC, /* len */
|
|
|
|
USB_DESC_TYPE_INTERFACEASSOCIATION, /* type */
|
|
|
|
CONFIG_CDCACM_IFNOBASE, /* firstif */
|
|
|
|
CDCACM_NINTERFACES, /* nifs */
|
|
|
|
USB_CLASS_CDC, /* class */
|
|
|
|
CDC_SUBCLASS_ACM, /* subclass */
|
|
|
|
CDC_PROTO_NONE, /* protocol */
|
|
|
|
0 /* ifunction */
|
|
|
|
};
|
|
|
|
#endif
|
|
|
|
|
2011-09-27 22:11:14 +02:00
|
|
|
/* Notification interface */
|
|
|
|
|
|
|
|
static const struct usb_ifdesc_s g_notifdesc =
|
|
|
|
{
|
|
|
|
USB_SIZEOF_IFDESC, /* len */
|
|
|
|
USB_DESC_TYPE_INTERFACE, /* type */
|
2012-01-26 00:04:17 +01:00
|
|
|
CDCACM_NOTIFID, /* ifno */
|
|
|
|
CDCACM_NOTALTIFID, /* alt */
|
2011-09-27 22:11:14 +02:00
|
|
|
1, /* neps */
|
|
|
|
USB_CLASS_CDC, /* class */
|
|
|
|
CDC_SUBCLASS_ACM, /* subclass */
|
|
|
|
CDC_PROTO_ATM, /* proto */
|
2012-01-26 00:04:17 +01:00
|
|
|
#ifdef CONFIG_CDCACM_NOTIFSTR
|
|
|
|
CDCACM_NOTIFSTRID /* iif */
|
2011-09-27 22:11:14 +02:00
|
|
|
#else
|
|
|
|
0 /* iif */
|
|
|
|
#endif
|
|
|
|
};
|
|
|
|
|
|
|
|
/* Header functional descriptor */
|
|
|
|
|
|
|
|
static const struct cdc_hdr_funcdesc_s g_funchdr =
|
|
|
|
{
|
|
|
|
SIZEOF_HDR_FUNCDESC, /* size */
|
|
|
|
USB_DESC_TYPE_CSINTERFACE, /* type */
|
|
|
|
CDC_DSUBTYPE_HDR, /* subtype */
|
|
|
|
{
|
|
|
|
LSBYTE(CDC_VERSIONNO), /* LS cdc */
|
|
|
|
MSBYTE(CDC_VERSIONNO) /* MS cdc */
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
/* ACM functional descriptor */
|
|
|
|
|
|
|
|
static const struct cdc_acm_funcdesc_s g_acmfunc =
|
|
|
|
{
|
|
|
|
SIZEOF_ACM_FUNCDESC, /* size */
|
|
|
|
USB_DESC_TYPE_CSINTERFACE, /* type */
|
|
|
|
CDC_DSUBTYPE_ACM, /* subtype */
|
|
|
|
0x06 /* caps */
|
|
|
|
};
|
|
|
|
|
|
|
|
/* Union functional descriptor */
|
|
|
|
|
|
|
|
static const struct cdc_union_funcdesc_s g_unionfunc =
|
|
|
|
{
|
|
|
|
SIZEOF_UNION_FUNCDESC(1), /* size */
|
|
|
|
USB_DESC_TYPE_CSINTERFACE, /* type */
|
|
|
|
CDC_DSUBTYPE_UNION, /* subtype */
|
|
|
|
0, /* master */
|
|
|
|
{1} /* slave[0] */
|
|
|
|
};
|
|
|
|
|
|
|
|
/* Interrupt IN endpoint descriptor */
|
|
|
|
|
|
|
|
static const struct usb_epdesc_s g_epintindesc =
|
|
|
|
{
|
|
|
|
USB_SIZEOF_EPDESC, /* len */
|
|
|
|
USB_DESC_TYPE_ENDPOINT, /* type */
|
2012-01-26 00:04:17 +01:00
|
|
|
CDCACM_EPINTIN_ADDR, /* addr */
|
|
|
|
CDCACM_EPINTIN_ATTR, /* attr */
|
2011-09-27 22:11:14 +02:00
|
|
|
{
|
2012-01-26 00:04:17 +01:00
|
|
|
LSBYTE(CONFIG_CDCACM_EPINTIN_FSSIZE), /* maxpacket (full speed) */
|
|
|
|
MSBYTE(CONFIG_CDCACM_EPINTIN_FSSIZE)
|
2011-09-27 22:11:14 +02:00
|
|
|
},
|
|
|
|
0xff /* interval */
|
|
|
|
};
|
|
|
|
|
|
|
|
/* Data interface descriptor */
|
|
|
|
|
|
|
|
static const struct usb_ifdesc_s g_dataifdesc =
|
|
|
|
{
|
|
|
|
USB_SIZEOF_IFDESC, /* len */
|
|
|
|
USB_DESC_TYPE_INTERFACE, /* type */
|
2012-01-26 00:04:17 +01:00
|
|
|
CDCACM_DATAIFID, /* ifno */
|
|
|
|
CDCACM_DATAALTIFID, /* alt */
|
2011-09-27 22:11:14 +02:00
|
|
|
2, /* neps */
|
|
|
|
USB_CLASS_CDC_DATA, /* class */
|
|
|
|
CDC_DATA_SUBCLASS_NONE, /* subclass */
|
|
|
|
CDC_DATA_PROTO_NONE, /* proto */
|
2012-01-26 00:04:17 +01:00
|
|
|
#ifdef CONFIG_CDCACM_DATAIFSTR
|
|
|
|
CDCACM_DATAIFSTRID /* iif */
|
2011-09-27 22:11:14 +02:00
|
|
|
#else
|
|
|
|
0 /* iif */
|
|
|
|
#endif
|
|
|
|
};
|
|
|
|
|
|
|
|
/* Bulk OUT endpoint descriptor */
|
|
|
|
|
|
|
|
static const struct usb_epdesc_s g_epbulkoutdesc =
|
|
|
|
{
|
|
|
|
USB_SIZEOF_EPDESC, /* len */
|
|
|
|
USB_DESC_TYPE_ENDPOINT, /* type */
|
2012-01-26 00:04:17 +01:00
|
|
|
CDCACM_EPOUTBULK_ADDR, /* addr */
|
|
|
|
CDCACM_EPOUTBULK_ATTR, /* attr */
|
2011-09-27 22:11:14 +02:00
|
|
|
{
|
2012-01-26 00:04:17 +01:00
|
|
|
LSBYTE(CONFIG_CDCACM_EPBULKOUT_FSSIZE), /* maxpacket (full speed) */
|
|
|
|
MSBYTE(CONFIG_CDCACM_EPBULKOUT_FSSIZE)
|
2011-09-27 22:11:14 +02:00
|
|
|
},
|
|
|
|
1 /* interval */
|
|
|
|
};
|
|
|
|
|
|
|
|
/* Bulk IN endpoint descriptor */
|
|
|
|
|
|
|
|
static const struct usb_epdesc_s g_epbulkindesc =
|
|
|
|
{
|
|
|
|
USB_SIZEOF_EPDESC, /* len */
|
|
|
|
USB_DESC_TYPE_ENDPOINT, /* type */
|
2012-01-26 00:04:17 +01:00
|
|
|
CDCACM_EPINBULK_ADDR, /* addr */
|
|
|
|
CDCACM_EPINBULK_ATTR, /* attr */
|
2011-09-27 22:11:14 +02:00
|
|
|
{
|
2012-01-26 00:04:17 +01:00
|
|
|
LSBYTE(CONFIG_CDCACM_EPBULKIN_FSSIZE), /* maxpacket (full speed) */
|
|
|
|
MSBYTE(CONFIG_CDCACM_EPBULKIN_FSSIZE)
|
2011-09-27 22:11:14 +02:00
|
|
|
},
|
|
|
|
1 /* interval */
|
|
|
|
};
|
|
|
|
|
|
|
|
/* The components of the the configuration descriptor are maintained as
|
|
|
|
* a collection of separate descriptor structure coordinated by the
|
|
|
|
* following array. These descriptors could have been combined into
|
|
|
|
* one larger "super" configuration descriptor structure. However, I
|
|
|
|
* have concerns about compiler-dependent alignment and packing. Since
|
|
|
|
* the individual structures consist only of byte types, alignment and
|
|
|
|
* packing is not an issue. And since the are concatentated at run time
|
|
|
|
* instead of compile time, there should no issues there either.
|
|
|
|
*/
|
|
|
|
|
2012-01-26 00:04:17 +01:00
|
|
|
static const struct cfgdecsc_group_s g_cfggroup[CDCACM_CFGGROUP_SIZE] =
|
2012-01-24 22:51:26 +01:00
|
|
|
{
|
|
|
|
/* Configuration Descriptor. If the serial device is used in as part
|
|
|
|
* or a composite device, then the configuration descriptor is
|
|
|
|
* provided by the composite device logic.
|
|
|
|
*/
|
|
|
|
|
2012-01-27 17:25:57 +01:00
|
|
|
#if !defined(CONFIG_CDCACM_COMPOSITE)
|
2011-09-27 22:11:14 +02:00
|
|
|
{
|
|
|
|
USB_SIZEOF_CFGDESC, /* 1. Configuration descriptor */
|
|
|
|
0,
|
|
|
|
(FAR void *)&g_cfgdesc
|
|
|
|
},
|
2012-01-27 17:25:57 +01:00
|
|
|
|
|
|
|
/* If the serial device is part of a composite device, then it should
|
|
|
|
* begin with an interface association descriptor (IAD) because the
|
|
|
|
* CDC/ACM device consists of more than one interface. The IAD associates
|
|
|
|
* the two CDC/ACM interfaces with the same CDC/ACM device.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#elif defined(CONFIG_COMPOSITE_IAD)
|
|
|
|
{
|
|
|
|
USB_SIZEOF_IADDESC, /* 1. Interface association descriptor */
|
|
|
|
0,
|
|
|
|
(FAR void *)&g_iaddesc
|
|
|
|
},
|
2012-01-24 22:51:26 +01:00
|
|
|
#endif
|
2011-09-27 22:11:14 +02:00
|
|
|
{
|
|
|
|
USB_SIZEOF_IFDESC, /* 2. Notification interface */
|
|
|
|
0,
|
|
|
|
(FAR void *)&g_notifdesc
|
|
|
|
},
|
|
|
|
{
|
|
|
|
SIZEOF_HDR_FUNCDESC, /* 3. Header functional descriptor */
|
|
|
|
0,
|
|
|
|
(FAR void *)&g_funchdr
|
|
|
|
},
|
|
|
|
{
|
|
|
|
SIZEOF_ACM_FUNCDESC, /* 4. ACM functional descriptor */
|
|
|
|
0,
|
|
|
|
(FAR void *)&g_acmfunc
|
|
|
|
},
|
|
|
|
{
|
|
|
|
SIZEOF_UNION_FUNCDESC(1), /* 5. Union functional descriptor */
|
|
|
|
0,
|
|
|
|
(FAR void *)&g_unionfunc
|
|
|
|
},
|
|
|
|
{
|
|
|
|
USB_SIZEOF_EPDESC, /* 6. Interrupt IN endpoint descriptor */
|
2012-01-26 00:04:17 +01:00
|
|
|
CONFIG_CDCACM_EPINTIN_HSSIZE,
|
2011-09-27 22:11:14 +02:00
|
|
|
(FAR void *)&g_epintindesc
|
|
|
|
},
|
|
|
|
{
|
|
|
|
USB_SIZEOF_IFDESC, /* 7. Data interface descriptor */
|
|
|
|
0,
|
|
|
|
(FAR void *)&g_dataifdesc
|
|
|
|
},
|
|
|
|
{
|
|
|
|
USB_SIZEOF_EPDESC, /* 8. Bulk OUT endpoint descriptor */
|
2012-01-26 00:04:17 +01:00
|
|
|
CONFIG_CDCACM_EPBULKOUT_HSSIZE,
|
2011-09-27 22:11:14 +02:00
|
|
|
(FAR void *)&g_epbulkoutdesc
|
|
|
|
},
|
|
|
|
{
|
|
|
|
USB_SIZEOF_EPDESC, /* 9. Bulk OUT endpoint descriptor */
|
2012-01-26 00:04:17 +01:00
|
|
|
CONFIG_CDCACM_EPBULKIN_HSSIZE,
|
2011-09-27 22:11:14 +02:00
|
|
|
(FAR void *)&g_epbulkindesc
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2012-01-26 00:04:17 +01:00
|
|
|
#if !defined(CONFIG_CDCACM_COMPOSITE) && defined(CONFIG_USBDEV_DUALSPEED)
|
2011-09-27 22:11:14 +02:00
|
|
|
static const struct usb_qualdesc_s g_qualdesc =
|
|
|
|
{
|
|
|
|
USB_SIZEOF_QUALDESC, /* len */
|
|
|
|
USB_DESC_TYPE_DEVICEQUALIFIER, /* type */
|
|
|
|
{ /* usb */
|
|
|
|
LSBYTE(0x0200),
|
|
|
|
MSBYTE(0x0200)
|
|
|
|
},
|
|
|
|
USB_CLASS_VENDOR_SPEC, /* class */
|
|
|
|
0, /* subclass */
|
|
|
|
0, /* protocol */
|
2012-01-26 00:04:17 +01:00
|
|
|
CONFIG_CDCACM_EP0MAXPACKET, /* mxpacketsize */
|
|
|
|
CDCACM_NCONFIGS, /* nconfigs */
|
2011-09-27 22:11:14 +02:00
|
|
|
0, /* reserved */
|
|
|
|
};
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Private Functions
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Public Functions
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
/****************************************************************************
|
2012-01-26 00:04:17 +01:00
|
|
|
* Name: cdcacm_mkstrdesc
|
2011-09-27 22:11:14 +02:00
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* Construct a string descriptor
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
2012-01-26 00:04:17 +01:00
|
|
|
int cdcacm_mkstrdesc(uint8_t id, struct usb_strdesc_s *strdesc)
|
2011-09-27 22:11:14 +02:00
|
|
|
{
|
2012-01-26 00:04:17 +01:00
|
|
|
#if !defined(CONFIG_CDCACM_COMPOSITE) || defined(CONFIG_CDCACM_NOTIFSTR) || \
|
|
|
|
defined(CONFIG_CDCACM_DATAIFSTR)
|
2012-01-24 22:51:26 +01:00
|
|
|
|
2011-09-27 22:11:14 +02:00
|
|
|
const char *str;
|
|
|
|
int len;
|
|
|
|
int ndata;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
switch (id)
|
|
|
|
{
|
2012-01-26 00:04:17 +01:00
|
|
|
#ifndef CONFIG_CDCACM_COMPOSITE
|
2011-09-27 22:11:14 +02:00
|
|
|
case 0:
|
|
|
|
{
|
|
|
|
/* Descriptor 0 is the language id */
|
|
|
|
|
|
|
|
strdesc->len = 4;
|
|
|
|
strdesc->type = USB_DESC_TYPE_STRING;
|
2012-01-26 00:04:17 +01:00
|
|
|
strdesc->data[0] = LSBYTE(CDCACM_STR_LANGUAGE);
|
|
|
|
strdesc->data[1] = MSBYTE(CDCACM_STR_LANGUAGE);
|
2011-09-27 22:11:14 +02:00
|
|
|
return 4;
|
|
|
|
}
|
|
|
|
|
2012-01-26 00:04:17 +01:00
|
|
|
case CDCACM_MANUFACTURERSTRID:
|
|
|
|
str = CONFIG_CDCACM_VENDORSTR;
|
2011-09-27 22:11:14 +02:00
|
|
|
break;
|
|
|
|
|
2012-01-26 00:04:17 +01:00
|
|
|
case CDCACM_PRODUCTSTRID:
|
|
|
|
str = CONFIG_CDCACM_PRODUCTSTR;
|
2011-09-27 22:11:14 +02:00
|
|
|
break;
|
|
|
|
|
2012-01-26 00:04:17 +01:00
|
|
|
case CDCACM_SERIALSTRID:
|
|
|
|
str = CONFIG_CDCACM_SERIALSTR;
|
2011-09-27 22:11:14 +02:00
|
|
|
break;
|
|
|
|
|
2012-01-26 00:04:17 +01:00
|
|
|
case CDCACM_CONFIGSTRID:
|
|
|
|
str = CONFIG_CDCACM_CONFIGSTR;
|
2011-09-27 22:11:14 +02:00
|
|
|
break;
|
2012-01-24 22:51:26 +01:00
|
|
|
#endif
|
2011-09-27 22:11:14 +02:00
|
|
|
|
2012-01-26 00:04:17 +01:00
|
|
|
#ifdef CONFIG_CDCACM_NOTIFSTR
|
|
|
|
case CDCACM_NOTIFSTRID:
|
|
|
|
str = CONFIG_CDCACM_NOTIFSTR;
|
2011-09-27 22:11:14 +02:00
|
|
|
break;
|
|
|
|
#endif
|
|
|
|
|
2012-01-26 00:04:17 +01:00
|
|
|
#ifdef CONFIG_CDCACM_DATAIFSTR
|
|
|
|
case CDCACM_DATAIFSTRID:
|
|
|
|
str = CONFIG_CDCACM_DATAIFSTR;
|
2011-09-27 22:11:14 +02:00
|
|
|
break;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
default:
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* The string is utf16-le. The poor man's utf-8 to utf16-le
|
|
|
|
* conversion below will only handle 7-bit en-us ascii
|
|
|
|
*/
|
|
|
|
|
|
|
|
len = strlen(str);
|
|
|
|
for (i = 0, ndata = 0; i < len; i++, ndata += 2)
|
|
|
|
{
|
|
|
|
strdesc->data[ndata] = str[i];
|
|
|
|
strdesc->data[ndata+1] = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
strdesc->len = ndata+2;
|
|
|
|
strdesc->type = USB_DESC_TYPE_STRING;
|
|
|
|
return strdesc->len;
|
2012-01-24 22:51:26 +01:00
|
|
|
#else
|
|
|
|
return -EINVAL;
|
|
|
|
#endif
|
2011-09-27 22:11:14 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************************************************
|
2012-01-26 00:04:17 +01:00
|
|
|
* Name: cdcacm_getepdesc
|
2011-09-27 22:11:14 +02:00
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* Return a pointer to the raw device descriptor
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
2012-01-26 00:04:17 +01:00
|
|
|
#ifndef CONFIG_CDCACM_COMPOSITE
|
|
|
|
FAR const struct usb_devdesc_s *cdcacm_getdevdesc(void)
|
2011-09-27 22:11:14 +02:00
|
|
|
{
|
|
|
|
return &g_devdesc;
|
|
|
|
}
|
2012-01-24 22:51:26 +01:00
|
|
|
#endif
|
2011-09-27 22:11:14 +02:00
|
|
|
|
|
|
|
/****************************************************************************
|
2012-01-26 00:04:17 +01:00
|
|
|
* Name: cdcacm_getepdesc
|
2011-09-27 22:11:14 +02:00
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* Return a pointer to the raw endpoint struct (used for configuring
|
|
|
|
* endpoints)
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
2012-01-26 00:04:17 +01:00
|
|
|
FAR const struct usb_epdesc_s *cdcacm_getepdesc(enum cdcacm_epdesc_e epid)
|
2011-09-27 22:11:14 +02:00
|
|
|
{
|
|
|
|
switch (epid)
|
|
|
|
{
|
2012-01-26 00:04:17 +01:00
|
|
|
case CDCACM_EPINTIN: /* Interrupt IN endpoint */
|
2011-09-27 22:11:14 +02:00
|
|
|
return &g_epintindesc;
|
|
|
|
|
2012-01-26 00:04:17 +01:00
|
|
|
case CDCACM_EPBULKOUT: /* Bulk OUT endpoint */
|
2011-09-27 22:11:14 +02:00
|
|
|
return &g_epbulkoutdesc;
|
|
|
|
|
2012-01-26 00:04:17 +01:00
|
|
|
case CDCACM_EPBULKIN: /* Bulk IN endpoint */
|
2011-09-27 22:11:14 +02:00
|
|
|
return &g_epbulkindesc;
|
|
|
|
|
|
|
|
default:
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************************************************
|
2012-01-26 00:04:17 +01:00
|
|
|
* Name: cdcacm_mkepdesc
|
2011-09-27 22:11:14 +02:00
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* Construct the endpoint descriptor using the correct max packet size.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
#ifdef CONFIG_USBDEV_DUALSPEED
|
2012-01-26 00:04:17 +01:00
|
|
|
void cdcacm_mkepdesc(num cdcacm_epdesc_e epid, uint16_t mxpacket,
|
2011-09-28 00:04:03 +02:00
|
|
|
FAR struct usb_epdesc_s *outdesc)
|
2011-09-27 22:11:14 +02:00
|
|
|
{
|
|
|
|
FAR const struct usb_epdesc_s *indesc;
|
|
|
|
|
|
|
|
/* Copy the "canned" descriptor */
|
|
|
|
|
2012-01-26 00:04:17 +01:00
|
|
|
indesc = cdcacm_getepdesc(epid)
|
2011-09-27 22:11:14 +02:00
|
|
|
memcpy(outdesc, indesc, USB_SIZEOF_EPDESC);
|
|
|
|
|
|
|
|
/* Then add the correct max packet size */
|
|
|
|
|
|
|
|
outdesc->mxpacketsize[0] = LSBYTE(mxpacket);
|
|
|
|
outdesc->mxpacketsize[1] = MSBYTE(mxpacket);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/****************************************************************************
|
2012-01-26 00:04:17 +01:00
|
|
|
* Name: cdcacm_mkcfgdesc
|
2011-09-27 22:11:14 +02:00
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* Construct the configuration descriptor
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
#ifdef CONFIG_USBDEV_DUALSPEED
|
2012-01-26 00:04:17 +01:00
|
|
|
int16_t cdcacm_mkcfgdesc(FAR uint8_t *buf, uint8_t speed, uint8_t type)
|
2011-09-27 22:11:14 +02:00
|
|
|
#else
|
2012-01-26 00:04:17 +01:00
|
|
|
int16_t cdcacm_mkcfgdesc(FAR uint8_t *buf)
|
2011-09-27 22:11:14 +02:00
|
|
|
#endif
|
|
|
|
{
|
|
|
|
FAR const struct cfgdecsc_group_s *group;
|
|
|
|
FAR uint8_t *dest = buf;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
#ifdef CONFIG_USBDEV_DUALSPEED
|
|
|
|
bool hispeed = (speed == USB_SPEED_HIGH);
|
|
|
|
|
|
|
|
/* Check for switches between high and full speed */
|
|
|
|
|
|
|
|
if (type == USB_DESC_TYPE_OTHERSPEEDCONFIG)
|
|
|
|
{
|
|
|
|
hispeed = !hispeed;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/* Copy all of the descriptors in the group */
|
|
|
|
|
2012-01-26 00:04:17 +01:00
|
|
|
for (i = 0, dest = buf; i < CDCACM_CFGGROUP_SIZE; i++)
|
2011-09-27 22:11:14 +02:00
|
|
|
{
|
|
|
|
group = &g_cfggroup[i];
|
|
|
|
|
|
|
|
/* The "canned" descriptors all have full speed endpoint maxpacket
|
|
|
|
* sizes. If high speed is selected, we will have to change the
|
|
|
|
* endpoint maxpacket size.
|
|
|
|
*
|
|
|
|
* Is there a alternative high speed maxpacket size in the table?
|
|
|
|
* If so, that is sufficient proof that the descriptor that we
|
|
|
|
* just copied is an endpoint descriptor and needs the fixup
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifdef CONFIG_USBDEV_DUALSPEED
|
|
|
|
if (highspeed && group->hsepsize != 0)
|
|
|
|
{
|
2012-01-26 00:04:17 +01:00
|
|
|
cdcacm_mkepdesc(group->desc, group->hsepsize,
|
2011-09-27 22:11:14 +02:00
|
|
|
(FAR struct usb_epdesc_s*)dest);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
#endif
|
|
|
|
/* Copy the "canned" descriptor with the full speed max packet
|
|
|
|
* size
|
|
|
|
*/
|
|
|
|
|
|
|
|
{
|
|
|
|
memcpy(dest, group->desc, group->descsize);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Advance to the destination location for the next descriptor */
|
|
|
|
|
|
|
|
dest += group->descsize;
|
|
|
|
}
|
|
|
|
|
2012-01-26 00:04:17 +01:00
|
|
|
return SIZEOF_CDCACM_CFGDESC;
|
2011-09-27 22:11:14 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************************************************
|
2012-01-26 00:04:17 +01:00
|
|
|
* Name: cdcacm_getqualdesc
|
2011-09-27 22:11:14 +02:00
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* Return a pointer to the raw qual descriptor
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
2012-01-26 00:04:17 +01:00
|
|
|
#if !defined(CONFIG_CDCACM_COMPOSITE) && defined(CONFIG_USBDEV_DUALSPEED)
|
|
|
|
FAR const struct usb_qualdesc_s *cdcacm_getqualdesc(void)
|
2011-09-27 22:11:14 +02:00
|
|
|
{
|
|
|
|
return &g_qualdesc;
|
|
|
|
}
|
|
|
|
#endif
|