4

So, I'm delving into udev and running into an issue.

I think that I understand the basic premise (please correct me if i'm wrong). Device is attached either due to your system booting up or sometime afterwards. Udev goes through all the rules looking for matches. once it finds a match, it executes whatever actions were requested, and continues going down the list of rules until it gets to the last one. Then it starts off on the next device.

Now, I have a usb device that creates 2 interfaces. When I attach it, i get both an can0 and can1 when I look in /sys/class/net/. But in /dev, there is only one entry for this under /dev/bus/usb/002/00X.

Now, here is where my problem comes. I want to name each of these interfaces something specific. I know that one always comes up before the other. If i do nothing, they get named can0 and can1. If I put a udev rule in, the first one that comes up gets renamed properly, but looking at the dmesg logs, the second one errs out because the kernel name is also can0 (since there is no can1).

How would one get around this? udevadm doesn't help since there is only one device listed in /dev, so it seems that I can't differentiate them by attributes.

output of lsusb -v below:

Bus 001 Device 011: ID 0c72:0011 PEAK System 
Device Descriptor:
  bLength                18
  bDescriptorType         1
  bcdUSB               2.00
  bDeviceClass            0 (Defined at Interface level)
  bDeviceSubClass         0 
  bDeviceProtocol         0 
  bMaxPacketSize0        64
  idVendor           0x0c72 PEAK System
  idProduct          0x0011 
  bcdDevice            0.00
  iManufacturer           1 PEAK-System Technik GmbH
  iProduct                2 PCAN-USB Pro FD
  iSerial                 0 
  bNumConfigurations      1
  Configuration Descriptor:
    bLength                 9
    bDescriptorType         2
    wTotalLength          111
    bNumInterfaces          2
    bConfigurationValue     1
    iConfiguration          4 Config00
    bmAttributes         0x80
      (Bus Powered)
    MaxPower              240mA
    Interface Descriptor:
      bLength                 9
      bDescriptorType         4
      bInterfaceNumber        0
      bAlternateSetting       0
      bNumEndpoints           6
      bInterfaceClass         0 (Defined at Interface level)
      bInterfaceSubClass      0 
      bInterfaceProtocol      0 
      iInterface              5 PCAN-USB Pro FD CAN
      Endpoint Descriptor:
        bLength                 7
        bDescriptorType         5
        bEndpointAddress     0x81  EP 1 IN
        bmAttributes            2
          Transfer Type            Bulk
          Synch Type               None
          Usage Type               Data
        wMaxPacketSize     0x0200  1x 512 bytes
        bInterval               0
      Endpoint Descriptor:
        bLength                 7
        bDescriptorType         5
        bEndpointAddress     0x01  EP 1 OUT
        bmAttributes            2
          Transfer Type            Bulk
          Synch Type               None
          Usage Type               Data
        wMaxPacketSize     0x0200  1x 512 bytes
        bInterval               0
      Endpoint Descriptor:
        bLength                 7
        bDescriptorType         5
        bEndpointAddress     0x82  EP 2 IN
        bmAttributes            2
          Transfer Type            Bulk
          Synch Type               None
          Usage Type               Data
        wMaxPacketSize     0x0200  1x 512 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     0x0200  1x 512 bytes
        bInterval               0
      Endpoint Descriptor:
        bLength                 7
        bDescriptorType         5
        bEndpointAddress     0x83  EP 3 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     0x03  EP 3 OUT
        bmAttributes            2
          Transfer Type            Bulk
          Synch Type               None
          Usage Type               Data
        wMaxPacketSize     0x0200  1x 512 bytes
        bInterval               0
    Interface Descriptor:
      bLength                 9
      bDescriptorType         4
      bInterfaceNumber        1
      bAlternateSetting       0
      bNumEndpoints           6
      bInterfaceClass         0 (Defined at Interface level)
      bInterfaceSubClass      0 
      bInterfaceProtocol      0 
      iInterface              6 PCAN-USB Pro FD LIN
      Endpoint Descriptor:
        bLength                 7
        bDescriptorType         5
        bEndpointAddress     0x84  EP 4 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     0x04  EP 4 OUT
        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     0x85  EP 5 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     0x05  EP 5 OUT
        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     0x86  EP 6 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     0x06  EP 6 OUT
        bmAttributes            2
          Transfer Type            Bulk
          Synch Type               None
          Usage Type               Data
        wMaxPacketSize     0x0040  1x 64 bytes
        bInterval               0
Device Qualifier (for other device speed):
  bLength                10
  bDescriptorType         6
  bcdUSB               2.00
  bDeviceClass            0 (Defined at Interface level)
  bDeviceSubClass         0 
  bDeviceProtocol         0 
  bMaxPacketSize0        64
  bNumConfigurations      1
Device Status:     0x0000
  (Bus Powered)
  • Use lsusb to find some property that distinguishes between the two interfaces, then use that property to write two udev rules. – Satō Katsura Sep 1 '17 at 4:15
  • @SatōKatsura The problem I'm having is that since there is only one usb device, and network interfaces aren't stored in /dev. With ethernet, the way someone would have separated them would have been through the mac address, but can doesn't have any similarly identifying features. This is my understanding based on my research. please correct me if i'm wrong or misunderstanding your comment – engineer14 Sep 1 '17 at 19:40
  • No. Since it's an USB device, dig around with lsusb at increasing verbosity levels. At some point you should be able to detect some difference between some attributes of the two interfaces. Most of the attributes listed by lsusb also map to udev attributes (provided you're brave enough to read through the docs). – Satō Katsura Sep 1 '17 at 19:51
3

As seen in lsusb -v, your interfaces have different names. This can be additionally checked by

udevadm info -a -p $(udevadm info -q path -n can0)
udevadm info -a -p $(udevadm info -q path -n can1)

Therefore you can use ATTR{interface} to distinguish them.

SUBSYSTEM=="usb", ATTRS{idVendor}=="0c72", ATTRS{idProduct}=="0011", ATTR{interface}=="PCAN-USB Pro FD CAN"

Note that above we use specific combination of ATTR and ATTRS keys that matters because we look for values in current or current and parent device, see http://www.reactivated.net/writing_udev_rules.html.

If interfaces names are the same then they can be distinguished by ATTR{bInterfaceNumber}.

  • Oh wow, I had forgotten this question was still out there. I figured it out a little earlier, and it was the exact same thing only difference was that when using udevadm, i gave it the actual path of the network interface (/sys/class/net...) instead of searching for it. And yes bInterfaceNumber was the only differing attribute. – engineer14 Jun 3 '18 at 13:33

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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