Manually using GPRS

From Openmoko

(Difference between revisions)
Jump to: navigation, search
(structure the page more, add a simpler method for start on boot)
m (Languages)
Line 284: Line 284:
 
* [[Manually using Bluetooth]]
 
* [[Manually using Bluetooth]]
  
 +
{{Languages|Manually_using_GPRS}}
 
[[Category:Documentation]]
 
[[Category:Documentation]]
 
[[Category:Developer software]]
 
[[Category:Developer software]]
  
 
[[Category:Guides]]
 
[[Category:Guides]]

Revision as of 17:11, 9 September 2007

You need to have GSM parts already initialized, with modem logged in to the network, for this to work. It is best to test it by doing test call. 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

Depending on the APN, you may need password authentication using CHAP or PAP. 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
*               *       ""                      *
"gprs"          *       "gprs"                  *
"eplus"         *       "gprs"                  *  

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

# File:
# gprs
#
# Description:
# This file holds the pppd options for GPRS

# To give some debug info (can be provided on command line too)
#debug

# To keep pppd output on the terminal (can be provided on command line too)
#nodetach

# Serial device to which the GPRS modem is connected
/dev/ttySAC0 # Raw serial on Neo1973
#/dev/ircomm0 # IrDA
#/dev/ttyACM0 # USB serial cable

# Serial port line speed
115200

# use hardware flow control
crtscts # serial cables etc.
#nocrtscts # IrDA

# time between retries
holdoff 3

# Connect script
connect /etc/ppp/peers/gprs-connect-chat

# Disconnect script
disconnect /etc/ppp/peers/gprs-disconnect-chat

# IP addresses:
# - accept peers idea of our local address and set address peer as 10.0.0.1
# (any address would do, since IPCP gives 0.0.0.0 to it)
# - if you use the 10. network at home or something and pppd rejects it,
# change the address to something else
:10.0.0.1

# pppd must not propose any IP address to the peer!
noipdefault

# Accept peers idea of our local address
ipcp-accept-local

# No ppp compression
novj
novjccomp

# Add default route
defaultroute

# Replace any other default route for the time of the connection:
replacedefaultroute

# very long timeouts (unwise?)
lcp-echo-interval 300
lcp-echo-failure 40000

# don't require the other end to authenticate to us
noauth

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

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

#!/bin/sh
#
# File:
# chat-gprs-connect
#
# Description:
# chat script to open Sonera GPRS service with GPRS phones. If ppp
# negotiation stalls, try restarting the phone. To try with other GPRS
# operator setting, change the PDP contex setting. The settings work with
# all Ericsson models, but Nokia 8310 does not suppor QoS parameters with
# AT commands, so just delete those lines and it'll work.
#
# Set PDP context CID=1, protocol=IP, APN=internet:
# AT+CGDCONT=1,"IP","internet","",0,0
#
# Set CID=1 QoS requirements from the network, not supported by 8310:
# AT+CGQREQ=1,0,0,0,0,0
#
# Set CID=1 minimum acceptable QoS parameters, not supported by 8310:
# AT+CGQMIN=1,0,0,0,0,0
#
# 'Call' CID=1 (activate PDP context one, perform GPRS attach):
# ATD*99***1#
#
# The actual chat script:
exec chat                                               \
TIMEOUT         22                              \
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'    \
SAY             "Press CTRL-C to close the connection at any stage!"    \
SAY             "\ndefining PDP context...\n"   \
""              "\d" \
""              "atz" \
OK              "ate1" \
OK              'at+cgdcont=1,"ip","internet","0.0.0.0",0,0' \
TIMEOUT         22      \
OK              ATDT*99***1#    \
TIMEOUT         22              \
SAY             "\nwaiting for connect...\n"    \
CONNECT         ""                              \
SAY             "\nConnected." \
SAY             "\nIf the following ppp negotiations fail,\n"   \
SAY             "try restarting the phone.\n"

You will need to adjust the APN name "internet" in at+cgdcont line to match what your network operator provides.


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

#!/bin/sh

exec /usr/sbin/chat -V -s -S    \
ABORT           "BUSY"          \
ABORT           "ERROR"         \
ABORT           "NO DIALTONE"   \
SAY             "\nSending break to the modem\n"        \
""              "\K"            \
""              "\K"            \
""              "\K"            \
""              "+++ATH"        \
""              "+++ATH"        \
""              "+++ATH"        \
"NO CARRIER"    ""              \
SAY             "\nPDP context detached\n"


Starting pppd

Then, after initializing GSM, you should be able to initialize GPRS by `pppd call gprs`. Good luck!

To dial in - and get verbose output on the terminal - use pppd

pppd debug nodetach call gprs


Some APN names for reference

Country Carrier Plan APN AT-CMD
USA T-mobile Anything less than full internet wap.voicestream.com
USA T-mobile Regular internet plan internet2.voicestream.com
USA T-mobile "VPN" internet plan internet3.voicestream.com
USA Cingular (AT&T) Less than full internet wap.cingular
Finland Saunalahti Any internet.saunalahti
Finland Sonera Any, behind NAT internet
Finland Sonera Any, public IP prointernet
Germany T-Mobile internet.t-mobile
Germany E-Plus BASE (and others?) internet.eplus.de 'AT+CGDCONT=1,"ip","internet.eplus.de"'
UK T-Mobile general.t-mobile.uk


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.


# 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

You need to have GSM parts already initialized, with modem logged in to the network, for this to work. It is best to test it by doing test call. 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

Depending on the APN, you may need password authentication using CHAP or PAP. 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
*               *       ""                      *
"gprs"          *       "gprs"                  *
"eplus"         *       "gprs"                  *  

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

# File:
# gprs
#
# Description:
# This file holds the pppd options for GPRS

# To give some debug info (can be provided on command line too)
#debug

# To keep pppd output on the terminal (can be provided on command line too)
#nodetach

# Serial device to which the GPRS modem is connected
/dev/ttySAC0 # Raw serial on Neo1973
#/dev/ircomm0 # IrDA
#/dev/ttyACM0 # USB serial cable

# Serial port line speed
115200

# use hardware flow control
crtscts # serial cables etc.
#nocrtscts # IrDA

# time between retries
holdoff 3

# Connect script
connect /etc/ppp/peers/gprs-connect-chat

# Disconnect script
disconnect /etc/ppp/peers/gprs-disconnect-chat

# IP addresses:
# - accept peers idea of our local address and set address peer as 10.0.0.1
# (any address would do, since IPCP gives 0.0.0.0 to it)
# - if you use the 10. network at home or something and pppd rejects it,
# change the address to something else
:10.0.0.1

# pppd must not propose any IP address to the peer!
noipdefault

# Accept peers idea of our local address
ipcp-accept-local

# No ppp compression
novj
novjccomp

# Add default route
defaultroute

# Replace any other default route for the time of the connection:
replacedefaultroute

# very long timeouts (unwise?)
lcp-echo-interval 300
lcp-echo-failure 40000

# don't require the other end to authenticate to us
noauth

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

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

#!/bin/sh
#
# File:
# chat-gprs-connect
#
# Description:
# chat script to open Sonera GPRS service with GPRS phones. If ppp
# negotiation stalls, try restarting the phone. To try with other GPRS
# operator setting, change the PDP contex setting. The settings work with
# all Ericsson models, but Nokia 8310 does not suppor QoS parameters with
# AT commands, so just delete those lines and it'll work.
#
# Set PDP context CID=1, protocol=IP, APN=internet:
# AT+CGDCONT=1,"IP","internet","",0,0
#
# Set CID=1 QoS requirements from the network, not supported by 8310:
# AT+CGQREQ=1,0,0,0,0,0
#
# Set CID=1 minimum acceptable QoS parameters, not supported by 8310:
# AT+CGQMIN=1,0,0,0,0,0
#
# 'Call' CID=1 (activate PDP context one, perform GPRS attach):
# ATD*99***1#
#
# The actual chat script:
exec chat                                               \
TIMEOUT         22                              \
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'    \
SAY             "Press CTRL-C to close the connection at any stage!"    \
SAY             "\ndefining PDP context...\n"   \
""              "\d" \
""              "atz" \
OK              "ate1" \
OK              'at+cgdcont=1,"ip","internet","0.0.0.0",0,0' \
TIMEOUT         22      \
OK              ATDT*99***1#    \
TIMEOUT         22              \
SAY             "\nwaiting for connect...\n"    \
CONNECT         ""                              \
SAY             "\nConnected." \
SAY             "\nIf the following ppp negotiations fail,\n"   \
SAY             "try restarting the phone.\n"

You will need to adjust the APN name "internet" in at+cgdcont line to match what your network operator provides.


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

#!/bin/sh

exec /usr/sbin/chat -V -s -S    \
ABORT           "BUSY"          \
ABORT           "ERROR"         \
ABORT           "NO DIALTONE"   \
SAY             "\nSending break to the modem\n"        \
""              "\K"            \
""              "\K"            \
""              "\K"            \
""              "+++ATH"        \
""              "+++ATH"        \
""              "+++ATH"        \
"NO CARRIER"    ""              \
SAY             "\nPDP context detached\n"


Starting pppd

Then, after initializing GSM, you should be able to initialize GPRS by `pppd call gprs`. Good luck!

To dial in - and get verbose output on the terminal - use pppd

pppd debug nodetach call gprs


Some APN names for reference

Country Carrier Plan APN AT-CMD
USA T-mobile Anything less than full internet wap.voicestream.com
USA T-mobile Regular internet plan internet2.voicestream.com
USA T-mobile "VPN" internet plan internet3.voicestream.com
USA Cingular (AT&T) Less than full internet wap.cingular
Finland Saunalahti Any internet.saunalahti
Finland Sonera Any, behind NAT internet
Finland Sonera Any, public IP prointernet
Germany T-Mobile internet.t-mobile
Germany E-Plus BASE (and others?) internet.eplus.de 'AT+CGDCONT=1,"ip","internet.eplus.de"'
UK T-Mobile general.t-mobile.uk


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.


# 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