Ubuntu – bluetoothd (BlueZ 5) won’t connect with any devices

bluetoothkubuntu

SOLVED.
Edited: see below.

I think I've scoured the internet long enough for this issue. It has been asked many times, but none of the solutions work for me. I upgraded to BlueZ 5 because I want to be able to use its low energy capabilities eventually. Right now, though, I can't get even get my devices paired. I can't use a GUI because this will eventually be for an embedded linux system. Therefore, I think I also can't use bluetoothctl, because it requires an interactive session. (I may be wrong on that.) So I want everything to be either through BASH, C, or python, in that order. Also, because it needs to be automated, the pairing and connection will have to be initiated from the bluetooth device, not from the linux box. Lastly, all devices need to use the a2dp profile.

There seem to be many approaches, but I am not clear on where one ends and the other begins:

APPROACH 1:

a)$ sudo bluetoothd -d -n #runs bluetoothd in verbose mode

b)$ hciconfig hci1 up #turns the device on

$ hciconfig -a #see device properties

    Type: BR/EDR  Bus: USB
    BD Address: 00:02:72:C5:D8:E0  ACL MTU: 1021:8  SCO MTU: 64:1
    UP RUNNING PSCAN ISCAN 
    RX bytes:32875 acl:761 sco:0 events:1037 errors:0
    TX bytes:20178 acl:780 sco:0 commands:329 errors:0
    Features: 0xbf 0xfe 0xcf 0xfe 0xdb 0xff 0x7b 0x87
    Packet type: DM1 DM3 DM5 DH1 DH3 DH5 HV1 HV2 HV3 
    Link policy: RSWITCH SNIFF 
    Link mode: SLAVE ACCEPT 
    Name: 'Adapter-1'
    Class: 0x00010c
    Service Classes: Unspecified
    Device Class: Computer, Laptop
    HCI Version: 4.0 (0x6)  Revision: 0x1000
    LMP Version: 4.0 (0x6)  Subversion: 0x220e
    Manufacturer: Broadcom Corporation (15)

c) try to pair from the device.

Result:
from bluetoothd:

bluetoothd[5359]: src/adapter.c:connected_callback() hci1 device 70:72:3C:62:49:7F connected eir_len 15
bluetoothd[5359]: src/adapter.c:user_confirm_request_callback() hci1 70:72:3C:62:49:7F confirm_hint 1
bluetoothd[5359]: src/device.c:new_auth() Requesting agent authentication for 70:72:3C:62:49:7F
** bluetoothd[5359]: No agent available for request type 2
** bluetoothd[5359]: device_confirm_passkey: Operation not permitted 
bluetoothd[5359]: src/adapter.c:btd_adapter_confirm_reply() hci1 addr 70:72:3C:62:49:7F success 0
bluetoothd[5359]: src/adapter.c:bonding_attempt_complete() hci1 bdaddr 70:72:3C:62:49:7F type 0 status 0x5
bluetoothd[5359]: src/device.c:device_bonding_complete() bonding (nil) status 0x05
bluetoothd[5359]: src/device.c:device_bonding_failed() status 5
bluetoothd[5359]: src/adapter.c:resume_discovery() 
bluetoothd[5359]: src/adapter.c:dev_disconnected() Device 70:72:3C:62:49:7F disconnected, reason 3
bluetoothd[5359]: src/adapter.c:adapter_remove_connection() 
bluetoothd[5359]: src/adapter.c:bonding_attempt_complete() hci1 bdaddr 70:72:3C:62:49:7F type 0 status 0xe
bluetoothd[5359]: src/device.c:device_bonding_complete() bonding (nil) status 0x0e
bluetoothd[5359]: src/device.c:device_bonding_failed() status 14
bluetoothd[5359]: src/adapter.c:resume_discovery()

Device says Couldn't pair with Adapter-1 because of an incorrect PIN or passkey.

Based on the starred responses above, I looked into why there wasn't an agent. What's an agent? Who knows, but I inferred that it was the middleman between my device and the bluetooth daemon.

d) $ ../bluey-5.15/test/simple-agent #I also tried using sudo with these commands

or $ ../bluey-5.15/test/simple-agent hci1

This is a python script that handles incoming pairing requests. If successful, it also tries to 'trust' and 'connect'

output: Agent registered

e) then I try again to pair from the device.

simple-agent output:

RequestConfirmation (/org/bluez/hci1/dev_70_72_3C_62_49_7F, 110643)
Confirm passkey (yes/no): yes 

I hit pair on the BT device and it says paired, but simple-agent hangs. I have used BlueZ 4, and I am pretty sure it's supposed to say something like "New Device XX_XX_XX_XX_XX_XX"

bluetoothd output:

** bluetoothd[5359]: src/agent.c:set_default_agent() Default agent set to :1.126 /test/agent
bluetoothd[5359]: src/adapter.c:connected_callback() hci1 device 70:72:3C:62:49:7F connected eir_len 15
bluetoothd[5359]: src/adapter.c:user_confirm_request_callback() hci1 70:72:3C:62:49:7F confirm_hint 0
bluetoothd[5359]: src/device.c:new_auth() Requesting agent authentication for 70:72:3C:62:49:7F
bluetoothd[5359]: src/agent.c:agent_ref() 0xa59290: ref=2
bluetoothd[5359]: src/agent.c:agent_request_confirmation() Calling Agent.RequestConfirmation: name=:1.126, path=/test/agent, passkey=110643
bluetoothd[5359]: src/agent.c:agent_ref() 0xa59290: ref=3
bluetoothd[5359]: src/adapter.c:btd_adapter_confirm_reply() hci1 addr 70:72:3C:62:49:7F success 1
bluetoothd[5359]: src/agent.c:agent_unref() 0xa59290: ref=2
bluetoothd[5359]: src/agent.c:agent_unref() 0xa59290: ref=1
bluetoothd[5359]: src/adapter.c:new_link_key_callback() hci1 new key for 70:72:3C:62:49:7F type 5 pin_len 0
bluetoothd[5359]: src/device.c:device_set_bonded() 
bluetoothd[5359]: src/device.c:device_bonding_complete() bonding (nil) status 0x00
bluetoothd[5359]: src/adapter.c:resume_discovery() 
bluetoothd[5359]: src/adapter.c:dev_disconnected() Device 70:72:3C:62:49:7F disconnected, reason 3
bluetoothd[5359]: src/adapter.c:adapter_remove_connection() 
bluetoothd[5359]: src/adapter.c:bonding_attempt_complete() hci1 bdaddr 70:72:3C:62:49:7F type 0 status 0xe
bluetoothd[5359]: src/device.c:device_bonding_complete() bonding (nil) status 0x0e
bluetoothd[5359]: src/device.c:device_bonding_failed() status 14
bluetoothd[5359]: src/adapter.c:resume_discovery()

So this does something.

hcidump output:

$ hcidump -i hci1

HCI sniffer - Bluetooth packet analyzer ver 5.15
device: hci1 snap_len: 1500 filter: 0xffffffffffffffff
> HCI Event: Connect Request (0x04) plen 10
    bdaddr 70:72:3C:62:49:7F class 0x5a020c type ACL
> HCI Event: Command Status (0x0f) plen 4
    Accept Connection Request (0x01|0x0009) status 0x00 ncmd 1
> HCI Event: Connect Complete (0x03) plen 11
    status 0x00 handle 11 bdaddr 70:72:3C:62:49:7F type ACL encrypt 0x00
> HCI Event: Command Status (0x0f) plen 4
    Read Remote Supported Features (0x01|0x001b) status 0x00 ncmd 1
> HCI Event: Read Remote Supported Features (0x0b) plen 11
    status 0x00 handle 11
    Features: 0xbf 0xfe 0xcf 0xfe 0xdb 0xff 0x7b 0x87
> HCI Event: Command Status (0x0f) plen 4
    Read Remote Extended Features (0x01|0x001c) status 0x00 ncmd 1
> HCI Event: Command Complete (0x0e) plen 10
    IO Capability Request Reply (0x01|0x002b) ncmd 1
    status 0x00 bdaddr 70:72:3C:62:49:7F
> HCI Event: Read Remote Extended Features (0x23) plen 13
    status 0x00 handle 11 page 1 max 1
    Features: 0x01 0x00 0x00 0x00 0x00 0x00 0x00 0x00
> HCI Event: Command Status (0x0f) plen 4
    Remote Name Request (0x01|0x0019) status 0x00 ncmd 1
> HCI Event: Remote Name Req Complete (0x07) plen 255
    status 0x00 bdaddr 70:72:3C:62:49:7F name 'Prism II'
> HCI Event: Command Complete (0x0e) plen 10
    User Confirmation Request Reply (0x01|0x002c) ncmd 1
    status 0x00 bdaddr 70:72:3C:62:49:7F
> HCI Event: Disconn Complete (0x05) plen 4
    status 0x00 handle 11 reason 0x13
    Reason: Remote User Terminated Connection

I even tried bluetoothctl, but it has the same results. The funny thing is that some scripts from BlueZ (like test-device) can see the BT device for some commands, but not others. For instance, test-device will 'trust' the device, but when I try to 'remove' it, it doesn't exist.

APPROACH 2:

DBUS directly using the dbus-send –system commands. I don't think any of these commands will do me any good until I can pair and connect the device.

APPROACH 3:

I tried all of the suggestions on this post. There is no /etc/bluetooth/hcid.conf in BlueZ 5. Do I need to create one? The rfcomm command will connect, but then disconnect right after.

$ sudo rfcomm connect /dev/rfcomm0 70:72:3C:62:49:7F 1
Connected /dev/rfcomm0 to 70:72:3C:62:49:7F on channel 1
Press CTRL-C for hangup
Disconnected

bluetoothd output:

bluetoothd[5359]: src/adapter.c:connected_callback() hci1 device 70:72:3C:62:49:7F connected eir_len 10
bluetoothd[5359]: src/adapter.c:dev_disconnected() Device 70:72:3C:62:49:7F disconnected, reason 3
bluetoothd[5359]: src/adapter.c:adapter_remove_connection() 
bluetoothd[5359]: src/adapter.c:bonding_attempt_complete() hci1 bdaddr 70:72:3C:62:49:7F type 0 status 0xe
bluetoothd[5359]: src/device.c:device_bonding_complete() bonding (nil) status 0x0e
bluetoothd[5359]: src/device.c:device_bonding_failed() status 14
bluetoothd[5359]: src/adapter.c:resume_discovery()

hcidump output:

$ hcidump -i hci1
HCI sniffer - Bluetooth packet analyzer ver 5.15
device: hci1 snap_len: 1500 filter: 0xffffffffffffffff
> HCI Event: Command Status (0x0f) plen 4
    Create Connection (0x01|0x0005) status 0x00 ncmd 1
> HCI Event: Connect Complete (0x03) plen 11
    status 0x00 handle 11 bdaddr 70:72:3C:62:49:7F type ACL encrypt 0x00
> HCI Event: Command Status (0x0f) plen 4
    Read Remote Supported Features (0x01|0x001b) status 0x00 ncmd 1
> HCI Event: Read Remote Supported Features (0x0b) plen 11
    status 0x00 handle 11
    Features: 0xbf 0xfe 0xcf 0xfe 0xdb 0xff 0x7b 0x87
> HCI Event: Command Status (0x0f) plen 4
    Read Remote Extended Features (0x01|0x001c) status 0x00 ncmd 1
> HCI Event: Read Remote Extended Features (0x23) plen 13
    status 0x00 handle 11 page 1 max 1
    Features: 0x01 0x00 0x00 0x00 0x00 0x00 0x00 0x00
> HCI Event: Command Status (0x0f) plen 4
    Remote Name Request (0x01|0x0019) status 0x00 ncmd 1
> HCI Event: Remote Name Req Complete (0x07) plen 255
    status 0x00 bdaddr 70:72:3C:62:49:7F name 'Prism II'
> HCI Event: Command Status (0x0f) plen 4
    Authentication Requested (0x01|0x0011) status 0x00 ncmd 1
> HCI Event: Command Complete (0x0e) plen 10
    Link Key Request Reply (0x01|0x000b) ncmd 1
    status 0x00 bdaddr 70:72:3C:62:49:7F
> HCI Event: Auth Complete (0x06) plen 3
    status 0x00 handle 11
> HCI Event: Command Status (0x0f) plen 4
    Set Connection Encryption (0x01|0x0013) status 0x00 ncmd 1
> HCI Event: Encrypt Change (0x08) plen 4
    status 0x00 handle 11 encrypt 0x01
> HCI Event: Command Status (0x0f) plen 4
    Exit Sniff Mode (0x02|0x0004) status 0x0c ncmd 1
    Error: Command Disallowed
> HCI Event: Disconn Complete (0x05) plen 4
    status 0x00 handle 11 reason 0x13
    Reason: Remote User Terminated Connection

Any suggestions? Am I:

  • Forgetting something really obvious?

  • Using the tools incorrectly?

  • Forgetting to set a config file?

Edit:

Since the bluez simple-agent wasn't giving me any useful errors, I wrote my own pairing agent. Once I did, I was able to pair but not connect. bluetoothd gave me this new error:

bluetoothd[3078]: profiles/audio/a2dp.c:a2dp_source_connect() path /org/bluez/hci0/dev_70_72_3C_62_49_7F
bluetoothd[3078]: a2dp-source profile connect failed for 70:72:3C:62:49:7F: Protocol not available

This post pointed out that maybe my LOCAL bluetooth adapter wasn't supporting the a2dp profile of my audio source. (Not acting like a sink) Then I saw that the same issue has been experienced by many people upgrading from BlueZ4 to BlueZ5. The issue also was posted on the BlueZ mailing list.

So far, I haven't found a way to add this protocol to my adapter.

Best Answer

Solution:

After finding that the profile (a2dp) wasn't connected and seeing that others had the same problem, I looked into whether this profile was implemented in BlueZ5 yet. I guess I didn't read the porting guide closely enough, because it explains that a2dp was moved out of the BlueZ stack and into GStreamer. I had never heard of GStreamer, but I also saw from this post that PulseAudio and JACK would implement this profile as well. I tried PulseAudio, but it would not load the proper UUIDs for the adapter. Then I finally found a post on the ArchLinux wiki. I must have been to this page a million times, but it was probably when I was still using BlueZ4.

Most importantly:

-download the new PulseAudio 5 source code, which has support for BlueZ5, and compile it. (It is not the newest version in the apt repositories.)

-compiling took a LOT of dependencies (JSON,libsndfile,libcap, etc)

-keep in mind that the path for PA5 is /usr/local not /usr/ (This is important, because I had to put it in $LD_LIBRARY_PATH so that PA could find libpulsecore-5.0 at startup)

-as the ArchLinux wiki says, kill the pulseaudio server that is run at startup and start a new one. It doesn't load the profiles at startup. Also make sure that the daemon respawns. (Set in /usr/local//etc/pulse/client.conf)

After that, the usual pactl commands work. I was able to get an a2dp BT source (i.e. iPod) to stream to PA5, and then, using the loopback module, stream to an a2dp BT sink!

I wasn't able to get it to run with ALSA, but I read somewhere that BlueZ5 may not support ALSA pcm plugins anymore.

Related Question