Bluetooth PAN on Linux – howto?

Categories: English Geeky

So, I bought a cheap-ass (115 pesos) bluetooth adapter, thinking I might use it to establish a PAN between my macbook and my desk computer; this is due to a) no CAT5 cable and no IP address for my laptop on the lan, b) no WLAN coverage up here. I know Bluetooth will be kind of slow but it beats having the macbook with no connection at all.

I followed the excellent [HOWTO written by Zdenek Bouresh][1] and things didn’t seem to work; the macbook wouldn’t find the Linux PC and so couldn’t pair to it.

It turns out that having ISCAN (whatever the hell that is) on your bluetooth device is imperative for it to be found. You can check if you have it by running hciconfig and you get something like this (look for ISCAN and INQUIRY on the third line; if like in this example you don’t have it, then something’s still wrong):

hci0:	Type: USB

 BD Address: 00:11:67:88:06:17 ACL MTU: 1021:8 SCO MTU: 48:10

 UP RUNNING PSCAN

 RX bytes:1377 acl:0 sco:0 events:46 errors:0

 TX bytes:672 acl:0 sco:0 commands:39 errors:0

So how to enable ISCAN?  Oddly, /etc/bluetooth/hcid.conf already contains a line that says:

iscan enable; pscan enable;

However it looks like it doesn’t work. So what I did (quick & dirty) is add this command to /etc/rc.local:

hciconfig hci0 piscan

Also, it appears as though the default startup script starts pand too quickly, and hcid hasn’t had a chance to initialize yet; as a result, your log file will show :

pand[5218]: Failed to connect to the local SDP server. Connection refused(111)

What I did was insert a 5-second sleep in /etc/init.d/bluetooth,  at the beginning of the pan_start function.

Voilá, now my macbook sees the linux computer, a passkey exchange is initiated (and managed on the linux box via kbluetooth, I highly recommend it). The Mac gives a list of “services you want to use with your device”. If you enable PAN only, it will probably say “there were no supported services found on your device”. I guess if you also enable Bluetooth DUN you’ll see this service. Regardless, when you click “continue” a cheery message says “congratulations” and states “your computer and device were configured with the following services” and “use as a personal area network” will be shown.

As you dismiss this dialog, the bluetooth icon on the status bar will sprout a new option, “join network on whatever”. Clicking this will initiate a connection attempt.

Again, the HOWTO refers to creation of a dev-up script but I found I also needed a dev-down.  so in /etc/defaults/bluetooth:

PAND_OPTIONS=” –listen –role nap -u /etc/bluetooth/pan/dev-up -o /etc/bluetooth/pan/dev-down”
``
`
/dev-down contains:

#!/bin/sh

ifdown bnep0

sleep 2
/etc/init.d/dhcp3-server stop

and it looks to be working now 😉

 [1]: http://www.howtoforge.com/bluetooth_pand_debian_etch