Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
90 changes: 83 additions & 7 deletions include/zephyr/usb/class/usb_cdc.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

/*
* Copyright (c) 2017 PHYTEC Messtechnik GmbH
* Copyright (c) 2025 - 2026 NXP
*
* SPDX-License-Identifier: Apache-2.0
*/
Expand Down Expand Up @@ -69,13 +70,22 @@
* @brief PSTN Subclass Class-Specific Notification Codes
* @note PSTN120.pdf, 6.5, Table 30
*/
#define USB_CDC_NETWORK_CONNECTION 0x00
#define USB_CDC_RESPONSE_AVAILABLE 0x01
#define USB_CDC_AUX_JACK_HOOK_STATE 0x08
#define USB_CDC_RING_DETECT 0x09
#define USB_CDC_SERIAL_STATE 0x20
#define USB_CDC_CALL_STATE_CHANGE 0x28
#define USB_CDC_LINE_STATE_CHANGE 0x23
/** Network connection notification */
#define USB_CDC_NETWORK_CONNECTION 0x00
/** Response available notification */
#define USB_CDC_RESPONSE_AVAILABLE 0x01
/** Auxiliary jack hook state notification */
#define USB_CDC_AUX_JACK_HOOK_STATE 0x08
/** Ring detect notification */
#define USB_CDC_RING_DETECT 0x09
/** Serial state notification */
#define USB_CDC_SERIAL_STATE 0x20
/** Line state change notification */
#define USB_CDC_LINE_STATE_CHANGE 0x23
/** Call state change notification */
#define USB_CDC_CALL_STATE_CHANGE 0x28
/** Connection speed change notification */
#define USB_CDC_CONNECTION_SPEED_CHANGE 0x2A

/**
* @brief PSTN UART State Bitmap Values
Expand Down Expand Up @@ -165,6 +175,72 @@
#define PACKET_TYPE_ALL_MULTICAST 0x02
#define PACKET_TYPE_PROMISCUOUS 0x01

/**
* @brief ECM Subclass Ethernet Statistics Feature Selector Codes
* @note ECM120.pdf, 6.2.5, Table 9
*/

/** Reserved for future use */
#define USB_CDC_ECM_STAT_RESERVED 0x00
/** Frames transmitted without errors */
#define USB_CDC_ECM_STAT_XMIT_OK 0x01
/** Frames received without errors */
#define USB_CDC_ECM_STAT_RCV_OK 0x02
/** Frames not transmitted, or transmitted with errors */
#define USB_CDC_ECM_STAT_XMIT_ERROR 0x03
/** Frames received with errors */
#define USB_CDC_ECM_STAT_RCV_ERROR 0x04
/** Frames missed, no buffers */
#define USB_CDC_ECM_STAT_RCV_NO_BUFFER 0x05
/** Directed bytes transmitted without errors */
#define USB_CDC_ECM_STAT_DIRECTED_BYTES_XMIT 0x06
/** Directed frames transmitted without errors */
#define USB_CDC_ECM_STAT_DIRECTED_FRAMES_XMIT 0x07
/** Multicast bytes transmitted without errors */
#define USB_CDC_ECM_STAT_MULTICAST_BYTES_XMIT 0x08
/** Multicast frames transmitted without errors */
#define USB_CDC_ECM_STAT_MULTICAST_FRAMES_XMIT 0x09
/** Broadcast bytes transmitted without errors */
#define USB_CDC_ECM_STAT_BROADCAST_BYTES_XMIT 0x0A
/** Broadcast frames transmitted without errors */
#define USB_CDC_ECM_STAT_BROADCAST_FRAMES_XMIT 0x0B
/** Directed bytes received without errors */
#define USB_CDC_ECM_STAT_DIRECTED_BYTES_RCV 0x0C
/** Directed frames received without errors */
#define USB_CDC_ECM_STAT_DIRECTED_FRAMES_RCV 0x0D
/** Multicast bytes received without errors */
#define USB_CDC_ECM_STAT_MULTICAST_BYTES_RCV 0x0E
/** Multicast frames received without errors */
#define USB_CDC_ECM_STAT_MULTICAST_FRAMES_RCV 0x0F
/** Broadcast bytes received without errors */
#define USB_CDC_ECM_STAT_BROADCAST_BYTES_RCV 0x10
/** Broadcast frames received without errors */
#define USB_CDC_ECM_STAT_BROADCAST_FRAMES_RCV 0x11
/** Frames received with circular redundancy check (CRC) or frame check sequence (FCS) error */
#define USB_CDC_ECM_STAT_RCV_CRC_ERROR 0x12
/** Length of transmit queue */
#define USB_CDC_ECM_STAT_TRANSMIT_QUEUE_LENGTH 0x13
/** Frames received with alignment error */
#define USB_CDC_ECM_STAT_RCV_ERROR_ALIGNMENT 0x14
/** Frames transmitted with one collision */
#define USB_CDC_ECM_STAT_XMIT_ONE_COLLISION 0x15
/** Frames transmitted with more than one collision */
#define USB_CDC_ECM_STAT_XMIT_MORE_COLLISIONS 0x16
/** Frames transmitted after deferral */
#define USB_CDC_ECM_STAT_XMIT_DEFERRED 0x17
/** Frames not transmitted due to collisions */
#define USB_CDC_ECM_STAT_XMIT_MAX_COLLISIONS 0x18
/** Frames not received due to overrun */
#define USB_CDC_ECM_STAT_RCV_OVERRUN 0x19
/** Frames not transmitted due to underrun */
#define USB_CDC_ECM_STAT_XMIT_UNDERRUN 0x1A
/** Frames transmitted with heartbeat failure */
#define USB_CDC_ECM_STAT_XMIT_HEARTBEAT_FAILURE 0x1B
/** Times carrier sense signal lost during transmission */
#define USB_CDC_ECM_STAT_XMIT_TIMES_CRS_LOST 0x1C
/** Late collisions detected */
#define USB_CDC_ECM_STAT_XMIT_LATE_COLLISIONS 0x1D

/** Header Functional Descriptor */
struct cdc_header_descriptor {
uint8_t bFunctionLength;
Expand Down
5 changes: 5 additions & 0 deletions subsys/usb/host/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,11 @@ zephyr_library_sources_ifdef(
usbh_shell.c
)

zephyr_library_sources_ifdef(
CONFIG_USBH_CDC_ECM_CLASS
class/usbh_cdc_ecm.c
)

zephyr_library_sources_ifdef(
CONFIG_USBH_VIDEO_CLASS
class/usbh_uvc.c
Expand Down
1 change: 1 addition & 0 deletions subsys/usb/host/class/Kconfig
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# SPDX-FileCopyrightText: Copyright Nordic Semiconductor ASA
# SPDX-License-Identifier: Apache-2.0

rsource "Kconfig.cdc_ecm"
rsource "Kconfig.uvc"
90 changes: 90 additions & 0 deletions subsys/usb/host/class/Kconfig.cdc_ecm
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
# SPDX-FileCopyrightText: Copyright (c) 2025 - 2026 NXP
# SPDX-License-Identifier: Apache-2.0

config USBH_CDC_ECM_CLASS
bool "USB Communication Device Class - Ethernet Control Mode (CDC-ECM) support [EXPERIMENTAL]"
select EXPERIMENTAL
select NET_L2_ETHERNET
help
USB Host Communication Device Class - Ethernet Control Mode (CDC-ECM)
implementation. This allows using USB ECM devices (such as USB Ethernet
adapters) as network interfaces.

if USBH_CDC_ECM_CLASS

config USBH_CDC_ECM_ETH_DRV_NAME
string "Ethernet interface name prefix"
default "zeth"
help
This option sets the driver name and name of the network interface
in your host system. If there are multiple network interfaces defined,
then this value is used as a prefix and use "(usbh_cdc_ecm)" as suffix
and the interface names will be "zeth0 (usbh_cdc_ecm)",
"zeth1 (usbh_cdc_ecm)", etc.

config USBH_CDC_ECM_MAX_SEGMENT_SIZE
int "Maximum Ethernet frame size"
default 1514
help
Maximum Ethernet frame size excluding FCS.
- 60: Minimum frame
- 1514: Standard Ethernet (MTU 1500)

Actual size negotiated via wMaxSegmentSize in ECM descriptor.
FCS is handled by USB device, not included in transfers.
Comment thread
D-Veda marked this conversation as resolved.

config USBH_CDC_ECM_MAX_LANGS
int "Maximum language IDs to query"
default 4
range 1 16
help
Buffer size for USB language IDs when retrieving MAC address.
Driver tries default LANGID first, then queries alternatives.
Most devices support 1-2 languages, default 4 is sufficient.

config USBH_CDC_ECM_DEFAULT_MAC_ADDR_UNICODE_LANGID
hex "Default language ID for MAC address"
default 0x0409
help
USB LANGID for MAC address string descriptor.
Falls back to device-supported languages if unsupported.

Common: 0x0409 (English US), 0x0804 (Chinese Simplified).

config USBH_CDC_ECM_MAX_MULTICAST_FILTERS
int "Maximum number of multicast filters"
default 32
range 4 256
help
Maximum multicast MAC addresses tracked per CDC-ECM instance.
Sent to USB device via SET_ETHERNET_MULTICAST_FILTERS request.

Memory per instance: N * 6 bytes
- 32 filters: 192 bytes
- 64 filters: 384 bytes
- 128 filters: 768 bytes

Actual filters sent to device limited by wNumberMCFilters in
ECM functional descriptor. Most devices support 16-64 filters.

config USBH_CDC_ECM_TX_PIPELINE_DEPTH
int "TX pipeline depth"
default 1
help
Concurrent bulk OUT transfers. Higher values improve throughput
at the cost of memory.

config USBH_CDC_ECM_RX_PIPELINE_DEPTH
int "RX pipeline depth"
default 1
help
Concurrent bulk IN transfers. Higher values reduce packet loss
at the cost of memory.

module = USBH_CDC_ECM
module-str = "usbh cdc_ecm"
default-count = 1
source "subsys/logging/Kconfig.template.log_config"
source "subsys/usb/common/Kconfig.template.instances_count"

endif # USBH_CDC_ECM_CLASS
Loading
Loading