]>
Commit | Line | Data |
---|---|---|
d76f5107 MT |
1 | #!/bin/bash |
2 | ############################################################################### | |
3 | # # | |
4 | # IPFire.org - A linux based firewall # | |
5 | # Copyright (C) 2010 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 | ||
8ee92277 | 22 | . /usr/lib/network/header-port |
d76f5107 | 23 | |
31670741 | 24 | HOOK_SETTINGS="HOOK ADDRESS BROADCAST_SSID CHANNEL MODE PHY SSID" |
25e32463 | 25 | HOOK_SETTINGS="${HOOK_SETTINGS} ENCRYPTION KEY" |
d76f5107 MT |
26 | |
27 | ADDRESS=$(mac_generate) | |
28 | BROADCAST_SSID=on | |
29 | CHANNEL=1 | |
25e32463 MT |
30 | ENCRYPTION="" |
31 | KEY="" | |
d76f5107 MT |
32 | MODE="g" |
33 | SSID= | |
34 | ||
2181765d | 35 | function hook_check() { |
d76f5107 MT |
36 | assert isset ADDRESS |
37 | assert ismac ADDRESS | |
38 | assert isset BROADCAST_SSID | |
39 | assert isbool BROADCAST_SSID | |
40 | assert isset CHANNEL | |
d76f5107 | 41 | assert isset MODE |
93d614f0 | 42 | assert isoneof MODE a b g n |
d76f5107 MT |
43 | assert isset PHY |
44 | assert ismac PHY | |
45 | assert isset SSID | |
25e32463 MT |
46 | |
47 | if isset ENCRYPTION; then | |
48 | assert isoneof ENCRYPTION WPA WPA2 WPA/WPA2 | |
49 | ||
50 | assert isset KEY | |
51 | assert [ ${#KEY} -ge 8 ] | |
52 | assert [ ${#KEY} -le 63 ] | |
53 | fi | |
d76f5107 MT |
54 | } |
55 | ||
1ba6a2bb | 56 | function hook_new() { |
d76f5107 MT |
57 | while [ $# -gt 0 ]; do |
58 | case "${1}" in | |
59 | --broadcast-ssid=*) | |
60 | BROADCAST_SSID=$(cli_get_val ${1}) | |
61 | ;; | |
62 | --channel=*) | |
63 | CHANNEL=$(cli_get_val ${1}) | |
64 | ;; | |
25e32463 MT |
65 | --encryption=*) |
66 | ENCRYPTION=$(cli_get_val ${1}) | |
67 | ;; | |
68 | --key=*) | |
69 | KEY=$(cli_get_val ${1}) | |
70 | ;; | |
d76f5107 MT |
71 | --mac=*) |
72 | ADDRESS=$(cli_get_val ${1}) | |
73 | ;; | |
74 | --mode=*) | |
75 | MODE=$(cli_get_val ${1}) | |
76 | ;; | |
77 | --phy=*) | |
78 | PHY=$(cli_get_val ${1}) | |
79 | ;; | |
80 | --ssid=*) | |
81 | SSID=$(cli_get_val ${1}) | |
82 | ;; | |
83 | *) | |
84 | warning "Ignoring unknown argument '${1}'" | |
85 | ;; | |
86 | esac | |
87 | shift | |
88 | done | |
89 | ||
90 | # Save address of phy do identify it again | |
91 | PHY=$(phy_get ${PHY}) | |
92 | PHY=$(phy_get_address ${PHY}) | |
93 | ||
8ee92277 | 94 | local port=$(port_find_free ${PORT_PATTERN_ACCESSPOINT}) |
d76f5107 MT |
95 | assert isset port |
96 | ||
e9df08ad | 97 | port_settings_write "${port}" ${HOOK_SETTINGS} |
d76f5107 MT |
98 | |
99 | exit ${EXIT_OK} | |
100 | } | |
101 | ||
2181765d | 102 | function hook_edit() { |
d76f5107 MT |
103 | local port=${1} |
104 | shift | |
105 | ||
106 | assert isset port | |
107 | ||
e9df08ad | 108 | port_settings_read "${port}" ${HOOK_SETTINGS} |
d76f5107 MT |
109 | |
110 | while [ $# -gt 0 ]; do | |
111 | case "${1}" in | |
112 | --broadcast-ssid=*) | |
113 | BROADCAST_SSID=$(cli_get_val ${1}) | |
114 | ;; | |
115 | --channel=*) | |
116 | CHANNEL=$(cli_get_val ${1}) | |
117 | ;; | |
25e32463 MT |
118 | --encryption=*) |
119 | ENCRYPTION=$(cli_get_val ${1}) | |
120 | ;; | |
121 | --key=*) | |
122 | KEY=$(cli_get_val ${1}) | |
123 | ;; | |
d76f5107 MT |
124 | --ssid=*) |
125 | SSID=$(cli_get_val ${1}) | |
126 | ;; | |
127 | --mode=*) | |
128 | MODE=$(cli_get_val ${1}) | |
129 | ;; | |
130 | *) | |
131 | warning "Unknown argument '${1}'" | |
132 | ;; | |
133 | esac | |
134 | shift | |
135 | done | |
136 | ||
e9df08ad | 137 | port_settings_write "${port}" ${HOOK_SETTINGS} |
d76f5107 MT |
138 | |
139 | exit ${EXIT_OK} | |
140 | } | |
141 | ||
1ba6a2bb MT |
142 | function hook_create() { |
143 | local port="${1}" | |
d76f5107 MT |
144 | assert isset port |
145 | ||
1ba6a2bb MT |
146 | device_exists "${port}" && exit ${EXIT_OK} |
147 | ||
e9df08ad | 148 | port_settings_read "${port}" ${HOOK_SETTINGS} |
d76f5107 | 149 | |
49ec20d8 MT |
150 | # Check if the PHY is present. |
151 | local phy=$(phy_get ${PHY}) | |
152 | if ! isset phy; then | |
153 | log DEBUG "phy '${PHY}' is not present" | |
154 | exit ${EXIT_ERROR} | |
155 | fi | |
156 | ||
1ba6a2bb MT |
157 | # Create the wireless device |
158 | wireless_create "${port}" \ | |
159 | --phy="${phy}" \ | |
160 | --type="ap" \ | |
161 | --address="${ADDRESS}" | |
d76f5107 MT |
162 | |
163 | exit ${EXIT_OK} | |
164 | } | |
165 | ||
1ba6a2bb MT |
166 | function hook_remove() { |
167 | local port="${1}" | |
d76f5107 MT |
168 | assert isset port |
169 | ||
b8026986 MT |
170 | # Remove the device if present |
171 | if device_exists "${port}"; then | |
172 | wireless_remove "${port}" | |
47859d95 | 173 | fi |
d76f5107 MT |
174 | |
175 | exit ${EXIT_OK} | |
176 | } | |
177 | ||
1ba6a2bb MT |
178 | function hook_up() { |
179 | local port="${1}" | |
180 | assert isset port | |
181 | ||
182 | # The port must already exist before | |
183 | # hostapd is started. Otherwise it will | |
184 | # fail horribly over and over again. | |
185 | assert device_exists "${port}" | |
186 | ||
187 | hostapd_start "${port}" | |
188 | } | |
189 | ||
190 | function hook_down() { | |
191 | local port="${1}" | |
192 | assert isset port | |
193 | ||
194 | hostapd_stop "${port}" | |
195 | } | |
196 | ||
2181765d | 197 | function hook_hotplug() { |
b8026986 | 198 | local port="${1}" |
47859d95 | 199 | assert isset port |
49ec20d8 | 200 | |
b8026986 MT |
201 | case "$(hotplug_action)" in |
202 | add) | |
1ba6a2bb MT |
203 | # Create the port when the phy is plugged in |
204 | if hotplug_event_port_uses_phy "${port}"; then | |
205 | hook_create "${port}" | |
b8026986 MT |
206 | fi |
207 | ;; | |
208 | ||
209 | remove) | |
210 | # Stop hostapd | |
211 | if hotplug_event_port_is_interface "${port}"; then | |
212 | hostapd_stop "${port}" | |
b8026986 | 213 | |
1ba6a2bb MT |
214 | exit ${EXIT_OK} |
215 | fi | |
b8026986 MT |
216 | ;; |
217 | esac | |
47859d95 | 218 | |
1ba6a2bb | 219 | exit ${EXIT_NOT_HANDLED} |
47859d95 | 220 | } |