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, fail_test, 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")
113 dev.set_network(id, "frequency", freq)
115 dev.set_network(id, "max_oper_chwidth", str(chwidth))
117 dev.set_network(id, "beacon_int", str(beacon_int))
119 dev.set_network(id, "mesh_basic_rates", basic_rates)
121 dev.mesh_group_add(id)
124 def test_wpas_mesh_group_added(dev):
125 """wpa_supplicant MESH group add"""
126 check_mesh_support(dev[0])
127 add_open_mesh_network(dev[0])
129 # Check for MESH-GROUP-STARTED event
130 check_mesh_group_added(dev[0])
133 def test_wpas_mesh_group_remove(dev):
134 """wpa_supplicant MESH group remove"""
135 check_mesh_support(dev[0])
136 add_open_mesh_network(dev[0])
137 # Check for MESH-GROUP-STARTED event
138 check_mesh_group_added(dev[0])
139 dev[0].mesh_group_remove()
140 # Check for MESH-GROUP-REMOVED event
141 check_mesh_group_removed(dev[0])
142 dev[0].mesh_group_remove()
144 def test_wpas_mesh_peer_connected(dev):
145 """wpa_supplicant MESH peer connected"""
146 check_mesh_support(dev[0])
147 add_open_mesh_network(dev[0], beacon_int=160)
148 add_open_mesh_network(dev[1], beacon_int=160)
150 # Check for mesh joined
151 check_mesh_group_added(dev[0])
152 check_mesh_group_added(dev[1])
154 # Check for peer connected
155 check_mesh_peer_connected(dev[0])
156 check_mesh_peer_connected(dev[1])
159 def test_wpas_mesh_peer_disconnected(dev):
160 """wpa_supplicant MESH peer disconnected"""
161 check_mesh_support(dev[0])
162 add_open_mesh_network(dev[0])
163 add_open_mesh_network(dev[1])
165 # Check for mesh joined
166 check_mesh_group_added(dev[0])
167 check_mesh_group_added(dev[1])
169 # Check for peer connected
170 check_mesh_peer_connected(dev[0])
171 check_mesh_peer_connected(dev[1])
173 # Remove group on dev 1
174 dev[1].mesh_group_remove()
175 # Device 0 should get a disconnection event
176 check_mesh_peer_disconnected(dev[0])
179 def test_wpas_mesh_mode_scan(dev):
180 """wpa_supplicant MESH scan support"""
181 check_mesh_support(dev[0])
182 add_open_mesh_network(dev[0])
183 add_open_mesh_network(dev[1], beacon_int=175)
185 # Check for mesh joined
186 check_mesh_group_added(dev[0])
187 check_mesh_group_added(dev[1])
189 # Check for Mesh scan
190 check_mesh_scan(dev[0], "use_id=1", beacon_int=175)
192 def test_wpas_mesh_open(dev, apdev):
193 """wpa_supplicant open MESH network connectivity"""
194 check_mesh_support(dev[0])
195 add_open_mesh_network(dev[0], freq="2462", basic_rates="60 120 240")
196 add_open_mesh_network(dev[1], freq="2462", basic_rates="60 120 240")
198 # Check for mesh joined
199 check_mesh_group_added(dev[0])
200 check_mesh_group_added(dev[1])
202 # Check for peer connected
203 check_mesh_peer_connected(dev[0])
204 check_mesh_peer_connected(dev[1])
206 # Test connectivity 0->1 and 1->0
207 hwsim_utils.test_connectivity(dev[0], dev[1])
209 def test_wpas_mesh_open_no_auto(dev, apdev):
210 """wpa_supplicant open MESH network connectivity"""
211 check_mesh_support(dev[0])
212 id = add_open_mesh_network(dev[0], start=False)
213 dev[0].set_network(id, "dot11MeshMaxRetries", "16")
214 dev[0].set_network(id, "dot11MeshRetryTimeout", "255")
215 dev[0].mesh_group_add(id)
217 id = add_open_mesh_network(dev[1], start=False)
218 dev[1].set_network(id, "no_auto_peer", "1")
219 dev[1].mesh_group_add(id)
221 # Check for mesh joined
222 check_mesh_group_added(dev[0])
223 check_mesh_group_added(dev[1])
225 # Check for peer connected
226 check_mesh_peer_connected(dev[0], timeout=30)
227 check_mesh_peer_connected(dev[1])
229 # Test connectivity 0->1 and 1->0
230 hwsim_utils.test_connectivity(dev[0], dev[1])
232 def add_mesh_secure_net(dev, psk=True):
233 id = dev.add_network()
234 dev.set_network(id, "mode", "5")
235 dev.set_network_quoted(id, "ssid", "wpas-mesh-sec")
236 dev.set_network(id, "key_mgmt", "SAE")
237 dev.set_network(id, "frequency", "2412")
239 dev.set_network_quoted(id, "psk", "thisismypassphrase!")
242 def test_wpas_mesh_secure(dev, apdev):
243 """wpa_supplicant secure MESH network connectivity"""
244 check_mesh_support(dev[0], secure=True)
245 dev[0].request("SET sae_groups ")
246 id = add_mesh_secure_net(dev[0])
247 dev[0].mesh_group_add(id)
249 dev[1].request("SET sae_groups ")
250 id = add_mesh_secure_net(dev[1])
251 dev[1].mesh_group_add(id)
253 # Check for mesh joined
254 check_mesh_group_added(dev[0])
255 check_mesh_group_added(dev[1])
257 # Check for peer connected
258 check_mesh_peer_connected(dev[0])
259 check_mesh_peer_connected(dev[1])
261 # Test connectivity 0->1 and 1->0
262 hwsim_utils.test_connectivity(dev[0], dev[1])
264 def test_wpas_mesh_secure_sae_group_mismatch(dev, apdev):
265 """wpa_supplicant secure MESH and SAE group mismatch"""
266 check_mesh_support(dev[0], secure=True)
267 addr0 = dev[0].p2p_interface_addr()
268 addr1 = dev[1].p2p_interface_addr()
269 addr2 = dev[2].p2p_interface_addr()
271 dev[0].request("SET sae_groups 19 25")
272 id = add_mesh_secure_net(dev[0])
273 dev[0].mesh_group_add(id)
275 dev[1].request("SET sae_groups 19")
276 id = add_mesh_secure_net(dev[1])
277 dev[1].mesh_group_add(id)
279 dev[2].request("SET sae_groups 26")
280 id = add_mesh_secure_net(dev[2])
281 dev[2].mesh_group_add(id)
283 check_mesh_group_added(dev[0])
284 check_mesh_group_added(dev[1])
285 check_mesh_group_added(dev[2])
287 ev = dev[0].wait_event(["MESH-PEER-CONNECTED"])
289 raise Exception("Remote peer did not connect")
291 raise Exception("Unexpected peer connected: " + ev)
293 ev = dev[1].wait_event(["MESH-PEER-CONNECTED"])
295 raise Exception("Remote peer did not connect")
297 raise Exception("Unexpected peer connected: " + ev)
299 ev = dev[2].wait_event(["MESH-PEER-CONNECTED"], timeout=1)
301 raise Exception("Unexpected peer connection at dev[2]: " + ev)
303 ev = dev[0].wait_event(["MESH-PEER-CONNECTED"], timeout=0.1)
305 raise Exception("Unexpected peer connection: " + ev)
307 ev = dev[1].wait_event(["MESH-PEER-CONNECTED"], timeout=0.1)
309 raise Exception("Unexpected peer connection: " + ev)
311 dev[0].request("SET sae_groups ")
312 dev[1].request("SET sae_groups ")
313 dev[2].request("SET sae_groups ")
315 def test_wpas_mesh_secure_sae_group_negotiation(dev, apdev):
316 """wpa_supplicant secure MESH and SAE group negotiation"""
317 check_mesh_support(dev[0], secure=True)
318 addr0 = dev[0].own_addr()
319 addr1 = dev[1].own_addr()
321 #dev[0].request("SET sae_groups 21 20 25 26")
322 dev[0].request("SET sae_groups 25")
323 id = add_mesh_secure_net(dev[0])
324 dev[0].mesh_group_add(id)
326 dev[1].request("SET sae_groups 19 25")
327 id = add_mesh_secure_net(dev[1])
328 dev[1].mesh_group_add(id)
330 check_mesh_group_added(dev[0])
331 check_mesh_group_added(dev[1])
333 check_mesh_peer_connected(dev[0])
334 check_mesh_peer_connected(dev[1])
336 dev[0].request("SET sae_groups ")
337 dev[1].request("SET sae_groups ")
339 def test_wpas_mesh_secure_sae_missing_password(dev, apdev):
340 """wpa_supplicant secure MESH and missing SAE password"""
341 check_mesh_support(dev[0], secure=True)
342 id = add_mesh_secure_net(dev[0], psk=False)
343 dev[0].set_network(id, "psk", "8f20b381f9b84371d61b5080ad85cac3c61ab3ca9525be5b2d0f4da3d979187a")
344 dev[0].mesh_group_add(id)
345 ev = dev[0].wait_event(["MESH-GROUP-STARTED", "Could not join mesh"],
348 raise Exception("Timeout on mesh start event")
349 if "MESH-GROUP-STARTED" in ev:
350 raise Exception("Unexpected mesh group start")
351 ev = dev[0].wait_event(["MESH-GROUP-STARTED"], timeout=0.1)
353 raise Exception("Unexpected mesh group start")
355 def test_wpas_mesh_secure_no_auto(dev, apdev):
356 """wpa_supplicant secure MESH network connectivity"""
357 check_mesh_support(dev[0], secure=True)
358 dev[0].request("SET sae_groups 19")
359 id = add_mesh_secure_net(dev[0])
360 dev[0].mesh_group_add(id)
362 dev[1].request("SET sae_groups 19")
363 id = add_mesh_secure_net(dev[1])
364 dev[1].set_network(id, "no_auto_peer", "1")
365 dev[1].mesh_group_add(id)
367 # Check for mesh joined
368 check_mesh_group_added(dev[0])
369 check_mesh_group_added(dev[1])
371 # Check for peer connected
372 check_mesh_peer_connected(dev[0], timeout=30)
373 check_mesh_peer_connected(dev[1])
375 # Test connectivity 0->1 and 1->0
376 hwsim_utils.test_connectivity(dev[0], dev[1])
378 dev[0].request("SET sae_groups ")
379 dev[1].request("SET sae_groups ")
381 def test_wpas_mesh_secure_dropped_frame(dev, apdev):
382 """Secure mesh network connectivity when the first plink Open is dropped"""
383 check_mesh_support(dev[0], secure=True)
385 dev[0].request("SET ext_mgmt_frame_handling 1")
386 dev[0].request("SET sae_groups ")
387 id = add_mesh_secure_net(dev[0])
388 dev[0].mesh_group_add(id)
390 dev[1].request("SET sae_groups ")
391 id = add_mesh_secure_net(dev[1])
392 dev[1].mesh_group_add(id)
394 # Check for mesh joined
395 check_mesh_group_added(dev[0])
396 check_mesh_group_added(dev[1])
398 # Drop the first Action frame (plink Open) to test unexpected order of
399 # Confirm/Open messages.
404 raise Exception("Did not see Action frames")
405 rx_msg = dev[0].mgmt_rx()
407 raise Exception("MGMT-RX timeout")
408 if rx_msg['subtype'] == 13:
409 logger.info("Drop the first Action frame")
411 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'))):
412 raise Exception("MGMT_RX_PROCESS failed")
414 dev[0].request("SET ext_mgmt_frame_handling 0")
416 # Check for peer connected
417 check_mesh_peer_connected(dev[0])
418 check_mesh_peer_connected(dev[1])
420 # Test connectivity 0->1 and 1->0
421 hwsim_utils.test_connectivity(dev[0], dev[1])
423 def test_wpas_mesh_ctrl(dev):
424 """wpa_supplicant ctrl_iface mesh command error cases"""
425 check_mesh_support(dev[0])
426 if "FAIL" not in dev[0].request("MESH_GROUP_ADD 123"):
427 raise Exception("Unexpected MESH_GROUP_ADD success")
428 id = dev[0].add_network()
429 if "FAIL" not in dev[0].request("MESH_GROUP_ADD %d" % id):
430 raise Exception("Unexpected MESH_GROUP_ADD success")
431 dev[0].set_network(id, "mode", "5")
432 dev[0].set_network(id, "key_mgmt", "WPA-PSK")
433 if "FAIL" not in dev[0].request("MESH_GROUP_ADD %d" % id):
434 raise Exception("Unexpected MESH_GROUP_ADD success")
436 if "FAIL" not in dev[0].request("MESH_GROUP_REMOVE foo"):
437 raise Exception("Unexpected MESH_GROUP_REMOVE success")
439 def test_wpas_mesh_dynamic_interface(dev):
440 """wpa_supplicant mesh with dynamic interface"""
441 check_mesh_support(dev[0])
445 mesh0 = dev[0].request("MESH_INTERFACE_ADD ifname=mesh0")
447 raise Exception("MESH_INTERFACE_ADD failed")
448 mesh1 = dev[1].request("MESH_INTERFACE_ADD")
450 raise Exception("MESH_INTERFACE_ADD failed")
452 wpas0 = WpaSupplicant(ifname=mesh0)
453 wpas1 = WpaSupplicant(ifname=mesh1)
454 logger.info(mesh0 + " address " + wpas0.get_status_field("address"))
455 logger.info(mesh1 + " address " + wpas1.get_status_field("address"))
457 add_open_mesh_network(wpas0)
458 add_open_mesh_network(wpas1)
459 check_mesh_group_added(wpas0)
460 check_mesh_group_added(wpas1)
461 check_mesh_peer_connected(wpas0)
462 check_mesh_peer_connected(wpas1)
463 hwsim_utils.test_connectivity(wpas0, wpas1)
465 # Must not allow MESH_GROUP_REMOVE on dynamic interface
466 if "FAIL" not in wpas0.request("MESH_GROUP_REMOVE " + mesh0):
467 raise Exception("Invalid MESH_GROUP_REMOVE accepted")
468 if "FAIL" not in wpas1.request("MESH_GROUP_REMOVE " + mesh1):
469 raise Exception("Invalid MESH_GROUP_REMOVE accepted")
471 # Must not allow MESH_GROUP_REMOVE on another radio interface
472 if "FAIL" not in wpas0.request("MESH_GROUP_REMOVE " + mesh1):
473 raise Exception("Invalid MESH_GROUP_REMOVE accepted")
474 if "FAIL" not in wpas1.request("MESH_GROUP_REMOVE " + mesh0):
475 raise Exception("Invalid MESH_GROUP_REMOVE accepted")
477 wpas0.remove_ifname()
478 wpas1.remove_ifname()
480 if "OK" not in dev[0].request("MESH_GROUP_REMOVE " + mesh0):
481 raise Exception("MESH_GROUP_REMOVE failed")
482 if "OK" not in dev[1].request("MESH_GROUP_REMOVE " + mesh1):
483 raise Exception("MESH_GROUP_REMOVE failed")
485 if "FAIL" not in dev[0].request("MESH_GROUP_REMOVE " + mesh0):
486 raise Exception("Invalid MESH_GROUP_REMOVE accepted")
487 if "FAIL" not in dev[1].request("MESH_GROUP_REMOVE " + mesh1):
488 raise Exception("Invalid MESH_GROUP_REMOVE accepted")
490 logger.info("Make sure another dynamic group can be added")
491 mesh0 = dev[0].request("MESH_INTERFACE_ADD ifname=mesh0")
493 raise Exception("MESH_INTERFACE_ADD failed")
494 mesh1 = dev[1].request("MESH_INTERFACE_ADD")
496 raise Exception("MESH_INTERFACE_ADD failed")
498 wpas0 = WpaSupplicant(ifname=mesh0)
499 wpas1 = WpaSupplicant(ifname=mesh1)
500 logger.info(mesh0 + " address " + wpas0.get_status_field("address"))
501 logger.info(mesh1 + " address " + wpas1.get_status_field("address"))
503 add_open_mesh_network(wpas0)
504 add_open_mesh_network(wpas1)
505 check_mesh_group_added(wpas0)
506 check_mesh_group_added(wpas1)
507 check_mesh_peer_connected(wpas0)
508 check_mesh_peer_connected(wpas1)
509 hwsim_utils.test_connectivity(wpas0, wpas1)
512 dev[0].request("MESH_GROUP_REMOVE " + mesh0)
514 dev[1].request("MESH_GROUP_REMOVE " + mesh1)
516 def test_wpas_mesh_max_peering(dev, apdev):
517 """Mesh max peering limit"""
518 check_mesh_support(dev[0])
520 dev[0].request("SET max_peer_links 1")
522 # first, connect dev[0] and dev[1]
523 add_open_mesh_network(dev[0])
524 add_open_mesh_network(dev[1])
526 ev = dev[i].wait_event(["MESH-PEER-CONNECTED"])
528 raise Exception("dev%d did not connect with any peer" % i)
530 # add dev[2] which will try to connect with both dev[0] and dev[1],
531 # but can complete connection only with dev[1]
532 add_open_mesh_network(dev[2])
533 for i in range(1, 3):
534 ev = dev[i].wait_event(["MESH-PEER-CONNECTED"])
536 raise Exception("dev%d did not connect the second peer" % i)
538 ev = dev[0].wait_event(["MESH-PEER-CONNECTED"], timeout=1)
540 raise Exception("dev0 connection beyond max peering limit")
542 ev = dev[2].wait_event(["MESH-PEER-CONNECTED"], timeout=0.1)
544 raise Exception("dev2 reported unexpected peering: " + ev)
547 dev[i].mesh_group_remove()
548 check_mesh_group_removed(dev[i])
550 dev[0].request("SET max_peer_links 99")
552 def test_wpas_mesh_open_5ghz(dev, apdev):
553 """wpa_supplicant open MESH network on 5 GHz band"""
555 _test_wpas_mesh_open_5ghz(dev, apdev)
557 subprocess.call(['iw', 'reg', 'set', '00'])
558 dev[0].flush_scan_cache()
559 dev[1].flush_scan_cache()
561 def _test_wpas_mesh_open_5ghz(dev, apdev):
562 check_mesh_support(dev[0])
563 subprocess.call(['iw', 'reg', 'set', 'US'])
566 ev = dev[i].wait_event(["CTRL-EVENT-REGDOM-CHANGE"], timeout=5)
568 raise Exception("No regdom change event")
569 if "alpha2=US" in ev:
571 add_open_mesh_network(dev[i], freq="5180")
573 # Check for mesh joined
574 check_mesh_group_added(dev[0])
575 check_mesh_group_added(dev[1])
577 # Check for peer connected
578 check_mesh_peer_connected(dev[0])
579 check_mesh_peer_connected(dev[1])
581 # Test connectivity 0->1 and 1->0
582 hwsim_utils.test_connectivity(dev[0], dev[1])
584 def test_wpas_mesh_open_vht_80p80(dev, apdev):
585 """wpa_supplicant open MESH network on VHT 80+80 MHz channel"""
587 _test_wpas_mesh_open_vht_80p80(dev, apdev)
589 subprocess.call(['iw', 'reg', 'set', '00'])
590 dev[0].flush_scan_cache()
591 dev[1].flush_scan_cache()
593 def _test_wpas_mesh_open_vht_80p80(dev, apdev):
594 check_mesh_support(dev[0])
595 subprocess.call(['iw', 'reg', 'set', 'US'])
598 ev = dev[i].wait_event(["CTRL-EVENT-REGDOM-CHANGE"], timeout=5)
600 raise Exception("No regdom change event")
601 if "alpha2=US" in ev:
603 add_open_mesh_network(dev[i], freq="5180", chwidth=3)
605 # Check for mesh joined
606 check_mesh_group_added(dev[0])
607 check_mesh_group_added(dev[1])
609 # Check for peer connected
610 check_mesh_peer_connected(dev[0])
611 check_mesh_peer_connected(dev[1])
613 # Test connectivity 0->1 and 1->0
614 hwsim_utils.test_connectivity(dev[0], dev[1])
616 sig = dev[0].request("SIGNAL_POLL").splitlines()
617 if "WIDTH=80+80 MHz" not in sig:
618 raise Exception("Unexpected SIGNAL_POLL value(2): " + str(sig))
619 if "CENTER_FRQ1=5210" not in sig:
620 raise Exception("Unexpected SIGNAL_POLL value(3): " + str(sig))
621 if "CENTER_FRQ2=5775" not in sig:
622 raise Exception("Unexpected SIGNAL_POLL value(4): " + str(sig))
624 sig = dev[1].request("SIGNAL_POLL").splitlines()
625 if "WIDTH=80+80 MHz" not in sig:
626 raise Exception("Unexpected SIGNAL_POLL value(2b): " + str(sig))
627 if "CENTER_FRQ1=5210" not in sig:
628 raise Exception("Unexpected SIGNAL_POLL value(3b): " + str(sig))
629 if "CENTER_FRQ2=5775" not in sig:
630 raise Exception("Unexpected SIGNAL_POLL value(4b): " + str(sig))
632 def test_wpas_mesh_password_mismatch(dev, apdev):
633 """Mesh network and one device with mismatching password"""
634 check_mesh_support(dev[0], secure=True)
635 dev[0].request("SET sae_groups ")
636 id = add_mesh_secure_net(dev[0])
637 dev[0].mesh_group_add(id)
639 dev[1].request("SET sae_groups ")
640 id = add_mesh_secure_net(dev[1])
641 dev[1].mesh_group_add(id)
643 dev[2].request("SET sae_groups ")
644 id = add_mesh_secure_net(dev[2])
645 dev[2].set_network_quoted(id, "psk", "wrong password")
646 dev[2].mesh_group_add(id)
648 # The two peers with matching password need to be able to connect
649 check_mesh_group_added(dev[0])
650 check_mesh_group_added(dev[1])
651 check_mesh_peer_connected(dev[0])
652 check_mesh_peer_connected(dev[1])
654 ev = dev[2].wait_event(["MESH-SAE-AUTH-FAILURE"], timeout=20)
656 raise Exception("dev2 did not report auth failure (1)")
657 ev = dev[2].wait_event(["MESH-SAE-AUTH-FAILURE"], timeout=20)
659 raise Exception("dev2 did not report auth failure (2)")
662 ev = dev[0].wait_event(["MESH-SAE-AUTH-FAILURE"], timeout=1)
664 logger.info("dev0 did not report auth failure")
666 if "addr=" + dev[2].own_addr() not in ev:
667 raise Exception("Unexpected peer address in dev0 event: " + ev)
670 ev = dev[1].wait_event(["MESH-SAE-AUTH-FAILURE"], timeout=1)
672 logger.info("dev1 did not report auth failure")
674 if "addr=" + dev[2].own_addr() not in ev:
675 raise Exception("Unexpected peer address in dev1 event: " + ev)
678 hwsim_utils.test_connectivity(dev[0], dev[1])
682 hwsim_utils.test_connectivity(dev[i], dev[2], timeout=1)
683 raise Exception("Data connectivity test passed unexpectedly")
685 if "data delivery failed" not in str(e):
689 raise Exception("Neither dev0 nor dev1 reported auth failure")
691 def test_wpas_mesh_password_mismatch_retry(dev, apdev, params):
692 """Mesh password mismatch and retry [long]"""
693 if not params['long']:
694 raise HwsimSkip("Skip test case with long duration due to --long not specified")
695 check_mesh_support(dev[0], secure=True)
696 dev[0].request("SET sae_groups ")
697 id = add_mesh_secure_net(dev[0])
698 dev[0].mesh_group_add(id)
700 dev[1].request("SET sae_groups ")
701 id = add_mesh_secure_net(dev[1])
702 dev[1].set_network_quoted(id, "psk", "wrong password")
703 dev[1].mesh_group_add(id)
705 # Check for mesh joined
706 check_mesh_group_added(dev[0])
707 check_mesh_group_added(dev[1])
710 ev = dev[0].wait_event(["MESH-SAE-AUTH-FAILURE"], timeout=20)
712 raise Exception("dev0 did not report auth failure (%d)" % i)
713 ev = dev[1].wait_event(["MESH-SAE-AUTH-FAILURE"], timeout=20)
715 raise Exception("dev1 did not report auth failure (%d)" % i)
717 ev = dev[0].wait_event(["MESH-SAE-AUTH-BLOCKED"], timeout=10)
719 raise Exception("dev0 did not report auth blocked")
720 ev = dev[1].wait_event(["MESH-SAE-AUTH-BLOCKED"], timeout=10)
722 raise Exception("dev1 did not report auth blocked")
724 def test_mesh_wpa_auth_init_oom(dev, apdev):
725 """Secure mesh network setup failing due to wpa_init() OOM"""
726 check_mesh_support(dev[0], secure=True)
727 dev[0].request("SET sae_groups ")
728 with alloc_fail(dev[0], 1, "wpa_init"):
729 id = add_mesh_secure_net(dev[0])
730 dev[0].mesh_group_add(id)
731 ev = dev[0].wait_event(["MESH-GROUP-STARTED"], timeout=0.2)
733 raise Exception("Unexpected mesh group start during OOM")
735 def test_mesh_wpa_init_fail(dev, apdev):
736 """Secure mesh network setup local failure"""
737 check_mesh_support(dev[0], secure=True)
738 dev[0].request("SET sae_groups ")
740 with fail_test(dev[0], 1, "os_get_random;=__mesh_rsn_auth_init"):
741 id = add_mesh_secure_net(dev[0])
742 dev[0].mesh_group_add(id)
743 wait_fail_trigger(dev[0], "GET_FAIL")
745 with alloc_fail(dev[0], 1, "mesh_rsn_auth_init"):
746 id = add_mesh_secure_net(dev[0])
747 dev[0].mesh_group_add(id)
748 wait_fail_trigger(dev[0], "GET_ALLOC_FAIL")
750 def test_wpas_mesh_reconnect(dev, apdev):
751 """Secure mesh network plink counting during reconnection"""
752 check_mesh_support(dev[0])
754 _test_wpas_mesh_reconnect(dev)
756 dev[0].request("SET max_peer_links 99")
758 def _test_wpas_mesh_reconnect(dev):
759 dev[0].request("SET max_peer_links 2")
760 dev[0].request("SET sae_groups ")
761 id = add_mesh_secure_net(dev[0])
762 dev[0].set_network(id, "beacon_int", "100")
763 dev[0].mesh_group_add(id)
764 dev[1].request("SET sae_groups ")
765 id = add_mesh_secure_net(dev[1])
766 dev[1].mesh_group_add(id)
767 check_mesh_group_added(dev[0])
768 check_mesh_group_added(dev[1])
769 check_mesh_peer_connected(dev[0])
770 check_mesh_peer_connected(dev[1])
773 # Drop incoming management frames to avoid handling link close
774 dev[0].request("SET ext_mgmt_frame_handling 1")
775 dev[1].mesh_group_remove()
776 check_mesh_group_removed(dev[1])
777 dev[1].request("FLUSH")
778 dev[0].request("SET ext_mgmt_frame_handling 0")
779 id = add_mesh_secure_net(dev[1])
780 dev[1].mesh_group_add(id)
781 check_mesh_group_added(dev[1])
782 check_mesh_peer_connected(dev[1])
783 dev[0].dump_monitor()
784 dev[1].dump_monitor()
786 def test_wpas_mesh_gate_forwarding(dev, apdev, p):
787 """Mesh forwards traffic to unknown sta to mesh gates"""
788 addr0 = dev[0].own_addr()
789 addr1 = dev[1].own_addr()
790 addr2 = dev[2].own_addr()
791 external_sta = '02:11:22:33:44:55'
793 # start 3 node connected mesh
794 check_mesh_support(dev[0])
796 add_open_mesh_network(dev[i])
797 check_mesh_group_added(dev[i])
799 check_mesh_peer_connected(dev[i])
801 hwsim_utils.test_connectivity(dev[0], dev[1])
802 hwsim_utils.test_connectivity(dev[1], dev[2])
803 hwsim_utils.test_connectivity(dev[0], dev[2])
805 # dev0 and dev1 are mesh gates
806 subprocess.call(['iw', 'dev', dev[0].ifname, 'set', 'mesh_param',
807 'mesh_gate_announcements=1'])
808 subprocess.call(['iw', 'dev', dev[1].ifname, 'set', 'mesh_param',
809 'mesh_gate_announcements=1'])
811 # wait for gate announcement frames
814 # data frame from dev2 -> external sta should be sent to both gates
815 dev[2].request("DATA_TEST_CONFIG 1")
816 dev[2].request("DATA_TEST_TX {} {} 0".format(external_sta, addr2))
817 dev[2].request("DATA_TEST_CONFIG 0")
819 capfile = os.path.join(p['logdir'], "hwsim0.pcapng")
820 filt = "wlan.sa==%s && wlan_mgt.fixed.mesh_addr5==%s" % (addr2,
823 da = run_tshark(capfile, filt, [ "wlan.da" ])
824 if addr0 in da and addr1 in da:
825 logger.debug("Frames seen in tshark iteration %d" % i)
830 raise Exception("Frame to gate %s not observed" % addr0)
832 raise Exception("Frame to gate %s not observed" % addr1)
834 def test_wpas_mesh_pmksa_caching(dev, apdev):
835 """Secure mesh network and PMKSA caching"""
836 check_mesh_support(dev[0], secure=True)
837 dev[0].request("SET sae_groups ")
838 id = add_mesh_secure_net(dev[0])
839 dev[0].mesh_group_add(id)
841 dev[1].request("SET sae_groups ")
842 id = add_mesh_secure_net(dev[1])
843 dev[1].mesh_group_add(id)
845 # Check for mesh joined
846 check_mesh_group_added(dev[0])
847 check_mesh_group_added(dev[1])
849 # Check for peer connected
850 check_mesh_peer_connected(dev[0])
851 check_mesh_peer_connected(dev[1])
853 addr0 = dev[0].own_addr()
854 addr1 = dev[1].own_addr()
855 pmksa0 = dev[0].get_pmksa(addr1)
856 pmksa1 = dev[1].get_pmksa(addr0)
857 if pmksa0 is None or pmksa1 is None:
858 raise Exception("No PMKSA cache entry created")
859 if pmksa0['pmkid'] != pmksa1['pmkid']:
860 raise Exception("PMKID mismatch in PMKSA cache entries")
862 if "OK" not in dev[0].request("MESH_PEER_REMOVE " + addr1):
863 raise Exception("Failed to remove peer")
864 pmksa0b = dev[0].get_pmksa(addr1)
866 raise Exception("PMKSA cache entry not maintained")
869 if "FAIL" not in dev[0].request("MESH_PEER_ADD " + addr1):
870 raise Exception("MESH_PEER_ADD unexpectedly succeeded in no_auto_peer=0 case")
872 def test_wpas_mesh_pmksa_caching2(dev, apdev):
873 """Secure mesh network and PMKSA caching with no_auto_peer=1"""
874 check_mesh_support(dev[0], secure=True)
875 addr0 = dev[0].own_addr()
876 addr1 = dev[1].own_addr()
877 dev[0].request("SET sae_groups ")
878 id = add_mesh_secure_net(dev[0])
879 dev[0].set_network(id, "no_auto_peer", "1")
880 dev[0].mesh_group_add(id)
882 dev[1].request("SET sae_groups ")
883 id = add_mesh_secure_net(dev[1])
884 dev[1].set_network(id, "no_auto_peer", "1")
885 dev[1].mesh_group_add(id)
887 # Check for mesh joined
888 check_mesh_group_added(dev[0])
889 check_mesh_group_added(dev[1])
891 # Check for peer connected
892 ev = dev[0].wait_event(["will not initiate new peer link"], timeout=10)
894 raise Exception("Missing no-initiate message")
895 if "OK" not in dev[0].request("MESH_PEER_ADD " + addr1):
896 raise Exception("MESH_PEER_ADD failed")
897 check_mesh_peer_connected(dev[0])
898 check_mesh_peer_connected(dev[1])
900 pmksa0 = dev[0].get_pmksa(addr1)
901 pmksa1 = dev[1].get_pmksa(addr0)
902 if pmksa0 is None or pmksa1 is None:
903 raise Exception("No PMKSA cache entry created")
904 if pmksa0['pmkid'] != pmksa1['pmkid']:
905 raise Exception("PMKID mismatch in PMKSA cache entries")
907 if "OK" not in dev[0].request("MESH_PEER_REMOVE " + addr1):
908 raise Exception("Failed to remove peer")
909 pmksa0b = dev[0].get_pmksa(addr1)
911 raise Exception("PMKSA cache entry not maintained")
913 ev = dev[0].wait_event(["will not initiate new peer link"], timeout=10)
915 raise Exception("Missing no-initiate message (2)")
916 if "OK" not in dev[0].request("MESH_PEER_ADD " + addr1):
917 raise Exception("MESH_PEER_ADD failed (2)")
918 check_mesh_peer_connected(dev[0])
919 check_mesh_peer_connected(dev[1])
921 pmksa0c = dev[0].get_pmksa(addr1)
922 pmksa1c = dev[1].get_pmksa(addr0)
923 if pmksa0c is None or pmksa1c is None:
924 raise Exception("No PMKSA cache entry created (2)")
925 if pmksa0c['pmkid'] != pmksa1c['pmkid']:
926 raise Exception("PMKID mismatch in PMKSA cache entries")
927 if pmksa0['pmkid'] != pmksa0c['pmkid']:
928 raise Exception("PMKID changed")
930 hwsim_utils.test_connectivity(dev[0], dev[1])
932 def test_wpas_mesh_pmksa_caching_no_match(dev, apdev):
933 """Secure mesh network and PMKSA caching with no PMKID match"""
934 check_mesh_support(dev[0], secure=True)
935 addr0 = dev[0].own_addr()
936 addr1 = dev[1].own_addr()
937 dev[0].request("SET sae_groups ")
938 id = add_mesh_secure_net(dev[0])
939 dev[0].set_network(id, "no_auto_peer", "1")
940 dev[0].mesh_group_add(id)
942 dev[1].request("SET sae_groups ")
943 id = add_mesh_secure_net(dev[1])
944 dev[1].set_network(id, "no_auto_peer", "1")
945 dev[1].mesh_group_add(id)
947 # Check for mesh joined
948 check_mesh_group_added(dev[0])
949 check_mesh_group_added(dev[1])
951 # Check for peer connected
952 ev = dev[0].wait_event(["will not initiate new peer link"], timeout=10)
954 raise Exception("Missing no-initiate message")
955 if "OK" not in dev[0].request("MESH_PEER_ADD " + addr1):
956 raise Exception("MESH_PEER_ADD failed")
957 check_mesh_peer_connected(dev[0])
958 check_mesh_peer_connected(dev[1])
960 pmksa0 = dev[0].get_pmksa(addr1)
961 pmksa1 = dev[1].get_pmksa(addr0)
962 if pmksa0 is None or pmksa1 is None:
963 raise Exception("No PMKSA cache entry created")
964 if pmksa0['pmkid'] != pmksa1['pmkid']:
965 raise Exception("PMKID mismatch in PMKSA cache entries")
967 if "OK" not in dev[0].request("MESH_PEER_REMOVE " + addr1):
968 raise Exception("Failed to remove peer")
970 if "OK" not in dev[1].request("PMKSA_FLUSH"):
971 raise Exception("Failed to flush PMKSA cache")
973 ev = dev[0].wait_event(["will not initiate new peer link"], timeout=10)
975 raise Exception("Missing no-initiate message (2)")
976 if "OK" not in dev[0].request("MESH_PEER_ADD " + addr1):
977 raise Exception("MESH_PEER_ADD failed (2)")
978 check_mesh_peer_connected(dev[0])
979 check_mesh_peer_connected(dev[1])
981 pmksa0c = dev[0].get_pmksa(addr1)
982 pmksa1c = dev[1].get_pmksa(addr0)
983 if pmksa0c is None or pmksa1c is None:
984 raise Exception("No PMKSA cache entry created (2)")
985 if pmksa0c['pmkid'] != pmksa1c['pmkid']:
986 raise Exception("PMKID mismatch in PMKSA cache entries")
987 if pmksa0['pmkid'] == pmksa0c['pmkid']:
988 raise Exception("PMKID did not change")
990 hwsim_utils.test_connectivity(dev[0], dev[1])
992 def test_mesh_oom(dev, apdev):
993 """Mesh network setup failing due to OOM"""
994 check_mesh_support(dev[0], secure=True)
995 dev[0].request("SET sae_groups ")
997 with alloc_fail(dev[0], 1, "mesh_config_create"):
998 add_open_mesh_network(dev[0])
999 ev = dev[0].wait_event(["Failed to init mesh"])
1001 raise Exception("Init failure not reported")
1003 for i in range(1, 65):
1004 with alloc_fail(dev[0], i, "wpa_supplicant_mesh_init"):
1005 add_open_mesh_network(dev[0])
1006 wait_fail_trigger(dev[0], "GET_ALLOC_FAIL")
1007 ev = dev[0].wait_event(["Failed to init mesh",
1008 "MESH-GROUP-STARTED"])
1010 raise Exception("Init failure not reported")
1012 def test_mesh_add_interface_oom(dev):
1013 """wpa_supplicant mesh with dynamic interface addition failing"""
1014 check_mesh_support(dev[0])
1015 for i in range(1, 3):
1018 with alloc_fail(dev[0], i, "wpas_mesh_add_interface"):
1019 mesh = dev[0].request("MESH_INTERFACE_ADD").strip()
1021 if mesh and mesh != "FAIL":
1022 dev[0].request("MESH_GROUP_REMOVE " + mesh)
1024 def test_mesh_scan_oom(dev):
1025 """wpa_supplicant mesh scan results and OOM"""
1026 check_mesh_support(dev[0])
1027 add_open_mesh_network(dev[0])
1028 check_mesh_group_added(dev[0])
1030 dev[1].scan(freq="2412")
1031 res = dev[1].request("SCAN_RESULTS")
1034 for r in res.splitlines():
1037 bssid = r.split('\t')[0]
1039 bss = dev[1].get_bss(bssid)
1041 raise Exception("Could not get BSS entry for mesh")
1043 for i in range(1, 3):
1044 with alloc_fail(dev[1], i, "mesh_attr_text"):
1045 bss = dev[1].get_bss(bssid)
1047 raise Exception("Unexpected BSS result during OOM")
1049 def test_mesh_sae_groups_invalid(dev, apdev):
1050 """Mesh with invalid SAE group configuration"""
1051 check_mesh_support(dev[0], secure=True)
1053 dev[0].request("SET sae_groups 25")
1054 id = add_mesh_secure_net(dev[0])
1055 dev[0].mesh_group_add(id)
1057 dev[1].request("SET sae_groups 123 122 121")
1058 id = add_mesh_secure_net(dev[1])
1059 dev[1].mesh_group_add(id)
1061 check_mesh_group_added(dev[0])
1062 check_mesh_group_added(dev[1])
1064 ev = dev[0].wait_event(["new peer notification"], timeout=10)
1066 raise Exception("dev[0] did not see peer")
1067 ev = dev[1].wait_event(["new peer notification"], timeout=10)
1069 raise Exception("dev[1] did not see peer")
1071 ev = dev[0].wait_event(["MESH-PEER-CONNECTED"], timeout=0.1)
1073 raise Exception("Unexpected connection(0)")
1075 ev = dev[1].wait_event(["MESH-PEER-CONNECTED"], timeout=0.01)
1077 raise Exception("Unexpected connection(1)")
1079 dev[0].request("SET sae_groups ")
1080 dev[1].request("SET sae_groups ")
1082 def test_mesh_sae_failure(dev, apdev):
1083 """Mesh and local SAE failures"""
1084 check_mesh_support(dev[0], secure=True)
1086 dev[0].request("SET sae_groups ")
1087 dev[1].request("SET sae_groups ")
1089 funcs = [ (1, "=mesh_rsn_auth_sae_sta", True),
1090 (1, "mesh_rsn_build_sae_commit;mesh_rsn_auth_sae_sta", False),
1091 (1, "auth_sae_init_committed;mesh_rsn_auth_sae_sta", True),
1092 (1, "=mesh_rsn_protect_frame", True),
1093 (2, "=mesh_rsn_protect_frame", True),
1094 (1, "aes_siv_encrypt;mesh_rsn_protect_frame", True),
1095 (1, "=mesh_rsn_process_ampe", True),
1096 (1, "aes_siv_decrypt;mesh_rsn_process_ampe", True) ]
1097 for count, func, success in funcs:
1098 id = add_mesh_secure_net(dev[0])
1099 dev[0].mesh_group_add(id)
1101 with alloc_fail(dev[1], count, func):
1102 id = add_mesh_secure_net(dev[1])
1103 dev[1].mesh_group_add(id)
1104 check_mesh_group_added(dev[0])
1105 check_mesh_group_added(dev[1])
1107 # retry is expected to work
1108 check_mesh_peer_connected(dev[0])
1109 check_mesh_peer_connected(dev[1])
1111 wait_fail_trigger(dev[1], "GET_ALLOC_FAIL")
1112 dev[0].mesh_group_remove()
1113 dev[1].mesh_group_remove()
1114 check_mesh_group_removed(dev[0])
1115 check_mesh_group_removed(dev[1])
1117 def test_mesh_failure(dev, apdev):
1118 """Mesh and local failures"""
1119 check_mesh_support(dev[0])
1121 funcs = [ (1, "ap_sta_add;mesh_mpm_add_peer", True),
1122 (1, "wpabuf_alloc;mesh_mpm_send_plink_action", True) ]
1123 for count, func, success in funcs:
1124 add_open_mesh_network(dev[0])
1126 with alloc_fail(dev[1], count, func):
1127 add_open_mesh_network(dev[1])
1128 check_mesh_group_added(dev[0])
1129 check_mesh_group_added(dev[1])
1131 # retry is expected to work
1132 check_mesh_peer_connected(dev[0])
1133 check_mesh_peer_connected(dev[1])
1135 wait_fail_trigger(dev[1], "GET_ALLOC_FAIL")
1136 dev[0].mesh_group_remove()
1137 dev[1].mesh_group_remove()
1138 check_mesh_group_removed(dev[0])
1139 check_mesh_group_removed(dev[1])
1141 funcs = [ (1, "mesh_mpm_init_link", True) ]
1142 for count, func, success in funcs:
1143 add_open_mesh_network(dev[0])
1145 with fail_test(dev[1], count, func):
1146 add_open_mesh_network(dev[1])
1147 check_mesh_group_added(dev[0])
1148 check_mesh_group_added(dev[1])
1150 # retry is expected to work
1151 check_mesh_peer_connected(dev[0])
1152 check_mesh_peer_connected(dev[1])
1154 wait_fail_trigger(dev[1], "GET_FAIL")
1155 dev[0].mesh_group_remove()
1156 dev[1].mesh_group_remove()
1157 check_mesh_group_removed(dev[0])
1158 check_mesh_group_removed(dev[1])
1160 def test_mesh_invalid_frequency(dev, apdev):
1161 """Mesh and invalid frequency configuration"""
1162 check_mesh_support(dev[0])
1163 add_open_mesh_network(dev[0], freq=None)
1164 ev = dev[0].wait_event(["MESH-GROUP-STARTED",
1165 "Could not join mesh"])
1166 if ev is None or "Could not join mesh" not in ev:
1167 raise Exception("Mesh join failure not reported")
1168 dev[0].request("REMOVE_NETWORK all")
1170 add_open_mesh_network(dev[0], freq="2413")
1171 ev = dev[0].wait_event(["MESH-GROUP-STARTED",
1172 "Could not join mesh"])
1173 if ev is None or "Could not join mesh" not in ev:
1174 raise Exception("Mesh join failure not reported")