[
Back to Kevin's Homepage
]
Using a Cingular Treo 650 as a modem via Bluetooth
I have a Cingular Treo 650 that predates the AT&T company rename.
I'm on an unlimited data PDA plan. While Bluetooth DUN on the Treo
does work, it's not pretty since the phone will reboot quite a bit and
chew through its battery, but frequently some connectivity is better
than none!
These instructions were developed on a kubuntu 6.06 LTS machine,
up-to-date as of 2007.09.14. Some of the file locations have definitely
changed as you move forward from Dapper to Edgy and Feisty
First step is to make sure your Bluetooth dongle works.
My Bluetooth dongle happens to be a cheapie from Fry's Electronics,
but it is supported. see Cheap Bluetooth
Dongle for more detail
- Install the Bluetooth software on your system:
sudo apt-cache update
sudo apt-get install bluez-util
- Monitor /var/log/messages for activity
sudo tail -f /var/log/messages &
- Insert Bluetooth dongle
- see that /var/log/messages reports something like this:
Sep 13 19:11:50 pocketeer kernel: [17180759.384000] usb 3-1: new full speed USB device using uhci_hcd and address 2
Sep 13 19:12:01 pocketeer kernel: [17180769.804000] Bluetooth: HCI USB driver ver 2.9
Sep 13 19:12:01 pocketeer kernel: [17180769.808000] usbcore: registered new driver hci_usb
- Verify also that
lsusb
shows your dongle
$ lsusb | grep -i blue
Bus 003 Device 004: ID 1131:1001 Integrated System Solution Corp. KY-BT100 Bluetooth Adapter
- Verify that the Bluetooth stack can talk to it; hcitool dev should output at least one device with a valid MAC address. All 00's is an indication that something is wrong.
$ hcitool dev
Devices:
hci0 00:11:67:55:C3:8D
Second step is to pair your machine with your phone.
- Make the phone discoverable from the Bluetooth menu
- Put the phone in DUN mode from the Bluetooth menu
- Plug it into a charger, because a full battery will be dead
in 30 minutes with DUN and actively downloading lots of data
- Find the MAC address of your phone with:
hcitool scan
$ hcitool scan
Scanning ...
00:07:E0:12:23:34 Kevin Wang
- Store phone Bluetooth MAC in sh variable for ease of use
- Initiate a connection between your Linux machine and your phone.
This should cause kbluetoothd to pop up a small blue almost-Bluetooth
icon in your desktop toolbar, indicating that it's connected. You can
right-click on it to show connection info, but it's not terribly
interesting otherwise. Left-click launches the file transfer tool,
but I don't know what that could be used for.
- Setting up a connection will pop up a "Enter passkey for $HOSTNAME-0"
on the Treo. Type in a 4 digit PIN, check the "Add to trusted device
list." box, and press "OK" button. In a few seconds, kbluetoothd will
ask for the same PIN. Type it in and press "OK" on your Linux machine.
- To verify that the pairing process was successful, disconnect and
reconnect, confirming that the connection goes away and comes back with
no PIN prompts:
$ hcitool con
Connections:
< ACL 00:07:E0:12:23:34 handle 1 state 1 lm MASTER ENCRYPT
$ sudo hcitool dc $MAC
$ hcitool con
Connections:
$ sudo hcitool cc $MAC
$ hcitool con
Connections:
< ACL 00:07:E0:12:23:34 handle 1 state 1 lm MASTER ENCRYPT
You should get no PIN prompt
- You can now set your Treo to Discoverable=No if you want extra
handset security.
Third step is to setup the rfcomm serial port emulation and ppp
- Append the following file content to /etc/bluetooth/rfcomm.conf
cat >>/etc/bluetooth/rfcomm.conf <<_EOF_
rfcomm0 {
bind yes;
# Bluetooth address of the device
device $MAC;
# RFCOMM channel for the connection
channel 1;
# Description of the connection
comment "$USER Treo modem";
_EOF_
Where if you still have the shell variable set, it should fill in $MAC
and $USER for you. Otherwise you'll have to substitute those in yourself.
- Setup ppp parameters
cat >/etc/ppp/peers/BluetoothDialup <<'_EOF_'
# tty name
/dev/rfcomm0
# speed
115200
# options
hide-password
debug
noauth
connect "/usr/sbin/chat -v -f /etc/chatscripts/BluetoothDialup"
usepeerdns
defaultroute
crtscts
lcp-echo-failure 0
novj
user "ISP@CINGULARGPRS.COM"
remotename BluetoothDialup
ipparam BluetoothDialup
_EOF_
The tricky part is knowing whether to put down here and below is
"ISP" or "WAP". Apparently if you have the "Media Net" package
only, you need to put in WAP. With the unlimited data package,
I can use "ISP"
- Setup ppp chat script
cat >/etc/chatscripts/BluetoothDialup <<'_EOF_'
TIMEOUT 35
ECHO ON
ABORT '\nBUSY\r'
ABORT '\nERROR\r'
ABORT '\nNO ANSWER\r'
ABORT '\nNO CARRIER\r'
ABORT '\nNO DIALTONE\r'
ABORT '\nRINGING\r\n\r\nRINGING\r'
'' \rAT
## The below two lines are alternative suggestions from other pages.
###########OK 'AT+CGDCONT=2,"IP","ISP.CINGULAR"'
###########OK 'AT&FE0V1&C1S0=0'
OK 'AT&f&d2&c1+cgdcont=1,"IP","isp.cingular"'
OK ATD*99***1#
CONNECT ""
_EOF_
- Setup ppp password
cat >>/etc/ppp/pap-secrets <<_EOF_
"ISP@CINGULARGPRS.COM" BluetoothDialup "CINGULAR1"
_EOF_
Again, be sure to set either "ISP" or "WAP" as appropriate.
- Test your ppp connection: sudo pon BluetoothDialup ;
Watch the output of /var/log/messages (that's still running,
right?) If all you see is "pppd started by root..." immediately
followed by "Exit", the rfcomm channel isn't initializing
correctly. You may have to reboot your phone in order to get
it to work correctly. If successful, you should see lots of
output from chat, looking much like the file you created above.
It should reach "CONNECT", and then from there it'll be setting
up the ppp connection.
- Verify that the ppp connection works: Continuing to watch
the output of /var/log/messages, it should finish with saying
"local, remote IP, and primary, secondary DNS addresses".
This indicates that your connection is successfully set up.
If you do not see a "PAP authentication succeeded" string,
check your /etc/ppp/pap-secrets file for typos.
- Verify that your IP connection is complete: ping www.google.com
- Success! Your connection is done! Note that 'poff
BluetoothDialup' will turn the DUN connection off. AFAIK,
pon is the same as "pppd call BluetoothDialup"
Extra credit: The below steps make your connection faster, but it
is a whole lot more work. Scripting experience recommended.
DNS caching on the near side of a slow link makes everything
faster. Installing nscd is a viable alternative to what I
present here, and is probably easier, but I've had bad experiences
with it. These scripts I've developed over the years, so they're
still good for backporting with old rh8 systems! Yes, I still
support some of those legacy installations.
Start by installing daemontools, the support software for
djbdns' dnscache application
cd /
sudo bash
mkdir /package
cd /package
# You may need this: yes | apt-get install build-essential gcc make flex bison gdb
# install daemontools
wget http://cr.yp.to/daemontools/daemontools-0.76.tar.gz
gunzip /' <$F.orig >$F
done
cd admin/daemontools*
sudo package/install
# init starts the svscan process
Install djbdns so we can use dnscache
cd /package
wget http://cr.yp.to/djbdns/djbdns-1.05.tar.gz
gunzip /' <$F.orig >$F
done
# install djbdns
cd /package/djbdns-1.05
make
make setup check
Turn on dnscache
useradd dnscache
useradd dnslog
IP=127.0.0.1
SUBNET=`echo $IP|cut -f1-3 -d.`
dnscache-conf dnscache dnslog /etc/dnscache-$SUBNET $IP
ln -s /etc/dnscache-$SUBNET /service
echo "nameserver 127.0.0.1" >> /etc/resolv.conf
Configure dnscache so that it asks the DNS servers provided
by Cingular.
echo 66.102.163.231 > /service/dnscache-127.0.0/root/servers/@
echo 66.209.10.201 >> /service/dnscache-127.0.0/root/servers/@
echo 1 > /service/dnscache-127.0.0/env/FORWARDONLY
Restart and test dnscache
svc -t /service/dnscache-127.0.0
nslookup www.google.com 127.0.0.1
nslookup www.google.com 127.0.0.1
The first nslookup should take a few seconds, but the second
one should be instant. If you can save 3 seconds for loading
every web page, that's pretty signifigant.
Deconfigure your test dnscache
svc -dx /service/dnscache-127.0.0
sleep 1
svc -dx /service/dnscache-127.0.0/log
sleep 1
rm -rf /service/dnscache-127.0.0 /etc/dnscache-127.0.0
So that was the easy part, getting dnscache installed
and tested. However, your system isn't configured to use the
local dnscache. that configuration file, /etc/resolv.conf
is rewritten by pppd every time a connection is established.
Therefore, we need to hook into the pppd startup scripts and
rewrite the file ourselves.
Download if-local and network_config to /usr/local/etc.
Yes, I know that newer version of ppp use /etc/ppp/ip-up.d/
but none of those scripts do quite what I want them to. Note also
that if you want any of the functionality of those scripts, you'll
have to add that in somewhere, because installing ip-up.local
overrides and prevents any of the ip-up.d/ dir scripts from
running.
sudo bash
mkdir /usr/local/etc
chmod +x /usr/local/etc/if-local
chmod +x /usr/local/etc/network_config
/usr/local/etc/if-local install
poff BluetoothDialup
sleep 10
pon BluetoothDialup
If the scripts are successful, you should see /etc/resolv.conf
pointing to 127.0.0.3, and ps should show dnscache running.
If not, check /tmp/LOG.ip-up.local, /tmp/LOG.network_config, and
/tmp/LOG.ip-down.local for errors. Debugging is unfortunately
going to take some reading of the code, as it doesn't handle
errors very well. Adding the command "set -x" just after the
"exec >>/tmp/LOG" and rerunning the poff/sleep/pon will log
all the executed commands, so you can figure out what line is
causing problems.
Extra credit #2: squid http proxy
TBD
Extra credit #3: Detect a down or hung connection and auto-restart
TBD
KJW - kjw@rightsock.com