A COMPLETE GUIDE TO WIRELESS CONFIGURATION LINUX UNWIRED ROGER WEEKS, EDD DUMBILL & BRIAN JEPSON
Chapter 7 CHAPTER 7 Bluetooth Bluetooth is a wireless cable-replacement technology that uses low-power signals in the 2.4 GHz band. Using Bluetooth, devices can transfer up to 720 kbps. This bandwidth is restricted in comparison to those obtainable from 802.11 wireless technology, and while networking is one application of Bluetooth, it is not the primary application area. Bluetooth’s goal is to be a low-cost, low-power, and, above all, pervasive technology.
This chapter first introduces the core Bluetooth concepts that will aid a Linux system administrator in his deployment, discusses kernel configuration and system-level tools, and finally covers user-level applications. Quick Start We tested a Belkin Bluetooth USB adapter with several Linux distributions on an IBM ThinkPad A20m. In all cases, we got it up and running to the point where we created a serial port connection between a Bluetooth cell phone (Nokia 3650) and the Linux machine.
3. The bluez-utils and bluez-sdp packages configured themselves to start in runlevel 3 and 5. After installing these packages, we started them with the following commands (but we could also have rebooted): /etc/init.d/bluez-utils start /etc/init.d/bluez-sdp start 4. The /dev/rfcomm* devices already exist, so we didn’t need to create them. SuSE 9.0 We used SuSE 9.0 (FTP install) with the latest available kernel package (2.4.21-166-default). To enable Bluetooth, we followed these steps: 1.
3. To make sure that the Bluetooth scripts were started on boot, we ran chkconfig --add bluetooth. 4. We ran /etc/init.d/bluetooth start (we could also have rebooted). 5. The /dev/rfcomm* devices did not exist, so we created them as shown in Example 7-4. Troubleshooting Generally, following the previous steps went smoothly, but we did run into some problems. Here are some tips that should help you out: Start hcid in the foreground By default, the startup scripts launch hcid in the background.
Double-check your kernel configuration If you’re compiling the kernel from source, be sure everything is configured the way it should be. For example, one of us was testing the examples in this chapter and received an Operation not supported error when we tried to make a connection over /dev/rfcomm0. We hadn’t configured RFCOMM TTY support (CONFIG_BLUEZ_RFCOMM_TTY) in the kernel. Well, we had, but it was configured as a module rather than statically compiled into the kernel.
RFCOMM (serial emulation) SDP (service discovery) SCO (for audio) L2CAP (logical link control and adaptation protocol) HCI (host controller interface) Radio transport Figure 7-1. Some layers of the Bluetooth specification What You Can Do with Bluetooth As Bluetooth is intended to replace cable, it can be used for more or less the same purposes as a cable, within the bandwidth constraints of the technology.
Input devices Bluetooth supports an array of input devices similar to USB. Major manufacturers such as Apple and Microsoft are shipping Bluetoothenabled mice and keyboards. Audio Audio is one of the most-promoted aspects of Bluetooth by cell phone manufacturers; it is possible to support bi-directional audio connections to headsets over Bluetooth. Concepts The following sections describe essential Bluetooth concepts that you need to be aware of.
Protocols The Bluetooth specification defines some protocols of its own and also reuses some existing standards. A protocol is an agreement about the way data is exchanged. It is on top of these protocols that all applications of Bluetooth are built. An in-depth knowledge of the protocols is not necessary to deploy Bluetooth, but passing familiarity with them helps in troubleshooting situations.
Hardcopy Cable Replacement (HCRP) Emulates a parallel port connection for the purposes of printing Dial-up Networking Profile (DUN) A connection to a modem or cell phone, which connects to an Internet access point LAN Access Profile (LAP) A point-to-point (PPP) access to a network Headset Profile (HS) A combination voice and control channel, which provides a link between a cell phone and audio headset Generic Object Exchange Profile (GOEP) A file exchange, which exchanges business cards on cell phones File
Discoverability A Bluetooth device is discoverable if it can be found by another device’s inquiry. During discovery, the inquiring device broadcasts a specially coded message. As remote devices receive the message, they send a return message indicating their presence. In most circumstances, you must make a device discoverable in order to initiate bonding.
Table 7-1. Major device types as expressed in the device class (continued) Bit pattern (bits 12–8) Meaning 0 0 0 1 0 Telephone (cell phone, payphone, cordless phone) 0 0 0 1 1 Network access point 0 0 1 0 0 Audio/video device (headset, speakers) 0 0 1 0 1 Peripheral (keyboard, mouse, joystick) 0 0 1 1 0 Imaging (printer, camera, scanner) 1 1 1 1 1 Uncategorized Table 7-2. Service classes as expressed in the device class Bit Meaning if set 16 Positioning (location information, e.g.
Various applications such as LAN access points require the master/slave relationship to be the same as the server/client relationship. For this reason, a client device, which serves as a master, initiates a connection to the access point; once connected, a role-switch occurs, and the client device now becomes a slave. For most applications of Bluetooth on Linux, you do not need to be aware of these distinctions, but the knowledge of their existence may be useful in debugging scenarios.
If you dual-boot your computer between Linux and the manufacturer’s operating system, such as Windows XP or Mac OS X, you may want to use the Bluetooth device your vendor recommends. Both the Apple-sold D-Link USB dongle and Microsoft-manufactured USB dongle are known to work with Linux. If in doubt, consult the Linux device compatibility list. When choosing a Bluetooth device, be aware of the difference between Class 1 and Class 2 Bluetooth devices.
Configuring the Kernel Bluetooth support under Linux requires a recent kernel. If your kernel is Version 2.4.22 or better, or a 2.6 series kernel, then you’re all set. Otherwise, you must upgrade your kernel. Alternatively, if you do not wish to upgrade, and have kernel 2.4.18 or better compiled from source, you can apply the patches from the “kernel patches” area of the BlueZ web site (http://bluez. sourceforge.net).
Figure 7-3. Configuring Bluetooth support in the Linux kernel Figure 7-4. Configuring Bluetooth hardware support in the Linux kernel Table 7-3.
Table 7-3. BlueZ protocol configuration options (continued) Option Purpose Recommended value SCO links support Bluetooth Audio m RFCOMM protocol support Serial data transfer m RFCOMM TTY support Maps Linux terminal devices (e.g., /dev/ rfcomm0) to Bluetooth serial ports y BNEP protocol support Personal area networking m BNEP Multicast filter support, protocol filter support Advanced filtering for networking y Table 7-4.
To verify this, ensure that the contents of Example 7-1 are present in /etc/ modules.conf. If you need to change this file, run depmod -a to ensure automatic loading of modules by the kernel. You must be the root user to perform this operation. Example 7-1.
When hotplug detects a new device, it loads the necessary driver modules into the kernel, and it runs any scripts the user has configured. In the case of BlueZ, hotplug is required for certain Bluetooth devices that require firmware downloaded to them, such as the USB dongles based on the Broadcom chipset. Hotplug ships with most Linux distributions. Version 2002_08_26 or later is required. If you need to install it separately, download it from http://linuxhotplug.sourceforge.net/.
Basic Configuration and Operation The bluez-utils package contains the tools you need to configure and test your Bluetooth setup. Once you’ve installed the package, run the init script (/etc/init.d/bluez-utils start on Debian, /etc/init.d/bluetooth start on Red Hat) to start the Bluetooth subsystem. These scripts normally run on boot, so they may have been started already if you installed from RPMs or Debian packages. The hcid daemon should now be running.
• Other Bluetooth devices will see this computer as saag-0. This name is configurable, as explained in Table 7-6. • The chipset is manufactured by Cambridge Silicon Radio (CSR). The CSR chipset is the most commonly used chipset for USB dongles. When diagnosing and reporting problems to kernel driver authors, you may be asked for the output of hciconfig -a. Note that you must be the root user to use some of the features of hciconfig. Table 7-6 shows the most useful options of the hciconfig tool. Table 7-6.
Why Isn’t Scanning Instantaneous? The reason scanning can take a long time is because a Bluetooth inquiry is being performed. As Bluetooth devices frequency-hop, inquiry cannot be instantaneous. The device performing the inquiry transmits a special code on two consecutive frequencies. When the other devices’ hop patterns take them onto those frequencies, they listen for a repetition of that code and then indicate their presence to the inquirer.
Configuring hcid The hcid daemon handles various low-level aspects of a system’s Bluetooth devices, including activating and configuring the Bluetooth interfaces, and handling device bonding. hcid should be running at all times on your system, and it is usually started by initialization scripts installed along with the rest of the tools from the bluez-utils package. The configuration file for hcid, /etc/bluetooth/hcid.conf, has two parts: global configuration and Bluetooth device configuration.
Device options This section is introduced by the devices keyword, which controls the configuration that hcid gives to each Bluetooth device as it is activated. This has the same effect as if you were to manually configure the device with hciconfig. Table 7-7 explains the most useful options available in this section. Table 7-7. Useful device-level options from /etc/bluetooth/hcid.conf Option Explanation name The name of the adapter as it appears to other devices.
Service Discovery Bluetooth devices implement the service discovery profile (SDP) in order to describe to other devices how their services may be accessed. SDP is generally used in two ways: browsing and searching. An SDP browse request causes a device to respond with a list of services that it supports. A search request is a query for details of a particular service. Two tools found in the bluez-sdp package handle SDP on Linux.
Example 7-3.
device with the current version of sdptool; it must perform an inquiry and search for the service on every device. Table 7-8 shows the service abbreviations that sdptool understands. Table 7-8.
Removing a service is slightly more complex, requiring the identifying “handle” of the record. In the output from an SDP browse in Example 7-3, there is a Service RecHandle entry for each record; the del command requires this number. So, assuming Example 7-3 refers to a local SDP server, you could remove the object push record with the command sdptool del 0x804d7f0.
Connecting to a cell phone To see an example of RFCOMM usage, you could set up a serial connection to a cell phone’s modem and try some commands on it. First, you must discover the RFCOMM channel that dial-up networking uses on the phone. For this, use sdptool browse ADDR (where ADDR is a Bluetooth address you retrieved with sdptool browse): $ sdptool browse 00:0A:D9:15:CB:B4 ...
Internet access via a cell phone By creating PPP connections with RFCOMM serial ports, you can use your cell phone for Internet access. (To learn how to do this with GPRS cell phones, see Chapter 9.) For example, to connect to AT&T Wireless’s GPRS network with a Nokia 3650 (see “GSM/GPRS Phone with Data Cable” in Chapter 9), use the peers script shown in Example 7-6. Be sure to use rfcomm bind as shown in Example 7-6. You can use the attws-connect and attws-disconnect scripts from Chapter 9. Example 7-6.
OBEX FTP over Bluetooth is not very well supported on Linux. The most popular package, obexftp, still has Bluetooth support in development at the time of writing. We advise you to check the project’s home page at http:// triq.net/obex. OBEX PUSH is better supported and is more practical since it is consistently implemented in consumer devices such as cell phones. There are several graphical programs available to support OBEX PUSH on Linux, as we shall see later.
To receive a file from a remote device, use the test program in server mode. (This is shown in the following listing.) You can then push a file to your computer from a remote device. $ sdptool add --channel=4 OPUSH $ obex_test -b ff:ff:ff:00:00:00 4 > s Note that some devices require the OBEX capability to be reflected in your Bluetooth device’s device class setting before they allow transfers to be made to your computer.
You can use LAN access to provide Bluetooth devices with access to your local network. Many PDA devices support this connection method, both for purposes of synchronization over TCP/IP and general Internet access. In order to use LAN access, you need the bluez-pan package installed on your computer. This contains two tools: dund and pand. LAN access is provided by dund, which we discuss here. You also need PPP support in your Linux kernel, and the PPP daemon pppd installed on your computer.
Example 7-7. PPP daemon configuration for LAN access (continued) crtscts lock local proxyarp ms-dns 192.168.0.5 # local : remote 192.168.7.1:192.168.7.2 You may want to adjust the last two entries in the configuration to suit your setup: the ms-dns line specifies the IP address of your DNS server. This will become useful when you enable routing. The two colon-separated addresses are the local IP address and the IP address to give the remote device. You should choose addresses in the 10.x.x.x or 192.168.x.
Our setup so far has no security considerations. There are several steps one can take to improve the security situation: • Require username/password authentication for the PPP setup; see the pppd documentation for how to do this. • Configure your Bluetooth device to always use link-level encryption in hcid.conf. You should rely on neither of these to provide more than basic security.
LAN NAP PANU PANU PANU Figure 7-6. Structure of a network connected to a NAP PANU PANU PANU GN PANU PANU PANU Figure 7-7. Structure of a GN Both of these types of network are supported under Linux. To set them up, you must have some familiarity with Linux network administration. Creating a GN GNs are easier to create, so they are good starting points to test PAN functionality. To set up a GN or NAP, the bluez-pan package must be compiled and installed.
and on the client: # ifconfig bnep0 192.168.7.2 If you use the 192.168.7.x network locally, substitute other suitable IP addresses. Test the connection by using ping to verify the connection from each end. Use ifconfig to display the interface configuration: # ifconfig bnep0 bnep0 Link encap:Ethernet HWaddr 00:80:98:24:15:6D inet addr:192.168.7.1 Bcast:192.168.7.255 Mask:255.255.255.
configurations on the master side for each interface, but it leaves the client devices unable to communicate with each other. The solution to this is called bridging. Bridging enables multiple network devices to appear as one interface on a network by tying, on the master side, all the bnep* devices into one interface. The first step is to ensure that bridging is enabled in your Linux kernel; bridging is supported in both the 2.4 and 2.6 series of kernels.
collisions:0 txqueuelen:1000 RX bytes:789 (789.0 b) TX bytes:880 (880.0 b) bnep1 Link encap:Ethernet HWaddr 00:80:98:24:15:6D inet6 addr: fe80::280:98ff:fe24:156d/64 Scope:Link UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1 RX packets:49 errors:0 dropped:0 overruns:0 frame:0 TX packets:72 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:1000 RX bytes:6453 (6.3 KiB) TX bytes:9019 (8.8 KiB) pan0 Link encap:Ethernet HWaddr 00:40:05:D0:DD:69 inet addr:192.168.7.1 Bcast:192.168.7.
Experimental Features The uses of Bluetooth covered so far in this chapter are the widespread applications of the BlueZ stack. In this section, we cover the more experimental uses: printing over Bluetooth, connecting Bluetooth mice and keyboards, and using audio with Bluetooth headsets. If you’re not afraid of some system configuration, happy with compiling programs from source, and understand how to use CVS, this section is for you.
Input device support entails enabling the user-level driver support in the Input device drivers section of your Linux kernel. As its name suggests, this allows regular programs to inject events into the system’s input device channels. Secondly, you must compile and configure the development version of BlueZ: # cvs -d :pserver:anonymous@cvs.bluez.sourceforge.net login # cvs -z3 -d :pserver:anonymous@cvs.bluez.sourceforge.net \ co libs2 utils2 # cd libs2 # ./bootstrap # .
Adding Bluetooth input devices to your system is now a matter of invoking the /opt/bluez2/bthid program. This runs once as a daemon, and then you should invoke it again, each time to add a device: # /opt/bluez2/bin/bthid -d # /opt/bluez2/bin/bthid -c 11:22:33:44:55:66 Note that the input devices need to be paired before they will connect. With mice, the manufacturer presets the PIN, usually to 0000. With keyboards, you enter a PIN and press return on the Bluetooth keyboard.
Figure 7-8. Browsing a device’s services in KDE Figure 7-9.
GNOME The GNOME Bluetooth subsystem’s home page is available at http:// usefulinc.com/software/gnome-bluetooth. Download it from the project’s home page. RPM and Debian packages are also available.
Figure 7-11. Sending a file via OBEX in GNOME Cool Bluetooth Tricks Aside from the everyday file management and connectivity, Bluetooth on Linux provides scope for some fun applications. This section outlines a few of them, mostly involving interfacing a cell phone with your computer.
You can find the code at http://www.hackdiary.com/projects/bluetoothremote. Controlling Music Players Using a similar trick as mentioned previously, the popular MP3-playing application XMMS can be controlled from a suitable Ericsson phone. The bluexmms program even supports display of the MP3 playlist on the phone’s screen. You can find instructions and a download at http://linuxbrit.co.uk/ bluexmms.