LibUSB Port : Quarter Term

Blog post by akshay1994 on Wed, 2014-06-11 10:57

Hello Everyone!

Here is an update on the port.

I decided to use usb_raw instead of USBKit. Majority of functionalities are now implemented, leaving the specifics of Error Handling, etc.

Below I mention some of my design choices, the reasons for them, and problems faced.

  1. Getting the device configuration descriptor using a control transfer, instead of building it up using configuration, interface, endpoint and generic descriptors.
    While parsing the configuration descriptor, the Bus Manager module skips over vendor specific descriptors following the configuration descriptor, and clubs those following interfaces and endpoints into a single list for that interface. I’m still iterating over all the interfaces, endpoints, for making translation-hashes, something which we can avoid by writing a parser for the fetched configuration, if required.
  2. Claim/Release Interface. I have implemented this using a list of claimed interfaces, kept in the USBDevice class (giving a pseudo-functionality to all libusb handles). This functionality should actually be implemented at a layer below, in the Bus Manager module, to provide exclusive access to interfaces, and prevent change of configurations/ alternate settings while someone has claimed an interface.
  3. Getting String Descriptors. This still fails for UHCI devices, and I am unable to find a reason for this. For EHCI, I was able to find the reason and have submitted a patch for this. I have opened a ticket for both the cases.
  4. I’m using BUSBRoster to enumerate and handle addition/removal of USB Devices. We would probably like to do away with this, given that we are not using USBKit.
  5. Release interface requires setting the alternate setting of the interface to 0. Doing this hangs the device, and no further transfers can be queued for the device. And the weird part is that the ioctl call to set the alternate setting, succeeds without any errors.
  6. Mass Storage Tests are now working.

Thanks a lot for giving me an opportunity to work on this project.
Feel free to provide your feedback.

______
[1] Link to github repository : https://github.com/akshay1994/libusb
[2] Link to Ticket [EHCI] : https://dev.haiku-os.org/ticket/10867
[3] Link to Ticket [UHCI] : https://dev.haiku-os.org/ticket/10915

Comments

Re: LibUSB Port : Quarter Term

Are you working on any detailed docs that will help others write drivers for USB devices.

I have a set of USB speakers that are suppose to be simple to use but don't presently work with Haiku. I would love to write a simple 16 bit stereo drive for them.

But I can't make out heads or tails how USB drivers are suppose to work. I have written/hacked/been coached into getting a working parallel port sound driver. I have gotten updated/hacked/been coached to get ram disk driver working but USB is like black magic to me.

PS. Don't try too hard, at 58 I maybe too old to learn this stuff.

Re: LibUSB Port : Quarter Term

Hi,

The "USB in a nutshell" book helps a lot in understanding the USB protocol. With our APIs being rather low level, it's easy to map them to the concepts explained in that book, which is available for free in online form.

That being said, we already have a driver for usb audio devices. The problem is usb audio needs isosynchronous transfers, and only our OHCI driver implements that. Unfortunately, modern computers come with UHCI and EHCI ports, but rarely OHCI.

Re: LibUSB Port : Quarter Term

Thank you for your contribution to the Haiku Project !!!
:-)

Regards