2 ###############################################################################
4 # IPFire.org - A linux based firewall #
5 # Copyright (C) 2011 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 .
/usr
/lib
/network
/functions
25 LOG_FACILITY
="network-hotplug-serial"
28 ASSOCIATED_HOOKS
="modem"
30 # Read network settings
33 log DEBUG
"Called with ACTION='${ACTION}', DEVNAME='${DEVNAME}'."
35 # If DEVNAME is not set, we cannot handle anything here and will
37 isset DEVNAME ||
exit ${EXIT_OK}
39 # Check if the udev environment variables are properly set.
44 # Check if the device node already exists.
45 if ! serial_exists
${DEVNAME}; then
46 log DEBUG
"Device node ${DEVNAME} does not exist"
50 # USB modems often register multiple serial interfaces.
51 # Some of them allow to send AT commands, some don't know.
52 # However, there is only one interface that can actually be used
53 # to connect to somewhere. This interface always runs in
54 # interrupt mode. Exit for all interfaces, not in this mode.
55 bus_type
="$(serial_get_bus_type "${DEVNAME}")"
56 if [ "${bus_type}" = "usb" ]; then
58 usb_device
="$(usb_device_find_by_tty "${DEVNAME}")"
60 # Find an interface in interrupt mode.
61 if ! usb_device_has_interface_type_interrupt
"${usb_device}"; then
62 log DEBUG
"USB device has no interface in interrupt mode: ${DEVNAME}"
67 # Check if the device is actually a modem.
68 if ! serial_is_modem
${DEVNAME}; then
69 log DEBUG
"${DEVNAME} does not look like a modem"
73 # When we get here, the modem is alive and responds to
75 log DEBUG
"${DEVNAME} looks like a modem"
77 # Initialize the modem here. Resets all established connections
79 modem_initialize
"${DEVNAME}" --sleep=3
81 # Unlock the SIM card if it has one.
82 if modem_sim_locked
"${DEVNAME}"; then
83 log ERROR
"SIM card is locked. Needs unlocking."
87 # Try to find the zone configuration by the IMSI of the
89 sim_imsi
="$(modem_get_sim_imsi "${DEVNAME}")"
90 isset sim_imsi ||
exit ${EXIT_OK}
92 for zone
in $
(zones_get_all
); do
93 # XXX Check if the zone is enabled.
95 # Skip unsupported hook types.
96 hook
="$(zone_get_hook "${zone}")"
97 list_match
"${hook}" ${ASSOCIATED_HOOKS} ||
continue
99 # Read IMSI from zone configuration.
100 zone_imsi
="$(zone_settings_get "${zone}" IMSI)"
102 # If IMSIs match, we start that zone.
103 if [ "${zone_imsi}" = "${sim_imsi}" ]; then
104 # Start the matching zone.
114 # After the interface has been removed/unplugged,
115 # there are often daemons (like pppd) which need