Difference between revisions of "Bluetooth"
(Add a bluetoothctl instruction (selecting controller).)
(→Troubleshooting: add likely replacements for deprecated tools)
|Line 185:||Line 185:|
== Troubleshooting ==
== Troubleshooting ==
=== bluetoothctl ===
=== bluetoothctl ===
Revision as of 15:17, 9 March 2017
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.
- 1 Installation
- 2 Configuration via the CLI
- 3 Configuration with a graphical front-end
- 4 Using Obex for sending and receiving files
- 5 Audio
- 6 Troubleshooting
- 6.1 Shell command _____ is missing from bluez-utils
- 6.2 bluetoothctl
- 6.3 gnome-bluetooth
- 6.4 Bluetooth USB Dongle
- 6.5 Logitech Bluetooth USB Dongle
- 6.6 hcitool scan: Device not found
- 6.7 rfkill unblock: Do not unblock
- 6.8 My computer is not visible
- 6.9 Logitech keyboard does not pair
- 6.10 HSP/HFP profiles
- 6.11 Thinkpad Bluetooth Laser Mouse problems
- 6.12 Foxconn / Hon Hai / Lite-On Broadcom device
- 6.13 Device connects, then disconnects after a few moments
- 6.14 Device does not connect with an error in journal
Install the and packages. The package provides the Bluetooth protocol stack, and the package provides the
Load the generic bluetooth driver, if not already loaded:
# modprobe btusb
- By default the bluetooth daemon will only give out bnep0 devices to users that are a member of the
lpgroup. 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
- Some Bluetooth adapters are bundled with a Wi-Fi card (e.g. Intel Centrino). These require that the Wi-Fi card is firstly enabled (typically a keyboard shortcut on a laptop) in order to make the Bluetooth adapter visible to the kernel.
- Some Bluetooth cards (e.g. Broadcom) conflict with the network adapter. Thus, you need to make sure that your Bluetooth device get connected before the network service boot.
- Some tools such as hcitool and hciconfig have been deprecated upstream, and are no longer included in FS#53110 and the Bluez mailing list for more information. . 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. See
Configuration via the CLI
Pairing a device from the shell is one of the simplest and most reliable options. The exact procedure depends on the devices involved and their input functionality. What follows is a general outline of pairing a device using
bluetoothctl interactive command. There one can input
help to get a list of available commands.
- Possibly select a default controller by inputting
select MAC Address
- Turn the power to the controller on by entering
power on. It is off by default.
devicesto get the MAC Address of the device with which to pair.
- Enter device discovery mode with
scan oncommand if device is not yet on the list.
- Turn the agent on with
pair MAC Addressto do the pairing (tab completion works).
- If using a device without a PIN, one may need to manually trust the device before it can reconnect successfully. Enter
trust MAC Addressto do so.
- Finally, use
connect MAC_addressto establish a connection.
An example session may look this way:
# bluetoothctl [NEW] Controller 00:10:20:30:40:50 pi [default] [bluetooth]# agent KeyboardOnly Agent registered [bluetooth]# default-agent Default agent request successful [bluetooth]# scan on Discovery started [CHG] Controller 00:10:20:30:40:50 Discovering: yes [NEW] Device 00:12:34:56:78:90 myLino [CHG] Device 00:12:34:56:78:90 LegacyPairing: yes [bluetooth]# pair 00:12:34:56:78:90 Attempting to pair with 00:12:34:56:78:90 [CHG] Device 00:12:34:56:78:90 Connected: yes [CHG] Device 00:12:34:56:78:90 Connected: no [CHG] Device 00:12:34:56:78:90 Connected: yes Request PIN code [agent] Enter PIN code: 1234 [CHG] Device 00:12:34:56:78:90 Paired: yes Pairing successful [CHG] Device 00:12:34:56:78:90 Connected: no [bluetooth]# connect 00:12:34:56:78:90 Attempting to connect to 00:12:34:56:78:90 [CHG] Device 00:12:34:56:78:90 Connected: yes Connection successful
In order to have the device active after a reboot, a udev rule is needed:
# Set bluetooth power up ACTION=="add", KERNEL=="hci0", RUN+="/usr/bin/hciconfig %k up"
KERNEL=="hci[0-9]*"to match all interfaces.
After a suspend/resume-cycle, the device can be powered on automatically using a custom systemd service:
[Unit] Description=Bluetooth auto power on After=bluetooth.service sys-subsystem-bluetooth-devices-%i.device suspend.target [Service] Type=oneshot ExecStart=/usr/bin/hciconfig %i up [Install] WantedBy=suspend.target
Enable an instance of the unit using your bluetooth device name, for example
Alternatively and instead of the custom service and udev rule, you can simply use the new AutoEnable feature introduced in BlueZ 5.35 by uncommenting
AutoEnable=true lines in
Configuration with a graphical front-end
The following packages allow for a graphical interface to customize Bluetooth.
GNOME Bluetooth is GNOME's Bluetooth tool. The package provides the back-end, provides the status monitor applet, and 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.
To receive files, you must install thepackage. You can then go to Settings -> Sharing to authorize receiving files from paired devices over Bluetooth.
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.
Blueberry is an alternative front-end for GNOME Bluetooth, which works in all desktop environments. It can be installed with thepackage. It provides a configuration tool (blueberry) and a system tray applet (blueberry-tray).
Using Obex for sending and receiving files
Another option, rather than using KDE or Gnome Bluetooth packages, is ObexFS which allows for the mounting of phones which are treated like any other filesystem.
Installand mount supported phones by running:
$ obexfs -b MAC_address_of_device /mountpoint
Once you have finished, to unmount the device use the command:
$ fusermount -u /mountpoint
For more mounting options see http://dev.zuckschwerdt.org/openobex/wiki/ObexFs
If your device supports the Obex FTP service but you do not wish to mount the device you can transfer files to and from the device using the obexftp command.
To send a file to a device run the command:
$ obexftp -b MAC_address_of_device -p /path/to/file
To retrieve a file from a device run the command:
$ obexftp -b MAC_address_of_device -g filename
Obex Object Push
For devices that do not support Obex FTP service, check if Obex Object Push is supported.
# sdptool browse XX:XX:XX:XX:XX:XX
Read the output, look for Obex Object Push, remember the channel for this service. If supported, one can useto send files to this device:
# ussp-push XX:XX:XX:XX:XX:XX@CHANNEL file wanted_file_name_on_phone
Using your computer's speakers as a bluetooth headset
This can allow you to do things such as playing what is on your phone through your computer speakers.
Add the following to the file
/etc/bluetooth/audio.conf (create it if not present):
More info in:
In order to be able to use audio equipment like bluetooth headphones, you need to install the additionalpackage.
Please have a look at the Bluetooth headset page for more information about bluetooth audio and bluetooth headsets.
In order to enable your system to be detected as an A2DP sink (e.g. to play music from your phone via your computer speakers), add
Shell command _____ is missing from bluez-utils
Some tools have been marked as deprecated and removed from the package. At this time they are still available in the AUR package D-Bus API:AUR. Their functionality is partially covered by new tools, while some things have yet to be implemented with the new
|Deprecated tool||Most likely replacement|
|gatttool||btgatt-client, [D-Bus Gatt API https://git.kernel.org/cgit/bluetooth/bluez.git/tree/doc/gatt-api.txt]|
|hciconfig||btmgmt (and bluetoothctl?)|
|hcidump||btmon (and btsnoop)|
|hcitool||missing, D-Bus Device API available|
|rfcomm||missing, implement with D-Bus Profile1 API?|
|sdptool||missing, functionality seems to be scattered over different D-Bus objects: Profile, Advertising, and the UUIDs arrays in device and adapter.|
If bluetoothctl cannot find any controller, the bluetooth device may be blocked. Try to unblock it using:
# rfkill unblock 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 installand issue:
You can edit the paths using:
$ vi ~/.config/user-dirs.dirs
Bluetooth USB Dongle
If you are using a USB dongle, you should check that your Bluetooth dongle is recognized. You can do that by running
journalctl -f when you have plugged in the USB dongle (or inspecting
/var/log/messages.log). It should look something like the following (look out for hci):
Feb 20 15:00:24 hostname kernel: [ 2661.349823] usb 4-1: new full-speed USB device number 3 using uhci_hcd Feb 20 15:00:24 hostname bluetoothd: HCI dev 0 registered Feb 20 15:00:24 hostname bluetoothd: Listening for HCI events on hci0 Feb 20 15:00:25 hostname bluetoothd: HCI dev 0 up Feb 20 15:00:25 hostname bluetoothd: 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:
hciconfig -a hci0
hci0: Type: USB BD Address: 00:00:00:00:00:00 ACL MTU: 0:0 SCO MTU: 0:0 DOWN RX bytes:0 acl:0 sco:0 events:0 errors:0 TX bytes:0 acl:0 sco:0 commands:0 errors:
# hciconfig hci0 up
hciconfig -a hci0
hci0: Type: USB BD Address: 00:02:72:C4:7C:06 ACL MTU: 377:10 SCO MTU: 64:8 UP RUNNING RX bytes:348 acl:0 sco:0 events:11 errors:0 TX bytes:38 acl:0 sco:0 commands:11 errors:0
If this fails with an error like:
Operation not possible due to RF-kill
it could be due either to the
rfkill utility, in which case it should be resolved with
# rfkill unblock all
or, it could simply be the hardware switch of the computer. The hardware bluetooth switch (at least sometimes) controls access to USB bluetooth dongles also. Flip/press this switch and try bringing the device up again.
To verify that the device was detected you can use
hcitool which is part of the
bluez-utils. You can get a list of available devices and their identifiers and their MAC address by issuing:
$ hcitool dev
Devices: hci0 00:1B:DC:0F:DB:40
More detailed information about the device can be retrieved by using
$ 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:
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
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 thepackage. When you connect your Logitech dongle it will automatically switch.
hcitool scan: Device not found
- On some Dell laptops (e.g. Studio 15) you have to switch the Bluetooth mode from HID to HCI. Install the udev should do this automatically. Alternatively, you can run this command to switch to HCI manually: package, then
- 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:
# hciconfig hci0 up
rfkill unblock: Do not unblock
If your device still soft blocked and you run connman, try this:
$ connmanctl enable bluetooth
My computer is not visible
Cannot discover computer from your phone? Enable PSCAN and ISCAN:
# enable PSCAN and ISCAN $ hciconfig hci0 piscan # check it worked
hci0: Type: USB BD Address: 00:12:34:56:78:9A ACL MTU: 192:8 SCO MTU: 64:8 UP RUNNING PSCAN ISCAN RX bytes:20425 acl:115 sco:0 events:526 errors:0 TX bytes:5543 acl:84 sco:0 commands:340 errors:0
Try changing device class in
/etc/bluetooth/main.conf as following:
# Default device class. Only the major and minor device class bits are # considered. #Class = 0x000100 (from default config) Class = 0x100100
This was the only solution to make my computer visible for my phone.
Logitech keyboard does not pair
If you do not get the passkey when you try to pair your Logitech keyboard, type the following command:
# hciconfig hci0 sspmode 0
If after pairing, the keyboard still does not connect, check the output of
hcidump -at. If the latter indicates repeatedly connections-disconnections like the following message:
status 0x00 handle 11 reason 0x13 Reason: Remote User Terminated Connection
then, the only solution for now is to install the old Bluetooth stack.
Thinkpad Bluetooth Laser Mouse problems
If you are experiencing that your Thinkpad Bluetooth Laser Mouse rapidly connects and then (after a few milliseconds) disconnects again every few seconds (when you move the mouse or press a button), try pairing it with the code
0000 instead pairing without a code.
Foxconn / Hon Hai / Lite-On Broadcom device
Some of these devices require the firmware to be flashed into the device at boot. The firmware is not provided but can converted from a Microsoft Windows .hex file into a .hcd using hex2hcd (which is installed with ).
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 ...
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
The .hex file can be extracted from the downloaded Windows driver without having to run Windows for it. Download the right driver, for example Bluetooth Widcomm (listed among the drivers for Lifebook P771), which contains the drivers for many Broadcomm devices. In case of Bluetooth Widcomm, the driver is a self-extracting RAR archive, so it can be extracted using x. To find out which of the many .hex files is the right one for you, look in the file
Win32/bcbtums-win7x86-brcm.inf and search for
E031 should be replaced with the product code (the second hex number in lsusb) of your device in upper-case. Underneath you should see the file name of the right .hex file.
Once you have the .hcd file, copy it into
/lib/firmware/brcm/BCM.hcd - this filename is suggested by
dmesg and it may change in your case so check your dmesg output in order to verify. Then reload the btusb module:
# rmmod btusb # modprobe btusb
In some cases (with older kernels?), you have to flash the .hcd file with the brcm_patchram_plus utility, provided by broken link: archived in aur-mirror]. First, make sure in dmesg that the device is recognized by btusb as a bluetooth device. Then, run the following (replace 04ca 2006 with your vendor product pair):AUR[
# echo '04ca 2006' > /sys/bus/usb/drivers/btusb/new_id
Turn on the device:
# hciconfig hci0 up
Flash the firmware:
# brcm_patchram_plus_usb --patchram fw-04ca_2006.hcd hci0
The device should now be available. See BBS#162688 for information on making these changes persistent.
Device connects, then disconnects after a few moments
If you see messages like the following in
journalctl output, and your device fails to connect or disconnects shortly after connecting:
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 can't handle multiple pairings associated with the same MAC address (i.e., bluetooth adapter). You can fix this by re-pairing the device. Start by removing the device:
$ bluetoothctl [bluetooth]# devices Device XX:XX:XX:XX:XX:XX My Device [bluetooth]# remove XX:XX:XX:XX:XX:XX
bluetooth.service, turn on your bluetooth adapter, make your device discoverable, re-scan for devices, and re-pair your device. Depending on your bluetooth manager, you may need to perform a full reboot in order to re-discover the device.
Device does not connect with an error in journal
If you see a message like the following in
journalctl output while trying to connect to a device:
a2dp-source profile connect failed for 9C:64:40:22:E1:3F: Protocol not available
try installingand restarting pulseaudio. This error can manifest even while using only file transfer.