2 ###############################################################################
4 # IPFire.org - A linux based firewall #
5 # Copyright (C) 2010 Michael Tremer & Christian Schmidt #
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. #
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. #
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/>. #
20 ###############################################################################
22 .
/lib
/network
/header-zone
24 # Modems support all authentication methods, that pppd does support.
25 MODEM_ALLOWED_AUTH_METHODS
="${PPP_ALLOWED_AUTH_METHODS}"
41 DEFAULT_BAUDRATE
=921600
43 hook_check_settings
() {
45 assert isset PHONE_NUMBER
47 # Make sure the PIN code is an integer, when set.
50 assert
[ ${#PIN} -ge 4 ]
51 assert
[ ${#PIN} -le 8 ]
54 assert isoneof BAUDRATE
${SERIAL_BAUDRATES}
57 assert isoneof AUTH
${MODEM_ALLOWED_AUTH_METHODS}
61 hook_parse_cmdline
() {
64 while [ $# -gt 0 ]; do
67 APN
=$
(cli_get_val
"${1}")
70 AUTH
=$
(cli_get_val
"${1}")
73 BAUDRATE
=$
(cli_get_val
"${1}")
74 assert isoneif
"${BAUDRATE}" ${SERIAL_BAUDRATES}
77 DEVICE
=$
(cli_get_val
"${1}")
80 IMSI
="$(cli_get_val "${1}")"
83 MONITOR_DEVICE
=$
(cli_get_val
"${1}")
86 MTU
=$
(cli_get_val
"${1}")
87 assert isinteger
${MTU}
90 PASSWORD
=$
(cli_get_val
"${1}")
93 PHONE_NUMBER
=$
(cli_get_val
"${1}")
96 PIN
=$
(cli_get_val
"${1}")
99 USERNAME
=$
(cli_get_val
"${1}")
102 echo "Unknown argument: ${1}" >&2
114 # Load configuration file.
115 zone_settings_read
"${zone}"
117 # If we have got a PIN, we try to unlock the device first.
119 if ! modem_sim_auto_unlock
"${DEVICE}" "${PIN}"; then
120 # Reset the PIN setting.
122 zone_settings_write
"${zone}"
123 error
"Could not unlock the SIM card. Removing PIN from settings."
126 # For mobile devices, check if a PIN is required although none is set.
127 elif modem_is_mobile
${DEVICE} && modem_sim_locked
${DEVICE}; then
128 error
"The SIM card is locked. Please configure the PIN code."
132 # Start the PPP daemon.
142 # Stop the PPP daemon.
152 cli_device_headline
${zone}
154 zone_settings_read
"${zone}"
156 cli_headline
2 "Configuration"
157 cli_print_fmt1
2 "Username" "${USERNAME}"
158 cli_print_fmt1
2 "Password" "<hidden>"
161 cli_headline
2 "Device settings"
162 cli_print_fmt1
2 "Device" "${DEVICE}"
163 if isset MONITOR_DEVICE
; then
164 cli_print_fmt1
2 "Monitor device" "${MONITOR_DEVICE}"
166 cli_print_fmt1
2 "Baudrate" "${BAUDRATE}"
167 cli_print_fmt1
2 "MTU/MRU" "${MTU}"
170 # If the device and the monitor device are both locked,
171 # we cannot show any carrier information.
173 for dev
in ${DEVICE} ${MONITOR_DEVICE}; do
174 if ! serial_exists
${dev}; then
178 if serial_is_locked
${dev}; then
185 if isset device
&& modem_is_mobile
"${device}"; then
186 modem_mobile_network_status
"${device}" 2
188 cli_print
2 "Device is locked."
192 # Exit if zone is down
193 if ! zone_is_up
${zone}; then
198 # XXX display time since connection started
200 cli_headline
2 "Point-to-Point-over-Ethernet protocol"
202 for proto
in ${IP_SUPPORTED_PROTOCOLS}; do
203 db_exists
"${zone}/${proto}" ||
continue
208 headline
="Internet Protocol Version 6"
211 headline
="Internet Protocol Version 4"
214 headline
="Unkown protocol"
217 cli_headline
3 "${headline}"
219 cli_print_fmt1
3 "IP address" "$(db_get "${zone}/${proto}/local-ip-address
")"
220 cli_print_fmt1
3 "Gateway" "$(db_get "${zone}/${proto}/remote-ip-address
")"
221 cli_print_fmt1
3 "DNS servers" "$(db_get "${zone}/${proto}/domain-name-servers
")"
228 hook_ppp_write_config
() {
235 # Read in the configuration files.
236 zone_settings_read
"${zone}"
238 pppd_write_config
${file} \
239 --interface="${zone}" \
240 --username="${USERNAME}" \
241 --password="${PASSWORD}" \
246 --serial-device="${DEVICE}" \
247 --baudrate="${BAUDRATE}" \
248 --connect-command="/usr/lib/network/dialer ${zone}"