Difference between revisions of "Bluetooth"

From ArchWiki
Jump to navigation Jump to search
(BLE howto)
(Update bluedevil code location.)
 
(119 intermediate revisions by 46 users not shown)
Line 9: Line 9:
 
[[zh-hans:Bluetooth]]
 
[[zh-hans:Bluetooth]]
 
{{Related articles start}}
 
{{Related articles start}}
{{Related|Bluez4}}
 
 
{{Related|Bluetooth mouse}}
 
{{Related|Bluetooth mouse}}
 +
{{Related|Bluetooth keyboard}}
 
{{Related|Bluetooth headset}}
 
{{Related|Bluetooth headset}}
 
{{Related|Blueman}}
 
{{Related|Blueman}}
 +
{{Related|ObexFTP}}
 
{{Related articles end}}
 
{{Related articles end}}
[http://www.bluetooth.org/ 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 [http://www.bluez.org/ BlueZ].
+
[[Wikipedia:Bluetooth|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 [http://www.bluez.org/ BlueZ].
  
 
== Installation ==
 
== Installation ==
  
[[Install]] the {{Pkg|bluez}} and {{Pkg|bluez-utils}} packages. The {{Pkg|bluez}} package provides the Bluetooth protocol stack, and the {{Pkg|bluez-utils}} package provides the {{ic|bluetoothctl}} utility.  
+
# [[Install]] the {{Pkg|bluez}} package, providing the Bluetooth protocol stack.
 
+
# [[Install]] the {{Pkg|bluez-utils}} package, providing the {{ic|bluetoothctl}} utility. Alternatively install {{AUR|bluez-utils-compat}} to additionally have the [[#Deprecated BlueZ tools|deprecated BlueZ tools]].
Load the generic bluetooth driver, if not already loaded:
+
# The generic Bluetooth driver is the {{ic|btusb}} Kernel module. [[Kernel_module#Obtaining_information|Check]] whether that module is loaded. If it's not, then [[Kernel_module#Manual_module_handling|load the module]].
# modprobe btusb
+
# [[Start/enable]] {{ic|bluetooth.service}}.
 
 
Then [[start]] the {{ic|bluetooth.service}} systemd unit. You can [[enable]] it to start automatically at boot time.
 
  
 
{{Note|
 
{{Note|
* By default the bluetooth daemon will only give out bnep0 devices to users that are a member of the {{ic|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 {{ic|/etc/dbus-1/system.d/bluetooth.conf}}.
+
* By default the bluetooth daemon will only give out bnep0 devices to users that are a member of the {{ic|lp}} [[Users and groups#System groups|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 {{ic|/usr/share/dbus-1/system.d/bluetooth.conf}}.
 
* Some Bluetooth adapters are bundled with a Wi-Fi card (e.g. [http://www.intel.com/content/www/us/en/wireless-products/centrino-advanced-n-6235.html 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 adapters are bundled with a Wi-Fi card (e.g. [http://www.intel.com/content/www/us/en/wireless-products/centrino-advanced-n-6235.html 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 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 {{Pkg|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 {{AUR|bluez-utils-compat}}. See {{Bug|53110}} and [https://www.spinics.net/lists/linux-bluetooth/msg69239.html the Bluez mailing list] for more information. }}
 
* Some tools such as hcitool and hciconfig have been deprecated upstream, and are no longer included in {{Pkg|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 {{AUR|bluez-utils-compat}}. See {{Bug|53110}} and [https://www.spinics.net/lists/linux-bluetooth/msg69239.html the Bluez mailing list] for more information. }}
  
== Configuration via the CLI ==
+
=== Front-ends ===
=== Bluetoothctl ===
 
Pairing a device from the shell is one of the simplest and most reliable options.  The exact procedure depends on the devices involved and their input functionality.  What follows is a general outline of pairing a device using {{ic|/usr/bin/bluetoothctl}}:
 
  
Start the {{ic|bluetoothctl}} interactive command. There one can input {{ic|help}} to get a list of available commands.
+
==== Console ====
* Possibly select a default controller by inputting {{ic|select ''MAC Address''}}
 
* Turn the power to the controller on by entering {{ic|power on}}. It is off by default.
 
* Enter {{ic|devices}} to get the MAC Address of the device with which to pair.
 
* Enter device discovery mode with {{ic|scan on}} command if device is not yet on the list.
 
* Turn the agent on with {{ic|agent on}}.
 
* Enter {{ic|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 {{ic|trust ''MAC Address''}} to do so.
 
* Finally, use {{ic|connect ''MAC_address''}} to establish a connection.
 
  
An example session may look this way:
+
* {{App|bluetoothctl|Pairing a device from the shell is one of the simplest and most reliable options.|http://www.bluez.org/|{{Pkg|bluez-utils}}}}
# bluetoothctl  
 
[NEW] Controller 00:10:20:30:40:50 pi [default]
 
[bluetooth]# agent KeyboardOnly
 
Agent registered
 
[bluetooth]# default-agent
 
Default agent request successful
 
[bluetooth]# scan on
 
Discovery started
 
[CHG] Controller 00:10:20:30:40:50 Discovering: yes
 
[NEW] Device 00:12:34:56:78:90 myLino
 
[CHG] Device 00:12:34:56:78:90 LegacyPairing: yes
 
[bluetooth]# pair 00:12:34:56:78:90
 
Attempting to pair with 00:12:34:56:78:90
 
[CHG] Device 00:12:34:56:78:90 Connected: yes
 
[CHG] Device 00:12:34:56:78:90 Connected: no
 
[CHG] Device 00:12:34:56:78:90 Connected: yes
 
Request PIN code
 
[agent] Enter PIN code: 1234
 
[CHG] Device 00:12:34:56:78:90 Paired: yes
 
Pairing successful
 
[CHG] Device 00:12:34:56:78:90 Connected: no
 
[bluetooth]# connect 00:12:34:56:78:90
 
Attempting to connect to 00:12:34:56:78:90
 
[CHG] Device 00:12:34:56:78:90 Connected: yes
 
Connection successful
 
  
In order to have the device active after a reboot, a udev rule is needed:
+
{{Tip|To automate bluetoothctl commands, use {{ic|echo -e "<command1>\n<command2>\n" {{!}} bluetoothctl}} or {{ic|bluetoothctl -- command}}}}
  
{{hc|/etc/udev/rules.d/10-local.rules|2=
+
==== Graphical ====
# Set bluetooth power up
 
ACTION=="add", KERNEL=="hci0", RUN+="/usr/bin/hciconfig %k up"}}
 
  
{{Tip|Replace {{ic|1=KERNEL=="hci0"}} with {{ic|1=KERNEL=="hci[0-9]*"}} to match all interfaces.}}
+
The following packages allow for a graphical interface to customize Bluetooth.
  
After a suspend/resume-cycle, the device can be powered on automatically using a custom ''systemd'' service:
+
* {{App|GNOME Bluetooth|[[GNOME]]'s Bluetooth tool.
 +
** {{Pkg|gnome-bluetooth}} provides the back-end
 +
** {{Pkg|gnome-shell}} provides the status monitor applet
 +
** {{Pkg|gnome-control-center}} provides the configuration front-end GUI that can be accessed by typing Bluetooth on the Activities overview, or with the {{ic|gnome-control-center bluetooth}} command.
 +
** You can also launch the {{ic|bluetooth-sendto}} command directly to send files to a remote device.
 +
** {{AUR|nautilus-bluetooth}} adds a "Send via Bluetooth" entry to Nautilus' right-click menu
 +
** To receive files, open the Bluetooth settings panel; you can only receive whilst the Bluetooth panel is open.
 +
** To add a Bluetooth entry to the ''Send To'' menu in Thunar's file properties menu, see instructions [http://docs.xfce.org/xfce/thunar/send-to here]. (The command that needs to be configured is {{ic|bluetooth-sendto %F}}).
 +
|https://wiki.gnome.org/Projects/GnomeBluetooth|}}
 +
* {{App|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.|https://cgit.kde.org/bluedevil.git|{{Pkg|bluedevil}}}}
 +
* {{App|Blueberry|Linux Mint's spin-off of GNOME Bluetooth, which works in all desktop environments. ''Blueberry'' does not support receiving files through Obex Object Push.|https://github.com/linuxmint/blueberry|{{Pkg|blueberry}}}}
 +
* {{App|[[Blueman]]|A full featured Bluetooth manager.|https://github.com/blueman-project/blueman|{{Pkg|blueman}}}}
 +
* {{App|[[ObexFTP]]|A tool for transferring files to/from any OBEX enabled device.|http://dev.zuckschwerdt.org/openobex/wiki/ObexFtp|{{AUR|obexftp}}}}
  
{{hc|/etc/systemd/system/bluetooth-auto-power@.service|<nowiki>
+
== Pairing ==
[Unit]
 
Description=Bluetooth auto power on
 
After=bluetooth.service sys-subsystem-bluetooth-devices-%i.device suspend.target
 
  
[Service]
+
{{Expansion|Step 5 is unclear. What are Bluetooth agents?}}
Type=oneshot
 
ExecStart=/usr/bin/hciconfig %i up
 
  
[Install]
+
{{Note|Before using the bluetooth device, make sure that it is not blocked by [[rfkill]].}}
WantedBy=suspend.target
 
</nowiki>}}
 
  
[[Enable]] an instance of the unit using your bluetooth device name, for example {{ic|bluetooth-auto-power@hci0.service}}.
+
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).
  
Alternatively and instead of the custom service and udev rule, you can simply use the new [http://www.bluez.org/release-of-bluez-5-35/ AutoEnable feature introduced in BlueZ 5.35] by uncommenting {{ic|[Policy]}} and {{ic|1=AutoEnable=true}} lines in {{ic|/etc/bluetooth/main.conf}}.
+
The exact procedure depends on the devices involved and their input functionality. What follows is a general outline of pairing a device using {{ic|bluetoothctl}}.
  
== Configuration with a graphical front-end ==
+
Start the {{ic|bluetoothctl}} interactive command. Input {{ic|help}} to get a list of available commands.
  
The following packages allow for a graphical interface to customize Bluetooth.
+
# (optional) Select a default controller with {{ic|select ''MAC_address''}}.
 +
# Enter {{ic|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 {{ic|devices}} to get the MAC Address of the device with which to pair.
 +
# Enter device discovery mode with {{ic|scan on}} command if device is not yet on the list.
 +
# Turn the agent on with {{ic|agent on}} or choose a specific agent: if you press tab twice after {{ic|agent}} you should see a list of available agents, e.g. DisplayOnly KeyboardDisplay NoInputNoOutput DisplayYesNo KeyboardOnly off on.
 +
# Enter {{ic|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 {{ic|trust ''MAC_address''}} to do so.
 +
# Enter {{ic|connect ''MAC_address''}} to establish a connection.
  
=== GNOME Bluetooth ===
+
An example session may look this way:
  
[https://wiki.gnome.org/Projects/GnomeBluetooth GNOME Bluetooth] is [[GNOME]]'s Bluetooth tool. The {{Pkg|gnome-bluetooth}} package provides the back-end, {{Pkg|gnome-shell}} provides the status monitor applet, and {{Pkg|gnome-control-center}} provides the configuration front-end GUI that can be accessed by typing Bluetooth on the Activities overview, or with the {{ic|gnome-control-center bluetooth}} command. You can also launch the {{ic|bluetooth-sendto}} command directly to send files to a remote device.
+
{{hc|# bluetoothctl|
 +
[NEW] Controller 00:10:20:30:40:50 pi [default]
 +
}}
  
To receive files, you must install the {{Pkg|gnome-user-share}} package. You can then go to ''Settings -> Sharing'' to authorize receiving files from paired devices over Bluetooth.
+
{{hc|[bluetooth]# agent KeyboardOnly|
 +
Agent registered
 +
}}
  
{{Tip|To add a Bluetooth entry to the ''Send To'' menu in Thunar's file properties menu, see instructions [http://docs.xfce.org/xfce/thunar/send-to here]. (The command that needs to be configured is {{ic|bluetooth-sendto %F}}).}}
+
{{hc|[bluetooth]# default-agent|
 +
Default agent request successful
 +
}}
  
=== Bluedevil ===
+
{{hc|[bluetooth]# power on|
 +
Changing power on succeeded
 +
[CHG] Controller 00:10:20:30:40:50 Powered: yes
 +
}}
  
[https://projects.kde.org/projects/kde/workspace/bluedevil Bluedevil] is [[KDE]]'s Bluetooth tool. It can be [[installed]] with the package {{Pkg|bluedevil}} (KDE Plasma 5).
+
{{hc|[bluetooth]# scan on|
 +
Discovery started
 +
[CHG] Controller 00:10:20:30:40:50 Discovering: yes
 +
[NEW] Device 00:12:34:56:78:90 myLino
 +
[CHG] Device 00:12:34:56:78:90 LegacyPairing: yes
 +
}}
  
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.
+
{{hc|[bluetooth]# pair 00:12:34:56:78:90|
 +
Attempting to pair with 00:12:34:56:78:90
 +
[CHG] Device 00:12:34:56:78:90 Connected: yes
 +
[CHG] Device 00:12:34:56:78:90 Connected: no
 +
[CHG] Device 00:12:34:56:78:90 Connected: yes
 +
Request PIN code
 +
[agent] Enter PIN code: 1234
 +
[CHG] Device 00:12:34:56:78:90 Paired: yes
 +
Pairing successful
 +
[CHG] Device 00:12:34:56:78:90 Connected: no
 +
}}
  
=== Blueberry ===
+
{{hc|[bluetooth]# connect 00:12:34:56:78:90|
 +
Attempting to connect to 00:12:34:56:78:90
 +
[CHG] Device 00:12:34:56:78:90 Connected: yes
 +
Connection successful
 +
}}
  
''Blueberry'' is an alternative front-end for GNOME Bluetooth, which works in all desktop environments. It can be installed with the {{Pkg|blueberry}} package. It provides a configuration tool (''blueberry'') and a system tray applet (''blueberry-tray'').
+
== Configuration ==
  
=== Blueman ===
+
=== Auto power-on after boot ===
  
See [[Blueman]].
+
By default, your Bluetooth adapter will not power on after a reboot. The former method by using {{ic|hciconfig hci0 up}} is deprecated, see the [http://www.bluez.org/release-of-bluez-5-35/ release note]. Now you just need to add the line {{ic|1=AutoEnable=true}} in {{ic|/etc/bluetooth/main.conf}} at the bottom in the {{ic|[Policy]}} section:
  
== Using Obex for sending and receiving files ==
+
{{hc|1=/etc/bluetooth/main.conf|2=
=== ObexFS ===
+
[Policy]
Another option, rather than using KDE or Gnome Bluetooth packages, is ObexFS which allows for the mounting of phones which are treated like any other filesystem.
+
AutoEnable=true
{{Note|To use ObexFS, one needs a device that provides an ObexFTP service.}}
+
}}
  
Install {{Pkg|obexfs}} and mount supported phones by running:
+
=== Discoverable on startup ===
$ obexfs -b ''MAC_address_of_device'' /mountpoint
 
  
Once you have finished, to unmount the device use the command:
+
If the device should always be visible and directly connectable:
$ fusermount -u /mountpoint
 
  
For more mounting options see http://dev.zuckschwerdt.org/openobex/wiki/ObexFs
+
{{hc|1=/etc/bluetooth/main.conf|2=
 +
[General]
 +
DiscoverableTimeout = 0
 +
Discoverable=true
 +
}}
  
{{Note|Ensure that the bluetooth device you are mounting is '''not''' set to mount ''read-only''. You should be able to do this from the device's settings. If the device is mounted ''read-only'' you may encounter a permissions error when trying to transfer files to the device.}}
+
== Audio ==
  
=== ObexFTP transfers ===
+
In order to be able to use audio equipment like bluetooth headphones or speakers, you need to install the additional {{Pkg|pulseaudio-bluetooth}} package. With a default PulseAudio installation you should immediately be able to stream audio from a bluetooth device to your speakers.
  
If your device supports the Obex FTP service but you do not wish to mount the device you can transfer files to and from the device using the obexftp command.
+
If you have a system-wide PulseAudio setup make sure the user running the daemon (usually {{ic|pulse}}) is in the {{ic|lp}} group and you load the bluetooth modules in your PulseAudio config:
  
To send a file to a device run the command:
+
{{hc|/etc/pulse/system.pa|2=
 +
...
 +
load-module module-bluetooth-policy
 +
load-module module-bluetooth-discover
 +
...
 +
}}
  
$ obexftp -b ''MAC_address_of_device'' -p /path/to/file
+
See the [[Bluetooth headset]] page for more information about bluetooth audio and bluetooth headsets.
  
To retrieve a file from a device run the command:
+
== Bluetooth serial ==
 +
To get bluetooth serial communication working on Bluetooth-to-Serial modules (HC-05, HC-06) do the following steps:
  
$ obexftp -b ''MAC_address_of_device'' -g filename
+
Pair your bluetooth device using {{ic|bluetoothctl}} as described [[#Pairing|above]].
  
{{Note|Ensure that the file you are retrieving is in the device's ''exchange folder''. If the file is in a subfolder of the exchange folder then provide the correct path in the command.}}
+
Install {{AUR|bluez-rfcomm}} and {{AUR|bluez-hcitool}}, as they provide certain functionality which is missing from newer tools.
  
=== Obex Object Push ===
+
Bind paired device MAC address to tty terminal:
For devices that do not support Obex FTP service, check if Obex Object Push is supported.
+
# rfcomm bind rfcomm0 <MAC address of bluetooth device>
  
# sdptool browse ''XX:XX:XX:XX:XX:XX''
+
Now you can open {{ic|/dev/rfcomm0}} for serial communication.
  
Read the output, look for Obex Object Push, remember the channel for this service.  If supported, one can use {{pkg|ussp-push}} to send files to this device:
+
== Troubleshooting ==
 
 
# ussp-push ''XX:XX:XX:XX:XX:XX''@''CHANNEL'' ''file'' ''wanted_file_name_on_phone''
 
 
 
=== Using your computer's speakers as a bluetooth headset ===
 
  
This can allow you to do things such as playing what is on your phone through your computer speakers.
+
{{Out of date|Replace hciconfig with newer commands.}}
  
Add the following to the file {{ic|/etc/bluetooth/audio.conf}} (create it if not present):
+
=== Debugging ===
  
[General]
+
In order to debug, first [[stop]] {{ic|bluetooth.service}}.
Enable=Source
 
  
More info in:
+
And then start it with the {{ic|-d}} parameter:
* https://gist.github.com/joergschiller/1673341
 
* http://www.lightofdawn.org/blog/?viewDetailed=00031
 
 
 
== Audio ==
 
  
In order to be able to use audio equipment like bluetooth headphones, you need to install the additional {{Pkg|pulseaudio-bluetooth}} package.
+
# /usr/lib/bluetooth/bluetoothd -n -d
  
Please have a look at the [[Bluetooth headset]] page for more information about bluetooth audio and bluetooth headsets.
+
Another option is via the {{ic|btmon}} tool.
  
In order to enable your system to be detected as an A2DP sink (e.g. to play music from your phone via your computer speakers), add {{ic|1=Enable=Source,Sink,Media,Socket}} under {{ic|[General]}} in {{ic|/etc/bluetooth/audio.conf}}.
+
=== Deprecated BlueZ tools ===
  
== Troubleshooting ==
+
Eight BlueZ tools [https://git.kernel.org/pub/scm/bluetooth/bluez.git/commit/?id=b1eb2c4cd057624312e0412f6c4be000f7fc3617 were deprecated] and removed from {{Pkg|bluez-utils}}, although not all of them were superseded by newer tools. The {{AUR|bluez-utils-compat}} package provides an alternative version of {{Pkg|bluez-utils}} with the deprecated tools.
  
=== Shell command _____ is missing from bluez-utils ===
 
Some tools have been marked as deprecated and removed from the package. At this time they are still available in the AUR package {{AUR|bluez-utils-compat}}. Their functionality is partially covered by new tools, while some things have yet to be implemented with the new [https://git.kernel.org/cgit/bluetooth/bluez.git/tree/doc/ D-Bus API]:
 
 
{| class="wikitable" style="max-width: 50em;"
 
{| class="wikitable" style="max-width: 50em;"
 
|-
 
|-
Line 193: Line 192:
 
! Most likely replacement
 
! Most likely replacement
 
|-
 
|-
| gatttool || btgatt-client, [D-Bus Gatt API https://git.kernel.org/cgit/bluetooth/bluez.git/tree/doc/gatt-api.txt]
+
| [https://manpages.debian.org/stretch/bluez/gatttool.1.en.html gatttool] || btgatt-client, [https://git.kernel.org/cgit/bluetooth/bluez.git/tree/doc/gatt-api.txt D-Bus Gatt API]
 
|-
 
|-
| hciattach || btattach
+
| [https://manpages.debian.org/stretch/bluez/hciattach.1.en.html hciattach] || btattach
 
|-
 
|-
| hciconfig || btmgmt (and bluetoothctl?)
+
| [https://manpages.debian.org/stretch/bluez/hciconfig.1.en.html hciconfig] || btmgmt (and bluetoothctl?)
 
|-
 
|-
| hcidump || btmon (and btsnoop)
+
| [https://manpages.debian.org/stretch/bluez-hcidump/hcidump.1.en.html hcidump] || btmon (and btsnoop)
 
|-
 
|-
| hcitool || missing, [https://git.kernel.org/cgit/bluetooth/bluez.git/tree/doc/device-api.txt D-Bus Device API] available
+
| [https://manpages.debian.org/stretch/bluez/hcitool.1.en.html hcitool] || missing, [https://git.kernel.org/cgit/bluetooth/bluez.git/tree/doc/device-api.txt D-Bus Device API] available
 
|-
 
|-
| rfcomm
+
| [https://manpages.debian.org/stretch/bluez/rfcomm.1.en.html rfcomm]
 
| rowspan="2" | missing, implement with [https://git.kernel.org/cgit/bluetooth/bluez.git/tree/doc/profile-api.txt D-Bus Profile1 API]?
 
| rowspan="2" | missing, implement with [https://git.kernel.org/cgit/bluetooth/bluez.git/tree/doc/profile-api.txt D-Bus Profile1 API]?
 
|-
 
|-
| ciptool
+
| [https://manpages.debian.org/stretch/bluez/ciptool.1.en.html ciptool]
 
|-
 
|-
| style="vertical-align: top;" | sdptool
+
| style="vertical-align: top;" | [https://manpages.debian.org/stretch/bluez/sdptool.1.en.html sdptool]
 
| missing, functionality seems to be scattered over different D-Bus objects: [https://git.kernel.org/cgit/bluetooth/bluez.git/tree/doc/profile-api.txt Profile], [https://git.kernel.org/cgit/bluetooth/bluez.git/tree/doc/advertising-api.txt Advertising], and the UUIDs arrays in [https://git.kernel.org/cgit/bluetooth/bluez.git/tree/doc/device-api.txt device] and [https://git.kernel.org/cgit/bluetooth/bluez.git/tree/doc/adapter-api.txt adapter].  
 
| missing, functionality seems to be scattered over different D-Bus objects: [https://git.kernel.org/cgit/bluetooth/bluez.git/tree/doc/profile-api.txt Profile], [https://git.kernel.org/cgit/bluetooth/bluez.git/tree/doc/advertising-api.txt Advertising], and the UUIDs arrays in [https://git.kernel.org/cgit/bluetooth/bluez.git/tree/doc/device-api.txt device] and [https://git.kernel.org/cgit/bluetooth/bluez.git/tree/doc/adapter-api.txt adapter].  
 
|}
 
|}
 
=== bluetoothctl ===
 
If bluetoothctl cannot find any controller, the bluetooth device may be blocked. Try to unblock it using {{Pkg|rfkill}}:
 
 
# rfkill unblock bluetooth
 
  
 
=== gnome-bluetooth ===
 
=== gnome-bluetooth ===
  
 
If you see this when trying to enable receiving files in bluetooth-properties:
 
If you see this when trying to enable receiving files in bluetooth-properties:
 +
 
  Bluetooth OBEX start failed: Invalid path
 
  Bluetooth OBEX start failed: Invalid path
 
  Bluetooth FTP start failed: Invalid path
 
  Bluetooth FTP start failed: Invalid path
Then install {{Pkg|xdg-user-dirs}} and issue:
+
 
$ xdg-user-dirs-update
+
Then make sure that the [[XDG user directories]] exist.
You can edit the paths using:
 
$ vi ~/.config/user-dirs.dirs
 
  
 
=== Bluetooth USB Dongle ===
 
=== Bluetooth USB Dongle ===
Line 242: Line 235:
 
Example:
 
Example:
  
{{hc|hciconfig -a hci0|
+
# btmgmt
hci0: Type: USB
+
{{hc|[mgmt]# info|
BD Address: 00:00:00:00:00:00 ACL MTU: 0:0 SCO MTU: 0:0
+
Index list with 1 item
DOWN
+
hci0: Primary controller
RX bytes:0 acl:0 sco:0 events:0 errors:0
+
addr 00:1A:7D:DA:71:10 version 6 manufacturer 10 class 0x000000
        TX bytes:0 acl:0 sco:0 commands:0 errors:
+
supported settings: powered connectable fast-connectable discoverable bondable link-security ssp br/edr hs le advertising secure-conn debug-keys privacy static-addr
 +
'''current settings:''' connectable discoverable bondable ssp br/edr le secure-conn
 +
name Mozart
 +
short name
 
}}
 
}}
  
# hciconfig hci0 up
+
{{hc|[mgmt]# select hci0|
 +
Selected index 0
 +
}}
  
{{hc|hciconfig -a hci0|
+
{{hc|[hci0]# power up|
hci0: Type: USB
+
hci0 Set Powered complete, settings: '''powered''' connectable discoverable bondable ssp br/edr le secure-conn
BD Address: 00:02:72:C4:7C:06 ACL MTU: 377:10 SCO MTU: 64:8
 
UP RUNNING
 
RX bytes:348 acl:0 sco:0 events:11 errors:0
 
        TX bytes:38 acl:0 sco:0 commands:11 errors:0
 
 
}}
 
}}
  
If this fails with an error like:
+
{{hc|[hci0]# info|
Operation not possible due to RF-kill
+
hci0: Primary controller
it could be due either to the {{ic|rfkill}} utility, in which case it should be resolved with
+
addr 00:1A:7D:DA:71:10 version 6 manufacturer 10 class 0x1c0104
# rfkill unblock all
+
supported settings: powered connectable fast-connectable discoverable bondable link-security ssp br/edr hs le advertising secure-conn debug-keys privacy static-addr
or, it could simply be the hardware switch of the computer. The hardware bluetooth switch (at least sometimes) controls access to USB bluetooth dongles also. Flip/press this switch and try bringing the device up again.
+
'''current settings: powered''' connectable discoverable bondable ssp br/edr le secure-conn
 +
}}
  
To verify that the device was detected you can use {{ic|hcitool}} which is part of the {{ic|bluez-utils}}. You can get a list of available devices and their identifiers and their MAC address by issuing:
+
Or
  
{{hc|$ hcitool dev|
+
# bluetoothctl
Devices:
+
 
        hci0 00:1B:DC:0F:DB:40
+
{{hc|[bluetooth]# show|
 +
Controller 00:1A:7D:DA:71:10 (public)
 +
Name: Mozart
 +
Alias: Mozart
 +
Class: 0x0000095c
 +
'''Powered: no'''
 +
Discoverable: yes
 +
Pairable: yes
 +
}}
 +
 
 +
{{hc|[bluetooth]# power on'''|
 +
[CHG] Controller 00:1A:7D:DA:71:10 Class: 0x001c0104
 +
Changing power on succeeded
 +
[CHG] Controller 00:1A:7D:DA:71:10 '''Powered: yes'''
 +
}}
 +
 
 +
{{hc|[bluetooth]# show|
 +
Controller 00:1A:7D:DA:71:10 (public)
 +
Name: Mozart
 +
Alias: Mozart
 +
Class: 0x001c0104
 +
'''Powered: yes'''
 +
Discoverable: yes
 +
Pairable: yes
 
}}
 
}}
  
More detailed information about the device can be retrieved by using {{ic|hciconfig}}.
+
To verify that the device was detected you can use {{ic|btmgmt}} which is part of the {{ic|bluez-utils}}. You can get a list of available devices and their identifiers and their MAC address by issuing:
 +
 
 +
{{hc|$ btmgmt info|
 +
Index list with 1 item
 +
hci0: Primary controller
 +
addr 00:1A:7D:DA:71:10 '''version 6''' manufacturer 10 class 0x1c0104
 +
supported settings: powered connectable fast-connectable discoverable bondable link-security ssp br/edr hs le advertising secure-conn debug-keys privacy static-addr
 +
current settings: powered connectable discoverable bondable ssp br/edr le secure-conn
 +
}}
 +
 
 +
It is possible to check the Bluetooth version as mapped to the HCI version according to the table in the [https://www.bluetooth.com/specifications/assigned-numbers/host-controller-interface/ official specification]. For example, in the previous output, HCI '''version 6''' is Bluetooth version 4.0.
 +
 
 +
More detailed information about the device can be retrieved by using the deprecated {{ic|hciconfig}}. ({{AUR|bluez-utils-compat}})
  
 
{{hc|$ hciconfig -a hci0|
 
{{hc|$ hciconfig -a hci0|
Line 305: Line 335:
 
Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
 
Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
 
}}
 
}}
 +
 +
==== CSR Dongle 0a12:0001 ====
 +
 +
The device {{ic|ID 0a12:0001 Cambridge Silicon Radio, Ltd Bluetooth Dongle (HCI mode)}} has a regression bug, and currently only works in the kernel version ≤ 3.9.11. There is a patch available for newer versions. For more information, see [https://bugzilla.kernel.org/show_bug.cgi?id=60824 Kernel Bug 60824].
  
 
=== Logitech Bluetooth USB Dongle ===
 
=== Logitech Bluetooth USB Dongle ===
Line 316: Line 350:
 
=== hcitool scan: Device not found ===
 
=== 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 {{Pkg|bluez-hid2hci}} package, then [[udev]] should do this automatically. Alternatively, you can run this command to switch to HCI manually:
+
* On some laptops (e.g. Dell Studio 15, Lenovo Thinkpad X1) you have to switch the Bluetooth mode from HID to HCI. Install the {{Pkg|bluez-hid2hci}} package, then [[udev]] should do this automatically. Alternatively, you can run this command to switch to HCI manually:
 +
 
 
  # /usr/lib/udev/hid2hci
 
  # /usr/lib/udev/hid2hci
  
Line 322: Line 357:
  
 
* Sometimes also this simple command helps:
 
* Sometimes also this simple command helps:
  # hciconfig hci0 up
+
 
 +
  # bluetoothctl power on
  
 
=== rfkill unblock: Do not unblock ===
 
=== rfkill unblock: Do not unblock ===
Line 332: Line 368:
 
=== My computer is not visible ===
 
=== My computer is not visible ===
  
Cannot discover computer from your phone? Enable PSCAN and ISCAN:
+
Cannot discover computer from your phone? Enable discoverable mode:
  # enable PSCAN and ISCAN
+
 
$ hciconfig hci0 piscan
+
  # bluetoothctl discoverable on
# check it worked
+
 
{{hc|$ hciconfig|
+
to check if it worked:
hci0:  Type: USB
+
 
        BD Address: 00:12:34:56:78:9A ACL MTU: 192:8 SCO MTU: 64:8
+
{{hc|# bluetoothctl show|
        '''UP RUNNING PSCAN ISCAN'''
+
Powered: yes
        RX bytes:20425 acl:115 sco:0 events:526 errors:0
+
Discoverable: yes
        TX bytes:5543 acl:84 sco:0 commands:340 errors:0
+
Pairable: yes
 
}}
 
}}
  
 
{{Note|Check DiscoverableTimeout and PairableTimeout in {{ic|/etc/bluetooth/main.conf}}}}
 
{{Note|Check DiscoverableTimeout and PairableTimeout in {{ic|/etc/bluetooth/main.conf}}}}
  
Try changing device class in {{ic|/etc/bluetooth/main.conf}} as following:
+
If even so it does not show up, try changing the device class in {{ic|/etc/bluetooth/main.conf}} as following:
 +
 
 
  # Default device class. Only the major and minor device class bits are
 
  # Default device class. Only the major and minor device class bits are
 
  # considered.
 
  # considered.
Line 352: Line 389:
 
  Class = 0x100100
 
  Class = 0x100100
  
This was the only solution to make my computer visible for my phone.
+
A user reported that this was the only solution to make his computer visible for his phone.
  
 
=== Logitech keyboard does not pair ===
 
=== Logitech keyboard does not pair ===
  
 
If you do not get the passkey when you try to pair your Logitech keyboard, type the following command:
 
If you do not get the passkey when you try to pair your Logitech keyboard, type the following command:
  # hciconfig hci0 sspmode 0
+
 
 +
  # btmgmt ssp off
  
 
If after pairing, the keyboard still does not connect, check the output of {{ic|hcidump -at}}. If the latter indicates repeatedly connections-disconnections like the following message:
 
If after pairing, the keyboard still does not connect, check the output of {{ic|hcidump -at}}. If the latter indicates repeatedly connections-disconnections like the following message:
Line 369: Line 407:
  
 
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.
 
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.
 
=== Thinkpad Bluetooth Laser Mouse problems ===
 
 
If you are experiencing that your Thinkpad Bluetooth Laser Mouse rapidly connects and then (after a few milliseconds) disconnects again every few seconds (when you move the mouse or press a button), try pairing it with the code {{ic|0000}} instead pairing without a code.
 
  
 
=== Foxconn / Hon Hai / Lite-On Broadcom device ===
 
=== Foxconn / Hon Hai / Lite-On Broadcom device ===
Line 397: Line 431:
 
  # modprobe btusb
 
  # modprobe btusb
  
In some cases (with older kernels?), you have to flash the ''.hcd'' file with the ''brcm_patchram_plus'' utility, provided by {{AUR|brcm_patchram_plus-git}}{{Broken package link|{{aur-mirror|brcm_patchram_plus-git}}}}. 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):
+
The device should now be available. See [https://bbs.archlinux.org/viewtopic.php?id=162688 BBS#162688] for information on making these changes persistent.
  
# echo '04ca 2006' > /sys/bus/usb/drivers/btusb/new_id
+
=== Intel combined wifi and bluetooth cards ===
   
 
Turn on the device:
 
  
# hciconfig hci0 up
+
See [[Wireless network configuration#Bluetooth coexistence]].
 
 
Flash the firmware:
 
 
 
# brcm_patchram_plus_usb --patchram fw-04ca_2006.hcd hci0
 
 
 
The device should now be available. See [https://bbs.archlinux.org/viewtopic.php?id=162688 BBS#162688] for information on making these changes persistent.
 
  
 
=== Device connects, then disconnects after a few moments ===
 
=== Device connects, then disconnects after a few moments ===
Line 418: Line 444:
 
  bluetoothd: connect error: Connection refused (111)
 
  bluetoothd: connect error: Connection refused (111)
  
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 can't 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:
+
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:
  
 
  $ bluetoothctl
 
  $ bluetoothctl
[bluetooth]# devices
+
 
Device XX:XX:XX:XX:XX:XX My Device
+
{{hc|[bluetooth]# devices|
 +
Device XX:XX:XX:XX:XX:XX My Device
 +
}}
 +
 
 
  [bluetooth]# remove XX:XX:XX:XX:XX:XX
 
  [bluetooth]# remove XX:XX:XX:XX:XX:XX
  
Line 433: Line 462:
 
  a2dp-source profile connect failed for 9C:64:40:22:E1:3F: Protocol not available
 
  a2dp-source profile connect failed for 9C:64:40:22:E1:3F: Protocol not available
  
try installing {{Pkg|pulseaudio-bluetooth}} and restarting pulseaudio. This error can manifest even while using only file transfer.
+
try installing {{Pkg|pulseaudio-bluetooth}} and restarting [[PulseAudio]]. This error can manifest even while using only file transfer.
  
 
=== Device does not show up in scan ===
 
=== 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've found to connect them is by installing {{aur|bluez-utils-compat}}, then:
+
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 {{aur|bluez-utils-compat}}, then [[start]] {{ic|bluetooth.service}} and do:
  
# systemctl start bluetooth.service
+
{{hc|# bluetoothctl|
# bluetoothctl
+
[NEW] Controller (MAC) myhostname [default]
[NEW] Controller (MAC) myhostname [default]
+
}}
[bluetooth]# power on
+
 
[CHG] Controller (MAC) Class: 0x0c010c
+
{{hc|[bluetooth]# power on|
Changing power on succeeded
+
[CHG] Controller (MAC) Class: 0x0c010c
[CHG] Controller (MAC) Powered: yes
+
Changing power on succeeded
[bluetooth]# scan on
+
[CHG] Controller (MAC) Powered: yes
Discovery started
+
}}
[CHG] Controller (MAC) Discovering: yes
+
 
 +
{{hc|[bluetooth]# scan on|
 +
Discovery started
 +
[CHG] Controller (MAC) Discovering: yes
 +
}}
  
 
In another terminal:
 
In another terminal:
Line 454: Line 487:
 
  # hcitool lescan
 
  # hcitool lescan
  
Wait until your device shows up, then Ctrl+C hcitool. bluetoothctl should now see your device and pair normally.
+
Wait until your device shows up, then {{ic|Ctrl+c}} hcitool. bluetoothctl should now see your device and pair normally.
 +
 
 +
=== Interference between Headphones and Mouse ===
 +
 
 +
If you experience audio stuttering while using a bluetooth mouse and keyboard simultaneously, you can try the following as referenced in #23 https://bugs.launchpad.net/ubuntu/+source/bluez/+bug/424215
 +
 
 +
# hciconfig hci0 lm ACCEPT,MASTER
 +
# hciconfig hci0 lp HOLD,SNIFF,PARK
 +
 
 +
=== Bluetooth mouse laggy movements ===
 +
 
 +
Try edit the file {{ic|/var/lib/bluetooth/XX:XX:XX:XX:XX:XX/YY:YY:YY:YY:YY:YY/info}} ({{ic|XX:XX:XX:XX:XX:XX}} - your Bluetooth adapter MAC-address, {{ic|YY:YY:YY:YY:YY:YY}} - your mouse MAC-address) and add those lines:
 +
 
 +
[ConnectionParameters]
 +
MinInterval=6
 +
MaxInterval=9
 +
Latency=44
 +
Timeout=216
 +
 
 +
You can see your local adapter MAC address by running command {{ic|hcitool dev}}, your can see MAC addresses of currently connected remote devices by running command {{ic|hcitool con}}
 +
 
 +
=== Adapter disappears after suspend/resume ===
 +
 
 +
First, find vendor and product ID of the adapter. For example:
 +
 
 +
{{hc|lsusb -tv|<nowiki>
 +
/:  Bus 01.Port 1: Dev 1, Class=root_hub, Driver=xhci_hcd/12p, 480M
 +
    ID 1d6b:0002 Linux Foundation 2.0 root hub
 +
    ...
 +
    |__ Port 3: Dev 3, If 0, Class=Wireless, Driver=btusb, 12M
 +
        ID 8087:0025 Intel Corp.
 +
    |__ Port 3: Dev 3, If 1, Class=Wireless, Driver=btusb, 12M
 +
        ID 8087:0025 Intel Corp.
 +
    ...
 +
</nowiki>}}
 +
 
 +
In this case, the vendor ID is 8087 and the product ID is 0025.
 +
 
 +
Then, use {{pkg|usb_modeswitch}} to reset the adapter:
 +
 
 +
# usb_modeswitch -R -v <vendor ID> -p <product ID>

Latest revision as of 07:13, 19 November 2019

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.

Installation

  1. Install the bluez package, providing the Bluetooth protocol stack.
  2. Install the bluez-utils package, providing the bluetoothctl utility. Alternatively install bluez-utils-compatAUR to additionally have the deprecated BlueZ tools.
  3. The generic Bluetooth driver is the btusb Kernel module. Check whether that module is loaded. If it's not, then load the module.
  4. Start/enable bluetooth.service.
Note:
  • 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 /usr/share/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.
http://www.bluez.org/ || bluez-utils
Tip: To automate bluetoothctl commands, use echo -e "<command1>\n<command2>\n" | bluetoothctl or bluetoothctl -- command

Graphical

The following packages allow for a graphical interface to customize Bluetooth.

  • GNOME BluetoothGNOME's Bluetooth tool.
    • gnome-bluetooth provides the back-end
    • gnome-shell provides the status monitor applet
    • gnome-control-center provides the configuration front-end GUI that can be accessed by typing Bluetooth on the Activities overview, or with the gnome-control-center bluetooth command.
    • You can also launch the bluetooth-sendto command directly to send files to a remote device.
    • nautilus-bluetoothAUR adds a "Send via Bluetooth" entry to Nautilus' right-click menu
    • To receive files, open the Bluetooth settings panel; you can only receive whilst the Bluetooth panel is open.
    • To add a Bluetooth entry to the Send To menu in Thunar's file properties menu, see instructions here. (The command that needs to be configured is bluetooth-sendto %F).
https://wiki.gnome.org/Projects/GnomeBluetooth ||
  • BluedevilKDE'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.
https://cgit.kde.org/bluedevil.git || bluedevil
  • Blueberry — Linux Mint's spin-off of GNOME Bluetooth, which works in all desktop environments. Blueberry does not support receiving files through Obex Object Push.
https://github.com/linuxmint/blueberry || blueberry
  • Blueman — A full featured Bluetooth manager.
https://github.com/blueman-project/blueman || blueman
  • ObexFTP — A tool for transferring files to/from any OBEX enabled device.
http://dev.zuckschwerdt.org/openobex/wiki/ObexFtp || obexftpAUR

Pairing

Tango-view-fullscreen.pngThis article or section needs expansion.Tango-view-fullscreen.png

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.

  1. (optional) Select a default controller with select MAC_address.
  2. 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.
  3. Enter devices to get the MAC Address of the device with which to pair.
  4. Enter device discovery mode with scan on command if device is not yet on the list.
  5. 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.
  6. Enter pair MAC_address to do the pairing (tab completion works).
  7. 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.
  8. Enter connect MAC_address to establish a connection.

An example session may look this way:

# bluetoothctl
[NEW] Controller 00:10:20:30:40:50 pi [default]
[bluetooth]# agent KeyboardOnly
Agent registered
[bluetooth]# default-agent
Default agent request successful
[bluetooth]# power on
Changing power on succeeded
[CHG] Controller 00:10:20:30:40:50 Powered: yes
[bluetooth]# scan on
Discovery started
[CHG] Controller 00:10:20:30:40:50 Discovering: yes
[NEW] Device 00:12:34:56:78:90 myLino
[CHG] Device 00:12:34:56:78:90 LegacyPairing: yes
[bluetooth]# pair 00:12:34:56:78:90
Attempting to pair with 00:12:34:56:78:90
[CHG] Device 00:12:34:56:78:90 Connected: yes
[CHG] Device 00:12:34:56:78:90 Connected: no
[CHG] Device 00:12:34:56:78:90 Connected: yes
Request PIN code
[agent] Enter PIN code: 1234
[CHG] Device 00:12:34:56:78:90 Paired: yes
Pairing successful
[CHG] Device 00:12:34:56:78:90 Connected: no
[bluetooth]# connect 00:12:34:56:78:90
Attempting to connect to 00:12:34:56:78:90
[CHG] Device 00:12:34:56:78:90 Connected: yes
Connection successful

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

Discoverable on startup

If the device should always be visible and directly connectable:

/etc/bluetooth/main.conf
[General]
DiscoverableTimeout = 0
Discoverable=true

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:

/etc/pulse/system.pa
...
load-module module-bluetooth-policy
load-module module-bluetooth-discover
...

See the Bluetooth headset page for more information about bluetooth audio and bluetooth headsets.

Bluetooth serial

To get bluetooth serial communication working on Bluetooth-to-Serial modules (HC-05, HC-06) do the following steps:

Pair your bluetooth device using bluetoothctl as described above.

Install bluez-rfcommAUR and bluez-hcitoolAUR, as they provide certain functionality which is missing from newer tools.

Bind paired device MAC address to tty terminal:

# rfcomm bind rfcomm0 <MAC address of bluetooth device>

Now you can open /dev/rfcomm0 for serial communication.

Troubleshooting

Tango-view-refresh-red.pngThis article or section is out of date.Tango-view-refresh-red.png

Reason: Replace hciconfig with newer commands. (Discuss in Talk:Bluetooth#)

Debugging

In order to debug, first stop bluetooth.service.

And then start it with the -d parameter:

# /usr/lib/bluetooth/bluetoothd -n -d

Another option is via the btmon tool.

Deprecated BlueZ tools

Eight BlueZ tools were deprecated and removed from bluez-utils, although not all of them were superseded by newer tools. The bluez-utils-compatAUR package provides an alternative version of bluez-utils with the deprecated tools.

Deprecated tool Most likely replacement
gatttool btgatt-client, D-Bus Gatt API
hciattach btattach
hciconfig btmgmt (and bluetoothctl?)
hcidump btmon (and btsnoop)
hcitool missing, D-Bus Device API available
rfcomm missing, implement with D-Bus Profile1 API?
ciptool
sdptool missing, functionality seems to be scattered over different D-Bus objects: Profile, Advertising, and the UUIDs arrays in device and adapter.

gnome-bluetooth

If you see this when trying to enable receiving files in bluetooth-properties:

Bluetooth OBEX start failed: Invalid path
Bluetooth FTP start failed: Invalid path

Then make sure that the XDG user directories exist.

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):

Feb 20 15:00:24 hostname kernel: [ 2661.349823] usb 4-1: new full-speed USB device number 3 using uhci_hcd
Feb 20 15:00:24 hostname bluetoothd[4568]: HCI dev 0 registered
Feb 20 15:00:24 hostname bluetoothd[4568]: Listening for HCI events on hci0
Feb 20 15:00:25 hostname bluetoothd[4568]: HCI dev 0 up
Feb 20 15:00:25 hostname bluetoothd[4568]: Adapter /org/bluez/4568/hci0 has been enabled

If you only get the first two lines, you may see that it found the device but you need to bring it up. Example:

# btmgmt
[mgmt]# info
Index list with 1 item
hci0:	Primary controller
	addr 00:1A:7D:DA:71:10 version 6 manufacturer 10 class 0x000000
	supported settings: powered connectable fast-connectable discoverable bondable link-security ssp br/edr hs le advertising secure-conn debug-keys privacy static-addr 
	current settings: connectable discoverable bondable ssp br/edr le secure-conn 
	name Mozart
	short name 
[mgmt]# select hci0
Selected index 0
[hci0]# power up
hci0 Set Powered complete, settings: powered connectable discoverable bondable ssp br/edr le secure-conn
[hci0]# info
hci0:	Primary controller
	addr 00:1A:7D:DA:71:10 version 6 manufacturer 10 class 0x1c0104
	supported settings: powered connectable fast-connectable discoverable bondable link-security ssp br/edr hs le advertising secure-conn debug-keys privacy static-addr 
	current settings: powered connectable discoverable bondable ssp br/edr le secure-conn

Or

# bluetoothctl
[bluetooth]# show
Controller 00:1A:7D:DA:71:10 (public)
	Name: Mozart
	Alias: Mozart
	Class: 0x0000095c
	Powered: no
	Discoverable: yes
	Pairable: yes
[bluetooth]# power on
[CHG] Controller 00:1A:7D:DA:71:10 Class: 0x001c0104
Changing power on succeeded
[CHG] Controller 00:1A:7D:DA:71:10 Powered: yes
[bluetooth]# show
Controller 00:1A:7D:DA:71:10 (public)
	Name: Mozart
	Alias: Mozart
	Class: 0x001c0104
	Powered: yes
	Discoverable: yes
	Pairable: yes

To verify that the device was detected you can use btmgmt which is part of the bluez-utils. You can get a list of available devices and their identifiers and their MAC address by issuing:

$ btmgmt info
Index list with 1 item
hci0:	Primary controller
	addr 00:1A:7D:DA:71:10 version 6 manufacturer 10 class 0x1c0104
	supported settings: powered connectable fast-connectable discoverable bondable link-security ssp br/edr hs le advertising secure-conn debug-keys privacy static-addr 
	current settings: powered connectable discoverable bondable ssp br/edr le secure-conn

It is possible to check the Bluetooth version as mapped to the HCI version according to the table in the official specification. For example, in the previous output, HCI version 6 is Bluetooth version 4.0.

More detailed information about the device can be retrieved by using the deprecated hciconfig. (bluez-utils-compatAUR)

$ hciconfig -a hci0
hci0:   Type: USB
        BD Address: 00:1B:DC:0F:DB:40 ACL MTU: 310:10 SCO MTU: 64:8
        UP RUNNING PSCAN ISCAN
        RX bytes:1226 acl:0 sco:0 events:27 errors:0
        TX bytes:351 acl:0 sco:0 commands:26 errors:0
        Features: 0xff 0xff 0x8f 0xfe 0x9b 0xf9 0x00 0x80
        Packet type: DM1 DM3 DM5 DH1 DH3 DH5 HV1 HV2 HV3
        Link policy: RSWITCH HOLD SNIFF PARK
        Link mode: SLAVE ACCEPT 
        Name: 'BlueZ (0)'
        Class: 0x000100
        Service Classes: Unspecified
        Device Class: Computer, Uncategorized
        HCI Ver: 2.0 (0x3) HCI Rev: 0xc5c LMP Ver: 2.0 (0x3) LMP Subver: 0xc5c
        Manufacturer: Cambridge Silicon Radio (10)

Audio devices start to skip at short distance from dongle

If other devices share the same USB host, they can interrupt communication with audio devices. Make sure it is the only device attached to its bus. For example:

$ lsusb
Bus 002 Device 002: ID 0a12:0001 Cambridge Silicon Radio, Ltd Bluetooth Dongle (HCI mode)
Bus 002 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
Bus 001 Device 004: ID 048d:1345 Integrated Technology Express, Inc. Multi Cardreader
Bus 001 Device 003: ID 0424:a700 Standard Microsystems Corp. 2 Port Hub
Bus 001 Device 002: ID 8087:0024 Intel Corp. Integrated Rate Matching Hub
Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub

CSR Dongle 0a12:0001

The device ID 0a12:0001 Cambridge Silicon Radio, Ltd Bluetooth Dongle (HCI mode) has a regression bug, and currently only works in the kernel version ≤ 3.9.11. There is a patch available for newer versions. For more information, see Kernel Bug 60824.

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 laptops (e.g. Dell Studio 15, Lenovo Thinkpad X1) 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.
  • Sometimes also this simple command helps:
# bluetoothctl power on

rfkill unblock: Do not unblock

If your device still soft blocked and you run connman, try this:

$ connmanctl enable bluetooth

My computer is not visible

Cannot discover computer from your phone? Enable discoverable mode:

# bluetoothctl discoverable on

to check if it worked:

# bluetoothctl show
	Powered: yes
	Discoverable: yes
	Pairable: yes
Note: Check DiscoverableTimeout and PairableTimeout in /etc/bluetooth/main.conf

If even so it does not show up, try changing the device class in /etc/bluetooth/main.conf as following:

# Default device class. Only the major and minor device class bits are
# considered.
#Class = 0x000100 (from default config)
Class = 0x100100

A user reported that this was the only solution to make his computer visible for his phone.

Logitech keyboard does not pair

If you do not get the passkey when you try to pair your Logitech keyboard, type the following command:

# btmgmt ssp off

If after pairing, the keyboard still does not connect, check the output of hcidump -at. If the latter indicates repeatedly connections-disconnections like the following message:

   status 0x00 handle 11 reason 0x13
   Reason: Remote User Terminated Connection

then, the only solution for now is to install the old Bluetooth stack.

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:

   ...
   Bus 002 Device 004: ID 04ca:2006 Lite-On Technology Corp. Broadcom BCM43142A0 Bluetooth Device
   ...

or

   Bus 004 Device 004: Id 0489:e031 Foxconn / Hon Hai

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

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

Intel combined wifi and bluetooth cards

See Wireless network configuration#Bluetooth coexistence.

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:

bluetoothd: Unable to get connect data for Headset Voice gateway: getpeername: Transport endpoint is not connected (107)
bluetoothd: connect error: Connection refused (111)

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:

$ bluetoothctl
[bluetooth]# devices
Device XX:XX:XX:XX:XX:XX My Device
[bluetooth]# remove XX:XX:XX:XX:XX:XX

Then restart bluetooth.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

try installing pulseaudio-bluetooth and restarting PulseAudio. This error can manifest even while using only file transfer.

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 start bluetooth.service and do:

# bluetoothctl
[NEW] Controller (MAC) myhostname [default]
[bluetooth]# power on
[CHG] Controller (MAC) Class: 0x0c010c
Changing power on succeeded
[CHG] Controller (MAC) Powered: yes
[bluetooth]# scan on
Discovery started
[CHG] Controller (MAC) Discovering: yes

In another terminal:

# hcitool lescan

Wait until your device shows up, then Ctrl+c hcitool. bluetoothctl should now see your device and pair normally.

Interference between Headphones and Mouse

If you experience audio stuttering while using a bluetooth mouse and keyboard simultaneously, you can try the following as referenced in #23 https://bugs.launchpad.net/ubuntu/+source/bluez/+bug/424215

# hciconfig hci0 lm ACCEPT,MASTER
# hciconfig hci0 lp HOLD,SNIFF,PARK

Bluetooth mouse laggy movements

Try edit the file /var/lib/bluetooth/XX:XX:XX:XX:XX:XX/YY:YY:YY:YY:YY:YY/info (XX:XX:XX:XX:XX:XX - your Bluetooth adapter MAC-address, YY:YY:YY:YY:YY:YY - your mouse MAC-address) and add those lines:

[ConnectionParameters]
MinInterval=6
MaxInterval=9
Latency=44
Timeout=216

You can see your local adapter MAC address by running command hcitool dev, your can see MAC addresses of currently connected remote devices by running command hcitool con

Adapter disappears after suspend/resume

First, find vendor and product ID of the adapter. For example:

lsusb -tv
/:  Bus 01.Port 1: Dev 1, Class=root_hub, Driver=xhci_hcd/12p, 480M
    ID 1d6b:0002 Linux Foundation 2.0 root hub
    ...
    |__ Port 3: Dev 3, If 0, Class=Wireless, Driver=btusb, 12M
        ID 8087:0025 Intel Corp. 
    |__ Port 3: Dev 3, If 1, Class=Wireless, Driver=btusb, 12M
        ID 8087:0025 Intel Corp. 
    ...

In this case, the vendor ID is 8087 and the product ID is 0025.

Then, use usb_modeswitch to reset the adapter:

# usb_modeswitch -R -v <vendor ID> -p <product ID>