我尝试使用本教程编写一个简单的 linux char 设备驱动程序:http: //matthias.vallentin.net/blog/2007/04/writing-a-linux-kernel-driver-for-an-unknown-usb-device /
我正在使用稍新的设备和稍新的内核。因此,我使用了他们的代码更改产品和供应商 ID,并且我只是尝试在连接设备时进行内核调用探测功能,但我未能查看我的 /var/log/messages。驱动加载成功:
Sep 5 18:32:43 manticore kernel: [10673.664884] usbcore: deregistering interface driver missile_launcher
Sep 5 18:32:43 manticore kernel: [10673.664908] [info] usb_ml_exit(661): module deregistered
Sep 5 18:32:43 manticore kernel: [10673.666314] usbcore: registered new interface driver missile_launcher
Sep 5 18:32:43 manticore kernel: [10673.666317] [info] usb_ml_init(651): driver registered successfully
但是当设备连接时,驱动程序不被使用:
Sep 5 17:58:12 manticore kernel: [ 8607.295688] usb 3-1.1: New USB device found, idVendor=2123, idProduct=1010
Sep 5 17:58:12 manticore kernel: [ 8607.295689] usb 3-1.1: New USB device strings: Mfr=1, Product=2, SerialNumber=0
Sep 5 17:58:12 manticore kernel: [ 8607.295691] usb 3-1.1: Product: USB Missile Launcher
Sep 5 17:58:12 manticore kernel: [ 8607.295693] usb 3-1.1: Manufacturer: Syntek
Sep 5 17:58:12 manticore kernel: [ 8607.295789] usb 3-1.1: usb_probe_device
Sep 5 17:58:12 manticore kernel: [ 8607.295791] usb 3-1.1: configuration #1 chosen from 1 choice
Sep 5 17:58:12 manticore kernel: [ 8607.295797] usb 3-1.1: ep 0x81 - rounding interval to 64 microframes, ep desc says 80 microframes
Sep 5 17:58:12 manticore kernel: [ 8607.295855] usb 3-1.1: Successful Endpoint Configure command
Sep 5 17:58:12 manticore kernel: [ 8607.296132] usb 3-1.1: adding 3-1.1:1.0 (config #1, interface 0)
Sep 5 17:58:12 manticore kernel: [ 8607.296173] usbhid 3-1.1:1.0: usb_probe_interface
Sep 5 17:58:12 manticore kernel: [ 8607.296174] usbhid 3-1.1:1.0: usb_probe_interface - got id
Sep 5 17:58:12 manticore kernel: [ 8607.298577] usbhid 3-1.1:1.0: looking for a minor, starting at 96
Sep 5 17:58:12 manticore kernel: [ 8607.298697] generic-usb 0003:2123:1010.0008: hiddev0,hidraw2: USB HID v1.10 Device [Syntek USB Missile Launcher] on usb-0000:00:14.0-1.1/input0
Sep 5 17:58:12 manticore kernel: [ 8607.298712] drivers/usb/core/inode.c: creating file '016'
Sep 5 17:58:12 manticore kernel: [ 8607.298754] hub 3-1:1.0: port 2, status 0101, change 0000, 12 Mb/s
Sep 5 17:58:12 manticore kernel: [ 8607.310627] hub 3-1:1.0: port 2 not reset yet, waiting 10ms
Sep 5 17:58:12 manticore kernel: [ 8607.372509] usb 3-1.2: new high-speed USB device number 17 using xhci_hcd
Sep 5 17:58:12 manticore kernel: [ 8607.418456] usb 3-1.2: skipped 1 descriptor after configuration
Sep 5 17:58:12 manticore kernel: [ 8607.418460] usb 3-1.2: skipped 6 descriptors after interface
Sep 5 17:58:12 manticore kernel: [ 8607.418462] usb 3-1.2: skipped 1 descriptor after endpoint
Sep 5 17:58:12 manticore kernel: [ 8607.418463] usb 3-1.2: skipped 9 descriptors after interface
Sep 5 17:58:12 manticore kernel: [ 8607.419100] usb 3-1.2: default language 0x0409
Sep 5 17:58:12 manticore kernel: [ 8607.421607] usb 3-1.2: udev 17, busnum 3, minor = 272
我负责建立此关联的代码是:
#define ML_VENDOR_ID 0x2123
#define ML_PRODUCT_ID 0x1010
static struct usb_device_id ml_table [] = {
{ USB_DEVICE(ML_VENDOR_ID, ML_PRODUCT_ID) },
{ }
};
static struct usb_driver ml_driver = {
.name = "missile_launcher",
.id_table = ml_table,
.probe = ml_probe,
.disconnect = ml_disconnect,
};
我的内核版本是 3.3.8
有什么想法可能是错的吗?
顺便提一句。我对此完全陌生,因此很可能我跳过了一些相关信息,请询问我是否需要更多信息。