Bluetooth

From postmarketOS

Bluetooth is a standard for the short-range wireless interconnection of cellular phones, computers, and other electronic devices. In Linux, the canonical implementation of the Bluetooth protocol stack is BlueZ.

Pairing

phone:~# service bluetooth start
phone:~# bluetoothctl
Agent registered
[CHG] Controller XX:XX:XX:XX:XX:XX Pairable: yes
[bluetooth]# scan on
[NEW] 00:11:22:33:44:55
[bluetooth]# pair 00:11:22:33:44:55

To use bluetooth headphones with pulseaudio, the package pulseaudio-bluez is required.

Supported Bluetooth Profiles

Audio/Video Remote Control Profile (AVRCP)

To use media keys with Bluetooth, the mpris-proxy command should be run. It needs access to Dbus. mpris-proxy is started at boot to enable AVRCP 1.5 support. PulseAudio and BlueZ must be installed for this which pulls in mpris-proxy automatically. MR at pmaports: https://gitlab.com/postmarketOS/pmaports/-/merge_requests/1804

Advanced Audio Distribution Profile (A2DP)

PulseAudio and BlueZ handle together Bluetooth A2DP 1.3 support. This is supported out-of-the-box.

PhoneBook Access Profile (PBAP)

BlueZ got PBAP 1.1 support recently in 5.63 with GNOME Evolution as backend. Currently, a MR is pending at Alpine to enable this feature: https://gitlab.alpinelinux.org/alpine/aports/-/merge_requests/29955

Object Push Profile (OPP)

OBEXd was enabled at boot to enable OPP 1.2 support for transfering and receiving files over Bluetooth. MR at pmaports: https://gitlab.com/postmarketOS/pmaports/-/merge_requests/2245

Human Interface Device Profile (HID)

BlueZ provides the HID 1.0 profile to support mice and keyboards over Bluetooth. It is enabled by default.

Unsupported Bluetooth Profiles

Message Access Profile (MAP)

BlueZ has support for MAP 1.0 but does not have a backend which is compatible with any UI stack. The supported backends are from the old Nokia Maemo days.

Personal Area Network (PAN)

BlueZ supports PAN 1.0, but hasn't been enabled in postmarketOS (yet). Preliminary tests show that NetworkManager has full support for PAN network and they work well over the commandline:

 nmcli connection add type bluetooth con-name "Bluetooth Hotspot" autoconnect no ifname btnap0 bluetooth.type nap ipv4.method shared ipv6.method disabled

For now, only IPv4 is marked as shared. IPv6 should work but was not tested. This works if BlueZ was built with BNEP support and a valid Bluetooth MAC address is available. Without a valid MAC address, the BlueZ BNEP network bridges cannot be added to the kernel.

Source: https://networkmanager.dev/docs/api/latest/nmcli-examples.html

Hands-Free Profile (HFP)

BlueZ and PulseAudio partly support HFP 1.6. Only the audio part is supported. Reporting battery levels from the AG to HF is unsupported and all cellular operations and status reporting is not supported (yet). A first step in fully supporting Bluetooth HFP 1.6 is taken here: https://gitlab.freedesktop.org/pulseaudio/pulseaudio/-/merge_requests/631

postmarketOS edge has the necessary patches applied to PulseAudio for supporting Bluetooth HFP AT commands (battery level reporting, cellular status, accept/reject calls, etc.), audio routing not yet. Feedback is welcome in https://gitlab.freedesktop.org/pulseaudio/pulseaudio/-/merge_requests/693

HFP AT command support for controlling calls is merged in PipeWire and will be available officially when postmarketOS switches to PipeWire in the near future.

Other profiles

Bluetooth supports many other profiles, see https://www.bluetooth.com/specifications/ It is currently unknown if they are supported or not.

Bluetooth profiles supported by other mobile OSes

Troubleshooting

No default controller available

# modprobe -r btqcomsmd
# modprobe btqcomsmd

Failed set serial line discipline: Invalid argument in btattach or Can't set line discipline: Invalid argument in hciattach:

Enable CONFIG_BT_HCIUART (and possibly CONFIG_BT_HCIUART_BCM) in kernel config.


btattach -P bcm doesn't set desired baud rate after uploading firmware:

Use hciattach instead (https://github.com/Arkq/bluez-alsa/issues/205) and verify results with stty -F /dev/tty.


Failed to start discovery: org.bluez.Error.NotReady or Failed to connect: org.bluez.Error.NotReady br-connection-adapter-not-powered

[bluetooth]# power on
Changing power on succeeded
[CHG] Controller XX:XX:XX:XX:XX:XX Powered: yes

Failed to connect: org.bluez.Error.Failed br-connection-profile-unavailable when connecting to a headset

# apk add bluez-alsa
# service bluealsa start
# bluetoothctl
[bluetooth]# connect 00:11:22:33:44:55
Attempting to connect 00:11:22:33:44:55
Connection successful
[CHG] Device 00:11:22:33:44:55 ServicesResolved: yes

Bluetooth keyboards, mice and other HID devices

Make sure CONFIG_UHID is enabled in your kernel. If it's enabled as a module, run:

# modprobe uhid
# service bluetooth restart

Getting the device to work might require a few tries; in general, what often works is first pairing the device, then turning off Bluetooth, turning it on again and letting the device connect again (many mice/keyboards will try to reconnect when you press any key/move the mouse).