]> git.ipfire.org Git - people/stevee/network.git/blob - ppp/dialer
ccec5a272833ad62611ed0740ae590de04f56f55
[people/stevee/network.git] / ppp / dialer
1 #!/bin/bash
2 ###############################################################################
3 # #
4 # IPFire.org - A linux based firewall #
5 # Copyright (C) 2012 IPFire Network Development Team #
6 # #
7 # This program is free software: you can redistribute it and/or modify #
8 # it under the terms of the GNU General Public License as published by #
9 # the Free Software Foundation, either version 3 of the License, or #
10 # (at your option) any later version. #
11 # #
12 # This program is distributed in the hope that it will be useful, #
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of #
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the #
15 # GNU General Public License for more details. #
16 # #
17 # You should have received a copy of the GNU General Public License #
18 # along with this program. If not, see <http://www.gnu.org/licenses/>. #
19 # #
20 ###############################################################################
21
22 LOG_FACILITY=$(basename ${0})
23
24 # Do not print any log messages because these may be sent to the modem.
25 LOG_DISABLE_STDOUT="true"
26
27 . /usr/lib/network/functions
28
29 log DEBUG "dialer called with arguments: $@"
30
31 # The zone is an optional argument.
32 ZONE=${1}
33 assert isset ZONE
34
35 # If we have the zone information, we will
36 # load the zone configuration.
37 if zone_exists ${ZONE}; then
38 zone_config_read ${ZONE}
39 fi
40
41 # The default speaker settings is on.
42 at_speaker=${AT_SPEAKER_ON}
43
44 # The default dial method is tone dial.
45 at_dial=${AT_TONE_DIAL}
46
47 # Initalize the commandline
48 commandline=""
49
50 # If we are running in debug mode, we start chat with the
51 # verbose flag as well.
52 if enabled DEBUG; then
53 commandline="${commandline} -v"
54 fi
55
56 # Create a temporary chat script file.
57 file=$(mktemp)
58 commandline="${commandline} -f ${file}"
59
60 # Helper function to write beatiful lines to
61 # the chat scripts.
62 function println() {
63 printf "%-30s %s\n" "$@" >> ${file}
64 }
65
66 ### Write the connect script.
67
68 # Set the timeout value for the configuration commands to
69 # 3 seconds. This will be increased later.
70 println "TIMEOUT" 3
71
72 # Let's log everything until we are properly connected.
73 println "REPORT" "CONNECT"
74
75 # End the connection, when one of the following conditions
76 # happens:
77 for condition in "BUSY" "NO ANSWER" "NO CARRIER" "NO DIALTONE"; do
78 println "ABORT" "'${condition}'"
79 done
80
81 # Now, we get to the exciting stuff.
82 # Initalize the modem.
83 println "''" "${AT_INITIALIZE}"
84 println "''" "AT"
85 println "''" "${AT_INITIALIZE}"
86
87 # End all left over connections by hanging up.
88 println "OK" "${AT_HANGUP}"
89
90 # Apply the speaker setting.
91 println "OK" "${at_speaker}"
92
93 # Set the APN if any.
94 if isset APN; then
95 println "''" "'AT+CGDCONT=1,\"IP\",\"${APN}\"'"
96 fi
97
98 # Enter a 5 seconds break so the modem can setup itself
99 # to the settings we just transmitted to it.
100 for i in $(seq 0 5); do
101 println "''" "\\d"
102 done
103
104 # Reset the timeout value to 30 seconds.
105 println "TIMEOUT" 30
106
107 # Actually dial the number.
108 println "OK" "${at_dial}${PHONE_NUMBER}"
109
110 # Wait for the CONNECT string.
111 println "CONNECT" "\\c"
112
113 # If login credentials were set, we send them.
114 if isset USERNAME && isset PASSWORD; then
115 println "ogin:--ogin:" "${USERNAME}"
116 println "assword:" "${PASSWORD}"
117 fi
118
119 # Exec the chat command which will start talking to the modem.
120 log DEBUG "Exec'ing chat with command line: ${commandline}"
121 exec chat ${commandline}
122
123 error "Could not execute chat. Exiting."
124 exit ${EXIT_ERROR}