2020-10-24 23:02:04 +02:00
|
|
|
/****************************************************************************
|
|
|
|
* drivers/usbdev/adb.c
|
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Included Files
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
#include <nuttx/config.h>
|
2022-09-25 17:08:38 +02:00
|
|
|
|
2021-05-18 08:59:14 +02:00
|
|
|
#include <assert.h>
|
2020-10-24 23:02:04 +02:00
|
|
|
#include <errno.h>
|
|
|
|
#include <debug.h>
|
|
|
|
|
2022-09-25 17:08:38 +02:00
|
|
|
#include <nuttx/nuttx.h>
|
2020-10-24 23:02:04 +02:00
|
|
|
#include <nuttx/kmalloc.h>
|
|
|
|
#include <nuttx/usb/usb.h>
|
|
|
|
#include <nuttx/usb/usbdev.h>
|
|
|
|
#include <nuttx/usb/usbdev_trace.h>
|
|
|
|
#include <nuttx/usb/adb.h>
|
|
|
|
#include <nuttx/fs/fs.h>
|
|
|
|
|
2023-08-25 08:49:45 +02:00
|
|
|
#ifdef CONFIG_BOARD_USBDEV_SERIALSTR
|
2022-01-18 02:36:37 +01:00
|
|
|
#include <nuttx/board.h>
|
|
|
|
#endif
|
|
|
|
|
2023-08-30 04:53:10 +02:00
|
|
|
#include "usbdev_fs.h"
|
2020-10-24 23:02:04 +02:00
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Pre-processor Definitions
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
/* FIXME use minor for char device npath */
|
|
|
|
|
2023-07-18 09:43:21 +02:00
|
|
|
#ifdef CONFIG_USBFASTBOOT
|
|
|
|
# define USBADB_CHARDEV_PATH "/dev/fastboot"
|
|
|
|
#else
|
|
|
|
# define USBADB_CHARDEV_PATH "/dev/adb0"
|
|
|
|
#endif
|
2020-10-24 23:02:04 +02:00
|
|
|
|
|
|
|
/* USB Controller */
|
|
|
|
|
|
|
|
#ifdef CONFIG_USBDEV_SELFPOWERED
|
2023-08-30 04:53:10 +02:00
|
|
|
# define USBADB_SELFPOWERED USB_CONFIG_ATTR_SELFPOWER
|
2020-10-24 23:02:04 +02:00
|
|
|
#else
|
2023-08-30 04:53:10 +02:00
|
|
|
# define USBADB_SELFPOWERED (0)
|
2020-10-24 23:02:04 +02:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef CONFIG_USBDEV_REMOTEWAKEUP
|
2023-08-30 04:53:10 +02:00
|
|
|
# define USBADB_REMOTEWAKEUP USB_CONFIG_ATTR_WAKEUP
|
2020-10-24 23:02:04 +02:00
|
|
|
#else
|
2023-08-30 04:53:10 +02:00
|
|
|
# define USBADB_REMOTEWAKEUP (0)
|
2020-10-24 23:02:04 +02:00
|
|
|
#endif
|
|
|
|
|
|
|
|
/* Buffer big enough for any of our descriptors (the config descriptor is the
|
|
|
|
* biggest).
|
|
|
|
*/
|
|
|
|
|
|
|
|
#define USBADB_MXDESCLEN (64)
|
|
|
|
#define USBADB_MAXSTRLEN (USBADB_MXDESCLEN-2)
|
|
|
|
|
|
|
|
/* Device descriptor values */
|
|
|
|
|
|
|
|
#define USBADB_VERSIONNO (0x0101) /* Device version number 1.1 (BCD) */
|
|
|
|
|
|
|
|
/* String language */
|
|
|
|
|
|
|
|
#define USBADB_STR_LANGUAGE (0x0409) /* en-us */
|
|
|
|
|
|
|
|
/* Descriptor strings. If there serial device is part of a composite device
|
|
|
|
* then the manufacturer, product, and serial number strings will be provided
|
|
|
|
* by the composite logic.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef CONFIG_USBADB_COMPOSITE
|
|
|
|
# define USBADB_MANUFACTURERSTRID (1)
|
|
|
|
# define USBADB_PRODUCTSTRID (2)
|
|
|
|
# define USBADB_SERIALSTRID (3)
|
|
|
|
# define USBADB_CONFIGSTRID (4)
|
|
|
|
# define USBADB_INTERFACESTRID (5)
|
2023-07-05 21:17:30 +02:00
|
|
|
# define USBADB_NSTRIDS (5)
|
2020-10-24 23:02:04 +02:00
|
|
|
#else
|
|
|
|
# define USBADB_INTERFACESTRID (1)
|
|
|
|
# define USBADB_NSTRIDS (1)
|
|
|
|
#endif
|
|
|
|
|
2023-07-05 21:17:30 +02:00
|
|
|
#define USBADB_NCONFIGS (1)
|
2020-10-24 23:02:04 +02:00
|
|
|
|
2023-07-18 09:43:21 +02:00
|
|
|
#ifdef CONFIG_USBFASTBOOT
|
|
|
|
# define USBADB_INTERFACEPROTOCOL (3)
|
|
|
|
#else
|
|
|
|
# define USBADB_INTERFACEPROTOCOL (1)
|
|
|
|
#endif
|
|
|
|
|
2020-10-24 23:02:04 +02:00
|
|
|
/****************************************************************************
|
|
|
|
* Private Data
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
/* USB descriptor ***********************************************************/
|
|
|
|
|
|
|
|
#ifndef CONFIG_USBADB_COMPOSITE
|
|
|
|
static const struct usb_devdesc_s g_adb_devdesc =
|
|
|
|
{
|
2024-07-02 08:36:49 +02:00
|
|
|
.len = USB_SIZEOF_DEVDESC, /* Descriptor length */
|
|
|
|
.type = USB_DESC_TYPE_DEVICE, /* Descriptor type */
|
|
|
|
.usb = /* USB version */
|
2020-10-24 23:02:04 +02:00
|
|
|
{
|
|
|
|
LSBYTE(0x0200),
|
|
|
|
MSBYTE(0x0200)
|
|
|
|
},
|
|
|
|
.classid = 0, /* Device class */
|
|
|
|
.subclass = 0, /* Device sub-class */
|
|
|
|
.protocol = 0, /* Device protocol */
|
|
|
|
.mxpacketsize = CONFIG_USBADB_EP0MAXPACKET, /* Max packet size (ep0) */
|
|
|
|
.vendor = /* Vendor ID */
|
|
|
|
{
|
|
|
|
LSBYTE(CONFIG_USBADB_VENDORID),
|
|
|
|
MSBYTE(CONFIG_USBADB_VENDORID)
|
|
|
|
},
|
2024-07-02 08:36:49 +02:00
|
|
|
.product = /* Product ID */
|
2023-07-05 21:17:30 +02:00
|
|
|
{
|
|
|
|
LSBYTE(CONFIG_USBADB_PRODUCTID),
|
2020-10-24 23:02:04 +02:00
|
|
|
MSBYTE(CONFIG_USBADB_PRODUCTID)
|
|
|
|
},
|
2024-07-02 08:36:49 +02:00
|
|
|
.device = /* Device ID */
|
2023-07-05 21:17:30 +02:00
|
|
|
{
|
|
|
|
LSBYTE(USBADB_VERSIONNO),
|
2020-10-24 23:02:04 +02:00
|
|
|
MSBYTE(USBADB_VERSIONNO)
|
|
|
|
},
|
2024-07-02 08:36:49 +02:00
|
|
|
.imfgr = USBADB_MANUFACTURERSTRID, /* Manufacturer */
|
|
|
|
.iproduct = USBADB_PRODUCTSTRID, /* Product */
|
|
|
|
.serno = USBADB_SERIALSTRID, /* Serial number */
|
|
|
|
.nconfigs = USBADB_NCONFIGS, /* Number of configurations */
|
2023-07-05 21:17:30 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
# ifdef CONFIG_USBDEV_DUALSPEED
|
|
|
|
static const struct usb_qualdesc_s g_adb_qualdesc =
|
|
|
|
{
|
2024-07-02 08:36:49 +02:00
|
|
|
USB_SIZEOF_QUALDESC, /* len */
|
|
|
|
USB_DESC_TYPE_DEVICEQUALIFIER, /* type */
|
|
|
|
{ /* usb */
|
2023-07-05 21:17:30 +02:00
|
|
|
LSBYTE(0x0200),
|
|
|
|
MSBYTE(0x0200)
|
|
|
|
},
|
2024-07-02 08:36:49 +02:00
|
|
|
0, /* classid */
|
|
|
|
0, /* subclass */
|
|
|
|
0, /* protocol */
|
|
|
|
CONFIG_USBADB_EP0MAXPACKET, /* mxpacketsize */
|
|
|
|
USBADB_NCONFIGS, /* nconfigs */
|
|
|
|
0, /* reserved */
|
2020-10-24 23:02:04 +02:00
|
|
|
};
|
2023-07-05 21:17:30 +02:00
|
|
|
# endif
|
2020-10-24 23:02:04 +02:00
|
|
|
|
2023-08-24 13:30:54 +02:00
|
|
|
static const struct usbdev_strdesc_s g_adb_strdesc[] =
|
2020-10-24 23:02:04 +02:00
|
|
|
{
|
2023-08-24 13:30:54 +02:00
|
|
|
{USBADB_MANUFACTURERSTRID, CONFIG_USBADB_VENDORSTR},
|
|
|
|
{USBADB_PRODUCTSTRID, CONFIG_USBADB_PRODUCTSTR},
|
|
|
|
# ifdef CONFIG_USBADB_SERIALSTR
|
|
|
|
{USBADB_SERIALSTRID, CONFIG_USBADB_SERIALSTR},
|
|
|
|
# else
|
|
|
|
{USBADB_SERIALSTRID, ""},
|
|
|
|
# endif
|
|
|
|
{USBADB_CONFIGSTRID, CONFIG_USBADB_CONFIGSTR},
|
|
|
|
{}
|
|
|
|
};
|
|
|
|
|
|
|
|
static const struct usbdev_strdescs_s g_adb_strdescs =
|
|
|
|
{
|
|
|
|
.language = USBADB_STR_LANGUAGE,
|
|
|
|
.strdesc = g_adb_strdesc,
|
|
|
|
};
|
|
|
|
|
|
|
|
static const struct usb_cfgdesc_s g_adb_cfgdesc =
|
|
|
|
{
|
|
|
|
.len = USB_SIZEOF_CFGDESC, /* Descriptor length */
|
|
|
|
.type = USB_DESC_TYPE_CONFIG, /* Descriptor type */
|
|
|
|
.cfgvalue = 1, /* Configuration value */
|
|
|
|
.icfg = USBADB_CONFIGSTRID, /* Configuration */
|
|
|
|
.attr = USB_CONFIG_ATTR_ONE |
|
|
|
|
USBADB_SELFPOWERED |
|
|
|
|
USBADB_REMOTEWAKEUP, /* Attributes */
|
|
|
|
|
|
|
|
.mxpower = (CONFIG_USBDEV_MAXPOWER + 1) / 2 /* Max power (mA/2) */
|
|
|
|
};
|
|
|
|
|
|
|
|
static const struct usbdev_devdescs_s g_adb_devdescs =
|
|
|
|
{
|
|
|
|
.cfgdesc = &g_adb_cfgdesc,
|
|
|
|
.strdescs = &g_adb_strdescs,
|
|
|
|
.devdesc = &g_adb_devdesc,
|
|
|
|
#ifdef CONFIG_USBDEV_DUALSPEED
|
|
|
|
.qualdesc = &g_adb_qualdesc,
|
2020-10-24 23:02:04 +02:00
|
|
|
#endif
|
2023-08-24 13:30:54 +02:00
|
|
|
};
|
|
|
|
#endif
|
|
|
|
|
|
|
|
static const struct usb_ifdesc_s g_adb_ifdesc =
|
|
|
|
{
|
|
|
|
.len = USB_SIZEOF_IFDESC,
|
|
|
|
.type = USB_DESC_TYPE_INTERFACE,
|
|
|
|
.ifno = 0,
|
|
|
|
.alt = 0,
|
|
|
|
.neps = 2,
|
|
|
|
.classid = USB_CLASS_VENDOR_SPEC,
|
|
|
|
.subclass = 0x42,
|
2023-07-18 09:43:21 +02:00
|
|
|
.protocol = USBADB_INTERFACEPROTOCOL,
|
2023-08-24 13:30:54 +02:00
|
|
|
.iif = USBADB_INTERFACESTRID
|
2020-10-24 23:02:04 +02:00
|
|
|
};
|
|
|
|
|
2023-08-30 04:53:10 +02:00
|
|
|
static const struct usbdev_epinfo_s g_adb_epbulkin =
|
2020-10-24 23:02:04 +02:00
|
|
|
{
|
2023-08-30 04:53:10 +02:00
|
|
|
.desc =
|
2020-10-24 23:02:04 +02:00
|
|
|
{
|
2024-07-03 09:21:39 +02:00
|
|
|
.len = USB_SIZEOF_EPDESC,
|
|
|
|
.type = USB_DESC_TYPE_ENDPOINT,
|
|
|
|
.addr = USB_DIR_IN,
|
|
|
|
.attr = USB_EP_ATTR_XFER_BULK |
|
|
|
|
USB_EP_ATTR_NO_SYNC |
|
|
|
|
USB_EP_ATTR_USAGE_DATA,
|
|
|
|
.interval = 0,
|
2023-08-30 04:53:10 +02:00
|
|
|
},
|
2024-07-03 09:21:39 +02:00
|
|
|
.reqnum = CONFIG_USBADB_NWRREQS,
|
|
|
|
.fssize = CONFIG_USBADB_EPBULKIN_FSSIZE,
|
2020-10-24 23:02:04 +02:00
|
|
|
#ifdef CONFIG_USBDEV_DUALSPEED
|
2024-07-03 09:21:39 +02:00
|
|
|
.hssize = CONFIG_USBADB_EPBULKIN_HSSIZE,
|
2024-07-02 08:36:49 +02:00
|
|
|
#endif
|
|
|
|
#ifdef CONFIG_USBDEV_SUPERSPEED
|
2024-07-03 09:21:39 +02:00
|
|
|
.sssize = CONFIG_USBADB_EPBULKIN_SSSIZE,
|
|
|
|
.compdesc =
|
|
|
|
{
|
|
|
|
.len = USB_SIZEOF_SS_EPCOMPDESC,
|
|
|
|
.type = USB_DESC_TYPE_ENDPOINT_COMPANION,
|
|
|
|
.mxburst = CONFIG_USBADB_EPBULKIN_MAXBURST,
|
|
|
|
.attr = CONFIG_USBADB_EPBULKIN_MAXSTREAM,
|
|
|
|
.wbytes[0] = 0,
|
|
|
|
.wbytes[1] = 0,
|
|
|
|
},
|
2020-10-24 23:02:04 +02:00
|
|
|
#endif
|
2023-08-30 04:53:10 +02:00
|
|
|
};
|
2020-10-24 23:02:04 +02:00
|
|
|
|
2023-08-30 04:53:10 +02:00
|
|
|
static const struct usbdev_epinfo_s g_adb_epbulkout =
|
2020-10-24 23:02:04 +02:00
|
|
|
{
|
2023-08-30 04:53:10 +02:00
|
|
|
.desc =
|
2020-10-24 23:02:04 +02:00
|
|
|
{
|
2024-07-03 09:21:39 +02:00
|
|
|
.len = USB_SIZEOF_EPDESC,
|
|
|
|
.type = USB_DESC_TYPE_ENDPOINT,
|
|
|
|
.addr = USB_DIR_OUT,
|
|
|
|
.attr = USB_EP_ATTR_XFER_BULK |
|
|
|
|
USB_EP_ATTR_NO_SYNC |
|
|
|
|
USB_EP_ATTR_USAGE_DATA,
|
|
|
|
.interval = 0,
|
2023-08-30 04:53:10 +02:00
|
|
|
},
|
2024-07-03 09:21:39 +02:00
|
|
|
.reqnum = CONFIG_USBADB_NRDREQS,
|
|
|
|
.fssize = CONFIG_USBADB_EPBULKOUT_FSSIZE,
|
2023-08-30 04:53:10 +02:00
|
|
|
#ifdef CONFIG_USBDEV_DUALSPEED
|
2024-07-03 09:21:39 +02:00
|
|
|
.hssize = CONFIG_USBADB_EPBULKOUT_HSSIZE,
|
2024-07-02 08:36:49 +02:00
|
|
|
#endif
|
|
|
|
#ifdef CONFIG_USBDEV_SUPERSPEED
|
2024-07-03 09:21:39 +02:00
|
|
|
.sssize = CONFIG_USBADB_EPBULKOUT_SSSIZE,
|
|
|
|
.compdesc =
|
|
|
|
{
|
|
|
|
.len = USB_SIZEOF_SS_EPCOMPDESC,
|
|
|
|
.type = USB_DESC_TYPE_ENDPOINT_COMPANION,
|
|
|
|
.mxburst = CONFIG_USBADB_EPBULKOUT_MAXBURST,
|
|
|
|
.attr = CONFIG_USBADB_EPBULKOUT_MAXSTREAM,
|
|
|
|
.wbytes[0] = 0,
|
|
|
|
.wbytes[1] = 0,
|
|
|
|
},
|
2020-10-24 23:02:04 +02:00
|
|
|
#endif
|
2023-08-30 04:53:10 +02:00
|
|
|
};
|
2020-10-24 23:02:04 +02:00
|
|
|
|
2023-08-30 04:53:10 +02:00
|
|
|
static const FAR struct usbdev_epinfo_s *g_adb_epinfos[USBADB_NUM_EPS] =
|
2020-10-24 23:02:04 +02:00
|
|
|
{
|
2023-08-30 04:53:10 +02:00
|
|
|
&g_adb_epbulkin,
|
|
|
|
&g_adb_epbulkout,
|
|
|
|
};
|
2020-10-24 23:02:04 +02:00
|
|
|
|
|
|
|
/****************************************************************************
|
2023-08-30 04:53:10 +02:00
|
|
|
* Private Functions
|
2020-10-24 23:02:04 +02:00
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
/****************************************************************************
|
2023-07-05 21:17:30 +02:00
|
|
|
* Name: usbclass_mkcfgdesc
|
2020-10-24 23:02:04 +02:00
|
|
|
*
|
|
|
|
* Description:
|
2023-07-05 21:17:30 +02:00
|
|
|
* Construct the configuration descriptor
|
2020-10-24 23:02:04 +02:00
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
static int16_t usbclass_mkcfgdesc(FAR uint8_t *buf,
|
|
|
|
FAR struct usbdev_devinfo_s *devinfo,
|
2022-09-19 10:28:50 +02:00
|
|
|
uint8_t speed, uint8_t type)
|
2020-10-24 23:02:04 +02:00
|
|
|
{
|
2024-07-03 09:21:39 +02:00
|
|
|
FAR uint8_t *epdesc;
|
2023-08-24 13:30:54 +02:00
|
|
|
FAR struct usb_ifdesc_s *dest;
|
2024-07-03 09:21:39 +02:00
|
|
|
uint32_t totallen = 0;
|
|
|
|
int ret;
|
2020-10-24 23:02:04 +02:00
|
|
|
|
|
|
|
/* Check for switches between high and full speed */
|
|
|
|
|
2024-07-02 08:36:49 +02:00
|
|
|
if (type == USB_DESC_TYPE_OTHERSPEEDCONFIG && speed < USB_SPEED_SUPER)
|
2020-10-24 23:02:04 +02:00
|
|
|
{
|
2024-07-02 08:36:49 +02:00
|
|
|
speed = speed == USB_SPEED_HIGH ? USB_SPEED_FULL : USB_SPEED_HIGH;
|
2020-10-24 23:02:04 +02:00
|
|
|
}
|
|
|
|
|
2023-08-24 13:30:54 +02:00
|
|
|
dest = (FAR struct usb_ifdesc_s *)buf;
|
2024-07-03 09:21:39 +02:00
|
|
|
epdesc = (FAR uint8_t *)(buf + sizeof(g_adb_ifdesc));
|
2020-10-24 23:02:04 +02:00
|
|
|
|
2023-08-24 13:30:54 +02:00
|
|
|
memcpy(dest, &g_adb_ifdesc, sizeof(g_adb_ifdesc));
|
2024-07-03 09:21:39 +02:00
|
|
|
totallen += sizeof(g_adb_ifdesc);
|
|
|
|
|
|
|
|
ret = usbdev_copy_epdesc((FAR struct usb_epdesc_s *)epdesc,
|
|
|
|
devinfo->epno[USBADB_EP_BULKIN_IDX],
|
|
|
|
speed,
|
|
|
|
&g_adb_epbulkin);
|
|
|
|
totallen += ret;
|
|
|
|
epdesc += ret;
|
|
|
|
|
|
|
|
ret = usbdev_copy_epdesc((FAR struct usb_epdesc_s *)epdesc,
|
|
|
|
devinfo->epno[USBADB_EP_BULKOUT_IDX],
|
|
|
|
speed,
|
|
|
|
&g_adb_epbulkout);
|
|
|
|
totallen += ret;
|
|
|
|
epdesc += ret;
|
2020-10-24 23:02:04 +02:00
|
|
|
|
|
|
|
#ifdef CONFIG_USBADB_COMPOSITE
|
|
|
|
/* For composite device, apply possible offset to the interface numbers */
|
|
|
|
|
2023-08-24 13:30:54 +02:00
|
|
|
dest->ifno = devinfo->ifnobase;
|
|
|
|
dest->iif = devinfo->strbase + USBADB_INTERFACESTRID;
|
2020-10-24 23:02:04 +02:00
|
|
|
#endif
|
|
|
|
|
2024-07-03 09:21:39 +02:00
|
|
|
return totallen;
|
2020-10-24 23:02:04 +02:00
|
|
|
}
|
|
|
|
|
2023-07-05 21:17:30 +02:00
|
|
|
/****************************************************************************
|
|
|
|
* Name: usbclass_mkstrdesc
|
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* Construct the string descriptor
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
2020-10-24 23:02:04 +02:00
|
|
|
static int usbclass_mkstrdesc(uint8_t id, FAR struct usb_strdesc_s *strdesc)
|
|
|
|
{
|
2022-03-05 18:59:15 +01:00
|
|
|
FAR uint8_t *data = (FAR uint8_t *)(strdesc + 1);
|
2020-10-24 23:02:04 +02:00
|
|
|
FAR const char *str;
|
|
|
|
int len;
|
|
|
|
int ndata;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
switch (id)
|
|
|
|
{
|
2023-08-24 13:30:54 +02:00
|
|
|
/* Composite driver removes offset before calling mkstrdesc() */
|
2020-10-24 23:02:04 +02:00
|
|
|
|
2023-08-24 13:30:54 +02:00
|
|
|
case USBADB_INTERFACESTRID:
|
|
|
|
str = CONFIG_USBADB_INTERFACESTR;
|
|
|
|
break;
|
2020-10-24 23:02:04 +02:00
|
|
|
|
2023-08-24 13:30:54 +02:00
|
|
|
default:
|
|
|
|
return -EINVAL;
|
2020-10-24 23:02:04 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/* The string is utf16-le. The poor man's utf-8 to utf16-le
|
|
|
|
* conversion below will only handle 7-bit en-us ascii
|
|
|
|
*/
|
|
|
|
|
|
|
|
len = strlen(str);
|
|
|
|
if (len > (USBADB_MAXSTRLEN / 2))
|
|
|
|
{
|
|
|
|
len = (USBADB_MAXSTRLEN / 2);
|
|
|
|
}
|
|
|
|
|
|
|
|
for (i = 0, ndata = 0; i < len; i++, ndata += 2)
|
|
|
|
{
|
2022-03-05 18:59:15 +01:00
|
|
|
data[ndata] = str[i];
|
|
|
|
data[ndata + 1] = 0;
|
2020-10-24 23:02:04 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
strdesc->len = ndata + 2;
|
|
|
|
strdesc->type = USB_DESC_TYPE_STRING;
|
|
|
|
return strdesc->len;
|
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************************************************
|
2023-08-30 04:53:10 +02:00
|
|
|
* Public Functions
|
2020-10-24 23:02:04 +02:00
|
|
|
****************************************************************************/
|
|
|
|
|
2023-08-30 04:53:10 +02:00
|
|
|
#ifndef CONFIG_USBADB_COMPOSITE
|
2020-10-24 23:02:04 +02:00
|
|
|
/****************************************************************************
|
2023-08-30 04:53:10 +02:00
|
|
|
* Name: usbdev_adb_initialize
|
2020-10-24 23:02:04 +02:00
|
|
|
*
|
|
|
|
* Description:
|
2023-08-30 04:53:10 +02:00
|
|
|
* Initialize the Android Debug Bridge USB device driver.
|
|
|
|
*
|
|
|
|
* Returned Value:
|
|
|
|
* A non-NULL "handle" is returned on success.
|
2020-10-24 23:02:04 +02:00
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
2023-08-30 04:53:10 +02:00
|
|
|
FAR void *usbdev_adb_initialize(void)
|
2020-10-24 23:02:04 +02:00
|
|
|
{
|
2023-08-30 04:53:10 +02:00
|
|
|
struct composite_devdesc_s devdesc;
|
2020-10-24 23:02:04 +02:00
|
|
|
|
2023-08-30 04:53:10 +02:00
|
|
|
usbdev_adb_get_composite_devdesc(&devdesc);
|
2020-10-24 23:02:04 +02:00
|
|
|
|
2023-08-30 04:53:10 +02:00
|
|
|
devdesc.devinfo.epno[USBADB_EP_BULKIN_IDX] =
|
|
|
|
USB_EPNO(CONFIG_USBADB_EPBULKIN);
|
|
|
|
devdesc.devinfo.epno[USBADB_EP_BULKOUT_IDX] =
|
|
|
|
USB_EPNO(CONFIG_USBADB_EPBULKOUT);
|
2020-10-24 23:02:04 +02:00
|
|
|
|
2023-08-30 04:53:10 +02:00
|
|
|
return usbdev_fs_initialize(&g_adb_devdescs, &devdesc);
|
2020-10-24 23:02:04 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************************************************
|
2023-08-30 04:53:10 +02:00
|
|
|
* Name: usbdev_adb_uninitialize
|
2020-10-24 23:02:04 +02:00
|
|
|
*
|
|
|
|
* Description:
|
2023-08-30 04:53:10 +02:00
|
|
|
* Uninitialize the Android Debug Bridge USB device driver.
|
2020-10-24 23:02:04 +02:00
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
2023-08-30 04:53:10 +02:00
|
|
|
void usbdev_adb_uninitialize(FAR void *handle)
|
2020-10-24 23:02:04 +02:00
|
|
|
{
|
2023-08-30 04:53:10 +02:00
|
|
|
usbdev_fs_uninitialize(handle);
|
2023-07-05 21:17:30 +02:00
|
|
|
}
|
2020-10-24 23:02:04 +02:00
|
|
|
#endif
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Name: usbdev_adb_get_composite_devdesc
|
|
|
|
*
|
|
|
|
* Returned Value:
|
|
|
|
* None
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
2023-08-30 04:53:10 +02:00
|
|
|
void usbdev_adb_get_composite_devdesc(FAR struct composite_devdesc_s *dev)
|
2020-10-24 23:02:04 +02:00
|
|
|
{
|
|
|
|
memset(dev, 0, sizeof(struct composite_devdesc_s));
|
|
|
|
|
2023-08-30 04:53:10 +02:00
|
|
|
dev->classobject = usbdev_fs_classobject;
|
|
|
|
dev->uninitialize = usbdev_fs_classuninitialize;
|
|
|
|
dev->mkconfdesc = usbclass_mkcfgdesc,
|
|
|
|
dev->mkstrdesc = usbclass_mkstrdesc,
|
2020-10-24 23:02:04 +02:00
|
|
|
dev->nconfigs = USBADB_NCONFIGS;
|
|
|
|
dev->configid = 1;
|
2024-07-03 09:21:39 +02:00
|
|
|
#ifdef CONFIG_USBDEV_SUPERSPEED
|
|
|
|
dev->cfgdescsize = sizeof(g_adb_ifdesc) +
|
|
|
|
USB_SIZEOF_EPDESC * 2 +
|
|
|
|
USB_SIZEOF_SS_EPCOMPDESC * 2;
|
|
|
|
#else
|
2023-08-24 13:30:54 +02:00
|
|
|
dev->cfgdescsize = sizeof(g_adb_ifdesc) + 2 * USB_SIZEOF_EPDESC;
|
2024-07-03 09:21:39 +02:00
|
|
|
#endif
|
2020-10-24 23:02:04 +02:00
|
|
|
dev->devinfo.ninterfaces = 1;
|
|
|
|
dev->devinfo.nstrings = USBADB_NSTRIDS;
|
|
|
|
dev->devinfo.nendpoints = USBADB_NUM_EPS;
|
2023-08-30 04:53:10 +02:00
|
|
|
dev->devinfo.epinfos = g_adb_epinfos;
|
|
|
|
dev->devinfo.name = USBADB_CHARDEV_PATH;
|
2023-07-05 21:17:30 +02:00
|
|
|
}
|