Working with Bluetooth: Connecting to All Those Cool Devices

418

Wireless peripherals have made connecting devices to your laptop or desktop a thing of beauty. Gone are the days of tangled wires, incompatible connectors and too-short cables. All you have to do now is make your Bluetooth device discoverable and connect to it on the computer. At least that’s how easy it’s supposed to be.

This tutorial will go over the basics of connecting Bluetooth devices to a Linux machine and what you need to know to make it work. We’ll take a look at some of the key utilities and commands you’ll need to get going with that shiny new Bluetooth device. Specific examples will be given for connecting headphones, keyboards, mice, and for file sharing.

Bluetooth the Standard

The Bluetooth standard is owned and maintained by the Bluetooth Special Interest Group (SIG) and has trademarked the name and symbol associated with it. Originally formed in 1998 with five companies, it has grown to over 10,000 members. Member companies include all the major computer hardware vendors, cell phone vendors and software developers.

Version 1.0 of the Bluetooth Specification was released in 1999. The first prototype hardware devices with Bluetooth support started showing up in 2000. You’ll find everything you ever wanted to know about the history of and technology behind Bluetooth on the SIG website. The most recent standard, version 3.0 + HS, was released in April of 2009 and includes new high-speed capabilities.

The Technology

At the lowest level Bluetooth is a radio frequency (RF) system operating in the unlicensed 2.4 GHz band. The transmitter typically has a very low power output limiting the distance to around 10 meters (33 feet). Bluetooth devices appear to the rest of the world as network nodes complete with a MAC address. In many cases you’ll need to know the MAC address of the device to connect it to your Linux machine.

Security is an area that affects Bluetooth transmission just as much as it does other wireless technologies. When you think of the types of information typically passed over a Bluetooth link, you have things like your voice conversations, keyboard strokes, and potentially sensitive data if you use it to sync a mobile device with your laptop or desktop. The latest Bluetooth spec calls for 128-bit AES encryption.

The biggest deterrent to unwanted data breaches is user awareness. Bluetooth uses the concept of a “trusted device” to permit data exchange without user acknowledgement. You should only trust a device you personally own and require all other devices to get permission before any data transfers. You can also set your Bluetooth device in “non-discoverable” mode so it won’t be seen by any snoopers.

Examples

The latest release of Ubuntu (9.04) does a great job with just about any Bluetooth device you want to throw at it. If your computer has a Bluetooth radio built in, you should see the blue icon in the system tray. Clicking on the icon brings up the “Setup new device” wizard where you should be able to connect to your Bluetooth peripheral. All you have to do is put the device in paring mode and follow the wizard.

Bluetooth audio uses the Advanced Linux Sound Architecture (ALSA) system and needs some configuration information in the .asoundrc file. There’s a good reference for what goes in the .asoundrc file on the ALSA website. Basically you have to add an entry to connect the MAC address of your Bluetooth headset to a specific named device in the configuration file. We found a nice shell script on the FOSSwire site that will configure everything for you although it does have some OS version restrictions. You’ll find some additional information on the Bluez wiki site as well.

Exchanging files between devices like a laptop and a cell phone is almost painless over Bluetooth. The pairing process typically will create a unique ID that you must enter on the device you wish to exchange with. This is a minimal security step to generate essentially a one-time key. The ID must be entered on the device to acknowledge the access request. Once this is complete you should be able to send and / or receive files with the newly trusted device.

To get things running on openSUSE 11.1 you’ll need to download and install the pulseaudio package. This is accomplished with the following command:

$ sudo zypper install pulseaudio

Tools for Troubleshooting

The BlueZ Utils package provides several tools to help you troubleshoot your Bluetooth problems. The main tool you’ll want to understand how to use is hcitool. This utility has a whole list of options, but the most useful is scan. This queries the Bluetooth stack for all devices that are within range. It should show both the MAC address and the name of each device it finds such as in:

hcitool scan

Scanning "

"""" 00:09:DD:70:BC:04""" Stereo Headset

The info option along with the MAC address of a device will display the device name, version and supported features. The full list of available commands is available with the –help option and for version 4.39 looks like the following:

hcitool - HCI Tool ver 4.39
Usage:
hcitool [options] [command parameters]
Options:
--help Display help
-i dev HCI device
Commands:
dev Display local devices
inq Inquire remote devices
scan Scan for remote devices
name Get name from remote device
info Get information from remote device
spinq Start periodic inquiry
epinq Exit periodic inquiry
cmd Submit arbitrary HCI commands
con Display active connections
cc Create connection to remote device
dc Disconnect from remote device
sr Switch master/slave role
cpt Change connection packet type
rssi Display connection RSSI
lq Display link quality
tpl Display transmit power level
afh Display AFH channel map
lp Set/display link policy settings
lst Set/display link supervision timeout
auth Request authentication
enc Set connection encryption
key Change connection link key
clkoff Read clock offset
clock Read local or remote clock

You might need to use another tool to connect your Bluetooth keyboard or mouse. Older versions of Linux use a Human Interface Device Daemon (HIDD) that can be controlled from the command line. For example, the following command will scan and connect to a Bluetooth mouse:

$ sudo hidd "search

Other commands for hidd include connect, kill, killall, server and show.

Bottom Line

Bluetooth has reached the standard equipment level on the majority of laptops manufactured within the last year or so. It’s also a key part of most mobile devices. Understanding how to connect the different devices and how to troubleshoot problems will help you get past most, if not all, of the issues you could potentially encounter.