HOWTO-BluetoothNetworking

HowTo set up bluetooth IP networking

This text explains how to connect to devices via PAN (IP over bluetooth). A device can either be a Nokia 770 or a PC running Linux.


Note on IT2006

This HowTo can also be applied to IT2006, but you will have to add the kernel module for bnep first.

insmod /mnt/initfs/lib/modules/current/bnep.ko

Requirements

  • BlueZ bluetooth stack and its utilities (770 allready has it)
  • a bluetooth dongle (770 has one integrated)

Scenarios

Different kinds of connections are possible via PAN as bluetooth can handle more than one connection at a time. They are called NAP (network access point) which works just like a WLAN access point and GP (Group ad-hoc Network). For further details see BlueZ'''**s HOWTO-PAN.

As an example we explain setup of a simple point-to-point connection using a box running Debian as NAP (imagine a server) and a 770 as PANU (imagine a client).

Point-to-Point Connection

1 .#0 Make sure sdpd is running. This is needed for the following steps to work. Our PAN server will register its service with sdpd and connecting devices will use this to find NAPs.

1 .#1 Start the PAN server in NAP mode to listen for new connections on the Debian box: `#!plain

pand -s -r NAP

`

1 .#2 Establish a connection to the NAP on the 770. For this you have to be root and need a running xterm. `#!plain

pand -Q10

` This performs a 10sec search for the HCI address of a NAP and then connects to it.

1 .#3 On each side you can check for the connection with: `#!plain

pand -l

If you see something like #!plain bnep0 00:12:37:4E:8E:D9 NAP on the NAP side, you got a connection and a new virtual network interfacebnep0`.

1 .#4 Now configure the virtual network interfaces (endpoints of the bluetooth connection) on each side. That is straight forward and assignes IP addresses to this interfaces: `#!plain

ifconfig bnep0 10.0.0.1

on the NAP side and #!plain

ifconfig bnep0 10.0.0.2

` on the client side. Now you should be able to ping each other. (**Hint''': the ping binary of the Debian ARM package inetutils-ping works out of the box on the 770!)

You don't need to do this by hand, though. You can write the needed instructions into /etc/bluetooth/pan/dev-up script that is executed when the connection is created.

Internet Connectivity

To use the webbrowser or any other IP capable application on your 770 you need to set up a "dummy" internet access point. Also make sure to enable ip-forwarding on the NAP (PC) side

#!plain
# echo 1 > /proc/sys/net/ipv4/ip_forward

and add a default gateway on the PANU side

#!plain
# route add default gw 10.0.0.1

Getting DNS to work

If you have an internet connection, and can connect to any IP address, but not to a domain name, you need to configure DNS on your tablet. First, find out the DNS address supplied by your ISP. Then: do this (as root):

Create /tmp/resolv.conf.bnep0 with the address to your DNS server

#!plain
echo "nameserver XXX.YYY.ZZZ.QQQ" > /tmp/resolv.conf.bnep0
(replace XXX.YYY.ZZZ.QQQ with IP address of your DNS server)

Edit /etc/dnsmasq.conf After the line: resolv-file=/tmp/resolv.conf.lo
add a new line: resolv-file=/tmp/resolv.conf.bnep0

And restart the dnsmasq daemon by doing

#!plain
/etc/init.d/dnsmasq restart

Now you should be all set.

Automation on PC side

The following statements where made for Debian. Translate them for you distro!

To make your life easier, read Debians documentation about bluez-utils in /usr/share/doc/bluez-utils/README.Debian.gz and edit /etc/default/bluez-utils to configure the bluetooth services started at boot time.

todo: DHCP, use hotplug to automatically bring up bnepX interfaces when they are created

Known to work

As of 8th Nov. 2005 I got the following to work: * Connect to Nokia 770 with each other via pand. ping and ssh where possible. * Connect a Nokia 770 to a Debian box via pand. ping, surfing and mailing where possible. Used dhcpd on Debian and udhcpc on the Nokia 770 for automatic interface configuration.

ToDo

Fedora Core 4 (Vermeer 8/7/2006)

I didn't get pand started automatically. So I just added the statements #!plain /usr/bin/sdptool add NAP /usr/bin/pand <del>listen </del>role NAP to the file /etc/init.d/bluetooth, the start() section, and #!plain killproc pand to the stop() section. Probably not the officially recommended way. Better ideas?

As for running the ifconfig command automatically under Fedora, I failed miserably.

  • Adding the command to /etc/sysconfig/network-scripts/ifup-bnep had no effect (why not?)
  • Adding bnep to the list in (two places) /etc/hotplug/net-agent: #!plain ppp*|ippp*|isdn*|plip*|lo*|irda*|dummy*|ipsec*|tun*|tap*|bnep* similarly had no effect.
  • Adding to /etc/sysconfig/networking-scripts the file ifcfg-bnep0 containing #!plain DEVICE=bnep0 BOOTPROTO=static IPADDR=10.0.0.1 NETMASK=255.0.0.0 ONBOOT=no as advised, was similarly useless.

  • Rebooting didn't change things.

So, I put the ifconfig command in a small shell script to be executed manually everytime a connection is made. A kludge, better ideas?


Small hack for automation on device side

Requirements

  • PC that works as router like described above
  • 770 in rd-mode

Installation

  • Enable rd-mode in your n770
  • Untar nap installer
  • Edit startstopnap.sh and dev-up scripts according your settings
  • Copy whole nap/ dir to your mmc using usb cable
  • Open xterm on device
  • Gain root (sudo /usr/sbin/gainroot)
  • Goto /media/mmc1/nap
  • Run install "sh install.sh" (Sorry, no uninstaller due this is just a hack until something official comes out)

Usage

  • Discover and pair the new "phone" first (has to be done only once) Note that the 770 does not see PAN service in host PC as workable, so to successfully pair and add PC to list of "phones", you might need to temporarily run "sdptool add dun" on PC before pairing.
  • Select NAP connection from connection menu (NAP is dummy connection) NOTE: This needs to be done first in order for DNS to work.
  • Select "NAP start/stop" fromt the file menu
  • Wait a few secs and you are up
  • To disconnect select "NAP start/stop" again

SDPD setup

By default the 770 does not have sdpd enabled. You can enable it e.g. by editing /etc/init.d/bluez-utils (find the line that starts with SDPD_ENABLED=). After the change you'll either need to reboot or run /etc/init.d/bluez-utils restart. (according to Johan Hedberg at nokia.com) - sic

SDPD_ENABLED=1 in /etc/init.d/bluez-utils

DUND setup

Make sure dund is enabled. For Debian, make sure

DUND_ENABLED=1 in /etc/default/bluez-utils.

Make sure the options to dund include listen persist msdun call dun. (For Debian, DUND_OPTIONS="listen persist msdun call dun" in /etc/default/bluez-utils).

PPP setup

Now, setup the PPP connection.

* In Linux, configure the /etc/ppp/peers/dun file to:
 debug
 debug
 passive
 5760 0
 noipdefault
 proxyarp
 # IP address of PC : IP address to be assigned to 770
 10 .0.0.1:10.0.0.2
 # 192.168.2.15: 192.168.2.14 <- I think this is the default of 770 current setup
 # My DNS server
 ms-dns 192.168.5.5
 ktune
 noauth
 local
 nodefaultroute
 noipx
 persist

Set your real DNS server address instead of 192.168.5.5. Question: How do you find out your real DNS server? If your computer is connected directly to the internet, what is the DNS? Enable routing and address translation

* Enable routing. You can either run the command echo 1 > /proc/sys/net/ipv4/ip_forward at some stage before trying to use hotsync, or (for Debian anyway) add the line net/ipv4/ip_forward=1 to /etc/sysctl.conf.

* Enable address translation: `#!plain

iptables <del>table nat </del>append POSTROUTING -j MASQUERADE`

Run SDPtool to add DUN

# sdptool add dun

Bluez-pin

In Linux PC / Desktop

# hcitool scan

This will, hopefully, return the Bluetooth ID of Nokia 770. Copy down this ID, you'll need it again.

Now run the following command to establish a connection between your Linux box and Nokia 770. You can view active connections with the hcitool con command.

#hcitool cc XX:XX:XX:XX:XX:XX

At this point, Nokia 770 should ask you if you wish to accept an incoming Bluetooth connection from your Linux box. Accept, and enter the same PIN number you entered in your Nokia 770.

In order to allow incoming connections from the phone to the USB adapter on your Linux box, you should use the bluez-pin application:

#bluez-pin in XX:XX:XX:XX:XX:XX (Substitute the X's for your Nokia 770 ID)

Run also the bluez-pin application for outgoing connections as well

#bluez-pin out XX:XX:XX:XX:XX:XX (Substitute the X's for your Nokia 770 ID)

(Not tested yet, I am having problem in pairing (bluez-pin) using D-link USB dongle in Ubuntu. I used NAP "package" above. I think bluez-pin is not problem now. I think the /etc/peers/ppp/dun setup as added above now. Not tested yet. Please try and report if NAP and DUN working with this new info. -NS/sic)

Windows and WIDCOMM

(questions on this section should go to AlexanderLash)

Requirements: root access, some time, and a recent version of WIDCOMM (5.0.1.801 is the version I'm using).

If you're using the WIDCOMM stack on Windows, the process is relatively straightforward.

First, right-click the WIDCOMM tray icon and go to Advanced Configuration. In the local services tab, change the properties of "Network Access" so that it will start automatically (checkbox) and then set the dropdown as appropriate (enable Internet+LAN or just LAN sharing depending on whether you want your computer to serve as a router or as a bridge.) You will also need to enable OBEX services (at least temporarily) so that the Nokia phone pairing tool will allow you to pair. Then, under the Accessibility tab, make sure that "Let other Bluetooth devices discover this computer" is checked. Click OK.

Note I had to enable the Dial-Up Networking (not OBEX) service in WIDCOMM. WIDCOMM won't let you do this unless you have a modem. Since I didn't, I just told Windows that I did. Once DUN was enabled, my computer showed up as a "Phone" and I was able to pair to my n800 properly.

Optional step: If you wish for your computer to serve as a router (required if your computer is plugged directly into your ISP or if your network does not allow unauthorized computers to connect) you will need to enable Internet Connection Sharing on your internet connection, and indicate that your home network is 'Bluetooth Network' (or similar: auto-created by the WIDCOMM tools.)

On the Nokia, pair with your computer as you would pair with a phone. Open up a root terminal, and try the following (assumes that you either bridged to a network with a DHCP server, or that your computer is serving as a DHCP server via Internet Connection Sharing):

(Note that this will sometimes fail the first time, as the Nokia does not wait long enough for manual authorization of connections. The solution is to wait for the pop-up that asks you to approve the Nokia's connection, click it, and click the option that will automatically approve connections from the Nokia in the future. Afterwards, try these steps again.)

pand -Q10
pand -l #Should show something like 'bnep0 00:12:37:4E:8E:D9 NAP'
udhcpc -i bnep0
ifconfig bnep0 #Should show that you have a valid IP

I've had to use pand -s instead of pand -Q10 and PAN was visible as a service of PAN on my PC what i could connect to drivers --shw

If ifconfig bnep0 shows you have an IP, you are in business. As with the linux method, to use the webbrowser or any other IP capable application on your 770 you need to set up a "dummy" internet access point.

CategoryBluetooth CategoryHowToNetworking