Skip to content

Instantly share code, notes, and snippets.

@bewest
Created September 27, 2012 06:20
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 3 You must be signed in to fork a gist
  • Save bewest/3792485 to your computer and use it in GitHub Desktop.
Save bewest/3792485 to your computer and use it in GitHub Desktop.
Ting configure AT chat+pppd in linux 3g+beaglebone angstrom cloud9-image
#!/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
#!/bin/sh
ACTUALCONF=/var/run/resolv.conf
if [ -f $ACTUALCONF.ppporig ] ; then
mv $ACTUALCONF.ppporig $ACTUALCONF
fi

Configure pppd in Linux for Ting/AT&T wireless via usb

Modify AT&T's suggestion for using pppd to connect to their wireless network.

http://www.att.com/esupport/article.jsp?sid=36059&cv=820#fbid=Ph3zROJiN9D

Tested on beaglebone with sierra 250 from Ting. Basically, one just dials ATD*99***1# and everything works. On older networks, use the 777 number instead.

I didn't know exactly what chat did or how it was used until this project, which is well after I wrote unapy. chat seems to be an elegant solution, but it makes conditional auditing and reporting somewhat painful if you don't love shell scripts. unapy or a similar framework in ruby or coffeescript (for node) might be handy in the future? There is some value in being able to audit and monitor the modem itself.

Symlinking /etc/ppp/peers/provider -> /etc/ppp/peers/gprs will enable starting properly such that pon and poff work. (No joke.)

Using

$ pppd call gprs

Note: This tells the PPPD dialer to call the gprs script, which in turn calls gprs-connect-chat and gprs-disconnect-chat as necessary. Attempt to browse. If unable to resolve url's it's likely due to PPPD not updating /etc/resolv.conf with the correct DNS servers. To fix this, back up /etc/resolv.conf and issue the following command:

echo - e "nameserver 10.250.1.10\nnameserver 10.250.1.11: > /etc/resolv.conf

To disconnect, press "Control-C" in the terminal window.

Notes

# Name: gprs
# Purpose: GPRS PPPD Connection Script
# Notes: This is a detailed connection script for using GPRS devices as a tethered modem when connected via Bluetooth, Serial or USB.
# See PPPD man pages for more info.
#
# Most GPRS devices will not reply to LCP echo's
lcp-echo-failure 0
lcp-echo-interval 0
#
# Specify 'nodetach' to allow PPPD to run interactively rather than as a background daemon.
nodetach
#
# Used to create a debug log.
# Comment this out once the PPP configuration is connecting successfully.
debug
#
# Show password in debug messages.
show-password
#
# Connect Script: CHAT is used to issue modem connect commands.
connect "/usr/sbin/chat -v -V -S -s -t3 -f /etc/ppp/peers/gprs-connect-chat"
#
# Disconnect Script: CHAT is used to issue modem disconnect commands.
disconnect /etc/ppp/peers/gprs-disconnect-chat
#
# Specify which device to use. By default this dynamically maps to devices created in /dev/modem but can be adjusted as necessary.
#/dev/modem
/dev/ttyUSB0
# /dev/ttyS0 # Serial Port 1 (COM1 in Windows)
# /dev/ttyS1 # Serial Port 2 (COM2 in Windows)
# /dev/ircomm0 # IrDA Serial Port
# /dev/ttyUSB0 # USB Serial device
# /dev/rfcomm0 # Bluetooth Serial Port 1
# /dev/rfcomm1 # Bluetooth Serial Port 2
#
# Set the LOCAL serial port line speed. This does NOT affect GPRS connection speed.
#57600 # Some IrDA devices don't run full-duplex and this speed must be used.
115200 # GPRS and EDGE Devices.
#230400 # UMTS devices.
#460800 # HSDPA UMTS devices.
#
# Hardware flow control should be used with most devices.
crtscts # Use for Serial, BlueTooth and USB devices.
#nocrtscts # Use for IrDA devices.
#
# Add the PPP interface as the default route to the IP routing table.
defaultroute
#
# PPP compression options.
# These are specific to the serial connection, not the GPRS connection.
novj
nobsdcomp
novjccomp
nopcomp
noaccomp
#
# Defines whether an attempt should be made to re-establish a dropped GPRS connection.
persist
#
# Defines the maximum number of reconnect attempts to try.
maxfail 99
#
# Ignore carrier detect signal from the modem.
# local
#
# This advises the PPP accept peers idea of our local address and sets address peer as 10.0.0.1.
# Any address will do since IPCP assigns 0.0.0.0 to it.
# PPPD may reject this if you are using the 10.x.x.x range on another interface.
# :10.0.0.1
#
# Advises PPPD to request any DHCP address, none in particular.
# noipdefault
#
# Allows the PPPD daemon to accept DHCP assigned IPs.
# ipcp-accept-local
#
# Advises PPPD to use the DNS provided by DHCP. Commonly causes "Received bad configure-nak/rej" errors when used.
# usepeerdns
#
# Used to disable authentication when establishing PDP context.
# If a custom PDP requires authentication, comment this out and provide the correct username below and update the username-password combination to the secrets file: /etc/ppp/pap-secrets (for PAP) or /etc/ppp/chap-secrets (for CHAP).
# See the PPPD man pages for further information.
# user "username"
#
# Asyncmap - Some devices may require this.
# asyncmap 0xa0000
#
# With the 'nomagic' option, PPPD cannot detect a looped-back line.
# Uncomment this only if the PPPD connection is buggy.
# nomagic
#
# Require the peer authenticate itself using PAP - Some devices may require this.
# require-pap
# Name: gprs-connect-chat
# Purpose: GPRS PPP Connect Script
# Notes: CHAT is used to issue modem AT commands. See CHAT man pages for more info.
#
# Activate the device and pause before sending additional AT commands.
#'' AT+CFUN=1
'' AT
#
# Verify GPRS Attach prior to attempting PDP Context negotiation.
#'' AT+CGREG=1
#
# Define the PDP Context: Context ID, Routing Protocol, APN
# Multiple definitions can be configured by assigning each a unique CID.
# Use "isp.cingular" or "Broadband" to connect to the Cingular/AT&T orange network.
# Use "proxy" to connect to the AT&T blue network.
#OK AT+CGDCONT=1,"IP","isp.cingular" or "Broadband"
#
# Set the dialing string and specify which PDP Context definition to use.
OK ATD*99***1#
#
# Attempt to connect.
CONNECT ''
# Name: gprs-disconnect-chat
# Purpose: GPRS PPP Disconnect Script
# Notes: CHAT is used to issue modem AT commands. See CHAT man pages for more info.
#
exec /usr/sbin/chat -V -s -S \
ABORT "BUSY" \
ABORT "ERROR" \
ABORT "NO DIALTONE" \
SAY "n\Sending break to the modem\n" \
"" "\K" \
"" "\K" \
"" "\K" \
"" "+++ATH" \
"" "+++ATH" \
"" "+++ATH" \
SAY "\nPDP context detached\n"
#!/bin/sh
#
# $Id: ip-down,v 1.2 1998/02/10 21:21:55 phil Exp $
#
# This script is run by the pppd _after_ the link is brought down.
# It uses run-parts to run scripts in /etc/ppp/ip-down.d, so to delete
# routes, unset IP addresses etc. you should create script(s) there.
#
# Be aware that other packages may include /etc/ppp/ip-down.d scripts (named
# after that package), so choose local script names with that in mind.
#
# This script is called with the following arguments:
# Arg Name Example
# $1 Interface name ppp0
# $2 The tty ttyS1
# $3 The link speed 38400
# $4 Local IP number 12.34.56.78
# $5 Peer IP number 12.34.56.99
# $6 Optional ``ipparam'' value foo
# The environment is cleared before executing this script
# so the path must be reset
PATH=/usr/local/sbin:/usr/sbin:/sbin:/usr/local/bin:/usr/bin:/bin
export PATH
# These variables are for the use of the scripts run by run-parts
PPP_IFACE="$1"
PPP_TTY="$2"
PPP_SPEED="$3"
PPP_LOCAL="$4"
PPP_REMOTE="$5"
PPP_IPPARAM="$6"
export PPP_IFACE PPP_TTY PPP_SPEED PPP_LOCAL PPP_REMOTE PPP_IPPARAM
# as an additional convenience, $PPP_TTYNAME is set to the tty name,
# stripped of /dev/ (if present) for easier matching.
PPP_TTYNAME=`/usr/bin/basename "$2"`
export PPP_TTYNAME
# Main Script starts here
run-parts /etc/ppp/ip-down.d
# last line
#!/bin/bash
# latest-kernel-support: 2.6.18
# Author: Kevin Lloyd <linux@sierrawireless.com>
# Date: 10/20/2006
if [ $# -eq 0 ]; then
exit 1
fi
if [ $1 = ppp0 ]; then
mv -f /etc/resolv.conf /etc/resolv.conf.ppp0
if [ -e /etc/resolv.conf.orig ]; then
cp /etc/resolv.conf.orig /etc/resolv.conf
else
grep -v ppp0 /etc/resolv.conf.ppp0 > /etc/resolv.conf
fi
chmod a+r /etc/resolv.conf
fi
#!/bin/sh
#
# $Id: ip-up,v 1.2 1998/02/10 21:25:34 phil Exp $
#
# This script is run by the pppd after the link is established.
# It uses run-parts to run scripts in /etc/ppp/ip-up.d, so to add routes,
# set IP address, run the mailq etc. you should create script(s) there.
#
# Be aware that other packages may include /etc/ppp/ip-up.d scripts (named
# after that package), so choose local script names with that in mind.
#
# This script is called with the following arguments:
# Arg Name Example
# $1 Interface name ppp0
# $2 The tty ttyS1
# $3 The link speed 38400
# $4 Local IP number 12.34.56.78
# $5 Peer IP number 12.34.56.99
# $6 Optional ``ipparam'' value foo
# The environment is cleared before executing this script
# so the path must be reset
PATH=/usr/local/sbin:/usr/sbin:/sbin:/usr/local/bin:/usr/bin:/bin
export PATH
# These variables are for the use of the scripts run by run-parts
PPP_IFACE="$1"
PPP_TTY="$2"
PPP_SPEED="$3"
PPP_LOCAL="$4"
PPP_REMOTE="$5"
PPP_IPPARAM="$6"
export PPP_IFACE PPP_TTY PPP_SPEED PPP_LOCAL PPP_REMOTE PPP_IPPARAM
# as an additional convenience, $PPP_TTYNAME is set to the tty name,
# stripped of /dev/ (if present) for easier matching.
PPP_TTYNAME=`/usr/bin/basename "$2"`
export PPP_TTYNAME
# Main Script starts here
run-parts /etc/ppp/ip-up.d
# last line
#!/bin/bash
# latest-kernel-support: 2.6.18
# Author: Kevin Lloyd <linux@sierrawireless.com>
# Date: 10/20/2006
if [ $# -eq 0 ]; then
exit 1
fi
if [ $1 = ppp0 ]; then
if [ -e /var/run/ppp/resolv.conf ]; then
grep -v ppp0 /etc/resolv.conf > /etc/resolv.conf.orig
echo \#These entries are from the ppp0 connection > /etc/resolv.conf
sed -e 's/$/ #ppp0 entry/g' /var/run/ppp/resolv.conf >> /etc/resolv.conf
cat /etc/resolv.conf.orig >> /etc/resolv.conf
chmod a+r /etc/resolv.conf
elif [ -e /etc/ppp/resolv.conf ]; then
grep -v ppp0 /etc/resolv.conf > /etc/resolv.conf.orig
echo \#These entries are from the ppp0 connection > /etc/resolv.conf
sed -e 's/$/ #ppp0 entry/g' /etc/ppp/resolv.conf >> /etc/resolv.conf
cat /etc/resolv.conf.orig >> /etc/resolv.conf
chmod a+r /etc/resolv.conf
fi
fi
logfile /var/log/ppp/log
noaccomp
nopcomp
nocrtscts
lock
maxfail 0
#/usr/bin/ntpdate -b -s -u pool.ntp.org
echo STARTING script >> /home/root/logfile.txt
export SHELL=/bin/sh
export TERM=vt100
export USER=root
export PATH=/usr/local/bin:/usr/bin:/bin:/usr/local/sbin:/usr/sbin:/sbin
export PWD=/home/root
export HOME=/home/root
export SHLVL=2
exportLOGNAME=root
d=`date`
env >> /home/root/logfile.txt
echo $d >>/home/root/logfile.txt
ifconfig >> /home/root/logfile.txt
/usr/bin/poff
sleep 5
/usr/bin/pon
sleep 5
echo resolv.conf file contents >> /home/root/logfile.txt
cat /etc/resolv.conf >> /home/root/logfile.txt
cp /etc/open.resolv.conf /etc/resolv.conf
export gw=`ifconfig ppp0 |grep inet | awk '{print $3}'|sed /P-t-P:/s///`
export PPP0=`ifconfig ppp0 | grep "inet addr" | awk '{ print $2 }' | awk 'BEGIN { FS=":" } { print $2 }'`
echo PPP0=$PPP0
/sbin/route add -net 0.0.0.0 gw $PPP0
ifconfig >> /home/root/logfile.txt
echo remote is at $PPP0 >> /home/root/logfile.txt
rm -f mconnect.php
/usr/bin/wget http://ifconfig.me/ >> /home/root/logfile.txt
/usr/bin/poff
#route delete default gw 66.1.125.193 dev ppp0
#route add default gw 192.168.1.1 dev eth0
echo ENDING script >> /home/root/logfile.txt
d=`date`
echo $d >>/home/root/logfile.txt
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment