I just had a similar issue. Specifically. I have a ICOM IC-7610 (ham radio) that runs on Windows, but I added 128GB of memory and installed Linux on it so I could make it a home lab.
Naturally, I still want to run Ham Radio Deluxe which is a windows app so I installed KVM and installed Windows on it so I could run it on that PC (it sits in front of my radio)
Anyhow. When I turn on my radio, it installs the "Prolific Technology Inc. IC-7610 SuperSpeed-FIFO Bridge" which I don't need, but it also installs two virtual com ports. Specifically "Silicon Labs CP210x UART Bridge"
These are used for Rig Control (where I can control the radio from the PC).
The problem is, udev rules don't seem to trigger for the virtual com ports.
The trick I used was to trigger on the SuperSpeed-FIFO Bridge, yet install the CP210x devices since they appear together when I turn the ICOM on.
Anyhow. I got it to work to install them, but the remove rule isn't working yet, but should be a blueprint for anyone needing to do something similar if something does get installed when plugged in / turned on.
Here is my udev rule.
Code:
ACTION=="bind", SUBSYSTEM=="usb", ATTRS{idVendor}=="0c26", ATTRS{idProduct}=="0029", ENV{ID_VENDOR_ID}="10c4", ENV{ID_MODEL_ID}="ea60", RUN+="/root/bin/kvm-udev attach Windows10"
ACTION=="remove", SUBSYSTEM=="usb", ATTRS{idVendor}=="10c4", ATTRS{idProduct}=="ea60", ENV{ID_VENDOR_ID}="10c4", ENV{ID_MODEL_ID}="ea60", RUN+="/root/bin/kvm-udev detach Windows10"
When the FIFO bridge gets detected it triggers this rule. It's vendor id is 0c26 anbd the product od is 0029. I then set an environment variable of ID_VENDOR_ID to 10c4 and the model top ea60 which are the two comm ports. (there are two! So we must specify an address too otherwise it will complain about which one to install!)
Since there are two, My script that gets executed actually does the same things twice to get both ports installed.
The script:
Code:
#!/bin/bash
# Usage: ./kvm-udev.sh attach|detach <domain>
set -e
touch /root/bin/udevrules
ACTION=$1
DOMAIN=$2
ADDR1=`udevadm info -a -p $(udevadm info -q path -n /dev/ttyUSB1) | grep -A 20 'KERNELS=="1-1.2"' | grep devnum | cut -d '"' -f 2`
ADDR2=`udevadm info -a -p $(udevadm info -q path -n /dev/ttyUSB2) | grep -A 20 'KERNELS=="1-1.3"' | grep devnum | cut -d '"' -f 2`
CONF_FILE1=$(mktemp --suffix=.kvm-udev)
CONF_FILE2=$(mktemp --suffix=.kvm-udev)
cat << EOF >$CONF_FILE1
<hostdev mode='subsystem' type='usb'>
<source>
<vendor id='0x${ID_VENDOR_ID}' />
<product id='0x${ID_MODEL_ID}' />
<address bus="1" device='${ADDR1}' />
</source>
</hostdev>
EOF
cat << EOF >$CONF_FILE2
<hostdev mode='subsystem' type='usb'>
<source>
<vendor id='0x${ID_VENDOR_ID}' />
<product id='0x${ID_MODEL_ID}' />
<address bus="1" device='${ADDR2}' />
</source>
</hostdev>
EOF
virsh "${ACTION}-device" "$DOMAIN" "$CONF_FILE1"
virsh "${ACTION}-device" "$DOMAIN" "$CONF_FILE2"
rm "$CONF_FILE1"
rm "$CONF_FILE2"
So from here, I assign the ACTION and DOMAIN (virtual host name) and then I use udevadm info to grab the address ID of the virtual comm ports. I use KERNELS (I know which ones they will be by checking) and use devnum (the bus / id) and cut to only get the bus id and assign it to addr1/2 for each.
Then I make a temp file and inject the XML required for virsh and populate the proper info for each device.
I then execute the virsh command with that config/xml file and then remove the temp config file.
As soon as I turn the radio on, it automatically maps the virtual comm ports to my Windows10 virtual machine that is running Ham Radio Deluxe.
Anyhow,. I hope that helps someone.
Dave