2

I have a USB VID and PID for an attached device on GNU / Linux. 045e:0084, for example. I want the binding so I grep the output of lsusb for the VID:PID and massage it into a format acceptable for udevadm lookup. Finally, I take the basename of the resultant path. Something like:

bus_dev=$(lsusb|grep VID:PID...) # Grep / Sed magic to extract bus and device from VID and PID.
path=$(udevadm info -q path -n /dev/bus/usb/$bus_dev) # e.g., -n /dev/bus/usb/003/018
basename $path # e.g., /devices/pci0000:00/0000:00:14.0/usb3/3-2/3-2.3/3-2.3.1
# e.g., yields 3-2.3.1

I can then use it like so:

echo 3-2.3.1|sudo tee /sys/bus/usb/drivers/usb/unbind

What's the preferred way to get the binding from a USB vendor and product ID?

Stephen Niedzielski
  • 2,173
  • 1
  • 22
  • 31

1 Answers1

1

You mean something like this?

vidpid="1d6b:0002"
bus_dev=`lsusb | grep "ID\s$vidpid" | sed 's/^.*Bus\s\([0-9]\+\)\sDevice\s\([0-9]\+\).*$/\1\/\2/g' | tail -n 1` 
path=$(udevadm info -q path -n /dev/bus/usb/$bus_dev)
basename $path
Onilton Maciel
  • 3,320
  • 19
  • 28
  • 1
    Not quite what I was looking for. I don't need the "SED / Grep magic" portion (it's actually what I'm trying to avoid). I've already got that working fine but I was hoping to find something more conventional and less hackish. Perhaps there's a way to query this from udev? Mine's quite similar to yours: # $1 - VID[:PID] usb_id_to_bind() { declare -r dev_name="$(lsusb|sed -rn 's_^Bus ([0-9]{3}) Device ([0-9]{3}): ID '"$1"'.*_/dev/bus/usb/\1/\2_p')" declare -r dev_path="$(udevadm info -q path -n"$dev_name")" basename "$dev_path" } – Stephen Niedzielski Oct 09 '12 at 00:07