Updates from coding standard review of PRs 753 and 754

This commit is contained in:
Gregory Nutt 2018-11-09 07:44:22 -06:00
parent 2fad9b86d1
commit 071d69e082
6 changed files with 291 additions and 226 deletions

View file

@ -1,7 +1,7 @@
/****************************************************************************
* drivers/usbdev/composite.c
*
* Copyright (C) 2012, 2016-2017 Gregory Nutt. All rights reserved.
* Copyright (C) 2012, 2016-2018 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <gnutt@nuttx.org>
*
* Redistribution and use in source and binary forms, with or without
@ -79,7 +79,8 @@ struct composite_alloc_s
/****************************************************************************
* Private Function Prototypes
****************************************************************************/
/* USB helps ****************************************************************/
/* USB helpers **************************************************************/
static void composite_ep0incomplete(FAR struct usbdev_ep_s *ep,
FAR struct usbdev_req_s *req);
@ -200,79 +201,94 @@ static int composite_classsetup(FAR struct composite_dev_s *priv,
* in each device's composite_devdesc_s.
*
****************************************************************************/
#ifdef CONFIG_COMPOSITE_MSFT_OS_DESCRIPTORS
static int composite_msftdescriptor(FAR struct composite_dev_s *priv,
FAR struct usbdev_s *dev,
FAR const struct usb_ctrlreq_s *ctrl, FAR struct usbdev_req_s *ctrl_rsp, FAR bool *dispatched)
static int composite_msftdescriptor(FAR struct composite_dev_s *priv,
FAR struct usbdev_s *dev,
FAR const struct usb_ctrlreq_s *ctrl,
FAR struct usbdev_req_s *ctrl_rsp,
FAR bool *dispatched)
{
if (ctrl->index[0] == MSFTOSDESC_INDEX_FUNCTION)
{
/* Function descriptor is common to whole device */
int i;
FAR struct usb_msft_os_feature_desc_s *response = (FAR struct usb_msft_os_feature_desc_s*)ctrl_rsp->buf;
memset(response, 0, sizeof(*response));
for (i = 0; i < priv->ndevices; i++)
{
if (priv->device[i].compdesc.msft_compatible_id[0] != 0)
{
FAR struct usb_msft_os_function_desc_s *func = &response->function[response->count];
memset(func, 0, sizeof(*func));
func->firstif = priv->device[i].compdesc.devinfo.ifnobase;
func->nifs = priv->device[i].compdesc.devinfo.ninterfaces;
memcpy(func->compatible_id, priv->device[i].compdesc.msft_compatible_id, sizeof(func->compatible_id));
memcpy(func->sub_id, priv->device[i].compdesc.msft_sub_id, sizeof(func->sub_id));
response->count++;
}
}
if (response->count > 0)
{
size_t total_len = sizeof(struct usb_msft_os_feature_desc_s) + (response->count - 1) * sizeof(struct usb_msft_os_function_desc_s);
response->len[0] = (total_len >> 0) & 0xFF;
response->len[1] = (total_len >> 8) & 0xFF;
response->len[2] = (total_len >> 16) & 0xFF;
response->len[3] = (total_len >> 24) & 0xFF;
response->version[1] = 0x01;
response->index[0] = MSFTOSDESC_INDEX_FUNCTION;
return total_len;
}
else
{
return 0;
}
}
else if (ctrl->index[0] == MSFTOSDESC_INDEX_EXTPROP || ctrl->index[0] == ctrl->value[0])
{
/* Extended properties are per-interface, pass the request to subdevice.
* NOTE: The documentation in OS_Desc_Ext_Prop.docx seems a bit incorrect here,
* the interface is in ctrl->value low byte.
* Also WinUSB driver has limitation that index[0] will not be correct if
* trying to read descriptors using e.g. libusb xusb.exe.
*/
int i;
int ret = -ENOTSUP;
uint8_t interface = ctrl->value[0];
for (i = 0; i < priv->ndevices; i++)
{
if (interface >= priv->device[i].compdesc.devinfo.ifnobase &&
interface < (priv->device[i].compdesc.devinfo.ifnobase +
priv->device[i].compdesc.devinfo.ninterfaces))
/* Function descriptor is common to whole device */
FAR struct usb_msft_os_feature_desc_s *response =
(FAR struct usb_msft_os_feature_desc_s *)ctrl_rsp->buf;
int i;
memset(response, 0, sizeof(*response));
for (i = 0; i < priv->ndevices; i++)
{
ret = CLASS_SETUP(priv->device[i].dev, dev, ctrl, NULL, 0);
*dispatched = true;
break;
if (priv->device[i].compdesc.msft_compatible_id[0] != 0)
{
FAR struct usb_msft_os_function_desc_s *func =
&response->function[response->count];
memset(func, 0, sizeof(*func));
func->firstif = priv->device[i].compdesc.devinfo.ifnobase;
func->nifs = priv->device[i].compdesc.devinfo.ninterfaces;
memcpy(func->compatible_id, priv->device[i].compdesc.msft_compatible_id,
sizeof(func->compatible_id));
memcpy(func->sub_id, priv->device[i].compdesc.msft_sub_id,
sizeof(func->sub_id));
response->count++;
}
}
if (response->count > 0)
{
size_t total_len = sizeof(struct usb_msft_os_feature_desc_s) +
(response->count - 1) *
sizeof(struct usb_msft_os_function_desc_s);
response->len[0] = (total_len >> 0) & 0xFF;
response->len[1] = (total_len >> 8) & 0xFF;
response->len[2] = (total_len >> 16) & 0xFF;
response->len[3] = (total_len >> 24) & 0xFF;
response->version[1] = 0x01;
response->index[0] = MSFTOSDESC_INDEX_FUNCTION;
return total_len;
}
else
{
return 0;
}
}
return ret;
}
else if (ctrl->index[0] == MSFTOSDESC_INDEX_EXTPROP ||
ctrl->index[0] == ctrl->value[0])
{
/* Extended properties are per-interface, pass the request to
* subdevice. NOTE: The documentation in OS_Desc_Ext_Prop.docx seems
* a bit incorrect here, the interface is in ctrl->value low byte.
* Also WinUSB driver has limitation that index[0] will not be correct if
* trying to read descriptors using e.g. libusb xusb.exe.
*/
uint8_t interface = ctrl->value[0];
int ret = -ENOTSUP;
int i;
for (i = 0; i < priv->ndevices; i++)
{
if (interface >= priv->device[i].compdesc.devinfo.ifnobase &&
interface < (priv->device[i].compdesc.devinfo.ifnobase +
priv->device[i].compdesc.devinfo.ninterfaces))
{
ret = CLASS_SETUP(priv->device[i].dev, dev, ctrl, NULL, 0);
*dispatched = true;
break;
}
}
return ret;
}
else
{
return -ENOTSUP;
}
{
return -ENOTSUP;
}
}
#endif
@ -577,11 +593,16 @@ static int composite_setup(FAR struct usbdevclass_driver_s *driver,
#ifdef CONFIG_COMPOSITE_MSFT_OS_DESCRIPTORS
else if (strid == USB_REQ_GETMSFTOSDESCRIPTOR)
{
/* Note: Windows has a habit of caching this response, so if you want to enable/disable
* it you'll usually need to change the device serial number afterwards. */
static const uint8_t msft_response[16] = {
'M',0,'S',0,'F',0,'T',0,'1',0,'0',0,'0',0,0xEE,0
/* Note: Windows has a habit of caching this response,
* so if you want to enable/disable it you'll usually
* need to change the device serial number afterwards.
*/
static const uint8_t msft_response[16] =
{
'M', 0, 'S', 0, 'F', 0, 'T', 0, '1', 0, '0', 0, '0', 0, 0xEE, 0
};
buf->len = 18;
buf->type = USB_DESC_TYPE_STRING;
memcpy(buf->data, msft_response, 16);
@ -598,7 +619,8 @@ static int composite_setup(FAR struct usbdevclass_driver_s *driver,
strid < priv->device[i].compdesc.devinfo.strbase +
priv->device[i].compdesc.devinfo.nstrings)
{
ret = priv->device[i].compdesc.mkstrdesc(strid - priv->device[i].compdesc.devinfo.strbase, buf);
ret = priv->device[i].compdesc.mkstrdesc(strid -
priv->device[i].compdesc.devinfo.strbase, buf);
break;
}
}

View file

@ -37,10 +37,10 @@
* Currently it supports the app-side ("Run-Time") part of the protocol:
* a sequence of DFU_DETACH and USB reset commands, which will reboot into
* a separate USB DFU bootloader.
*
*
* The bootloader is provided by board-specific logic, or STM32's
* built-in ROM bootloader can be used.
*
*
* https://www.usb.org/sites/default/files/DFU_1.1.pdf
*/
@ -71,9 +71,9 @@
#define USB_REQ_DFU_GETSTATUS 3
#ifdef CONFIG_DFU_MSFT_OS_DESCRIPTORS
#define DFU_MAX_DESCRIPTOR_LEN 256
# define DFU_MAX_DESCRIPTOR_LEN 256
#else
#define DFU_MAX_DESCRIPTOR_LEN sizeof(struct dfu_cfgdesc_s)
# define DFU_MAX_DESCRIPTOR_LEN sizeof(struct dfu_cfgdesc_s)
#endif
/****************************************************************************
@ -81,6 +81,7 @@
****************************************************************************/
/* Response to DFU_GETSTATUS */
struct dfu_getstatus_response_s
{
uint8_t status; /* Status of latest command */
@ -90,6 +91,7 @@ struct dfu_getstatus_response_s
};
/* DFU functional descriptor */
struct dfu_funcdesc_s
{
uint8_t len; /* Descriptor length */
@ -101,6 +103,7 @@ struct dfu_funcdesc_s
};
/* USB configuration descriptor */
struct dfu_cfgdesc_s
{
struct usb_ifdesc_s ifdesc; /* DFU interface descriptor */
@ -111,8 +114,8 @@ struct dfu_driver_s
{
struct usbdevclass_driver_s drvr;
struct usbdev_devinfo_s devinfo;
FAR struct usbdev_req_s *ctrlreq; /* Pointer to preallocated control request */
struct work_s work_item; /* Work queue entry for activating bootloader */
FAR struct usbdev_req_s *ctrlreq; /* Pointer to preallocated control request */
struct work_s work_item; /* Work queue entry for activating bootloader */
};
/****************************************************************************
@ -151,23 +154,23 @@ const static struct usbdevclass_driverops_s g_dfu_driverops =
static const struct dfu_cfgdesc_s g_dfu_cfgdesc =
{
{
.len = USB_SIZEOF_IFDESC,
.type = USB_DESC_TYPE_INTERFACE,
.ifno = 0,
.alt = 0,
.neps = 0,
.classid = 0xFE,
.subclass = 0x01,
.protocol = 0x01, /* DFU runtime protocol */
.iif = 0
.len = USB_SIZEOF_IFDESC,
.type = USB_DESC_TYPE_INTERFACE,
.ifno = 0,
.alt = 0,
.neps = 0,
.classid = 0xFE,
.subclass = 0x01,
.protocol = 0x01, /* DFU runtime protocol */
.iif = 0
},
{
.len = sizeof(struct dfu_funcdesc_s),
.type = 0x21,
.attributes = 0x0B,
.len = sizeof(struct dfu_funcdesc_s),
.type = 0x21,
.attributes = 0x0B,
.detach_timeout = { LSBYTE(DFU_MAX_TIMEOUT), MSBYTE(DFU_MAX_TIMEOUT) },
.transfer_size = { LSBYTE(DFU_MAX_TRANSFER), MSBYTE(DFU_MAX_TRANSFER) },
.dfu_version = { LSBYTE(DFU_VERSION), MSBYTE(DFU_VERSION) }
.transfer_size = { LSBYTE(DFU_MAX_TRANSFER), MSBYTE(DFU_MAX_TRANSFER) },
.dfu_version = { LSBYTE(DFU_VERSION), MSBYTE(DFU_VERSION) }
}
};
@ -234,24 +237,26 @@ static void usbclass_ep0incomplete(FAR struct usbdev_ep_s *ep,
static int16_t usbclass_mkcfgdesc(FAR uint8_t *buf,
FAR struct usbdev_devinfo_s *devinfo)
{
FAR struct dfu_cfgdesc_s *dest = (FAR struct dfu_cfgdesc_s*)buf;
FAR struct dfu_cfgdesc_s *dest = (FAR struct dfu_cfgdesc_s *)buf;
*dest = g_dfu_cfgdesc;
dest->ifdesc.ifno += devinfo->ifnobase;
dest->ifdesc.iif = devinfo->strbase;
return sizeof(g_dfu_cfgdesc);
}
static int convert_to_utf16(FAR uint8_t *dest, FAR const char *src)
{
int bytes = 0;
while (*src)
{
*dest++ = *src++;
*dest++ = 0x00;
bytes += 2;
}
{
*dest++ = *src++;
*dest++ = 0x00;
bytes += 2;
}
return bytes;
}
@ -279,48 +284,51 @@ static int dfu_make_msft_extprop_desc(FAR uint8_t *buf)
{
FAR const char *propname = "DeviceInterfaceGUIDs";
FAR const char *propval = CONFIG_DFU_INTERFACE_GUID;
FAR struct usb_msft_os_extprop_hdr_s *hdr = (FAR struct usb_msft_os_extprop_hdr_s*)buf;
FAR struct usb_msft_os_extprop_hdr_s *hdr =
(FAR struct usb_msft_os_extprop_hdr_s *)buf;
FAR uint8_t *payload = buf + sizeof(struct usb_msft_os_extprop_hdr_s);
int namelen, valuelen, proplen, totallen;
namelen = strlen(propname) * 2 + 2;
int namelen;
int valuelen;
int proplen;
int totallen;
namelen = strlen(propname) * 2 + 2;
valuelen = strlen(propval) * 2 + 4;
proplen = 14 + namelen + valuelen;
proplen = 14 + namelen + valuelen;
totallen = sizeof(struct usb_msft_os_extprop_hdr_s) + proplen;
memset(buf, 0, totallen);
hdr->len[0] = LSBYTE(totallen);
hdr->len[1] = MSBYTE(totallen);
hdr->len[0] = LSBYTE(totallen);
hdr->len[1] = MSBYTE(totallen);
hdr->version[1] = 0x01;
hdr->index[0] = MSFTOSDESC_INDEX_EXTPROP;
hdr->count[0] = 1;
*payload++ = LSBYTE(proplen); // dwSize
hdr->index[0] = MSFTOSDESC_INDEX_EXTPROP;
hdr->count[0] = 1;
*payload++ = LSBYTE(proplen); /* dwSize */
*payload++ = MSBYTE(proplen);
*payload++ = 0;
*payload++ = 0;
*payload++ = 7; // dwPropertyDataType = REG_MULTI_SZ
*payload++ = 7; /* dwPropertyDataType = REG_MULTI_SZ */
*payload++ = 0;
*payload++ = 0;
*payload++ = 0;
*payload++ = LSBYTE(namelen); // wPropertyNameLength
*payload++ = LSBYTE(namelen); /* wPropertyNameLength */
*payload++ = MSBYTE(namelen);
payload += convert_to_utf16(payload, propname); // bPropertyName
*payload++ = 0; // Null terminator
payload += convert_to_utf16(payload, propname); /* bPropertyName */
*payload++ = 0; /* Null terminator */
*payload++ = 0;
*payload++= LSBYTE(valuelen); // dwPropertyDataLength
*payload++= MSBYTE(valuelen);
*payload++ = LSBYTE(valuelen); /* dwPropertyDataLength */
*payload++ = MSBYTE(valuelen);
*payload++ = 0;
*payload++ = 0;
payload += convert_to_utf16(payload, propval);
*payload++ = 0; // Null terminator for string
payload += convert_to_utf16(payload, propval);
*payload++ = 0; /* Null terminator for string */
*payload++ = 0;
*payload++ = 0; // Null terminator for array
*payload++ = 0; /* Null terminator for array */
*payload++ = 0;
return totallen;
}
#endif
static void dfu_workqueue_callback(void *arg)
@ -338,69 +346,76 @@ static int usbclass_setup(FAR struct usbdevclass_driver_s *driver,
uint16_t value;
uint16_t len;
int ret = -EOPNOTSUPP;
value = GETUINT16(ctrl->value);
len = GETUINT16(ctrl->len);
usbtrace(TRACE_CLASSSETUP, ctrl->req);
uinfo("type=%02x req=%02x value=%04x len=%04x\n",
ctrl->type, ctrl->req, value, len);
if ((ctrl->type & USB_REQ_TYPE_MASK) == USB_REQ_TYPE_STANDARD)
{
if (ctrl->req == USB_REQ_GETDESCRIPTOR)
{
if (ctrl->value[1] == USB_DESC_TYPE_CONFIG)
{
ret = usbclass_mkcfgdesc(ctrlreq->buf, &priv->devinfo);
}
else if (ctrl->value[1] == USB_DESC_TYPE_STRING)
{
ret = usbclass_mkstrdesc(ctrl->value[0], (struct usb_strdesc_s *)ctrlreq->buf);
}
if (ctrl->req == USB_REQ_GETDESCRIPTOR)
{
if (ctrl->value[1] == USB_DESC_TYPE_CONFIG)
{
ret = usbclass_mkcfgdesc(ctrlreq->buf, &priv->devinfo);
}
else if (ctrl->value[1] == USB_DESC_TYPE_STRING)
{
ret = usbclass_mkstrdesc(ctrl->value[0],
(FAR struct usb_strdesc_s *)ctrlreq->buf);
}
}
else if (ctrl->req == USB_REQ_SETCONFIGURATION)
{
return 0; /* Composite driver will send the reply */
}
else if (ctrl->req == USB_REQ_SETINTERFACE)
{
/* Only one alternate setting (0) is supported */
if (value == 0)
{
ret = 0;
}
}
else if (ctrl->req == USB_REQ_GETINTERFACE)
{
*(FAR uint8_t *) ctrlreq->buf = 0;
ret = 1;
}
}
else if (ctrl->req == USB_REQ_SETCONFIGURATION)
{
return 0; // Composite driver will send the reply
}
else if (ctrl->req == USB_REQ_SETINTERFACE)
{
// Only one alternate setting (0) is supported
if (value == 0)
{
ret = 0;
}
}
else if (ctrl->req == USB_REQ_GETINTERFACE)
{
*(FAR uint8_t *) ctrlreq->buf = 0;
ret = 1;
}
}
else if ((ctrl->type & USB_REQ_TYPE_MASK) == USB_REQ_TYPE_CLASS)
{
if (ctrl->req == USB_REQ_DFU_DETACH)
{
// Execute the bootloader activation through work queue, so that we can send
// the USB reply packet first.
work_queue(HPWORK, &priv->work_item, dfu_workqueue_callback, NULL, 1);
ret = 0;
if (ctrl->req == USB_REQ_DFU_DETACH)
{
/* Execute the bootloader activation through work queue, so that
* we can send the USB reply packet first.
*/
work_queue(HPWORK, &priv->work_item, dfu_workqueue_callback, NULL, 1);
ret = 0;
}
else if (ctrl->req == USB_REQ_DFU_GETSTATUS)
{
/* Respond with APP_IDLE status */
FAR struct dfu_getstatus_response_s *response =
(FAR struct dfu_getstatus_response_s *)ctrlreq->buf;
memset(response, 0, sizeof(struct dfu_getstatus_response_s));
ret = sizeof(struct dfu_getstatus_response_s);
}
}
else if (ctrl->req == USB_REQ_DFU_GETSTATUS)
{
/* Respond with APP_IDLE status */
FAR struct dfu_getstatus_response_s *response = (FAR struct dfu_getstatus_response_s*)ctrlreq->buf;
memset(response, 0, sizeof(struct dfu_getstatus_response_s));
ret = sizeof(struct dfu_getstatus_response_s);
}
}
#ifdef CONFIG_DFU_MSFT_OS_DESCRIPTORS
else if (ctrl->req == USB_REQ_GETMSFTOSDESCRIPTOR)
{
ret = dfu_make_msft_extprop_desc(ctrlreq->buf);
}
{
ret = dfu_make_msft_extprop_desc(ctrlreq->buf);
}
#endif
/* Respond to the setup command if data was returned. On an error return
* value (ret < 0), the USB driver will stall.
*/
@ -424,15 +439,16 @@ static int usbclass_bind(FAR struct usbdevclass_driver_s *driver,
FAR struct usbdev_s *dev)
{
FAR struct dfu_driver_s *priv = (FAR struct dfu_driver_s *)driver;
priv->ctrlreq = usbclass_allocreq(dev->ep0, DFU_MAX_DESCRIPTOR_LEN);
if (priv->ctrlreq == NULL)
{
usbtrace(TRACE_CLSERROR(USBSER_TRACEERR_ALLOCCTRLREQ), 0);
return -ENOMEM;
}
priv->ctrlreq->callback = usbclass_ep0incomplete;
return OK;
}
@ -440,18 +456,17 @@ static void usbclass_unbind(FAR struct usbdevclass_driver_s *driver,
FAR struct usbdev_s *dev)
{
FAR struct dfu_driver_s *priv = (FAR struct dfu_driver_s *)driver;
if (priv->ctrlreq != NULL)
{
usbclass_freereq(dev->ep0, priv->ctrlreq);
priv->ctrlreq = NULL;
}
{
usbclass_freereq(dev->ep0, priv->ctrlreq);
priv->ctrlreq = NULL;
}
}
static void usbclass_disconnect(FAR struct usbdevclass_driver_s *driver,
FAR struct usbdev_s *dev)
{
}
/****************************************************************************
@ -464,23 +479,24 @@ static void usbclass_disconnect(FAR struct usbdevclass_driver_s *driver,
* 0 on success, negative error code on failure.
*
****************************************************************************/
static int usbclass_classobject(int minor,
FAR struct usbdev_devinfo_s *devinfo,
FAR struct usbdevclass_driver_s **classdev)
{
FAR struct dfu_driver_s *alloc;
alloc = kmm_zalloc(sizeof(struct dfu_driver_s));
if (!alloc)
if (alloc == NULL)
{
return -ENOMEM;
}
*classdev = &alloc->drvr;
alloc->drvr.speed = USB_SPEED_FULL;
alloc->drvr.ops = &g_dfu_driverops;
return OK;
}
@ -494,6 +510,7 @@ static int usbclass_classobject(int minor,
* 0 on success, negative error code on failure.
*
****************************************************************************/
static void usbclass_uninitialize(FAR struct usbdevclass_driver_s *classdev)
{
kmm_free(classdev);
@ -507,13 +524,13 @@ void usbdev_dfu_get_composite_devdesc(struct composite_devdesc_s *dev)
{
memset(dev, 0, sizeof(struct composite_devdesc_s));
dev->mkconfdesc = usbclass_mkcfgdesc;
dev->mkstrdesc = usbclass_mkstrdesc;
dev->classobject = usbclass_classobject;
dev->uninitialize = usbclass_uninitialize;
dev->nconfigs = 1;
dev->configid = 0;
dev->cfgdescsize = sizeof(g_dfu_cfgdesc);
dev->mkconfdesc = usbclass_mkcfgdesc;
dev->mkstrdesc = usbclass_mkstrdesc;
dev->classobject = usbclass_classobject;
dev->uninitialize = usbclass_uninitialize;
dev->nconfigs = 1;
dev->configid = 0;
dev->cfgdescsize = sizeof(g_dfu_cfgdesc);
dev->devinfo.ninterfaces = 1;
dev->devinfo.nstrings = 1;
dev->devinfo.nendpoints = 0;
@ -522,5 +539,3 @@ void usbdev_dfu_get_composite_devdesc(struct composite_devdesc_s *dev)
memcpy(dev->msft_compatible_id, "WINUSB", 6);
#endif
}

View file

@ -1,7 +1,7 @@
/****************************************************************************
* drivers/usbdev/rndis.c
*
* Copyright (C) 2011-2017 Gregory Nutt. All rights reserved.
* Copyright (C) 2011-2018 Gregory Nutt. All rights reserved.
* Authors: Sakari Kapanen <sakari.m.kapanen@gmail.com>,
* Petteri Aimonen <jpa@git.mail.kapsi.fi>
*
@ -72,7 +72,8 @@
#define CONFIG_RNDIS_NWRREQS (2)
#define RNDIS_PACKET_HDR_SIZE (sizeof(struct rndis_packet_msg))
#define CONFIG_RNDIS_BULKIN_REQLEN (CONFIG_NET_ETH_PKTSIZE + CONFIG_NET_GUARDSIZE + RNDIS_PACKET_HDR_SIZE)
#define CONFIG_RNDIS_BULKIN_REQLEN \
(CONFIG_NET_ETH_PKTSIZE + CONFIG_NET_GUARDSIZE + RNDIS_PACKET_HDR_SIZE)
#define CONFIG_RNDIS_BULKOUT_REQLEN CONFIG_RNDIS_BULKIN_REQLEN
#define RNDIS_NCONFIGS (1)
@ -1849,7 +1850,7 @@ static int usbclass_mkstrdesc(uint8_t id, FAR struct usb_strdesc_s *strdesc)
static int16_t usbclass_mkcfgdesc(FAR uint8_t *buf,
FAR struct usbdev_devinfo_s *devinfo)
{
FAR struct rndis_cfgdesc_s *dest = (FAR struct rndis_cfgdesc_s*)buf;
FAR struct rndis_cfgdesc_s *dest = (FAR struct rndis_cfgdesc_s *)buf;
uint16_t totallen;
/* This is the total length of the configuration (not necessarily the
@ -1861,16 +1862,18 @@ static int16_t usbclass_mkcfgdesc(FAR uint8_t *buf,
#ifndef CONFIG_RNDIS_COMPOSITE
/* For a stand-alone device, just fill in the total length */
dest->cfgdesc.totallen[0] = LSBYTE(totallen);
dest->cfgdesc.totallen[1] = MSBYTE(totallen);
#else
/* For composite device, apply possible offset to the interface numbers */
dest->assoc_desc.firstif += devinfo->ifnobase;
dest->comm_ifdesc.ifno += devinfo->ifnobase;
dest->epintindesc.addr = USB_EPIN(devinfo->epno[RNDIS_EP_INTIN_IDX]);
dest->data_ifdesc.ifno += devinfo->ifnobase;
dest->epbulkindesc.addr = USB_EPIN(devinfo->epno[RNDIS_EP_BULKIN_IDX]);
dest->epbulkoutdesc.addr = USB_EPOUT(devinfo->epno[RNDIS_EP_BULKOUT_IDX]);
dest->comm_ifdesc.ifno += devinfo->ifnobase;
dest->epintindesc.addr = USB_EPIN(devinfo->epno[RNDIS_EP_INTIN_IDX]);
dest->data_ifdesc.ifno += devinfo->ifnobase;
dest->epbulkindesc.addr = USB_EPIN(devinfo->epno[RNDIS_EP_BULKIN_IDX]);
dest->epbulkoutdesc.addr = USB_EPOUT(devinfo->epno[RNDIS_EP_BULKOUT_IDX]);
#endif
return totallen;
@ -1929,7 +1932,8 @@ static int usbclass_bind(FAR struct usbdevclass_driver_s *driver,
/* Pre-allocate the IN interrupt endpoint */
priv->epintin = DEV_ALLOCEP(dev, USB_EPIN(priv->devinfo.epno[RNDIS_EP_INTIN_IDX]), true, USB_EP_ATTR_XFER_INT);
priv->epintin = DEV_ALLOCEP(dev, USB_EPIN(priv->devinfo.epno[RNDIS_EP_INTIN_IDX]),
true, USB_EP_ATTR_XFER_INT);
if (!priv->epintin)
{
usbtrace(TRACE_CLSERROR(USBSER_TRACEERR_EPINTINALLOCFAIL), 0);
@ -1951,7 +1955,8 @@ static int usbclass_bind(FAR struct usbdevclass_driver_s *driver,
/* Pre-allocate the IN bulk endpoint */
priv->epbulkin = DEV_ALLOCEP(dev, USB_EPIN(priv->devinfo.epno[RNDIS_EP_BULKIN_IDX]), true, USB_EP_ATTR_XFER_BULK);
priv->epbulkin = DEV_ALLOCEP(dev, USB_EPIN(priv->devinfo.epno[RNDIS_EP_BULKIN_IDX]),
true, USB_EP_ATTR_XFER_BULK);
if (!priv->epbulkin)
{
usbtrace(TRACE_CLSERROR(USBSER_TRACEERR_EPBULKINALLOCFAIL), 0);
@ -1963,7 +1968,8 @@ static int usbclass_bind(FAR struct usbdevclass_driver_s *driver,
/* Pre-allocate the OUT bulk endpoint */
priv->epbulkout = DEV_ALLOCEP(dev, USB_EPOUT(priv->devinfo.epno[RNDIS_EP_BULKOUT_IDX]), false, USB_EP_ATTR_XFER_BULK);
priv->epbulkout = DEV_ALLOCEP(dev, USB_EPOUT(priv->devinfo.epno[RNDIS_EP_BULKOUT_IDX]),
false, USB_EP_ATTR_XFER_BULK);
if (!priv->epbulkout)
{
usbtrace(TRACE_CLSERROR(USBSER_TRACEERR_EPBULKOUTALLOCFAIL), 0);
@ -2028,6 +2034,7 @@ static int usbclass_bind(FAR struct usbdevclass_driver_s *driver,
}
/* Report if we are selfpowered */
#ifndef CONFIG_RNDIS_COMPOSITE
#ifdef CONFIG_USBDEV_SELFPOWERED
DEV_SETSELFPOWERED(dev);
@ -2250,7 +2257,8 @@ static int usbclass_setup(FAR struct usbdevclass_driver_s *driver,
{
/* index == language code. */
ret = usbclass_mkstrdesc(ctrl->value[0], (struct usb_strdesc_s *)ctrlreq->buf);
ret = usbclass_mkstrdesc(ctrl->value[0],
(FAR struct usb_strdesc_s *)ctrlreq->buf);
}
break;
@ -2525,10 +2533,10 @@ static int usbclass_setconfig(FAR struct rndis_dev_s *priv, uint8_t config)
priv->rdreq->callback = rndis_rdcomplete;
ret = rndis_submit_rdreq(priv);
if (ret != OK)
{
usbtrace(TRACE_CLSERROR(USBSER_TRACEERR_RDSUBMIT), (uint16_t)-ret);
goto errout;
}
{
usbtrace(TRACE_CLSERROR(USBSER_TRACEERR_RDSUBMIT), (uint16_t)-ret);
goto errout;
}
/* We are successfully configured */
@ -2555,6 +2563,7 @@ errout:
* 0 on success, negative error code on failure.
*
****************************************************************************/
static int usbclass_classobject(int minor,
FAR struct usbdev_devinfo_s *devinfo,
FAR struct usbdevclass_driver_s **classdev)
@ -2623,7 +2632,7 @@ static int usbclass_classobject(int minor,
static void usbclass_uninitialize(FAR struct usbdevclass_driver_s *classdev)
{
FAR struct rndis_driver_s *drvr = (FAR struct rndis_driver_s*)classdev;
FAR struct rndis_driver_s *drvr = (FAR struct rndis_driver_s *)classdev;
FAR struct rndis_alloc_s *alloc = (FAR struct rndis_alloc_s *)drvr->dev;
if (drvr->dev->registered)
@ -2656,6 +2665,7 @@ static void usbclass_uninitialize(FAR struct usbdevclass_driver_s *classdev)
* 0 on success, -errno on failure
*
****************************************************************************/
#ifndef CONFIG_RNDIS_COMPOSITE
int usbdev_rndis_initialize(FAR const uint8_t *mac_address)
{
@ -2670,7 +2680,7 @@ int usbdev_rndis_initialize(FAR const uint8_t *mac_address)
return ret;
}
drvr = (FAR struct rndis_driver_s*)classdev;
drvr = (FAR struct rndis_driver_s *)classdev;
if (mac_address)
{
@ -2709,9 +2719,11 @@ int usbdev_rndis_initialize(FAR const uint8_t *mac_address)
* 0 on success, -errno on failure
*
****************************************************************************/
int usbdev_rndis_set_host_mac_addr(FAR struct net_driver_s *netdev, FAR const uint8_t *mac_address)
int usbdev_rndis_set_host_mac_addr(FAR struct net_driver_s *netdev,
FAR const uint8_t *mac_address)
{
FAR struct rndis_dev_s *dev = (FAR struct rndis_dev_s*)netdev;
FAR struct rndis_dev_s *dev = (FAR struct rndis_dev_s *)netdev;
if (mac_address)
{
@ -2721,11 +2733,10 @@ int usbdev_rndis_set_host_mac_addr(FAR struct net_driver_s *netdev, FAR const ui
{
memcpy(dev->host_mac_address, g_rndis_default_mac_addr, 6);
}
return OK;
}
/****************************************************************************
* Name: usbdev_rndis_get_composite_devdesc
*
@ -2746,20 +2757,22 @@ void usbdev_rndis_get_composite_devdesc(struct composite_devdesc_s *dev)
{
memset(dev, 0, sizeof(struct composite_devdesc_s));
dev->mkconfdesc = usbclass_mkcfgdesc;
dev->mkstrdesc = usbclass_mkstrdesc;
dev->classobject = usbclass_classobject;
dev->uninitialize = usbclass_uninitialize;
dev->nconfigs = RNDIS_NCONFIGS;
dev->configid = RNDIS_CONFIGID;
dev->cfgdescsize = sizeof(g_rndis_cfgdesc);
dev->mkconfdesc = usbclass_mkcfgdesc;
dev->mkstrdesc = usbclass_mkstrdesc;
dev->classobject = usbclass_classobject;
dev->uninitialize = usbclass_uninitialize;
dev->nconfigs = RNDIS_NCONFIGS;
dev->configid = RNDIS_CONFIGID;
dev->cfgdescsize = sizeof(g_rndis_cfgdesc);
dev->devinfo.ninterfaces = RNDIS_NINTERFACES;
dev->devinfo.nstrings = 0;
dev->devinfo.nendpoints = RNDIS_NUM_EPS;
/* Default endpoint indexes, board-specific logic can override these */
dev->devinfo.epno[RNDIS_EP_INTIN_IDX] = USB_EPNO(RNDIS_EPINTIN_ADDR);
dev->devinfo.epno[RNDIS_EP_BULKIN_IDX] = USB_EPNO(RNDIS_EPBULKIN_ADDR);
dev->devinfo.epno[RNDIS_EP_BULKOUT_IDX] = USB_EPNO(RNDIS_EPBULKOUT_ADDR);
}
#endif

View file

@ -91,3 +91,4 @@ void usbdev_dfu_activate_bootloader();
#endif
#endif /* __INCLUDE_NUTTX_USB_DFU_H */

View file

@ -1,7 +1,7 @@
/************************************************************************************
* include/nuttx/usb/rndis.h
*
* Copyright (C) 2011-2017 Gregory Nutt. All rights reserved.
* Copyright (C) 2011-2018 Gregory Nutt. All rights reserved.
* Authors: Sakari Kapanen <sakari.m.kapanen@gmail.com>,
Petteri Aimonen <jpa@git.mail.kapsi.fi>
*
@ -49,6 +49,7 @@
****************************************************************************/
/* Indexes for devinfo.epno[] array. Used for composite device configuration. */
#define RNDIS_EP_INTIN_IDX (0)
#define RNDIS_EP_BULKIN_IDX (1)
#define RNDIS_EP_BULKOUT_IDX (2)
@ -110,7 +111,8 @@ int usbdev_rndis_initialize(FAR const uint8_t *mac_address);
*
****************************************************************************/
int usbdev_rndis_set_host_mac_addr(FAR struct net_driver_s *netdev, FAR const uint8_t *mac_address);
int usbdev_rndis_set_host_mac_addr(FAR struct net_driver_s *netdev,
FAR const uint8_t *mac_address);
/****************************************************************************
* Name: usbdev_rndis_get_composite_devdesc

View file

@ -1,7 +1,7 @@
/************************************************************************************
* include/nuttx/usb/usb.h
*
* Copyright (C) 2008, 2009-2010, 2012 Gregory Nutt. All rights reserved.
* Copyright (C) 2008, 2009-2010, 2012, 2008 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <gnutt@nuttx.org>
*
* Redistribution and use in source and binary forms, with or without
@ -47,6 +47,7 @@
/************************************************************************************
* Pre-processor Definitions
************************************************************************************/
/* A packet identifier (PID) immediately follows the SYNC field of every USB packet.
* A PID consists of a four-bit packet type field followed by a four-bit check field
* USB Tokens (See Table 8-1 in the USB specification)
@ -260,6 +261,7 @@
#define USB_MAX_DEVICES (127)
/* Microsoft OS Descriptor specific values */
#define USB_REQ_GETMSFTOSDESCRIPTOR (0xEE)
#define MSFTOSDESC_INDEX_FUNCTION 4
#define MSFTOSDESC_INDEX_EXTPROP 5
@ -278,6 +280,7 @@ struct usb_ctrlreq_s
uint8_t index[2];
uint8_t len[2];
};
#define USB_SIZEOF_CTRLREQ 8
/* Generic descriptor */
@ -307,6 +310,7 @@ struct usb_devdesc_s
uint8_t serno; /* Serial number */
uint8_t nconfigs; /* Number of configurations */
};
#define USB_SIZEOF_DEVDESC 18
/* Configuration descriptor */
@ -322,6 +326,7 @@ struct usb_cfgdesc_s
uint8_t attr; /* Attributes */
uint8_t mxpower; /* Max power (mA/2) */
};
#define USB_SIZEOF_CFGDESC 9
struct usb_otherspeedconfigdesc_s
@ -335,6 +340,7 @@ struct usb_otherspeedconfigdesc_s
uint8_t attr; /* Attributes */
uint8_t mxpower; /* Max power (mA/2) */
};
#define USB_SIZEOF_OTHERSPEEDCONFIGDESC 9
/* String descriptor */
@ -360,6 +366,7 @@ struct usb_ifdesc_s
uint8_t protocol; /* Interface protocol */
uint8_t iif; /* iInterface */
};
#define USB_SIZEOF_IFDESC 9
/* Endpoint descriptor */
@ -373,6 +380,7 @@ struct usb_epdesc_s
uint8_t mxpacketsize[2]; /* Maximum packet size */
uint8_t interval; /* Interval */
};
#define USB_SIZEOF_EPDESC 7
struct usb_audioepdesc_s
@ -381,6 +389,7 @@ struct usb_audioepdesc_s
uint8_t refresh;
uint8_t synchaddr;
};
#define USB_SIZEOF_AUDIOEPDESC 9
/* Device qualifier descriptor */
@ -397,6 +406,7 @@ struct usb_qualdesc_s
uint8_t nconfigs; /* Number of configurations */
uint8_t reserved;
};
#define USB_SIZEOF_QUALDESC 10
/* Interface association descriptor
@ -420,6 +430,7 @@ struct usb_iaddesc_s
uint8_t protocol; /* Protocol code */
uint8_t ifunction; /* Index to string identifying the function */
};
#define USB_SIZEOF_IADDESC 8
/* Microsoft OS function descriptor.
@ -460,6 +471,7 @@ struct usb_msft_os_feature_desc_s
* The interface will have one extended properties descriptor, which may contain
* multiple properties inside it.
*/
struct usb_msft_os_extprop_hdr_s
{
uint8_t len[4]; /* Descriptor length */