Tuesday, November 25, 2008

Syntac Checking for PHP in Emacs

Syntax checking for PHP in Emacs

When programming PHP I often find it useful to see parse errors that are created as I type. A missing semicolon at the end of the line, a missing quotation mark, a dot in the wrong place, stuff like that that triggers PHP Fatal or Parse Errors. On-the-fly syntax checking is a common feature of good programming IDE’s and editors. Emacs is no exception – there’s flymake minor mode that is meant to help you discover errors at the time of writing code. Flymake is currently a part of Emacs distribution and it covers on-the-fly syntax checks for a lot of popular programming languages like C, C++, Java, Perl and others. Unfortunately PHP syntax checks are not included in that package. I have been looking around trying to find an extension for flymake to make it work with PHP

but couldn’t find any so I decided to write my own.

Flymake-php.el is a bit os Lisp code that plays nicely with flymake and PHP on-the-fly syntax checking. Below you can see this extension in action:

!Flymake and PHP in action

How to install ?

1. Copy the following code to your Emacs library path (for example ~/.emacs.d/flymake-php.el)
    ;; Flymake PHP Extension

(require 'flymake)

(defconst flymake-allowed-php-file-name-masks '(
(".php3'" flymake-php-init)
(".inc'" flymake-php-init)
(".php'" flymake-php-init))
"Filename extensions that switch on flymake-php mode syntax checks")

(defconst flymake-php-err-line-pattern-re '("(Parse|Fatal) error: (.*) in (.*) on line ([0-9]+)" 3 4 nil 2)
"Regexp matching PHP error messages")

(defun flymake-php-init ()
(let* ((temp-file (flymake-init-create-temp-buffer-copy
(local-file (file-relative-name
(file-name-directory buffer-file-name))))
(list "php" (list "-f" local-file "-l"))))

(defun flymake-php-load ()
(setq flymake-allowed-file-name-masks (append flymake-allowed-file-name-masks flymake-allowed-php-file-name-masks))
(setq flymake-err-line-patterns (cons flymake-php-err-line-pattern-re flymake-err-line-patterns))
(flymake-mode t)
(local-set-key "C-cd" 'flymake-display-err-menu-for-current-line))

(provide 'flymake-php)
2. Make sure the library path is present in your .emacs, for example:
    (add-to-list 'load-path "~/.emacs.d/")
3. Require the flymake-php extension
    (require 'flymake-php)
4. If you’re using php-mode (I bet you are if you program in PHP) you can add a hook to this extension, so that every time a php-mode is switched on you’ll have flymake minor mode running. 5.
(add-hook 'php-mode-user-hook 'flymake-php-load)


Now every time you open a php file that has an extension specified in flymake-allowed-php-file-name-masks a flymake minor mode will be switched on with on-the-fly syntax checking. If you see a highlighted line you can position the cursor on the line and press C-c d to see a popup window with an error message (similar to the screenshot above).

M-x flymake-goto-next-error and M-x flymake-goto-prev-error functions allow for easy navigation to the next/previous erroneous line, respectively. You can also bind these functions to the keys of your choice (local-set-key function).

How does this work ?

Quote from flymake-info manual:

Flymake runs the pre-configured syntax check tool (compiler for C++ files, `perl’ for perl files, etc.) in the background, passing it a temporary copy of the current buffer, and parses the output for known error/warning message patterns. Flymake then highlights erroneous lines (i.e. lines for which at least one error or warning has been reported by the syntax check tool), and displays an overall buffer status in the mode line. Status information displayed by Flymake contains total number of errors and warnings reported for the buffer during the last syntax check.
Syntax check is done ‘on-the-fly’. It is started whenever

- buffer is loaded - a newline character is added to the buffer - some changes were made to the buffer more than `0.5’ seconds ago (the delay is configurable).

Customise your flymake

You can further customise your flymake-mode. For example to disable a syntax check every time a newline is added to a buffer you can set flymake-start-syntax-check-on-newline variable to nil, eg.:

(setq flymake-start-syntax-check-on-newline nil) 

You can also customise the look of the error line “face” (font, size and color of the error line) by setting flymake-errline-face. Please refer to flymake info manual for all the available options.

php.ini settings Because flymake will call php -l temp-buffer every time a request is trigger it’s a good idea to disable error logging in php.ini (cli version)

; Log errors into a log file (server-specific log, stderr, or error_log (below)) ; As stated above, you’re strongly advised to use error logging in place of ; error displaying on production web sites. log_errors = Off

What about warnings ?

If you’re an adventurous soul (by this I mean “hacking Lisp code” type of adventure :) ), you may extend this a little bit and add support for PHP warning messages.

Sunday, November 16, 2008

Bluetooth PAND (Personal Area Network) Howto For Debian Etch


I wanted to access the internet over bluetooth instead of GPRS/3G network from my mobile phone (SE K800i). After a lot of searching I couldn't find a clear explanation as how to accomplish this. I did manage to set it up with Windows XP, using the "Personal Area Network" in the bluetooth utility and doing internet connection sharing. After another fruitless search, I managed to figure out how to make a bluetooth internet profile instead of GPRS or 3G on the phone. Since I work in Linux most of the time, I decided to have a go and do it with Debian, my workstation's main OS. After spending a few hours, I had it working using the steps below.

This howto is for Debian Etch, current "testing" branch soon to be 4.0. May work on Ubuntu or other Debian based distros. Settings for older versions may be similar. In Debian 3 the bluetooth daemon maybe regarded to as hcid.


  • Kernel 2.6.x, may work under 2.4, not tested.
  • iptables is needed if you want to access other computers or the internet.


apt-get install bluetooth

install apt get install bluez-utils

install apt-get install dhcp3-server


apt-get install kdebluetooth

Has the kde pinhelper application for easy pairing.

Note: Pairing your bluetooth devices is beyond the scope of this howto. It assumes you can pair you device to your system.

As root:

Edit /etc/bluetooth/hcid.conf. Change

lm accept;


lm accept, master;

Edit /etc/default/bluetooth.Change







PAND_OPTIONS="--listen --role=NAP --devup /etc/bluetooth/pan/dev-up"

mkdir /etc/bluetooth/pan

touch /etc/bluetooth/pan/dev-up

Put the following in /etc/bluetooth/pan/dev-up:

echo 1 > /proc/sys/net/ipv4/ip_forward
ifup bnep0
sleep 2
/etc/init.d/dhcp3-server restart

Make it executable:

chmpd +x /etc/bluetooth/pan/dev-up

In /etc/network/interfaces add the bluetooth interface as follows:

iface bnep0 inet static

post-up iptables -t nat -A POSTROUTING -s -j MASQUERADE
post-up iptables -A FORWARD -i bnep0 -o eth0 -j ACCEPT
post-up iptables -A FORWARD -o bnep0 -i eth0 -j ACCEPT
pre-down /etc/init.d/dhcp3-server stop

eth0 is the interface you will be NAT-ed behind. Your external interface.

Change the IPs and network settings as you like, just make sure to also reflect it in your dhcp.

In /etc/dhcp3/dhcpd.conf make sure you set

option domain-name "somedomainname.com";
option domain-name-servers ip-of-dns-server-goes-here;

where ip-of-dns-server-goes-here is the IP address of the dns server to use. You can see the server you're using in /etc/resolv.conf.

Declare a subnet for the PAN segment, should be the subnet you used for the bnetp device in /etc/network/interfaces. Replace the option routers; with the IP you have given your bnep0 interface in /etc/network/interfaces.

subnet netmask {
option domain-name-servers;
option domain-name "bluetoothap.int.yourdomain.com";
option routers;
option broadcast-address;
default-lease-time 600;
max-lease-time 7200;

Now restart the bluetooth daemon:

/etc/init.d/bluetooth restart

Pair your device with the machine. Once paired you should be able to access the network using the bluetooth PAN service for another computer, PDA or mobile phone.


1. See if your bnep0 device is going up when a connection is requested and the interface is asked to come up. You can watch this with the following command as root:

watch -n1 “ifconfig”

You should see bnep0 coming up when you fire up your bluetooth client device to try and access the PAN network.

2. See that the script /etc/bluetooth/pan/dev-up is being executed.

3.Watch the output of syslog to see if the dhcp server is asinign an IP to your device.

tail -f /var/log/syslog

tail -f /var/log/messages

4. Once you see the IP, try to ping your device with the ping command.

Bluetooth PAN settings for Sony Ericsson k800i


Settings -> Connectivity -> Data Accounts.

In the list you should see your bluetooth AP.

Go to

Settings -> Connectivity -> Internet Settings -> Internet Profiles -> New profile

In Name enter a name for the connection. eg. PAN.

For Connect Using choose the bluetooth icon with the name of your bluetooth machine, the one showing in the data accounts, and also the PC you paired your k800i with.

Now make this profile active for internet, java and streaming.

Make sure you press save.

Now you should be able to browse the internet trough your k800k. Enjoy!

How to use your blackberry as a modem in Debian

After aquiring a BlackBerry cellphone, I wanted to use it as a modem for my laptop, running Debian. Here's how to do it via USB:

I recommend you read all this procedure before starting

  • Install barry (so you can use the cellphone via USB, this makes it chargeable too

  • Install XmBlackBerry

  • connect your mobile phone to your computer, via USB

  • sudo XmBlackBerry

  • clicking in the options menu you'll see in the stderr (console where you
    run this app) a /dev/pts/something , which is your GPRS device

  • click "connect" and see if your phone tells you that you're connected to the desktop

  • sudo vi /etc/chatscripts/blackberry :

    SAY “Initializing\n”
    ” ATZ
    SAY "ATE\n"
    OK 'AT+CGDCONT=1,"IP","wap.voicestream.com"'
    OK 'AT'OK 'ATDT*99***1#'
    SAY "Dialing\n"

  • (change "device" here) sudo vi /etc/ppp/peers/blackberry

    debug debug debug
    connect "/usr/sbin/chat -f /etc/chatscripts/blackberry"
    ipcp-restart 7
    lcp-echo-interval 0
    lcp-echo-failure 999
    user ""
    password ""

  • sudo pppd call blackberry

And you're on!

Yeah, but how to install XmBlackBerry?

Here are the steps to install XmBlackBerry:

* get and install libmotif 2.3.0 debian packages here
* aptitude install xaw3dg-dev xorg-dev x11proto-print-dev autoconf libtool libopensync-dev libcurl4-openssl-dev
* As root, run
ln -s /usr/include/X11/Xaw3d /usr/include/X11/Xaw
* Install Xlt (tested with 13.0.13): get it here, untar it and, in its directory...

./configure --with-motif-libraries=/usr/X11R6/lib --prefix=/usr
make && make install

* Install XmBlackBerry:

cvs -d:pserver:anonymous@xmblackberry.cvs.sourceforge.net:/cvsroot/xmblackberry co XmBlackBerry
cd XmBlackBerry/
cvs -d :pserver:anonymous@libusb.cvs.sourceforge.net:/cvsroot/libusb co libusb
cd libusb
make && make install
cd ..
./configure --enable-maintainer-mode --disable-shared --with-motif-libraries=/usr/X11R6/lib
sudo make install
sudo ln -s /usr/X11R6/lib/libXm.so.4 /usr/lib/libXm.so.4

And how to install Barry?

In Pearl's case you need CVS version of it.

* Install barry:
cvs -d:pserver:anonymous@barry.cvs.sourceforge.net:/cvsroot/barry login
cvs -z3 -d:pserver:anonymous@barry.cvs.sourceforge.net:/cvsroot/barry co -P barry
cd barrysh
./configure --prefix=/usr
sudo make install
sudo cp udev/*b* /etc/udev/rules.d/.

Howto setting up bluetooth audio under Debian

This is a quick how to setting up bluetooth audio under Debian.

First off we need to install a couple packages:

# apt-get install bluez-utils bluez-gnome bluez-audio

Now we need to run ‘hcitool scan‘ to get the address of the bluetooth device. For example,

$ hcitool scan
Scanning ...
00:00:00:00:00:00 Nokia BH-501

Now to get the audio part to work:

Modify or create your ~/.asoundrc to contain

  1. pcm.bluetooth {
  2. type plug
  3. slave {
  4. pcm "bluetooth_hw"
  5. }
  6. }

  7. pcm.bluetooth_hw {
  8. type bluetooth
  9. device 00:11:22:33:44:55
  10. profile "auto"
  11. }

Where 00:11:22:33:44:55 is the bluetooth address of your headset that you got from ‘hcitool scan‘ output

Now to test the bluetooth headset audio is working with ‘arecord‘ and ‘aplay‘ for example,

$ arecord -Dplug:bluetooth -f S16_LE | aplay -Dplug:bluetooth -f S16_LE
Recording WAVE 'stdin' : Signed 16 bit Little Endian, Rate 8000 Hz, Mono
Playing WAVE 'stdin' : Signed 16 bit Little Endian, Rate 8000 Hz, Mono
Aborted by signal Interrupt...
Aborted by signal Interrupt...

Finally configure your audio applications to use the alsa device ‘bluetooth’.

Example fro setting up Skype to use the bluetooth headset:
Right click on the Skype icon on the gnome-panel and go Options => Sound Devices and change the ‘Sound In’ and ‘Sound Out’ to ‘bluetooth’ and click apply.

Tuesday, May 6, 2008


Bluetooth USB Dongle

Enable Bluetooth support

  • Check whether Dongle is recognized and working. We use a kernel with bluetooth support! ;)

Start debian bluetooth support:

/etc/init.d/bluez-utils start

The log:

Apr  2 20:54:04 tadpole hcid[19051]: Bluetooth HCI daemon
Apr 2 20:54:04 tadpole hcid[19051]: Starting security manager 0
Apr 2 20:54:04 tadpole sdpd[19055]: Bluetooth SDP daemon
Apr 2 21:04:24 tadpole hcid[19204]: HCI dev 0 registered
Apr 2 21:04:24 tadpole hcid[19204]: HCI dev 0 up

With bluez-utils started successfully we use hciconfig to determine the dongle status:

root@tadpole:~# hciconfig
hci0: Type: USB
BD Address: 00:09:DD:10:50:F8 ACL MTU: 192:8 SCO MTU: 64:8
RX bytes:101 acl:0 sco:0 events:13 errors:0
TX bytes:296 acl:0 sco:0 commands:12 errors:0

This means, the USB bluetooth dongle is operational.

  • We may make the bluetooth stuff be survive reboot:
update-rc.d bluez-utils defaults

Device Detection

  • Put mobile phone in See-Me mode and scan for it:
root@tadpole:~# hcitool scan
Scanning ...
00:0F:DE:14:47:21 TF-Mobile
root@tadpole:~# hcitool inq
Inquiring ...
00:0F:DE:35:71:22 clock offset: 0x569d class: 0x520204

Yep, found the right thingy. We might want to use graphical interfaces (http://gentoo-wiki.com/HOWTO_mobile_phone,_Bluetooth_and_GNOME) to interact with our mobile phone.

Once we know our phone's bluetooth MAC we can ping the phone as we would do on a standard network to check network availability:

root@tadpole:~# l2ping 00:0F:DE:13:88:91
Ping: 00:0F:DE:13:88:91 from 00:09:DD:13:92:F8 (data size 20) ...
0 bytes from 00:0F:DE:13:88:91 id 0 time 38.70ms
0 bytes from 00:0F:DE:13:88:91 id 1 time 40.69ms
0 bytes from 00:0F:DE:13:88:91 id 2 time 43.19ms
0 bytes from 00:0F:DE:13:88:91 id 3 time 37.67ms
0 bytes from 00:0F:DE:13:88:91 id 4 time 35.21ms
5 sent, 5 received, 0% loss

Interestingly enough, the l2ping to a Nokia 6230i is a bit faster. ;)

Ping: 08:00:28:4F:1B:A6 from 00:09:DD:13:88:98 (data size 20) ...
0 bytes from 08:00:28:4F:1B:A6 id 0 time 16.53ms
0 bytes from 08:00:28:4F:1B:A6 id 1 time 29.33ms
0 bytes from 08:00:28:4F:1B:A6 id 2 time 29.63ms
0 bytes from 08:00:28:4F:1B:A6 id 3 time 34.59ms
0 bytes from 08:00:28:4F:1B:A6 id 4 time 33.41ms
0 bytes from 08:00:28:4F:1B:A6 id 5 time 27.51ms
0 bytes from 08:00:28:4F:1B:A6 id 6 time 41.03ms

Connection Establishing

  • We might change the name XYZ line in /etc/bluetooth/hcid.conf to something more personal. :) See man 5 hcid.conf for more.
  • Write a whatever PIN into /etc/bluetooth/pin. Remember it and enter it when prompted for a PIN connecting from your phone to the dongle.
  • When connecting from the phone to the dongle have a look at the logs, /var/log/syslog:
Apr  2 20:26:32 tadpole hcid[18268]: link_key_request (sba=00:09:DD:13:92:F8, dba=00:0F:DE:13:88:91)
Apr 2 20:26:32 tadpole hcid[18268]: pin_code_request (sba=00:09:DD:13:92:F8, dba=00:0F:DE:13:88:91)
Apr 2 20:26:33 tadpole hcid[18268]: link_key_notify (sba=00:09:DD:13:92:F8)
Apr 2 20:26:33 tadpole hcid[18268]: Replacing link key 00:09:DD:13:92:F8 00:0F:DE:13:88:91
Apr 2 20:26:34 tadpole hcid[18268]: link_key_request (sba=00:09:DD:13:92:F8, dba=00:0F:DE:13:88:91)
Apr 2 20:27:11 tadpole hcid[18268]: link_key_request (sba=00:09:DD:13:92:F8, dba=00:0F:DE:13:88:91)
Apr 2 20:27:16 tadpole hcid[18268]: link_key_request (sba=00:09:DD:13:92:F8, dba=00:0F:DE:13:88:91)
  • We may now push our data from the phone to the computer with the USB-dongle connected.
  • It might be necessary to grant access to our X server for the helper tool to query us for the PIN. To do so execute xhost + as user.

Device Capability Discovery

  • Query the capabilities:
sdptool browse

The T630 answer and the one the Nokia 6230i gave.

Pulling Data From Mobile

  • First query the list of available files:
obexftp -b  00:0F:DE:13:88:11 -c Bilder
Browsing 00:0F:DE:13:88:11 ...
Channel: 7
No custom transport
Connecting...bt: 1
Sending Bilder... Sending Bilder... done
Receiving (null).../

  • Get specific file:
radtkens@tadpole:$  obexftp -b  00:0F:DE:13:88:11 -c Bilder  -g "img(27).jpg"
Browsing 00:0F:DE:13:88:11 ...
Channel: 7
No custom transport
Connecting...bt: 1
Sending Bilder... Sending Bilder... done
Receiving img(27).jpg...-done

The image is now in pwd. Fire up gqview and see! :-)

  • To boldly fetch any picture in Bilder directory, use this one-liner:
for i in $(obexftp -b 00:0F:DE:13:88:11 -c Bilder -l 2>&1 | grep .jpg | \
sed 's/.*name="//g; s/" size.*//g'); do obexftp -b 00:0F:DE:13:88:11 -c Bilder -g "$i"; done;
  • We rename the files to a nicer naming scheme:
for i in $(ls *.jpg); do \
no=$(echo $i|sed 's/img(\(.*\)).jpg/\1/g');
mv -vi $i img_$(printf "%03.0f" $no).jpg;

Before: "img(1).jpg", after: "img_001.jpg". Have fun! :-)

Sync Tools

  • obexftp is suitable for pulling images.
  • Synchronise contacts, events and tasks using a tool such as multisync.
  • multisync has IRDA and Bluetooth plugins as well as backup, evolution and SyncML plugins.



Start bluetooth (debian way):

/etc/init.d/bluez-utils start

Check whether our bluetooth is up and running:

hcitool dev
hci0 00:05:33:10:71:F3

This is the MAC address of our USB-bluetooth adapter.

Put your headset into pairing mode and scan for it:

hcitool scan

It should have discovered your headset, so connect to it via:

hcitool cc 

This will require us to enter the headset PIN: To prevent it from asking every time we connect we setup a small pin-helper /etc/bluetooth/pin-helper.sh script:

echo "PIN:0000"

Modify /etc/bluetooth/hcid.conf to match this filename:

pin_helper /etc/bluetooth/pin-helper.sh;

Bluez Configuration Files


options {
autoinit yes;
security user;
pairing multi;
pin_helper /etc/bluetooth/pin-helper.sh;
device {
name "My_bt%d";
class 0x3e0100;
iscan enable; pscan enable;
lm accept;
lp rswitch,hold,sniff,park;
auth enable;
encrypt enable;


rfcomm0 {
bind yes;
device ;
channel 1;
comment "My-bt";

Build btsco


From btsco README:

  • automake-1.7
  • libbluetooth-dev
  • libasound2-dev (aka alsa-devel)
  • a recent ( or newer) kernel with *integrated* alsa enabled (it won't work with the "standalone" alsa drivers that are a separate download from the kernel)

Get btsco from CVS

cvs -d:pserver:anonymous@cvs.sf.net:/cvsroot/bluetooth-alsa login
cvs -d:pserver:anonymous@cvs.sf.net:/cvsroot/bluetooth-alsa co btsco

btsco Compilation

cd btsco/
make install

We might skip this one as we need some tools built that are otherwise wiped again:

make maintainer-clean

Kernel Module Compilation

For SCO (two-way voice quality audio) you need a kernel with the emu10k1 driver selected (this is one of the drivers that forces the inclusion of the implementation of "snd_hwdep_new").

cd kernel/
make install
depmod -e
make clean

Using btsco

modprobe snd_bt_sco

If running esd stop it:

esdctl stop


hciconfig hci0 voice 0x0060

Put headset into pairing mode. It should not be connected with your mobile as it would prevent pairing with our linux box. Run btsco with -v for verbose mode or with -f for daemon mode:


This might ask for the headset PIN. Standard is with most devices 0000.


Play some WAV file (not every WAV will work, try some):

aplay -B 1000000 -D plughw:Headset my_wav_that_works.wav

The btsco seems in alpha stage. While playing a WAV may work the first time it fails on subsequent tries. Leaving this in the kernel log:

radtkens@tadpole:$ dmesg | tail
[17190778.216000] snd-bt-sco: Shift problem detected! Fixing to 1.
[17190778.216000] snd-bt-sco: Shift problem detected! Fixing to 0.
[17190779.196000] snd-bt-sco: playback_trigger 0
[17190779.196000] snd-bt-sco: setting playback to NULL
[17190779.200000] snd-bt-sco: Disposing of previous socket count 2
[17190782.504000] snd-bt-sco: playback_open
[17190782.508000] snd-bt-sco: prepare ok bps: 16000 size: 16002 count: 4000
[17190782.508000] snd-bt-sco: playback_trigger 1
[17190782.508000] snd-bt-sco: setting playback to bspcm
[17191026.524000] snd-bt-sco: Disposing of previous socket count 2
[17191026.560000] hci_scodata_packet: hci0 SCO packet for unknown connection handle 48
[17191026.560000] hci_scodata_packet: hci0 SCO packet for unknown connection handle 48
[17191026.560000] hci_scodata_packet: hci0 SCO packet for unknown connection handle 48

Unloading (rmmod sco) and reloading (modprobe sco) the sco kernel module reenables playback..

Sample output from verbose btsco:

radtkens@tadpole:$ /usr/local/btsco/bin/btsco MAC -v
btsco v0.41
Device is 2:0
Voice setting: 0x0060
RFCOMM channel 1 connected
Using interface hci0
recieved AT*ECBP=?
recieved AT+CLIP=1
recieved AT+CSCS="UTF-8"
recieved AT+CLAN?
speaker volume: 0 mic volume: 0
i/o needed: connecting sco...
connected SCO channel
Done setting sco fd
speaker volume: 0 mic volume: 0
driver is not in use
disconnected SCO channel
RFCOMM channel lost


To use our bluetooth headset with skype we start btsco right before we start skype. skype now offers one more input method in the preferences. Have fun! :-)

We may configure the daemonized btsco using ~/.btscorc.


  • btsco homepage (http://bluetooth-alsa.sourceforge.net/), alsa support for bluetooth headsets
  • btsco howto (http://www.linux.ie/articles/bluetoothheadset.php) short and good.
  • List of bluetooth devices (http://www.holtmann.org/linux/bluetooth/features.html) with features
  • Bluetooth howto collection (http://www.holtmann.org/linux/bluetooth/)
  • How to whack'n'hack bluetooth headsets (http://isospider.net/news/?a=view&id=1520), his homepage (http://www.digitalmunition.com/) and the tools (http://trifinite.org/trifinite_downloads.html)
  • Bluetooth howto (http://www.des.udc.es/~mpquique/HOWTO/en-txt/Bluetooth-Howto.txt), features some note on obex and push mechanism.
  • General bluetooth information (http://www.developertutorials.com/tutorials/wireless-technology/linux-wireless-networking-050504/page3.html) and short overview of bluez-utils (such as hci../sdpd/..).
  • Nice bluetooth tool compilation (http://tuxmobil.org/bluetooth_cell_apps.html)
  • Using IRDA (http://ale.shouldshave.org/t630_linux.html)
  • Nice page about using bluetooth (http://www.caside.lancs.ac.uk/java_bt.php) with linux including determining the notebooks OBEX DIAC.
  • Gentoo and bluetooth (http://www.gentoo.org/doc/en/bluetooth-guide.xml) presenting a bunch of gnome and kde bluetooth tools.
  • Nokia's Smartphone with Python (http://pramode.net/articles/lfy/mobile/pramode.html). There's also an interesting section called 'Parting thoughts', give it a try, that's a good thought. :)
  • Wikipedia Bluetooth (http://en.wikipedia.org/wiki/Bluetooth) page.
  • Jean Tourrilhes' bluetooth (http://www.hpl.hp.com/personal/Jean_Tourrilhes/bt/) page.
  • Running a bluetooth network (http://www.triptico.com/software/bluetooth.html)
  • Bluez (http://www.bluez.org/) homepage.

Bluetooth and GPRS

How to setup Bluetooth

This HOWTO tells you how to install and configure Bluetooth on your Linux driven ThinkPad and how to make the most common Bluetooth applications (like connecting your mobile phone etc.) work.

Enabling Bluetooth

If Bluetooth is disabled and you have Ibm-acpi running you could enable/disable bluetooth by entering:

# echo enable > /proc/acpi/ibm/bluetooth


# echo disable > /proc/acpi/ibm/bluetooth

You should also be able to toggle bluetooth with Fn+F5 keys.

Under Ubuntu Gutsy, in /etc/acpi/ibm-wireless.sh you have to comment "if ! isAnyWirelessPoweredOn; then" and the corresponding "fi" to make the Fn+F5 work.

Configuring the kernel

Since the Bluetooth card is connected to the USB subsystem, you will need to enable USB support in your kernel:

Device Drivers → USB support → Support for Host-side USB (CONFIG_USB)
Device Drivers → USB support → [*]USB device file system (CONFIG_USB_DEVICEFS)

Choose an appropriate USB host driver, one of:

Device Drivers → USB support → EHCI HCD (USB 2.0) support (CONFIG_USB_EHCI_HCD)
Device Drivers → USB support → UHCI HCD support (CONFIG_USB_UHCI)
Device Drivers → USB support → OHCI HCD support (CONFIG_USB_OHCI)

Enable Bluetooth subsystem and drivers:

Networking → <*>Bluetooth subsystem support (CONFIG_BT)
Networking → Bluetooth subsystem support → <*>L2CAP protocol support (CONFIG_BT_L2CAP)
Networking → Bluetooth subsystem support → <*>SCO links support (CONFIG_BT_SCO)
Networking → Bluetooth subsystem support → <*>RFCOMM protocol support (CONFIG_BT_RFCOMM)
Networking → Bluetooth subsystem support → [*]RFCOMM TTY support (CONFIG_BT_RFCOMM_TTY)
Networking → Bluetooth subsystem support → <*>BNEP protocol support (CONFIG_BT_BNEP)
Networking → Bluetooth subsystem support → <*>HID protocol support (CONFIG_BT_HID)
Networking → Bluetooth subsystem support → Bluetooth device drivers → HCI USB driver (CONFIG_BT_HCIUSB)
Networking → Bluetooth subsystem support → Bluetooth device drivers → [*]SCO (voice) support (CONFIG_BT_HCIUSB_SCO)

Make sure that the according modules are loaded:

# modprobe uhci_hcd ; modprobe ehci_hcd ; modprobe hci_usb

Serial connection over Bluetooth

One common application is to connect your mobile phone and use it as a modem to connect to the internet via GPRS or 3G (UMTS). A lot of phones do this through using AT-commands on a serial over Bluetooth connection.

By configuring /etc/bluetooth/rfcomm.conf correctly, you'll get a device /dev/rfcomm0.

Eventually one could use the command:

# rfcomm bind 0 00:15:A0:7A:90:F2 3

The hardware address should be replaced with that of your phone. If you don't know the hardware address of your phone yet, you can get it by running:

# hcitool scan

The last parameter ('3') is the channel to use. I spent quite some time fighting before I found out of that one; I didn't find it documented anywhere, but by running

# sdptool records 00:15:A0:7A:90:F2

I found channel 3 to be the right one for my phone. You will have to experiment to find the right one for your phone setup; for T-Mobile GSM/GPRS carrier in USA this is channel 1.

By experimenting, the bluetooth stack on the cellphone may crash. Reboot it if that happens.

Alternativly one could use the following to find the right channel:

# sdptool search DUN
Inquiring ...
Searching for DUN on 00:11:22:33:44:55 ...
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: 4

Now /dev/rfcomm0 exists.

At this point you can use an automatic dialing utility such as wvdial, editing the config file to point to the modem at /dev/rfcomm0, and everything should work just like a land line!

If you experience strange disconnects while using wvdial, disable "Carrier Check" in your wvdial configuration.

You may directly access the modem (i.e. by using minicom:)

$ minicom -s

set the serial device to be /dev/rfcomm0, choose 'exit' and then the AT-commands can be typed in. With my operator (Telenor, Norway) it seemed simple enough, I just entered

ATDT *99#

and lots of cryptic letters started dancing across the screen, indicating a ppp session startup.

To configure pppd create /etc/ppp/peers/nokia with particularly those lines:

connect '/usr/sbin/chat -v -f /etc/ppp/chat-nokia'

Furthermore, you need a simple chat script. Create /etc/ppp/chat-nokia:

'ABORT' 'Invalid Login'
'ABORT' 'Login incorrect'
'OK' 'ATDT*99#'

Here's a script that works for Cingular's network:

OK ATD*99***1#

See more here

Run pppd with:

$ pppd call nokia

This should establish the internet connection.

Different network operators may require different call strings. For many carriers (including T-Mobile USA) "*99#" works without additional parameters.

For editing phonebook / ringtones / etc., the gammu utils (http://www.gamu.net) has been reported to work well, but this appears to be primarily for Nokia phones.

File Transfer

File transfers are accomplished through OBEX transfer, which I believe is basically an FTP over bluetooth connection. Once you have bonded with your phone (yes, I know you love your sexy RAZR, but here I mean paired it with your laptop via bluetooth), you can easily use "obexftp" to transfer files. As an example,

obexftp -b 00:01:02:03:04:05 -l

will list the root directory of the phone with bluetooth address 00:01:02:03:04:05. Refer to the man page for more of the unique commands. What a wonderful interface! Unfortunately there doesn't seem to be a way to get a standard 'ftp' session using familiar commands (e.g. 'mget').

For a more user-friendly experience, you can use the kde tools, just launch


for a file browser. In the Location: option put


to list the files. Note that the brackets *are* necessary. From there, you can list directories easily and batch download files.

Mount a phone as a directory

You can also mount a phone as a standard directory using obexfs and the FUSE (file system in userspace) utilities.

The ibm bluetooth card can work like an usb-dongle. You don't need the bcm203x module.

Configure your kernel as outlined above.

  • Install the required packages

To mount the filesystem we need the fuse program. FuseFS is also implemented in the kernel, but for some reason it only works with 2.6.18. If you run 2.6.17 or earlier, please download it and build the module according to your distro.

  • Emerge or apt-get bluez-utils and obexfs. This should pull other required packages (bluez-libs, openobex, obexftp, sys-fs/fuse) as dependencies.
# emerge bluez-utils obexfs
  • Modify /etc/bluetooth/hcid.conf if you haven't already. It can be done as above, or use the following:
options {
autoinit yes"
security user
pairing multi
pin_helper /usr/bin/bluepin
device {
name testname
class 0x3e0100
iscan enable
pscan enable
lm accept
lp rswitch,hold,sniff,park
  • load the modules:
# modprobe fuse
# modprobe bluetooth
# modprobe ehci-hcd
# modprobe uhci-hcd
# modprobe hci_usb
# modprobe l2cap
# modprobe rfcomm
  • activate your bluetooth (show howto ibm-acpi for more details) by using fn+f5 or:
# echo enable >/proc/acpi/ibm/bluetooth
  • start the bluetooth device:
# /etc/init.d/bluetooth start
  • turn on bluetooth of your mobile phone (visible mode) and get the mac-address of your phone using hcitool.
# hcitool scan

For non symbian mobile phones

  • mount your phone - don't forget to umount it when you're finished
# mkdir /mnt/phone
# mount -t fuse "obexfs#-b00:16:20:32:25:3C -B6" /mnt/phone

use your mac-address instead of my 00:16:20:32:25:3C and don't forget the -b option in front of the mac

Works perfectly with IBM T43p, X41, sony ericsson k750i, nokia 6280, samsung z400, sony ericsson k700i.

Mounting Symbian Phones

  • You need network file system support in your kernel
# cd /usr/src/linux
# make menuconfig
File Systems → Network File Systems → NFS file system support (NFS_FS)
File Systems → Network File Systems → Provide NFSv3 client support (NFS_V3)
File Systems → Network File Systems → NFS server support (NFSD)
File Systems → Network File Systems → <*>Provide NFSv3 server support (NFSD_V3)
File Systems → Network File Systems → <*>Provide NFS server over TCP support (NFSD_TCP)
# make && make modules_install
  • Install required programs
# emerge -av p3nfs
  • Modify your /etc/bluetooth/rfcomm.conf
rfcomm0 {
bind yes;
device 00:0F:DE:8C:E6:94;
channel 13;
comment "symbian connection"
  • restart your bluetooth device, load kernel modules and start portmap (required for p3nfs)
# /etc/init.d/bluetooth restart
# modprobe nfs
# modprobe nfsd
# /etc/init.d/portmap start
  • get the application for your mobile phone here
  • start bt at your mobile phone, send application to mobilephone, install and launch the nfsapp with bluetooth at channel 13 (default)
# obexftp -b 00:0F:DE:8C:E6:94 -p /home/tava/ablage/nfsapp*
  • mount your mobile phone:
# p3nfsd -UIQ -tty /dev/rfcomm0 -dir /mnt/bluetooth (-UIQ is only for UIQ-Phones, type p3nfsd --help and get informations for your phone)
  • if doesn't work, make sure rfcomm0 is clean
# rfcomm

Building from source

Get the source packages from www.bluez.org.

Build each of them with the usual steps:

$ ./configure && make
# make install

Gentoo ebuilds

Under Gentoo, install the following ebuilds:

  • net-wireless/bluez-bluefw
  • net-wireless/bluez-firmware
  • net-wireless/bluez-hcidump
  • net-wireless/bluez-hciemu
  • net-wireless/bluez-libs
  • net-wireless/bluez-utils
net-wireless/bluez-kernel is not needed, since the current version is included in your kernel.

Other distributions

You will find packages for Debian, Red Hat and Slackware on the packages page of the BlueZ project.

Bluez packages are included in Debian Sid (bluez-utils, and non-free package bluez-firmware).


If you cant get hci0 up with a /etc/init.d/bluetooth restart (or similar) then you might want to try a

# hciconfig hci0 down && hciconfig hci0 up

(solved the problem on a X60s and T60 (debian/testing))

External Links

Bluetooth accesspoint with Debian GNU/Linux

With a cheap USB bluetooth dongle, you can make your computer act as a bluetooth access point. It is best to get a class 1 device, which will give at least a range of 100 meters unobscured, and will go through 1 or 2 concrete walls or ceilings. Setting it up under Debian, or any other distro is not trivial. As this took me a while, I decided to document the process.

When you use Bluetooth for network services (as opposed to wireless microphone, wiresless mouse, etc), you are using its PAN, or Personal Area Network profile. PAN is provied by the PAN daemon, pand, from the bluez-utils package. PAN uses the BNEP protocol. BNEP stands for Bluetooth Network Encapsulation Protocol.

Kernel configuration

Get a recent 2.6.x kernel, and enable the following features, either as module or built-in:

Debian packages

Install the following Debian packages:
  • bridge-utils (for brctl)
  • bluez-utils (for pand)

Configuration files

  • Edit /etc/bluetooth/hcid.conf to set class to 0x020100;
  • Edit /etc/default/bluez-utils to set PAND_ENABLED=1 and PAND_OPTIONS="--listen --role NAP"
  • Create /etc/bluetooth/pan/dev-up with this contents:
    ifconfig $1
    brctl addif br0 $1
  • Add a bridge as a network interface to /etc/network/interfaces by using something like this (I use 192.168.192.x as my local address space).
            auto br0
    iface br0 inet manual
    up echo "Adding ethernet bridge between LAN and PAN"
    up ifconfig eth0
    up brctl addbr br0
    up brctl setfd br0 0
    up brctl stp br0 off
    up brctl addif br0 eth0
    up ifconfig br0 netmask up
    down echo "Removing ethernet bridge between LAN and PAN"
    down ifconfig br0 down
    down brctl delif br0 eth0
    down brctl delbr br0


First check, whether your USB dongle has been detected by the kernel. You can check this by running 'hciconfig -a'. You should get information on the hci0 interface. Now, if a client bluetooth device will request network service, the PAN daemon, pand, will respond to this. Check your process list to see if pand is running. If not, '/etc/init.d/bluez-utils start' is required. Once the two bluetooth devices connect, a network device called 'bnep0' is created, and pand will execute the /etc/bluetooth/pan/dev-up script. In this script, we will bridge the newly created bnep0 to eth0, using the bridge called br0. To kill the connection at either side, run 'pand -K'.


A linux client for the bluetooth network, can connect to the server by using this command:
    pand --nodetach --role PANU --search
UPDATE: I've found that I need to have 'dbus' installed to get rid of the error "Inquiry failed. No such device" I recently experienced. Without dbus, /etc/init.d/bluetooth would fail.


Don't forget that your dhcpd server should now listen on the bridge br0, not on the LAN eth0. Edit /etc/init.d/dhcpd to change this.

The whole deal with the bridging is required, so that dhcpd can function regardless wether bnep0 exists or not. You cannot bring up dhcpd to listen on bnep0, if there is no bluetooth PAN connection. You can, however, have dhcpd listen on the br0 bridge, and attach it to bnep0 whenever a bluetooth client connects.

If you experience troubles, check the /var/log/daemon.log file for more information.


Bluetooth Dialup

This page describes how to configure PPP dialup through a Bluetooth-compatible mobile phone. The emphasis is on using GPRS/EDGE services. These instruction were compiled and tested on Debian 4.0 (Etch) on an IBM ThinkPad T40p with a Samsung T809 phone using T-Mobile's "Unlimited Internet VPN" plan.

Configure mobile phone data profiles

Getting the data access profile


T-Mobile accounts generally require separate data profiles for WAP and general data access. (Some people have had success running a regular data connection over the WAP profile.) Getting access to general data access requires a data access plan. Currently, the "Unlimited Internet VPN" is the best deal, as it costs the same as the "Unlimited Internet" plan but gives you a real, public IP address. Incoming connections are blocked on any T-Mobile data plan. T-Mobile does not seem to offer metered data plans anymore.

There are two ways to get the data service profile on your phone. Manual configuration is probably faster and better.


T-Mobile can send the data services profile directly to your phone via SMS. Only the "wireless data" customer service people can send the data services profile to your phone. The regular service people can only send the WAP data profile, which will not work for general use. You will have to be transferred once or twice to reach the wireless data division. Once there, simply request that the data service profile for your plan be sent to your phone. (Of course, you'll need to be signed up for a data plan.)

Once you receive the plan information, your phone will ask you where you want to store it. T-Mobile uses profile 1 for the WAP profile, so don't overwrite it. I recommend using profile 2, as it's usually the first empty profile.

After storing the data services profile, your phone will probably set it as the default. This will probably cause your WAP (T-Zones/T-Mobile Internet) to fail for your on-phone browser. Set the WAP data profile (profile 1) to default fix this. See the configuration section below for your phone's brand. Setting the default profile is usually fairly obvious once you've reach the data services configuration screen.


Access the data profiles configuration for your phone's brand using the instructions under the configuration section below. The order and name for settings is for a Samsung T809. These settings are modified from the SMS T-Mobile sends Unlimited Internet VPN plan users. By adding the DNS and proxy information, you can use this profile for either T-Zones or general web browsing.

Use the following settings for the Unlimited Internet VPN plan:

  • Name: T-Mobile VPN

  • Home URL: http://www.t-mobile.com

  • Bearer: GPRS only

  • Proxy use: Enable

  • GPRS settings

    • Proxy:

    • Proxy Port: 8080

    • DNS1:

    • DNS2:

    • APN: internet3.voicestream.com

    • Login ID: Empty

    • Password: Empty

Other companies

Call your mobile service provider and request information about data plans. Many charge by the megabyte, but unlimited plans are increasingly available. Most of the instruction for T-Mobile will probably apply.


Sony Ericsson GSM

This is from my memory of using a T610, but it should apply to any Sony Ericsson phone. Choose the lower-left icon from the main menu.

Samsung GSM

This is tested on a T809, but should apply to any Samsung GSM phone. Enter code *#87927# from the main screen. Select "Current profile" to choose the default profile. Select "Profile settings" to manage profiles.


This is tested on a CU 320 and works. If you have problems authenticating from the machine, discover it from the phone.

Nokia GSM

This is tested on a 5300 XpressMusic with Vodafone Live The Netherlands. I didn't change any settings on the phone.

Installing Bluetooth and dialup packages

  • If you have the ubuntu-desktop package installed, you can skip to the next section

  • Otherwise, run the following at a shell prompt; this should install the basic Bluetooth and PPP packages

sudo apt-get install bluez-utils bluez-pin ppp

Listing Bluetooth devices

  • Make your phone Bluetooth discoverable.

  • Run the following at a shell prompt:

hcitool scan
  • Copy the MAC address (the text with the capital letters, numbers, and ':'s) somewhere convenient. You'll need it many times.


You can skip this section if you've already paired your phone with your computer. However, consider the final optional step, as your phone might otherwise nag you every time you use if for dialup.

  • Run the following, replacing your-phone-mac-address with the proper data

sudo hcitool cc your-phone-mac-address
  • Run the following, replacing your-phone-mac-address with the proper data

sudo hcitool auth your-phone-mac-address
  • If this command doesn't work, try the pairing instructions on other Bluetooth wiki pages; it seems 5.10 and older have issues with the PIN wrapper

  • Enter a numeric code into the dialog box that pops up. If no dialog box pops up, run the following in another window

sudo passkey-agent --default /usr/bin/bluez-pin
  • Accept the pairing from your phone handset.

  • Enter the same number on your phone

  • Run the hcitool auth your-phone-mac-address command again if it fails

  • You can remove your handset's Bluetooth discoverability now

  • Some phones (notably Samsungs) require further authorization for certain Bluetooth activities, including dialup; consult your phone's user manual to avoid confirming your computer's dialup action on your phone every time

Note: I couldn't pair using the above instructions in Edgy. I had to install bluez-passkey-gnome, launch bt-applet (it's invisible when waiting), then initiate pairing from the phone.

Note: I couldn't pair using the above instructions in Feisty. The pairing instead took place when I dialed the connection for the first time. I could not pair from the phone since my computer was hidden.

Configuring the rfcomm device

  • Get the channel number for your phone's dialup service by running the following, replacing your-phone-mac-address with the proper data

sdptool browse your-phone-mac-address
  • Look under "Service Name: Dial-up Networking"

  • Under "Protocol Descriptor List:" and "RFCOMM", there should be a number after "Channel:"

  • Remember that number; you'll need it for the rfcomm configuration

  • Run

gksudo gedit /etc/bluetooth/rfcomm.conf
  • Paste the following into the file, replacing your-phone-mac-address and your-phone-rfcomm-channel with appropriate values

rfcomm0 {
bind yes;
device your-phone-mac-address;
channel your-phone-rfcomm-channel;
comment "Bluetooth PPP Connection";
  • Save and close the rfcomm.conf file

  • Run the following, which will create the rfcomm0 device

sudo /etc/init.d/bluez-utils restart

Note that on Edgy and Feisty the correct command is:

sudo /etc/init.d/bluetooth restart

Note: On the Nokia N95 (and possibly other Symbian S60 phones) the RFCOMM channel number is not consistent, but seems to change from time to time. If you have a phone that behaves like this, and you find youself unable to connect, you will need to re-run sdptool as described above to see if the channel number has changed. Rather than edit rfcomm.conf (and hence have RFCOMM bind to the channel at startup) you may find it more convenient to bind the RFCOMM channel on the command line:

rfcomm bind 0 your-phone-mac-address your-phone-rfcomm-channel

If you get the wrong channel (or if the wrong channel was bound at startup as a result of rfcomm.conf) then you need to release it before you can bind it again:

rfcomm release 0

Configuring PPP

  • Run the following

gksudo gedit /etc/ppp/peers/BluetoothDialup
  • Paste the following into the file (the file should start out blank)(I found that on my Motorola V360 that I had to comment out #lcp-echo-failure 0 useing T-Mobile.)

connect "/usr/sbin/chat -v -f /etc/chatscripts/BluetoothDialup"
/dev/rfcomm0 115200
lcp-echo-failure 0
  • Save and close the BluetoothDialup file

  • Run the following

gksudo gedit /etc/chatscripts/BluetoothDialup
  • Paste the following into the file (the file should start out blank), replacing your-apn-here with the APN from your data services profile and your-data-profile-number-here with the number you stored the profile into on the phone (probably 2).

'' \rAT
OK 'AT+CGDCONT=2,"IP","your-apn-here"'
OK ATD*99***your-data-profile-number-here#

Carrier specific configuration info

Phone specific configuration details

Samsung SGH-X820

This phone seems to have problems with various PPP options. Adding the following options to the relevant file in /etc/ppp/peers seemed to make it work.


Authorizing dialout

  • Run the following at a shell prompt, replacing your-username-here with your username:

sudo adduser your-username-here dialout
  • This concludes the one-time setup


Begin here on subsequent connections.

  • If you have NetworkManager installed, right-click the applet and uncheck "Enable Wireless"; this will keep it from hopping onto wireless networks and botching your dialup DNS and default route settings

N.b. I do have NetworkManager installed and have found a work-around so that it doesn't mess with my connection over Bluetooth. I have not tried this in an environment where there are multiple WiFi connections _and_ yet I'm still trying to use the phone as a modem. The work-around is to edit the file /etc/network/interfaces and to add a line at the end of the file that reads:

iface hci0 inet static
  • Run the following

pon BluetoothDialup
  • Wait about 30-60 seconds

  • You should now be able to ping ubuntu.com; expect latencies of around one second for most GPRS services

  • If pinging fails, see the troubleshooting section below

  • See the disconnect section below when you're finished using the connection

PPP and TCP/IP troubleshooting

Try these troubleshooting sections in order.

Using the correct data plan

  • Check that you're indeed using a real data profile, as WAP-only profiles generally disallow pinging, instant messaging, file sharing, and some web browsing

  • Try setting the unrestricted data profile as your default data profile on your phone

    • This will only work if the profile has proper DNS settings

      • If you use the T-Mobile automatic profile setup listed above, it will not have proper on-phone DNS settings

      • The manual method will work for T-Zones

    • Use the built-in WAP browser to test the profile

      • If it works, it's probably not your data plan (though it could be); continue troubleshooting below

PPP connection

  • Monitor /var/log/syslog for dialup status information

    • The following indicates PPP success, where xxxs can be anything

xxx localhost pppd[xxx]: Script /etc/ppp/ip-up finished (pid xxx), status = 0x0

Solution if problem

  • Make sure there's not a PPP connection with rfcomm0 already in session; run poff BluetoothDialup to disconnect one in session

  • Find where the error is in either the chatscripts or peers file

    • Consult other help sources and update this page

IP address configuration

  • Run ifconfig to check your PPP connection

    • The ppp0 section should be as below, where xxx is anything

ppp0 Link encap:Point-to-Point Protocol
inet addr:xxx.xxx.xxx.xxx P-t-P:xxx.xxx.xxx.xxx Mask:
RX packets:xxx errors:0 dropped:0 overruns:0 frame:0
TX packets:xxx errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:xxx
RX bytes:xxx (xxx b) TX bytes:xxx (xxx b)
  • P-t-P:xxx.xxx.xxx.xxx should match the address on the /var/log/syslog line xxx localhost pppd[xxx]: remote IP address xxx.xxx.xxx.xxx

  • inet addr:xxx.xxx.xxx.xxx should match the address on the /var/log/syslog line xxx localhost pppd[xxx]: local IP address xxx.xxx.xxx.xxx

  • If the addresses match, then your IP address configuration is probably fine

Solution if problem

  • If a /var/log/syslog line seems absent, try reconnecting via poff BluetoothDialup and pon BluetoothDialup

  • Make sure you're using the right data profile on your phone

Default route configuration

  • Ping a valid public hostname on a connected computer, then (if it worked) try pinging the actual IP address from your PPP-connected computer

    • If it didn't work, try pinging a different hostname; some block pings

    • If this works, then your routing table is probably fine

  • Check the routing table by running route -n

    • Your routing table should look like the following, where xxx is anything

Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
xxx.xxx.xxx.xxx * UH 0 0 0 ppp0
default * U 0 0 0 ppp0
  • The xxx.xxx.xxx.xxx should match the P-t-P:xxx.xxx.xxx.xxx in the ifconfig command's ppp0 block above

  • If the routing table checks out, routing is probably not the problem

Solutions if problem

Preferred method: Manually fix routing table

This needs instructions, as it should be the preferred method

Alternate method: Remove other interfaces
  • Run the following

poff BluetoothDialup
  • Remove any non-loopback and ppp0 connections by running the following, replacing your-extra-interface with the appropriate names

sudo ifconfig your-extra-interface down
  • Run the following

pon BluetoothDialup

DNS configuration

  • Try pinging the DNS servers

  • Try running dig hostname-here, where hostname-here is a valid hostname

    • If it resolves, DNS is probably not the problem

  • Check /etc/resolv.conf to check your DNS configuration

    • Your routing table should look like the following, where xxx is anything

nameserver xxx.xxx.xxx.xxx
nameserver xxx.xxx.xxx.xxx
  • The lines above should match the /var/log/syslog lines like the following

xxx localhost pppd[xxx]: primary DNS address xxx.xxx.xxx.xxx
xxx localhost pppd[xxx]: secondary DNS address xxx.xxx.xxx.xxx

Solution if problem

  • If a /var/log/syslog line seems absent, try reconnecting via poff BluetoothDialup and pon BluetoothDialup

  • Manually configure /etc/resolv.conf to point to your provider's DNS servers (or a public DNS server)

    • Try pinging the manually-configured DNS servers; if it fails only on the Bluetooth dialup machine, double-check the routing configuration


  • Run the following

poff BluetoothDialup

Other useful guides

GPRS Internet over Bluetooth on Debian

My Configuration

  • Debian 4.0 ( Etch )
  • Integrated Bluetooth on my laptops
  • Sony Ericsson P910i Cellphone
  • Vodacom GPRS/EDGE/3G connection

This should be portable across all Debian-based distibutions, and telecoms. But the configuration might vary from phone to phone (notably the channel number).

See GPRS for more general information.

Any "#" prompt means root, i.e. run sudo -s before you do this.

Install the relevent packages

# aptitude install bluez-gnome pppconfig


Your user needs to be able to dial-out (if you are the first user on an ubuntu system, this is already done):

# adduser my-username-here dialout

Log out and in again.

Connect to your phone

Turn on bluetooth on your phone and computer.

If you've already tried connecting them before, delete any reference to your computer from your phone's list of Bluetooth devices. And delete any reference to your phone's ID from the files in /var/lib/bluetooth/computer-id-here/.

If the gnome bluetooth applet doesn't appear, run:

$ bluetooth-applet

It should make your computer discoverable by default.

Do a bluetooth scan on the phone, and add your computer as a paired device.

Enter the same number in both phone and computer. They should bond.

Now you can edit the properties of the computer on the phone's list of Bluetooth devices and tell it to always accept connections from the computer.

Debugging connections

If you need to find your phone's bluetooth ID, make the phone discoverable, and run

$ sdptool scan

If things go wrong here, go into /var/lib/bluetooth/*PC-Address*/ and look for your phone's address in those files. If it's there, remove it, and

# invoke-rc.d bluetooth restart

and try again.

If your phone isn't a P900

You'll need to find out what channel to connect to:

# sdptool browse 00:0A:D9:EA:A4:F8        <- Insert your phone's ID here
Browsing 00:0A:D9:EA:A4:F8 ...
Service Name: Voice gateway
Service Description: Voice gateway
Service Provider: Sony Ericsson
Service RecHandle: 0x10000
Service Class ID List:
"Headset Audio Gateway" (0x1112)
"Generic Audio" (0x1203)
Protocol Descriptor List:
"L2CAP" (0x0100)
"RFCOMM" (0x0003)
Channel: 8
Language Base Attr List:
code_ISO639: 0x656e
encoding: 0x6a
base_offset: 0x100
Profile Descriptor List:
"Headset" (0x1108)
Version: 0x0100

Service Name: OBEX Object Push
Service RecHandle: 0x10001
Service Class ID List:
"OBEX Object Push" (0x1105)
Protocol Descriptor List:
"L2CAP" (0x0100)
"RFCOMM" (0x0003)
Channel: 1
"OBEX" (0x0008)
Profile Descriptor List:
"OBEX Object Push" (0x1105)
Version: 0x0100

Service Name: OBEX File Transfer
Service RecHandle: 0x10002
Service Class ID List:
"OBEX File Transfer" (0x1106)
Protocol Descriptor List:
"L2CAP" (0x0100)
"RFCOMM" (0x0003)
Channel: 2
"OBEX" (0x0008)

Service Name: Bluetooth Serial Port
Service Description: Bluetooth Serial Port
Service Provider: Symbian Ltd.
Service RecHandle: 0x10003
Service Class ID List:
"Serial Port" (0x1101)
Protocol Descriptor List:
"L2CAP" (0x0100)
"RFCOMM" (0x0003)
Channel: 3
Language Base Attr List:
code_ISO639: 0x656e
encoding: 0x6a
base_offset: 0x100

Service Name: Dial-up Networking
Service Description: Dial-up Networking
Service Provider: Sony Ericsson
Service RecHandle: 0x10004
Service Class ID List:
"Dialup Networking" (0x1103)
Protocol Descriptor List:
"L2CAP" (0x0100)
"RFCOMM" (0x0003)
Channel: 4
Language Base Attr List:
code_ISO639: 0x656e
encoding: 0x6a
base_offset: 0x100
Profile Descriptor List:
"Dialup Networking" (0x1103)
Version: 0x0100

The number you want is the Channel number for Dial-up Networking.

Configure bluez

# vi /etc/bluetooth/rfcomm.conf

Add this stanza at the end:

rfcomm0 {
bind yes;
device 00:0A:D9:EA:A4:F8; <- Insert your phone's ID here
channel 4;
comment "P900 PPP connection";
# /etc/init.d/bluez-utils restart

Configure PPP

# cat > /etc/ppp/peers/bluetooth << EOF
connect "/usr/sbin/chat -v -f /etc/chatscripts/bluetooth"
user "x"
remotename bluetooth
ipparam bluetooth

lcp-echo-interval 0
# cat > /etc/chatscripts/bluetooth << EOF
OK-AT-OK "ATDT*99***1#"

You might need to change the *99***1#. See GPRS#Cell Phone for details.

# echo '"x" bluetooth "x"' >> /etc/ppp/pap-secrets

Test and debug

$ pon bluetooth
# tail -f /var/log/syslog

You should see the connection progress.


BTW: You can make your phone undiscoverable again :-)


  1. The above instructions can easily be adapted for USB cable use. The earlier bluetooth specific steps can be skipped, start at the ppp configuration step. The device specified must be the USB appropriate modem device, eg. /dev/ttyACM0. If you are unsure of what device to use, monitor the log files (eg. /var/log/syslog) to see what device is detected when the phone is plugged via USB.
    • The main disadvantage to using bluetooth is it increases the battery consumption of the phone. The advantage to using bluetooth is that you can put the phone in a further away location where it gets a better cellphone signal.
  1. The dial number specified is critical, if by mistake, you use your MMS connection, it will appear to connect fine, but nothing will work :-)
  1. If for some silly reason, you already have a default route, ppp will not replace it with a new one. You'll have to sort this out yourself.