2013-10-04 119 views
2

我想使用udev給相關名稱一個USB串行設備,但我現在有運氣。udev規則與bInterfaceNumber不起作用

# lsusb -d 04e2:1412 -v 

    Bus 004 Device 028: ID 04e2:1412 Exar Corp. 
    Device Descriptor: 
     bLength    18 
     bDescriptorType   1 
     bcdUSB    2.00 
     bDeviceClass   239 Miscellaneous Device 
     bDeviceSubClass   2 Common Class 
     bDeviceProtocol   1 Interface Association 
     bMaxPacketSize0  64 
     idVendor   0x04e2 Exar Corp. 
     idProduct   0x1412 
     bcdDevice   0.02 
     iManufacturer   0 
     iProduct    0 
     iSerial     0 
     bNumConfigurations  1 
     Configuration Descriptor: 
     bLength     9 
     bDescriptorType   2 
     wTotalLength   141 
     bNumInterfaces   4 
     bConfigurationValue  1 
     iConfiguration   0 
     bmAttributes   0xa0 
      (Bus Powered) 
      Remote Wakeup 
     MaxPower    94mA 
     Interface Association: 
      bLength     8 
      bDescriptorType  11 
      bFirstInterface   0 
      bInterfaceCount   2 
      bFunctionClass   2 Communications 
      bFunctionSubClass  2 Abstract (modem) 
      bFunctionProtocol  0 None 
      iFunction    0 
     Interface Descriptor: 
      bLength     9 
      bDescriptorType   4 
      bInterfaceNumber  0 
      bAlternateSetting  0 
      bNumEndpoints   1 
      bInterfaceClass   2 Communications 
      bInterfaceSubClass  2 Abstract (modem) 
      bInterfaceProtocol  1 AT-commands (v.25ter) 
      iInterface    0 
      CDC Header: 
      bcdCDC    1.10 
      CDC ACM: 
      bmCapabilities  0x06 
       sends break 
       line coding and serial state 
      CDC Union: 
      bMasterInterface  0 
      bSlaveInterface   1 
      CDC Call Management: 
      bmCapabilities  0x01 
       call management 
      bDataInterface   1 
      Endpoint Descriptor: 
      bLength     7 
      bDescriptorType   5 
      bEndpointAddress  0x85 EP 5 IN 
      bmAttributes   3 
       Transfer Type   Interrupt 
       Synch Type    None 
       Usage Type    Data 
      wMaxPacketSize  0x0040 1x 64 bytes 
      bInterval    2 
     Interface Descriptor: 
      bLength     9 
      bDescriptorType   4 
      bInterfaceNumber  1 
      bAlternateSetting  0 
      bNumEndpoints   2 
      bInterfaceClass  10 CDC Data 
      bInterfaceSubClass  0 Unused 
      bInterfaceProtocol  0 
      iInterface    0 
      Endpoint Descriptor: 
      bLength     7 
      bDescriptorType   5 
      bEndpointAddress  0x01 EP 1 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  0x81 EP 1 IN 
      bmAttributes   2 
       Transfer Type   Bulk 
       Synch Type    None 
       Usage Type    Data 
      wMaxPacketSize  0x0040 1x 64 bytes 
      bInterval    0 
     Interface Association: 
      bLength     8 
      bDescriptorType  11 
      bFirstInterface   2 
      bInterfaceCount   2 
      bFunctionClass   2 Communications 
      bFunctionSubClass  2 Abstract (modem) 
      bFunctionProtocol  0 None 
      iFunction    0 
     Interface Descriptor: 
      bLength     9 
      bDescriptorType   4 
      bInterfaceNumber  2 
      bAlternateSetting  0 
      bNumEndpoints   1 
      bInterfaceClass   2 Communications 
      bInterfaceSubClass  2 Abstract (modem) 
      bInterfaceProtocol  1 AT-commands (v.25ter) 
      iInterface    0 
      CDC Header: 
      bcdCDC    1.10 
      CDC ACM: 
      bmCapabilities  0x06 
       sends break 
       line coding and serial state 
      CDC Union: 
      bMasterInterface  2 
      bSlaveInterface   3 
      CDC Call Management: 
      bmCapabilities  0x01 
       call management 
      bDataInterface   3 
      Endpoint Descriptor: 
      bLength     7 
      bDescriptorType   5 
      bEndpointAddress  0x86 EP 6 IN 
      bmAttributes   3 
       Transfer Type   Interrupt 
       Synch Type    None 
       Usage Type    Data 
      wMaxPacketSize  0x0040 1x 64 bytes 
      bInterval    2 
     Interface Descriptor: 
      bLength     9 
      bDescriptorType   4 
      bInterfaceNumber  3 
      bAlternateSetting  0 
      bNumEndpoints   2 
      bInterfaceClass  10 CDC Data 
      bInterfaceSubClass  0 Unused 
      bInterfaceProtocol  0 
      iInterface    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 
      Endpoint Descriptor: 
      bLength     7 
      bDescriptorType   5 
      bEndpointAddress  0x82 EP 2 IN 
      bmAttributes   2 
       Transfer Type   Bulk 
       Synch Type    None 
       Usage Type    Data 
      wMaxPacketSize  0x0040 1x 64 bytes 
      bInterval    0 
    Device Status:  0x0000 
     (Bus Powered) 

我想udev的規則是:

KERNEL=="ttyUSB[0-9]*", SUBSYSTEMS=="usb", ATTRS{bInterfaceNumber}=="01", ATTRS{idVendor}=="04e2", ATTRS{idProduct}=="1412", ACTION=="add", SYMLINK+="test_USB0" 
    KERNEL=="ttyUSB[0-9]*", SUBSYSTEMS=="usb", ATTRS{bInterfaceNumber}=="01", ATTRS{idVendor}=="04e2", ATTRS{idProduct}=="1412", ACTION=="add", SYMLINK+="test_USB1" 
    KERNEL=="ttyUSB[0-9]*", SUBSYSTEMS=="usb", ATTRS{bInterfaceNumber}=="02", ATTRS{idVendor}=="04e2", ATTRS{idProduct}=="1412", ACTION=="add", SYMLINK+="test_USB2" 
    KERNEL=="ttyUSB[0-9]*", SUBSYSTEMS=="usb", ATTRS{bInterfaceNumber}=="03", ATTRS{idVendor}=="04e2", ATTRS{idProduct}=="1412", ACTION=="add", SYMLINK+="test_USB3" 

當我只用第一udev規則沒有bInterfaceNumber屬性,就像這樣:

KERNEL=="ttyUSB[0-9]*", SUBSYSTEMS=="usb", ATTRS{idVendor}=="04e2", ATTRS{idProduct}=="1412", ACTION=="add", SYMLINK+="test_USB0" 

它工作正常。我可以看到創建了指向/ dev/ttyUSB0的符號鏈接/ dev/test_USB0,但插入此usbserial設備時創建的其他ttyUSB設備又如何?

我的猜測是使用bInterfaceNumber屬性,但是當我放入時,沒有任何反應,它似乎完全繞過我的規則。

任何人都可以幫助我嗎?

回答

6

可能是因爲帶有「usb」子系統的設備接口沒有得到任何 創建的設備文件,只有usb設備本身。當您使用udevadm monitor插入設備時,您可以看到創建的udev事件 以及變量。

我看到對應的sysfs節點,它可以 有bInterfaceNumber屬性不具備DEVNAME變量,它 可能意味着沒有設備文件的設備的事件。同樣的sysfs節點 也沒有「dev」文件,這加強了這一點。然後,我認爲你不想創建一個符號鏈接到一個裸露的「usb」設備,但是 而不是「tty」設備,所以你應該匹配「tty」子系統。

我能到我的單接口TTY轉換器,這個規則匹配:

SUBSYSTEM=="tty", ACTION=="add", \ 
    ENV{ID_VENDOR_ID}=="067b", ENV{ID_MODEL_ID}=="2303", \ 
    ENV{ID_USB_INTERFACE_NUM}=="00", SYMLINK+="test_USB0" 

但隨後的「ID_USB_INTERFACE_NUM」是越來越受udev規則我 系統(Debian的傑西)和你的分配,但是不太可能,可能沒有他們。 但是,您應該能夠制定這樣的規則,可能首先匹配接口設備,然後將bInterfaceNumber分配給變量環境 ,然後在匹配tty設備的規則中使用它。

+0

ENV {ID_USB_INTERFACE_NUM}適用於Fedora 18. ATTRS {bInterfaceNumber}不支持。 – GioMac