Skip to content

rndis error (AEGHB-1328) #619

@via1968

Description

@via1968

Answers checklist.

  • I have read the documentation ESP-IDF Programming Guide and the issue is not addressed there.
  • I have updated my IDF branch (master or release) to the latest version and checked that the issue is present there.
  • I have searched the issue tracker for a similar issue and not found a similar issue.

IDF version.

5.4.0

Espressif SoC revision.

esp32s3n8r8

Operating System used.

Windows

How did you build your project?

VS Code IDE

If you are using Windows, please specify command line type.

None

Development Kit.

esp32s3n8r8

Power Supply used.

USB

What is the expected behavior?

ESP32-S3 连接EC801E 4G 网卡,并开始 softAP,手机连接 softAP 进行网络测速: 上行(Mbps) 5.8 下行(Mbps) 7.9

What is the actual behavior?

usb_rndis_4g_module 示例运行过程中,虽然4g模块成功拨号获取了ip,AP热点也能正常被手机连接。但是在手机使用网络的途中ping task返回经常出现timeout,日志打印“E (12635) usbh_rndis: Error rndis packet message”,而手机那边的网速也只有200KB/s。这是为什么呢?

Steps to reproduce.

/*
 * SPDX-FileCopyrightText: 2024-2025 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Apache-2.0
*/
#include <stdio.h>
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#include "esp_err.h"
#include "esp_log.h"
#include "esp_check.h"
#include "esp_event.h"
#include "esp_netif.h"
#include "esp_event.h"
#include "dhcpserver/dhcpserver_options.h"
#include "ping/ping_sock.h"
#include "iot_usbh_rndis.h"
#include "app_wifi.h"
#include "iot_eth.h"
#include "iot_eth_netif_glue.h"
#include "iot_usbh_cdc.h"

static const char *TAG = "RNDIS_4G_MODULE";

static void on_ping_success(esp_ping_handle_t hdl, void *args)
{
    uint8_t ttl;
    uint16_t seqno;
    uint32_t elapsed_time, recv_len;
    ip_addr_t target_addr;
    esp_ping_get_profile(hdl, ESP_PING_PROF_SEQNO, &seqno, sizeof(seqno));
    esp_ping_get_profile(hdl, ESP_PING_PROF_TTL, &ttl, sizeof(ttl));
    esp_ping_get_profile(hdl, ESP_PING_PROF_IPADDR, &target_addr, sizeof(target_addr));
    esp_ping_get_profile(hdl, ESP_PING_PROF_SIZE, &recv_len, sizeof(recv_len));
    esp_ping_get_profile(hdl, ESP_PING_PROF_TIMEGAP, &elapsed_time, sizeof(elapsed_time));
    ESP_LOGI(TAG, "%"PRIu32" bytes from %s icmp_seq=%u ttl=%u time=%"PRIu32" ms\n", recv_len, ipaddr_ntoa(&target_addr), seqno, ttl, elapsed_time);
}

static void on_ping_timeout(esp_ping_handle_t hdl, void *args)
{
    uint16_t seqno;
    ip_addr_t target_addr;
    esp_ping_get_profile(hdl, ESP_PING_PROF_SEQNO, &seqno, sizeof(seqno));
    esp_ping_get_profile(hdl, ESP_PING_PROF_IPADDR, &target_addr, sizeof(target_addr));
    ESP_LOGW(TAG, "From %s icmp_seq=%u timeout\n", ipaddr_ntoa(&target_addr), seqno);
    // Users can add logic to handle ping timeout
    // Add Wait or Reset logic
}

static void iot_event_handle(void *arg, esp_event_base_t event_base, int32_t event_id, void *event_data)
{
    switch (event_id) {
    case IOT_ETH_EVENT_START:
        ESP_LOGI(TAG, "IOT_ETH_EVENT_START");
        break;
    case IOT_ETH_EVENT_STOP:
        ESP_LOGI(TAG, "IOT_ETH_EVENT_STOP");
        break;
    case IOT_ETH_EVENT_CONNECTED:
        ESP_LOGI(TAG, "IOT_ETH_EVENT_CONNECTED");
        break;
    case IOT_ETH_EVENT_DISCONNECTED:
        ESP_LOGI(TAG, "IOT_ETH_EVENT_DISCONNECTED");
        break;
    default:
        ESP_LOGI(TAG, "IOT_ETH_EVENT_UNKNOWN");
        break;
    }
}

void app_main(void)
{
    /* Initialize default TCP/IP stack */
    ESP_ERROR_CHECK(esp_netif_init());
    ESP_ERROR_CHECK(esp_event_loop_create_default());

    esp_event_handler_register(IOT_ETH_EVENT, ESP_EVENT_ANY_ID, iot_event_handle, NULL);

    // install usbh cdc driver with increased buffer sizes for better 4G module support
    usbh_cdc_driver_config_t config = {
        .task_stack_size = 1024 * 16,      // Increased stack size
        .task_priority = 6,                // Slightly higher priority
        .task_coreid = 0,
        .skip_init_usb_host_driver = false,
    };
    ESP_ERROR_CHECK(usbh_cdc_driver_install(&config));

    iot_usbh_rndis_config_t rndis_cfg = {
        .auto_detect = true,
        .auto_detect_timeout = pdMS_TO_TICKS(1000),
    };

    iot_eth_driver_t *rndis_handle = NULL;
    esp_err_t ret = iot_eth_new_usb_rndis(&rndis_cfg, &rndis_handle);
    if (ret != ESP_OK || rndis_handle == NULL) {
        ESP_LOGE(TAG, "Failed to create USB RNDIS driver");
        return;
    }

    iot_eth_config_t eth_cfg = {
        .driver = rndis_handle,
        .stack_input = NULL,
        .user_data = NULL,
    };

    iot_eth_handle_t eth_handle = NULL;
    ret = iot_eth_install(&eth_cfg, &eth_handle);
    if (ret != ESP_OK) {
        ESP_LOGE(TAG, "Failed to install USB RNDIS driver");
        return;
    }

    esp_netif_config_t netif_cfg = ESP_NETIF_DEFAULT_ETH();
    esp_netif_t *eth_netif = esp_netif_new(&netif_cfg);

    iot_eth_netif_glue_handle_t glue = iot_eth_new_netif_glue(eth_handle);
    if (glue == NULL) {
        ESP_LOGE(TAG, "Failed to create netif glue");
        return;
    }
    esp_netif_attach(eth_netif, glue);

    while (1) {
        ret = iot_eth_start(eth_handle);
        if (ret != ESP_OK) {
            ESP_LOGW(TAG, "Failed to start USB RNDIS driver, try again...");
            vTaskDelay(1000 / portTICK_PERIOD_MS);
            continue;
        }
        break;
    }

    app_wifi_main();
    while (1) {
        // esp_ping_start(ping);
        vTaskDelay(5000 / portTICK_PERIOD_MS);
    }
}

Debug Logs.

I (2971) iot_eth.netif_glue: Ethernet Got IP Address
I (2971) iot_eth.netif_glue: ~~~~~~~~~~~
I (2971) iot_eth.netif_glue: ETHIP:192.168.43.100
I (2972) iot_eth.netif_glue: ETHMASK:255.255.255.0
I (2977) iot_eth.netif_glue: ETHGW:192.168.43.1
I (2981) iot_eth.netif_glue: ~~~~~~~~~~~
I (5669) wifi:new:<1,1>, old:<1,1>, ap:<1,1>, sta:<255,255>, prof:1, snd_ch_cfg:0x0
I (5670) wifi:station: 9a:32:60:ea:44:a6 join, AID=1, bgn, 40U
I (5717) app wifi: station 9a:32:60:ea:44:a6 join, AID=1
I (5718) app wifi: ip_napt_enable
I (6083) esp_netif_lwip: DHCP server assigned IP to a client, IP is: 192.168.4.2
E (12635) usbh_rndis: Error rndis packet message type: 50e0945d
E (16671) usbh_rndis: Error rndis packet message type: 9e94146e
E (19788) usbh_rndis: Error rndis packet message type: 0b45ef7b
E (21877) usbh_rndis: Error rndis packet message type: 1fe79dc8
E (38480) usbh_rndis: Error rndis packet message type: 0767f717
E (38502) usbh_rndis: Error rndis packet message type: 1b8fc401
E (96907) usbh_rndis: Error rndis packet message type: 2969039f

More Information.

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions