IP over Bluetooth with Raspbian systems

tvuillemin picture tvuillemin · Feb 3, 2015 · Viewed 17k times · Source

I have got 2 Raspberry Pis, running Raspbian, up-to-date. Each Pi has exactly one Bluetooth USB dongle. I can make them communicate via RFCOMM using this.

Now, I would like to establish a proper IP layer over the Bluetooth physical link. As far as I understand, I have to use PAN (Personal Area Network), that should create a network interface I could manage with ifconfig. I am trying to adapt this tutorial, but I am stuck at an invalid exchange error.

On RPi0, I run

$ sudo pand --nodetach --listen --master --role=NAP
pand[2313]: Bluetooth PAN daemon version 4.99

On RPi1, I run

$ pand --nodetach --connect 00:1A:7D:DA:71:16
pand[2323]: Bluetooth PAN daemon version 4.99
pand[2323]: Connecting to 00:1A:7D:DA:71:16
pand[2323]: Connect to 00:1A:7D:DA:71:16 failed. Invalid exchange(52)

I cannot find any relevant information about this error code. Any idea how I could solve this ? Or am I mistaken and should I use something else instead of PAN ?

Thanks in advance !

EDIT: When specifying the Bluetooth device I want to listen on, I get another error message. It doesn't really make sense either, since I do not run any other Bluetooth server.

$ sudo pand -i 00:1A:7D:DA:71:16 --nodetach --listen --role=NAP
pand[2582]: Bluetooth PAN daemon version 4.99
pand[2582]: Bind failed. Address already in use(98)

Answer

CowsWithGuns picture CowsWithGuns · Nov 13, 2016

So things seem to have changed quite a lot recently and the Pi comes with Bluez 5.23 in 2016.

Having just spent two days, these steps have solved it for my pi but might help for any Debian Jessie install. I hope so. Tested on a new pi, running jessie with fresh install just now. This will give a bluetooth pan bridged to your eth0 network (and thus use your existing dhcp/dns server etc). This is my first post, so please forgive stupidity around the various conventions here. I hope this helps someone and saves you a little time.

This is prbably not an optimal solution (I'm no guru), and I'd love to hear about some improvements.

Install some things (python stuff will help with scritps): sudo apt-get install bridge-utils bluez python-dbus python-gobject

Download two very cool python scripts, put them in /usr/local/bin and chmod both perhaps to 755 depending on who needs access to execute... blueagent5 and bt-pan. Many thanks and homage to their respective authors. Gosh this kind of thing saves so much time and misery.

Now, we need a bridge. Add the following to the end of /etc/network/interfaces

auto pan0
iface pan0 inet dhcp
  bridge_stp off
  bridge_ports eth0

I rebooted at about this time to make sure all was as it would be normally.

sudo reboot

Log back in and we issue

modprobe bnep
hciconfig hci0 lm master,accept
ip link set pan0 up

If you don't want pin prompt, don't do this next step. To ensure we get a PIN prompt, issue this...

hciconfig hci0 sspmode 0

Start PAN using the special magic in the bt-pan script. It doesn't return, so add an ampersand at the end.

bt-pan  server pan0 &

Start the bluetooth security agent with wonderful ease and confidence. Optionally set a pin (it defaults to 0000).

blueagent5 --pin 4321 &

Okay, one last thing. Forward the network. This will only work if there is no fancy authentication at the router/dhcp, if there is, you may need to look further to solve this issue.

sysctl -w net.ipv4.ip_forward=1

iptables -A INPUT -i pan0 -j ACCEPT
iptables -A FORWARD -i pan0 -j ACCEPT

Once done, you may need to save these iptables settings and reinstate them each time the system boots.

Tiptoe over to your tablet or whatever you are trying to connect to the internet. Open Bluetooth in your settings. Pair with 4321 as your pin, and connect to the local network.

But you didn't need to tiptoe after all, it all seems quite robust to me. Enjoy!