Bluetooth
From ArchWiki
Contents |
Introduction
This article is about setting up and using Bluetooth with an USB Bluetooth dongle on Arch Linux.
Installation
First you have to install the bluez package for the Linux Bluetooth protocol stack and start all needed daemons.
# pacman -S bluez
It seems like dbus must be running for certain settings to be read. It is also needed (afaik) for pin pairing. It is important that dbus is started *before* bluetooth.
# /etc/rc.d/dbus start
# /etc/rc.d/bluetooth start
After that you should check if your Bluetooth dongle is recognized. You can do that by inspecting /var/log/messages.log when plugging in the USB dongle. It should look something like the following (look out for hci):
# tail -f /var/log/messages.log May 2 23:36:40 tatooine usb 4-1: new full speed USB device using uhci_hcd and address 9 May 2 23:36:40 tatooine usb 4-1: configuration #1 chosen from 1 choice May 2 23:36:41 tatooine hcid[8109]: HCI dev 0 registered May 2 23:36:41 tatooine hcid[8109]: HCI dev 0 up May 2 23:36:41 tatooine hcid[8109]: Device hci0 has been added May 2 23:36:41 tatooine hcid[8109]: Starting security manager 0 May 2 23:36:41 tatooine hcid[8109]: Device hci0 has been activated
For a list of supported hardware please refer to the resources section on this page.
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 informations 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)
Configuration
The bluez configuration files are located in /etc/bluetooth.
$ ls -1 /etc/bluetooth audio.conf hcid.conf network.conf rfcomm.conf
The default configuration file of the hcid daemon should fit most purposes. However, you probably have to change the passkey option to the one of your phone (most mobile phones use either 1234 or 0000).
# HCId options
options {
...
# Default PIN code for incoming connections
passkey "0000";
}
For some mobile phones you maybe also have to change the device class in the device section (I haven't found a comprehensive list of device classes yet, in my case the default setting worked).
# Default settings for HCI devices
device {
...
# Local device class
class 0x000100;
...
}
Pairing
Many bluetooth devices require pairing. (Wikipedia entry) The exact procedure depends among other on the devices involved, and their input functionality. The procedure on a mobile may be as follows:
- The computer sends a connect request to the mobile.
- A pin, determined by the computer, is prompted for at the mobile
- The same key must be re-entered at the computer.
To scan for external devices, do
$> hcitool scan
To pair with a device without using the gnome-bluez package you will need to use a tool named bluez-simple-agent that comes with the bluez package. You need a few python related packages from the regular repositories to get this to run: dbus-python and pygobject. If you have everything ready you can start the script from the root user:
$> bluez-simple-agent
If it all works, you should get the message "Agent registered" on that console. You can now start pairing from your mobile device, and the script will ask you for the passcode on this console, you type it and confirm with enter - voila that's all. You can now also shut down the agent using ^C-c, you need it only for pairing, not every time you want to connect.
For an example scroll down to the example section.
Using Obex for sending and receiving files
Using GNOME tools
Blueman
Blueman is a full featured Bluetooth manager for GNOME/GTK. Blueman is designed to provide simple, yet effective means for controlling BlueZ API and simplifying Bluetooth. For installation instructions see the Blueman article.
bluez-gnome
First install the package:
# pacman -S bluez-gnome
Then run this for a nice Bluetooth applet:
$ bluetooth-applet
Now you should be able to setup devices and send files by right-clicking the Bluetooth icon. Note that bluez-gnome doesn't add support for receiving files.
To add a Bluetooth entry to the SendTo menu in Thunar's file properties menu, see: http://thunar.xfce.org/pwiki/documentation/sendto_menu
gnome-bluetooth
Install gnome-bluetooth:
# pacman -S gnome-bluetooth
Then run this to be able to receive files:
$ gnome-obex-server
A blue tray icon will appear. Now you should be able to send files to your Arch box, where a receive dialog will appear and you can choose to accept them or not.
Browse Device
TODO
At present, "Browse Device" function of bluetooth tray icon (bluez-gnome) doesn't work, It only shows a blank nautilus window. It is said that gnome-vfs-obexftp package in AUR may work, but I cannot figure it out for now.
Using Obexfs
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 Obex FTP service.
To install;
# pacman -S obexfs
and then your phone can then be mounted running as root
# obexfs -b <devices mac address> /mountpoint
For more mounting options see http://dev.zuckschwerdt.org/openobex/wiki/ObexFs
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
$> 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
$> su -c bluez-simple-agent Password: Agent registered
Back to the first console
$> obexftp -b $B -l "Address book" # 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="" /> ... $> 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 $> obexftp -b 00:01:E3:6B:FF:D7 -p a ... Sending "a"... done Disconnecting...done
Logitech Mouse MX Laser
Connect Bluetooth Logitech Mouse MX Laser without Dongle.
$> hidd --connect XX:XX:XX:XX:XX:XX
Troubleshooting
passkey-agent
$> passkey-agent --default 1234 Can't register passkey agent The name org.bluez was not provided by any .service files
You probably started /etc/rc.d/bluetooth before /etc/rc.d/dbus
$> hciconfig dev # (no listing)
Try running hciconfig hc0 up
bluez-gnome
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 run:
# pacman -S xdg-user-dirs $ xdg-user-dirs-update
You can edit the paths using:
$ vi ~/.config/user-dirs.dirs