]> git.ipfire.org Git - people/stevee/network.git/blame - src/hooks/ports/batman-adv-port
Remove support for ISDN
[people/stevee/network.git] / src / hooks / ports / batman-adv-port
CommitLineData
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
31670741 24HOOK_SETTINGS="HOOK ADDRESS MESH_ID SSID CHANNEL PHY"
e6993835
MT
25
26ADDRESS=$(mac_generate)
27CHANNEL=1
e6993835 28MESH_ID=
1509acb7 29PHY=
e6993835
MT
30SSID=
31
32# batman-adv inserts an additional header of 28 bytes, so we set the MTU
2da210b5
MT
33# to 1560, that normal ethernet packets with 1500 bytes can pass the network.
34MTU=1560
e6993835 35
2181765d 36function hook_check() {
e6993835
MT
37 assert isset ADDRESS
38 assert ismac ADDRESS
39 assert isset CHANNEL
e6993835
MT
40 assert isset MESH_ID
41 assert ismac MESH_ID
42 assert isset PHY
43 assert ismac PHY
44 assert isset SSID
45}
46
2181765d 47function hook_create() {
e6993835
MT
48 while [ $# -gt 0 ]; do
49 case "${1}" in
50 --address=*)
51 ADDRESS=$(cli_get_val ${1})
52 ;;
53 --channel=*)
54 CHANNEL=$(cli_get_val ${1})
55 ;;
e6993835
MT
56 --phy=*)
57 PHY=$(cli_get_val ${1})
58 ;;
59 --ssid=*)
60 SSID=$(cli_get_val ${1})
61 ;;
62 --mesh-id=*)
63 MESH_ID=$(cli_get_val ${1})
64 ;;
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
76 local port=$(port_find_free ${PORT_PATTERN_BATMAN_ADV_PORT})
77 assert isset port
78
e9df08ad 79 port_settings_write "${port}" ${HOOK_SETTINGS}
e6993835
MT
80
81 exit ${EXIT_OK}
82}
83
2181765d 84function 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
93 --channel=*)
94 CHANNEL=$(cli_get_val ${1})
95 ;;
e6993835
MT
96 --mesh-id=*)
97 MESH_ID=$(cli_get_val ${1})
98 ;;
99 --ssid=*)
100 SSID=$(cli_get_val ${1})
101 ;;
102 *)
103 warning "Unknown argument '${1}'"
104 ;;
105 esac
106 shift
107 done
108
e9df08ad 109 port_settings_write "${port}" ${HOOK_SETTINGS}
e6993835
MT
110
111 exit ${EXIT_OK}
112}
113
2181765d 114function hook_up() {
e6993835
MT
115 local port=${1}
116 assert isset port
117
e9df08ad 118 port_settings_read "${port}" ${HOOK_SETTINGS}
e6993835
MT
119
120 # Check if the PHY is present.
121 local phy=$(phy_get ${PHY})
122 if ! isset phy; then
123 log DEBUG "phy '${PHY}' is not present"
124 exit ${EXIT_ERROR}
125 fi
126
127 # Create the wireless device, if it does not exist, yet.
128 if ! device_exists ${port}; then
129 wireless_create ${port} \
130 --address="${ADDRESS}" \
131 --phy="${phy}" \
132 --type="ibss"
133 fi
134
135 # Set the MTU.
136 device_set_mtu "${port}" "${MTU}"
137
138 # Join the ad-hoc network.
139 wireless_ibss_join "${port}" --channel="${CHANNEL}" \
140 --bssid="${MESH_ID}" --essid="${SSID}"
141
142 # Add the device as a batman-adv device.
cb1475f6 143 local parent="$(hook_find_parent ${port})"
e6993835
MT
144 if isset parent; then
145 batman_adv_interface_add "${parent}" "${port}"
146 fi
147
148 exit ${EXIT_OK}
149}
150
2181765d 151function hook_down() {
e6993835
MT
152 local port=${1}
153 assert isset port
154
155 # Remove the batman-adv device.
156 batman_adv_interface_del "${port}"
157
158 # Leave the ad-hoc network.
159 wireless_ibss_leave "${port}"
160
161 # Remove the device if it is still present.
162 if device_exists ${port}; then
163 wireless_remove ${port}
164 fi
165
166 exit ${EXIT_OK}
167}
168
2181765d 169function hook_hotplug() {
e6993835
MT
170 local port=${1}
171 assert isset port
172
173 local phy=${2}
174 assert isset phy
175
176 assert port_exists ${port}
177
178 # Read configuration of port.
e9df08ad 179 port_settings_read "${port}" ${HOOK_SETTINGS}
e6993835
MT
180
181 # Get the address of the phy.
05365355 182 local phy_address=$(phy_get_address "${phy}")
e6993835
MT
183
184 # Check if the phy is the same we have
185 # read from the configuration file.
186 if [ "${PHY}" = "${phy_address}" ]; then
187 # Bring up the device.
188 port_up "${port}"
05365355
MT
189
190 exit ${EXIT_OK}
e6993835
MT
191 fi
192
05365355 193 exit ${EXIT_NOT_HANDLED}
e6993835
MT
194}
195
2181765d 196function hook_find_parent() {
e6993835
MT
197 local port=${1}
198 assert isset port
199
200 local p child hook
201 for p in $(ports_get); do
202 hook=$(port_get_hook "${p}")
203
204 if [ "${hook}" = "batman-adv" ]; then
205 for child in $(port_get_children "${p}"); do
e6993835
MT
206 [ "${child}" = "${port}" ] || continue
207
208 print "${p}"
209 return ${EXIT_OK}
210 done
211 fi
212 done
213
214 return ${EXIT_ERROR}
215}