news.volyx.in

USB for Software Developers: An introduction to writing userspace USB drivers (werwolv.net)

411 points by WerWolv · 144 days ago · 48 comments on HN

Article summary

The article provides an introduction to writing userspace USB drivers, explaining how to use the libusb library to communicate with USB devices without needing to write kernel code. It uses an Android phone in Bootloader mode as an example device and demonstrates how to enumerate the device, send requests, and retrieve descriptors. The article aims to show that writing a driver for a USB device is not much more difficult than writing an application that uses sockets. The libusb library provides a simple API for communicating with USB devices from userspace.

Main themes

  • USB drivers
  • Userspace programming
  • libusb library
  • Device enumeration
  • Descriptor retrieval
  • Kernel vs userspace

What commenters say

  • Writing a userspace driver is a viable alternative to kernel drivers, offering easier development and debugging, as well as improved security.
  • Some argue that certain subsystems, such as networking, should be implemented in userspace to reduce kernel overhead and improve performance.
  • Others believe that kernel drivers are still necessary for certain devices and that userspace drivers may not be suitable for all use cases.
  • The use of libusb and other userspace libraries can simplify the development of custom USB devices and protocols, but may require additional work to integrate with existing systems.
  • Some commenters have successfully used userspace drivers for specific devices, such as UVC devices, and advocate for their use in certain situations.
  • There are differing opinions on the use of trailing return types in C++ code, with some finding it useful for consistency and others seeing it as unnecessary verbosity.
  • The complexity of USB descriptors and the lack of clear documentation can make it difficult to develop custom USB devices, but some commenters have found ways to overcome these challenges.
  • The security implications of using userspace drivers, including the potential for DMA attacks, are a concern for some commenters.