vpelletier / python-libusb1

Python ctype-based wrapper around libusb1
GNU Lesser General Public License v2.1
168 stars 65 forks source link

Send control request with invalid bmRequestType #56

Closed FFY00 closed 3 years ago

FFY00 commented 3 years ago

Hi, I need to send a control request with a invalid direction in bmRequestType.

The device I want to talk to is awful and requires me to send some requests with the device to host direction, how can I do this?

Since controlWrite sets the direction bit, I tried to use _controlTransfer directly, but I run into the following error.

Traceback (most recent call last):
  File "./MD800E.py", line 140, in <module>
    main()
  File "./MD800E.py", line 95, in main
    dev.request(_Request.REG_READ, 0x0000, 0x0000)
  File "./MD800E.py", line 65, in request
    self._dev._controlTransfer(
  File "/usr/lib/python3.8/site-packages/usb1/__init__.py", line 1466, in _controlTransfer
    mayRaiseUSBError(result)
  File "/usr/lib/python3.8/site-packages/usb1/__init__.py", line 133, in mayRaiseUSBError
    __raiseUSBError(value)
  File "/usr/lib/python3.8/site-packages/usb1/__init__.py", line 125, in raiseUSBError
    raise __STATUS_TO_EXCEPTION_DICT.get(value, __USBError)(value)
usb1.USBErrorIO: LIBUSB_ERROR_IO [-1]

Please find attached a capture of what my packets need to look like. Sorry for the zip, Github won't let me upload the capture directly.

md800e-512-384.zip

FFY00 commented 3 years ago

I managed to get it to work with _controlTransfer. Perhaps controlWrite could get a direction kw argument?

vpelletier commented 3 years ago

Hello,

Isn't controlRead what you need ? There are 2 differences between controlRead and controlWrite:

From what I understand from the capture, the setup transaction only has an IN data stage (device-to-host, which would be consistent with the bmRequestType flag), so it seems consistent. Or I'm missing something.

USB can be confusing at times, because at each protocol layer the directions can change.

FFY00 commented 3 years ago

Yes! My bad :blush: