Bluetooth Network Aggregation Point

This article Article description::covers the setup of a Bluetooth Network Aggregation Point (NAP) on Gentoo Linux.

What is a NAP
The Bluetooth specification incorporates the ability to create a Personal Area Network (PAN). It is an Ethernet transparent protocol, thus all standard protocols (especially IP) can be used in such a PAN. A NAP can be thought of being the Master in such a network. It will provide the connectivity to other networks (Internet for instance), for up to eight via Bluetooth connected PAN devices (cell phones, PDAs, laptops maybe).

Scope of this article
We will deal with the creation of a Gentoo NAP, in order to connect a Bluetooth enabled cell phone with the Internet. Then for instance, one could synchronize the cell phone's contacts/calendar with a SyncML capable groupware server, located anywhere on the Internet (or the local network). We will henceforth call the NAP server "Gentoo-Box" and the PAN client "cell phone".

Prerequisites
A Bluetooth installation must be done first. If you use simple-agent or, no GUI programs or applets are needed. Set the "test-programs" USE flag on the net-wireless/bluez-4 package, to get the latest bluez-test-nap script. Newer net-wireless/bluez-5 doesn't have this USE flag yet, but the script named test-nap can be copied from the sources later. We also need Network Bridging, but with our own host configuration.

Setting up a network bridge
As the BlueZ NAP server relies on Gentoo to handle the Ethernet link created by BlueZ, we will create an Ethernet bridge, so we will be able to use the full power of the Gentoo startup scripts. Make sure to backup all files before editing them.

We will deal with the following scenario, as this is probably the easiest and most common case: +−−−−−−−−−−+                            Global IP address  ┌─────>╎ Internet ╎ │     +−−−−−−−−−−+                                                │                                                v                          ┌────────────────────────────────────────────┐ │                  Router                   │ │ (with DHCP and routing (NAT) capabilities) │ └────────────────────────────────────────────┘                                        ^              ^                                         │              │ ┌────────────┐       ┌────────────┐      │              │      +−−−−−−−−−−−−−−−+ │ Cell phone │<─────>│ Gentoo-Box │<─────┘              └─────>╎ Local network ╎ └────────────┘      └────────────┘                            +−−−−−−−−−−−−−−−+                                         Local IP address

Execute ifconfig to locate the network card which connects to the router:

The line "inet 192.168.0.2 netmask 255.255.255.0  broadcast 192.168.0.255" is the one you should be looking for.

Remember the device name (eth0) and edit :

This tells Gentoo to not ask for a DHCP lease on eth0 (actually it tells Gentoo to do nothing for eth0), and create a new bridge br1, which contains eth0. As eth0 used to get its IP address via DHCP, we set br1 to do exactly that. The options "bridge_stp_state_br1=1" and "bridge_forward_delay_br1=100" make sure, the Spanning Tree Protocol is used, and the forwarding state of the bridge will be reached within one second of a topology change. The last options speed up the cell phone connection considerably, as Gentoo tends to default to around 10 seconds, thus every cell phone connect would take at least that long.

Create a new symbolic link, and restart the network:

Check, if you are connected to the web. If everything works well, add br1 to the "default" runlevel:

BlueZ 4 method
Start the NAP service and notice interface br1. Enter in a terminal:

Watch Syslog when you tell your cell phone to connect to the Internet using the Gentoo-Box as NAP:

You should now be able to connect and load webpages.

Modifying the bluez-test-nap script
If you want to get rid of the sleep timer in the standard bluez-test-nap script, or you want to run the NAP service in the background, you could make these small changes:

Copy the script to an alternate location, and apply the patch:

Now the NAP service can be started in five ways:

 

If comes first in your $PATH, you can still type:

 

To run the script in the background, and stop it:

 

To run at startup, let Local.d read next scripts. These files must be made executable:

 

Instead of the local.d files approach, it's better to use a real init script. This file must be made executable:

 

In case of plugging and unplugging an USB dongle, just an udev rule can do the job:

 

BlueZ 5 method
The BlueZ 4 way will work, but bluez-test-nap must be renamed to test-nap. Copy the new script test-nap and it's dependency bluezutils.py, from the test directory in the source package to. The script test-nap must be made executable.

Also the default behaviour of BlueZ 5 changed. Before using test-nap, the device must be initialized. Desktop applications like BlueDevil do that automatically. Otherwise, this command can be used:

No webpages can be loaded
If the phone does not show any sign of being connected, try Wireshark to figure out what packets are being sent and received. Maybe a simple

can do the trick. Make sure no firewall settings on the Gentoo-Box interfere.

Restore your old Internet connection
If you lose your Internet connectivity, if things break, restore your backup of and restart networking:

Tools for testing
There is a bluez-test-network utility, that you can use for testing PAN connection initiated from server side, and a monitor-bluetooth utility to watch what is going behind the D-Bus scene, because watching can be not enough.