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}"
31 HOOK_SETTINGS
="${HOOK_SETTINGS} APN"
33 # Sets the authentication algortihm that must be used.
35 HOOK_SETTINGS
="${HOOK_SETTINGS} AUTH"
39 HOOK_SETTINGS
="${HOOK_SETTINGS} BAUDRATE"
41 # The device name of the serial device.
42 # XXX how can we make sure that this does not change all the time?
44 HOOK_SETTINGS
="${HOOK_SETTINGS} DEVICE"
47 # Send AT commands to this device, when the primary device is
50 HOOK_SETTINGS
="${HOOK_SETTINGS} MONITOR_DEVICE"
52 # Maximum transmission unit.
54 HOOK_SETTINGS
="${HOOK_SETTINGS} MTU"
59 HOOK_SETTINGS
="${HOOK_SETTINGS} USERNAME PASSWORD"
63 HOOK_SETTINGS
="${HOOK_SETTINGS} PIN"
67 HOOK_SETTINGS
="${HOOK_SETTINGS} PHONE_NUMBER"
69 function hook_check
() {
71 assert isset PHONE_NUMBER
73 # Make sure the PIN code is an integer, when set.
76 assert
[ ${#PIN} -ge 4 ]
77 assert
[ ${#PIN} -le 8 ]
80 assert isoneof BAUDRATE
${SERIAL_BAUDRATES}
82 isset AUTH
&& assert isoneof AUTH
${MODEM_ALLOWED_AUTH_METHODS}
85 function hook_parse_cmdline
() {
88 while [ $# -gt 0 ]; do
91 APN
=$
(cli_get_val
${1})
94 AUTH
=$
(cli_get_val
${1})
97 BAUDRATE
=$
(cli_get_val
${1})
98 assert isoneif
"${BAUDRATE}" ${SERIAL_BAUDRATES}
101 DEVICE
=$
(cli_get_val
${1})
104 MONITOR_DEVICE
=$
(cli_get_val
${1})
107 MTU
=$
(cli_get_val
${1})
108 assert isinteger
${MTU}
111 PASSWORD
=$
(cli_get_val
${1})
114 PHONE_NUMBER
=$
(cli_get_val
${1})
117 PIN
=$
(cli_get_val
${1})
120 USERNAME
=$
(cli_get_val
${1})
123 echo "Unknown argument: ${1}" >&2
135 # Load configuration file.
136 zone_config_read
${zone}
138 # If we have got a PIN, we try to unlock the device first.
140 modem_sim_status
${DEVICE} &>/dev
/null
141 local sim_status_code
=$?
143 case "${sim_status_code}" in
145 # Everything's fine. The SIM card is
149 # Try to unlock the device.
150 if ! modem_sim_unlock
${DEVICE} ${PIN}; then
151 # Reset the PIN setting.
153 config_write $
(zone_dir
${zone})/settings
${HOOK_SETTINGS}
155 error
"Could not unlock the SIM card. Removing PIN from settings."
160 error
"SIM card is PUK locked. Please unlock manually."
165 # For mobile devices, check if a PIN is required although none is set.
166 elif modem_is_mobile
${DEVICE} && modem_sim_locked
${DEVICE}; then
167 error
"The SIM card is locked. Please configure the PIN code."
171 # Start the PPP daemon.
177 function hook_down
() {
181 # Stop the PPP daemon.
187 function hook_status
() {
191 cli_device_headline
${zone}
193 zone_config_read
${zone}
195 cli_headline
2 "Configuration"
196 cli_print_fmt1
2 "Username" "${USERNAME}"
197 cli_print_fmt1
2 "Password" "<hidden>"
200 cli_headline
2 "Device settings"
201 cli_print_fmt1
2 "Device" "${DEVICE}"
202 if isset MONITOR_DEVICE
; then
203 cli_print_fmt1
2 "Monitor device" "${MONITOR_DEVICE}"
205 cli_print_fmt1
2 "Baudrate" "${BAUDRATE}"
206 cli_print_fmt1
2 "MTU/MRU" "${MTU}"
209 # Exit if zone is down
210 if ! zone_is_up
${zone}; then
215 cli_headline
2 "Carrier network"
217 # If the device and the monitor device are both locked,
218 # we cannot show any carrier information.
220 for dev
in ${DEVICE} ${MONITOR_DEVICE}; do
221 if ! serial_exists
${dev}; then
224 if serial_is_locked
${dev}; then
231 if isset device
; then
232 cli_print_fmt1
2 "Operator" \
233 "$(modem_get_network_operator ${device})"
234 cli_print_fmt1
2 "SIM IMSI" \
235 "$(modem_get_sim_imsi ${device})"
236 cli_print_fmt1
2 "Mode" \
237 "$(modem_get_network_mode ${device})"
238 cli_print_fmt1
2 "Signal strength" \
239 "$(modem_get_signal_quality ${device}) dBm"
240 local ber
=$
(modem_get_bit_error_rate
${device})
241 isset ber || ber
="unknown"
242 cli_print_fmt1
2 "Bit error rate" "${ber}"
244 cli_print
2 "Device is locked."
248 # XXX display time since connection started
250 cli_headline
2 "Point-to-Point-over-Ethernet protocol"
252 for proto
in ${IP_SUPPORTED_PROTOCOLS}; do
253 routing_db_exists
${zone} ${proto} ||
continue
258 headline
="Internet Protocol Version 6"
261 headline
="Internet Protocol Version 4"
264 headline
="Unkown protocol"
267 cli_headline
3 "${headline}"
269 cli_print_fmt1
3 "IP address" "$(routing_db_get ${zone} ${proto} local-ip-address)"
270 cli_print_fmt1
3 "Gateway" "$(routing_db_get ${zone} ${proto} remote-ip-address)"
271 cli_print_fmt1
3 "DNS servers" "$(routing_db_get ${zone} ${proto} dns)"
278 function hook_ppp_write_config
() {
285 # Read in the configuration files.
286 zone_config_read
${zone}
288 pppd_write_config
${file} \
289 --interface="${zone}" \
290 --username="${USERNAME}" \
291 --password="${PASSWORD}" \
296 --serial-device="${DEVICE}" \
297 --baudrate="${BAUDRATE}" \
298 --connect-command="/usr/lib/network/dialer ${zone}"