bluez icon indicating copy to clipboard operation
bluez copied to clipboard

Connect problems with Gamepads (Authentication Failed)

Open DrKlipper opened this issue 2 years ago • 20 comments

Hi ! I use a Raspberry Pi Zero 2 which has embedded BT. I want to connect a little gamepad: This one : https://www.amazon.de/auvisio-Gamepad-Bluetooth-Mini-Akku-Game-Controller-Fernbedienung-black/dp/B0179P8WMG

It´s working in Windows like a charm and I know it worked ~2 years ago as I bought it.

But when I try it now it drives me crazy :-) This is my workflow:

  • sudo bluetoothctl
  • scan on
  • turn on the gamepad
  • wait to get the new device message in bluetoothctl
  • pair the ID
  • trust the ID (but this doesn´t really change anything at all)
  • connect the ID

The result is this:

Agent registered
[bluetooth]# scan on
hci0 type 7 discovering on
Discovery started
[CHG] Controller B8:27:EB:39:52:35 Discovering: yes
[NEW] Device 2C:90:1F:28:8D:3C 2C-90-1F-28-8D-3C
[NEW] Device 4F:56:CA:87:45:04 4F-56-CA-87-45-04
[bluetooth]# devices
Device 17:05:16:03:35:E1 MOCUTE-032S_A03-35E1
Device 08:A9:5A:91:95:B2 Sony PLAYSTATION(R)3 Controller
Device 2C:90:1F:28:8D:3C 2C-90-1F-28-8D-3C
Device 4F:56:CA:87:45:04 4F-56-CA-87-45-04
[NEW] Device A8:51:AB:24:B7:F6 A8-51-AB-24-B7-F6
hci0 type 7 discovering off
[bluetooth]# remove 17:05:16:03:35:E1
[DEL] Device 17:05:16:03:35:E1 MOCUTE-032S_A03-35E1
Device has been removed
hci0 type 7 discovering on
[CHG] Device 4F:56:CA:87:45:04 RSSI: 0xffffffab (-85)
hci0 type 7 discovering off
[bluetooth]# pair 17:05:16:03:35:E1
Device 17:05:16:03:35:E1 not available
hci0 type 7 discovering on
[CHG] Device 2C:90:1F:28:8D:3C RSSI: 0xffffffaa (-86)
[CHG] Device A8:51:AB:24:B7:F6 RSSI: 0xffffffa2 (-94)
[NEW] Device 17:05:16:03:35:E1 MOCUTE-032S_A03-35E1
[bluetooth]# pair 17:05:16:03:35:E1
Attempting to pair with 17:05:16:03:35:E1
hci0 device_flags_changed: 17:05:16:03:35:E1 (BR/EDR)
     supp: 0x00000001  curr: 0x00000000
hci0 type 7 discovering off
hci0 17:05:16:03:35:E1 type BR/EDR connected eir_len 27
[CHG] Device 17:05:16:03:35:E1 Connected: yes
hci0 new_link_key 17:05:16:03:35:E1 type 0x04 pin_len 0 store_hint 1
[CHG] Device 17:05:16:03:35:E1 Bonded: yes
hci0 device_flags_changed: 17:05:16:03:35:E1 (BR/EDR)
     supp: 0x00000001  curr: 0x00000001
[CHG] Device 17:05:16:03:35:E1 UUIDs: 00000000-deca-fade-deca-deafdecacaff
[CHG] Device 17:05:16:03:35:E1 UUIDs: 00001101-0000-1000-8000-00805f9b34fb
[CHG] Device 17:05:16:03:35:E1 UUIDs: 00001124-0000-1000-8000-00805f9b34fb
[CHG] Device 17:05:16:03:35:E1 ServicesResolved: yes
[CHG] Device 17:05:16:03:35:E1 Paired: yes
Pairing successful
[CHG] Device 17:05:16:03:35:E1 WakeAllowed: yes
hci0 17:05:16:03:35:E1 type BR/EDR disconnected with reason 2
[CHG] Device 17:05:16:03:35:E1 ServicesResolved: no
[CHG] Device 17:05:16:03:35:E1 Connected: no
hci0 type 7 discovering on
[CHG] Device A8:51:AB:24:B7:F6 RSSI: 0xffffffab (-85)
[CHG] Device 2C:90:1F:28:8D:3C RSSI: 0xffffffa1 (-95)
[bluetooth]# connect 17:05:16:03:35:E1
Attempting to connect to 17:05:16:03:35:E1
hci0 17:05:16:03:35:E1 type BR/EDR connected eir_len 27
[CHG] Device 17:05:16:03:35:E1 Connected: yes
hci0 17:05:16:03:35:E1 auth failed with status 0x05 (Authentication Failed)
Failed to connect: org.bluez.Error.Failed br-connection-create-socket
hci0 17:05:16:03:35:E1 type BR/EDR disconnected with reason 4
[CHG] Device 17:05:16:03:35:E1 Connected: no
[bluetooth]#
hci0 type 7 discovering off
[bluetooth]# exit

As you can see it is connected, then gets disconnected and then it tells me the Authentication failed. I used the git commit 670f0d0f6 to test this. There was an issue with some other gamepads and my hope was this could fix something. Anyway .. I also used the latest 5.69 tar.gz file from kernel.org. This is even worse. That version asks for a key. But this damn little gamepad hasn´t even one. Even updating the Raspberry Pi kernel to the latest possible 6.1.53-v7+ didn´t help at all.

I ran btmon, too. This is the output from the above connection try:

        Status: Success (0x00)
        Address: 17:05:16:03:35:E1 (OUI 17-05-16)
        Name: MOCUTE-032S_A03-35E1
@ MGMT Event: Device Connected (0x000b) plen 40                                                                                                                 {0x0002} [hci0] 68.718229
        BR/EDR Address: 17:05:16:03:35:E1 (OUI 17-05-16)
        Flags: 0x00000008
          Connection Locally Initiated
        Data length: 27
        Name (complete): MOCUTE-032S_A03-35E1
        Class: 0x000540
          Major class: Peripheral (mouse, joystick, keyboards)
          Minor class: 0x10
@ MGMT Event: Device Connected (0x000b) plen 40                                                                                                                 {0x0001} [hci0] 68.718229
        BR/EDR Address: 17:05:16:03:35:E1 (OUI 17-05-16)
        Flags: 0x00000008
          Connection Locally Initiated
        Data length: 27
        Name (complete): MOCUTE-032S_A03-35E1
        Class: 0x000540
          Major class: Peripheral (mouse, joystick, keyboards)
          Minor class: 0x10
< HCI Command: Authentication Requested (0x01|0x0011) plen 2                                                                                                        #150 [hci0] 68.718263
        Handle: 12 Address: 17:05:16:03:35:E1 (OUI 17-05-16)
> HCI Event: Command Status (0x0f) plen 4                                                                                                                           #151 [hci0] 68.718765
      Authentication Requested (0x01|0x0011) ncmd 1
        Status: Success (0x00)
> HCI Event: Link Key Request (0x17) plen 6                                                                                                                         #152 [hci0] 68.718772
        Address: 17:05:16:03:35:E1 (OUI 17-05-16)
< HCI Command: Link Key Request Reply (0x01|0x000b) plen 22                                                                                                         #153 [hci0] 68.718835
        Address: 17:05:16:03:35:E1 (OUI 17-05-16)
        Link key: c0f7bb2acb8207c15f25707656e8b345
> HCI Event: Command Complete (0x0e) plen 10                                                                                                                        #154 [hci0] 68.720694
      Link Key Request Reply (0x01|0x000b) ncmd 1
        Status: Success (0x00)
        Address: 17:05:16:03:35:E1 (OUI 17-05-16)
> HCI Event: Auth Complete (0x06) plen 3                                                                                                                            #155 [hci0] 68.766099
        Status: PIN or Key Missing (0x06)
        Handle: 12 Address: 17:05:16:03:35:E1 (OUI 17-05-16)
@ MGMT Event: Authentication Failed (0x0011) plen 8                                                                                                             {0x0002} [hci0] 68.766139
        BR/EDR Address: 17:05:16:03:35:E1 (OUI 17-05-16)
        Status: Authentication Failed (0x05)
@ MGMT Event: Authentication Failed (0x0011) plen 8                                                                                                             {0x0001} [hci0] 68.766139
        BR/EDR Address: 17:05:16:03:35:E1 (OUI 17-05-16)
        Status: Authentication Failed (0x05)
= bluetoothd: profiles/input/device.c:control_connect_cb() connect to 17:05:16:03:35:E1: Invalid exchange (52)                                                                  68.768268
< HCI Command: Disconnect (0x01|0x0006) plen 3                                                                                                                      #156 [hci0] 68.815665
        Handle: 12 Address: 17:05:16:03:35:E1 (OUI 17-05-16)
        Reason: Remote User Terminated Connection (0x13)
> HCI Event: Command Status (0x0f) plen 4                                                                                                                           #157 [hci0] 68.816209
      Disconnect (0x01|0x0006) ncmd 1
        Status: Success (0x00)
> HCI Event: Disconnect Complete (0x05) plen 4                                                                                                                      #158 [hci0] 68.915947
        Status: Success (0x00)
        Handle: 12 Address: 17:05:16:03:35:E1 (OUI 17-05-16)
        Reason: Connection Terminated By Local Host (0x16)
@ MGMT Event: Device Disconnected (0x000c) plen 8                                                                                                               {0x0002} [hci0] 68.915982
        BR/EDR Address: 17:05:16:03:35:E1 (OUI 17-05-16)
        Reason: Connection terminated due to authentication failure (0x04)
@ MGMT Event: Device Disconnected (0x000c) plen 8                                                                                                               {0x0001} [hci0] 68.915982
        BR/EDR Address: 17:05:16:03:35:E1 (OUI 17-05-16)
        Reason: Connection terminated due to authentication failure (0x04)
< HCI Command: LE Set Scan Enable (0x08|0x000c) plen 2                                                                                                              #159 [hci0] 70.775679
        Scanning: Disabled (0x00)
        Filter duplicates: Disabled (0x00)

I hope I got all the information pinned down here so that anyone can have a look at it. If there is anything missing please let me know. I would love to get this running again.

Dominik

DrKlipper avatar Sep 18 '23 07:09 DrKlipper

Just a side note ... Installed Retropie on the Zero2w. It uses bluez 5.50 with Kernel 5.10.103-v7+ (Debian Buster). It works without any issues. No key is required at all. So it must be a problem of a newer bluez version or the new version 6 Kernel.

DrKlipper avatar Sep 18 '23 18:09 DrKlipper

I had the same authentication-failed issue with a PS5 DualSense Controller.

Trusting the device doesn't work immediately. However after rebooting my system my controller connected immediately and everything works fine since then.

jdeut avatar Sep 23 '23 10:09 jdeut

Ok I found a strange workaround. But to be honest, I don't know if this is a real workaround or "works as expected".

Anyway ... Here is what I can do:

  • Go to the Retropie repo in the bluetooth folder: https://github.com/RetroPie/RetroPie-Setup/tree/master/scriptmodules/supplementary/bluetooth
  • Download bluez-simple-agent and save it as bluez-simple-agent.py
  • Download bluezutils.py from the same folder
  • put the two files onto your Pi
  • Start sudo bluetoothctl and run scan on
  • Use a second Terminal and start python bluez-simple-agent.py
  • Pair, Trust, Connect the gamepad and you are done

In some way this is how it works in Retropie, too.

There is still the problem that it won´t reconnect after a reboot. But ok I can get around that problem as described here: https://unix.stackexchange.com/questions/334386/how-to-set-up-automatic-connection-of-bluetooth-headset

Can anyone tell me why this solution is working? I´m a little bit confused why the bluez stack can handle a simple gamepad not by it´s own.

DrKlipper avatar Sep 24 '23 12:09 DrKlipper

Yes, it seems to be a problem of newer bluez versions. I did not have this problem in ubuntu 23.04, but I have it in fedora 38 and ubuntu 23.10

CristianArean avatar Oct 17 '23 13:10 CristianArean

Maybe this issue should get a bug tag assigned ?

DrKlipper avatar Oct 18 '23 02:10 DrKlipper

Isn't this a duplicated of #614?

Vudentz avatar Oct 24 '23 23:10 Vudentz

Same issue, Arch Linux. Probably affects more distros that anticipated, will there be a new release soon? @Vudentz

Leopard1907 avatar Nov 13 '23 15:11 Leopard1907

Yeah, it seems that the same bug affects me now. Seems that some regression has hit pairing since the latest 5.70 release.

RodoMa92 avatar Nov 17 '23 14:11 RodoMa92

Perhaps this is due to mgmt submenu registing callbacks and thus interfering with pairing, that was fixed by https://github.com/bluez/bluez/commit/9741e47aebcdcff343dd2ca7dadc3ec41b66744f

Vudentz avatar Nov 17 '23 16:11 Vudentz

Perhaps this is due to mgmt submenu registing callbacks and thus interfering with pairing, that was fixed by https://github.com/bluez/bluez/commit/9741e47aebcdcff343dd2ca7dadc3ec41b66744f

Guess I'll discover in the next release then. Thanks for your time, @Vudentz :)

RodoMa92 avatar Nov 17 '23 16:11 RodoMa92

bluez-git didn't work either. bluetoothctl deletes the device as soon as I try to connect.

[bluetooth]# scan on
Discovery started
[NEW] Device 98:47:44:xx:xx:xx realme Buds Wireless 3
[bluetooth]# pair 98:47:44:xx:xx:xx
Attempting to pair with 98:47:44:xx:xx:xx
Failed to pair: org.bluez.Error.AuthenticationCanceled
[DEL] Device 98:47:44:xx:xx:xx realme Buds Wireless 3
[bluetooth]# connect 98:47:44:xx:xx:xx
Device 98:47:44:xx:xx:xx not available
[NEW] Device 98:47:44:xx:xx:xx realme Buds Wireless 3
[bluetooth]# connect 98:47:44:xx:xx:xx
Attempting to connect to 98:47:44:xx:xx:xx
[DEL] Device 98:47:44:xx:xx:xx realme Buds Wireless 3
[bluetooth]#

Logs:

Nov 22 13:53:27 arch bluetoothd[2615]: Path / reserved for Adv Monitor app :1.112
Nov 22 13:54:15 arch bluetoothd[2615]: Adv Monitor app :1.112 disconnected from D-Bus

foxjaw avatar Nov 22 '23 08:11 foxjaw

Having issues getting the 8BitDo arcade stick connected when in Bluetooth mode. I can pair it using either the GUI or through bluetoothctl but once paired and trusted the connection immediatelly fails, and unlike with the DualSense gamepad rebooting doesn't help. Trying to connect will almost immediatelly throw an error.

[bluetooth]# connect E4:17:D8:xx:xx:xx
Attempting to connect to E4:17:D8:xx:xx:xx
hci0 E4:17:D8:xx:xx:xx type BR/EDR connect failed (status 0x04, Connect Failed)
Failed to connect: org.bluez.Error.Failed br-connection-page-timeout

This is with bluez 5.70 on Arch.

[Update] Downgraded to 5.68 and the arcade stick paired without issue and is able to connect even after upgrading back to 5.70 so there was a huge regression at some point. Alongside the unstable Bluetooth connection when trying to use an Xbox Series S controller.

CosmicHeron avatar Dec 03 '23 18:12 CosmicHeron

Ok an update :-) Tried to compile 5.72 (last commit) and this commit (d994c9d45dad68bc060add77642fdc37834cd7c1). Last one fixed an authentication error / binding error fpr PS4 / PS5 controller.

But getting my little mini gamepad working is still not possible - regardless which version I choose.

Still got this messages after pairing:

[NEW] Device 17:05:16:03:35:E1 MOCUTE-032S_A03-35E1
hci0 type 7 discovering off
[bluetooth]# pair 17:05:16:03:35:E1
Attempting to pair with 17:05:16:03:35:E1
[bluetooth]# hci0 device_flags_changed: 17:05:16:03:35:E1 (BR/EDR)
[bluetooth]#      supp: 0x00000000  curr: 0x00000000
[bluetooth]# hci0 17:05:16:03:35:E1 type BR/EDR connected eir_len 27
[CHG] Device 17:05:16:03:35:E1 Connected: yes
[MOCUTE-032S_A03-35E1]# hci0 new_link_key 17:05:16:03:35:E1 type 0x04 pin_len 0 store_hint 1
[MOCUTE-032S_A03-35E1]# [CHG] Device 17:05:16:03:35:E1 Bonded: yes
[MOCUTE-032S_A03-35E1]# [CHG] Device 17:05:16:03:35:E1 UUIDs: 00000000-deca-fade-deca-deafdecacaff
[MOCUTE-032S_A03-35E1]# [CHG] Device 17:05:16:03:35:E1 UUIDs: 00001101-0000-1000-8000-00805f9b34fb
[MOCUTE-032S_A03-35E1]# [CHG] Device 17:05:16:03:35:E1 UUIDs: 00001124-0000-1000-8000-00805f9b34fb
[MOCUTE-032S_A03-35E1]# [CHG] Device 17:05:16:03:35:E1 ServicesResolved: yes
[MOCUTE-032S_A03-35E1]# [CHG] Device 17:05:16:03:35:E1 Paired: yes
[MOCUTE-032S_A03-35E1]# Pairing successful
[MOCUTE-032S_A03-35E1]# hci0 17:05:16:03:35:E1 type BR/EDR disconnected with reason 2
[MOCUTE-032S_A03-35E1]# [CHG] Device 17:05:16:03:35:E1 ServicesResolved: no
[CHG] Device 17:05:16:03:35:E1 Connected: no

And if I try to connect I got this:

[bluetooth]# connect 17:05:16:03:35:E1
Attempting to connect to 17:05:16:03:35:E1
[bluetooth]# hci0 17:05:16:03:35:E1 type BR/EDR connected eir_len 22
[CHG] Device 17:05:16:03:35:E1 Connected: yes
[MOCUTE-032S_A03-35E1]# hci0 17:05:16:03:35:E1 auth failed with status 0x05 (Authentication Failed)
[MOCUTE-032S_A03-35E1]# Failed to connect: org.bluez.Error.Failed br-connection-create-socket
[MOCUTE-032S_A03-35E1]# hci0 17:05:16:03:35:E1 type BR/EDR disconnected with reason 2
[CHG] Device 17:05:16:03:35:E1 Connected: no

Will there be any fix for this in the next release? Can I send some additional data to help debugging this issue? Would love to see this controller running - and I assume there are a lot of other simple gamepads which have trouble with connecting ...

Just reinstalled Raspberry Pi Bullseye. Which comes with version 5.55. I can pair the gamepad. But reconnect after power cycle did not work. Anyway ... Something must be broken in the new versions

DrKlipper avatar Jan 30 '24 11:01 DrKlipper

I've come across this issue as well, though with an Xbox Wireless Controller with slightly different symptoms.

  • Xbox Wireless Controller
    • Model 1914 (latest version available)
    • Firmware version 5.21.3241.0 (latest)
  • BlueZ 5.66
  • RetroPie 4.8.8 64-bit (commit 03b7224) (built from source on a Raspberry Pi 5; commit date 2024-07-03)
  • Raspberry Pi 5 (brand new, has never been paired with this Xbox controller before)
  • Xbox Controller works fine with several Windows machines (Windows 10 and 11).

Error: AuthenticationCanceled immediately after attempting to pair. Seems to be related to issue #552.

Tried the following as suggested by some, but don't resolve the issue:

  • sudo bash -c 'echo 1 > /sys/module/bluetooth/parameters/disable_ertm'
    • (apparently Xbox controllers have issues with ERTM being enabled)
  • Privacy=device

Symptoms:

  • When attempting to pair directly with bluetoothctl, the following happens:
    • Xbox controller is picked up, though BlueZ rapidly flicks between Connected: yes and Connected: no states every half-second; coincidentally matching the Xbox symbol 'breathing' light pattern on the controller indicating pairing in progress.
    • Attempting to pair with the controller by ID, results in an immediate Failed to pair: org.bluez.Error.AuthenticationCanceled error message.

geofire avatar Jul 05 '24 15:07 geofire

@geofire the ETRM configs are no longer needed with recent kernels. Try installing the xpadneo driver (available under RetroPie's driver packages) and re-pair. Make sure your Xbox controller's firmware is updated (with the Windows update application from the store).

cmitu avatar Jul 05 '24 18:07 cmitu

Just to inform you; it looks like it works on x86 but fails on ARM. If more people see the same, then focus debugging on bluez+ARM compatibility problems. Maybe some bit manipulation differences that lead to problems on ARM!?

anonymouz avatar Sep 11 '24 08:09 anonymouz

Ok my tests where all based on ARM systems (mainly Raspberry Pi). I can do a X86 test and report back.

DrKlipper avatar Sep 11 '24 08:09 DrKlipper