Bluetooth: Difference between revisions

From ArchWiki
(→‎PulseAudio: add a reference about the default config)
 
(57 intermediate revisions by 27 users not shown)
Line 12: Line 12:
{{Related|ObexFTP}}
{{Related|ObexFTP}}
{{Related articles end}}
{{Related articles end}}
[[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].
[[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 [https://www.bluez.org/ BlueZ].


== Installation ==
== Installation ==


# [[Install]] the {{Pkg|bluez}} package, providing the Bluetooth protocol stack.
# [[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]].
# [[Install]] the {{Pkg|bluez-utils}} package, providing the {{ic|bluetoothctl}} utility. Alternatively install {{Pkg|bluez-deprecated-tools}} to additionally have the [[#Deprecated BlueZ tools|deprecated BlueZ tools]].
# The generic Bluetooth driver is the {{ic|btusb}} kernel module. [[Kernel module#Obtaining information|Check]] whether that module is loaded. If it is not, then [[Kernel module#Manual module handling|load the module]].
# The generic Bluetooth driver is the {{ic|btusb}} kernel module. [[Kernel module#Obtaining information|Check]] whether that module is loaded. If it is not, then [[Kernel module#Manual module handling|load the module]].
# [[Start/enable]] {{ic|bluetooth.service}}.
# [[Start/enable]] {{ic|bluetooth.service}}.
Line 23: Line 23:
{{Note|
{{Note|
* 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}}.
* 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. [https://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. [https://www.intel.com/content/www/us/en/wireless-products/centrino-advanced-n-6235.html Intel Centrino]{{Dead link|2023|09|16|status=404}}). 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 gets 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 gets 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://lore.kernel.org/linux-bluetooth/20170104133401.3636-1-luiz.dentz@gmail.com/ 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 {{Pkg|bluez-deprecated-tools}}. See {{Bug|53110}} and [https://lore.kernel.org/linux-bluetooth/20170104133401.3636-1-luiz.dentz@gmail.com/ the Bluez mailing list] for more information.
* Since [https://gitlab.archlinux.org/archlinux/packaging/packages/bluez/-/commit/3dc43f553660cf4409532b8b0b3c2dc9c6e4f1a9 this] commit, {{Pkg|bluez-obex}} and {{Pkg|bluez-mesh}} have been separated from {{Pkg|bluez}}. Therefore, if you plan to transfer files over Bluetooth, {{Pkg|bluez-obex}} needs to be installed.}}


=== Front-ends ===
=== Front-ends ===
Line 31: Line 32:
==== Console ====
==== Console ====


* {{App|bluetoothctl|Pairing a device from the shell is one of the simplest and most reliable options.|http://www.bluez.org/|{{Pkg|bluez-utils}}}}
* {{App|bluetoothctl|Pairing a device from the shell is one of the simplest and most reliable options.|https://www.bluez.org/|{{Pkg|bluez-utils}}}}
* {{App|bluetuith|Provides a bluetooth manager via a Terminal User Interface for easier pairing and device/adapter management, with OBEX File Transfer and mouse support.|https://www.github.com/darkhz/bluetuith|{{AUR|bluetuith}}}}
* {{App|bluetuith|Provides a bluetooth manager via a Terminal User Interface for easier pairing and device/adapter management, with OBEX File Transfer and mouse support.|https://www.github.com/darkhz/bluetuith|{{AUR|bluetuith}}}}


Line 53: Line 54:
* {{App|[[Blueman]]|A full featured Bluetooth manager.|https://github.com/blueman-project/blueman|{{Pkg|blueman}}}}
* {{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}}}}
* {{App|[[ObexFTP]]|A tool for transferring files to/from any OBEX enabled device.|http://dev.zuckschwerdt.org/openobex/wiki/ObexFtp|{{AUR|obexftp}}}}
* {{App|Overskride|A simple yet powerful bluetooth client.|https://github.com/kaii-lb/overskride#overskride|{{AUR|overskride}}}}


== Pairing ==
== Pairing ==
Line 130: Line 132:
The registry key containing the link keys may only be accessed by the [https://docs.microsoft.com/en-us/windows/security/identity-protection/access-control/local-accounts#system SYSTEM account], which cannot be logged into. Therefore, you will need Microsoft's [https://docs.microsoft.com/en-us/sysinternals/downloads/psexec PsExec] tool from the official Windows Sysinternals site in order to run {{ic|regedit.exe}} as {{ic|SYSTEM}}.
The registry key containing the link keys may only be accessed by the [https://docs.microsoft.com/en-us/windows/security/identity-protection/access-control/local-accounts#system SYSTEM account], which cannot be logged into. Therefore, you will need Microsoft's [https://docs.microsoft.com/en-us/sysinternals/downloads/psexec PsExec] tool from the official Windows Sysinternals site in order to run {{ic|regedit.exe}} as {{ic|SYSTEM}}.


Download [https://download.sysinternals.com/files/PSTools.zip PsTools], and extract {{ic|PsExe64.exe}}.
Download [https://download.sysinternals.com/files/PSTools.zip PsTools], and extract {{ic|PsExec64.exe}}.


In an administrator instance of a [https://docs.microsoft.com/en-us/windows-server/administration/windows-commands/windows-commands#command-shell-overview command shell], from the location of the extracted EXE, launch the registry editor:
In an administrator instance of a [https://docs.microsoft.com/en-us/windows-server/administration/windows-commands/windows-commands#command-shell-overview command shell], from the location of the extracted EXE, launch the registry editor:
Line 138: Line 140:
  HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\BTHPORT\Parameters\Keys
  HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\BTHPORT\Parameters\Keys


Within this key is a key for each Bluetooth adapter, by MAC address. If there are multiple keys, and you are unsure of which to use, follow [https://www.addictivetips.com/windows-tips/find-bluetooth-mac-address-windows-10/ this guide] to find the MAC address for the desired Bluetooth adapter.
Within this registry key is one subkey per Bluetooth adapter, named by MAC address. If there are multiple subkeys, and you are unsure of which to use, follow [https://www.addictivetips.com/windows-tips/find-bluetooth-mac-address-windows-10/ this guide] to find the MAC address for the desired Bluetooth adapter.


Within the desired device adapter key, there is a binary value for each paired device, by MAC address in the same way.
In the desired adapter's registry key, there is a name-value pair for each paired device, with the name being its MAC address. Additionally, you might see some subkeys named by MAC addresses, each containing name-value pairs with names like {{ic|LTK}} or {{ic|IRK}}. These subkeys (if any) are for Bluetooth 5.1 devices. If the device you're trying to share has a subkey, it is a Bluetooth 5.1 device. If it does not have a subkey, only a name-value pair, it is not a Bluetooth 5.1 device.


For each paired device that you wish to share between the installations, right click on the whole key and export it as a ''.reg'' file. This is a text file that you can copy the keys from.
Right click on the adapter's registry key and export it as a ''.reg'' file. This is a text file that you can copy keys from. As mentioned, it contains pairing keys in name-value pairs for non-Bluetooth 5.1 devices, and pairing keys (and some other information) in per-device subkeys for Bluetooth 5.1 devices. Make this file available to your Linux installation and reboot into it.


Within this file, if there is a single binary key, then this is ''not'' a Bluetooth 5.1 device, and that paring key is all that is needed.
If the device you want to share is ''not'' a Bluetooth 5.1 device, jump to [[#Finishing up]]. If it is a Bluetooth 5.1 device, you need to make some modifications to the pairing keys and the associated information before finishing up. Refer to [[#Preparing Bluetooth 5.1 Keys]] to see how.
 
Otherwise, if there are several keys for the paired device such as {{ic|LTK}} or {{ic|IRK}}, then this ''is'' a BT5.1 device. Refer to [[#Preparing Bluetooth 5.1 Keys]] to see how to use them.
 
Finally, to import the key(s) into your Linux installation, reboot into Linux and proceed to [[#Finishing up]].


===== Extracting on Linux =====
===== Extracting on Linux =====
Line 224: Line 222:
{{Note|The reversal can be done with the following [[Python]] code:
{{Note|The reversal can be done with the following [[Python]] code:
{{bc|1=
{{bc|1=
>>> Key="98 54 2f aa bb cc dd ee ff gg hh ii jj kk ll mm}"
>>> key = "98 54 2f aa bb cc dd ee ff gg hh ii jj kk ll mm"
>>> Key=list(reversed(ERand.strip().split()))
>>> " ".join(reversed(key.strip().split()))
}}
}}
}}
}}
Line 242: Line 240:
! Device !! Source Key and Transformations (Windows) !! Source Key and Transformations (macOS) || Destination Key File
! Device !! Source Key and Transformations (Windows) !! Source Key and Transformations (macOS) || Destination Key File
|-
|-
|rowspan="3"|Logitech MX Master 3
|rowspan="3"|
* Logitech MX Master 3
* Logitech MX Master 3S
* Logitech MX Keys
* Logitech MX Mechanical
* Xbox One S Wireless Controller
|
|
* Copy {{ic|IRK}}.
* Copy {{ic|IRK}}.
Line 259: Line 262:
| {{-}}
| {{-}}
|-
|-
|rowspan="4"|ThinkPad TrackPoint Keyboard II, Pebble M350 mouse, Logitech G604 Lightspeed mouse
|rowspan="6"|
* Logitech MX Anywhere 2S
|
* Copy {{ic|IRK}}.
* Remove the spaces between the hex octets.
| {{Grey|?}}
| {{ic|IdentityResolvingKey.Key}}
|-
|
* Copy {{ic|CSRK}}.
* Remove the spaces between the hex octets.
| {{Grey|?}}
| {{ic|LocalSignatureKey.Key}}
|-
|
* Copy {{ic|LTK}}.
* Remove the spaces between the hex octets.
| {{Grey|?}}
| {{ic|LongTermKey.Key}}
|-
|
* Copy {{ic|KeyLength}}.
* Convert the whole number to decimal.
| {{Grey|?}}
| {{ic|LongTermKey.EncSize}}
|-
|
* Copy {{ic|EDIV}}.
* Convert the whole number to decimal.
| {{Grey|?}}
| {{ic|LongTermKey.EDiv}}
|-
|
* Copy {{ic|ERand}}.
* Reverse the order of the octets.
* Convert the whole number to decimal.
| {{Grey|?}}
| {{ic|LongTermKey.Rand}}
|-
|rowspan="4"|
* ThinkPad TrackPoint Keyboard II
* Pebble M350 mouse
* Logitech G604 Lightspeed mouse
|
|
* Copy {{ic|IRK}}.
* Copy {{ic|IRK}}.
Line 269: Line 314:
|-
|-
|
|
* Copy {{ic|LTK}}. Remove the spaces between the hexadecimal octets.
* Copy {{ic|LTK}}.
* Remove the spaces between the hexadecimal octets.
|
|
* Copy ''Remote Encryption'' > ''Long-term Key''.
* Copy ''Remote Encryption'' > ''Long-term Key''.
Line 281: Line 327:
|
|
* Copy ''Remote Encryption'' > ''Random Number''.
* Copy ''Remote Encryption'' > ''Random Number''.
* Convert from base64 to hex.
* Convert from base64 to a little-endian decimal number (see Python code below).
* Reverse the order of the octets.
| {{ic|LongTermKey.Rand}}
| {{ic|LongTermKey.Rand}}
|-
|-
Line 291: Line 336:
|
|
* Copy ''Remote Encryption'' > ''Encrypted Diversifier''.
* Copy ''Remote Encryption'' > ''Encrypted Diversifier''.
* Convert from base64 to hex.
* Convert from base64 to a little-endian decimal number (see Python code below).
* Reverse the order of the octets.
| {{ic|LongTermKey.EDiv}}
| {{ic|LongTermKey.EDiv}}
|-
|-
Line 321: Line 365:
* Reverse the order of the octets.
* Reverse the order of the octets.
| {{ic|LongTermKey.EDiv}}
| {{ic|LongTermKey.EDiv}}
|-
|rowspan="1"|Xbox wireless controller
|
* Copy {{ic|LTK}}.
* Remove the spaces between the hex octets.
| {{Grey|?}}
| {{ic|SlaveLongTermKey.Key}}
|}
|}


Line 341: Line 392:
  struct.unpack('<H', base64.decodebytes(b'...'))
  struct.unpack('<H', base64.decodebytes(b'...'))
* This Python code does the full macOS Random Number conversion:
* This Python code does the full macOS Random Number conversion:
  struct.unpack('<H', base64.decodebytes(b'...'))
  struct.unpack('&lt;Q', base64.decodebytes(b'...'))
}}
}}


Line 350: Line 401:


==== Finishing up ====
==== Finishing up ====
{{Style|Informal section title.}}


Now that you have the keys change user to root, then continue with:
Now that you have the keys change user to root, then continue with:
Line 370: Line 423:
{{Note|You will have to make sure that all the letters are in capital case. Remove any spaces.}}
{{Note|You will have to make sure that all the letters are in capital case. Remove any spaces.}}


If you have Bluetooth 5.1 keys, then you must instead copy the key files to the MAC address directory.
If you have several keys, as in Bluetooth 5.1, edit the {{ic|info}} file and substitute all applicable keys with their recorded values. E.g. for an Xbox One S Wireless Controller:
 
{{hc|1=info|2=
[IdentityResolvingKey]
Key=<IdentityResolvingKey.Key>
 
[PeripheralLongTermKey]
Key=<PeripheralLongTermKey.Key>
 
[SlaveLongTermKey]
Key=<SlaveLongTermKey.Key>
}}


Then [[restart]] {{ic|bluetooth.service}} and {{ic|pulseaudio}} (with {{ic|pulseaudio -k && pulseaudio --start}}).
Then [[restart]] {{ic|bluetooth.service}} and {{ic|pulseaudio}} (with {{ic|pulseaudio -k && pulseaudio --start}}).
Line 435: Line 499:
=== Enabling experimental features ===
=== Enabling experimental features ===


The Bluez stack keeps new, potentially buggy features behind the D-Bus experimental and kernel experimental options. The functionality included under these varies over time, as experimental features are determined to be stable and no longer require the option. To enable these, uncomment the corresponding line in the configuration:
The Bluez stack keeps new, potentially buggy features behind the D-Bus experimental and kernel experimental options. The functionality included under these varies over time, as experimental features are determined to be stable and no longer require the option (as an example: enabling D-Bus experimental interfaces currently allows to report battery level for old headsets). To enable these, uncomment the corresponding line in the configuration:


{{hc|/etc/bluetooth/main.conf|2=
{{hc|/etc/bluetooth/main.conf|2=
Line 518: Line 582:
'''Pair''' your Bluetooth device using {{ic|bluetoothctl}} as described [[#Pairing|above]].
'''Pair''' your Bluetooth device using {{ic|bluetoothctl}} as described [[#Pairing|above]].


Install {{AUR|bluez-utils-compat}}, as it provides certain functionality which is missing from newer tools.
Install {{Pkg|bluez-deprecated-tools}}, as it provides certain functionality which is missing from newer tools.


Bind paired device MAC address to tty terminal:
Bind paired device MAC address to tty terminal:
Line 532: Line 596:
{{Out of date|Replace hciconfig with newer commands.}}
{{Out of date|Replace hciconfig with newer commands.}}


=== Debugging ===
=== General Troubleshooting ===
 
==== Debugging ====


In order to debug, first [[stop]] {{ic|bluetooth.service}}.
In order to debug, first [[stop]] {{ic|bluetooth.service}}.
Line 542: Line 608:
Another option is via the {{ic|btmon}} tool.
Another option is via the {{ic|btmon}} tool.


=== Deprecated BlueZ tools ===
==== Deprecated BlueZ tools ====


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.
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 {{Pkg|bluez-deprecated-tools}} package provides an alternative version of {{Pkg|bluez-utils}} with the deprecated tools.


{| class="wikitable"
{| class="wikitable"
Line 551: Line 617:
! Most likely replacement
! Most likely replacement
|-
|-
| [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]
| [https://manpages.debian.org/latest/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]{{Dead link|2023|10|29|status=404}}
|-
|-
| [https://manpages.debian.org/stretch/bluez/hciattach.1.en.html hciattach] || btattach
| [https://manpages.debian.org/latest/bluez/hciattach.1.en.html hciattach] || btattach
|-
|-
| [https://manpages.debian.org/stretch/bluez/hciconfig.1.en.html hciconfig] || btmgmt (and bluetoothctl?)
| [https://manpages.debian.org/latest/bluez/hciconfig.1.en.html hciconfig] || btmgmt (and bluetoothctl?)
|-
|-
| [https://manpages.debian.org/stretch/bluez-hcidump/hcidump.1.en.html hcidump] || btmon (and btsnoop)
| [https://manpages.debian.org/latest/bluez-hcidump/hcidump.1.en.html hcidump] || btmon (and btsnoop)
|-
|-
| [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
| [https://manpages.debian.org/latest/bluez/hcitool.1.en.html hcitool] || missing, [https://git.kernel.org/cgit/bluetooth/bluez.git/tree/doc/device-api.txt D-Bus Device API]{{Dead link|2023|10|29|status=404}} available
|-
|-
| [https://manpages.debian.org/stretch/bluez/rfcomm.1.en.html rfcomm]
| [https://manpages.debian.org/latest/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]{{Dead link|2023|10|29|status=404}}?
|-
|-
| [https://manpages.debian.org/stretch/bluez/ciptool.1.en.html ciptool]
| [https://manpages.debian.org/latest/bluez/ciptool.1.en.html ciptool]
|-
|-
|[https://manpages.debian.org/stretch/bluez/sdptool.1.en.html sdptool]
|[https://manpages.debian.org/latest/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]{{Dead link|2023|10|29|status=404}}, [https://git.kernel.org/cgit/bluetooth/bluez.git/tree/doc/advertising-api.txt Advertising]{{Dead link|2023|10|29|status=404}}, and the UUIDs arrays in [https://git.kernel.org/cgit/bluetooth/bluez.git/tree/doc/device-api.txt device]{{Dead link|2023|10|29|status=404}} and [https://git.kernel.org/cgit/bluetooth/bluez.git/tree/doc/adapter-api.txt adapter]{{Dead link|2023|10|29|status=404}}.  
|}
|}


=== gnome-bluetooth ===
=== Service issues ===
 
==== systemd: Condition check resulted in Bluetooth service being skipped ====
 
{{ic|bluetooth.service}} only requires the directory {{ic|/sys/class/bluetooth}} to exist, which should be created by kernel module {{ic|bluetooth}}, which is only autoloaded by {{ic|systemd-udev}} if it actually finds a working Bluetooth hardware device.
 
If your {{ic|/sys/class/bluetooth}} does not exist, check if your kernel Bluetooth module is loaded by {{ic|lsmod}}. If not, and you believe you have a Bluetooth device, you can try manually starting them by [[Kernel module#Manual module handling|loading the Bluetooth module]] and [[restart]]ing {{ic|bluetooth.service}}.
 
You should also load your corresponding kernel Bluetooth driver when loading the {{ic|bluetooth}} module, most likely {{ic|btusb}}, but can also be {{ic|btrtl,btintel,btbcm,bnep,btusb}} etc.
 
Check {{ic|bluetooth.service}}'s [[unit status]] to see whether it started.
 
See also [https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=853207 Debian Bug report logs - #853207].
 
If {{ic|bluetooth.service}} started successfully, there is a chance that you still cannot use Bluetooth normally (e.g. {{ic|bluetoothctl}} says something like {{ic|org.Bluez.Error.NotReady}} when you {{ic|scan on}}). If this happens, try rebooting your computer, and double-check: whether directory {{ic|/sys/class/bluetooth}} exists; whether {{ic|lsmod}} includes correct Bluetooth modules; log messages in the [[journal]]; etc. {{ic|systemd-udev}} should pickup your Bluetooth hardware automatically without manual changes again.
 
==== Bluetooth immediately waking up suspend-to-idle devices ====
 
On systems capable of [[Power management/Suspend and hibernate|suspend-to-idle/S2idle/S0ix/Modern Standby]], Bluetooth controllers will stay enabled during sleep. This will usually cause the system to [https://bugzilla.kernel.org/show_bug.cgi?id=200039 wake up immediately after going to sleep] if any Bluetooth device is connected.
 
To prevent this, you can disable Bluetooth completely before going to sleep - install {{Pkg|bluez-utils}} and create this file:
 
{{hc|/etc/systemd/system/bluetooth-disable-before-sleep.service|2=
[Unit]
Description=Disable Bluetooth before going to sleep
Before=sleep.target
Before=suspend.target
Before=hybrid-sleep.target
Before=suspend-then-hibernate.target
StopWhenUnneeded=yes
 
[Service]
Type=oneshot
RemainAfterExit=yes
 
ExecStart=/usr/bin/bluetoothctl power off
ExecStop=/usr/bin/bluetoothctl power on
 
[Install]
WantedBy=sleep.target
WantedBy=suspend.target
WantedBy=hybrid-sleep.target
WantedBy=suspend-then-hibernate.target
}}
 
[[Enable]] this service and check if Bluetooth devices disconnect when going to sleep, and whenever Bluetooth goes back up after waking up the system.


If you see this when trying to enable receiving files in bluetooth-properties:
If this workaround is in use, [[#Wake from suspend|waking up the system with a Bluetooth mouse/keyboard]] will not work.
 
==== Bluetooth turns off after logout on a headless/server system ====
 
This can have various causes:
 
* Both [[PulseAudio]] and [[PipeWire]] run as user services by default, which are terminated once the last session ends. Enable [[Systemd/User#Automatic start-up of systemd user instances|lingering]] for the user to fix this.
* Additionally, when running [[WirePlumber]] with [[PipeWire]] (which is usually the case), WirePlumber runs a "logind-monitor" which enables Bluetooth on login and disables it on logout. See [[WirePlumber#Keep Bluetooth running after logout / Headless Bluetooth]] for a fix.
 
=== Adapter issues ===
 
==== 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 {{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
 
* 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
 
==== bluetoothctl: No default controller available ====
 
There is a bug with some motherboard bluetooth controllers. To see if this might be the issue, run {{ic|journalctl {{!}} grep hci}}. If there are entries like "command tx timeout" or "Reading Intel version command failed", then power off your pc and physically unplug the power cable for a few seconds. This forces the controller to reload the firmware (while a standard reboot will not). See bug report [https://bugs.launchpad.net/ubuntu/+source/linux/+bug/1859592 here].
 
Make sure the device is not being blocked by [[rfkill]].
 
If using [[USBGuard]], make sure it does not block the device. See [[USBGuard#Allow Bluetooth controllers]].
 
It might also happen with some intel cards (such as the 8260) to not be picked up correctly by the Bluetooth service. In some cases, using the deprecated {{Pkg|bluez-deprecated-tools}} in lieu of {{Pkg|bluez-utils}} have reportedly fixed the issue.
 
This might also be caused by power saving measures, in which case adding the [[Kernel parameters#Configuration|kernel parameter]] {{ic|1=btusb.enable_autosuspend=n}} is a potential solution. See also [https://bugzilla.redhat.com/show_bug.cgi?id=1573562 Red Hat Bugzilla – Bug 1573562].
 
Sometimes unloading and loading {{ic|btusb}} without options helps to get the controller back:
 
# modprobe -r btusb
# modprobe btusb
 
It may also occur when the dongle is a [[#CSR dongle 0a12:0001|CSR clone]].
 
==== rfkill unblock: Do not unblock ====


Bluetooth OBEX start failed: Invalid path
If your device still soft blocked and you run [[ConnMan]], try this:
Bluetooth FTP start failed: Invalid path


Then make sure that the [[XDG user directories]] exist.
$ connmanctl enable bluetooth


=== Bluetooth USB dongle ===
==== 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 {{ic|journalctl -f}} as root when you have plugged in the USB dongle (or inspecting {{ic|/var/log/messages.log}}). It should look something like the following (look out for hci):
If you are using a USB dongle, you should check that your Bluetooth dongle is recognized. You can do that by running {{ic|journalctl -f}} as root when you have plugged in the USB dongle (or inspecting {{ic|/var/log/messages.log}}). It should look something like the following (look out for hci):
Line 656: Line 808:
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.
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}})
More detailed information about the device can be retrieved by using the deprecated {{ic|hciconfig}}. ({{Pkg|bluez-deprecated-tools}})


{{hc|$ hciconfig -a hci0|
{{hc|$ hciconfig -a hci0|
Line 676: Line 828:
}}
}}


==== Audio devices start to skip at short distance from dongle ====
===== Audio devices start to skip at short distance from dongle =====


If other devices share the same USB host, they can [https://bbs.archlinux.org/viewtopic.php?pid=1440161#p1440161 interrupt communication with audio devices]. Make sure it is the only device attached to its bus. For example:
If other devices share the same USB host, they can [https://bbs.archlinux.org/viewtopic.php?pid=1440161#p1440161 interrupt communication with audio devices]. Make sure it is the only device attached to its bus. For example:
Line 689: Line 841:
}}
}}


==== CSR dongle 0a12:0001 ====
===== 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 5.17 and < 6.0. For more information, see [https://bugzilla.kernel.org/show_bug.cgi?id=60824 Kernel Bug 60824].
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 5.17 and < 6.0. For more information, see [https://bugzilla.kernel.org/show_bug.cgi?id=60824 Kernel Bug 60824].


=== Logitech Bluetooth USB dongle ===
==== 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.
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.
Line 701: Line 853:
Alternatively, you can install the {{Pkg|bluez-hid2hci}} package. When you connect your Logitech dongle it will automatically switch.
Alternatively, you can install the {{Pkg|bluez-hid2hci}} package. When you connect your Logitech dongle it will automatically switch.


=== hcitool scan: Device not found ===
==== Foxconn / Hon Hai / Lite-On Broadcom device ====
 
Some of these devices require the firmware to be flashed into the device at boot.


* 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:
Some firmware is available when searching for [https://aur.archlinux.org/packages?K=broadcom broadcom] on the [[AUR]], a notable package being {{AUR|broadcom-bt-firmware}}, which provides the files for [https://github.com/winterheart/broadcom-bt-firmware/blob/master/DEVICES.md multiple cards].
 
Alternatively, the firmware can be converted from a Microsoft Windows ''.hex'' file into a ''.hcd'' using [https://github.com/jessesung/hex2hcd hex2hcd] (which is installed with {{Pkg|bluez-utils}}).


# /usr/lib/udev/hid2hci
In order to get the right ''.hex'' file, try searching the device vendor:product code obtained with ''lsusb'', for example:


* 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.
Bus 002 Device 004: ID '''04ca:2006''' Lite-On Technology Corp. Broadcom BCM43142A0 Bluetooth Device


* Sometimes also this simple command helps:
or


  # bluetoothctl power on
  Bus 004 Device 004: Id '''0489:e031''' Foxconn / Hon Hai


=== bluetoothctl: No default controller available ===
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 {{ic|iProduct}}.


There is a bug with some motherboard bluetooth controllers. To see if this might be the issue, run {{ic|journalctl {{!}} grep hci}}. If there are entries like "command tx timeout" or "Reading Intel version command failed", then power off your pc and physically unplug the power cable for a few seconds. This forces the controller to reload the firmware (while a standard reboot will not). See bug report [https://bugs.launchpad.net/ubuntu/+source/linux/+bug/1859592 here].
The ''.hex'' file can be extracted from the downloaded Windows driver without having to run Windows for it. Download the right driver, for example [http://www.fujitsupc.com/downloads/mobile/BLUETOOTH_WIDCOMM_V6.5.0.3100_WIN7-32_FPC46-1771-01.EXE Bluetooth Widcomm]{{Dead link|2023|09|16|status=domain name not resolved}}. Depending on the format, extracting the files might need {{Pkg|unrar}} or {{Pkg|cabextract}}. To find out which of the many ''.hex'' files is the right one for you, look in the file {{ic|Win32/bcbtums-win7x86-brcm.inf}} and search for {{ic|[RAMUSB'''E031'''.CopyList]}}, where {{ic|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.


Make sure the device is not being blocked by [[rfkill]].
Once you have the ''.hcd'' file, copy it into {{ic|/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:


It might also happen with some intel cards (such as the 8260) to not be picked up correctly by the Bluetooth service. In some cases, using the deprecated {{AUR|bluez-utils-compat}} in lieu of {{Pkg|bluez-utils}} have reportedly fixed the issue.
# rmmod btusb
# modprobe btusb


This might also be caused by power saving measures, in which case adding the [[Kernel parameters#Configuration|kernel parameter]] {{ic|1=btusb.enable_autosuspend=n}} is a potential solution. See also [https://bugzilla.redhat.com/show_bug.cgi?id=1573562 Red Hat Bugzilla – Bug 1573562].
The device should now be available. See [https://bbs.archlinux.org/viewtopic.php?id=162688 BBS#162688] for information on making these changes persistent.


Sometimes unloading and loading {{ic|btusb}} without options helps to get the controller back:
==== Intel combined WiFi and Bluetooth cards ====


# modprobe -r btusb
See [[Wireless network configuration#Bluetooth coexistence]].
# modprobe btusb


It may occur also when the dongle is a [[#CSR dongle 0a12:0001|CSR clone]]
==== Mediatek MT7921 or MT7961 on dual boot with windows ====


=== systemd: Condition check resulted in Bluetooth service being skipped ===
On dual boot systems, if Bluetooth firmware versions are different for Windows and Linux, the Bluetooth adapter is not working after rebooting to Windows.


{{ic|bluetooth.service}} only requires the directory {{ic|/sys/class/bluetooth}} to exist, which should be created by kernel module {{ic|bluetooth}}, which is only autoloaded by {{ic|systemd-udev}} if it actually finds a working Bluetooth hardware device.  
The best way to prevent this is updating the Bluetooth drivers (especially firmware) with latest version for each OS.  


If your {{ic|/sys/class/bluetooth}} does not exist, check if your kernel Bluetooth module is loaded by {{ic|lsmod}}. If not, and you believe you have a Bluetooth device, you can try manually starting them by [[Kernel module#Manual module handling|loading the Bluetooth module]] and [[restart]]ing {{ic|bluetooth.service}}.
If you cannot find the latest version driver (or firmware) for Windows, you can copy the latest firmware file {{ic|/usr/lib/firmware/mediatek/BT_RAM_CODE_MT7961_1_2_hdr.bin.xz}} from Arch Linux and extract to Windows (e.g. {{ic|C:\WINDOWS\system32\DRIVERS\}}, you can find the firmware file path in the device manager on Windows).


You should also load your corresponding kernel Bluetooth driver when loading the {{ic|bluetooth}} module, most likely {{ic|btusb}}, but can also be {{ic|btrtl,btintel,btbcm,bnep,btusb}} etc.
==== Adapter disappears after suspend/resume ====


Check {{ic|bluetooth.service}}'s [[unit status]] to see whether it started.
First, find vendor and product ID of the adapter. For example:


See also [https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=853207 Debian Bug report logs - #853207].
{{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>}}


If {{ic|bluetooth.service}} started successfully, but there is chance that you still cannot use Bluetooth normally (e.g. {{ic|bluetoothctl}} says something like {{ic|org.Bluez.Error.NotReady}} when you {{ic|scan on}}). If this happens, try rebooting your computer, and double-check: whether directory {{ic|/sys/class/bluetooth}} exists; whether {{ic|lsmod}} includes correct Bluetooth modules; log messages in the [[journal]]; etc. {{ic|systemd-udev}} should pickup your Bluetooth hardware automatically without manual changes again.
In this case, the vendor ID is 8087 and the product ID is 0025.


=== rfkill unblock: Do not unblock ===
Then, use {{pkg|usb_modeswitch}} to reset the adapter:


If your device still soft blocked and you run [[ConnMan]], try this:
# usb_modeswitch -R -v ''vendor_ID'' -p ''product_ID''


$ connmanctl enable bluetooth
=== Pairing and connectivity issues ===


=== Computer is not visible ===
==== Computer is not visible ====


Enable discoverable mode if your computer cannot be discovered from your phone:
Enable discoverable mode if your computer cannot be discovered from your phone:
Line 779: Line 944:
See https://bluetooth-pentest.narod.ru/software/bluetooth_class_of_device-service_generator.html to generate Bluetooth device/service classes.
See https://bluetooth-pentest.narod.ru/software/bluetooth_class_of_device-service_generator.html to generate Bluetooth device/service classes.


=== Foxconn / Hon Hai / Lite-On Broadcom device ===
==== Device connects, then disconnects after a few moments ====
 
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 [https://github.com/jessesung/hex2hcd hex2hcd] (which is installed with {{Pkg|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 {{ic|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 [http://www.fujitsupc.com/downloads/mobile/BLUETOOTH_WIDCOMM_V6.5.0.3100_WIN7-32_FPC46-1771-01.EXE Bluetooth Widcomm] (listed among the drivers for [http://support.fujitsupc.com/CS/Portal/supportsearch.do?srch=DOWNLOADS&Series=P%20Series&Model=P771&ProductType=Notebook%20PC Lifebook P771]{{Dead link|2022|09|17|status=domain name not resolved}}), 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 ''{{Pkg|unrar}} x''. To find out which of the many ''.hex'' files is the right one for you, look in the file {{ic|Win32/bcbtums-win7x86-brcm.inf}} and search for {{ic|[RAMUSB'''E031'''.CopyList]}}, where {{ic|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 {{ic|/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 [https://bbs.archlinux.org/viewtopic.php?id=162688 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 the journal, and your device fails to connect or disconnects shortly after connecting:
If you see messages like the following in the journal, and your device fails to connect or disconnects shortly after connecting:
Line 817: Line 953:
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 adapters). Follow instructions on [[#Dual boot pairing]] for solving this issue.
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 adapters). Follow instructions on [[#Dual boot pairing]] for solving this issue.


=== 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 have found to connect them is by installing {{aur|bluez-utils-compat}}, then [[start]] {{ic|bluetooth.service}} and do:
Some devices using Bluetooth low energy do not appear when scanning with bluetoothctl, for example the [[Logitech MX Master]]. You can use {{ic|transport le}} to scan it.
 
{{hc|# bluetoothctl|
[bluetooth]# menu scan
[bluetooth]# transport le
[bluetooth]# back
[bluetooth]# scan on
[bluetooth]# devices
...
Device XX:XX:XX:XX:XX:XX DA V2 X <---- low energy device here
}}
 
Another way to connect them is by installing {{Pkg|bluez-deprecated-tools}}, then [[start]] {{ic|bluetooth.service}} and do:


{{hc|# bluetoothctl|
{{hc|# bluetoothctl|
Line 840: Line 988:
Wait until your device shows up, then {{ic|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.


=== Cannot receive transferred files due to symlink ===
==== No BLE device can be discovered with Intel Corp. AX200 Bluetooth ====
 
If incoming file transfers fail on an an otherwise functional Bluetooth connection, the problem may be due to symlinks in your file transfer path.  Logs like this would appear in the journal:


Jun 18 11:18:13 ember obexd[3338969]: open(/home/me/.cache/obexd/MOC740): Operation not permitted (1)
It seems that BLE passive scan is broken on this device. See [https://community.intel.com/t5/Wireless/AX200-Passive-BLE-scan-linux/m-p/1227456 upstream bug report] for more details.


If the path shown in the error message contains a symlink, then obexd by default [https://git.kernel.org/pub/scm/bluetooth/bluez.git/tree/obexd/plugins/filesystem.c#n90 will not accept it]. The behavior can be overridden on initialization using a [[drop-in file]] for the {{ic|obex.service}} [[systemd/User|user service]]:
==== Cannot reconnect after sleep ====


{{hc|~/.config/systemd/user/obex.service.d/10-symlink.conf|2=
You may notice that you cannot automatically reconnect to a device after it goes to sleep, or after the computer wakes from suspend.  
[Service]
ExecStart=
ExecStart=/usr/lib/bluetooth/obexd --symlinks
}}


Then [[reload]] the ''systemd'' manager configuration of the calling user and [[restart]] the {{ic|obex.service}} user unit.
You would for example notice the following errors in your logs:


=== Interference between Headphones and Mouse ===
{{bc|
 
bluetoothd[487]: Authentication attempt without agent
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
bluetoothd[487]: Access denied: org.bluez.Error.Rejected
 
# hciconfig hci0 lm ACCEPT,MASTER
# hciconfig hci0 lp HOLD,SNIFF,PARK
 
=== Bluetooth mouse laggy movements ===
 
Try to 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 these lines:
 
[ConnectionParameters]
MinInterval=6
MaxInterval=9
Latency=44
Timeout=216
 
You can see your local adapter MAC address by running the command {{ic|hcitool dev}}. You can see the MAC addresses of currently connected remote devices by running the 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''
 
=== Problems with all BLE devices on kernel 5.9+ ===
 
Starting with v5.9, the kernel Bluetooth stack tries to use link-layer privacy on BLE connections. If the device works after pairing but does not survive a reboot or suspend, it is probably because of this.
 
To workaround [https://lkml.kernel.org/lkml/D577711C-4AF5-4E82-8A17-E766B64E15A9@holtmann.org/] this issue, open {{ic|/var/lib/bluetooth/''adapter_mac''/''device_mac''/info}}, remove the following lines, and restart {{ic|bluetooth.service}}:
 
{{bc|1=
[IdentityResolvingKey]
Key=...
}}
}}


See the relevant [https://bbs.archlinux.org/viewtopic.php?id=259954 discussion] on the Arch forum.
This could be because the device is not marked as ''trusted''. See [[#Pairing]].


=== Bluetooth immediately waking up suspend-to-idle devices ===
=== Device-speific issues ===


On systems capable of [[Power management/Suspend and hibernate|suspend-to-idle/S2idle/S0ix/Modern Standby]], Bluetooth controllers will stay enabled during sleep. This will usually cause the system to [https://bugzilla.kernel.org/show_bug.cgi?id=200039 wake up immediately after going to sleep] if any Bluetooth device is connected.
==== Bluetooth mouse lags / disconnect / does not respond ====


To prevent this, you can disable Bluetooth completely before going to sleep - install {{Pkg|bluez-utils}} and create this file:
See [[Bluetooth mouse#Troubleshooting]].


{{hc|/etc/systemd/system/bluetooth-disable-before-sleep.service|2=
==== Audio device fails to connect with br-connection-profile-unavailable ====
[Unit]
Description=Disable Bluetooth before going to sleep
Before=sleep.target
Before=suspend.target
Before=hybrid-sleep.target
Before=suspend-then-hibernate.target
StopWhenUnneeded=yes


[Service]
A bluetooth audio device will fail to connect if pipewire (rather than pulseaudio-bluetooth) is being used, but an instance of pipewire is not running. [[Start]] the {{ic|pipewire.service}} [[user unit]] or play some audio to start the pipewire daemon, then try to connect the audio device again.
Type=oneshot
RemainAfterExit=yes


ExecStart=/usr/bin/bluetoothctl power off
==== Interference between headphones and mouse ====
ExecStop=/usr/bin/bluetoothctl power on


[Install]
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
WantedBy=sleep.target
WantedBy=suspend.target
WantedBy=hybrid-sleep.target
WantedBy=suspend-then-hibernate.target
}}


[[Enable]] this service and check if Bluetooth devices disconnect when going to sleep, and whenever Bluetooth goes back up after waking up the system.
# hciconfig hci0 lm ACCEPT,MASTER
# hciconfig hci0 lp HOLD,SNIFF,PARK


If this workaround is in use, [[#Wake from suspend|waking up the system with a Bluetooth mouse/keyboard]] will not work.
==== Continually connect/disconnect with TP-LINK UB400 and Xbox controller ====
 
=== Continually connect/disconnect with TP-LINK UB400 and Xbox controller ===


Use the settings below:
Use the settings below:
Line 948: Line 1,028:
{{hc|/etc/bluetooth/main.conf|2=
{{hc|/etc/bluetooth/main.conf|2=
...
...
[General
[General]
JustWorksRepairing = always
JustWorksRepairing = always
FastConnectable = true
FastConnectable = true
Line 963: Line 1,043:
You can see relevant [https://github.com/atar-axis/xpadneo/issues/166 discussion on xpadneo] but the xpadneo driver is not needed.
You can see relevant [https://github.com/atar-axis/xpadneo/issues/166 discussion on xpadneo] but the xpadneo driver is not needed.


=== Mediatek MT7921 or MT7961 on dual boot with windows ===
=== File transfer issues ===
 
==== 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.
 
==== Cannot receive transferred files due to symlink ====
 
If incoming file transfers fail on an an otherwise functional Bluetooth connection, the problem may be due to symlinks in your file transfer path.  Logs like this would appear in the journal:


On dual boot systems, if Bluetooth firmware versions are different for Windows and Linux, the Bluetooth adapter is not working after rebooting to Windows.
Jun 18 11:18:13 ember obexd[3338969]: open(/home/me/.cache/obexd/MOC740): Operation not permitted (1)
 
If the path shown in the error message contains a symlink, then obexd by default [https://git.kernel.org/pub/scm/bluetooth/bluez.git/tree/obexd/plugins/filesystem.c#n90 will not accept it]. The behavior can be overridden on initialization using a [[drop-in file]] for the {{ic|obex.service}} [[systemd/User|user service]]:


The best way to prevent this is updating the Bluetooth drivers (especially firmware) with latest version for each OS.  
{{hc|~/.config/systemd/user/obex.service.d/10-symlink.conf|2=
[Service]
ExecStart=
ExecStart=/usr/lib/bluetooth/obexd --symlinks
}}


If you cannot find the latest version driver (or firmware) for Windows, you can copy the latest firmware file {{ic|/usr/lib/firmware/mediatek/BT_RAM_CODE_MT7961_1_2_hdr.bin.xz}} from Arch Linux and extract to Windows (e.g. {{ic|C:\WINDOWS\system32\DRIVERS\}}, you can find the firmware file path in the device manager on Windows).
Then [[reload]] the ''systemd'' manager configuration of the calling user and [[restart]] the {{ic|obex.service}} user unit.


== See also ==
== See also ==

Latest revision as of 22:57, 18 March 2024

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-deprecated-tools 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 is 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[dead link 2023-09-16 ⓘ]). 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 gets 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-deprecated-tools. See FS#53110 and the Bluez mailing list for more information.
  • Since this commit, bluez-obex and bluez-mesh have been separated from bluez. Therefore, if you plan to transfer files over Bluetooth, bluez-obex needs to be installed.

Front-ends

Console

  • bluetoothctl — Pairing a device from the shell is one of the simplest and most reliable options.
https://www.bluez.org/ || bluez-utils
  • bluetuith — Provides a bluetooth manager via a Terminal User Interface for easier pairing and device/adapter management, with OBEX File Transfer and mouse support.
https://www.github.com/darkhz/bluetuith || bluetuithAUR
Tip: To automate bluetoothctl commands, use echo -e "command1\ncommand2\n" | bluetoothctl or bluetoothctl -- command.

Graphical

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

  • GNOME BluetoothGNOME's Bluetooth tool.
    • gnome-bluetooth-3.0 provides the back-end (gnome-bluetooth is now legacy)
    • 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://invent.kde.org/plasma/bluedevil || 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
  • Overskride — A simple yet powerful bluetooth client.
https://github.com/kaii-lb/overskride#overskride || overskrideAUR

Pairing

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. (optional) Enter power on to turn the power to the controller on if the device is set to off. It is on by default; see #Default adapter power state.
  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. A bluetooth agent is what manages the Bluetooth 'pairing code'. It can either respond to a 'pairing code' coming in, or can send one out. The default-agent should be appropriate in most cases.[1]
  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 hostname [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 device name
[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

Dual boot pairing

To pair devices on dual boot setups you need to change the pairing keys on your Linux install so that they are consistent with what Windows or macOS is using.

This page only describes the manual method of doing so. To automate the process, see the bt-dualboot project and the related repositories.

Setup

To do this, first pair your device on your Arch Linux install. Then reboot into the other OS and pair the device. Now you need to extract the pairing keys, but first switch off the Bluetooth devices to prevent any connection attempts.

Note: Some Logitech devices, such as the Logitech MX Master and Logitech 604 Lightspeed, increment the MAC address by one every time that the device is paired with a new system. You should determine whether this is the case, so that it can be accounted for at the end of the process.

For Windows

Extracting on Windows

First, boot into Windows.

The registry key containing the link keys may only be accessed by the SYSTEM account, which cannot be logged into. Therefore, you will need Microsoft's PsExec tool from the official Windows Sysinternals site in order to run regedit.exe as SYSTEM.

Download PsTools, and extract PsExec64.exe.

In an administrator instance of a command shell, from the location of the extracted EXE, launch the registry editor:

.\PsExec64.exe -s -i regedit.exe

In the registry editor, navigate to the following registry key:

HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\BTHPORT\Parameters\Keys

Within this registry key is one subkey per Bluetooth adapter, named by MAC address. If there are multiple subkeys, and you are unsure of which to use, follow this guide to find the MAC address for the desired Bluetooth adapter.

In the desired adapter's registry key, there is a name-value pair for each paired device, with the name being its MAC address. Additionally, you might see some subkeys named by MAC addresses, each containing name-value pairs with names like LTK or IRK. These subkeys (if any) are for Bluetooth 5.1 devices. If the device you're trying to share has a subkey, it is a Bluetooth 5.1 device. If it does not have a subkey, only a name-value pair, it is not a Bluetooth 5.1 device.

Right click on the adapter's registry key and export it as a .reg file. This is a text file that you can copy keys from. As mentioned, it contains pairing keys in name-value pairs for non-Bluetooth 5.1 devices, and pairing keys (and some other information) in per-device subkeys for Bluetooth 5.1 devices. Make this file available to your Linux installation and reboot into it.

If the device you want to share is not a Bluetooth 5.1 device, jump to #Finishing up. If it is a Bluetooth 5.1 device, you need to make some modifications to the pairing keys and the associated information before finishing up. Refer to #Preparing Bluetooth 5.1 Keys to see how.

Extracting on Linux
Note: If your Windows partition is encrypted with Bitlocker, you will not be able to access it from Linux using chntpw.

Reboot into Arch. Install chntpw. Mount your windows system drive.

$ cd /path/to/windows/system/Windows/System32/config
$ chntpw -e SYSTEM
Note: Instead of CurrentControlSet you may see ControlSet00X, where X is any number. Check using the ls command.

Inside the chntpw environment, run

> cd CurrentControlSet\Services\BTHPORT\Parameters\Keys

or

> cd ControlSet00X\Services\BTHPORT\Parameters\Keys

Then get your Bluetooth adapter's MAC address and enter its folder

> ls
> cd your-device's-mac-address

Do the same for your paired devices. If this is not a Bluetooth 5.1 device, you will only see the pairing key:

> ls
Node has 0 subkeys and 1 values
size  type        value name    [value if type DWORD]
16    REG_BINARY <123456789876>

If so, get your device's key through hex:

> hex 123456789876
:00000 XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX (some other chars)

The "XX"s are the pairing key. Make note of which keys map to which MAC addresses.

If this is a Bluetooth 5.1 device, then you will see several keys corresponding to the one device.

Node has 0 subkeys and 8 values
  size     type              value name             [value if type DWORD]
    16  3 REG_BINARY         <LTK>
     4  4 REG_DWORD          <KeyLength>               16 [0x10]
     8  b REG_QWORD          <ERand>
     4  4 REG_DWORD          <EDIV>                 37520 [0x9290]
    16  3 REG_BINARY         <IRK>
     8  b REG_QWORD          <Address>
     4  4 REG_DWORD          <AddressType>              1 [0x1]
     4  4 REG_DWORD          <AuthReq>                 45 [0x2d]

Refer to #Preparing Bluetooth 5.1 Keys to see how to use these, using hex value_name to obtain the requested values.

Finally, to import the key(s) into your Linux installation, proceed to #Finishing up.

For macOS

Boot into macOS:

  • For macOS Monterey or newer:
    1. Open Keychain Access and search for Bluetooth.
    2. Sort by date.
    3. If you've recently removed and reconnected the device then you can simply sort the keys by date modified and pick the latest. It is probably called MobileBluetooth (for older Bluetooth devices) or is just an UUID (for Bluetooth 5.1+).
    4. Double click on the entry. Check that the MAC address in the Account field matches the MAC address of your device.
    5. Click the "Show password" checkbox. You will now need to enter your password, twice.
    6. Copy the text in the password field, it's actually an XML file (⌘+a ⌘+c)
    7. Paste the text in bt_keys.txt in your home directory.
  • For High Sierra or newer, run the following in a terminal:
    # defaults read /private/var/root/Library/Preferences/com.apple.bluetoothd.plist LinkKeys > ~/bt_keys.txt
  • For Sierra or older, run the following in a terminal:
    # defaults read /private/var/root/Library/Preferences/blued.plist LinkKeys > ~/bt_keys.txt

The ~/.bt_keys.txt file now contains the established Bluetooth keys. For older versions of macOS (High Sierra and older) you will have to reverse the keys before proceeding. For example, 98 54 2f aa bb cc dd ee ff gg hh ii jj kk ll mm becomes MM LL KK JJ GG FF EE DD CC BB AA 2F 54 98.

Note: The reversal can be done with the following Python code:
>>> key = "98 54 2f aa bb cc dd ee ff gg hh ii jj kk ll mm"
>>> " ".join(reversed(key.strip().split()))

If this is a Bluetooth 5.1 device, then there will be more than one key corresponding to one device. Refer to #Preparing Bluetooth 5.1 Keys to see how to use these.

Finally, to import the key(s) into your Linux installation, reboot into Linux and proceed to #Finishing up.

Preparing Bluetooth 5.1 Keys

This article or section needs expansion.

Reason: We are still working on getting a comprehensive idea of how these work across vendors. For now, documenting specific devices' compatibility with these methods is helpful - especially non-Logitech data points. (Discuss in Talk:Bluetooth#Bluetooth 5.1 Devices)

If you observed the presence of Bluetooth 5.1 keys while following #For Windows or #For macOS, you must apply certain transformations to their values before importing them into Linux. Create the requested files with their appropriate contents, for installation in #Finishing up. This process will depend on the device, and some of the values have to be manipulated; code utilities for doing so are provided below.

Device Source Key and Transformations (Windows) Source Key and Transformations (macOS) Destination Key File
  • Logitech MX Master 3
  • Logitech MX Master 3S
  • Logitech MX Keys
  • Logitech MX Mechanical
  • Xbox One S Wireless Controller
  • Copy IRK.
  • Remove the spaces between the hex octets.
? IdentityResolvingKey.Key
  • Copy LTK.
  • Remove the spaces between the hex octets.
? SlaveLongTermKey.Key and PeripheralLongTermKey.Key
ERand and EDIV should be 0 Random Number and Encrypted Diversifier should be 0.
  • Logitech MX Anywhere 2S
  • Copy IRK.
  • Remove the spaces between the hex octets.
? IdentityResolvingKey.Key
  • Copy CSRK.
  • Remove the spaces between the hex octets.
? LocalSignatureKey.Key
  • Copy LTK.
  • Remove the spaces between the hex octets.
? LongTermKey.Key
  • Copy KeyLength.
  • Convert the whole number to decimal.
? LongTermKey.EncSize
  • Copy EDIV.
  • Convert the whole number to decimal.
? LongTermKey.EDiv
  • Copy ERand.
  • Reverse the order of the octets.
  • Convert the whole number to decimal.
? LongTermKey.Rand
  • ThinkPad TrackPoint Keyboard II
  • Pebble M350 mouse
  • Logitech G604 Lightspeed mouse
  • Copy IRK.
  • Reverse the order of the octets.
  • Copy Remote IRK.
  • Convert from base64 to hex.
IdentityResolvingKey.Key
  • Copy LTK.
  • Remove the spaces between the hexadecimal octets.
  • Copy Remote Encryption > Long-term Key.
  • Convert from base64 to hex.
LongTermKey.Key
  • Copy ERand.
  • Reverse the order of the octets.
  • Convert the whole number to decimal.
  • Copy Remote Encryption > Random Number.
  • Convert from base64 to a little-endian decimal number (see Python code below).
LongTermKey.Rand
  • Copy EDIV.
  • Reverse the order of the octets.
  • Convert the whole number to decimal.
  • Copy Remote Encryption > Encrypted Diversifier.
  • Convert from base64 to a little-endian decimal number (see Python code below).
LongTermKey.EDiv
Other devices
  • Copy LTK.
  • Remove the spaces between the hex octets.
  • Copy Remote IRK.
  • Convert from base64 to hex.
LongTermKey.Key
  • Copy ERand.
  • Reverse the order of the octets.
  • Convert the whole number to decimal.
  • Copy Remote Encryption > Long-term Key.
  • Convert from base64 to hex.
LongTermKey.Rand
  • Copy EDIV.
  • Remove the spaces between the hex octets.
  • Copy Remote Encryption > Encrypted Diversifier.
  • Convert from base64 to hex.
  • Reverse the order of the octets.
LongTermKey.EDiv
Xbox wireless controller
  • Copy LTK.
  • Remove the spaces between the hex octets.
? SlaveLongTermKey.Key
Note:
>>> "key_value".replace(" ", "")
  • This Python code does only the octet reversal:
>>> ERand=" 63 02 84 B8 5D 40 44 DF   "
>>> ERand=list(reversed(ERand.strip().split()))
  • This Python code does the additional decimal conversion required for some:
>>> int("".join(ERand), 16)
16088054540146049635
  • This Python code does the base64 to hex conversion:
binascii.hexlify(base64.decodebytes(b'...')).upper()
  • This Python code does the full macOS Encrypted Diversifier conversion:
struct.unpack('<H', base64.decodebytes(b'...'))
  • This Python code does the full macOS Random Number conversion:
struct.unpack('<Q', base64.decodebytes(b'...'))

For an example of the general case:

  • An LTK of 48 4D AF CD 0F 92 22 88 0A 52 9A F4 76 DA 8B 94 makes for a LongTermKey.Key of 484DAFCD0F9222880A529AF476DA8B94.
  • An ERand of 63 02 84 B8 5D 40 44 DF makes for a Rand of 16088054540146049635.
  • An EDIV of 37520 makes for an EDiv of 37520.

Finishing up

This article or section needs language, wiki syntax or style improvements. See Help:Style for reference.

Reason: Informal section title. (Discuss in Talk:Bluetooth)

Now that you have the keys change user to root, then continue with:

# cd /var/lib/bluetooth/BT-Adapter-MAC-address

Here you will find folders for each paired Bluetooth device. For each device you want to pair with Arch and your dual boot, do the following:

# cd device-MAC-address
Note: At this point, if you are using a device which increments its MAC address on pairing, you must move the MAC address directory to the incremented path. Either copy the MAC address from Windows, or increment it yourself while minding the fact that each octet is a two-digit hexadecimal number.

If you have a pairing key (i.e. this is not a Bluetooth 5.1 device), then edit the info file and change the key under [LinkKey]. E.g.:

info
[LinkKey]
Key=XXXXXXXXXXXXXXX
Note: You will have to make sure that all the letters are in capital case. Remove any spaces.

If you have several keys, as in Bluetooth 5.1, edit the info file and substitute all applicable keys with their recorded values. E.g. for an Xbox One S Wireless Controller:

info
[IdentityResolvingKey]
Key=<IdentityResolvingKey.Key>

[PeripheralLongTermKey]
Key=<PeripheralLongTermKey.Key>

[SlaveLongTermKey]
Key=<SlaveLongTermKey.Key>

Then restart bluetooth.service and pulseaudio (with pulseaudio -k && pulseaudio --start).

You should be able to connect to your device now.

Note: Depending on your Bluetooth manager, you may need to perform a full reboot in order to reconnect to the device.

Configuration

Default adapter power state

As of bluez 5.65, BlueZ' default behavior is to power on all Bluetooth adapters when starting the service or resuming from suspend. [2]

If you would like the adapter to not be automatically enabled (e.g. on a portable device where you wish to save battery), set AutoEnable=false in /etc/bluetooth/main.conf in the [Policy] section:

/etc/bluetooth/main.conf
[Policy]
AutoEnable=false

The adapter can still be turned on manually by running power on as described in #Pairing.

Discoverable on startup

If the device should always be visible and directly connectable:

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

Wake from suspend

To allow Bluetooth keyboards, mice, etc. to wake the system from suspend. First, check the bios settings and make sure that wake from USB is not disabled. In many cases, Bluetooth from the motherboard is a USB device.

Find the vendor code and device ID for the Bluetooth adapter.

$ lsusb | grep bluetooth -i
Bus 001 Device 002: ID 8087:0039 Intel Corp. AX200 Bluetooth

Add a new udev rule for the vendor code and device ID to enable wake from suspend.

/etc/udev/rules.d/91-keyboard-mouse-wakeup.rules
SUBSYSTEM=="usb", ATTRS{idVendor}=="8087", ATTRS{idProduct}=="0039" RUN+="/bin/sh -c 'echo enabled > /sys$env{DEVPATH}/../power/wakeup;'"

To automatically re-configure your Bluetooth keyboard after wakeups to e.g. have a different keymap or key press repeat rate (for details, see Xorg/Keyboard configuration#Adjusting typematic delay and rate and xmodmap), create an executable script.

configure_keyboard.sh
#!/bin/sh
export DISPLAY=:0
xset r rate 220 30
xmodmap /your/path/to/.Xmodmap

Then create an additional udev rule like above.

/etc/udev/rules.d/92-keyboard-reconfiguration-wakeup.rules
SUBSYSTEM=="usb", ATTRS{idVendor}=="8087", ATTRS{idProduct}=="0039" RUN+="/your/path/to/configure_keyboard.sh"

Enabling experimental features

The Bluez stack keeps new, potentially buggy features behind the D-Bus experimental and kernel experimental options. The functionality included under these varies over time, as experimental features are determined to be stable and no longer require the option (as an example: enabling D-Bus experimental interfaces currently allows to report battery level for old headsets). To enable these, uncomment the corresponding line in the configuration:

/etc/bluetooth/main.conf
...

# Enables D-Bus experimental interfaces
# Possible values: true or false
#Experimental = true

# Enables kernel experimental features, alternatively a list of UUIDs
# can be given.
# Possible values: true,false,<UUID List>
# Possible UUIDS:
...
# Defaults to false.
#KernelExperimental = true

Alternatively, you can edit the bluetooth.service to add the --experimental or --kernel flag, like this drop-in file:

/etc/systemd/system/bluetooth.service.d/override.conf
[Service]
ExecStart=
ExecStart=/usr/lib/bluetooth/bluetoothd --experimental

Either way, you must then restart the bluetooth.service.

Audio

You will typically need to take an additional step to integrate the audio server with Bluetooth. This is detailed in the below sections.

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

PulseAudio

In order to be able to use audio equipment like Bluetooth headphones or speakers, you need to install the additional pulseaudio-bluetooth package. Make sure to restart pulseaudio to make the installation take effect: pulseaudio -k. With a default PulseAudio installation (specifically, using a user instance with the packaged default.pa) you should immediately be able to stream audio from a Bluetooth device to your speakers. [3]

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
...

Optionally, add load-module module-switch-on-connect if you want to auto-switch all audio to the Bluetooth device.

PipeWire

PipeWire as of v0.3.19 enables its Bluetooth support by default.

ALSA

Note: Bluez5 has dropped direct integration for ALSA and supports PulseAudio only. Follow the instructions below if you cannot or do not want to use PulseAudio.

First, ensure that your Bluetooth audio device is correctly paired and connected to the system.

Then, install bluez-alsa-gitAUR, start (and enable) the bluealsa service, and add your user to the audio group.

Run the following command to check if everything is working as intended (replace XX:XX:XX:XX:XX:XX and FILE.wav below):

$ aplay -D bluealsa:SRV=org.bluealsa,DEV=XX:XX:XX:XX:XX:XX,PROFILE=a2dp FILE.wav

Finally, add the following lines to your ~/.asoundrc:

~/.asoundrc
defaults.bluealsa {
    service "org.bluealsa"
    device "XX:XX:XX:XX:XX:XX"
    profile "a2dp"
}

You can now use the bluealsa device to reach your Bluetooth audio device. Volume management is conducted normally via alsamixer with the option -D bluealsa.

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-deprecated-tools, as it provides 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:

$ picocom /dev/rfcomm0 -b 115200

Troubleshooting

This article or section is out of date.

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

General Troubleshooting

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-deprecated-tools package provides an alternative version of bluez-utils with the deprecated tools.

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

Service issues

systemd: Condition check resulted in Bluetooth service being skipped

bluetooth.service only requires the directory /sys/class/bluetooth to exist, which should be created by kernel module bluetooth, which is only autoloaded by systemd-udev if it actually finds a working Bluetooth hardware device.

If your /sys/class/bluetooth does not exist, check if your kernel Bluetooth module is loaded by lsmod. If not, and you believe you have a Bluetooth device, you can try manually starting them by loading the Bluetooth module and restarting bluetooth.service.

You should also load your corresponding kernel Bluetooth driver when loading the bluetooth module, most likely btusb, but can also be btrtl,btintel,btbcm,bnep,btusb etc.

Check bluetooth.service's unit status to see whether it started.

See also Debian Bug report logs - #853207.

If bluetooth.service started successfully, there is a chance that you still cannot use Bluetooth normally (e.g. bluetoothctl says something like org.Bluez.Error.NotReady when you scan on). If this happens, try rebooting your computer, and double-check: whether directory /sys/class/bluetooth exists; whether lsmod includes correct Bluetooth modules; log messages in the journal; etc. systemd-udev should pickup your Bluetooth hardware automatically without manual changes again.

Bluetooth immediately waking up suspend-to-idle devices

On systems capable of suspend-to-idle/S2idle/S0ix/Modern Standby, Bluetooth controllers will stay enabled during sleep. This will usually cause the system to wake up immediately after going to sleep if any Bluetooth device is connected.

To prevent this, you can disable Bluetooth completely before going to sleep - install bluez-utils and create this file:

/etc/systemd/system/bluetooth-disable-before-sleep.service
[Unit]
Description=Disable Bluetooth before going to sleep
Before=sleep.target
Before=suspend.target
Before=hybrid-sleep.target
Before=suspend-then-hibernate.target
StopWhenUnneeded=yes

[Service]
Type=oneshot
RemainAfterExit=yes

ExecStart=/usr/bin/bluetoothctl power off
ExecStop=/usr/bin/bluetoothctl power on

[Install]
WantedBy=sleep.target
WantedBy=suspend.target
WantedBy=hybrid-sleep.target
WantedBy=suspend-then-hibernate.target

Enable this service and check if Bluetooth devices disconnect when going to sleep, and whenever Bluetooth goes back up after waking up the system.

If this workaround is in use, waking up the system with a Bluetooth mouse/keyboard will not work.

Bluetooth turns off after logout on a headless/server system

This can have various causes:

Adapter issues

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

bluetoothctl: No default controller available

There is a bug with some motherboard bluetooth controllers. To see if this might be the issue, run journalctl | grep hci. If there are entries like "command tx timeout" or "Reading Intel version command failed", then power off your pc and physically unplug the power cable for a few seconds. This forces the controller to reload the firmware (while a standard reboot will not). See bug report here.

Make sure the device is not being blocked by rfkill.

If using USBGuard, make sure it does not block the device. See USBGuard#Allow Bluetooth controllers.

It might also happen with some intel cards (such as the 8260) to not be picked up correctly by the Bluetooth service. In some cases, using the deprecated bluez-deprecated-tools in lieu of bluez-utils have reportedly fixed the issue.

This might also be caused by power saving measures, in which case adding the kernel parameter btusb.enable_autosuspend=n is a potential solution. See also Red Hat Bugzilla – Bug 1573562.

Sometimes unloading and loading btusb without options helps to get the controller back:

# modprobe -r btusb
# modprobe btusb

It may also occur when the dongle is a CSR clone.

rfkill unblock: Do not unblock

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

$ connmanctl enable bluetooth

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 as root 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-deprecated-tools)

$ 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 5.17 and < 6.0. 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.

Foxconn / Hon Hai / Lite-On Broadcom device

Some of these devices require the firmware to be flashed into the device at boot.

Some firmware is available when searching for broadcom on the AUR, a notable package being broadcom-bt-firmwareAUR, which provides the files for multiple cards.

Alternatively, the firmware can be 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[dead link 2023-09-16 ⓘ]. Depending on the format, extracting the files might need unrar or cabextract. 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.

Mediatek MT7921 or MT7961 on dual boot with windows

On dual boot systems, if Bluetooth firmware versions are different for Windows and Linux, the Bluetooth adapter is not working after rebooting to Windows.

The best way to prevent this is updating the Bluetooth drivers (especially firmware) with latest version for each OS.

If you cannot find the latest version driver (or firmware) for Windows, you can copy the latest firmware file /usr/lib/firmware/mediatek/BT_RAM_CODE_MT7961_1_2_hdr.bin.xz from Arch Linux and extract to Windows (e.g. C:\WINDOWS\system32\DRIVERS\, you can find the firmware file path in the device manager on Windows).

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

Pairing and connectivity issues

Computer is not visible

Enable discoverable mode if your computer cannot be discovered from your phone:

# bluetoothctl discoverable on

Verify that discoverable mode is on:

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

If the computer still does not show up, try changing the device class in /etc/bluetooth/main.conf as follows:

# Default device class. Only the major and minor device class bits are
# considered.
#Class = 0x000100 # Computer Type (from default config)
Class = 0x100100 # (Object-Transfer Service & Computer Type)
Note: In some cases, Class in main.conf gets overridden after device initialization, so set the class directly with hciconfig hci0 class 100100.

A user reported that this was the only solution to make their computer visible for their phone. LG TVs (and some others) are discoverable from their audio devices, so using 000414 (the soundbar class) will make such devices appear.

See https://bluetooth-pentest.narod.ru/software/bluetooth_class_of_device-service_generator.html to generate Bluetooth device/service classes.

Device connects, then disconnects after a few moments

If you see messages like the following in the journal, 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 adapters). Follow instructions on #Dual boot pairing for solving this issue.

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. You can use transport le to scan it.

# bluetoothctl
[bluetooth]# menu scan
[bluetooth]# transport le
[bluetooth]# back
[bluetooth]# scan on
[bluetooth]# devices
...
Device XX:XX:XX:XX:XX:XX DA V2 X <---- low energy device here

Another way to connect them is by installing bluez-deprecated-tools, 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.

No BLE device can be discovered with Intel Corp. AX200 Bluetooth

It seems that BLE passive scan is broken on this device. See upstream bug report for more details.

Cannot reconnect after sleep

You may notice that you cannot automatically reconnect to a device after it goes to sleep, or after the computer wakes from suspend.

You would for example notice the following errors in your logs:

bluetoothd[487]: Authentication attempt without agent
bluetoothd[487]: Access denied: org.bluez.Error.Rejected

This could be because the device is not marked as trusted. See #Pairing.

Device-speific issues

Bluetooth mouse lags / disconnect / does not respond

See Bluetooth mouse#Troubleshooting.

Audio device fails to connect with br-connection-profile-unavailable

A bluetooth audio device will fail to connect if pipewire (rather than pulseaudio-bluetooth) is being used, but an instance of pipewire is not running. Start the pipewire.service user unit or play some audio to start the pipewire daemon, then try to connect the audio device again.

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

Continually connect/disconnect with TP-LINK UB400 and Xbox controller

Use the settings below:

/etc/bluetooth/main.conf
...
[General]
JustWorksRepairing = always
FastConnectable = true
Class = 0x000100
...
[GATT]
ReconnectIntervals=1,1,2,3,5,8,13,21,34,55
AutoEnable=true
...

Then restart the bluetooth.service.

You can see relevant discussion on xpadneo but the xpadneo driver is not needed.

File transfer issues

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.

Cannot receive transferred files due to symlink

If incoming file transfers fail on an an otherwise functional Bluetooth connection, the problem may be due to symlinks in your file transfer path. Logs like this would appear in the journal:

Jun 18 11:18:13 ember obexd[3338969]: open(/home/me/.cache/obexd/MOC740): Operation not permitted (1)

If the path shown in the error message contains a symlink, then obexd by default will not accept it. The behavior can be overridden on initialization using a drop-in file for the obex.service user service:

~/.config/systemd/user/obex.service.d/10-symlink.conf
[Service]
ExecStart=
ExecStart=/usr/lib/bluetooth/obexd --symlinks

Then reload the systemd manager configuration of the calling user and restart the obex.service user unit.

See also