Bluetooth PAN from Windows Mobile to Fedora 11 · Aug 12, 06:10 PM
If you have a mobile phone with a generous data plan, and a laptop without an internet connection, it’s tempting to put the two together to be able to use the internet on the move. While on holiday I managed to do it with a Windows Mobile phone and a laptop running Fedora 11, here’s how…
A working internet connection involves, amongst other things, being able to look up the addresses of hosts, ie. converting a name like www.google.com into a numerical IP address for a server. This is typically done with DNS. Also, the internet connection provides a router which will accept packets from the laptop and send them onwards towards their destination. This is the default gateway. Exactly how this is achieved doesn’t really matter, so long as it works and a reply from the destination can find its way back to the laptop.
When using a mobile phone to access the internet, the network operator will provide certain information that enables the phone to access the internet. Again the details are not that important so long as it works. Parts of the phone might be acting like a modem – in the past I have connected a phone to a laptop and the laptop recognises the phone as a modem. In this case the laptop has to provide the same esoteric information to be able to make the phone connect to the network.
A more modern way of connecting the phone and laptop is to use a Bluetooth PAN (Personal Area Network). This has the advantage of being wireless, as well as being completely removed from the details of the phone’s connection to the network. As we can see, the laptop only needs to connect to the PAN and doesn’t need any mobile network information.
First, some notes about the hardware and software I used. The phone was an O2 XDA Ignito (rebranded HTC touch diamond) running Windows Mobile 6.1 Professional (CE OS 5.2.20779 Build 20779.1.4.11). The laptop was a Dell Inspiron 6000 with Bluetooth, running Fedora 11. The kernel was kernel-2.6.29.6-217.2.3.fc11.i586 and the Bluetooth packages were bluez-4.42-1.fc11.i586. I was using the Gnome desktop on the laptop.
Setting up Bluetooth is relatively simple. The basic steps are to enable Bluetooth on the phone and laptop, ensuring both devices are ‘visible’. On the laptop, right-click on the Bluetooth icon on the panel and choose ‘Setup new device…’. The Bluetooth device wizard guides you through the process.
To set up the PAN, the laptop and the phone have to be paired – this is a nod to security in the Bluetooth world. On the phone start ‘Internet Sharing’ and choose PC Connection ‘Bluetooth PAN’. The Network Connection should be the default that the mobile operator has set up. Click ‘connect’ on the phone and it should say it’s waiting for the PC to connect. That’s all you need to do on the phone.

On the laptop, the bnep kernel module is needed – I noticed it was already loaded though. The software that sets up the PAN is called PAND (PAN Daemon) and it can be run manually like this:
pand —ethernet=bnep0 —connect 00:21:BA:FE:7E:C4 -r PANU -d NAP -n
This means to use the bnep0 device, to connect to a certain Bluetooth address (ie. your phone) with a role PANU (PAN User) and service NAP. The only mystery here is finding the phone address – it can be done like this:
sdptool search NAP
Which will report the Bluetooth address of nearby phones providing NAP.
One day this will all ‘just work’ with Network Manager, according to people I’ve spoken to on IRC, but I’ll believe that when I see a Gnome notification balloon pop up to tell me that everything is working. In the meantime the closest I could get was to add the file /etc/sysconfig/network-scripts/ifcfg-bnep0 which matches the eth0 (wired network) and eth1 (wireless network) files. Of course since it is a different kind of device to wired or wireless ethernet, it has different configuration options. In Fedora I feel this networking stuff has a whiff of Hitchhikers’ Guide to it – if anyone ever figures out exactly how it is supposed to work, and what it’s for, it will disappear in a yum upgrade to be replaced by something even more bizarre and inexplicable. This has definitely already happened.
I found out what to put in the ifcfg-bnep0 script by looking at the ifup-bnep script and seeing what variables it needed to call bnep with:
DEVICE=bnep0
BOOTPROTO=dhcp
ONBOOT=no
REMOTEBDADDR=00:21:BA:FE:7E:C4
ROLE=PANU
This results in several things happening when you type ifup bnep0, including this pand command being run:
/usr/bin/pand —persist —pidfile=/var/run/pand-bnep0.pid —ethernet=bnep0 —autozap —cache —connect 00:21:BA:FE:7E:C4
You can also shut it down with ifdown bnep0.
This works in the sense that the phone will go from ready to connected then disconnected in response to ifup and ifdown, but it’s not enough to get internet access that works. The interface needs bringing up and configuring. I found some things online suggesting that DHCP should work, but I wasn’t able to get any responses to dhclient – not a single packet. It wouldn’t even respond to a broadcast ping. But if I assumed that the phone would be 192.168.0.1/24, and set the laptop to 192.168.0.2, it just worked. To configure this we need ifconfig:
ifconfig bnep0 192.168.0.2 up
We also need to add a default route:
route add default gw 192.168.0.1 bnep0
I found that there is a switch for the pand command that will run a command on bringing up the connection, —devup. So I put the commands into a script and tagged it on to the end of the REMOTEBDADDR in the ifcfg-bnep0 script:
DEVICE=bnep0
BOOTPROTO=dhcp
ONBOOT=no
REMOTEBDADDR=“00:21:BA:FE:7E:C4 —devup /etc/sysconfig/network-scripts/ifup-bnep-post”
ROLE=PANU
This was my /etc/sysconfig/network-scripts/ifup-bnep-post script:
ifconfig $1 192.168.0.2 up
route add default gw 192.168.0.1 $1
cp /etc/resolv.conf.opendns /etc/resolv.conf
I figured out that the device name (bnep0) was passed as the first argument to the devup script. The Bluetooth address is passed as the second parameter but that wasn’t any use. The last line is optional, it configures OpenDNS servers. Using the default gateway (ie. the phone) to look up DNS names works, but the OpenDNS servers seem faster and more reliable, and avoid burdening the phone with the responsibility to cache and proxy the requests. This is my /etc/resolv.conf.opendns file:
nameserver 208.67.222.222
nameserver 208.67.220.220
So finally I have a setup that works reliably, with one command to bring up and take down the interface on the laptop and a few clicks on the phone. It does seem a lot simpler than the old modem strings and wired connections. If only Gnome desktop would automate things a bit it would be great…
<<<Caramel Crater Shortbread · Basic DVD authoring on Fedora>>>

