Skip navigation.

Using your mobile phone as modem in Gentoo (via Bluetooth)

, , , ,

Okay, no fancy introductions this time. I'm going to document here how I've managed to connect to the Internet using a mobile phone (over Bluetooth). I'm pretty sure other people might find this post helpful. Also, I'm pretty sure I myself will find it helpful in future. :D

Introduction
My current system is an Asus M51S laptop (with built-in bluetooth), running stable amd64 Gentoo/Linux. The mobile phone is Nokia 6120 classic (with Claro as mobile operator), but the setup was also previously tested with Sony Ericsson K750i (with Oi as mobile operator).

Although BlueZ versions 3.25 until 3.36 are available in portage, I'm still using 2.25, since this is the latest version marked as stable. The exact package versions are net-wireless/bluez-libs-2.25 and net-wireless/bluez-utils-2.25-r1.

Bluetooth configuration
Pretty simple, very straightforward.

I've modified only one line from /etc/bluetooth/hcid.conf, and only for cosmetic reasons:
  # Local device name
  #   %d - device id
  #   %h - host name
  #name "BlueZ (%d)";
  name "BlueZ %d@%h";
This way, instead of just BlueZ 0, the laptop will be named as BlueZ 0@hostname. If you have more than one bluetooth-enabled computer nearby, it should be very obvious why this is an important change.

Then, I've modified /etc/bluetooth/rfcomm.conf. This file configures all RFCOMM ports available to this computer, which can be seem as "serial-over-bluetooth", or something like that.
rfcomm0 {
  bind yes;
  device 00:12:EE:0E:67:1B;
  channel 1;
  comment "Denilson's K750i phone";
}
rfcomm1 {
  bind yes;
  device 00:1B:AF:15:EF:62;
  channel 2;
  comment "Denilson's Nokia 6120 classic phone";
}
The bind option defines if the /dev/rfcomm* devices should be created at the startup. All other options are pretty self-explanatory.

You can discover the Bluetooth address of your device by running hcitool scan. Make sure the device is set as visible.

The Bluetooth channel works basically the same way as TCP and UDP ports. Well, not exactly the same way, but the concept is somewhat similar: you have multiple channels for RFCOMM on your Bluetooth device, and each channel corresponds to a service.

To discover what channel you should use, run sdptool browse 00:12:EE:0E:67:1B, where, obviously, you should put the correct device address. This command will print over a hundred lines, so probably you will want to save the output to a file (> temp.txt), pipe it to a pager (| less), or pipe it directly into Vim (| vim -). Then, look for a section similar to this one:
Service Name: Dial-up Networking
Service RecHandle: 0x10001
Service Class ID List:
  "Dialup Networking" (0x1103)
  "Generic Networking" (0x1201)
Protocol Descriptor List:
  "L2CAP" (0x0100)
  "RFCOMM" (0x0003)
    Channel: 1
Profile Descriptor List:
  "Dialup Networking" (0x1103)
    Version: 0x0100
As you can see, in this phone the Dial-up Networking service is available at RFCOMM channel 1. At the other phone, however, the same service is available at channel 2. This is why you need to find what channel your phone uses.

Finally, you should make sure that the RFCOMM service is enabled at /etc/conf.d/bluetooth:
# Bind rfcomm devices (allowed values are "true" and "false")
RFCOMM_ENABLE=true
That's all! You can start the bluetooth daemons by running /etc/init.d/bluetooth start (you can also use restart or stop).

One interesting sidenote: you don't need to manually tell the system to start bluetooth service on boot. There is a udev rule at /etc/udev/rules.d/70-bluetooth.rules that calls /lib/udev/bluetooth.sh script, that calls /etc/init.d/bluetooth with start or stop parameters. This means that, if a Bluetooth device is plugged in, the bluetooth service will automatically start. If the device is unplugged, then the service will automatically stop.

PPP configuration
One thing I love about Gentoo is the network configuration file. All interfaces are configured at one single file: /etc/conf.d/net. Each interface gets a symlink in /etc/init.d/, so, essentially, each interface works as a service. There is also a huge /etc/conf.d/net.example file that you should look. Although sometimes this file seems a bit complicated and messy, it's actually very powerful and simple to understand.

Back on topic, here are the settings:
# Internet over mobile phone bluetooth
config_ppp0=( "ppp" )
link_ppp0="/dev/rfcomm1"  # rfcomm1 is my Nokia 6120 classic
phone_number_ppp0=( "*99#" )
#phone_number_ppp0=( "*99***1#" )
username_ppp0=''
password_ppp0=''
#username_ppp0='web'
#password_ppp0='web'
pppd_ppp0=(
  "maxfail 10"
  "noauth"
  "lcp-echo-interval 5"
  "lcp-echo-failure 12"
  "debug"
  "noipdefault"
  "defaultroute"
  "usepeerdns"
  "ipcp-accept-remote"
  "ipcp-accept-local"
  "holdoff 3"
  "noaccomp noccp nobsdcomp nodeflate nopcomp novj novjccomp"
  "921600"
  "lock"
  "nocrtscts"
)
chat_ppp0=(
  'ABORT' 'BUSY'
  'ABORT' 'ERROR'
  'ABORT' 'NO ANSWER'
  'ABORT' 'NO CARRIER'
  'ABORT' 'NO DIALTONE'
  'ABORT' 'Invalid Login'
  'ABORT' 'Login incorrect'
  'TIMEOUT' '5'
  '' 'ATZ'
  'OK' 'ATM0'
  # Next line is required for Nokia, except if you set the access point at
  # Settings->Phone sett.->Connection->Packet data->Access point
  #'OK' 'AT+CGDCONT=,,"claro.com.br"'
  'OK' 'ATDT\T'
  'TIMEOUT' '60'
  'CONNECT' ''
  'TIMEOUT' '5'
  '~--' ''
)
There are many small things I want to point out in these lines:
  • There are some obvious changes that you must make in order to suit your needs, like renaming ppp0 to ppp1 or any other number, and setting the correct /dev/rfcomm* device.
  • The *99# phone number appears to be a standard for all mobile phone data connections. However, if this number does not work for you, try *99***1#.
  • Usually, username/password can be left empty. If, for some reason, it does not work, you can pass some dummy values, like web/web or operatorname/operatorname.
  • The pppd options are based on Gentoo's net.example file, plus some other things I found somewhere on the Internet. However, I'm not sure what are the best possible options, and I think no one really knows for sure.
  • The chat script is also from Gentoo's net.example file.
  • The AT+CGDCONT line is tricky, as not all phones require that. I found this line on the Internet. There are some variants too.

Access point configuration on Nokia phones
I think the AT+CGDCONT command deserves a deeper explanation, so let me try to describe it.

First of all, I never needed this command with Sony Ericsson K750i, nor with any other device I had access (I've used one or two 3G modems, and none of them required that). However, for "some reason", this Nokia didn't want to work without this command. Looking at the web, I found that other Symbian S60 Nokia phones also required such command.

There is an explanation. These Nokia phones have a setting to let the user define the (default) access point for data connections. This setting, however, is separate from access point setting for applications that run on the phone itself.

I feel the S60 interface is confusing, but that's the subject for another post. Anyway, you have two choices: define the (default) access point at the phone itself, or pass it using an AT command:
  • At your Nokia S60 phone, go to Settings -> Phone sett. -> Connection -> Packet data and type the access point at Access point text field. If you don't know what to type, go back one level and select Access points option to see the configured access points at your phone. Select (edit) the one you use for data connection and you will see in Access point name what you have to type.
  • Or, at your computer, uncomment that "AT+CGDCONT" line (and change the access point to the one from your operator).
I found some variations of that "AT+CGDCONT" command, passing more parameters. I have no idea what they mean, and Wikipedia's AT commands article is not helpful either.

Finishing off
If you are a Gentoo user, you should already know this. If you are not a Gentoo user, you don't need to know this... Anyway, for completeness sake, I'm describing these last steps:
cd /etc/init.d
ln -s net.lo net.ppp0
/etc/init.d/net.ppp0 start
Open another root terminal with this command tail -f /var/log/messages, just to make sure everything works, or to find out why something does not work.

If everything went well, you should have a ppp0 interface up and running, and some DNS servers at /etc/resolv.conf.

Final thoughts
Some people say that Internet connection over Bluetooth is noticeably slower than over USB. If you have those high-speed 3.5G connections, that's probably true, as they can reach 7.2 Mbit/s or so. According to Wikipedia, Bluetooth 1.2 has 1 Mbit/s data rate, while Bluetooth 2.0 + EDR has 3 Mbit/s. Of course the actual throughput is probably lower than this (because of wireless noise, and also because of overhead from multiple layers of protocols). In my case, though, 1 to 3 Mbit/s is more than enough (usually the 3G connection speed here is lower than that), so it's not a problem. Also, the freedom of cables is something very nice in some situations.

If you want to use the connection over USB, I think you just need to change the link_ppp0 line to point to your phone (probably /dev/ttyUSB0 or /dev/ttyACM0), and nothing more. Maybe you need to recompile your kernel to enable some driver module, but this is beyond the scope of this post.

By the way, if you know some way to discover the version of a Bluetooth device (1.2 or 2.0), as well as discovering if it has EDR, please tell me!

As I said, the settings above worked fine for both Sony Ericsson K750i (which has only 2G/GPRS support) and Nokia 6120 classic (which has 3G/3.5G support). They also worked for different mobile operators. Of course, YMMV.

P.S.: I still need to write a blog post about this Nokia 6120 classic.

Windows Explorer folder type in VistaBrowser sniffing is bad

Comments

Aadil 21. January 2009, 14:01

I have an application on my phone called joikuspot.
This application allows you to use the WLAN port on my phone as a wireless access point. I wonder which would be more effective for the average person.
I'll keep this post in mind though since I may just want to use this method one day when I actually buy a laptop. :up:.

Denilson Figueiredo de Sá 21. January 2009, 17:31

Oh, just a notice: neither phone I tested had Wi-Fi support. Thus, the only options were bluetooth and USB.

Aadil 21. January 2009, 18:45

Point taken. :lol:

Aadil 14. August 2009, 19:52

Update: I've recently purchaced a small 'netbook' running Linpus Linux Lite. This machine has built-in wi-fi support. JoikuSpot does not work with this combination on my Nokia E65. Googling shows that many people have this problem. It appears that Apple Macs have the most success with Joikuspot. :left:.

How to use Quote function:

  1. Select some text
  2. Click on the Quote link

Write a comment

Comment
(BBcode and HTML is turned off for anonymous user comments.)

If you can't read the words, press the small reload icon.


Smilies

December 2009
S M T W T F S
November 2009January 2010
1 2 3 4 5
6 7 8 9 10 11 12
13 14 15 16 17 18 19
20 21 22 23 24 25 26
27 28 29 30 31