]> git.ipfire.org Git - people/stevee/network.git/blob - src/hooks/ports/wireless-mesh
Add port hook for wireless mesh devices after 802.11s
[people/stevee/network.git] / src / hooks / ports / wireless-mesh
1 #!/bin/bash
2 ###############################################################################
3 # #
4 # IPFire.org - A linux based firewall #
5 # Copyright (C) 2017 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
24 HOOK_PORT_PATTERN="${PORT_PATTERN_MESH}"
25
26 HOOK_SETTINGS="HOOK ADDRESS MESH_ID CHANNEL PHY"
27
28 hook_check_settings() {
29 assert ismac ADDRESS
30 assert isset MESH_ID
31 assert isset CHANNEL
32 assert isset PHY
33 assert ismac PHY
34 }
35
36 hook_parse_cmdline() {
37 while [ $# -gt 0 ]; do
38 case "${1}" in
39 --address=*)
40 ADDRESS=$(cli_get_val "${1}")
41 ;;
42 --channel=*)
43 CHANNEL=$(cli_get_val "${1}")
44 ;;
45 --mesh-id=*)
46 MESH_ID=$(cli_get_val "${1}")
47 ;;
48 --phy=*)
49 PHY=$(cli_get_val "${1}")
50 ;;
51 *)
52 warning "Ignoring unknown argument '${1}'"
53 ;;
54 esac
55 shift
56 done
57
58 if ! isset MESH_ID; then
59 error "Please pass a mesh ID"
60 return ${EXIT_ERROR}
61 fi
62
63 # Save address of phy do identify it again
64 PHY=$(phy_get ${PHY})
65 PHY=$(phy_get_address ${PHY})
66
67 # Generate a MAC address if none given
68 if ! isset ADDRESS; then
69 ADDRESS=$(mac_generate)
70 fi
71
72 # XXX check if wireless channel is valid
73 }
74
75 hook_create() {
76 local port="${1}"
77 assert isset port
78
79 # Read settings
80 port_settings_read "${port}" ${HOOK_SETTINGS}
81
82 # Check if the PHY is present.
83 local phy="$(phy_get "${PHY}")"
84 if ! isset phy; then
85 log DEBUG "phy '${PHY}' is not present"
86 return ${EXIT_ERROR}
87 fi
88
89 # Create the wireless device, if it does not exist, yet.
90 if ! device_exists "${port}"; then
91 wireless_create "${port}" \
92 --address="${ADDRESS}" \
93 --channel="${CHANNEL}" \
94 --phy="${phy}" \
95 --type="mesh-point" || return $?
96 fi
97
98 return ${EXIT_OK}
99 }
100
101 hook_remove() {
102 local port="${1}"
103 assert isset port
104
105 if device_exists "${port}"; then
106 wireless_remove "${port}"
107 fi
108
109 exit ${EXIT_OK}
110 }
111
112 hook_hotplug() {
113 local port="${1}"
114 assert isset port
115
116 port_settings_read "${port}" ${HOOK_SETTINGS}
117
118 case "$(hotplug_action)" in
119 add)
120 # Bring up the port when the phy is plugged in
121 if hotplug_event_port_uses_phy "${port}"; then
122 hook_create "${port}" || exit $?
123 fi
124 ;;
125
126 *)
127 exit ${EXIT_NOT_HANDLED}
128 ;;
129 esac
130
131 exit ${EXIT_OK}
132 }