Linux, 3G, bluetooth and DUN

So I got this working on my older Nokia 3120, then got an E52 and then had to go through all of this again. So I decided that’s that, I need a reference. Posted here because it’s least likely to go away, and easiest place to find it again. Also, other people may find this useful.

First things first, you obviously need the Linux bluetooth stack. Look for a package containing “bluez”, on Gentoo Linux there is two sets, the first is bluez-utils and a bunch of other dependencies, and “bluez” (which from what I can tell is the newer stuff). Once you’ve got this installed you should probably try and start the bluetooth daemon to see if it starts, also whether the drivers are loaded etc …

Finding the Bluetooth drivers for your chip is not something I’m going to discuss, lspci and lshw is your friends in this respect, and most distro’s will auto-load kernel modules based on available hardware. If you can type “ip ad sh” and see a pan0 device you’re probably good to go.

At this point I suggest looking at /etc/bluetooth and editing as you see fit (starting with main.conf, probably only want to edit Name = … and even that’s a maybe).

To find out whether all actually works as expected, you should be able to run “hcitool scan”, this should output something like:

# hcitool scan
Scanning ...
        34:7E:39:62:7B:65       Reboot
#

Reboot is my new Nokia phone. The MAC-addr like number on the left is called a bdaddr. Get that string in your cut buffer – you’re going to need it a lot.

Now you need to “pair” your phone with your laptop. This is the hardest part of the whole exercise and depends on which of the tools you’re using. I had quite a lot of trouble doing this from command-line only and eventually just installed gnome-bluetooth and used the wizard to pair, then on my phone set my laptop to authorized to allow it to connect without having to go through the whole pairing process every time. On the laptop side I didn’t actually change anything or had to set things explicitly.

With the 4.XX variant of bluez (without bluez-utils) a new utility called simple-agent is included. Just run it from the command-line, and attempt to connect to your phone. Your phone should prompt for a key first, enter one, and then when you hit OK on the phone the utility will prompt in return. This should be it.

The next step is to locate the bluetooth “endpoint” on the phone to use for dial-up networking. This is done using sdptool:

# sdptool search --bdaddr 34:7E:39:62:7B:65 DUN
Searching for DUN on 34:7E:39:62:7B:65 ...
Service Name: Dial-Up Networking
Service RecHandle: 0x10047
Service Class ID List:
  "Dialup Networking" (0x1103)
Protocol Descriptor List:
  "L2CAP" (0x0100)
  "RFCOMM" (0x0003)
    Channel: 5
Language Base Attr List:
  code_ISO639: 0x454e
  encoding:    0x6a
  base_offset: 0x100
Profile Descriptor List:
  "Dialup Networking" (0x1103)
    Version: 0x0100

#

The important bit there is Channel: 5. Now edit /etc/bluetooth/rfcomm.conf, in particular we want to create a serial device called rfcomm0, that always binds to our phone, on the correct channel. The config file ends up looking like this:

rfcomm0 {
    bind yes;
    device 34:7E:39:62:7B:65;
    channel 5;
    comment "DUN on Reboot";
}

Now restart bluetooth again and you should now have a rfcomm0 device node in /dev/. If you do, try opening two terminals, in the one, issue cat /dev/rfcomm0, and in the other issue “echo ATZ > /dev/rfcomm0”, the cat side should echo back your ATZ and hopefully not spit too much gunk at you. From here on it’s pretty simple. I use my chat perl script from my 3G, PINs, prompts and pppd entry, along with this file in /etc/ppp/peers/:

/dev/rfcomm0
linkname 3g-rfcomm0
defaultmetric 5000

# Don't require the peer to authenticate (this _seems_ to get the connection going in a shorter time)
noauth

# If you want more detailed logs, enable this (it doesn't generate that much
# noise, but assists a lot in finding problems):
#debug

# Make this one second since the modem probably has to be re-initialized at least
# once.
holdoff 1

# modem initialization
connect /usr/local/sbin/uls_3g_connect.pl

# We probably want to use the DNS as advertized by the peer
usepeerdns

# Use this link as the default gateway
defaultroute

# Inform out ip-up script about what this is:
ipparam "type=intl dnsroutes=yes routemetric=10"

# 3G doesn't like all kinds of compression ... which they did - it's slow
# enough.
noccp
nobsdcomp
novj

# Make the connection persistent, and not terminate if/when errors occur.
persist
maxfail 0

There is no real difference between this peers file and the one in 3g from the blog mentioned above. This one just adds a linkname and explicit reference to the rfcomm0 device. I saved this file as bluetooth. Now you should be able to run “pon bluetooth”, or more directly “pppd call bluetooth” or even “pppd call bluetooth debug nodetach” if you prefer.

One Response to “Linux, 3G, bluetooth and DUN”

  1. Daniel Correia says:

    Very nice, man! Good writeup about getting DUN working. Helped a lot.