2017-09-24 15:24:34 +02:00
|
|
|
/****************************************************************************
|
|
|
|
* drivers/usbdev/rndis.c
|
|
|
|
*
|
2021-05-27 11:12:43 +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
|
2017-09-24 15:24:34 +02:00
|
|
|
*
|
2021-05-27 11:12:43 +02:00
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
2017-09-24 15:24:34 +02:00
|
|
|
*
|
2021-05-27 11:12:43 +02:00
|
|
|
* 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.
|
2017-09-24 15:24:34 +02:00
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
2021-05-27 11:12:43 +02:00
|
|
|
/* References:
|
|
|
|
* [MS-RNDIS]:
|
|
|
|
* Remote Network Driver Interface Specification (RNDIS) Protocol
|
|
|
|
*/
|
|
|
|
|
2017-09-24 15:24:34 +02:00
|
|
|
/****************************************************************************
|
|
|
|
* Included Files
|
|
|
|
****************************************************************************/
|
|
|
|
|
2021-05-18 08:59:14 +02:00
|
|
|
#include <assert.h>
|
2021-05-14 04:45:57 +02:00
|
|
|
#include <debug.h>
|
2017-09-24 15:24:34 +02:00
|
|
|
#include <errno.h>
|
2020-11-27 10:00:19 +01:00
|
|
|
#include <inttypes.h>
|
2017-09-24 15:24:34 +02:00
|
|
|
#include <string.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <stdio.h>
|
2023-02-27 07:52:21 +01:00
|
|
|
#include <stdint.h>
|
2017-09-24 15:24:34 +02:00
|
|
|
|
2023-02-03 14:42:03 +01:00
|
|
|
#include <sys/param.h>
|
|
|
|
|
2022-09-25 17:08:38 +02:00
|
|
|
#include <nuttx/queue.h>
|
2017-09-24 15:24:34 +02:00
|
|
|
#include <nuttx/net/net.h>
|
|
|
|
#include <nuttx/net/netdev.h>
|
|
|
|
#include <nuttx/kmalloc.h>
|
|
|
|
#include <nuttx/arch.h>
|
|
|
|
#include <nuttx/usb/usb.h>
|
|
|
|
#include <nuttx/usb/cdc.h>
|
|
|
|
#include <nuttx/usb/usbdev.h>
|
|
|
|
#include <nuttx/usb/usbdev_trace.h>
|
2018-11-09 13:56:58 +01:00
|
|
|
#include <nuttx/usb/rndis.h>
|
2017-09-24 15:24:34 +02:00
|
|
|
#include <nuttx/wqueue.h>
|
|
|
|
|
2022-01-18 02:36:37 +01:00
|
|
|
#ifdef CONFIG_RNDIS_BOARD_SERIALSTR
|
|
|
|
#include <nuttx/board.h>
|
|
|
|
#endif
|
|
|
|
|
2017-09-24 15:24:34 +02:00
|
|
|
#include "rndis_std.h"
|
|
|
|
|
2023-07-05 03:20:33 +02:00
|
|
|
#ifdef CONFIG_RNDIS_COMPOSITE
|
2023-03-23 11:45:44 +01:00
|
|
|
# include <nuttx/usb/composite.h>
|
|
|
|
#endif
|
|
|
|
|
2017-09-24 15:24:34 +02:00
|
|
|
/****************************************************************************
|
|
|
|
* Pre-processor definitions
|
|
|
|
****************************************************************************/
|
|
|
|
|
2023-03-24 13:18:36 +01:00
|
|
|
#define RNDIS_MKEPINTIN(desc) (USB_DIR_IN | (desc)->epno[RNDIS_EP_INTIN_IDX])
|
|
|
|
#define RNDIS_EPINTIN_ATTR (USB_EP_ATTR_XFER_INT)
|
|
|
|
|
|
|
|
#define RNDIS_MKEPBULKIN(desc) (USB_DIR_IN | (desc)->epno[RNDIS_EP_BULKIN_IDX])
|
|
|
|
#define RNDIS_EPOUTBULK_ATTR (USB_EP_ATTR_XFER_BULK)
|
|
|
|
|
|
|
|
#define RNDIS_MKEPBULKOUT(desc) ((desc)->epno[RNDIS_EP_BULKOUT_IDX])
|
|
|
|
#define RNDIS_EPINBULK_ATTR (USB_EP_ATTR_XFER_BULK)
|
|
|
|
|
2017-09-24 15:24:34 +02:00
|
|
|
#define CONFIG_RNDIS_EP0MAXPACKET 64
|
|
|
|
|
2019-08-10 19:52:19 +02:00
|
|
|
#ifndef CONFIG_RNDIS_NWRREQS
|
|
|
|
# define CONFIG_RNDIS_NWRREQS (2)
|
|
|
|
#endif
|
2017-09-24 15:24:34 +02:00
|
|
|
|
|
|
|
#define RNDIS_PACKET_HDR_SIZE (sizeof(struct rndis_packet_msg))
|
2018-11-09 14:44:22 +01:00
|
|
|
#define CONFIG_RNDIS_BULKIN_REQLEN \
|
|
|
|
(CONFIG_NET_ETH_PKTSIZE + CONFIG_NET_GUARDSIZE + RNDIS_PACKET_HDR_SIZE)
|
2017-11-13 09:55:41 +01:00
|
|
|
#define CONFIG_RNDIS_BULKOUT_REQLEN CONFIG_RNDIS_BULKIN_REQLEN
|
2017-09-24 15:24:34 +02:00
|
|
|
|
2023-02-14 10:16:46 +01:00
|
|
|
static_assert(CONFIG_NET_LL_GUARDSIZE >= RNDIS_PACKET_HDR_SIZE + ETH_HDRLEN,
|
|
|
|
"CONFIG_NET_LL_GUARDSIZE cannot be less than ETH_HDRLEN"
|
|
|
|
" + RNDIS_PACKET_HDR_SIZE");
|
|
|
|
|
|
|
|
static_assert((CONFIG_NET_LL_GUARDSIZE % 4) == 2,
|
|
|
|
"CONFIG_NET_LL_GUARDSIZE - ETH_HDRLEN "
|
|
|
|
"should be aligned to 4 bytes");
|
|
|
|
|
2017-09-24 15:24:34 +02:00
|
|
|
#define RNDIS_NCONFIGS (1)
|
|
|
|
#define RNDIS_CONFIGID (1)
|
|
|
|
#define RNDIS_CONFIGIDNONE (0)
|
2018-11-09 13:56:58 +01:00
|
|
|
#define RNDIS_NINTERFACES (2)
|
2023-03-21 12:16:44 +01:00
|
|
|
#define RNDIS_NSTRIDS (0)
|
2017-09-24 15:24:34 +02:00
|
|
|
|
2023-03-24 13:13:04 +01:00
|
|
|
#ifndef CONFIG_RNDIS_COMPOSITE
|
|
|
|
# define RNDIS_EPINTIN_ADDR USB_EPIN(CONFIG_RNDIS_EPINTIN)
|
|
|
|
# define RNDIS_EPBULKIN_ADDR USB_EPIN(CONFIG_RNDIS_EPBULKIN)
|
|
|
|
# define RNDIS_EPBULKOUT_ADDR USB_EPOUT(CONFIG_RNDIS_EPBULKOUT)
|
|
|
|
#endif
|
2018-11-09 13:56:58 +01:00
|
|
|
#define RNDIS_NUM_EPS (3)
|
2017-09-24 15:24:34 +02:00
|
|
|
|
|
|
|
#define RNDIS_MANUFACTURERSTRID (1)
|
|
|
|
#define RNDIS_PRODUCTSTRID (2)
|
|
|
|
#define RNDIS_SERIALSTRID (3)
|
|
|
|
|
|
|
|
#define RNDIS_STR_LANGUAGE (0x0409) /* en-us */
|
|
|
|
|
|
|
|
#define RNDIS_MXDESCLEN (128)
|
|
|
|
#define RNDIS_MAXSTRLEN (RNDIS_MXDESCLEN-2)
|
2021-03-24 08:11:26 +01:00
|
|
|
#define RNDIS_CTRLREQ_LEN (256)
|
2021-03-26 09:41:27 +01:00
|
|
|
#define RNDIS_RESP_QUEUE_WORDS (64)
|
2017-09-24 15:24:34 +02:00
|
|
|
|
2018-07-04 22:10:40 +02:00
|
|
|
#define RNDIS_BUFFER_SIZE CONFIG_NET_ETH_PKTSIZE
|
2017-09-24 15:24:34 +02:00
|
|
|
#define RNDIS_BUFFER_COUNT 4
|
|
|
|
|
2017-10-09 17:00:48 +02:00
|
|
|
/* Work queue to use for network operations. LPWORK should be used here */
|
|
|
|
|
|
|
|
#define ETHWORK LPWORK
|
|
|
|
|
2017-09-24 15:24:34 +02:00
|
|
|
/****************************************************************************
|
|
|
|
* Private Types
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
/* Container to support a list of requests */
|
|
|
|
|
|
|
|
struct rndis_req_s
|
|
|
|
{
|
|
|
|
FAR struct rndis_req_s *flink; /* Implements a singly linked list */
|
|
|
|
FAR struct usbdev_req_s *req; /* The contained request */
|
2023-02-14 10:16:46 +01:00
|
|
|
FAR struct iob_s *iob; /* IOB offload */
|
|
|
|
FAR uint8_t *buf; /* Use malloc buffer when config IOB_LEN < CONFIG_RNDIS_BULKIN_REQLEN */
|
2017-09-24 15:24:34 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
/* This structure describes the internal state of the driver */
|
|
|
|
|
|
|
|
struct rndis_dev_s
|
|
|
|
{
|
|
|
|
struct net_driver_s netdev; /* Network driver structure */
|
2018-11-09 13:56:58 +01:00
|
|
|
struct usbdev_devinfo_s devinfo;
|
|
|
|
|
2017-09-24 15:24:34 +02:00
|
|
|
FAR struct usbdev_s *usbdev; /* usbdev driver pointer */
|
|
|
|
FAR struct usbdev_ep_s *epintin; /* Interrupt IN endpoint structure */
|
|
|
|
FAR struct usbdev_ep_s *epbulkin; /* Bulk IN endpoint structure */
|
|
|
|
FAR struct usbdev_ep_s *epbulkout; /* Bulk OUT endpoint structure */
|
|
|
|
FAR struct usbdev_req_s *ctrlreq; /* Pointer to preallocated control request */
|
|
|
|
FAR struct usbdev_req_s *epintin_req; /* Pointer to preallocated interrupt in endpoint request */
|
|
|
|
FAR struct usbdev_req_s *rdreq; /* Pointer to Preallocated control endpoint read request */
|
|
|
|
struct sq_queue_s reqlist; /* List of free write request containers */
|
|
|
|
|
|
|
|
/* Preallocated USB request buffers */
|
|
|
|
|
|
|
|
struct rndis_req_s wrreqs[CONFIG_RNDIS_NWRREQS];
|
|
|
|
|
|
|
|
struct work_s rxwork; /* Worker for dispatching RX packets */
|
|
|
|
struct work_s pollwork; /* TX poll worker */
|
|
|
|
|
2018-11-09 13:56:58 +01:00
|
|
|
bool registered; /* Has netdev_register() been called */
|
|
|
|
|
2017-09-24 15:24:34 +02:00
|
|
|
uint8_t config; /* USB Configuration number */
|
|
|
|
FAR struct rndis_req_s *net_req; /* Pointer to request whose buffer is assigned to network */
|
|
|
|
FAR struct rndis_req_s *rx_req; /* Pointer request container that holds RX buffer */
|
|
|
|
size_t current_rx_received; /* Number of bytes of current RX datagram received over USB */
|
|
|
|
size_t current_rx_datagram_size; /* Total number of bytes of the current RX datagram */
|
|
|
|
size_t current_rx_datagram_offset; /* Offset of current RX datagram */
|
2017-11-08 14:33:09 +01:00
|
|
|
size_t current_rx_msglen; /* Length of the entire message to be received */
|
2017-09-24 15:24:34 +02:00
|
|
|
bool rdreq_submitted; /* Indicates if the read request is submitted */
|
|
|
|
bool rx_blocked; /* Indicates if we can receive packets on bulk in endpoint */
|
2017-09-24 19:18:01 +02:00
|
|
|
bool connected; /* Connection status indicator */
|
2017-09-24 15:24:34 +02:00
|
|
|
uint32_t rndis_packet_filter; /* RNDIS packet filter value */
|
|
|
|
uint32_t rndis_host_tx_count; /* TX packet counter */
|
|
|
|
uint32_t rndis_host_rx_count; /* RX packet counter */
|
|
|
|
uint8_t host_mac_address[6]; /* Host side MAC address */
|
2021-03-24 08:11:26 +01:00
|
|
|
|
2021-03-26 09:41:27 +01:00
|
|
|
size_t response_queue_words; /* Count of words waiting in response_queue. */
|
|
|
|
uint32_t response_queue[RNDIS_RESP_QUEUE_WORDS];
|
2017-09-24 15:24:34 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
/* The internal version of the class driver */
|
|
|
|
|
|
|
|
struct rndis_driver_s
|
|
|
|
{
|
|
|
|
struct usbdevclass_driver_s drvr;
|
|
|
|
FAR struct rndis_dev_s *dev;
|
|
|
|
};
|
|
|
|
|
|
|
|
/* This is what is allocated */
|
|
|
|
|
|
|
|
struct rndis_alloc_s
|
|
|
|
{
|
|
|
|
struct rndis_dev_s dev;
|
|
|
|
struct rndis_driver_s drvr;
|
|
|
|
};
|
|
|
|
|
|
|
|
/* RNDIS USB configuration descriptor */
|
|
|
|
|
|
|
|
struct rndis_cfgdesc_s
|
|
|
|
{
|
2018-11-09 13:56:58 +01:00
|
|
|
#ifndef CONFIG_RNDIS_COMPOSITE
|
2017-09-24 15:24:34 +02:00
|
|
|
struct usb_cfgdesc_s cfgdesc; /* Configuration descriptor */
|
2023-03-21 21:18:35 +01:00
|
|
|
#elif defined(CONFIG_COMPOSITE_IAD)
|
2017-09-24 15:24:34 +02:00
|
|
|
struct usb_iaddesc_s assoc_desc; /* Interface association descriptor */
|
2023-03-21 21:18:35 +01:00
|
|
|
#endif
|
2017-09-24 15:24:34 +02:00
|
|
|
struct usb_ifdesc_s comm_ifdesc; /* Communication interface descriptor */
|
|
|
|
struct usb_epdesc_s epintindesc; /* Interrupt endpoint descriptor */
|
|
|
|
struct usb_ifdesc_s data_ifdesc; /* Data interface descriptor */
|
|
|
|
struct usb_epdesc_s epbulkindesc; /* Bulk in interface descriptor */
|
|
|
|
struct usb_epdesc_s epbulkoutdesc; /* Bulk out interface descriptor */
|
|
|
|
};
|
|
|
|
|
|
|
|
/* RNDIS object ID - value pair structure */
|
|
|
|
|
|
|
|
struct rndis_oid_value_s
|
|
|
|
{
|
2017-09-24 19:18:01 +02:00
|
|
|
uint32_t objid;
|
|
|
|
uint32_t length;
|
|
|
|
uint32_t value;
|
|
|
|
FAR const void *data; /* Data pointer overrides value if non-NULL. */
|
2017-09-24 15:24:34 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Private Function Prototypes
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
/* Netdev driver callbacks */
|
|
|
|
|
|
|
|
static int rndis_ifup(FAR struct net_driver_s *dev);
|
|
|
|
static int rndis_ifdown(FAR struct net_driver_s *dev);
|
|
|
|
static int rndis_txavail(FAR struct net_driver_s *dev);
|
2017-11-13 09:55:41 +01:00
|
|
|
static int rndis_transmit(FAR struct rndis_dev_s *priv);
|
2017-09-24 15:24:34 +02:00
|
|
|
static int rndis_txpoll(FAR struct net_driver_s *dev);
|
|
|
|
|
|
|
|
/* usbclass callbacks */
|
|
|
|
|
|
|
|
static int usbclass_setup(FAR struct usbdevclass_driver_s *driver,
|
|
|
|
FAR struct usbdev_s *dev,
|
|
|
|
FAR const struct usb_ctrlreq_s *ctrl,
|
|
|
|
FAR uint8_t *dataout, size_t outlen);
|
|
|
|
static int usbclass_bind(FAR struct usbdevclass_driver_s *driver,
|
|
|
|
FAR struct usbdev_s *dev);
|
|
|
|
static void usbclass_unbind(FAR struct usbdevclass_driver_s *driver,
|
|
|
|
FAR struct usbdev_s *dev);
|
|
|
|
static void usbclass_disconnect(FAR struct usbdevclass_driver_s *driver,
|
|
|
|
FAR struct usbdev_s *dev);
|
|
|
|
static int usbclass_setconfig(FAR struct rndis_dev_s *priv, uint8_t config);
|
|
|
|
static void usbclass_resetconfig(FAR struct rndis_dev_s *priv);
|
|
|
|
|
2019-07-24 00:12:50 +02:00
|
|
|
/* usbclass helpers */
|
|
|
|
|
|
|
|
static int usbclass_copy_epdesc(int epid, FAR struct usb_epdesc_s *epdesc,
|
|
|
|
FAR struct usbdev_devinfo_s *devinfo,
|
|
|
|
bool hispeed);
|
|
|
|
|
2017-09-24 15:24:34 +02:00
|
|
|
/****************************************************************************
|
|
|
|
* Private Data
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
/* USB driver operations */
|
|
|
|
|
|
|
|
const static struct usbdevclass_driverops_s g_driverops =
|
|
|
|
{
|
|
|
|
&usbclass_bind,
|
|
|
|
&usbclass_unbind,
|
|
|
|
&usbclass_setup,
|
|
|
|
&usbclass_disconnect,
|
|
|
|
NULL,
|
|
|
|
NULL
|
|
|
|
};
|
|
|
|
|
2018-11-09 13:56:58 +01:00
|
|
|
#ifndef CONFIG_RNDIS_COMPOSITE
|
2017-09-24 15:24:34 +02:00
|
|
|
static const struct usb_devdesc_s g_devdesc =
|
|
|
|
{
|
|
|
|
USB_SIZEOF_DEVDESC, /* len */
|
|
|
|
USB_DESC_TYPE_DEVICE, /* type */
|
|
|
|
{LSBYTE(0x0200), MSBYTE(0x0200)}, /* usb */
|
|
|
|
0, /* classid */
|
|
|
|
0, /* subclass */
|
|
|
|
0, /* protocol */
|
|
|
|
CONFIG_RNDIS_EP0MAXPACKET, /* maxpacketsize */
|
|
|
|
{ LSBYTE(CONFIG_RNDIS_VENDORID), /* vendor */
|
|
|
|
MSBYTE(CONFIG_RNDIS_VENDORID) },
|
|
|
|
{ LSBYTE(CONFIG_RNDIS_PRODUCTID), /* product */
|
|
|
|
MSBYTE(CONFIG_RNDIS_PRODUCTID) },
|
|
|
|
{ LSBYTE(CONFIG_RNDIS_VERSIONNO), /* device */
|
|
|
|
MSBYTE(CONFIG_RNDIS_VERSIONNO) },
|
|
|
|
RNDIS_MANUFACTURERSTRID, /* imfgr */
|
|
|
|
RNDIS_PRODUCTSTRID, /* iproduct */
|
|
|
|
RNDIS_SERIALSTRID, /* serno */
|
|
|
|
RNDIS_NCONFIGS /* nconfigs */
|
|
|
|
};
|
2018-11-09 13:56:58 +01:00
|
|
|
#endif
|
2017-09-24 15:24:34 +02:00
|
|
|
|
|
|
|
const static struct rndis_cfgdesc_s g_rndis_cfgdesc =
|
|
|
|
{
|
2018-11-09 13:56:58 +01:00
|
|
|
#ifndef CONFIG_RNDIS_COMPOSITE
|
2017-09-24 15:24:34 +02:00
|
|
|
{
|
2017-09-24 19:18:01 +02:00
|
|
|
.len = USB_SIZEOF_CFGDESC,
|
|
|
|
.type = USB_DESC_TYPE_CONFIG,
|
2019-12-24 17:37:30 +01:00
|
|
|
.totallen =
|
|
|
|
{
|
|
|
|
0, 0
|
|
|
|
},
|
2018-11-09 13:56:58 +01:00
|
|
|
.ninterfaces = RNDIS_NINTERFACES,
|
2017-09-24 19:18:01 +02:00
|
|
|
.cfgvalue = RNDIS_CONFIGID,
|
|
|
|
.icfg = 0,
|
|
|
|
.attr = USB_CONFIG_ATTR_ONE | USB_CONFIG_ATTR_SELFPOWER,
|
2017-10-09 17:00:48 +02:00
|
|
|
.mxpower = (CONFIG_USBDEV_MAXPOWER + 1) / 2
|
2017-09-24 15:24:34 +02:00
|
|
|
},
|
2023-03-21 21:18:35 +01:00
|
|
|
#elif defined(CONFIG_COMPOSITE_IAD)
|
2017-09-24 15:24:34 +02:00
|
|
|
{
|
2017-09-24 19:18:01 +02:00
|
|
|
.len = USB_SIZEOF_IADDESC,
|
|
|
|
.type = USB_DESC_TYPE_INTERFACEASSOCIATION,
|
|
|
|
.firstif = 0,
|
2018-11-09 13:56:58 +01:00
|
|
|
.nifs = RNDIS_NINTERFACES,
|
2017-09-24 19:18:01 +02:00
|
|
|
.classid = 0xef,
|
|
|
|
.subclass = 0x04,
|
|
|
|
.protocol = 0x01,
|
|
|
|
.ifunction = 0
|
2017-09-24 15:24:34 +02:00
|
|
|
},
|
2023-03-21 21:18:35 +01:00
|
|
|
#endif
|
2017-09-24 15:24:34 +02:00
|
|
|
{
|
2017-09-24 19:18:01 +02:00
|
|
|
.len = USB_SIZEOF_IFDESC,
|
|
|
|
.type = USB_DESC_TYPE_INTERFACE,
|
|
|
|
.ifno = 0,
|
|
|
|
.alt = 0,
|
|
|
|
.neps = 1,
|
|
|
|
.classid = USB_CLASS_CDC,
|
|
|
|
.subclass = CDC_SUBCLASS_ACM,
|
|
|
|
.protocol = CDC_PROTO_VENDOR,
|
|
|
|
.iif = 0
|
2017-09-24 15:24:34 +02:00
|
|
|
},
|
|
|
|
{
|
2017-09-24 19:18:01 +02:00
|
|
|
.len = USB_SIZEOF_EPDESC,
|
|
|
|
.type = USB_DESC_TYPE_ENDPOINT,
|
2023-03-24 13:13:04 +01:00
|
|
|
#ifndef CONFIG_RNDIS_COMPOSITE
|
2017-09-24 19:18:01 +02:00
|
|
|
.addr = RNDIS_EPINTIN_ADDR,
|
2023-03-24 13:13:04 +01:00
|
|
|
#endif
|
2017-09-24 19:18:01 +02:00
|
|
|
.attr = USB_EP_ATTR_XFER_INT,
|
2019-12-24 17:37:30 +01:00
|
|
|
.mxpacketsize =
|
|
|
|
{
|
|
|
|
LSBYTE(16), MSBYTE(16)
|
|
|
|
},
|
2017-09-24 15:24:34 +02:00
|
|
|
.interval = 1
|
|
|
|
},
|
|
|
|
{
|
2017-09-24 19:18:01 +02:00
|
|
|
.len = USB_SIZEOF_IFDESC,
|
|
|
|
.type = USB_DESC_TYPE_INTERFACE,
|
|
|
|
.ifno = 1,
|
|
|
|
.alt = 0,
|
|
|
|
.neps = 2,
|
|
|
|
.classid = USB_CLASS_CDC_DATA,
|
|
|
|
.subclass = 0,
|
|
|
|
.protocol = 0,
|
|
|
|
.iif = 0
|
2017-09-24 15:24:34 +02:00
|
|
|
},
|
|
|
|
{
|
2017-09-24 19:18:01 +02:00
|
|
|
.len = USB_SIZEOF_EPDESC,
|
|
|
|
.type = USB_DESC_TYPE_ENDPOINT,
|
2023-03-24 13:13:04 +01:00
|
|
|
#ifndef CONFIG_RNDIS_COMPOSITE
|
2017-09-24 19:18:01 +02:00
|
|
|
.addr = RNDIS_EPBULKIN_ADDR,
|
2023-03-24 13:13:04 +01:00
|
|
|
#endif
|
2017-09-24 19:18:01 +02:00
|
|
|
.attr = USB_EP_ATTR_XFER_BULK,
|
2017-11-13 09:55:41 +01:00
|
|
|
#ifdef CONFIG_USBDEV_DUALSPEED
|
2019-12-24 17:37:30 +01:00
|
|
|
.mxpacketsize =
|
|
|
|
{
|
|
|
|
LSBYTE(512), MSBYTE(512)
|
|
|
|
},
|
2017-11-13 09:55:41 +01:00
|
|
|
.interval = 0
|
|
|
|
#else
|
2019-12-24 17:37:30 +01:00
|
|
|
.mxpacketsize =
|
|
|
|
{
|
|
|
|
LSBYTE(64), MSBYTE(64)
|
|
|
|
},
|
2017-09-24 19:18:01 +02:00
|
|
|
.interval = 1
|
2017-11-13 09:55:41 +01:00
|
|
|
#endif
|
2017-09-24 15:24:34 +02:00
|
|
|
},
|
|
|
|
{
|
2017-09-24 19:18:01 +02:00
|
|
|
.len = USB_SIZEOF_EPDESC,
|
|
|
|
.type = USB_DESC_TYPE_ENDPOINT,
|
2023-03-24 13:13:04 +01:00
|
|
|
#ifndef CONFIG_RNDIS_COMPOSITE
|
2017-09-24 19:18:01 +02:00
|
|
|
.addr = RNDIS_EPBULKOUT_ADDR,
|
2023-03-24 13:13:04 +01:00
|
|
|
#endif
|
2017-09-24 19:18:01 +02:00
|
|
|
.attr = USB_EP_ATTR_XFER_BULK,
|
2017-11-13 09:55:41 +01:00
|
|
|
#ifdef CONFIG_USBDEV_DUALSPEED
|
2019-12-24 17:37:30 +01:00
|
|
|
.mxpacketsize =
|
|
|
|
{
|
|
|
|
LSBYTE(512), MSBYTE(512)
|
|
|
|
},
|
2017-11-13 09:55:41 +01:00
|
|
|
.interval = 0
|
|
|
|
#else
|
2019-12-24 17:37:30 +01:00
|
|
|
.mxpacketsize =
|
|
|
|
{
|
|
|
|
LSBYTE(64), MSBYTE(64)
|
|
|
|
},
|
2017-09-24 19:18:01 +02:00
|
|
|
.interval = 1
|
2017-11-13 09:55:41 +01:00
|
|
|
#endif
|
2017-09-24 15:24:34 +02:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
/* Default MAC address given to the host side of the interface. */
|
|
|
|
|
|
|
|
static uint8_t g_rndis_default_mac_addr[6] =
|
|
|
|
{
|
|
|
|
0x02, 0x00, 0x00, 0x11, 0x22, 0x33
|
|
|
|
};
|
|
|
|
|
|
|
|
/* These lists give dummy responses to be returned to PC. The values are
|
2020-08-06 19:41:45 +02:00
|
|
|
* chosen so that Windows is happy - other operating systems don't really
|
|
|
|
* care much.
|
2017-09-24 15:24:34 +02:00
|
|
|
*/
|
|
|
|
|
|
|
|
static const uint32_t g_rndis_supported_oids[] =
|
|
|
|
{
|
|
|
|
RNDIS_OID_GEN_SUPPORTED_LIST,
|
|
|
|
RNDIS_OID_GEN_HARDWARE_STATUS,
|
|
|
|
RNDIS_OID_GEN_MEDIA_SUPPORTED,
|
|
|
|
RNDIS_OID_GEN_MEDIA_IN_USE,
|
|
|
|
RNDIS_OID_GEN_MAXIMUM_FRAME_SIZE,
|
|
|
|
RNDIS_OID_GEN_LINK_SPEED,
|
|
|
|
RNDIS_OID_GEN_TRANSMIT_BLOCK_SIZE,
|
|
|
|
RNDIS_OID_GEN_RECEIVE_BLOCK_SIZE,
|
|
|
|
RNDIS_OID_GEN_VENDOR_ID,
|
|
|
|
RNDIS_OID_GEN_VENDOR_DESCRIPTION,
|
|
|
|
RNDIS_OID_GEN_VENDOR_DRIVER_VERSION,
|
|
|
|
RNDIS_OID_GEN_CURRENT_PACKET_FILTER,
|
|
|
|
RNDIS_OID_GEN_MAXIMUM_TOTAL_SIZE,
|
|
|
|
RNDIS_OID_GEN_MEDIA_CONNECT_STATUS,
|
|
|
|
RNDIS_OID_GEN_PHYSICAL_MEDIUM,
|
|
|
|
RNDIS_OID_GEN_XMIT_OK,
|
|
|
|
RNDIS_OID_GEN_RCV_OK,
|
|
|
|
RNDIS_OID_GEN_XMIT_ERROR,
|
|
|
|
RNDIS_OID_GEN_RCV_ERROR,
|
|
|
|
RNDIS_OID_GEN_RCV_NO_BUFFER,
|
|
|
|
RNDIS_OID_802_3_PERMANENT_ADDRESS,
|
|
|
|
RNDIS_OID_802_3_CURRENT_ADDRESS,
|
|
|
|
RNDIS_OID_802_3_MULTICAST_LIST,
|
|
|
|
RNDIS_OID_802_3_MAC_OPTIONS,
|
|
|
|
RNDIS_OID_802_3_MAXIMUM_LIST_SIZE,
|
|
|
|
RNDIS_OID_802_3_RCV_ERROR_ALIGNMENT,
|
|
|
|
RNDIS_OID_802_3_XMIT_ONE_COLLISION,
|
|
|
|
RNDIS_OID_802_3_XMIT_MORE_COLLISION,
|
|
|
|
};
|
|
|
|
|
|
|
|
static const struct rndis_oid_value_s g_rndis_oid_values[] =
|
|
|
|
{
|
2019-12-24 17:37:30 +01:00
|
|
|
{
|
|
|
|
RNDIS_OID_GEN_SUPPORTED_LIST,
|
|
|
|
sizeof(g_rndis_supported_oids), 0,
|
|
|
|
g_rndis_supported_oids
|
|
|
|
},
|
2018-07-04 22:10:40 +02:00
|
|
|
{RNDIS_OID_GEN_MAXIMUM_FRAME_SIZE, 4, CONFIG_NET_ETH_PKTSIZE, NULL},
|
2017-11-13 09:55:41 +01:00
|
|
|
#ifdef CONFIG_USBDEV_DUALSPEED
|
2017-09-24 15:24:34 +02:00
|
|
|
{RNDIS_OID_GEN_LINK_SPEED, 4, 100000, NULL},
|
2017-11-13 09:55:41 +01:00
|
|
|
#else
|
|
|
|
{RNDIS_OID_GEN_LINK_SPEED, 4, 2000000, NULL},
|
|
|
|
#endif
|
2018-07-04 22:10:40 +02:00
|
|
|
{RNDIS_OID_GEN_TRANSMIT_BLOCK_SIZE, 4, CONFIG_NET_ETH_PKTSIZE, NULL},
|
|
|
|
{RNDIS_OID_GEN_RECEIVE_BLOCK_SIZE, 4, CONFIG_NET_ETH_PKTSIZE, NULL},
|
2019-12-24 17:37:30 +01:00
|
|
|
{RNDIS_OID_GEN_VENDOR_ID, 4, 0x00ffffff, NULL},
|
2017-09-24 15:24:34 +02:00
|
|
|
{RNDIS_OID_GEN_VENDOR_DESCRIPTION, 6, 0, "RNDIS"},
|
|
|
|
{RNDIS_OID_GEN_CURRENT_PACKET_FILTER, 4, 0, NULL},
|
|
|
|
{RNDIS_OID_GEN_MAXIMUM_TOTAL_SIZE, 4, 2048, NULL},
|
|
|
|
{RNDIS_OID_GEN_XMIT_OK, 4, 0, NULL},
|
|
|
|
{RNDIS_OID_GEN_RCV_OK, 4, 0, NULL},
|
|
|
|
{RNDIS_OID_802_3_PERMANENT_ADDRESS, 6, 0, NULL},
|
|
|
|
{RNDIS_OID_802_3_CURRENT_ADDRESS, 6, 0, NULL},
|
2019-12-24 17:37:30 +01:00
|
|
|
{RNDIS_OID_802_3_MULTICAST_LIST, 4, 0xe0000000, NULL},
|
2017-09-24 15:24:34 +02:00
|
|
|
{RNDIS_OID_802_3_MAXIMUM_LIST_SIZE, 4, 1, NULL},
|
|
|
|
{0x0, 4, 0, NULL}, /* Default fallback */
|
|
|
|
};
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Private Data
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Buffering of data is implemented in the following manner:
|
|
|
|
*
|
|
|
|
* RNDIS driver holds a number of preallocated bulk IN endpoint write
|
|
|
|
* requests along with buffers large enough to hold an Ethernet packet and
|
|
|
|
* the corresponding RNDIS header.
|
|
|
|
*
|
|
|
|
* One of these is always reserved for packet reception - when data arrives
|
|
|
|
* on the bulk OUT endpoint, it is copied to the reserved request buffer.
|
|
|
|
* When the reception of an Ethernet packet is complete, a worker to process
|
|
|
|
* the packet is scheduled and bulk OUT endpoint is set to NAK.
|
|
|
|
*
|
2020-08-06 19:41:45 +02:00
|
|
|
* The processing worker passes the buffer to the network. When the network
|
|
|
|
* is done processing the packet, the buffer might contain data to be sent.
|
2017-09-24 15:24:34 +02:00
|
|
|
* If so, the corresponding write request is queued on the bulk IN endpoint.
|
|
|
|
* The NAK state on bulk OUT endpoint is cleared to allow new packets to
|
|
|
|
* arrive. If there's no data to send, the request is returned to the list of
|
|
|
|
* free requests.
|
|
|
|
*
|
|
|
|
* When a bulk IN write operation is complete, the request is added to the
|
|
|
|
* list of free requests.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Name: rndis_submit_rdreq
|
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* Submits the bulk OUT read request. Takes care not to submit the request
|
|
|
|
* when the RX packet buffer is already in use.
|
|
|
|
*
|
|
|
|
* Input Parameters:
|
|
|
|
* priv: pointer to RNDIS device driver structure
|
|
|
|
*
|
|
|
|
* Returned Value:
|
|
|
|
* The return value of the EP_SUBMIT operation
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
static int rndis_submit_rdreq(FAR struct rndis_dev_s *priv)
|
|
|
|
{
|
|
|
|
irqstate_t flags = enter_critical_section();
|
|
|
|
int ret = OK;
|
|
|
|
|
|
|
|
if (!priv->rdreq_submitted && !priv->rx_blocked)
|
|
|
|
{
|
|
|
|
priv->rdreq->len = priv->epbulkout->maxpacket;
|
|
|
|
ret = EP_SUBMIT(priv->epbulkout, priv->rdreq);
|
|
|
|
if (ret != OK)
|
|
|
|
{
|
|
|
|
usbtrace(TRACE_CLSERROR(USBSER_TRACEERR_RDSUBMIT),
|
|
|
|
(uint16_t)-priv->rdreq->result);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
priv->rdreq_submitted = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
leave_critical_section(flags);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Name: rndis_cancel_rdreq
|
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* Cancels the bulk OUT endpoint read request.
|
|
|
|
*
|
|
|
|
* Input Parameters:
|
|
|
|
* priv: pointer to RNDIS device driver structure
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
2017-09-24 19:18:01 +02:00
|
|
|
|
2017-09-24 15:24:34 +02:00
|
|
|
static void rndis_cancel_rdreq(FAR struct rndis_dev_s *priv)
|
|
|
|
{
|
|
|
|
irqstate_t flags = enter_critical_section();
|
|
|
|
if (priv->rdreq_submitted)
|
|
|
|
{
|
|
|
|
EP_CANCEL(priv->epbulkout, priv->rdreq);
|
|
|
|
priv->rdreq_submitted = false;
|
|
|
|
}
|
2017-09-24 19:18:01 +02:00
|
|
|
|
2017-09-24 15:24:34 +02:00
|
|
|
leave_critical_section(flags);
|
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Name: rndis_block_rx
|
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* Blocks reception of further bulk OUT endpoint data.
|
|
|
|
*
|
|
|
|
* Input Parameters:
|
|
|
|
* priv: pointer to RNDIS device driver structure
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
static void rndis_block_rx(FAR struct rndis_dev_s *priv)
|
|
|
|
{
|
|
|
|
irqstate_t flags = enter_critical_section();
|
2017-09-24 19:18:01 +02:00
|
|
|
|
2017-09-24 15:24:34 +02:00
|
|
|
priv->rx_blocked = true;
|
|
|
|
rndis_cancel_rdreq(priv);
|
|
|
|
leave_critical_section(flags);
|
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Name: rndis_unblock_rx
|
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* Unblocks reception of bulk OUT endpoint data.
|
|
|
|
*
|
|
|
|
* Input Parameters:
|
|
|
|
* priv: pointer to RNDIS device driver structure
|
|
|
|
*
|
|
|
|
* Assumptions:
|
|
|
|
* Called from critical section
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
static void rndis_unblock_rx(FAR struct rndis_dev_s *priv)
|
|
|
|
{
|
|
|
|
priv->rx_blocked = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Name: rndis_allocwrreq
|
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* Allocates a bulk IN endpoint request from the list of free request
|
|
|
|
* buffers.
|
|
|
|
*
|
|
|
|
* Input Parameters:
|
|
|
|
* priv: pointer to RNDIS device driver structure
|
|
|
|
*
|
|
|
|
* Returned Value:
|
|
|
|
* NULL if allocation failed; pointer to allocated request if succeeded
|
|
|
|
*
|
|
|
|
* Assumptions:
|
|
|
|
* Called from critical section
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
static FAR struct rndis_req_s *rndis_allocwrreq(FAR struct rndis_dev_s *priv)
|
|
|
|
{
|
|
|
|
return (FAR struct rndis_req_s *)sq_remfirst(&priv->reqlist);
|
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Name: rndis_hasfreereqs
|
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* Checks if there are free requests usable for TX data.
|
|
|
|
*
|
|
|
|
* Input Parameters:
|
|
|
|
* priv: pointer to RNDIS device driver structure
|
|
|
|
*
|
|
|
|
* Returned Value:
|
|
|
|
* true if requests available; false if no requests available
|
|
|
|
*
|
|
|
|
* Assumptions:
|
|
|
|
* Called from critical section
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
static bool rndis_hasfreereqs(FAR struct rndis_dev_s *priv)
|
|
|
|
{
|
|
|
|
return sq_count(&priv->reqlist) > 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Name: rndis_freewrreq
|
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* Returns a bulk IN endpoint write requests to the list of free requests.
|
|
|
|
*
|
|
|
|
* Input Parameters:
|
|
|
|
* priv: pointer to RNDIS device driver structure
|
|
|
|
* req: pointer to the request
|
|
|
|
*
|
|
|
|
* Assumptions:
|
|
|
|
* Called with interrupts disabled.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
static void rndis_freewrreq(FAR struct rndis_dev_s *priv,
|
|
|
|
FAR struct rndis_req_s *req)
|
|
|
|
{
|
2017-09-24 19:18:01 +02:00
|
|
|
DEBUGASSERT(req != NULL);
|
2023-02-14 10:16:46 +01:00
|
|
|
if (req->iob)
|
|
|
|
{
|
|
|
|
/* In ep submit case, need release iob chain when write complete */
|
|
|
|
|
|
|
|
iob_free_chain(req->iob);
|
|
|
|
req->iob = NULL;
|
|
|
|
}
|
|
|
|
|
2017-09-24 15:24:34 +02:00
|
|
|
sq_addlast((FAR sq_entry_t *)req, &priv->reqlist);
|
|
|
|
rndis_submit_rdreq(priv);
|
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Name: rndis_allocnetreq
|
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* Allocates a request buffer to be used on the network.
|
|
|
|
*
|
|
|
|
* Input Parameters:
|
|
|
|
* priv: pointer to RNDIS device driver structure
|
|
|
|
*
|
|
|
|
* Returned Value:
|
|
|
|
* true if succeeded; false if failed
|
|
|
|
*
|
|
|
|
* Assumptions:
|
|
|
|
* Caller holds the network lock
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
static bool rndis_allocnetreq(FAR struct rndis_dev_s *priv)
|
|
|
|
{
|
|
|
|
irqstate_t flags = enter_critical_section();
|
2017-09-24 19:18:01 +02:00
|
|
|
DEBUGASSERT(priv->net_req == NULL);
|
2017-09-24 15:24:34 +02:00
|
|
|
|
|
|
|
if (!rndis_hasfreereqs(priv))
|
|
|
|
{
|
|
|
|
leave_critical_section(flags);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
priv->net_req = rndis_allocwrreq(priv);
|
|
|
|
|
|
|
|
leave_critical_section(flags);
|
|
|
|
return priv->net_req != NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Name: rndis_sendnetreq
|
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* Submits the request buffer held by the network.
|
|
|
|
*
|
|
|
|
* Input Parameters:
|
|
|
|
* priv: pointer to RNDIS device driver structure
|
|
|
|
*
|
|
|
|
* Assumptions:
|
|
|
|
* Caller holds the network lock
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
static void rndis_sendnetreq(FAR struct rndis_dev_s *priv)
|
|
|
|
{
|
|
|
|
irqstate_t flags = enter_critical_section();
|
2017-09-24 19:18:01 +02:00
|
|
|
|
|
|
|
DEBUGASSERT(priv->net_req != NULL);
|
|
|
|
|
2017-09-24 15:24:34 +02:00
|
|
|
priv->net_req->req->priv = priv->net_req;
|
|
|
|
EP_SUBMIT(priv->epbulkin, priv->net_req->req);
|
2017-09-24 19:18:01 +02:00
|
|
|
|
|
|
|
priv->net_req = NULL;
|
2017-09-24 15:24:34 +02:00
|
|
|
leave_critical_section(flags);
|
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Name: rndis_freenetreq
|
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* Frees the request buffer held by the network.
|
|
|
|
*
|
|
|
|
* Input Parameters:
|
|
|
|
* priv: pointer to RNDIS device driver structure
|
|
|
|
*
|
|
|
|
* Assumptions:
|
|
|
|
* Caller holds the network lock
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
static void rndis_freenetreq(FAR struct rndis_dev_s *priv)
|
|
|
|
{
|
|
|
|
irqstate_t flags = enter_critical_section();
|
2017-09-24 19:18:01 +02:00
|
|
|
|
2017-09-24 15:24:34 +02:00
|
|
|
rndis_freewrreq(priv, priv->net_req);
|
2023-02-14 10:16:46 +01:00
|
|
|
priv->net_req = NULL;
|
|
|
|
|
2017-09-24 15:24:34 +02:00
|
|
|
leave_critical_section(flags);
|
|
|
|
}
|
|
|
|
|
2023-02-14 10:16:46 +01:00
|
|
|
/****************************************************************************
|
|
|
|
* Name: rndis_iob2buf
|
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* Map the appropriate location of req iob to buf.
|
|
|
|
*
|
|
|
|
* Input Parameters:
|
|
|
|
* priv: pointer to RNDIS device driver structure
|
|
|
|
* req: the request whose buffer we should fill
|
|
|
|
* Assumptions:
|
|
|
|
* Caller holds the network lock
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
static void rndis_iob2buf(FAR struct rndis_dev_s *priv,
|
|
|
|
FAR struct rndis_req_s *req)
|
|
|
|
{
|
|
|
|
uint16_t llhdrlen = NET_LL_HDRLEN(&priv->netdev);
|
|
|
|
uint32_t offset = CONFIG_NET_LL_GUARDSIZE - llhdrlen -
|
|
|
|
RNDIS_PACKET_HDR_SIZE;
|
|
|
|
|
|
|
|
/* ----------------------------------------------------------------
|
|
|
|
* |<--- CONFIG_NET_LL_GUARDSIZE ---->|<-- io_len/io_pktlen(0) -->|
|
|
|
|
* ---------------------------------------------------------------|
|
|
|
|
* |unused | rndis hdr size |llhdrlen |<-- io_len/io_pktlen(0) -->|
|
|
|
|
* ---------------------------------------------------------------|
|
|
|
|
* |unused | req->buf(0) |
|
|
|
|
* ---------------------------------------------------------------|
|
|
|
|
*/
|
|
|
|
|
|
|
|
if (req->iob->io_flink == NULL)
|
|
|
|
{
|
|
|
|
req->req->buf = &req->iob->io_data[offset];
|
|
|
|
req->req->len = CONFIG_RNDIS_BULKIN_REQLEN;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
req->req->buf = req->buf;
|
|
|
|
iob_copyout(&req->req->buf[RNDIS_PACKET_HDR_SIZE], req->iob,
|
|
|
|
req->iob->io_pktlen + llhdrlen, -llhdrlen);
|
|
|
|
iob_free_chain(req->iob);
|
|
|
|
req->iob = NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-09-24 15:24:34 +02:00
|
|
|
/****************************************************************************
|
|
|
|
* Name: rndis_allocrxreq
|
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* Allocates a buffer for packet reception if there already isn't one.
|
|
|
|
*
|
|
|
|
* Input Parameters:
|
|
|
|
* priv: pointer to RNDIS device driver structure
|
|
|
|
*
|
|
|
|
* Returned Value:
|
|
|
|
* true if succeeded; false if failed
|
|
|
|
*
|
|
|
|
* Assumptions:
|
|
|
|
* Called from critical section
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
static bool rndis_allocrxreq(FAR struct rndis_dev_s *priv)
|
|
|
|
{
|
2023-02-14 10:16:46 +01:00
|
|
|
FAR struct iob_s *iob;
|
|
|
|
|
2017-09-24 15:24:34 +02:00
|
|
|
if (priv->rx_req != NULL)
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2023-02-14 10:16:46 +01:00
|
|
|
/* Prepare buffer to receivce data from usb driver */
|
|
|
|
|
|
|
|
iob = iob_tryalloc(false);
|
|
|
|
if (iob == NULL)
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
iob_reserve(iob, CONFIG_NET_LL_GUARDSIZE);
|
|
|
|
|
|
|
|
if ((priv->rx_req = rndis_allocwrreq(priv)) == NULL)
|
|
|
|
{
|
|
|
|
iob_free_chain(iob);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
priv->rx_req->iob = iob;
|
|
|
|
rndis_iob2buf(priv, priv->rx_req);
|
|
|
|
|
|
|
|
return true;
|
2017-09-24 15:24:34 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Name: rndis_giverxreq
|
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* Passes the RX packet buffer to the network
|
|
|
|
*
|
|
|
|
* Input Parameters:
|
|
|
|
* priv: pointer to RNDIS device driver structure
|
|
|
|
*
|
|
|
|
* Assumptions:
|
|
|
|
* Caller holds the network lock
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
static void rndis_giverxreq(FAR struct rndis_dev_s *priv)
|
|
|
|
{
|
2017-09-24 19:18:01 +02:00
|
|
|
DEBUGASSERT(priv->rx_req != NULL);
|
|
|
|
DEBUGASSERT(priv->net_req == NULL);
|
|
|
|
|
2023-02-14 10:16:46 +01:00
|
|
|
priv->net_req = priv->rx_req;
|
|
|
|
priv->rx_req = NULL;
|
|
|
|
|
|
|
|
/* Move iob from net_req to netdev */
|
|
|
|
|
|
|
|
netdev_iob_release(&priv->netdev);
|
|
|
|
|
|
|
|
priv->netdev.d_iob = priv->net_req->iob;
|
|
|
|
priv->netdev.d_len = priv->net_req->iob->io_pktlen;
|
|
|
|
priv->net_req->iob = NULL;
|
2017-09-24 15:24:34 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Name: rndis_fillrequest
|
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* Fills the RNDIS header to the request buffer
|
|
|
|
*
|
|
|
|
* Input Parameters:
|
|
|
|
* priv: pointer to RNDIS device driver structure
|
|
|
|
* req: the request whose buffer we should fill
|
|
|
|
*
|
2018-02-01 17:00:02 +01:00
|
|
|
* Returned Value:
|
2017-09-24 15:24:34 +02:00
|
|
|
* The total length of the request data
|
|
|
|
*
|
|
|
|
* Assumptions:
|
|
|
|
* Caller holds the network lock
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
static uint16_t rndis_fillrequest(FAR struct rndis_dev_s *priv,
|
2023-02-14 10:16:46 +01:00
|
|
|
FAR struct rndis_req_s *req)
|
2017-09-24 15:24:34 +02:00
|
|
|
{
|
2017-09-24 19:18:01 +02:00
|
|
|
size_t datalen;
|
|
|
|
|
2023-02-14 10:16:46 +01:00
|
|
|
req->req->len = 0;
|
2017-09-24 15:24:34 +02:00
|
|
|
|
2023-02-03 14:42:03 +01:00
|
|
|
datalen = MIN(priv->netdev.d_len,
|
2017-09-24 19:18:01 +02:00
|
|
|
CONFIG_RNDIS_BULKIN_REQLEN - RNDIS_PACKET_HDR_SIZE);
|
2017-09-24 15:24:34 +02:00
|
|
|
if (datalen > 0)
|
|
|
|
{
|
2023-02-14 10:16:46 +01:00
|
|
|
/* Move iob from netdev to net_req and send the required headers */
|
2017-09-24 15:24:34 +02:00
|
|
|
|
2023-02-14 10:16:46 +01:00
|
|
|
req->iob = priv->netdev.d_iob;
|
|
|
|
netdev_iob_clear(&priv->netdev);
|
|
|
|
rndis_iob2buf(priv, req);
|
2020-08-06 19:41:45 +02:00
|
|
|
FAR struct rndis_packet_msg *msg =
|
2023-02-14 10:16:46 +01:00
|
|
|
(FAR struct rndis_packet_msg *)req->req->buf;
|
2017-09-24 15:24:34 +02:00
|
|
|
memset(msg, 0, RNDIS_PACKET_HDR_SIZE);
|
|
|
|
|
2017-09-24 19:18:01 +02:00
|
|
|
msg->msgtype = RNDIS_PACKET_MSG;
|
|
|
|
msg->msglen = RNDIS_PACKET_HDR_SIZE + datalen;
|
|
|
|
msg->dataoffset = RNDIS_PACKET_HDR_SIZE - 8;
|
|
|
|
msg->datalen = datalen;
|
2017-09-24 15:24:34 +02:00
|
|
|
|
2023-02-14 10:16:46 +01:00
|
|
|
req->req->flags = USBDEV_REQFLAGS_NULLPKT;
|
|
|
|
req->req->len = datalen + RNDIS_PACKET_HDR_SIZE;
|
2017-09-24 15:24:34 +02:00
|
|
|
}
|
|
|
|
|
2023-02-14 10:16:46 +01:00
|
|
|
return req->req->len;
|
2017-09-24 15:24:34 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Name: rndis_rxdispatch
|
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* Processes the received Ethernet packet. Called from work queue.
|
|
|
|
*
|
|
|
|
* Input Parameters:
|
|
|
|
* arg: pointer to RNDIS device driver structure
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
static void rndis_rxdispatch(FAR void *arg)
|
|
|
|
{
|
|
|
|
FAR struct rndis_dev_s *priv = (FAR struct rndis_dev_s *)arg;
|
2017-09-24 19:18:01 +02:00
|
|
|
FAR struct eth_hdr_s *hdr;
|
|
|
|
irqstate_t flags;
|
2017-09-24 15:24:34 +02:00
|
|
|
|
|
|
|
net_lock();
|
2017-09-24 19:18:01 +02:00
|
|
|
flags = enter_critical_section();
|
2017-09-24 15:24:34 +02:00
|
|
|
rndis_giverxreq(priv);
|
|
|
|
priv->netdev.d_len = priv->current_rx_datagram_size;
|
|
|
|
leave_critical_section(flags);
|
|
|
|
|
2023-02-14 10:16:46 +01:00
|
|
|
hdr = (FAR struct eth_hdr_s *)
|
|
|
|
&priv->netdev.d_iob->io_data[CONFIG_NET_LL_GUARDSIZE -
|
|
|
|
NET_LL_HDRLEN(&priv->netdev)];
|
2017-09-24 15:24:34 +02:00
|
|
|
|
|
|
|
/* We only accept IP packets of the configured type and ARP packets */
|
|
|
|
|
|
|
|
#ifdef CONFIG_NET_IPv4
|
|
|
|
if (hdr->type == HTONS(ETHTYPE_IP))
|
|
|
|
{
|
|
|
|
NETDEV_RXIPV4(&priv->netdev);
|
|
|
|
|
2022-11-26 19:13:21 +01:00
|
|
|
/* Receive an IPv4 packet from the network device */
|
2017-09-24 15:24:34 +02:00
|
|
|
|
|
|
|
ipv4_input(&priv->netdev);
|
2017-11-13 09:55:41 +01:00
|
|
|
|
|
|
|
if (priv->netdev.d_len > 0)
|
|
|
|
{
|
|
|
|
/* And send the packet */
|
|
|
|
|
|
|
|
rndis_transmit(priv);
|
|
|
|
}
|
2017-09-24 15:24:34 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
#endif
|
|
|
|
#ifdef CONFIG_NET_IPv6
|
|
|
|
if (hdr->type == HTONS(ETHTYPE_IP6))
|
|
|
|
{
|
|
|
|
NETDEV_RXIPV6(&priv->netdev);
|
|
|
|
|
|
|
|
/* Give the IPv6 packet to the network layer */
|
|
|
|
|
|
|
|
ipv6_input(&priv->netdev);
|
2017-11-13 09:55:41 +01:00
|
|
|
|
|
|
|
if (priv->netdev.d_len > 0)
|
|
|
|
{
|
|
|
|
/* And send the packet */
|
|
|
|
|
|
|
|
rndis_transmit(priv);
|
|
|
|
}
|
2017-09-24 15:24:34 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
#endif
|
|
|
|
#ifdef CONFIG_NET_ARP
|
2022-01-18 08:38:00 +01:00
|
|
|
if (hdr->type == HTONS(ETHTYPE_ARP))
|
2017-09-24 15:24:34 +02:00
|
|
|
{
|
|
|
|
NETDEV_RXARP(&priv->netdev);
|
|
|
|
|
2022-12-04 08:01:53 +01:00
|
|
|
arp_input(&priv->netdev);
|
2017-11-13 09:55:41 +01:00
|
|
|
|
|
|
|
if (priv->netdev.d_len > 0)
|
|
|
|
{
|
|
|
|
rndis_transmit(priv);
|
|
|
|
}
|
2019-12-24 17:37:30 +01:00
|
|
|
}
|
2017-09-24 15:24:34 +02:00
|
|
|
else
|
|
|
|
#endif
|
|
|
|
{
|
2020-08-06 19:41:45 +02:00
|
|
|
uerr("ERROR: Unsupported packet type dropped (%02x)\n",
|
2022-01-18 08:38:00 +01:00
|
|
|
HTONS(hdr->type));
|
2017-09-24 15:24:34 +02:00
|
|
|
NETDEV_RXDROPPED(&priv->netdev);
|
|
|
|
priv->netdev.d_len = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
priv->current_rx_datagram_size = 0;
|
|
|
|
rndis_unblock_rx(priv);
|
2017-09-24 19:18:01 +02:00
|
|
|
|
|
|
|
if (priv->net_req != NULL)
|
|
|
|
{
|
|
|
|
rndis_freenetreq(priv);
|
|
|
|
}
|
2017-09-24 15:24:34 +02:00
|
|
|
|
|
|
|
net_unlock();
|
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Name: rndis_txpoll
|
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* Sends the packet that is stored in the network packet buffer. Called
|
|
|
|
* from work queue by e.g. txavail and txpoll callbacks.
|
|
|
|
*
|
|
|
|
* Input Parameters:
|
|
|
|
* dev: pointer to network driver structure
|
|
|
|
*
|
|
|
|
* Assumptions:
|
|
|
|
* Caller holds the network lock
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
static int rndis_txpoll(FAR struct net_driver_s *dev)
|
|
|
|
{
|
|
|
|
FAR struct rndis_dev_s *priv = (FAR struct rndis_dev_s *)dev->d_private;
|
|
|
|
|
2017-09-24 19:18:01 +02:00
|
|
|
if (!priv->connected)
|
|
|
|
{
|
|
|
|
return -EBUSY;
|
|
|
|
}
|
2017-09-24 15:24:34 +02:00
|
|
|
|
2022-11-26 20:31:07 +01:00
|
|
|
return rndis_transmit(priv);
|
2017-11-13 09:55:41 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Name: rndis_transmit
|
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* Start hardware transmission.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
static int rndis_transmit(FAR struct rndis_dev_s *priv)
|
|
|
|
{
|
|
|
|
int ret = OK;
|
|
|
|
|
|
|
|
/* Queue the packet */
|
|
|
|
|
2023-02-14 10:16:46 +01:00
|
|
|
rndis_fillrequest(priv, priv->net_req);
|
2017-11-13 09:55:41 +01:00
|
|
|
rndis_sendnetreq(priv);
|
|
|
|
|
|
|
|
if (!rndis_allocnetreq(priv))
|
|
|
|
{
|
|
|
|
ret = -EBUSY;
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
2017-09-24 15:24:34 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Name: rndis_ifup
|
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* Network ifup callback
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
static int rndis_ifup(FAR struct net_driver_s *dev)
|
|
|
|
{
|
|
|
|
return OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Name: rndis_ifdown
|
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* Network ifdown callback
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
static int rndis_ifdown(FAR struct net_driver_s *dev)
|
|
|
|
{
|
|
|
|
return OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Name: rndis_txavail_work
|
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* txavail worker function
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
static void rndis_txavail_work(FAR void *arg)
|
|
|
|
{
|
|
|
|
FAR struct rndis_dev_s *priv = (FAR struct rndis_dev_s *)arg;
|
|
|
|
|
|
|
|
net_lock();
|
|
|
|
|
|
|
|
if (rndis_allocnetreq(priv))
|
|
|
|
{
|
2022-05-29 15:47:28 +02:00
|
|
|
devif_poll(&priv->netdev, rndis_txpoll);
|
2017-09-24 19:18:01 +02:00
|
|
|
if (priv->net_req != NULL)
|
|
|
|
{
|
|
|
|
rndis_freenetreq(priv);
|
|
|
|
}
|
2017-09-24 15:24:34 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
net_unlock();
|
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Name: rndis_txavail
|
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* Network txavail callback that's called when there are buffers available
|
|
|
|
* for sending data. May be called from an interrupt, so we must queue a
|
|
|
|
* worker to do the actual processing.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
static int rndis_txavail(FAR struct net_driver_s *dev)
|
|
|
|
{
|
|
|
|
FAR struct rndis_dev_s *priv = (FAR struct rndis_dev_s *)dev->d_private;
|
|
|
|
|
|
|
|
if (work_available(&priv->pollwork))
|
|
|
|
{
|
2017-10-09 17:00:48 +02:00
|
|
|
work_queue(ETHWORK, &priv->pollwork, rndis_txavail_work, priv, 0);
|
2017-09-24 15:24:34 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return OK;
|
|
|
|
}
|
|
|
|
|
2020-08-06 19:41:45 +02:00
|
|
|
/****************************************************************************
|
2017-09-24 15:24:34 +02:00
|
|
|
* Name: rndis_recvpacket
|
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* Handles a USB packet arriving on the data bulk out endpoint.
|
|
|
|
*
|
|
|
|
* Assumptions:
|
|
|
|
* Called from the USB interrupt handler with interrupts disabled.
|
|
|
|
*
|
2020-08-06 19:41:45 +02:00
|
|
|
****************************************************************************/
|
2017-09-24 15:24:34 +02:00
|
|
|
|
|
|
|
static inline int rndis_recvpacket(FAR struct rndis_dev_s *priv,
|
|
|
|
FAR uint8_t *reqbuf, uint16_t reqlen)
|
|
|
|
{
|
|
|
|
if (!rndis_allocrxreq(priv))
|
|
|
|
{
|
|
|
|
return -ENOMEM;
|
|
|
|
}
|
|
|
|
|
2017-09-24 19:18:01 +02:00
|
|
|
if (!priv->connected)
|
2017-09-24 15:24:34 +02:00
|
|
|
{
|
|
|
|
return -EBUSY;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!priv->current_rx_datagram_size)
|
|
|
|
{
|
|
|
|
if (reqlen < 16)
|
|
|
|
{
|
|
|
|
/* Packet too small to contain a message header */
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* The packet contains a RNDIS packet message header */
|
|
|
|
|
2020-08-06 19:41:45 +02:00
|
|
|
FAR struct rndis_packet_msg *msg =
|
|
|
|
(FAR struct rndis_packet_msg *)reqbuf;
|
2017-09-24 19:18:01 +02:00
|
|
|
if (msg->msgtype == RNDIS_PACKET_MSG)
|
2017-09-24 15:24:34 +02:00
|
|
|
{
|
|
|
|
priv->current_rx_received = reqlen;
|
2017-09-24 19:18:01 +02:00
|
|
|
priv->current_rx_datagram_size = msg->datalen;
|
2017-11-08 14:33:09 +01:00
|
|
|
priv->current_rx_msglen = msg->msglen;
|
|
|
|
|
|
|
|
/* According to RNDIS-over-USB send, if the message length is a
|
|
|
|
* multiple of endpoint max packet size, the host must send an
|
2020-08-06 19:41:45 +02:00
|
|
|
* additional single-byte zero packet. Take that in account
|
|
|
|
* here.
|
2017-11-08 14:33:09 +01:00
|
|
|
*/
|
|
|
|
|
2020-08-06 19:41:45 +02:00
|
|
|
if (!(priv->current_rx_msglen % priv->epbulkout->maxpacket))
|
2017-11-08 14:33:09 +01:00
|
|
|
{
|
|
|
|
priv->current_rx_msglen += 1;
|
|
|
|
}
|
2017-09-24 15:24:34 +02:00
|
|
|
|
2020-08-06 19:41:45 +02:00
|
|
|
/* Data offset is defined as an offset from the beginning of
|
|
|
|
* the offset field itself
|
2017-09-24 15:24:34 +02:00
|
|
|
*/
|
|
|
|
|
2017-09-24 19:18:01 +02:00
|
|
|
priv->current_rx_datagram_offset = msg->dataoffset + 8;
|
2017-09-24 15:24:34 +02:00
|
|
|
if (priv->current_rx_datagram_offset < reqlen)
|
|
|
|
{
|
2023-02-14 10:16:46 +01:00
|
|
|
iob_trycopyin(priv->rx_req->iob,
|
|
|
|
&reqbuf[priv->current_rx_datagram_offset],
|
|
|
|
reqlen - priv->current_rx_datagram_offset,
|
|
|
|
-NET_LL_HDRLEN(&priv->netdev), false);
|
2017-09-24 15:24:34 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2020-11-27 10:00:19 +01:00
|
|
|
uerr("Unknown RNDIS message type %" PRIu32 "\n", msg->msgtype);
|
2017-09-24 15:24:34 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2017-11-08 14:33:09 +01:00
|
|
|
else
|
2017-09-24 15:24:34 +02:00
|
|
|
{
|
2017-11-08 14:33:09 +01:00
|
|
|
if (priv->current_rx_received >= priv->current_rx_datagram_offset &&
|
2017-11-13 09:55:41 +01:00
|
|
|
priv->current_rx_received <= priv->current_rx_datagram_size +
|
|
|
|
priv->current_rx_datagram_offset)
|
2017-11-08 14:33:09 +01:00
|
|
|
{
|
2020-08-06 19:41:45 +02:00
|
|
|
size_t index = priv->current_rx_received -
|
|
|
|
priv->current_rx_datagram_offset;
|
2023-02-03 14:42:03 +01:00
|
|
|
size_t copysize = MIN(reqlen,
|
2020-08-06 19:41:45 +02:00
|
|
|
priv->current_rx_datagram_size - index);
|
2017-11-08 14:33:09 +01:00
|
|
|
|
2017-11-13 09:55:41 +01:00
|
|
|
/* Check if the received packet exceeds request buffer */
|
2017-09-24 15:24:34 +02:00
|
|
|
|
2018-09-20 14:50:58 +02:00
|
|
|
if ((index + copysize) <= CONFIG_NET_ETH_PKTSIZE)
|
2017-09-24 15:24:34 +02:00
|
|
|
{
|
2023-02-14 10:16:46 +01:00
|
|
|
iob_trycopyin(priv->rx_req->iob, reqbuf, copysize,
|
|
|
|
priv->rx_req->iob->io_pktlen, false);
|
2017-09-24 15:24:34 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2021-12-26 23:18:22 +01:00
|
|
|
uerr("The packet exceeds request buffer (reqlen=%d)\n",
|
2020-08-06 19:41:45 +02:00
|
|
|
reqlen);
|
2017-11-13 09:55:41 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
priv->current_rx_received += reqlen;
|
|
|
|
}
|
2017-09-24 15:24:34 +02:00
|
|
|
|
2017-11-13 09:55:41 +01:00
|
|
|
if (priv->current_rx_received >= priv->current_rx_msglen)
|
|
|
|
{
|
|
|
|
/* Check for a usable packet length (4 added for the CRC) */
|
2017-09-24 19:18:01 +02:00
|
|
|
|
2018-07-04 22:10:40 +02:00
|
|
|
if (priv->current_rx_datagram_size > (CONFIG_NET_ETH_PKTSIZE + 4) ||
|
2017-11-13 09:55:41 +01:00
|
|
|
priv->current_rx_datagram_size <= (ETH_HDRLEN + 4))
|
|
|
|
{
|
2023-02-27 07:52:21 +01:00
|
|
|
uerr("ERROR: Bad packet size dropped (%zu)\n",
|
2017-11-13 09:55:41 +01:00
|
|
|
priv->current_rx_datagram_size);
|
|
|
|
NETDEV_RXERRORS(&priv->netdev);
|
|
|
|
priv->current_rx_datagram_size = 0;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
DEBUGASSERT(work_available(&priv->rxwork));
|
|
|
|
ret = work_queue(ETHWORK, &priv->rxwork, rndis_rxdispatch,
|
|
|
|
priv, 0);
|
|
|
|
DEBUGASSERT(ret == 0);
|
|
|
|
UNUSED(ret);
|
|
|
|
|
|
|
|
rndis_block_rx(priv);
|
|
|
|
priv->rndis_host_tx_count++;
|
|
|
|
return -EBUSY;
|
2017-09-24 15:24:34 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Name: rndis_prepare_response
|
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* Passes the RX packet buffer to the network
|
|
|
|
*
|
|
|
|
* Input Parameters:
|
|
|
|
* priv: pointer to RNDIS device driver structure
|
|
|
|
*
|
2021-03-24 08:11:26 +01:00
|
|
|
* Returns:
|
|
|
|
* pointer to response buffer
|
|
|
|
*
|
2017-09-24 15:24:34 +02:00
|
|
|
* Assumptions:
|
|
|
|
* Called from critical section
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
2021-03-24 10:07:42 +01:00
|
|
|
static FAR void *
|
2020-08-06 19:41:45 +02:00
|
|
|
rndis_prepare_response(FAR struct rndis_dev_s *priv, size_t size,
|
|
|
|
FAR struct rndis_command_header *request_hdr)
|
2017-09-24 15:24:34 +02:00
|
|
|
{
|
2021-03-26 09:41:27 +01:00
|
|
|
size_t size_words = size / sizeof(uint32_t);
|
|
|
|
uint32_t *buf = priv->response_queue + priv->response_queue_words;
|
2017-09-24 15:24:34 +02:00
|
|
|
FAR struct rndis_response_header *hdr =
|
2021-03-24 08:11:26 +01:00
|
|
|
(FAR struct rndis_response_header *)buf;
|
2017-09-24 15:24:34 +02:00
|
|
|
|
2021-03-26 09:41:27 +01:00
|
|
|
if (priv->response_queue_words + size_words > RNDIS_RESP_QUEUE_WORDS)
|
2021-03-24 08:20:48 +01:00
|
|
|
{
|
2021-03-24 10:07:42 +01:00
|
|
|
uerr("RNDIS response queue full, dropping command %08x",
|
|
|
|
(unsigned int)request_hdr->msgtype);
|
2021-03-24 08:20:48 +01:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2017-09-24 19:18:01 +02:00
|
|
|
hdr->msgtype = request_hdr->msgtype | RNDIS_MSG_COMPLETE;
|
|
|
|
hdr->msglen = size;
|
|
|
|
hdr->reqid = request_hdr->reqid;
|
|
|
|
hdr->status = RNDIS_STATUS_SUCCESS;
|
2017-09-24 15:24:34 +02:00
|
|
|
|
2021-03-24 08:11:26 +01:00
|
|
|
return hdr;
|
2017-09-24 15:24:34 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Name: rndis_send_encapsulated_response
|
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* Give a notification to the host that there is an encapsulated response
|
|
|
|
* available.
|
|
|
|
*
|
|
|
|
* Input Parameters:
|
|
|
|
* priv: pointer to RNDIS device driver structure
|
|
|
|
*
|
|
|
|
* Assumptions:
|
|
|
|
* Called from critical section
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
2021-03-24 10:07:42 +01:00
|
|
|
static int rndis_send_encapsulated_response(FAR struct rndis_dev_s *priv,
|
|
|
|
size_t size)
|
2017-09-24 15:24:34 +02:00
|
|
|
{
|
2021-03-26 09:41:27 +01:00
|
|
|
size_t size_words = size / sizeof(uint32_t);
|
2017-09-24 15:24:34 +02:00
|
|
|
FAR struct rndis_notification *notif =
|
|
|
|
(FAR struct rndis_notification *)priv->epintin_req->buf;
|
|
|
|
|
2021-03-26 09:41:27 +01:00
|
|
|
/* RNDIS packets should always be multiple of 4 bytes in size */
|
|
|
|
|
|
|
|
DEBUGASSERT(size_words * sizeof(uint32_t) == size);
|
|
|
|
|
2021-03-24 08:11:26 +01:00
|
|
|
/* Mark the response as available in the queue */
|
2021-03-24 10:07:42 +01:00
|
|
|
|
2021-03-26 09:41:27 +01:00
|
|
|
priv->response_queue_words += size_words;
|
|
|
|
DEBUGASSERT(priv->response_queue_words <= RNDIS_RESP_QUEUE_WORDS);
|
2021-03-24 08:11:26 +01:00
|
|
|
|
|
|
|
/* Send notification on IRQ endpoint, to tell host to read the data. */
|
2021-03-24 10:07:42 +01:00
|
|
|
|
2017-09-24 19:18:01 +02:00
|
|
|
notif->notification = RNDIS_NOTIFICATION_RESPONSE_AVAILABLE;
|
|
|
|
notif->reserved = 0;
|
2017-09-24 15:24:34 +02:00
|
|
|
priv->epintin_req->len = sizeof(struct rndis_notification);
|
|
|
|
|
|
|
|
EP_CANCEL(priv->epintin, priv->epintin_req);
|
|
|
|
EP_SUBMIT(priv->epintin, priv->epintin_req);
|
|
|
|
|
|
|
|
return OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Name: rndis_handle_control_message
|
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* Handle a RNDIS control message.
|
|
|
|
*
|
|
|
|
* Input Parameters:
|
|
|
|
* priv: pointer to RNDIS device driver structure
|
|
|
|
*
|
|
|
|
* Assumptions:
|
|
|
|
* Called from critical section
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
static int rndis_handle_control_message(FAR struct rndis_dev_s *priv,
|
2020-08-06 19:41:45 +02:00
|
|
|
FAR uint8_t *dataout,
|
|
|
|
uint16_t outlen)
|
2017-09-24 15:24:34 +02:00
|
|
|
{
|
|
|
|
FAR struct rndis_command_header *cmd_hdr =
|
|
|
|
(FAR struct rndis_command_header *)dataout;
|
|
|
|
|
2017-09-24 19:18:01 +02:00
|
|
|
switch (cmd_hdr->msgtype)
|
2017-09-24 15:24:34 +02:00
|
|
|
{
|
|
|
|
case RNDIS_INITIALIZE_MSG:
|
|
|
|
{
|
|
|
|
FAR struct rndis_initialize_cmplt *resp;
|
2021-03-24 10:07:42 +01:00
|
|
|
size_t respsize = sizeof(struct rndis_initialize_cmplt);
|
2017-09-24 15:24:34 +02:00
|
|
|
|
2021-03-24 10:07:42 +01:00
|
|
|
resp = rndis_prepare_response(priv, respsize, cmd_hdr);
|
2021-03-24 08:20:48 +01:00
|
|
|
if (!resp)
|
|
|
|
{
|
|
|
|
return -ENOMEM;
|
|
|
|
}
|
2017-09-24 15:24:34 +02:00
|
|
|
|
2017-09-24 19:18:01 +02:00
|
|
|
resp->major = RNDIS_MAJOR_VERSION;
|
|
|
|
resp->minor = RNDIS_MINOR_VERSION;
|
|
|
|
resp->devflags = RNDIS_DEVICEFLAGS;
|
|
|
|
resp->medium = RNDIS_MEDIUM_802_3;
|
|
|
|
resp->pktperxfer = 1;
|
2017-11-13 09:55:41 +01:00
|
|
|
resp->xfrsize = (4 + 44 + 22) + RNDIS_BUFFER_SIZE;
|
2017-09-24 19:18:01 +02:00
|
|
|
resp->pktalign = 2;
|
2017-09-24 15:24:34 +02:00
|
|
|
|
2021-03-24 10:07:42 +01:00
|
|
|
rndis_send_encapsulated_response(priv, respsize);
|
2017-09-24 15:24:34 +02:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case RNDIS_HALT_MSG:
|
|
|
|
{
|
2021-03-26 09:41:27 +01:00
|
|
|
priv->response_queue_words = 0;
|
2017-09-24 19:18:01 +02:00
|
|
|
priv->connected = false;
|
2017-09-24 15:24:34 +02:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case RNDIS_QUERY_MSG:
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
size_t max_reply_size = sizeof(struct rndis_query_cmplt) +
|
|
|
|
sizeof(g_rndis_supported_oids);
|
2021-03-24 08:11:26 +01:00
|
|
|
FAR struct rndis_query_cmplt *resp;
|
2017-09-24 15:24:34 +02:00
|
|
|
FAR struct rndis_query_msg *req =
|
|
|
|
(FAR struct rndis_query_msg *)dataout;
|
2021-03-24 08:11:26 +01:00
|
|
|
|
|
|
|
resp = rndis_prepare_response(priv, max_reply_size, cmd_hdr);
|
2021-03-24 08:20:48 +01:00
|
|
|
if (!resp)
|
|
|
|
{
|
|
|
|
return -ENOMEM;
|
|
|
|
}
|
2017-09-24 15:24:34 +02:00
|
|
|
|
2017-09-24 19:18:01 +02:00
|
|
|
resp->hdr.msglen = sizeof(struct rndis_query_cmplt);
|
|
|
|
resp->bufoffset = 0;
|
|
|
|
resp->buflen = 0;
|
|
|
|
resp->hdr.status = RNDIS_STATUS_NOT_SUPPORTED;
|
2017-09-24 15:24:34 +02:00
|
|
|
|
|
|
|
for (i = 0;
|
2020-08-06 19:41:45 +02:00
|
|
|
i < sizeof(g_rndis_oid_values) /
|
|
|
|
sizeof(g_rndis_oid_values[0]);
|
2017-09-24 15:24:34 +02:00
|
|
|
i++)
|
|
|
|
{
|
2017-09-24 19:18:01 +02:00
|
|
|
bool match = (g_rndis_oid_values[i].objid == req->objid);
|
2017-09-24 15:24:34 +02:00
|
|
|
|
2017-09-24 19:18:01 +02:00
|
|
|
if (!match && g_rndis_oid_values[i].objid == 0)
|
2017-09-24 15:24:34 +02:00
|
|
|
{
|
|
|
|
int j;
|
|
|
|
|
|
|
|
/* Check whether to apply the fallback entry */
|
|
|
|
|
2019-12-24 17:37:30 +01:00
|
|
|
for (j = 0;
|
|
|
|
j < sizeof(g_rndis_supported_oids) / sizeof(uint32_t);
|
|
|
|
j++)
|
2017-09-24 15:24:34 +02:00
|
|
|
{
|
2017-09-24 19:18:01 +02:00
|
|
|
if (g_rndis_supported_oids[j] == req->objid)
|
2017-09-24 15:24:34 +02:00
|
|
|
{
|
|
|
|
match = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (match)
|
|
|
|
{
|
2017-09-24 19:18:01 +02:00
|
|
|
resp->hdr.status = RNDIS_STATUS_SUCCESS;
|
|
|
|
resp->bufoffset = 16;
|
|
|
|
resp->buflen = g_rndis_oid_values[i].length;
|
2017-09-24 15:24:34 +02:00
|
|
|
|
2017-09-24 19:18:01 +02:00
|
|
|
if (req->objid == RNDIS_OID_GEN_CURRENT_PACKET_FILTER)
|
2017-09-24 15:24:34 +02:00
|
|
|
{
|
2017-09-24 19:18:01 +02:00
|
|
|
resp->buffer[0] = priv->rndis_packet_filter;
|
2017-09-24 15:24:34 +02:00
|
|
|
}
|
2017-09-24 19:18:01 +02:00
|
|
|
else if (req->objid == RNDIS_OID_GEN_XMIT_OK)
|
2017-09-24 15:24:34 +02:00
|
|
|
{
|
2017-09-24 19:18:01 +02:00
|
|
|
resp->buffer[0] = priv->rndis_host_tx_count;
|
2017-09-24 15:24:34 +02:00
|
|
|
}
|
2017-09-24 19:18:01 +02:00
|
|
|
else if (req->objid == RNDIS_OID_GEN_RCV_OK)
|
2017-09-24 15:24:34 +02:00
|
|
|
{
|
2017-09-24 19:18:01 +02:00
|
|
|
resp->buffer[0] = priv->rndis_host_rx_count;
|
2017-09-24 15:24:34 +02:00
|
|
|
}
|
2017-09-24 19:18:01 +02:00
|
|
|
else if (req->objid == RNDIS_OID_802_3_CURRENT_ADDRESS ||
|
|
|
|
req->objid == RNDIS_OID_802_3_PERMANENT_ADDRESS)
|
2017-09-24 15:24:34 +02:00
|
|
|
{
|
2017-09-24 19:18:01 +02:00
|
|
|
memcpy(resp->buffer, priv->host_mac_address, 6);
|
2017-09-24 15:24:34 +02:00
|
|
|
}
|
2017-09-24 19:18:01 +02:00
|
|
|
else if (g_rndis_oid_values[i].data)
|
2017-09-24 15:24:34 +02:00
|
|
|
{
|
2017-09-24 19:18:01 +02:00
|
|
|
memcpy(resp->buffer, g_rndis_oid_values[i].data,
|
|
|
|
resp->buflen);
|
2017-09-24 15:24:34 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2017-09-24 19:18:01 +02:00
|
|
|
memcpy(resp->buffer, &g_rndis_oid_values[i].value,
|
|
|
|
resp->buflen);
|
2017-09-24 15:24:34 +02:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
uinfo("RNDIS Query RID=%08x OID=%08x LEN=%d DAT=%08x",
|
2017-09-24 19:18:01 +02:00
|
|
|
(unsigned)req->hdr.reqid, (unsigned)req->objid,
|
|
|
|
(int)resp->buflen, (unsigned)resp->buffer[0]);
|
2017-09-24 15:24:34 +02:00
|
|
|
|
2017-09-24 19:18:01 +02:00
|
|
|
resp->hdr.msglen += resp->buflen;
|
2017-09-24 15:24:34 +02:00
|
|
|
|
2021-03-26 09:41:27 +01:00
|
|
|
/* Align to word boundary */
|
|
|
|
|
|
|
|
if ((resp->hdr.msglen & 3) != 0)
|
|
|
|
{
|
|
|
|
resp->hdr.msglen += 4 - (resp->hdr.msglen & 3);
|
|
|
|
}
|
|
|
|
|
2021-03-24 08:11:26 +01:00
|
|
|
rndis_send_encapsulated_response(priv, resp->hdr.msglen);
|
2017-09-24 15:24:34 +02:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case RNDIS_SET_MSG:
|
|
|
|
{
|
|
|
|
FAR struct rndis_set_msg *req;
|
|
|
|
FAR struct rndis_response_header *resp;
|
2021-03-24 10:07:42 +01:00
|
|
|
size_t respsize = sizeof(struct rndis_response_header);
|
2017-09-24 15:24:34 +02:00
|
|
|
|
2021-03-24 10:07:42 +01:00
|
|
|
resp = rndis_prepare_response(priv, respsize, cmd_hdr);
|
2017-09-24 15:24:34 +02:00
|
|
|
req = (FAR struct rndis_set_msg *)dataout;
|
|
|
|
|
2021-03-24 08:20:48 +01:00
|
|
|
if (!resp)
|
|
|
|
{
|
|
|
|
return -ENOMEM;
|
|
|
|
}
|
|
|
|
|
2017-09-24 15:24:34 +02:00
|
|
|
uinfo("RNDIS SET RID=%08x OID=%08x LEN=%d DAT=%08x",
|
2017-09-24 19:18:01 +02:00
|
|
|
(unsigned)req->hdr.reqid, (unsigned)req->objid,
|
|
|
|
(int)req->buflen, (unsigned)req->buffer[0]);
|
2017-09-24 15:24:34 +02:00
|
|
|
|
2017-09-24 19:18:01 +02:00
|
|
|
if (req->objid == RNDIS_OID_GEN_CURRENT_PACKET_FILTER)
|
2017-09-24 15:24:34 +02:00
|
|
|
{
|
2017-09-24 19:18:01 +02:00
|
|
|
priv->rndis_packet_filter = req->buffer[0];
|
2017-09-24 15:24:34 +02:00
|
|
|
|
2017-09-24 19:18:01 +02:00
|
|
|
if (req->buffer[0] == 0)
|
2017-09-24 15:24:34 +02:00
|
|
|
{
|
2017-09-24 19:18:01 +02:00
|
|
|
priv->connected = false;
|
2017-09-24 15:24:34 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
uinfo("RNDIS is now connected");
|
2017-09-24 19:18:01 +02:00
|
|
|
priv->connected = true;
|
2017-09-24 15:24:34 +02:00
|
|
|
}
|
|
|
|
}
|
2017-09-24 19:18:01 +02:00
|
|
|
else if (req->objid == RNDIS_OID_802_3_MULTICAST_LIST)
|
2017-09-24 15:24:34 +02:00
|
|
|
{
|
|
|
|
uinfo("RNDIS multicast list ignored");
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2017-09-24 19:18:01 +02:00
|
|
|
uinfo("RNDIS unsupported set %08x", (unsigned)req->objid);
|
|
|
|
resp->status = RNDIS_STATUS_NOT_SUPPORTED;
|
2017-09-24 15:24:34 +02:00
|
|
|
}
|
|
|
|
|
2021-03-24 10:07:42 +01:00
|
|
|
rndis_send_encapsulated_response(priv, respsize);
|
2017-09-24 15:24:34 +02:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case RNDIS_RESET_MSG:
|
|
|
|
{
|
|
|
|
FAR struct rndis_reset_cmplt *resp;
|
2021-03-24 10:07:42 +01:00
|
|
|
size_t respsize = sizeof(struct rndis_reset_cmplt);
|
2017-09-24 15:24:34 +02:00
|
|
|
|
2021-03-26 09:41:27 +01:00
|
|
|
priv->response_queue_words = 0;
|
2021-03-24 10:07:42 +01:00
|
|
|
resp = rndis_prepare_response(priv, respsize, cmd_hdr);
|
2021-03-24 08:20:48 +01:00
|
|
|
|
|
|
|
if (!resp)
|
|
|
|
{
|
|
|
|
return -ENOMEM;
|
|
|
|
}
|
|
|
|
|
2017-09-24 19:18:01 +02:00
|
|
|
resp->addreset = 0;
|
|
|
|
priv->connected = false;
|
2021-03-24 10:07:42 +01:00
|
|
|
rndis_send_encapsulated_response(priv, respsize);
|
2017-09-24 15:24:34 +02:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case RNDIS_KEEPALIVE_MSG:
|
|
|
|
{
|
2021-03-24 08:20:48 +01:00
|
|
|
FAR struct rndis_response_header *resp;
|
2021-03-24 10:07:42 +01:00
|
|
|
size_t respsize = sizeof(struct rndis_response_header);
|
|
|
|
resp = rndis_prepare_response(priv, respsize, cmd_hdr);
|
2021-03-24 08:20:48 +01:00
|
|
|
if (!resp)
|
|
|
|
{
|
|
|
|
return -ENOMEM;
|
|
|
|
}
|
|
|
|
|
2021-03-24 10:07:42 +01:00
|
|
|
rndis_send_encapsulated_response(priv, respsize);
|
2017-09-24 15:24:34 +02:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
2020-11-27 10:00:19 +01:00
|
|
|
uwarn("Unsupported RNDIS control message: %" PRIu32 "\n",
|
|
|
|
cmd_hdr->msgtype);
|
2017-09-24 15:24:34 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Name: rndis_rdcomplete
|
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* Handle completion of read request on the bulk OUT endpoint.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
static void rndis_rdcomplete(FAR struct usbdev_ep_s *ep,
|
|
|
|
FAR struct usbdev_req_s *req)
|
|
|
|
{
|
|
|
|
FAR struct rndis_dev_s *priv;
|
|
|
|
irqstate_t flags;
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
/* Sanity check */
|
|
|
|
|
|
|
|
#ifdef CONFIG_DEBUG_FEATURES
|
|
|
|
if (!ep || !ep->priv || !req)
|
|
|
|
{
|
|
|
|
usbtrace(TRACE_CLSERROR(USBSER_TRACEERR_INVALIDARG), 0);
|
|
|
|
return;
|
2019-12-24 17:37:30 +01:00
|
|
|
}
|
2017-09-24 15:24:34 +02:00
|
|
|
#endif
|
|
|
|
|
|
|
|
/* Extract references to private data */
|
|
|
|
|
|
|
|
priv = (FAR struct rndis_dev_s *)ep->priv;
|
|
|
|
|
|
|
|
/* Process the received data unless this is some unusual condition */
|
|
|
|
|
|
|
|
ret = OK;
|
|
|
|
|
|
|
|
flags = enter_critical_section();
|
|
|
|
priv->rdreq_submitted = false;
|
|
|
|
|
|
|
|
switch (req->result)
|
|
|
|
{
|
|
|
|
case 0: /* Normal completion */
|
|
|
|
ret = rndis_recvpacket(priv, req->buf, req->xfrd);
|
2017-09-24 19:18:01 +02:00
|
|
|
DEBUGASSERT(ret != -ENOMEM);
|
2017-09-24 15:24:34 +02:00
|
|
|
break;
|
|
|
|
|
|
|
|
case -ESHUTDOWN: /* Disconnection */
|
|
|
|
usbtrace(TRACE_CLSERROR(USBSER_TRACEERR_RDSHUTDOWN), 0);
|
|
|
|
leave_critical_section(flags);
|
|
|
|
return;
|
|
|
|
|
|
|
|
default: /* Some other error occurred */
|
2020-08-06 19:41:45 +02:00
|
|
|
usbtrace(TRACE_CLSERROR(USBSER_TRACEERR_RDUNEXPECTED),
|
|
|
|
(uint16_t)-req->result);
|
2017-09-24 15:24:34 +02:00
|
|
|
break;
|
|
|
|
};
|
|
|
|
|
|
|
|
if (ret == OK)
|
|
|
|
{
|
|
|
|
rndis_submit_rdreq(priv);
|
|
|
|
}
|
|
|
|
|
|
|
|
leave_critical_section(flags);
|
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Name: rndis_wrcomplete
|
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* Handle completion of write request. This function probably executes
|
|
|
|
* in the context of an interrupt handler.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
static void rndis_wrcomplete(FAR struct usbdev_ep_s *ep,
|
|
|
|
FAR struct usbdev_req_s *req)
|
|
|
|
{
|
|
|
|
FAR struct rndis_dev_s *priv;
|
|
|
|
FAR struct rndis_req_s *reqcontainer;
|
|
|
|
irqstate_t flags;
|
|
|
|
|
|
|
|
/* Sanity check */
|
|
|
|
|
|
|
|
#ifdef CONFIG_DEBUG_FEATURES
|
|
|
|
if (!ep || !ep->priv || !req || !req->priv)
|
|
|
|
{
|
|
|
|
usbtrace(TRACE_CLSERROR(USBSER_TRACEERR_INVALIDARG), 0);
|
|
|
|
return;
|
2019-12-24 17:37:30 +01:00
|
|
|
}
|
2017-09-24 15:24:34 +02:00
|
|
|
#endif
|
|
|
|
|
|
|
|
/* Extract references to our private data */
|
|
|
|
|
|
|
|
priv = (FAR struct rndis_dev_s *)ep->priv;
|
|
|
|
reqcontainer = (FAR struct rndis_req_s *)req->priv;
|
|
|
|
|
|
|
|
/* Return the write request to the free list */
|
|
|
|
|
|
|
|
flags = enter_critical_section();
|
|
|
|
rndis_freewrreq(priv, reqcontainer);
|
|
|
|
if (rndis_hasfreereqs(priv))
|
|
|
|
{
|
|
|
|
rndis_txavail(&priv->netdev);
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (req->result)
|
|
|
|
{
|
|
|
|
case OK: /* Normal completion */
|
|
|
|
priv->rndis_host_rx_count++;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case -ESHUTDOWN: /* Disconnection */
|
|
|
|
break;
|
|
|
|
|
|
|
|
default: /* Some other error occurred */
|
|
|
|
usbtrace(TRACE_CLSERROR(USBSER_TRACEERR_WRUNEXPECTED),
|
|
|
|
(uint16_t)-req->result);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
leave_critical_section(flags);
|
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Name: usbclass_ep0incomplete
|
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* Handle completion of EP0 control operations
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
static void usbclass_ep0incomplete(FAR struct usbdev_ep_s *ep,
|
|
|
|
FAR struct usbdev_req_s *req)
|
|
|
|
{
|
2023-03-23 12:55:29 +01:00
|
|
|
FAR struct rndis_dev_s *priv;
|
|
|
|
|
2017-09-24 15:24:34 +02:00
|
|
|
if (req->result || req->xfrd != req->len)
|
|
|
|
{
|
|
|
|
usbtrace(TRACE_CLSERROR(USBSER_TRACEERR_REQRESULT),
|
|
|
|
(uint16_t)-req->result);
|
|
|
|
}
|
2023-03-23 12:55:29 +01:00
|
|
|
else if (req->len > 0 && req->priv)
|
2017-09-24 15:24:34 +02:00
|
|
|
{
|
2023-03-23 12:55:29 +01:00
|
|
|
/* Get EP0 request private data */
|
|
|
|
|
|
|
|
priv = (FAR struct rndis_dev_s *)req->priv;
|
|
|
|
|
2021-03-24 10:07:42 +01:00
|
|
|
/* This transfer was from the response queue,
|
|
|
|
* subtract remaining byte count.
|
|
|
|
*/
|
|
|
|
|
2021-03-26 09:41:27 +01:00
|
|
|
size_t len_words = req->len / sizeof(uint32_t);
|
|
|
|
DEBUGASSERT(len_words * sizeof(uint32_t) == req->len);
|
2021-03-24 08:11:26 +01:00
|
|
|
req->priv = 0;
|
2021-03-26 09:41:27 +01:00
|
|
|
if (len_words >= priv->response_queue_words)
|
2021-03-24 08:11:26 +01:00
|
|
|
{
|
|
|
|
/* Queue now empty */
|
2021-03-24 10:07:42 +01:00
|
|
|
|
2021-03-26 09:41:27 +01:00
|
|
|
priv->response_queue_words = 0;
|
2021-03-24 08:11:26 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* Copy the remaining responses to beginning of buffer. */
|
2021-03-24 10:07:42 +01:00
|
|
|
|
2021-03-26 09:41:27 +01:00
|
|
|
priv->response_queue_words -= len_words;
|
|
|
|
memcpy(priv->response_queue, priv->response_queue + len_words,
|
|
|
|
priv->response_queue_words * sizeof(uint32_t));
|
2021-03-24 08:11:26 +01:00
|
|
|
}
|
2017-09-24 15:24:34 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************************************************
|
2023-03-23 12:55:29 +01:00
|
|
|
* Name: usbclass_epintin_complete
|
2017-09-24 15:24:34 +02:00
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* Handle completion of interrupt IN endpoint operations
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
static void usbclass_epintin_complete(FAR struct usbdev_ep_s *ep,
|
|
|
|
FAR struct usbdev_req_s *req)
|
|
|
|
{
|
|
|
|
if (req->result || req->xfrd != req->len)
|
|
|
|
{
|
|
|
|
usbtrace(TRACE_CLSERROR(USBSER_TRACEERR_REQRESULT),
|
|
|
|
(uint16_t)-req->result);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Name: usbclass_mkstrdesc
|
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* Construct a string descriptor
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
2018-11-09 13:56:58 +01:00
|
|
|
static int usbclass_mkstrdesc(uint8_t id, FAR struct usb_strdesc_s *strdesc)
|
2017-09-24 15:24:34 +02:00
|
|
|
{
|
2022-03-05 18:59:15 +01:00
|
|
|
FAR uint8_t *data = (FAR uint8_t *)(strdesc + 1);
|
2017-09-24 15:24:34 +02:00
|
|
|
FAR const char *str;
|
|
|
|
int len;
|
|
|
|
int ndata;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
switch (id)
|
|
|
|
{
|
2018-11-09 13:56:58 +01:00
|
|
|
#ifndef CONFIG_RNDIS_COMPOSITE
|
2017-09-24 15:24:34 +02:00
|
|
|
case 0:
|
|
|
|
{
|
|
|
|
/* Descriptor 0 is the language id */
|
|
|
|
|
2022-03-05 18:59:15 +01:00
|
|
|
strdesc->len = 4;
|
|
|
|
strdesc->type = USB_DESC_TYPE_STRING;
|
|
|
|
data[0] = LSBYTE(RNDIS_STR_LANGUAGE);
|
|
|
|
data[1] = MSBYTE(RNDIS_STR_LANGUAGE);
|
2017-09-24 15:24:34 +02:00
|
|
|
return 4;
|
|
|
|
}
|
|
|
|
|
|
|
|
case RNDIS_MANUFACTURERSTRID:
|
|
|
|
str = CONFIG_RNDIS_VENDORSTR;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case RNDIS_PRODUCTSTRID:
|
|
|
|
str = CONFIG_RNDIS_PRODUCTSTR;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case RNDIS_SERIALSTRID:
|
2022-01-18 02:36:37 +01:00
|
|
|
#ifdef CONFIG_RNDIS_BOARD_SERIALSTR
|
|
|
|
str = board_usbdev_serialstr();
|
|
|
|
#else
|
2017-09-24 15:24:34 +02:00
|
|
|
str = CONFIG_RNDIS_SERIALSTR;
|
2022-01-18 02:36:37 +01:00
|
|
|
#endif
|
2017-09-24 15:24:34 +02:00
|
|
|
break;
|
2018-11-09 13:56:58 +01:00
|
|
|
#endif
|
2017-09-24 15:24:34 +02:00
|
|
|
|
|
|
|
default:
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
2019-12-24 17:37:30 +01: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 > (RNDIS_MAXSTRLEN / 2))
|
|
|
|
{
|
|
|
|
len = (RNDIS_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;
|
2019-12-24 17:37:30 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
strdesc->len = ndata + 2;
|
|
|
|
strdesc->type = USB_DESC_TYPE_STRING;
|
|
|
|
return strdesc->len;
|
2017-09-24 15:24:34 +02:00
|
|
|
}
|
|
|
|
|
2019-07-24 00:12:50 +02:00
|
|
|
/****************************************************************************
|
|
|
|
* Name: usbclass_copy_epdesc
|
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* Copies the requested Endpoint Description into the buffer given.
|
|
|
|
* Returns the number of Bytes filled in ( sizeof(struct usb_epdesc_s) ).
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
static int usbclass_copy_epdesc(int epid, FAR struct usb_epdesc_s *epdesc,
|
|
|
|
FAR struct usbdev_devinfo_s *devinfo,
|
|
|
|
bool hispeed)
|
|
|
|
{
|
|
|
|
#ifndef CONFIG_USBDEV_DUALSPEED
|
|
|
|
UNUSED(hispeed);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
switch (epid)
|
|
|
|
{
|
|
|
|
case RNDIS_EP_INTIN_IDX: /* Interrupt IN endpoint */
|
|
|
|
{
|
|
|
|
epdesc->len = USB_SIZEOF_EPDESC; /* Descriptor length */
|
|
|
|
epdesc->type = USB_DESC_TYPE_ENDPOINT; /* Descriptor type */
|
|
|
|
epdesc->addr = RNDIS_MKEPINTIN(devinfo); /* Endpoint address */
|
|
|
|
epdesc->attr = RNDIS_EPINTIN_ATTR; /* Endpoint attributes */
|
|
|
|
|
|
|
|
#ifdef CONFIG_USBDEV_DUALSPEED
|
|
|
|
if (hispeed)
|
|
|
|
{
|
|
|
|
/* Maximum packet size (high speed) */
|
|
|
|
|
|
|
|
epdesc->mxpacketsize[0] = LSBYTE(CONFIG_RNDIS_EPINTIN_HSSIZE);
|
|
|
|
epdesc->mxpacketsize[1] = MSBYTE(CONFIG_RNDIS_EPINTIN_HSSIZE);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
#endif
|
|
|
|
{
|
|
|
|
/* Maximum packet size (full speed) */
|
|
|
|
|
|
|
|
epdesc->mxpacketsize[0] = LSBYTE(CONFIG_RNDIS_EPINTIN_FSSIZE);
|
|
|
|
epdesc->mxpacketsize[1] = MSBYTE(CONFIG_RNDIS_EPINTIN_FSSIZE);
|
|
|
|
}
|
|
|
|
|
|
|
|
epdesc->interval = 10; /* Interval */
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case RNDIS_EP_BULKOUT_IDX: /* Bulk OUT endpoint */
|
|
|
|
{
|
|
|
|
epdesc->len = USB_SIZEOF_EPDESC; /* Descriptor length */
|
|
|
|
epdesc->type = USB_DESC_TYPE_ENDPOINT; /* Descriptor type */
|
|
|
|
epdesc->addr = RNDIS_MKEPBULKOUT(devinfo); /* Endpoint address */
|
|
|
|
epdesc->attr = RNDIS_EPOUTBULK_ATTR; /* Endpoint attributes */
|
|
|
|
|
|
|
|
#ifdef CONFIG_USBDEV_DUALSPEED
|
|
|
|
if (hispeed)
|
|
|
|
{
|
|
|
|
/* Maximum packet size (high speed) */
|
|
|
|
|
|
|
|
epdesc->mxpacketsize[0] = LSBYTE(CONFIG_RNDIS_EPBULKOUT_HSSIZE);
|
|
|
|
epdesc->mxpacketsize[1] = MSBYTE(CONFIG_RNDIS_EPBULKOUT_HSSIZE);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
#endif
|
|
|
|
{
|
|
|
|
/* Maximum packet size (full speed) */
|
|
|
|
|
|
|
|
epdesc->mxpacketsize[0] = LSBYTE(CONFIG_RNDIS_EPBULKOUT_FSSIZE);
|
|
|
|
epdesc->mxpacketsize[1] = MSBYTE(CONFIG_RNDIS_EPBULKOUT_FSSIZE);
|
|
|
|
}
|
|
|
|
|
|
|
|
epdesc->interval = 0; /* Interval */
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case RNDIS_EP_BULKIN_IDX: /* Bulk IN endpoint */
|
|
|
|
{
|
|
|
|
epdesc->len = USB_SIZEOF_EPDESC; /* Descriptor length */
|
|
|
|
epdesc->type = USB_DESC_TYPE_ENDPOINT; /* Descriptor type */
|
|
|
|
epdesc->addr = RNDIS_MKEPBULKIN(devinfo); /* Endpoint address */
|
|
|
|
epdesc->attr = RNDIS_EPINBULK_ATTR; /* Endpoint attributes */
|
|
|
|
|
|
|
|
#ifdef CONFIG_USBDEV_DUALSPEED
|
|
|
|
if (hispeed)
|
|
|
|
{
|
|
|
|
/* Maximum packet size (high speed) */
|
|
|
|
|
|
|
|
epdesc->mxpacketsize[0] = LSBYTE(CONFIG_RNDIS_EPBULKIN_HSSIZE);
|
|
|
|
epdesc->mxpacketsize[1] = MSBYTE(CONFIG_RNDIS_EPBULKIN_HSSIZE);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
#endif
|
|
|
|
{
|
|
|
|
/* Maximum packet size (full speed) */
|
|
|
|
|
2019-07-24 01:59:53 +02:00
|
|
|
epdesc->mxpacketsize[0] = LSBYTE(CONFIG_RNDIS_EPBULKIN_FSSIZE);
|
|
|
|
epdesc->mxpacketsize[1] = MSBYTE(CONFIG_RNDIS_EPBULKIN_FSSIZE);
|
2019-07-24 00:12:50 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
epdesc->interval = 0; /* Interval */
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
return sizeof(struct usb_epdesc_s);
|
|
|
|
}
|
|
|
|
|
2017-09-24 15:24:34 +02:00
|
|
|
/****************************************************************************
|
|
|
|
* Name: usbclass_mkcfgdesc
|
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* Construct the configuration descriptor
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
2023-02-01 14:11:54 +01:00
|
|
|
#ifdef CONFIG_USBDEV_DUALSPEED
|
|
|
|
static int16_t usbclass_mkcfgdesc(FAR uint8_t *buf,
|
|
|
|
FAR struct usbdev_devinfo_s *devinfo,
|
|
|
|
uint8_t speed, uint8_t type)
|
|
|
|
#else
|
2018-11-09 13:56:58 +01:00
|
|
|
static int16_t usbclass_mkcfgdesc(FAR uint8_t *buf,
|
|
|
|
FAR struct usbdev_devinfo_s *devinfo)
|
2023-02-01 14:11:54 +01:00
|
|
|
#endif
|
2017-09-24 15:24:34 +02:00
|
|
|
{
|
2018-11-09 14:44:22 +01:00
|
|
|
FAR struct rndis_cfgdesc_s *dest = (FAR struct rndis_cfgdesc_s *)buf;
|
2023-02-01 14:11:54 +01:00
|
|
|
bool hispeed = false;
|
2017-09-24 15:24:34 +02:00
|
|
|
uint16_t totallen;
|
|
|
|
|
2023-02-01 14:11:54 +01:00
|
|
|
#ifdef CONFIG_USBDEV_DUALSPEED
|
|
|
|
hispeed = (speed == USB_SPEED_HIGH);
|
|
|
|
|
|
|
|
/* Check for switches between high and full speed */
|
|
|
|
|
|
|
|
if (type == USB_DESC_TYPE_OTHERSPEEDCONFIG)
|
|
|
|
{
|
|
|
|
hispeed = !hispeed;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2017-09-24 15:24:34 +02:00
|
|
|
/* This is the total length of the configuration (not necessarily the
|
|
|
|
* size that we will be sending now).
|
|
|
|
*/
|
|
|
|
|
|
|
|
totallen = sizeof(g_rndis_cfgdesc);
|
|
|
|
|
2023-03-21 10:16:59 +01:00
|
|
|
if (dest != NULL)
|
|
|
|
{
|
|
|
|
memcpy(dest, &g_rndis_cfgdesc, totallen);
|
|
|
|
|
|
|
|
usbclass_copy_epdesc(RNDIS_EP_INTIN_IDX, &dest->epintindesc,
|
|
|
|
devinfo, hispeed);
|
|
|
|
usbclass_copy_epdesc(RNDIS_EP_BULKIN_IDX, &dest->epbulkindesc,
|
|
|
|
devinfo, hispeed);
|
|
|
|
usbclass_copy_epdesc(RNDIS_EP_BULKOUT_IDX, &dest->epbulkoutdesc,
|
|
|
|
devinfo, hispeed);
|
2023-02-01 14:11:54 +01:00
|
|
|
|
2018-11-09 13:56:58 +01:00
|
|
|
#ifndef CONFIG_RNDIS_COMPOSITE
|
2023-03-21 10:16:59 +01:00
|
|
|
/* For a stand-alone device, just fill in the total length */
|
2018-11-09 14:44:22 +01:00
|
|
|
|
2023-03-21 10:16:59 +01:00
|
|
|
dest->cfgdesc.totallen[0] = LSBYTE(totallen);
|
|
|
|
dest->cfgdesc.totallen[1] = MSBYTE(totallen);
|
2018-11-09 13:56:58 +01:00
|
|
|
#else
|
2023-03-21 21:18:35 +01:00
|
|
|
/* For composite device, apply possible offset to the interface
|
|
|
|
* numbers
|
|
|
|
*/
|
2018-11-09 14:44:22 +01:00
|
|
|
|
2023-03-21 21:18:35 +01:00
|
|
|
# ifdef CONFIG_COMPOSITE_IAD
|
2023-03-21 10:16:59 +01:00
|
|
|
dest->assoc_desc.firstif += devinfo->ifnobase;
|
2023-03-21 21:18:35 +01:00
|
|
|
# endif
|
2023-03-21 10:16:59 +01:00
|
|
|
dest->comm_ifdesc.ifno += devinfo->ifnobase;
|
|
|
|
dest->data_ifdesc.ifno += devinfo->ifnobase;
|
2018-11-09 13:56:58 +01:00
|
|
|
#endif
|
2023-03-21 10:16:59 +01:00
|
|
|
}
|
2017-09-24 15:24:34 +02:00
|
|
|
|
|
|
|
return totallen;
|
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Name: usbclass_bind
|
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* Invoked when the driver is bound to a USB device driver
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
static int usbclass_bind(FAR struct usbdevclass_driver_s *driver,
|
|
|
|
FAR struct usbdev_s *dev)
|
|
|
|
{
|
|
|
|
FAR struct rndis_dev_s *priv = ((FAR struct rndis_driver_s *)driver)->dev;
|
|
|
|
FAR struct rndis_req_s *reqcontainer;
|
|
|
|
irqstate_t flags;
|
|
|
|
uint16_t reqlen;
|
|
|
|
int ret;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
usbtrace(TRACE_CLASSBIND, 0);
|
|
|
|
|
|
|
|
/* Bind the structures */
|
|
|
|
|
|
|
|
priv->usbdev = dev;
|
|
|
|
|
|
|
|
/* Save the reference to our private data structure in EP0 so that it
|
|
|
|
* can be recovered in ep0 completion events (Unless we are part of
|
|
|
|
* a composite device and, in that case, the composite device owns
|
|
|
|
* EP0).
|
|
|
|
*/
|
|
|
|
|
2023-03-23 12:55:29 +01:00
|
|
|
#ifndef CONFIG_RNDIS_COMPOSITE
|
2017-09-24 15:24:34 +02:00
|
|
|
dev->ep0->priv = priv;
|
2023-03-23 12:55:29 +01:00
|
|
|
#endif
|
2017-09-24 15:24:34 +02:00
|
|
|
|
|
|
|
/* Preallocate control request */
|
|
|
|
|
2023-07-06 07:57:42 +02:00
|
|
|
priv->ctrlreq = usbdev_allocreq(dev->ep0, RNDIS_CTRLREQ_LEN);
|
2017-09-24 15:24:34 +02:00
|
|
|
if (priv->ctrlreq == NULL)
|
|
|
|
{
|
|
|
|
usbtrace(TRACE_CLSERROR(USBSER_TRACEERR_ALLOCCTRLREQ), 0);
|
|
|
|
ret = -ENOMEM;
|
|
|
|
goto errout;
|
|
|
|
}
|
|
|
|
|
|
|
|
priv->ctrlreq->callback = usbclass_ep0incomplete;
|
|
|
|
|
|
|
|
/* Pre-allocate all endpoints... the endpoints will not be functional
|
|
|
|
* until the SET CONFIGURATION request is processed in usbclass_setconfig.
|
|
|
|
* 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
|
2017-09-24 15:24:34 +02:00
|
|
|
* logic where kmm_malloc calls will fail.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/* Pre-allocate the IN interrupt endpoint */
|
|
|
|
|
2020-08-06 19:41:45 +02:00
|
|
|
priv->epintin = DEV_ALLOCEP(dev,
|
|
|
|
USB_EPIN(priv->devinfo.epno[RNDIS_EP_INTIN_IDX]),
|
|
|
|
true, USB_EP_ATTR_XFER_INT);
|
2017-09-24 15:24:34 +02:00
|
|
|
if (!priv->epintin)
|
|
|
|
{
|
|
|
|
usbtrace(TRACE_CLSERROR(USBSER_TRACEERR_EPINTINALLOCFAIL), 0);
|
|
|
|
ret = -ENODEV;
|
|
|
|
goto errout;
|
|
|
|
}
|
|
|
|
|
|
|
|
priv->epintin->priv = priv;
|
|
|
|
|
2019-12-24 17:37:30 +01:00
|
|
|
priv->epintin_req =
|
2023-07-06 07:57:42 +02:00
|
|
|
usbdev_allocreq(priv->epintin, sizeof(struct rndis_notification));
|
2017-09-24 15:24:34 +02:00
|
|
|
if (priv->epintin_req == NULL)
|
|
|
|
{
|
|
|
|
usbtrace(TRACE_CLSERROR(USBSER_TRACEERR_RDALLOCREQ), -ENOMEM);
|
|
|
|
ret = -ENOMEM;
|
|
|
|
goto errout;
|
|
|
|
}
|
|
|
|
|
|
|
|
priv->epintin_req->callback = usbclass_epintin_complete;
|
|
|
|
|
|
|
|
/* Pre-allocate the IN bulk endpoint */
|
|
|
|
|
2020-08-06 19:41:45 +02:00
|
|
|
priv->epbulkin = DEV_ALLOCEP(dev,
|
|
|
|
USB_EPIN(priv->devinfo.epno[RNDIS_EP_BULKIN_IDX]),
|
|
|
|
true, USB_EP_ATTR_XFER_BULK);
|
2017-09-24 15:24:34 +02:00
|
|
|
if (!priv->epbulkin)
|
|
|
|
{
|
|
|
|
usbtrace(TRACE_CLSERROR(USBSER_TRACEERR_EPBULKINALLOCFAIL), 0);
|
|
|
|
ret = -ENODEV;
|
|
|
|
goto errout;
|
|
|
|
}
|
|
|
|
|
|
|
|
priv->epbulkin->priv = priv;
|
|
|
|
|
|
|
|
/* Pre-allocate the OUT bulk endpoint */
|
|
|
|
|
2019-12-24 17:37:30 +01:00
|
|
|
priv->epbulkout =
|
|
|
|
DEV_ALLOCEP(dev, USB_EPOUT(priv->devinfo.epno[RNDIS_EP_BULKOUT_IDX]),
|
|
|
|
false, USB_EP_ATTR_XFER_BULK);
|
2017-09-24 15:24:34 +02:00
|
|
|
if (!priv->epbulkout)
|
|
|
|
{
|
|
|
|
usbtrace(TRACE_CLSERROR(USBSER_TRACEERR_EPBULKOUTALLOCFAIL), 0);
|
|
|
|
ret = -ENODEV;
|
|
|
|
goto errout;
|
|
|
|
}
|
|
|
|
|
|
|
|
priv->epbulkout->priv = priv;
|
|
|
|
|
|
|
|
/* Pre-allocate read requests. The buffer size is one full packet. */
|
|
|
|
|
|
|
|
reqlen = 64;
|
|
|
|
|
2017-11-13 09:55:41 +01:00
|
|
|
if (CONFIG_RNDIS_BULKOUT_REQLEN > reqlen)
|
|
|
|
{
|
|
|
|
reqlen = CONFIG_RNDIS_BULKOUT_REQLEN;
|
|
|
|
}
|
|
|
|
|
2023-07-06 07:57:42 +02:00
|
|
|
priv->rdreq = usbdev_allocreq(priv->epbulkout, reqlen);
|
2017-09-24 15:24:34 +02:00
|
|
|
if (priv->rdreq == NULL)
|
2019-12-24 17:37:30 +01:00
|
|
|
{
|
|
|
|
usbtrace(TRACE_CLSERROR(USBSER_TRACEERR_RDALLOCREQ), -ENOMEM);
|
|
|
|
ret = -ENOMEM;
|
|
|
|
goto errout;
|
|
|
|
}
|
2017-09-24 15:24:34 +02:00
|
|
|
|
|
|
|
priv->rdreq->callback = rndis_rdcomplete;
|
|
|
|
|
|
|
|
/* Pre-allocate write request containers and put in a free list.
|
|
|
|
* The buffer size should be larger than a full packet. Otherwise,
|
|
|
|
* we will send a bogus null packet at the end of each packet.
|
|
|
|
*
|
|
|
|
* Pick the larger of the max packet size and the configured request
|
|
|
|
* size.
|
|
|
|
*/
|
|
|
|
|
2023-02-14 10:16:46 +01:00
|
|
|
if (CONFIG_IOB_BUFSIZE >= CONFIG_RNDIS_BULKIN_REQLEN)
|
|
|
|
{
|
|
|
|
reqlen = 0;
|
|
|
|
}
|
|
|
|
else
|
2017-09-24 15:24:34 +02:00
|
|
|
{
|
|
|
|
reqlen = CONFIG_RNDIS_BULKIN_REQLEN;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (i = 0; i < CONFIG_RNDIS_NWRREQS; i++)
|
|
|
|
{
|
|
|
|
reqcontainer = &priv->wrreqs[i];
|
2023-07-06 07:57:42 +02:00
|
|
|
reqcontainer->req = usbdev_allocreq(priv->epbulkin, reqlen);
|
2017-09-24 15:24:34 +02:00
|
|
|
|
|
|
|
if (reqcontainer->req == NULL)
|
|
|
|
{
|
|
|
|
usbtrace(TRACE_CLSERROR(USBSER_TRACEERR_WRALLOCREQ), -ENOMEM);
|
|
|
|
ret = -ENOMEM;
|
|
|
|
goto errout;
|
|
|
|
}
|
|
|
|
|
2023-02-14 10:16:46 +01:00
|
|
|
reqcontainer->buf = reqcontainer->req->buf;
|
2017-09-24 15:24:34 +02:00
|
|
|
reqcontainer->req->priv = reqcontainer;
|
|
|
|
reqcontainer->req->callback = rndis_wrcomplete;
|
|
|
|
|
|
|
|
flags = enter_critical_section();
|
|
|
|
sq_addlast((FAR sq_entry_t *)reqcontainer, &priv->reqlist);
|
|
|
|
leave_critical_section(flags);
|
|
|
|
}
|
|
|
|
|
2021-03-24 08:11:26 +01:00
|
|
|
/* Initialize response queue to empty */
|
2021-03-24 10:07:42 +01:00
|
|
|
|
2021-03-26 09:41:27 +01:00
|
|
|
priv->response_queue_words = 0;
|
2021-03-24 08:11:26 +01:00
|
|
|
|
2017-09-24 15:24:34 +02:00
|
|
|
/* Report if we are selfpowered */
|
2018-11-09 14:44:22 +01:00
|
|
|
|
2018-11-09 13:56:58 +01:00
|
|
|
#ifndef CONFIG_RNDIS_COMPOSITE
|
2017-09-24 15:24:34 +02:00
|
|
|
#ifdef CONFIG_USBDEV_SELFPOWERED
|
|
|
|
DEV_SETSELFPOWERED(dev);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/* And pull-up the data line for the soft connect function */
|
|
|
|
|
|
|
|
DEV_CONNECT(dev);
|
2018-11-09 13:56:58 +01:00
|
|
|
#endif
|
2017-09-24 15:24:34 +02:00
|
|
|
|
|
|
|
return OK;
|
|
|
|
|
|
|
|
errout:
|
|
|
|
usbclass_unbind(driver, dev);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Name: usbclass_unbind
|
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* Invoked when the driver is unbound from a USB device driver
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
static void usbclass_unbind(FAR struct usbdevclass_driver_s *driver,
|
|
|
|
FAR struct usbdev_s *dev)
|
|
|
|
{
|
|
|
|
FAR struct rndis_dev_s *priv;
|
|
|
|
FAR struct rndis_req_s *reqcontainer;
|
|
|
|
irqstate_t flags;
|
|
|
|
|
|
|
|
usbtrace(TRACE_CLASSUNBIND, 0);
|
|
|
|
|
|
|
|
#ifdef CONFIG_DEBUG_FEATURES
|
|
|
|
if (!driver || !dev || !dev->ep0)
|
|
|
|
{
|
|
|
|
usbtrace(TRACE_CLSERROR(USBSER_TRACEERR_INVALIDARG), 0);
|
|
|
|
return;
|
2019-12-24 17:37:30 +01:00
|
|
|
}
|
2017-09-24 15:24:34 +02:00
|
|
|
#endif
|
|
|
|
|
|
|
|
/* Extract reference to private data */
|
|
|
|
|
|
|
|
priv = ((FAR struct rndis_driver_s *)driver)->dev;
|
|
|
|
|
|
|
|
#ifdef CONFIG_DEBUG_FEATURES
|
|
|
|
if (!priv)
|
|
|
|
{
|
|
|
|
usbtrace(TRACE_CLSERROR(USBSER_TRACEERR_EP0NOTBOUND), 0);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/* 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
|
|
|
|
* already have been reset. If not, then calling usbclass_resetconfig
|
|
|
|
* should cause the endpoints to immediately terminate all
|
|
|
|
* transfers and return the requests to us (with result == -ESHUTDOWN)
|
|
|
|
*/
|
|
|
|
|
|
|
|
usbclass_resetconfig(priv);
|
|
|
|
up_mdelay(50);
|
|
|
|
|
|
|
|
/* Free the interrupt IN endpoint */
|
|
|
|
|
|
|
|
if (priv->epintin)
|
|
|
|
{
|
|
|
|
DEV_FREEEP(dev, priv->epintin);
|
|
|
|
priv->epintin = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Free the bulk IN endpoint */
|
|
|
|
|
|
|
|
if (priv->epbulkin)
|
|
|
|
{
|
|
|
|
DEV_FREEEP(dev, priv->epbulkin);
|
|
|
|
priv->epbulkin = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Free the pre-allocated control request */
|
|
|
|
|
|
|
|
if (priv->ctrlreq != NULL)
|
|
|
|
{
|
2023-07-06 07:57:42 +02:00
|
|
|
usbdev_freereq(dev->ep0, priv->ctrlreq);
|
2017-09-24 15:24:34 +02:00
|
|
|
priv->ctrlreq = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (priv->epintin_req != NULL)
|
|
|
|
{
|
2023-07-06 07:57:42 +02:00
|
|
|
usbdev_freereq(priv->epintin, priv->epintin_req);
|
2017-09-24 15:24:34 +02:00
|
|
|
priv->epintin_req = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Free pre-allocated read requests (which should all have
|
|
|
|
* been returned to the free list at this time -- we don't check)
|
|
|
|
*/
|
|
|
|
|
|
|
|
if (priv->rdreq)
|
|
|
|
{
|
2023-07-06 07:57:42 +02:00
|
|
|
usbdev_freereq(priv->epbulkout, priv->rdreq);
|
2017-09-24 15:24:34 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Free the bulk OUT endpoint */
|
|
|
|
|
|
|
|
if (priv->epbulkout)
|
|
|
|
{
|
|
|
|
DEV_FREEEP(dev, priv->epbulkout);
|
|
|
|
priv->epbulkout = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
netdev_unregister(&priv->netdev);
|
|
|
|
|
|
|
|
/* Free write requests that are not in use (which should be all
|
|
|
|
* of them
|
|
|
|
*/
|
|
|
|
|
|
|
|
flags = enter_critical_section();
|
|
|
|
while (!sq_empty(&priv->reqlist))
|
|
|
|
{
|
|
|
|
reqcontainer = (struct rndis_req_s *)sq_remfirst(&priv->reqlist);
|
|
|
|
if (reqcontainer->req != NULL)
|
|
|
|
{
|
2023-02-14 10:16:46 +01:00
|
|
|
reqcontainer->req->buf = reqcontainer->buf;
|
2023-07-06 07:57:42 +02:00
|
|
|
usbdev_freereq(priv->epbulkin, reqcontainer->req);
|
2017-09-24 15:24:34 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
leave_critical_section(flags);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Name: usbclass_setup
|
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* Invoked for ep0 control requests. This function probably executes
|
|
|
|
* in the context of an interrupt handler.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
static int usbclass_setup(FAR struct usbdevclass_driver_s *driver,
|
|
|
|
FAR struct usbdev_s *dev,
|
|
|
|
FAR const struct usb_ctrlreq_s *ctrl,
|
|
|
|
FAR uint8_t *dataout, size_t outlen)
|
|
|
|
{
|
|
|
|
FAR struct rndis_dev_s *priv;
|
|
|
|
FAR struct usbdev_req_s *ctrlreq;
|
|
|
|
uint16_t value;
|
|
|
|
uint16_t len;
|
|
|
|
int ret = -EOPNOTSUPP;
|
|
|
|
|
|
|
|
#ifdef CONFIG_DEBUG_FEATURES
|
|
|
|
if (!driver || !dev || !dev->ep0 || !ctrl)
|
|
|
|
{
|
|
|
|
usbtrace(TRACE_CLSERROR(USBSER_TRACEERR_INVALIDARG), 0);
|
|
|
|
return -EIO;
|
2019-12-24 17:37:30 +01:00
|
|
|
}
|
2017-09-24 15:24:34 +02:00
|
|
|
#endif
|
|
|
|
|
|
|
|
/* Extract reference to private data */
|
|
|
|
|
|
|
|
usbtrace(TRACE_CLASSSETUP, ctrl->req);
|
|
|
|
priv = ((FAR struct rndis_driver_s *)driver)->dev;
|
|
|
|
|
|
|
|
#ifdef CONFIG_DEBUG_FEATURES
|
|
|
|
if (!priv || !priv->ctrlreq)
|
|
|
|
{
|
|
|
|
usbtrace(TRACE_CLSERROR(USBSER_TRACEERR_EP0NOTBOUND), 0);
|
|
|
|
return -ENODEV;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
ctrlreq = priv->ctrlreq;
|
2021-03-24 08:11:26 +01:00
|
|
|
ctrlreq->priv = 0;
|
2017-09-24 15:24:34 +02:00
|
|
|
|
|
|
|
/* Extract the little-endian 16-bit values to host order */
|
|
|
|
|
|
|
|
value = GETUINT16(ctrl->value);
|
|
|
|
len = GETUINT16(ctrl->len);
|
|
|
|
|
2017-11-22 19:55:39 +01:00
|
|
|
uinfo("type=%02x req=%02x value=%04x len=%04x\n",
|
|
|
|
ctrl->type, ctrl->req, value, len);
|
2017-09-24 15:24:34 +02:00
|
|
|
|
|
|
|
switch (ctrl->type & USB_REQ_TYPE_MASK)
|
|
|
|
{
|
|
|
|
/***********************************************************************
|
|
|
|
* Standard Requests
|
|
|
|
***********************************************************************/
|
|
|
|
|
|
|
|
case USB_REQ_TYPE_STANDARD:
|
|
|
|
{
|
|
|
|
switch (ctrl->req)
|
|
|
|
{
|
|
|
|
case USB_REQ_GETDESCRIPTOR:
|
|
|
|
{
|
2020-08-06 19:41:45 +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)
|
2017-09-24 15:24:34 +02:00
|
|
|
*/
|
|
|
|
|
|
|
|
switch (ctrl->value[1])
|
|
|
|
{
|
2018-11-09 13:56:58 +01:00
|
|
|
#ifndef CONFIG_RNDIS_COMPOSITE
|
2017-09-24 15:24:34 +02:00
|
|
|
case USB_DESC_TYPE_DEVICE:
|
|
|
|
{
|
|
|
|
ret = USB_SIZEOF_DEVDESC;
|
|
|
|
memcpy(ctrlreq->buf, &g_devdesc, ret);
|
|
|
|
}
|
|
|
|
break;
|
2018-11-09 13:56:58 +01:00
|
|
|
#endif
|
2017-09-24 15:24:34 +02:00
|
|
|
|
2023-03-23 13:18:38 +01:00
|
|
|
/* If the serial device is used in as part of a composite
|
|
|
|
* device, then the configuration descriptor is provided by
|
|
|
|
* logic in the composite device implementation.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef CONFIG_CDCACM_COMPOSITE
|
|
|
|
# ifdef CONFIG_USBDEV_DUALSPEED
|
2023-02-01 14:11:54 +01:00
|
|
|
case USB_DESC_TYPE_OTHERSPEEDCONFIG:
|
2023-03-23 13:18:38 +01:00
|
|
|
# endif /* CONFIG_USBDEV_DUALSPEED */
|
2017-09-24 15:24:34 +02:00
|
|
|
case USB_DESC_TYPE_CONFIG:
|
|
|
|
{
|
2023-03-23 13:18:38 +01:00
|
|
|
# ifdef CONFIG_USBDEV_DUALSPEED
|
2023-02-01 14:11:54 +01:00
|
|
|
ret = usbclass_mkcfgdesc(ctrlreq->buf, &priv->devinfo,
|
|
|
|
dev->speed, ctrl->req);
|
2023-03-23 13:18:38 +01:00
|
|
|
# else
|
2018-11-09 13:56:58 +01:00
|
|
|
ret = usbclass_mkcfgdesc(ctrlreq->buf, &priv->devinfo);
|
2023-03-23 13:18:38 +01:00
|
|
|
# endif
|
2017-09-24 15:24:34 +02:00
|
|
|
}
|
|
|
|
break;
|
2023-03-23 13:18:38 +01:00
|
|
|
#endif
|
2017-09-24 15:24:34 +02:00
|
|
|
|
2023-03-23 13:18:38 +01:00
|
|
|
#ifndef CONFIG_CDCACM_COMPOSITE
|
2017-09-24 15:24:34 +02:00
|
|
|
case USB_DESC_TYPE_STRING:
|
|
|
|
{
|
|
|
|
/* index == language code. */
|
|
|
|
|
2018-11-09 14:44:22 +01:00
|
|
|
ret = usbclass_mkstrdesc(ctrl->value[0],
|
2020-08-06 19:41:45 +02:00
|
|
|
(FAR struct usb_strdesc_s *)ctrlreq->buf);
|
2017-09-24 15:24:34 +02:00
|
|
|
}
|
|
|
|
break;
|
2023-03-23 13:18:38 +01:00
|
|
|
#endif
|
2017-09-24 15:24:34 +02:00
|
|
|
|
|
|
|
default:
|
|
|
|
{
|
2020-08-06 19:41:45 +02:00
|
|
|
usbtrace(TRACE_CLSERROR(USBSER_TRACEERR_GETUNKNOWNDESC),
|
|
|
|
value);
|
2017-09-24 15:24:34 +02:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case USB_REQ_SETCONFIGURATION:
|
|
|
|
{
|
|
|
|
if (ctrl->type == 0)
|
|
|
|
{
|
|
|
|
ret = usbclass_setconfig(priv, value);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2023-03-23 13:18:38 +01:00
|
|
|
/* If the serial 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.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef CONFIG_CDCACM_COMPOSITE
|
2017-09-24 15:24:34 +02:00
|
|
|
case USB_REQ_GETCONFIGURATION:
|
|
|
|
{
|
|
|
|
if (ctrl->type == USB_DIR_IN)
|
|
|
|
{
|
|
|
|
*(FAR uint8_t *)ctrlreq->buf = priv->config;
|
|
|
|
ret = 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
2023-03-23 13:18:38 +01:00
|
|
|
#endif
|
2017-09-24 15:24:34 +02:00
|
|
|
|
|
|
|
default:
|
2020-08-06 19:41:45 +02:00
|
|
|
usbtrace(TRACE_CLSERROR(USBSER_TRACEERR_UNSUPPORTEDSTDREQ),
|
|
|
|
ctrl->req);
|
2017-09-24 15:24:34 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
/* Class requests */
|
|
|
|
|
|
|
|
case USB_REQ_TYPE_CLASS:
|
|
|
|
{
|
2020-08-06 19:41:45 +02:00
|
|
|
if ((ctrl->type & USB_REQ_RECIPIENT_MASK) ==
|
|
|
|
USB_REQ_RECIPIENT_INTERFACE)
|
2017-09-24 15:24:34 +02:00
|
|
|
{
|
|
|
|
if (ctrl->req == RNDIS_SEND_ENCAPSULATED_COMMAND)
|
|
|
|
{
|
|
|
|
ret = rndis_handle_control_message(priv, dataout, outlen);
|
|
|
|
}
|
|
|
|
else if (ctrl->req == RNDIS_GET_ENCAPSULATED_RESPONSE)
|
|
|
|
{
|
2021-03-26 09:41:27 +01:00
|
|
|
if (priv->response_queue_words == 0)
|
2017-09-24 15:24:34 +02:00
|
|
|
{
|
2021-03-24 10:07:42 +01:00
|
|
|
/* No reply available is indicated with a single
|
|
|
|
* 0x00 byte.
|
|
|
|
*/
|
|
|
|
|
2017-09-24 15:24:34 +02:00
|
|
|
ret = 1;
|
|
|
|
ctrlreq->buf[0] = 0;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2021-03-24 10:07:42 +01:00
|
|
|
/* Retrieve a single reply from the response queue to
|
|
|
|
* control request buffer.
|
|
|
|
*/
|
|
|
|
|
2017-09-24 19:18:01 +02:00
|
|
|
FAR struct rndis_response_header *hdr =
|
2021-03-24 08:11:26 +01:00
|
|
|
(struct rndis_response_header *)priv->response_queue;
|
|
|
|
memcpy(ctrlreq->buf, hdr, hdr->msglen);
|
2023-03-23 12:55:29 +01:00
|
|
|
ctrlreq->priv = priv;
|
2017-09-24 19:18:01 +02:00
|
|
|
ret = hdr->msglen;
|
2017-09-24 15:24:34 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
usbtrace(TRACE_CLSERROR(USBSER_TRACEERR_UNSUPPORTEDTYPE), ctrl->type);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Respond to the setup command if data was returned. On an error return
|
|
|
|
* value (ret < 0), the USB driver will stall.
|
|
|
|
*/
|
|
|
|
|
|
|
|
if (ret >= 0)
|
|
|
|
{
|
2023-03-23 11:45:44 +01:00
|
|
|
/* Configure the response */
|
|
|
|
|
2023-02-03 14:42:03 +01:00
|
|
|
ctrlreq->len = MIN(len, ret);
|
2017-09-24 15:24:34 +02:00
|
|
|
ctrlreq->flags = USBDEV_REQFLAGS_NULLPKT;
|
2023-03-23 11:45: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_RNDIS_COMPOSITE
|
|
|
|
ret = EP_SUBMIT(dev->ep0, ctrlreq);
|
|
|
|
#else
|
2023-03-23 17:21:25 +01:00
|
|
|
ret = composite_ep0submit(driver, dev, ctrlreq, ctrl);
|
2023-03-23 11:45:44 +01:00
|
|
|
#endif
|
2017-09-24 15:24:34 +02:00
|
|
|
if (ret < 0)
|
|
|
|
{
|
|
|
|
usbtrace(TRACE_CLSERROR(USBSER_TRACEERR_EPRESPQ), (uint16_t)-ret);
|
|
|
|
ctrlreq->result = OK;
|
|
|
|
usbclass_ep0incomplete(dev->ep0, ctrlreq);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Name: usbclass_disconnect
|
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
static void usbclass_disconnect(FAR struct usbdevclass_driver_s *driver,
|
|
|
|
FAR struct usbdev_s *dev)
|
|
|
|
{
|
|
|
|
FAR struct rndis_dev_s *priv;
|
|
|
|
irqstate_t flags;
|
|
|
|
|
|
|
|
usbtrace(TRACE_CLASSDISCONNECT, 0);
|
|
|
|
|
|
|
|
#ifdef CONFIG_DEBUG_FEATURES
|
|
|
|
if (!driver || !dev || !dev->ep0)
|
|
|
|
{
|
|
|
|
usbtrace(TRACE_CLSERROR(USBSER_TRACEERR_INVALIDARG), 0);
|
|
|
|
return;
|
2019-12-24 17:37:30 +01:00
|
|
|
}
|
2017-09-24 15:24:34 +02:00
|
|
|
#endif
|
|
|
|
|
|
|
|
/* Extract reference to private data */
|
|
|
|
|
|
|
|
priv = ((FAR struct rndis_driver_s *)driver)->dev;
|
|
|
|
|
|
|
|
#ifdef CONFIG_DEBUG_FEATURES
|
|
|
|
if (!priv)
|
|
|
|
{
|
|
|
|
usbtrace(TRACE_CLSERROR(USBSER_TRACEERR_EP0NOTBOUND), 0);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/* Inform the "upper half" network driver that we have lost the USB
|
|
|
|
* connection.
|
|
|
|
*/
|
|
|
|
|
|
|
|
priv->netdev.d_ifdown(&priv->netdev);
|
|
|
|
|
|
|
|
flags = enter_critical_section();
|
|
|
|
|
|
|
|
/* Reset the configuration */
|
|
|
|
|
|
|
|
usbclass_resetconfig(priv);
|
|
|
|
|
|
|
|
leave_critical_section(flags);
|
|
|
|
|
|
|
|
/* Perform the soft connect function so that we will we can be
|
2023-03-23 13:18:38 +01:00
|
|
|
* re-enumerated (unless we are part of a composite device)
|
2017-09-24 15:24:34 +02:00
|
|
|
*/
|
|
|
|
|
2023-03-23 13:18:38 +01:00
|
|
|
#ifndef CONFIG_CDCACM_COMPOSITE
|
2017-09-24 15:24:34 +02:00
|
|
|
DEV_CONNECT(dev);
|
2023-03-23 13:18:38 +01:00
|
|
|
#endif
|
2017-09-24 15:24:34 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Name: usbclass_resetconfig
|
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* Mark the device as not configured and disable all endpoints.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
static void usbclass_resetconfig(FAR struct rndis_dev_s *priv)
|
|
|
|
{
|
|
|
|
/* Are we configured? */
|
|
|
|
|
|
|
|
if (priv->config != RNDIS_CONFIGIDNONE)
|
|
|
|
{
|
|
|
|
/* Yes.. but not anymore */
|
|
|
|
|
|
|
|
priv->config = RNDIS_CONFIGIDNONE;
|
|
|
|
|
|
|
|
priv->netdev.d_ifdown(&priv->netdev);
|
|
|
|
|
|
|
|
/* Disable endpoints. This should force completion of all pending
|
|
|
|
* transfers.
|
|
|
|
*/
|
|
|
|
|
|
|
|
EP_DISABLE(priv->epintin);
|
|
|
|
EP_DISABLE(priv->epbulkin);
|
|
|
|
EP_DISABLE(priv->epbulkout);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Name: usbclass_setconfig
|
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* Set the device configuration by allocating and configuring endpoints and
|
|
|
|
* by allocating and queue read and write requests.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
static int usbclass_setconfig(FAR struct rndis_dev_s *priv, uint8_t config)
|
|
|
|
{
|
2019-07-24 00:12:50 +02:00
|
|
|
struct usb_epdesc_s epdesc;
|
|
|
|
bool hispeed = false;
|
2017-09-24 15:24:34 +02:00
|
|
|
int ret = 0;
|
|
|
|
|
|
|
|
#ifdef CONFIG_DEBUG_FEATURES
|
|
|
|
if (priv == NULL)
|
|
|
|
{
|
|
|
|
usbtrace(TRACE_CLSERROR(USBSER_TRACEERR_INVALIDARG), 0);
|
|
|
|
return -EIO;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2019-07-24 00:12:50 +02:00
|
|
|
#ifdef CONFIG_USBDEV_DUALSPEED
|
|
|
|
hispeed = (priv->usbdev->speed == USB_SPEED_HIGH);
|
|
|
|
#endif
|
|
|
|
|
2017-09-24 15:24:34 +02:00
|
|
|
if (config == priv->config)
|
|
|
|
{
|
|
|
|
/* Already configured -- Do nothing */
|
|
|
|
|
|
|
|
usbtrace(TRACE_CLSERROR(USBSER_TRACEERR_ALREADYCONFIGURED), 0);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Discard the previous configuration data */
|
|
|
|
|
|
|
|
usbclass_resetconfig(priv);
|
|
|
|
|
|
|
|
/* Was this a request to simply discard the current configuration? */
|
|
|
|
|
|
|
|
if (config == RNDIS_CONFIGIDNONE)
|
|
|
|
{
|
|
|
|
usbtrace(TRACE_CLSERROR(USBSER_TRACEERR_CONFIGNONE), 0);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* We only accept one configuration */
|
|
|
|
|
|
|
|
if (config != RNDIS_CONFIGID)
|
|
|
|
{
|
|
|
|
usbtrace(TRACE_CLSERROR(USBSER_TRACEERR_CONFIGIDBAD), 0);
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Configure the IN interrupt endpoint */
|
|
|
|
|
2019-07-24 00:12:50 +02:00
|
|
|
usbclass_copy_epdesc(RNDIS_EP_INTIN_IDX, &epdesc, &priv->devinfo, hispeed);
|
|
|
|
ret = EP_CONFIGURE(priv->epintin, &epdesc, false);
|
2017-09-24 15:24:34 +02:00
|
|
|
if (ret < 0)
|
|
|
|
{
|
|
|
|
usbtrace(TRACE_CLSERROR(USBSER_TRACEERR_EPINTINCONFIGFAIL), 0);
|
|
|
|
goto errout;
|
|
|
|
}
|
2017-09-24 19:18:01 +02:00
|
|
|
|
2017-09-24 15:24:34 +02:00
|
|
|
priv->epintin->priv = priv;
|
|
|
|
|
|
|
|
/* Configure the IN bulk endpoint */
|
|
|
|
|
2020-08-06 19:41:45 +02:00
|
|
|
usbclass_copy_epdesc(RNDIS_EP_BULKIN_IDX,
|
|
|
|
&epdesc, &priv->devinfo, hispeed);
|
2019-07-24 00:12:50 +02:00
|
|
|
ret = EP_CONFIGURE(priv->epbulkin, &epdesc, false);
|
2017-09-24 15:24:34 +02:00
|
|
|
|
|
|
|
if (ret < 0)
|
|
|
|
{
|
|
|
|
usbtrace(TRACE_CLSERROR(USBSER_TRACEERR_EPBULKINCONFIGFAIL), 0);
|
|
|
|
goto errout;
|
|
|
|
}
|
|
|
|
|
|
|
|
priv->epbulkin->priv = priv;
|
|
|
|
|
|
|
|
/* Configure the OUT bulk endpoint */
|
|
|
|
|
2020-08-06 19:41:45 +02:00
|
|
|
usbclass_copy_epdesc(RNDIS_EP_BULKOUT_IDX,
|
|
|
|
&epdesc, &priv->devinfo, hispeed);
|
2019-07-24 00:12:50 +02:00
|
|
|
ret = EP_CONFIGURE(priv->epbulkout, &epdesc, true);
|
2017-09-24 15:24:34 +02:00
|
|
|
|
|
|
|
if (ret < 0)
|
|
|
|
{
|
|
|
|
usbtrace(TRACE_CLSERROR(USBSER_TRACEERR_EPBULKOUTCONFIGFAIL), 0);
|
|
|
|
goto errout;
|
|
|
|
}
|
|
|
|
|
|
|
|
priv->epbulkout->priv = priv;
|
|
|
|
|
|
|
|
/* Queue read requests in the bulk OUT endpoint */
|
|
|
|
|
|
|
|
priv->rdreq->callback = rndis_rdcomplete;
|
|
|
|
ret = rndis_submit_rdreq(priv);
|
|
|
|
if (ret != OK)
|
2018-11-09 14:44:22 +01:00
|
|
|
{
|
|
|
|
usbtrace(TRACE_CLSERROR(USBSER_TRACEERR_RDSUBMIT), (uint16_t)-ret);
|
|
|
|
goto errout;
|
|
|
|
}
|
2017-09-24 15:24:34 +02:00
|
|
|
|
|
|
|
/* We are successfully configured */
|
|
|
|
|
|
|
|
priv->config = config;
|
2017-09-24 19:18:01 +02:00
|
|
|
if (priv->netdev.d_ifup(&priv->netdev) == OK)
|
|
|
|
{
|
|
|
|
priv->netdev.d_flags |= IFF_UP;
|
|
|
|
}
|
2017-09-24 15:24:34 +02:00
|
|
|
|
|
|
|
return OK;
|
|
|
|
|
|
|
|
errout:
|
|
|
|
usbclass_resetconfig(priv);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************************************************
|
2018-11-09 13:56:58 +01:00
|
|
|
* Name: usbclass_classobject
|
2017-09-24 15:24:34 +02:00
|
|
|
*
|
|
|
|
* Description:
|
2018-11-09 13:56:58 +01:00
|
|
|
* Allocate memory for the RNDIS driver class object
|
2017-09-24 15:24:34 +02:00
|
|
|
*
|
|
|
|
* Returned Value:
|
2018-11-09 13:56:58 +01:00
|
|
|
* 0 on success, negative error code on failure.
|
2017-09-24 15:24:34 +02:00
|
|
|
*
|
|
|
|
****************************************************************************/
|
2018-11-09 14:44:22 +01:00
|
|
|
|
2018-11-09 13:56:58 +01:00
|
|
|
static int usbclass_classobject(int minor,
|
|
|
|
FAR struct usbdev_devinfo_s *devinfo,
|
|
|
|
FAR struct usbdevclass_driver_s **classdev)
|
2017-09-24 15:24:34 +02:00
|
|
|
{
|
|
|
|
FAR struct rndis_alloc_s *alloc;
|
|
|
|
FAR struct rndis_dev_s *priv;
|
|
|
|
FAR struct rndis_driver_s *drvr;
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
/* Allocate the structures needed */
|
|
|
|
|
2020-08-06 19:41:45 +02:00
|
|
|
alloc = kmm_zalloc(sizeof(struct rndis_alloc_s));
|
2017-09-24 15:24:34 +02:00
|
|
|
if (!alloc)
|
|
|
|
{
|
|
|
|
usbtrace(TRACE_CLSERROR(USBSER_TRACEERR_ALLOCDEVSTRUCT), 0);
|
|
|
|
return -ENOMEM;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Convenience pointers into the allocated blob */
|
|
|
|
|
|
|
|
priv = &alloc->dev;
|
|
|
|
drvr = &alloc->drvr;
|
2018-11-09 13:56:58 +01:00
|
|
|
*classdev = &drvr->drvr;
|
|
|
|
|
2023-03-21 12:16:44 +01:00
|
|
|
/* Get device info */
|
|
|
|
|
|
|
|
memcpy(&priv->devinfo, devinfo, sizeof(struct usbdev_devinfo_s));
|
2017-09-24 15:24:34 +02:00
|
|
|
|
|
|
|
/* Initialize the USB ethernet driver structure */
|
|
|
|
|
|
|
|
sq_init(&priv->reqlist);
|
2018-11-09 13:56:58 +01:00
|
|
|
memcpy(priv->host_mac_address, g_rndis_default_mac_addr, 6);
|
2017-09-24 15:24:34 +02:00
|
|
|
priv->netdev.d_private = priv;
|
|
|
|
priv->netdev.d_ifup = &rndis_ifup;
|
|
|
|
priv->netdev.d_ifdown = &rndis_ifdown;
|
|
|
|
priv->netdev.d_txavail = &rndis_txavail;
|
|
|
|
|
|
|
|
/* MAC address filtering is purposefully left out of this driver. Since
|
|
|
|
* in the RNDIS USB scenario there are only two devices in the network
|
|
|
|
* (host and us), there shouldn't be any packets received that don't
|
|
|
|
* belong to us.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/* Initialize the USB class driver structure */
|
|
|
|
|
2023-02-01 14:11:54 +01:00
|
|
|
#ifdef CONFIG_USBDEV_DUALSPEED
|
|
|
|
drvr->drvr.speed = USB_SPEED_HIGH;
|
|
|
|
#else
|
2017-09-24 15:24:34 +02:00
|
|
|
drvr->drvr.speed = USB_SPEED_FULL;
|
2023-02-01 14:11:54 +01:00
|
|
|
#endif
|
|
|
|
|
2017-09-24 15:24:34 +02:00
|
|
|
drvr->drvr.ops = &g_driverops;
|
|
|
|
drvr->dev = priv;
|
|
|
|
|
2018-11-09 13:56:58 +01:00
|
|
|
ret = netdev_register(&priv->netdev, NET_LL_ETHERNET);
|
|
|
|
if (ret)
|
|
|
|
{
|
|
|
|
uerr("Failed to register net device");
|
|
|
|
return ret;
|
|
|
|
}
|
2017-09-24 15:24:34 +02:00
|
|
|
|
2018-11-09 13:56:58 +01:00
|
|
|
drvr->dev->registered = true;
|
|
|
|
|
|
|
|
return OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void usbclass_uninitialize(FAR struct usbdevclass_driver_s *classdev)
|
|
|
|
{
|
2018-11-09 14:44:22 +01:00
|
|
|
FAR struct rndis_driver_s *drvr = (FAR struct rndis_driver_s *)classdev;
|
2018-11-09 13:56:58 +01:00
|
|
|
FAR struct rndis_alloc_s *alloc = (FAR struct rndis_alloc_s *)drvr->dev;
|
2023-06-21 08:46:34 +02:00
|
|
|
if (!alloc->dev.registered)
|
|
|
|
{
|
|
|
|
#ifdef CONFIG_USBADB_COMPOSITE
|
|
|
|
kmm_free(alloc);
|
|
|
|
#endif
|
|
|
|
return;
|
|
|
|
}
|
2018-11-09 13:56:58 +01:00
|
|
|
if (drvr->dev->registered)
|
|
|
|
{
|
|
|
|
netdev_unregister(&drvr->dev->netdev);
|
|
|
|
drvr->dev->registered = false;
|
2023-06-21 08:46:34 +02:00
|
|
|
#ifndef CONFIG_RNDIS_COMPOSITE
|
2018-11-09 13:56:58 +01:00
|
|
|
kmm_free(alloc);
|
2023-06-21 08:46:34 +02:00
|
|
|
#endif
|
|
|
|
return;
|
2018-11-09 13:56:58 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Public Functions
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Name: usbdev_rndis_initialize
|
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* Initialize the RNDIS USB device driver.
|
|
|
|
*
|
|
|
|
* Input Parameters:
|
|
|
|
* mac_address: pointer to an array of six octets which is the MAC address
|
|
|
|
* of the host side of the interface. May be NULL to use the
|
|
|
|
* default MAC address.
|
|
|
|
*
|
|
|
|
* Returned Value:
|
|
|
|
* 0 on success, -errno on failure
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
2018-11-09 14:44:22 +01:00
|
|
|
|
2018-11-09 13:56:58 +01:00
|
|
|
#ifndef CONFIG_RNDIS_COMPOSITE
|
|
|
|
int usbdev_rndis_initialize(FAR const uint8_t *mac_address)
|
|
|
|
{
|
|
|
|
int ret;
|
|
|
|
FAR struct usbdevclass_driver_s *classdev;
|
|
|
|
FAR struct rndis_driver_s *drvr;
|
2023-03-21 12:16:44 +01:00
|
|
|
struct usbdev_devinfo_s devinfo;
|
|
|
|
|
|
|
|
memset(&devinfo, 0, sizeof(struct usbdev_devinfo_s));
|
|
|
|
devinfo.ninterfaces = RNDIS_NINTERFACES;
|
|
|
|
devinfo.nstrings = RNDIS_NSTRIDS;
|
|
|
|
devinfo.nendpoints = RNDIS_NUM_EPS;
|
|
|
|
devinfo.epno[RNDIS_EP_INTIN_IDX] = CONFIG_RNDIS_EPINTIN;
|
|
|
|
devinfo.epno[RNDIS_EP_BULKIN_IDX] = CONFIG_RNDIS_EPBULKIN;
|
|
|
|
devinfo.epno[RNDIS_EP_BULKOUT_IDX] = CONFIG_RNDIS_EPBULKOUT;
|
2018-11-09 13:56:58 +01:00
|
|
|
|
2023-03-21 12:16:44 +01:00
|
|
|
ret = usbclass_classobject(0, &devinfo, &classdev);
|
2017-09-24 15:24:34 +02:00
|
|
|
if (ret)
|
|
|
|
{
|
2018-11-09 13:56:58 +01:00
|
|
|
nerr("usbclass_classobject failed: %d\n", ret);
|
|
|
|
return ret;
|
2017-09-24 15:24:34 +02:00
|
|
|
}
|
|
|
|
|
2018-11-09 14:44:22 +01:00
|
|
|
drvr = (FAR struct rndis_driver_s *)classdev;
|
2018-11-09 13:56:58 +01:00
|
|
|
|
|
|
|
if (mac_address)
|
|
|
|
{
|
|
|
|
memcpy(drvr->dev->host_mac_address, mac_address, 6);
|
|
|
|
}
|
|
|
|
|
|
|
|
ret = usbdev_register(&drvr->drvr);
|
2017-09-24 15:24:34 +02:00
|
|
|
if (ret)
|
|
|
|
{
|
2018-11-09 13:56:58 +01:00
|
|
|
nerr("usbdev_register failed: %d\n", ret);
|
|
|
|
usbtrace(TRACE_CLSERROR(USBSER_TRACEERR_DEVREGISTER), (uint16_t)-ret);
|
|
|
|
usbclass_uninitialize(classdev);
|
|
|
|
return ret;
|
2017-09-24 15:24:34 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return OK;
|
2018-11-09 13:56:58 +01:00
|
|
|
}
|
|
|
|
#endif
|
2017-09-24 15:24:34 +02:00
|
|
|
|
2018-11-09 13:56:58 +01:00
|
|
|
/****************************************************************************
|
|
|
|
* Name: usbdev_rndis_set_host_mac_addr
|
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* Set host MAC address. Mainly for use with composite devices where
|
|
|
|
* the MAC cannot be given directly to usbdev_rndis_initialize().
|
|
|
|
*
|
|
|
|
* Input Parameters:
|
|
|
|
* netdev: pointer to the network interface. Can be obtained from
|
|
|
|
* e.g. netdev_findbyname().
|
|
|
|
*
|
|
|
|
* mac_address: pointer to an array of six octets which is the MAC address
|
|
|
|
* of the host side of the interface. May be NULL to use the
|
|
|
|
* default MAC address.
|
|
|
|
*
|
|
|
|
* Returned Value:
|
|
|
|
* 0 on success, -errno on failure
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
2018-11-09 14:44:22 +01:00
|
|
|
|
|
|
|
int usbdev_rndis_set_host_mac_addr(FAR struct net_driver_s *netdev,
|
|
|
|
FAR const uint8_t *mac_address)
|
2018-11-09 13:56:58 +01:00
|
|
|
{
|
2018-11-09 14:44:22 +01:00
|
|
|
FAR struct rndis_dev_s *dev = (FAR struct rndis_dev_s *)netdev;
|
2018-11-09 13:56:58 +01:00
|
|
|
|
|
|
|
if (mac_address)
|
|
|
|
{
|
|
|
|
memcpy(dev->host_mac_address, mac_address, 6);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
memcpy(dev->host_mac_address, g_rndis_default_mac_addr, 6);
|
|
|
|
}
|
2018-11-09 14:44:22 +01:00
|
|
|
|
2018-11-09 13:56:58 +01:00
|
|
|
return OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Name: usbdev_rndis_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
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
#ifdef CONFIG_RNDIS_COMPOSITE
|
|
|
|
void usbdev_rndis_get_composite_devdesc(struct composite_devdesc_s *dev)
|
|
|
|
{
|
|
|
|
memset(dev, 0, sizeof(struct composite_devdesc_s));
|
|
|
|
|
2023-03-21 10:16:59 +01:00
|
|
|
/* The callback functions for the RNDIS class.
|
|
|
|
*
|
|
|
|
* classobject() and uninitialize() must be provided by board-specific
|
|
|
|
* logic
|
|
|
|
*/
|
|
|
|
|
2018-11-09 14:44:22 +01:00
|
|
|
dev->mkconfdesc = usbclass_mkcfgdesc;
|
|
|
|
dev->mkstrdesc = usbclass_mkstrdesc;
|
|
|
|
dev->classobject = usbclass_classobject;
|
|
|
|
dev->uninitialize = usbclass_uninitialize;
|
2023-03-21 10:16:59 +01:00
|
|
|
|
|
|
|
dev->nconfigs = RNDIS_NCONFIGS; /* Number of configurations supported */
|
|
|
|
dev->configid = RNDIS_CONFIGID; /* The only supported configuration ID */
|
|
|
|
|
|
|
|
/* Let the construction function calculate the size of config descriptor */
|
|
|
|
|
|
|
|
#ifdef CONFIG_USBDEV_DUALSPEED
|
|
|
|
dev->cfgdescsize = usbclass_mkcfgdesc(NULL, NULL, USB_SPEED_UNKNOWN, 0);
|
|
|
|
#else
|
|
|
|
dev->cfgdescsize = usbclass_mkcfgdesc(NULL, NULL);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/* Board-specific logic must provide the device minor */
|
|
|
|
|
|
|
|
/* Interfaces.
|
|
|
|
*
|
|
|
|
* ifnobase must be provided by board-specific logic
|
|
|
|
*/
|
|
|
|
|
2018-11-09 13:56:58 +01:00
|
|
|
dev->devinfo.ninterfaces = RNDIS_NINTERFACES;
|
2023-03-21 10:16:59 +01:00
|
|
|
|
|
|
|
/* Strings.
|
|
|
|
*
|
|
|
|
* strbase must be provided by board-specific logic
|
|
|
|
*/
|
|
|
|
|
2018-11-09 13:56:58 +01:00
|
|
|
dev->devinfo.nstrings = 0;
|
|
|
|
|
2023-03-21 10:16:59 +01:00
|
|
|
/* Endpoints.
|
|
|
|
*
|
|
|
|
* Endpoint numbers must be provided by board-specific logic.
|
|
|
|
*/
|
2018-11-09 14:44:22 +01:00
|
|
|
|
2023-03-21 10:16:59 +01:00
|
|
|
dev->devinfo.nendpoints = RNDIS_NUM_EPS;
|
2017-09-24 15:24:34 +02:00
|
|
|
}
|
2018-11-09 13:56:58 +01:00
|
|
|
#endif
|