On 7/22/09, Christopher Piggott <cpiggott@xxxxxxxxx> wrote: > I must be missing something really fundamental, because whatever rules > I write, they don't seem to see attributes. > > Here is one example. I am inserting a device that is a CDMA modem. > Its path is: > > /devices/pci0000:00/0000:00:1d.1/usb3/3-2/3-2:1.0/ttyUSB0/tty/ttyUSB0 > > If I start in > /sys/devices/pci0000:00/0000:00:1d.1/usb3/3-2/3-2:1.0/ttyUSB0/tty/ttyUSB0 > and start searching upward, I find a file named: > > /sys/devices/pci0000:00/0000:00:1d.1/usb3/3-2/idVendor > > That file contains the string "1410" ... so far so good, that's > exactly what I want. > > Next, I try to write a rule like this: > > ACTION=="add", , SYMLINK+="usb-cell" > > Nothing happens. It doesn't match, because idVendor is (apparently) > not assigned. So, to troubleshoot this I try something else: > > ACTION=="add", RUN+="/usr/bin/logger add devpath=%p driver=$driver > id=%b links=$links vendor=$attr{idVendor}, product=$attr{product}" > > What that should do is that any time ANYTHING is added it uses logger > to write a line to the log file. I remove and reinsert the device > and, indeed, logger gets called. What gets logged is a string like > this: > > logger: add > devpath=/devices/pci0000:00/0000:00:1d.1/usb3/3-2/3-2:1.0/ttyUSB0/tty/ttyUSB0 > driver=option id=3-2:1.0 links=char/188:0 > serial/by-path/pci-0000:00:1d.1-usb-0:2:1.0-port0 > serial/by-id/usb-Novatel_Wireless_Inc._Novatel_Wireless_CDMA_091073597351000-if00-port0 > vendor=, product= > > > So ... lots of useful stuff there. It logged, it sees a device path > that makes sense, but vendor and product are not assigned. Two general things may be worth knowing - 1) "udevadm info" is a good way to see a list of env keys or attributes you can match on. 2) libptp and libmtp match on idVendor / idProduct, so it is possible. More specific gotchas - The documentation for $attr{} is a little misleading. It will only look at the actual device and a maximum of one "ancestor". It will only look at an ancestor device if it was used to fulfil a match (presumably an ATTRS match, but it could be anything). That explains why it doesn't expand to anything in your debug rule. - Similarly, in you first rule, ATTRS{idVendor}=="1410", DRIVERS=="option", ATTRS{port_number}=="0" all these matches must apply to the same device. I suspect idVendor and DRIVER are on the same usb ancestor device, but port_number is not. If port_number is an attribute of the actual device, you can use ATTR{} to match it instead, and that should work. I guess would be easier to do this if you could match on SYMLINKs, (you can't). Then people who want human-readable aliases could add rules like SYMLINK=="serial/by-id/usb-Novatel_Wireless_Inc._Novatel_Wireless_CDMA_091073597351000-if00-port0", SYMLINK="usb-cell". I'm not sure if it's worthwhile, or how to document it so people would find it :-). The code would be easy though. Alan -- To unsubscribe from this list: send the line "unsubscribe linux-hotplug" in the body of a message to majordomo@xxxxxxxxxxxxxxx More majordomo info at http://vger.kernel.org/majordomo-info.html