複数のインターフェイスを持つデバイスのUdevルール

複数のインターフェイスを持つデバイスのUdevルール

だからudevを掘り下げて問題に遭遇しました。

基本的な前提は理解したようです(間違っている場合は訂正してください)。デバイスはシステム起動時またはしばらくして接続されます。 Udevは、一致するものを見つけるためにすべてのルールを慎重に調べます。一致するものが見つかったら、要求されたすべての操作を実行し、最後の項目に達するまでルールのリストを続行します。その後、次のデバイスで起動します。

これで、2つのインターフェースを生成するUSB​​デバイスがあります。貼ってみるとcan0、can1の両方が出ます/sys/class/net/。ただし、/devこれに関連する項目は1つだけです/dev/bus/usb/002/00X

今これが私の問題があるところです。私はこれらの各インターフェイスに特定の名前を付けたいと思います。私はいつも他のものよりも先に来ていることを知っています。何もしないと、名前はcan0と で指定されますcan1。 udevルールを入れると、最初のルールの名前が正しく変更されますが、ログを見ると、2番目のルールにdmesgカーネル名が多すぎるためcan0(エラーがないためcan1)エラーが発生します。

この問題を解決するには?udevadmリストにデバイスが 1 つしかない/devため、属性別に区別できないようなので役に立ちません。

出力はlsusb -v次のとおりです。

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)

ベストアンサー1

に示すように、lsusb -vインターフェイスの名前は異なります。これはさらに確認できます。

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

したがってATTR{interface}、を使用して区別できます。

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

ATTR上記では、キーの特定の組み合わせを使用しましたATTRS。これは、現在または現在および親デバイスで値を探しているので重要です。http://www.reactivated.net/writing_udev_rules.html

インターフェイス名が同じ場合は区別できますATTR{bInterfaceNumber}

おすすめ記事