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}
121 port_settings_read
"${port}" ${HOOK_SETTINGS}
123 # Check if the PHY is present.
124 local phy
=$
(phy_get
${PHY})
126 log DEBUG
"phy '${PHY}' is not present"
130 # Create the wireless device, if it does not exist, yet.
131 if ! device_exists
${port}; then
132 wireless_create
${port} --address="${ADDRESS}" \
133 --phy="${phy}" --type="ibss"
139 function hook_down
() {
143 # Do nothing if the device already went away
144 if ! device_exists
"${port}"; then
148 # Leave the ad-hoc network.
149 wireless_ibss_leave
"${port}"
151 # Remove the device if it is still present.
152 wireless_remove
"${port}"
157 function hook_hotplug
() {
161 port_settings_read
"${port}" ${HOOK_SETTINGS}
163 case "$(hotplug_action)" in
165 # Join the adhoc network after the device has
167 if hotplug_event_port_is_interface
"${port}"; then
169 if isinteger MTU
; then
170 device_set_mtu
"${port}" "${MTU}"
173 wireless_ibss_join
"${port}" --channel="${CHANNEL}" \
174 --bssid="${BSSID}" --essid="${SSID}"
176 # Bring up the port when the phy is plugged in
177 elif hotplug_event_port_uses_phy
"${port}"; then
183 exit ${EXIT_NOT_HANDLED}
190 function hook_find_parent
() {
195 for p
in $
(ports_get
); do
196 hook
=$
(port_get_hook
"${p}")
198 if [ "${hook}" = "batman-adv" ]; then
199 for child
in $
(port_get_children
"${p}"); do
200 [ "${child}" = "${port}" ] ||
continue