33.2 Bluetooth

Bluetooth is a wireless technology for connecting various devices, such as cellular phones, PDAs, peripheral devices, laptops, or system components like the keyboard or mouse. The name is derived from the Danish king Harold Bluetooth, who united various warring factions in Scandinavia. The Bluetooth logo is based on the runes for H (resembles a star) and B.

A number of important aspects distinguish Bluetooth from IrDA. First, the individual devices do not need to see each other directly and, second, several devices can be connected in a network. However, the maximum data rate is 2.1 Mbps (in the current version 2.0). Theoretically, Bluetooth can even communicate through walls. In practice, however, this depends on the properties of the wall and the device class. There are three device classes with transmission ranges between 10 and 100 meters.

33.2.1 Basics

The following sections outline the basic principles of how Bluetooth works. Learn which software requirements need to be met, how Bluetooth interacts with your system, and how Bluetooth profiles work.

Software

To be able to use Bluetooth, you need a Bluetooth adapter (either a built-in adapter or an external device), drivers, and a Bluetooth protocol stack. The Linux kernel already contains the basic drivers for using Bluetooth. The Bluez system is used as protocol stack. To make sure that the applications work with Bluetooth, the base packages bluez-libs and bluez-utils must be installed. These packages provide a number of needed services and utilities. Additionally, some adapters, such as Broadcom or AVM BlueFritz!, require the bluez-firmware package to be installed. The bluez-cups package enables printing over Bluetooth connections. If you need to debug problems with Bluetooth connections, install the package bluez-hcidump and bluez-test.

General Interaction

A Bluetooth system consists of four interlocked layers that provide the desired functionality:

Hardware

The adapter and a suitable driver for support by the Linux kernel.

Configuration Files

Used for controlling the Bluetooth system.

Daemons

Services that are controlled by the configuration files and provide the functionality.

Applications

The applications allow the functionality provided by the daemons to be used and controlled by the user.

When inserting a Bluetooth adapter, its driver is loaded by the hotplug system. After the driver is loaded, the system checks the configuration files to see if Bluetooth should be started. If this is the case, it determines the services to start. Based on this information, the respective daemons are started.

Profiles

In Bluetooth, services are defined by means of profiles, such as the file transfer profile, the basic printing profile, and the personal area network profile. To enable a device to use the services of another device, both must understand the same profile—a piece of information that is often missing in the device package and manual. Unfortunately, some manufacturers do not comply strictly with the definitions of the individual profiles. Despite this, communication between the devices usually works smoothly.

In the following text, local devices are those physically connected to the computer. All other devices that can only be accessed over wireless connections are referred to as remote devices.

33.2.2 Configuration

This section introduces Bluetooth configuration. Learn which configuration files are involved, which tools are needed, and how to configure Bluetooth.

The configuration files for the individual components of the Bluez system are located in the directory /etc/bluetooth. The only exception is the file /etc/sysconfig/bluetooth for starting the components.

The configuration files described below can only be modified by the user root. Currently, there is no graphical user interface to change all settings. Most of these settings are only interesting for experienced users with special use cases. Usually, the default settings should be adequate.

Various settings, such as the device names and the security mode, can be changed in the configuration file /etc/bluetooth/hcid.conf. Usually, the default settings should be adequate. The file contains comments describing the options for the various settings. However, most of the settings included in this file can also be made with kbluetooth or bluez-gnome.

Two sections in the included file are designated as options and device. The first contains general information that hcid uses for starting. The latter contains settings for the individual local Bluetooth devices.

One of the most important settings of the options section is security auto;. If set to auto, hcid tries to use the local PIN for incoming connections. If it fails, it switches to none and establishes the connection anyway. For increased security, this default setting should be set to user to make sure that the user is requested to enter a PIN every time a connection is established.

Set the name under which the computer is displayed on the other side in the device section. The device class, such as Desktop, Laptop, or Server, is defined in this section. Authentication and encryption are also enabled or disabled here.

33.2.3 System Components and Utilities

The operability of Bluetooth depends on the interaction of various services. hcid (host controller interface daemon), serves as an interface for the Bluetooth device and controls it. hcid also provides the sdpd (service discovery protocol daemon), by means of which a device can detect the services the host makes available. hcid is activated automatically when the system is started or when a Bluetooth adapter is plugged in to the system. Should this not have been the case, start the Bluetooth subsystem manually with rcbluetooth start. This command must be executed as root.

The following paragraphs briefly describe the most important shell tools that can be used for working with Bluetooth. Although various graphical components are now available for controlling Bluetooth, it can be worthwhile to check these programs.

Some of the commands can only be executed as root. This includes the command l2ping device_address for testing the connection to a remote device.

hcitool

Use hcitool to determine whether local and remote devices are detected. The command hcitool dev lists the local devices. The output generates a line in the form interface_name device_address for every detected local device.

Search for remote devices with the command hcitool inq. Three values are returned for every detected device: the device address, the clock offset, and the device class. The device address is important, because other commands use it for identifying the target device. The clock offset mainly serves a technical purpose. The class specifies the device type and the service type as a hexadecimal value.

Use hcitool name device-address to determine the device name of a remote device. In the case of a remote computer, the class and the device name correspond to the information in its /etc/bluetooth/hcid.conf. Local device addresses generate an error output.

hciconfig

The command /usr/sbin/hciconfig delivers further information about the local device. If hciconfig is executed without any arguments, the output shows device information, such as the device name (hciX), the physical device address (a 12-digit number in the form 00:12:34:56:78), and information about the amount of transmitted data.

hciconfig hci0 name displays the name that is returned by your computer when it receives requests from remote devices. As well as querying the settings of the local device, hciconfig can modify these settings. For example, hciconfig hci0 name TEST sets the name to TEST.

sdptool

Use sdptool to check which services are made available by a specific device. The command sdptool browse device_address returns all services of a device. Use sdptool search service_code to search for a specific service. This command scans all accessible devices for the requested service. If one of the devices offers the service, the program prints the full service name returned by the device together with a brief description. View a list of all possible service codes by entering sdptool without any parameters.

33.2.4 Graphical Applications

In Konqueror, enter the URL bluetooth:/ to list local and remote Bluetooth devices. Double-click a device for an overview of the services provided by the device. If you move across one of the specified services with the mouse, the browser's status bar shows which profile is used for the service. If you click a service, a dialog opens, asking whether to save, use the service (an application must be started to do this), or cancel the action. Mark a check box if you do not want the dialog to be displayed again but always want the selected action to be performed. For some services, support is not yet available. Other graphical front-ends to Bluetooth are included in the kbluetooth, bluez-gnome, and gnome-bluetooth packages.

33.2.5 Example — Establishing a Network Connection via Bluetooth

In this example, a network connection is established between the hosts H1 and H2. These two hosts have the Bluetooth device addresses baddr1 and baddr2 (determined on both hosts with the command hcitool dev as described above). The hosts should be identified with the IP addresses 192.168.1.3 (H1) and 192.168.1.4 (H2).

The Bluetooth connection is established with the help of pand (personal area networking daemon). The following commands must be executed by the user root. The description focuses on the Bluetooth-specific actions and does not provide a detailed explanation of the network command ip.

Enter pand -s to start pand on the host H1. Subsequently, establish a connection on the host H2 with pand -c baddr1. If you enter ip link show on one of the hosts to list the available network interfaces, the output should contain an entry like the following:

bnep0: <BROADCAST,MULTICAST> mtu 1500 qdisc noop qlen 1000 
link/ether 00:12:34:56:89:90 brd ff:ff:ff:ff:ff:ff

Instead of 00:12:34:56:89:90, the output should contain the local device address baddr1 or baddr2. Now this interface must be assigned an IP address and activated. On H1, do this with the following two commands:

ip addr add 192.168.1.3/24 dev bnep0
ip link set bnep0 up

On H2, use the following commands:

ip addr add 192.168.1.4/24 dev bnep0
ip link set bnep0 up

Now H1 can be accessed from H2 at the IP 192.168.1.3. Use the command ssh 192.168.1.4 to access H2 from H1, assuming H2 runs an sshd, which is activated by default in openSUSE®. The command ssh 192.168.1.4 can also be run as a normal user.

33.2.6 Troubleshooting

If you have difficulties establishing a connection, proceed according to the following list. Remember that the error can be on either side of a connection or even on both sides. If possible, reconstruct the problem with another Bluetooth device to verify that the device is not defective.

Is the local device listed in the output of hcitool dev?

If the local device is not listed in this output, hcid is not started or the device is not recognized as a Bluetooth device. This can have various causes. The device may be defective or the correct driver may be missing. Laptops with built-in Bluetooth often have an on and off switch for wireless devices, like WLAN and Bluetooth. Check the manual of your laptop to see if your device has such a switch. Restart the Bluetooth system with the command rcbluetooth restart and check if any errors are reported in /var/log/messages.

Does your Bluetooth adapter need a firmware file?

If it does, install bluez-bluefw and restart the Bluetooth system with rcbluetooth restart.

Does the output of hcitool inq return other devices?

Test this command more than once. The connection may have interferences, because the frequency band of Bluetooth is also used by other devices.

Can the remote device see your computer?

Try to establish the connection from the remote device. Check if this device sees the computer.

Can a network connection be established (see Section 33.2.5, Example — Establishing a Network Connection via Bluetooth)?

The setup described in Section 33.2.5, Example — Establishing a Network Connection via Bluetooth may not work for several reasons. For example, one of the two computers may not support SSH. Try ping 192.168.1.3 or ping 192.168.1.4. If this works, check if sshd is active. Another problem could be that one of the two devices already has network settings that conflict with the address 192.168.1.X in the example. If this is the case, try different addresses, such as 10.123.1.2 and 10.123.1.3.

If you have installed the bluez-hcidump package, you can use hcidump -X to check what is sent between the devices. Sometimes the output helps give a hint where the problem is, but be aware of the fact that it is only partly in clear text.

33.2.7 For More Information

Some additional (last-minute) documentation can be found in /usr/share/doc/packages/bluez-utils/ (German and English versions available).

An extensive overview of various instructions for the use and configuration of Bluetooth is available at http://www.bluez.org/. Other useful information and instructions: