2008-10-25 00:42:28 +02:00
|
|
|
/****************************************************************************
|
2012-01-26 15:24:15 +01:00
|
|
|
* drivers/usbdev/usbmsc.c
|
2008-10-25 00:42:28 +02:00
|
|
|
*
|
2020-04-01 18:13:52 +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
|
2008-10-25 00:42:28 +02:00
|
|
|
*
|
2020-04-01 18:13:52 +02:00
|
|
|
* 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.
|
2008-10-25 00:42:28 +02:00
|
|
|
*
|
2020-04-01 18:13:52 +02:00
|
|
|
****************************************************************************/
|
|
|
|
|
2021-03-04 07:10:42 +01:00
|
|
|
/* Mass storage class device. Bulk-only with SCSI subclass. */
|
|
|
|
|
2020-04-01 18:13:52 +02:00
|
|
|
/* References:
|
2008-10-25 00:42:28 +02:00
|
|
|
* "Universal Serial Bus Mass Storage Class, Specification Overview,"
|
|
|
|
* Revision 1.2, USB Implementer's Forum, June 23, 2003.
|
|
|
|
*
|
|
|
|
* "Universal Serial Bus Mass Storage Class, Bulk-Only Transport,"
|
|
|
|
* Revision 1.0, USB Implementer's Forum, September 31, 1999.
|
|
|
|
*
|
|
|
|
* "SCSI Primary Commands - 3 (SPC-3)," American National Standard
|
|
|
|
* for Information Technology, May 4, 2005
|
|
|
|
*
|
|
|
|
* "SCSI Primary Commands - 4 (SPC-4)," American National Standard
|
|
|
|
* for Information Technology, July 19, 2008
|
|
|
|
*
|
|
|
|
* "SCSI Block Commands -2 (SBC-2)," American National Standard
|
|
|
|
* for Information Technology, November 13, 2004
|
|
|
|
*
|
2008-10-28 01:30:42 +01:00
|
|
|
* "SCSI Multimedia Commands - 3 (MMC-3)," American National Standard
|
|
|
|
* for Information Technology, November 12, 2001
|
2020-04-01 18:13:52 +02:00
|
|
|
*/
|
2008-10-25 00:42:28 +02:00
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Included Files
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
#include <nuttx/config.h>
|
|
|
|
|
2009-12-15 15:25:14 +01:00
|
|
|
#include <sys/types.h>
|
|
|
|
#include <stdint.h>
|
|
|
|
#include <stdbool.h>
|
2008-10-25 00:42:28 +02:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
#include <string.h>
|
2021-05-18 08:59:14 +02:00
|
|
|
#include <assert.h>
|
2008-10-25 00:42:28 +02:00
|
|
|
#include <errno.h>
|
|
|
|
#include <debug.h>
|
|
|
|
|
2016-02-14 14:32:58 +01:00
|
|
|
#include <nuttx/irq.h>
|
2011-04-06 18:40:47 +02:00
|
|
|
#include <nuttx/kmalloc.h>
|
2014-03-25 21:19:27 +01:00
|
|
|
#include <nuttx/kthread.h>
|
2008-10-25 00:42:28 +02:00
|
|
|
#include <nuttx/arch.h>
|
2022-09-25 17:08:38 +02:00
|
|
|
#include <nuttx/queue.h>
|
2012-03-21 19:01:07 +01:00
|
|
|
#include <nuttx/fs/fs.h>
|
2010-12-14 04:33:39 +01:00
|
|
|
#include <nuttx/usb/usb.h>
|
2011-01-12 03:12:41 +01:00
|
|
|
#include <nuttx/usb/storage.h>
|
2010-12-14 04:33:39 +01:00
|
|
|
#include <nuttx/usb/usbdev.h>
|
|
|
|
#include <nuttx/usb/usbdev_trace.h>
|
2008-10-25 00:42:28 +02:00
|
|
|
|
2012-01-26 15:24:15 +01:00
|
|
|
#include "usbmsc.h"
|
2008-10-25 00:42:28 +02:00
|
|
|
|
2012-01-26 18:42:44 +01:00
|
|
|
#ifdef CONFIG_USBMSC_COMPOSITE
|
2012-01-27 00:14:27 +01:00
|
|
|
# include <nuttx/usb/composite.h>
|
2012-01-26 18:42:44 +01:00
|
|
|
# include "composite.h"
|
|
|
|
#endif
|
|
|
|
|
2008-10-25 00:42:28 +02:00
|
|
|
/****************************************************************************
|
|
|
|
* Private Types
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
/* The internal version of the class driver */
|
|
|
|
|
2012-01-25 21:17:59 +01:00
|
|
|
struct usbmsc_driver_s
|
2008-10-25 00:42:28 +02:00
|
|
|
{
|
|
|
|
struct usbdevclass_driver_s drvr;
|
2012-01-25 21:17:59 +01:00
|
|
|
FAR struct usbmsc_dev_s *dev;
|
2008-10-25 00:42:28 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
/* This is what is allocated */
|
|
|
|
|
2012-01-25 21:17:59 +01:00
|
|
|
struct usbmsc_alloc_s
|
2008-10-25 00:42:28 +02:00
|
|
|
{
|
2012-01-25 21:17:59 +01:00
|
|
|
struct usbmsc_dev_s dev;
|
|
|
|
struct usbmsc_driver_s drvr;
|
2008-10-25 00:42:28 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Private Function Prototypes
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
/* Class Driver Support *****************************************************/
|
|
|
|
|
2012-01-25 21:17:59 +01:00
|
|
|
static void usbmsc_ep0incomplete(FAR struct usbdev_ep_s *ep,
|
2008-10-25 00:42:28 +02:00
|
|
|
FAR struct usbdev_req_s *req);
|
|
|
|
|
|
|
|
/* Class Driver Operations (most at interrupt level) ************************/
|
|
|
|
|
2012-01-26 18:42:44 +01:00
|
|
|
static int usbmsc_bind(FAR struct usbdevclass_driver_s *driver,
|
|
|
|
FAR struct usbdev_s *dev);
|
|
|
|
static void usbmsc_unbind(FAR struct usbdevclass_driver_s *driver,
|
|
|
|
FAR struct usbdev_s *dev);
|
|
|
|
static int usbmsc_setup(FAR struct usbdevclass_driver_s *driver,
|
|
|
|
FAR struct usbdev_s *dev,
|
2012-04-12 18:30:48 +02:00
|
|
|
FAR const struct usb_ctrlreq_s *ctrl, FAR uint8_t *dataout,
|
|
|
|
size_t outlen);
|
2012-01-26 18:42:44 +01:00
|
|
|
static void usbmsc_disconnect(FAR struct usbdevclass_driver_s *driver,
|
|
|
|
FAR struct usbdev_s *dev);
|
2008-10-25 00:42:28 +02:00
|
|
|
|
|
|
|
/* Initialization/Uninitialization ******************************************/
|
|
|
|
|
2012-01-25 21:17:59 +01:00
|
|
|
static void usbmsc_lununinitialize(struct usbmsc_lun_s *lun);
|
2019-07-01 13:45:56 +02:00
|
|
|
#if !defined(CONFIG_USBDEV_COMPOSITE) && defined(CONFIG_USBMSC_COMPOSITE)
|
2012-01-27 00:14:27 +01:00
|
|
|
static int usbmsc_exportluns(FAR void *handle);
|
|
|
|
#endif
|
2008-10-25 00:42:28 +02:00
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Private Data
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
/* Driver operations ********************************************************/
|
|
|
|
|
|
|
|
static struct usbdevclass_driverops_s g_driverops =
|
|
|
|
{
|
2012-01-25 21:17:59 +01:00
|
|
|
usbmsc_bind, /* bind */
|
|
|
|
usbmsc_unbind, /* unbind */
|
|
|
|
usbmsc_setup, /* setup */
|
|
|
|
usbmsc_disconnect, /* disconnect */
|
|
|
|
NULL, /* suspend */
|
|
|
|
NULL /* resume */
|
2008-10-25 00:42:28 +02:00
|
|
|
};
|
|
|
|
|
2020-04-15 16:41:49 +02:00
|
|
|
/* Used to hand-off the state structure when the SCSI worker thread is
|
|
|
|
* started.
|
|
|
|
*/
|
2014-03-25 21:19:27 +01:00
|
|
|
|
|
|
|
FAR struct usbmsc_dev_s *g_usbmsc_handoff;
|
|
|
|
|
2008-10-25 00:42:28 +02:00
|
|
|
/****************************************************************************
|
|
|
|
* Private Functions
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
/****************************************************************************
|
2012-01-25 21:17:59 +01:00
|
|
|
* Name: usbmsc_ep0incomplete
|
2008-10-25 00:42:28 +02:00
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* Handle completion of EP0 control operations
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
2012-01-25 21:17:59 +01:00
|
|
|
static void usbmsc_ep0incomplete(FAR struct usbdev_ep_s *ep,
|
|
|
|
FAR struct usbdev_req_s *req)
|
2008-10-25 00:42:28 +02:00
|
|
|
{
|
|
|
|
if (req->result || req->xfrd != req->len)
|
|
|
|
{
|
2012-01-25 21:17:59 +01:00
|
|
|
usbtrace(TRACE_CLSERROR(USBMSC_TRACEERR_REQRESULT),
|
2009-12-15 15:25:14 +01:00
|
|
|
(uint16_t)-req->result);
|
2008-10-25 00:42:28 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************************************************
|
2012-01-25 21:17:59 +01:00
|
|
|
* Name: usbmsc_bind
|
2008-10-25 00:42:28 +02:00
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* Invoked when the driver is bound to a USB device driver
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
2012-01-26 18:42:44 +01:00
|
|
|
static int usbmsc_bind(FAR struct usbdevclass_driver_s *driver,
|
|
|
|
FAR struct usbdev_s *dev)
|
2008-10-25 00:42:28 +02:00
|
|
|
{
|
2020-04-01 18:13:52 +02:00
|
|
|
FAR struct usbmsc_dev_s *priv =
|
|
|
|
((FAR struct usbmsc_driver_s *)driver)->dev;
|
2012-01-25 21:17:59 +01:00
|
|
|
FAR struct usbmsc_req_s *reqcontainer;
|
2008-10-25 00:42:28 +02:00
|
|
|
irqstate_t flags;
|
2008-10-28 02:18:14 +01:00
|
|
|
int ret = OK;
|
2008-10-25 00:42:28 +02:00
|
|
|
int i;
|
|
|
|
|
|
|
|
usbtrace(TRACE_CLASSBIND, 0);
|
|
|
|
|
|
|
|
/* Bind the structures */
|
|
|
|
|
2017-07-16 16:43:17 +02:00
|
|
|
priv->usbdev = dev;
|
2012-01-26 18:42:44 +01:00
|
|
|
|
|
|
|
/* Save the reference to our private data structure in EP0 so that it
|
2014-03-21 00:27:59 +01:00
|
|
|
* can be recovered in ep0 completion events (Unless we are part of
|
2012-01-26 18:42:44 +01:00
|
|
|
* a composite device and, in that case, the composite device owns
|
|
|
|
* EP0).
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef CONFIG_USBMSC_COMPOSITE
|
2009-06-17 01:23:31 +02:00
|
|
|
dev->ep0->priv = priv;
|
2012-01-26 18:42:44 +01:00
|
|
|
#endif
|
2008-10-25 00:42:28 +02:00
|
|
|
|
|
|
|
/* The configured EP0 size should match the reported EP0 size. We could
|
|
|
|
* easily adapt to the reported EP0 size, but then we could not use the
|
|
|
|
* const, canned descriptors.
|
|
|
|
*/
|
|
|
|
|
2012-01-25 21:17:59 +01:00
|
|
|
DEBUGASSERT(CONFIG_USBMSC_EP0MAXPACKET == dev->ep0->maxpacket);
|
2008-10-25 00:42:28 +02:00
|
|
|
|
|
|
|
/* Preallocate control request */
|
|
|
|
|
2023-07-06 07:57:42 +02:00
|
|
|
priv->ctrlreq = usbdev_allocreq(dev->ep0, USBMSC_MXDESCLEN);
|
2008-10-25 00:42:28 +02:00
|
|
|
if (priv->ctrlreq == NULL)
|
|
|
|
{
|
2012-01-25 21:17:59 +01:00
|
|
|
usbtrace(TRACE_CLSERROR(USBMSC_TRACEERR_ALLOCCTRLREQ), 0);
|
2008-10-25 00:42:28 +02:00
|
|
|
ret = -ENOMEM;
|
|
|
|
goto errout;
|
|
|
|
}
|
2013-09-24 23:06:17 +02:00
|
|
|
|
2012-01-25 21:17:59 +01:00
|
|
|
priv->ctrlreq->callback = usbmsc_ep0incomplete;
|
2008-10-25 00:42:28 +02:00
|
|
|
|
|
|
|
/* Pre-allocate all endpoints... the endpoints will not be functional
|
2012-01-25 21:17:59 +01:00
|
|
|
* until the SET CONFIGURATION request is processed in usbmsc_setconfig.
|
2014-09-01 01:26:36 +02:00
|
|
|
* This is done here because there may be calls to kmm_malloc and the SET
|
2019-10-08 16:01:30 +02:00
|
|
|
* CONFIGURATION processing probably occurs within interrupt handling
|
2014-09-01 01:26:36 +02:00
|
|
|
* logic where kmm_malloc calls will fail.
|
2008-10-25 00:42:28 +02:00
|
|
|
*/
|
|
|
|
|
|
|
|
/* Pre-allocate the IN bulk endpoint */
|
|
|
|
|
2017-07-20 17:34:48 +02:00
|
|
|
priv->epbulkin = DEV_ALLOCEP(dev, USBMSC_MKEPBULKIN(&priv->devinfo),
|
2017-07-16 16:43:17 +02:00
|
|
|
true, USB_EP_ATTR_XFER_BULK);
|
2008-10-25 00:42:28 +02:00
|
|
|
if (!priv->epbulkin)
|
|
|
|
{
|
2012-01-25 21:17:59 +01:00
|
|
|
usbtrace(TRACE_CLSERROR(USBMSC_TRACEERR_EPBULKINALLOCFAIL), 0);
|
2008-10-25 00:42:28 +02:00
|
|
|
ret = -ENODEV;
|
|
|
|
goto errout;
|
|
|
|
}
|
2013-09-24 23:06:17 +02:00
|
|
|
|
2009-06-17 01:23:31 +02:00
|
|
|
priv->epbulkin->priv = priv;
|
2008-10-25 00:42:28 +02:00
|
|
|
|
|
|
|
/* Pre-allocate the OUT bulk endpoint */
|
|
|
|
|
2017-07-20 17:34:48 +02:00
|
|
|
priv->epbulkout = DEV_ALLOCEP(dev, USBMSC_MKEPBULKOUT(&priv->devinfo),
|
2017-07-16 16:43:17 +02:00
|
|
|
false, USB_EP_ATTR_XFER_BULK);
|
2008-10-25 00:42:28 +02:00
|
|
|
if (!priv->epbulkout)
|
|
|
|
{
|
2012-01-25 21:17:59 +01:00
|
|
|
usbtrace(TRACE_CLSERROR(USBMSC_TRACEERR_EPBULKOUTALLOCFAIL), 0);
|
2008-10-25 00:42:28 +02:00
|
|
|
ret = -ENODEV;
|
|
|
|
goto errout;
|
|
|
|
}
|
2013-09-24 23:06:17 +02:00
|
|
|
|
2009-06-17 01:23:31 +02:00
|
|
|
priv->epbulkout->priv = priv;
|
2008-10-25 00:42:28 +02:00
|
|
|
|
|
|
|
/* Pre-allocate read requests */
|
|
|
|
|
2012-01-25 21:17:59 +01:00
|
|
|
for (i = 0; i < CONFIG_USBMSC_NRDREQS; i++)
|
2008-10-25 00:42:28 +02:00
|
|
|
{
|
|
|
|
reqcontainer = &priv->rdreqs[i];
|
2023-07-06 07:57:42 +02:00
|
|
|
reqcontainer->req = usbdev_allocreq(priv->epbulkout,
|
2017-07-16 16:43:17 +02:00
|
|
|
CONFIG_USBMSC_BULKOUTREQLEN);
|
2008-10-25 00:42:28 +02:00
|
|
|
if (reqcontainer->req == NULL)
|
|
|
|
{
|
2012-01-25 21:17:59 +01:00
|
|
|
usbtrace(TRACE_CLSERROR(USBMSC_TRACEERR_RDALLOCREQ),
|
2009-12-15 15:25:14 +01:00
|
|
|
(uint16_t)-ret);
|
2008-10-25 00:42:28 +02:00
|
|
|
ret = -ENOMEM;
|
|
|
|
goto errout;
|
|
|
|
}
|
2017-07-16 16:43:17 +02:00
|
|
|
|
2009-06-17 01:23:31 +02:00
|
|
|
reqcontainer->req->priv = reqcontainer;
|
2012-01-25 21:17:59 +01:00
|
|
|
reqcontainer->req->callback = usbmsc_rdcomplete;
|
2008-10-25 00:42:28 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Pre-allocate write request containers and put in a free list */
|
|
|
|
|
2012-01-25 21:17:59 +01:00
|
|
|
for (i = 0; i < CONFIG_USBMSC_NWRREQS; i++)
|
2008-10-25 00:42:28 +02:00
|
|
|
{
|
|
|
|
reqcontainer = &priv->wrreqs[i];
|
2023-07-06 07:57:42 +02:00
|
|
|
reqcontainer->req = usbdev_allocreq(priv->epbulkin,
|
2017-07-16 16:43:17 +02:00
|
|
|
CONFIG_USBMSC_BULKINREQLEN);
|
2008-10-25 00:42:28 +02:00
|
|
|
if (reqcontainer->req == NULL)
|
|
|
|
{
|
2012-01-25 21:17:59 +01:00
|
|
|
usbtrace(TRACE_CLSERROR(USBMSC_TRACEERR_WRALLOCREQ),
|
2009-12-15 15:25:14 +01:00
|
|
|
(uint16_t)-ret);
|
2008-10-25 00:42:28 +02:00
|
|
|
ret = -ENOMEM;
|
|
|
|
goto errout;
|
|
|
|
}
|
2017-07-16 16:43:17 +02:00
|
|
|
|
2009-06-17 01:23:31 +02:00
|
|
|
reqcontainer->req->priv = reqcontainer;
|
2012-01-25 21:17:59 +01:00
|
|
|
reqcontainer->req->callback = usbmsc_wrcomplete;
|
2008-10-25 00:42:28 +02:00
|
|
|
|
2016-02-14 14:32:58 +01:00
|
|
|
flags = enter_critical_section();
|
2015-10-10 18:41:00 +02:00
|
|
|
sq_addlast((FAR sq_entry_t *)reqcontainer, &priv->wrreqlist);
|
2016-02-14 14:32:58 +01:00
|
|
|
leave_critical_section(flags);
|
2008-10-25 00:42:28 +02:00
|
|
|
}
|
|
|
|
|
2020-04-15 16:41:49 +02:00
|
|
|
/* Report if we are selfpowered (unless we are part of a composite
|
|
|
|
* device).
|
|
|
|
*/
|
2008-10-25 00:42:28 +02:00
|
|
|
|
2012-01-25 21:17:59 +01:00
|
|
|
#ifndef CONFIG_USBMSC_COMPOSITE
|
2008-10-25 00:42:28 +02:00
|
|
|
#ifdef CONFIG_USBDEV_SELFPOWERED
|
|
|
|
DEV_SETSELFPOWERED(dev);
|
|
|
|
#endif
|
2010-12-04 18:35:19 +01:00
|
|
|
|
2012-01-25 20:27:20 +01:00
|
|
|
/* And pull-up the data line for the soft connect function (unless we are
|
|
|
|
* part of a composite device)
|
|
|
|
*/
|
2010-12-04 18:35:19 +01:00
|
|
|
|
|
|
|
DEV_CONNECT(dev);
|
2012-01-25 20:27:20 +01:00
|
|
|
#endif
|
2008-10-25 00:42:28 +02:00
|
|
|
return OK;
|
|
|
|
|
|
|
|
errout:
|
2012-01-26 18:42:44 +01:00
|
|
|
usbmsc_unbind(driver, dev);
|
2008-10-25 00:42:28 +02:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************************************************
|
2012-01-25 21:17:59 +01:00
|
|
|
* Name: usbmsc_unbind
|
2008-10-25 00:42:28 +02:00
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* Invoked when the driver is unbound from a USB device driver
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
2012-01-26 18:42:44 +01:00
|
|
|
static void usbmsc_unbind(FAR struct usbdevclass_driver_s *driver,
|
|
|
|
FAR struct usbdev_s *dev)
|
2008-10-25 00:42:28 +02:00
|
|
|
{
|
2012-01-25 21:17:59 +01:00
|
|
|
FAR struct usbmsc_dev_s *priv;
|
|
|
|
FAR struct usbmsc_req_s *reqcontainer;
|
2008-10-25 00:42:28 +02:00
|
|
|
irqstate_t flags;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
usbtrace(TRACE_CLASSUNBIND, 0);
|
|
|
|
|
2016-06-11 22:14:08 +02:00
|
|
|
#ifdef CONFIG_DEBUG_FEATURES
|
2012-01-26 18:42:44 +01:00
|
|
|
if (!driver || !dev || !dev->ep0)
|
2008-10-25 00:42:28 +02:00
|
|
|
{
|
2012-01-25 21:17:59 +01:00
|
|
|
usbtrace(TRACE_CLSERROR(USBMSC_TRACEERR_UNBINDINVALIDARGS), 0);
|
2008-10-25 00:42:28 +02:00
|
|
|
return;
|
2020-04-01 18:13:52 +02:00
|
|
|
}
|
2008-10-25 00:42:28 +02:00
|
|
|
#endif
|
|
|
|
|
|
|
|
/* Extract reference to private data */
|
|
|
|
|
2015-10-10 18:41:00 +02:00
|
|
|
priv = ((FAR struct usbmsc_driver_s *)driver)->dev;
|
2008-10-25 00:42:28 +02:00
|
|
|
|
2016-06-11 22:14:08 +02:00
|
|
|
#ifdef CONFIG_DEBUG_FEATURES
|
2008-10-25 00:42:28 +02:00
|
|
|
if (!priv)
|
|
|
|
{
|
2012-01-25 21:17:59 +01:00
|
|
|
usbtrace(TRACE_CLSERROR(USBMSC_TRACEERR_EP0NOTBOUND1), 0);
|
2008-10-25 00:42:28 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/* The worker thread should have already been stopped by the
|
|
|
|
* driver un-initialize logic.
|
|
|
|
*/
|
|
|
|
|
2020-04-01 18:13:52 +02:00
|
|
|
DEBUGASSERT(priv->thstate == USBMSC_STATE_TERMINATED ||
|
|
|
|
priv->thstate == USBMSC_STATE_NOTSTARTED);
|
2008-10-25 00:42:28 +02:00
|
|
|
|
|
|
|
/* Make sure that we are not already unbound */
|
|
|
|
|
|
|
|
if (priv != NULL)
|
|
|
|
{
|
|
|
|
/* Make sure that the endpoints have been unconfigured. If
|
|
|
|
* we were terminated gracefully, then the configuration should
|
2012-01-25 21:17:59 +01:00
|
|
|
* already have been reset. If not, then calling usbmsc_resetconfig
|
2008-10-25 00:42:28 +02:00
|
|
|
* should cause the endpoints to immediately terminate all
|
|
|
|
* transfers and return the requests to us (with result == -ESHUTDOWN)
|
|
|
|
*/
|
|
|
|
|
2012-01-25 21:17:59 +01:00
|
|
|
usbmsc_resetconfig(priv);
|
2008-10-25 00:42:28 +02:00
|
|
|
up_mdelay(50);
|
|
|
|
|
|
|
|
/* Free the pre-allocated control request */
|
|
|
|
|
|
|
|
if (priv->ctrlreq != NULL)
|
|
|
|
{
|
2023-07-06 07:57:42 +02:00
|
|
|
usbdev_freereq(dev->ep0, priv->ctrlreq);
|
2008-10-25 00:42:28 +02:00
|
|
|
priv->ctrlreq = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Free pre-allocated read requests (which should all have
|
|
|
|
* been returned to the free list at this time -- we don't check)
|
|
|
|
*/
|
|
|
|
|
2012-01-25 21:17:59 +01:00
|
|
|
for (i = 0; i < CONFIG_USBMSC_NRDREQS; i++)
|
2008-10-25 00:42:28 +02:00
|
|
|
{
|
|
|
|
reqcontainer = &priv->rdreqs[i];
|
|
|
|
if (reqcontainer->req)
|
|
|
|
{
|
2023-07-06 07:57:42 +02:00
|
|
|
usbdev_freereq(priv->epbulkout, reqcontainer->req);
|
2008-10-25 00:42:28 +02:00
|
|
|
reqcontainer->req = NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Free the bulk OUT endpoint */
|
|
|
|
|
|
|
|
if (priv->epbulkout)
|
|
|
|
{
|
|
|
|
DEV_FREEEP(dev, priv->epbulkout);
|
|
|
|
priv->epbulkout = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Free write requests that are not in use (which should be all
|
|
|
|
* of them
|
|
|
|
*/
|
|
|
|
|
2016-02-14 14:32:58 +01:00
|
|
|
flags = enter_critical_section();
|
2008-10-25 00:42:28 +02:00
|
|
|
while (!sq_empty(&priv->wrreqlist))
|
|
|
|
{
|
2017-07-16 16:43:17 +02:00
|
|
|
reqcontainer = (struct usbmsc_req_s *)
|
|
|
|
sq_remfirst(&priv->wrreqlist);
|
|
|
|
|
2008-10-25 00:42:28 +02:00
|
|
|
if (reqcontainer->req != NULL)
|
|
|
|
{
|
2023-07-06 07:57:42 +02:00
|
|
|
usbdev_freereq(priv->epbulkin, reqcontainer->req);
|
2008-10-25 00:42:28 +02:00
|
|
|
}
|
|
|
|
}
|
2011-07-26 19:27:57 +02:00
|
|
|
|
|
|
|
/* Free the bulk IN endpoint */
|
|
|
|
|
|
|
|
if (priv->epbulkin)
|
|
|
|
{
|
|
|
|
DEV_FREEEP(dev, priv->epbulkin);
|
|
|
|
priv->epbulkin = NULL;
|
|
|
|
}
|
|
|
|
|
2016-02-14 14:32:58 +01:00
|
|
|
leave_critical_section(flags);
|
2008-10-25 00:42:28 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************************************************
|
2012-01-25 21:17:59 +01:00
|
|
|
* Name: usbmsc_setup
|
2008-10-25 00:42:28 +02:00
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* Invoked for ep0 control requests. This function probably executes
|
|
|
|
* in the context of an interrupt handler.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
2012-01-26 18:42:44 +01:00
|
|
|
static int usbmsc_setup(FAR struct usbdevclass_driver_s *driver,
|
|
|
|
FAR struct usbdev_s *dev,
|
2012-04-12 18:30:48 +02:00
|
|
|
FAR const struct usb_ctrlreq_s *ctrl,
|
|
|
|
FAR uint8_t *dataout, size_t outlen)
|
2008-10-25 00:42:28 +02:00
|
|
|
{
|
2012-01-25 21:17:59 +01:00
|
|
|
FAR struct usbmsc_dev_s *priv;
|
2008-10-25 00:42:28 +02:00
|
|
|
FAR struct usbdev_req_s *ctrlreq;
|
2009-12-15 15:25:14 +01:00
|
|
|
uint16_t value;
|
|
|
|
uint16_t index;
|
|
|
|
uint16_t len;
|
2008-10-25 00:42:28 +02:00
|
|
|
int ret = -EOPNOTSUPP;
|
|
|
|
|
2016-06-11 22:14:08 +02:00
|
|
|
#ifdef CONFIG_DEBUG_FEATURES
|
2012-01-26 18:42:44 +01:00
|
|
|
if (!driver || !dev || !dev->ep0 || !ctrl)
|
2008-10-25 00:42:28 +02:00
|
|
|
{
|
2012-01-25 21:17:59 +01:00
|
|
|
usbtrace(TRACE_CLSERROR(USBMSC_TRACEERR_SETUPINVALIDARGS), 0);
|
2008-10-25 00:42:28 +02:00
|
|
|
return -EIO;
|
2013-09-24 23:06:17 +02:00
|
|
|
}
|
2008-10-25 00:42:28 +02:00
|
|
|
#endif
|
|
|
|
|
|
|
|
/* Extract reference to private data */
|
|
|
|
|
|
|
|
usbtrace(TRACE_CLASSSETUP, ctrl->req);
|
2012-01-26 18:42:44 +01:00
|
|
|
priv = ((FAR struct usbmsc_driver_s *)driver)->dev;
|
2008-10-25 00:42:28 +02:00
|
|
|
|
2016-06-11 22:14:08 +02:00
|
|
|
#ifdef CONFIG_DEBUG_FEATURES
|
2008-10-25 00:42:28 +02:00
|
|
|
if (!priv || !priv->ctrlreq)
|
|
|
|
{
|
2012-01-25 21:17:59 +01:00
|
|
|
usbtrace(TRACE_CLSERROR(USBMSC_TRACEERR_EP0NOTBOUND2), 0);
|
2008-10-25 00:42:28 +02:00
|
|
|
return -ENODEV;
|
|
|
|
}
|
|
|
|
#endif
|
2020-04-01 18:13:52 +02:00
|
|
|
|
2008-10-25 00:42:28 +02:00
|
|
|
ctrlreq = priv->ctrlreq;
|
|
|
|
|
|
|
|
/* Extract the little-endian 16-bit values to host order */
|
|
|
|
|
|
|
|
value = GETUINT16(ctrl->value);
|
|
|
|
index = GETUINT16(ctrl->index);
|
|
|
|
len = GETUINT16(ctrl->len);
|
|
|
|
|
2016-06-11 19:59:51 +02:00
|
|
|
uinfo("type=%02x req=%02x value=%04x index=%04x len=%04x\n",
|
2008-10-25 00:42:28 +02:00
|
|
|
ctrl->type, ctrl->req, value, index, len);
|
|
|
|
|
|
|
|
if ((ctrl->type & USB_REQ_TYPE_MASK) == USB_REQ_TYPE_STANDARD)
|
|
|
|
{
|
|
|
|
/**********************************************************************
|
|
|
|
* Standard Requests
|
|
|
|
**********************************************************************/
|
|
|
|
|
|
|
|
switch (ctrl->req)
|
|
|
|
{
|
|
|
|
case USB_REQ_GETDESCRIPTOR:
|
|
|
|
{
|
2020-04-01 18:13:52 +02:00
|
|
|
/* The value field specifies the descriptor type in the MS byte
|
|
|
|
* and the descriptor index in the LS byte (order is little
|
|
|
|
* endian)
|
2008-10-25 00:42:28 +02:00
|
|
|
*/
|
|
|
|
|
|
|
|
switch (ctrl->value[1])
|
|
|
|
{
|
2017-07-16 16:43:17 +02:00
|
|
|
/* If the mass storage device is used in as part of a
|
|
|
|
* composite device, then the device descriptor is is
|
|
|
|
* provided by logic in the composite device implementation.
|
2012-01-25 20:27:20 +01:00
|
|
|
*/
|
|
|
|
|
2012-01-25 21:17:59 +01:00
|
|
|
#ifndef CONFIG_USBMSC_COMPOSITE
|
2008-10-25 00:42:28 +02:00
|
|
|
case USB_DESC_TYPE_DEVICE:
|
|
|
|
{
|
|
|
|
ret = USB_SIZEOF_DEVDESC;
|
2012-01-25 21:17:59 +01:00
|
|
|
memcpy(ctrlreq->buf, usbmsc_getdevdesc(), ret);
|
2008-10-25 00:42:28 +02:00
|
|
|
}
|
|
|
|
break;
|
2012-01-25 20:27:20 +01:00
|
|
|
#endif
|
2008-10-25 00:42:28 +02:00
|
|
|
|
2017-07-16 16:43:17 +02:00
|
|
|
/* If the mass storage device is used in as part of a
|
|
|
|
* composite device, then the device qualifier descriptor is
|
|
|
|
* provided by logic in the composite device implementation.
|
2012-01-25 20:27:20 +01:00
|
|
|
*/
|
|
|
|
|
2012-01-25 21:17:59 +01:00
|
|
|
#if !defined(CONFIG_USBMSC_COMPOSITE) && defined(CONFIG_USBDEV_DUALSPEED)
|
2008-10-25 00:42:28 +02:00
|
|
|
case USB_DESC_TYPE_DEVICEQUALIFIER:
|
|
|
|
{
|
|
|
|
ret = USB_SIZEOF_QUALDESC;
|
2012-01-25 21:17:59 +01:00
|
|
|
memcpy(ctrlreq->buf, usbmsc_getqualdesc(), ret);
|
2008-10-25 00:42:28 +02:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case USB_DESC_TYPE_OTHERSPEEDCONFIG:
|
2012-01-25 20:27:20 +01:00
|
|
|
#endif
|
|
|
|
|
2020-04-01 18:13:52 +02:00
|
|
|
/* If the mass storage device is used in as part of a
|
|
|
|
* composite device, then the configuration descriptor is
|
|
|
|
* provided by logic in the composite device implementation.
|
2012-01-25 20:27:20 +01:00
|
|
|
*/
|
2008-10-25 00:42:28 +02:00
|
|
|
|
2012-01-25 21:17:59 +01:00
|
|
|
#ifndef CONFIG_USBMSC_COMPOSITE
|
2008-10-25 00:42:28 +02:00
|
|
|
case USB_DESC_TYPE_CONFIG:
|
|
|
|
{
|
|
|
|
#ifdef CONFIG_USBDEV_DUALSPEED
|
2017-07-20 18:07:53 +02:00
|
|
|
ret = usbmsc_mkcfgdesc(ctrlreq->buf, &priv->devinfo,
|
|
|
|
dev->speed, ctrl->value[1]);
|
2008-10-25 00:42:28 +02:00
|
|
|
#else
|
2017-07-20 18:07:53 +02:00
|
|
|
ret = usbmsc_mkcfgdesc(ctrlreq->buf, &priv->devinfo);
|
2008-10-25 00:42:28 +02:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
break;
|
2012-01-25 20:27:20 +01:00
|
|
|
#endif
|
|
|
|
|
2017-07-16 16:43:17 +02:00
|
|
|
/* If the mass storage device is used in as part of a
|
|
|
|
* composite device, then the language string descriptor is
|
|
|
|
* provided by logic in the composite device implementation.
|
2012-01-25 20:27:20 +01:00
|
|
|
*/
|
2008-10-25 00:42:28 +02:00
|
|
|
|
2012-01-25 21:17:59 +01:00
|
|
|
#ifndef CONFIG_USBMSC_COMPOSITE
|
2008-10-25 00:42:28 +02:00
|
|
|
case USB_DESC_TYPE_STRING:
|
|
|
|
{
|
|
|
|
/* index == language code. */
|
|
|
|
|
2017-07-16 16:43:17 +02:00
|
|
|
ret = usbmsc_mkstrdesc(ctrl->value[0],
|
2020-04-01 18:13:52 +02:00
|
|
|
(FAR struct usb_strdesc_s *)
|
|
|
|
ctrlreq->buf);
|
2008-10-25 00:42:28 +02:00
|
|
|
}
|
|
|
|
break;
|
2012-01-25 20:27:20 +01:00
|
|
|
#endif
|
2008-10-25 00:42:28 +02:00
|
|
|
|
|
|
|
default:
|
|
|
|
{
|
2020-04-01 18:13:52 +02:00
|
|
|
usbtrace(TRACE_CLSERROR(USBMSC_TRACEERR_GETUNKNOWNDESC),
|
|
|
|
value);
|
2008-10-25 00:42:28 +02:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case USB_REQ_SETCONFIGURATION:
|
|
|
|
{
|
|
|
|
if (ctrl->type == 0)
|
|
|
|
{
|
2017-07-16 16:43:17 +02:00
|
|
|
/* Signal the worker thread to instantiate the new
|
|
|
|
* configuration.
|
|
|
|
*/
|
2008-10-25 00:42:28 +02:00
|
|
|
|
2012-01-25 21:17:59 +01:00
|
|
|
priv->theventset |= USBMSC_EVENT_CFGCHANGE;
|
2008-10-25 00:42:28 +02:00
|
|
|
priv->thvalue = value;
|
2014-03-25 21:19:27 +01:00
|
|
|
usbmsc_scsi_signal(priv);
|
2008-10-25 00:42:28 +02:00
|
|
|
|
|
|
|
/* Return here... the response will be provided later by the
|
|
|
|
* worker thread.
|
|
|
|
*/
|
|
|
|
|
|
|
|
return OK;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2017-07-16 16:43:17 +02:00
|
|
|
/* If the mass storage device is used in as part of a composite
|
|
|
|
* device, then the overall composite class configuration is
|
|
|
|
* managed by logic in the composite device implementation.
|
2012-01-25 20:27:20 +01:00
|
|
|
*/
|
|
|
|
|
2012-01-25 21:17:59 +01:00
|
|
|
#ifndef CONFIG_USBMSC_COMPOSITE
|
2008-10-25 00:42:28 +02:00
|
|
|
case USB_REQ_GETCONFIGURATION:
|
|
|
|
{
|
|
|
|
if (ctrl->type == USB_DIR_IN)
|
|
|
|
{
|
|
|
|
ctrlreq->buf[0] = priv->config;
|
|
|
|
ret = 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
2012-01-25 20:27:20 +01:00
|
|
|
#endif
|
2008-10-25 00:42:28 +02:00
|
|
|
|
|
|
|
case USB_REQ_SETINTERFACE:
|
|
|
|
{
|
|
|
|
if (ctrl->type == USB_REQ_RECIPIENT_INTERFACE)
|
|
|
|
{
|
2012-01-25 21:17:59 +01:00
|
|
|
if (priv->config == USBMSC_CONFIGID &&
|
|
|
|
index == USBMSC_INTERFACEID &&
|
|
|
|
value == USBMSC_ALTINTERFACEID)
|
2008-10-25 00:42:28 +02:00
|
|
|
{
|
|
|
|
/* Signal to instantiate the interface change */
|
|
|
|
|
2012-01-25 21:17:59 +01:00
|
|
|
priv->theventset |= USBMSC_EVENT_IFCHANGE;
|
2014-03-25 21:19:27 +01:00
|
|
|
usbmsc_scsi_signal(priv);
|
2008-10-25 00:42:28 +02:00
|
|
|
|
2017-07-16 16:43:17 +02:00
|
|
|
/* Return here... the response will be provided later by
|
|
|
|
* the worker thread.
|
2008-10-25 00:42:28 +02:00
|
|
|
*/
|
|
|
|
|
|
|
|
return OK;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case USB_REQ_GETINTERFACE:
|
|
|
|
{
|
2015-10-10 18:41:00 +02:00
|
|
|
if (ctrl->type == (USB_DIR_IN | USB_REQ_RECIPIENT_INTERFACE) &&
|
2012-01-25 21:17:59 +01:00
|
|
|
priv->config == USBMSC_CONFIGIDNONE)
|
2008-10-25 00:42:28 +02:00
|
|
|
{
|
2012-01-25 21:17:59 +01:00
|
|
|
if (index != USBMSC_INTERFACEID)
|
2008-10-25 00:42:28 +02:00
|
|
|
{
|
|
|
|
ret = -EDOM;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2012-01-25 21:17:59 +01:00
|
|
|
ctrlreq->buf[0] = USBMSC_ALTINTERFACEID;
|
2008-10-25 00:42:28 +02:00
|
|
|
ret = 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
2020-04-01 18:13:52 +02:00
|
|
|
usbtrace(TRACE_CLSERROR(USBMSC_TRACEERR_UNSUPPORTEDSTDREQ),
|
|
|
|
ctrl->req);
|
2008-10-25 00:42:28 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2012-01-27 19:33:41 +01:00
|
|
|
else if ((ctrl->type & USB_REQ_TYPE_MASK) == USB_REQ_TYPE_CLASS)
|
2008-10-25 00:42:28 +02:00
|
|
|
{
|
|
|
|
/**********************************************************************
|
|
|
|
* Bulk-Only Mass Storage Class Requests
|
|
|
|
**********************************************************************/
|
|
|
|
|
|
|
|
/* Verify that we are configured */
|
|
|
|
|
|
|
|
if (!priv->config)
|
|
|
|
{
|
2012-01-25 21:17:59 +01:00
|
|
|
usbtrace(TRACE_CLSERROR(USBMSC_TRACEERR_NOTCONFIGURED), 0);
|
2008-10-25 00:42:28 +02:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (ctrl->req)
|
|
|
|
{
|
2012-01-25 21:17:59 +01:00
|
|
|
case USBMSC_REQ_MSRESET: /* Reset mass storage device and interface */
|
2008-10-25 00:42:28 +02:00
|
|
|
{
|
2012-01-25 21:17:59 +01:00
|
|
|
if (ctrl->type == USBMSC_TYPE_SETUPOUT && value == 0 && len == 0)
|
2008-10-25 00:42:28 +02:00
|
|
|
{
|
|
|
|
/* Only one interface is supported */
|
|
|
|
|
2012-01-25 21:17:59 +01:00
|
|
|
if (index != USBMSC_INTERFACEID)
|
2008-10-25 00:42:28 +02:00
|
|
|
{
|
2020-04-01 18:13:52 +02:00
|
|
|
usbtrace(TRACE_CLSERROR(USBMSC_TRACEERR_MSRESETNDX),
|
|
|
|
index);
|
2008-10-25 00:42:28 +02:00
|
|
|
ret = -EDOM;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2017-07-16 16:43:17 +02:00
|
|
|
/* Signal to stop the current operation and reinitialize
|
|
|
|
* state.
|
|
|
|
*/
|
2008-10-25 00:42:28 +02:00
|
|
|
|
2012-01-25 21:17:59 +01:00
|
|
|
priv->theventset |= USBMSC_EVENT_RESET;
|
2014-03-25 21:19:27 +01:00
|
|
|
usbmsc_scsi_signal(priv);
|
2008-10-25 00:42:28 +02:00
|
|
|
|
2017-07-16 16:43:17 +02:00
|
|
|
/* Return here... the response will be provided later by
|
|
|
|
* the worker thread.
|
2008-10-25 00:42:28 +02:00
|
|
|
*/
|
|
|
|
|
|
|
|
return OK;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2012-01-25 21:17:59 +01:00
|
|
|
case USBMSC_REQ_GETMAXLUN: /* Return number LUNs supported */
|
2008-10-25 00:42:28 +02:00
|
|
|
{
|
2012-01-25 21:17:59 +01:00
|
|
|
if (ctrl->type == USBMSC_TYPE_SETUPIN && value == 0 && len == 1)
|
2008-10-25 00:42:28 +02:00
|
|
|
{
|
|
|
|
/* Only one interface is supported */
|
|
|
|
|
2012-01-25 21:17:59 +01:00
|
|
|
if (index != USBMSC_INTERFACEID)
|
2008-10-25 00:42:28 +02:00
|
|
|
{
|
2020-04-01 18:13:52 +02:00
|
|
|
usbtrace(TRACE_CLSERROR(USBMSC_TRACEERR_GETMAXLUNNDX),
|
|
|
|
index);
|
2008-10-25 00:42:28 +02:00
|
|
|
ret = -EDOM;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
ctrlreq->buf[0] = priv->nluns - 1;
|
|
|
|
ret = 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
2012-01-27 19:33:41 +01:00
|
|
|
usbtrace(TRACE_CLSERROR(USBMSC_TRACEERR_BADREQUEST), ctrl->req);
|
2008-10-25 00:42:28 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2012-01-27 19:33:41 +01:00
|
|
|
else
|
|
|
|
{
|
|
|
|
usbtrace(TRACE_CLSERROR(USBMSC_TRACEERR_UNSUPPORTEDTYPE), ctrl->type);
|
|
|
|
}
|
2008-10-25 00:42:28 +02:00
|
|
|
|
|
|
|
/* Respond to the setup command if data was returned. On an error return
|
|
|
|
* value (ret < 0), the USB driver will stall EP0.
|
|
|
|
*/
|
|
|
|
|
|
|
|
if (ret >= 0)
|
|
|
|
{
|
2012-01-26 18:42:44 +01:00
|
|
|
/* Configure the response */
|
|
|
|
|
2012-01-25 20:27:20 +01:00
|
|
|
ctrlreq->len = MIN(len, ret);
|
2008-10-25 16:40:37 +02:00
|
|
|
ctrlreq->flags = USBDEV_REQFLAGS_NULLPKT;
|
2012-01-26 18:42:44 +01:00
|
|
|
|
|
|
|
/* Send the response -- either directly to the USB controller or
|
|
|
|
* indirectly in the case where this class is a member of a composite
|
|
|
|
* device.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef CONFIG_USBMSC_COMPOSITE
|
|
|
|
ret = EP_SUBMIT(dev->ep0, ctrlreq);
|
|
|
|
#else
|
2023-03-23 17:21:25 +01:00
|
|
|
ret = composite_ep0submit(driver, dev, ctrlreq, ctrl);
|
2012-01-26 18:42:44 +01:00
|
|
|
#endif
|
2008-10-25 00:42:28 +02:00
|
|
|
if (ret < 0)
|
|
|
|
{
|
2012-01-25 21:17:59 +01:00
|
|
|
usbtrace(TRACE_CLSERROR(USBMSC_TRACEERR_EPRESPQ), (uint16_t)-ret);
|
2008-10-25 00:42:28 +02:00
|
|
|
#if 0 /* Not necessary */
|
|
|
|
ctrlreq->result = OK;
|
2012-01-25 21:17:59 +01:00
|
|
|
usbmsc_ep0incomplete(dev->ep0, ctrlreq);
|
2008-10-25 00:42:28 +02:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************************************************
|
2012-01-25 21:17:59 +01:00
|
|
|
* Name: usbmsc_disconnect
|
2008-10-25 00:42:28 +02:00
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* Invoked after all transfers have been stopped, when the host is
|
|
|
|
* disconnected. This function is probably called from the context of an
|
|
|
|
* interrupt handler.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
2012-01-26 18:42:44 +01:00
|
|
|
static void usbmsc_disconnect(FAR struct usbdevclass_driver_s *driver,
|
|
|
|
FAR struct usbdev_s *dev)
|
2008-10-25 00:42:28 +02:00
|
|
|
{
|
2012-01-25 21:17:59 +01:00
|
|
|
struct usbmsc_dev_s *priv;
|
2008-10-25 00:42:28 +02:00
|
|
|
irqstate_t flags;
|
|
|
|
|
|
|
|
usbtrace(TRACE_CLASSDISCONNECT, 0);
|
|
|
|
|
2016-06-11 22:14:08 +02:00
|
|
|
#ifdef CONFIG_DEBUG_FEATURES
|
2012-01-26 18:42:44 +01:00
|
|
|
if (!driver || !dev || !dev->ep0)
|
2008-10-25 00:42:28 +02:00
|
|
|
{
|
2012-01-25 21:17:59 +01:00
|
|
|
usbtrace(TRACE_CLSERROR(USBMSC_TRACEERR_DISCONNECTINVALIDARGS), 0);
|
2008-10-25 00:42:28 +02:00
|
|
|
return;
|
2020-04-01 18:13:52 +02:00
|
|
|
}
|
2008-10-25 00:42:28 +02:00
|
|
|
#endif
|
|
|
|
|
|
|
|
/* Extract reference to private data */
|
|
|
|
|
2012-01-26 18:42:44 +01:00
|
|
|
priv = ((FAR struct usbmsc_driver_s *)driver)->dev;
|
2008-10-25 00:42:28 +02:00
|
|
|
|
2016-06-11 22:14:08 +02:00
|
|
|
#ifdef CONFIG_DEBUG_FEATURES
|
2008-10-25 00:42:28 +02:00
|
|
|
if (!priv)
|
|
|
|
{
|
2012-01-25 21:17:59 +01:00
|
|
|
usbtrace(TRACE_CLSERROR(USBMSC_TRACEERR_EP0NOTBOUND3), 0);
|
2008-10-25 00:42:28 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/* Reset the configuration */
|
|
|
|
|
2016-02-14 14:32:58 +01:00
|
|
|
flags = enter_critical_section();
|
2012-01-25 21:17:59 +01:00
|
|
|
usbmsc_resetconfig(priv);
|
2008-10-25 00:42:28 +02:00
|
|
|
|
|
|
|
/* Signal the worker thread */
|
|
|
|
|
2012-01-25 21:17:59 +01:00
|
|
|
priv->theventset |= USBMSC_EVENT_DISCONNECT;
|
2014-03-25 21:19:27 +01:00
|
|
|
usbmsc_scsi_signal(priv);
|
2016-02-14 14:32:58 +01:00
|
|
|
leave_critical_section(flags);
|
2010-12-04 18:35:19 +01:00
|
|
|
|
|
|
|
/* Perform the soft connect function so that we will we can be
|
2012-01-25 20:27:20 +01:00
|
|
|
* re-enumerated (unless we are part of a composite device)
|
2010-12-04 18:35:19 +01:00
|
|
|
*/
|
|
|
|
|
2012-01-25 21:17:59 +01:00
|
|
|
#ifndef CONFIG_USBMSC_COMPOSITE
|
2012-01-25 20:27:20 +01:00
|
|
|
DEV_CONNECT(dev);
|
|
|
|
#endif
|
2008-10-25 00:42:28 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************************************************
|
2012-01-25 21:17:59 +01:00
|
|
|
* Name: usbmsc_lununinitialize
|
2008-10-25 00:42:28 +02:00
|
|
|
****************************************************************************/
|
|
|
|
|
2012-01-25 21:17:59 +01:00
|
|
|
static void usbmsc_lununinitialize(struct usbmsc_lun_s *lun)
|
2008-10-25 00:42:28 +02:00
|
|
|
{
|
|
|
|
/* Has a block driver has been bound to the LUN? */
|
|
|
|
|
|
|
|
if (lun->inode)
|
|
|
|
{
|
|
|
|
/* Close the block driver */
|
|
|
|
|
2020-01-02 17:49:34 +01:00
|
|
|
close_blockdriver(lun->inode);
|
2008-10-25 00:42:28 +02:00
|
|
|
}
|
|
|
|
|
2017-06-19 18:45:35 +02:00
|
|
|
memset(lun, 0, sizeof(struct usbmsc_lun_s));
|
2008-10-25 00:42:28 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Public Functions
|
|
|
|
****************************************************************************/
|
2017-07-16 16:43:17 +02:00
|
|
|
|
2008-10-25 00:42:28 +02:00
|
|
|
/****************************************************************************
|
2012-01-25 21:17:59 +01:00
|
|
|
* Name: usbmsc_setconfig
|
2008-10-25 00:42:28 +02:00
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* Set the device configuration by allocating and configuring endpoints and
|
2009-12-01 16:28:33 +01:00
|
|
|
* by allocating and queuing read and write requests.
|
2008-10-25 00:42:28 +02:00
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
2012-01-25 21:17:59 +01:00
|
|
|
int usbmsc_setconfig(FAR struct usbmsc_dev_s *priv, uint8_t config)
|
2008-10-25 00:42:28 +02:00
|
|
|
{
|
2012-01-25 21:17:59 +01:00
|
|
|
FAR struct usbmsc_req_s *privreq;
|
2008-10-25 00:42:28 +02:00
|
|
|
FAR struct usbdev_req_s *req;
|
2017-07-16 16:43:17 +02:00
|
|
|
struct usb_epdesc_s epdesc;
|
|
|
|
bool hispeed = false;
|
2008-10-25 00:42:28 +02:00
|
|
|
int i;
|
|
|
|
int ret = 0;
|
|
|
|
|
2016-06-11 22:14:08 +02:00
|
|
|
#ifdef CONFIG_DEBUG_FEATURES
|
2008-10-25 00:42:28 +02:00
|
|
|
if (priv == NULL)
|
|
|
|
{
|
2012-01-25 21:17:59 +01:00
|
|
|
usbtrace(TRACE_CLSERROR(USBMSC_TRACEERR_SETCONFIGINVALIDARGS), 0);
|
2008-10-25 00:42:28 +02:00
|
|
|
return -EIO;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
if (config == priv->config)
|
|
|
|
{
|
|
|
|
/* Already configured -- Do nothing */
|
|
|
|
|
2012-01-25 21:17:59 +01:00
|
|
|
usbtrace(TRACE_CLSERROR(USBMSC_TRACEERR_ALREADYCONFIGURED), 0);
|
2009-12-01 16:28:33 +01:00
|
|
|
return OK;
|
2008-10-25 00:42:28 +02:00
|
|
|
}
|
|
|
|
|
2017-07-16 16:43:17 +02:00
|
|
|
#ifdef CONFIG_USBDEV_DUALSPEED
|
|
|
|
hispeed = (priv->usbdev->speed == USB_SPEED_HIGH);
|
|
|
|
#endif
|
|
|
|
|
2008-10-25 00:42:28 +02:00
|
|
|
/* Discard the previous configuration data */
|
|
|
|
|
2012-01-25 21:17:59 +01:00
|
|
|
usbmsc_resetconfig(priv);
|
2008-10-25 00:42:28 +02:00
|
|
|
|
|
|
|
/* Was this a request to simply discard the current configuration? */
|
|
|
|
|
2012-01-25 21:17:59 +01:00
|
|
|
if (config == USBMSC_CONFIGIDNONE)
|
2008-10-25 00:42:28 +02:00
|
|
|
{
|
2012-01-25 21:17:59 +01:00
|
|
|
usbtrace(TRACE_CLSERROR(USBMSC_TRACEERR_CONFIGNONE), 0);
|
2009-12-01 16:28:33 +01:00
|
|
|
return OK;
|
2008-10-25 00:42:28 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/* We only accept one configuration */
|
|
|
|
|
2012-01-25 21:17:59 +01:00
|
|
|
if (config != USBMSC_CONFIGID)
|
2008-10-25 00:42:28 +02:00
|
|
|
{
|
2012-01-25 21:17:59 +01:00
|
|
|
usbtrace(TRACE_CLSERROR(USBMSC_TRACEERR_CONFIGIDBAD), 0);
|
2008-10-25 00:42:28 +02:00
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Configure the IN bulk endpoint */
|
|
|
|
|
2017-07-20 17:34:48 +02:00
|
|
|
usbmsc_copy_epdesc(USBMSC_EPBULKIN, &epdesc, &priv->devinfo,
|
2017-07-16 16:43:17 +02:00
|
|
|
hispeed);
|
|
|
|
ret = EP_CONFIGURE(priv->epbulkin, &epdesc, false);
|
2008-10-25 00:42:28 +02:00
|
|
|
if (ret < 0)
|
|
|
|
{
|
2012-01-25 21:17:59 +01:00
|
|
|
usbtrace(TRACE_CLSERROR(USBMSC_TRACEERR_EPBULKINCONFIGFAIL), 0);
|
2008-10-25 00:42:28 +02:00
|
|
|
goto errout;
|
|
|
|
}
|
|
|
|
|
2009-06-17 01:23:31 +02:00
|
|
|
priv->epbulkin->priv = priv;
|
2008-10-25 00:42:28 +02:00
|
|
|
|
|
|
|
/* Configure the OUT bulk endpoint */
|
|
|
|
|
2017-07-20 17:34:48 +02:00
|
|
|
usbmsc_copy_epdesc(USBMSC_EPBULKOUT, &epdesc, &priv->devinfo,
|
2017-07-16 16:43:17 +02:00
|
|
|
hispeed);
|
|
|
|
ret = EP_CONFIGURE(priv->epbulkout, &epdesc, true);
|
2008-10-25 00:42:28 +02:00
|
|
|
if (ret < 0)
|
|
|
|
{
|
2012-01-25 21:17:59 +01:00
|
|
|
usbtrace(TRACE_CLSERROR(USBMSC_TRACEERR_EPBULKOUTCONFIGFAIL), 0);
|
2008-10-25 00:42:28 +02:00
|
|
|
goto errout;
|
|
|
|
}
|
|
|
|
|
2009-06-17 01:23:31 +02:00
|
|
|
priv->epbulkout->priv = priv;
|
2008-10-25 00:42:28 +02:00
|
|
|
|
|
|
|
/* Queue read requests in the bulk OUT endpoint */
|
|
|
|
|
2012-01-25 21:17:59 +01:00
|
|
|
for (i = 0; i < CONFIG_USBMSC_NRDREQS; i++)
|
2008-10-25 00:42:28 +02:00
|
|
|
{
|
|
|
|
privreq = &priv->rdreqs[i];
|
|
|
|
req = privreq->req;
|
2012-01-25 21:17:59 +01:00
|
|
|
req->len = CONFIG_USBMSC_BULKOUTREQLEN;
|
2009-06-17 01:23:31 +02:00
|
|
|
req->priv = privreq;
|
2012-01-25 21:17:59 +01:00
|
|
|
req->callback = usbmsc_rdcomplete;
|
2017-07-16 16:43:17 +02:00
|
|
|
|
2008-10-25 00:42:28 +02:00
|
|
|
ret = EP_SUBMIT(priv->epbulkout, req);
|
|
|
|
if (ret < 0)
|
|
|
|
{
|
2017-07-16 16:43:17 +02:00
|
|
|
usbtrace(TRACE_CLSERROR(USBMSC_TRACEERR_RDSUBMIT),
|
|
|
|
(uint16_t)-ret);
|
2008-10-25 00:42:28 +02:00
|
|
|
goto errout;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
priv->config = config;
|
|
|
|
return OK;
|
|
|
|
|
|
|
|
errout:
|
2012-01-25 21:17:59 +01:00
|
|
|
usbmsc_resetconfig(priv);
|
2008-10-25 00:42:28 +02:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************************************************
|
2012-01-25 21:17:59 +01:00
|
|
|
* Name: usbmsc_resetconfig
|
2008-10-25 00:42:28 +02:00
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* Mark the device as not configured and disable all endpoints.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
2012-01-25 21:17:59 +01:00
|
|
|
void usbmsc_resetconfig(FAR struct usbmsc_dev_s *priv)
|
2008-10-25 00:42:28 +02:00
|
|
|
{
|
|
|
|
/* Are we configured? */
|
|
|
|
|
2012-01-25 21:17:59 +01:00
|
|
|
if (priv->config != USBMSC_CONFIGIDNONE)
|
2008-10-25 00:42:28 +02:00
|
|
|
{
|
|
|
|
/* Yes.. but not anymore */
|
|
|
|
|
2012-01-25 21:17:59 +01:00
|
|
|
priv->config = USBMSC_CONFIGIDNONE;
|
2008-10-25 00:42:28 +02:00
|
|
|
|
|
|
|
/* Disable endpoints. This should force completion of all pending
|
|
|
|
* transfers.
|
|
|
|
*/
|
|
|
|
|
|
|
|
EP_DISABLE(priv->epbulkin);
|
|
|
|
EP_DISABLE(priv->epbulkout);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************************************************
|
2012-01-25 21:17:59 +01:00
|
|
|
* Name: usbmsc_wrcomplete
|
2008-10-25 00:42:28 +02:00
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* Handle completion of write request. This function probably executes
|
|
|
|
* in the context of an interrupt handler.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
2017-07-16 16:43:17 +02:00
|
|
|
void usbmsc_wrcomplete(FAR struct usbdev_ep_s *ep,
|
|
|
|
FAR struct usbdev_req_s *req)
|
2008-10-25 00:42:28 +02:00
|
|
|
{
|
2012-01-25 21:17:59 +01:00
|
|
|
FAR struct usbmsc_dev_s *priv;
|
|
|
|
FAR struct usbmsc_req_s *privreq;
|
2008-10-25 00:42:28 +02:00
|
|
|
irqstate_t flags;
|
|
|
|
|
|
|
|
/* Sanity check */
|
|
|
|
|
2016-06-11 22:14:08 +02:00
|
|
|
#ifdef CONFIG_DEBUG_FEATURES
|
2009-06-17 01:23:31 +02:00
|
|
|
if (!ep || !ep->priv || !req || !req->priv)
|
2008-10-25 00:42:28 +02:00
|
|
|
{
|
2012-01-25 21:17:59 +01:00
|
|
|
usbtrace(TRACE_CLSERROR(USBMSC_TRACEERR_WRCOMPLETEINVALIDARGS), 0);
|
2008-10-25 00:42:28 +02:00
|
|
|
return;
|
2013-09-24 23:06:17 +02:00
|
|
|
}
|
2008-10-25 00:42:28 +02:00
|
|
|
#endif
|
|
|
|
|
|
|
|
/* Extract references to private data */
|
|
|
|
|
2015-10-10 18:41:00 +02:00
|
|
|
priv = (FAR struct usbmsc_dev_s *)ep->priv;
|
2012-01-25 21:17:59 +01:00
|
|
|
privreq = (FAR struct usbmsc_req_s *)req->priv;
|
2008-10-25 00:42:28 +02:00
|
|
|
|
|
|
|
/* Return the write request to the free list */
|
|
|
|
|
2016-02-14 14:32:58 +01:00
|
|
|
flags = enter_critical_section();
|
2015-10-10 18:41:00 +02:00
|
|
|
sq_addlast((FAR sq_entry_t *)privreq, &priv->wrreqlist);
|
2016-02-14 14:32:58 +01:00
|
|
|
leave_critical_section(flags);
|
2008-10-25 00:42:28 +02:00
|
|
|
|
|
|
|
/* Process the received data unless this is some unusual condition */
|
|
|
|
|
|
|
|
switch (req->result)
|
|
|
|
{
|
|
|
|
case OK: /* Normal completion */
|
2008-10-25 16:40:37 +02:00
|
|
|
usbtrace(TRACE_CLASSWRCOMPLETE, req->xfrd);
|
2008-10-25 00:42:28 +02:00
|
|
|
break;
|
|
|
|
|
|
|
|
case -ESHUTDOWN: /* Disconnection */
|
2012-01-25 21:17:59 +01:00
|
|
|
usbtrace(TRACE_CLSERROR(USBMSC_TRACEERR_WRSHUTDOWN), 0);
|
2008-10-25 00:42:28 +02:00
|
|
|
break;
|
|
|
|
|
|
|
|
default: /* Some other error occurred */
|
2012-01-25 21:17:59 +01:00
|
|
|
usbtrace(TRACE_CLSERROR(USBMSC_TRACEERR_WRUNEXPECTED),
|
2009-12-15 15:25:14 +01:00
|
|
|
(uint16_t)-req->result);
|
2008-10-25 00:42:28 +02:00
|
|
|
break;
|
|
|
|
};
|
|
|
|
|
|
|
|
/* Inform the worker thread that a write request has been returned */
|
|
|
|
|
2012-01-25 21:17:59 +01:00
|
|
|
priv->theventset |= USBMSC_EVENT_WRCOMPLETE;
|
2014-03-25 21:19:27 +01:00
|
|
|
usbmsc_scsi_signal(priv);
|
2008-10-25 00:42:28 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************************************************
|
2012-01-25 21:17:59 +01:00
|
|
|
* Name: usbmsc_rdcomplete
|
2008-10-25 00:42:28 +02:00
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* Handle completion of read request on the bulk OUT endpoint. This
|
|
|
|
* is handled like the receipt of serial data on the "UART"
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
2017-07-16 16:43:17 +02:00
|
|
|
void usbmsc_rdcomplete(FAR struct usbdev_ep_s *ep,
|
|
|
|
FAR struct usbdev_req_s *req)
|
2008-10-25 00:42:28 +02:00
|
|
|
{
|
2012-01-25 21:17:59 +01:00
|
|
|
FAR struct usbmsc_dev_s *priv;
|
|
|
|
FAR struct usbmsc_req_s *privreq;
|
2008-10-25 00:42:28 +02:00
|
|
|
irqstate_t flags;
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
/* Sanity check */
|
|
|
|
|
2016-06-11 22:14:08 +02:00
|
|
|
#ifdef CONFIG_DEBUG_FEATURES
|
2009-06-17 01:23:31 +02:00
|
|
|
if (!ep || !ep->priv || !req || !req->priv)
|
2008-10-25 00:42:28 +02:00
|
|
|
{
|
2012-01-25 21:17:59 +01:00
|
|
|
usbtrace(TRACE_CLSERROR(USBMSC_TRACEERR_RDCOMPLETEINVALIDARGS), 0);
|
2008-10-25 00:42:28 +02:00
|
|
|
return;
|
2013-09-24 23:06:17 +02:00
|
|
|
}
|
2008-10-25 00:42:28 +02:00
|
|
|
#endif
|
|
|
|
|
|
|
|
/* Extract references to private data */
|
|
|
|
|
2015-10-10 18:41:00 +02:00
|
|
|
priv = (FAR struct usbmsc_dev_s *)ep->priv;
|
2012-01-25 21:17:59 +01:00
|
|
|
privreq = (FAR struct usbmsc_req_s *)req->priv;
|
2008-10-25 00:42:28 +02:00
|
|
|
|
|
|
|
/* Process the received data unless this is some unusual condition */
|
|
|
|
|
|
|
|
switch (req->result)
|
|
|
|
{
|
|
|
|
case 0: /* Normal completion */
|
|
|
|
{
|
2008-10-25 16:40:37 +02:00
|
|
|
usbtrace(TRACE_CLASSRDCOMPLETE, req->xfrd);
|
2008-10-25 00:42:28 +02:00
|
|
|
|
|
|
|
/* Add the filled read request from the rdreqlist */
|
|
|
|
|
2016-02-14 14:32:58 +01:00
|
|
|
flags = enter_critical_section();
|
2015-10-10 18:41:00 +02:00
|
|
|
sq_addlast((FAR sq_entry_t *)privreq, &priv->rdreqlist);
|
2016-02-14 14:32:58 +01:00
|
|
|
leave_critical_section(flags);
|
2008-10-25 00:42:28 +02:00
|
|
|
|
2020-04-15 16:41:49 +02:00
|
|
|
/* Signal the worker thread that there is received data to be
|
|
|
|
* processed.
|
|
|
|
*/
|
2008-10-25 00:42:28 +02:00
|
|
|
|
2012-01-25 21:17:59 +01:00
|
|
|
priv->theventset |= USBMSC_EVENT_RDCOMPLETE;
|
2014-03-25 21:19:27 +01:00
|
|
|
usbmsc_scsi_signal(priv);
|
2008-10-25 00:42:28 +02:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case -ESHUTDOWN: /* Disconnection */
|
|
|
|
{
|
2012-01-25 21:17:59 +01:00
|
|
|
usbtrace(TRACE_CLSERROR(USBMSC_TRACEERR_RDSHUTDOWN), 0);
|
2008-10-25 00:42:28 +02:00
|
|
|
|
|
|
|
/* Drop the read request... it will be cleaned up later */
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
default: /* Some other error occurred */
|
|
|
|
{
|
2012-01-25 21:17:59 +01:00
|
|
|
usbtrace(TRACE_CLSERROR(USBMSC_TRACEERR_RDUNEXPECTED),
|
2009-12-15 15:25:14 +01:00
|
|
|
(uint16_t)-req->result);
|
2008-10-25 00:42:28 +02:00
|
|
|
|
|
|
|
/* Return the read request to the bulk out endpoint for re-filling */
|
|
|
|
|
|
|
|
req = privreq->req;
|
2009-06-17 01:23:31 +02:00
|
|
|
req->priv = privreq;
|
2012-01-25 21:17:59 +01:00
|
|
|
req->callback = usbmsc_rdcomplete;
|
2008-10-25 00:42:28 +02:00
|
|
|
|
|
|
|
ret = EP_SUBMIT(priv->epbulkout, req);
|
|
|
|
if (ret != OK)
|
|
|
|
{
|
2012-01-25 21:17:59 +01:00
|
|
|
usbtrace(TRACE_CLSERROR(USBMSC_TRACEERR_RDCOMPLETERDSUBMIT),
|
2009-12-15 15:25:14 +01:00
|
|
|
(uint16_t)-ret);
|
2008-10-25 00:42:28 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************************************************
|
2012-01-25 21:17:59 +01:00
|
|
|
* Name: usbmsc_deferredresponse
|
2008-10-25 00:42:28 +02:00
|
|
|
*
|
|
|
|
* Description:
|
2019-09-11 16:56:56 +02:00
|
|
|
* Some EP0 setup request cannot be responded to immediately because they
|
2008-10-25 00:42:28 +02:00
|
|
|
* require some asynchronous action from the SCSI worker thread. This
|
|
|
|
* function is provided for the SCSI thread to make that deferred response.
|
|
|
|
* The specific requests that require this deferred response are:
|
|
|
|
*
|
|
|
|
* 1. USB_REQ_SETCONFIGURATION,
|
|
|
|
* 2. USB_REQ_SETINTERFACE, or
|
2012-01-25 21:17:59 +01:00
|
|
|
* 3. USBMSC_REQ_MSRESET
|
2008-10-25 00:42:28 +02:00
|
|
|
*
|
2020-02-22 19:31:14 +01:00
|
|
|
* In all cases, the success response is a zero-length packet; the failure
|
2008-10-25 00:42:28 +02:00
|
|
|
* response is an EP0 stall.
|
|
|
|
*
|
2018-02-01 17:00:02 +01:00
|
|
|
* Input Parameters:
|
2008-10-25 00:42:28 +02:00
|
|
|
* priv - Private state structure for this USB storage instance
|
2009-12-15 15:25:14 +01:00
|
|
|
* stall - true is the action failed and a stall is required
|
2008-10-25 00:42:28 +02:00
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
2012-01-25 21:17:59 +01:00
|
|
|
void usbmsc_deferredresponse(FAR struct usbmsc_dev_s *priv, bool failed)
|
2008-10-25 00:42:28 +02:00
|
|
|
{
|
2023-03-23 19:00:03 +01:00
|
|
|
#ifndef CONFIG_USBMSC_COMPOSITE
|
2008-10-25 00:42:28 +02:00
|
|
|
FAR struct usbdev_s *dev;
|
|
|
|
FAR struct usbdev_req_s *ctrlreq;
|
|
|
|
int ret;
|
|
|
|
|
2016-06-11 22:14:08 +02:00
|
|
|
#ifdef CONFIG_DEBUG_FEATURES
|
2008-10-25 00:42:28 +02:00
|
|
|
if (!priv || !priv->usbdev || !priv->ctrlreq)
|
|
|
|
{
|
2012-01-25 21:17:59 +01:00
|
|
|
usbtrace(TRACE_CLSERROR(USBMSC_TRACEERR_DEFERREDRESPINVALIDARGS), 0);
|
2008-10-25 00:42:28 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
dev = priv->usbdev;
|
|
|
|
ctrlreq = priv->ctrlreq;
|
|
|
|
|
2008-10-25 16:40:37 +02:00
|
|
|
/* If no error occurs, respond to the deferred setup command with a null
|
2008-10-25 00:42:28 +02:00
|
|
|
* packet.
|
|
|
|
*/
|
|
|
|
|
|
|
|
if (!failed)
|
|
|
|
{
|
2008-10-25 16:40:37 +02:00
|
|
|
ctrlreq->len = 0;
|
|
|
|
ctrlreq->flags = USBDEV_REQFLAGS_NULLPKT;
|
|
|
|
ret = EP_SUBMIT(dev->ep0, ctrlreq);
|
2008-10-25 00:42:28 +02:00
|
|
|
if (ret < 0)
|
|
|
|
{
|
2012-01-25 21:17:59 +01:00
|
|
|
usbtrace(TRACE_CLSERROR(USBMSC_TRACEERR_DEFERREDRESPSUBMIT),
|
2009-12-15 15:25:14 +01:00
|
|
|
(uint16_t)-ret);
|
2008-10-25 00:42:28 +02:00
|
|
|
#if 0 /* Not necessary */
|
|
|
|
ctrlreq->result = OK;
|
2012-01-25 21:17:59 +01:00
|
|
|
usbmsc_ep0incomplete(dev->ep0, ctrlreq);
|
2008-10-25 00:42:28 +02:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* On a failure, the USB driver will stall. */
|
|
|
|
|
2013-09-07 01:24:02 +02:00
|
|
|
usbtrace(TRACE_CLSERROR(USBMSC_TRACEERR_DEFERREDRESPSTALLED), 0);
|
2008-10-25 00:42:28 +02:00
|
|
|
EP_STALL(dev->ep0);
|
|
|
|
}
|
2023-03-23 19:00:03 +01:00
|
|
|
#endif
|
2008-10-25 00:42:28 +02:00
|
|
|
}
|
|
|
|
|
2014-03-25 21:19:27 +01:00
|
|
|
/****************************************************************************
|
|
|
|
* Name: usbmsc_sync_wait
|
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* Wait for the worker thread to obtain the USB MSC state data
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
2020-04-01 18:13:52 +02:00
|
|
|
static int usbmsc_sync_wait(FAR struct usbmsc_dev_s *priv)
|
2014-03-25 21:19:27 +01:00
|
|
|
{
|
2020-04-01 18:13:52 +02:00
|
|
|
return nxsem_wait_uninterruptible(&priv->thsynch);
|
2014-03-25 21:19:27 +01:00
|
|
|
}
|
|
|
|
|
2008-10-25 00:42:28 +02:00
|
|
|
/****************************************************************************
|
2012-01-25 21:17:59 +01:00
|
|
|
* Name: usbmsc_configure
|
2008-10-25 00:42:28 +02:00
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* One-time initialization of the USB storage driver. The initialization
|
|
|
|
* sequence is as follows:
|
|
|
|
*
|
2012-01-25 21:17:59 +01:00
|
|
|
* 1. Call usbmsc_configure to perform one-time initialization specifying
|
2008-10-25 00:42:28 +02:00
|
|
|
* the number of luns.
|
2012-01-25 21:17:59 +01:00
|
|
|
* 2. Call usbmsc_bindlun to configure each supported LUN
|
|
|
|
* 3. Call usbmsc_exportluns when all LUNs are configured
|
2008-10-25 00:42:28 +02:00
|
|
|
*
|
|
|
|
* Input Parameters:
|
|
|
|
* nluns - the number of LUNs that will be registered
|
|
|
|
* handle - Location to return a handle that is used in other API calls.
|
|
|
|
*
|
|
|
|
* Returned Value:
|
|
|
|
* 0 on success; a negated errno on failure
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
2012-01-25 21:17:59 +01:00
|
|
|
int usbmsc_configure(unsigned int nluns, void **handle)
|
2008-10-25 00:42:28 +02:00
|
|
|
{
|
2012-01-25 21:17:59 +01:00
|
|
|
FAR struct usbmsc_alloc_s *alloc;
|
|
|
|
FAR struct usbmsc_dev_s *priv;
|
|
|
|
FAR struct usbmsc_driver_s *drvr;
|
2008-10-25 00:42:28 +02:00
|
|
|
int ret;
|
|
|
|
|
2016-06-11 22:14:08 +02:00
|
|
|
#ifdef CONFIG_DEBUG_FEATURES
|
2008-10-25 00:42:28 +02:00
|
|
|
if (nluns > 15)
|
|
|
|
{
|
2012-01-25 21:17:59 +01:00
|
|
|
usbtrace(TRACE_CLSERROR(USBMSC_TRACEERR_TOOMANYLUNS), 0);
|
2008-10-25 00:42:28 +02:00
|
|
|
return -EDOM;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/* Allocate the structures needed */
|
|
|
|
|
2020-04-01 18:13:52 +02:00
|
|
|
alloc = (FAR struct usbmsc_alloc_s *)
|
|
|
|
kmm_malloc(sizeof(struct usbmsc_alloc_s));
|
2008-10-25 00:42:28 +02:00
|
|
|
if (!alloc)
|
|
|
|
{
|
2012-01-25 21:17:59 +01:00
|
|
|
usbtrace(TRACE_CLSERROR(USBMSC_TRACEERR_ALLOCDEVSTRUCT), 0);
|
2008-10-25 00:42:28 +02:00
|
|
|
return -ENOMEM;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Initialize the USB storage driver structure */
|
|
|
|
|
|
|
|
priv = &alloc->dev;
|
2012-01-25 21:17:59 +01:00
|
|
|
memset(priv, 0, sizeof(struct usbmsc_dev_s));
|
2008-10-25 00:42:28 +02:00
|
|
|
|
2022-09-06 08:18:45 +02:00
|
|
|
/* Initialize semaphores & mutex */
|
2016-11-03 18:00:47 +01:00
|
|
|
|
2017-10-03 20:51:15 +02:00
|
|
|
nxsem_init(&priv->thsynch, 0, 0);
|
2022-09-06 08:18:45 +02:00
|
|
|
nxmutex_init(&priv->thlock);
|
2017-10-03 20:51:15 +02:00
|
|
|
nxsem_init(&priv->thwaitsem, 0, 0);
|
2008-10-25 00:42:28 +02:00
|
|
|
|
2016-11-03 18:00:47 +01:00
|
|
|
sq_init(&priv->wrreqlist);
|
2008-10-25 00:42:28 +02:00
|
|
|
priv->nluns = nluns;
|
|
|
|
|
|
|
|
/* Allocate the LUN table */
|
|
|
|
|
2015-10-10 18:41:00 +02:00
|
|
|
priv->luntab = (FAR struct usbmsc_lun_s *)
|
|
|
|
kmm_malloc(priv->nluns*sizeof(struct usbmsc_lun_s));
|
|
|
|
|
2008-10-25 00:42:28 +02:00
|
|
|
if (!priv->luntab)
|
|
|
|
{
|
|
|
|
ret = -ENOMEM;
|
|
|
|
goto errout;
|
|
|
|
}
|
2013-09-24 23:06:17 +02:00
|
|
|
|
2012-01-25 21:17:59 +01:00
|
|
|
memset(priv->luntab, 0, priv->nluns * sizeof(struct usbmsc_lun_s));
|
2008-10-25 00:42:28 +02:00
|
|
|
|
|
|
|
/* Initialize the USB class driver structure */
|
|
|
|
|
|
|
|
drvr = &alloc->drvr;
|
|
|
|
#ifdef CONFIG_USBDEV_DUALSPEED
|
|
|
|
drvr->drvr.speed = USB_SPEED_HIGH;
|
|
|
|
#else
|
|
|
|
drvr->drvr.speed = USB_SPEED_FULL;
|
|
|
|
#endif
|
|
|
|
drvr->drvr.ops = &g_driverops;
|
|
|
|
drvr->dev = priv;
|
|
|
|
|
2017-07-20 18:07:53 +02:00
|
|
|
/* Initialize the device information if we are not part of a composite.
|
|
|
|
* If we are part of a composite, the device information will be
|
2020-04-01 18:13:52 +02:00
|
|
|
* initialized through coordinated actions of
|
|
|
|
* usbmsc_get_composite_devdesc() and board-specific logic.
|
2017-07-20 18:07:53 +02:00
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef CONFIG_USBMSC_COMPOSITE
|
|
|
|
/* minor - not used */
|
2020-04-01 18:13:52 +02:00
|
|
|
|
2017-07-20 18:07:53 +02:00
|
|
|
/* Interfaces (ifnobase == 0) */
|
|
|
|
|
2020-04-01 18:13:52 +02:00
|
|
|
priv->devinfo.ninterfaces = USBMSC_NINTERFACES; /* Number of interfaces
|
|
|
|
* in the configuration */
|
2017-07-20 18:07:53 +02:00
|
|
|
|
|
|
|
/* Strings (strbase == 0) */
|
|
|
|
|
|
|
|
priv->devinfo.nstrings = USBMSC_NSTRIDS; /* Number of Strings */
|
|
|
|
|
|
|
|
/* Endpoints */
|
|
|
|
|
|
|
|
priv->devinfo.nendpoints = USBMSC_NENDPOINTS;
|
|
|
|
priv->devinfo.epno[USBMSC_EP_BULKIN_IDX] = CONFIG_USBMSC_EPBULKIN;
|
|
|
|
priv->devinfo.epno[USBMSC_EP_BULKOUT_IDX] = CONFIG_USBMSC_EPBULKOUT;
|
|
|
|
#endif
|
|
|
|
|
2008-10-25 00:42:28 +02:00
|
|
|
/* Return the handle and success */
|
|
|
|
|
2015-10-10 18:41:00 +02:00
|
|
|
*handle = (FAR void *)alloc;
|
2008-10-25 00:42:28 +02:00
|
|
|
return OK;
|
|
|
|
|
|
|
|
errout:
|
2012-01-25 21:17:59 +01:00
|
|
|
usbmsc_uninitialize(alloc);
|
2008-10-25 00:42:28 +02:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************************************************
|
2012-01-25 21:17:59 +01:00
|
|
|
* Name: usbmsc_bindlun
|
2008-10-25 00:42:28 +02:00
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* Bind the block driver specified by drvrpath to a USB storage LUN.
|
|
|
|
*
|
|
|
|
* Input Parameters:
|
2020-04-01 18:13:52 +02:00
|
|
|
* handle - The handle returned by a previous call to
|
|
|
|
* usbmsc_configure().
|
2008-10-25 00:42:28 +02:00
|
|
|
* drvrpath - the full path to the block driver
|
|
|
|
* startsector - A sector offset into the block driver to the start of the
|
|
|
|
* partition on drvrpath (0 if no partitions)
|
|
|
|
* nsectors - The number of sectors in the partition (if 0, all sectors
|
|
|
|
* to the end of the media will be exported).
|
|
|
|
* lunno - the LUN to bind to
|
|
|
|
*
|
|
|
|
* Returned Value:
|
|
|
|
* 0 on success; a negated errno on failure.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
2012-01-25 21:17:59 +01:00
|
|
|
int usbmsc_bindlun(FAR void *handle, FAR const char *drvrpath,
|
|
|
|
unsigned int lunno, off_t startsector, size_t nsectors,
|
|
|
|
bool readonly)
|
2008-10-25 00:42:28 +02:00
|
|
|
{
|
2012-01-25 21:17:59 +01:00
|
|
|
FAR struct usbmsc_alloc_s *alloc = (FAR struct usbmsc_alloc_s *)handle;
|
|
|
|
FAR struct usbmsc_dev_s *priv;
|
|
|
|
FAR struct usbmsc_lun_s *lun;
|
2008-10-25 00:42:28 +02:00
|
|
|
FAR struct inode *inode;
|
|
|
|
struct geometry geo;
|
|
|
|
int ret;
|
|
|
|
|
2016-06-11 22:14:08 +02:00
|
|
|
#ifdef CONFIG_DEBUG_FEATURES
|
2014-02-11 01:08:49 +01:00
|
|
|
if (!alloc || !drvrpath || startsector < 0)
|
2008-10-25 00:42:28 +02:00
|
|
|
{
|
2012-01-25 21:17:59 +01:00
|
|
|
usbtrace(TRACE_CLSERROR(USBMSC_TRACEERR_BINLUNINVALIDARGS1), 0);
|
2008-10-25 00:42:28 +02:00
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
priv = &alloc->dev;
|
|
|
|
|
2016-06-11 22:14:08 +02:00
|
|
|
#ifdef CONFIG_DEBUG_FEATURES
|
2008-10-25 00:42:28 +02:00
|
|
|
if (!priv->luntab)
|
|
|
|
{
|
2012-01-25 21:17:59 +01:00
|
|
|
usbtrace(TRACE_CLSERROR(USBMSC_TRACEERR_INTERNALCONFUSION1), 0);
|
2008-10-25 00:42:28 +02:00
|
|
|
return -EIO;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (lunno > priv->nluns)
|
|
|
|
{
|
2012-01-25 21:17:59 +01:00
|
|
|
usbtrace(TRACE_CLSERROR(USBMSC_TRACEERR_BINDLUNINVALIDARGS2), 0);
|
2008-10-25 00:42:28 +02:00
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
lun = &priv->luntab[lunno];
|
|
|
|
|
2016-06-11 22:14:08 +02:00
|
|
|
#ifdef CONFIG_DEBUG_FEATURES
|
2008-10-25 00:42:28 +02:00
|
|
|
if (lun->inode != NULL)
|
|
|
|
{
|
2012-01-25 21:17:59 +01:00
|
|
|
usbtrace(TRACE_CLSERROR(USBMSC_TRACEERR_LUNALREADYBOUND), 0);
|
2008-10-25 00:42:28 +02:00
|
|
|
return -EBUSY;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/* Open the block driver */
|
|
|
|
|
|
|
|
ret = open_blockdriver(drvrpath, 0, &inode);
|
|
|
|
if (ret < 0)
|
|
|
|
{
|
2012-01-25 21:17:59 +01:00
|
|
|
usbtrace(TRACE_CLSERROR(USBMSC_TRACEERR_BLKDRVEOPEN), 0);
|
2008-10-25 00:42:28 +02:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Get the drive geometry */
|
|
|
|
|
|
|
|
if (!inode || !inode->u.i_bops || !inode->u.i_bops->geometry ||
|
|
|
|
inode->u.i_bops->geometry(inode, &geo) != OK || !geo.geo_available)
|
|
|
|
{
|
2012-01-25 21:17:59 +01:00
|
|
|
usbtrace(TRACE_CLSERROR(USBMSC_TRACEERR_NOGEOMETRY), 0);
|
2008-10-25 00:42:28 +02:00
|
|
|
return -ENODEV;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Verify that the partition parameters are valid */
|
|
|
|
|
|
|
|
if (startsector >= geo.geo_nsectors)
|
|
|
|
{
|
2012-01-25 21:17:59 +01:00
|
|
|
usbtrace(TRACE_CLSERROR(USBMSC_TRACEERR_BINDLUNINVALIDARGS3), 0);
|
2008-10-25 00:42:28 +02:00
|
|
|
return -EDOM;
|
|
|
|
}
|
|
|
|
else if (nsectors == 0)
|
|
|
|
{
|
|
|
|
nsectors = geo.geo_nsectors - startsector;
|
|
|
|
}
|
|
|
|
else if (startsector + nsectors >= geo.geo_nsectors)
|
|
|
|
{
|
2012-01-25 21:17:59 +01:00
|
|
|
usbtrace(TRACE_CLSERROR(USBMSC_TRACEERR_BINDLUNINVALIDARGS4), 0);
|
2008-10-25 00:42:28 +02:00
|
|
|
return -EDOM;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Initialize the LUN structure */
|
|
|
|
|
2017-06-19 18:45:35 +02:00
|
|
|
memset(lun, 0, sizeof(struct usbmsc_lun_s));
|
2008-10-25 00:42:28 +02:00
|
|
|
|
2017-07-16 16:43:17 +02:00
|
|
|
/* Allocate an I/O buffer big enough to hold one hardware sector. SCSI
|
|
|
|
* commands are processed one at a time so all LUNs may share a single I/O
|
|
|
|
* buffer. The I/O buffer will be allocated so that is it as large as the
|
|
|
|
* largest block device sector size
|
2008-10-25 00:42:28 +02:00
|
|
|
*/
|
|
|
|
|
|
|
|
if (!priv->iobuffer)
|
|
|
|
{
|
2022-07-12 07:44:55 +02:00
|
|
|
#ifdef CONFIG_USBMSC_WRMULTIPLE
|
|
|
|
priv->iobuffer = (FAR uint8_t *)kmm_malloc(geo.geo_sectorsize *
|
|
|
|
CONFIG_USBMSC_NWRREQS);
|
|
|
|
#else
|
2015-10-10 18:41:00 +02:00
|
|
|
priv->iobuffer = (FAR uint8_t *)kmm_malloc(geo.geo_sectorsize);
|
2022-07-12 07:44:55 +02:00
|
|
|
#endif
|
2008-10-25 00:42:28 +02:00
|
|
|
if (!priv->iobuffer)
|
|
|
|
{
|
2020-04-01 18:13:52 +02:00
|
|
|
usbtrace(TRACE_CLSERROR(USBMSC_TRACEERR_ALLOCIOBUFFER),
|
|
|
|
geo.geo_sectorsize);
|
2008-10-25 00:42:28 +02:00
|
|
|
return -ENOMEM;
|
|
|
|
}
|
2013-09-24 23:06:17 +02:00
|
|
|
|
2022-07-12 07:44:55 +02:00
|
|
|
#ifdef CONFIG_USBMSC_WRMULTIPLE
|
|
|
|
priv->iosize = geo.geo_sectorsize * CONFIG_USBMSC_NWRREQS;
|
|
|
|
#else
|
2008-10-25 00:42:28 +02:00
|
|
|
priv->iosize = geo.geo_sectorsize;
|
2022-07-12 07:44:55 +02:00
|
|
|
#endif
|
2008-10-25 00:42:28 +02:00
|
|
|
}
|
|
|
|
else if (priv->iosize < geo.geo_sectorsize)
|
|
|
|
{
|
2017-07-16 16:43:17 +02:00
|
|
|
FAR void *tmp;
|
|
|
|
|
|
|
|
tmp = (FAR void *)kmm_realloc(priv->iobuffer, geo.geo_sectorsize);
|
2008-10-25 00:42:28 +02:00
|
|
|
if (!tmp)
|
|
|
|
{
|
2020-04-01 18:13:52 +02:00
|
|
|
usbtrace(TRACE_CLSERROR(USBMSC_TRACEERR_REALLOCIOBUFFER),
|
|
|
|
geo.geo_sectorsize);
|
2008-10-25 00:42:28 +02:00
|
|
|
return -ENOMEM;
|
|
|
|
}
|
|
|
|
|
2015-10-10 18:41:00 +02:00
|
|
|
priv->iobuffer = (FAR uint8_t *)tmp;
|
2008-10-25 00:42:28 +02:00
|
|
|
priv->iosize = geo.geo_sectorsize;
|
|
|
|
}
|
|
|
|
|
|
|
|
lun->inode = inode;
|
|
|
|
lun->startsector = startsector;
|
|
|
|
lun->nsectors = nsectors;
|
|
|
|
lun->sectorsize = geo.geo_sectorsize;
|
2017-02-09 02:12:56 +01:00
|
|
|
lun->readonly = readonly;
|
2008-10-25 00:42:28 +02:00
|
|
|
|
2020-04-15 16:41:49 +02:00
|
|
|
/* If the driver does not support the write method, then this is read-
|
|
|
|
* only.
|
|
|
|
*/
|
2008-10-25 00:42:28 +02:00
|
|
|
|
|
|
|
if (!inode->u.i_bops->write)
|
|
|
|
{
|
2009-12-15 15:25:14 +01:00
|
|
|
lun->readonly = true;
|
2008-10-25 00:42:28 +02:00
|
|
|
}
|
2013-09-24 23:06:17 +02:00
|
|
|
|
2008-10-25 00:42:28 +02:00
|
|
|
return OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************************************************
|
2012-01-25 21:17:59 +01:00
|
|
|
* Name: usbmsc_unbindlun
|
2008-10-25 00:42:28 +02:00
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* Un-bind the block driver for the specified LUN
|
|
|
|
*
|
|
|
|
* Input Parameters:
|
2012-01-25 21:17:59 +01:00
|
|
|
* handle - The handle returned by a previous call to usbmsc_configure().
|
2008-10-25 00:42:28 +02:00
|
|
|
* lun - the LUN to unbind from
|
|
|
|
*
|
|
|
|
* Returned Value:
|
|
|
|
* 0 on success; a negated errno on failure.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
2012-01-25 21:17:59 +01:00
|
|
|
int usbmsc_unbindlun(FAR void *handle, unsigned int lunno)
|
2008-10-25 00:42:28 +02:00
|
|
|
{
|
2012-01-25 21:17:59 +01:00
|
|
|
FAR struct usbmsc_alloc_s *alloc = (FAR struct usbmsc_alloc_s *)handle;
|
|
|
|
FAR struct usbmsc_dev_s *priv;
|
|
|
|
FAR struct usbmsc_lun_s *lun;
|
2008-10-25 00:42:28 +02:00
|
|
|
int ret;
|
|
|
|
|
2016-06-11 22:14:08 +02:00
|
|
|
#ifdef CONFIG_DEBUG_FEATURES
|
2008-10-25 00:42:28 +02:00
|
|
|
if (!alloc)
|
|
|
|
{
|
2012-01-25 21:17:59 +01:00
|
|
|
usbtrace(TRACE_CLSERROR(USBMSC_TRACEERR_UNBINDLUNINVALIDARGS1), 0);
|
2008-10-25 00:42:28 +02:00
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
priv = &alloc->dev;
|
|
|
|
|
2016-06-11 22:14:08 +02:00
|
|
|
#ifdef CONFIG_DEBUG_FEATURES
|
2008-10-25 00:42:28 +02:00
|
|
|
if (!priv->luntab)
|
|
|
|
{
|
2012-01-25 21:17:59 +01:00
|
|
|
usbtrace(TRACE_CLSERROR(USBMSC_TRACEERR_INTERNALCONFUSION2), 0);
|
2008-10-25 00:42:28 +02:00
|
|
|
return -EIO;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (lunno > priv->nluns)
|
|
|
|
{
|
2012-01-25 21:17:59 +01:00
|
|
|
usbtrace(TRACE_CLSERROR(USBMSC_TRACEERR_UNBINDLUNINVALIDARGS2), 0);
|
2008-10-25 00:42:28 +02:00
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
lun = &priv->luntab[lunno];
|
2022-09-06 08:18:45 +02:00
|
|
|
ret = nxmutex_lock(&priv->thlock);
|
2020-04-01 18:13:52 +02:00
|
|
|
if (ret < 0)
|
|
|
|
{
|
|
|
|
return ret;
|
|
|
|
}
|
2008-10-25 00:42:28 +02:00
|
|
|
|
2016-06-11 22:14:08 +02:00
|
|
|
#ifdef CONFIG_DEBUG_FEATURES
|
2008-10-25 00:42:28 +02:00
|
|
|
if (lun->inode == NULL)
|
|
|
|
{
|
2012-01-25 21:17:59 +01:00
|
|
|
usbtrace(TRACE_CLSERROR(USBMSC_TRACEERR_LUNNOTBOUND), 0);
|
2008-10-25 00:42:28 +02:00
|
|
|
ret = -EBUSY;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
#endif
|
2020-04-01 18:13:52 +02:00
|
|
|
{
|
2008-10-25 00:42:28 +02:00
|
|
|
/* Close the block driver */
|
|
|
|
|
2020-04-01 18:13:52 +02:00
|
|
|
usbmsc_lununinitialize(lun);
|
|
|
|
ret = OK;
|
|
|
|
}
|
2008-10-25 00:42:28 +02:00
|
|
|
|
2022-09-06 08:18:45 +02:00
|
|
|
nxmutex_unlock(&priv->thlock);
|
2008-10-25 00:42:28 +02:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************************************************
|
2012-01-25 21:17:59 +01:00
|
|
|
* Name: usbmsc_exportluns
|
2008-10-25 00:42:28 +02:00
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* After all of the LUNs have been bound, this function may be called
|
|
|
|
* in order to export those LUNs in the USB storage device.
|
|
|
|
*
|
|
|
|
* Input Parameters:
|
2012-01-25 21:17:59 +01:00
|
|
|
* handle - The handle returned by a previous call to usbmsc_configure().
|
2008-10-25 00:42:28 +02:00
|
|
|
*
|
|
|
|
* Returned Value:
|
|
|
|
* 0 on success; a negated errno on failure
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
2019-07-01 13:45:56 +02:00
|
|
|
#if !defined(CONFIG_USBDEV_COMPOSITE) && defined(CONFIG_USBMSC_COMPOSITE)
|
2012-01-27 00:14:27 +01:00
|
|
|
static
|
|
|
|
#endif
|
2012-01-25 21:17:59 +01:00
|
|
|
int usbmsc_exportluns(FAR void *handle)
|
2008-10-25 00:42:28 +02:00
|
|
|
{
|
2012-01-25 21:17:59 +01:00
|
|
|
FAR struct usbmsc_alloc_s *alloc = (FAR struct usbmsc_alloc_s *)handle;
|
|
|
|
FAR struct usbmsc_dev_s *priv;
|
2015-07-01 18:02:19 +02:00
|
|
|
#ifndef CONFIG_USBMSC_COMPOSITE
|
2012-01-25 21:17:59 +01:00
|
|
|
FAR struct usbmsc_driver_s *drvr;
|
2015-07-01 18:02:19 +02:00
|
|
|
#endif
|
2008-10-25 00:42:28 +02:00
|
|
|
irqstate_t flags;
|
2020-04-01 18:13:52 +02:00
|
|
|
int ret;
|
2008-10-25 00:42:28 +02:00
|
|
|
|
2016-06-11 22:14:08 +02:00
|
|
|
#ifdef CONFIG_DEBUG_FEATURES
|
2008-10-25 00:42:28 +02:00
|
|
|
if (!alloc)
|
|
|
|
{
|
2012-01-25 21:17:59 +01:00
|
|
|
usbtrace(TRACE_CLSERROR(USBMSC_TRACEERR_EXPORTLUNSINVALIDARGS), 0);
|
2008-10-25 00:42:28 +02:00
|
|
|
return -ENXIO;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
priv = &alloc->dev;
|
2015-07-01 18:02:19 +02:00
|
|
|
#ifndef CONFIG_USBMSC_COMPOSITE
|
2008-10-25 00:42:28 +02:00
|
|
|
drvr = &alloc->drvr;
|
2015-07-01 18:02:19 +02:00
|
|
|
#endif
|
2008-10-25 00:42:28 +02:00
|
|
|
|
2014-03-25 21:19:27 +01:00
|
|
|
/* Start the worker thread
|
|
|
|
*
|
|
|
|
* REVISIT: g_usbmsc_handoff is a global and, hence, really requires
|
|
|
|
* some protection against re-entrant usage.
|
|
|
|
*/
|
|
|
|
|
2022-09-06 08:18:45 +02:00
|
|
|
ret = nxmutex_lock(&priv->thlock);
|
2020-04-01 18:13:52 +02:00
|
|
|
if (ret < 0)
|
|
|
|
{
|
|
|
|
return ret;
|
|
|
|
}
|
2008-10-25 00:42:28 +02:00
|
|
|
|
2014-03-25 21:19:27 +01:00
|
|
|
priv->thstate = USBMSC_STATE_NOTSTARTED;
|
2012-01-25 21:17:59 +01:00
|
|
|
priv->theventset = USBMSC_EVENT_NOEVENTS;
|
2008-10-25 00:42:28 +02:00
|
|
|
|
2014-03-25 21:19:27 +01:00
|
|
|
g_usbmsc_handoff = priv;
|
|
|
|
|
2016-06-11 19:59:51 +02:00
|
|
|
uinfo("Starting SCSI worker thread\n");
|
2022-03-21 23:47:09 +01:00
|
|
|
ret = kthread_create("scsid", CONFIG_USBMSC_SCSI_PRIO,
|
|
|
|
CONFIG_USBMSC_SCSI_STACKSIZE,
|
|
|
|
usbmsc_scsi_main, NULL);
|
|
|
|
if (ret < 0)
|
2008-10-25 00:42:28 +02:00
|
|
|
{
|
2022-03-21 23:47:09 +01:00
|
|
|
usbtrace(TRACE_CLSERROR(USBMSC_TRACEERR_THREADCREATE), (uint16_t)ret);
|
2014-03-25 21:19:27 +01:00
|
|
|
goto errout_with_lock;
|
2008-10-25 00:42:28 +02:00
|
|
|
}
|
|
|
|
|
2022-03-21 23:47:09 +01:00
|
|
|
priv->thpid = (pid_t)ret;
|
|
|
|
|
2014-03-25 21:19:27 +01:00
|
|
|
/* Wait for the worker thread to run and initialize */
|
2013-11-01 19:09:25 +01:00
|
|
|
|
2016-06-11 19:59:51 +02:00
|
|
|
uinfo("Waiting for the SCSI worker thread\n");
|
2020-04-01 18:13:52 +02:00
|
|
|
ret = usbmsc_sync_wait(priv);
|
|
|
|
if (ret < 0)
|
|
|
|
{
|
|
|
|
goto errout_with_lock;
|
|
|
|
}
|
|
|
|
|
2014-03-25 21:19:27 +01:00
|
|
|
DEBUGASSERT(g_usbmsc_handoff == NULL);
|
2013-11-01 19:09:25 +01:00
|
|
|
|
2020-04-15 16:41:49 +02:00
|
|
|
/* Register the USB storage class driver (unless we are part of a composite
|
|
|
|
* device).
|
|
|
|
*/
|
2008-10-25 00:42:28 +02:00
|
|
|
|
2012-01-26 00:04:17 +01:00
|
|
|
#ifndef CONFIG_USBMSC_COMPOSITE
|
2008-10-25 00:42:28 +02:00
|
|
|
ret = usbdev_register(&drvr->drvr);
|
|
|
|
if (ret != OK)
|
|
|
|
{
|
2012-01-25 21:17:59 +01:00
|
|
|
usbtrace(TRACE_CLSERROR(USBMSC_TRACEERR_DEVREGISTER), (uint16_t)-ret);
|
2014-03-25 21:19:27 +01:00
|
|
|
goto errout_with_lock;
|
2008-10-25 00:42:28 +02:00
|
|
|
}
|
2012-01-25 20:27:20 +01:00
|
|
|
#endif
|
2008-10-25 00:42:28 +02:00
|
|
|
|
|
|
|
/* Signal to start the thread */
|
|
|
|
|
2016-06-11 19:59:51 +02:00
|
|
|
uinfo("Signalling for the SCSI worker thread\n");
|
2016-02-14 14:32:58 +01:00
|
|
|
flags = enter_critical_section();
|
2012-01-25 21:17:59 +01:00
|
|
|
priv->theventset |= USBMSC_EVENT_READY;
|
2014-03-25 21:19:27 +01:00
|
|
|
usbmsc_scsi_signal(priv);
|
2016-02-14 14:32:58 +01:00
|
|
|
leave_critical_section(flags);
|
2008-10-25 00:42:28 +02:00
|
|
|
|
2014-03-25 21:19:27 +01:00
|
|
|
errout_with_lock:
|
2022-09-06 08:18:45 +02:00
|
|
|
nxmutex_unlock(&priv->thlock);
|
2008-10-25 00:42:28 +02:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2012-01-27 00:14:27 +01:00
|
|
|
/****************************************************************************
|
|
|
|
* Name: usbmsc_classobject
|
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* Register USB mass storage device and return the class object.
|
|
|
|
*
|
|
|
|
* Input Parameters:
|
|
|
|
* classdev - The location to return the CDC serial class' device
|
|
|
|
* instance.
|
|
|
|
*
|
|
|
|
* Returned Value:
|
|
|
|
* 0 on success; a negated errno on failure
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
#ifdef CONFIG_USBMSC_COMPOSITE
|
|
|
|
int usbmsc_classobject(FAR void *handle,
|
2017-07-20 17:34:48 +02:00
|
|
|
FAR struct usbdev_devinfo_s *devinfo,
|
2012-01-27 00:14:27 +01:00
|
|
|
FAR struct usbdevclass_driver_s **classdev)
|
|
|
|
{
|
2012-01-27 17:25:57 +01:00
|
|
|
FAR struct usbmsc_alloc_s *alloc = (FAR struct usbmsc_alloc_s *)handle;
|
2012-01-27 00:14:27 +01:00
|
|
|
int ret;
|
|
|
|
|
2017-07-16 16:43:17 +02:00
|
|
|
DEBUGASSERT(handle != NULL && classdev != NULL);
|
|
|
|
|
|
|
|
/* Save the device description */
|
|
|
|
|
2017-07-20 17:34:48 +02:00
|
|
|
memcpy(&alloc->dev.devinfo, devinfo, sizeof(struct usbdev_devinfo_s));
|
2012-01-27 00:14:27 +01:00
|
|
|
|
|
|
|
/* Export the LUNs as with the "standalone" USB mass storage driver, but
|
|
|
|
* don't register the class instance with the USB device infrastructure.
|
|
|
|
*/
|
|
|
|
|
|
|
|
ret = usbmsc_exportluns(handle);
|
|
|
|
if (ret == OK)
|
|
|
|
{
|
2018-09-14 14:55:45 +02:00
|
|
|
/* On success, return an (typed) instance of the class instance */
|
2012-01-27 00:14:27 +01:00
|
|
|
|
2012-01-27 17:25:57 +01:00
|
|
|
*classdev = &alloc->drvr.drvr;
|
2012-01-27 00:14:27 +01:00
|
|
|
}
|
2013-09-24 23:06:17 +02:00
|
|
|
|
2012-01-27 00:14:27 +01:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2008-10-25 00:42:28 +02:00
|
|
|
/****************************************************************************
|
2012-01-25 21:17:59 +01:00
|
|
|
* Name: usbmsc_uninitialize
|
2008-10-25 00:42:28 +02:00
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* Un-initialize the USB storage class driver
|
|
|
|
*
|
|
|
|
* Input Parameters:
|
2012-01-25 21:17:59 +01:00
|
|
|
* handle - The handle returned by a previous call to usbmsc_configure().
|
2008-10-25 00:42:28 +02:00
|
|
|
*
|
|
|
|
* Returned Value:
|
|
|
|
* None
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
2012-01-25 21:17:59 +01:00
|
|
|
void usbmsc_uninitialize(FAR void *handle)
|
2008-10-25 00:42:28 +02:00
|
|
|
{
|
2012-01-25 21:17:59 +01:00
|
|
|
FAR struct usbmsc_alloc_s *alloc = (FAR struct usbmsc_alloc_s *)handle;
|
|
|
|
FAR struct usbmsc_dev_s *priv;
|
2008-10-25 00:42:28 +02:00
|
|
|
irqstate_t flags;
|
2020-04-01 18:13:52 +02:00
|
|
|
int ret;
|
2008-10-25 00:42:28 +02:00
|
|
|
int i;
|
|
|
|
|
2016-06-11 22:14:08 +02:00
|
|
|
#ifdef CONFIG_DEBUG_FEATURES
|
2008-10-25 00:42:28 +02:00
|
|
|
if (!handle)
|
|
|
|
{
|
2012-01-25 21:17:59 +01:00
|
|
|
usbtrace(TRACE_CLSERROR(USBMSC_TRACEERR_UNINITIALIZEINVALIDARGS), 0);
|
2008-10-25 00:42:28 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
#endif
|
2013-09-24 23:06:17 +02:00
|
|
|
|
2008-10-25 00:42:28 +02:00
|
|
|
priv = &alloc->dev;
|
|
|
|
|
2013-11-05 16:12:08 +01:00
|
|
|
#ifdef CONFIG_USBMSC_COMPOSITE
|
|
|
|
/* Check for pass 2 uninitialization. We did most of the work on the
|
|
|
|
* first pass uninitialization.
|
|
|
|
*/
|
|
|
|
|
2014-03-25 21:19:27 +01:00
|
|
|
if (priv->thpid == 0)
|
2013-11-05 16:12:08 +01:00
|
|
|
{
|
|
|
|
/* In this second and final pass, all that remains to be done is to
|
|
|
|
* free the memory resources.
|
|
|
|
*/
|
|
|
|
|
2014-09-01 01:04:02 +02:00
|
|
|
kmm_free(priv);
|
2013-11-05 16:12:08 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2008-10-25 00:42:28 +02:00
|
|
|
/* If the thread hasn't already exitted, tell it to exit now */
|
|
|
|
|
2012-01-25 21:17:59 +01:00
|
|
|
if (priv->thstate != USBMSC_STATE_NOTSTARTED)
|
2008-10-25 00:42:28 +02:00
|
|
|
{
|
2020-04-01 18:13:52 +02:00
|
|
|
/* Get exclusive access to SCSI state data */
|
|
|
|
|
|
|
|
do
|
|
|
|
{
|
2022-09-06 08:18:45 +02:00
|
|
|
ret = nxmutex_lock(&priv->thlock);
|
2020-04-01 18:13:52 +02:00
|
|
|
|
2022-09-06 08:18:45 +02:00
|
|
|
/* nxmutex_lock() will fail with ECANCELED, only
|
2020-04-01 18:13:52 +02:00
|
|
|
* if this thread is canceled. At this point, we
|
|
|
|
* have no option but to continue with the teardown.
|
|
|
|
*/
|
|
|
|
|
2020-04-15 16:27:20 +02:00
|
|
|
DEBUGASSERT(ret == OK || ret == -ECANCELED);
|
2020-04-01 18:13:52 +02:00
|
|
|
}
|
|
|
|
while (ret < 0);
|
|
|
|
|
|
|
|
/* The thread was started.. Is it still running? */
|
2008-10-25 00:42:28 +02:00
|
|
|
|
2012-01-25 21:17:59 +01:00
|
|
|
if (priv->thstate != USBMSC_STATE_TERMINATED)
|
2008-10-25 00:42:28 +02:00
|
|
|
{
|
|
|
|
/* Yes.. Ask the thread to stop */
|
|
|
|
|
2016-02-14 14:32:58 +01:00
|
|
|
flags = enter_critical_section();
|
2012-01-25 21:17:59 +01:00
|
|
|
priv->theventset |= USBMSC_EVENT_TERMINATEREQUEST;
|
2014-03-25 21:19:27 +01:00
|
|
|
usbmsc_scsi_signal(priv);
|
2016-02-14 14:32:58 +01:00
|
|
|
leave_critical_section(flags);
|
2008-10-25 00:42:28 +02:00
|
|
|
}
|
2013-09-24 23:06:17 +02:00
|
|
|
|
2022-09-06 08:18:45 +02:00
|
|
|
nxmutex_unlock(&priv->thlock);
|
2008-10-25 00:42:28 +02:00
|
|
|
|
2014-03-25 21:19:27 +01:00
|
|
|
/* Wait for the thread to exit */
|
2013-11-01 19:09:25 +01:00
|
|
|
|
|
|
|
while ((priv->theventset & USBMSC_EVENT_TERMINATEREQUEST) != 0)
|
|
|
|
{
|
2020-04-01 18:13:52 +02:00
|
|
|
ret = usbmsc_sync_wait(priv);
|
|
|
|
if (ret < 0)
|
|
|
|
{
|
|
|
|
/* Just break out and continue if the thread has been
|
|
|
|
* canceled.
|
|
|
|
*/
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
2013-11-01 19:09:25 +01:00
|
|
|
}
|
2008-10-25 00:42:28 +02:00
|
|
|
}
|
2013-09-24 23:06:17 +02:00
|
|
|
|
2014-03-25 21:19:27 +01:00
|
|
|
priv->thpid = 0;
|
2008-10-25 00:42:28 +02:00
|
|
|
|
2013-09-24 23:06:17 +02:00
|
|
|
/* Unregister the driver (unless we are a part of a composite device) */
|
2008-10-25 00:42:28 +02:00
|
|
|
|
2012-01-26 00:04:17 +01:00
|
|
|
#ifndef CONFIG_USBMSC_COMPOSITE
|
2008-10-25 00:42:28 +02:00
|
|
|
usbdev_unregister(&alloc->drvr.drvr);
|
2012-01-25 20:27:20 +01:00
|
|
|
#endif
|
2008-10-25 00:42:28 +02:00
|
|
|
|
|
|
|
/* Uninitialize and release the LUNs */
|
|
|
|
|
|
|
|
for (i = 0; i < priv->nluns; ++i)
|
|
|
|
{
|
2012-01-25 21:17:59 +01:00
|
|
|
usbmsc_lununinitialize(&priv->luntab[i]);
|
2008-10-25 00:42:28 +02:00
|
|
|
}
|
2013-09-24 23:06:17 +02:00
|
|
|
|
2014-09-01 01:04:02 +02:00
|
|
|
kmm_free(priv->luntab);
|
2008-10-25 00:42:28 +02:00
|
|
|
|
|
|
|
/* Release the I/O buffer */
|
|
|
|
|
|
|
|
if (priv->iobuffer)
|
|
|
|
{
|
2014-09-01 01:04:02 +02:00
|
|
|
kmm_free(priv->iobuffer);
|
2008-10-25 00:42:28 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Uninitialize and release the driver structure */
|
|
|
|
|
2017-10-03 23:35:24 +02:00
|
|
|
nxsem_destroy(&priv->thsynch);
|
2022-09-06 08:18:45 +02:00
|
|
|
nxmutex_destroy(&priv->thlock);
|
2017-10-03 23:35:24 +02:00
|
|
|
nxsem_destroy(&priv->thwaitsem);
|
2008-10-25 00:42:28 +02:00
|
|
|
|
2013-11-05 16:12:08 +01:00
|
|
|
#ifndef CONFIG_USBMSC_COMPOSITE
|
|
|
|
/* For the case of the composite driver, there is a two pass
|
|
|
|
* uninitialization sequence. We cannot yet free the driver structure.
|
|
|
|
* We will do that on the second pass (and we will know that it is the
|
2014-03-25 21:19:27 +01:00
|
|
|
* second pass because of priv->thpid == 0)
|
2013-11-05 16:12:08 +01:00
|
|
|
*/
|
|
|
|
|
2014-09-01 01:04:02 +02:00
|
|
|
kmm_free(priv);
|
2013-11-05 16:12:08 +01:00
|
|
|
#endif
|
2008-10-25 00:42:28 +02:00
|
|
|
}
|
2017-07-16 16:43:17 +02:00
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Name: usbmsc_get_composite_devdesc
|
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* Helper function to fill in some constants into the composite
|
|
|
|
* configuration struct.
|
|
|
|
*
|
|
|
|
* Input Parameters:
|
|
|
|
* dev - Pointer to the configuration struct we should fill
|
|
|
|
*
|
|
|
|
* Returned Value:
|
|
|
|
* None
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
#if defined(CONFIG_USBDEV_COMPOSITE) && defined(CONFIG_USBMSC_COMPOSITE)
|
|
|
|
void usbmsc_get_composite_devdesc(FAR struct composite_devdesc_s *dev)
|
|
|
|
{
|
|
|
|
memset(dev, 0, sizeof(struct composite_devdesc_s));
|
|
|
|
|
|
|
|
/* The callback functions for the CDC/ACM class.
|
|
|
|
*
|
2017-07-20 18:07:53 +02:00
|
|
|
* classobject() and uninitialize() must be provided by board-specific
|
2017-07-16 16:43:17 +02:00
|
|
|
* logic
|
|
|
|
*/
|
|
|
|
|
|
|
|
dev->mkconfdesc = usbmsc_mkcfgdesc;
|
|
|
|
dev->mkstrdesc = usbmsc_mkstrdesc;
|
|
|
|
|
|
|
|
dev->nconfigs = USBMSC_NCONFIGS; /* Number of configurations supported */
|
|
|
|
dev->configid = USBMSC_CONFIGID; /* The only supported configuration ID */
|
|
|
|
dev->cfgdescsize = SIZEOF_USBMSC_CFGDESC; /* The size of the config descriptor */
|
|
|
|
|
|
|
|
/* Board-specific logic must provide the device minor */
|
|
|
|
|
|
|
|
/* Interfaces.
|
|
|
|
*
|
|
|
|
* ifnobase must be provided by board-specific logic
|
|
|
|
*/
|
|
|
|
|
2017-07-20 17:34:48 +02:00
|
|
|
dev->devinfo.ninterfaces = USBMSC_NINTERFACES; /* Number of interfaces in the configuration */
|
2017-07-16 16:43:17 +02:00
|
|
|
|
|
|
|
/* Strings.
|
|
|
|
*
|
|
|
|
* strbase must be provided by board-specific logic
|
|
|
|
*/
|
|
|
|
|
2017-07-20 17:34:48 +02:00
|
|
|
dev->devinfo.nstrings = USBMSC_NSTRIDS; /* Number of Strings */
|
2017-07-16 16:43:17 +02:00
|
|
|
|
|
|
|
/* Endpoints.
|
|
|
|
*
|
|
|
|
* Endpoint numbers must be provided by board-specific logic.
|
|
|
|
*/
|
|
|
|
|
2017-07-20 17:34:48 +02:00
|
|
|
dev->devinfo.nendpoints = USBMSC_NENDPOINTS;
|
2017-07-16 16:43:17 +02:00
|
|
|
}
|
2017-10-16 19:38:00 +02:00
|
|
|
#endif
|