Eu tenho um driver bem simples para o teclado USB:
#include <linux/module.h>
#include <linux/kernel.h>
#include <linux/usb.h>
#include <linux/usb/input.h>
#include <linux/hid.h>
MODULE_LICENSE("GPL");
MODULE_AUTHOR("TEST_USER");
MODULE_DESCRIPTION("A USB Keyboard Driver Kernel Module");
static struct usb_device_id usb_kbd_id_table[] = {
{ USB_INTERFACE_INFO(
USB_INTERFACE_CLASS_HID,
USB_INTERFACE_SUBCLASS_BOOT,
USB_INTERFACE_PROTOCOL_KEYBOARD) },
{ } /* Terminating entry */
};
MODULE_DEVICE_TABLE(usb, usb_kbd_id_table);
static int kbd_probe(struct usb_interface *interface,
const struct usb_device_id *id)
{
pr_info("USB keyboard probe function called\n");
return 0;
}
static void kbd_disconnect(struct usb_interface *interface)
{
pr_info("USB keyboard disconnect function called\n");
}
static struct usb_driver kbd_driver = {
.name = "usbkbd",
.probe = kbd_probe,
.disconnect = kbd_disconnect,
.id_table = usb_kbd_id_table,
};
static int __init kbd_init(void)
{
int res = 0;
res = usb_register(&kbd_driver);
if (res)
pr_err("usb_register failed with error %d", res);
return res;
}
static void __exit kbd_exit(void)
{
pr_debug("USB Keyboard Removed..\n");
usb_deregister(&kbd_driver);
return;
}
module_init(kbd_init);
module_exit(kbd_exit);
Eu nomeio kbtest.ko
e carrego com insmod kbtest.ko
e ele é confirmado e com êxito com lsmod
. Concretamente:
lsmod | grep "usb"
usbhid 31758 0
hid 69153 2 hid_generic,usbhid
usbcore 115019 6 ohci_hcd,ohci_pci,ehci_hcd,ehci_pci,kbtest,usbhid
usb_common 12484 1 usbcore
Por isso, conecto meu teclado USB, mas não consigo executar o driver. Concretamente, a função sonda não é chamada. Aqui está o meu dmesg após a detecção do teclado:
[ 1219.695553] usb 1-2: new full-speed USB device number 6 using ohci-pci
[ 1219.996010] usb 1-2: New USB device found, idVendor=1267, idProduct=0103
[ 1220.016126] usb 1-2: New USB device strings: Mfr=0, Product=0, SerialNumber=0
[ 1220.100005] input: HID 1267:0103 as /devices/pci0000:00/0000:00:06.0/usb1/1-2/1-2:1.0/0003:1267:0103.0008/input/input14
[ 1220.126349] hid-generic 0003:1267:0103.0008: input,hidraw1: USB HID v1.10 Keyboard [HID 1267:0103] on usb-0000:00:06.0-2/input0
[ 1220.206453] input: HID 1267:0103 as /devices/pci0000:00/0000:00:06.0/usb1/1-2/1-2:1.1/0003:1267:0103.0009/input/input15
[ 1220.224334] hid-generic 0003:1267:0103.0009: input,hidraw2: USB HID v1.10 Device [HID 1267:0103] on usb-0000:00:06.0-2/input1
A informação termina aqui. Qual é exatamente o problema aqui? Estou executando a máquina Debian dentro do Virtual Box.