]>
git.ipfire.org Git - people/stevee/network.git/blob - src/hooks/ports/batman-adv-port
b14351e052c52d18bfb58976004cc97532862b6e
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 PHY"
26 ADDRESS
=$
(mac_generate
)
31 # batman-adv inserts an additional header of 28 bytes, so we set the MTU
32 # to 1560, that normal ethernet packets with 1500 bytes can pass the network.
35 function hook_check
() {
46 function hook_create
() {
47 while [ $# -gt 0 ]; do
50 ADDRESS
=$
(cli_get_val
${1})
53 CHANNEL
=$
(cli_get_val
${1})
56 PHY
=$
(cli_get_val
${1})
59 SSID
=$
(cli_get_val
${1})
62 MESH_ID
=$
(cli_get_val
${1})
65 warning
"Ignoring unknown argument '${1}'"
71 # Save address of phy do identify it again
73 PHY
=$
(phy_get_address
${PHY})
75 local port
=$
(port_find_free
${PORT_PATTERN_BATMAN_ADV_PORT})
78 config_write $
(port_file
${port}) ${HOOK_SETTINGS}
83 function hook_edit
() {
88 config_read $
(port_file
${port})
90 while [ $# -gt 0 ]; do
93 CHANNEL
=$
(cli_get_val
${1})
96 MESH_ID
=$
(cli_get_val
${1})
99 SSID
=$
(cli_get_val
${1})
102 warning
"Unknown argument '${1}'"
108 config_write $
(port_file
${port}) ${HOOK_SETTINGS}
117 config_read $
(port_file
${port})
119 # Check if the PHY is present.
120 local phy
=$
(phy_get
${PHY})
122 log DEBUG
"phy '${PHY}' is not present"
126 # Create the wireless device, if it does not exist, yet.
127 if ! device_exists
${port}; then
128 wireless_create
${port} \
129 --address="${ADDRESS}" \
135 device_set_mtu
"${port}" "${MTU}"
137 # Join the ad-hoc network.
138 wireless_ibss_join
"${port}" --channel="${CHANNEL}" \
139 --bssid="${MESH_ID}" --essid="${SSID}"
141 # Add the device as a batman-adv device.
142 local parent
="$(hook_find_parent ${port})"
143 if isset parent
; then
144 batman_adv_interface_add
"${parent}" "${port}"
150 function hook_down
() {
154 # Remove the batman-adv device.
155 batman_adv_interface_del
"${port}"
157 # Leave the ad-hoc network.
158 wireless_ibss_leave
"${port}"
160 # Remove the device if it is still present.
161 if device_exists
${port}; then
162 wireless_remove
${port}
168 function hook_hotplug
() {
175 assert port_exists
${port}
177 # Read configuration of port.
178 config_read $
(port_file
${port})
180 # Get the address of the phy.
181 local phy_address
=$
(phy_get_address
${phy})
183 # Check if the phy is the same we have
184 # read from the configuration file.
185 if [ "${PHY}" = "${phy_address}" ]; then
186 # Bring up the device.
193 function hook_find_parent
() {
198 for p
in $
(ports_get
); do
199 hook
=$
(port_get_hook
"${p}")
201 if [ "${hook}" = "batman-adv" ]; then
202 for child
in $
(port_get_children
"${p}"); do
203 [ "${child}" = "${port}" ] ||
continue