]>
Commit | Line | Data |
---|---|---|
a85bde82 | 1 | # hostapd configuration tests |
a4d744fe | 2 | # Copyright (c) 2014-2016, Jouni Malinen <j@w1.fi> |
a85bde82 JM |
3 | # |
4 | # This software may be distributed under the terms of the BSD license. | |
5 | # See README for more details. | |
6 | ||
eb89361b JM |
7 | import os |
8 | import signal | |
9 | import time | |
cedca7d0 JM |
10 | import logging |
11 | logger = logging.getLogger(__name__) | |
20a09e08 | 12 | import subprocess |
eb89361b | 13 | |
9fd6804d | 14 | from remotehost import remote_compatible |
a85bde82 | 15 | import hostapd |
cedca7d0 | 16 | from utils import alloc_fail, fail_test |
a85bde82 | 17 | |
9fd6804d | 18 | @remote_compatible |
a85bde82 JM |
19 | def test_ap_config_errors(dev, apdev): |
20 | """Various hostapd configuration errors""" | |
a85bde82 JM |
21 | |
22 | # IEEE 802.11d without country code | |
fab49f61 | 23 | params = {"ssid": "foo", "ieee80211d": "1"} |
41ba40e7 | 24 | hapd = hostapd.add_ap(apdev[0], params, no_enable=True) |
a85bde82 JM |
25 | if "FAIL" not in hapd.request("ENABLE"): |
26 | raise Exception("Unexpected ENABLE success (ieee80211d without country_code)") | |
1728a2e7 | 27 | hostapd.remove_bss(apdev[0]) |
a85bde82 JM |
28 | |
29 | # IEEE 802.11h without IEEE 802.11d | |
fab49f61 | 30 | params = {"ssid": "foo", "ieee80211h": "1"} |
41ba40e7 | 31 | hapd = hostapd.add_ap(apdev[0], params, no_enable=True) |
a85bde82 JM |
32 | if "FAIL" not in hapd.request("ENABLE"): |
33 | raise Exception("Unexpected ENABLE success (ieee80211h without ieee80211d") | |
1728a2e7 | 34 | hostapd.remove_bss(apdev[0]) |
a85bde82 JM |
35 | |
36 | # Power Constraint without IEEE 802.11d | |
fab49f61 | 37 | params = {"ssid": "foo", "local_pwr_constraint": "1"} |
41ba40e7 | 38 | hapd = hostapd.add_ap(apdev[0], params, no_enable=True) |
a85bde82 JM |
39 | if "FAIL" not in hapd.request("ENABLE"): |
40 | raise Exception("Unexpected ENABLE success (local_pwr_constraint without ieee80211d)") | |
1728a2e7 | 41 | hostapd.remove_bss(apdev[0]) |
a85bde82 JM |
42 | |
43 | # Spectrum management without Power Constraint | |
fab49f61 | 44 | params = {"ssid": "foo", "spectrum_mgmt_required": "1"} |
41ba40e7 | 45 | hapd = hostapd.add_ap(apdev[0], params, no_enable=True) |
a85bde82 JM |
46 | if "FAIL" not in hapd.request("ENABLE"): |
47 | raise Exception("Unexpected ENABLE success (spectrum_mgmt_required without local_pwr_constraint)") | |
1728a2e7 | 48 | hostapd.remove_bss(apdev[0]) |
a85bde82 JM |
49 | |
50 | # IEEE 802.1X without authentication server | |
fab49f61 | 51 | params = {"ssid": "foo", "ieee8021x": "1"} |
41ba40e7 | 52 | hapd = hostapd.add_ap(apdev[0], params, no_enable=True) |
a85bde82 JM |
53 | if "FAIL" not in hapd.request("ENABLE"): |
54 | raise Exception("Unexpected ENABLE success (ieee8021x)") | |
1728a2e7 | 55 | hostapd.remove_bss(apdev[0]) |
a85bde82 JM |
56 | |
57 | # RADIUS-PSK without macaddr_acl=2 | |
58 | params = hostapd.wpa2_params(ssid="foo", passphrase="12345678") | |
59 | params["wpa_psk_radius"] = "1" | |
41ba40e7 | 60 | hapd = hostapd.add_ap(apdev[0], params, no_enable=True) |
a85bde82 JM |
61 | if "FAIL" not in hapd.request("ENABLE"): |
62 | raise Exception("Unexpected ENABLE success (wpa_psk_radius)") | |
1728a2e7 | 63 | hostapd.remove_bss(apdev[0]) |
a85bde82 JM |
64 | |
65 | # FT without NAS-Identifier | |
fab49f61 JM |
66 | params = {"wpa": "2", |
67 | "wpa_key_mgmt": "FT-PSK", | |
68 | "rsn_pairwise": "CCMP", | |
69 | "wpa_passphrase": "12345678"} | |
41ba40e7 | 70 | hapd = hostapd.add_ap(apdev[0], params, no_enable=True) |
a85bde82 JM |
71 | if "FAIL" not in hapd.request("ENABLE"): |
72 | raise Exception("Unexpected ENABLE success (FT without nas_identifier)") | |
1728a2e7 | 73 | hostapd.remove_bss(apdev[0]) |
a85bde82 JM |
74 | |
75 | # Hotspot 2.0 without WPA2/CCMP | |
76 | params = hostapd.wpa2_params(ssid="foo") | |
77 | params['wpa_key_mgmt'] = "WPA-EAP" | |
78 | params['ieee8021x'] = "1" | |
79 | params['auth_server_addr'] = "127.0.0.1" | |
80 | params['auth_server_port'] = "1812" | |
81 | params['auth_server_shared_secret'] = "radius" | |
82 | params['interworking'] = "1" | |
83 | params['hs20'] = "1" | |
84 | params['wpa'] = "1" | |
41ba40e7 | 85 | hapd = hostapd.add_ap(apdev[0], params, no_enable=True) |
a85bde82 JM |
86 | if "FAIL" not in hapd.request("ENABLE"): |
87 | raise Exception("Unexpected ENABLE success (HS 2.0 without WPA2/CCMP)") | |
1728a2e7 | 88 | hostapd.remove_bss(apdev[0]) |
eb89361b JM |
89 | |
90 | def test_ap_config_reload(dev, apdev, params): | |
91 | """hostapd configuration reload""" | |
fab49f61 | 92 | hapd = hostapd.add_ap(apdev[0], {"ssid": "foo"}) |
eb89361b JM |
93 | hapd.set("ssid", "foobar") |
94 | with open(os.path.join(params['logdir'], 'hostapd-test.pid'), "r") as f: | |
95 | pid = int(f.read()) | |
96 | os.kill(pid, signal.SIGHUP) | |
97 | time.sleep(0.1) | |
98 | dev[0].connect("foobar", key_mgmt="NONE", scan_freq="2412") | |
99 | hapd.set("ssid", "foo") | |
100 | os.kill(pid, signal.SIGHUP) | |
101 | dev[0].wait_disconnected() | |
102 | dev[0].request("DISCONNECT") | |
103 | ||
104 | def test_ap_config_reload_file(dev, apdev, params): | |
105 | """hostapd configuration reload from file""" | |
106 | hapd = hostapd.add_iface(apdev[0], "bss-1.conf") | |
107 | hapd.enable() | |
108 | hapd.set("ssid", "foobar") | |
109 | with open(os.path.join(params['logdir'], 'hostapd-test.pid'), "r") as f: | |
110 | pid = int(f.read()) | |
111 | os.kill(pid, signal.SIGHUP) | |
112 | time.sleep(0.1) | |
113 | dev[0].connect("foobar", key_mgmt="NONE", scan_freq="2412") | |
114 | hapd.set("ssid", "foo") | |
115 | os.kill(pid, signal.SIGHUP) | |
116 | dev[0].wait_disconnected() | |
117 | dev[0].request("DISCONNECT") | |
118 | ||
544b5a0d JM |
119 | def test_ap_config_reload_file_while_disabled(dev, apdev, params): |
120 | """hostapd configuration reload from file when disabled""" | |
121 | hapd = hostapd.add_iface(apdev[0], "bss-1.conf") | |
122 | hapd.enable() | |
123 | ev = hapd.wait_event(["AP-ENABLED"], timeout=3) | |
124 | if ev is None: | |
125 | raise Exception("AP-ENABLED event not reported") | |
126 | hapd.set("ssid", "foobar") | |
127 | with open(os.path.join(params['logdir'], 'hostapd-test.pid'), "r") as f: | |
128 | pid = int(f.read()) | |
129 | hapd.disable() | |
130 | ev = hapd.wait_event(["AP-DISABLED"], timeout=3) | |
131 | if ev is None: | |
132 | raise Exception("AP-DISABLED event not reported") | |
133 | hapd.dump_monitor() | |
134 | os.kill(pid, signal.SIGHUP) | |
135 | time.sleep(0.1) | |
136 | hapd.enable() | |
137 | dev[0].connect("foobar", key_mgmt="NONE", scan_freq="2412") | |
138 | ||
381523ec | 139 | def write_hostapd_config(conffile, ifname, ssid, ht=True, bss2=False): |
20a09e08 JM |
140 | with open(conffile, "w") as f: |
141 | f.write("driver=nl80211\n") | |
142 | f.write("hw_mode=g\n") | |
143 | f.write("channel=1\n") | |
9a0c472f JM |
144 | if ht: |
145 | f.write("ieee80211n=1\n") | |
20a09e08 JM |
146 | f.write("interface=" + ifname + "\n") |
147 | f.write("ssid=" + ssid + "\n") | |
381523ec JM |
148 | if bss2: |
149 | f.write("bss=" + ifname + "_2\n") | |
150 | f.write("ssid=" + ssid + "-2\n") | |
20a09e08 JM |
151 | |
152 | def test_ap_config_reload_on_sighup(dev, apdev, params): | |
153 | """hostapd configuration reload modification from file on SIGHUP""" | |
9a0c472f JM |
154 | run_ap_config_reload_on_sighup(dev, apdev, params) |
155 | ||
156 | def test_ap_config_reload_on_sighup_no_ht(dev, apdev, params): | |
157 | """hostapd configuration reload modification from file on SIGHUP (no HT)""" | |
158 | run_ap_config_reload_on_sighup(dev, apdev, params, ht=False) | |
159 | ||
160 | def run_ap_config_reload_on_sighup(dev, apdev, params, ht=True): | |
161 | name = "ap_config_reload_on_sighup" | |
162 | if not ht: | |
163 | name += "_no_ht" | |
164 | pidfile = os.path.join(params['logdir'], name + "-hostapd.pid") | |
165 | logfile = os.path.join(params['logdir'], name + "-hostapd-log") | |
e0534658 | 166 | conffile = os.path.join(os.getcwd(), params['logdir'], |
9a0c472f | 167 | name + "-hostapd.conf") |
20a09e08 JM |
168 | prg = os.path.join(params['logdir'], 'alt-hostapd/hostapd/hostapd') |
169 | if not os.path.exists(prg): | |
170 | prg = '../../hostapd/hostapd' | |
9a0c472f | 171 | write_hostapd_config(conffile, apdev[0]['ifname'], "test-1", ht=ht) |
fab49f61 | 172 | cmd = [prg, '-B', '-dddt', '-P', pidfile, '-f', logfile, conffile] |
20a09e08 JM |
173 | res = subprocess.check_call(cmd) |
174 | if res != 0: | |
175 | raise Exception("Could not start hostapd: %s" % str(res)) | |
176 | ||
177 | dev[0].connect("test-1", key_mgmt="NONE", scan_freq="2412") | |
178 | dev[0].request("REMOVE_NETWORK all") | |
179 | dev[0].wait_disconnected() | |
180 | ||
9a0c472f | 181 | write_hostapd_config(conffile, apdev[0]['ifname'], "test-2", ht=ht) |
20a09e08 JM |
182 | with open(pidfile, "r") as f: |
183 | pid = int(f.read()) | |
184 | os.kill(pid, signal.SIGHUP) | |
185 | ||
9a0c472f JM |
186 | time.sleep(0.1) |
187 | dev[0].flush_scan_cache() | |
188 | ||
20a09e08 | 189 | dev[0].connect("test-2", key_mgmt="NONE", scan_freq="2412") |
9a0c472f | 190 | bss = dev[0].get_bss(apdev[0]['bssid']) |
20a09e08 JM |
191 | dev[0].request("REMOVE_NETWORK all") |
192 | dev[0].wait_disconnected() | |
193 | ||
194 | os.kill(pid, signal.SIGTERM) | |
195 | removed = False | |
196 | for i in range(20): | |
197 | time.sleep(0.1) | |
198 | if not os.path.exists(pidfile): | |
199 | removed = True | |
200 | break | |
201 | if not removed: | |
202 | raise Exception("hostapd PID file not removed on SIGTERM") | |
203 | ||
9a0c472f JM |
204 | if ht and "dd180050f202" not in bss['ie']: |
205 | raise Exception("Missing WMM IE after reload") | |
206 | if not ht and "dd180050f202" in bss['ie']: | |
207 | raise Exception("Unexpected WMM IE after reload") | |
208 | ||
381523ec JM |
209 | def test_ap_config_reload_on_sighup_bss_changes(dev, apdev, params): |
210 | """hostapd configuration reload modification from file on SIGHUP with bss remove/add""" | |
211 | name = "ap_config_reload_on_sighup_bss_changes" | |
212 | pidfile = os.path.join(params['logdir'], name + "-hostapd.pid") | |
213 | logfile = os.path.join(params['logdir'], name + "-hostapd-log") | |
214 | conffile = os.path.join(os.getcwd(), params['logdir'], | |
215 | name + "-hostapd.conf") | |
216 | prg = os.path.join(params['logdir'], 'alt-hostapd/hostapd/hostapd') | |
217 | if not os.path.exists(prg): | |
218 | prg = '../../hostapd/hostapd' | |
219 | write_hostapd_config(conffile, apdev[0]['ifname'], "test", bss2=True) | |
fab49f61 | 220 | cmd = [prg, '-B', '-dddt', '-P', pidfile, '-f', logfile, conffile] |
381523ec JM |
221 | res = subprocess.check_call(cmd) |
222 | if res != 0: | |
223 | raise Exception("Could not start hostapd: %s" % str(res)) | |
224 | ||
225 | dev[0].connect("test", key_mgmt="NONE", scan_freq="2412", | |
226 | wait_connect=False) | |
227 | dev[1].connect("test-2", key_mgmt="NONE", scan_freq="2412") | |
228 | dev[0].wait_connected() | |
229 | dev[0].request("REMOVE_NETWORK all") | |
230 | dev[1].request("REMOVE_NETWORK all") | |
231 | dev[0].wait_disconnected() | |
232 | dev[1].wait_disconnected() | |
233 | dev[0].dump_monitor() | |
234 | dev[1].dump_monitor() | |
235 | ||
236 | write_hostapd_config(conffile, apdev[0]['ifname'], "test-a", bss2=False) | |
237 | with open(pidfile, "r") as f: | |
238 | pid = int(f.read()) | |
239 | os.kill(pid, signal.SIGHUP) | |
240 | ||
241 | time.sleep(0.5) | |
242 | dev[0].flush_scan_cache() | |
243 | ||
244 | dev[0].connect("test-a", key_mgmt="NONE", scan_freq="2412") | |
245 | dev[0].request("REMOVE_NETWORK all") | |
246 | dev[0].wait_disconnected() | |
247 | dev[0].dump_monitor() | |
248 | ||
249 | write_hostapd_config(conffile, apdev[0]['ifname'], "test-b", bss2=True) | |
250 | os.kill(pid, signal.SIGHUP) | |
251 | ||
252 | time.sleep(0.5) | |
253 | dev[0].flush_scan_cache() | |
254 | dev[1].flush_scan_cache() | |
255 | ||
256 | dev[0].connect("test-b", key_mgmt="NONE", scan_freq="2412", | |
257 | wait_connect=False) | |
258 | dev[1].connect("test-b-2", key_mgmt="NONE", scan_freq="2412") | |
259 | dev[0].wait_connected() | |
260 | dev[0].request("REMOVE_NETWORK all") | |
261 | dev[1].request("REMOVE_NETWORK all") | |
262 | dev[0].wait_disconnected() | |
263 | dev[1].wait_disconnected() | |
264 | dev[0].dump_monitor() | |
265 | dev[1].dump_monitor() | |
266 | ||
267 | os.kill(pid, signal.SIGTERM) | |
268 | ||
eb89361b JM |
269 | def test_ap_config_reload_before_enable(dev, apdev, params): |
270 | """hostapd configuration reload before enable""" | |
271 | hapd = hostapd.add_iface(apdev[0], "bss-1.conf") | |
272 | with open(os.path.join(params['logdir'], 'hostapd-test.pid'), "r") as f: | |
273 | pid = int(f.read()) | |
274 | os.kill(pid, signal.SIGHUP) | |
275 | hapd.ping() | |
412a70c1 | 276 | |
f3569aba JM |
277 | def test_ap_config_sigusr1(dev, apdev, params): |
278 | """hostapd SIGUSR1""" | |
fab49f61 | 279 | hapd = hostapd.add_ap(apdev[0], {"ssid": "foobar"}) |
f3569aba JM |
280 | with open(os.path.join(params['logdir'], 'hostapd-test.pid'), "r") as f: |
281 | pid = int(f.read()) | |
282 | os.kill(pid, signal.SIGUSR1) | |
283 | dev[0].connect("foobar", key_mgmt="NONE", scan_freq="2412") | |
284 | os.kill(pid, signal.SIGUSR1) | |
285 | ||
412a70c1 JM |
286 | def test_ap_config_invalid_value(dev, apdev, params): |
287 | """Ignoring invalid hostapd configuration parameter updates""" | |
fab49f61 | 288 | hapd = hostapd.add_ap(apdev[0], {"ssid": "test"}, no_enable=True) |
412a70c1 | 289 | not_exist = "/tmp/hostapd-test/does-not-exist" |
fab49f61 JM |
290 | tests = [("driver", "foobar"), |
291 | ("ssid2", "Q"), | |
292 | ("macaddr_acl", "255"), | |
293 | ("accept_mac_file", not_exist), | |
294 | ("deny_mac_file", not_exist), | |
295 | ("eapol_version", "255"), | |
296 | ("eap_user_file", not_exist), | |
297 | ("wep_key_len_broadcast", "-1"), | |
298 | ("wep_key_len_unicast", "-1"), | |
299 | ("wep_rekey_period", "-1"), | |
300 | ("eap_rekey_period", "-1"), | |
301 | ("radius_client_addr", "foo"), | |
302 | ("acs_chan_bias", "-1:0.8"), | |
303 | ("acs_chan_bias", "1"), | |
304 | ("acs_chan_bias", "1:p"), | |
305 | ("acs_chan_bias", "1:-0.8"), | |
306 | ("acs_chan_bias", "1:0.8p"), | |
307 | ("dtim_period", "0"), | |
308 | ("bss_load_update_period", "-1"), | |
309 | ("send_probe_response", "255"), | |
310 | ("beacon_rate", "ht:-1"), | |
311 | ("beacon_rate", "ht:32"), | |
312 | ("beacon_rate", "vht:-1"), | |
313 | ("beacon_rate", "vht:10"), | |
314 | ("beacon_rate", "9"), | |
315 | ("beacon_rate", "10001"), | |
316 | ("vlan_file", not_exist), | |
317 | ("bss", ""), | |
318 | ("bssid", "foo"), | |
319 | ("extra_cred", not_exist), | |
320 | ("anqp_elem", "265"), | |
321 | ("anqp_elem", "265"), | |
322 | ("anqp_elem", "265:1"), | |
323 | ("anqp_elem", "265:1q"), | |
324 | ("fst_priority", ""), | |
325 | ("fils_cache_id", "q"), | |
c805a7ae JM |
326 | ("venue_url", "foo"), |
327 | ("venue_url", "1:" + 255*"a"), | |
fab49f61 | 328 | ("unknown-item", "foo")] |
412a70c1 JM |
329 | for field, val in tests: |
330 | if "FAIL" not in hapd.request("SET %s %s" % (field, val)): | |
331 | raise Exception("Invalid %s accepted" % field) | |
332 | hapd.enable() | |
333 | dev[0].connect("test", key_mgmt="NONE", scan_freq="2412") | |
a4d744fe JM |
334 | |
335 | def test_ap_config_eap_user_file_parsing(dev, apdev, params): | |
336 | """hostapd eap_user_file parsing""" | |
95b493dc | 337 | tmp = os.path.join(params['logdir'], 'ap_config_eap_user_file_parsing.tmp') |
fab49f61 | 338 | hapd = hostapd.add_ap(apdev[0], {"ssid": "foobar"}) |
a4d744fe JM |
339 | |
340 | for i in range(2): | |
341 | if "OK" not in hapd.request("SET eap_user_file auth_serv/eap_user.conf"): | |
342 | raise Exception("eap_user_file rejected") | |
343 | ||
fab49f61 JM |
344 | tests = ["#\n\n*\tTLS\nradius_accept_attr=:", |
345 | "foo\n", | |
346 | "\"foo\n", | |
347 | "\"foo\"\n", | |
348 | "\"foo\" FOOBAR\n", | |
349 | "\"foo\" " + 10*"TLS," + "TLS \"\n", | |
350 | "\"foo\" TLS \nfoo\n", | |
351 | "\"foo\" PEAP hash:foo\n", | |
352 | "\"foo\" PEAP hash:8846f7eaee8fb117ad06bdd830b7586q\n", | |
353 | "\"foo\" PEAP 01020\n", | |
95b493dc JM |
354 | "\"foo\" PEAP 010q\n" |
355 | '"pwd" PWD ssha1:\n', | |
356 | '"pwd" PWD ssha1:' + 20*'00' + '\n', | |
357 | '"pwd" PWD ssha256:\n', | |
358 | '"pwd" PWD ssha512:\n', | |
359 | '"pwd" PWD ssha1:' + 20*'00' + 'qq\n', | |
360 | '"pwd" PWD ssha1:' + 19*'00' + 'qq00\n', | |
fab49f61 JM |
361 | "\"foo\" TLS\nradius_accept_attr=123:x:012\n", |
362 | "\"foo\" TLS\nradius_accept_attr=123:x:012q\n", | |
363 | "\"foo\" TLS\nradius_accept_attr=123:Q:01\n", | |
364 | "\"foo\" TLS\nradius_accept_attr=123\nfoo\n"] | |
a4d744fe JM |
365 | for t in tests: |
366 | with open(tmp, "w") as f: | |
367 | f.write(t) | |
368 | if "FAIL" not in hapd.request("SET eap_user_file " + tmp): | |
369 | raise Exception("Invalid eap_user_file accepted") | |
370 | ||
fab49f61 JM |
371 | tests = [("\"foo\" TLS\n", 2, "hostapd_config_read_eap_user"), |
372 | ("\"foo\" PEAP \"foo\"\n", 3, "hostapd_config_read_eap_user"), | |
373 | ("\"foo\" PEAP hash:8846f7eaee8fb117ad06bdd830b75861\n", 3, | |
374 | "hostapd_config_read_eap_user"), | |
375 | ("\"foo\" PEAP 0102\n", 3, "hostapd_config_read_eap_user"), | |
376 | ("\"foo\" TLS\nradius_accept_attr=123\n", 1, | |
377 | "=hostapd_parse_radius_attr"), | |
378 | ("\"foo\" TLS\nradius_accept_attr=123\n", 1, | |
379 | "wpabuf_alloc;hostapd_parse_radius_attr"), | |
380 | ("\"foo\" TLS\nradius_accept_attr=123:s:foo\n", 2, | |
381 | "hostapd_parse_radius_attr"), | |
382 | ("\"foo\" TLS\nradius_accept_attr=123:x:0102\n", 2, | |
383 | "hostapd_parse_radius_attr"), | |
384 | ("\"foo\" TLS\nradius_accept_attr=123:d:1\n", 2, | |
385 | "hostapd_parse_radius_attr"), | |
95b493dc JM |
386 | ('"pwd" PWD ssha1:046239e0660a59015231082a071c803e9f5848ae42eaccb4c08c97ae397bc879c4b071b9088ee715\n', 1, "hostapd_config_eap_user_salted"), |
387 | ('"pwd" PWD ssha1:046239e0660a59015231082a071c803e9f5848ae42eaccb4c08c97ae397bc879c4b071b9088ee715\n', 2, "hostapd_config_eap_user_salted"), | |
fab49f61 | 388 | ("* TLS\n", 1, "hostapd_config_read_eap_user")] |
a4d744fe JM |
389 | for t, count, func in tests: |
390 | with alloc_fail(hapd, count, func): | |
391 | with open(tmp, "w") as f: | |
392 | f.write(t) | |
393 | if "FAIL" not in hapd.request("SET eap_user_file " + tmp): | |
394 | raise Exception("eap_user_file accepted during OOM") | |
cedca7d0 JM |
395 | |
396 | def test_ap_config_set_oom(dev, apdev): | |
397 | """hostapd configuration parsing OOM""" | |
fab49f61 JM |
398 | hapd = hostapd.add_ap(apdev[0], {"ssid": "foobar"}) |
399 | ||
400 | tests = [(1, "hostapd_parse_das_client", | |
401 | "SET radius_das_client 192.168.1.123 pw"), | |
402 | (1, "hostapd_config_read_wep", "SET wep_key0 \"hello\""), | |
403 | (1, "hostapd_config_read_wep", "SET wep_key0 0102030405"), | |
404 | (1, "hostapd_parse_chanlist", "SET chanlist 1 6 11-13"), | |
405 | (1, "hostapd_config_bss", "SET bss foo"), | |
406 | (2, "hostapd_config_bss", "SET bss foo"), | |
407 | (3, "hostapd_config_bss", "SET bss foo"), | |
408 | (1, "add_r0kh", | |
409 | "SET r0kh 02:01:02:03:04:05 r0kh-1.example.com 000102030405060708090a0b0c0d0e0f"), | |
410 | (1, "add_r1kh", | |
411 | "SET r1kh 02:01:02:03:04:05 02:11:22:33:44:55 000102030405060708090a0b0c0d0e0f"), | |
412 | (1, "parse_roaming_consortium", "SET roaming_consortium 021122"), | |
413 | (1, "parse_lang_string", "SET venue_name eng:Example venue"), | |
414 | (1, "parse_3gpp_cell_net", | |
415 | "SET anqp_3gpp_cell_net 244,91;310,026;234,56"), | |
416 | (1, "parse_nai_realm", "SET nai_realm 0,example.com;example.net"), | |
417 | (2, "parse_nai_realm", "SET nai_realm 0,example.com;example.net"), | |
418 | (1, "parse_anqp_elem", "SET anqp_elem 265:0000"), | |
419 | (2, "parse_anqp_elem", "SET anqp_elem 266:000000"), | |
c805a7ae | 420 | (1, "parse_venue_url", "SET venue_url 1:http://example.com/"), |
fab49f61 JM |
421 | (1, "hs20_parse_conn_capab", "SET hs20_conn_capab 1:0:2"), |
422 | (1, "hs20_parse_wan_metrics", | |
423 | "SET hs20_wan_metrics 01:8000:1000:80:240:3000"), | |
424 | (1, "hs20_parse_icon", | |
425 | "SET hs20_icon 32:32:eng:image/png:icon32:/tmp/icon32.png"), | |
426 | (1, "hs20_parse_osu_server_uri", | |
427 | "SET osu_server_uri https://example.com/osu/"), | |
428 | (1, "hostapd_config_parse_acs_chan_bias", | |
429 | "SET acs_chan_bias 1:0.8 6:0.8 11:0.8"), | |
430 | (2, "hostapd_config_parse_acs_chan_bias", | |
431 | "SET acs_chan_bias 1:0.8 6:0.8 11:0.8"), | |
432 | (1, "parse_wpabuf_hex", "SET vendor_elements 01020304"), | |
433 | (1, "parse_fils_realm", "SET fils_realm example.com"), | |
434 | (1, "hostapd_config_fill", | |
435 | "SET pac_opaque_encr_key 000102030405060708090a0b0c0d0e0f"), | |
436 | (1, "hostapd_config_fill", "SET eap_message hello"), | |
437 | (1, "hostapd_config_fill", | |
438 | "SET wpa_psk 0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef"), | |
439 | (1, "hostapd_config_fill", "SET time_zone EST5"), | |
440 | (1, "hostapd_config_fill", | |
441 | "SET network_auth_type 02http://www.example.com/redirect/"), | |
442 | (1, "hostapd_config_fill", "SET domain_name example.com"), | |
443 | (1, "hostapd_config_fill", "SET hs20_operating_class 5173"), | |
444 | (1, "hostapd_config_fill", "SET own_ie_override 11223344"), | |
445 | (1, "hostapd_parse_intlist", "SET sae_groups 19 25"), | |
446 | (1, "hostapd_parse_intlist", "SET basic_rates 10 20 55 110"), | |
447 | (1, "hostapd_parse_intlist", "SET supported_rates 10 20 55 110")] | |
cedca7d0 JM |
448 | for count, func, cmd in tests: |
449 | with alloc_fail(hapd, count, func): | |
450 | if "FAIL" not in hapd.request(cmd): | |
451 | raise Exception("Command accepted during OOM: " + cmd) | |
452 | ||
453 | hapd.set("hs20_icon", "32:32:eng:image/png:icon32:/tmp/icon32.png") | |
454 | hapd.set("hs20_conn_capab", "1:0:2") | |
455 | hapd.set("nai_realm", "0,example.com;example.net") | |
456 | hapd.set("venue_name", "eng:Example venue") | |
457 | hapd.set("roaming_consortium", "021122") | |
458 | hapd.set("osu_server_uri", "https://example.com/osu/") | |
459 | hapd.set("vendor_elements", "01020304") | |
460 | hapd.set("vendor_elements", "01020304") | |
461 | hapd.set("vendor_elements", "") | |
462 | hapd.set("lci", "11223344") | |
463 | hapd.set("civic", "11223344") | |
464 | hapd.set("lci", "") | |
465 | hapd.set("civic", "") | |
466 | ||
fab49f61 JM |
467 | tests = [(1, "hs20_parse_icon", |
468 | "SET hs20_icon 32:32:eng:image/png:icon32:/tmp/icon32.png"), | |
469 | (1, "parse_roaming_consortium", "SET roaming_consortium 021122"), | |
470 | (2, "parse_nai_realm", "SET nai_realm 0,example.com;example.net"), | |
471 | (1, "parse_lang_string", "SET venue_name eng:Example venue"), | |
472 | (1, "hs20_parse_osu_server_uri", | |
473 | "SET osu_server_uri https://example.com/osu/"), | |
474 | (1, "hs20_parse_osu_nai", "SET osu_nai anonymous@example.com"), | |
a32f4c22 | 475 | (1, "hs20_parse_osu_nai2", "SET osu_nai2 anonymous@example.com"), |
fab49f61 JM |
476 | (1, "hostapd_parse_intlist", "SET osu_method_list 1 0"), |
477 | (1, "hs20_parse_osu_icon", "SET osu_icon icon32"), | |
478 | (2, "hs20_parse_osu_icon", "SET osu_icon icon32"), | |
479 | (2, "hs20_parse_osu_icon", "SET osu_icon icon32"), | |
480 | (1, "hs20_parse_conn_capab", "SET hs20_conn_capab 1:0:2")] | |
cedca7d0 JM |
481 | for count, func, cmd in tests: |
482 | with alloc_fail(hapd, count, func): | |
483 | if "FAIL" not in hapd.request(cmd): | |
484 | raise Exception("Command accepted during OOM (2): " + cmd) | |
485 | ||
fab49f61 | 486 | tests = [(1, "parse_fils_realm", "SET fils_realm example.com")] |
cedca7d0 JM |
487 | for count, func, cmd in tests: |
488 | with fail_test(hapd, count, func): | |
489 | if "FAIL" not in hapd.request(cmd): | |
490 | raise Exception("Command accepted during FAIL_TEST: " + cmd) | |
491 | ||
492 | def test_ap_config_set_errors(dev, apdev): | |
493 | """hostapd configuration parsing errors""" | |
fab49f61 | 494 | hapd = hostapd.add_ap(apdev[0], {"ssid": "foobar"}) |
cedca7d0 JM |
495 | hapd.set("wep_key0", '"hello"') |
496 | hapd.set("wep_key1", '"hello"') | |
497 | hapd.set("wep_key0", '') | |
498 | hapd.set("wep_key0", '"hello"') | |
499 | if "FAIL" not in hapd.request("SET wep_key1 \"hello\""): | |
500 | raise Exception("SET wep_key1 allowed to override existing key") | |
501 | hapd.set("wep_key1", '') | |
502 | hapd.set("wep_key1", '"hello"') | |
503 | ||
504 | hapd.set("auth_server_addr", "127.0.0.1") | |
505 | hapd.set("acct_server_addr", "127.0.0.1") | |
506 | ||
fab49f61 JM |
507 | tests = ["SET eap_reauth_period -1", |
508 | "SET fst_llt ", | |
509 | "SET auth_server_addr_replace foo", | |
510 | "SET acct_server_addr_replace foo"] | |
cedca7d0 JM |
511 | for t in tests: |
512 | if "FAIL" not in hapd.request(t): | |
513 | raise Exception("Invalid command accepted: " + t) | |
514 | ||
515 | # Deprecated entries | |
516 | hapd.set("tx_queue_after_beacon_aifs", '2') | |
517 | hapd.set("tx_queue_beacon_aifs", '2') | |
518 | hapd.set("tx_queue_data9_aifs", '2') | |
519 | hapd.set("debug", '1') | |
520 | hapd.set("dump_file", '/tmp/hostapd-test-dump') | |
521 | hapd.set("eap_authenticator", '0') | |
522 | hapd.set("radio_measurements", '0') | |
523 | hapd.set("radio_measurements", '1') | |
524 | ||
525 | # Various extra coverage (not really errors) | |
526 | hapd.set("logger_syslog_level", '1') | |
527 | hapd.set("logger_syslog", '0') | |
528 | ||
529 | for i in range(50000): | |
530 | if "OK" not in hapd.request("SET hs20_conn_capab 17:5060:0"): | |
531 | logger.info("hs20_conn_capab limit at %d" % i) | |
532 | break | |
533 | if i < 1000 or i >= 49999: | |
534 | raise Exception("hs20_conn_capab limit not seen") |