]> git.ipfire.org Git - people/stevee/network.git/blob - src/ppp/dialer
Rename all "config" to "settings"
[people/stevee/network.git] / src / 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 # Read network settings
30 network_settings_read
31
32 log DEBUG "dialer called with arguments: $@"
33
34 # The zone is an optional argument.
35 ZONE=${1}
36 assert isset ZONE
37
38 # If we have the zone information, we will
39 # load the zone configuration.
40 if zone_exists ${ZONE}; then
41 zone_settings_read "${ZONE}"
42 fi
43
44 # The default speaker settings is on.
45 at_speaker=${AT_SPEAKER_ON}
46
47 # The default dial method is tone dial.
48 at_dial=${AT_TONE_DIAL}
49
50 # Initalize the commandline
51 commandline=""
52
53 # If we are running in debug mode, we start chat with the
54 # verbose flag as well.
55 if enabled DEBUG; then
56 commandline="${commandline} -v"
57 fi
58
59 # Create a temporary chat script file.
60 file=$(mktemp)
61 commandline="${commandline} -f ${file}"
62
63 # Helper function to write beatiful lines to
64 # the chat scripts.
65 function println() {
66 printf "%-30s %s\n" "$@" >> ${file}
67 }
68
69 ### Write the connect script.
70
71 # Set the timeout value for the configuration commands to
72 # 3 seconds. This will be increased later.
73 println "TIMEOUT" 3
74
75 # Let's log everything until we are properly connected.
76 println "REPORT" "CONNECT"
77
78 # End the connection, when one of the following conditions
79 # happens:
80 for condition in "BUSY" "NO ANSWER" "NO CARRIER" "NO DIALTONE"; do
81 println "ABORT" "'${condition}'"
82 done
83
84 # Now, we get to the exciting stuff.
85 # Initalize the modem.
86 println "''" "${AT_INITIALIZE}"
87 println "''" "AT"
88 println "''" "${AT_INITIALIZE}"
89
90 # End all left over connections by hanging up.
91 println "OK" "${AT_HANGUP}"
92
93 # Apply the speaker setting.
94 println "OK" "${at_speaker}"
95
96 # Set the APN if any.
97 if isset APN; then
98 println "''" "'AT+CGDCONT=1,\"IP\",\"${APN}\"'"
99 fi
100
101 # Enter a 5 seconds break so the modem can setup itself
102 # to the settings we just transmitted to it.
103 for i in $(seq 0 5); do
104 println "''" "\\d"
105 done
106
107 # Reset the timeout value to 30 seconds.
108 println "TIMEOUT" 30
109
110 # Actually dial the number.
111 println "OK" "${at_dial}${PHONE_NUMBER}"
112
113 # Wait for the CONNECT string.
114 println "CONNECT" "\\c"
115
116 # If login credentials were set, we send them.
117 if isset USERNAME && isset PASSWORD; then
118 println "ogin:--ogin:" "${USERNAME}"
119 println "assword:" "${PASSWORD}"
120 fi
121
122 # Exec the chat command which will start talking to the modem.
123 log DEBUG "Exec'ing chat with command line: ${commandline}"
124 exec chat ${commandline}
125
126 error "Could not execute chat. Exiting."
127 exit ${EXIT_ERROR}