触发特定键盘的udev规则

时间:2013-12-16 19:35:35

标签: udev

我需要为特定键盘编写一个udev规则,该规则似乎没有任何匹配的唯一属性。

以下行是插入设备时udevadm monitor的输出。这里有什么我可以用来唯一识别这个键盘吗?

KERNEL[58443.215701] add      /devices/pci0000:00/0000:00:1a.0/usb1/1-1/1-1.2 (usb)
KERNEL[58443.218536] add      /devices/pci0000:00/0000:00:1a.0/usb1/1-1/1-1.2/1-1.2:1.0 (usb)
KERNEL[58443.218662] add      /devices/pci0000:00/0000:00:1a.0/usb1/1-1/1-1.2/1-1.2:1.0/0003:04B3:3025.0005 (hid)
KERNEL[58443.221610] add      /devices/pci0000:00/0000:00:1a.0/usb1/1-1/1-1.2/1-1.2:1.0/input/input15 (input)
KERNEL[58443.221669] add      /devices/pci0000:00/0000:00:1a.0/usb1/1-1/1-1.2/1-1.2:1.0/input/input15/event4 (input)
KERNEL[58443.221868] add      /devices/pci0000:00/0000:00:1a.0/usb1/1-1/1-1.2/1-1.2:1.0/0003:04B3:3025.0005/hidraw/hidraw0 
UDEV  [58443.236718] add      /devices/pci0000:00/0000:00:1a.0/usb1/1-1/1-1.2 (usb)                                       
UDEV  [58443.238026] add      /devices/pci0000:00/0000:00:1a.0/usb1/1-1/1-1.2/1-1.2:1.0 (usb)
UDEV  [58443.239532] add      /devices/pci0000:00/0000:00:1a.0/usb1/1-1/1-1.2/1-1.2:1.0/0003:04B3:3025.0005 (hid)
UDEV  [58443.240670] add      /devices/pci0000:00/0000:00:1a.0/usb1/1-1/1-1.2/1-1.2:1.0/0003:04B3:3025.0005/hidraw/hidraw0 
UDEV  [58443.288767] add      /devices/pci0000:00/0000:00:1a.0/usb1/1-1/1-1.2/1-1.2:1.0/input/input15 (input)             
UDEV  [58443.319799] add      /devices/pci0000:00/0000:00:1a.0/usb1/1-1/1-1.2/1-1.2:1.0/input/input15/event4 (input)

编辑:

以下是将键盘插入另一个USB端口的行。据我所知,似乎没有任何信息保持不变。

KERNEL[59428.187673] add      /devices/pci0000:00/0000:00:1d.0/usb2/2-1/2-1.1 (usb)
KERNEL[59428.190323] add      /devices/pci0000:00/0000:00:1d.0/usb2/2-1/2-1.1/2-1.1:1.0 (usb)
KERNEL[59428.190494] add      /devices/pci0000:00/0000:00:1d.0/usb2/2-1/2-1.1/2-1.1:1.0/0003:04B3:3025.0006 (hid)
KERNEL[59428.193088] add      /devices/pci0000:00/0000:00:1d.0/usb2/2-1/2-1.1/2-1.1:1.0/input/input16 (input)
KERNEL[59428.193266] add      /devices/pci0000:00/0000:00:1d.0/usb2/2-1/2-1.1/2-1.1:1.0/input/input16/event4 (input)
KERNEL[59428.193426] add      /devices/pci0000:00/0000:00:1d.0/usb2/2-1/2-1.1/2-1.1:1.0/0003:04B3:3025.0006/hidraw/hidraw0 
UDEV  [59428.300690] add      /devices/pci0000:00/0000:00:1d.0/usb2/2-1/2-1.1 (usb)                                       
UDEV  [59428.301790] add      /devices/pci0000:00/0000:00:1d.0/usb2/2-1/2-1.1/2-1.1:1.0 (usb)
UDEV  [59428.302553] add      /devices/pci0000:00/0000:00:1d.0/usb2/2-1/2-1.1/2-1.1:1.0/0003:04B3:3025.0006 (hid)
UDEV  [59428.303130] add      /devices/pci0000:00/0000:00:1d.0/usb2/2-1/2-1.1/2-1.1:1.0/0003:04B3:3025.0006/hidraw/hidraw0 
UDEV  [59428.319082] add      /devices/pci0000:00/0000:00:1d.0/usb2/2-1/2-1.1/2-1.1:1.0/input/input16 (input)             
UDEV  [59428.321444] add      /devices/pci0000:00/0000:00:1d.0/usb2/2-1/2-1.1/2-1.1:1.0/input/input16/event4 (input)

编辑:使用lsusb -v,我找到了idVendoridProduct

Bus 002 Device 009: ID 04b3:3025 IBM Corp. 
Device Descriptor:
  bLength                18
  bDescriptorType         1
  bcdUSB               1.10
  bDeviceClass            0 (Defined at Interface level)
  bDeviceSubClass         0 
  bDeviceProtocol         0 
  bMaxPacketSize0         8
  idVendor           0x04b3 IBM Corp.
  idProduct          0x3025 
  bcdDevice            1.09
  iManufacturer           1 LITE-ON Technology
  iProduct                2 USB NetVista Full Width Keyboard.
  iSerial                 0 
  bNumConfigurations      1
  Configuration Descriptor:
    bLength                 9
    bDescriptorType         2
    wTotalLength           34
    bNumInterfaces          1
    bConfigurationValue     1
    iConfiguration          4 HID Keyboard
    bmAttributes         0xa0
      (Bus Powered)
      Remote Wakeup
    MaxPower               70mA
    Interface Descriptor:
      bLength                 9
      bDescriptorType         4
      bInterfaceNumber        0
      bAlternateSetting       0
      bNumEndpoints           1
      bInterfaceClass         3 Human Interface Device
      bInterfaceSubClass      1 Boot Interface Subclass
      bInterfaceProtocol      1 Keyboard
      iInterface              5 EP1 Interrupt
        HID Device Descriptor:
          bLength                 9
          bDescriptorType        33
          bcdHID               1.10
          bCountryCode            0 Not supported
          bNumDescriptors         1
          bDescriptorType        34 Report
          wDescriptorLength      65
         Report Descriptors: 
           ** UNAVAILABLE **
      Endpoint Descriptor:
        bLength                 7
        bDescriptorType         5
        bEndpointAddress     0x81  EP 1 IN
        bmAttributes            3
          Transfer Type            Interrupt
          Synch Type               None
          Usage Type               Data
        wMaxPacketSize     0x0008  1x 8 bytes
        bInterval              24
Device Status:     0x0000
  (Bus Powered)

所以我创建了以下udev规则:

SUBSYSTEM=="usb", ATTR{idVendor}=="0x04b3", ATTRS{idProduct}=="0x3025", RUN+="/home/myuser/bin/udev_jap.sh"

但是到目前为止还没有触发任何内容。奇怪的是,idVendoridProduct信息未显示在udevadm monitor上。这是否意味着udev无法与这些属性匹配?

1 个答案:

答案 0 :(得分:1)

无论如何,这是一个老问题:

  • 您必须删除0x十六进制前缀。
  • 请注意,ATTRATTRS不同,但对于您的情况,两者都应该有效。
  • 您的脚本udev_jap.sh应该从shebang #!/bin/sh开始,或者运行shell本身:

     RUN+="/bin/sh /home/myuser/bin/udev_jap.sh"
    

试试这个:

SUBSYSTEM=="usb", ATTR{idVendor}=="04b3", ATTR{idProduct}=="3025", RUN+="/home/myuser/bin/udev_jap.sh"