Live data from Hacker News

USB for Software Developers: An introduction to writing userspace USB drivers

werwolv.net

31–40 of 57 posts

Re: USB for Software Developers: An introduction to writing userspace USB drivers

#31
Nice article, happen to have been working on a usbip system for my Macbook M3 using similar tech.

Worth noting that, this approach is limitted on newer macOS systems: can't build libusb "userspace USB drivers" for devices that are supported by macOS. Without manually disabling some Security features, can't override drivers for system-recognized USB devices.

Re: USB for Software Developers: An introduction to writing userspace USB drivers

#33

If you are interested in doing this in golang I wrote a library to avoid needing cgo: https://github.com/kevmo314/go-usb I use this to access UVC devices correspondingly without cgo: https://github.com/kevmo314/go-uvc

And for Rust, https://github.com/kevinmehall/nusb

Re: USB for Software Developers: An introduction to writing userspace USB drivers

#34
post #31

Nice article, happen to have been working on a usbip system for my Macbook M3 using similar tech. Worth noting that, this approach is limitted on newer macOS systems: can't build libusb "userspace USB drivers" for devices that are supported by macOS. Without manually disabling some Security features, can't override drivers for system-recognized USB devices.

Overriding drivers can be mitigated as it is just one layer.

Re: USB for Software Developers: An introduction to writing userspace USB drivers

#35

Does the adb tool use libusb or a kernel driver?

ADB uses libusb or WinUSB directly from userspace too yeah. On Windows you still need a .inf driver though because the WinUSB driver isn't getting loaded by default for Android devices because they're lacking the MS OS Descriptor

Re: USB for Software Developers: An introduction to writing userspace USB drivers

#36

Ages ago when I was trying to create a simple USB device, I found that there is very much zero information how to do it - e.g. how to correctly write descriptors and so on. The typical advice was: find similar device to what you want to make, copy its descriptors and adapt to your own device using trial and error. Sounds like USB is a wonderful standard. Am I wrong?

Descriptors also were kind of a mystery for me until I realized that they're just a binary structure with a fixed format that the host reads and interprets.

The device descriptor is easy enough to get right as it doesn't have too many fields and every USB class just defines in the specification which Class and SubClass it uses for its interface descriptor as well as which endpoints that interface needs to have. And that's, for the most part, all you need for the host to recognize your device

Re: USB for Software Developers: An introduction to writing userspace USB drivers

#37

Ages ago when I was trying to create a simple USB device, I found that there is very much zero information how to do it - e.g. how to correctly write descriptors and so on. The typical advice was: find similar device to what you want to make, copy its descriptors and adapt to your own device using trial and error. Sounds like USB is a wonderful standard. Am I wrong?

USB is nice, but electrically some parts of USB 1/2 are kind of complicated (not true differential signaling.)

Re: USB for Software Developers: An introduction to writing userspace USB drivers

#38

Dumb question.. do USB devices support DMA? Is it done through the host? Or does the USB device always push/pull data to host memory?

All transfers are initiated by the host, including ones that look like they're client-first; there is no DMA, which would be a massive security pain.

Re: USB for Software Developers: An introduction to writing userspace USB drivers

#39
post #35

Does the adb tool use libusb or a kernel driver?

ADB uses libusb or WinUSB directly from userspace too yeah. On Windows you still need a .inf driver though because the WinUSB driver isn't getting loaded by default for Android devices because they're lacking the MS OS Descriptor

In 99% of cases you don't need a kernel driver.

I don't think anyone uses the "native" usb way on either windows or mac os, when it's so much easier to go through libusb.

I've personally done a custom DFU updater for Mac OS some time ago by using libusb. It worked just fine(tm). I don't want to try and evaluate how long it would have taken to do it with the mac api.

Re: USB for Software Developers: An introduction to writing userspace USB drivers

#40

Ages ago when I was trying to create a simple USB device, I found that there is very much zero information how to do it - e.g. how to correctly write descriptors and so on. The typical advice was: find similar device to what you want to make, copy its descriptors and adapt to your own device using trial and error. Sounds like USB is a wonderful standard. Am I wrong?

Eh, there's very little tutorial content, but as far as big corporate standards go it's fairly reasonable. There is a downside to "too much choice", in that you have to read a lot to find the most relevant pre-defined type of device to what you're doing.
Post reply on HN