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.
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.
A list of the currently supported devices can be found at:
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
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.
(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
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
# emerge net-wireless/bluez-libs net-wireless/bluez-utils
Additionally, as we have compiled the Bluetooth subsystem as modules, we will
need hotplug and coldplug, which are explained in the
# emerge hotplug coldplug # rc-update add coldplug boot
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
(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.
(Change 123456 with your desired pin number.) 123456
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
(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)
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 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 know 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
We can establish a radio frequency connection to another Bluetooth device using
the
The whole segment of the config starting from
(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
(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 -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)
First of all, we need the
# modprobe bnep # echo "bnep" >> /etc/modules.autoload.d/kernel-2.6
We have to start the
# 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
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.
If you are a gnome user, you will most probably go with
# 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):
# emerge gnome-phone-manager
KDE makes use of
# emerge kdebluetooth
Special thanks to