atar-axis / xpadneo

Advanced Linux Driver for Xbox One Wireless Controller (shipped with Xbox One S)
https://atar-axis.github.io/xpadneo/
GNU General Public License v3.0
1.98k stars 112 forks source link

Share button triggers Select events on first connection after boot on Series X controller #340

Closed hadicharara closed 2 years ago

hadicharara commented 2 years ago

Version of xpadneo

Controller Model

Connection mode

Installed Software

Severity / Impact

Describe the Bug

When I connect my Series X controller for the first time after boot, it does weird things:

If I disconnect the controller and connect it again, al these bugs seem to go away.

Steps to Reproduce

Checkout commit 4fd620cd6cb80fb0c1490dc1c864108679d91ab1, compile and install (latest commit as of time of writing). Boot computer, connect Series X controller (without pressing any button), and run evtest.

Expected Behavior

The Select button registers as the select button. The Share button should not show up on evtest.

Screenshots / GIFs / Videos

evtest_first_connect.txt evtest_subsequent_connects.txt

video.mp4

System Information

# uname -a
Linux gaming-pc 5.13.13-051313-generic #202108270918-Ubuntu SMP Fri Aug 27 09:36:58 UTC 2021 x86_64 x86_64 x86_64 GNU/Linux
# xxd -c20 -g1 /sys/module/hid_xpadneo/drivers/hid:xpadneo/0005:045E:*/report_descriptor | tee >(cksum)
00000000: 05 01 09 05 a1 01 85 01 09 01 a1 00 09 30 09 31 15 00 27 ff  .............0.1..'.
00000014: ff 00 00 95 02 75 10 81 02 c0 09 01 a1 00 09 33 09 34 15 00  .....u.........3.4..
00000028: 27 ff ff 00 00 95 02 75 10 81 02 c0 05 01 09 32 15 00 26 ff  '......u.......2..&.
0000003c: 03 95 01 75 0a 81 02 15 00 25 00 75 06 95 01 81 03 05 01 09  ...u.....%.u........
00000050: 35 15 00 26 ff 03 95 01 75 0a 81 02 15 00 25 00 75 06 95 01  5..&....u.....%.u...
00000064: 81 03 05 01 09 39 15 01 25 08 35 00 46 3b 01 66 14 00 75 04  .....9..%.5.F;.f..u.
00000078: 95 01 81 42 75 04 95 01 15 00 25 00 35 00 45 00 65 00 81 03  ...Bu.....%.5.E.e...
0000008c: 05 09 19 01 29 0c 15 00 25 01 75 01 95 0c 81 02 15 00 25 00  ....)...%.u.......%.
000000a0: 75 01 95 04 81 03 05 0c 0a b2 00 15 00 25 01 95 01 75 01 81  u............%...u..
000000b4: 02 15 00 25 00 75 07 95 01 81 03 05 0f 09 21 85 03 a1 02 09  ...%.u........!.....
000000c8: 97 15 00 25 01 75 04 95 01 91 02 15 00 25 00 75 04 95 01 91  ...%.u.......%.u....
000000dc: 03 09 70 15 00 25 64 75 08 95 04 91 02 09 50 66 01 10 55 0e  ..p..%du......Pf..U.
000000f0: 15 00 26 ff 00 75 08 95 01 91 02 09 a7 15 00 26 ff 00 75 08  ..&..u.........&..u.
00000104: 95 01 91 02 65 00 55 00 09 7c 15 00 26 ff 00 75 08 95 01 91  ....e.U..|..&..u....
00000118: 02 c0 c0                                                     ...
2986910699 1363

Controller and Bluetooth Information

xpadneo-btmon.txt xpadneo-dmesg.txt xpadneo-lsusb.txt

Additional Context

kakra commented 2 years ago

The Share button should be part of the secondary device "Consumer Control". Can you evtest that, too?

Also, the latest commit doesn't affect your model. The commit adds support for PID 0x0B20 while yours is 0x0B13.

Did you setup any quirks parameter?

The following lines do not match:

[   35.491846] xpadneo 0005:045E:0B13.0011: controller quirks: 0x00000050
[   36.647742] xpadneo 0005:045E:0B13.0011: controller quirks: 0x00000010
[  621.638738] xpadneo 0005:045E:0B13.0012: controller quirks: 0x00000050

If quirk flag 0x40 is set, XPADNEO_QUIRK_SHARE_BUTTON is applied. But it seems sometimes it isn't. But that is actually part of the code unless you overwrote the quirks parameter via modparams, or you have two instances of the driver installed. According to the log, the driver is loaded only once.

The quirk is needed for firmware versions that place the share button at the select button bitmap position of previous versions. The flags are handled via the model database at https://github.com/atar-axis/xpadneo/blob/4fd620cd6cb80fb0c1490dc1c864108679d91ab1/hid-xpadneo/src/hid-xpadneo.c#L1256 and following lines.

hadicharara commented 2 years ago

I tested the secondary device Consumer Control with evtest. On first connect, no events show up when pressing the share button (probably because it sends SELECT instead). On any subsequent connects, the normal KEY_RECORD event shows up when pressing the share button.

I have not touched the quirks parameter via modparams, and have only installed the driver once. I don't think the quirk isn't being applied all the time, as only the bugs appear only on the first connection of the controller since boot. If I disconnect and connect, it behaves normally. Maybe the quirk is not being applied on the first connection?

kakra commented 2 years ago

It should be because no other ID would match... But I see that hid-generic first claims the device which is different on my system:

[   35.426419] hid-generic 0005:045E:0B13.0011: input,hidraw10: BLUETOOTH HID v5.13 Gamepad [Xbox Wireless Controller] on f8:34:41:65:44:8c

Could you try modprobe hid-xpadneo once after boot before connecting the controller and see if it changes behavior? If it does, we may need to change the rebind rules in udev.

hadicharara commented 2 years ago

I just tried it, and running modprobe hid-xpadneo did indeed prevent the bugs from appearing. Your intuition was correct.

kakra commented 2 years ago

A work-around would be to just load hid-xpadneo as part of the boot process. In systemd systems, you can usually create a file /etc/modules-load.d/xpadneo and insert one module name per line.

hadicharara commented 2 years ago

I already applied it. Since I don't really know how udev rules work, I will remain available to test any potential fix. Thanks for the great driver!

EwokExile commented 2 years ago

modprobe hid-xpadneo

Confirming that this also resolves the issue with the 1708 controller I mentioned here- https://github.com/atar-axis/xpadneo/issues/337#issuecomment-1071946271

kakra commented 2 years ago

Yeah, I've been suspecting we need to change the rebind rules since a few weeks because I stumbled upon some posts that suggest unbind and bind should be issued with a small delay. I'll look into it, it's currently baked into one single rule.

mendhak commented 2 years ago

Can also confirm the workaround, I added to my module list like so:

echo "hid-xpadneo" | sudo tee /etc/modules-load.d/xpadneo.conf

Is there any harm in leaving that workaround in there, it won't affect future updates I hope? (Not really a Linux expert)

Now the ◻◻ two squares view/select button is working. Thanks for your video @hadicharara it was useful to match the problem I was having just today.

kakra commented 2 years ago

Auto-loading the module on boot is a totally valid option, it won't affect future updates.

kakra commented 2 years ago

I can confirm the following new behavior: If you unload hid-xpadneo and reload it, it won't properly apply all fixups, resulting in broken Select button for some models. I'm not sure what the underlying problem is but it also seems to affect our udev rules. It looks like the kernel caches the device with our fixups applied (the SDL fixups), and upon reloading or rebinding the xpadneo driver, the module doesn't properly detect all the fixups and needed quirks. I'm also not sure yet what kernel version introduced this change. One effect from this is that on first load, it would show 0x50 quirk flags, and when reloading the driver, it would show 0x10 quirk flags (and that's actually missing the Select button fix then). Quirk flags can be observed in dmesg.

Using modprobe hid-xpadneo quirks=<CONTROLLERMAC>+0x40 will probably work around it.