Add support to CDC-MBIM USB host driver

This driver was created by Adam Porter and posted on NuttX
mailing list at Google Group on Nov 14 2019
This commit is contained in:
Adam Porter 2020-06-14 10:10:11 -03:00 committed by patacongo
parent 5785340e04
commit 07c0faff59
6 changed files with 2740 additions and 81 deletions

View File

@ -262,6 +262,15 @@ config USBHOST_CDCACM_TXBUFSIZE
endif # USBHOST_CDCACM
config USBHOST_CDCMBIM
bool "CDC/MBIM support"
default n
depends on USBHOST_HAVE_ASYNCH && !USBHOST_BULK_DISABLE && !USBHOST_INT_DISABLE
select USBHOST_ASYNCH
---help---
Select this option to build in host support for CDC/MBIM network
devices.
config USBHOST_HIDKBD
bool "HID Keyboard Class Support"
default n

View File

@ -58,6 +58,10 @@ ifeq ($(CONFIG_USBHOST_CDCACM),y)
CSRCS += usbhost_cdcacm.c
endif
ifeq ($(CONFIG_USBHOST_CDCMBIM),y)
CSRCS += usbhost_cdcmbim.c
endif
ifeq ($(CONFIG_USBHOST_HIDKBD),y)
CSRCS += usbhost_hidkbd.c
endif

File diff suppressed because it is too large Load Diff

View File

@ -155,7 +155,8 @@ enum net_lltype_e
NET_LL_BLUETOOTH, /* Bluetooth */
NET_LL_IEEE80211, /* IEEE 802.11 */
NET_LL_IEEE802154, /* IEEE 802.15.4 MAC */
NET_LL_PKTRADIO /* Non-standard packet radio */
NET_LL_PKTRADIO, /* Non-standard packet radio */
NET_LL_MBIM
};
/* This defines a bitmap big enough for one bit for each socket option */

View File

@ -1,4 +1,4 @@
/********************************************************************************************
/*****************************************************************************
* include/nuttx/usb/cdc.h
*
* Copyright (C) 2011, 2017 Gregory Nutt. All rights reserved.
@ -34,30 +34,38 @@
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
********************************************************************************************/
*****************************************************************************/
#ifndef __INCLUDE_NUTTX_USB_CDC_H
#define __INCLUDE_NUTTX_USB_CDC_H
/********************************************************************************************
/*****************************************************************************
* Included Files
********************************************************************************************/
*****************************************************************************/
#include <nuttx/config.h>
/********************************************************************************************
/*****************************************************************************
* Pre-processor Definitions
********************************************************************************************/
/* Device Class Codes ***********************************************************************/
/* Table 14: Communication Device Class Code (see definition USB_CLASS_CDC in usb.h) */
/* Table 18: Data Interface Class Code (see definition USB_CLASS_CDC_DATA in usb.h) */
*****************************************************************************/
/* Device Class Codes ********************************************************/
/* Table 14: Communication Device Class Code (see definition USB_CLASS_CDC in
* usb.h)
*/
/* Table 18: Data Interface Class Code (see definition USB_CLASS_CDC_DATA in
* usb.h)
*/
/* Communication Interface Class Codes ***************************************/
/* Communication Interface Class Codes ******************************************************/
/* Table 15: Communication Interface Class Code */
#define CDC_CLASS_COMM 0x02 /* Communication Interface Class */
/* Communication Interface Sub-Class Codes **************************************************/
/* Communication Interface Sub-Class Codes ***********************************/
#define CDC_SUBCLASS_NONE 0x00 /* Reserved */
#define CDC_SUBCLASS_DLC 0x01 /* Direct Line Control Model */
@ -67,26 +75,35 @@
#define CDC_SUBCLASS_CAPI 0x05 /* CAPI Control Model */
#define CDC_SUBCLASS_ECM 0x06 /* Ethernet Networking Control Model */
#define CDC_SUBCLASS_ATM 0x07 /* ATM Networking Control Model */
/* 0x08-0x7f Reserved (future use) */
/* 0x08-0x0d Reserved (future use) */
#define CDC_SUBCLASS_MBIM 0x0e /* MBIM Control Model */
/* 0x0f-0x7f Reserved (future use) */
/* 0x80-0xfe Reserved (vendor specific) */
/* Communication Interface Class Protocol Codes ********************************************/
/* Communication Interface Class Protocol Codes ******************************/
/* Table 17: Communication Interface Class Control Protocol Codes */
#define CDC_PROTO_NONE 0x00 /* No class specific protocol required */
#define CDC_PROTO_ATM 0x01 /* Common AT commands (also known as Hayes compatible) */
#define CDC_PROTO_ATM 0x01 /* Common AT commands (also known as Hayes
* compatible)
*/
/* 0x02-0xfe Reserved (future use) */
#define CDC_PROTO_VENDOR 0xff /* Vendor-specific */
/* Data Interface Sub-Class Codes ***********************************************************/
/* Data Interface Sub-Class Codes ********************************************/
/* None defined, should be zero */
#define CDC_DATA_SUBCLASS_NONE 0x00
/* Date Interface Class Protocol Codes ******************************************************/
/* Date Interface Class Protocol Codes ***************************************/
/* Table 19: Data Interface Class Protocol Codes */
#define CDC_DATA_PROTO_NONE 0x00 /* No class specific protocol required */
/* 0x01-0x2f Reserved (future use) */
#define CDC_DATA_PROTO_NTB 0x02 /* Network Transfer Block protocol */
#define CDC_DATA_PROTO_ISDN 0x30 /* Physical interface protocol for ISDN BRI */
#define CDC_DATA_PROTO_HDLC 0x31 /* HDLC */
#define CDC_DATA_PROTO_TRANSP 0x32 /* Transparent */
@ -107,7 +124,8 @@
*/
#define CDC_DATA_PROTO_VENDOR 0xff /* Vendor-specific */
/* Requests and Notifications ***************************************************************/
/* Requests and Notifications ************************************************/
/* Table 2: Requests, Direct Line Control Model */
#define DLC_SET_AUX_LINE_STATE 0x10 /* Request to connect or disconnect secondary jack from
@ -128,6 +146,7 @@
#define DLC_RING_AUX_JACK 0x15 /* Request for a ring signal to be generated on secondary
* phone jack. (Optional)
*/
/* Table 3: Notifications, Direct Line Control Model */
#define DLC_AUX_JACK_HOOK_STATE 0x08 /* Indicates hook state of secondary device plugged
@ -136,6 +155,7 @@
#define DLC_RING_DETECT 0x09 /* Message to notify host that ring voltage was
* detected on POTS interface. (Required)
*/
/* Table 4: Requests, Abstract Control Model */
#define ACM_SEND_COMMAND 0x00 /* Issues a command in the format of the supported
@ -164,6 +184,7 @@
*/
#define ACM_SEND_BREAK 0x23 /* Sends special carrier
*/
/* Table 5: Notifications, Abstract Control Model */
#define ACM_NETWORK_CONNECTION 0x00 /* Notification to host of network connection status.
@ -175,6 +196,7 @@
#define ACM_SERIAL_STATE 0x20 /* Returns the current state of the carrier detect, DSR,
* break, and ring signal. (Optional)
*/
/* Table 6: Requests, Telephone Control Model */
#define TCM_SET_COMM_FEATURE 0x02 /* Used to set a unique communication feature, which is
@ -208,12 +230,14 @@
*/
#define TCM_DIAL_DIGITS 0x36 /* Dials digits on the network connection. (Required)
*/
/* Table 7: Notifications, Telephone Control Model */
#define TCM_CALL_STATE_CHANGE 0x28 /* DReports a state change on a call. (Required)
*/
#define TCM_LINE_STATE_CHANGE 0x29 /* DReports a state change on a line. (Optional)
*/
/* Table 8: Requests, Multi-Channel Model */
#define MCM_SET_UNIT_PARAM 0x37 /* Used to set a Unit specific parameter (Optional)
@ -223,11 +247,13 @@
#define MCM_CLEAR_UNIT_PARAM 0x39 /* Used to set a Unit specific parameter to its default
* state. (Optional)
*/
/* Table 9: Request, CAPI Control Model */
#define CAPI_GET_PROFILE 0x3a /* Returns the implemented capabilities of the device
* (Required)
*/
/* Table 10: Requests, Ethernet Networking Control Model */
#define ECM_SEND_COMMAND 0x00 /* Issues a command in the format of the supported
@ -267,6 +293,7 @@
* transmitted, frames received, and bad frames received.
* (Optional)
*/
/* Table 11: Notifications, Ethernet Networking Control Model */
#define ECM_NETWORK_CONNECTION 0x00 /* Reports whether or not the physical layer (modem,
@ -277,6 +304,7 @@
*/
#define ECM_SPEED_CHANGE 0x2a /* Reports a change in upstream or downstream (Required)
*/
/* Table 12: Requests, ATM Networking Control Model */
#define ATM_SEND_COMMAND 0x00 /* Issues a command in the format of the supported control
@ -302,6 +330,7 @@
#define ATM_GET_VC_STATISTICS 0x53 /* Retrieves statistics from the ATM Networking device for
* a particular VPI/VCI. (Optional)
*/
/* Table 13: Requests, Ethernet and ATM Networking Control Model */
#define ATM_NETWORK_CONNECTION 0x00 /* Reports whether or not the physical layer (modem,
@ -317,7 +346,8 @@
*/
#define ECM_SPEED_CHANGE ATM_SPEED_CHANGE
/* Descriptors ******************************************************************************/
/* Descriptors ***************************************************************/
/* Table 25: bDescriptor SubType in Functional Descriptors */
#define CDC_DSUBTYPE_HDR 0x00 /* Header Functional Descriptor, which marks the
@ -340,6 +370,7 @@
#define CDC_DSUBTYPE_CAPI 0x0e /* CAPI Control Management Functional Descriptor */
#define CDC_DSUBTYPE_ECM 0x0f /* Ethernet Networking Functional Descriptor */
#define CDC_DSUBTYPE_ATM 0x10 /* ATM Networking Functional Descriptor */
#define CDC_DSUBTYPE_MBIM 0x1b /* MBIM Functional Descriptor */
/* 0x11-0xff Reserved (future use) */
/* Table 42: Ethernet Statistics Capabilities */
@ -390,6 +421,7 @@
#define FEATURE_COUNTRY_SETTING 0x02 /* Country code in hexadecimal format as defined in
* ISO 3166
*/
/* Table 49: POTS Relay Configuration Values */
#define POTS_ON_HOOK 0x0000
@ -515,18 +547,22 @@
* been detected with HEC errors in the cell
* header and successfully corrected.
*/
/* Table 66: ATM VC Selector Codes */
#define VC_US_CELLS_SENT 0x01 /* The number of cells that have been sent upstream to
* the WAN link for the specified VPI/VCI since the
#define VC_US_CELLS_SENT 0x01 /* The number of cells that have been
* sent upstream to the WAN link for the
* specified VPI/VCI since the device
* has been powered on or reset
*/
#define VC_DS_CELLS_RECEIVED 0x02 /* The number of cells that have been
* received downstream from the WAN link
* for the specified VPI/VCI since the
* device has been powered on or reset
*/
#define VC_DS_CELLS_RECEIVED 0x02 /* The number of cells that have been received
* downstream from the WAN link for the specified
* VPI/VCI since the device has been
* powered on or reset
*/
/* Notifications ****************************************************************************/
/* Notifications *************************************************************/
/* Table 69: UART State Bitmap Values */
#define CDC_UART_RXCARRIER (1 << 0) /* bRxCarrier State of receiver carrier detection
@ -554,12 +590,14 @@
#define CDCACM_UART_DCD CDC_UART_RXCARRIER
#define CDCACM_UART_DSR CDC_UART_TXCARRIER
/* "SerialState is used like a real interrupt status register. Once a notification has been
* sent, the device will reset and reevaluate the different signals. For the consistent
* signals like carrier detect or transmission carrier, this will mean another notification
* will not be generated until there is a state change. For the irregular signals like
* break, the incoming ring signal, or the overrun error state, this will reset their values
* to zero and again will not send another notification until their state changes."
/* "SerialState is used like a real interrupt status register. Once a
* notification has been sent, the device will reset and reevaluate the
* different signals. For the consistent signals like carrier detect or
* transmission carrier, this will mean another notification will not be
* generated until there is a state change. For the irregular signals like
* break, the incoming ring signal, or the overrun error state, this will
* reset their values to zero and again will not send another notification
* until their state changes."
*/
#define CDC_UART_CONSISTENT (CDC_UART_RXCARRIER | CDC_UART_TXCARRIER)
@ -583,9 +621,9 @@
#define CDC_LINEST_OFFHOOK 0x0002 /* Hook-switch has gone off hook */
#define CDC_LINEST_ONHOOK 0x0003 /* Hook-switch has gone on hook */
/********************************************************************************************
/*****************************************************************************
* Public Types
********************************************************************************************/
*****************************************************************************/
/* Table 1: Data Class Protocol Wrapper */
@ -594,10 +632,13 @@ struct cdc_protowrapper_s
uint8_t size[2]; /* Size of wrapper in bytes */
uint8_t dstproto; /* bDstProtocol, Destination protocol ID */
uint8_t srcproto; /* bSrcProtocol, Source protocol ID */
uint8_t data[1]; /* Data payload, actual size depends of size of the wrapper */
uint8_t data[1]; /* Data payload, actual size depends of size of the
* wrapper
*/
};
/* Functional Descriptors *******************************************************************/
/* Functional Descriptors ****************************************************/
/* Table 23: Functional Descriptor General Format */
struct cdc_funcdesc_s
@ -758,14 +799,18 @@ struct cdc_usbterm_funcdesc_s
struct cdc_netchan_funcdesc_s
{
uint8_t size; /* bFunctionLength, Size of this descriptor */
uint8_t type; /* bDescriptorType, USB_DESC_TYPE_CSINTERFACE */
uint8_t subtype; /* bDescriptorSubType, CDC_DSUBTYPE_NETCHAN as defined in Table 25 */
uint8_t id; /* bEntityId, Constant uniquely identifying the Terminal */
uint8_t name; /* iName, Index of string descriptor, describing the name of the Network
* Channel Terminal
*/
uint8_t index; /* bChannelIndex, The channel index of the associated network channel */
uint8_t phyif; /* bPhysicalInterface, Type of physical interface */
uint8_t type; /* bDescriptorType, USB_DESC_TYPE_CSINTERFACE */
uint8_t subtype; /* bDescriptorSubType, CDC_DSUBTYPE_NETCHAN as defined in
* Table 25 */
uint8_t id; /* bEntityId, Constant uniquely identifying the
* Terminal */
uint8_t name; /* iName, Index of string descriptor, describing the name
* of the Network Channel Terminal
*/
uint8_t index; /* bChannelIndex, The channel index of the associated
* network channel
*/
uint8_t phyif; /* bPhysicalInterface, Type of physical interface */
};
#define SIZEOF_NETCHAN_FUNCDESC 7
@ -827,22 +872,28 @@ struct cdc_capi_funcdesc_s
struct cdc_ecm_funcdesc_s
{
uint8_t size; /* bFunctionLength, Size of this descriptor */
uint8_t type; /* bDescriptorType, USB_DESC_TYPE_CSINTERFACE */
uint8_t subtype; /* bDescriptorSubType, CDC_DSUBTYPE_ECM as defined in Table 25 */
uint8_t mac; /* iMACAddress, Index of the 48bit Ethernet MAC address string descriptor */
uint8_t stats[4]; /* bmEthernetStatistics, Indicates which Ethernet statistics functions
* the device collects. See Table 42.
*/
uint8_t maxseg[2]; /* wMaxSegmentSize, The maximum segment size that the Ethernet device is
* capable of supporting.
*/
uint8_t nmcflts[2]; /* wNumberMCFilters, Contains the number of multicast filters that can be
* configured by the host.
*/
uint8_t npwrflts; /* bNumberPowerFilters, Contains the number of pattern filters that are
* available for causing wake-up of the host.
*/
uint8_t size; /* bFunctionLength, Size of this descriptor */
uint8_t type; /* bDescriptorType, USB_DESC_TYPE_CSINTERFACE */
uint8_t subtype; /* bDescriptorSubType, CDC_DSUBTYPE_ECM as defined in
* Table 25.
*/
uint8_t mac; /* iMACAddress, Index of the 48bit Ethernet MAC address
* string descriptor.
*/
uint8_t stats[4]; /* bmEthernetStatistics, Indicates which Ethernet
* statistics functions the device collects.
* See Table 42.
*/
uint8_t maxseg[2]; /* wMaxSegmentSize, The maximum segment size that the
* Ethernet device is capable of supporting.
*/
uint8_t nmcflts[2]; /* wNumberMCFilters, Contains the number of multicast
* filters that can be configured by the host.
*/
uint8_t npwrflts; /* bNumberPowerFilters, Contains the number of pattern
* filters that are available for causing wake-up of
* the host.
*/
};
#define SIZEOF_ECM_FUNCDESC 13
@ -853,26 +904,33 @@ struct cdc_atm_funcdesc_s
{
uint8_t size; /* bFunctionLength, Size of this descriptor */
uint8_t type; /* bDescriptorType, USB_DESC_TYPE_CSINTERFACE */
uint8_t subtype; /* bDescriptorSubType, CDC_DSUBTYPE_ATM as defined in Table 25 */
uint8_t endid; /* iEndSystemIdentifier, Index of End System Identifier string descriptor */
uint8_t datacaps; /* bmDataCapabilities, The ATM data types the device supports */
uint8_t devstats; /* bmATMDeviceStatistics, Indicates which optional statistics functions the
* device collects.
uint8_t subtype; /* bDescriptorSubType, CDC_DSUBTYPE_ATM as defined in
* Table 25.
*/
uint8_t mxseg2[2]; /* wType2MaxSegmentSize, The maximum segment size that the Type 2 device is
* capable of supporting.
uint8_t endid; /* iEndSystemIdentifier, Index of End System Identifier
* string descriptor.
*/
uint8_t mxseg3[2]; /* wType3MaxSegmentSize, The maximum segment size that the Type 3 device is
* capable of supporting
uint8_t datacaps; /* bmDataCapabilities, The ATM data types the device
* supports.
*/
uint8_t mxvc[2]; /* wMaxVC, The maximum number of simultaneous virtual circuits the device is
* capable of supporting
uint8_t devstats; /* bmATMDeviceStatistics, Indicates which optional
* statistics functions the device collects.
*/
uint8_t mxseg2[2]; /* wType2MaxSegmentSize, The maximum segment size that
* the Type 2 device is capable of supporting.
*/
uint8_t mxseg3[2]; /* wType3MaxSegmentSize, The maximum segment size that
* the Type 3 device is capable of supporting
*/
uint8_t mxvc[2]; /* wMaxVC, The maximum number of simultaneous virtual
* circuits the device is capable of supporting
*/
};
#define SIZEOF_ATM_FUNCDESC 12
/* Descriptor Data Structures ***************************************************************/
/* Descriptor Data Structures ************************************************/
/* Table 50: Line Coding Structure */
struct cdc_linecoding_s
@ -890,15 +948,15 @@ struct cdc_linecoding_s
struct cdc_linestatus_s
{
uint8_t size[2]; /* wLength, Size of this structure, in bytes */
uint8_t ringer[4]; /* dwRingerBitmap, Ringer Configuration bitmap for this line */
uint8_t ringer[4]; /* dwRingerBitmap, Ringer Conf bitmap for this line */
uint8_t line[4]; /* dwLineState, Defines current state of the line */
uint32_t call[1]; /* dwCallStateN, Defines current state of call N on the line */
uint32_t call[1]; /* dwCallStateN, Current state of call N on the line */
};
/* Messages are formatted as a standardized 8-byte header, followed by a variable-length
* data field. The header identifies the kind of notification, and the interface associated
* with the notification; it also indicates the length of the variable length portion of
* the message
/* Messages are formatted as a standardized 8-byte header, followed by a
* variable-length data field. The header identifies the kind of notification,
* and the interface associated with the notification; it also indicates the
* length of the variable length portion of the message
*/
struct cdc_notification_s
@ -918,12 +976,15 @@ struct cdc_notification_s
struct cdc_unitparm_s
{
uint8_t id; /* bEntityId, Unit ID */
uint8_t index; /* bParameterIndex, A zero based value indicating Unit parameter index */
uint8_t index; /* bParameterIndex, A zero based value indicating Unit
* parameter index
*/
};
/* Table 61: Power Management Pattern Filter Structure */
/* Notification Data Structures *************************************************************/
/* Notification Data Structures **********************************************/
/* Table 72: ConnectionSpeedChange Data Structure */
struct cdc_speedchange_s

View File

@ -55,6 +55,7 @@
#define NETDEV_PAN_FORMAT "pan%d"
#define NETDEV_WLAN_FORMAT "wlan%d"
#define NETDEV_WPAN_FORMAT "wpan%d"
#define NETDEV_MBIM_FORMAT "wwan%d"
#if defined(CONFIG_DRIVERS_IEEE80211) /* Usually also has CONFIG_NET_ETHERNET */
# define NETDEV_DEFAULT_FORMAT NETDEV_WLAN_FORMAT
@ -313,6 +314,11 @@ int netdev_register(FAR struct net_driver_s *dev, enum net_lltype_e lltype)
devfmt = NETDEV_TUN_FORMAT;
break;
#endif
case NET_LL_MBIM:
dev->d_llhdrlen = 0;
dev->d_pktsize = 1200;
devfmt = NETDEV_MBIM_FORMAT;
break;
default:
nerr("ERROR: Unrecognized link type: %d\n", lltype);