Manually using GPRS

From Openmoko

(Difference between revisions)
Jump to: navigation, search
(Some APN names for reference)
m (Some APN names for reference)
Line 255: Line 255:
  
 
[2] Unless stated otherwise the phone number to call is "*99#"
 
[2] Unless stated otherwise the phone number to call is "*99#"
 +
 +
Also see Ross Barkman's page for a detailed list of more [http://www.taniwha.org.uk/gprs.html global GPRS providers]
  
 
== Starting pppd automatically ==
 
== Starting pppd automatically ==

Revision as of 09:14, 6 August 2008

The GPRS connection is made using the PPP protocol to a server identified by an "APN" at the network operator.

The program that implements PPP on Linux is pppd, which we need to configure and run to get a connection. When that is working, we can configure pppd to wait until it's needed before it connects, and to disconnect if the connection becomes idle. Further, we can start pppd in the background during the boot process.

Contents

Configuring pppd for manual connections

You'll need /etc/ppp/peers/gprs:

# Uncomment the following if you want some debug.
#debug
#logfile /var/volatile/log/pppd.log
lock
/dev/ttySAC0 115200
crtscts 
connect /etc/ppp/gprs-connect-chat
disconnect /etc/ppp/gprs-disconnect-chat
hide-password
usepeerdns
ipcp-accept-local
noauth
noipdefault
novj
novjccomp
defaultroute
replacedefaultroute
# Reopen the connection if it fails, pausing for a while.
persist
holdoff 15
# Check the line every 20 seconds and presume
# the peer is gone if no replay for 4 times.
lcp-echo-interval 20
lcp-echo-failure 4

Depending on the APN, you may need password authentication using CHAP or PAP. In /etc/ppp/pap-secrets you can add the following default line for "password-less" connections:

# client        server  secret                  IP addresses
*               *       ""                      *

For CHAP, lines in /etc/ppp/chap-secrets are used. For PAP, the lines are in /etc/ppp/pap-secrets. The client should match the "user" option in pppd the config file (below). You can use * to mean any here, but the option user "" doesn't mean empty!

For example:

# Secrets for authentication using CHAP
# client        server  secret                  IP addresses
"user"         *       "password"                  *  

For this you need the following options in /etc/ppp/peers/gprs:

# username to use for authentication, should match "client" in /etc/ppp/{chap,pap}-secrets
user "user"

And you'll need /etc/ppp/gprs-connect-chat (needs "chmod +x"):

#!/bin/sh -e
exec chat -v -S -s\
        TIMEOUT 15\
        "" "\K\K\K\d+++ATH"\
        OK-AT-OK ATZ\
        OK ATE1\
        ABORT BUSY\
        ABORT DELAYED\
        ABORT "NO ANSWER"\
        ABORT "NO DIALTONE"\
        ABORT VOICE\
        ABORT ERROR\
        ABORT RINGING\
        TIMEOUT 60\
        OK AT+CFUN=1\
        OK AT+COPS\
        OK AT+CGDCONT=1,\"IP\",\"internet\"\
        OK ATD*99#\
        CONNECT /n/d

Update: On my freerunner the first AT+CFUN=1 always generated ERROR. I managed to get gprs work by using the following script from http://lists.openmoko.org/pipermail/community/2008-July/023246.html:

#!/bin/sh -e
exec /usr/sbin/chat -v \
        TIMEOUT 10 \
        OK-AT-'' ''\
        ABORT BUSY\
        ABORT DELAYED\
        ABORT "NO ANSWER"\
        ABORT "NO DIALTONE"\
        ABORT VOICE\
        ABORT ERROR\
        ABORT RINGING\
        TIMEOUT 30 \
        '' ATZ\
        OK ATE1\
        OK AT+CFUN=1\
        ERROR AT+CPIN=\"XXXX\"\         << USE YOUR OWN
        OK AT+COPS\
        OK AT+CGDCONT=1,\"IP\",\"internet\"\
        OK 'ATDT*99***1#'\
        CONNECT ''

You will need to adjust the APN name "internet" in at+cgdcont line and possibly the phone number in the ATD line to match what your network operator provides. See below in the table "Some APN names for reference" for the right settings for your operator.

Also good to have is /etc/ppp/gprs-disconnect-chat (needs "chmod +x"):

#!/bin/sh -e
/usr/sbin/chat -v\
	ABORT OK\
	ABORT BUSY\
	ABORT DELAYED\
	ABORT "NO ANSWER"\
	ABORT "NO CARRIER"\
	ABORT "NO DIALTONE"\
	ABORT VOICE\
	ABORT ERROR\
	ABORT RINGING\
	TIMEOUT 12\
	"" "\K\K\K\d+++ATH"\
	"NO CARRIER-AT-OK" "\c"

The following script can be used to start the ppp connection. First it stops gsmd because gsmd may put the phone in a unknown state. It then turns on the power to the phone, modifies the ownership, and then creates a tty connection. Finally it starts pppd with the gprs settings.

/etc/init.d/gsmd stop
echo "1" > /sys/bus/platform/devices/neo1973-pm-gsm.0/power_on
chown uucp.uucp /dev/ttySAC0
stty -F /dev/ttySAC0 crtscts
pppd call gprs

If you are having problems connecting ensure you have a good GSM signal and replace the last line with the below line. This will allow you to see the details of the connection on the console.

pppd debug nodetach call gprs

The config above will establish a persistant link over gprs. The battery will run low in less than an hour. See an example for an on-demand config below.

Resolve.conf issues

The latest build seems to have solved the following issue, it should be automatically updated by pppd.

If you expeience DNS issues after connecting to DNS you may need a proper /etc/resolv.conf:

ln -sf /var/run/resolv.conf /etc

If needed put your nameserver for usb-net into /var/run/resolv.conf, not in /etc.

The image does not set a correct resolv.conf. i do so with an

echo  nameserver 192.168.0.201 > /var/run/resolv.conf

in the right place. because a post-up in /etc/network/interfaces is not supported i do that in /etc/network/if-up.d/08setupdns

another problem is pppd's /etc/ppp/ip-down.d/92removedns which does not properly remove the link when shuting down ppp. my fix is this script:

#!/bin/sh
ACTUALCONF=/var/run/resolv.conf
PPPCONF=/var/run/ppp/resolv.conf
if [ -f $PPPCONF ] ; then
        if [ -f $ACTUALCONF ] ; then
                if [ ! -h $ACTUALCONF -o ! "`readlink $ACTUALCONF 2>&1`" = "$PPPCONF" ] ; then
                        mv $ACTUALCONF $ACTUALCONF.ppporig
                fi
        fi

        ln -sf $PPPCONF $ACTUALCONF
fi


Some APN names for reference

Country Carrier Plan APN/Phone user/password if required Working pppd scripts
Canada Rogers Any, behind NAT internet.com
Estonia Elisa Any, behind NAT internet
Estonia EMT Any, behind NAT internet.emt.ee
Finland Saunalahti Any internet.saunalahti
Finland Sonera Any, behind NAT internet
Finland Sonera Any, public IP prointernet
France SFR 10.x.x.x? websfr under tests
France SFR 10.x.x.x? wapsfr[1] under tests
France Orange  ??? orange.fr under tests
Germany E-Plus BASE (and others?) internet.eplus.de eplus gprs Base pppd scripts
Germany T-Mobile internet.t-mobile
Germany Vodafone Any, behind NAT web.vodafone.de
Italy Wind Superinternet, public IP internet.wind / *99# wind/wind (any string) Wind pppd scripts
Netherlands Vodafone Any live.vodafone.com / *99***1# Vodafone pppd scripts
New Zealand Vodafone Any live.vodafone.com / *99***2#
Norway Netcom Any internet.netcom.no
Norway Telenor Any telenor
Switzerland Swisscom e.g. Natel Basic Liberty, behind NAT gprs.swisscom.ch
UK T-Mobile general.t-mobile.uk
UK Virgin goto.virginmobile.uk user
UK other providers
USA AT&T Unlimited data plan (attached to pay-as-you-go voice plan) wap.cingular / *99***1# WAP@CINGULARGPRS.COM/CINGULAR1
USA Cingular (AT&T) Less than full internet wap.cingular / may require *99***1#
USA T-mobile Anything less than full internet wap.voicestream.com
USA T-mobile Regular internet plan internet2.voicestream.com T-Mobile pppd scripts
USA T-mobile "VPN" internet plan internet3.voicestream.com
Venezuela Digitel Pre- y post-pago gprsweb.digitel.ve
India AirTel MobileOffice airtelgprs.com

[1] connected through a WAP proxy (slower, but the only way to access Vodafone live! and SFR portal)

[2] Unless stated otherwise the phone number to call is "*99#"

Also see Ross Barkman's page for a detailed list of more global GPRS providers

Starting pppd automatically

Once you have finished debugging your gprs-connect-chat and gprs options files, you may wish to automatically connect whenever needed and hang up when finished. Make sure you understand the impact of this change to your carrier plan billing. This is not recommended unless you have a large-use or unlimited data plan. These scripts do NOT prompt you before connecting.

On-demand connection settings

Additional settings are needed if you want the actual connection to be up only while there is traffic. In the 'gprs' file above, insert the following, making sure 'nodetach' is commented out. If 'nodetach' is on, the boot process will stop when it starts pppd. Also remove the option 'persist' mentioned above.


# Wait until needed before connecting
demand

# Disconnect if idle for given amount of seconds
idle 20

Start on boot (method 1)

Add the following definition to /etc/network/interfaces:

auto ppp0
iface ppp0 inet ppp
        provider gprs

That should be it. Now you can use 'ifup ppp0' and 'ifdown ppp0' manually too.

Start on boot (method 2)

Create the following file as /etc/ppp/ppp_on_boot (needs chmod +x). The /etc/init.d/ppp script will call it to set up the daemon.

#!/bin/sh
#
#   Rename this file to ppp_on_boot and pppd will be fired up as
#   soon as the system comes up, connecting to `provider'.
#
#   If you also make this file executable, and replace the first line
#   with just "#!/bin/sh", the commands below will be executed instead.
#

# The location of the ppp daemon itself (shouldn't need to be changed)
PPPD=/usr/sbin/pppd

# The default provider to connect to
$PPPD call gprs

# Additional connections, which would just use settings from
# /etc/ppp/options.<tty>
#$PPPD ttyS0
#$PPPD ttyS1
#$PPPD ttyS2
#$PPPD ttyS3


Finally, you need to add the /etc/init.d/ppp script to the init process by creating symbolic links from the appropriate directories. I chose the following:

/etc/rc0.d/K25ppp
/etc/rc1.d/K45ppp
/etc/rc2.d/S45ppp
/etc/rc3.d/S45ppp
/etc/rc4.d/S45ppp
/etc/rc5.d/S45ppp
/etc/rc6.d/K25ppp

See also

Personal tools

The GPRS connection is made using the PPP protocol to a server identified by an "APN" at the network operator.

The program that implements PPP on Linux is pppd, which we need to configure and run to get a connection. When that is working, we can configure pppd to wait until it's needed before it connects, and to disconnect if the connection becomes idle. Further, we can start pppd in the background during the boot process.

Configuring pppd for manual connections

You'll need /etc/ppp/peers/gprs:

# Uncomment the following if you want some debug.
#debug
#logfile /var/volatile/log/pppd.log
lock
/dev/ttySAC0 115200
crtscts 
connect /etc/ppp/gprs-connect-chat
disconnect /etc/ppp/gprs-disconnect-chat
hide-password
usepeerdns
ipcp-accept-local
noauth
noipdefault
novj
novjccomp
defaultroute
replacedefaultroute
# Reopen the connection if it fails, pausing for a while.
persist
holdoff 15
# Check the line every 20 seconds and presume
# the peer is gone if no replay for 4 times.
lcp-echo-interval 20
lcp-echo-failure 4

Depending on the APN, you may need password authentication using CHAP or PAP. In /etc/ppp/pap-secrets you can add the following default line for "password-less" connections:

# client        server  secret                  IP addresses
*               *       ""                      *

For CHAP, lines in /etc/ppp/chap-secrets are used. For PAP, the lines are in /etc/ppp/pap-secrets. The client should match the "user" option in pppd the config file (below). You can use * to mean any here, but the option user "" doesn't mean empty!

For example:

# Secrets for authentication using CHAP
# client        server  secret                  IP addresses
"user"         *       "password"                  *  

For this you need the following options in /etc/ppp/peers/gprs:

# username to use for authentication, should match "client" in /etc/ppp/{chap,pap}-secrets
user "user"

And you'll need /etc/ppp/gprs-connect-chat (needs "chmod +x"):

#!/bin/sh -e
exec chat -v -S -s\
        TIMEOUT 15\
        "" "\K\K\K\d+++ATH"\
        OK-AT-OK ATZ\
        OK ATE1\
        ABORT BUSY\
        ABORT DELAYED\
        ABORT "NO ANSWER"\
        ABORT "NO DIALTONE"\
        ABORT VOICE\
        ABORT ERROR\
        ABORT RINGING\
        TIMEOUT 60\
        OK AT+CFUN=1\
        OK AT+COPS\
        OK AT+CGDCONT=1,\"IP\",\"internet\"\
        OK ATD*99#\
        CONNECT /n/d

Update: On my freerunner the first AT+CFUN=1 always generated ERROR. I managed to get gprs work by using the following script from http://lists.openmoko.org/pipermail/community/2008-July/023246.html:

#!/bin/sh -e
exec /usr/sbin/chat -v \
        TIMEOUT 10 \
        OK-AT-'' ''\
        ABORT BUSY\
        ABORT DELAYED\
        ABORT "NO ANSWER"\
        ABORT "NO DIALTONE"\
        ABORT VOICE\
        ABORT ERROR\
        ABORT RINGING\
        TIMEOUT 30 \
        '' ATZ\
        OK ATE1\
        OK AT+CFUN=1\
        ERROR AT+CPIN=\"XXXX\"\         << USE YOUR OWN
        OK AT+COPS\
        OK AT+CGDCONT=1,\"IP\",\"internet\"\
        OK 'ATDT*99***1#'\
        CONNECT ''

You will need to adjust the APN name "internet" in at+cgdcont line and possibly the phone number in the ATD line to match what your network operator provides. See below in the table "Some APN names for reference" for the right settings for your operator.

Also good to have is /etc/ppp/gprs-disconnect-chat (needs "chmod +x"):

#!/bin/sh -e
/usr/sbin/chat -v\
	ABORT OK\
	ABORT BUSY\
	ABORT DELAYED\
	ABORT "NO ANSWER"\
	ABORT "NO CARRIER"\
	ABORT "NO DIALTONE"\
	ABORT VOICE\
	ABORT ERROR\
	ABORT RINGING\
	TIMEOUT 12\
	"" "\K\K\K\d+++ATH"\
	"NO CARRIER-AT-OK" "\c"

The following script can be used to start the ppp connection. First it stops gsmd because gsmd may put the phone in a unknown state. It then turns on the power to the phone, modifies the ownership, and then creates a tty connection. Finally it starts pppd with the gprs settings.

/etc/init.d/gsmd stop
echo "1" > /sys/bus/platform/devices/neo1973-pm-gsm.0/power_on
chown uucp.uucp /dev/ttySAC0
stty -F /dev/ttySAC0 crtscts
pppd call gprs

If you are having problems connecting ensure you have a good GSM signal and replace the last line with the below line. This will allow you to see the details of the connection on the console.

pppd debug nodetach call gprs

The config above will establish a persistant link over gprs. The battery will run low in less than an hour. See an example for an on-demand config below.

Resolve.conf issues

The latest build seems to have solved the following issue, it should be automatically updated by pppd.

If you expeience DNS issues after connecting to DNS you may need a proper /etc/resolv.conf:

ln -sf /var/run/resolv.conf /etc

If needed put your nameserver for usb-net into /var/run/resolv.conf, not in /etc.

The image does not set a correct resolv.conf. i do so with an

echo  nameserver 192.168.0.201 > /var/run/resolv.conf

in the right place. because a post-up in /etc/network/interfaces is not supported i do that in /etc/network/if-up.d/08setupdns

another problem is pppd's /etc/ppp/ip-down.d/92removedns which does not properly remove the link when shuting down ppp. my fix is this script:

#!/bin/sh
ACTUALCONF=/var/run/resolv.conf
PPPCONF=/var/run/ppp/resolv.conf
if [ -f $PPPCONF ] ; then
        if [ -f $ACTUALCONF ] ; then
                if [ ! -h $ACTUALCONF -o ! "`readlink $ACTUALCONF 2>&1`" = "$PPPCONF" ] ; then
                        mv $ACTUALCONF $ACTUALCONF.ppporig
                fi
        fi

        ln -sf $PPPCONF $ACTUALCONF
fi


Some APN names for reference

Country Carrier Plan APN/Phone user/password if required Working pppd scripts
Canada Rogers Any, behind NAT internet.com
Estonia Elisa Any, behind NAT internet
Estonia EMT Any, behind NAT internet.emt.ee
Finland Saunalahti Any internet.saunalahti
Finland Sonera Any, behind NAT internet
Finland Sonera Any, public IP prointernet
France SFR 10.x.x.x? websfr under tests
France SFR 10.x.x.x? wapsfr[1] under tests
France Orange  ??? orange.fr under tests
Germany E-Plus BASE (and others?) internet.eplus.de eplus gprs Base pppd scripts
Germany T-Mobile internet.t-mobile
Germany Vodafone Any, behind NAT web.vodafone.de
Italy Wind Superinternet, public IP internet.wind / *99# wind/wind (any string) Wind pppd scripts
Netherlands Vodafone Any live.vodafone.com / *99***1# Vodafone pppd scripts
New Zealand Vodafone Any live.vodafone.com / *99***2#
Norway Netcom Any internet.netcom.no
Norway Telenor Any telenor
Switzerland Swisscom e.g. Natel Basic Liberty, behind NAT gprs.swisscom.ch
UK T-Mobile general.t-mobile.uk
UK Virgin goto.virginmobile.uk user
UK other providers
USA AT&T Unlimited data plan (attached to pay-as-you-go voice plan) wap.cingular / *99***1# WAP@CINGULARGPRS.COM/CINGULAR1
USA Cingular (AT&T) Less than full internet wap.cingular / may require *99***1#
USA T-mobile Anything less than full internet wap.voicestream.com
USA T-mobile Regular internet plan internet2.voicestream.com T-Mobile pppd scripts
USA T-mobile "VPN" internet plan internet3.voicestream.com
Venezuela Digitel Pre- y post-pago gprsweb.digitel.ve
India AirTel MobileOffice airtelgprs.com

[1] connected through a WAP proxy (slower, but the only way to access Vodafone live! and SFR portal)

[2] Unless stated otherwise the phone number to call is "*99#"

Also see Ross Barkman's page for a detailed list of more global GPRS providers

Starting pppd automatically

Once you have finished debugging your gprs-connect-chat and gprs options files, you may wish to automatically connect whenever needed and hang up when finished. Make sure you understand the impact of this change to your carrier plan billing. This is not recommended unless you have a large-use or unlimited data plan. These scripts do NOT prompt you before connecting.

On-demand connection settings

Additional settings are needed if you want the actual connection to be up only while there is traffic. In the 'gprs' file above, insert the following, making sure 'nodetach' is commented out. If 'nodetach' is on, the boot process will stop when it starts pppd. Also remove the option 'persist' mentioned above.


# Wait until needed before connecting
demand

# Disconnect if idle for given amount of seconds
idle 20

Start on boot (method 1)

Add the following definition to /etc/network/interfaces:

auto ppp0
iface ppp0 inet ppp
        provider gprs

That should be it. Now you can use 'ifup ppp0' and 'ifdown ppp0' manually too.

Start on boot (method 2)

Create the following file as /etc/ppp/ppp_on_boot (needs chmod +x). The /etc/init.d/ppp script will call it to set up the daemon.

#!/bin/sh
#
#   Rename this file to ppp_on_boot and pppd will be fired up as
#   soon as the system comes up, connecting to `provider'.
#
#   If you also make this file executable, and replace the first line
#   with just "#!/bin/sh", the commands below will be executed instead.
#

# The location of the ppp daemon itself (shouldn't need to be changed)
PPPD=/usr/sbin/pppd

# The default provider to connect to
$PPPD call gprs

# Additional connections, which would just use settings from
# /etc/ppp/options.<tty>
#$PPPD ttyS0
#$PPPD ttyS1
#$PPPD ttyS2
#$PPPD ttyS3


Finally, you need to add the /etc/init.d/ppp script to the init process by creating symbolic links from the appropriate directories. I chose the following:

/etc/rc0.d/K25ppp
/etc/rc1.d/K45ppp
/etc/rc2.d/S45ppp
/etc/rc3.d/S45ppp
/etc/rc4.d/S45ppp
/etc/rc5.d/S45ppp
/etc/rc6.d/K25ppp

See also