0

I am trying to write a modified/custom USB keyboard driver. I'm having an issue with the irq handler not receiving key presses as expect.

What I've done:

  1. Made a copy of /linux/driver/hid/usbhid/usbkbd.c link and modified usb_kbd_id_table to have only the vendor id and product id associated with my keyboard.
  2. Built the modified driver.
  3. Inserted the modified driver with sudo insmod usbkbd.ko.
  4. Prevented the keyboard from being associated with the standard HID driver by adding usbhid:quirks=0x03eb:0x20ff:0x4 to /etc/default/grub.

Behavior:

  1. Upon plugging in the keyboard, it is correctly associated with my driver. I know this because I see a printk statement that I added in usb_kbd_probe show up in /var/log/syslog. It actually shows up twice because the device has 2 interfaces.
  2. The function usb_kbd_irq is repeatedly called in a loop. I have added a printk here as well and I see that kbd->new always has 0 in every byte.
  3. This loop continues rapidly and pressing any of the keys has no effect (kbd->new always has 0 in every byte regardless of keys pressed).

I have tried using wireshark to view the usb trafic and I see that the host and device are going back and forth. I was expecting one way traffic. wireshark screenshot

I am confused about why the key presses have no effect. Shouldn't I see some data in kbd->new if a key has been pressed?

Edit: Screen shot with device info at https://i.stack.imgur.com/lNq4e.png

1 Answers1

0

The issue was with the way I was dissociating the device with the generic USBHID driver. Listed in set 4 above:

  1. Prevented the keyboard from being associated with the standard HID driver by adding usbhid:quirks=0x03eb:0x20ff:0x4 to /etc/default/grub

If I instead unbind the device manually and bind it to my driver then the IRQ no longer loops and I do in fact see different input for each key press. I used instructions found here https://lwn.net/Articles/143397/