How to Use TCP/IP over Bluetooth

TCP/IP over PAN/BNEP

PAN and BNEP are the “official” way to do networking with BlueTooth. BNEP is a simple encapsulation of Ethernet frames in a L2CAP session. PAN is the BlueTooth profile using BNEP and defining how to do networking. It includes the definition of the SDP attributes and various node roles. What are the node roles ? It’s just something to make your life more complex. In a typical Ad-Hoc scenario, the server will have the role GN, and up to 7 clients with role PANU can be connected to it. An Access Point would take a NAP (yeah, boring).

The support of BNEP in BlueZ is quite new and and not yet documented in the Official Howto, but there is an alternate Unofficial Howto.

As usual, I’ll go straight to a very simple example of setting up TCP/IP between two nodes. You can do more complex stuff by reading the Howto above.
First, you need to set up the server. The server will listen for incomming connections. In our example, it’s not an Access Point, so we do :

> modprobe bnep
> pand --listen --role GN

On the client side, we first need to know the address of the server ; the inquiry is currently done like this :

> hcitool inq
Inquiring ...
        50:C2:00:03:C4:DC       clock offset: 0x2454    class: 0x020300

Now, you just need to connect to the other side :

> modprobe bnep
> pand --connect 50:C2:00:03:C4:DC

Unfortunately, pand can fail silently, so the way to check if this succeed is to see if a new device bnep0 has been created, either using cat /proc/net/dev or ifconfig bnep0. You may notice that the interface is down, that’s perfectly normal at this point. In case of problem, you need to check the logs for details, in my case /var/log/daemon.log.

What’s left ? BNEP is only a Ethernet emulation. We need to configure TCP/IP on the new interface. This is done with :

> ifconfig bnep0 10.10.10.1 broadcast 10.10.10.255 netmask 255.255.255.0

Just remember that you need to assign an different IP address on each node, otherwise it won’t work. After that, you should be able to ping, telnet and all that jazz.

To terminate your connection on the client, just do :

> ifconfig bnep0 down
> pand --kill 50:C2:00:03:C4:DC

If you want to get more fancy, you can use HotPlug to automatically assign IP addresses to the bnep interfaces, and you can start playing with the SPD to know which node support PAN or not. And, if you want to build an Access Point, you will need to enable bridging. The HOWTO explains that in details.

This info has been extracted from http://www.hpl.hp.com/personal/Jean_Tourrilhes/bt/

How to use Bluetooth on Slackware

To start the bluetooth system, just run as root:

Code:

#sh /etc/rc.d/rc.bluetooth start

To bring the bluetooth device online, first, see if your dongle is recognized by running:

#hciconfig -a

The device name will most likely be hci0.

 

You can now bring it online with:

Code:

#hciconfig hci0 up

 

If you want this to start at boot up, add these lines to your ‘/etc/rc.d/rc.local’

Code:

PATH=/bin:/sbin:/usr/bin:/usr/sbin /etc/rc.d/rc.bluetooth start hciconfig hci0 up

Then you can use the command ‘hcitool’ from the command line.

For more information about how to install bluetooth on Slackware, see http://www.linuxquestions.org/linux/answers/Applications_GUI_Multimedia/Bluetooth_in_Slackware_HOWTO