WSL2 COM port pass-through with usbipd (firewall issues)

July 30, 2024 0 By addshore

I’ll start by saying that ultimately you want to read and follow the Connecting USB devices documentation for WSL.

However, a few things cropped up along the way that I think might be worth writing down for future me, and others.

Requirements

Firstly, you need to be on WSL2.

Next, install the USBIPD-WIN program.

winget install --interactive --exact dorssel.usbipd-winCode language: CSS (css)

Listing devices

In windows cmd or powershell, you can use usbipd list to list all devices. This should line up with what you see in Windows device manager if you open it.

In WSL Linux bash, you can run lsusb to list devices.

And at this stage, you’d likely expect this list to be empty, but you might see some things…

(Mainly the Linux bits, you can ignore my 0403 device…)

Binding

In windows, the usbipd bind command can be used to bind the usbipd tool to one of the devices.

Take note of the various options, as the standard documentation just refers to -b for the bus ID, however -i might be more useful.

Usage:
  usbipd bind [options]

Options:
  -b, --busid <BUSID>          Share device having <BUSID>
  -f, --force                  Force binding; the host cannot use the device
  -i, --hardware-id <VID:PID>  Share device having <VID>:<PID>
  -?, -h, --help               Show help and usage informationCode language: HTML, XML (xml)

As I know the device hardware ID that I want to bind, I’ll use usbipd bind -i 1a86:7523 run as an administrator from PowerShell.

You need to have the device connected for this step, and you also would need to bind each separate USB (and thus COM port) that you plug the device into.

This does allow you some nice flexibility, such as being able to have one USB socket binding your development devices to Windows (default), and another binding them to WSL

In this case, again, you might find the -b option useful, and always do usbipd bind -u 1-9 for example.

Attaching

In order to actually attach WSL to the device, you need to use the attach command from Windows.

You can only have a device attached to, and thus used by either WSL or Windows.

Firewall issue

At this stage, I personally had to hunt around for a solution to my error which said something about a firewall.

usbipd: warning: A firewall may be blocking the connection; ensure TCP port 3240 is allowed.Code language: HTTP (http)

I read a bunch of GitHub issues and ultimately discovered that most people had got around this error by switching from the NAT networking mode to mirrored.

mirrored so hard has not worked well for me, and I confirmed this again by trying once more.

Ultimately, I was poking firewall rules, and found that turning Edge traversal on and off again seemed to make my issue with port 3240 for usbpid go away!

You can see my comment on Github here.