# [SOLVED] custom udev rules for usb devices

## Vieri

Hello,

I'd like to know how to write a custom udev rule so that a particular USB device is always assigned to a "custom-labeled" port, such as "RS-232-adapter-1" instead of a "variable" ttyUSB? (where ? usually changes).

I understand that the concept is to create a "RS-232-adapter-1" symlink in /dev through a custom udev rule. What's the correct way of doing this?

My USB device:

```

# lsusb -D /proc/bus/usb/002/007

Device: ID 0403:6001 Future Technology Devices International, Ltd 8-bit FIFO

Device Descriptor:

  bLength                18

  bDescriptorType         1

  bcdUSB               1.10

  bDeviceClass            0 (Defined at Interface level)

  bDeviceSubClass         0

  bDeviceProtocol         0

  bMaxPacketSize0         8

  idVendor           0x0403 Future Technology Devices International, Ltd

  idProduct          0x6001 8-bit FIFO

  bcdDevice            4.00

  iManufacturer           1 FTDI

  iProduct                2 usb serial converter

  iSerial                 3 FTCTWS1T

  bNumConfigurations      1

  Configuration Descriptor:

    bLength                 9

    bDescriptorType         2

    wTotalLength           32

    bNumInterfaces          1

    bConfigurationValue     1

    iConfiguration          0

    bmAttributes         0xa0

      (Bus Powered)

      Remote Wakeup

    MaxPower               44mA

    Interface Descriptor:

      bLength                 9

      bDescriptorType         4

      bInterfaceNumber        0

      bAlternateSetting       0

      bNumEndpoints           2

      bInterfaceClass       255 Vendor Specific Class

      bInterfaceSubClass    255 Vendor Specific Subclass

      bInterfaceProtocol    255 Vendor Specific Protocol

      iInterface              2 usb serial converter

      Endpoint Descriptor:

        bLength                 7

        bDescriptorType         5

        bEndpointAddress     0x81  EP 1 IN

        bmAttributes            2

          Transfer Type            Bulk

          Synch Type               None

          Usage Type               Data

        wMaxPacketSize     0x0040  1x 64 bytes

        bInterval               0

      Endpoint Descriptor:

        bLength                 7

        bDescriptorType         5

        bEndpointAddress     0x02  EP 2 OUT

        bmAttributes            2

          Transfer Type            Bulk

          Synch Type               None

          Usage Type               Data

        wMaxPacketSize     0x0040  1x 64 bytes

        bInterval               0

Device Status:     0x0000

  (Bus Powered)

```

Last edited by Vieri on Mon Aug 31, 2009 10:51 am; edited 1 time in total

----------

## DawgG

you have to find out the one distinguishing property of your device (like manufacturer, serial, etc) and put it inside the udev-rule that creates the named symlink, then the device will always  get that name.

you probably have to do some reading (it's worth it  :wink: ) if you haven't already:

http://reactivated.net/writing_udev_rules.html#udevinfo

GOOD LUCK!

----------

## Vieri

Thanks.

I did the following:

```

# udevinfo -a -p /sys/class/usb_device/usbdev2.7

  looking at device '/class/usb_device/usbdev2.7':

    KERNEL=="usbdev2.7"

    SUBSYSTEM=="usb_device"

    DRIVER==""

  looking at parent device '/devices/pci0000:00/0000:00:1d.0/usb2/2-2':

    KERNELS=="2-2"

    SUBSYSTEMS=="usb"

    DRIVERS=="usb"

    ATTRS{serial}=="FTCTWS1T"

    ATTRS{product}=="usb serial converter"

    ATTRS{manufacturer}=="FTDI"

    ATTRS{quirks}=="0x0"

    ATTRS{maxchild}=="0"

    ATTRS{version}==" 1.10"

    ATTRS{devnum}=="7"

    ATTRS{busnum}=="2"

    ATTRS{speed}=="12"

    ATTRS{bMaxPacketSize0}=="8"

    ATTRS{bNumConfigurations}=="1"

    ATTRS{bDeviceProtocol}=="00"

    ATTRS{bDeviceSubClass}=="00"

    ATTRS{bDeviceClass}=="00"

    ATTRS{bcdDevice}=="0400"

    ATTRS{idProduct}=="6001"

    ATTRS{idVendor}=="0403"

    ATTRS{bMaxPower}==" 44mA"

    ATTRS{bmAttributes}=="a0"

    ATTRS{bConfigurationValue}=="1"

    ATTRS{bNumInterfaces}==" 1"

    ATTRS{configuration}==""

So I tried these udev rules:

DOES NOT WORK: KERNEL=="usb_device", SUBSYSTEMS=="usb", ATTRS{product}=="usb serial converter", ATTRS{manufacturer}=="FTDI", ATTRS{serial}=="FTCTWS1T", NAME="ttyUSB-GSM-630725830"

DOES NOT WORK: SUBSYSTEM=="usb_device", SUBSYSTEMS=="usb", ATTRS{product}=="usb serial converter", ATTRS{manufacturer}=="FTDI", ATTRS{serial}=="FTCTWS1T", NAME="ttyUSB-GSM-630725830"

works: SUBSYSTEMS=="usb", ATTRS{product}=="usb serial converter", ATTRS{manufacturer}=="FTDI", ATTRS{serial}=="FTCTWS1T", NAME="ttyUSB-GSM-630725830"

alternative (works):

SUBSYSTEMS=="usb", ATTRS{product}=="usb serial converter", ATTRS{manufacturer}=="FTDI", ATTRS{serial}=="FTCTWS1T", SYMLINK+="ttyUSB-GSM-630725830"

I tried this:

udevadm control --reload_rules

udevadm trigger --sybsystem-match=usb

to test my new udev rules without rebooting but that did not work. I had to force a reboot.

```

So, even if my problem is solved now, I'd like to know:

1) why are my first 2 rules invalid?

2) how can I correctly reload udev rules without rebooting a system?

Thanks.

----------

## DawgG

glad it works now!

 *Quote:*   

> why are my first 2 rules invalid? 

 

i think 

```
=="usb_device"
```

 is neither part of KERNEL nor SUBSYSTEM in udev-rules.

 *Quote:*   

> how can I correctly reload udev rules without rebooting a system? 

 

in my case (automounting usbdrives and executing a script on add and remove) 

```
killall -1 udevd
```

 (as root) did the trick.

----------

## Vieri

Thanks!

----------

