2016-08-26 17:07:52 +02:00
|
|
|
/****************************************************************************
|
|
|
|
* drivers/usbhost/usbhost_composite.c
|
|
|
|
*
|
2020-08-04 20:34:41 +02:00
|
|
|
* Licensed to the Apache Software Foundation (ASF) under one or more
|
|
|
|
* contributor license agreements. See the NOTICE file distributed with
|
|
|
|
* this work for additional information regarding copyright ownership. The
|
|
|
|
* ASF licenses this file to you under the Apache License, Version 2.0 (the
|
|
|
|
* "License"); you may not use this file except in compliance with the
|
|
|
|
* License. You may obtain a copy of the License at
|
|
|
|
*
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
|
|
|
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
|
|
|
* License for the specific language governing permissions and limitations
|
|
|
|
* under the License.
|
2016-08-26 17:07:52 +02:00
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Included Files
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
#include <nuttx/config.h>
|
|
|
|
|
2016-08-30 18:52:41 +02:00
|
|
|
#include <string.h>
|
2016-08-26 17:47:38 +02:00
|
|
|
#include <assert.h>
|
2016-08-29 15:53:57 +02:00
|
|
|
#include <errno.h>
|
2016-08-26 17:47:38 +02:00
|
|
|
#include <debug.h>
|
|
|
|
|
2016-08-29 15:53:57 +02:00
|
|
|
#include <nuttx/kmalloc.h>
|
2016-08-26 17:07:52 +02:00
|
|
|
#include <nuttx/usb/usbhost.h>
|
|
|
|
|
|
|
|
#include "usbhost_composite.h"
|
|
|
|
|
|
|
|
#ifdef CONFIG_USBHOST_COMPOSITE
|
|
|
|
|
2016-08-30 18:52:41 +02:00
|
|
|
/****************************************************************************
|
|
|
|
* Pre-processor Definitions
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
/* This is the size of a large, allocated temporary buffer that we will use
|
2020-02-23 09:50:23 +01:00
|
|
|
* to construct custom configuration descriptors for each member class.
|
2016-08-30 18:52:41 +02:00
|
|
|
*/
|
|
|
|
|
|
|
|
#define CUSTOM_CONFIG_BUFSIZE \
|
|
|
|
(USB_SIZEOF_CFGDESC + 3 * USB_SIZEOF_IFDESC + 9 * USB_SIZEOF_EPDESC)
|
|
|
|
|
2016-08-26 17:07:52 +02:00
|
|
|
/****************************************************************************
|
|
|
|
* Private Types
|
|
|
|
****************************************************************************/
|
|
|
|
|
2016-08-26 17:47:38 +02:00
|
|
|
/* This structure describes one component class of the composite */
|
|
|
|
|
2016-08-30 18:52:41 +02:00
|
|
|
struct usbhost_member_s
|
2016-08-26 17:47:38 +02:00
|
|
|
{
|
2017-05-11 21:35:56 +02:00
|
|
|
/* This the classobject returned by each contained class */
|
2016-08-26 18:13:35 +02:00
|
|
|
|
2016-08-29 15:53:57 +02:00
|
|
|
FAR struct usbhost_class_s *usbclass;
|
2016-08-26 20:34:58 +02:00
|
|
|
|
|
|
|
/* This is the information that we need to do the registry lookup for this
|
|
|
|
* class member.
|
|
|
|
*/
|
|
|
|
|
2016-08-29 15:53:57 +02:00
|
|
|
struct usbhost_id_s id;
|
2016-08-29 23:02:15 +02:00
|
|
|
|
|
|
|
/* This information will be needed to construct a meaningful configuration
|
|
|
|
* for CLASS_CONNSET()
|
|
|
|
*/
|
|
|
|
|
2016-08-30 18:52:41 +02:00
|
|
|
uint8_t firstif; /* First interface */
|
2016-08-29 23:02:15 +02:00
|
|
|
uint8_t nifs; /* Number of interfaces */
|
2016-08-26 17:47:38 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
/* This structure contains the internal, private state of the USB host
|
|
|
|
* CDC/ACM class.
|
|
|
|
*/
|
|
|
|
|
2016-08-29 15:53:57 +02:00
|
|
|
struct usbhost_composite_s
|
2016-08-26 17:47:38 +02:00
|
|
|
{
|
|
|
|
/* This is the externally visible portion of the state. The usbclass must
|
|
|
|
* the first element of the structure. It is then cast compatible with
|
2016-08-29 15:53:57 +02:00
|
|
|
* struct usbhost_composite_s.
|
2016-08-26 17:47:38 +02:00
|
|
|
*/
|
|
|
|
|
|
|
|
struct usbhost_class_s usbclass;
|
|
|
|
|
|
|
|
/* Class specific data follows */
|
|
|
|
|
|
|
|
uint16_t nclasses; /* Number of component classes in the composite */
|
|
|
|
|
|
|
|
/* The following points to an allocated array of type struct
|
2016-08-30 18:52:41 +02:00
|
|
|
* usbhost_member_s. Element element of the array corresponds to one
|
2016-08-26 17:47:38 +02:00
|
|
|
* component class in the composite.
|
|
|
|
*/
|
|
|
|
|
2016-08-30 18:52:41 +02:00
|
|
|
FAR struct usbhost_member_s *members;
|
2016-08-26 17:47:38 +02:00
|
|
|
};
|
|
|
|
|
2016-08-26 17:07:52 +02:00
|
|
|
/****************************************************************************
|
|
|
|
* Private Function Prototypes
|
|
|
|
****************************************************************************/
|
|
|
|
|
2016-08-26 17:47:38 +02:00
|
|
|
/* struct usbhost_class_s methods */
|
|
|
|
|
|
|
|
static int usbhost_connect(FAR struct usbhost_class_s *usbclass,
|
|
|
|
FAR const uint8_t *configdesc, int desclen);
|
|
|
|
static int usbhost_disconnected(FAR struct usbhost_class_s *usbclass);
|
|
|
|
|
2016-08-26 17:07:52 +02:00
|
|
|
/****************************************************************************
|
|
|
|
* Private Functions
|
|
|
|
****************************************************************************/
|
|
|
|
|
2016-08-26 18:13:35 +02:00
|
|
|
/****************************************************************************
|
|
|
|
* Name: usbhost_disconnect_all
|
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* Disconnect all contained class instances.
|
|
|
|
*
|
|
|
|
* Input Parameters:
|
2020-02-22 19:31:14 +01:00
|
|
|
* priv - Reference to private, composite container state structure.
|
2016-08-26 18:13:35 +02:00
|
|
|
*
|
|
|
|
* Returned Value:
|
|
|
|
* None
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
2016-08-29 15:53:57 +02:00
|
|
|
static void usbhost_disconnect_all(FAR struct usbhost_composite_s *priv)
|
2016-08-26 18:13:35 +02:00
|
|
|
{
|
2016-08-30 18:52:41 +02:00
|
|
|
FAR struct usbhost_member_s *member;
|
2016-08-29 15:53:57 +02:00
|
|
|
int i;
|
2016-08-26 18:13:35 +02:00
|
|
|
|
|
|
|
/* Loop, processing each class that has been included into the composite */
|
|
|
|
|
2016-08-29 15:53:57 +02:00
|
|
|
for (i = 0; i < priv->nclasses; i++)
|
2016-08-26 18:13:35 +02:00
|
|
|
{
|
|
|
|
member = &priv->members[i];
|
|
|
|
|
|
|
|
/* Has this member been included to the composite? */
|
|
|
|
|
|
|
|
if (member->usbclass != NULL)
|
|
|
|
{
|
|
|
|
/* Yes.. disconnect it, freeing all of the class resources */
|
|
|
|
|
|
|
|
CLASS_DISCONNECTED(member->usbclass);
|
|
|
|
member->usbclass = NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-08-26 17:47:38 +02:00
|
|
|
/****************************************************************************
|
|
|
|
* Name: usbhost_connect
|
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* This function implements the connect() method of struct
|
|
|
|
* usbhost_class_s. This method is a callback into the class
|
2016-08-28 16:33:38 +02:00
|
|
|
* implementation from the common enumeration logic. It is normally used
|
|
|
|
* to provide the device's configuration descriptor to the class so that
|
|
|
|
* the class may initialize properly. That calling sequence is:
|
|
|
|
*
|
|
|
|
* 1. usbhost_enumerate()
|
|
|
|
* 2. usbhost_classbind()
|
|
|
|
* 3. CLASS_CONNECT()
|
|
|
|
*
|
|
|
|
* However, that applies only to the Non-composite device.
|
|
|
|
* usbhost_classbind() is not called for the composite device and, hence,
|
|
|
|
* this method is never called. Rather, the composite logic calls
|
|
|
|
* CLASS_CONNECT() for each member of the composite in a calling sequence
|
|
|
|
* like:
|
|
|
|
*
|
|
|
|
* 1. usbhost_enumerate()
|
|
|
|
* 2. usbhost_composite()
|
|
|
|
* 3. Call CLASS_CONNECT() for each composite member
|
2016-08-26 17:47:38 +02:00
|
|
|
*
|
|
|
|
* Input Parameters:
|
|
|
|
* usbclass - The USB host class entry previously obtained from a call to
|
|
|
|
* create().
|
|
|
|
* configdesc - A pointer to a uint8_t buffer container the configuration
|
|
|
|
* descriptor.
|
|
|
|
* desclen - The length in bytes of the configuration descriptor.
|
|
|
|
*
|
|
|
|
* Returned Value:
|
2020-08-04 20:34:41 +02:00
|
|
|
* On success, zero (OK) is returned. On a failure, a negated errno value
|
|
|
|
* is returned indicating the nature of the failure
|
2016-08-26 17:47:38 +02:00
|
|
|
*
|
2020-08-04 20:34:41 +02:00
|
|
|
* NOTE that the class instance remains valid upon return with a failure.
|
|
|
|
* It is the responsibility of the higher level enumeration logic to call
|
2016-08-26 17:47:38 +02:00
|
|
|
* CLASS_DISCONNECTED to free up the class driver resources.
|
|
|
|
*
|
|
|
|
* Assumptions:
|
|
|
|
* - This function will *not* be called from an interrupt handler.
|
|
|
|
* - If this function returns an error, the USB host controller driver
|
|
|
|
* must call to DISCONNECTED method to recover from the error
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
static int usbhost_connect(FAR struct usbhost_class_s *usbclass,
|
|
|
|
FAR const uint8_t *configdesc, int desclen)
|
|
|
|
{
|
2016-08-28 16:33:38 +02:00
|
|
|
return -ENOSYS;
|
2016-08-26 17:47:38 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Name: usbhost_disconnected
|
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* This function implements the disconnected() method of struct
|
|
|
|
* usbhost_class_s. This method is a callback into the class
|
|
|
|
* implementation. It is used to inform the class that the USB device has
|
|
|
|
* been disconnected.
|
|
|
|
*
|
|
|
|
* Input Parameters:
|
|
|
|
* usbclass - The USB host class entry previously obtained from a call to
|
|
|
|
* create().
|
|
|
|
*
|
|
|
|
* Returned Value:
|
|
|
|
* On success, zero (OK) is returned. On a failure, a negated errno value
|
|
|
|
* is returned indicating the nature of the failure
|
|
|
|
*
|
|
|
|
* Assumptions:
|
|
|
|
* This function may be called from an interrupt handler.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
static int usbhost_disconnected(struct usbhost_class_s *usbclass)
|
|
|
|
{
|
2020-08-04 20:34:41 +02:00
|
|
|
FAR struct usbhost_composite_s *priv =
|
|
|
|
(FAR struct usbhost_composite_s *)usbclass;
|
2016-08-26 17:47:38 +02:00
|
|
|
|
|
|
|
DEBUGASSERT(priv != NULL);
|
|
|
|
|
|
|
|
/* Forward the disconnect event to each contained class in the composite. */
|
|
|
|
|
2016-08-26 18:33:41 +02:00
|
|
|
usbhost_disconnect_all(priv);
|
|
|
|
|
|
|
|
/* Free the allocate array of composite members */
|
|
|
|
|
|
|
|
if (priv->members != NULL)
|
|
|
|
{
|
|
|
|
kmm_free(priv->members);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* The destroy the composite container itself */
|
2016-08-26 17:47:38 +02:00
|
|
|
|
|
|
|
kmm_free(priv);
|
|
|
|
return OK;
|
|
|
|
}
|
|
|
|
|
2016-08-30 18:52:41 +02:00
|
|
|
/****************************************************************************
|
|
|
|
* Name: usbhost_copyinterface
|
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* Find an interface descriptor and copy it along with all of its
|
2019-06-21 14:57:17 +02:00
|
|
|
* following endpoint and cs interface descriptors.
|
2016-08-30 18:52:41 +02:00
|
|
|
*
|
|
|
|
* Input Parameters:
|
2019-06-21 14:57:17 +02:00
|
|
|
* ifno - The interface ID to find.
|
2016-08-30 18:52:41 +02:00
|
|
|
* configdesc - The original configuration descriptor that contains the
|
|
|
|
* the interface descriptor.
|
|
|
|
* desclen - the length of configdesc.
|
|
|
|
* buffer - The buffer in which to return the descriptors
|
|
|
|
* buflen - The length of buffer
|
|
|
|
*
|
|
|
|
* Returned Value:
|
|
|
|
* On success, the number of bytes copied is returned. On a failure, a
|
|
|
|
* negated errno value is returned indicating the nature of the failure:
|
|
|
|
*
|
|
|
|
* -ENOENT: Did not find interface descriptor
|
|
|
|
* -EINVAL: Did not find all endpoint descriptors
|
2019-06-21 14:57:17 +02:00
|
|
|
* -ENOSPC: Provided buffer too small to hold all found descriptors
|
2016-08-30 18:52:41 +02:00
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
static int usbhost_copyinterface(uint8_t ifno, FAR const uint8_t *configdesc,
|
2020-08-04 20:34:41 +02:00
|
|
|
int desclen, FAR uint8_t *buffer,
|
|
|
|
int buflen)
|
2016-08-30 18:52:41 +02:00
|
|
|
{
|
2019-06-21 14:57:17 +02:00
|
|
|
FAR struct usb_desc_s *desc;
|
2016-08-30 18:52:41 +02:00
|
|
|
FAR struct usb_ifdesc_s *ifdesc;
|
|
|
|
int retsize;
|
|
|
|
int offset;
|
|
|
|
int neps;
|
|
|
|
int len;
|
|
|
|
|
|
|
|
/* Make sure that the buffer will hold at least the interface descriptor */
|
|
|
|
|
|
|
|
if (buflen < USB_SIZEOF_IFDESC)
|
|
|
|
{
|
|
|
|
return -ENOSPC;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Search for the interface */
|
|
|
|
|
|
|
|
for (offset = 0, retsize = 0;
|
2019-06-21 14:57:17 +02:00
|
|
|
offset < desclen - sizeof(struct usb_desc_s);
|
2016-08-30 18:52:41 +02:00
|
|
|
offset += len)
|
|
|
|
{
|
2019-06-21 14:57:17 +02:00
|
|
|
desc = (FAR struct usb_desc_s *)&configdesc[offset];
|
|
|
|
len = desc->len;
|
2016-08-30 18:52:41 +02:00
|
|
|
|
2019-06-21 14:57:17 +02:00
|
|
|
/* Is this an interface descriptor? */
|
2016-08-30 18:52:41 +02:00
|
|
|
|
2019-06-21 14:57:17 +02:00
|
|
|
if (desc->type == USB_DESC_TYPE_INTERFACE)
|
2016-08-30 18:52:41 +02:00
|
|
|
{
|
2019-06-21 14:57:17 +02:00
|
|
|
ifdesc = (FAR struct usb_ifdesc_s *)&configdesc[offset];
|
2016-08-30 18:52:41 +02:00
|
|
|
|
2019-06-21 14:57:17 +02:00
|
|
|
/* Is it the one we are looking for? */
|
2016-08-30 18:52:41 +02:00
|
|
|
|
2019-06-21 14:57:17 +02:00
|
|
|
if (ifdesc->ifno == ifno && ifdesc->neps != 0)
|
2016-08-30 18:52:41 +02:00
|
|
|
{
|
2019-06-21 14:57:17 +02:00
|
|
|
/* Yes.. return the interface descriptor */
|
2016-08-30 18:52:41 +02:00
|
|
|
|
2019-06-21 14:57:17 +02:00
|
|
|
memcpy(buffer, desc, len);
|
|
|
|
buffer += len;
|
|
|
|
buflen -= len;
|
|
|
|
retsize += len;
|
2016-08-30 18:52:41 +02:00
|
|
|
|
2019-06-21 14:57:17 +02:00
|
|
|
/* Make sure that the buffer will hold at least the endpoint
|
|
|
|
* descriptors.
|
|
|
|
*/
|
|
|
|
|
|
|
|
neps = ifdesc->neps;
|
|
|
|
if (buflen < neps * USB_SIZEOF_EPDESC)
|
|
|
|
{
|
|
|
|
return -ENOSPC;
|
|
|
|
}
|
2016-08-30 18:52:41 +02:00
|
|
|
|
2019-06-21 14:57:17 +02:00
|
|
|
/* The CS and endpoint descriptors should immediately
|
|
|
|
* follow the interface descriptor.
|
|
|
|
*/
|
2016-08-30 18:52:41 +02:00
|
|
|
|
2019-06-21 14:57:17 +02:00
|
|
|
for (offset += len;
|
|
|
|
offset < desclen - sizeof(struct usb_desc_s);
|
|
|
|
offset += len)
|
2016-08-30 18:52:41 +02:00
|
|
|
{
|
2019-06-21 14:57:17 +02:00
|
|
|
desc = (FAR struct usb_desc_s *)&configdesc[offset];
|
|
|
|
len = desc->len;
|
|
|
|
|
|
|
|
/* Is this a class-specific interface descriptor? */
|
|
|
|
|
|
|
|
if (desc->type == USB_DESC_TYPE_CSINTERFACE)
|
|
|
|
{
|
|
|
|
/* Yes... return the descriptor */
|
|
|
|
|
|
|
|
if (buflen < len)
|
|
|
|
{
|
|
|
|
return -ENOSPC;
|
|
|
|
}
|
2016-08-30 18:52:41 +02:00
|
|
|
|
2019-06-21 14:57:17 +02:00
|
|
|
memcpy(buffer, desc, len);
|
|
|
|
buffer += len;
|
|
|
|
buflen -= len;
|
|
|
|
retsize += len;
|
|
|
|
}
|
2016-08-30 18:52:41 +02:00
|
|
|
|
2019-06-21 14:57:17 +02:00
|
|
|
/* Is this an endpoint descriptor? */
|
2016-08-30 18:52:41 +02:00
|
|
|
|
2019-06-21 14:57:17 +02:00
|
|
|
else if (desc->type == USB_DESC_TYPE_ENDPOINT)
|
2016-08-30 18:52:41 +02:00
|
|
|
{
|
2019-06-21 14:57:17 +02:00
|
|
|
/* Yes.. return the endpoint descriptor */
|
|
|
|
|
|
|
|
if (buflen < len)
|
|
|
|
{
|
|
|
|
return -ENOSPC;
|
|
|
|
}
|
|
|
|
|
|
|
|
memcpy(buffer, desc, len);
|
|
|
|
buffer += len;
|
|
|
|
buflen -= len;
|
|
|
|
retsize += len;
|
2016-08-30 18:52:41 +02:00
|
|
|
|
2020-08-04 20:34:41 +02:00
|
|
|
/* And reduce the number of endpoints we are looking
|
|
|
|
* for.
|
|
|
|
*/
|
2019-06-21 14:57:17 +02:00
|
|
|
|
|
|
|
if (--neps <= 0)
|
|
|
|
{
|
2020-08-04 20:34:41 +02:00
|
|
|
/* That is all of them! Return the total size
|
|
|
|
* copied.
|
|
|
|
*/
|
2019-06-21 14:57:17 +02:00
|
|
|
|
|
|
|
return retsize;
|
|
|
|
}
|
2016-08-30 18:52:41 +02:00
|
|
|
}
|
2016-08-30 21:58:01 +02:00
|
|
|
|
2020-08-04 20:34:41 +02:00
|
|
|
/* The endpoint descriptors following the interface
|
|
|
|
* descriptor should all be contiguous. But we will
|
|
|
|
* complain only if another interface descriptor is
|
|
|
|
* encountered before all of the endpoint descriptors have
|
|
|
|
* been found.
|
2019-06-21 14:57:17 +02:00
|
|
|
*/
|
2016-08-30 21:58:01 +02:00
|
|
|
|
2019-06-21 14:57:17 +02:00
|
|
|
else if (desc->type == USB_DESC_TYPE_INTERFACE)
|
|
|
|
{
|
|
|
|
break;
|
|
|
|
}
|
2016-08-30 21:58:01 +02:00
|
|
|
}
|
2016-08-30 18:52:41 +02:00
|
|
|
|
2019-06-21 14:57:17 +02:00
|
|
|
/* Did not find all of the interface descriptors */
|
2016-08-30 18:52:41 +02:00
|
|
|
|
2019-06-21 14:57:17 +02:00
|
|
|
return -EINVAL;
|
|
|
|
}
|
2016-08-30 18:52:41 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Could not find the interface descriptor */
|
|
|
|
|
|
|
|
return -ENOENT;
|
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Name: usbhost_createconfig
|
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* Create a custom configuration for a member class.
|
|
|
|
*
|
|
|
|
* Input Parameters:
|
|
|
|
* configdesc - The original configuration descriptor that contains the
|
|
|
|
* the interface descriptor.
|
|
|
|
* desclen - the length of configdesc.
|
|
|
|
* buffer - The buffer in which to return the descriptors
|
|
|
|
* buflen - The length of buffer
|
|
|
|
*
|
|
|
|
* Returned Value:
|
|
|
|
* On success, the size of the new configuration descriptor is returned.
|
|
|
|
* On a failure, a negated errno value is returned indicating the nature
|
|
|
|
* of the failure:
|
|
|
|
*
|
|
|
|
* -ENOENT: Did not find interface descriptor
|
|
|
|
* -EINVAL: Did not find all endpoint descriptors
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
static int usbhost_createconfig(FAR struct usbhost_member_s *member,
|
|
|
|
FAR const uint8_t *configdesc, int desclen,
|
|
|
|
FAR uint8_t *buffer, int buflen)
|
|
|
|
{
|
|
|
|
FAR struct usb_cfgdesc_s *cfgdesc;
|
|
|
|
int cfgsize;
|
|
|
|
int ifsize;
|
|
|
|
int ifno;
|
|
|
|
int nifs;
|
|
|
|
|
|
|
|
/* Copy and modify the original configuration descriptor */
|
|
|
|
|
|
|
|
if (buflen < USB_SIZEOF_CFGDESC)
|
|
|
|
{
|
|
|
|
return -ENOSPC;
|
|
|
|
}
|
|
|
|
|
|
|
|
memcpy(buffer, configdesc, USB_SIZEOF_CFGDESC);
|
2019-06-22 15:27:15 +02:00
|
|
|
cfgdesc = (FAR struct usb_cfgdesc_s *)buffer;
|
2016-08-30 18:52:41 +02:00
|
|
|
cfgsize = USB_SIZEOF_CFGDESC;
|
|
|
|
buffer += USB_SIZEOF_CFGDESC;
|
|
|
|
buflen -= USB_SIZEOF_CFGDESC;
|
|
|
|
|
|
|
|
/* Modify the copied configuration descriptor */
|
|
|
|
|
|
|
|
cfgdesc->len = USB_SIZEOF_CFGDESC;
|
|
|
|
cfgdesc->ninterfaces = member->nifs;
|
|
|
|
|
|
|
|
/* Then copy all of the interfaces to the configuration buffer */
|
|
|
|
|
|
|
|
for (nifs = 0, ifno = member->firstif; nifs < member->nifs; nifs++, ifno++)
|
|
|
|
{
|
|
|
|
ifsize = usbhost_copyinterface(ifno, configdesc, desclen,
|
|
|
|
buffer, buflen);
|
|
|
|
if (ifsize < 0)
|
|
|
|
{
|
2019-06-21 14:57:17 +02:00
|
|
|
uerr("ERROR: Failed to copy interface: %d\n", ifsize);
|
2016-08-30 18:52:41 +02:00
|
|
|
return ifsize;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Update sizes and pointers */
|
|
|
|
|
|
|
|
cfgsize += ifsize;
|
|
|
|
buffer += ifsize;
|
|
|
|
buflen -= ifsize;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Set the totallen of the configuration descriptor and return success */
|
|
|
|
|
|
|
|
cfgdesc->totallen[0] = cfgsize & 0xff; /* Little endian always */
|
|
|
|
cfgdesc->totallen[1] = cfgsize >> 8;
|
|
|
|
return cfgsize;
|
|
|
|
}
|
|
|
|
|
2016-08-26 17:07:52 +02:00
|
|
|
/****************************************************************************
|
|
|
|
* Public Functions
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Name: usbhost_composite
|
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* As the final steps in the device enumeration sequence this function
|
|
|
|
* will be called in order to determine (1) determine if the device is
|
|
|
|
* a composite device, and if so, (2) create the composite class which
|
|
|
|
* contains all of the individual class instances making up the composite.
|
|
|
|
*
|
|
|
|
* Input Parameters:
|
|
|
|
* hport - The downstream port to which the (potential) composite
|
|
|
|
* device has been connected.
|
|
|
|
* configdesc - The full configuration descriptor
|
|
|
|
* desclen - The length of the configuration descriptor
|
2016-08-27 18:31:18 +02:00
|
|
|
* id - Lookup information extracted from the device descriptor.
|
|
|
|
* for the case of the composite devices, we need only the
|
|
|
|
* vid and pid.
|
2016-08-26 18:13:35 +02:00
|
|
|
* usbclass - If the class driver for the device is successful located
|
2016-08-26 17:07:52 +02:00
|
|
|
* and bound to the hub port, the allocated class instance
|
|
|
|
* is returned into this caller-provided memory location.
|
|
|
|
*
|
|
|
|
* Returned Value:
|
|
|
|
* Zero (OK) is returned if (1) the device was determined to be a
|
2018-09-14 14:55:45 +02:00
|
|
|
* composite device and (2) the composite class wrapper was successfully
|
2016-08-26 17:07:52 +02:00
|
|
|
* created and bound to the HCD. A negated errno value is returned on
|
|
|
|
* any failure. The value -ENOENT, in particular means that the attached
|
|
|
|
* device is not a composite device. Other values would indicate other
|
|
|
|
* various, unexpected failures.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
int usbhost_composite(FAR struct usbhost_hubport_s *hport,
|
|
|
|
FAR const uint8_t *configdesc, int desclen,
|
2016-08-27 18:31:18 +02:00
|
|
|
FAR struct usbhost_id_s *id,
|
2016-08-26 18:13:35 +02:00
|
|
|
FAR struct usbhost_class_s **usbclass)
|
2016-08-26 17:07:52 +02:00
|
|
|
{
|
2016-08-29 15:53:57 +02:00
|
|
|
FAR struct usbhost_composite_s *priv;
|
2016-08-30 18:52:41 +02:00
|
|
|
FAR struct usbhost_member_s *member;
|
2016-08-26 20:24:35 +02:00
|
|
|
FAR const struct usbhost_registry_s *reg;
|
2016-08-27 01:03:16 +02:00
|
|
|
FAR struct usb_desc_s *desc;
|
2016-08-30 18:52:41 +02:00
|
|
|
FAR uint8_t *cfgbuffer;
|
2016-08-27 18:31:18 +02:00
|
|
|
uint32_t mergeset;
|
2016-08-27 01:03:16 +02:00
|
|
|
uint16_t nintfs;
|
|
|
|
uint16_t nmerged;
|
2016-08-26 17:47:38 +02:00
|
|
|
uint16_t nclasses;
|
2016-08-30 18:52:41 +02:00
|
|
|
int cfgsize;
|
2016-08-27 01:03:16 +02:00
|
|
|
int offset;
|
2016-08-29 15:53:57 +02:00
|
|
|
int ret;
|
2016-08-26 17:47:38 +02:00
|
|
|
int i;
|
|
|
|
|
2016-08-26 17:07:52 +02:00
|
|
|
/* Determine if this a composite device has been connected to the
|
|
|
|
* downstream port.
|
2016-08-27 01:03:16 +02:00
|
|
|
*
|
2016-08-27 18:53:43 +02:00
|
|
|
* First look at there device descriptor information. A composite
|
|
|
|
* device is only possible if:
|
|
|
|
*
|
|
|
|
* 1. Manufacturers of composite devices typically assign a value of zero
|
|
|
|
* to the device class (bDeviceClass), subclass (bDeviceSubClass), and
|
|
|
|
* protocol (bDeviceProtocol) fields in the device descriptor, as
|
|
|
|
* specified by the Universal Serial Bus Specification. This allows
|
|
|
|
* the manufacturer to associate each individual interface with a
|
|
|
|
* different device class and protocol.
|
|
|
|
*
|
|
|
|
* 2. The USB-IF core team has devised a special class and protocol code
|
|
|
|
* set that notifies the operating system that one or more IADs are
|
|
|
|
* present in device firmware. A device's device descriptor must have
|
|
|
|
* the values that appear in the following table:
|
|
|
|
*
|
|
|
|
* bDeviceClass 0xEF
|
|
|
|
* bDeviceSubClass 0x02
|
|
|
|
* bDeviceProtocol 0x01
|
|
|
|
*/
|
|
|
|
|
2020-08-04 20:34:41 +02:00
|
|
|
if (id->base != USB_CLASS_PER_INTERFACE && id->base != USB_CLASS_MISC)
|
|
|
|
{
|
|
|
|
return -ENOENT;
|
|
|
|
}
|
2016-08-27 18:53:43 +02:00
|
|
|
|
|
|
|
/* First, count the number of interface descriptors (nintfs) and the
|
2020-02-23 09:50:23 +01:00
|
|
|
* number of interfaces that are associated to one device via IAD
|
2016-08-27 01:03:16 +02:00
|
|
|
* descriptor (nmerged).
|
2016-08-26 17:07:52 +02:00
|
|
|
*/
|
|
|
|
|
2016-08-29 15:53:57 +02:00
|
|
|
mergeset = 0;
|
2016-08-27 18:31:18 +02:00
|
|
|
nintfs = 0;
|
|
|
|
nmerged = 0;
|
|
|
|
|
|
|
|
for (offset = 0; offset < desclen - sizeof(struct usb_desc_s); )
|
2016-08-27 01:03:16 +02:00
|
|
|
{
|
|
|
|
desc = (FAR struct usb_desc_s *)&configdesc[offset];
|
|
|
|
int len = desc->len;
|
|
|
|
|
2016-08-31 21:24:38 +02:00
|
|
|
if (offset + len <= desclen)
|
2016-08-27 01:03:16 +02:00
|
|
|
{
|
|
|
|
/* Is this an interface descriptor? */
|
|
|
|
|
|
|
|
if (desc->type == USB_DESC_TYPE_INTERFACE)
|
|
|
|
{
|
2016-08-30 18:52:41 +02:00
|
|
|
#ifdef CONFIG_DEBUG_ASSERTIONS
|
2016-08-27 18:31:18 +02:00
|
|
|
FAR struct usb_ifdesc_s *ifdesc =
|
|
|
|
(FAR struct usb_ifdesc_s *)desc;
|
|
|
|
|
2016-08-31 21:29:38 +02:00
|
|
|
DEBUGASSERT(ifdesc->ifno < 32);
|
2016-08-30 18:52:41 +02:00
|
|
|
#endif
|
|
|
|
/* Increment the count of interfaces */
|
|
|
|
|
2016-08-27 01:03:16 +02:00
|
|
|
nintfs++;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Check for IAD descriptors that will be used when it is
|
|
|
|
* necessary to associate multiple interfaces with a single
|
2016-08-31 16:16:12 +02:00
|
|
|
* class driver.
|
2016-08-27 01:03:16 +02:00
|
|
|
*/
|
|
|
|
|
2020-08-04 20:34:41 +02:00
|
|
|
else if (desc->type == USB_DESC_TYPE_INTERFACEASSOCIATION)
|
|
|
|
{
|
|
|
|
FAR struct usb_iaddesc_s *iad =
|
|
|
|
(FAR struct usb_iaddesc_s *)desc;
|
2016-08-27 18:31:18 +02:00
|
|
|
uint32_t mask;
|
|
|
|
|
2016-08-31 16:16:12 +02:00
|
|
|
/* Keep count of the number of interfaces that will be merged */
|
2016-08-27 01:03:16 +02:00
|
|
|
|
2016-08-27 18:31:18 +02:00
|
|
|
nmerged += (iad->nifs - 1);
|
2016-08-27 01:03:16 +02:00
|
|
|
|
2016-08-30 18:52:41 +02:00
|
|
|
/* Keep track of which interfaces will be merged */
|
2016-08-27 18:31:18 +02:00
|
|
|
|
|
|
|
DEBUGASSERT(iad->firstif + iad->nifs < 32);
|
2016-08-29 15:53:57 +02:00
|
|
|
mask = (1 << iad->nifs) - 1;
|
|
|
|
mergeset |= mask << iad->firstif;
|
2020-08-04 20:34:41 +02:00
|
|
|
}
|
2016-08-27 01:03:16 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
offset += len;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (nintfs < 2)
|
|
|
|
{
|
2016-08-28 16:33:38 +02:00
|
|
|
/* Only one interface descriptor. Can't be a composite device */
|
2016-08-27 01:03:16 +02:00
|
|
|
|
|
|
|
return -ENOENT;
|
|
|
|
}
|
|
|
|
|
2016-08-27 18:53:43 +02:00
|
|
|
#if 0 /* I think not needed, the device descriptor classid check should handle this */
|
|
|
|
/* Special case: Some NON-composite device have more than on interface: CDC/ACM
|
2016-08-27 01:03:16 +02:00
|
|
|
* and MSC both may have two interfaces.
|
2016-08-26 17:07:52 +02:00
|
|
|
*/
|
2016-08-27 01:03:16 +02:00
|
|
|
|
|
|
|
if (nintfs < 3 && nmerged == 0)
|
|
|
|
{
|
|
|
|
/* Do the special case checks */
|
2016-08-26 18:33:41 +02:00
|
|
|
#warning Missing logic
|
2016-08-27 01:03:16 +02:00
|
|
|
}
|
2016-08-27 18:53:43 +02:00
|
|
|
#endif
|
2016-08-27 01:03:16 +02:00
|
|
|
|
|
|
|
/* The total number of classes is then the number of interfaces minus the
|
|
|
|
* number of interfaces merged via the IAD descriptor.
|
|
|
|
*/
|
|
|
|
|
2016-08-31 16:16:12 +02:00
|
|
|
if (nintfs <= nmerged)
|
2016-08-27 01:03:16 +02:00
|
|
|
{
|
|
|
|
/* Should not happen. Means a bug. */
|
|
|
|
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
nclasses = nintfs - nmerged;
|
2016-08-26 17:07:52 +02:00
|
|
|
|
|
|
|
/* Allocate the composite class container */
|
|
|
|
|
2016-08-29 15:53:57 +02:00
|
|
|
priv = (FAR struct usbhost_composite_s *)
|
|
|
|
kmm_zalloc(sizeof(struct usbhost_composite_s));
|
2016-08-26 17:47:38 +02:00
|
|
|
|
|
|
|
if (priv == NULL)
|
|
|
|
{
|
2016-10-18 19:52:23 +02:00
|
|
|
uerr("ERROR: Failed to allocate class container\n");
|
2016-08-26 17:47:38 +02:00
|
|
|
return -ENOMEM;
|
|
|
|
}
|
|
|
|
|
2016-08-30 18:52:41 +02:00
|
|
|
priv->members = (FAR struct usbhost_member_s *)
|
|
|
|
kmm_zalloc(nclasses * sizeof(struct usbhost_member_s));
|
2016-08-26 17:47:38 +02:00
|
|
|
|
|
|
|
if (priv->members == NULL)
|
|
|
|
{
|
2016-10-18 19:52:23 +02:00
|
|
|
uerr("ERROR: Failed to allocate class members\n");
|
2016-08-26 18:13:35 +02:00
|
|
|
ret = -ENOMEM;
|
|
|
|
goto errout_with_container;
|
2016-08-26 17:47:38 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Initialize the non-zero elements of the class container */
|
|
|
|
|
|
|
|
priv->usbclass.hport = hport;
|
|
|
|
priv->usbclass.connect = usbhost_connect;
|
|
|
|
priv->usbclass.disconnected = usbhost_disconnected;
|
|
|
|
priv->nclasses = nclasses;
|
|
|
|
|
2016-08-27 18:31:18 +02:00
|
|
|
/* Re-parse the configuration descriptor and save the CLASS ID information
|
2016-08-27 01:03:16 +02:00
|
|
|
* in the member structure: If the interface is defined by an interface
|
|
|
|
* descriptor, then we have to use the info in the interface descriptor;
|
|
|
|
* If the interface has a IAD, we have to use info in the IAD.
|
|
|
|
*/
|
2016-08-27 18:31:18 +02:00
|
|
|
|
|
|
|
for (i = 0, offset = 0; offset < desclen - sizeof(struct usb_desc_s); )
|
|
|
|
{
|
|
|
|
desc = (FAR struct usb_desc_s *)&configdesc[offset];
|
|
|
|
int len = desc->len;
|
|
|
|
|
2016-08-31 21:24:38 +02:00
|
|
|
if (offset + len <= desclen)
|
2016-08-27 18:31:18 +02:00
|
|
|
{
|
|
|
|
/* Is this an interface descriptor? */
|
|
|
|
|
|
|
|
if (desc->type == USB_DESC_TYPE_INTERFACE)
|
|
|
|
{
|
|
|
|
FAR struct usb_ifdesc_s *ifdesc =
|
|
|
|
(FAR struct usb_ifdesc_s *)desc;
|
|
|
|
|
|
|
|
/* Was the interface merged via an IAD descriptor? */
|
|
|
|
|
2016-08-31 21:29:38 +02:00
|
|
|
DEBUGASSERT(ifdesc->ifno < 32);
|
|
|
|
if ((mergeset & (1 << ifdesc->ifno)) == 0)
|
2016-08-27 18:31:18 +02:00
|
|
|
{
|
|
|
|
/* No, this interface was not merged. Save the registry
|
|
|
|
* lookup information from the interface descriptor.
|
|
|
|
*/
|
|
|
|
|
2020-08-04 20:34:41 +02:00
|
|
|
member = (FAR struct usbhost_member_s *)
|
|
|
|
&priv->members[i];
|
2016-08-30 18:52:41 +02:00
|
|
|
member->id.base = ifdesc->classid;
|
|
|
|
member->id.subclass = ifdesc->subclass;
|
|
|
|
member->id.proto = ifdesc->protocol;
|
|
|
|
member->id.vid = id->vid;
|
|
|
|
member->id.pid = id->pid;
|
2016-08-27 18:31:18 +02:00
|
|
|
|
2016-08-31 21:29:38 +02:00
|
|
|
member->firstif = ifdesc->ifno;
|
2016-08-30 18:52:41 +02:00
|
|
|
member->nifs = 1;
|
2016-08-27 18:31:18 +02:00
|
|
|
|
2016-08-29 23:02:15 +02:00
|
|
|
/* Increment the member index */
|
|
|
|
|
|
|
|
i++;
|
2016-08-27 18:31:18 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Check for IAD descriptors that will be used when it is
|
|
|
|
* necessary to associate multiple interfaces with a single
|
|
|
|
* device.
|
|
|
|
*/
|
|
|
|
|
|
|
|
else if (desc->type == USB_DESC_TYPE_INTERFACEASSOCIATION)
|
|
|
|
{
|
2020-08-04 20:34:41 +02:00
|
|
|
FAR struct usb_iaddesc_s *iad =
|
|
|
|
(FAR struct usb_iaddesc_s *)desc;
|
2016-08-27 18:31:18 +02:00
|
|
|
|
2016-08-29 15:53:57 +02:00
|
|
|
/* Yes.. Save the registry lookup information from the IAD. */
|
2016-08-27 18:31:18 +02:00
|
|
|
|
2020-08-04 20:34:41 +02:00
|
|
|
member = (FAR struct usbhost_member_s *)
|
|
|
|
&priv->members[i];
|
2016-08-30 18:52:41 +02:00
|
|
|
member->id.base = iad->classid;
|
|
|
|
member->id.subclass = iad->subclass;
|
|
|
|
member->id.proto = iad->protocol;
|
|
|
|
member->id.vid = id->vid;
|
|
|
|
member->id.pid = id->pid;
|
2016-08-27 18:31:18 +02:00
|
|
|
|
2016-08-30 18:52:41 +02:00
|
|
|
member->firstif = iad->firstif;
|
|
|
|
member->nifs = iad->nifs;
|
2016-08-29 23:02:15 +02:00
|
|
|
|
2016-08-29 15:53:57 +02:00
|
|
|
/* Increment the member index */
|
2016-08-27 18:31:18 +02:00
|
|
|
|
2016-08-29 15:53:57 +02:00
|
|
|
i++;
|
2016-08-27 18:31:18 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
offset += len;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* If everything worked, the final index must be the same as the pre-
|
|
|
|
* calculated number of member classes.
|
|
|
|
*/
|
|
|
|
|
|
|
|
DEBUGASSERT(i == nclasses);
|
2016-08-27 01:03:16 +02:00
|
|
|
|
2016-08-31 16:16:12 +02:00
|
|
|
/* Allocate a temporary buffer in which we can construct a custom
|
|
|
|
* configuration descriptor for each member class.
|
2016-08-29 22:55:03 +02:00
|
|
|
*/
|
|
|
|
|
2023-08-28 09:39:47 +02:00
|
|
|
cfgbuffer = kmm_malloc(CUSTOM_CONFIG_BUFSIZE);
|
2016-08-30 18:52:41 +02:00
|
|
|
if (cfgbuffer == NULL)
|
|
|
|
{
|
2016-08-31 21:24:38 +02:00
|
|
|
uerr("ERROR: Failed to allocate configuration buffer");
|
2016-08-30 18:52:41 +02:00
|
|
|
ret = -ENOMEM;
|
|
|
|
goto errout_with_members;
|
|
|
|
}
|
|
|
|
|
2016-08-28 16:48:40 +02:00
|
|
|
/* Now loop, performing the registry lookup and initialization of each
|
|
|
|
* member class in the composite.
|
2016-08-27 01:03:16 +02:00
|
|
|
*/
|
2016-08-26 17:07:52 +02:00
|
|
|
|
2016-08-26 17:47:38 +02:00
|
|
|
for (i = 0; i < nclasses; i++)
|
|
|
|
{
|
|
|
|
member = &priv->members[i];
|
|
|
|
|
2016-08-26 20:24:35 +02:00
|
|
|
/* Is there is a class implementation registered to support this
|
|
|
|
* device.
|
|
|
|
*/
|
2016-08-26 17:47:38 +02:00
|
|
|
|
2016-08-29 15:53:57 +02:00
|
|
|
reg = usbhost_findclass(&member->id);
|
2016-08-26 20:24:35 +02:00
|
|
|
if (reg == NULL)
|
2016-08-26 18:33:41 +02:00
|
|
|
{
|
2016-08-30 18:52:41 +02:00
|
|
|
uerr("ERROR: usbhost_findclass failed\n");
|
2016-08-31 15:56:27 +02:00
|
|
|
#ifdef CONFIG_USBHOST_COMPOSITE_STRICT
|
2016-08-26 20:24:35 +02:00
|
|
|
ret = -EINVAL;
|
2016-08-30 18:52:41 +02:00
|
|
|
goto errout_with_cfgbuffer;
|
2016-08-31 15:56:27 +02:00
|
|
|
#else
|
|
|
|
continue;
|
|
|
|
#endif
|
2016-08-26 20:24:35 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Yes.. there is a class for this device. Get an instance of its
|
|
|
|
* interface.
|
|
|
|
*/
|
|
|
|
|
|
|
|
member->usbclass = CLASS_CREATE(reg, hport, id);
|
|
|
|
if (member->usbclass == NULL)
|
|
|
|
{
|
2016-08-30 18:52:41 +02:00
|
|
|
uerr("ERROR: CLASS_CREATE failed\n");
|
2016-08-26 20:24:35 +02:00
|
|
|
ret = -ENOMEM;
|
2016-08-30 18:52:41 +02:00
|
|
|
goto errout_with_cfgbuffer;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Construct a custom configuration descriptor for this member */
|
|
|
|
|
|
|
|
cfgsize = usbhost_createconfig(member, configdesc, desclen,
|
|
|
|
cfgbuffer, CUSTOM_CONFIG_BUFSIZE);
|
|
|
|
if (cfgsize < 0)
|
|
|
|
{
|
|
|
|
uerr("ERROR: Failed to create the custom configuration: %d\n",
|
|
|
|
cfgsize);
|
|
|
|
ret = cfgsize;
|
|
|
|
goto errout_with_cfgbuffer;
|
2016-08-26 18:33:41 +02:00
|
|
|
}
|
2016-08-26 17:07:52 +02:00
|
|
|
|
2016-08-28 16:48:40 +02:00
|
|
|
/* Call the newly instantiated classes connect() method provide it
|
2016-08-31 16:16:12 +02:00
|
|
|
* with the configuration information that it needs to initialize
|
|
|
|
* properly.
|
2016-08-26 18:13:35 +02:00
|
|
|
*/
|
|
|
|
|
2016-08-30 18:52:41 +02:00
|
|
|
ret = CLASS_CONNECT(member->usbclass, cfgbuffer, cfgsize);
|
2016-08-28 16:48:40 +02:00
|
|
|
if (ret < 0)
|
|
|
|
{
|
|
|
|
/* On failure, call the class disconnect method of each contained
|
|
|
|
* class which should then free the allocated usbclass instance.
|
|
|
|
*/
|
|
|
|
|
|
|
|
uerr("ERROR: CLASS_CONNECT failed: %d\n", ret);
|
2016-08-30 18:52:41 +02:00
|
|
|
goto errout_with_cfgbuffer;
|
2016-08-28 16:48:40 +02:00
|
|
|
}
|
2016-08-26 18:13:35 +02:00
|
|
|
}
|
|
|
|
|
2016-08-31 16:16:12 +02:00
|
|
|
/* Free the temporary buffer */
|
|
|
|
|
2016-08-30 18:52:41 +02:00
|
|
|
kmm_free(cfgbuffer);
|
|
|
|
|
2016-08-26 18:13:35 +02:00
|
|
|
/* Return our USB class structure */
|
|
|
|
|
|
|
|
*usbclass = &priv->usbclass;
|
|
|
|
return OK;
|
2016-08-26 17:07:52 +02:00
|
|
|
|
2016-08-30 18:52:41 +02:00
|
|
|
errout_with_cfgbuffer:
|
|
|
|
kmm_free(cfgbuffer);
|
|
|
|
|
2016-08-26 18:13:35 +02:00
|
|
|
errout_with_members:
|
|
|
|
/* On an failure, call the class disconnect method of each contained
|
|
|
|
* class which should then free the allocated usbclass instance.
|
|
|
|
*/
|
|
|
|
|
|
|
|
usbhost_disconnect_all(priv);
|
|
|
|
|
|
|
|
/* Free the allocate array of composite members */
|
|
|
|
|
|
|
|
if (priv->members != NULL)
|
|
|
|
{
|
|
|
|
kmm_free(priv->members);
|
|
|
|
}
|
|
|
|
|
|
|
|
errout_with_container:
|
2020-08-04 20:34:41 +02:00
|
|
|
|
2016-08-26 18:13:35 +02:00
|
|
|
/* Then free the composite container itself */
|
|
|
|
|
|
|
|
kmm_free(priv);
|
|
|
|
return ret;
|
2016-08-26 17:07:52 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
#endif /* CONFIG_USBHOST_COMPOSITE */
|