commit | author | age
|
281a7f
|
1 |
#!/bin/sh |
G |
2 |
# FILE:/usr/sbin/ifup-ppp |
|
3 |
# Copyright (C) 2011 GuoWenxue <guowenxue@gmail.com> |
|
4 |
# This file used to do PPP dial up. |
|
5 |
|
|
6 |
#-------------------------------------------------- |
|
7 |
# Function definition here |
|
8 |
#-------------------------------------------------- |
|
9 |
usage() |
|
10 |
{ |
|
11 |
prog=`basename $0` |
|
12 |
echo "$prog Usage: $prog [-d /dev/ttyUSB0] [-a apn] [-u username] [-p password] [-v chap/pap] [-i ipaddr] pppXX" |
|
13 |
echo "" |
|
14 |
echo " This shell script used to do pppd dial up on GPRS/3G modem, if no options gived, it" |
|
15 |
echo "will use the default configure file \"$network_cfg_dir/ifcfg-pppXX\". If get options" |
|
16 |
echo "in this command, it will use the option from the command line, and be careful the -d" |
|
17 |
echo "option must be given to specify the modem device." |
|
18 |
echo "" |
|
19 |
|
|
20 |
echo "pppXX: Required, specify the dial up generated PPP device, such as ppp10." |
|
21 |
echo "-d: Required, if use command line options, specify the modem TTY device." |
|
22 |
echo "-a: Option, APN(Access Point Name) for the SIM card provider." |
|
23 |
echo "-u: Option, username for the GPRS login if needed." |
|
24 |
echo "-p: Option, password for the GPRS login if needed." |
|
25 |
echo "-v: Option, authenticate method, pap or chap." |
|
26 |
echo "-i: Option, <local_IP_address>:<remote_IP_address> such as 0.0.0.0:0.0.0.0 " |
|
27 |
echo "Example: ifup-ppp -d /dev/ttyUSB0 -a 3gnet -u uid -p pwd ppp10" |
|
28 |
|
|
29 |
echo "" |
|
30 |
echo "Copyright (C) 2011 GuoWenxue <guowenxue@gmail.com>" |
|
31 |
exit |
|
32 |
} |
|
33 |
|
|
34 |
#=============================== |
|
35 |
# Global variable declare = |
|
36 |
#=============================== |
|
37 |
modem= |
|
38 |
inf= |
|
39 |
apn= |
|
40 |
uid= |
|
41 |
pwd= |
|
42 |
|
|
43 |
|
|
44 |
# Configure file |
|
45 |
if [ -z "$network_cfg_dir" ]; then |
|
46 |
export network_cfg_dir=/apps/etc/network |
|
47 |
fi |
|
48 |
|
|
49 |
#=============================== |
|
50 |
# Shell body start here = |
|
51 |
#=============================== |
|
52 |
|
|
53 |
if [ $# -lt 1 ] ; then |
|
54 |
usage; |
|
55 |
elif [ $# -eq 1 ] ; then |
|
56 |
inf=$1 |
|
57 |
conf=ifcfg-$inf |
|
58 |
|
|
59 |
cd $network_cfg_dir |
|
60 |
|
|
61 |
if [ ! -f $conf ]; then |
|
62 |
echo "=================================================================================" |
|
63 |
echo "ERROR: $inf dial up configure file \"$network_cfg_dir/$conf\" not found!" |
|
64 |
echo "=================================================================================" |
|
65 |
echo "" |
|
66 |
usage; |
|
67 |
exit; |
|
68 |
fi |
|
69 |
|
|
70 |
. $conf |
|
71 |
modem=$MODEM |
|
72 |
apn=$APN |
|
73 |
uid=$USERNAME |
|
74 |
pwd=$PASSWORD |
|
75 |
vrfy=$VERIFY |
|
76 |
ipaddr=$IPADDR |
|
77 |
cd - |
|
78 |
else |
|
79 |
while getopts "a:d:u:p:v:hi:" Option |
|
80 |
do |
|
81 |
case $Option in |
|
82 |
d) modem=$OPTARG ;; |
|
83 |
i) ipaddr=$OPTARG ;; |
|
84 |
a) apn=$OPTARG ;; |
|
85 |
u) uid=$OPTARG ;; |
|
86 |
p) pwd=$OPTARG ;; |
|
87 |
v) vrfy=$OPTARG ;; |
|
88 |
h) pwd=$OPTARG; usage ;; |
|
89 |
esac |
|
90 |
done |
|
91 |
shift $(($OPTIND - 1)) |
|
92 |
inf=$* |
|
93 |
fi |
|
94 |
|
|
95 |
if [ -z "$modem" ] ; then |
|
96 |
usage; |
|
97 |
exit; |
|
98 |
fi |
|
99 |
|
|
100 |
if [ ! -c "$modem" ] ; then |
|
101 |
echo "ERROR: Modem device $modem doesn't exist!" |
|
102 |
exit |
|
103 |
fi |
|
104 |
|
|
105 |
inf=$( echo $inf | tr -cd '[0-9]\n' ) |
|
106 |
|
|
107 |
|
|
108 |
# Chat script need these two variable |
|
109 |
export APN=$apn |
|
110 |
export DIALNUM="*99***1#" |
|
111 |
chat_script="/etc/ppp/gprs-chat" |
|
112 |
|
|
113 |
#====================== |
|
114 |
# The pppd options # |
|
115 |
#====================== |
|
116 |
|
|
117 |
options="$modem 115200" |
|
118 |
|
|
119 |
if [ -n "$uid" -a -n "pwd" ]; then |
|
120 |
options=$options" name $uid" |
|
121 |
options=$options" password $pwd" |
|
122 |
fi |
|
123 |
|
|
124 |
if [ -n "$inf" ] ; then |
|
125 |
options=$options" unit $inf" |
|
126 |
fi |
|
127 |
|
|
128 |
if [ "$vrfy" == "chap" ] ; then |
|
129 |
options=$options" require-chap" |
|
130 |
else |
|
131 |
options=$options" require-pap" |
|
132 |
fi |
|
133 |
|
|
134 |
# Restart after idle X second |
|
135 |
options=$options" idle 86400" |
|
136 |
|
|
137 |
options=$options" refuse-mschap refuse-mschap-v2 refuse-eap" |
|
138 |
|
|
139 |
options=$options" nodefaultroute updetach" |
|
140 |
options=$options" debug" |
|
141 |
|
|
142 |
options=$options" lcp-echo-failure 3 lcp-echo-interval 5" |
|
143 |
options=$options" ipcp-accept-local ipcp-accept-remote ipcp-restart 50" |
|
144 |
|
|
145 |
options=$options" modem crtscts" |
|
146 |
|
|
147 |
|
|
148 |
if [ -n "$ipaddr" ] ; then |
|
149 |
options=$options" $ipaddr" |
|
150 |
fi |
|
151 |
|
|
152 |
# Let the phone figure out all the IP addresses |
|
153 |
options=$options" noipdefault" |
|
154 |
|
|
155 |
options=$options" noauth" |
|
156 |
|
|
157 |
# No ppp compression |
|
158 |
options=$options" novj noccp novjccomp" |
|
159 |
|
|
160 |
# For sanity, keep a lock on the serial line |
|
161 |
options=$options" lock" |
|
162 |
|
|
163 |
#================================= |
|
164 |
# PPP dial up command start up # |
|
165 |
#================================= |
|
166 |
set -x |
|
167 |
|
|
168 |
#chat option should can be: -v -E -V -f |
|
169 |
pppd $options connect "/usr/sbin/chat -v -E -f $chat_script" |
|
170 |
|
|
171 |
if [ -d /sys/class/net/ppp$inf ] ; then |
|
172 |
ip route add default dev ppp$inf metric 10 |
|
173 |
#ip route add default dev ppp$inf |
|
174 |
/apps/tools/gatewayD > /dev/null 2>&1 |
|
175 |
fi |