1 # wpa_supplicant mesh mode tests
2 # Copyright (c) 2014, cozybit Inc.
4 # This software may be distributed under the terms of the BSD license.
5 # See README for more details.
8 logger = logging.getLogger()
14 from wpasupplicant import WpaSupplicant
15 from utils import HwsimSkip, alloc_fail, wait_fail_trigger
16 from tshark import run_tshark
18 def check_mesh_support(dev, secure=False):
19 if "MESH" not in dev.get_capability("modes"):
20 raise HwsimSkip("Driver does not support mesh")
21 if secure and "SAE" not in dev.get_capability("auth_alg"):
22 raise HwsimSkip("SAE not supported")
24 def check_mesh_scan(dev, params, other_started=False, beacon_int=0):
27 id = dev.request("SCAN " + params)
29 raise Exception("Failed to start scan")
33 ev = dev.wait_event(["CTRL-EVENT-SCAN-STARTED"])
35 raise Exception("Other scan did not start")
36 if "id=" + str(id) in ev:
37 raise Exception("Own scan id unexpectedly included in start event")
39 ev = dev.wait_event(["CTRL-EVENT-SCAN-RESULTS"])
41 raise Exception("Other scan did not complete")
42 if "id=" + str(id) in ev:
44 "Own scan id unexpectedly included in completed event")
46 ev = dev.wait_event(["CTRL-EVENT-SCAN-STARTED"])
48 raise Exception("Scan did not start")
49 if "id=" + str(id) not in ev:
50 raise Exception("Scan id not included in start event")
52 ev = dev.wait_event(["CTRL-EVENT-SCAN-RESULTS"])
54 raise Exception("Scan did not complete")
55 if "id=" + str(id) not in ev:
56 raise Exception("Scan id not included in completed event")
58 res = dev.request("SCAN_RESULTS")
60 if res.find("[MESH]") < 0:
61 raise Exception("Scan did not contain a MESH network")
63 bssid = res.splitlines()[1].split(' ')[0]
64 bss = dev.get_bss(bssid)
66 raise Exception("Could not get BSS entry for mesh")
67 if 'mesh_capability' not in bss:
68 raise Exception("mesh_capability missing from BSS entry")
70 if 'beacon_int' not in bss:
71 raise Exception("beacon_int missing from BSS entry")
72 if str(beacon_int) != bss['beacon_int']:
73 raise Exception("Unexpected beacon_int in BSS entry: " + bss['beacon_int'])
75 def check_mesh_group_added(dev):
76 ev = dev.wait_event(["MESH-GROUP-STARTED"])
78 raise Exception("Test exception: Couldn't join mesh")
81 def check_mesh_group_removed(dev):
82 ev = dev.wait_event(["MESH-GROUP-REMOVED"])
84 raise Exception("Test exception: Couldn't leave mesh")
87 def check_mesh_peer_connected(dev, timeout=10):
88 ev = dev.wait_event(["MESH-PEER-CONNECTED"], timeout=timeout)
90 raise Exception("Test exception: Remote peer did not connect.")
93 def check_mesh_peer_disconnected(dev):
94 ev = dev.wait_event(["MESH-PEER-DISCONNECTED"])
96 raise Exception("Test exception: Peer disconnect event not detected.")
99 def test_wpas_add_set_remove_support(dev):
100 """wpa_supplicant MESH add/set/remove network support"""
101 check_mesh_support(dev[0])
102 id = dev[0].add_network()
103 dev[0].set_network(id, "mode", "5")
104 dev[0].remove_network(id)
106 def add_open_mesh_network(dev, freq="2412", start=True, beacon_int=0,
107 basic_rates=None, chwidth=0):
108 id = dev.add_network()
109 dev.set_network(id, "mode", "5")
110 dev.set_network_quoted(id, "ssid", "wpas-mesh-open")
111 dev.set_network(id, "key_mgmt", "NONE")
112 dev.set_network(id, "frequency", freq)
114 dev.set_network(id, "max_oper_chwidth", str(chwidth))
116 dev.set_network(id, "beacon_int", str(beacon_int))
118 dev.set_network(id, "mesh_basic_rates", basic_rates)
120 dev.mesh_group_add(id)
123 def test_wpas_mesh_group_added(dev):
124 """wpa_supplicant MESH group add"""
125 check_mesh_support(dev[0])
126 add_open_mesh_network(dev[0])
128 # Check for MESH-GROUP-STARTED event
129 check_mesh_group_added(dev[0])
132 def test_wpas_mesh_group_remove(dev):
133 """wpa_supplicant MESH group remove"""
134 check_mesh_support(dev[0])
135 add_open_mesh_network(dev[0])
136 # Check for MESH-GROUP-STARTED event
137 check_mesh_group_added(dev[0])
138 dev[0].mesh_group_remove()
139 # Check for MESH-GROUP-REMOVED event
140 check_mesh_group_removed(dev[0])
141 dev[0].mesh_group_remove()
143 def test_wpas_mesh_peer_connected(dev):
144 """wpa_supplicant MESH peer connected"""
145 check_mesh_support(dev[0])
146 add_open_mesh_network(dev[0], beacon_int=160)
147 add_open_mesh_network(dev[1], beacon_int=160)
149 # Check for mesh joined
150 check_mesh_group_added(dev[0])
151 check_mesh_group_added(dev[1])
153 # Check for peer connected
154 check_mesh_peer_connected(dev[0])
155 check_mesh_peer_connected(dev[1])
158 def test_wpas_mesh_peer_disconnected(dev):
159 """wpa_supplicant MESH peer disconnected"""
160 check_mesh_support(dev[0])
161 add_open_mesh_network(dev[0])
162 add_open_mesh_network(dev[1])
164 # Check for mesh joined
165 check_mesh_group_added(dev[0])
166 check_mesh_group_added(dev[1])
168 # Check for peer connected
169 check_mesh_peer_connected(dev[0])
170 check_mesh_peer_connected(dev[1])
172 # Remove group on dev 1
173 dev[1].mesh_group_remove()
174 # Device 0 should get a disconnection event
175 check_mesh_peer_disconnected(dev[0])
178 def test_wpas_mesh_mode_scan(dev):
179 """wpa_supplicant MESH scan support"""
180 check_mesh_support(dev[0])
181 add_open_mesh_network(dev[0])
182 add_open_mesh_network(dev[1], beacon_int=175)
184 # Check for mesh joined
185 check_mesh_group_added(dev[0])
186 check_mesh_group_added(dev[1])
188 # Check for Mesh scan
189 check_mesh_scan(dev[0], "use_id=1", beacon_int=175)
191 def test_wpas_mesh_open(dev, apdev):
192 """wpa_supplicant open MESH network connectivity"""
193 check_mesh_support(dev[0])
194 add_open_mesh_network(dev[0], freq="2462", basic_rates="60 120 240")
195 add_open_mesh_network(dev[1], freq="2462", basic_rates="60 120 240")
197 # Check for mesh joined
198 check_mesh_group_added(dev[0])
199 check_mesh_group_added(dev[1])
201 # Check for peer connected
202 check_mesh_peer_connected(dev[0])
203 check_mesh_peer_connected(dev[1])
205 # Test connectivity 0->1 and 1->0
206 hwsim_utils.test_connectivity(dev[0], dev[1])
208 def test_wpas_mesh_open_no_auto(dev, apdev):
209 """wpa_supplicant open MESH network connectivity"""
210 check_mesh_support(dev[0])
211 id = add_open_mesh_network(dev[0], start=False)
212 dev[0].set_network(id, "dot11MeshMaxRetries", "16")
213 dev[0].set_network(id, "dot11MeshRetryTimeout", "255")
214 dev[0].mesh_group_add(id)
216 id = add_open_mesh_network(dev[1], start=False)
217 dev[1].set_network(id, "no_auto_peer", "1")
218 dev[1].mesh_group_add(id)
220 # Check for mesh joined
221 check_mesh_group_added(dev[0])
222 check_mesh_group_added(dev[1])
224 # Check for peer connected
225 check_mesh_peer_connected(dev[0], timeout=30)
226 check_mesh_peer_connected(dev[1])
228 # Test connectivity 0->1 and 1->0
229 hwsim_utils.test_connectivity(dev[0], dev[1])
231 def add_mesh_secure_net(dev, psk=True):
232 id = dev.add_network()
233 dev.set_network(id, "mode", "5")
234 dev.set_network_quoted(id, "ssid", "wpas-mesh-sec")
235 dev.set_network(id, "key_mgmt", "SAE")
236 dev.set_network(id, "frequency", "2412")
238 dev.set_network_quoted(id, "psk", "thisismypassphrase!")
241 def test_wpas_mesh_secure(dev, apdev):
242 """wpa_supplicant secure MESH network connectivity"""
243 check_mesh_support(dev[0], secure=True)
244 dev[0].request("SET sae_groups ")
245 id = add_mesh_secure_net(dev[0])
246 dev[0].mesh_group_add(id)
248 dev[1].request("SET sae_groups ")
249 id = add_mesh_secure_net(dev[1])
250 dev[1].mesh_group_add(id)
252 # Check for mesh joined
253 check_mesh_group_added(dev[0])
254 check_mesh_group_added(dev[1])
256 # Check for peer connected
257 check_mesh_peer_connected(dev[0])
258 check_mesh_peer_connected(dev[1])
260 # Test connectivity 0->1 and 1->0
261 hwsim_utils.test_connectivity(dev[0], dev[1])
263 def test_wpas_mesh_secure_sae_group_mismatch(dev, apdev):
264 """wpa_supplicant secure MESH and SAE group mismatch"""
265 check_mesh_support(dev[0], secure=True)
266 addr0 = dev[0].p2p_interface_addr()
267 addr1 = dev[1].p2p_interface_addr()
268 addr2 = dev[2].p2p_interface_addr()
270 dev[0].request("SET sae_groups 19 25")
271 id = add_mesh_secure_net(dev[0])
272 dev[0].mesh_group_add(id)
274 dev[1].request("SET sae_groups 19")
275 id = add_mesh_secure_net(dev[1])
276 dev[1].mesh_group_add(id)
278 dev[2].request("SET sae_groups 26")
279 id = add_mesh_secure_net(dev[2])
280 dev[2].mesh_group_add(id)
282 check_mesh_group_added(dev[0])
283 check_mesh_group_added(dev[1])
284 check_mesh_group_added(dev[2])
286 ev = dev[0].wait_event(["MESH-PEER-CONNECTED"])
288 raise Exception("Remote peer did not connect")
290 raise Exception("Unexpected peer connected: " + ev)
292 ev = dev[1].wait_event(["MESH-PEER-CONNECTED"])
294 raise Exception("Remote peer did not connect")
296 raise Exception("Unexpected peer connected: " + ev)
298 ev = dev[2].wait_event(["MESH-PEER-CONNECTED"], timeout=1)
300 raise Exception("Unexpected peer connection at dev[2]: " + ev)
302 ev = dev[0].wait_event(["MESH-PEER-CONNECTED"], timeout=0.1)
304 raise Exception("Unexpected peer connection: " + ev)
306 ev = dev[1].wait_event(["MESH-PEER-CONNECTED"], timeout=0.1)
308 raise Exception("Unexpected peer connection: " + ev)
310 dev[0].request("SET sae_groups ")
311 dev[1].request("SET sae_groups ")
312 dev[2].request("SET sae_groups ")
314 def test_wpas_mesh_secure_sae_missing_password(dev, apdev):
315 """wpa_supplicant secure MESH and missing SAE password"""
316 check_mesh_support(dev[0], secure=True)
317 id = add_mesh_secure_net(dev[0], psk=False)
318 dev[0].set_network(id, "psk", "8f20b381f9b84371d61b5080ad85cac3c61ab3ca9525be5b2d0f4da3d979187a")
319 dev[0].mesh_group_add(id)
320 ev = dev[0].wait_event(["MESH-GROUP-STARTED", "Could not join mesh"],
323 raise Exception("Timeout on mesh start event")
324 if "MESH-GROUP-STARTED" in ev:
325 raise Exception("Unexpected mesh group start")
326 ev = dev[0].wait_event(["MESH-GROUP-STARTED"], timeout=0.1)
328 raise Exception("Unexpected mesh group start")
330 def test_wpas_mesh_secure_no_auto(dev, apdev):
331 """wpa_supplicant secure MESH network connectivity"""
332 check_mesh_support(dev[0], secure=True)
333 dev[0].request("SET sae_groups 19")
334 id = add_mesh_secure_net(dev[0])
335 dev[0].mesh_group_add(id)
337 dev[1].request("SET sae_groups 19")
338 id = add_mesh_secure_net(dev[1])
339 dev[1].set_network(id, "no_auto_peer", "1")
340 dev[1].mesh_group_add(id)
342 # Check for mesh joined
343 check_mesh_group_added(dev[0])
344 check_mesh_group_added(dev[1])
346 # Check for peer connected
347 check_mesh_peer_connected(dev[0], timeout=30)
348 check_mesh_peer_connected(dev[1])
350 # Test connectivity 0->1 and 1->0
351 hwsim_utils.test_connectivity(dev[0], dev[1])
353 dev[0].request("SET sae_groups ")
354 dev[1].request("SET sae_groups ")
356 def test_wpas_mesh_secure_dropped_frame(dev, apdev):
357 """Secure mesh network connectivity when the first plink Open is dropped"""
358 check_mesh_support(dev[0], secure=True)
360 dev[0].request("SET ext_mgmt_frame_handling 1")
361 dev[0].request("SET sae_groups ")
362 id = add_mesh_secure_net(dev[0])
363 dev[0].mesh_group_add(id)
365 dev[1].request("SET sae_groups ")
366 id = add_mesh_secure_net(dev[1])
367 dev[1].mesh_group_add(id)
369 # Check for mesh joined
370 check_mesh_group_added(dev[0])
371 check_mesh_group_added(dev[1])
373 # Drop the first Action frame (plink Open) to test unexpected order of
374 # Confirm/Open messages.
379 raise Exception("Did not see Action frames")
380 rx_msg = dev[0].mgmt_rx()
382 raise Exception("MGMT-RX timeout")
383 if rx_msg['subtype'] == 13:
384 logger.info("Drop the first Action frame")
386 if "OK" not in dev[0].request("MGMT_RX_PROCESS freq={} datarate={} ssi_signal={} frame={}".format(rx_msg['freq'], rx_msg['datarate'], rx_msg['ssi_signal'], rx_msg['frame'].encode('hex'))):
387 raise Exception("MGMT_RX_PROCESS failed")
389 dev[0].request("SET ext_mgmt_frame_handling 0")
391 # Check for peer connected
392 check_mesh_peer_connected(dev[0])
393 check_mesh_peer_connected(dev[1])
395 # Test connectivity 0->1 and 1->0
396 hwsim_utils.test_connectivity(dev[0], dev[1])
398 def test_wpas_mesh_ctrl(dev):
399 """wpa_supplicant ctrl_iface mesh command error cases"""
400 check_mesh_support(dev[0])
401 if "FAIL" not in dev[0].request("MESH_GROUP_ADD 123"):
402 raise Exception("Unexpected MESH_GROUP_ADD success")
403 id = dev[0].add_network()
404 if "FAIL" not in dev[0].request("MESH_GROUP_ADD %d" % id):
405 raise Exception("Unexpected MESH_GROUP_ADD success")
406 dev[0].set_network(id, "mode", "5")
407 dev[0].set_network(id, "key_mgmt", "WPA-PSK")
408 if "FAIL" not in dev[0].request("MESH_GROUP_ADD %d" % id):
409 raise Exception("Unexpected MESH_GROUP_ADD success")
411 if "FAIL" not in dev[0].request("MESH_GROUP_REMOVE foo"):
412 raise Exception("Unexpected MESH_GROUP_REMOVE success")
414 def test_wpas_mesh_dynamic_interface(dev):
415 """wpa_supplicant mesh with dynamic interface"""
416 check_mesh_support(dev[0])
420 mesh0 = dev[0].request("MESH_INTERFACE_ADD ifname=mesh0")
422 raise Exception("MESH_INTERFACE_ADD failed")
423 mesh1 = dev[1].request("MESH_INTERFACE_ADD")
425 raise Exception("MESH_INTERFACE_ADD failed")
427 wpas0 = WpaSupplicant(ifname=mesh0)
428 wpas1 = WpaSupplicant(ifname=mesh1)
429 logger.info(mesh0 + " address " + wpas0.get_status_field("address"))
430 logger.info(mesh1 + " address " + wpas1.get_status_field("address"))
432 add_open_mesh_network(wpas0)
433 add_open_mesh_network(wpas1)
434 check_mesh_group_added(wpas0)
435 check_mesh_group_added(wpas1)
436 check_mesh_peer_connected(wpas0)
437 check_mesh_peer_connected(wpas1)
438 hwsim_utils.test_connectivity(wpas0, wpas1)
440 # Must not allow MESH_GROUP_REMOVE on dynamic interface
441 if "FAIL" not in wpas0.request("MESH_GROUP_REMOVE " + mesh0):
442 raise Exception("Invalid MESH_GROUP_REMOVE accepted")
443 if "FAIL" not in wpas1.request("MESH_GROUP_REMOVE " + mesh1):
444 raise Exception("Invalid MESH_GROUP_REMOVE accepted")
446 # Must not allow MESH_GROUP_REMOVE on another radio interface
447 if "FAIL" not in wpas0.request("MESH_GROUP_REMOVE " + mesh1):
448 raise Exception("Invalid MESH_GROUP_REMOVE accepted")
449 if "FAIL" not in wpas1.request("MESH_GROUP_REMOVE " + mesh0):
450 raise Exception("Invalid MESH_GROUP_REMOVE accepted")
452 wpas0.remove_ifname()
453 wpas1.remove_ifname()
455 if "OK" not in dev[0].request("MESH_GROUP_REMOVE " + mesh0):
456 raise Exception("MESH_GROUP_REMOVE failed")
457 if "OK" not in dev[1].request("MESH_GROUP_REMOVE " + mesh1):
458 raise Exception("MESH_GROUP_REMOVE failed")
460 if "FAIL" not in dev[0].request("MESH_GROUP_REMOVE " + mesh0):
461 raise Exception("Invalid MESH_GROUP_REMOVE accepted")
462 if "FAIL" not in dev[1].request("MESH_GROUP_REMOVE " + mesh1):
463 raise Exception("Invalid MESH_GROUP_REMOVE accepted")
465 logger.info("Make sure another dynamic group can be added")
466 mesh0 = dev[0].request("MESH_INTERFACE_ADD ifname=mesh0")
468 raise Exception("MESH_INTERFACE_ADD failed")
469 mesh1 = dev[1].request("MESH_INTERFACE_ADD")
471 raise Exception("MESH_INTERFACE_ADD failed")
473 wpas0 = WpaSupplicant(ifname=mesh0)
474 wpas1 = WpaSupplicant(ifname=mesh1)
475 logger.info(mesh0 + " address " + wpas0.get_status_field("address"))
476 logger.info(mesh1 + " address " + wpas1.get_status_field("address"))
478 add_open_mesh_network(wpas0)
479 add_open_mesh_network(wpas1)
480 check_mesh_group_added(wpas0)
481 check_mesh_group_added(wpas1)
482 check_mesh_peer_connected(wpas0)
483 check_mesh_peer_connected(wpas1)
484 hwsim_utils.test_connectivity(wpas0, wpas1)
487 dev[0].request("MESH_GROUP_REMOVE " + mesh0)
489 dev[1].request("MESH_GROUP_REMOVE " + mesh1)
491 def test_wpas_mesh_max_peering(dev, apdev):
492 """Mesh max peering limit"""
493 check_mesh_support(dev[0])
495 dev[0].request("SET max_peer_links 1")
497 # first, connect dev[0] and dev[1]
498 add_open_mesh_network(dev[0])
499 add_open_mesh_network(dev[1])
501 ev = dev[i].wait_event(["MESH-PEER-CONNECTED"])
503 raise Exception("dev%d did not connect with any peer" % i)
505 # add dev[2] which will try to connect with both dev[0] and dev[1],
506 # but can complete connection only with dev[1]
507 add_open_mesh_network(dev[2])
508 for i in range(1, 3):
509 ev = dev[i].wait_event(["MESH-PEER-CONNECTED"])
511 raise Exception("dev%d did not connect the second peer" % i)
513 ev = dev[0].wait_event(["MESH-PEER-CONNECTED"], timeout=1)
515 raise Exception("dev0 connection beyond max peering limit")
517 ev = dev[2].wait_event(["MESH-PEER-CONNECTED"], timeout=0.1)
519 raise Exception("dev2 reported unexpected peering: " + ev)
522 dev[i].mesh_group_remove()
523 check_mesh_group_removed(dev[i])
525 dev[0].request("SET max_peer_links 99")
527 def test_wpas_mesh_open_5ghz(dev, apdev):
528 """wpa_supplicant open MESH network on 5 GHz band"""
530 _test_wpas_mesh_open_5ghz(dev, apdev)
532 subprocess.call(['iw', 'reg', 'set', '00'])
533 dev[0].flush_scan_cache()
534 dev[1].flush_scan_cache()
536 def _test_wpas_mesh_open_5ghz(dev, apdev):
537 check_mesh_support(dev[0])
538 subprocess.call(['iw', 'reg', 'set', 'US'])
541 ev = dev[i].wait_event(["CTRL-EVENT-REGDOM-CHANGE"], timeout=5)
543 raise Exception("No regdom change event")
544 if "alpha2=US" in ev:
546 add_open_mesh_network(dev[i], freq="5180")
548 # Check for mesh joined
549 check_mesh_group_added(dev[0])
550 check_mesh_group_added(dev[1])
552 # Check for peer connected
553 check_mesh_peer_connected(dev[0])
554 check_mesh_peer_connected(dev[1])
556 # Test connectivity 0->1 and 1->0
557 hwsim_utils.test_connectivity(dev[0], dev[1])
559 def test_wpas_mesh_open_vht_80p80(dev, apdev):
560 """wpa_supplicant open MESH network on VHT 80+80 MHz channel"""
562 _test_wpas_mesh_open_vht_80p80(dev, apdev)
564 subprocess.call(['iw', 'reg', 'set', '00'])
565 dev[0].flush_scan_cache()
566 dev[1].flush_scan_cache()
568 def _test_wpas_mesh_open_vht_80p80(dev, apdev):
569 check_mesh_support(dev[0])
570 subprocess.call(['iw', 'reg', 'set', 'US'])
573 ev = dev[i].wait_event(["CTRL-EVENT-REGDOM-CHANGE"], timeout=5)
575 raise Exception("No regdom change event")
576 if "alpha2=US" in ev:
578 add_open_mesh_network(dev[i], freq="5180", chwidth=3)
580 # Check for mesh joined
581 check_mesh_group_added(dev[0])
582 check_mesh_group_added(dev[1])
584 # Check for peer connected
585 check_mesh_peer_connected(dev[0])
586 check_mesh_peer_connected(dev[1])
588 # Test connectivity 0->1 and 1->0
589 hwsim_utils.test_connectivity(dev[0], dev[1])
591 sig = dev[0].request("SIGNAL_POLL").splitlines()
592 if "WIDTH=80+80 MHz" not in sig:
593 raise Exception("Unexpected SIGNAL_POLL value(2): " + str(sig))
594 if "CENTER_FRQ1=5210" not in sig:
595 raise Exception("Unexpected SIGNAL_POLL value(3): " + str(sig))
596 if "CENTER_FRQ2=5775" not in sig:
597 raise Exception("Unexpected SIGNAL_POLL value(4): " + str(sig))
599 sig = dev[1].request("SIGNAL_POLL").splitlines()
600 if "WIDTH=80+80 MHz" not in sig:
601 raise Exception("Unexpected SIGNAL_POLL value(2b): " + str(sig))
602 if "CENTER_FRQ1=5210" not in sig:
603 raise Exception("Unexpected SIGNAL_POLL value(3b): " + str(sig))
604 if "CENTER_FRQ2=5775" not in sig:
605 raise Exception("Unexpected SIGNAL_POLL value(4b): " + str(sig))
607 def test_wpas_mesh_password_mismatch(dev, apdev):
608 """Mesh network and one device with mismatching password"""
609 check_mesh_support(dev[0], secure=True)
610 dev[0].request("SET sae_groups ")
611 id = add_mesh_secure_net(dev[0])
612 dev[0].mesh_group_add(id)
614 dev[1].request("SET sae_groups ")
615 id = add_mesh_secure_net(dev[1])
616 dev[1].mesh_group_add(id)
618 dev[2].request("SET sae_groups ")
619 id = add_mesh_secure_net(dev[2])
620 dev[2].set_network_quoted(id, "psk", "wrong password")
621 dev[2].mesh_group_add(id)
623 # The two peers with matching password need to be able to connect
624 check_mesh_group_added(dev[0])
625 check_mesh_group_added(dev[1])
626 check_mesh_peer_connected(dev[0])
627 check_mesh_peer_connected(dev[1])
629 ev = dev[2].wait_event(["MESH-SAE-AUTH-FAILURE"], timeout=20)
631 raise Exception("dev2 did not report auth failure (1)")
632 ev = dev[2].wait_event(["MESH-SAE-AUTH-FAILURE"], timeout=20)
634 raise Exception("dev2 did not report auth failure (2)")
637 ev = dev[0].wait_event(["MESH-SAE-AUTH-FAILURE"], timeout=1)
639 logger.info("dev0 did not report auth failure")
641 if "addr=" + dev[2].own_addr() not in ev:
642 raise Exception("Unexpected peer address in dev0 event: " + ev)
645 ev = dev[1].wait_event(["MESH-SAE-AUTH-FAILURE"], timeout=1)
647 logger.info("dev1 did not report auth failure")
649 if "addr=" + dev[2].own_addr() not in ev:
650 raise Exception("Unexpected peer address in dev1 event: " + ev)
653 hwsim_utils.test_connectivity(dev[0], dev[1])
657 hwsim_utils.test_connectivity(dev[i], dev[2], timeout=1)
658 raise Exception("Data connectivity test passed unexpectedly")
660 if "data delivery failed" not in str(e):
664 raise Exception("Neither dev0 nor dev1 reported auth failure")
666 def test_wpas_mesh_password_mismatch_retry(dev, apdev, params):
667 """Mesh password mismatch and retry [long]"""
668 if not params['long']:
669 raise HwsimSkip("Skip test case with long duration due to --long not specified")
670 check_mesh_support(dev[0], secure=True)
671 dev[0].request("SET sae_groups ")
672 id = add_mesh_secure_net(dev[0])
673 dev[0].mesh_group_add(id)
675 dev[1].request("SET sae_groups ")
676 id = add_mesh_secure_net(dev[1])
677 dev[1].set_network_quoted(id, "psk", "wrong password")
678 dev[1].mesh_group_add(id)
680 # Check for mesh joined
681 check_mesh_group_added(dev[0])
682 check_mesh_group_added(dev[1])
685 ev = dev[0].wait_event(["MESH-SAE-AUTH-FAILURE"], timeout=20)
687 raise Exception("dev0 did not report auth failure (%d)" % i)
688 ev = dev[1].wait_event(["MESH-SAE-AUTH-FAILURE"], timeout=20)
690 raise Exception("dev1 did not report auth failure (%d)" % i)
692 ev = dev[0].wait_event(["MESH-SAE-AUTH-BLOCKED"], timeout=10)
694 raise Exception("dev0 did not report auth blocked")
695 ev = dev[1].wait_event(["MESH-SAE-AUTH-BLOCKED"], timeout=10)
697 raise Exception("dev1 did not report auth blocked")
699 def test_mesh_wpa_auth_init_oom(dev, apdev):
700 """Secure mesh network setup failing due to wpa_init() OOM"""
701 check_mesh_support(dev[0], secure=True)
702 dev[0].request("SET sae_groups ")
703 with alloc_fail(dev[0], 1, "wpa_init"):
704 id = add_mesh_secure_net(dev[0])
705 dev[0].mesh_group_add(id)
706 ev = dev[0].wait_event(["MESH-GROUP-STARTED"], timeout=0.2)
708 raise Exception("Unexpected mesh group start during OOM")
710 def test_wpas_mesh_reconnect(dev, apdev):
711 """Secure mesh network plink counting during reconnection"""
712 check_mesh_support(dev[0])
714 _test_wpas_mesh_reconnect(dev)
716 dev[0].request("SET max_peer_links 99")
718 def _test_wpas_mesh_reconnect(dev):
719 dev[0].request("SET max_peer_links 2")
720 dev[0].request("SET sae_groups ")
721 id = add_mesh_secure_net(dev[0])
722 dev[0].set_network(id, "beacon_int", "100")
723 dev[0].mesh_group_add(id)
724 dev[1].request("SET sae_groups ")
725 id = add_mesh_secure_net(dev[1])
726 dev[1].mesh_group_add(id)
727 check_mesh_group_added(dev[0])
728 check_mesh_group_added(dev[1])
729 check_mesh_peer_connected(dev[0])
730 check_mesh_peer_connected(dev[1])
733 # Drop incoming management frames to avoid handling link close
734 dev[0].request("SET ext_mgmt_frame_handling 1")
735 dev[1].mesh_group_remove()
736 check_mesh_group_removed(dev[1])
737 dev[1].request("FLUSH")
738 dev[0].request("SET ext_mgmt_frame_handling 0")
739 id = add_mesh_secure_net(dev[1])
740 dev[1].mesh_group_add(id)
741 check_mesh_group_added(dev[1])
742 check_mesh_peer_connected(dev[1])
743 dev[0].dump_monitor()
744 dev[1].dump_monitor()
746 def test_wpas_mesh_gate_forwarding(dev, apdev, p):
747 """Mesh forwards traffic to unknown sta to mesh gates"""
748 addr0 = dev[0].own_addr()
749 addr1 = dev[1].own_addr()
750 addr2 = dev[2].own_addr()
751 external_sta = '02:11:22:33:44:55'
753 # start 3 node connected mesh
754 check_mesh_support(dev[0])
756 add_open_mesh_network(dev[i])
757 check_mesh_group_added(dev[i])
759 check_mesh_peer_connected(dev[i])
761 hwsim_utils.test_connectivity(dev[0], dev[1])
762 hwsim_utils.test_connectivity(dev[1], dev[2])
763 hwsim_utils.test_connectivity(dev[0], dev[2])
765 # dev0 and dev1 are mesh gates
766 subprocess.call(['iw', 'dev', dev[0].ifname, 'set', 'mesh_param',
767 'mesh_gate_announcements=1'])
768 subprocess.call(['iw', 'dev', dev[1].ifname, 'set', 'mesh_param',
769 'mesh_gate_announcements=1'])
771 # wait for gate announcement frames
774 # data frame from dev2 -> external sta should be sent to both gates
775 dev[2].request("DATA_TEST_CONFIG 1")
776 dev[2].request("DATA_TEST_TX {} {} 0".format(external_sta, addr2))
777 dev[2].request("DATA_TEST_CONFIG 0")
779 capfile = os.path.join(p['logdir'], "hwsim0.pcapng")
780 filt = "wlan.sa==%s && wlan_mgt.fixed.mesh_addr5==%s" % (addr2,
783 da = run_tshark(capfile, filt, [ "wlan.da" ])
784 if addr0 in da and addr1 in da:
785 logger.debug("Frames seen in tshark iteration %d" % i)
790 raise Exception("Frame to gate %s not observed" % addr0)
792 raise Exception("Frame to gate %s not observed" % addr1)
794 def test_wpas_mesh_pmksa_caching(dev, apdev):
795 """Secure mesh network and PMKSA caching"""
796 check_mesh_support(dev[0], secure=True)
797 dev[0].request("SET sae_groups ")
798 id = add_mesh_secure_net(dev[0])
799 dev[0].mesh_group_add(id)
801 dev[1].request("SET sae_groups ")
802 id = add_mesh_secure_net(dev[1])
803 dev[1].mesh_group_add(id)
805 # Check for mesh joined
806 check_mesh_group_added(dev[0])
807 check_mesh_group_added(dev[1])
809 # Check for peer connected
810 check_mesh_peer_connected(dev[0])
811 check_mesh_peer_connected(dev[1])
813 addr0 = dev[0].own_addr()
814 addr1 = dev[1].own_addr()
815 pmksa0 = dev[0].get_pmksa(addr1)
816 pmksa1 = dev[1].get_pmksa(addr0)
817 if pmksa0 is None or pmksa1 is None:
818 raise Exception("No PMKSA cache entry created")
819 if pmksa0['pmkid'] != pmksa1['pmkid']:
820 raise Exception("PMKID mismatch in PMKSA cache entries")
822 if "OK" not in dev[0].request("MESH_PEER_REMOVE " + addr1):
823 raise Exception("Failed to remove peer")
824 pmksa0b = dev[0].get_pmksa(addr1)
826 raise Exception("PMKSA cache entry not maintained")
829 if "FAIL" not in dev[0].request("MESH_PEER_ADD " + addr1):
830 raise Exception("MESH_PEER_ADD unexpectedly succeeded in no_auto_peer=0 case")
832 def test_wpas_mesh_pmksa_caching2(dev, apdev):
833 """Secure mesh network and PMKSA caching with no_auto_peer=1"""
834 check_mesh_support(dev[0], secure=True)
835 addr0 = dev[0].own_addr()
836 addr1 = dev[1].own_addr()
837 dev[0].request("SET sae_groups ")
838 id = add_mesh_secure_net(dev[0])
839 dev[0].set_network(id, "no_auto_peer", "1")
840 dev[0].mesh_group_add(id)
842 dev[1].request("SET sae_groups ")
843 id = add_mesh_secure_net(dev[1])
844 dev[1].set_network(id, "no_auto_peer", "1")
845 dev[1].mesh_group_add(id)
847 # Check for mesh joined
848 check_mesh_group_added(dev[0])
849 check_mesh_group_added(dev[1])
851 # Check for peer connected
852 ev = dev[0].wait_event(["will not initiate new peer link"], timeout=10)
854 raise Exception("Missing no-initiate message")
855 if "OK" not in dev[0].request("MESH_PEER_ADD " + addr1):
856 raise Exception("MESH_PEER_ADD failed")
857 check_mesh_peer_connected(dev[0])
858 check_mesh_peer_connected(dev[1])
860 pmksa0 = dev[0].get_pmksa(addr1)
861 pmksa1 = dev[1].get_pmksa(addr0)
862 if pmksa0 is None or pmksa1 is None:
863 raise Exception("No PMKSA cache entry created")
864 if pmksa0['pmkid'] != pmksa1['pmkid']:
865 raise Exception("PMKID mismatch in PMKSA cache entries")
867 if "OK" not in dev[0].request("MESH_PEER_REMOVE " + addr1):
868 raise Exception("Failed to remove peer")
869 pmksa0b = dev[0].get_pmksa(addr1)
871 raise Exception("PMKSA cache entry not maintained")
873 ev = dev[0].wait_event(["will not initiate new peer link"], timeout=10)
875 raise Exception("Missing no-initiate message (2)")
876 if "OK" not in dev[0].request("MESH_PEER_ADD " + addr1):
877 raise Exception("MESH_PEER_ADD failed (2)")
878 check_mesh_peer_connected(dev[0])
879 check_mesh_peer_connected(dev[1])
881 pmksa0c = dev[0].get_pmksa(addr1)
882 pmksa1c = dev[1].get_pmksa(addr0)
883 if pmksa0c is None or pmksa1c is None:
884 raise Exception("No PMKSA cache entry created (2)")
885 if pmksa0c['pmkid'] != pmksa1c['pmkid']:
886 raise Exception("PMKID mismatch in PMKSA cache entries")
887 if pmksa0['pmkid'] != pmksa0c['pmkid']:
888 raise Exception("PMKID changed")
890 hwsim_utils.test_connectivity(dev[0], dev[1])
892 def test_wpas_mesh_pmksa_caching_no_match(dev, apdev):
893 """Secure mesh network and PMKSA caching with no PMKID match"""
894 check_mesh_support(dev[0], secure=True)
895 addr0 = dev[0].own_addr()
896 addr1 = dev[1].own_addr()
897 dev[0].request("SET sae_groups ")
898 id = add_mesh_secure_net(dev[0])
899 dev[0].set_network(id, "no_auto_peer", "1")
900 dev[0].mesh_group_add(id)
902 dev[1].request("SET sae_groups ")
903 id = add_mesh_secure_net(dev[1])
904 dev[1].set_network(id, "no_auto_peer", "1")
905 dev[1].mesh_group_add(id)
907 # Check for mesh joined
908 check_mesh_group_added(dev[0])
909 check_mesh_group_added(dev[1])
911 # Check for peer connected
912 ev = dev[0].wait_event(["will not initiate new peer link"], timeout=10)
914 raise Exception("Missing no-initiate message")
915 if "OK" not in dev[0].request("MESH_PEER_ADD " + addr1):
916 raise Exception("MESH_PEER_ADD failed")
917 check_mesh_peer_connected(dev[0])
918 check_mesh_peer_connected(dev[1])
920 pmksa0 = dev[0].get_pmksa(addr1)
921 pmksa1 = dev[1].get_pmksa(addr0)
922 if pmksa0 is None or pmksa1 is None:
923 raise Exception("No PMKSA cache entry created")
924 if pmksa0['pmkid'] != pmksa1['pmkid']:
925 raise Exception("PMKID mismatch in PMKSA cache entries")
927 if "OK" not in dev[0].request("MESH_PEER_REMOVE " + addr1):
928 raise Exception("Failed to remove peer")
930 if "OK" not in dev[1].request("PMKSA_FLUSH"):
931 raise Exception("Failed to flush PMKSA cache")
933 ev = dev[0].wait_event(["will not initiate new peer link"], timeout=10)
935 raise Exception("Missing no-initiate message (2)")
936 if "OK" not in dev[0].request("MESH_PEER_ADD " + addr1):
937 raise Exception("MESH_PEER_ADD failed (2)")
938 check_mesh_peer_connected(dev[0])
939 check_mesh_peer_connected(dev[1])
941 pmksa0c = dev[0].get_pmksa(addr1)
942 pmksa1c = dev[1].get_pmksa(addr0)
943 if pmksa0c is None or pmksa1c is None:
944 raise Exception("No PMKSA cache entry created (2)")
945 if pmksa0c['pmkid'] != pmksa1c['pmkid']:
946 raise Exception("PMKID mismatch in PMKSA cache entries")
947 if pmksa0['pmkid'] == pmksa0c['pmkid']:
948 raise Exception("PMKID did not change")
950 hwsim_utils.test_connectivity(dev[0], dev[1])
952 def test_mesh_oom(dev, apdev):
953 """Mesh network setup failing due to OOM"""
954 check_mesh_support(dev[0], secure=True)
955 dev[0].request("SET sae_groups ")
957 with alloc_fail(dev[0], 1, "mesh_config_create"):
958 add_open_mesh_network(dev[0])
959 ev = dev[0].wait_event(["Failed to init mesh"])
961 raise Exception("Init failure not reported")
963 for i in range(1, 65):
964 with alloc_fail(dev[0], i, "wpa_supplicant_mesh_init"):
965 add_open_mesh_network(dev[0])
966 wait_fail_trigger(dev[0], "GET_ALLOC_FAIL")
967 ev = dev[0].wait_event(["Failed to init mesh",
968 "MESH-GROUP-STARTED"])
970 raise Exception("Init failure not reported")
972 def test_mesh_add_interface_oom(dev):
973 """wpa_supplicant mesh with dynamic interface addition failing"""
974 check_mesh_support(dev[0])
975 for i in range(1, 3):
978 with alloc_fail(dev[0], i, "wpas_mesh_add_interface"):
979 mesh = dev[0].request("MESH_INTERFACE_ADD").strip()
981 if mesh and mesh != "FAIL":
982 dev[0].request("MESH_GROUP_REMOVE " + mesh)
984 def test_mesh_scan_oom(dev):
985 """wpa_supplicant mesh scan results and OOM"""
986 check_mesh_support(dev[0])
987 add_open_mesh_network(dev[0])
988 check_mesh_group_added(dev[0])
990 dev[1].scan(freq="2412")
991 res = dev[1].request("SCAN_RESULTS")
994 for r in res.splitlines():
997 bssid = r.split('\t')[0]
999 bss = dev[1].get_bss(bssid)
1001 raise Exception("Could not get BSS entry for mesh")
1003 for i in range(1, 3):
1004 with alloc_fail(dev[1], i, "mesh_attr_text"):
1005 bss = dev[1].get_bss(bssid)
1007 raise Exception("Unexpected BSS result during OOM")