Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error: Handshake failed (USB-HID Gaming Keyboard) #102

Open
EquinoxTheGryph opened this issue Dec 21, 2020 · 20 comments
Open

Error: Handshake failed (USB-HID Gaming Keyboard) #102

EquinoxTheGryph opened this issue Dec 21, 2020 · 20 comments

Comments

@EquinoxTheGryph
Copy link

Hello!

I've recently finished my custom build using a GK64XS board.
When i try to run this software on linux (arch) it will throw this error:

Handshake failed (USB-HID Gaming Keyboard) Exception occured. System.TimeoutException: The operation has timed out.
  at HidSharp.Platform.SysHidStream.CommonWrite (System.Byte[] buffer, System.Int32 offset, System.Int32 count, System.Collections.Generic.Queue`1[T] queue, System.Boolean feature, System.Int32 maxOutputReportLength) [0x000c0] in <c054361863a44e168db2058f0e09fb11>:0 
  at HidSharp.Platform.Linux.LinuxHidStream.Write (System.Byte[] buffer, System.Int32 offset, System.Int32 count) [0x00016] in <c054361863a44e168db2058f0e09fb11>:0 
  at HidSharp.HidStream.Write (System.Byte[] buffer) [0x00011] in <c054361863a44e168db2058f0e09fb11>:0 
  at (wrapper remoting-invoke-with-check) HidSharp.HidStream.Write(byte[])
  at GK6X.KeyboardDeviceManager.WriteSimplePacket (HidSharp.HidStream stream, System.UInt16 opcode) [0x00036] in <db153b96816840d5bd65cfc519156440>:0 
  at GK6X.KeyboardDeviceManager.Handshake (HidSharp.HidStream stream) [0x00002] in <db153b96816840d5bd65cfc519156440>:0 
Keyboard handshake failed

lsusb:
Bus 001 Device 004: ID 1ea7:0907 SHARKOON Technologies GmbH Keyboard

So far tried:

  • Running in sudo (sudo mono GK6X.exe)
  • Rebooting
  • Replugging the keyboard
  • Make sure no other keyboards are connected
  • Running pre-compiled (gui and no gui versions) and self-compiled versions

I feel like i'm missing something... Any tips?
Thanks!

@pixeltris
Copy link
Owner

I'm not sure. It detects the device but fails to send any data to it. The only thing I can think that might cause this is something else is already using interacting with the device so the write fails.

@EquinoxTheGryph
Copy link
Author

Is there any way to enable debug output / increase output verbosity to maybe see at which step it fails?

@EquinoxTheGryph
Copy link
Author

Do i need any external libraries?

@pixeltris
Copy link
Owner

pixeltris commented Dec 21, 2020

I'm assuming it's failing on the first write (I assume this because if one write is successful, all of them should be successful, all that matters for read/write is that you use the correct "report length", see the HID spec).

using (Packet packet = WriteSimplePacket(stream, 0x0901))

The actual write occurs on a separate thread. The thread that waits for the write has a timeout value, at which point the write is aborted. The actual write call is made in HIDSharp here:

https://github.com/treehopper-electronics/HIDSharp/blob/6fa83aaa3c82547451f4c2ae3666e45afd04b431/HidSharp/Platform/Linux/LinuxHidStream.cs#L229

There isn't any more verbose logging that you could add to GK6X. You might be able to check errno after the write, but with all the C# stuff going on, errno might be overwritten anyway.

Your best bet is probably sniffing what's going on with wireshark's USB sniffer. Making sure there's the expected request, and a response from the device (I think these are always 65 bytes long).

@EquinoxTheGryph
Copy link
Author

Well, sadly i don't have a whole lot of experience with c# and especially wireshark usb, but at least i can confirm that the program throws the error at the given line

Console.WriteLine("#0");
using (Packet packet = WriteSimplePacket(stream, 0x0901))
{
    Console.WriteLine("#1");

@EquinoxTheGryph
Copy link
Author

Alright, here's a capture at the moment of connecting the device in wireshark, device should be at 1.10.0, which is at the end of the capture. maybe it might be of use?
capture.zip

@pixeltris
Copy link
Owner

pixeltris commented Jan 16, 2021

It looks like the keyboard responds to the first request, but there's no data in the response. The handshake is expecting a report response with a matching opcode.

Packet No. 1064 (request):

0000   80 4a 32 ac ef 91 ff ff 53 02 00 0a 01 00 00 00   .J2.....S.......
0010   2a ac fd 5f 00 00 00 00 f7 64 0a 00 8d ff ff ff   *.._.....d......
0020   00 00 00 00 00 00 00 00 00 09 01 00 00 00 00 00   ................
0030   00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00   ................

Packet No. 1065 (response):

0000   80 4a 32 ac ef 91 ff ff 43 02 00 0a 01 00 2d 3e   .J2.....C.....->
0010   2a ac fd 5f 00 00 00 00 51 68 0a 00 00 00 00 00   *.._....Qh......
0020   00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00   ................
0030   00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00   ................

It's hard to tell why it would respond with an empty report. I'd probably suggest probing the device with other reports to see how it responds (i.e. the 0x0101 report), and if it always responds with empty reports. I'd also suggest seeing how it behaves under a different OS such as Windows.

@EquinoxTheGryph
Copy link
Author

Well, the only thing i can say is that it does work in windows with the official software... (I don't have any experience with the USB protocol, i only figured out how to wireshark usb) maybe it has to do with the firmware on the keyboard? is there any way to update it? it seems like the official software doesn't come with any way to update it, it only reports the fw version (1.19, driver version 6.0.0.39)

@pixeltris
Copy link
Owner

pixeltris commented Jan 16, 2021

Does this project work on Windows for you? It could potentially be a bug in HIDSharp on Linux, or hidraw, or just something that I'm doing wrong with interacting with HID which is non-standard. I'm not super familiar with the protocol in general, I just implemented things based on what I saw.

You shouldn't need to update the firmware if it works on Windows as that means the keyboard is operating correctly. There generally aren't firmware files available to download for GK6X boards either.

@EquinoxTheGryph
Copy link
Author

Seems like it does work on windows! will look into the libraries you mentioned...

The CLI on windows reports Connected to device 'GK64XS-RGB' model:656801805 fw:v1.19

@pixeltris
Copy link
Owner

I guess that would mean it's either an issue with HIDSharp, hidraw, or a non-standard interaction. I'll make a wireshark log on windows at some point and compare to see if I see anything that stands out. If the outgoing report is correct/standard then I'd assume it could only be an issue in hidraw, or a lower level Linux API. Though I wouldn't have a clue as to exactly what in such case.

@EquinoxTheGryph
Copy link
Author

EquinoxTheGryph commented Jan 16, 2021

I will try building the latest version of hidraw, maybe it already fixed some stuff.

EDIT: Nope, didn't work...

@Invades
Copy link

Invades commented Feb 15, 2021

I've also been having this exact same issue on my arch install while it works fine on windows, did you ever figure it out? @stcraft

@EquinoxTheGryph
Copy link
Author

I've also been having this exact same issue on my arch install while it works fine on windows, did you ever figure it out? @stcraft

Well, the script + GUI works on windows, but I just don't know how I can fix it on Linux... I think it is indeed some kind of bug in the libraries.

@Invades
Copy link

Invades commented Feb 15, 2021

I just tried it on a USB 2.0 port and that seemed to fix the issue for me, have you tried that?

@konsumer
Copy link

On Pop!OS 20.10, I was having similar problem, with keyboard attached through a USB hub, on a black USB1 port.

Plugged directly into a USB2 (blue) plug I got this:

Connected to device 'SK96S RGB' model:656801880 fw:v1.15

I plugged the hub into the same port, and the keyboard through that, and it also worked fine. Thanks for the pointer to check the USB port.

@abilash2574
Copy link

hi guys, did you guys find any solution to this problem? I m using this is arch linux, and I am getting the same error as above, Can anyone help me solve this problem

@konsumer
Copy link

@abilash2574 The solution for me and @Invades was to use a USB2 port.

@rahul-ar
Copy link

rahul-ar commented Dec 7, 2021

I have the same issue in both Windows and Manjaro Linux. My model is GK64 and worked fine with the official driver on Windows.

USB 3 port gives this:

Handshake failed (USB-HID Gaming Keyboard) Exception occured. System.IO.IOException: I/O output report failed.
at HidSharp.Platform.SysHidStream.CommonWrite (System.Byte[] buffer, System.Int32 offset, System.Int32 count, System.Collections.Generic.Queue`1[T] queue, System.Boolean feature, System.Int32 maxOutputReportLength) [0x00096] in :0
at HidSharp.Platform.Linux.LinuxHidStream.Write (System.Byte[] buffer, System.Int32 offset, System.Int32 count) [0x00016] in :0
at HidSharp.HidStream.Write (System.Byte[] buffer) [0x00011] in :0
at (wrapper remoting-invoke-with-check) HidSharp.HidStream.Write(byte[])
at GK6X.KeyboardDeviceManager.WriteSimplePacket (HidSharp.HidStream stream, System.UInt16 opcode) [0x00036] in <81a99fc7af6f43389e4f3ca1f344f6d0>:0
at GK6X.KeyboardDeviceManager.Handshake (HidSharp.HidStream stream) [0x0008e] in <81a99fc7af6f43389e4f3ca1f344f6d0>:0

While USB 2 port just gives this:

Handshake failed (USB-HID Gaming Keyboard) Couldn't find data for keyboard
Keyboard handshake failed

@Ovsyanka
Copy link

Ovsyanka commented Feb 10, 2022

I got the similar error on arch linux:

Expand
Handshake failed (USB-HID Gaming Keyboard) Exception occured. System.TimeoutException: The operation has timed out.
at HidSharp.Platform.SysHidStream.CommonRead (System.Byte[] buffer, System.Int32 offset, System.Int32 count, System.Collections.Generic.Queue`1[T] queue) [0x0008d] in <c054361863a44e168db2058f0e09fb11>:0 
at HidSharp.Platform.Linux.LinuxHidStream.Read (System.Byte[] buffer, System.Int32 offset, System.Int32 count) [0x00000] in <c054361863a44e168db2058f0e09fb11>:0 
at HidSharp.HidStream.Read (System.Byte[] buffer) [0x00011] in <c054361863a44e168db2058f0e09fb11>:0 
at (wrapper remoting-invoke-with-check) HidSharp.HidStream.Read(byte[])
at GK6X.KeyboardDeviceManager.WriteSimplePacket (HidSharp.HidStream stream, System.UInt16 opcode) [0x00046] in <81a99fc7af6f43389e4f3ca1f344f6d0>:0 
at GK6X.KeyboardDeviceManager.Handshake (HidSharp.HidStream stream) [0x00002] in <81a99fc7af6f43389e4f3ca1f344f6d0>:0 
Keyboard handshake failed

Surprisingly enough reconnecting cable to the same port did solve the problem for me this time:

Connected to device 'SK61 RGB' model:655491117 fw:v1.20

I believe the reason could be faulty cable, so I would suggest you to test your keyboard with a different cable(s) just in case. It could be not related to the ports themself, just the movements of the cable.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants