-
Notifications
You must be signed in to change notification settings - Fork 0
/
mobile_ppp
106 lines (93 loc) · 2.63 KB
/
mobile_ppp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
# Adapted by Benjamin Binier <poulpatine@gmail.com>
# Based on Thomas Bächler’s <thomas@archlinux.org> pppoe script
# and on Robbie Smith <zoqaeski@gmail.com> contribution
# Also see <https://wiki.archlinux.org/index.php/3G_and_GPRS_modems_with_pppd> for more information.
: ${PPPD:=pppd}
: ${InterfaceRoot=dev/}
quote_word() {
set -- "${@//\\/\\\\}"
printf '"%s"\n' "${@//\"/\\\"}"
}
mobile_ppp_up() {
local options_dir="$STATE_DIR/mobile_ppp-$Interface-$Profile"
network_ready
mkdir -p "$options_dir"
if [[ -z $ChatScript ]]; then
ChatScript="$options_dir/modem.chat"
cat >> "$ChatScript" << EOF
ECHO ON
ABORT 'BUSY'
ABORT 'NO CARRIER'
ABORT 'VOICE'
ABORT 'NO DIALTONE'
ABORT 'NO DIAL TONE'
ABORT 'NO ANSWER'
ABORT 'DELAYED'
ABORT '\nRINGING\r\n\r\nRINGING\r'
REPORT CONNECT
TIMEOUT 6
'' 'ATQ0'
'OK-AT-OK' 'ATZ'
TIMEOUT 3
'OK' 'AT+CFUN=1'
'OK' 'AT${Pin:++CPIN=$(quote_word "$Pin")}'
'' 'AT'
'OK' 'AT+CPIN?'
'+CPIN: READY' 'AT'
'OK' 'ATZ'
'OK' '${Init:-ATQ0 V1 E1 S0=0 &C1 &D2 +FCLASS=0}'
'OK' 'AT$(case $Mode in
3Gonly) printf "\^SYSCFG=14,2,3fffffff,0,1";;
3Gpref) printf "\^SYSCFG=2,2,3fffffff,0,1";;
GPRSonly) printf "\^SYSCFG=13,1,3fffffff,0,0";;
GPRSpref) printf "\^SYSCFG=2,1,3fffffff,0,0";;
SYSCFG=*) printf "\^$Mode";;
# If set to "None", this is a no-op
esac)'
${AccessPointName:+'OK-AT-OK' 'AT+CGDCONT=2,$(quote_word "IP"),$(quote_word "$AccessPointName")'}
'OK' 'ATDT${PhoneNumber:-*99#}'
TIMEOUT 30
CONNECT ''
EOF
fi
cat >> "$options_dir/options" << EOF
linkname $(quote_word "$Profile")
${PPPUnit:+unit $(quote_word "$PPPUnit")}
$(quote_word "$Interface")
921600
lock
crtscts
modem
passive
novj
holdoff 10
noauth
noipdefault
$(is_yes "${DefaultRoute:-yes}" || printf no)defaultroute
maxfail $(quote_word "${MaxFail:-5}")
$(is_yes "${UsePeerDNS:-yes}" && printf usepeerdns)
hide-password
${User:+user $(quote_word "$User")}
${Password:+password $(quote_word "$Password")}
connect $(quote_word "/usr/sbin/chat -v -t15 -f $(quote_word "$ChatScript")")
${OptionsFile:+file $(quote_word "$OptionsFile")}
EOF
if ! $PPPD file "$options_dir/options"; then
rm -r "$options_dir"
report_error "Could not establish a ppp connection for profile '$Profile'."
return 1
fi
}
mobile_ppp_down() {
local options_dir pidfile pid
options_dir="$STATE_DIR/mobile_ppp-$Interface-$Profile"
pidfile="/var/run/ppp-$Profile.pid"
if [[ -r $pidfile ]]; then
read pid < "$pidfile"
(( pid )) && kill "$pid"
# Allow pppd up to one second to clean up
timeout_wait 1 '[[ ! -f $pidfile ]]'
fi
rm -r "$options_dir"
}
# vim: ft=sh ts=4 et sw=4: