2

I have a USB-Device that I would like to send some bytes to.

lsusb
Bus 001 Device 005: ID 04b4:0a0a Cypress Semiconductor Corp.

With Wireshark and usbmon, I figured, that a certain byte sequence leads to the desired behaviour(it unlocks a physical lock). Now I would like to copy this and send it myself. Therefore I tried to create a binary file and write it on the bus like this:

cat byteFile > /dev/bus/usb/001/005

But I get the following error:

cat: write error: Invalid argument

Now it seems that it is not possible to write bytes on "raw" USB-Devices, but I did not find the correct(or generic) approach to do this. How can I send the byte sequence from the file to the USB-Device? I would be happy to get this running in python/java or bash if possible. Such that I can later use it in my program. -> No GUI-application ;-)

Dijkgraaf
  • 11,049
  • 17
  • 42
  • 54
Salocin
  • 393
  • 6
  • 17

1 Answers1

2

You cannot send raw bytes to a USB device. Intead you send URB (that is USB Request Blocks) to a USB endpoint.

With usbmon you can discover that endpoint and what are the parameters and payload of the URB, and then replicate that from your program by using libusb.

But libusb is a C library to access raw USB devices, but I am not aware of any way to use it directly from the command line. My advice is to write a simple C program that sends the data you want to the proper endpoint and just call it from your script.

rodrigo
  • 94,151
  • 12
  • 143
  • 190
  • @Salocin: I'm not familiar with PyUSB, but it looks like a `libusb` wrapper or reimplementation in Python, so I think it should work. – rodrigo Jan 30 '18 at 09:35
  • 1
    it did work.. I just copied the URB setup part of wireshark and reused them as arguments.. the locks open and close :) thank you! – Salocin Jan 30 '18 at 12:44
  • For anyone to find more details: https://stackoverflow.com/questions/37943825/pyusb-send-hid-report – Salocin Jan 30 '18 at 12:59