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()
16 from wpasupplicant import WpaSupplicant
17 from utils import HwsimSkip, alloc_fail
18 from tshark import run_tshark
20 def check_mesh_support(dev, secure=False):
21 if "MESH" not in dev.get_capability("modes"):
22 raise HwsimSkip("Driver does not support mesh")
23 if secure and "SAE" not in dev.get_capability("auth_alg"):
24 raise HwsimSkip("SAE not supported")
26 def check_mesh_scan(dev, params, other_started=False, beacon_int=0):
29 id = dev.request("SCAN " + params)
31 raise Exception("Failed to start scan")
35 ev = dev.wait_event(["CTRL-EVENT-SCAN-STARTED"])
37 raise Exception("Other scan did not start")
38 if "id=" + str(id) in ev:
39 raise Exception("Own scan id unexpectedly included in start event")
41 ev = dev.wait_event(["CTRL-EVENT-SCAN-RESULTS"])
43 raise Exception("Other scan did not complete")
44 if "id=" + str(id) in ev:
46 "Own scan id unexpectedly included in completed event")
48 ev = dev.wait_event(["CTRL-EVENT-SCAN-STARTED"])
50 raise Exception("Scan did not start")
51 if "id=" + str(id) not in ev:
52 raise Exception("Scan id not included in start event")
54 ev = dev.wait_event(["CTRL-EVENT-SCAN-RESULTS"])
56 raise Exception("Scan did not complete")
57 if "id=" + str(id) not in ev:
58 raise Exception("Scan id not included in completed event")
60 res = dev.request("SCAN_RESULTS")
62 if res.find("[MESH]") < 0:
63 raise Exception("Scan did not contain a MESH network")
65 bssid = res.splitlines()[1].split(' ')[0]
66 bss = dev.get_bss(bssid)
68 raise Exception("Could not get BSS entry for mesh")
69 if 'mesh_capability' not in bss:
70 raise Exception("mesh_capability missing from BSS entry")
72 if 'beacon_int' not in bss:
73 raise Exception("beacon_int missing from BSS entry")
74 if str(beacon_int) != bss['beacon_int']:
75 raise Exception("Unexpected beacon_int in BSS entry: " + bss['beacon_int'])
77 def check_mesh_group_added(dev):
78 ev = dev.wait_event(["MESH-GROUP-STARTED"])
80 raise Exception("Test exception: Couldn't join mesh")
83 def check_mesh_group_removed(dev):
84 ev = dev.wait_event(["MESH-GROUP-REMOVED"])
86 raise Exception("Test exception: Couldn't leave mesh")
89 def check_mesh_peer_connected(dev, timeout=10):
90 ev = dev.wait_event(["MESH-PEER-CONNECTED"], timeout=timeout)
92 raise Exception("Test exception: Remote peer did not connect.")
95 def check_mesh_peer_disconnected(dev):
96 ev = dev.wait_event(["MESH-PEER-DISCONNECTED"])
98 raise Exception("Test exception: Peer disconnect event not detected.")
101 def test_wpas_add_set_remove_support(dev):
102 """wpa_supplicant MESH add/set/remove network support"""
103 check_mesh_support(dev[0])
104 id = dev[0].add_network()
105 dev[0].set_network(id, "mode", "5")
106 dev[0].remove_network(id)
108 def add_open_mesh_network(dev, freq="2412", start=True, beacon_int=0,
109 basic_rates=None, chwidth=0):
110 id = dev.add_network()
111 dev.set_network(id, "mode", "5")
112 dev.set_network_quoted(id, "ssid", "wpas-mesh-open")
113 dev.set_network(id, "key_mgmt", "NONE")
114 dev.set_network(id, "frequency", freq)
116 dev.set_network(id, "max_oper_chwidth", str(chwidth))
118 dev.set_network(id, "beacon_int", str(beacon_int))
120 dev.set_network(id, "mesh_basic_rates", basic_rates)
122 dev.mesh_group_add(id)
125 def test_wpas_mesh_group_added(dev):
126 """wpa_supplicant MESH group add"""
127 check_mesh_support(dev[0])
128 add_open_mesh_network(dev[0])
130 # Check for MESH-GROUP-STARTED event
131 check_mesh_group_added(dev[0])
134 def test_wpas_mesh_group_remove(dev):
135 """wpa_supplicant MESH group remove"""
136 check_mesh_support(dev[0])
137 add_open_mesh_network(dev[0])
138 # Check for MESH-GROUP-STARTED event
139 check_mesh_group_added(dev[0])
140 dev[0].mesh_group_remove()
141 # Check for MESH-GROUP-REMOVED event
142 check_mesh_group_removed(dev[0])
143 dev[0].mesh_group_remove()
145 def test_wpas_mesh_peer_connected(dev):
146 """wpa_supplicant MESH peer connected"""
147 check_mesh_support(dev[0])
148 add_open_mesh_network(dev[0], beacon_int=160)
149 add_open_mesh_network(dev[1], beacon_int=160)
151 # Check for mesh joined
152 check_mesh_group_added(dev[0])
153 check_mesh_group_added(dev[1])
155 # Check for peer connected
156 check_mesh_peer_connected(dev[0])
157 check_mesh_peer_connected(dev[1])
160 def test_wpas_mesh_peer_disconnected(dev):
161 """wpa_supplicant MESH peer disconnected"""
162 check_mesh_support(dev[0])
163 add_open_mesh_network(dev[0])
164 add_open_mesh_network(dev[1])
166 # Check for mesh joined
167 check_mesh_group_added(dev[0])
168 check_mesh_group_added(dev[1])
170 # Check for peer connected
171 check_mesh_peer_connected(dev[0])
172 check_mesh_peer_connected(dev[1])
174 # Remove group on dev 1
175 dev[1].mesh_group_remove()
176 # Device 0 should get a disconnection event
177 check_mesh_peer_disconnected(dev[0])
180 def test_wpas_mesh_mode_scan(dev):
181 """wpa_supplicant MESH scan support"""
182 check_mesh_support(dev[0])
183 add_open_mesh_network(dev[0])
184 add_open_mesh_network(dev[1], beacon_int=175)
186 # Check for mesh joined
187 check_mesh_group_added(dev[0])
188 check_mesh_group_added(dev[1])
190 # Check for Mesh scan
191 check_mesh_scan(dev[0], "use_id=1", beacon_int=175)
193 def test_wpas_mesh_open(dev, apdev):
194 """wpa_supplicant open MESH network connectivity"""
195 check_mesh_support(dev[0])
196 add_open_mesh_network(dev[0], freq="2462", basic_rates="60 120 240")
197 add_open_mesh_network(dev[1], freq="2462", basic_rates="60 120 240")
199 # Check for mesh joined
200 check_mesh_group_added(dev[0])
201 check_mesh_group_added(dev[1])
203 # Check for peer connected
204 check_mesh_peer_connected(dev[0])
205 check_mesh_peer_connected(dev[1])
207 # Test connectivity 0->1 and 1->0
208 hwsim_utils.test_connectivity(dev[0], dev[1])
210 def test_wpas_mesh_open_no_auto(dev, apdev):
211 """wpa_supplicant open MESH network connectivity"""
212 check_mesh_support(dev[0])
213 id = add_open_mesh_network(dev[0], start=False)
214 dev[0].set_network(id, "dot11MeshMaxRetries", "16")
215 dev[0].set_network(id, "dot11MeshRetryTimeout", "255")
216 dev[0].mesh_group_add(id)
218 id = add_open_mesh_network(dev[1], start=False)
219 dev[1].set_network(id, "no_auto_peer", "1")
220 dev[1].mesh_group_add(id)
222 # Check for mesh joined
223 check_mesh_group_added(dev[0])
224 check_mesh_group_added(dev[1])
226 # Check for peer connected
227 check_mesh_peer_connected(dev[0], timeout=30)
228 check_mesh_peer_connected(dev[1])
230 # Test connectivity 0->1 and 1->0
231 hwsim_utils.test_connectivity(dev[0], dev[1])
233 def add_mesh_secure_net(dev, psk=True):
234 id = dev.add_network()
235 dev.set_network(id, "mode", "5")
236 dev.set_network_quoted(id, "ssid", "wpas-mesh-sec")
237 dev.set_network(id, "key_mgmt", "SAE")
238 dev.set_network(id, "frequency", "2412")
240 dev.set_network_quoted(id, "psk", "thisismypassphrase!")
243 def test_wpas_mesh_secure(dev, apdev):
244 """wpa_supplicant secure MESH network connectivity"""
245 check_mesh_support(dev[0], secure=True)
246 dev[0].request("SET sae_groups ")
247 id = add_mesh_secure_net(dev[0])
248 dev[0].mesh_group_add(id)
250 dev[1].request("SET sae_groups ")
251 id = add_mesh_secure_net(dev[1])
252 dev[1].mesh_group_add(id)
254 # Check for mesh joined
255 check_mesh_group_added(dev[0])
256 check_mesh_group_added(dev[1])
258 # Check for peer connected
259 check_mesh_peer_connected(dev[0])
260 check_mesh_peer_connected(dev[1])
262 # Test connectivity 0->1 and 1->0
263 hwsim_utils.test_connectivity(dev[0], dev[1])
265 def test_wpas_mesh_secure_sae_group_mismatch(dev, apdev):
266 """wpa_supplicant secure MESH and SAE group mismatch"""
267 check_mesh_support(dev[0], secure=True)
268 addr0 = dev[0].p2p_interface_addr()
269 addr1 = dev[1].p2p_interface_addr()
270 addr2 = dev[2].p2p_interface_addr()
272 dev[0].request("SET sae_groups 19 25")
273 id = add_mesh_secure_net(dev[0])
274 dev[0].mesh_group_add(id)
276 dev[1].request("SET sae_groups 19")
277 id = add_mesh_secure_net(dev[1])
278 dev[1].mesh_group_add(id)
280 dev[2].request("SET sae_groups 26")
281 id = add_mesh_secure_net(dev[2])
282 dev[2].mesh_group_add(id)
284 check_mesh_group_added(dev[0])
285 check_mesh_group_added(dev[1])
286 check_mesh_group_added(dev[2])
288 ev = dev[0].wait_event(["MESH-PEER-CONNECTED"])
290 raise Exception("Remote peer did not connect")
292 raise Exception("Unexpected peer connected: " + ev)
294 ev = dev[1].wait_event(["MESH-PEER-CONNECTED"])
296 raise Exception("Remote peer did not connect")
298 raise Exception("Unexpected peer connected: " + ev)
300 ev = dev[2].wait_event(["MESH-PEER-CONNECTED"], timeout=1)
302 raise Exception("Unexpected peer connection at dev[2]: " + ev)
304 ev = dev[0].wait_event(["MESH-PEER-CONNECTED"], timeout=0.1)
306 raise Exception("Unexpected peer connection: " + ev)
308 ev = dev[1].wait_event(["MESH-PEER-CONNECTED"], timeout=0.1)
310 raise Exception("Unexpected peer connection: " + ev)
312 dev[0].request("SET sae_groups ")
313 dev[1].request("SET sae_groups ")
314 dev[2].request("SET sae_groups ")
316 def test_wpas_mesh_secure_sae_missing_password(dev, apdev):
317 """wpa_supplicant secure MESH and missing SAE password"""
318 check_mesh_support(dev[0], secure=True)
319 id = add_mesh_secure_net(dev[0], psk=False)
320 dev[0].set_network(id, "psk", "8f20b381f9b84371d61b5080ad85cac3c61ab3ca9525be5b2d0f4da3d979187a")
321 dev[0].mesh_group_add(id)
322 ev = dev[0].wait_event(["MESH-GROUP-STARTED", "Could not join mesh"],
325 raise Exception("Timeout on mesh start event")
326 if "MESH-GROUP-STARTED" in ev:
327 raise Exception("Unexpected mesh group start")
328 ev = dev[0].wait_event(["MESH-GROUP-STARTED"], timeout=0.1)
330 raise Exception("Unexpected mesh group start")
332 def test_wpas_mesh_secure_no_auto(dev, apdev):
333 """wpa_supplicant secure MESH network connectivity"""
334 check_mesh_support(dev[0], secure=True)
335 dev[0].request("SET sae_groups 19")
336 id = add_mesh_secure_net(dev[0])
337 dev[0].mesh_group_add(id)
339 dev[1].request("SET sae_groups 19")
340 id = add_mesh_secure_net(dev[1])
341 dev[1].set_network(id, "no_auto_peer", "1")
342 dev[1].mesh_group_add(id)
344 # Check for mesh joined
345 check_mesh_group_added(dev[0])
346 check_mesh_group_added(dev[1])
348 # Check for peer connected
349 check_mesh_peer_connected(dev[0], timeout=30)
350 check_mesh_peer_connected(dev[1])
352 # Test connectivity 0->1 and 1->0
353 hwsim_utils.test_connectivity(dev[0], dev[1])
355 dev[0].request("SET sae_groups ")
356 dev[1].request("SET sae_groups ")
358 def test_wpas_mesh_secure_dropped_frame(dev, apdev):
359 """Secure mesh network connectivity when the first plink Open is dropped"""
360 check_mesh_support(dev[0], secure=True)
362 dev[0].request("SET ext_mgmt_frame_handling 1")
363 dev[0].request("SET sae_groups ")
364 id = add_mesh_secure_net(dev[0])
365 dev[0].mesh_group_add(id)
367 dev[1].request("SET sae_groups ")
368 id = add_mesh_secure_net(dev[1])
369 dev[1].mesh_group_add(id)
371 # Check for mesh joined
372 check_mesh_group_added(dev[0])
373 check_mesh_group_added(dev[1])
375 # Drop the first Action frame (plink Open) to test unexpected order of
376 # Confirm/Open messages.
381 raise Exception("Did not see Action frames")
382 rx_msg = dev[0].mgmt_rx()
384 raise Exception("MGMT-RX timeout")
385 if rx_msg['subtype'] == 13:
386 logger.info("Drop the first Action frame")
388 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'))):
389 raise Exception("MGMT_RX_PROCESS failed")
391 dev[0].request("SET ext_mgmt_frame_handling 0")
393 # Check for peer connected
394 check_mesh_peer_connected(dev[0])
395 check_mesh_peer_connected(dev[1])
397 # Test connectivity 0->1 and 1->0
398 hwsim_utils.test_connectivity(dev[0], dev[1])
400 def test_wpas_mesh_ctrl(dev):
401 """wpa_supplicant ctrl_iface mesh command error cases"""
402 check_mesh_support(dev[0])
403 if "FAIL" not in dev[0].request("MESH_GROUP_ADD 123"):
404 raise Exception("Unexpected MESH_GROUP_ADD success")
405 id = dev[0].add_network()
406 if "FAIL" not in dev[0].request("MESH_GROUP_ADD %d" % id):
407 raise Exception("Unexpected MESH_GROUP_ADD success")
408 dev[0].set_network(id, "mode", "5")
409 dev[0].set_network(id, "key_mgmt", "WPA-PSK")
410 if "FAIL" not in dev[0].request("MESH_GROUP_ADD %d" % id):
411 raise Exception("Unexpected MESH_GROUP_ADD success")
413 if "FAIL" not in dev[0].request("MESH_GROUP_REMOVE foo"):
414 raise Exception("Unexpected MESH_GROUP_REMOVE success")
416 def test_wpas_mesh_dynamic_interface(dev):
417 """wpa_supplicant mesh with dynamic interface"""
418 check_mesh_support(dev[0])
422 mesh0 = dev[0].request("MESH_INTERFACE_ADD ifname=mesh0")
424 raise Exception("MESH_INTERFACE_ADD failed")
425 mesh1 = dev[1].request("MESH_INTERFACE_ADD")
427 raise Exception("MESH_INTERFACE_ADD failed")
429 wpas0 = WpaSupplicant(ifname=mesh0)
430 wpas1 = WpaSupplicant(ifname=mesh1)
431 logger.info(mesh0 + " address " + wpas0.get_status_field("address"))
432 logger.info(mesh1 + " address " + wpas1.get_status_field("address"))
434 add_open_mesh_network(wpas0)
435 add_open_mesh_network(wpas1)
436 check_mesh_group_added(wpas0)
437 check_mesh_group_added(wpas1)
438 check_mesh_peer_connected(wpas0)
439 check_mesh_peer_connected(wpas1)
440 hwsim_utils.test_connectivity(wpas0, wpas1)
442 # Must not allow MESH_GROUP_REMOVE on dynamic interface
443 if "FAIL" not in wpas0.request("MESH_GROUP_REMOVE " + mesh0):
444 raise Exception("Invalid MESH_GROUP_REMOVE accepted")
445 if "FAIL" not in wpas1.request("MESH_GROUP_REMOVE " + mesh1):
446 raise Exception("Invalid MESH_GROUP_REMOVE accepted")
448 # Must not allow MESH_GROUP_REMOVE on another radio interface
449 if "FAIL" not in wpas0.request("MESH_GROUP_REMOVE " + mesh1):
450 raise Exception("Invalid MESH_GROUP_REMOVE accepted")
451 if "FAIL" not in wpas1.request("MESH_GROUP_REMOVE " + mesh0):
452 raise Exception("Invalid MESH_GROUP_REMOVE accepted")
454 wpas0.remove_ifname()
455 wpas1.remove_ifname()
457 if "OK" not in dev[0].request("MESH_GROUP_REMOVE " + mesh0):
458 raise Exception("MESH_GROUP_REMOVE failed")
459 if "OK" not in dev[1].request("MESH_GROUP_REMOVE " + mesh1):
460 raise Exception("MESH_GROUP_REMOVE failed")
462 if "FAIL" not in dev[0].request("MESH_GROUP_REMOVE " + mesh0):
463 raise Exception("Invalid MESH_GROUP_REMOVE accepted")
464 if "FAIL" not in dev[1].request("MESH_GROUP_REMOVE " + mesh1):
465 raise Exception("Invalid MESH_GROUP_REMOVE accepted")
467 logger.info("Make sure another dynamic group can be added")
468 mesh0 = dev[0].request("MESH_INTERFACE_ADD ifname=mesh0")
470 raise Exception("MESH_INTERFACE_ADD failed")
471 mesh1 = dev[1].request("MESH_INTERFACE_ADD")
473 raise Exception("MESH_INTERFACE_ADD failed")
475 wpas0 = WpaSupplicant(ifname=mesh0)
476 wpas1 = WpaSupplicant(ifname=mesh1)
477 logger.info(mesh0 + " address " + wpas0.get_status_field("address"))
478 logger.info(mesh1 + " address " + wpas1.get_status_field("address"))
480 add_open_mesh_network(wpas0)
481 add_open_mesh_network(wpas1)
482 check_mesh_group_added(wpas0)
483 check_mesh_group_added(wpas1)
484 check_mesh_peer_connected(wpas0)
485 check_mesh_peer_connected(wpas1)
486 hwsim_utils.test_connectivity(wpas0, wpas1)
489 dev[0].request("MESH_GROUP_REMOVE " + mesh0)
491 dev[1].request("MESH_GROUP_REMOVE " + mesh1)
493 def test_wpas_mesh_max_peering(dev, apdev):
494 """Mesh max peering limit"""
495 check_mesh_support(dev[0])
497 dev[0].request("SET max_peer_links 1")
499 # first, connect dev[0] and dev[1]
500 add_open_mesh_network(dev[0])
501 add_open_mesh_network(dev[1])
503 ev = dev[i].wait_event(["MESH-PEER-CONNECTED"])
505 raise Exception("dev%d did not connect with any peer" % i)
507 # add dev[2] which will try to connect with both dev[0] and dev[1],
508 # but can complete connection only with dev[1]
509 add_open_mesh_network(dev[2])
510 for i in range(1, 3):
511 ev = dev[i].wait_event(["MESH-PEER-CONNECTED"])
513 raise Exception("dev%d did not connect the second peer" % i)
515 ev = dev[0].wait_event(["MESH-PEER-CONNECTED"], timeout=1)
517 raise Exception("dev0 connection beyond max peering limit")
519 ev = dev[2].wait_event(["MESH-PEER-CONNECTED"], timeout=0.1)
521 raise Exception("dev2 reported unexpected peering: " + ev)
524 dev[i].mesh_group_remove()
525 check_mesh_group_removed(dev[i])
527 dev[0].request("SET max_peer_links 99")
529 def test_wpas_mesh_open_5ghz(dev, apdev):
530 """wpa_supplicant open MESH network on 5 GHz band"""
532 _test_wpas_mesh_open_5ghz(dev, apdev)
534 subprocess.call(['iw', 'reg', 'set', '00'])
535 dev[0].flush_scan_cache()
536 dev[1].flush_scan_cache()
538 def _test_wpas_mesh_open_5ghz(dev, apdev):
539 check_mesh_support(dev[0])
540 subprocess.call(['iw', 'reg', 'set', 'US'])
543 ev = dev[i].wait_event(["CTRL-EVENT-REGDOM-CHANGE"], timeout=5)
545 raise Exception("No regdom change event")
546 if "alpha2=US" in ev:
548 add_open_mesh_network(dev[i], freq="5180")
550 # Check for mesh joined
551 check_mesh_group_added(dev[0])
552 check_mesh_group_added(dev[1])
554 # Check for peer connected
555 check_mesh_peer_connected(dev[0])
556 check_mesh_peer_connected(dev[1])
558 # Test connectivity 0->1 and 1->0
559 hwsim_utils.test_connectivity(dev[0], dev[1])
561 def test_wpas_mesh_open_vht_80p80(dev, apdev):
562 """wpa_supplicant open MESH network on VHT 80+80 MHz channel"""
564 _test_wpas_mesh_open_vht_80p80(dev, apdev)
566 subprocess.call(['iw', 'reg', 'set', '00'])
567 dev[0].flush_scan_cache()
568 dev[1].flush_scan_cache()
570 def _test_wpas_mesh_open_vht_80p80(dev, apdev):
571 check_mesh_support(dev[0])
572 subprocess.call(['iw', 'reg', 'set', 'US'])
575 ev = dev[i].wait_event(["CTRL-EVENT-REGDOM-CHANGE"], timeout=5)
577 raise Exception("No regdom change event")
578 if "alpha2=US" in ev:
580 add_open_mesh_network(dev[i], freq="5180", chwidth=3)
582 # Check for mesh joined
583 check_mesh_group_added(dev[0])
584 check_mesh_group_added(dev[1])
586 # Check for peer connected
587 check_mesh_peer_connected(dev[0])
588 check_mesh_peer_connected(dev[1])
590 # Test connectivity 0->1 and 1->0
591 hwsim_utils.test_connectivity(dev[0], dev[1])
593 sig = dev[0].request("SIGNAL_POLL").splitlines()
594 if "WIDTH=80+80 MHz" not in sig:
595 raise Exception("Unexpected SIGNAL_POLL value(2): " + str(sig))
596 if "CENTER_FRQ1=5210" not in sig:
597 raise Exception("Unexpected SIGNAL_POLL value(3): " + str(sig))
598 if "CENTER_FRQ2=5775" not in sig:
599 raise Exception("Unexpected SIGNAL_POLL value(4): " + str(sig))
601 sig = dev[1].request("SIGNAL_POLL").splitlines()
602 if "WIDTH=80+80 MHz" not in sig:
603 raise Exception("Unexpected SIGNAL_POLL value(2b): " + str(sig))
604 if "CENTER_FRQ1=5210" not in sig:
605 raise Exception("Unexpected SIGNAL_POLL value(3b): " + str(sig))
606 if "CENTER_FRQ2=5775" not in sig:
607 raise Exception("Unexpected SIGNAL_POLL value(4b): " + str(sig))
609 def test_wpas_mesh_password_mismatch(dev, apdev):
610 """Mesh network and one device with mismatching password"""
611 check_mesh_support(dev[0], secure=True)
612 dev[0].request("SET sae_groups ")
613 id = add_mesh_secure_net(dev[0])
614 dev[0].mesh_group_add(id)
616 dev[1].request("SET sae_groups ")
617 id = add_mesh_secure_net(dev[1])
618 dev[1].mesh_group_add(id)
620 dev[2].request("SET sae_groups ")
621 id = add_mesh_secure_net(dev[2])
622 dev[2].set_network_quoted(id, "psk", "wrong password")
623 dev[2].mesh_group_add(id)
625 # The two peers with matching password need to be able to connect
626 check_mesh_group_added(dev[0])
627 check_mesh_group_added(dev[1])
628 check_mesh_peer_connected(dev[0])
629 check_mesh_peer_connected(dev[1])
631 ev = dev[2].wait_event(["MESH-SAE-AUTH-FAILURE"], timeout=20)
633 raise Exception("dev2 did not report auth failure (1)")
634 ev = dev[2].wait_event(["MESH-SAE-AUTH-FAILURE"], timeout=20)
636 raise Exception("dev2 did not report auth failure (2)")
639 ev = dev[0].wait_event(["MESH-SAE-AUTH-FAILURE"], timeout=1)
641 logger.info("dev0 did not report auth failure")
643 if "addr=" + dev[2].own_addr() not in ev:
644 raise Exception("Unexpected peer address in dev0 event: " + ev)
647 ev = dev[1].wait_event(["MESH-SAE-AUTH-FAILURE"], timeout=1)
649 logger.info("dev1 did not report auth failure")
651 if "addr=" + dev[2].own_addr() not in ev:
652 raise Exception("Unexpected peer address in dev1 event: " + ev)
655 hwsim_utils.test_connectivity(dev[0], dev[1])
659 hwsim_utils.test_connectivity(dev[i], dev[2], timeout=1)
660 raise Exception("Data connectivity test passed unexpectedly")
662 if "data delivery failed" not in str(e):
666 raise Exception("Neither dev0 nor dev1 reported auth failure")
668 def test_wpas_mesh_password_mismatch_retry(dev, apdev, params):
669 """Mesh password mismatch and retry [long]"""
670 if not params['long']:
671 raise HwsimSkip("Skip test case with long duration due to --long not specified")
672 check_mesh_support(dev[0], secure=True)
673 dev[0].request("SET sae_groups ")
674 id = add_mesh_secure_net(dev[0])
675 dev[0].mesh_group_add(id)
677 dev[1].request("SET sae_groups ")
678 id = add_mesh_secure_net(dev[1])
679 dev[1].set_network_quoted(id, "psk", "wrong password")
680 dev[1].mesh_group_add(id)
682 # Check for mesh joined
683 check_mesh_group_added(dev[0])
684 check_mesh_group_added(dev[1])
687 ev = dev[0].wait_event(["MESH-SAE-AUTH-FAILURE"], timeout=20)
689 raise Exception("dev0 did not report auth failure (%d)" % i)
690 ev = dev[1].wait_event(["MESH-SAE-AUTH-FAILURE"], timeout=20)
692 raise Exception("dev1 did not report auth failure (%d)" % i)
694 ev = dev[0].wait_event(["MESH-SAE-AUTH-BLOCKED"], timeout=10)
696 raise Exception("dev0 did not report auth blocked")
697 ev = dev[1].wait_event(["MESH-SAE-AUTH-BLOCKED"], timeout=10)
699 raise Exception("dev1 did not report auth blocked")
701 def test_mesh_wpa_auth_init_oom(dev, apdev):
702 """Secure mesh network setup failing due to wpa_init() OOM"""
703 check_mesh_support(dev[0], secure=True)
704 dev[0].request("SET sae_groups ")
705 with alloc_fail(dev[0], 1, "wpa_init"):
706 id = add_mesh_secure_net(dev[0])
707 dev[0].mesh_group_add(id)
708 ev = dev[0].wait_event(["MESH-GROUP-STARTED"], timeout=0.2)
710 raise Exception("Unexpected mesh group start during OOM")
712 def test_wpas_mesh_reconnect(dev, apdev):
713 """Secure mesh network plink counting during reconnection"""
714 check_mesh_support(dev[0])
716 _test_wpas_mesh_reconnect(dev)
718 dev[0].request("SET max_peer_links 99")
720 def _test_wpas_mesh_reconnect(dev):
721 dev[0].request("SET max_peer_links 2")
722 dev[0].request("SET sae_groups ")
723 id = add_mesh_secure_net(dev[0])
724 dev[0].set_network(id, "beacon_int", "100")
725 dev[0].mesh_group_add(id)
726 dev[1].request("SET sae_groups ")
727 id = add_mesh_secure_net(dev[1])
728 dev[1].mesh_group_add(id)
729 check_mesh_group_added(dev[0])
730 check_mesh_group_added(dev[1])
731 check_mesh_peer_connected(dev[0])
732 check_mesh_peer_connected(dev[1])
735 # Drop incoming management frames to avoid handling link close
736 dev[0].request("SET ext_mgmt_frame_handling 1")
737 dev[1].mesh_group_remove()
738 check_mesh_group_removed(dev[1])
739 dev[1].request("FLUSH")
740 dev[0].request("SET ext_mgmt_frame_handling 0")
741 id = add_mesh_secure_net(dev[1])
742 dev[1].mesh_group_add(id)
743 check_mesh_group_added(dev[1])
744 check_mesh_peer_connected(dev[1])
745 dev[0].dump_monitor()
746 dev[1].dump_monitor()
748 def test_wpas_mesh_gate_forwarding(dev, apdev, p):
749 """Mesh forwards traffic to unknown sta to mesh gates"""
750 addr0 = dev[0].own_addr()
751 addr1 = dev[1].own_addr()
752 addr2 = dev[2].own_addr()
753 external_sta = '02:11:22:33:44:55'
755 # start 3 node connected mesh
756 check_mesh_support(dev[0])
758 add_open_mesh_network(dev[i])
759 check_mesh_group_added(dev[i])
761 check_mesh_peer_connected(dev[i])
763 hwsim_utils.test_connectivity(dev[0], dev[1])
764 hwsim_utils.test_connectivity(dev[1], dev[2])
765 hwsim_utils.test_connectivity(dev[0], dev[2])
767 # dev0 and dev1 are mesh gates
768 subprocess.call(['iw', 'dev', dev[0].ifname, 'set', 'mesh_param',
769 'mesh_gate_announcements=1'])
770 subprocess.call(['iw', 'dev', dev[1].ifname, 'set', 'mesh_param',
771 'mesh_gate_announcements=1'])
773 # wait for gate announcement frames
776 # data frame from dev2 -> external sta should be sent to both gates
777 dev[2].request("DATA_TEST_CONFIG 1")
778 dev[2].request("DATA_TEST_TX {} {} 0".format(external_sta, addr2))
779 dev[2].request("DATA_TEST_CONFIG 0")
781 capfile = os.path.join(p['logdir'], "hwsim0.pcapng")
782 filt = "wlan.sa==%s && wlan_mgt.fixed.mesh_addr5==%s" % (addr2,
785 da = run_tshark(capfile, filt, [ "wlan.da" ])
786 if addr0 in da and addr1 in da:
787 logger.debug("Frames seen in tshark iteration %d" % i)
792 raise Exception("Frame to gate %s not observed" % addr0)
794 raise Exception("Frame to gate %s not observed" % addr1)
796 def test_wpas_mesh_pmksa_caching(dev, apdev):
797 """Secure mesh network and PMKSA caching"""
798 check_mesh_support(dev[0], secure=True)
799 dev[0].request("SET sae_groups ")
800 id = add_mesh_secure_net(dev[0])
801 dev[0].mesh_group_add(id)
803 dev[1].request("SET sae_groups ")
804 id = add_mesh_secure_net(dev[1])
805 dev[1].mesh_group_add(id)
807 # Check for mesh joined
808 check_mesh_group_added(dev[0])
809 check_mesh_group_added(dev[1])
811 # Check for peer connected
812 check_mesh_peer_connected(dev[0])
813 check_mesh_peer_connected(dev[1])
815 addr0 = dev[0].own_addr()
816 addr1 = dev[1].own_addr()
817 pmksa0 = dev[0].get_pmksa(addr1)
818 pmksa1 = dev[1].get_pmksa(addr0)
819 if pmksa0 is None or pmksa1 is None:
820 raise Exception("No PMKSA cache entry created")
821 if pmksa0['pmkid'] != pmksa1['pmkid']:
822 raise Exception("PMKID mismatch in PMKSA cache entries")
824 if "OK" not in dev[0].request("MESH_PEER_REMOVE " + addr1):
825 raise Exception("Failed to remove peer")
826 pmksa0b = dev[0].get_pmksa(addr1)
828 raise Exception("PMKSA cache entry not maintained")
831 if "FAIL" not in dev[0].request("MESH_PEER_ADD " + addr1):
832 raise Exception("MESH_PEER_ADD unexpectedly succeeded in no_auto_peer=0 case")
834 def test_wpas_mesh_pmksa_caching2(dev, apdev):
835 """Secure mesh network and PMKSA caching with no_auto_peer=1"""
836 check_mesh_support(dev[0], secure=True)
837 addr0 = dev[0].own_addr()
838 addr1 = dev[1].own_addr()
839 dev[0].request("SET sae_groups ")
840 id = add_mesh_secure_net(dev[0])
841 dev[0].set_network(id, "no_auto_peer", "1")
842 dev[0].mesh_group_add(id)
844 dev[1].request("SET sae_groups ")
845 id = add_mesh_secure_net(dev[1])
846 dev[1].set_network(id, "no_auto_peer", "1")
847 dev[1].mesh_group_add(id)
849 # Check for mesh joined
850 check_mesh_group_added(dev[0])
851 check_mesh_group_added(dev[1])
853 # Check for peer connected
854 ev = dev[0].wait_event(["will not initiate new peer link"], timeout=10)
856 raise Exception("Missing no-initiate message")
857 if "OK" not in dev[0].request("MESH_PEER_ADD " + addr1):
858 raise Exception("MESH_PEER_ADD failed")
859 check_mesh_peer_connected(dev[0])
860 check_mesh_peer_connected(dev[1])
862 pmksa0 = dev[0].get_pmksa(addr1)
863 pmksa1 = dev[1].get_pmksa(addr0)
864 if pmksa0 is None or pmksa1 is None:
865 raise Exception("No PMKSA cache entry created")
866 if pmksa0['pmkid'] != pmksa1['pmkid']:
867 raise Exception("PMKID mismatch in PMKSA cache entries")
869 if "OK" not in dev[0].request("MESH_PEER_REMOVE " + addr1):
870 raise Exception("Failed to remove peer")
871 pmksa0b = dev[0].get_pmksa(addr1)
873 raise Exception("PMKSA cache entry not maintained")
875 ev = dev[0].wait_event(["will not initiate new peer link"], timeout=10)
877 raise Exception("Missing no-initiate message (2)")
878 if "OK" not in dev[0].request("MESH_PEER_ADD " + addr1):
879 raise Exception("MESH_PEER_ADD failed (2)")
880 check_mesh_peer_connected(dev[0])
881 check_mesh_peer_connected(dev[1])
883 pmksa0c = dev[0].get_pmksa(addr1)
884 pmksa1c = dev[1].get_pmksa(addr0)
885 if pmksa0c is None or pmksa1c is None:
886 raise Exception("No PMKSA cache entry created (2)")
887 if pmksa0c['pmkid'] != pmksa1c['pmkid']:
888 raise Exception("PMKID mismatch in PMKSA cache entries")
889 if pmksa0['pmkid'] != pmksa0c['pmkid']:
890 raise Exception("PMKID changed")
892 hwsim_utils.test_connectivity(dev[0], dev[1])
894 def test_wpas_mesh_pmksa_caching_no_match(dev, apdev):
895 """Secure mesh network and PMKSA caching with no PMKID match"""
896 check_mesh_support(dev[0], secure=True)
897 addr0 = dev[0].own_addr()
898 addr1 = dev[1].own_addr()
899 dev[0].request("SET sae_groups ")
900 id = add_mesh_secure_net(dev[0])
901 dev[0].set_network(id, "no_auto_peer", "1")
902 dev[0].mesh_group_add(id)
904 dev[1].request("SET sae_groups ")
905 id = add_mesh_secure_net(dev[1])
906 dev[1].set_network(id, "no_auto_peer", "1")
907 dev[1].mesh_group_add(id)
909 # Check for mesh joined
910 check_mesh_group_added(dev[0])
911 check_mesh_group_added(dev[1])
913 # Check for peer connected
914 ev = dev[0].wait_event(["will not initiate new peer link"], timeout=10)
916 raise Exception("Missing no-initiate message")
917 if "OK" not in dev[0].request("MESH_PEER_ADD " + addr1):
918 raise Exception("MESH_PEER_ADD failed")
919 check_mesh_peer_connected(dev[0])
920 check_mesh_peer_connected(dev[1])
922 pmksa0 = dev[0].get_pmksa(addr1)
923 pmksa1 = dev[1].get_pmksa(addr0)
924 if pmksa0 is None or pmksa1 is None:
925 raise Exception("No PMKSA cache entry created")
926 if pmksa0['pmkid'] != pmksa1['pmkid']:
927 raise Exception("PMKID mismatch in PMKSA cache entries")
929 if "OK" not in dev[0].request("MESH_PEER_REMOVE " + addr1):
930 raise Exception("Failed to remove peer")
932 if "OK" not in dev[1].request("PMKSA_FLUSH"):
933 raise Exception("Failed to flush PMKSA cache")
935 ev = dev[0].wait_event(["will not initiate new peer link"], timeout=10)
937 raise Exception("Missing no-initiate message (2)")
938 if "OK" not in dev[0].request("MESH_PEER_ADD " + addr1):
939 raise Exception("MESH_PEER_ADD failed (2)")
940 check_mesh_peer_connected(dev[0])
941 check_mesh_peer_connected(dev[1])
943 pmksa0c = dev[0].get_pmksa(addr1)
944 pmksa1c = dev[1].get_pmksa(addr0)
945 if pmksa0c is None or pmksa1c is None:
946 raise Exception("No PMKSA cache entry created (2)")
947 if pmksa0c['pmkid'] != pmksa1c['pmkid']:
948 raise Exception("PMKID mismatch in PMKSA cache entries")
949 if pmksa0['pmkid'] == pmksa0c['pmkid']:
950 raise Exception("PMKID did not change")
952 hwsim_utils.test_connectivity(dev[0], dev[1])