2 ###############################################################################
4 # IPFire.org - A linux based firewall #
5 # Copyright (C) 2013 Michael Tremer #
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
/header-port
24 HOOK_SETTINGS
="HOOK ADDRESS BSSID SSID CHANNEL MTU PHY"
26 ADDRESS
=$
(mac_generate
)
33 function hook_check
() {
44 function hook_create
() {
45 while [ $# -gt 0 ]; do
48 ADDRESS
=$
(cli_get_val
${1})
51 BSSID
=$
(cli_get_val
${1})
54 CHANNEL
=$
(cli_get_val
${1})
57 MTU
="$(cli_get_val "${1}")"
60 PHY
=$
(cli_get_val
${1})
63 SSID
=$
(cli_get_val
${1})
66 warning
"Ignoring unknown argument '${1}'"
72 # Save address of phy do identify it again
74 PHY
=$
(phy_get_address
${PHY})
76 local port
=$
(port_find_free
${PORT_PATTERN_WIRELESS_ADHOC})
79 port_settings_write
"${port}" ${HOOK_SETTINGS}
84 function hook_edit
() {
89 port_settings_read
"${port}" ${HOOK_SETTINGS}
91 while [ $# -gt 0 ]; do
94 BSSID
=$
(cli_get_val
${1})
97 CHANNEL
=$
(cli_get_val
${1})
100 MTU
="$(cli_get_val "${1}")"
103 SSID
=$
(cli_get_val
${1})
106 warning
"Unknown argument '${1}'"
112 port_settings_write
"${port}" ${HOOK_SETTINGS}
117 function hook_create
() {
121 device_exists
"${port}" && exit ${EXIT_OK}
123 port_settings_read
"${port}" ${HOOK_SETTINGS}
125 # Check if the PHY is present.
126 local phy
="$(phy_get "${PHY}")"
128 log DEBUG
"phy '${PHY}' is not present"
132 # Create the wireless device, if it does not exist, yet.
133 wireless_create
"${port}" \
134 --address="${ADDRESS}" \
141 function hook_remove
() {
145 if device_exists
"${port}"; then
146 wireless_remove
"${port}"
156 port_settings_read
"${port}" ${HOOK_SETTINGS}
158 # Check if the PHY is present.
159 local phy
=$
(phy_get
${PHY})
161 log DEBUG
"phy '${PHY}' is not present"
165 # Create the wireless device, if it does not exist, yet.
166 if ! device_exists
${port}; then
167 wireless_create
${port} --address="${ADDRESS}" \
168 --phy="${phy}" --type="ibss"
174 function hook_down
() {
178 # Do nothing if the device already went away
179 if ! device_exists
"${port}"; then
183 # Leave the ad-hoc network.
184 wireless_ibss_leave
"${port}"
189 function hook_hotplug
() {
193 port_settings_read
"${port}" ${HOOK_SETTINGS}
195 case "$(hotplug_action)" in
197 # Join the adhoc network after the device has
199 if hotplug_event_port_is_interface
"${port}"; then
201 if isinteger MTU
; then
202 device_set_mtu
"${port}" "${MTU}"
205 wireless_ibss_join
"${port}" --channel="${CHANNEL}" \
206 --bssid="${BSSID}" --essid="${SSID}"
208 # Bring up the port when the phy is plugged in
209 elif hotplug_event_port_uses_phy
"${port}"; then
215 exit ${EXIT_NOT_HANDLED}
222 function hook_find_parent
() {
227 for p
in $
(ports_get
); do
228 hook
=$
(port_get_hook
"${p}")
230 if [ "${hook}" = "batman-adv" ]; then
231 for child
in $
(port_get_children
"${p}"); do
232 [ "${child}" = "${port}" ] ||
continue