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

USB packets that are 64 byte aligned in data size are not forwarded through the usbproxy on the GreatFET One #283

Closed
reverse0x90 opened this issue Sep 11, 2019 · 1 comment · Fixed by #287
Assignees
Labels
software technical support request for technical support

Comments

@reverse0x90
Copy link

reverse0x90 commented Sep 11, 2019

USB packets that are 64 byte aligned in data size (1024, 2048, etc) are not forwarded through the usbproxy (see example below):

65 bytes of data (packet gets forwarded through the usbproxy on the GreatFET)

ubuntu@ubuntu:~/Example$ cat usb_fail1.py 
import usb.core

VENDOR_ID = 0x18d1
PRODUCT_ID = 0xd00d

dev = usb.core.find(idVendor=VENDOR_ID, idProduct=PRODUCT_ID)

data = '\x41' * 65
dev.ctrl_transfer(0x21, 1, wValue=1, data_or_wLength=data)

ubuntu@ubuntu:~/Example$ sudo python3 usb_fail1.py 
Traceback (most recent call last):
  File "usb_fail1.py", line 10, in <module>
    dev.ctrl_transfer(0x21, 1, wValue=1, data_or_wLength=data)
  File "/usr/local/lib/python3.6/dist-packages/usb/core.py", line 1043, in ctrl_transfer
    self.__get_timeout(timeout))
  File "/usr/local/lib/python3.6/dist-packages/usb/backend/libusb1.py", line 883, in ctrl_transfer
    timeout))
  File "/usr/local/lib/python3.6/dist-packages/usb/backend/libusb1.py", line 595, in _check
    raise USBError(_strerror(ret), ret, _libusb_errno[ret])
usb.core.USBError: [Errno 32] Pipe error

64 bytes of data (operation times out and packet is not shown in GreatFET usbproxy output)

ubuntu@ubuntu:~/Example$ cat usb_fail2.py 
import usb.core

VENDOR_ID = 0x18d1
PRODUCT_ID = 0xd00d

dev = usb.core.find(idVendor=VENDOR_ID, idProduct=PRODUCT_ID)

data = '\x42' * 64
dev.ctrl_transfer(0x21, 1, wValue=1, data_or_wLength=data)


ubuntu@ubuntu:~/Example$ sudo python3 usb_fail2.py 
Traceback (most recent call last):
  File "usb_fail2.py", line 10, in <module>
    dev.ctrl_transfer(0x21, 1, wValue=1, data_or_wLength=data)
  File "/usr/local/lib/python3.6/dist-packages/usb/core.py", line 1043, in ctrl_transfer
    self.__get_timeout(timeout))
  File "/usr/local/lib/python3.6/dist-packages/usb/backend/libusb1.py", line 883, in ctrl_transfer
    timeout))
  File "/usr/local/lib/python3.6/dist-packages/usb/backend/libusb1.py", line 595, in _check
    raise USBError(_strerror(ret), ret, _libusb_errno[ret])
usb.core.USBError: [Errno 110] Operation timed out

GreatFET usbproxy output

ubuntu@ubuntu:~/Example/Facedancer$ gf info
Found a GreatFET One!
  Board ID: 0
  Firmware version: v2019.9.1
  Part ID: xxxxxxxxxxxxxx
  Serial number: xxxxxxxxxxxxxxxxxxxx
                 
ubuntu@ubuntu:~/Example/Facedancer$ sudo python3 facedancer-usbproxy.py -v 0x18d1 -p 0xd00d
NOTE: Skipping GoodFET-based devices, as pyserial isn't installed.
Using GreatDancer backend.
GreatDancer initialized
GreatDancer connected device Proxy'd USB Device
-- Reset requested! --
[20:38:46] <, standard request to device (GET_DESCRIPTOR: value=DEVICE descriptor (index=0x00), index=0, length=64)
[20:38:46] <: b'\x12\x01\x00\x02\x00\x00\x00@\xd1\x18\r\xd0\x00\x01\x01\x02\x03\x01'
-- Patched device descriptor. --
-- Reset requested! --
[20:38:46] <, standard request to device (GET_DESCRIPTOR: value=DEVICE descriptor (index=0x00), index=0, length=18)
[20:38:46] <: b'\x12\x01\x00\x02\x00\x00\x00@\xd1\x18\r\xd0\x00\x01\x01\x02\x03\x01'
-- Patched device descriptor. --
[20:38:46] <, standard request to device (GET_DESCRIPTOR: value=DEVICE_QUALIFIER descriptor (index=0x00), index=0, length=10)
[20:38:46] < --STALLED-- 
[20:38:46] <, standard request to device (GET_DESCRIPTOR: value=DEVICE_QUALIFIER descriptor (index=0x00), index=0, length=10)
[20:38:46] < --STALLED-- 
[20:38:46] <, standard request to device (GET_DESCRIPTOR: value=DEVICE_QUALIFIER descriptor (index=0x00), index=0, length=10)
[20:38:46] < --STALLED-- 
[20:38:46] <, standard request to device (GET_DESCRIPTOR: value=CONFIGURATION descriptor (index=0x00), index=0, length=9)
[20:38:46] <: b'\t\x02 \x00\x01\x01\x00\x80\x80'
[20:38:46] <, standard request to device (GET_DESCRIPTOR: value=CONFIGURATION descriptor (index=0x00), index=0, length=32)
[20:38:46] <: b'\t\x02 \x00\x01\x01\x00\x80\x80\t\x04\x00\x00\x02\xffB\x03\x04\x07\x05\x81\x02\x00\x02\x00\x07\x05\x01\x02\x00\x02\x01'
-- Storing configuration <USBConfiguration index=1 num_interfaces=1 attributes=0x80 max_power=256mA> --
[20:38:46] <, standard request to device (GET_DESCRIPTOR: value=STRING descriptor (index=0x00), index=0, length=255)
[20:38:46] <: ̄Љ
[20:38:46] <, standard request to device (GET_DESCRIPTOR: value=STRING descriptor (index=0x02), index=409, length=255)
[20:38:46] <: ̐Android
[20:38:46] <, standard request to device (GET_DESCRIPTOR: value=STRING descriptor (index=0x01), index=409, length=255)
[20:38:46] <: ̎Google
[20:38:46] <, standard request to device (GET_DESCRIPTOR: value=STRING descriptor (index=0x03), index=409, length=255)
[20:38:46] <: ̐1a2ed7f
[20:38:46] >, standard request to device (SET_CONFIGURATION: value=1, index=0, length=0)
-- Applying configuration <USBConfiguration index=1 num_interfaces=1 attributes=0x80 max_power=256mA> --
Setting up endpoint 1 (direction=1, transfer_type=2, max_packet_size=512)
Setting up endpoint 1 (direction=0, transfer_type=2, max_packet_size=512)
[20:38:46] <, standard request to device (GET_DESCRIPTOR: value=STRING descriptor (index=0x04), index=409, length=255)
[20:38:46] <: ̒fastboot
[20:38:51] >, class request to interface (class request 1: value=1, index=0, length=65)
[20:38:51] >: b'AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA'
@reverse0x90 reverse0x90 changed the title USB packets that are 64 byte aligned in data size are not forwarded though the usbproxy on the GreatFET One USB packets that are 64 byte aligned in data size are not forwarded through the usbproxy on the GreatFET One Sep 11, 2019
@Qyriad
Copy link
Contributor

Qyriad commented Sep 16, 2019

So Linux seems to actually violate the USB spec and not send short packets to terminate a control transfer if the length is a multiple of the max packet size, but some devices seem to be just fine with this, and act as if the transfer is complete once the specified amount of data has been received.
So, with #287, we now emulate this in GreatDancer and consider a control transfer to be completed either if the specified amount of data has been received, or if we receive a short packet, which seems to fix the issue.

Qyriad added a commit to Qyriad/libgreat that referenced this issue Sep 24, 2019
This fixes 64-byte-aligned USB0 commands, which were broken due to a Linux spec violation.
See greatscottgadgets/greatfet#283 for more details.
@straithe straithe added software technical support request for technical support labels Feb 19, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
software technical support request for technical support
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants