Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

I am using modem for sending sms which has 16 ( ttyUSB0 to ttyUSB15 ) ports. I want to make udev rule to give device name "AMPM" and ports should be name Port1, Port2,...Port16.

Check out this output of lsusb and udevadm command on port ttyUSB0

kk@kk:~$ lsusb
Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
Bus 002 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
Bus 003 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub
Bus 004 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub
Bus 005 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub
Bus 006 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub
Bus 007 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub
Bus 003 Device 004: ID 0461:4d22 Primax Electronics, Ltd
Bus 001 Device 015: ID 0409:005a NEC Corp. HighSpeed Hub
Bus 001 Device 016: ID 0403:6011 Future Technology Devices International, Ltd FT4232H Quad HS USB-UART/FIFO IC
Bus 003 Device 003: ID 413c:2003 Dell Computer Corp. Keyboard
Bus 001 Device 017: ID 0403:6011 Future Technology Devices International, Ltd FT4232H Quad HS USB-UART/FIFO IC
Bus 001 Device 018: ID 0403:6011 Future Technology Devices International, Ltd FT4232H Quad HS USB-UART/FIFO IC
Bus 001 Device 019: ID 0403:6011 Future Technology Devices International, Ltd FT4232H Quad HS USB-UART/FIFO IC
kk@kk:~$



kk@kk:~$ udevadm info -q all -n /dev/ttyUSB0
P: /devices/pci0000:00/0000:00:1a.7/usb1/1-3/1-3.1/1-3.1:1.0/ttyUSB0/tty/ttyUSB0
N: ttyUSB0
S: serial/by-id/usb-FTDI_Quad_RS232-HS-if00-port0
S: serial/by-path/pci-0000:00:1a.7-usb-0:3.1:1.0-port0
E: DEVLINKS=/dev/serial/by-id/usb-FTDI_Quad_RS232-HS-if00-port0 /dev/serial/by-path/pci-0000:00:1a.7-usb-0:3.1:1.0-port0
E: DEVNAME=/dev/ttyUSB0
E: DEVPATH=/devices/pci0000:00/0000:00:1a.7/usb1/1-3/1-3.1/1-3.1:1.0/ttyUSB0/tty/ttyUSB0
E: ID_BUS=usb
E: ID_MM_CANDIDATE=1
E: ID_MODEL=Quad_RS232-HS
E: ID_MODEL_ENC=Quad\x20RS232-HS
E: ID_MODEL_FROM_DATABASE=FT4232H Quad HS USB-UART/FIFO IC
E: ID_MODEL_ID=6011
E: ID_PATH=pci-0000:00:1a.7-usb-0:3.1:1.0
E: ID_PATH_TAG=pci-0000_00_1a_7-usb-0_3_1_1_0
E: ID_REVISION=0800
E: ID_SERIAL=FTDI_Quad_RS232-HS
E: ID_TYPE=generic
E: ID_USB_DRIVER=ftdi_sio
E: ID_USB_INTERFACES=:ffffff:
E: ID_USB_INTERFACE_NUM=00
E: ID_VENDOR=FTDI
E: ID_VENDOR_ENC=FTDI
E: ID_VENDOR_FROM_DATABASE=Future Technology Devices International, Ltd
E: ID_VENDOR_ID=0403
E: MAJOR=188
E: MINOR=0
E: SUBSYSTEM=tty
E: UDEV_LOG=3
E: USEC_INITIALIZED=7668235100

I am getting fail in following udev rule.

SUBSYSTEMS=="usb", KERNEL=="ttyUSB[0-15]*", ATTRS{idVendor}=="0403", ATTRS{product}=="6011", NAME=="AMPM" , SYMLINK=="AMPM", GROUP="tty", MODE="0660"
share|improve this question
    
seems devices are being created properly. what's output of ls -l /dev/ttyUSB* ? –  rhasti Jan 3 '13 at 8:08
    
Meet me on chat, I can't paste here as I finished all capacity. –  K.K Patel Jan 3 '13 at 8:12
    
didn't find you on chat. have to leave for work. check in later. –  rhasti Jan 3 '13 at 8:21
    
@K.KPatel I'm confused as to how you plan to symlink 16 different devices to one file... But anyway, I think you want SUBSYSTEMS=="usb-serial" At least guessing from one of the default rules. –  derobert Jan 3 '13 at 15:21
    
@K.KPatel Also, the key debugging tool is udevadm. E.g., udevadm info --query=all --name /dev/ttyUSB0 will help you. Or --attribute-walk. –  derobert Jan 3 '13 at 15:23

2 Answers 2

up vote 1 down vote accepted

Wait—I see it. Two things:

  1. You used ATTRS{product}=="6011" when you meant ATTRS{idProduct}=="6011" That missing id will break it. Copy-and-paste from udevadm info --attribute-walk to prevent typos like this.
  2. Your pattern is wrong; it should be KERNEL=="ttyUSB[0-9]*". Its a (very limited) regular expression, so [0-15]* means "any of the characters 0–1 or 5, repeated any number of times"

Also, you probably want to use SYMLINK+= instead of SYMLINK== to preserve the other links. You're correct that it needs to be SUBSYSTEMS=="usb" to match on product/vendor.

In order to number your AMPM devices, you need to give udev the number. Unfortunately, this is part of the usb-serial device, not the usb one. So you can't just use %s{port_number}/$attr{port_number}. Instead, borrow a trick from 60-persistent-serial.rules in newer udev versions, and do something like this:

SUBSYSTEMS=="usb-serial", ENV{.LOCAL_PORT_NUM}="$attr{port_number}"
SUBSYSTEMS=="usb", KERNEL=="ttyUSB[0-9]*", ATTRS{idVendor}=="0403", ATTRS{idProduct}=="6011", SYMLINK+="AMPM$env{.LOCAL_PORT_NUM}"

On older udev, you may have to use %E{…} instead of $env{…}.

Or, alternatively, if your udev is new enough, just use /dev/serial/by-id:

$ ls -l /dev/serial/by-id/
total 0
lrwxrwxrwx 1 root root 13 Jan  4 06:02 usb-067b_2303-if00-port0 -> ../../ttyUSB0

You should see your vendor/product code there, and all your ports.

share|improve this answer

Had similar needs; to map many FTDI usb-serial devices to unique names so that scripts can refer them uniquely.

On an Ubuntu 13.04, after some tinkering, the following worked for me.

Hopefully may be of help:

#######################################################################################################################################
# Creating unique symbolic links to usb-serial devices based on their "serial" number and other such as "bInterfaceNumber" attributes.
# Use udevadm [e.g. udevadm info -a -p $(udevadm info -q path -n ttyUSB0)] to find the subsystems that match and their attributes.
#######################################################################################################################################
SUBSYSTEMS=="usb", ATTRS{serial}=="0000:00:1d.0", ENV{.LOCAL_serial}="$attr{serial}"
SUBSYSTEMS=="usb", ENV{.LOCAL_ifNum}="$attr{bInterfaceNumber}"
SUBSYSTEMS=="usb", KERNEL=="ttyUSB[0-9]*", ATTRS{idVendor}=="0403", ATTRS{idProduct}=="6010", ENV{.LOCAL_serial}=="0000:00:1d.0", ENV{.LOCAL_ifNum}=="00",  SYMLINK+="ttyPapilioJTAG",  MODE="0660"
SUBSYSTEMS=="usb", KERNEL=="ttyUSB[0-9]*", ATTRS{idVendor}=="0403", ATTRS{idProduct}=="6010", ENV{.LOCAL_serial}=="0000:00:1d.0", ENV{.LOCAL_ifNum}=="01",  SYMLINK+="ttyPapilioConsole",  MODE="0660"
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.