Discussion:
Trying to come up with udev rule for USB geographic naming
(too old to reply)
Paul D. DeRocco
2017-07-11 02:33:41 UTC
Permalink
Raw Message
That is, I want a rule for creating a symlink that describes the USB port
something is plugged into, rather than the specific device plugged into
it. Linux USB has a way of representing the location of each physical
jack, even when hubs are involved. For devices like USB serial and USB
MIDI, I'd like apps to be able to refer to devices by where they're
plugged in.

I used udevadm to generate the info for a USB MIDI converter. The first
three levels look like this:

looking at device
'/devices/platform/soc/3f980000.usb/usb1/1-1/1-1.2/1-1.2:1.0/sound/card1/m
idiC1D0':
KERNEL=="midiC1D0"
SUBSYSTEM=="sound"
DRIVER==""

looking at parent device
'/devices/platform/soc/3f980000.usb/usb1/1-1/1-1.2/1-1.2:1.0/sound/card1':
KERNELS=="card1"
SUBSYSTEMS=="sound"
DRIVERS==""
ATTRS{id}=="XMidi1X1"
ATTRS{number}=="1"

looking at parent device
'/devices/platform/soc/3f980000.usb/usb1/1-1/1-1.2/1-1.2:1.0':
KERNELS=="1-1.2:1.0"
SUBSYSTEMS=="usb"
DRIVERS=="snd-usb-audio"
ATTRS{authorized}=="1"
ATTRS{bAlternateSetting}==" 0"
ATTRS{bInterfaceClass}=="01"
ATTRS{bInterfaceNumber}=="00"
ATTRS{bInterfaceProtocol}=="00"
ATTRS{bInterfaceSubClass}=="01"
ATTRS{bNumEndpoints}=="00"
ATTRS{supports_autosuspend}=="1"

(There may be spurious line breaks in there, due to email.)

I'd like an alias for this device to be "/dev/midi1-1.2:1.0". I tried the
following:

KERNEL=="midiC*", DRIVERS=="snd-usb-audio", SYMLINK+="midi%k"

It did bupkis. The man page seems to imply that, while a single rule can't
match items from different parents, it's okay to match something in the
device and then something else in a parent. So I would expect the KERNEL
key would match the device itself, DRIVERS would match a parent, but what
then does %k refer to, the kernel name in the device or the kernel name in
the parent?

But it not only didn't create a "midi1-1.2:1.0", it didn't create a
"midimidiC1D0" either, so it doesn't look like the rule matched at all.

There is already a symlink
"/dev/snd/by-path/platform-3f980000.usb-usb-0:1.2:1.0", but it refers to
the useless "controlC1" interface. It also doesn't appear to be generated
by an explicit rule anywhere that might show me what to do.

What am I doing wrong? Do I need a rule that just matches the MIDI device,
and then runs a script that searches for the parent name?
--
Ciao, Paul D. DeRocco
Paul mailto:***@ix.netcom.com
Andrei Borzenkov
2017-07-11 03:54:19 UTC
Permalink
Raw Message
Post by Paul D. DeRocco
That is, I want a rule for creating a symlink that describes the USB port
something is plugged into, rather than the specific device plugged into
it. Linux USB has a way of representing the location of each physical
jack, even when hubs are involved. For devices like USB serial and USB
MIDI, I'd like apps to be able to refer to devices by where they're
plugged in.
I used udevadm to generate the info for a USB MIDI converter. The first
looking at device
'/devices/platform/soc/3f980000.usb/usb1/1-1/1-1.2/1-1.2:1.0/sound/card1/m
KERNEL=="midiC1D0"
SUBSYSTEM=="sound"
DRIVER==""
looking at parent device
KERNELS=="card1"
SUBSYSTEMS=="sound"
DRIVERS==""
ATTRS{id}=="XMidi1X1"
ATTRS{number}=="1"
looking at parent device
KERNELS=="1-1.2:1.0"
SUBSYSTEMS=="usb"
DRIVERS=="snd-usb-audio"
ATTRS{authorized}=="1"
ATTRS{bAlternateSetting}==" 0"
ATTRS{bInterfaceClass}=="01"
ATTRS{bInterfaceNumber}=="00"
ATTRS{bInterfaceProtocol}=="00"
ATTRS{bInterfaceSubClass}=="01"
ATTRS{bNumEndpoints}=="00"
ATTRS{supports_autosuspend}=="1"
(There may be spurious line breaks in there, due to email.)
I'd like an alias for this device to be "/dev/midi1-1.2:1.0". I tried the
KERNEL=="midiC*", DRIVERS=="snd-usb-audio", SYMLINK+="midi%k"
You probably want %b instead of %k here which should refer to device
name matched by DRIVERS.
Post by Paul D. DeRocco
It did bupkis. The man page seems to imply that, while a single rule can't
match items from different parents, it's okay to match something in the
device and then something else in a parent. So I would expect the KERNEL
key would match the device itself, DRIVERS would match a parent, but what
then does %k refer to, the kernel name in the device or the kernel name in
the parent?
But it not only didn't create a "midi1-1.2:1.0", it didn't create a
"midimidiC1D0" either, so it doesn't look like the rule matched at all.
It could be race condition between driver loading and follow-up
processing. Or there is some rule that stops further processing. Start
with "udevadm test" to verify.
Post by Paul D. DeRocco
There is already a symlink
"/dev/snd/by-path/platform-3f980000.usb-usb-0:1.2:1.0", but it refers to
the useless "controlC1" interface. It also doesn't appear to be generated
by an explicit rule anywhere that might show me what to do.
It is created by 60-persistent-alsa.rules that explicitly restricts
processing to controlC*.
Post by Paul D. DeRocco
What am I doing wrong? Do I need a rule that just matches the MIDI device,
and then runs a script that searches for the parent name?
Paul D. DeRocco
2017-07-11 20:04:31 UTC
Permalink
Raw Message
Post by Andrei Borzenkov
Post by Paul D. DeRocco
There is already a symlink
"/dev/snd/by-path/platform-3f980000.usb-usb-0:1.2:1.0", but
it refers to
the useless "controlC1" interface. It also doesn't appear
to be generated
by an explicit rule anywhere that might show me what to do.
It is created by 60-persistent-alsa.rules that explicitly restricts
processing to controlC*.
Ahah! The systemd man page only mention /usr/lib, /etc, and /run as locations for udev/rules.d subdirectories, but apparently there's also one in /lib that's full of rules I didn't see.
--
Ciao, Paul D. DeRocco
Paul mailto:***@ix.netcom.com
Paul D. DeRocco
2017-07-11 23:53:38 UTC
Permalink
Raw Message
Post by Andrei Borzenkov
Post by Paul D. DeRocco
KERNEL=="midiC*", DRIVERS=="snd-usb-audio", SYMLINK+="midi%k"
You probably want %b instead of %k here which should refer to device
name matched by DRIVERS.
Start with "udevadm test" to verify.
I tried the following rule:

ACTION=="add", KERNEL=="midiC*", DRIVERS=="snd-usb-audio", SYMLINK+="snd/midi%b"

and "udevadm test" complains about an "invalid DRIVERS option". What could be invalid about it?
--
Ciao, Paul D. DeRocco
Paul mailto:***@ix.netcom.com
Andrei Borzenkov
2017-07-12 03:25:08 UTC
Permalink
Raw Message
Post by Paul D. DeRocco
Post by Andrei Borzenkov
Post by Paul D. DeRocco
KERNEL=="midiC*", DRIVERS=="snd-usb-audio", SYMLINK+="midi%k"
You probably want %b instead of %k here which should refer to device
name matched by DRIVERS.
Start with "udevadm test" to verify.
ACTION=="add", KERNEL=="midiC*", DRIVERS=="snd-usb-audio", SYMLINK+="snd/midi%b"
and "udevadm test" complains about an "invalid DRIVERS option". What could be invalid about it?
No idea. Please copy-paste actual command invocation and its output.
Paul D. DeRocco
2017-07-12 15:59:27 UTC
Permalink
Raw Message
From: Andrei Borzenkov
Please copy-paste actual command invocation and its output.
No need. I had used = instead of == on the DRIVERS. Works fine now. Thanks for your assistance.
--
Ciao, Paul D. DeRocco
Paul mailto:***@ix.netcom.com
Loading...