8
votes

I'm researching ways to communicate with a USB device in Linux and would prefer to not write a Linux Kernel driver. I understand that libusb exists and is a user-land library that would work, but our embedded device doesn't support usbfs ( and would be really a pain to change kernels to add the support ).

So my question is basically this: Is it possible / advisable to communicate with a USB device by directly reading and writing to the /dev/USB or the udev file corresponding to the USB device thus bypassing the need for a custom Linux Driver and usbfs?

I'm hoping it's possible to communicate using the USB devices protocol just by reading / writing protocol packets directly through file-type read/write commands once the /dev/USB or udev device file is open.

Thoughts and suggestions please.

FOLLOW UP:

Since the USB device I needed to talk to is a USB HID class device, I was able to use libudev and the standard Linux USB HID RAW driver by reading / writing directly to /dev/hidraw0 ( or the appropriate /dev/hidraw device ). It wasn't necessary to write a custom driver for a simple USB HID device.

1

1 Answers

5
votes

Jim, I don't think you can escape the need to write a driver and just manage to read the USB file in /dev. Because who defines as to what should happen when you do a read() on the USB device file? And who defines what action should be initiated when you invoke sysioctl()? Your driver! In other words, the device files are themselves incapable of anything until they are supported by the underlying drivers. In fact, you can treat the device files to be an abstraction of the underlying driver! So, no driver, no use of device file :(

I suggest you go through the following articles about how to write a driver and also understand the USB internals-

  1. http://www.linux-usb.org/USB-guide/c15.html

  2. http://www.linuxjournal.com/article/4786 ( Slightly outdated )