Tuesday, May 6, 2008

Bluetooth accesspoint with Debian GNU/Linux

With a cheap USB bluetooth dongle, you can make your computer act as a bluetooth access point. It is best to get a class 1 device, which will give at least a range of 100 meters unobscured, and will go through 1 or 2 concrete walls or ceilings. Setting it up under Debian, or any other distro is not trivial. As this took me a while, I decided to document the process.

When you use Bluetooth for network services (as opposed to wireless microphone, wiresless mouse, etc), you are using its PAN, or Personal Area Network profile. PAN is provied by the PAN daemon, pand, from the bluez-utils package. PAN uses the BNEP protocol. BNEP stands for Bluetooth Network Encapsulation Protocol.

Kernel configuration

Get a recent 2.6.x kernel, and enable the following features, either as module or built-in:

Debian packages

Install the following Debian packages:
  • bridge-utils (for brctl)
  • bluez-utils (for pand)

Configuration files

  • Edit /etc/bluetooth/hcid.conf to set class to 0x020100;
  • Edit /etc/default/bluez-utils to set PAND_ENABLED=1 and PAND_OPTIONS="--listen --role NAP"
  • Create /etc/bluetooth/pan/dev-up with this contents:
    ifconfig $1
    brctl addif br0 $1
  • Add a bridge as a network interface to /etc/network/interfaces by using something like this (I use 192.168.192.x as my local address space).
            auto br0
    iface br0 inet manual
    up echo "Adding ethernet bridge between LAN and PAN"
    up ifconfig eth0
    up brctl addbr br0
    up brctl setfd br0 0
    up brctl stp br0 off
    up brctl addif br0 eth0
    up ifconfig br0 netmask up
    down echo "Removing ethernet bridge between LAN and PAN"
    down ifconfig br0 down
    down brctl delif br0 eth0
    down brctl delbr br0


First check, whether your USB dongle has been detected by the kernel. You can check this by running 'hciconfig -a'. You should get information on the hci0 interface. Now, if a client bluetooth device will request network service, the PAN daemon, pand, will respond to this. Check your process list to see if pand is running. If not, '/etc/init.d/bluez-utils start' is required. Once the two bluetooth devices connect, a network device called 'bnep0' is created, and pand will execute the /etc/bluetooth/pan/dev-up script. In this script, we will bridge the newly created bnep0 to eth0, using the bridge called br0. To kill the connection at either side, run 'pand -K'.


A linux client for the bluetooth network, can connect to the server by using this command:
    pand --nodetach --role PANU --search
UPDATE: I've found that I need to have 'dbus' installed to get rid of the error "Inquiry failed. No such device" I recently experienced. Without dbus, /etc/init.d/bluetooth would fail.


Don't forget that your dhcpd server should now listen on the bridge br0, not on the LAN eth0. Edit /etc/init.d/dhcpd to change this.

The whole deal with the bridging is required, so that dhcpd can function regardless wether bnep0 exists or not. You cannot bring up dhcpd to listen on bnep0, if there is no bluetooth PAN connection. You can, however, have dhcpd listen on the br0 bridge, and attach it to bnep0 whenever a bluetooth client connects.

If you experience troubles, check the /var/log/daemon.log file for more information.


No comments: