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"
71 HOOK_SETTINGS
="${HOOK_SETTINGS} IMSI"
73 hook_check_settings
() {
75 assert isset PHONE_NUMBER
77 # Make sure the PIN code is an integer, when set.
80 assert
[ ${#PIN} -ge 4 ]
81 assert
[ ${#PIN} -le 8 ]
84 assert isoneof BAUDRATE
${SERIAL_BAUDRATES}
87 assert isoneof AUTH
${MODEM_ALLOWED_AUTH_METHODS}
91 hook_parse_cmdline
() {
94 while [ $# -gt 0 ]; do
97 APN
=$
(cli_get_val
${1})
100 AUTH
=$
(cli_get_val
${1})
103 BAUDRATE
=$
(cli_get_val
${1})
104 assert isoneif
"${BAUDRATE}" ${SERIAL_BAUDRATES}
107 DEVICE
=$
(cli_get_val
${1})
110 IMSI
="$(cli_get_val "${1}")"
113 MONITOR_DEVICE
=$
(cli_get_val
${1})
116 MTU
=$
(cli_get_val
${1})
117 assert isinteger
${MTU}
120 PASSWORD
=$
(cli_get_val
${1})
123 PHONE_NUMBER
=$
(cli_get_val
${1})
126 PIN
=$
(cli_get_val
${1})
129 USERNAME
=$
(cli_get_val
${1})
132 echo "Unknown argument: ${1}" >&2
144 # Load configuration file.
145 zone_settings_read
"${zone}"
147 # If we have got a PIN, we try to unlock the device first.
149 if ! modem_sim_auto_unlock
"${DEVICE}" "${PIN}"; then
150 # Reset the PIN setting.
152 zone_settings_write
"${zone}"
153 error
"Could not unlock the SIM card. Removing PIN from settings."
156 # For mobile devices, check if a PIN is required although none is set.
157 elif modem_is_mobile
${DEVICE} && modem_sim_locked
${DEVICE}; then
158 error
"The SIM card is locked. Please configure the PIN code."
162 # Start the PPP daemon.
172 # Stop the PPP daemon.
182 cli_device_headline
${zone}
184 zone_settings_read
"${zone}"
186 cli_headline
2 "Configuration"
187 cli_print_fmt1
2 "Username" "${USERNAME}"
188 cli_print_fmt1
2 "Password" "<hidden>"
191 cli_headline
2 "Device settings"
192 cli_print_fmt1
2 "Device" "${DEVICE}"
193 if isset MONITOR_DEVICE
; then
194 cli_print_fmt1
2 "Monitor device" "${MONITOR_DEVICE}"
196 cli_print_fmt1
2 "Baudrate" "${BAUDRATE}"
197 cli_print_fmt1
2 "MTU/MRU" "${MTU}"
200 cli_headline
2 "Carrier network"
202 # If the device and the monitor device are both locked,
203 # we cannot show any carrier information.
205 for dev
in ${DEVICE} ${MONITOR_DEVICE}; do
206 if ! serial_exists
${dev}; then
210 if serial_is_locked
${dev}; then
217 if isset device
&& modem_is_mobile
"${device}"; then
218 cli_print_fmt1
2 "Network Registration" \
219 "$(modem_get_network_registration ${device})"
220 cli_print_fmt1
2 "Operator" \
221 "$(modem_get_network_operator ${device})"
222 cli_print_fmt1
2 "SIM IMSI" \
223 "$(modem_get_sim_imsi ${device})"
224 cli_print_fmt1
2 "Mode" \
225 "$(modem_get_network_mode ${device})"
226 cli_print_fmt1
2 "Signal strength" \
227 "$(modem_get_signal_quality ${device}) dBm"
228 local ber
=$
(modem_get_bit_error_rate
${device})
229 isset ber || ber
="unknown"
230 cli_print_fmt1
2 "Bit error rate" "${ber}"
232 cli_print
2 "Device is locked."
236 # Exit if zone is down
237 if ! zone_is_up
${zone}; then
242 # XXX display time since connection started
244 cli_headline
2 "Point-to-Point-over-Ethernet protocol"
246 for proto
in ${IP_SUPPORTED_PROTOCOLS}; do
247 db_exists
"${zone}/${proto}" ||
continue
252 headline
="Internet Protocol Version 6"
255 headline
="Internet Protocol Version 4"
258 headline
="Unkown protocol"
261 cli_headline
3 "${headline}"
263 cli_print_fmt1
3 "IP address" "$(db_get "${zone}/${proto}/local-ip-address
")"
264 cli_print_fmt1
3 "Gateway" "$(db_get "${zone}/${proto}/remote-ip-address
")"
265 cli_print_fmt1
3 "DNS servers" "$(db_get "${zone}/${proto}/domain-name-servers
")"
272 hook_ppp_write_config
() {
279 # Read in the configuration files.
280 zone_settings_read
"${zone}"
282 pppd_write_config
${file} \
283 --interface="${zone}" \
284 --username="${USERNAME}" \
285 --password="${PASSWORD}" \
290 --serial-device="${DEVICE}" \
291 --baudrate="${BAUDRATE}" \
292 --connect-command="/usr/lib/network/dialer ${zone}"