]>
Commit | Line | Data |
---|---|---|
e6993835 MT |
1 | #!/bin/bash |
2 | ############################################################################### | |
3 | # # | |
4 | # IPFire.org - A linux based firewall # | |
5 | # Copyright (C) 2013 Michael Tremer # | |
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/header-port | |
23 | ||
b8026986 | 24 | HOOK_SETTINGS="HOOK ADDRESS BSSID SSID CHANNEL MTU PHY" |
e6993835 MT |
25 | |
26 | ADDRESS=$(mac_generate) | |
b8026986 | 27 | BSSID= |
e6993835 | 28 | CHANNEL=1 |
b8026986 | 29 | MTU=1500 |
1509acb7 | 30 | PHY= |
e6993835 MT |
31 | SSID= |
32 | ||
1c6a4e30 | 33 | hook_check_settings() { |
e6993835 MT |
34 | assert isset ADDRESS |
35 | assert ismac ADDRESS | |
36 | assert isset CHANNEL | |
b8026986 MT |
37 | assert isset BSSID |
38 | assert ismac BSSID | |
e6993835 MT |
39 | assert isset PHY |
40 | assert ismac PHY | |
41 | assert isset SSID | |
42 | } | |
43 | ||
1c6a4e30 | 44 | hook_new() { |
e6993835 MT |
45 | while [ $# -gt 0 ]; do |
46 | case "${1}" in | |
47 | --address=*) | |
2212045f | 48 | ADDRESS=$(cli_get_val "${1}") |
e6993835 | 49 | ;; |
b8026986 | 50 | --bssid=*) |
2212045f | 51 | BSSID=$(cli_get_val "${1}") |
b8026986 | 52 | ;; |
e6993835 | 53 | --channel=*) |
2212045f | 54 | CHANNEL=$(cli_get_val "${1}") |
e6993835 | 55 | ;; |
b8026986 MT |
56 | --mtu=*) |
57 | MTU="$(cli_get_val "${1}")" | |
58 | ;; | |
e6993835 | 59 | --phy=*) |
2212045f | 60 | PHY=$(cli_get_val "${1}") |
e6993835 MT |
61 | ;; |
62 | --ssid=*) | |
2212045f | 63 | SSID=$(cli_get_val "${1}") |
e6993835 | 64 | ;; |
e6993835 MT |
65 | *) |
66 | warning "Ignoring unknown argument '${1}'" | |
67 | ;; | |
68 | esac | |
69 | shift | |
70 | done | |
71 | ||
72 | # Save address of phy do identify it again | |
73 | PHY=$(phy_get ${PHY}) | |
74 | PHY=$(phy_get_address ${PHY}) | |
75 | ||
b8026986 | 76 | local port=$(port_find_free ${PORT_PATTERN_WIRELESS_ADHOC}) |
e6993835 MT |
77 | assert isset port |
78 | ||
e9df08ad | 79 | port_settings_write "${port}" ${HOOK_SETTINGS} |
e6993835 MT |
80 | |
81 | exit ${EXIT_OK} | |
82 | } | |
83 | ||
1c6a4e30 | 84 | hook_edit() { |
e6993835 MT |
85 | local port=${1} |
86 | assert isset port | |
87 | shift | |
88 | ||
e9df08ad | 89 | port_settings_read "${port}" ${HOOK_SETTINGS} |
e6993835 MT |
90 | |
91 | while [ $# -gt 0 ]; do | |
92 | case "${1}" in | |
b8026986 | 93 | --bssid=*) |
2212045f | 94 | BSSID=$(cli_get_val "${1}") |
b8026986 | 95 | ;; |
e6993835 | 96 | --channel=*) |
2212045f | 97 | CHANNEL=$(cli_get_val "${1}") |
e6993835 | 98 | ;; |
b8026986 MT |
99 | --mtu=*) |
100 | MTU="$(cli_get_val "${1}")" | |
e6993835 MT |
101 | ;; |
102 | --ssid=*) | |
2212045f | 103 | SSID=$(cli_get_val "${1}") |
e6993835 MT |
104 | ;; |
105 | *) | |
106 | warning "Unknown argument '${1}'" | |
107 | ;; | |
108 | esac | |
109 | shift | |
110 | done | |
111 | ||
e9df08ad | 112 | port_settings_write "${port}" ${HOOK_SETTINGS} |
e6993835 MT |
113 | |
114 | exit ${EXIT_OK} | |
115 | } | |
116 | ||
1c6a4e30 | 117 | hook_create() { |
1ba6a2bb MT |
118 | local port="${1}" |
119 | assert isset port | |
120 | ||
121 | device_exists "${port}" && exit ${EXIT_OK} | |
122 | ||
123 | port_settings_read "${port}" ${HOOK_SETTINGS} | |
124 | ||
125 | # Check if the PHY is present. | |
126 | local phy="$(phy_get "${PHY}")" | |
127 | if ! isset phy; then | |
128 | log DEBUG "phy '${PHY}' is not present" | |
129 | exit ${EXIT_ERROR} | |
130 | fi | |
131 | ||
132 | # Create the wireless device, if it does not exist, yet. | |
133 | wireless_create "${port}" \ | |
134 | --address="${ADDRESS}" \ | |
135 | --phy="${phy}" \ | |
136 | --type="ibss" | |
137 | ||
138 | exit ${EXIT_OK} | |
139 | } | |
140 | ||
1c6a4e30 | 141 | hook_remove() { |
1ba6a2bb MT |
142 | local port="${1}" |
143 | assert isset port | |
144 | ||
145 | if device_exists "${port}"; then | |
146 | wireless_remove "${port}" | |
147 | fi | |
148 | ||
149 | exit ${EXIT_OK} | |
150 | } | |
151 | ||
1c6a4e30 | 152 | hook_up() { |
e6993835 MT |
153 | local port=${1} |
154 | assert isset port | |
155 | ||
e9df08ad | 156 | port_settings_read "${port}" ${HOOK_SETTINGS} |
e6993835 MT |
157 | |
158 | # Check if the PHY is present. | |
159 | local phy=$(phy_get ${PHY}) | |
160 | if ! isset phy; then | |
161 | log DEBUG "phy '${PHY}' is not present" | |
162 | exit ${EXIT_ERROR} | |
163 | fi | |
164 | ||
165 | # Create the wireless device, if it does not exist, yet. | |
166 | if ! device_exists ${port}; then | |
b8026986 MT |
167 | wireless_create ${port} --address="${ADDRESS}" \ |
168 | --phy="${phy}" --type="ibss" | |
e6993835 MT |
169 | fi |
170 | ||
171 | exit ${EXIT_OK} | |
172 | } | |
173 | ||
1c6a4e30 | 174 | hook_down() { |
b8026986 | 175 | local port="${1}" |
e6993835 MT |
176 | assert isset port |
177 | ||
b8026986 MT |
178 | # Do nothing if the device already went away |
179 | if ! device_exists "${port}"; then | |
180 | exit ${EXIT_OK} | |
181 | fi | |
e6993835 MT |
182 | |
183 | # Leave the ad-hoc network. | |
184 | wireless_ibss_leave "${port}" | |
185 | ||
e6993835 MT |
186 | exit ${EXIT_OK} |
187 | } | |
188 | ||
1c6a4e30 | 189 | hook_hotplug() { |
b8026986 | 190 | local port="${1}" |
e6993835 MT |
191 | assert isset port |
192 | ||
e9df08ad | 193 | port_settings_read "${port}" ${HOOK_SETTINGS} |
e6993835 | 194 | |
b8026986 MT |
195 | case "$(hotplug_action)" in |
196 | add) | |
197 | # Join the adhoc network after the device has | |
198 | # been created... | |
199 | if hotplug_event_port_is_interface "${port}"; then | |
200 | # Set the MTU. | |
201 | if isinteger MTU; then | |
202 | device_set_mtu "${port}" "${MTU}" | |
203 | fi | |
204 | ||
205 | wireless_ibss_join "${port}" --channel="${CHANNEL}" \ | |
206 | --bssid="${BSSID}" --essid="${SSID}" | |
207 | ||
208 | # Bring up the port when the phy is plugged in | |
209 | elif hotplug_event_port_uses_phy "${port}"; then | |
210 | hook_up "${port}" | |
211 | fi | |
212 | ;; | |
213 | ||
214 | *) | |
215 | exit ${EXIT_NOT_HANDLED} | |
216 | ;; | |
217 | esac | |
e6993835 | 218 | |
b8026986 | 219 | exit ${EXIT_OK} |
e6993835 MT |
220 | } |
221 | ||
1c6a4e30 | 222 | hook_find_parent() { |
e6993835 MT |
223 | local port=${1} |
224 | assert isset port | |
225 | ||
226 | local p child hook | |
227 | for p in $(ports_get); do | |
228 | hook=$(port_get_hook "${p}") | |
229 | ||
230 | if [ "${hook}" = "batman-adv" ]; then | |
231 | for child in $(port_get_children "${p}"); do | |
e6993835 MT |
232 | [ "${child}" = "${port}" ] || continue |
233 | ||
234 | print "${p}" | |
235 | return ${EXIT_OK} | |
236 | done | |
237 | fi | |
238 | done | |
239 | ||
240 | return ${EXIT_ERROR} | |
241 | } |