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).
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/