Hack 45. Use a Bluetooth Headset with Linux
Use a Bluetooth-enabled headset to make VoIP calls or listen to music while wirelessly roaming throughout your house. One of the coolest wireless technologies to come along recently is Bluetooth. Unlike its more well-known cousin, Wi-Fi, Bluetooth is not intended to be a networking protocol, though it can be used as one. Bluetooth was designed to fill a more mundane purposecable replacement. When Bluetooth devices are talking to one another (defined as pairing), they form a Personal Area Network (PAN). There are many Bluetooth-enabled devices today, including PDAs, headsets, cellphones, and computers. I own quite a few devices that are Bluetooth-capable, and I've used several of them under Linux. One of the more difficult things I've tried is getting a Bluetooth headset working in Linux, because the software isn't quite there yet. After a good deal of experimentation, I've finally gotten this working. This has been tested under Ubuntu Linux (Hoary Hedgehog release), kernel 2.6.10. In theory, it would also work with Debian Linux with little or no modification. For users of other distributions, these steps might give you enough information to get a Bluetooth headset working. Here's what you'll need:
The btsco code is the magic that makes the headset work. To get the btsco source code you'll need to use CVS, as the developers of the code haven't yet released a stable tarball. To check out the code from CVS, use the following commands (no password is needed for the anonymous access): bill@excalibur:/usr/src$ cvs -d:pserver:anonymous@cvs.sf.net:/cvsroot/ bluetooth-alsa login Logging in to :pserver:anonymous@cvs.sf.net:2401/cvsroot/bluetooth-alsa CVS password: bill@excalibur:/usr/src$ cvs -d:pserver:anonymous@cvs.sf.net:/cvsroot/ bluetooth-alsa co btsco cvs checkout: Updating btsco The source code will then be checked out (downloaded) from the development server. You will see a bunch of status messages as the files are downloaded to your system. Once the files are downloaded, you'll need to build the program from the source. Don't panicit's a lot easier than it sounds. Let's get started on the build. First, compile the code: bill@excalibur:/usr/src/btsco$ ./bootstrap bill@excalibur:/usr/src/btsco$ ./configure bill@excalibur:/usr/src/btsco$ make You'll need to be root (or have root permissions via sudo) for the next two steps: root@excalibur:/usr/src/btsco# make install root@excalibur:/usr/src/btsco# make maintainer-clean Next, you have to build the bluetooth-to-alsa kernel module. bill@excalibur:/usr/src/btsco$ cd kernel bill@excalibur:/usr/src/btsco/kernel$make You'll need to be root (or have root permissions via sudo) for the next three steps: root@excalibur:/usr/src/btsco/kernel# make install root@excalibur:/usr/src/btsco/kernel# depmod -e root@excalibur:/usr/src/btsco/kernel# make clean At this point everything should have built and installed properly. Now, we'll go through the configuration and basic playback steps. To use the new code, first load the kernel module you built. Make sure that your Bluetooth hardware is online and ready to go. Load the module as root with modprobe: bill@excalibur:~# modprobe snd_bt_sco Verify that the module loaded: bill@excalibur:~$ dmesg | tail snd-bt-sco revision 1.6 $ snd-bt-sco: snd-bt-scod thread starting Next, configure the Bluetooth adapter for voice using hciconfig as root: bill@excalibur:~# hciconfig hci0 voice 0x0060 Turn on the headset and prepare it to be paired with the computer. On my Jabra BT250, this is done by holding the power button until the headset beeps and the power LED illuminates with a solid blue light. Since you haven't paired the headset and the computer yet; you'll need to run hcitool as root to scan for available Bluetooth devices: bill@excalibur:~# hcitool scan Scanning … 00:07:A4:03:26:5E JABRA 250 Now, run btsco with the Bluetooth address of the headset as an argument. bill@excalibur:~$ btsco 00:07:A4:03:26:5E &
This should cause bluez-pin to pop up a Bluetooth PIN window where you can enter your PIN. I have populated the PIN with "0000"that is the default PIN for pairing a Jabra BT250. Your headset's PIN and pairing instructions may differ slightly. Now that this is done, you should be able to successfully play a sound file to your headset: bill@excalibur:~$ aplay -B 1000000 -D plughw:Headset \ /usr/share/sounds/KDE_Logout.wav Now if you look at your /dev device tree, you'll see a new sound device: bill@excalibur:~$ ls -l /dev/dsp* crw-rw---- 1 root audio 14, 3 2005-07-07 14:11 /dev/dsp crw-rw---- 1 root audio 14, 19 2005-07-10 20:34 /dev/dsp1 At this point, any ALSA-aware sound application will play through the headset if you configure it for /dev/dsp1. This works with audio-recording applications as well. Now that you've gotten your Bluetooth headset working under Linux, you can start using it as a free IP phone with Skype [Hack #98] or another VoIP application! Have fun! Bill Childers |