Bluetooth Network Aggregation Point

This article will deal with getting Gentoo to act as a Bluetooth Network Aggregation Point "NAP".

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. 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, no GUI programs or applets are needed. Set the "test-programs" USE flag on the net-wireless/bluez package, to get the latest bluez-test-nap script. 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 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 I think this to be the easiest and most common case. Internet <-- Global IP Address --> Router (with DHCP and routing (NAT) capabilities) <-- local IP Address --> Gentoo-Box

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

The line inet addr:192.168.0.2 Bcast:192.168.0.255 Mask:255.255.255.0 is the one you should be looking for.

Remember the device name (eth0) and edit /etc/conf.d/net.

This tells Gentoo to not ask for a dhcp-lease (actually it tells Gentoo to do nothing for eth0) on 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 "stp on" and "setfd 1" 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 speeds 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 (ping wiki.gentoo.org). If everything works well, add br1 to your default runlevel.

Connecting your cell phone to the Internet
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 three ways:
 * If /usr/local/bin comes first in your $PATH, you can still type:


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


 * To run at startup, let /etc/init.d/local read next scripts. These files must be made executable.

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 send 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 /etc/conf.d/net and restart networking.

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