Difference between revisions of "Bluetooth"

From ArchWiki
Jump to: navigation, search
(GNOME Bluetooth)
(hcitool scan: Device not found: improved wording)
(48 intermediate revisions by 20 users not shown)
Line 5: Line 5:
 
[[fr:Bluetooth]]
 
[[fr:Bluetooth]]
 
[[it:Bluetooth]]
 
[[it:Bluetooth]]
 +
[[ja:Bluetooth]]
 
[[ru:Bluetooth]]
 
[[ru:Bluetooth]]
 
[[zh-CN:Bluetooth]]
 
[[zh-CN:Bluetooth]]
{{Article summary start}}
+
{{Related articles start}}
{{Article summary text|Covers the installation and use of Bluetooth on Arch Linux.}}
+
{{Related|Bluez4}}
{{Article summary heading|Related}}
+
{{Related|Bluetooth Mouse}}
{{Article summary wiki|Bluetooth mouse configuration}}
+
{{Related|Bluetooth mouse configuration}}
{{Article summary end}}
+
{{Related|Bluetooth Headset}}
 
+
{{Related|Blueman}}
{{Out of date|Several generations of various deprecated tools are mentioned. bluez4 and bluez are confused. This article needs cleanup from someone who knows what commands belong in which packages.}}
+
{{Related articles end}}
 
+
 
[http://www.bluetooth.org/ Bluetooth] is a standard for the short-range wireless interconnection of cellular phones, computers, and other electronic devices. In Linux, the canonical implementation of the Bluetooth protocol stack is [http://www.bluez.org/ BlueZ].
 
[http://www.bluetooth.org/ Bluetooth] is a standard for the short-range wireless interconnection of cellular phones, computers, and other electronic devices. In Linux, the canonical implementation of the Bluetooth protocol stack is [http://www.bluez.org/ BlueZ].
  
 
== Installation ==
 
== Installation ==
  
To use Bluetooth, [[pacman|install]] {{Pkg|bluez}} from the [[official repositories]]. The {{ic|dbus}} daemon, which is started automatically by ''systemd'', is used to read settings and for PIN pairing, while the {{ic|bluetooth}} daemon is required for the Bluetooth protocol.
+
Install the Bluetooth protocol stack {{Pkg|bluez}} and the {{Pkg|bluez-utils}} package which provides the {{ic|bluetoothctl}} utility from the [[official repositories]]. The {{ic|dbus}} daemon, which is started automatically by ''systemd'', is used to read settings and for PIN pairing, while the {{ic|bluetooth}} daemon is required for the Bluetooth protocol.  
  
Enable the ''bluetooth'' service to start it at system boot up.
+
To start the bluetooth [[systemd]] service use the command:
 +
# systemctl start bluetooth
  
Start the bluetooth [[systemd]] service.
+
To enable the bluetooth service at boot time use the command:
 +
# systemctl enable bluetooth
  
== Graphical front-ends ==
+
{{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 {{ic|/etc/dbus-1/system.d/bluetooth.conf}}.}}
  
The following packages allow for a graphical interface to customize Bluetooth.
+
{{Note|Some Bluetooth adapters are bundled with a Wi-Fi card (e.g. [http://www.intel.com/content/www/us/en/wireless-products/centrino-advanced-n-6235.html Intel Centrino]).  These require that the Wi-Fi card is first enabled (typically a keyboard shortcut on a laptop) in order to make the Bluetooth adapter visible to the kernel.}}
  
=== Blueman ===
+
== Configuration via the CLI ==
 +
=== Bluetoothctl ===
 +
Pairing a device from the shell is one of the most simplistic and reliable options.  The exact procedure depends on the devices involved and their input functionality.  What follows is a general outline of pairing a device using {{ic|/usr/bin/bluetoothctl}}:
  
{{Note|As of 2013-09-01, ''bluedevil'' depends on the older {{Pkg|bluez4}}, which conflicts with the current {{Pkg|bluez}} (v5)}}
+
Start the {{ic|bluetoothctl}} interactive command. There one can input {{ic|help}} to get a list of available commands.
 +
* Turn the power to the controller on by entering {{ic|power on}}. It is off by default.
 +
* Enter {{ic|devices}} to get the MAC Address of the device with which to pair.
 +
* Enter device discovery mode with {{ic|scan on}} command if device is not yet on the list.
 +
* Turn the agent on with {{ic|agent on}}.
 +
* Enter {{ic|pair ''MAC Address''}} to do the pairing (tab completion works).
 +
* If using a device without a PIN, one may need to manually trust the device before it can reconnect successfully. Enter {{ic|trust ''MAC Address''}} to do so.
 +
* Finally, use {{ic|connect ''MAC_address''}} to establish a connection.
  
See [[Blueman]] article.
 
 
=== GNOME Bluetooth ===
 
 
[http://live.gnome.org/GnomeBluetooth GNOME Bluetooth] is a fork of the old ''bluez-gnome'' and is focused on integration with the [[GNOME]] desktop environment. GNOME Bluetooth is required by {{Pkg|gnome-shell}}, so you should already have it installed if you are running GNOME 3. Otherwise, it can be installed with the package {{Pkg|gnome-bluetooth}}. Note that gnome-shell, gnome-bluetooth <= 3.8 depend upon {{Pkg|bluez4}}. From gnome-shell 3.10 onwards, {{Pkg|bluez}} will be supported. More information regarding the GNOME migration to ''bluez'' can be found [http://worldofgnome.org/gnome-3-10-port-to-bluez-5/ here] (June 2013 blog post).
 
 
Run {{ic|bluetooth-applet}} for a nice Bluetooth applet. In newer versions, for this to work, you might need to install {{Pkg|bluetooth-panel-applet-git}} from the AUR. You should now be able to setup devices and send files by right-clicking the Bluetooth icon. To make the applet run on login, add it to ''System > Preferences > Startup Applications''.
 
 
To add a Bluetooth entry to the ''SendTo'' menu in Thunar's file properties menu, see instructions [http://thunar.xfce.org/pwiki/documentation/sendto_menu here].
 
 
=== BlueDevil ===
 
 
{{Note|As of 2013-09-01, ''bluedevil'' depends on the older {{Pkg|bluez4}}, which conflicts with the current {{Pkg|bluez}} (v5). Additionally, {{AUR|bluedevil-git}} is not updated to fix this dependency.}}
 
 
The Bluetooth tool for [[KDE]] is [https://projects.kde.org/projects/extragear/base/bluedevil BlueDevil]. It can be installed with the package {{Pkg|bluedevil}}, available in the official repositories.
 
 
Make sure {{ic|bluetooth}} daemon is running, as described above. You should get a Bluetooth icon both in Dolphin and in the system tray, from which you can configure BlueDevil and detect Bluetooth devices by clicking the icon. You can also configure BlueDevil from the KDE System Settings
 
 
=== Fluxbox, Openbox, other WM ===
 
 
Of course you can still use the preceding applications even if GNOME, Xfce or KDE are not your desktop manager. This list should help you figuring out which application does what:
 
* bluetooth-applet -- tray icon with access to settings, pairing wizard, management of known devices
 
* /usr/lib/gnome-user-share/gnome-user-share -- needs to be running if you're about to receive files via obexBT from a paired/bonded device
 
 
if you're receiving an error during transmission and/or there's no file received add this into
 
 
{{ic|/etc/dbus-1/system.d/bluetooth.conf}}
 
  <policy user="your_user_id">
 
    <allow own="org.bluez"/>
 
    <allow send_destination="org.bluez"/>
 
    <allow send_interface="org.bluez.Agent"/>
 
  </policy>
 
 
* bluetooth-wizard - for new devices to be paired
 
* bluetooth-properties - accessible also via bluetooth-applet icon
 
* gnome-file-share-properties - permissions on receiving files via Bluetooth
 
* bluez-sendto - GUI for sending files to a remote device
 
 
== Bluez Utils ==
 
 
The package {{Pkg|bluez-utils}} contains various commands useful to configure and troubleshoot Bluetooth from the command line.
 
 
=== hciconfig ===
 
 
Print name and basic information about all the Bluetooth devices installed in the system:
 
 
{{hc|# hciconfig|
 
hci0:  Type: BR/EDR  Bus: USB
 
      BD Address: 90:4C:E5:DB:E9:77  ACL MTU: 1021:8  SCO MTU: 64:1
 
      DOWN
 
      RX bytes:484 acl:0 sco:0 events:20 errors:0
 
      TX bytes:323 acl:0 sco:0 commands:20 errors:0
 
}}
 
 
''hciconfig'' is part of the {{Pkg|bluez-utils}}  package.
 
 
To activate a device, use:
 
# hciconfig ''device-name'' up
 
 
=== hcitool ===
 
 
To scan for remote devices:
 
$ hcitool scan
 
 
== Pairing ==
 
 
Many Bluetooth devices require {{Wikipedia:Bluetooth#Pairing|pairing}}.
 
The exact procedure depends on the devices involved and their input functionality.
 
 
=== With bluez5 ===
 
 
Start the {{ic|bluetoothctl}} interactive command. There you can input {{ic|help}} to get a list of available commands.
 
* Enter {{ic|devices}} to get the MAC Address of the device with which you want to pair.
 
* Enter device discovery mode with {{ic|scan on}} command if device is not yet on the list
 
* Enter {{ic|pair ''MAC Address''}} to do the pairing.
 
* Finally, use {{ic|connect ''MAC_address''}} to establish a connection.
 
 
An example session may look this way:
 
An example session may look this way:
 
  # bluetoothctl  
 
  # bluetoothctl  
Line 131: Line 66:
 
  Pairing successful
 
  Pairing successful
 
  [CHG] Device 00:12:34:56:78:90 Connected: no
 
  [CHG] Device 00:12:34:56:78:90 Connected: no
[bluetooth]#
 
  
=== With bluez4 ===
+
In order to have the device active after a reboot, a udev rule is needed:
 +
{{ic|/etc/udev/rules.d/10-local.rules}}
 +
# Set bluetooth power up
 +
ACTION=="add", KERNEL=="hci0", RUN+="/usr/bin/hciconfig hci0 up"
  
The procedure on a mobile may be as follows:
+
After a suspend/resume-cycle, the device can be powered off automatically using something like this systemd service:
* The computer sends a connect request to the mobile.  
+
{{hc|/etc/systemd/system/bluetooth-auto-power@.service|<nowiki>
* A pin, determined by the computer, is prompted for at the mobile
+
[Unit]
* The same key must be re-entered at the computer.
+
Description=Bluetooth auto power on
 +
After=bluetooth.service sys-subsystem-bluetooth-devices-%i.device suspend.target
  
To pair with a device without using the gnome-bluez package, the ''bluez-simple-agent'' utility that comes with the bluez package can be used. This utility depends on three packages from the official repositories: {{Pkg|python2-dbus}} {{Pkg|python2-gobject}} {{Pkg|dbus-glib}}.
+
[Service]
 +
Type=oneshot
 +
#We could also do a 200 char long call to bluez via dbus. Except this does not work since bluez does not react to dbus at this point of the resume sequence and I do not know how I get this service to run at a time it does. So we just ignore bluez and force %i up using hciconfig. Welcome to the 21st century.
 +
#ExecStart=/usr/bin/dbus-send --system --type=method_call --dest=org.bluez /org/bluez/%I org.freedesktop.DBus.Properties.Set string:org.bluez.Adapter1 string:Powered variant:boolean:true
 +
ExecStart=/usr/bin/hciconfig %i up
  
First, scan for external devices:
+
[Install]
$ hcitool scan
+
WantedBy=suspend.target
 
+
Run the script as root:
+
 
+
# bluez-simple-agent
+
 
+
The message "Agent registered" should be returned, press {{ic|Ctrl+c}} to quit.
+
 
+
Below is a basic example of pairing with a specific device. The script will ask for the passcode, enter the code and confirm with enter.
+
 
+
# bluez-simple-agent hci0 00:11:22:33:AA:BB
+
 
+
{{Note|bluez-simple-agent is only needed once for pairing a device, not every time you want to connect.}}
+
 
+
See the Examples section below for pairing examples with various devices.
+
 
+
== Using Obex for sending and receiving files ==
+
 
+
Another option, rather than using KDE or Gnome Bluetooth packages, is ObexFS which allows you to mount your phone and treat it as part of your filesystem. Note that to use ObexFS, you need a device that provides an ObexFTP service.
+
 
+
Install {{Pkg|obexfs}} and then your phone can then be mounted by running
+
$ obexfs -b ''devices_MAC_address'' /mountpoint
+
 
+
For more mounting options see http://dev.zuckschwerdt.org/openobex/wiki/ObexFs
+
 
+
For devices don't 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, you can use ussp-push to send files to this device:
+
 
+
# ussp-push ''XX:XX:XX:XX:XX:XX''@''CHANNEL'' ''file'' ''wanted_file_name_on_phone''
+
 
+
== Examples ==
+
 
+
=== Siemens S55 ===
+
 
+
This is what I did to connect to my S55. (I have not figured out how to initiate the connection from the phone)
+
* The steps under installation
+
 
+
{{hc|$ hcitool scan|
+
Scanning ...
+
        ''XX:XX:XX:XX:XX:XX''  NAME
+
}}
+
$ B=''XX:XX:XX:XX:XX:XX''
+
Start the simple-agent in a second terminal:
+
{{hc|$ su -c bluez-simple-agent|
+
Password:
+
Agent registered
+
}}
+
Back to the first console:
+
{{hc|$ obexftp -b $B -l "Address book"|<nowiki>
+
# Phone ask for pin, I enter it and answer yes when asked if I want to save the device
+
...
+
<file name="5F07.adr" size="78712" modified="20030101T001858" user-perm="WD" group-perm="" />
+
...
+
 
</nowiki>}}
 
</nowiki>}}
{{hc|$ obexftp -b 00:01:E3:6B:FF:D7 -g "Address book/5F07.adr"|
 
Browsing 00:01:E3:6B:FF:D7 ...
 
Channel: 5
 
Connecting...done
 
Receiving "Address book/5F07.adr"... Sending "Address book"... done
 
Disconnecting...done
 
}}
 
{{hc|$ obexftp -b 00:01:E3:6B:FF:D7 -p a|
 
...
 
Sending "a"... done
 
Disconnecting...done
 
}}
 
  
=== Logitech mouse MX Laser / M555b ===
+
== Configuration with a Graphical Front-end ==
  
To quickly test the connection:
+
The following packages allow for a graphical interface to customize Bluetooth.
  
$ hidd --connect ''XX:XX:XX:XX:XX:XX''
+
=== GNOME Bluetooth ===
  
For automated reconnection, use your desktop wizard to configure the bluetooth mouse.
+
[https://wiki.gnome.org/Projects/GnomeBluetooth GNOME Bluetooth] is a fork of the old ''bluez-gnome'' and is focused on integration with the [[GNOME]] desktop environment. The {{Pkg|gnome-bluetooth}} package provides the back-end, {{Pkg|gnome-shell}} provides the status monitor applet, and {{Pkg|gnome-control-center}} provides the configuration front-end GUI that can be accessed by typing Bluetooth on the Activities overview, or with the {{ic|gnome-control-center bluetooth}} command.
If your desktop environment doesn't includes support for this task, see the [[Bluetooth mouse manual configuration]] guide.
+
  
=== Motorola V900 ===
+
Users who are not using GNOME Shell can install {{AUR|gnome-bluetooth-applet-git}} from AUR, which provides the old status monitor applet, and allows setup devices and transfer of files by clicking the Bluetooth icon. Just make sure that {{ic|bluetooth-applet}} is [[autostart|autostarted]] with your session.
  
After installing [[Blueman]] and running ''blueman-applet'', click "find me" under ''connections > bluetooth'' in Motorola device. In ''blueman-applet'', scan devices, find the Motorola, click "add". Click "bond" in ''blueman-applet'', enter some PIN, enter the same PIN in Motorola when it asks. In terminal:
+
You can also launch the following commands directly:
 +
* {{ic|bluetooth-sendto}}: send files to a remote device
 +
* {{ic|bluetooth-wizard}}: for new devices to be paired
  
{{bc|
+
To add a Bluetooth entry to the ''SendTo'' menu in Thunar's file properties menu, see instructions [http://docs.xfce.org/xfce/thunar/send-to here]. (The command that needs to be configured is {{ic|bluetooth-sendto %F}})
$ mkdir ~/bluetooth-temp
+
$ obexfs -n ''XX:XX:XX:XX:XX:XX'' ~/bluetooth-temp
+
$ cd ~/bluetooth-temp
+
}}
+
  
and browse... Only audio, video, and pictures are available when you do this.
+
=== BlueDevil ===
  
=== Motorola RAZ ===
+
The Bluetooth tool for [[KDE]] is [https://projects.kde.org/projects/extragear/base/bluedevil BlueDevil]. It can be installed with the package {{Pkg|bluedevil}}, available in the official repositories.
  
Install {{Pkg|obextool}} {{Pkg|obexfs}} {{Pkg|obexftp}} {{Pkg|openobex}} {{Pkg|bluez}}.
+
Make sure {{ic|bluetooth}} daemon is running, as described above. A Bluetooth icon should be visible in both Dolphin and in the system tray, from which users may configure BlueDevil and detect Bluetooth devices by clicking the icon.  An interface is also available from the KDE System Settings.
  
{{hc|# lsusb|
+
== Using Obex for sending and receiving files ==
Bus 005 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub
+
=== ObexFS ===
Bus 004 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub
+
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.
Bus 003 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub
+
{{Note|To use ObexFS, one needs a device that provides an ObexFTP service.}}
Bus 002 Device 002: ID 03f0:171d Hewlett-Packard Wireless (Bluetooth + WLAN) Interface [Integrated Module]
+
Bus 002 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub
+
Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
+
}}
+
  
  # hciconfig hci0 up
+
Install {{Pkg|obexfs}} and mount supported phones by running:
 +
  $ obexfs -b ''devices_MAC_address'' /mountpoint
  
{{hc|# hciconfig|
+
Once you have finished, to unmount the device use the command:
hci0:   Type: BR/EDR  Bus: USB
+
  $ fusermount -u /mountpoint
        BD Address: 00:16:41:97:BA:5E ACL MTU: 1017:8  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
+
}}
+
  
{{hc|# hcitool dev|
+
For more mounting options see http://dev.zuckschwerdt.org/openobex/wiki/ObexFs
Devices:
+
        hci0    00:16:41:97:BA:5E
+
}}
+
  
Make sure that bluetooth on your phone is enabled and your phone is visible!
+
{{Note|Ensure that the bluetooth device you are mounting is '''not''' set to mount ''read-only''. You should be able to do this from the device's settings. If the device is mounted ''read-only'' you may encounter a permissions error when trying to transfer files to the device.}}
  
{{hc|# hcitool scan|
+
=== ObexFTP Transfers ===
Scanning ...
+
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.
        00:1A:1B:82:9B:6D      [quirxi]
+
}}
+
  
{{hc|# hcitool inq|
+
{{Tip|If you installed {{pkg|obexfs}} earlier then {{pkg|obexftp}} should have also been installed as a dependency.}}
Inquiring ...
+
        00:1A:1B:82:9B:6D      clock offset: 0x1ee4    class: 0x522204
+
}}
+
  
{{hc|# l2ping 00:1A:1B:82:9B:6D|
+
To send a file to a device run the command:
Ping: 00:1A:1B:82:9B:6D from 00:16:41:97:BA:5E (data size 44) ...
+
44 bytes from 00:1A:1B:82:9B:6D id 0 time 23.94ms
+
44 bytes from 00:1A:1B:82:9B:6D id 1 time 18.85ms
+
44 bytes from 00:1A:1B:82:9B:6D id 2 time 30.88ms
+
44 bytes from 00:1A:1B:82:9B:6D id 3 time 18.88ms
+
44 bytes from 00:1A:1B:82:9B:6D id 4 time 17.88ms
+
44 bytes from 00:1A:1B:82:9B:6D id 5 time 17.88ms
+
6 sent, 6 received, 0% loss
+
}}
+
  
{{hc|# hcitool name 00:1A:1B:82:9B:6D|
+
$ obexftp -b ''devices_MAC_address'' -p /path/to/file
[quirxi]
+
}}
+
  
{{hc|# hciconfig -a hci0|
+
To retrieve a file from a device run the command:
hci0:  Type: BR/EDR  Bus: USB
+
        BD Address: 00:16:41:97:BA:5E  ACL MTU: 1017:8  SCO MTU: 64:8
+
        UP RUNNING
+
        RX bytes:9740 acl:122 sco:0 events:170 errors:0
+
        TX bytes:2920 acl:125 sco:0 commands:53 errors:0
+
        Features: 0xff 0xff 0x8d 0xfe 0x9b 0xf9 0x00 0x80
+
        Packet type: DM1 DM3 DM5 DH1 DH3 DH5 HV1 HV2 HV3
+
        Link policy:
+
        Link mode: SLAVE ACCEPT
+
        Name: 'BCM2045'
+
        Class: 0x000000
+
        Service Classes: Unspecified
+
        Device Class: Miscellaneous,
+
        HCI Version: 2.0 (0x3)  Revision: 0x204a
+
        LMP Version: 2.0 (0x3)  Subversion: 0x4176
+
        Manufacturer: Broadcoml / Corporation (15)
+
}}
+
  
{{hc|# hcitool info 00:1A:1B:82:9B:6D|
+
  $ obexftp -b ''devices_MAC_address'' -g filename
Requesting information ...
+
        BD Address: 00:1A:1B:82:9B:6D
+
        Device Name: [quirxi]
+
        LMP Version: 1.2 (0x2) LMP Subversion: 0x309
+
        Manufacturer: Broadcom Corporation (15)
+
        Features: 0xff 0xfe 0x0d 0x00 0x08 0x08 0x00 0x00
+
                <3-slot packets> <5-slot packets> <encryption> <slot offset>
+
                <timing accuracy> <role switch> <hold mode> <sniff mode>
+
                <RSSI> <channel quality> <SCO link> <HV2 packets>
+
                <HV3 packets> <A-law log> <CVSD> <power control>
+
                <transparent SCO> <AFH cap. slave> <AFH cap. master>
+
}}
+
  
Edit your {{ic|/etc/bluetooth/main.conf}} and enter the proper class for your phone ( Class = 0x100100 ):
+
{{Note|Ensure that the file you are retrieving is in the device's ''exchange folder''. If the file is in a subfolder of the exchange folder then provide the correct path in the command.}}
{{bc|<nowiki>
+
# Default device class. Only the major and minor device class bits are
+
# considered.
+
#Class = 0x000100
+
Class =  0x100100
+
</nowiki>}}
+
  
{{hc|# systemctl start bluetooth|
+
=== Obex Object Push ===
:: Stopping bluetooth subsystem:  pand dund rfcomm hidd  bluetoothd
+
For devices that do not support Obex FTP service, check if Obex Object Push is supported.
[DONE]
+
:: Starting bluetooth subsystem:  bluetoothd
+
}}
+
  
Pairing with bluez-simple-agent only has to be done once. On your Motorola phone give 0000 in as your PIN when phone asks for it!
+
# sdptool browse ''XX:XX:XX:XX:XX:XX''
{{hc|/usr/bin/bluez-simple-agent hci0 00:1A:1B:82:9B:6D|
+
RequestPinCode (/org/bluez/10768/hci0/dev_00_1A_1B_82_9B_6D)
+
Enter PIN Code: 0000
+
Release
+
New device (/org/bluez/10768/hci0/dev_00_1A_1B_82_9B_6D)
+
}}
+
  
Now you can browse the filesystem of your phone with obexftp:
+
Read the output, look for Obex Object Push, remember the channel for this service.  If supported, one can use {{pkg|ussp-push}} to send files to this device:
{{hc|obexftp -v -b 00:1A:1B:82:9B:6D -B 9 -l|<nowiki>
+
Connecting..\done
+
Tried to connect for 448ms
+
Receiving "(null)"...-<?xml version="1.0" ?>
+
<!DOCTYPE folder-listing SYSTEM "obex-folder-listing.dtd">
+
<folder-listing>
+
<parent-folder />
+
<folder name="audio" size="0" type="folder" modified="20101010T132323Z" user-perm="RW" />
+
<folder name="video" size="0" type="folder" modified="20101010T132323Z" user-perm="RW" />
+
<folder name="picture" size="0" type="folder" modified="20101010T132323Z" user-perm="RW" />
+
</folder-listing>
+
done
+
Disconnecting..\done
+
</nowiki>}}
+
  
Or you can mount your phone into a directory on your computer and treat it like a normal file system:
+
# ussp-push ''XX:XX:XX:XX:XX:XX''@''CHANNEL'' ''file'' ''wanted_file_name_on_phone''
{{bc|
+
# groupadd bluetooth
+
# mkdir /mnt/bluetooth
+
# chown root:bluetooth /mnt/bluetooth
+
# chmod 775 /mnt/bluetooth
+
# usermod -a -G bluetooth arno
+
# obexfs -b 00:1A:1B:82:9B:6D /mnt/bluetooth/
+
}}
+
  
=== Pairing with an iPhone using bluez-simple-agent ===
+
== Examples ==
  
Assuming a bluetooth device called hci0 and an iPhone that showed up in a hcitool scan as '00:00:DE:AD:BE:EF':
+
All examples have been moved to the [[bluez4]] article. They need to be checked and fixed for use with bluez5.
 
+
# bluez-simple-agent hci0 00:00:DE:AD:BE:EF
+
Passcode:
+
 
+
=== Headset and ALSA devices ===
+
 
+
==== by referencing the bluetooth device in asound.conf ====
+
 
+
1. Scan for your device:
+
$ hcitool (-i ''optional hci#''***) scan
+
2. Pair your headset with your device:
+
$ bluez-simple-agent (optional hci# ***) XX:XX:XX:XX:XX:XX
+
  and put in your PIN (0000 or 1234, etc)
+
3. Add this to your {{ic|/etc/asound.conf}} file:
+
 
+
{{bc|
+
pcm.btheadset {
+
  type plug
+
  slave {
+
      pcm {
+
          type bluetooth
+
          device XX:XX:XX:XX:XX:XX
+
          profile "auto"
+
      }
+
  }
+
  hint {
+
      show on
+
      description "BT Headset"
+
  }
+
}
+
ctl.btheadset {
+
  type bluetooth
+
}
+
}}
+
 
+
4. Check to see if it has been added to ALSA devices
+
$ aplay -L
+
 
+
5. Now play with ''aplay'':
+
$ aplay -D btheadset ''/path/to/audio/file''
+
 
+
or MPlayer:
+
$ mplayer -ao alsa:device=btheadset ''/path/to/audio/or/video/file''
+
 
+
To find hci# for a usb dongle, type in:
+
$ hcitool dev
+
 
+
==== by using bluez-tools from the AUR ====
+
 
+
You can use {{AUR|bluez-tools}} from the [[AUR]] with PulseAudio to stream audio to a bluetooth headset.
+
Find the MAC of the headset:
+
$ hcitool scan
+
Connect to the headset:
+
$ bt-audio -c XX:XX:XX:XX:XX:XX
+
Open pulseaudio volume control:
+
$ pavucontrol
+
The headset should show up in the Configuration tab.
+
 
+
=== Microsoft Bluetooth Mobile Keyboard 6000 ===
+
 
+
1. Scan for your device
+
$ hcitool (-i ''optional_hci#''***) scan
+
Scanning ...
+
        00:11:22:33:44:55      Microsoft Bluetooth Mobile Keyboard 6000
+
 
+
2. On second console run as root (do not terminate):
+
# bluez-simple-agent
+
Agent registered
+
 
+
3. Back on first console run:
+
$ bluez-simple-agent hci0 00:11:22:33:44:55
+
Enter PIN Code: 1234
+
(now enter that PIN on the keyboard and press enter)
+
Release
+
New device (/org/bluez/5373/hci0/dev_00_11_22_33_44_55)
+
 
+
4.
+
$ bluez-test-device trusted 00:11:22:33:44:55
+
 
+
5.
+
$ bluez-test-input connect 00:11:22:33:44:55
+
 
+
No your keyboard should work. You can terminate ''bluez-simple-agent'' on second console with {{ic|Ctrl+C}}
+
  
 
== Troubleshooting ==
 
== Troubleshooting ==
 
=== passkey-agent ===
 
 
$ passkey-agent --default 1234
 
Can't register passkey agent
 
The name org.bluez was not provided by any .service files
 
and
 
$ hciconfig dev
 
# (no listing)
 
Try running {{ic|hciconfig hc0 up}}
 
  
 
=== gnome-bluetooth ===
 
=== gnome-bluetooth ===
Line 481: Line 167:
 
=== 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 inspecting {{ic|/var/log/messages.log}} when plugging in the USB dongle (or running {{ic|journalctl -f}} with systemd). 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}} when plugging in the USB dongle (or inspecting {{ic|/var/log/messages.log}}). It should look something like the following (look out for hci):
  
 
{{bc|
 
{{bc|
Line 527: Line 213:
 
}}
 
}}
  
More detailed informations about the device can be retrieved by using {{ic|hciconfig}}.
+
More detailed information about the device can be retrieved by using {{ic|hciconfig}}.
  
 
{{hc|$ hciconfig -a hci0|
 
{{hc|$ hciconfig -a hci0|
Line 555: Line 241:
 
=== hcitool scan: Device not found ===
 
=== hcitool scan: Device not found ===
  
* On some Dell laptops (e.g. Studio 15) you have to switch the Bluetooth mode from HID to HCI using
+
* On some Dell laptops (e.g. Studio 15) you have to switch the Bluetooth mode from HID to HCI. Install the {{Pkg|bluez-hid2hci}} package, then [[udev]] should do this automatically. Alternatively, you can run this command to switch to HCI manually:
  # hid2hci
+
  # /usr/lib/udev/hid2hci
  
{{Note|hid2hci is no longer in the $PATH, it is under /lib/udev/hid2hci, but udev should run it automatically for you.}}
+
* 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.
 
+
* If the device won't 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:
 
* Sometimes also this simple command helps:
Line 574: Line 258:
 
=== My computer is not visible ===
 
=== My computer is not visible ===
  
Can't discover computer from your phone? Enable PSCAN and ISCAN:
+
Cannot discover computer from your phone? Enable PSCAN and ISCAN:
 
  # enable PSCAN and ISCAN
 
  # enable PSCAN and ISCAN
 
  $ hciconfig hci0 piscan  
 
  $ hciconfig hci0 piscan  
Line 594: Line 278:
 
  Class = 0x100100
 
  Class = 0x100100
  
This was the only solution to make my computer visible for my phone.  
+
This was the only solution to make my computer visible for my phone.
 
+
=== Nautilus cannot browse files ===
+
 
+
If nautilus doesn't open and show this error:
+
Nautilus cannot handle obex: locations. Couldn't display "obex://[XX:XX:XX:XX:XX:XX]/".
+
Install {{Pkg|gvfs-obexftp}} package.
+
 
+
=== Sennheiser MM400 headset connection problems ===
+
 
+
If your {{ic|Sennheiser MM400 Headset}} immediately disconnects after connecting as {{ic|Headset Service}} with Blueman, try to connect it as {{ic|Audio Sink}}. Afterwards you can change the headset's {{ic|Audio Profile}} to {{ic|Telephony Duplex}} with a right click in Blueman.
+
With this option headset functionality will be available although the headset was only connected as {{ic|Audio Sink}} in first place and no disconnection will happen (tested with bluez 4.96-3, pulseaudio 1.1-1 and blueman 1.23-2).
+
 
+
=== My device is paired but no sound is played from it ===
+
 
+
Try to first inspect {{ic|/var/log/messages.log}}. If you see such messages:
+
{{bc|
+
Jan 12 20:08:58 localhost pulseaudio[1584]: [pulseaudio] module-bluetooth-device.c: Service not connected
+
Jan 12 20:08:58 localhost pulseaudio[1584]: [pulseaudio] module-bluetooth-device.c: Bluetooth audio service not available
+
}}
+
try first:
+
# pactl load-module module-bluetooth-device
+
 
+
If the module fails to work, do this workaround:
+
Open {{ic|/etc/bluetooth/audio.conf}} and add after '''[General]''' (on a new line)
+
Enable=Socket
+
Then restart the bluetooth daemon.
+
Pair again your device, and you should find it in the pulseaudio settings (advanced settings for the sound)
+
  
[http://wiki.gentoo.org/index.php?title=Bluetooth_Headset&redirect=no More information on Gentoo Wiki]
+
=== Logitech keyboard does not pair ===
  
If after fixing this you still can't get sound, try using blueman (this is the only one that works for me), make sure that notify-osd is installed or it might show you weird error messages like this one: "Stream setup failed"
+
If you do not get the passkey when you try to pair your Logitech keyboard, type the following command:
 +
$ sudo hciconfig hci0 sspmode 0
  
fail (/usr/lib/python2.7/site-packages/blueman/gui/manager/ManagerDeviceMenu.py:134)
+
If after pairing, the keyboard still does not connect, check the output of {{ic|hcidump -at}}. If the latter indicates repeatedly connections-disconnections like the following message:
fail (DBusException(dbus.String(u'Stream setup failed'),),)
+
  
== See also ==
+
    status 0x00 handle 11 reason 0x13
 +
    Reason: Remote User Terminated Connection
  
* [http://www.gentoo.org/doc/en/bluetooth-guide.xml Gentoo Linux Bluetooth guide]
+
then, the only solution for now is to install [[bluez4|the old Bluetooth stack]].
* [http://en.opensuse.org/HCL:Bluetooth openSUSE Bluetooth hardware compatibility list]
+
* [http://linuxgazette.net/109/oregan3.html Accessing a Bluetooth phone (Linux Gazette)]
+
* [http://www.adamish.com/blog/#a000361 Bluetooth computer visibility]
+
* [http://www.elstel.org/MobilePhone.html Bluetooth for your mobile phone: Bluetooth pairing, data synchronization, photo download, Internet Dial-Up (tethering)]
+
* [http://www.elstel.org/MobilePhone.html Bluetooth pairing and applications for synchronizing phone numbers, SMS-messages, phone call entries, your calendar and time; tethering]
+

Revision as of 13:16, 28 February 2014

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

Install the Bluetooth protocol stack bluez and the bluez-utils package which provides the bluetoothctl utility from the official repositories. The dbus daemon, which is started automatically by systemd, is used to read settings and for PIN pairing, while the bluetooth daemon is required for the Bluetooth protocol.

To start the bluetooth systemd service use the command:

# systemctl start bluetooth

To enable the bluetooth service at boot time use the command:

# systemctl enable bluetooth
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 /etc/dbus-1/system.d/bluetooth.conf.
Note: Some Bluetooth adapters are bundled with a Wi-Fi card (e.g. Intel Centrino). These require that the Wi-Fi card is first enabled (typically a keyboard shortcut on a laptop) in order to make the Bluetooth adapter visible to the kernel.

Configuration via the CLI

Bluetoothctl

Pairing a device from the shell is one of the most simplistic and 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 /usr/bin/bluetoothctl:

Start the bluetoothctl interactive command. There one can input help to get a list of available commands.

  • Turn the power to the controller on by entering power on. It is off by default.
  • Enter devices to get the MAC Address of the device with which to pair.
  • Enter device discovery mode with scan on command if device is not yet on the list.
  • Turn the agent on with agent on.
  • Enter pair MAC Address to do the pairing (tab completion works).
  • If using a device without a PIN, one may need to manually trust the device before it can reconnect successfully. Enter trust MAC Address to do so.
  • Finally, use connect MAC_address to establish a connection.

An example session may look this way:

# bluetoothctl 
[NEW] Controller 00:10:20:30:40:50 pi [default]
[bluetooth]# agent KeyboardOnly 
Agent registered
[bluetooth]# default-agent 
Default agent request successful
[bluetooth]# 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

In order to have the device active after a reboot, a udev rule is needed: /etc/udev/rules.d/10-local.rules

# Set bluetooth power up
ACTION=="add", KERNEL=="hci0", RUN+="/usr/bin/hciconfig hci0 up"

After a suspend/resume-cycle, the device can be powered off automatically using something like this systemd service:

/etc/systemd/system/bluetooth-auto-power@.service
[Unit]
Description=Bluetooth auto power on
After=bluetooth.service sys-subsystem-bluetooth-devices-%i.device suspend.target

[Service]
Type=oneshot
#We could also do a 200 char long call to bluez via dbus. Except this does not work since bluez does not react to dbus at this point of the resume sequence and I do not know how I get this service to run at a time it does. So we just ignore bluez and force %i up using hciconfig. Welcome to the 21st century.
#ExecStart=/usr/bin/dbus-send --system --type=method_call --dest=org.bluez /org/bluez/%I org.freedesktop.DBus.Properties.Set string:org.bluez.Adapter1 string:Powered variant:boolean:true
ExecStart=/usr/bin/hciconfig %i up

[Install]
WantedBy=suspend.target

Configuration with a Graphical Front-end

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

GNOME Bluetooth

GNOME Bluetooth is a fork of the old bluez-gnome and is focused on integration with the GNOME desktop environment. The gnome-bluetooth package provides the back-end, gnome-shell provides the status monitor applet, and 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.

Users who are not using GNOME Shell can install gnome-bluetooth-applet-gitAUR from AUR, which provides the old status monitor applet, and allows setup devices and transfer of files by clicking the Bluetooth icon. Just make sure that bluetooth-applet is autostarted with your session.

You can also launch the following commands directly:

  • bluetooth-sendto: send files to a remote device
  • bluetooth-wizard: for new devices to be paired

To add a Bluetooth entry to the SendTo menu in Thunar's file properties menu, see instructions here. (The command that needs to be configured is bluetooth-sendto %F)

BlueDevil

The Bluetooth tool for KDE is BlueDevil. It can be installed with the package bluedevil, available in the official repositories.

Make sure bluetooth daemon is running, as described above. A Bluetooth icon should be visible in both Dolphin and in the system tray, from which users may configure BlueDevil and detect Bluetooth devices by clicking the icon. An interface is also available from the KDE System Settings.

Using Obex for sending and receiving files

ObexFS

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.

Note: To use ObexFS, one needs a device that provides an ObexFTP service.

Install obexfs and mount supported phones by running:

$ obexfs -b devices_MAC_address /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

Note: Ensure that the bluetooth device you are mounting is not set to mount read-only. You should be able to do this from the device's settings. If the device is mounted read-only you may encounter a permissions error when trying to transfer files to the device.

ObexFTP Transfers

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.

Tip: If you installed obexfs earlier then obexftp should have also been installed as a dependency.

To send a file to a device run the command:

$ obexftp -b devices_MAC_address -p /path/to/file

To retrieve a file from a device run the command:

$ obexftp -b devices_MAC_address -g filename
Note: Ensure that the file you are retrieving is in the device's exchange folder. If the file is in a subfolder of the exchange folder then provide the correct path in the command.

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 use ussp-push to send files to this device:

# ussp-push XX:XX:XX:XX:XX:XX@CHANNEL file wanted_file_name_on_phone

Examples

All examples have been moved to the bluez4 article. They need to be checked and fixed for use with bluez5.

Troubleshooting

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 install xdg-user-dirs and issue:

$ xdg-user-dirs-update

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

For a list of supported hardware please refer to the Resource section on this page.

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.

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

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

hcitool scan: Device not found

  • On some Dell laptops (e.g. Studio 15) you have to switch the Bluetooth mode from HID to HCI. Install the bluez-hid2hci package, then udev should do this automatically. Alternatively, you can run this command to switch to HCI manually:
# /usr/lib/udev/hid2hci
  • If the device will not show up and you have a Windows operating system on your machine, try booting it and enable the bluetooth adapter from windows.
  • 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
$ hciconfig
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
Note: Check DiscoverableTimeout and PairableTimeout in /etc/bluetooth/main.conf

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:

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