Skip to content

Commit 1aaf6a1

Browse files
committed
usb: device_next: NCM driver for usb-next
USB NCM Ethernet driver implementation. Signed-off-by: Jukka Rissanen <[email protected]>
1 parent 9f60075 commit 1aaf6a1

File tree

7 files changed

+1462
-1
lines changed

7 files changed

+1462
-1
lines changed
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# Copyright (c) 2024 Nordic Semiconductor ASA
2+
# SPDX-License-Identifier: Apache-2.0
3+
4+
description: USB CDC NCM virtual Ethernet controller
5+
6+
compatible: "zephyr,cdc-ncm-ethernet"
7+
8+
include: ethernet-controller.yaml
9+
10+
properties:
11+
remote-mac-address:
12+
type: string
13+
required: true
14+
description: |
15+
Remote MAC address of the virtual Ethernet connection.
16+
Should not be the same as local-mac-address property.

include/zephyr/usb/class/usb_cdc.h

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,13 @@
2828
#define ACM_SUBCLASS 0x02
2929
#define ECM_SUBCLASS 0x06
3030
#define EEM_SUBCLASS 0x0c
31+
#define NCM_SUBCLASS 0x0d
3132

3233
/** Communications Class Protocol Codes */
3334
#define AT_CMD_V250_PROTOCOL 0x01
3435
#define EEM_PROTOCOL 0x07
3536
#define ACM_VENDOR_PROTOCOL 0xFF
37+
#define NCM_DATA_PROTOCOL 0x01
3638

3739
/**
3840
* @brief Data Class Interface Codes
@@ -50,6 +52,7 @@
5052
#define ACM_FUNC_DESC 0x02
5153
#define UNION_FUNC_DESC 0x06
5254
#define ETHERNET_FUNC_DESC 0x0F
55+
#define ETHERNET_FUNC_DESC_NCM 0x1a
5356

5457
/**
5558
* @brief PSTN Subclass Specific Requests
@@ -139,6 +142,22 @@
139142
#define SET_ETHERNET_PACKET_FILTER 0x43
140143
#define GET_ETHERNET_STATISTIC 0x44
141144

145+
/**
146+
* @brief Class-Specific Request Codes for NCM subclass
147+
* @note NCM100.pdf, 6.2, Table 6-2
148+
*/
149+
#define GET_NTB_PARAMETERS 0x80
150+
#define GET_NET_ADDRESS 0x81
151+
#define SET_NET_ADDRESS 0x82
152+
#define GET_NTB_FORMAT 0x83
153+
#define SET_NTB_FORMAT 0x84
154+
#define GET_NTB_INPUT_SIZE 0x85
155+
#define SET_NTB_INPUT_SIZE 0x86
156+
#define GET_MAX_DATAGRAM_SIZE 0x87
157+
#define SET_MAX_DATAGRAM_SIZE 0x88
158+
#define GET_CRC_MODE 0x89
159+
#define SET_CRC_MODE 0x8A
160+
142161
/** Ethernet Packet Filter Bitmap */
143162
#define PACKET_TYPE_MULTICAST 0x10
144163
#define PACKET_TYPE_BROADCAST 0x08
@@ -210,4 +229,13 @@ struct cdc_ecm_descriptor {
210229
uint8_t bNumberPowerFilters;
211230
} __packed;
212231

232+
/** Ethernet Network Control Model (NCM) Descriptor */
233+
struct cdc_ncm_descriptor {
234+
uint8_t bFunctionLength;
235+
uint8_t bDescriptorType;
236+
uint8_t bDescriptorSubtype;
237+
uint16_t bcdNcmVersion;
238+
uint8_t bmNetworkCapabilities;
239+
} __packed;
240+
213241
#endif /* ZEPHYR_INCLUDE_USB_CLASS_USB_CDC_H_ */

subsys/net/lib/config/Kconfig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ if NET_CONFIG_SETTINGS
2424

2525
config NET_CONFIG_AUTO_INIT
2626
bool "Init networking support automatically during device startup"
27-
default n if USB_DEVICE_NETWORK
27+
default n if USB_DEVICE_NETWORK || USBD_CDC_ECM_CLASS || USBD_CDC_NCM_CLASS
2828
default y
2929
help
3030
If this option is set, then the networking system is automatically

subsys/usb/device_next/CMakeLists.txt

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,15 @@ zephyr_library_sources_ifdef(
4141
class/usbd_cdc_ecm.c
4242
)
4343

44+
zephyr_include_directories_ifdef(
45+
CONFIG_USBD_CDC_NCM_CLASS
46+
${ZEPHYR_BASE}/drivers/ethernet
47+
)
48+
zephyr_library_sources_ifdef(
49+
CONFIG_USBD_CDC_NCM_CLASS
50+
class/usbd_cdc_ncm.c
51+
)
52+
4453
zephyr_library_sources_ifdef(
4554
CONFIG_USBD_BT_HCI
4655
class/bt_hci.c

subsys/usb/device_next/class/Kconfig

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
rsource "Kconfig.loopback"
66
rsource "Kconfig.cdc_acm"
77
rsource "Kconfig.cdc_ecm"
8+
rsource "Kconfig.cdc_ncm"
89
rsource "Kconfig.bt"
910
rsource "Kconfig.msc"
1011
rsource "Kconfig.uac2"
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
# Copyright (c) 2024 Nordic Semiconductor ASA
2+
#
3+
# SPDX-License-Identifier: Apache-2.0
4+
5+
config USBD_CDC_NCM_CLASS
6+
bool "USB CDC NCM implementation [EXPERIMENTAL]"
7+
default y
8+
depends on NET_L2_ETHERNET
9+
depends on DT_HAS_ZEPHYR_CDC_NCM_ETHERNET_ENABLED
10+
select EXPERIMENTAL
11+
help
12+
USB CDC Network Control Model (NCM) implementation
13+
14+
if USBD_CDC_NCM_CLASS
15+
16+
config USBD_CDC_NCM_MAX_DGRAM_PER_NTB
17+
int "Max number of received datagrams per NTB"
18+
range 0 $(UINT16_MAX)
19+
default 2
20+
help
21+
How many datagrams we are able to receive per NTB.
22+
23+
config USBD_CDC_NCM_SUPPORT_NTB32
24+
bool "Support NTB32 format"
25+
help
26+
Enable support for NTB32 format which allows larger
27+
packet sizes.
28+
29+
module = USBD_CDC_NCM
30+
module-str = usbd cdc_ncm
31+
default-count = 1
32+
source "subsys/logging/Kconfig.template.log_config"
33+
rsource "Kconfig.template.instances_count"
34+
35+
endif

0 commit comments

Comments
 (0)