docs/mindstab.net_blog/2007-07-26-getting-my-ubunt...

8.0 KiB

Getting my Ubuntu laptop and Sony Ericsson k510a cell phone to talk to each other with Bluetooth: file sharing and internet over GPRS and ppp

Jul 26, 2007

Well, I taught my laptop a new trick.

I went out and bought a DLink DBT-122 Bluetooth adapter (USB). Cheapest one they had, plugged it into my laptop (Ubuntu Feisty) and it was recognized right away. Installed bluez and bluetooth related packages and started to play.

First thing I did was enable the bluetooth applet that runs in the notification area. It can also be accessed from 'System->Preferences->Bluetooth Preferences'. Once that was on and my cell phone's (Sony Ericsson k510a) bluetooth was on I was able to use nautilus' sendto to send files via bluetooth to my cell phone. Then after turning on 'Applications->Accessories->Bluetooth File Sharing', which starts an applet in the notification area, I was able to send files to my laptop from my cell phone via bluetooth. So that was all cool, but it was also just warm up.

Next I wanted to get internet on my laptop through my cell phone. While impractical in the areas on cost and speed, it does have far greater coverage than random unsecured wifi access points around the city (especially as of late as people are finally starting to use WEP and WPA) and it's coverage out of city is of course no contest either.

So I installed a few more tools, ppp (Point to Point Protocol) related, like ppp and pppconfig.

The first tool I used was 'hcitool' which is used for establishing bluetooth connections and other bluetooth related issues.

# hcitool scan
Scanning ...
         00:17:B9:DA:E4:F2       phone.mindstab.net

This will scan for all bluetooth devices in range and return their name and MAC address. Next I had to connect to the phone and laptop or 'pair' the devices. For my phone, the Sony Ericsson k510a, I had to do this on the phone's side. I went to Settings->Connectivity->Bluetooth->My Devices. Then I selected New Device and after it scanned, I selected my laptop. It then bid me enter a 'password' so I choose a few numbers, and then the bluetooth manager on my laptop notified me a device was trying to 'pair' and asked me to enter the number there. That done my cell phone accepted my laptop. I selected my laptop/device on my cell phone and told it to always accept connections from that device. Also, to be safe, I put the password/number in /etc/bluetooth/pin although I'm not really certain if that was necessary.

Now the devices were set to connect to each other on a regular basis so back to hcitool to handle that. The cc argument establishes or breaks a connection and the auth argument authenticates the connection.

# hcitool cc 00:17:B9:DA:E4:F2
# hcitool auth 00:17:B9:DA:E4:F2

Now a bluetooth connection with the phone was established. Next up it was time to configure the ppp connection that would run from my laptop, over bluetooth to the cell, and from there over GPRS (or possibly EDGE?) to the internet.

First, I needed to further setup Bluez (Bluetooth handler on Linux) to facilitate this by creating a /dev/ entry for the connection. And I needed a bit more info. The command sdptool delivered this to me. It can be used to list all the supported features of a device and their details. I was specifically interested in the 'Dial-up Networking' section.

# sdptool browse 00:17:B9:DA:E4:F2
...
Service Name: Dial-up Networking
Service RecHandle: 0x10002
Service Class ID List:
  "Dialup Networking" (0x1103)
  "Generic Networking" (0x1201)
Protocol Descriptor List:
  "L2CAP" (0x0100)
  "RFCOMM" (0x0003)
    Channel: 2
Profile Descriptor List:
  "Dialup Networking" (0x1103)
    Version: 0x0100
...

In there I found the 'Channel' that the protocol was operating on, in this case '2'. Now I opened up /etc/bluetooth/rfcomm.conf and setup the device.

/etc/bluetooth/rfcomm.conf

rfcomm0 {
        bind yes;
        device 00:17:B9:DA:E4:F2;
        channel 2;
        comment "Bluetooth PPP Connection";
}

Then I restart bluetooth. On newer Ubuntu versions the service is just called 'bluetooth' but on older versions it's apparently called 'bluez'.

# invoke-rd.d bluetooth restart

Now I had setup a connection to my cell phone and created /dev/rfcomm0 for it. I was now ready to setup a ppp connection over bluetooth.

pppconfig thankfully does most of the hard work here. It configures the ppp/peer files and the even more convoluted chatscript (some kind of text file that contains the initial connection protocol text that is used to establish the connection).

# pppconfig

pppconfig gives you a menu. I chose 'Create Connection'. Called it whatever, I chose 'gprs'. Next I selected 'Dynamic' (for DNS). Then I selected 'Chat' for the Authentication Method. I entered no password or login, and then deleted the text when it asked for a User name and another password. The default speed of '115200' baud was fine. 'Tone' is the choice for the 'Pulse or Tone' section. The number to dial was a bit tricky. It's in the form of something like *99***slot-of-internet-on-cell# so for me *99***2# was what I entered but others might try *99***1# or possibly *99#. I entered the port to use manually and entered '/dev/rfcomm0'. Then it gave me a chance to review and then write the file. I did so.

The two main files it creates are '/etc/ppp/peers/gprs' and '/etc/chatscripts/gprs'. If you are lucky you should just be able to connect now, but I had problems, so I had to tweak the files a bit. In '/etc/ppp/peers/gprs' I had to comment out the remotename and ipparam lines with hashs (#).

/etc/ppp/peers/gprs

...
user ""
#remotename gprs2
#ipparam gprs2

and in '/etc/chatscripts/gprs' I had to comment out the 'ogin:' and 'ssword:' lines again with hashes.

/etc/chatscripts/gprs

...
# ispname
#ogin: ""
# isppassword
#ssword: ""
# postlogin

Now all the ppp config files were properly configured to work with my phone, so it was time to try the connection out. Before that though, I turned other networking off, which is easy enough with NetworkManager, I just right clicked on it and unchecked 'Networking'. Then to turn on the connection over bluetooth, ppp, and gprs, I just used the 'pon' command.

# pon gprs

and gave it a few seconds. My cell lit up and told me it was connecting and then it connected. Then I was good to go. Sadly gprs internet rates are expensive here at $0.05 / kB. Also, it's a bit firewalled so the standard ping google.com test to see if the connection is working fails. I just loaded a small web page in my browser. It worked! Then tried to 'ssh' to my server, and that also worked! When I was done, I just

# poff gprs

to turn the connection off.

And that's it. Now I can get files to and from my cell phone and get internet from it for my laptop as well.

When I was having trouble, I looked in '/var/log/syslog' to see where the trouble was coming from.

Also, for some reason, the next day, 'sdptool' was reporting that the 'Dailup Networking' service had moved to channel 2 so I had to change '/etc/bluetooth/rfcomm.conf' file to represent that and restart bluetooth with invoke-rc.d bluetooth restart, so keep an eye out for that if your connection starts failing later for no reason.

References