]>
Commit | Line | Data |
---|---|---|
95416c1e MT |
1 | #!/bin/bash |
2 | ############################################################################### | |
3 | # # | |
4 | # IPFire.org - A linux based firewall # | |
5 | # Copyright (C) 2011 Michael Tremer & Christian Schmidt # | |
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 | . /usr/lib/network/functions | |
23 | ||
24 | # Setup logging. | |
25 | LOG_FACILITY="network-hotplug-serial" | |
26 | ||
27 | # Associated hooks. | |
28 | ASSOCIATED_HOOKS="modem" | |
29 | ||
e9df08ad MT |
30 | # Read network settings |
31 | network_settings_read | |
95416c1e MT |
32 | |
33 | log DEBUG "Called with ACTION='${ACTION}', DEVNAME='${DEVNAME}'." | |
34 | ||
35 | # If DEVNAME is not set, we cannot handle anything here and will | |
36 | # exit silently. | |
37 | isset DEVNAME || exit ${EXIT_OK} | |
38 | ||
39 | # Check if the udev environment variables are properly set. | |
40 | assert isset ACTION | |
41 | ||
42 | case "${ACTION}" in | |
43 | add|register) | |
44 | # Check if the device node already exists. | |
45 | if ! serial_exists ${DEVNAME}; then | |
46 | log DEBUG "Device node ${DEVNAME} does not exist" | |
47 | exit ${EXIT_ERROR} | |
48 | fi | |
49 | ||
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 | |
57 | # Find USB device. | |
58 | usb_device="$(usb_device_find_by_tty "${DEVNAME}")" | |
59 | ||
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}" | |
63 | exit ${EXIT_OK} | |
64 | fi | |
65 | fi | |
66 | ||
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" | |
70 | exit ${EXIT_OK} | |
71 | fi | |
72 | ||
73 | # When we get here, the modem is alive and responds to | |
74 | # AT commands. | |
75 | log DEBUG "${DEVNAME} looks like a modem" | |
76 | ||
77 | # Initialize the modem here. Resets all established connections | |
78 | # and so on. | |
3255c894 | 79 | modem_initialize "${DEVNAME}" --sleep=3 |
95416c1e MT |
80 | |
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." | |
84 | exit ${EXIT_OK} | |
85 | fi | |
86 | ||
87 | # Try to find the zone configuration by the IMSI of the | |
88 | # SIM card. | |
89 | sim_imsi="$(modem_get_sim_imsi "${DEVNAME}")" | |
90 | isset sim_imsi || exit ${EXIT_OK} | |
91 | ||
92 | for zone in $(zones_get_all); do | |
0eb236f4 MT |
93 | # Skip zones that are not enabled for auto-start. |
94 | if ! zone_is_enabled "${zone}"; then | |
95 | continue | |
96 | fi | |
95416c1e MT |
97 | |
98 | # Skip unsupported hook types. | |
99 | hook="$(zone_get_hook "${zone}")" | |
100 | list_match "${hook}" ${ASSOCIATED_HOOKS} || continue | |
101 | ||
102 | # Read IMSI from zone configuration. | |
e9df08ad | 103 | zone_imsi="$(zone_settings_get "${zone}" IMSI)" |
95416c1e MT |
104 | |
105 | # If IMSIs match, we start that zone. | |
106 | if [ "${zone_imsi}" = "${sim_imsi}" ]; then | |
107 | # Start the matching zone. | |
108 | zone_up "${zone}" | |
109 | break | |
110 | fi | |
111 | done | |
112 | ||
113 | exit ${EXIT_OK} | |
114 | ;; | |
115 | ||
116 | remove|unregister) | |
117 | # After the interface has been removed/unplugged, | |
118 | # there are often daemons (like pppd) which need | |
119 | # to be stopped. | |
120 | ;; | |
121 | esac | |
122 | ||
123 | exit ${EXIT_OK} |