USB keyboard stops working after pressing extended key

Bug #1511511 reported by Daniel M. Lambea
38
This bug affects 6 people
Affects Status Importance Assigned to Milestone
linux (Ubuntu)
Confirmed
Medium
Unassigned

Bug Description

USB keyboard Cougar 500k Gaming Keyboard has some additional extended keys, all of them making the keyboard stop responding if pressed under linux. The device is recovered only by unplugging the USB and plugging it again.

The keyboard has been tested under Ubuntu 14.04.3 LTS, Ubuntu 15.04 and Ubuntu 15.10 (the latter running as virtualbox guest). All tests failed with exactly the same behaviour.

USB ID is: "060b:500a Solid Year".

ProblemType: Bug
DistroRelease: Ubuntu 15.10
Package: linux-image-4.2.0-16-generic 4.2.0-16.19 [modified: boot/vmlinuz-4.2.0-16-generic]
ProcVersionSignature: Ubuntu 4.2.0-16.19-generic 4.2.3
Uname: Linux 4.2.0-16-generic x86_64
ApportVersion: 2.19.1-0ubuntu3
Architecture: amd64
AudioDevicesInUse:
 USER PID ACCESS COMMAND
 /dev/snd/controlC0: pinfli 1055 F.... pulseaudio
Date: Thu Oct 29 19:33:23 2015
HibernationDevice: RESUME=UUID=f68f4b91-ea68-4e4b-9a10-8ed5bca2efbe
InstallationDate: Installed on 2015-10-24 (5 days ago)
InstallationMedia: Ubuntu-GNOME 15.10 "Wily Werewolf" - Release amd64 (20151021)
IwConfig:
 enp0s3 no wireless extensions.

 lo no wireless extensions.
Lsusb:
 Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
 Bus 002 Device 002: ID 060b:500a Solid Year
 Bus 002 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub
MachineType: innotek GmbH VirtualBox
ProcFB:

ProcKernelCmdLine: BOOT_IMAGE=/boot/vmlinuz-4.2.0-16-generic root=UUID=523dfd8b-b825-47e3-a116-cb85f901386c ro quiet splash
PulseList: Error: command ['pacmd', 'list'] failed with exit code 1: No PulseAudio daemon running, or not running as session daemon.
RelatedPackageVersions:
 linux-restricted-modules-4.2.0-16-generic N/A
 linux-backports-modules-4.2.0-16-generic N/A
 linux-firmware 1.149
RfKill:

SourcePackage: linux
UdevLog: Error: [Errno 2] No such file or directory: '/var/log/udev'
UpgradeStatus: No upgrade log present (probably fresh install)
dmi.bios.date: 12/01/2006
dmi.bios.vendor: innotek GmbH
dmi.bios.version: VirtualBox
dmi.board.name: VirtualBox
dmi.board.vendor: Oracle Corporation
dmi.board.version: 1.2
dmi.chassis.type: 1
dmi.chassis.vendor: Oracle Corporation
dmi.modalias: dmi:bvninnotekGmbH:bvrVirtualBox:bd12/01/2006:svninnotekGmbH:pnVirtualBox:pvr1.2:rvnOracleCorporation:rnVirtualBox:rvr1.2:cvnOracleCorporation:ct1:cvr:
dmi.product.name: VirtualBox
dmi.product.version: 1.2
dmi.sys.vendor: innotek GmbH

Revision history for this message
Daniel M. Lambea (dmlambea) wrote :
Revision history for this message
Brad Figg (brad-figg) wrote : Status changed to Confirmed

This change was made by a bot.

Changed in linux (Ubuntu):
status: New → Confirmed
Revision history for this message
Daniel M. Lambea (dmlambea) wrote :

Dmesg log info shows the folling: "hid-generic 0003:060B:500A.000A: usage index exceeded".

I attach the device rdesc file, obtained from: cat /sys/kernel/debug/hid/0003:060B:500A.000A/rdesc

Revision history for this message
Joseph Salisbury (jsalisbury) wrote :

Did this issue start happening after an update/upgrade? Was there a prior kernel version where you were not having this particular problem?

Would it be possible for you to test the latest upstream kernel? Refer to https://wiki.ubuntu.com/KernelMainlineBuilds . Please test the latest v4.3 kernel[0].

If this bug is fixed in the mainline kernel, please add the following tag 'kernel-fixed-upstream'.

If the mainline kernel does not fix this bug, please add the tag: 'kernel-bug-exists-upstream'.

Once testing of the upstream kernel is complete, please mark this bug as "Confirmed".

Thanks in advance.

[0] http://kernel.ubuntu.com/~kernel-ppa/mainline/v4.3-unstable/

Changed in linux (Ubuntu):
importance: Undecided → Medium
status: Confirmed → Incomplete
Revision history for this message
Daniel M. Lambea (dmlambea) wrote :

The keyboard was bought a few months ago and the bug have always been there. I've tried the keyboard both in upgraded systems and in fresh installations to no avail.

Following your instructions, I have just tested it right now using the mainline kernel (at the URL you provided) and the bug is still showing, so I proceed with adding the tag 'kernel-bug-exists-upstream'.

tags: added: kernel-bug-exists-upstream
Changed in linux (Ubuntu):
status: Incomplete → Confirmed
Revision history for this message
Daniel M. Lambea (dmlambea) wrote :

The keyboard has been tested in Ubuntu 16.04LTS kernel 4.4.0-34 x86_64 with the same behavior.

Revision history for this message
Daniel M. Lambea (dmlambea) wrote :

I've managed to collect two PCAPNG files, one captured using virtualized Windows 7 and the second directly under Ubuntu 16.04LTS fully upgraded up to date.

In both sessions, after initialization I pressed "a" key, then special key "G6". The "a" key makes four packets to be recorded. The "G6" special key generates six packets under Windows and only four packets under Linux (the first two packets that can be seen in the Windows dump never occur in Linux). After hitting "G6", the Windows session is fully responsive. But in the Linux session, the device stops responding until:
  a) is unplugged, then replugged.
  b) the USB is connected to the Windows Virtual Machine (VirtualBox), which resets the device and makes it responsive again.

In the Windows dump, the last 10 packets correspond to the "a" keypress (4 packets) then "G6" keypress (6 packets). In the Linux dump, the last 8 packets correspond to the "a" keypress (4 packets), then "G6" keypress (only 4 packets).

Revision history for this message
nachofaith (ruben-godoy) wrote :

the same happen in cougar 500k :D

Revision history for this message
Alexander (netzschlange) wrote :

Partially I solved the problem with Cougar 500K.
The problem lies in the fact that this keyboard has three interfaces (in terms of USB), for the first two (keyboard and mouse) the kernel attaches the input driver (from dmesg):

0003:060B:500A.0001: input,hidraw0: USB HID v1.11 Keyboard [Cougar500k Cougar500k Gaming Keyboard] on usb-0000:00:06.0-1/input0
----> input: Cougar500k Cougar500k Gaming Keyboard as /devices/pci0000:00/0000:00:06.0/usb2/2-1/2-1:1.0/0003:060B:500A.0001/input/input6

0003:060B:500A.0002: input,hiddev0,hidraw2: USB HID v1.11 Mouse [Cougar500k Cougar500k Gaming Keyboard] on usb-0000:00:06.0-1/input1
----> input: Cougar500k Cougar500k Gaming Keyboard as /devices/pci0000:00/0000:00:06.0/usb2/2-1/2-1:1.1/0003:060B:500A.0002/input/input7

and for the third it does not (from dmesg):

0003:060B:500A.0003: hiddev0,hidraw1: USB HID v1.11 Device [Cougar500k Cougar500k Gaming Keyboard] on usb-0000:00:06.0-1/input2
----> !!!!! no input driver attached !!!!!

Problem arise due to the lack of an input driver for the third interface.
When you press any additional extended key, the microcontroller of the keyboard generates the USB packets for transmission through the third interface to kernel.
And the keyboard microcontroller will stop his work until the kernel driver process this USB packets.

I solved this problem ugly (due insufficient knowledge in writing drivers for Linux and HID devices). I connect the simplest input driver to the third interface which reads USB packets without processing any data in packet. As a result, the main keys work, but additional keys not. But at least the keyboard no longer freezes when I press additional keys.

Revision history for this message
Alejandro Díaz-Caro (janusdc) wrote :

@Alexander: I would very much appreciate if you could share the driver you have created...

Revision history for this message
Alexander (netzschlange) wrote :

As a basis, I used the sources from https://bitbucket.org/Swoogan/aziokbd/overview.
Just correct values for the 'VENDOR_ID' and "PRODUCT ID' and other parameters, as well as cut out a piece of code that handles data from the keyboard (the method 'static void usb_kbd_irq (struct urb * urb)', lines 167 to 281).
I understand that this is not right, but I do not have knowledge for more and I haven't enough time for study 'Linux Device Drivers' and write a correct driver.

Revision history for this message
dewes (rdewes) wrote :

I can confirm that the same happens on Cougar 700k. Also tried on Fedora 25.

Revision history for this message
Taimur (taimur-rabuske) wrote :

@Alexander: This is by far the best solution that I found so far. I followed your steps, and managed to attach the whole device (the 3 interfaces) to the aziokbd driver. However, by doing so, the main keys also do not work. How did you attach only the third interface to the aziokbd driver, and kept the two main interfaces (keyboard and mouse) attached to the usbhid driver?

Cheers.

Revision history for this message
Taimur (taimur-rabuske) wrote :

Never mind, @Alexander. I managed to find out myself. As it may be useful to others, I will explain how it's done. I created a small bash script, e.g. cougar_keyboard.sh, with the following contents:

#!/bin/bash
sudo su -c 'echo -n "1-13:1.2" > /sys/bus/usb/drivers/usbhid/unbind'
sudo su -c 'echo -n "1-13:1.2" > /sys/bus/usb/drivers/aziokbd/bind'

Here, 1-13:1 is the USB address of my keyboard, it will vary on other computers.
The first command unbinds the third (thus xxx.2 in the address, as it starts from 0) interface of the USB device from the regular usbhid driver. Second command binds it to the aziokbd driver.

Cheers.

Revision history for this message
Kai-Heng Feng (kaihengfeng) wrote :
Revision history for this message
Alejandro Díaz-Caro (janus) wrote :

@Kai-Heng Feng: Could you please upload a patch, or the sources, or the config file, or whatever change you have made to the kernel, so those with other distributions (like me) can also test it?
I am on Arch Linux with kernel 4.12.8.

Revision history for this message
Kai-Heng Feng (kaihengfeng) wrote :

Well, that's something from quite a long time ago, I can't find anything remains for this bug in my Linux source tree, so...

I guess I added some workaround for it, but it's not the right solution.

The correct way is to write a new HID driver for the device.

Revision history for this message
Daniel M. Lambea (dmlambea) wrote :

@Alexander, @Taimur: thanks to your comments and efforts, I've managed to make a very basic HID driver for this keyboard. I have tested it against kernel 4.15.0-23-generic with success. Please remove "hid_generic" before loading this module and plugging the keyboard in, so that hid_generic doesn't take on the device.

I took some parts from the aziokbd.c driver (by Colin Svingen; https://bitbucket.org/Swoogan/aziokbd/src/f3611717bce078056634bc2312dba2787a433401/aziokbd.c?fileviewer=file-view-default) and made a minimal mapping table between the special keys G1-G6 to F1-F5 and SPACE. this way, the rightmost part of the spacebar (which is labelled as G6) also works as the SPACE key.

This is my very first implementation of anything related to kernel code, so expect it to be ugly, buggy and incorrect. Actually, I've found that the kernel oops with a stack trace when the device is disconnected. This is not a problem if you're using the keyboard as usual, but if you're unplugging it (as when debugging with a VM, for example), your machine/VM will become unstable.

I hope somebody with better understanding of USB and kernel driver programming will take it and make something good out of this code. If you are interested in evolving this driver and you need me to send you keycodes/debugging output, don't hesitate to contact me.

Revision history for this message
Daniel M. Lambea (dmlambea) wrote :

I've uploaded the code to Github, so it can be better read there.

https://github.com/dmlambea/linux-cougar-500k-drv

description: updated
Revision history for this message
Daniel M. Lambea (dmlambea) wrote :

Release 0.5 makes this device fully functional. You can download it from: https://github.com/dmlambea/linux-cougar-500k-drv/releases

Revision history for this message
Kai-Heng Feng (kaihengfeng) wrote :

Will you upstream your driver? I can backport it to Ubuntu's kernel.

Revision history for this message
Daniel M. Lambea (dmlambea) wrote :

@kaihengfeng, I believe upstreaming the driver is the right thing to do, but I need to learn more about how in-tree drivers are written and submitted.

Yes, I will try my best to upstreaming it. I will contact you when/if the driver is accepted. Thank you very much for your help.

Revision history for this message
Alejandro Díaz-Caro (janusdc) wrote :

I confirm the module works like a charm on Arch Linux, kernel 4.17.
Thanks!
(Here are the instructions to compile it: https://help.ubuntu.com/community/DKMS)

Revision history for this message
Daniel M. Lambea (dmlambea) wrote :

@kaihengfeng, I've sent the code to kernel.org and it's under review.

In the meantime, I am keeping the code in my Github updated, so the users can download a pre-packaged DKMS deb file from it (or compile their own).

To post a comment you must log in.