Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(usb) compile tinyusb_net.c when RNDIS is enabled (IEC-96) #313

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
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
2 changes: 1 addition & 1 deletion expat/idf_component.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
version: "2.6.0"
version: "2.6.2"
description: "Expat - XML Parsing C Library"
url: https://github.com/espressif/idf-extra-components/tree/master/expat
dependencies:
Expand Down
6 changes: 3 additions & 3 deletions expat/port/include/expat_config.h
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@
#define PACKAGE_NAME "expat"

/* Define to the full name and version of this package. */
#define PACKAGE_STRING "expat 2.6.0"
#define PACKAGE_STRING "expat 2.6.2"

/* Define to the one symbol short name of this package. */
#define PACKAGE_TARNAME "expat"
Expand All @@ -76,13 +76,13 @@
#define PACKAGE_URL ""

/* Define to the version of this package. */
#define PACKAGE_VERSION "2.6.0"
#define PACKAGE_VERSION "2.6.2"

/* Define to 1 if you have the ANSI C header files. */
#define STDC_HEADERS 1

/* Version number of package */
#define VERSION "2.6.0"
#define VERSION "2.6.2"

/* whether byteorder is bigendian */
/* #undef WORDS_BIGENDIAN */
Expand Down
4 changes: 2 additions & 2 deletions expat/sbom_libexpat.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name: libexpat
version: 2.6.0
version: 2.6.2
cpe: cpe:2.3:a:libexpat_project:libexpat:{}:*:*:*:*:*:*:*
supplier: 'Organization: libexpat_project'
description: Fast streaming XML parser written in C99
url: https://github.com/libexpat/libexpat/
hash: 849da3e3fe727fccef5e96ef35482d66447f06a2
hash: fa75b96546c069d17b8f80d91e0f4ef0cde3790d
2 changes: 1 addition & 1 deletion usb/esp_tinyusb/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ if(CONFIG_TINYUSB_MSC_ENABLED)
)
endif() # CONFIG_TINYUSB_MSC_ENABLED

if(CONFIG_TINYUSB_NET_MODE_NCM)
if(CONFIG_TINYUSB_NET_MODE_NCM OR CONFIG_TINYUSB_NET_MODE_RNDIS OR CONFIG_TINYUSB_NET_MODE_ECM)
list(APPEND srcs
tinyusb_net.c
)
Expand Down
9 changes: 6 additions & 3 deletions usb/esp_tinyusb/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -259,12 +259,15 @@ menu "TinyUSB Stack"
help
Select network driver you want to use.

config TINYUSB_NET_MODE_ECM_RNDIS
bool "ECM/RNDIS"

config TINYUSB_NET_MODE_NCM
bool "NCM"

config TINYUSB_NET_MODE_RNDIS
bool "RNDIS"

config TINYUSB_NET_MODE_ECM
bool "ECM"

Comment on lines +265 to +270
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we keep it tha way it was? ECM+RNDIS together? There are 2 reasons for this:

  1. The TinyUSB driver has ECM+RNDIS protocol together
  2. We usually don't want to enable ECM and disalble RNDIS (or vice versa). RNDIS works with windows, while ECM workds with linux and macOS. Only with both we can support all operating systems

config TINYUSB_NET_MODE_NONE
bool "None"
endchoice
Expand Down
10 changes: 7 additions & 3 deletions usb/esp_tinyusb/include/tusb_config.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,12 @@ extern "C" {
# define CONFIG_TINYUSB_CUSTOM_CLASS_ENABLED 0
#endif

#ifndef CONFIG_TINYUSB_NET_MODE_ECM_RNDIS
# define CONFIG_TINYUSB_NET_MODE_ECM_RNDIS 0
#ifndef CONFIG_TINYUSB_NET_MODE_ECM
# define CONFIG_TINYUSB_NET_MODE_ECM 0
#endif

#ifndef CONFIG_TINYUSB_NET_MODE_RNDIS
# define CONFIG_TINYUSB_NET_MODE_RNDIS 0
#endif

#ifndef CONFIG_TINYUSB_NET_MODE_NCM
Expand Down Expand Up @@ -142,7 +146,7 @@ extern "C" {
#define CFG_TUD_HID CONFIG_TINYUSB_HID_COUNT
#define CFG_TUD_MIDI CONFIG_TINYUSB_MIDI_COUNT
#define CFG_TUD_CUSTOM_CLASS CONFIG_TINYUSB_CUSTOM_CLASS_ENABLED
#define CFG_TUD_ECM_RNDIS CONFIG_TINYUSB_NET_MODE_ECM_RNDIS
#define CFG_TUD_ECM_RNDIS (CONFIG_TINYUSB_NET_MODE_RNDIS || CONFIG_TINYUSB_NET_MODE_ECM)
#define CFG_TUD_NCM CONFIG_TINYUSB_NET_MODE_NCM
#define CFG_TUD_DFU CONFIG_TINYUSB_DFU_MODE_DFU
#define CFG_TUD_DFU_RUNTIME CONFIG_TINYUSB_DFU_MODE_DFU_RUNTIME
Expand Down
4 changes: 2 additions & 2 deletions usb/esp_tinyusb/tinyusb.c
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,8 @@ esp_err_t tinyusb_driver_install(const tinyusb_config_t *config)
if (config->configuration_descriptor) {
cfg_descriptor = config->configuration_descriptor;
} else {
// Default configuration descriptor is provided only for CDC, MSC and NCM classes
#if (CFG_TUD_HID > 0 || CFG_TUD_MIDI > 0 || CFG_TUD_CUSTOM_CLASS > 0 || CFG_TUD_ECM_RNDIS > 0 || CFG_TUD_DFU > 0 || CFG_TUD_DFU_RUNTIME > 0 || CFG_TUD_BTH > 0)
// Default configuration descriptor is provided only for CDC, MSC, ECM, RNDIS and NCM classes
#if (CFG_TUD_HID > 0 || CFG_TUD_MIDI > 0 || CFG_TUD_CUSTOM_CLASS > 0 || CFG_TUD_DFU > 0 || CFG_TUD_DFU_RUNTIME > 0 || CFG_TUD_BTH > 0)
ESP_RETURN_ON_FALSE(config->configuration_descriptor, ESP_ERR_INVALID_ARG, TAG, "Configuration descriptor must be provided for this device");
#else
cfg_descriptor = descriptor_cfg_kconfig;
Expand Down
8 changes: 8 additions & 0 deletions usb/esp_tinyusb/tinyusb_net.c
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,10 @@ const static int TX_FINISHED_BIT = BIT0;
static struct tinyusb_net_handle s_net_obj = { };
static const char *TAG = "tusb_net";

#if CONFIG_TINYUSB_NET_MODE_RNDIS || CONFIG_TINYUSB_NET_MODE_ECM
uint8_t tud_network_mac_address[6] = {0}; // for RNDIS (net_device.h, rndis_reports.c)
#endif

static void do_send_sync(void *ctx)
{
(void) ctx;
Expand Down Expand Up @@ -130,12 +134,16 @@ esp_err_t tinyusb_net_init(tinyusb_usbdev_t usb_dev, const tinyusb_net_config_t
s_net_obj.tx_buff_free_cb = cfg->free_tx_buffer;
s_net_obj.ctx = cfg->user_context;

#if CONFIG_TINYUSB_NET_MODE_RNDIS
memcpy(tud_network_mac_address, cfg->mac_addr, MAC_ADDR_LEN);
#elif CONFIG_TINYUSB_NET_MODE_ECM || CONFIG_TINYUSB_NET_MODE_NCM
const uint8_t *mac = &cfg->mac_addr[0];
snprintf(s_net_obj.mac_str, sizeof(s_net_obj.mac_str), "%02X%02X%02X%02X%02X%02X",
mac[0], mac[1], mac[2], mac[3], mac[4], mac[5]);
uint8_t mac_id = tusb_get_mac_string_id();
// Pass it to Descriptor control module
tinyusb_set_str_descriptor(s_net_obj.mac_str, mac_id);
#endif

s_net_obj.initialized = true;

Expand Down
30 changes: 21 additions & 9 deletions usb/esp_tinyusb/usb_descriptors.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
*/
#define _PID_MAP(itf, n) ((CFG_TUD_##itf) << (n))
#define USB_TUSB_PID (0x4000 | _PID_MAP(CDC, 0) | _PID_MAP(MSC, 1) | _PID_MAP(HID, 2) | \
_PID_MAP(MIDI, 3) ) //| _PID_MAP(AUDIO, 4) | _PID_MAP(VENDOR, 5) )
_PID_MAP(MIDI, 3) | _PID_MAP(AUDIO, 4) | _PID_MAP(NCM, 5) | _PID_MAP(ECM_RNDIS, 6))

/**** Kconfig driven Descriptor ****/

Expand Down Expand Up @@ -82,7 +82,7 @@ const char *descriptor_str_kconfig[] = {
"",
#endif

#if CONFIG_TINYUSB_NET_MODE_ECM_RNDIS || CONFIG_TINYUSB_NET_MODE_NCM
#if CONFIG_TINYUSB_NET_MODE_NCM || CONFIG_TINYUSB_NET_MODE_RNDIS || CONFIG_TINYUSB_NET_MODE_ECM
"USB net", // 6. NET Interface
"", // 7. MAC
#endif
Expand All @@ -105,7 +105,7 @@ enum {
ITF_NUM_MSC,
#endif

#if CFG_TUD_NCM
#if CFG_TUD_NCM || CFG_TUD_ECM_RNDIS
ITF_NUM_NET,
ITF_NUM_NET_DATA,
#endif
Expand All @@ -116,8 +116,14 @@ enum {
enum {
TUSB_DESC_TOTAL_LEN = TUD_CONFIG_DESC_LEN +
CFG_TUD_CDC * TUD_CDC_DESC_LEN +
CFG_TUD_MSC * TUD_MSC_DESC_LEN +
CFG_TUD_NCM * TUD_CDC_NCM_DESC_LEN
CFG_TUD_MSC * TUD_MSC_DESC_LEN
#if CONFIG_TINYUSB_NET_MODE_ECM
+ CFG_TUD_ECM_RNDIS * TUD_CDC_ECM_DESC_LEN
#elif CONFIG_TINYUSB_NET_MODE_RNDIS
+ CFG_TUD_ECM_RNDIS * TUD_RNDIS_DESC_LEN
#elif CONFIG_TINYUSB_NET_MODE_NCM
+ CFG_TUD_NCM * TUD_CDC_NCM_DESC_LEN
#endif
};

//------------- USB Endpoint numbers -------------//
Expand All @@ -138,7 +144,7 @@ enum {
EPNUM_MSC,
#endif

#if CFG_TUD_NCM
#if CFG_TUD_NCM || CFG_TUD_ECM_RNDIS
EPNUM_NET_NOTIF,
EPNUM_NET_DATA,
#endif
Expand All @@ -158,7 +164,7 @@ enum {
STRID_MSC_INTERFACE,
#endif

#if CFG_TUD_NCM
#if CFG_TUD_NCM || CFG_TUD_ECM_RNDIS
STRID_NET_INTERFACE,
STRID_MAC,
#endif
Expand All @@ -185,13 +191,19 @@ uint8_t const descriptor_cfg_kconfig[] = {
TUD_MSC_DESCRIPTOR(ITF_NUM_MSC, STRID_MSC_INTERFACE, EPNUM_MSC, 0x80 | EPNUM_MSC, 64), // highspeed 512
#endif

#if CFG_TUD_NCM
#if CONFIG_TINYUSB_NET_MODE_NCM
// Interface number, description string index, MAC address string index, EP notification address and size, EP data address (out, in), and size, max segment size.
TUD_CDC_NCM_DESCRIPTOR(ITF_NUM_NET, STRID_NET_INTERFACE, STRID_MAC, (0x80 | EPNUM_NET_NOTIF), 64, EPNUM_NET_DATA, (0x80 | EPNUM_NET_DATA), CFG_TUD_NET_ENDPOINT_SIZE, CFG_TUD_NET_MTU),
#elif CONFIG_TINYUSB_NET_MODE_RNDIS
// Interface number, string index, EP notification address and size, EP data address (out, in) and size.
TUD_RNDIS_DESCRIPTOR(ITF_NUM_NET, STRID_NET_INTERFACE, (0x80 | EPNUM_NET_NOTIF), 8, EPNUM_NET_DATA, (0x80 | EPNUM_NET_DATA), CFG_TUD_NET_ENDPOINT_SIZE),
#elif CONFIG_TINYUSB_NET_MODE_ECM
// Interface number, description string index, MAC address string index, EP notification address and size, EP data address (out, in), and size, max segment size.
TUD_CDC_ECM_DESCRIPTOR(ITF_NUM_NET, STRID_NET_INTERFACE, STRID_MAC, (0x80 | EPNUM_NET_NOTIF), 64, EPNUM_NET_DATA, (0x80 | EPNUM_NET_DATA), CFG_TUD_NET_ENDPOINT_SIZE, CFG_TUD_NET_MTU),
#endif
};

#if CFG_TUD_NCM
#if CFG_TUD_NCM || CFG_TUD_ECM_RNDIS
uint8_t tusb_get_mac_string_id(void)
{
return STRID_MAC;
Expand Down
Loading