raspberrypi / tinyusb

MIT License
68 stars 18 forks source link

Usb: Host: TinyUSB is not checking number of configuration descriptors #8

Closed ismell closed 2 years ago

ismell commented 3 years ago

This is another bug that surfaced from raspberrypi/pico-sdk#361. When the device descriptor contains 0 for the number of configuration descriptors, TinYUSB continues to query the device for a configuration descriptor. We should modify TinyUSB to actually check the max descriptor field. See attached log.

hcd_edpt_open dev_addr 1, ep_addr 0
hw_endpoint_init dev 1 ep 0 out xfer 0
dev 1 ep 0 out setup buffer @ 0x50100180
endpoint control (0x50100100) <- 0xa0000180
Set dev addr 1 ep 0 = 0
Control Setup: R: DEVICE, T: STANDARD, D: IN, R: GET_DESCRIPTOR, V: DEVICE, DescIdx: 0, Idx: 0, Len: 18
80 06 00 01 00 00 12 00
hcd_setup_send dev_addr 1
hw_endpoint_init dev 1 ep 0 out xfer 0
dev 1 ep 0 out setup buffer @ 0x50100180
endpoint control (0x50100100) <- 0xa0000180
hcd_port_speed_get
full speed
Sent setup packet
on EP 00 with 8 bytes
hcd_edpt_xfer dev_addr 1, ep_addr 0x80, len 18
hw_endpoint_init dev 1 ep 0 in xfer 0
dev 1 ep 0 in setup buffer @ 0x50100180
endpoint control (0x50100100) <- 0xa0000180
hw_endpoint_xfer ep 0 in total_len 18, start=1
Start transfer of total len 18 on ep 0 in
Last buf (18 bytes left)
buffer control (0x50100080) <- 0x6412
hcd_port_speed_get
full speed
buf_status 0x00000001
rx 8 bytes (buf_ctrl 0x0000e008)
Short rx transfer
Completed transfer of 8 bytes on ep 0 in
on EP 80 with 8 bytes
Control data:
  0000:  12 01 00 02 FF FF FF 08 00 00 00 00 00 00 00 00  |................|
  0010:  00 00                                            |..|

<-- Device descriptor says 0 for number of configurations. We should stop enumeration.

Len: 18/18, Type: DEVICE, USB: 0x200, Class: 0xff, SubClass: 0xff, Protocol: 0xff, PacketSize: 8, VID: 0, PID: 0, Device: 0,
hcd_edpt_xfer dev_addr 1, ep_addr 0x0, len 0
hw_endpoint_init dev 1 ep 0 out xfer 0
dev 1 ep 0 out setup buffer @ 0x50100180
endpoint control (0x50100100) <- 0xa0000180
hw_endpoint_xfer ep 0 out total_len 0, start=1
Start transfer of total len 0 on ep 0 out
Last buf (0 bytes left)
buffer control (0x50100080) <- 0xe400
hcd_port_speed_get
full speed
buf_status 0x00000001
tx 0 bytes (buf_ctrl 0x00006000)
Completed transfer of 0 bytes on ep 0 out
on EP 00 with 0 bytes
Get 9 bytes of Configuration Descriptor
Control Setup: R: DEVICE, T: STANDARD, D: IN, R: GET_DESCRIPTOR, V: CONFIGURATION, DescIdx: 0, Idx: 0, Len: 9
80 06 00 02 00 00 09 00
hcd_setup_send dev_addr 1
hw_endpoint_init dev 1 ep 0 out xfer 0
dev 1 ep 0 out setup buffer @ 0x50100180
endpoint control (0x50100100) <- 0xa0000180
hcd_port_speed_get
full speed
Sent setup packet
on EP 00 with 8 bytes
hcd_edpt_xfer dev_addr 1, ep_addr 0x80, len 9
hw_endpoint_init dev 1 ep 0 in xfer 0
dev 1 ep 0 in setup buffer @ 0x50100180
endpoint control (0x50100100) <- 0xa0000180
hw_endpoint_xfer ep 0 in total_len 9, start=1
Start transfer of total len 9 on ep 0 in
Last buf (9 bytes left)
buffer control (0x50100080) <- 0x6409
hcd_port_speed_get
full speed
buf_status 0x00000001
rx 8 bytes (buf_ctrl 0x0000e008)
Short rx transfer
Completed transfer of 8 bytes on ep 0 in
on EP 80 with 8 bytes
Control data:
  0000:  09 02 99 00 04 01 00 A0 00                       |.........|
Len: 9/9, Type: CONFIGURATION,
hcd_edpt_xfer dev_addr 1, ep_addr 0x0, len 0
hw_endpoint_init dev 1 ep 0 out xfer 0
dev 1 ep 0 out setup buffer @ 0x50100180
endpoint control (0x50100100) <- 0xa0000180
hw_endpoint_xfer ep 0 out total_len 0, start=1
Start transfer of total len 0 on ep 0 out
Last buf (0 bytes left)
buffer control (0x50100080) <- 0xe400
lurch commented 3 years ago

@hathach I hope you don't mind me pinging you again, but is this issue also RP2040-specific, or related to upstream tinyusb too?

hathach commented 3 years ago

@hathach I hope you don't mind me pinging you again, but is this issue also RP2040-specific, or related to upstream tinyusb too?

no problem at all, feel free to do so when you need any of my feedback. I am a middle of something. Will check it out tomorrow or so.

hathach commented 3 years ago

I have two questions though

  1. Which device you are testing, I have never seen a device with zero configuration.
  2. Since device has zero configuration, why it response to GET_CONFIGURATION instead of stalling the request. Also the wTotalLength within the response configuration descriptor is also incorrect.
lurch commented 3 years ago

ping @ismell It would be good if you could review / verify / close some of your issues / PRs in this repo, in light of the updated TinyUSB version that's now used by the latest release of pico-sdk :slightly_smiling_face: