Problem setting stable ID for pcan interface

USB to CAN Interface
Post Reply
CarlosMardones
Posts: 4
Joined: Mon 1. Aug 2016, 16:54

Problem setting stable ID for pcan interface

Post by CarlosMardones » Mon 1. Aug 2016, 17:44

Hi,

I have installed peak_drivers 7.15 and OS Ubuntu 14.04.
I need to use 4 can interfaces and I want to set a persistent ID for all of them.
I want to set a rule to udev with a relation of unique attrs

In /sys/class/net I have can0, can1, can2 and can3.
The attrs that I can read for all are as follow.

Code: Select all

udevadm info -a -p /sys/class/net/can0

  looking at device '/devices/virtual/net/can0':
    KERNEL=="can0"
    SUBSYSTEM=="net"
    DRIVER==""
    ATTR{mtu}=="16"
    ATTR{type}=="280"
    ATTR{netdev_group}=="0"
    ATTR{flags}=="0x80"
    ATTR{addr_assign_type}=="0"
    ATTR{dev_id}=="0x0"
    ATTR{gro_flush_timeout}=="0"
    ATTR{iflink}=="5"
    ATTR{addr_len}=="0"
    ATTR{address}==""
    ATTR{operstate}=="down"
    ATTR{carrier_changes}=="0"
    ATTR{broadcast}==""
    ATTR{tx_queue_len}=="10"
    ATTR{dev_port}=="0"
    ATTR{ifalias}==""
    ATTR{ifindex}=="5"
    ATTR{link_mode}=="0"
The rule that I can define is:
SUBSYSTEM=="net", ACTION=="add", KERNEL=="can*",ATTR{iflink}=="5", NAME="privateCan"

The attributes that changes are ATTR{iflink}=="5" and ATTR{ifindex}=="5" but I think that it is an autoincrement value so in the same session the value could be different with unplug/plug peak-can

So, when I try to identify a persisten and different attrs for use its on Udev rules I can´t.

If I run this code against /sys/class/usbmisc/can0 I can read:

Code: Select all

 KERNEL=="pcanusb0"
    SUBSYSTEM=="usbmisc"
    DRIVER==""
    ATTR{pcan_hwtype}=="11"
    ATTR{pcan_devid}=="16"
    ATTR{pcan_minor}=="0"

  looking at parent device '/devices/pci0000:00/0000:00:11.0/0000:02:00.0/usb2/2-2/2-2.2/2-2.2:1.0':
    KERNELS=="2-2.2:1.0"
    SUBSYSTEMS=="usb"
    DRIVERS=="pcan"
    ATTRS{bInterfaceClass}=="00"
    ATTRS{bInterfaceSubClass}=="00"
    ATTRS{bInterfaceProtocol}=="00"
    ATTRS{bNumEndpoints}=="04"
    ATTRS{supports_autosuspend}=="0"
    ATTRS{bAlternateSetting}==" 0"
    ATTRS{bInterfaceNumber}=="00"

  looking at parent device '/devices/pci0000:00/0000:00:11.0/0000:02:00.0/usb2/2-2/2-2.2':
    KERNELS=="2-2.2"
    SUBSYSTEMS=="usb"
    DRIVERS=="usb"
    ATTRS{bDeviceSubClass}=="00"
    ATTRS{bDeviceProtocol}=="00"
    ATTRS{devpath}=="2.2"
    ATTRS{idVendor}=="0c72"
    ATTRS{speed}=="12"
    ATTRS{bNumInterfaces}==" 1"
    ATTRS{bConfigurationValue}=="1"
    ATTRS{bMaxPacketSize0}=="16"
    ATTRS{busnum}=="2"
    ATTRS{devnum}=="5"
    ATTRS{configuration}==""
    ATTRS{bMaxPower}=="200mA"
    ATTRS{authorized}=="1"
    ATTRS{bmAttributes}=="80"
    ATTRS{bNumConfigurations}=="3"
    ATTRS{maxchild}=="0"
    ATTRS{bcdDevice}=="1c10"
    ATTRS{avoid_reset_quirk}=="0"
    ATTRS{quirks}=="0x0"
    ATTRS{version}==" 1.00"
    ATTRS{urbnum}=="24"
    ATTRS{ltm_capable}=="no"
    ATTRS{removable}=="unknown"
    ATTRS{idProduct}=="000c"
    ATTRS{bDeviceClass}=="00"

  looking at parent device '/devices/pci0000:00/0000:00:11.0/0000:02:00.0/usb2/2-2':
    KERNELS=="2-2"
    SUBSYSTEMS=="usb"
    DRIVERS=="usb"
    ATTRS{bDeviceSubClass}=="00"
    ATTRS{bDeviceProtocol}=="00"
    ATTRS{devpath}=="2"
    ATTRS{idVendor}=="0e0f"
    ATTRS{speed}=="12"
    ATTRS{bNumInterfaces}==" 1"
    ATTRS{bConfigurationValue}=="1"
    ATTRS{bMaxPacketSize0}=="8"
    ATTRS{busnum}=="2"
    ATTRS{devnum}=="3"
    ATTRS{configuration}=="VMware Virtual USB Hub"
    ATTRS{bMaxPower}=="0mA"
    ATTRS{authorized}=="1"
    ATTRS{bmAttributes}=="e0"
    ATTRS{bNumConfigurations}=="1"
    ATTRS{maxchild}=="7"
    ATTRS{bcdDevice}=="0100"
    ATTRS{avoid_reset_quirk}=="0"
    ATTRS{quirks}=="0x0"
    ATTRS{version}==" 1.10"
    ATTRS{urbnum}=="66"
    ATTRS{ltm_capable}=="no"
    ATTRS{removable}=="unknown"
    ATTRS{idProduct}=="0002"
    ATTRS{bDeviceClass}=="09"
    ATTRS{product}=="VMware Virtual USB Hub"

  looking at parent device '/devices/pci0000:00/0000:00:11.0/0000:02:00.0/usb2':
    KERNELS=="usb2"
    SUBSYSTEMS=="usb"
    DRIVERS=="usb"
    ATTRS{bDeviceSubClass}=="00"
    ATTRS{bDeviceProtocol}=="00"
    ATTRS{devpath}=="0"
    ATTRS{idVendor}=="1d6b"
    ATTRS{speed}=="12"
    ATTRS{bNumInterfaces}==" 1"
    ATTRS{bConfigurationValue}=="1"
    ATTRS{bMaxPacketSize0}=="64"
    ATTRS{authorized_default}=="1"
    ATTRS{busnum}=="2"
    ATTRS{devnum}=="1"
    ATTRS{configuration}==""
    ATTRS{bMaxPower}=="0mA"
    ATTRS{authorized}=="1"
    ATTRS{bmAttributes}=="e0"
    ATTRS{bNumConfigurations}=="1"
    ATTRS{maxchild}=="2"
    ATTRS{bcdDevice}=="0319"
    ATTRS{avoid_reset_quirk}=="0"
    ATTRS{quirks}=="0x0"
    ATTRS{serial}=="0000:02:00.0"
    ATTRS{version}==" 1.10"
    ATTRS{urbnum}=="32"
    ATTRS{ltm_capable}=="no"
    ATTRS{manufacturer}=="Linux 3.19.0-25-generic uhci_hcd"
    ATTRS{removable}=="unknown"
    ATTRS{idProduct}=="0001"
    ATTRS{bDeviceClass}=="09"
    ATTRS{product}=="UHCI Host Controller"

  looking at parent device '/devices/pci0000:00/0000:00:11.0/0000:02:00.0':
    KERNELS=="0000:02:00.0"
    SUBSYSTEMS=="pci"
    DRIVERS=="uhci_hcd"
    ATTRS{irq}=="18"
    ATTRS{subsystem_vendor}=="0x15ad"
    ATTRS{broken_parity_status}=="0"
    ATTRS{class}=="0x0c0300"
    ATTRS{label}=="usb"
    ATTRS{driver_override}=="(null)"
    ATTRS{consistent_dma_mask_bits}=="32"
    ATTRS{dma_mask_bits}=="32"
    ATTRS{local_cpus}=="ff"
    ATTRS{device}=="0x0774"
    ATTRS{enable}=="1"
    ATTRS{msi_bus}=="1"
    ATTRS{local_cpulist}=="0-7"
    ATTRS{vendor}=="0x15ad"
    ATTRS{acpi_index}=="16777728"
    ATTRS{subsystem_device}=="0x1976"
    ATTRS{d3cold_allowed}=="0"

  looking at parent device '/devices/pci0000:00/0000:00:11.0':
    KERNELS=="0000:00:11.0"
    SUBSYSTEMS=="pci"
    DRIVERS==""
    ATTRS{irq}=="0"
    ATTRS{subsystem_vendor}=="0x15ad"
    ATTRS{broken_parity_status}=="0"
    ATTRS{class}=="0x060401"
    ATTRS{driver_override}=="(null)"
    ATTRS{consistent_dma_mask_bits}=="32"
    ATTRS{dma_mask_bits}=="32"
    ATTRS{local_cpus}=="ff"
    ATTRS{device}=="0x0790"
    ATTRS{enable}=="1"
    ATTRS{msi_bus}=="1"
    ATTRS{local_cpulist}=="0-7"
    ATTRS{vendor}=="0x15ad"
    ATTRS{subsystem_device}=="0x0790"
    ATTRS{d3cold_allowed}=="0"

  looking at parent device '/devices/pci0000:00':
    KERNELS=="pci0000:00"
    SUBSYSTEMS==""
    DRIVERS==""
I try this solution in a computer without peak-drivers and attrs in /sys/class/net/canX were quite close to the attrs in /sys/class/usbmisc/pcanusbX the definition of rules works but I think that is better have peak-drivers and /sys/class/net/canX attribues completed to custom net name.

Do you think there is any way to "complete" /sys/class/net/canX attributes?

Regards and sorry for my english.

User avatar
S.Grosjean
Software Development
Software Development
Posts: 302
Joined: Wed 4. Jul 2012, 17:02

Re: Problem setting stable ID for pcan interface

Post by S.Grosjean » Wed 3. Aug 2016, 09:37

Hello Carlos,

There's an easiest way for you to assign a unique name to any "canX" interface handled by pcan 7.15 in netdev mode:

By using the "command line options" when loading the pcan module, you're able to tell the driver to fix the "X" in "canX" with a "device id" you previously have setup in each of your PCAN-USB:

1 - unplug all of your PCAN-USB, unload pcan

Code: Select all

$ sudo rmmod pcan
2 - load pcan

Code: Select all

$ sudo modprobe pcan
3 - plug one PCAN-USB, then, in the peak-linux-driver-x.y.z directory, run this tool:

Code: Select all

$ test/pcan-settings -f=/dev/pcanusb0 -d 
This should display the current "device id" of this PCAN-USB. You can change this value into your own one. For example, in order to setup "device id" Y, run:

Code: Select all

$ test/pcan-settings -f=/dev/pcanusb0 -d=Y
You can then unplug this PCAN-USB and repeat step 3 for each of the others (be sure to setup the right "device id" to the right PCAN-USB!)

4 - once you're finished with all of your PCAN-USB, then you must unload the current pcan module:

Code: Select all

$ sudo rmmod pcan
5 - edit (with root permissions) the file "/etc/modprobe.d/pcan.conf" in order to add the "assign=devid" option the system will use when it will load the pcan module next: simply add this line:

Code: Select all

options pcan assign=devid
6 - finally, reload the pcan module:

Code: Select all

$ sudo modprobe pcan
You should normally find a "canX" interface with "X" = the "device id" you have setup, for each PCAN-USB plugged into your system.

Hope this will help!

Regards,

Stéphane
— Stéphane

CarlosMardones
Posts: 4
Joined: Mon 1. Aug 2016, 16:54

Re: Problem setting stable ID for pcan interface

Post by CarlosMardones » Thu 4. Aug 2016, 08:59

Hello Stéphane,

Thanks a lot, the solution works really fine. I tested it with pcan and pcan-pro and It solve all my problems.

Post Reply