]> git.ipfire.org Git - people/ms/network.git/blame - src/hooks/ports/wireless-ap
wireless-ap: Allow to disable DFS in configuration
[people/ms/network.git] / src / hooks / ports / wireless-ap
CommitLineData
d76f5107
MT
1#!/bin/bash
2###############################################################################
3# #
4# IPFire.org - A linux based firewall #
5# Copyright (C) 2010 Michael Tremer & Christian Schmidt #
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
8ee92277 22. /usr/lib/network/header-port
d76f5107 23
54bae947
MT
24HOOK_PORT_PATTERN="${PORT_PATTERN_ACCESSPOINT}"
25
8578e61d 26HOOK_SETTINGS="ADDRESS BROADCAST_SSID CHANNEL MODE PHY SSID"
25e32463 27HOOK_SETTINGS="${HOOK_SETTINGS} ENCRYPTION KEY"
d76f5107
MT
28
29ADDRESS=$(mac_generate)
30BROADCAST_SSID=on
469bc87f 31CHANNEL=0
25e32463
MT
32ENCRYPTION=""
33KEY=""
d76f5107
MT
34SSID=
35
7b297fb2
MT
36# Perform radar detection by default when possible
37DFS="on"
38
1c6a4e30 39hook_check_settings() {
d76f5107
MT
40 assert isset ADDRESS
41 assert ismac ADDRESS
42 assert isset BROADCAST_SSID
43 assert isbool BROADCAST_SSID
44 assert isset CHANNEL
7b297fb2 45 assert isbool DFS
d76f5107 46 assert isset MODE
6c262922 47 assert isoneof MODE ${HOSTAPD_SUPPORTED_MODES}
d76f5107
MT
48 assert isset PHY
49 assert ismac PHY
50 assert isset SSID
25e32463
MT
51
52 if isset ENCRYPTION; then
53 assert isoneof ENCRYPTION WPA WPA2 WPA/WPA2
54
55 assert isset KEY
56 assert [ ${#KEY} -ge 8 ]
57 assert [ ${#KEY} -le 63 ]
58 fi
d76f5107
MT
59}
60
270aab39 61hook_parse_cmdline() {
d76f5107
MT
62 while [ $# -gt 0 ]; do
63 case "${1}" in
64 --broadcast-ssid=*)
2212045f 65 BROADCAST_SSID=$(cli_get_val "${1}")
d76f5107
MT
66 ;;
67 --channel=*)
2212045f 68 CHANNEL=$(cli_get_val "${1}")
d76f5107 69 ;;
7b297fb2
MT
70 --dfs=*)
71 DFS="$(cli_get_val "${1}")"
72
73 if enabled DFS; then
74 DFS="on"
75 elif disabled DFS; then
76 DFS="off"
77 else
78 error "Invalid value for DFS: ${DFS}"
79 return ${EXIT_ERROR}
80 fi
81 ;;
25e32463 82 --encryption=*)
2212045f 83 ENCRYPTION=$(cli_get_val "${1}")
25e32463
MT
84 ;;
85 --key=*)
2212045f 86 KEY=$(cli_get_val "${1}")
25e32463 87 ;;
d76f5107 88 --mac=*)
2212045f 89 ADDRESS=$(cli_get_val "${1}")
d76f5107
MT
90 ;;
91 --mode=*)
2212045f 92 MODE=$(cli_get_val "${1}")
6c262922
MT
93
94 if ! isoneof MODE ${HOSTAPD_SUPPORTED_MODES}; then
95 error "Unsupported mode: ${MODE}"
96 error "Mode must be one of ${HOSTAPD_SUPPORTED_MODES}"
97 return ${EXIT_ERROR}
98 fi
d76f5107
MT
99 ;;
100 --phy=*)
2212045f 101 PHY=$(cli_get_val "${1}")
d76f5107
MT
102 ;;
103 --ssid=*)
2212045f 104 SSID=$(cli_get_val "${1}")
d76f5107
MT
105 ;;
106 *)
107 warning "Ignoring unknown argument '${1}'"
108 ;;
109 esac
110 shift
111 done
112
8578e61d
MT
113 # Generate a random MAC address if none is set
114 if ! isset ADDRESS; then
115 ADDRESS="$(mac_generate)"
116 fi
117
6c262922
MT
118 # MODE must be set
119 if ! isset MODE; then
120 error "--mode is not set"
121 return ${EXIT_ERROR}
122 fi
123
d76f5107
MT
124 # Save address of phy do identify it again
125 PHY=$(phy_get ${PHY})
126 PHY=$(phy_get_address ${PHY})
270aab39
MT
127}
128
1c6a4e30 129hook_edit() {
d76f5107 130 local port=${1}
d76f5107
MT
131 assert isset port
132
2212045f 133 if ! hook_default_edit "$@"; then
270aab39
MT
134 return ${EXIT_ERROR}
135 fi
d76f5107 136
270aab39
MT
137 # To apply all changes, we need to restart the port
138 port_restart "${port}"
d76f5107
MT
139}
140
1c6a4e30 141hook_create() {
1ba6a2bb 142 local port="${1}"
d76f5107
MT
143 assert isset port
144
1ba6a2bb
MT
145 device_exists "${port}" && exit ${EXIT_OK}
146
e9df08ad 147 port_settings_read "${port}" ${HOOK_SETTINGS}
d76f5107 148
49ec20d8
MT
149 # Check if the PHY is present.
150 local phy=$(phy_get ${PHY})
151 if ! isset phy; then
152 log DEBUG "phy '${PHY}' is not present"
153 exit ${EXIT_ERROR}
154 fi
155
1ba6a2bb
MT
156 # Create the wireless device
157 wireless_create "${port}" \
158 --phy="${phy}" \
159 --type="ap" \
160 --address="${ADDRESS}"
d76f5107
MT
161
162 exit ${EXIT_OK}
163}
164
1c6a4e30 165hook_remove() {
1ba6a2bb 166 local port="${1}"
d76f5107
MT
167 assert isset port
168
b8026986
MT
169 # Remove the device if present
170 if device_exists "${port}"; then
171 wireless_remove "${port}"
47859d95 172 fi
d76f5107
MT
173
174 exit ${EXIT_OK}
175}
176
1c6a4e30 177hook_up() {
1ba6a2bb
MT
178 local port="${1}"
179 assert isset port
180
181 # The port must already exist before
182 # hostapd is started. Otherwise it will
183 # fail horribly over and over again.
184 assert device_exists "${port}"
185
186 hostapd_start "${port}"
187}
188
1c6a4e30 189hook_down() {
1ba6a2bb
MT
190 local port="${1}"
191 assert isset port
192
193 hostapd_stop "${port}"
194}
195
1c6a4e30 196hook_hotplug() {
b8026986 197 local port="${1}"
47859d95 198 assert isset port
49ec20d8 199
b8026986
MT
200 case "$(hotplug_action)" in
201 add)
1ba6a2bb
MT
202 # Create the port when the phy is plugged in
203 if hotplug_event_port_uses_phy "${port}"; then
204 hook_create "${port}"
b8026986
MT
205 fi
206 ;;
207
208 remove)
209 # Stop hostapd
210 if hotplug_event_port_is_interface "${port}"; then
211 hostapd_stop "${port}"
b8026986 212
1ba6a2bb
MT
213 exit ${EXIT_OK}
214 fi
b8026986
MT
215 ;;
216 esac
47859d95 217
1ba6a2bb 218 exit ${EXIT_NOT_HANDLED}
47859d95 219}