b0rk, (edited )
@b0rk@jvns.ca avatar

if you’ve written code to interact with a USB device (in userspace, not in the kernel), what tools/learning resources did you use?

right now I’m thinking gousb (and Wireshark to spy on USB traffic) but I’ve never done this before

the USB device in question is a USB-to-Ethernet adapter on a Mac

AngryAnt,
@AngryAnt@mastodon.gamedev.place avatar

@b0rk I worked on a small utility in Swift to send active application context to a keyboard.

Needing to probe that context made the high level approach desirable and from there I also had easy access to a higher level than straight USB interaction: Custom HID device interaction.

If I were to attack a problem like the one you describe, this background would drive me to see if engaging at a similar higher level again would be doable.

AngryAnt,
@AngryAnt@mastodon.gamedev.place avatar

@b0rk Ah and the resource I used at the time was just Swift API docs.

mcr314,
@mcr314@todon.nl avatar

@b0rk USB Ethernet devices are an entire subclass of USB, and ought to have common packets. They are mostly all handled by the kernel, so what do you want to do exactly? If you are trying to send/receive packets, the kernels will do that for you. Libpcap has routines that can help if you want to send packets at layer 2. What is your goal?

b0rk, (edited )
@b0rk@jvns.ca avatar

@mcr314 i want to send packets at layer 2 on Mac OS. In the past i’ve had a lot of problems with the OS intercepting the packets and closing my connections which is why I’m thinking of bypassing the OS as much as possible

raggi,
@raggi@rag.pub avatar

@b0rk @mcr314 you’ll find a lot of usb nics don’t actually implement usb-cdc, instead they present old rndis style interface. Some try to do a composite mode thing to offer both, but that tends to break compatibility with one OS or another. You’ll also find many don’t implement hardware flow control, so if you’re too slow or too fast packets will be dropped. Even different runs from a vendor might implement different interfaces, as they just glue and ship.

b0rk,
@b0rk@jvns.ca avatar

@raggi interesting! the one I have is using NCM with my OS (according to Wireshark)

whitequark,
@whitequark@mastodon.social avatar
timonsku,
@timonsku@mastodon.social avatar

@b0rk aside from the all powerful libusb you also have WebUSB available in Chrome and friends.
There is also node-usb which offers a WebUSB like interface.
https://github.com/node-usb/node-usb

timonsku,
@timonsku@mastodon.social avatar

@b0rk they are all just libusb in the end but the interface is more friendly to use :D

penguin42,
@penguin42@mastodon.org.uk avatar

@b0rk How about: https://libusb.info/

(Don't think I've actually used it myself, but I see lots using it).

mjk,
@mjk@hachyderm.io avatar

@b0rk I've used libusb to talk to both off-the-shelf and custom hardware from userland. Of all the libraries I've used, it was certainly one of them.

(It's basically fine, just very C-flavored and the docs assume that you know everything about USB already)

I spent a lot of time with "USB in a Nutshell" that summer (https://www.beyondlogic.org/usbnutshell/usb1.shtml)

b0rk,
@b0rk@jvns.ca avatar

@mjk thanks so much for the pointer to USB in a nutshell! I don’t know anything about USB so i’m very intimidated by libusb :)

timonsku,
@timonsku@mastodon.social avatar

@b0rk @mjk I can also recommend "USB Complete", great book to look up details.

mjk,
@mjk@hachyderm.io avatar

@b0rk You're welcome!

It seems like every other USB library is actually just "libusb in a trenchcoat", so it may be unavoidable, but starting with high-level bindings definitely seems reasonable. PyUSB is another decent wrapper, for the Python-inclined.

b0rk,
@b0rk@jvns.ca avatar

@mjk my hope is that some of the wrapper libraries come with more beginner friendly examples but I haven’t tested that out yet

  • All
  • Subscribed
  • Moderated
  • Favorites
  • random
  • mdbf
  • DreamBathrooms
  • thenastyranch
  • ngwrru68w68
  • tacticalgear
  • magazineikmin
  • Youngstown
  • khanakhh
  • rosin
  • slotface
  • InstantRegret
  • everett
  • kavyap
  • cubers
  • megavids
  • GTA5RPClips
  • cisconetworking
  • modclub
  • ethstaker
  • osvaldo12
  • Durango
  • normalnudes
  • tester
  • provamag3
  • Leos
  • anitta
  • JUstTest
  • lostlight
  • All magazines