3 # wpa_supplicant mesh mode tests
4 # Copyright (c) 2014, cozybit Inc.
6 # This software may be distributed under the terms of the BSD license.
7 # See README for more details.
10 logger = logging.getLogger()
14 from wpasupplicant import WpaSupplicant
15 from utils import HwsimSkip, alloc_fail
17 def check_mesh_support(dev, secure=False):
18 if "MESH" not in dev.get_capability("modes"):
19 raise HwsimSkip("Driver does not support mesh")
20 if secure and "SAE" not in dev.get_capability("auth_alg"):
21 raise HwsimSkip("SAE not supported")
23 def check_mesh_scan(dev, params, other_started=False, beacon_int=0):
26 id = dev.request("SCAN " + params)
28 raise Exception("Failed to start scan")
32 ev = dev.wait_event(["CTRL-EVENT-SCAN-STARTED"])
34 raise Exception("Other scan did not start")
35 if "id=" + str(id) in ev:
36 raise Exception("Own scan id unexpectedly included in start event")
38 ev = dev.wait_event(["CTRL-EVENT-SCAN-RESULTS"])
40 raise Exception("Other scan did not complete")
41 if "id=" + str(id) in ev:
43 "Own scan id unexpectedly included in completed event")
45 ev = dev.wait_event(["CTRL-EVENT-SCAN-STARTED"])
47 raise Exception("Scan did not start")
48 if "id=" + str(id) not in ev:
49 raise Exception("Scan id not included in start event")
51 ev = dev.wait_event(["CTRL-EVENT-SCAN-RESULTS"])
53 raise Exception("Scan did not complete")
54 if "id=" + str(id) not in ev:
55 raise Exception("Scan id not included in completed event")
57 res = dev.request("SCAN_RESULTS")
59 if res.find("[MESH]") < 0:
60 raise Exception("Scan did not contain a MESH network")
62 bssid = res.splitlines()[1].split(' ')[0]
63 bss = dev.get_bss(bssid)
65 raise Exception("Could not get BSS entry for mesh")
66 if 'mesh_capability' not in bss:
67 raise Exception("mesh_capability missing from BSS entry")
69 if 'beacon_int' not in bss:
70 raise Exception("beacon_int missing from BSS entry")
71 if str(beacon_int) != bss['beacon_int']:
72 raise Exception("Unexpected beacon_int in BSS entry: " + bss['beacon_int'])
74 def check_mesh_group_added(dev):
75 ev = dev.wait_event(["MESH-GROUP-STARTED"])
77 raise Exception("Test exception: Couldn't join mesh")
80 def check_mesh_group_removed(dev):
81 ev = dev.wait_event(["MESH-GROUP-REMOVED"])
83 raise Exception("Test exception: Couldn't leave mesh")
86 def check_mesh_peer_connected(dev, timeout=10):
87 ev = dev.wait_event(["MESH-PEER-CONNECTED"], timeout=timeout)
89 raise Exception("Test exception: Remote peer did not connect.")
92 def check_mesh_peer_disconnected(dev):
93 ev = dev.wait_event(["MESH-PEER-DISCONNECTED"])
95 raise Exception("Test exception: Peer disconnect event not detected.")
98 def test_wpas_add_set_remove_support(dev):
99 """wpa_supplicant MESH add/set/remove network support"""
100 check_mesh_support(dev[0])
101 id = dev[0].add_network()
102 dev[0].set_network(id, "mode", "5")
103 dev[0].remove_network(id)
105 def add_open_mesh_network(dev, freq="2412", start=True, beacon_int=0):
106 id = dev.add_network()
107 dev.set_network(id, "mode", "5")
108 dev.set_network_quoted(id, "ssid", "wpas-mesh-open")
109 dev.set_network(id, "key_mgmt", "NONE")
110 dev.set_network(id, "frequency", freq)
112 dev.set_network(id, "beacon_int", str(beacon_int))
114 dev.mesh_group_add(id)
117 def test_wpas_mesh_group_added(dev):
118 """wpa_supplicant MESH group add"""
119 check_mesh_support(dev[0])
120 add_open_mesh_network(dev[0])
122 # Check for MESH-GROUP-STARTED event
123 check_mesh_group_added(dev[0])
126 def test_wpas_mesh_group_remove(dev):
127 """wpa_supplicant MESH group remove"""
128 check_mesh_support(dev[0])
129 add_open_mesh_network(dev[0])
130 # Check for MESH-GROUP-STARTED event
131 check_mesh_group_added(dev[0])
132 dev[0].mesh_group_remove()
133 # Check for MESH-GROUP-REMOVED event
134 check_mesh_group_removed(dev[0])
135 dev[0].mesh_group_remove()
137 def test_wpas_mesh_peer_connected(dev):
138 """wpa_supplicant MESH peer connected"""
139 check_mesh_support(dev[0])
140 add_open_mesh_network(dev[0], beacon_int=160)
141 add_open_mesh_network(dev[1], beacon_int=160)
143 # Check for mesh joined
144 check_mesh_group_added(dev[0])
145 check_mesh_group_added(dev[1])
147 # Check for peer connected
148 check_mesh_peer_connected(dev[0])
149 check_mesh_peer_connected(dev[1])
152 def test_wpas_mesh_peer_disconnected(dev):
153 """wpa_supplicant MESH peer disconnected"""
154 check_mesh_support(dev[0])
155 add_open_mesh_network(dev[0])
156 add_open_mesh_network(dev[1])
158 # Check for mesh joined
159 check_mesh_group_added(dev[0])
160 check_mesh_group_added(dev[1])
162 # Check for peer connected
163 check_mesh_peer_connected(dev[0])
164 check_mesh_peer_connected(dev[1])
166 # Remove group on dev 1
167 dev[1].mesh_group_remove()
168 # Device 0 should get a disconnection event
169 check_mesh_peer_disconnected(dev[0])
172 def test_wpas_mesh_mode_scan(dev):
173 """wpa_supplicant MESH scan support"""
174 check_mesh_support(dev[0])
175 add_open_mesh_network(dev[0])
176 add_open_mesh_network(dev[1], beacon_int=175)
178 # Check for mesh joined
179 check_mesh_group_added(dev[0])
180 check_mesh_group_added(dev[1])
182 # Check for Mesh scan
183 check_mesh_scan(dev[0], "use_id=1", beacon_int=175)
185 def test_wpas_mesh_open(dev, apdev):
186 """wpa_supplicant open MESH network connectivity"""
187 check_mesh_support(dev[0])
188 add_open_mesh_network(dev[0], freq="2462")
189 add_open_mesh_network(dev[1], freq="2462")
191 # Check for mesh joined
192 check_mesh_group_added(dev[0])
193 check_mesh_group_added(dev[1])
195 # Check for peer connected
196 check_mesh_peer_connected(dev[0])
197 check_mesh_peer_connected(dev[1])
199 # Test connectivity 0->1 and 1->0
200 hwsim_utils.test_connectivity(dev[0], dev[1])
202 def test_wpas_mesh_open_no_auto(dev, apdev):
203 """wpa_supplicant open MESH network connectivity"""
204 check_mesh_support(dev[0])
205 id = add_open_mesh_network(dev[0], start=False)
206 dev[0].set_network(id, "dot11MeshMaxRetries", "16")
207 dev[0].set_network(id, "dot11MeshRetryTimeout", "255")
208 dev[0].mesh_group_add(id)
210 id = add_open_mesh_network(dev[1], start=False)
211 dev[1].set_network(id, "no_auto_peer", "1")
212 dev[1].mesh_group_add(id)
214 # Check for mesh joined
215 check_mesh_group_added(dev[0])
216 check_mesh_group_added(dev[1])
218 # Check for peer connected
219 check_mesh_peer_connected(dev[0], timeout=30)
220 check_mesh_peer_connected(dev[1])
222 # Test connectivity 0->1 and 1->0
223 hwsim_utils.test_connectivity(dev[0], dev[1])
225 def add_mesh_secure_net(dev, psk=True):
226 id = dev.add_network()
227 dev.set_network(id, "mode", "5")
228 dev.set_network_quoted(id, "ssid", "wpas-mesh-sec")
229 dev.set_network(id, "key_mgmt", "SAE")
230 dev.set_network(id, "frequency", "2412")
232 dev.set_network_quoted(id, "psk", "thisismypassphrase!")
235 def test_wpas_mesh_secure(dev, apdev):
236 """wpa_supplicant secure MESH network connectivity"""
237 check_mesh_support(dev[0], secure=True)
238 dev[0].request("SET sae_groups ")
239 id = add_mesh_secure_net(dev[0])
240 dev[0].mesh_group_add(id)
242 dev[1].request("SET sae_groups ")
243 id = add_mesh_secure_net(dev[1])
244 dev[1].mesh_group_add(id)
246 # Check for mesh joined
247 check_mesh_group_added(dev[0])
248 check_mesh_group_added(dev[1])
250 # Check for peer connected
251 check_mesh_peer_connected(dev[0])
252 check_mesh_peer_connected(dev[1])
254 # Test connectivity 0->1 and 1->0
255 hwsim_utils.test_connectivity(dev[0], dev[1])
257 def test_wpas_mesh_secure_sae_group_mismatch(dev, apdev):
258 """wpa_supplicant secure MESH and SAE group mismatch"""
259 check_mesh_support(dev[0], secure=True)
260 addr0 = dev[0].p2p_interface_addr()
261 addr1 = dev[1].p2p_interface_addr()
262 addr2 = dev[2].p2p_interface_addr()
264 dev[0].request("SET sae_groups 19 25")
265 id = add_mesh_secure_net(dev[0])
266 dev[0].mesh_group_add(id)
268 dev[1].request("SET sae_groups 19")
269 id = add_mesh_secure_net(dev[1])
270 dev[1].mesh_group_add(id)
272 dev[2].request("SET sae_groups 26")
273 id = add_mesh_secure_net(dev[2])
274 dev[2].mesh_group_add(id)
276 check_mesh_group_added(dev[0])
277 check_mesh_group_added(dev[1])
278 check_mesh_group_added(dev[2])
280 ev = dev[0].wait_event(["MESH-PEER-CONNECTED"])
282 raise Exception("Remote peer did not connect")
284 raise Exception("Unexpected peer connected: " + ev)
286 ev = dev[1].wait_event(["MESH-PEER-CONNECTED"])
288 raise Exception("Remote peer did not connect")
290 raise Exception("Unexpected peer connected: " + ev)
292 ev = dev[2].wait_event(["MESH-PEER-CONNECTED"], timeout=1)
294 raise Exception("Unexpected peer connection at dev[2]: " + ev)
296 ev = dev[0].wait_event(["MESH-PEER-CONNECTED"], timeout=0.1)
298 raise Exception("Unexpected peer connection: " + ev)
300 ev = dev[1].wait_event(["MESH-PEER-CONNECTED"], timeout=0.1)
302 raise Exception("Unexpected peer connection: " + ev)
304 dev[0].request("SET sae_groups ")
305 dev[1].request("SET sae_groups ")
306 dev[2].request("SET sae_groups ")
308 def test_wpas_mesh_secure_sae_missing_password(dev, apdev):
309 """wpa_supplicant secure MESH and missing SAE password"""
310 check_mesh_support(dev[0], secure=True)
311 id = add_mesh_secure_net(dev[0], psk=False)
312 dev[0].set_network(id, "psk", "8f20b381f9b84371d61b5080ad85cac3c61ab3ca9525be5b2d0f4da3d979187a")
313 dev[0].mesh_group_add(id)
314 ev = dev[0].wait_event(["MESH-GROUP-STARTED", "Could not join mesh"],
317 raise Exception("Timeout on mesh start event")
318 if "MESH-GROUP-STARTED" in ev:
319 raise Exception("Unexpected mesh group start")
320 ev = dev[0].wait_event(["MESH-GROUP-STARTED"], timeout=0.1)
322 raise Exception("Unexpected mesh group start")
324 def test_wpas_mesh_secure_no_auto(dev, apdev):
325 """wpa_supplicant secure MESH network connectivity"""
326 check_mesh_support(dev[0], secure=True)
327 dev[0].request("SET sae_groups 19")
328 id = add_mesh_secure_net(dev[0])
329 dev[0].mesh_group_add(id)
331 dev[1].request("SET sae_groups 19")
332 id = add_mesh_secure_net(dev[1])
333 dev[1].set_network(id, "no_auto_peer", "1")
334 dev[1].mesh_group_add(id)
336 # Check for mesh joined
337 check_mesh_group_added(dev[0])
338 check_mesh_group_added(dev[1])
340 # Check for peer connected
341 check_mesh_peer_connected(dev[0], timeout=30)
342 check_mesh_peer_connected(dev[1])
344 # Test connectivity 0->1 and 1->0
345 hwsim_utils.test_connectivity(dev[0], dev[1])
347 dev[0].request("SET sae_groups ")
348 dev[1].request("SET sae_groups ")
350 def test_wpas_mesh_ctrl(dev):
351 """wpa_supplicant ctrl_iface mesh command error cases"""
352 check_mesh_support(dev[0])
353 if "FAIL" not in dev[0].request("MESH_GROUP_ADD 123"):
354 raise Exception("Unexpected MESH_GROUP_ADD success")
355 id = dev[0].add_network()
356 if "FAIL" not in dev[0].request("MESH_GROUP_ADD %d" % id):
357 raise Exception("Unexpected MESH_GROUP_ADD success")
358 dev[0].set_network(id, "mode", "5")
359 dev[0].set_network(id, "key_mgmt", "WPA-PSK")
360 if "FAIL" not in dev[0].request("MESH_GROUP_ADD %d" % id):
361 raise Exception("Unexpected MESH_GROUP_ADD success")
363 if "FAIL" not in dev[0].request("MESH_GROUP_REMOVE foo"):
364 raise Exception("Unexpected MESH_GROUP_REMOVE success")
366 def test_wpas_mesh_dynamic_interface(dev):
367 """wpa_supplicant mesh with dynamic interface"""
368 check_mesh_support(dev[0])
372 mesh0 = dev[0].request("MESH_INTERFACE_ADD ifname=mesh0")
374 raise Exception("MESH_INTERFACE_ADD failed")
375 mesh1 = dev[1].request("MESH_INTERFACE_ADD")
377 raise Exception("MESH_INTERFACE_ADD failed")
379 wpas0 = WpaSupplicant(ifname=mesh0)
380 wpas1 = WpaSupplicant(ifname=mesh1)
381 logger.info(mesh0 + " address " + wpas0.get_status_field("address"))
382 logger.info(mesh1 + " address " + wpas1.get_status_field("address"))
384 add_open_mesh_network(wpas0)
385 add_open_mesh_network(wpas1)
386 check_mesh_group_added(wpas0)
387 check_mesh_group_added(wpas1)
388 check_mesh_peer_connected(wpas0)
389 check_mesh_peer_connected(wpas1)
390 hwsim_utils.test_connectivity(wpas0, wpas1)
392 # Must not allow MESH_GROUP_REMOVE on dynamic interface
393 if "FAIL" not in wpas0.request("MESH_GROUP_REMOVE " + mesh0):
394 raise Exception("Invalid MESH_GROUP_REMOVE accepted")
395 if "FAIL" not in wpas1.request("MESH_GROUP_REMOVE " + mesh1):
396 raise Exception("Invalid MESH_GROUP_REMOVE accepted")
398 # Must not allow MESH_GROUP_REMOVE on another radio interface
399 if "FAIL" not in wpas0.request("MESH_GROUP_REMOVE " + mesh1):
400 raise Exception("Invalid MESH_GROUP_REMOVE accepted")
401 if "FAIL" not in wpas1.request("MESH_GROUP_REMOVE " + mesh0):
402 raise Exception("Invalid MESH_GROUP_REMOVE accepted")
404 wpas0.remove_ifname()
405 wpas1.remove_ifname()
407 if "OK" not in dev[0].request("MESH_GROUP_REMOVE " + mesh0):
408 raise Exception("MESH_GROUP_REMOVE failed")
409 if "OK" not in dev[1].request("MESH_GROUP_REMOVE " + mesh1):
410 raise Exception("MESH_GROUP_REMOVE failed")
412 if "FAIL" not in dev[0].request("MESH_GROUP_REMOVE " + mesh0):
413 raise Exception("Invalid MESH_GROUP_REMOVE accepted")
414 if "FAIL" not in dev[1].request("MESH_GROUP_REMOVE " + mesh1):
415 raise Exception("Invalid MESH_GROUP_REMOVE accepted")
417 logger.info("Make sure another dynamic group can be added")
418 mesh0 = dev[0].request("MESH_INTERFACE_ADD ifname=mesh0")
420 raise Exception("MESH_INTERFACE_ADD failed")
421 mesh1 = dev[1].request("MESH_INTERFACE_ADD")
423 raise Exception("MESH_INTERFACE_ADD failed")
425 wpas0 = WpaSupplicant(ifname=mesh0)
426 wpas1 = WpaSupplicant(ifname=mesh1)
427 logger.info(mesh0 + " address " + wpas0.get_status_field("address"))
428 logger.info(mesh1 + " address " + wpas1.get_status_field("address"))
430 add_open_mesh_network(wpas0)
431 add_open_mesh_network(wpas1)
432 check_mesh_group_added(wpas0)
433 check_mesh_group_added(wpas1)
434 check_mesh_peer_connected(wpas0)
435 check_mesh_peer_connected(wpas1)
436 hwsim_utils.test_connectivity(wpas0, wpas1)
439 dev[0].request("MESH_GROUP_REMOVE " + mesh0)
441 dev[1].request("MESH_GROUP_REMOVE " + mesh1)
443 def test_wpas_mesh_max_peering(dev, apdev):
444 """Mesh max peering limit"""
445 check_mesh_support(dev[0])
447 dev[0].request("SET max_peer_links 1")
449 # first, connect dev[0] and dev[1]
450 add_open_mesh_network(dev[0])
451 add_open_mesh_network(dev[1])
453 ev = dev[i].wait_event(["MESH-PEER-CONNECTED"])
455 raise Exception("dev%d did not connect with any peer" % i)
457 # add dev[2] which will try to connect with both dev[0] and dev[1],
458 # but can complete connection only with dev[1]
459 add_open_mesh_network(dev[2])
460 for i in range(1, 3):
461 ev = dev[i].wait_event(["MESH-PEER-CONNECTED"])
463 raise Exception("dev%d did not connect the second peer" % i)
465 ev = dev[0].wait_event(["MESH-PEER-CONNECTED"], timeout=1)
467 raise Exception("dev0 connection beyond max peering limit")
469 ev = dev[2].wait_event(["MESH-PEER-CONNECTED"], timeout=0.1)
471 raise Exception("dev2 reported unexpected peering: " + ev)
474 dev[i].mesh_group_remove()
475 check_mesh_group_removed(dev[i])
477 dev[0].request("SET max_peer_links 99")
479 def test_wpas_mesh_open_5ghz(dev, apdev):
480 """wpa_supplicant open MESH network on 5 GHz band"""
482 _test_wpas_mesh_open_5ghz(dev, apdev)
484 subprocess.call(['iw', 'reg', 'set', '00'])
485 dev[0].flush_scan_cache()
486 dev[1].flush_scan_cache()
488 def _test_wpas_mesh_open_5ghz(dev, apdev):
489 check_mesh_support(dev[0])
490 subprocess.call(['iw', 'reg', 'set', 'US'])
493 ev = dev[i].wait_event(["CTRL-EVENT-REGDOM-CHANGE"], timeout=5)
495 raise Exception("No regdom change event")
496 if "alpha2=US" in ev:
498 add_open_mesh_network(dev[i], freq="5180")
500 # Check for mesh joined
501 check_mesh_group_added(dev[0])
502 check_mesh_group_added(dev[1])
504 # Check for peer connected
505 check_mesh_peer_connected(dev[0])
506 check_mesh_peer_connected(dev[1])
508 # Test connectivity 0->1 and 1->0
509 hwsim_utils.test_connectivity(dev[0], dev[1])
511 def test_wpas_mesh_password_mismatch(dev, apdev):
512 """Mesh network and one device with mismatching password"""
513 check_mesh_support(dev[0], secure=True)
514 dev[0].request("SET sae_groups ")
515 id = add_mesh_secure_net(dev[0])
516 dev[0].mesh_group_add(id)
518 dev[1].request("SET sae_groups ")
519 id = add_mesh_secure_net(dev[1])
520 dev[1].mesh_group_add(id)
522 dev[2].request("SET sae_groups ")
523 id = add_mesh_secure_net(dev[2])
524 dev[2].set_network_quoted(id, "psk", "wrong password")
525 dev[2].mesh_group_add(id)
527 # The two peers with matching password need to be able to connect
528 check_mesh_group_added(dev[0])
529 check_mesh_group_added(dev[1])
530 check_mesh_peer_connected(dev[0])
531 check_mesh_peer_connected(dev[1])
533 ev = dev[2].wait_event(["MESH-SAE-AUTH-FAILURE"], timeout=20)
535 raise Exception("dev2 did not report auth failure (1)")
536 ev = dev[2].wait_event(["MESH-SAE-AUTH-FAILURE"], timeout=20)
538 raise Exception("dev2 did not report auth failure (2)")
541 ev = dev[0].wait_event(["MESH-SAE-AUTH-FAILURE"], timeout=1)
543 logger.info("dev0 did not report auth failure")
545 if "addr=" + dev[2].own_addr() not in ev:
546 raise Exception("Unexpected peer address in dev0 event: " + ev)
549 ev = dev[1].wait_event(["MESH-SAE-AUTH-FAILURE"], timeout=1)
551 logger.info("dev1 did not report auth failure")
553 if "addr=" + dev[2].own_addr() not in ev:
554 raise Exception("Unexpected peer address in dev1 event: " + ev)
557 hwsim_utils.test_connectivity(dev[0], dev[1])
561 hwsim_utils.test_connectivity(dev[i], dev[2], timeout=1)
562 raise Exception("Data connectivity test passed unexpectedly")
564 if "data delivery failed" not in str(e):
568 raise Exception("Neither dev0 nor dev1 reported auth failure")
570 def test_wpas_mesh_password_mismatch_retry(dev, apdev, params):
571 """Mesh password mismatch and retry [long]"""
572 if not params['long']:
573 raise HwsimSkip("Skip test case with long duration due to --long not specified")
574 check_mesh_support(dev[0], secure=True)
575 dev[0].request("SET sae_groups ")
576 id = add_mesh_secure_net(dev[0])
577 dev[0].mesh_group_add(id)
579 dev[1].request("SET sae_groups ")
580 id = add_mesh_secure_net(dev[1])
581 dev[1].set_network_quoted(id, "psk", "wrong password")
582 dev[1].mesh_group_add(id)
584 # Check for mesh joined
585 check_mesh_group_added(dev[0])
586 check_mesh_group_added(dev[1])
589 ev = dev[0].wait_event(["MESH-SAE-AUTH-FAILURE"], timeout=20)
591 raise Exception("dev0 did not report auth failure (%d)" % i)
592 ev = dev[1].wait_event(["MESH-SAE-AUTH-FAILURE"], timeout=20)
594 raise Exception("dev1 did not report auth failure (%d)" % i)
596 ev = dev[0].wait_event(["MESH-SAE-AUTH-BLOCKED"], timeout=10)
598 raise Exception("dev0 did not report auth blocked")
599 ev = dev[1].wait_event(["MESH-SAE-AUTH-BLOCKED"], timeout=10)
601 raise Exception("dev1 did not report auth blocked")
603 def test_mesh_wpa_auth_init_oom(dev, apdev):
604 """Secure mesh network setup failing due to wpa_init() OOM"""
605 check_mesh_support(dev[0], secure=True)
606 dev[0].request("SET sae_groups ")
607 with alloc_fail(dev[0], 1, "wpa_init"):
608 id = add_mesh_secure_net(dev[0])
609 dev[0].mesh_group_add(id)
610 ev = dev[0].wait_event(["MESH-GROUP-STARTED"], timeout=0.2)
612 raise Exception("Unexpected mesh group start during OOM")