Revision as of 06:15, 5 November 2018

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.

By default the bluetooth daemon will only give out bnep0 devices to users that are a member of the lp group. Make sure to add your user to that group if you intend to connect to a bluetooth tether. You can change the group that is required in the file /etc/dbus-1/system.d/bluetooth.conf.

Some Bluetooth adapters are bundled with a Wi-Fi card (e.g. Intel Centrino). These require that the Wi-Fi card is firstly enabled (typically a keyboard shortcut on a laptop) in order to make the Bluetooth adapter visible to the kernel.

Some Bluetooth cards (e.g. Broadcom) conflict with the network adapter. Thus, you need to make sure that your Bluetooth device get connected before the network service boot.

Some tools such as hcitool and hciconfig have been deprecated upstream, and are no longer included in bluez-utils. Since these tools will no longer be updated, it is recommended that scripts be updated to avoid using them. If you still desire to use them, install bluez-utils-compatAUR. See FS#53110 and the Bluez mailing list for more information.

Front-ends

Console

bluetoothctl — Pairing a device from the shell is one of the simplest and most reliable options.

Bluedevil — KDE's Bluetooth tool. If there is no Bluetooth icon visible in Dolphin and in the system tray, enable it in the system tray options or add a widget. You can configure Bluedevil and detect Bluetooth devices by clicking the icon. An interface is also available from the KDE System Settings.

Pairing

Reason: Step 5 is unclear. What are Bluetooth agents? (Discuss in Talk:Bluetooth#)

Note: Before using the bluetooth device, make sure that it is not blocked by rfkill.

This section describes directly configuring bluez5 via the bluetoothctl CLI, which might not be necessary if you are using an alternative front-end tool (such as GNOME Bluetooth).

The exact procedure depends on the devices involved and their input functionality. What follows is a general outline of pairing a device using bluetoothctl.

Start the bluetoothctl interactive command. Input help to get a list of available commands.

(optional) Select a default controller with select MAC_address.

Enter power on to turn the power to the controller on. It is off by default and will turn off again each reboot, see #Auto power-on after boot.

Enter devices to get the MAC Address of the device with which to pair.

Enter device discovery mode with scan on command if device is not yet on the list.

Turn the agent on with agent on or choose a specific agent: if you press tab twice after agent you should see a list of available agents, e.g. DisplayOnly KeyboardDisplay NoInputNoOutput DisplayYesNo KeyboardOnly off on.

Enter pair MAC_address to do the pairing (tab completion works).

If using a device without a PIN, one may need to manually trust the device before it can reconnect successfully. Enter trust MAC_address to do so.

Configuration

Auto power-on after boot

By default, your Bluetooth adapter will not power on after a reboot. The former method by using hciconfig hci0 up is deprecated, see the release note. Now you just need to add the line AutoEnable=true in /etc/bluetooth/main.conf at the bottom in the [Policy] section:

/etc/bluetooth/main.conf

[Policy]
AutoEnable=true

Then you need to enable the Policy Bluez plugin by adding the --plugin=policy flag to the ExecStart command in the bluetooth systemd unit file:

Some users may experience disconnection, and you may try to remove the added --plugin=policy flag.

Audio

In order to be able to use audio equipment like bluetooth headphones or speakers, you need to install the additional pulseaudio-bluetooth package. With a default PulseAudio installation you should immediately be able to stream audio from a bluetooth device to your speakers.

If you have a system-wide PulseAudio setup make sure the user running the daemon (usually pulse) is in the lp group and you load the bluetooth modules in your PulseAudio config:

Bluetooth USB Dongle

If you are using a USB dongle, you should check that your Bluetooth dongle is recognized. You can do that by running journalctl -f when you have plugged in the USB dongle (or inspecting /var/log/messages.log). It should look something like the following (look out for hci):

Logitech Bluetooth USB Dongle

There are Logitech dongles (ex. Logitech MX5000) that can work in two modes: Embedded and HCI. In embedded mode dongle emulates a USB device so it seems to your PC that you are using a normal USB mouse/keyoard.

If you hold the little red Button on the USB BT mini-receiver it will enable the other mode. Hold the red button on the BT dongle and plug it into the computer, and after 3-5 seconds of holding the button, the Bluetooth icon will appear in the system tray. Discussion

Alternatively, you can install the bluez-hid2hci package. When you connect your Logitech dongle it will automatically switch.

hcitool scan: Device not found

On some Dell laptops (e.g. Studio 15) you have to switch the Bluetooth mode from HID to HCI. Install the bluez-hid2hci package, then udev should do this automatically. Alternatively, you can run this command to switch to HCI manually:

# /usr/lib/udev/hid2hci

If the device will not show up and you have a Windows operating system on your machine, try booting it and enable the bluetooth adapter from windows.

HSP/HFP profiles

bluez5 removed support for the HSP/HFP profiles (telephony headset for TeamSpeak, Skype, etc.). You need to install PulseAudio (>= version 6) or another application that implements HSP/HFP itself.

Foxconn / Hon Hai / Lite-On Broadcom device

Some of these devices require the firmware to be flashed into the device at boot. The firmware is not provided but can converted from a Microsoft Windows .hex file into a .hcd using hex2hcd (which is installed with bluez-utils).

In order to get the right .hex file, try searching the device vendor:product code obtained with lsusb, for example:

Alternatively, boot into Windows (a virtual machine installation will suffice) and get the firmware name from the Device Manager utility. If you want to know the model of your device but cannot see it in lsusb, you might see it in lsusb -v as iProduct.

The .hex file can be extracted from the downloaded Windows driver without having to run Windows for it. Download the right driver, for example Bluetooth Widcomm (listed among the drivers for Lifebook P771), which contains the drivers for many Broadcomm devices. In case of Bluetooth Widcomm, the driver is a self-extracting RAR archive, so it can be extracted using unrar x. To find out which of the many .hex files is the right one for you, look in the file Win32/bcbtums-win7x86-brcm.inf and search for [RAMUSBE031.CopyList], where E031 should be replaced with the product code (the second hex number in lsusb) of your device in upper-case. Underneath you should see the file name of the right .hex file.

Once you have the .hcd file, copy it into /lib/firmware/brcm/BCM.hcd - this filename is suggested by dmesg and it may change in your case so check your dmesg output in order to verify. Then reload the btusb module:

# rmmod btusb
# modprobe btusb

In some cases (with older kernels?), you have to flash the .hcd file with the brcm_patchram_plus utility, provided by brcm_patchram_plus-gitAUR[broken link: archived in aur-mirror]. First, make sure in dmesg that the device is recognized by btusb as a bluetooth device. Then, run the following (replace 04ca 2006 with your vendor product pair):

# echo '04ca 2006' > /sys/bus/usb/drivers/btusb/new_id

Turn on the device:

# hciconfig hci0 up

Flash the firmware:

# brcm_patchram_plus_usb --patchram fw-04ca_2006.hcd hci0

The device should now be available. See BBS#162688 for information on making these changes persistent.

Device connects, then disconnects after a few moments

If you see messages like the following in journalctl output, and your device fails to connect or disconnects shortly after connecting:

This may be because you have already paired the device with another operating system using the same bluetooth adapter (e.g., dual-booting). Some devices cannot handle multiple pairings associated with the same MAC address (i.e., bluetooth adapter). You can fix this by re-pairing the device. Start by removing the device:

Then restartbluetooth.service, turn on your bluetooth adapter, make your device discoverable, re-scan for devices, and re-pair your device. Depending on your bluetooth manager, you may need to perform a full reboot in order to re-discover the device.

Device does not connect with an error in journal

If you see a message like the following in journalctl output while trying to connect to a device:

a2dp-source profile connect failed for 9C:64:40:22:E1:3F: Protocol not available

Device does not show up in scan

Some devices using bluetooth low energy do not appear when scanning with bluetoothctl, for example the Logitech MX Master. The simplest way I have found to connect them is by installing bluez-utils-compatAUR, then startbluetooth.service and do: