Sunday, September 17, 2006

Symbian, Python and ubuntu

My fyp deadline is coming and I didn't work on my fyp for a long time now. Realizing that this is a do or die situation here, I finally started setting up my nokia phone for hacking.
So, I borrowed Nokia 6620, which has 2nd edition of s60 (way better for hacking than 3rd). My first aim was to connect btconsole to my laptop, so that I can execute and test my code on the fly. This console creates an interactive shell for you on the pc, and the actual commands are run live on the mobile. Very handy for quick testing.

My attempts at getting Windows XP to work with btconsole went all in vain and caused much frustation. "socket not found", to "Connection Refused" errors, I got them all repeatedly. After all this trying, I thot of giving linux a shot (which I love to do anyway). My laptop doesn't have a bluetooth, so bought one for 45USD, quite expensive by very powerful; and that was the only one available at RadioShack anyway. After quite some attempts and struggling through random how to's online, I finally found my way to connect to my mobile through ubuntu (Dapper). Makes sense to document the precious pearls, for myself in future, and for others who won't like to be frustated as well. So, here goes:

1. Install bluez-utils, cu, gnome-bluetooth packages.

2. Restart ur bluetooth service.
$ sudo /etc/init.d/bluez-utils restart

Scan for other devices
$ hcitools scan
This will be able to locate ur mobile, and provide you the address which you need from now on.
Also, pair up your device w/ the pc, by going to Tools->Connection->Bluetooth. In options, add a new paired device. It will search and then be able to find ur laptop.

3. Check if your mobile supports OBEX based message transfer.
$ sdptools browser

... verbose output ...
Search for "OBEX File Transfer", and note down the channel (say 3), and rfcomm port (say 3).
In /etc/bluetooth/rfcomm.conf, add a section
rfcomm 3
{
bind yes;
device 00:02:EE:6D:0E:58; #replace with your address
channel 3;
comment "OBEX File Transfer"
}

Also, another section
rfcomm0 {
bind no;
device 00:02:EE:6D:0E:58; #replace with your address
channel 1;
comment "Hacking on Nokia 6620";
}

4. Restart bluetooth service:
$ /etc/init.d/bluez-utils restart

Bind to your mobile
$ sudo rfcomm bind /dev/rfcomm0
$ sudo minicom -m -s
This will open up a configuration editor. The only thing to do is to set the name of the device to connect to as /dev/rfcomm0. Save the new configuration as the default configuration and invoke:
$ sudo minicom -m

{Shamelessly copied from [1] }
Minicom is now ready to talk to your phone! Type in `AT' and the program will respond with an `OK'. Say you wish to make your phone dial a number. Just type:
atdt 1234567;
There are many other AT commands you can experiment with; try googling for say `mobile phone AT commands' or something of that sort! After you have finished with your virtual serial port manipulations, you should run:
rfcomm release /dev/rfcomm0

to `release' the serial-bluetooth link.
{ Copying finished }

5. Now, time to connect to btconsole:

$ sdptool add --channel=1 SP // add service. Note that this channel is the rfcomm0 channel.
$ sdptool browser local // view the current services if you want to confirm it
$ sudo rfcomm listen /dev/rfcomm0 1 // listen on channel 1, bind to /dev/rfcomm0
This command would block the terminal. In other terminal, run
$ sudo minicom -m

You shd be able to connect to your mobile device now.

>>> 2+2
4

Yeah! Python works. :)
This information is a mix match of various howto's + forums. Adding references to the ones that are still open in my window.

References:
[1] http://pramode.net/articles/lfy/mobile/pramode.html
[2] http://discussions.forum.nokia.com/forum/printthread.php?t=63435