In this section i'll discuss the different possible Dialers for different scenario's.
The basic idea in GPRS dialing is this:
The AT-Commands we found in the previous chapter will be used as initstrings, when that's done we tell the dialer to dial the special GPRS number. When that's done, and the phone responds with CONNECT the dialers usually start pppd to handle the ppp data. When the ppp negotiation is done, you're ready to use your connectivity.
With this description you will be able to dial in to your GPRS connection with the simple command pppd call gprs. The downside of this is that it is very inflexible. Everything is hardcoded, so if you have to change anything you have to change the configuration files. This is okay if you (for example) always use the same APN to connect to (like typical end-users do :-) ).
This setup requires two files: A pppd configuration file and a chat script. The configuration file is listed below and should be saved as /etc/ppp/peers/gprs:
/dev/tts/USB0
115200
connect 'chat -f /etc/ppp/chat/gprs'
defaultroute
usepeerdns
Note that the first line is my device name, the second is it's serial speed.
The third line is to tell pppd which chat script to use (we'll get there soon).
The last two lines are to tell pppd to use the default gateway and dns
information received from the remote host to complete the configuration of IP
related settings.
My internet connection did not require authentication, otherwise you should also set that up (more on that later).
Next is the chat-script. The char script is used to send commands to your modem until it's ready for negotiation of the ppp connection. This is my chat script:
ABORT 'BUSY'
ABORT 'NO CARRIER'
ABORT 'ERROR'
'' AT
OK AT+CGDCONT=1,"IP","internet"
OK ATDT*99***1#
It should be saved as /etc/ppp/chat/gprs (as configured in the pppd
configuration file). The first three lines are to detect errors from your modem
and stop the dialin process. The next three lines are send if everything is ok.
You should add any commands here you need for initialization (like sending the
PIN code and tell the device to attach). My device does everything automatically
so this is all i need.
If you need a username and password to connect to the APN you need to add an extra line to /etc/ppp/peers/gprs which contains your username like this:
/dev/tts/USB0
115200
connect 'chat -f /etc/ppp/chat/gprs'
defaultroute
usepeerdns
name username
You should replace username with the name you need to use to connect. The
password should be provided in /etc/ppp/pap-secrets or /etc/ppp/chap-secrets.
This file looks like this:
# Secrets for authentication using PAP
#client server secret IP addresses
username * password
Ofcourse you should replace username and password with the actual username
(which you also configured in /etc/ppp/peers/gprs) and password. Both files
have the same layout, but chap is preferred because pap sends the password in
clear text.
If the pppd configuration confuses you, you might take a look at wvdail. It's a commandline frond-end for pppd. You configure wvdial, and wvdial takes care of configuring pppd. Wvdial uses a single configuration file (/etc/wvdail.conf) which has a simple syntax. An example is listed below:
[Dialer Defaults]
Modem = /dev/tts/USB0
Baud = 230400
Init1 = AT+CGDCONT=1,"IP","internet"
Init2 =
Init3 =
Area Code =
Phone = *99***1#
Username = internet
Password = internet
Ask Password = 0
Dial Command = ATDT
Stupid Mode = 1
Compuserve = 0
Force Address =
Idle Seconds = 0
DialMessage1 =
DialMessage2 =
ISDN = 0
Auto DNS = 1
Check Def Route = 1
As you see the wvdial file is completely different from all pppd stuff, but
contains the same information (initstrings instead of a chatscript, a username
and password instead of pap and chap secrets, and some other basic stuff). I
called this dialer "Defaults". This makes wvdial use this configuration when no
dialer name is supplied.
With wvdial we got all configuration items in one configuration file. But if you often change to a different APN, you still have to edit it manually. To solve this i made a script that asks this information and creates a wvdial configuration according to that. This script also solves an other inconvenience: If a default route exists on the system, pppd (or wvdial) will NOT overwrite it. The script checks the default route, deletes it, starts wvdial, and when wvdial exists it re-creates the original default route.
This is the complete script:
#!/bin/sh
APN="internet"
USER="internet"
PASSWD="internet"
printf "APN [$APN] "
read USERAPN
if [ -z $USERAPN ]
then
USERAPN=$APN
fi
printf "USERNAME [$USER] "
read USERUSER
if [ -z $USERUSER ]
then
USERUSER=$USER
fi
printf "PASSWORD [$PASSWD] "
read -s USERPWD
echo ""
if [ -z $USERPWD ]
then
USERPWD=$PASSWD
fi
DEF_GW=`route -n | awk '{ if ($1=="0.0.0.0") print "route add default gw " $2 " dev " $8 }'`
route del default
cat wvdial.conf.template | \
sed s/@APN@/"$USERAPN"/g | \
sed s/@USERNAME@/"$USERUSER"/g | \
sed s/@PASSWORD@/"$USERPWD"/g > /etc/wvdial.conf
wvdial
$DEF_GW
The APN/Username/Password are default, so if you configure this correct for the APN you use the most you only have to press enter three times to make a connection.
The script uses a template to create a normal wvdial configuration. A template is just a complete wvdial configuration, which @APN@ at the location where the script should place the APN, @USERNAME@ where it should put the username and @PASSWORD@ where it should put the password. As a result, my template looks like this:
Modem = /dev/tts/USB0
Baud = 230400
Init1 = AT+CGDCONT=1,"IP","@APN@"
Init2 =
Init3 =
Area Code =
Phone = *99***1#
Username = @USERNAME@
Password = @PASSWORD@
Ask Password = 0
Dial Command = ATDT
Stupid Mode = 1
Compuserve = 0
Force Address =
Idle Seconds = 0
DialMessage1 =
DialMessage2 =
ISDN = 0
Auto DNS = 1
Check Def Route = 1
Now just place the wvdial.conf.template and the dialer script in the same
directory, and execute the script to start your GPRS connection.
Warning: This script will overwrite /etc/wvdial.conf every time you run it. If you don't want that, maybe changing to ~/.wvdialrc (user specific wvdial configuration) is an option.
Sorry, this is still in progress. The idea is to make a udev configuration which makes standard names for GPRS devices. These names will be known by a dialer script which automatically selects the fastest available, or lets the user choose.
There are some special programs available which will take care of the dialing process and other AT commands.
If you wish to such program, make sure to check availability in your package manager before you download from their site.