Gentoo Linux Bluetooth Guide
From http://www.gentoo.org/doc/en/bluetooth-guide.xml
----------------------------------------------------------------------------------------------------
1. Introduction
What is Bluetooth?
Bluetooth is an industrial specification that provides users a way to connect and exchange information between devices like personal computers, PDAs or mobile phones. Using the Bluetooth technology, users can achieve wireless voice and data transmission between devices at a low cost. Bluetooth also offers the possibility to create small wireless LANs and to synchronize devices.
About the content of this guide
The first part of this guide is to identify qualified and non-qualified devices that support the Bluetooth technology. This way, users can purchase Bluetooth devices that are known to work. After that, the guide explains how to configure the system kernel, identify the Bluetooth devices installed on the system and detected by the kernel and install the necessary basic Bluetooth tools.
The second part covers how to detect remote devices and how to establish a connection from or to them by either setting up radio frequency communication (RFCOMM) or by setting up a personal area network (PAN).
The last part of the guide lists in detail applications that can take advantage of all the possibilities offered by the Bluetooth technology.
2. Supported Devices
Qualified and non-qualified devices that support Bluetooth
Important: These products might work even though some are not qualified Bluetooth products. Gentoo does not support them in any way, they might just work. |
A list of the currently supported devices can be found at: Bluetooth device features and revision information by Marcel Holtmann.
3. Configuring the system
Kernel Configuration
As the latest Linux stable kernel is 2.6, the configuration will be done for these series of the kernel. Most Bluetooth devices are connected to a USB port, so USB will be enabled too. Please refer to the Gentoo Linux USB Guide.
Code Listing 3.1: Configuration for 2.6 kernels |
Networking --->
<*> Bluetooth subsystem support --->
--- Bluetooth subsystem support
<M> L2CAP protocol support
<M> SCO links support
<M> RFCOMM protocol support
[*] RFCOMM TTY support
<M> BNEP protocol support
[*] Multicast filter support
[*] Protocol filter support
<M> HIDP protocol support
Bluetooth device drivers --->
<M> HCI USB driver
[*] SCO (voice) support
<M> HCI UART driver
[*] UART (H4) protocol support
[*] BCSP protocol support
[*] Transmit CRC with every BCSP packet
<M> HCI BCM203x USB driver
<M> HCI BPA10x USB driver
<M> HCI BlueFRITZ! USB driver
<M> HCI DTL1 (PC Card) driver
<M> HCI BT3C (PC Card) driver
<M> HCI BlueCard (PC Card) driver
<M> HCI UART (PC Card) device driver
<M> HCI VHCI (Virtual HCI device) driver
USB support --->
<*> Support for Host-side USB
--- USB Host Controller Drivers
<M> EHCI HCD (USB 2.0) support
[ ] Full speed ISO transactions (EXPERIMENTAL)
[ ] Root Hub Transaction Translators (EXPERIMENTAL)
<*> OHCI HCD support
<*> UHCI HCD (most Intel and VIA) support
< > SL811HS HCD support
|
Now we'll reboot with our new kernel. If everything went fine, we will have a system that is Bluetooth ready.
Important: Your USB device may have two modes the default of which may not be HCI, but HID. If this is your case, use hid2hci to switch to HCI mode. Your system will not remember this change when you next reboot. |
Code Listing 3.2: Checking the Bluetooth devices |
# cat /proc/bus/usb/devices | grep -e^[TPD] | grep -e Cls=e0 -B1 -A1
T: Bus=02 Lev=02 Prnt=03 Port=00 Cnt=01 Dev#= 4 Spd=12 MxCh= 0
D: Ver= 1.10 Cls=e0(unk. ) Sub=01 Prot=01 MxPS=64 #Cfgs= 1
P: Vendor=0a12 ProdID=0001 Rev= 5.25
# lsusb
Bus 003 Device 002: ID 046d:c00e Logitech, Inc. Optical Mouse
Bus 003 Device 001: ID 0000:0000
Bus 002 Device 002: ID 0db0:1967 Micro Star International Bluetooth Dongle
|
4. BlueZ - The Bluetooth Stack
Installing BlueZ
Now that the device is detected by the kernel, we need a layer that lets applications communicate with the Bluetooth device. BlueZ provides the official Linux Bluetooth stack. The ebuilds that provide what we need are bluez-libs and bluez-utils. Devices that need Broadcom firmware files or the like may need bluez-firmware.
Code Listing 4.1: Installing bluez-libs and bluez-utils |
# emerge net-wireless/bluez-libs net-wireless/bluez-utils
|
BlueZ configuration and PIN pairing
Now it's time to see if the Bluetooth device is being picked up correctly by the system. We start up the required Bluetooth services first.
Code Listing 4.2: Running hciconfig |
# /etc/init.d/bluetooth start
* Starting Bluetooth ...
* Starting hcid ... [ ok ]
* Starting sdpd ... [ ok ]
* Starting rfcomm ... [ ok ]
# hciconfig
hci0: Type: USB
BD Address: 00:01:02:03:04:05 ACL MTU: 192:8 SCO MTU: 64:8
DOWN
RX bytes:131 acl:0 sco:0 events:18 errors:0
TX bytes:565 acl:0 sco:0 commands:17 errors:0
|
This shows that the Bluetooth device has been recognised. As you might have noticed the device is DOWN. Let's configure it so that we can bring it up. The configuration file is at /etc/bluetooth/hcid.conf. The required changes to the config file are shown below. For additional details please refer to man hcid.conf.
Code Listing 4.3: Editing /etc/bluetooth/hcid.conf |
# HCId options
options {
# Automatically initialize new devices
autoinit yes;
# Security Manager mode
# none - Security manager disabled
# auto - Use local PIN for incoming connections
# user - Always ask user for a PIN
#
security auto;
# Pairing mode
pairing multi;
# PIN helper
pin_helper /etc/bluetooth/pin-helper;
}
# Default settings for HCI devices
device {
# Local device name
# %d - device id
# %h - host name
name "BlueZ at %h (%d)";
# Local device class
class 0x3e0100;
# Inquiry and Page scan
iscan enable; pscan enable;
# Default link mode
lm accept;
# Default link policy
lp rswitch,hold,sniff,park;
# Authentication and Encryption (Security Mode 3)
#auth enable;
#encrypt enable;
}
|
After that, we have to configure the Bluetooth device PIN. That will help in pairing this device with another one.
Code Listing 4.4: Editing /etc/bluetooth/pin |
123456
|
Important: This number (of your choice) must be the same in all your hosts with Bluetooth devices so they can be paired. This number must also be kept secret since anyone with knowledge of this number can essentially establish connections with your devices. |
Note: If you are using <=bluez-libs-2.x and <=bluez-utils-2.x you can choose from different pin helpers, depending on what you want to use. Available pin helpers are: /usr/lib/kdebluetooth/kbluepin (net-wireless/kdebluetooth), /usr/bin/bluepin or /etc/bluetooth/pin-helper among others. |
Note: Beginning with >=bluez-libs-3.x and >=bluez-utils-3.x, pin helpers have been replaced by passkey agents. There are a few different graphical passkey agents available to help manage your PIN, such as bluez-gnome and kdebluetooth. You can also use passkey-agent (found in bluez-utils) from the command line. |
Services configuration
Now that we have concluded with the configuration of BlueZ, it's time to restart the necessary services.
Code Listing 4.5: Starting the Bluetooth daemons |
# /etc/init.d/bluetooth restart
# rc-update add bluetooth default
* bluetooth added to runlevel default
* rc-update complete.
|
Let's be sure that the Bluetooth daemons started correctly. If we can see that both hcid and sdpd are running, then we configured Bluetooth the right way. After that, we can see if the devices are now up and running with the configured options.
Code Listing 4.6: Checking whether Bluetooth daemons started correctly |
# ps -ae | grep hcid
26050 ? 00:00:00 hcid
# ps -ae | grep sdpd
26054 ? 00:00:00 sdpd
# hciconfig -a
hci0: Type: USB
BD Address: 00:0A:0B:0C:0D:0E ACL MTU: 192:8 SCO MTU: 64:8
UP RUNNING PSCAN ISCAN
RX bytes:125 acl:0 sco:0 events:17 errors:0
TX bytes:565 acl:0 sco:0 commands:17 errors:0
Features: 0xff 0xff 0x0f 0x00 0x00 0x00 0x00 0x00
Packet type: DM1 DM3 DM5 DH1 DH3 DH5 HV1 HV2 HV3
Link policy: RSWITCH HOLD SNIFF PARK
Link mode: SLAVE ACCEPT
Name: 'BlueZ at bluehat (0)'
Class: 0x3e0100
Service Classes: Networking, Rendering, Capturing, Object Transfer,
Audio
Device Class: Computer, Uncategorized
HCI Ver: 1.1 (0x1) HCI Rev: 0x1e7 LMP Ver: 1.1 (0x1) LMP Subver: 0x1e7
Manufacturer: Cambridge Silicon Radio (10)
|
5. Detecting and Connecting to Remote Devices
Detecting Bluetooth devices in other hosts
At this point we are now ready to detect Bluetooth devices installed in other machines. This is independent of the host Operating System. We will make use of the hcitool command for the same.
Code Listing 5.1: Checking for local devices |
# hcitool dev
Devices:
hci0 00:01:02:03:04:05
|
Code Listing 5.2: Scanning for remote devices |
# hcitool scan
Scanning ...
00:0A:0B:0C:0D:0E Grayhat
|
Code Listing 5.3: Inquiring remote devices |
# hcitool inq
Inquiring ...
00:0A:0B:0C:0D:0E clock offset: 0x5579 class: 0x72010c
|
Now that we know the MAC address of the remote Bluetooth devices, we can check if we paired them correctly.
Code Listing 5.4: Running l2ping |
# l2ping 00:0A:0B:0C:0D:0E
Ping: 00:0A:0B:0C:0D:0E from 00:01:02:03:04:05 (data size 20) ...
20 bytes from 00:0A:0B:0C:0D:0E id 200 time 69.85ms
20 bytes from 00:0A:0B:0C:0D:0E id 201 time 9.97ms
20 bytes from 00:0A:0B:0C:0D:0E id 202 time 56.86ms
20 bytes from 00:0A:0B:0C:0D:0E id 203 time 39.92ms
4 sent, 4 received, 0% loss
|
Setting up Radio Frequency Communication (RFCOMM)
Note: Please note that setting up radio frequency communication is optional. |
We can establish a radio frequency connection to another Bluetooth device using the rfcomm command. To make things a little easier especially for users with multiple devices that support Bluetooth, it is advisable to make a few changes to the default rfcomm config at /etc/bluetooth/rfcomm.conf.
The whole segment of the config starting from rfcomm0 { and ending with } is the config for the device that will establish a connection at /dev/rfcomm0. In this case, we will only show one example, rfcomm0. You can add more devices as you see fit.
Code Listing 5.5: Editing /etc/bluetooth/rfcomm.conf |
rfcomm0 {
# Automatically bind the device at startup
bind yes;
# Bluetooth address of the device
device 00:0A:0B:0C:0D:0E;
}
|
After configuring RFCOMM, we can connect to any device. Since we've made the required settings to the /etc/bluetooth/rfcomm.conf file, we just issue the command shown below. In case you've not made changes to the config file, an alternative method is also shown in the code listing that follows
Code Listing 5.6: Establishing an RFCOMM connection |
# rfcomm connect 0
Connected /dev/rfcomm0 to 00:0A:0B:0C:0D:0E on channel 1
Press CTRL-C for hangup
# rfcomm connect 0 00:0A:0B:0C:0D:0E 1
Connected /dev/rfcomm0 to 00:0F:DE:69:50:24 on channel 1
Press CTRL-C for hangup
|
The first parameter after the connect command is the RFCOMM TTY device node that will be used (usually 0). The second parameter is the MAC address of the remote device. The third parameter is optional and specifies the channel to be used. Please, note that in order to connect to a device, that device must be listening for incoming connections. To do that, we have to explicitly tell it to listen. We can cancel the communication at any moment by just hitting CTRL+C.
Code Listing 5.7: Listening for incoming RFCOMM connections |
# rfcomm listen 0 1
Waiting for connection on channel 1
|
In a similar way to the connect command, the listen command can receive two parameters. The first one explicits the RFCOMM TTY device node (usually 0) that will be used to accept a connection, while the second is the channel that will be used.
Each time you call the rfcomm command, you can also specify the physical device you want to use. Below you can see a small example specifiying the physical device on the above two commands.
Code Listing 5.8: RFCOMM connections specifying physical device |
# rfcomm -i hci0 listen 0 1
Waiting for connection on channel 1
# rfcomm -i hci0 connect 0 00:0A:0B:0C:0D:0E 1
|
Setting up a Personal Area Network (PAN)
Note: Please note that setting up a Personal Area Network is optional. This section describes how to set up and connect to a Network Access Point, though setting up a Group Ad-Hoc Network follows a similar way. |
First of all, we need the bnep module loaded. And probably we want it loaded each time the computer starts.
Code Listing 5.9: Loading the bnep module |
# modprobe bnep
# echo "bnep" >> /etc/modules.autoload.d/kernel-2.6
|
We have to start the pand daemon in the host that will provide the NAP. We'll have to specify that we want to provide a NAP service and that this host will be the master, thus the other hosts that connect to it, the slaves. Another possible service is GN (Group ad-hoc Network).
Code Listing 5.10: Running the pand daemon |
# pand --listen --role NAP --master --autozap
|
After doing that, we have a host listening, so the rest of hosts just have to connect to that one.
Code Listing 5.11: Connecting to the Network Access Point |
# pand --connect 00:0A:0B:0C:0D:0E --service NAP --autozap
|
If everything went fine, we can now configure the IP addresses of our hosts.
Code Listing 5.12: bnep IP address configuration |
host0 # ifconfig bnep0 192.168.2.1
host1 # ifconfig bnep0 192.168.2.2
host0 # ifconfig bnep0
bnep0 Link encap:Ethernet HWaddr 00:0A:0B:0C:0D:0E
inet addr:192.168.2.1 Bcast:192.168.2.255 Mask:255.255.255.0
inet6 addr: fe80::210:60ff:fea3:cb41/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:0 errors:0 dropped:0 overruns:0 frame:0
TX packets:5 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:208 (208.0 b) TX bytes:188 (188.0 b)
host1 # ifconfig bnep0
bnep0 Link encap:Ethernet HWaddr 00:01:02:03:04:05
inet addr:192.168.2.2 Bcast:192.168.2.255 Mask:255.255.255.0
inet6 addr: fe80::210:60ff:fea2:dd2a/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:0 errors:0 dropped:0 overruns:0 frame:0
TX packets:5 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:208 (208.0 b) TX bytes:188 (188.0 b)
|
Finally, we can do a simple test to see that the network is working fine.
Code Listing 5.13: IP ping between bnep interfaces |
host1 # ping 192.168.2.1
PING 192.168.2.1 (192.168.2.1) 56(84) bytes of data.
64 bytes from 192.168.2.1: icmp_seq=1 ttl=64 time=34.0 ms
64 bytes from 192.168.2.1: icmp_seq=2 ttl=64 time=37.3 ms
--- 192.168.2.1 ping statistics ---
2 packets transmitted, 2 received, 0% packet loss, time 1000ms
rtt min/avg/max/mdev = 34.045/35.690/37.336/1.656 ms
|
6. Desktop Applications for Bluetooth
Introduction
We have quite a few Bluetooth applications that run on the desktop and this chapter has been divided into 3 parts, one each for Gnome, KDE and Miscellaneous applications.
For Gnome
If you are a gnome user, you will most probably go with gnome-bluetooth. It provides the most basic yet most used functionalities, as you can see below.
- gnome-bluetooth-manager: To manage Bluetooth remote devices.
- gnome-obex-send: To send files to other devices.
- gnome-obex-server: To receive files.
Code Listing 6.1: Installing gnome-bluetooth |
# emerge gnome-bluetooth
|
This adds menu entries under Applications > System Tools from where you can easily start up the manager or File sharing to transfer files between devices.
To transfer files (the easy way):
- From the Phone to the Computer - Send the file from the phone via Bluetooth and it will be picked up and saved to your /home always.
gnome-phone-manager is a nifty app that you can use to send and receive messages to and from your phone, using only your system. You do not have to touch your phone to read or send messages since all that happens through the application. You are also notified of a new message on your screen if the option is enabled under Preferences. Installation is a breeze as always.
Code Listing 6.2: Installing gnome-phone-manager |
# emerge gnome-phone-manager
|
For KDE
KDE makes use of kdebluetooth and provides more utilities than its Gnome counterpart as seen below.
- kbluetoothd: Bluetooth Meta Server.
- kbtsearch: Bluetooth device/service search utility.
- khciconfig: KDE Bluetooth Monitor.
- kioclient: KIO command line client.
- qobexclient: Swiss army knife for obex testing/development.
- kbtobexclient: A KDE Bluetooth Framework Application.
- kioobex_start
- kbtserialchat
- kbemusedsrv: KDE Bemused Server.
- kbtobexsrv: KDE OBEX Push Server for Bluetooth.
- kbluepin: A KDE KPart Application.
- auth-helper: A helper program for kbtobexsrv that sends an authentication request for a given ACL link.
Code Listing 6.3: Installing kdebluetooth |
# emerge kdebluetooth
|
Other Interesting Applications
- app-mobilephone/obexftp: File transfer over OBEX for mobile phones
- app-mobilephone/bemused: Bemused is a system which allows you to control your music collection from your phone, using Bluetooth.
- app-pda/multisync: Multisync allows you to sync contacts, calendar entries and notes from your mobile phone with your computer, over a Bluetooth connection (amongst other things). It includes such features as backing up this information and restoring it later, and syncing with the Evolution e-mail client. You will need the irmc USE flag set to ensure that multisync has Bluetooth support.
- net-wireless/opd and net-wireless/ussp-push are command line tools (server and client) that can be used to send files to your mobile phone.
7. Acknowledgements
Special thanks to Marcel Holtmann for his time and dedication to the Bluetooth development and for reviewing this guide. And big thanks to Douglas Russell for performing additional hardware tests and improving this guide.