eclipse-threadx / usbx

Eclipse ThreadX - USBX is a high-performance USB host, device, and on-the-go (OTG) embedded stack, that is fully integrated with Eclipse ThreadX RTOS
https://github.com/eclipse-threadx/rtos-docs/blob/main/rtos-docs/usbx/index.md
MIT License
157 stars 94 forks source link

USB host CDC-ECM functionality is not working for LTE module as USB CDC-ECM device #173

Open MaheshAvula-Alifsemi opened 2 months ago

MaheshAvula-Alifsemi commented 2 months ago

Hi,

I am working with the USBx CDC-ECM class in host mode. I have connected a USB device, which functions as a USB-to-Ethernet CDC-ECM adapter, to my target, which operates as a USB host.

The USB-to-Ethernet adapter (USB device) is enumerated on the host, and a network connection is established. An IP address is assigned to the host, and I can successfully ping the server IP from the client and vice versa.

We have another CDC-ECM USB device, which is an LTE module. When I connect the LTE module to the host, it enumerates successfully, but I don’t see any network connection notifications on the interrupt endpoint from the USB device. Since no network connection is established, the CDC-ECM link remains down, and my application thread keeps checking for the link to be up, resulting in an infinite loop.

The same device(LTE module) works on Linux, and after debugging, I found that the Linux host sends a class-specific request as a SET Ethernet Packet Filter to the device, which then acknowledges it. Following this, the LTE device sends network connection notifications on the interrupt endpoint, and everything functions correctly.

I was reviewing the USBX host CDC-ECM class code and noticed that it is not sending any class-specific requests to the device. The device may be expecting these requests from the host.

Below are the code change in the USBX host CDC-ECM class code to send the SET Ethernet Packet Filter request to the device, and device acknowledges it. Following this, the LTE device sends network connection notifications on the interrupt endpoint, and everything functions correctly.

--> ux_host_class_cdc_ecm_mac_address_get.c packt_filter = _ux_utility_memory_allocate(UX_SAFE_ALIGN, UX_CACHE_SAFE_MEMORY, 8); if (descriptor == UX_NULL) return(UX_MEMORY_INSUFFICIENT); / Create a transfer_request for the request. / transfer_request -> ux_transfer_request_data_pointer = packt_filter; transfer_request -> ux_transfer_request_requested_length = 0; transfer_request -> ux_transfer_request_function = USB_CDC_SET_ETHERNET_PACKET_FILTER; transfer_request -> ux_transfer_request_type = UX_REQUEST_OUT | UX_REQUEST_TYPE_CLASS | UX_REQUEST_TARGET_INTERFACE; transfer_request -> ux_transfer_request_value = USB_CDC_PACKET_TYPE_DIRECTED | USB_CDC_PACKET_TYPE_BROADCAST | USB_CDC_PACKET_TYPE_ALL_MULTICAST; transfer_request -> ux_transfer_request_index = cdc_ecm -> ux_host_class_cdc_ecm_interface_control -> ux_interface_descriptor.bInterfaceNumber; / Send request to HCD layer. / status = _ux_host_stack_transfer_request(transfer_request);

 /* Check for correct transfer. */
 if (status == UX_SUCCESS)
 {
      return status;
 }
 else
 {
     return status;
 }

I would like to know if this code change is acceptable. If not, could you please provide pointers on how to make it work?"

Regards Mahesh

MaheshAvula-Alifsemi commented 2 months ago

Hi @xiaocq2001 ,

Could you please help on this issue.