Bluetooth

This article describes the configuration and usage of Bluetooth controllers and devices.

Prerequisites
This article assumes that udev and USB have been previously configured.

Kernel
In most cases enabling RFCOMM, HIDP, HCI USB and/or HCI UART should be sufficient.

Software
BlueZ is the Bluetooth protocol stack for Linux. It is provided by the package. Portage has ebuilds for BlueZ 4, which is deprecated, and BlueZ 5.

Bluetooth support can be enabled system-wide by setting the  variable to.

Portage will by default install BlueZ 5. If BlueZ 4 is required, mask BlueZ 5 to prevent it from being installed.

The system needs to be updated if the  variable was set to.

Install BlueZ.

Permissions
Permissions for Bluetooth devices will be handled automatically if the  variable is set to   and ConsoleKit or systemd is being used.

Alternatively, adding a user to the plugdev group will allow that user to access Bluetooth devices.

Starting
OpenRC
 * Start Bluetooth.


 * Start Bluetooth at boot.

systemd
 * Start Bluetooth.


 * Start Bluetooth at boot.

Controller setup

 * Display controller information.

Where  is the name of the controller and   indicates that the controller is enabled.


 * Enable the controller if hciconfig indicates (with ) that the controller is disabled.


 * The following message may be displayed when attempting to enable the controller.

In this case, query the rfkill state of the controller with.


 * Unblock the controller if rfkill indicates (with ) that the controller is blocked.


 * Unblock the controller by physical switch or keyboard function key if rfkill indicates (with ) that the controller is blocked.


 * The following udev rule will enable a controller before a graphical desktop environment is up and running.

Device pairing
Bluetooth devices need to be paired with a Bluetooth controller before they can be used. This is done by entering a PIN (or other code) on both devices via an interaction agent. Certain devices such as headsets do not allow entering an arbitrary PIN. These devices use a static PIN, which is usually 0000, 1111, 1234 or 9999. There are devices (e.g. Sony BD Remote Control) that do not require PIN</tt> entry and attempting to enter a PIN</tt> when prompted will result in failure. Paring can be skipped with such devices.

This article only covers device pairing with a command-line interaction agent. If a graphical desktop environment is being used, device paring can be done with a graphical interaction agent. For KDE use, for GNOME use and for GTK+ use.

BlueZ 4
Device paring, which is done with simple-agent</tt>, requires the  flag   to be enabled for the  package.


 * Put the device into pairing mode. This generally involves pressing a button or a combinations of buttons, usually for several seconds.


 * Discover the device MAC address.

Where 00:1F:20:1D:1B:4B is the MAC address of the device.


 * Pair with the device.

Enter a PIN</tt> and press. Now enter the same PIN</tt> on the device.


 * The following message may be displayed when attempting to pair with the device if a graphical interaction agent is installed (BlueDevil, GNOME Bluetooth etc.).

In this case stop or disable the graphical interaction agent and attempt to pair with the device again.


 * Query the trust status of the device.

Where 0 is not trusted and 1 is trusted.


 * Trust the device so it can connect automatically.


 * Connect to the device. This only needs to be done once if the device is trusted.


 * The device is now paired.

BlueZ 5
Device paring is done with bluetoothctl</tt>, which is provided by the package.


 * Start bluetoothctl</tt>.


 * List the available controllers.


 * Display information about a controller.


 * Set the default controller.


 * Power on the controller.


 * Enable the agent and set it as default.


 * Set the controller as discoverable (temporarily for 3 minutes) and pairable.


 * Scan for devices.


 * Put the device into pairing mode.


 * Discover the device MAC address.


 * Pair with the device.


 * Enter the PIN</tt> code if prompted.


 * Allow the service authorization request if prompted.


 * Trust the device.


 * Connect to the device.


 * Display information about the device.


 * The device is now paired.

External resources

 * Bluetooth for Your Mobile Phone