]>
Commit | Line | Data |
---|---|---|
0e035311 MT |
1 | #!/bin/bash |
2 | ############################################################################### | |
3 | # # | |
4 | # IPFire.org - A linux based firewall # | |
5 | # Copyright (C) 2012 IPFire Network Development Team # | |
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 | ||
49ec20d8 | 22 | HOSTAPD_CONTROL_INTERFACE_DIR="/run/hostapd/ctrl" |
0e035311 | 23 | |
6c262922 MT |
24 | HOSTAPD_SUPPORTED_MODES="802.11a 802.11a/n 802.11ac 802.11g 802.11g/n" |
25 | ||
1c6a4e30 | 26 | hostapd_config_write() { |
0e035311 | 27 | local device=${1} |
49ec20d8 | 28 | assert isset device |
0e035311 | 29 | |
49ec20d8 MT |
30 | local file=${2} |
31 | assert isset file | |
32 | ||
33 | # Shift the device and file argument. | |
34 | shift 2 | |
0e035311 MT |
35 | |
36 | local broadcast_ssid | |
37 | local channel | |
f9e980d9 | 38 | local channel_bandwidth |
31670741 | 39 | local country_code="$(wireless_get_reg_domain)" |
7b297fb2 | 40 | local dfs="on" |
0e035311 | 41 | local encryption |
7842c2ce | 42 | local environment="${WIRELESS_DEFAULT_ENVIRONMENT}" |
0e035311 MT |
43 | local key |
44 | local mode | |
45 | local ssid | |
19c166f8 | 46 | local wmm="1" |
0e035311 MT |
47 | |
48 | while [ $# -gt 0 ]; do | |
49 | case "${1}" in | |
50 | --broadcast-ssid=*) | |
2212045f | 51 | broadcast_ssid=$(cli_get_val "${1}") |
0e035311 MT |
52 | ;; |
53 | --channel=*) | |
2212045f | 54 | channel=$(cli_get_val "${1}") |
0e035311 | 55 | ;; |
f9e980d9 MT |
56 | --channel-bandwidth=*) |
57 | channel_bandwidth="$(cli_get_val "${1}")" | |
58 | ;; | |
7b297fb2 MT |
59 | --dfs=*) |
60 | dfs="$(cli_get_val "${1}")" | |
61 | ;; | |
0e035311 | 62 | --encryption=*) |
2212045f | 63 | encryption=$(cli_get_val "${1}") |
0e035311 | 64 | ;; |
7842c2ce MT |
65 | --environment=*) |
66 | environment="$(cli_get_val "${1}")" | |
67 | ;; | |
0e035311 | 68 | --key=*) |
2212045f | 69 | key=$(cli_get_val "${1}") |
0e035311 | 70 | ;; |
4cfc085f | 71 | --mode=*) |
2212045f | 72 | mode=$(cli_get_val "${1}") |
6c262922 MT |
73 | |
74 | if ! isoneof mode ${HOSTAPD_SUPPORTED_MODES}; then | |
75 | error "Unsupported mode: ${mode}" | |
76 | return ${EXIT_ERROR} | |
77 | fi | |
4cfc085f MT |
78 | ;; |
79 | --ssid=*) | |
2212045f | 80 | ssid=$(cli_get_val "${1}") |
4cfc085f | 81 | ;; |
19c166f8 MT |
82 | --wmm=*) |
83 | local val="$(cli_get_val "${1}")" | |
84 | if enabled val; then | |
85 | wmm="1" | |
86 | else | |
87 | wmm="0" | |
88 | fi | |
89 | ;; | |
0e035311 MT |
90 | *) |
91 | warning_log "Ignoring unknown argument '${1}'." | |
92 | ;; | |
93 | esac | |
94 | shift | |
95 | done | |
96 | ||
6c262922 MT |
97 | # Check if mode is set |
98 | if ! isset mode; then | |
99 | error "Mode is not set" | |
100 | return ${EXIT_ERROR} | |
101 | fi | |
102 | ||
0e035311 MT |
103 | assert isset broadcast_ssid |
104 | assert isbool broadcast_ssid | |
105 | ||
106 | assert isset channel | |
107 | assert isinteger channel | |
108 | ||
0e035311 MT |
109 | assert isset mode |
110 | assert isset ssid | |
111 | ||
112 | # Check if key is set when encryption is used. | |
113 | if isset encryption; then | |
114 | assert isoneof encryption WPA WPA2 WPA/WPA2 | |
115 | assert isset key | |
116 | fi | |
117 | ||
7842c2ce MT |
118 | # Check wireless environment |
119 | if ! wireless_environment_is_valid "${environment}"; then | |
120 | error "Invalid wireless environment: ${environment}" | |
121 | return ${EXIT_ERROR} | |
122 | fi | |
123 | ||
1b4aa2ca MT |
124 | # With channel 0, ACS must be supported |
125 | if [ ${channel} -eq 0 ] && ! wireless_supports_acs "${device}"; then | |
126 | error "ACS requested, but not supported by ${device}" | |
127 | return ${EXIT_ERROR} | |
128 | fi | |
129 | ||
f9e980d9 MT |
130 | # Check channel bandwidth for validity |
131 | if isset channel_bandwidth && ! wireless_channel_bandwidth_is_valid "${mode}" "${channel_bandwidth}"; then | |
132 | error "Invalid channel bandwidth for ${mode}: ${channel_bandwidth}" | |
133 | return ${EXIT_ERROR} | |
134 | fi | |
135 | ||
6c262922 MT |
136 | # 802.11ac/n flags |
137 | local ieee80211ac | |
138 | local ieee80211n | |
139 | local vht_caps | |
f9e980d9 | 140 | local vht_oper_chwidth="0" |
6c262922 MT |
141 | local ht_caps |
142 | ||
143 | local hw_mode | |
144 | case "${mode}" in | |
145 | 802.11a) | |
146 | hw_mode="a" | |
147 | ;; | |
148 | ||
149 | 802.11a/n) | |
150 | hw_mode="a" | |
151 | ieee80211n="1" | |
152 | ||
153 | # Fetch HT caps | |
154 | ht_caps="$(wireless_get_ht_caps "${device}")" | |
155 | ;; | |
156 | ||
157 | 802.11g) | |
158 | hw_mode="g" | |
159 | ;; | |
160 | ||
161 | 802.11g/n) | |
162 | hw_mode="g" | |
163 | ieee80211n="1" | |
164 | ||
165 | # Fetch HT caps | |
166 | ht_caps="$(wireless_get_ht_caps "${device}")" | |
167 | ;; | |
168 | ||
169 | 802.11ac) | |
170 | hw_mode="a" | |
171 | ieee80211ac="1" | |
172 | ieee80211n="1" | |
173 | ||
174 | # Fetch VHT caps | |
175 | vht_caps="$(wireless_get_vht_caps "${device}")" | |
1526e219 | 176 | |
6c262922 MT |
177 | # Fetch HT caps |
178 | ht_caps="$(wireless_get_ht_caps "${device}")" | |
f9e980d9 MT |
179 | |
180 | case "${channel_bandwidth}" in | |
181 | 80) | |
182 | vht_oper_chwidth="1" | |
183 | ;; | |
184 | 160) | |
185 | vht_oper_chwidth="2" | |
186 | ;; | |
187 | 80+80) | |
188 | vht_oper_chwidth="3" | |
189 | ;; | |
190 | esac | |
6c262922 MT |
191 | ;; |
192 | esac | |
0e1c630c | 193 | |
49ec20d8 MT |
194 | # Create configuration directory. |
195 | local config_dir=$(dirname ${file}) | |
196 | mkdir -p ${HOSTAPD_CONTROL_INTERFACE_DIR} ${config_dir} 2>/dev/null | |
197 | ||
198 | config_header "hostapd" > ${file} | |
199 | ||
200 | # Interface configuration | |
201 | ( | |
202 | print "# Interface configuration" | |
203 | print "driver=nl80211" | |
204 | print "interface=${device}" | |
205 | ||
206 | ) >> ${file} | |
207 | ||
208 | # Wireless configuration | |
0e035311 MT |
209 | local ignore_broadcast_ssid |
210 | if enabled broadcast_ssid; then | |
211 | ignore_broadcast_ssid="0" | |
212 | else | |
213 | ignore_broadcast_ssid="1" | |
214 | fi | |
215 | ||
49ec20d8 | 216 | ( |
b6ec3dd6 MT |
217 | # Advertise country code and maximum transmission power |
218 | print "ieee80211d=1" | |
7842c2ce MT |
219 | print "country_code=${country_code}" |
220 | ||
221 | # Wireless Environment | |
222 | case "${environment}" in | |
223 | indoor) | |
224 | print "country3=0x49" | |
225 | country3 | |
226 | ;; | |
227 | outdoor) | |
228 | print "country3=0x4f" | |
229 | ;; | |
230 | indoor+outdoor) | |
231 | print "country3=0x20" | |
232 | ;; | |
233 | esac | |
b6ec3dd6 | 234 | |
96026172 MT |
235 | # Always advertise TPC |
236 | print "local_pwr_constraint=3" | |
237 | print "spectrum_mgmt_required=1" | |
238 | ||
6c262922 | 239 | # Enable Radar Detection |
dc6d97fb | 240 | if enabled dfs && wireless_supports_dfs "${device}"; then |
7b297fb2 MT |
241 | print "ieee80211h=1" |
242 | else | |
243 | print "ieee80211h=0" | |
244 | fi | |
6c262922 MT |
245 | |
246 | print # empty line | |
247 | ||
49ec20d8 | 248 | print "# Wireless configuration" |
6c262922 MT |
249 | print "hw_mode=${hw_mode}" |
250 | ||
251 | if isset ieee80211ac; then | |
252 | print "ieee80211ac=${ieee80211ac}" | |
253 | fi | |
254 | ||
255 | if isset ieee80211n; then | |
256 | print "ieee80211n=${ieee80211n}" | |
257 | fi | |
258 | ||
49ec20d8 | 259 | print "channel=${channel}" |
49ec20d8 | 260 | print "ignore_broadcast_ssid=${ignore_broadcast_ssid}" |
0e035311 | 261 | |
49ec20d8 MT |
262 | if contains_spaces "${ssid}"; then |
263 | print "ssid=\"${ssid}\"" | |
264 | else | |
265 | print "ssid=${ssid}" | |
266 | fi | |
0e035311 | 267 | |
fcdbed86 | 268 | # WMM & WMM-PS Unscheduled Automatic Power Save Delivery |
19c166f8 | 269 | print "wmm_enabled=${wmm}" |
fcdbed86 MT |
270 | print "uapsd_advertisement_enabled=1" |
271 | ||
272 | # Low Priority / AC_BK = Background | |
273 | print "wmm_ac_bk_cwmin=4" | |
274 | print "wmm_ac_bk_cwmax=10" | |
275 | print "wmm_ac_bk_aifs=7" | |
276 | print "wmm_ac_bk_txop_limit=0" | |
277 | print "wmm_ac_bk_acm=0" | |
278 | print "tx_queue_data3_aifs=7" | |
279 | print "tx_queue_data3_cwmin=15" | |
280 | print "tx_queue_data3_cwmax=1023" | |
281 | print "tx_queue_data3_burst=0" | |
282 | ||
283 | # Normal Priority / AC_BE = Best Effort | |
284 | print "wmm_ac_be_aifs=3" | |
285 | print "wmm_ac_be_cwmin=4" | |
286 | print "wmm_ac_be_cwmax=10" | |
287 | print "wmm_ac_be_txop_limit=0" | |
288 | print "wmm_ac_be_acm=0" | |
289 | print "tx_queue_data2_aifs=3" | |
290 | print "tx_queue_data2_cwmin=15" | |
291 | print "tx_queue_data2_cwmax=63" | |
292 | print "tx_queue_data2_burst=0" | |
293 | ||
294 | # High Priority / AC_VI = Video | |
295 | print "wmm_ac_vi_aifs=2" | |
296 | print "wmm_ac_vi_cwmin=3" | |
297 | print "wmm_ac_vi_cwmax=4" | |
298 | print "wmm_ac_vi_txop_limit=94" | |
299 | print "wmm_ac_vi_acm=0" | |
300 | print "tx_queue_data1_aifs=1" | |
301 | print "tx_queue_data1_cwmin=7" | |
302 | print "tx_queue_data1_cwmax=15" | |
303 | print "tx_queue_data1_burst=3.0" | |
304 | ||
305 | # Highest Priority / AC_VO = Voice | |
306 | print "wmm_ac_vo_aifs=2" | |
307 | print "wmm_ac_vo_cwmin=2" | |
308 | print "wmm_ac_vo_cwmax=3" | |
309 | print "wmm_ac_vo_txop_limit=47" | |
310 | print "wmm_ac_vo_acm=0" | |
311 | print "tx_queue_data0_aifs=1" | |
312 | print "tx_queue_data0_cwmin=3" | |
313 | print "tx_queue_data0_cwmax=7" | |
314 | print "tx_queue_data0_burst=1.5" | |
19c166f8 | 315 | |
1526e219 MT |
316 | # Enable VHT caps |
317 | if isset vht_caps; then | |
318 | print "vht_capab=${vht_caps}" | |
319 | fi | |
320 | ||
0e1c630c MT |
321 | # Enable HT caps |
322 | print "ht_capab=${ht_caps}" | |
323 | ||
f9e980d9 MT |
324 | # Wider Channels |
325 | print "vht_oper_chwidth=${vht_oper_chwidth}" | |
326 | ||
49ec20d8 MT |
327 | |
328 | ) >> ${file} | |
0e035311 | 329 | |
49ec20d8 MT |
330 | # Control interface. |
331 | ( | |
332 | print "# Control interface" | |
333 | print "ctrl_interface=${HOSTAPD_CONTROL_INTERFACE_DIR}" | |
334 | print "ctrl_interface_group=0" | |
335 | ||
336 | ) >> ${file} | |
0e035311 | 337 | |
49ec20d8 | 338 | # Encryption settings |
0e035311 MT |
339 | if isset encryption; then |
340 | local encryption_mode=0 | |
341 | case "${encryption}" in | |
342 | WPA) | |
343 | encryption_mode=1 | |
344 | ;; | |
345 | WPA2) | |
346 | encryption_mode=2 | |
347 | ;; | |
348 | WPA/WPA2) | |
349 | encryption_mode=3 | |
350 | ;; | |
351 | esac | |
352 | ||
49ec20d8 MT |
353 | ( |
354 | print "# Encryption settings" | |
355 | print "wpa=${encryption_mode}" | |
356 | print "wpa_passphrase=${key}" | |
357 | print "wpa_key_mgmt=WPA-PSK" | |
358 | print "wpa_pairwise=TKIP" | |
359 | print "rsn_pairwise=CCMP" | |
360 | ||
361 | ) >> ${file} | |
0e035311 MT |
362 | fi |
363 | ||
364 | return ${EXIT_OK} | |
365 | } | |
366 | ||
1c6a4e30 | 367 | hostapd_start() { |
0e035311 | 368 | local device=${1} |
0e035311 MT |
369 | assert isset device |
370 | ||
0e035311 MT |
371 | service_start "hostapd@${device}.service" |
372 | local ret=$? | |
373 | ||
49ec20d8 MT |
374 | if [ ${ret} -eq ${EXIT_OK} ]; then |
375 | log DEBUG "hostapd has been successfully started on '${device}'" | |
376 | else | |
377 | log ERROR "Could not start hostapd on '${device}': ${ret}" | |
378 | return ${EXIT_ERROR} | |
379 | fi | |
380 | ||
381 | return ${EXIT_OK} | |
0e035311 MT |
382 | } |
383 | ||
1c6a4e30 | 384 | hostapd_stop() { |
0e035311 MT |
385 | local device=${1} |
386 | assert isset device | |
387 | ||
388 | service_stop "hostapd@${device}.service" | |
0e035311 | 389 | } |