9

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.

Chimera
  • 5,884
  • 7
  • 49
  • 81

1 Answers1

8

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 )

Community
  • 1
  • 1
Pavan Manjunath
  • 27,404
  • 12
  • 99
  • 125
  • Thank you Pavan. That's what I figured the answer would be. It shouldn't be too difficult to just go ahead and use libusb. – Chimera Mar 05 '12 at 16:59
  • USB driver is an interesting piece! I've been very long wanting to write something on that. Would love to know your progress in this, Jim! – Pavan Manjunath Mar 05 '12 at 17:14
  • Pavan, I've managed to get a proof of concept tool to communicate with my USB device by using the libusb library. Works very well for HID class devices. Thank you again. – Chimera Mar 08 '12 at 16:48