paroj / xpad

Linux Kernel Driver for the Xbox/ Xbox 360/ Xbox One Controllers
820 stars 181 forks source link

XBox one Bluetooth Controller #53

Closed DigitalKrony closed 2 years ago

DigitalKrony commented 7 years ago

This is a question more than an issue,

Is there any information on pairing and connecting the new XBox One Wireless controller released with the S?

While using bluetoothctl

cgutman commented 7 years ago

@radical-equanimity Actually, that's exactly what you can use for games that don't support this gamepad. Xboxdrv provides an "Xbox 360 wired gamepad" emulation mode where it creates a fake controller that forwards input events from your real gamepad.

Steam can also help here, since it can feed games with SDL mappings for gamepads that the game itself didn't support when it was built via the SDL_GAMECONTROLLERCONFIG environment variable (which you can do by hand with other games too). You can try mapping the gamepad in Steam and seeing whether that fixes your Steam games.

lowlyocean commented 7 years ago

Had difficulty mapping bluetooth mode in Steam to match USB mode. I ordered a Steam Link since it's only $15 now on sale. On the Steamlink, bluetooth mode works as I want it to (as if via USB). I'm able to SSH in to the Steam Link and this is the output of dmesg when I connect my controller:

[ 70.841252] input: Xbox Wireless Controller as /devices/virtual/bluetooth/hci0/hci0:1/input3 [ 70.853519] microsoft 0005:045E:02FD.000B: input,hidraw8: BLUETOOTH HID v9.03 Gamepad [Xbox Wireless Controller] on e0:31:9e:46:bb:90

I don't think the hci0 bit appears when connecting controller via Bluetooth on my Ubuntu machine, and dug further to find this on the Steam Link filesystem, residing in the file /etc/udev/rules.d/97-bluetooth-hid2hci.rules :

# Variety of Dell Bluetooth devices # # it looks like a bit of an odd rule, because it is matching # on a mouse device that is self powered, but that is where # a HID report needs to be sent to switch modes. # # Known supported devices: # 413c:8154 # 413c:8158 # 413c:8162 ACTION=="add", ENV{ID_VENDOR}=="413c", ENV{ID_CLASS}=="mouse", ATTRS{bmAttributes}=="e0", KERNEL=="mouse*", RUN+="/usr/sbin/hid2hci --method dell -v $env{ID_VENDOR} -p $env{ID_MODEL} --mode hci"

# Logitech devices ACTION=="add", ENV{ID_VENDOR}=="046d", ENV{ID_MODEL}=="c703" RUN+="/usr/sbin/hid2hci --method logitech -v $env{ID_VENDOR} -p $env{ID_MODEL} --mode hci" ACTION=="add", ENV{ID_VENDOR}=="046d", ENV{ID_MODEL}=="c704" RUN+="/usr/sbin/hid2hci --method logitech -v $env{ID_VENDOR} -p $env{ID_MODEL} --mode hci" ACTION=="add", ENV{ID_VENDOR}=="046d", ENV{ID_MODEL}=="c705" RUN+="/usr/sbin/hid2hci --method logitech -v $env{ID_VENDOR} -p $env{ID_MODEL} --mode hci" ACTION=="add", ENV{ID_VENDOR}=="046d", ENV{ID_MODEL}=="c70a" RUN+="/usr/sbin/hid2hci --method logitech -v $env{ID_VENDOR} -p $env{ID_MODEL} --mode hci" ACTION=="add", ENV{ID_VENDOR}=="046d", ENV{ID_MODEL}=="c70b" RUN+="/usr/sbin/hid2hci --method logitech -v $env{ID_VENDOR} -p $env{ID_MODEL} --mode hci" ACTION=="add", ENV{ID_VENDOR}=="046d", ENV{ID_MODEL}=="c70c" RUN+="/usr/sbin/hid2hci --method logitech -v $env{ID_VENDOR} -p $env{ID_MODEL} --mode hci" ACTION=="add", ENV{ID_VENDOR}=="046d", ENV{ID_MODEL}=="c70e" RUN+="/usr/sbin/hid2hci --method logitech -v $env{ID_VENDOR} -p $env{ID_MODEL} --mode hci" ACTION=="add", ENV{ID_VENDOR}=="046d", ENV{ID_MODEL}=="c713" RUN+="/usr/sbin/hid2hci --method logitech -v $env{ID_VENDOR} -p $env{ID_MODEL} --mode hci" ACTION=="add", ENV{ID_VENDOR}=="046d", ENV{ID_MODEL}=="c714" RUN+="/usr/sbin/hid2hci --method logitech -v $env{ID_VENDOR} -p $env{ID_MODEL} --mode hci" ACTION=="add", ENV{ID_VENDOR}=="046d", ENV{ID_MODEL}=="c71b" RUN+="/usr/sbin/hid2hci --method logitech -v $env{ID_VENDOR} -p $env{ID_MODEL} --mode hci" ACTION=="add", ENV{ID_VENDOR}=="046d", ENV{ID_MODEL}=="c71c" RUN+="/usr/sbin/hid2hci --method logitech -v $env{ID_VENDOR} -p $env{ID_MODEL} --mode hci"

# CSR devices (in HID mode) ACTION=="add", ENV{ID_VENDOR}=="0a12", ENV{ID_MODEL}=="1000" RUN+="/usr/sbin/hid2hci --method csr -v $env{ID_VENDOR} -p $env{ID_MODEL} --mode hci" ACTION=="add", ENV{ID_VENDOR}=="0458", ENV{ID_MODEL}=="1000" RUN+="/usr/sbin/hid2hci --method csr -v $env{ID_VENDOR} -p $env{ID_MODEL} --mode hci" ACTION=="add", ENV{ID_VENDOR}=="05ac", ENV{ID_MODEL}=="1000" RUN+="/usr/sbin/hid2hci --method csr -v $env{ID_VENDOR} -p $env{ID_MODEL} --mode hci"

# CSR devices (in HCI mode) #ACTION=="add", ENV{ID_VENDOR}=="0a12", ENV{ID_MODEL}=="0001" RUN+="/usr/sbin/hid2hci --method csr -v $env{ID_VENDOR} -p $env{ID_MODEL} --mode hid" #ACTION=="add", ENV{ID_VENDOR}=="0458", ENV{ID_MODEL}=="003f" RUN+="/usr/sbin/hid2hci --method csr -v $env{ID_VENDOR} -p $env{ID_MODEL} --mode hid" #ACTION=="add", ENV{ID_VENDOR}=="05ac", ENV{ID_MODEL}=="8203" RUN+="/usr/sbin/hid2hci --method csr -v $env{ID_VENDOR} -p $env{ID_MODEL} --mode hid" #ACTION=="add", ENV{ID_VENDOR}=="05ac", ENV{ID_MODEL}=="8204" RUN+="/usr/sbin/hid2hci --method csr -v $env{ID_VENDOR} -p $env{ID_MODEL} --mode hid" #ACTION=="add", ENV{ID_VENDOR}=="05ac", ENV{ID_MODEL}=="8207" RUN+="/usr/sbin/hid2hci --method csr -v $env{ID_VENDOR} -p $env{ID_MODEL} --mode hid"

Does anybody know more about what's going on here? What is hid2hci doing when I connect the controller that makes it work as I'd like it to without any need to configure anything manually?

raincode00 commented 7 years ago

I think I have found a working solution to get my Xbox One S Controller working properly with Bluetooth with the latest firmware in Ubuntu 16.04 with the hwe kernel 4.10 installed.

I think I have a basic grasp of what is going on and what is wrong through my fixes are mashup of various kernel patches and work-arounds due to my lack of knowledge in the linux kernel. So far I can tell this that this has nothing to do with the xpad driver and the work-arounds are done with HID and bluetooth drivers patches in the Linux kernel.

So far here is a recollection of issues I have run into and each solution/workaround.

Controller does not pair properly or randomly disconnects.

Left analog stick moves the mouse.

Controller is detected as a generic HID device.

Incorrect button mapping and Back and Home buttons don't work.

I noticed a few other strange quirks in the key mappings though they don't seem to hamper usage of the controller in games.

The controller reports Simulation HIDs for the L and R triggers. It reports Brake HID (0x000200c5) and Gas HID (0x000200c4), while at the same time it uses the standard L Trigger (Z Axis) HID (0x00010032) to represent the Right Analog X Axis. and the standard R Trigger (RZ Axis) HID (0x00010035) to represent the Right Analog Y Axis.

I can't imagine the horrors of game developers when seeing this axis mapping mixup. I think Steam has already implemented work-arounds for these since if I try and change the mappings, it makes Steam confused, but other tools like jstest-gtk seem to be no longer confused.

Anyways, I have a gist here of all the driver patches I applied, including ones from Valve and my own here: https://gist.github.com/jahrain/2006b6cd3d5bbf9d39fd45f20abbe9c9

Edit: I've been keeping a more up-to-date patch in my own fork of the Ubuntu Xenial hwe kernel here: https://github.com/jahrain/ubuntu-xenial

Unshackle8078 commented 7 years ago

I think this actually used to just work in ~16.04 but having same issue in 17.04. Tried disable_ertm with no success. Somehow 4 instances of an xbox controller device were created and were breaking controller support for Steam games in general.

rootyElf commented 6 years ago

I’d just like to share my observations.

I also had this issue with messed up button mapping. The back key was not registered as gamepad button but rather as back key like you would have on a mouse. So for example it causes the web browser to go one page back. The Home button is not recognized either. It still seems to work though → when I press the home button in steam it opens Big Picture Mode. I don’t know if it’s a bug or intended.

On my computer I have both Arch Linux and Windows 10 installed. I used this method to dual pair the XBox One Pad with both OSes: https://askubuntu.com/a/741821 What I found out is that the button mapping is different depending on which OS the controller was paired with last.

When I pair the controller with Linux I get the following button layout: A -> B0 B -> B1 X -> B3 Y -> B4 LB -> B6 RB -> B7 START -> B11 L3 -> B13 R3 -> B14

LS -> A0 & A1 RS -> A2 & A3 RT -> A4 LT -> A5 DPAD -> A6 & A7

that’s probably the result most of you get. Now, when I pair the controller with Windows 10 and then copy the link key over to Linux I get a different button layout (in Linux)

A -> B0 B -> B1 X -> B2 Y -> B3 LB -> B4 RB -> B5 BACK -> B6 START -> B7 L3 -> B8 R3 -> B9

LS -> A0 & A1 RS -> A2 & A3 RT -> A4 LT -> A5 DPAD -> A6 & A7

There’s also button 10 – 14 which don’t seem to do anything. This should mostly be the same as the on in Windows and it also looks a bit more sane (imho – except for button 10 - 14). The thing with the home button is still the same but on Windows it’s also not shown as button and as I said – it somehow still works at least for steam.

So the button issue might depend on the state the controller is in (so if it either had normal pairing or special Windows 10 pairing) rather than on how the computer handles the device. Maybe it is the pairing process which needs some tweaking.

I don't know if this was addressed before. If not maybe someone might try to confirm/reproduce this.

Btw. If you do the reverse thing (pair the controller on Linux and then use it on Windows) you get quite a funny result. I don’t know how to explain it, but it’s definitely not working properly.

raincode00 commented 6 years ago

The controller seems to have some internal state that switches to a special "Android Controller Mode" when paired with Linux, and switches back to normal "Xbox One S Controller" mode when paired with Windows.

In the "Android Controller Mode", the back button gets mapped to the "back keyboard button" and the xbox button gets mapped to the "home keyboard button". These keys are used to navigate the "home" and "back" Android UI function.

kakra commented 6 years ago

I now managed to pair the controller via bluetooth by applying and crafting my own kernel patch collected from different sources (SteamOS kernel and @jahrain patch). The select and home buttons now correctly report as button events in jstest, additionally to sending a key XF86_Back und XF86_Home in xev. I think that's fine so far.

But still, in Steam games the select button does not work, it is simply ignored. Any ideas?

EDIT It seems that only some games still do not recognize the select button while others do.

atar-axis commented 6 years ago

take a look at https://github.com/atar-axis/xpadneo, which supports

I am also working on a correct mapping for all models and firmware versions. I would appreciate any support (especially on the mapping and integration into other distributions).

kakra commented 6 years ago

If it helps, I can send my jscal config files with which I was able to correctly map all buttons in native Linux games.

PS: I simply paste it here, saves one round of ping-pong:

NAME="Xbox Wireless Controller"
VENDOR="0a12"
PRODUCT="0001"
jscal -u 8,0,1,2,5,9,10,16,17,15,304,305,307,308,310,311,314,315,316,317,318,306,309,312,313
jscal -s 8,1,255,28672,36862,21844,21844,1,255,28672,36862,21844,21844,1,255,28672,36862,21844,21844,1,255,28672,36862,21844,21844,1,3,448,574,1394469,1394469,1,3,448,574,1394469,1394469,1,0,0,0,536870912,536870912,1,0,0,0,536870912,536870912
wingedonezero commented 6 years ago

@atar-axis Does it do rumble correctly yet? And by that i mean ive had drivers for some controllers that only do max rumble and not the varied rumble were all used to. And does it work on steam on linux? Also you mentioned correct mappings does that mean like the xbox 360 controller does currently button wise so its compatible with everything?

atar-axis commented 6 years ago

@wingedonezero It is capable of rumbling in any strength - yes, for sure!

We've never tested it on steam - would appreciate if you do :). I've developed the driver to telecontrol a RC-car for a student project, we tested the driver on jstest, evtest, sdl-jstest, fftest and so on - therefore it should work on every game...

By 'correct mapping' I mean: Every single button should work as expected - I mapped every button "by hand" to it's event - but there is a known bug, I already know exactly how to fix it - I am just missing some information - the bug haven't occured since months so i can't reproduce it at the moment.

wingedonezero commented 6 years ago

@atar-axis Sounds good ill test it for a few days and report anything weird on your git. This is a big step forward if all works. Hopefully more people get to testing and bug reporting so we can get this pushed in to the kernel. I see so many reports on the web of people upset about this issue and the rumble.

You would think microsoft would do a firmware update to make it so linux isnt reported as a android device. Seeing as how you can now run linux stuff in windows. But it may also be harder for them to do than that since android runs the linux kernel.

Itd be nice if someone came up with custom firmware that removed the android mode that we can flash then life would be easier. But i havent seen anyone even mention that route. Id think thats be the easier route i see so many custom firmware for various things people have edited.

lowlyocean commented 6 years ago

Nice work @atar-axis ! I agree with @wingedonezero that this should be moved upstream sooner than later. Seems the first step is for @atar-axis to fork this repo, make his changes, and issue a pull request to have @paroj review & merge into xpad.

Also- I'm not sure I agree about firmware being the easier route. If it's done in driver then it can easily be distributed via distro's package manager. Usually not the same with firmware

kakra commented 6 years ago

The xpadneo driver now works fine in Steam with one caveat: Steam applies a wrong SDL mapping to games which needs to be manually fixed in config.vdf. After doing this, the controller works fine in all games, not just some, as long as you use the xpadneo driver.

The fix in config.vdf is replacing the mapping with a standard Xbox 360 mapping.

atar-axis commented 6 years ago

@radical-equanimity There are no "changes I made" - it is a completely new driver. I don't think that it is a good idea to put everything into the old non-HID driver.

@kakra Just to keep this discussion up-to-date: the SDL mapping problem is solved too (I don't remember the name of the guy who had the idea for the solution... who was it... ah, yes - you!) ;D

lowlyocean commented 6 years ago

@atar-axis Is it called xpadneo because intention is to deprecate xpad? (i.e., include and extend functionality). Does it only support this Xbox One S controller?

atar-axis commented 6 years ago

not really, it's intention is to support the newer (neo) devices - everything from One S upwards...

the new protocol does not fit into the old driver very well, but lets dicuss that somewhere else :)

ipkpjersi commented 5 years ago

Hi guys,

I guess this is a known issue? Does anyone have any updated advice for getting the Xbox One Bluetooth Controller to properly work on Ubuntu 16.04 (I'm on kernel 4.15.0-38-generic x86_64)? Does anyone know if it works properly on Ubuntu 18.04 or is it literally a problem that is inherent with Linux? I'd love to get this problem solved, my 360 controller works fine of course. Honestly, I might even be willing to pay a bit of money to someone who can fix this problem if it helps out because this is something I definitely want to see working on Ubuntu 16.04, it's literally the only thing I can think of that doesn't work...

I'm new to Bluetooth and I just ordered some Bluetooth headphones, hopefully it is plug-n-play and Bluetooth isn't just inherently broken on Linux...

Thanks guys.

lowlyocean commented 5 years ago

Xpad is used for xinput devices. The XBox One S gamepad isn't an XInput device when it's used in Bluetooth mode. In bluetooth mode, the xpad driver isn't even aware of it. Instead, the Bluetooth HID drivers on the system perform the mapping. Those drivers don't reflect Microsoft's button mapping properly, which is what causes the confusing behavior

Edit: see https://github.com/paroj/xpad/issues/53#issuecomment-328280325 above, particularly the sections Controller is detected as a generic HID device and Incorrect button mapping and Back and Home buttons don't work

ipkpjersi commented 5 years ago

Thanks for explaining the issue, and so quickly too. I'm glad it's a common issue and it's not just me, I guess that means it's more likely for this to be fixed. Has anyone found a solution?

lowlyocean commented 5 years ago

Looks like you may need to apply these patches to the kernel source code and then rebuild a custom kernel with the patches. And here's a guide for building kernel from source code

kakra commented 5 years ago

@ipkpjersi You could try the xpadneo driver from @atar-axis, it works great here: https://github.com/atar-axis/xpadneo

Here's my kernel patch to build it right into the kernel: https://github.com/kakra/linux/commits/rebase-4.18/xpadneo

ipkpjersi commented 5 years ago

Thanks for all the information. Hmm... I'm guessing there's probably a zero percent chance I will ever see this in Ubuntu 16.04 standard kernels, or is it still possible?

Does this work in Ubuntu 18.04?

lowlyocean commented 5 years ago

One of these gentlemen might be able to set up an automated daily build recipe on launchpad mirroring the git repos for their custom kernels, and then you'd be able to get the latest build by just adding their PPA to your sources. Something similar to this.

As for official, official? Not likely... if you don't see these kernel patches packaged in Ubuntu Bionic then they probably won't be backported to Xenial-backports

kakra commented 5 years ago

@lowlyocean @ipkpjersi I think @atar-axis added DKMS support to his project, including instructions how to use it. I'm using Gentoo which builds from source anyway, so no need for DKMS. But since Ubuntu is Debian-based, it should work.

lowlyocean commented 5 years ago

nice! with DKMS support I think following instructions here will be the way to go. I assume there's no need to blacklist any kernel modules that could conflict with this

kakra commented 5 years ago

@lowlyocean I think with the kernel patch you mentioned the gamepad would generally work but support no rumble. At least back when I started working on it, this was the case with that patch.

ipkpjersi commented 5 years ago

@kakra Oh, I had no idea there was a solution (xpadneo) that works so well. Now I'm glad I asked here, now other people who find this issue can see that there's a solution to it!

With DKMS, does that mean it will survive kernel upgrades? That means I shouldn't need to keep re-patching it, I just install it once with the install.sh script and then it's done?

@lowlyocean Wait, do you mean Ubuntu 18.04 does not have this controller supported officially currently? Will it ever be supported officially? Would that xpadneo work on Ubuntu 18.04 as well?

I guess overall what I'm asking is, are there any "downsides" or known limitations to xpadneo or is it perfectly stable and works without any issues?

Thanks for all the quick responses guys, I really appreciate it!

lowlyocean commented 5 years ago

With DKMS, does that mean it will survive kernel upgrades? That means I shouldn't need to keep re-patching it, I just install it once with the install.sh script and then it's done?

Yes, that's the idea @lowlyocean Wait, do you mean Ubuntu 18.04 does not have this controller supported officially currently? Will it ever be supported officially? Would that xpadneo work on Ubuntu 18.04 as well?

AFAIK, Ubuntu 18.04 does not have this controller officially supported. I don't know if it will be supported. I suspect that xpadneo would work fine on Ubuntu 18.04 especially since it's a kernel module not a userspace driver I guess overall what I'm asking is, are there any "downsides" or known limitations to xpadneo or is it perfectly stable and works without any issues?

No idea- TBH I haven't used xpadneo myself but it appears to work as expected with Bluetooth (maybe not USB)

kakra commented 5 years ago

@ipkpjersi I'm using xpadneo here successfully since many months, in native Linux games, in Steam with SteamPlay/Proton, and in Wine. That driver also has some sophisticated workarounds for the various "button-mapping fixes" that have gone into various layers of software (i.e., some versions of SDL have fixes, Steam has fixes, Wine games would map correctly sometimes, sometimes not, depending on which game controller API is used, if two layers apply fixes everything becomes messed up even more). This is all fixed by faking the version/serial identifier of the HID interface. There's some details on this in the docs of xpadneo. It took quite a while for @atar-axis and me to find a proper fix for this. But I'm not sure if this fix is enabled by default but I guess so.

Not sure how DKMS works internally but I think it's designed to rebuild modules upon kernel updates.

@lowlyocean xpadneo is designed to work with a bluetooth dongle. The one provided with the gamepad is actually not bluetooth but wifi-direct. It would enable using the audio jack of the gamepad. So that's the only feature not supported by xpadneo. Apparently, there's no kernel driver for that wifi-direct dongle yet. I think @atar-axis put some research into it already but I don't know about the progress.

kakra commented 5 years ago

@ipkpjersi BTW: You may need to upgrade the firmware version of the controller first using a Windows machine... The different firmware versions mess around with the button mappings. The latest firmware seems to have stabilized wrt the mappings.

lowlyocean commented 5 years ago

I've never heard of the wifi-direct dongle- the controller has bluetooth built-in. I wouldn't spend much energy if I were @atar-axis on getting the dongle to work just for audio purposes. A case of diminishing returns, I think. Spoofing the version/serial identifier is a clever solution to avoiding bespoke workarounds

ipkpjersi commented 5 years ago

I actually have an Xbox One X so I used that to update the firmware of my controller, I tried out this DKMS xpadneo project and wow it works really well, and of course my 360 controller still works too. You guys are awesome, thanks for all the help!

kakra commented 5 years ago

@ipkpjersi BTW xpadneo also supports the rumble motors in the triggers which even Windows doesn't support (it's an exclusive XBox feature). Tho, I've not seen a game that could support this yet. But this is also likely a problem with properly exposing the rumble API (it should work with games that use directional rumble). If you find a game that supports this, I'd be happy to test and improve the code.

ipkpjersi commented 5 years ago

I can't say I know any games that do support this. Is it possible to turn the rumble off? I find I don't like rumble most of the time. Is there any way to turn it off globally, or is it something that'd have to be done on a per-game basis only?

kakra commented 5 years ago

I prefer rumble as a haptic feedback in many games (like in Tomb Raider when you're nearby some hidden treasure). So, I never felt the urge to disable it globally. Maybe ask in the xpadneo issues or look at the configuration sections in the docs. The module may have a parameter to turn rumble off globally. Tho, most games should have an option for this. And Steam may have an option, too, if you turn on Steam controller configuration support for the gamepad.

chivigoku commented 5 years ago

Hi folks,

I`ve tried many times xpadneo driver and it works properly in Debian and Raspbian. However, this driver doesn´t work (at least, I couldn´t) in OSMC.

As far as I could investigate about it, it´s because in OSMC they don't recommend install DKMS and even installing it, you got errors when installing headers (in this case rbp2 headers).

I´m working disabling ertm on my OS but as you guys mentioned above, home and select buttons are not working at all.

Have you guys made work Xbox One S controller on OSMC via bluetooth properly?

lowlyocean commented 5 years ago

I switched back to Raspbian because OSMC wasn't much more than Raspbian with pre-installed Kodi media center and auto-boot to Kodi. OSMC guys also made some radical deviations from Raspbian that kept causing me issues

atar-axis commented 5 years ago

feel free to open a new issue at xpadneo @chivigoku, I will then give it a try to come up with a solution.

amueller commented 5 years ago

Unfortunately the echo 1 > /sys/module/bluetooth/parameters/disable_ertm and variants of that didn't work for me for connecting. It still keeps disconnecting, using Ubuntu 18.04 with Xbox wireless controller and firmware 3.1.1221.0 (which it claims is the newest)

atar-axis commented 5 years ago

@amueller give xpadneo a try ;)

amueller commented 5 years ago

@atar-axis sweet, worked out of the box! a ppa for ubuntu would be nice ;)

atar-axis commented 5 years ago

@amueller Feel free to open a new issue - or even better: a pull request ;)

paroj commented 2 years ago

meanwhile no additional hacks are needed to get the BT controllers working