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 MESH_ID SSID CHANNEL COUNTRY_CODE PHY"
26 ADDRESS
=$
(mac_generate
)
32 # batman-adv inserts an additional header of 28 bytes, so we set the MTU
33 # to 1528, that normal ethernet packets with 1500 bytes can pass the network.
36 function hook_check
() {
40 assert isset COUNTRY_CODE
48 function hook_create
() {
49 while [ $# -gt 0 ]; do
52 ADDRESS
=$
(cli_get_val
${1})
55 CHANNEL
=$
(cli_get_val
${1})
58 COUNTRY_CODE
=$
(cli_get_val
${1})
61 PHY
=$
(cli_get_val
${1})
64 SSID
=$
(cli_get_val
${1})
67 MESH_ID
=$
(cli_get_val
${1})
70 warning
"Ignoring unknown argument '${1}'"
76 # Save address of phy do identify it again
78 PHY
=$
(phy_get_address
${PHY})
80 local port
=$
(port_find_free
${PORT_PATTERN_BATMAN_ADV_PORT})
83 config_write $
(port_file
${port}) ${HOOK_SETTINGS}
88 function hook_edit
() {
93 config_read $
(port_file
${port})
95 while [ $# -gt 0 ]; do
98 CHANNEL
=$
(cli_get_val
${1})
101 COUNTRY_CODE
=$
(cli_get_val
${1})
104 MESH_ID
=$
(cli_get_val
${1})
107 SSID
=$
(cli_get_val
${1})
110 warning
"Unknown argument '${1}'"
116 config_write $
(port_file
${port}) ${HOOK_SETTINGS}
125 config_read $
(port_file
${port})
127 # Check if the PHY is present.
128 local phy
=$
(phy_get
${PHY})
130 log DEBUG
"phy '${PHY}' is not present"
134 # Create the wireless device, if it does not exist, yet.
135 if ! device_exists
${port}; then
136 wireless_create
${port} \
137 --address="${ADDRESS}" \
143 device_set_mtu
"${port}" "${MTU}"
145 # Join the ad-hoc network.
146 wireless_ibss_join
"${port}" --channel="${CHANNEL}" \
147 --bssid="${MESH_ID}" --essid="${SSID}"
149 # Add the device as a batman-adv device.
150 local parent
="$(_find_parent ${port})"
151 if isset parent
; then
152 batman_adv_interface_add
"${parent}" "${port}"
158 function hook_down
() {
162 # Remove the batman-adv device.
163 batman_adv_interface_del
"${port}"
165 # Leave the ad-hoc network.
166 wireless_ibss_leave
"${port}"
168 # Remove the device if it is still present.
169 if device_exists
${port}; then
170 wireless_remove
${port}
176 function hook_hotplug
() {
183 assert port_exists
${port}
185 # Read configuration of port.
186 config_read $
(port_file
${port})
188 # Get the address of the phy.
189 local phy_address
=$
(phy_get_address
${phy})
191 # Check if the phy is the same we have
192 # read from the configuration file.
193 if [ "${PHY}" = "${phy_address}" ]; then
194 # Bring up the device.
201 function hook_find_parent
() {
206 for p
in $
(ports_get
); do
207 hook
=$
(port_get_hook
"${p}")
209 if [ "${hook}" = "batman-adv" ]; then
210 for child
in $
(port_get_children
"${p}"); do
211 log ERROR
"child=${child}"
212 [ "${child}" = "${port}" ] ||
continue