Gentoo Linux Bluetooth Guide Ioannis Aslanidis Douglas Russell Marcel Holtmann Shyam Mani Ɓukasz Damentko This guide will explain how to successfully install a host Bluetooth device, configure the kernel properly, explain all the possibilities that the Bluetooth interconnection offers and how to have some fun with Bluetooth. 1.0 2005-08-25 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.

Supported Devices
Qualified and non-qualified devices that support Bluetooth 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.

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. If you want, you can use hotplugging in case you want to use modules instead of compiling support built into the kernel. Please, refer to the Gentoo Linux USB Guide.

Device Drivers  --->
  Networking Support  --->

<*> 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
(The four drivers below are for PCMCIA Bluetooth devices and will only
show up if you have also selected PCMCIA support in your kernel.)
<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   
(The driver below is intended for HCI Emulation software.)
<M> HCI VHCI (Virtual HCI device) driver

(Move back three levels to Device Drives and then check if USB is
enabled. This is required if you use a Bluetooth dongle, which are mostly USB
based.)
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.

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.
(One way to check for the device)
# cat /proc/bus/usb/devices | grep -e^[TPD] | grep -e Cls=e0 -B1 -A1
(The Cls=e0(unk. ) identifies the Bluetooth adapter.)
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 
(Some might show up on lsusb from sys-apps/usbutils)
# 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
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.

# emerge net-wireless/bluez-libs net-wireless/bluez-utils
Do not emerge bluez-kernel or bluez-sdp as they will break bluez-utils!

Additionally, as we have compiled the Bluetooth subsystem as modules, we will need hotplug and coldplug, which are explained in the Gentoo Linux USB Guide.

# emerge hotplug coldplug
# rc-update add coldplug boot
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.

(Start up Bluetooth)
# /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.

(Recommended changes to be made to the file are shown)

(Change security to "auto")
        # Security Manager mode
        #   none - Security manager disabled
        #   auto - Use local PIN for incoming connections
        #   user - Always ask user for a PIN
        #
        security auto;

(Change pin_helper to use /etc/bluetooth/pin-helper)
        # PIN helper
        pin_helper /etc/bluetooth/pin-helper;

(Set your device name here, you can call it anything you want)
        # Local device name
        #   %d - device id
        #   %h - host name
        name "BlueZ at %h (%d)";

(Leave as is, if you don't know what exactly these do)
        # 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.

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.
(Change 123456 with your desired pin number.)
123456
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.
Services configuration

Now that we have concluded with the configuration of BlueZ, it's time to restart the necessary services.

# /etc/init.d/bluetooth restart
(We can also add it to the default runlevel.)
# 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 decices are now up and running with the configured options.

(Check to see if the services are running)
# 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 AUTH ENCRYPT
        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)
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.

# hcitool dev
Devices:
        hci0    00:01:02:03:04:05
# hcitool scan
Scanning ...
        00:0A:0B:0C:0D:0E       Grayhat 
# hcitool inq
Inquiring ...
        00:0A:0B:0C:0D:0E       clock offset: 0x5579    class: 0x72010c 

Now that we now the MAC address of the remote Bluetooth devices, we can check if we paired them correctly.

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

(Only changes that might be needed are shown)
rfcomm0 {
        # Automatically bind the device at startup
        (Creates the device node, /dev/rfcomm0 at start up)
        bind yes;

        # Bluetooth address of the device
        (Enter the address of the device you want to connect to)
        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

(The 0 refers to the rfcomm0 in the config file)
# rfcomm connect 0 
Connected /dev/rfcomm0 to 00:0A:0B:0C:0D:0E on channel 1
Press CTRL-C for hangup

(If you did not edit /etc/bluetooth/rfcomm.conf)
# 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.

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

# rfcomm -i hci0 listen 0 1
Waiting for connection on channel 1
(To listen to a determined device) 
# rfcomm -i hci0 connect 0 00:0A:0B:0C:0D:0E 1
(To use a determined device when connecting to another one)
Setting up a Personal Area Network (PAN) 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.

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

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

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

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.

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

# 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.
# 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.
  • media-plugins/xmms-btexmms: Btexmms is an XMMS plugin that allows you to use your Bluetooth-enabled (Sony) Ericsson mobile phone as a remote control for XMMS.
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.