timdoug's tidbits


2022-07-14

Use a CH9200 USB Ethernet adapter on macOS Monterey

Recently I had an immediate need for hardwired network connectivity on my M1 Air, and could only secure a QinHeng CH9200 dongle that doesn't have macOS drivers. It's a USB 1.1 "full-speed" device, i.e., 12 Mbps, so decidedly archaic bandwidth, but still plenty for video conferencing, and, critically, low and consistent latency vs. 2.4 GHz Wi-Fi that drops when someone starts a microwave nearby. (Editors of The New Yorker: let me know if that is a sufficient comma count thx.)

Luckily mainline Linux has supported it since 2015, so we can virtualize Debian with QEMU and use USB passthru to establish connectivity. Modern macOS no longer supports TAP devices, so we can't bridge the virtualized network to the Mac, but we can (ab)use userland SLIRP and WireGuard to get packets flowing.

First build QEMU — I used version 7.0.0 — with the aarch64-softmmu target (s/aarch64/amd64/ if an Intel Mac) and create a disk image, then grab the Debian installer netboot kernel (filename linux) and initrd.gz. Install Debian with the following arguments, attaching the USB dongle accordingly:

qemu-system-aarch64 -nographic -m 1G -machine virt,accel=hvf -cpu host -kernel linux -initrd initrd.gz -append console=ttyAMA0 -hda debian_aarch64.img -device qemu-xhci -device usb-host,vendorid=0x1a86,productid=0xe092

The installer won't set up a bootloader, so when it's complete, nc the installed kernel and initrd to the Mac. After installation, start it up with port 11111 (or whichever) forwarded for WireGuard:

qemu-system-aarch64 -nographic -m 1G -machine virt,accel=hvf -cpu host -kernel vmlinuz -initrd initrd.img -append "console=ttyAMA0 root=/dev/vda1" -hda debian_aarch64.img -device qemu-xhci -device usb-host,vendorid=0x1a86,productid=0xe092 -nic hostfwd=udp::11111-:11111

Upon boot I had to run dhclient enp0s1 to bring up the userland SLIRP interface from which the Mac will connect; twiddling /etc/network/interfaces correctly should obviate this manual step.

Then install and configure WireGuard, ensuring the POSTROUTING interface in the config is correct; mine was of the form enx84**********. You should be all set!

[/osx] permanent link


© 2006-24 timdoug | email: "me" at this domain
So necessary