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 enumeration stage error for some device (IDFGH-9778) #11113

Merged
merged 1 commit into from
Apr 19, 2023

Conversation

20051231
Copy link
Contributor

@20051231 20051231 commented Apr 3, 2023

Fix enumeration process crashed with stall status when enumerating devices which return bConfigurationValue with non standard value in the configuration description.

I encounter the bug when I try to connect a serial device from Netchip Technology. The device responses the request for first configuration with bConfigurationValue = 2. But in current code, the config_num is hardcoded to be ENUM_CONFIG_INDEX + 1 which is 1.

❯ lsusb -vd 0525:a4a7

Bus 001 Device 050: ID 0525:a4a7 Netchip Technology, Inc. Linux-USB Serial Gadget (CDC ACM mode)
Couldn't open device, some information will be missing
Device Descriptor:
  bLength                18
  bDescriptorType         1
  bcdUSB               2.00
  bDeviceClass            2 Communications
  bDeviceSubClass         0 
  bDeviceProtocol         0 
  bMaxPacketSize0        64
  idVendor           0x0525 Netchip Technology, Inc.
  idProduct          0xa4a7 Linux-USB Serial Gadget (CDC ACM mode)
  bcdDevice           24.18
  iManufacturer           1 Linux 2.6.39 with atmel_usba_udc
  iProduct                2 Gadget Serial v2.4
  iSerial                 0 
  bNumConfigurations      1
  Configuration Descriptor:
    bLength                 9
    bDescriptorType         2
    wTotalLength       0x004b
    bNumInterfaces          2
    bConfigurationValue     2
    iConfiguration          3 
    bmAttributes         0xc0
      Self Powered
    MaxPower                2mA
    Interface Association:
      bLength                 8
      bDescriptorType        11
      bFirstInterface         0
      bInterfaceCount         2
      bFunctionClass          2 Communications
      bFunctionSubClass       2 Abstract (modem)
      bFunctionProtocol       1 AT-commands (v.25ter)
      iFunction               6 
    Interface Descriptor:
      bLength                 9
      bDescriptorType         4
      bInterfaceNumber        0
      bAlternateSetting       0
      bNumEndpoints           1
      bInterfaceClass         2 Communications
      bInterfaceSubClass      2 Abstract (modem)
      bInterfaceProtocol      1 AT-commands (v.25ter)
      iInterface              4 
      CDC Header:
        bcdCDC               1.10
      CDC Call Management:
        bmCapabilities       0x00
        bDataInterface          1
      CDC ACM:
        bmCapabilities       0x02
          line coding and serial state
      CDC Union:
        bMasterInterface        0
        bSlaveInterface         1 
      Endpoint Descriptor:
        bLength                 7
        bDescriptorType         5
        bEndpointAddress     0x83  EP 3 IN
        bmAttributes            3
          Transfer Type            Interrupt
          Synch Type               None
          Usage Type               Data
        wMaxPacketSize     0x000a  1x 10 bytes
        bInterval               9
    Interface Descriptor:
      bLength                 9
      bDescriptorType         4
      bInterfaceNumber        1
      bAlternateSetting       0
      bNumEndpoints           2
      bInterfaceClass        10 CDC Data
      bInterfaceSubClass      0 
      bInterfaceProtocol      0 
      iInterface              5 
      Endpoint Descriptor:
        bLength                 7
        bDescriptorType         5
        bEndpointAddress     0x81  EP 1 IN
        bmAttributes            2
          Transfer Type            Bulk
          Synch Type               None
          Usage Type               Data
        wMaxPacketSize     0x0200  1x 512 bytes
        bInterval               0
      Endpoint Descriptor:
        bLength                 7
        bDescriptorType         5
        bEndpointAddress     0x02  EP 2 OUT
        bmAttributes            2
          Transfer Type            Bulk
          Synch Type               None
          Usage Type               Data
        wMaxPacketSize     0x0200  1x 512 bytes
        bInterval               0

Here is the pcapng when I connect the device into PC.
usbmon.zip

@CLAassistant
Copy link

CLAassistant commented Apr 3, 2023

CLA assistant check
All committers have signed the CLA.

@espressif-bot espressif-bot added the Status: Opened Issue is new label Apr 3, 2023
@github-actions github-actions bot changed the title Fix usb enumeration stage error for some device Fix usb enumeration stage error for some device (IDFGH-9778) Apr 3, 2023
@Alvin1Zhang
Copy link
Collaborator

Thanks for your contribution.

@roma-jam
Copy link
Collaborator

roma-jam commented Apr 5, 2023

Hi @20051231,
Thanks for the PR.

There is another ticket here which is also related to the configuration value.
For fully support the variety of configurations there should be a way to choose preferable one to work with and this option should also depend on bNumConfigurations value from device descriptor.

@espressif-bot espressif-bot added Status: Selected for Development Issue is selected for development and removed Status: Opened Issue is new labels Apr 11, 2023
@Dazza0 Dazza0 self-requested a review April 17, 2023 08:47
Copy link
Contributor

@Dazza0 Dazza0 left a comment

Choose a reason for hiding this comment

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

@20051231 Thank you for your contribution, Changes LGTM. I'll add an extra commit to update some comments and docs.

@Dazza0
Copy link
Contributor

Dazza0 commented Apr 17, 2023

sha=9d1c8f4f1815ce1d4bcea32ab7ef2cb830e90a08

@Dazza0 Dazza0 added the PR-Sync-Merge Pull request sync as merge commit label Apr 17, 2023
@espressif-bot espressif-bot added Status: In Progress Work is in progress Resolution: NA Issue resolution is unavailable Status: Done Issue is done internally Resolution: Done Issue is done internally and removed Status: Selected for Development Issue is selected for development Status: In Progress Work is in progress Resolution: NA Issue resolution is unavailable labels Apr 18, 2023
espressif-bot pushed a commit that referenced this pull request Apr 19, 2023
…eration

This commit updates some comments and documentation regarding changes made in
PR #11113.
@espressif-bot espressif-bot merged commit 9d1c8f4 into espressif:master Apr 19, 2023
espressif-bot pushed a commit that referenced this pull request May 5, 2023
…eration

This commit updates some comments and documentation regarding changes made in
PR #11113.
espressif-bot pushed a commit that referenced this pull request May 14, 2023
…eration

This commit updates some comments and documentation regarding changes made in
PR #11113.
espressif-bot pushed a commit that referenced this pull request Jun 14, 2023
…eration

This commit updates some comments and documentation regarding changes made in
PR #11113.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
PR-Sync-Merge Pull request sync as merge commit Resolution: Done Issue is done internally Status: Done Issue is done internally
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants