LibUSB Port : Quarter Term

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

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