Team LiB
Previous Section Next Section

Hack 92. Make an Internet Connection Using Bluetooth and a Mobile Phone

Linux now has good support for Bluetooth networking with mobile embedded devices. This is useful for laptop and desktop users who want to use a mobile phone for quick dialup access. But configuring the multitude of Bluetooth options is still fairly cumbersome and unwieldy. This quick and dirty hack uses simple shell scripts to establish a dialup Internet connection, using Bluetooth as the link between a laptop and mobile phone. Once it is set up, you can use the Bluetooth tools to easily interface with a mobile phone's phone book and provide SMS capability using a third-party utility, such as gnokii (http://www.gnokii.org). It is also trivial to replace the laptop used in this hack with a desktop PC equipped with a low-cost USB Bluetooth dongle adapter device.

Bluetooth support in Linux is provided through the BlueZ software stack (http://www.bluez.org). This is a collection of utilities and drivers that configure the underlying hardware, as well as provide the interface seen by software applications. Each Bluetooth device contains a unique identifiermuch like a network MAC addressthat is used in communications to determine the source and destination of the data being transmitted. Certain operations cannot be performed unless the two communicating devices have been paired or logically bound together using a password. In this way it is possible to provide some level of safeguard against unauthorized use of a mobile phone, while allowing those who have paired with it free reign to make any calls they want. The script in this hack relies on such a pairing to reduce the hassle of calling an ISP to a single click of a desktop icon.

To begin, you must install the BlueZ protocol stack. The good news is that BlueZ support is standard in most recent Linux distributions, including those based on kernels 2.4 and 2.6. Linux supports most of the inexpensive Bluetooth devices on the market (especially those using the popular CSR chipset) because they are usually based on the same generic parts, but with a different badge and label on the box. Most distribution kernels are built with support for all the currently supported Bluetooth hardware devices, but some older systems must be updated for Bluetooth support. If the tools mentioned here are not available on your system, first check to see if they are included on the distribution installation discs or as downloads on the BlueZ web site. Red Hat, SUSE, Mandrake, and Debian all ship with Bluetooth support, but the Bluetooth tools might not have been installed when you installed your distribution.

As a minimum, you should ensure that the bluez-utils, bluez-pin, and bluez-sdp packages are installed on your system. These provide the tools and utilities required by Bluetooth, a GUI application for pin entry, and a server program that can advertise the system to other compatible Bluetooth devices. The bluez-utils package also contains a range of useful utilities, including hcitool and rfcomm. You can use the former to enumerate available Bluetooth devices, and the latter to establish a connection. With the necessary packages installed, the following command should tell you the Bluetooth address of the host Linux laptop:

foo@bar:~$ hcitool dev
Devices:
        hci0    00:09:DD:10:3F:8B

To communicate with a Bluetooth-enabled mobile phone, switch on its Bluetooth function and ensure that it is set up to advertise its presence to other devices (it needn't advertise itself once the following steps have been completed, however). Look for Bluetooth devices using the hcitool command (this will take some time to complete):

foo@bar:~$ hcitool scan
Scanning ...
        00:E0:03:3D:58:2E       bob

This shows that the Nokia 6230 mobile phone used in this example has a hardware address of 00:E0:03:3D:58:2E and is called bob. It is now possible to communicate with that device and establish a connection to the modem device within it. This will show up as an extra serial port (called /dev/rfcomm0) that you can use to dial connections to an ISP. Connect to the phone using a command similar to the following:

foo@bar:~$ rfcomm bind 0 00:E0:03:3D:58:2E 1

You should ensure that you replace the hardware address 00:E0:03:3D:58:2E with the appropriate address discovered previously on your own device, but leave the rest of the command intact. Now you can use the phone's internal modem via the /dev/rfcomm0 serial device. You also can script these actions and store them in a file. This example uses a file called /usr/local/bin/bluetooth_call.sh with the following contents:

#!/bin/sh
echo Configuring bluetooth...
rfcomm release 0
rfcomm bind 0 00:E0:03:3D:58:2E 1

Most Linux distributions provide an easy-to-use GUI tool for dialup configuration. Locate the appropriate tool for your system and configure a new connection using /dev/rfcomm0 in place of /dev/modem, or whichever modem device is selected by default on your system. In the case of pppd running on Debian, it is possible to call an ISP through a single command appended to the previous script:

pppd call my_isp

You can reduce this entire process to a single desktop icon click by adding a new desktop launcher icon and configuring it to execute the appropriate script. Note that it will be necessary to run any such script using a wrapper such as gnome-sudo to run with root privileges. On a GNOME desktop, you can configure a launcher icon to run the previous script:

foo@bar:~$ gnome-sudo /usr/local/bin/bluetooth_call.sh

Jon Masters

    Team LiB
    Previous Section Next Section