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")
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_group_negotiation(dev, apdev):
315 """wpa_supplicant secure MESH and SAE group negotiation"""
316 check_mesh_support(dev[0], secure=True)
317 addr0 = dev[0].own_addr()
318 addr1 = dev[1].own_addr()
320 #dev[0].request("SET sae_groups 21 20 25 26")
321 dev[0].request("SET sae_groups 25")
322 id = add_mesh_secure_net(dev[0])
323 dev[0].mesh_group_add(id)
325 dev[1].request("SET sae_groups 19 25")
326 id = add_mesh_secure_net(dev[1])
327 dev[1].mesh_group_add(id)
329 check_mesh_group_added(dev[0])
330 check_mesh_group_added(dev[1])
332 check_mesh_peer_connected(dev[0])
333 check_mesh_peer_connected(dev[1])
335 dev[0].request("SET sae_groups ")
336 dev[1].request("SET sae_groups ")
338 def test_wpas_mesh_secure_sae_missing_password(dev, apdev):
339 """wpa_supplicant secure MESH and missing SAE password"""
340 check_mesh_support(dev[0], secure=True)
341 id = add_mesh_secure_net(dev[0], psk=False)
342 dev[0].set_network(id, "psk", "8f20b381f9b84371d61b5080ad85cac3c61ab3ca9525be5b2d0f4da3d979187a")
343 dev[0].mesh_group_add(id)
344 ev = dev[0].wait_event(["MESH-GROUP-STARTED", "Could not join mesh"],
347 raise Exception("Timeout on mesh start event")
348 if "MESH-GROUP-STARTED" in ev:
349 raise Exception("Unexpected mesh group start")
350 ev = dev[0].wait_event(["MESH-GROUP-STARTED"], timeout=0.1)
352 raise Exception("Unexpected mesh group start")
354 def test_wpas_mesh_secure_no_auto(dev, apdev):
355 """wpa_supplicant secure MESH network connectivity"""
356 check_mesh_support(dev[0], secure=True)
357 dev[0].request("SET sae_groups 19")
358 id = add_mesh_secure_net(dev[0])
359 dev[0].mesh_group_add(id)
361 dev[1].request("SET sae_groups 19")
362 id = add_mesh_secure_net(dev[1])
363 dev[1].set_network(id, "no_auto_peer", "1")
364 dev[1].mesh_group_add(id)
366 # Check for mesh joined
367 check_mesh_group_added(dev[0])
368 check_mesh_group_added(dev[1])
370 # Check for peer connected
371 check_mesh_peer_connected(dev[0], timeout=30)
372 check_mesh_peer_connected(dev[1])
374 # Test connectivity 0->1 and 1->0
375 hwsim_utils.test_connectivity(dev[0], dev[1])
377 dev[0].request("SET sae_groups ")
378 dev[1].request("SET sae_groups ")
380 def test_wpas_mesh_secure_dropped_frame(dev, apdev):
381 """Secure mesh network connectivity when the first plink Open is dropped"""
382 check_mesh_support(dev[0], secure=True)
384 dev[0].request("SET ext_mgmt_frame_handling 1")
385 dev[0].request("SET sae_groups ")
386 id = add_mesh_secure_net(dev[0])
387 dev[0].mesh_group_add(id)
389 dev[1].request("SET sae_groups ")
390 id = add_mesh_secure_net(dev[1])
391 dev[1].mesh_group_add(id)
393 # Check for mesh joined
394 check_mesh_group_added(dev[0])
395 check_mesh_group_added(dev[1])
397 # Drop the first Action frame (plink Open) to test unexpected order of
398 # Confirm/Open messages.
403 raise Exception("Did not see Action frames")
404 rx_msg = dev[0].mgmt_rx()
406 raise Exception("MGMT-RX timeout")
407 if rx_msg['subtype'] == 13:
408 logger.info("Drop the first Action frame")
410 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'))):
411 raise Exception("MGMT_RX_PROCESS failed")
413 dev[0].request("SET ext_mgmt_frame_handling 0")
415 # Check for peer connected
416 check_mesh_peer_connected(dev[0])
417 check_mesh_peer_connected(dev[1])
419 # Test connectivity 0->1 and 1->0
420 hwsim_utils.test_connectivity(dev[0], dev[1])
422 def test_wpas_mesh_ctrl(dev):
423 """wpa_supplicant ctrl_iface mesh command error cases"""
424 check_mesh_support(dev[0])
425 if "FAIL" not in dev[0].request("MESH_GROUP_ADD 123"):
426 raise Exception("Unexpected MESH_GROUP_ADD success")
427 id = dev[0].add_network()
428 if "FAIL" not in dev[0].request("MESH_GROUP_ADD %d" % id):
429 raise Exception("Unexpected MESH_GROUP_ADD success")
430 dev[0].set_network(id, "mode", "5")
431 dev[0].set_network(id, "key_mgmt", "WPA-PSK")
432 if "FAIL" not in dev[0].request("MESH_GROUP_ADD %d" % id):
433 raise Exception("Unexpected MESH_GROUP_ADD success")
435 if "FAIL" not in dev[0].request("MESH_GROUP_REMOVE foo"):
436 raise Exception("Unexpected MESH_GROUP_REMOVE success")
438 def test_wpas_mesh_dynamic_interface(dev):
439 """wpa_supplicant mesh with dynamic interface"""
440 check_mesh_support(dev[0])
444 mesh0 = dev[0].request("MESH_INTERFACE_ADD ifname=mesh0")
446 raise Exception("MESH_INTERFACE_ADD failed")
447 mesh1 = dev[1].request("MESH_INTERFACE_ADD")
449 raise Exception("MESH_INTERFACE_ADD failed")
451 wpas0 = WpaSupplicant(ifname=mesh0)
452 wpas1 = WpaSupplicant(ifname=mesh1)
453 logger.info(mesh0 + " address " + wpas0.get_status_field("address"))
454 logger.info(mesh1 + " address " + wpas1.get_status_field("address"))
456 add_open_mesh_network(wpas0)
457 add_open_mesh_network(wpas1)
458 check_mesh_group_added(wpas0)
459 check_mesh_group_added(wpas1)
460 check_mesh_peer_connected(wpas0)
461 check_mesh_peer_connected(wpas1)
462 hwsim_utils.test_connectivity(wpas0, wpas1)
464 # Must not allow MESH_GROUP_REMOVE on dynamic interface
465 if "FAIL" not in wpas0.request("MESH_GROUP_REMOVE " + mesh0):
466 raise Exception("Invalid MESH_GROUP_REMOVE accepted")
467 if "FAIL" not in wpas1.request("MESH_GROUP_REMOVE " + mesh1):
468 raise Exception("Invalid MESH_GROUP_REMOVE accepted")
470 # Must not allow MESH_GROUP_REMOVE on another radio interface
471 if "FAIL" not in wpas0.request("MESH_GROUP_REMOVE " + mesh1):
472 raise Exception("Invalid MESH_GROUP_REMOVE accepted")
473 if "FAIL" not in wpas1.request("MESH_GROUP_REMOVE " + mesh0):
474 raise Exception("Invalid MESH_GROUP_REMOVE accepted")
476 wpas0.remove_ifname()
477 wpas1.remove_ifname()
479 if "OK" not in dev[0].request("MESH_GROUP_REMOVE " + mesh0):
480 raise Exception("MESH_GROUP_REMOVE failed")
481 if "OK" not in dev[1].request("MESH_GROUP_REMOVE " + mesh1):
482 raise Exception("MESH_GROUP_REMOVE failed")
484 if "FAIL" not in dev[0].request("MESH_GROUP_REMOVE " + mesh0):
485 raise Exception("Invalid MESH_GROUP_REMOVE accepted")
486 if "FAIL" not in dev[1].request("MESH_GROUP_REMOVE " + mesh1):
487 raise Exception("Invalid MESH_GROUP_REMOVE accepted")
489 logger.info("Make sure another dynamic group can be added")
490 mesh0 = dev[0].request("MESH_INTERFACE_ADD ifname=mesh0")
492 raise Exception("MESH_INTERFACE_ADD failed")
493 mesh1 = dev[1].request("MESH_INTERFACE_ADD")
495 raise Exception("MESH_INTERFACE_ADD failed")
497 wpas0 = WpaSupplicant(ifname=mesh0)
498 wpas1 = WpaSupplicant(ifname=mesh1)
499 logger.info(mesh0 + " address " + wpas0.get_status_field("address"))
500 logger.info(mesh1 + " address " + wpas1.get_status_field("address"))
502 add_open_mesh_network(wpas0)
503 add_open_mesh_network(wpas1)
504 check_mesh_group_added(wpas0)
505 check_mesh_group_added(wpas1)
506 check_mesh_peer_connected(wpas0)
507 check_mesh_peer_connected(wpas1)
508 hwsim_utils.test_connectivity(wpas0, wpas1)
511 dev[0].request("MESH_GROUP_REMOVE " + mesh0)
513 dev[1].request("MESH_GROUP_REMOVE " + mesh1)
515 def test_wpas_mesh_max_peering(dev, apdev):
516 """Mesh max peering limit"""
517 check_mesh_support(dev[0])
519 dev[0].request("SET max_peer_links 1")
521 # first, connect dev[0] and dev[1]
522 add_open_mesh_network(dev[0])
523 add_open_mesh_network(dev[1])
525 ev = dev[i].wait_event(["MESH-PEER-CONNECTED"])
527 raise Exception("dev%d did not connect with any peer" % i)
529 # add dev[2] which will try to connect with both dev[0] and dev[1],
530 # but can complete connection only with dev[1]
531 add_open_mesh_network(dev[2])
532 for i in range(1, 3):
533 ev = dev[i].wait_event(["MESH-PEER-CONNECTED"])
535 raise Exception("dev%d did not connect the second peer" % i)
537 ev = dev[0].wait_event(["MESH-PEER-CONNECTED"], timeout=1)
539 raise Exception("dev0 connection beyond max peering limit")
541 ev = dev[2].wait_event(["MESH-PEER-CONNECTED"], timeout=0.1)
543 raise Exception("dev2 reported unexpected peering: " + ev)
546 dev[i].mesh_group_remove()
547 check_mesh_group_removed(dev[i])
549 dev[0].request("SET max_peer_links 99")
551 def test_wpas_mesh_open_5ghz(dev, apdev):
552 """wpa_supplicant open MESH network on 5 GHz band"""
554 _test_wpas_mesh_open_5ghz(dev, apdev)
556 subprocess.call(['iw', 'reg', 'set', '00'])
557 dev[0].flush_scan_cache()
558 dev[1].flush_scan_cache()
560 def _test_wpas_mesh_open_5ghz(dev, apdev):
561 check_mesh_support(dev[0])
562 subprocess.call(['iw', 'reg', 'set', 'US'])
565 ev = dev[i].wait_event(["CTRL-EVENT-REGDOM-CHANGE"], timeout=5)
567 raise Exception("No regdom change event")
568 if "alpha2=US" in ev:
570 add_open_mesh_network(dev[i], freq="5180")
572 # Check for mesh joined
573 check_mesh_group_added(dev[0])
574 check_mesh_group_added(dev[1])
576 # Check for peer connected
577 check_mesh_peer_connected(dev[0])
578 check_mesh_peer_connected(dev[1])
580 # Test connectivity 0->1 and 1->0
581 hwsim_utils.test_connectivity(dev[0], dev[1])
583 def test_wpas_mesh_open_vht_80p80(dev, apdev):
584 """wpa_supplicant open MESH network on VHT 80+80 MHz channel"""
586 _test_wpas_mesh_open_vht_80p80(dev, apdev)
588 subprocess.call(['iw', 'reg', 'set', '00'])
589 dev[0].flush_scan_cache()
590 dev[1].flush_scan_cache()
592 def _test_wpas_mesh_open_vht_80p80(dev, apdev):
593 check_mesh_support(dev[0])
594 subprocess.call(['iw', 'reg', 'set', 'US'])
597 ev = dev[i].wait_event(["CTRL-EVENT-REGDOM-CHANGE"], timeout=5)
599 raise Exception("No regdom change event")
600 if "alpha2=US" in ev:
602 add_open_mesh_network(dev[i], freq="5180", chwidth=3)
604 # Check for mesh joined
605 check_mesh_group_added(dev[0])
606 check_mesh_group_added(dev[1])
608 # Check for peer connected
609 check_mesh_peer_connected(dev[0])
610 check_mesh_peer_connected(dev[1])
612 # Test connectivity 0->1 and 1->0
613 hwsim_utils.test_connectivity(dev[0], dev[1])
615 sig = dev[0].request("SIGNAL_POLL").splitlines()
616 if "WIDTH=80+80 MHz" not in sig:
617 raise Exception("Unexpected SIGNAL_POLL value(2): " + str(sig))
618 if "CENTER_FRQ1=5210" not in sig:
619 raise Exception("Unexpected SIGNAL_POLL value(3): " + str(sig))
620 if "CENTER_FRQ2=5775" not in sig:
621 raise Exception("Unexpected SIGNAL_POLL value(4): " + str(sig))
623 sig = dev[1].request("SIGNAL_POLL").splitlines()
624 if "WIDTH=80+80 MHz" not in sig:
625 raise Exception("Unexpected SIGNAL_POLL value(2b): " + str(sig))
626 if "CENTER_FRQ1=5210" not in sig:
627 raise Exception("Unexpected SIGNAL_POLL value(3b): " + str(sig))
628 if "CENTER_FRQ2=5775" not in sig:
629 raise Exception("Unexpected SIGNAL_POLL value(4b): " + str(sig))
631 def test_wpas_mesh_password_mismatch(dev, apdev):
632 """Mesh network and one device with mismatching password"""
633 check_mesh_support(dev[0], secure=True)
634 dev[0].request("SET sae_groups ")
635 id = add_mesh_secure_net(dev[0])
636 dev[0].mesh_group_add(id)
638 dev[1].request("SET sae_groups ")
639 id = add_mesh_secure_net(dev[1])
640 dev[1].mesh_group_add(id)
642 dev[2].request("SET sae_groups ")
643 id = add_mesh_secure_net(dev[2])
644 dev[2].set_network_quoted(id, "psk", "wrong password")
645 dev[2].mesh_group_add(id)
647 # The two peers with matching password need to be able to connect
648 check_mesh_group_added(dev[0])
649 check_mesh_group_added(dev[1])
650 check_mesh_peer_connected(dev[0])
651 check_mesh_peer_connected(dev[1])
653 ev = dev[2].wait_event(["MESH-SAE-AUTH-FAILURE"], timeout=20)
655 raise Exception("dev2 did not report auth failure (1)")
656 ev = dev[2].wait_event(["MESH-SAE-AUTH-FAILURE"], timeout=20)
658 raise Exception("dev2 did not report auth failure (2)")
661 ev = dev[0].wait_event(["MESH-SAE-AUTH-FAILURE"], timeout=1)
663 logger.info("dev0 did not report auth failure")
665 if "addr=" + dev[2].own_addr() not in ev:
666 raise Exception("Unexpected peer address in dev0 event: " + ev)
669 ev = dev[1].wait_event(["MESH-SAE-AUTH-FAILURE"], timeout=1)
671 logger.info("dev1 did not report auth failure")
673 if "addr=" + dev[2].own_addr() not in ev:
674 raise Exception("Unexpected peer address in dev1 event: " + ev)
677 hwsim_utils.test_connectivity(dev[0], dev[1])
681 hwsim_utils.test_connectivity(dev[i], dev[2], timeout=1)
682 raise Exception("Data connectivity test passed unexpectedly")
684 if "data delivery failed" not in str(e):
688 raise Exception("Neither dev0 nor dev1 reported auth failure")
690 def test_wpas_mesh_password_mismatch_retry(dev, apdev, params):
691 """Mesh password mismatch and retry [long]"""
692 if not params['long']:
693 raise HwsimSkip("Skip test case with long duration due to --long not specified")
694 check_mesh_support(dev[0], secure=True)
695 dev[0].request("SET sae_groups ")
696 id = add_mesh_secure_net(dev[0])
697 dev[0].mesh_group_add(id)
699 dev[1].request("SET sae_groups ")
700 id = add_mesh_secure_net(dev[1])
701 dev[1].set_network_quoted(id, "psk", "wrong password")
702 dev[1].mesh_group_add(id)
704 # Check for mesh joined
705 check_mesh_group_added(dev[0])
706 check_mesh_group_added(dev[1])
709 ev = dev[0].wait_event(["MESH-SAE-AUTH-FAILURE"], timeout=20)
711 raise Exception("dev0 did not report auth failure (%d)" % i)
712 ev = dev[1].wait_event(["MESH-SAE-AUTH-FAILURE"], timeout=20)
714 raise Exception("dev1 did not report auth failure (%d)" % i)
716 ev = dev[0].wait_event(["MESH-SAE-AUTH-BLOCKED"], timeout=10)
718 raise Exception("dev0 did not report auth blocked")
719 ev = dev[1].wait_event(["MESH-SAE-AUTH-BLOCKED"], timeout=10)
721 raise Exception("dev1 did not report auth blocked")
723 def test_mesh_wpa_auth_init_oom(dev, apdev):
724 """Secure mesh network setup failing due to wpa_init() OOM"""
725 check_mesh_support(dev[0], secure=True)
726 dev[0].request("SET sae_groups ")
727 with alloc_fail(dev[0], 1, "wpa_init"):
728 id = add_mesh_secure_net(dev[0])
729 dev[0].mesh_group_add(id)
730 ev = dev[0].wait_event(["MESH-GROUP-STARTED"], timeout=0.2)
732 raise Exception("Unexpected mesh group start during OOM")
734 def test_mesh_wpa_init_fail(dev, apdev):
735 """Secure mesh network setup local failure"""
736 check_mesh_support(dev[0], secure=True)
737 dev[0].request("SET sae_groups ")
739 with fail_test(dev[0], 1, "os_get_random;=__mesh_rsn_auth_init"):
740 id = add_mesh_secure_net(dev[0])
741 dev[0].mesh_group_add(id)
742 wait_fail_trigger(dev[0], "GET_FAIL")
744 with alloc_fail(dev[0], 1, "mesh_rsn_auth_init"):
745 id = add_mesh_secure_net(dev[0])
746 dev[0].mesh_group_add(id)
747 wait_fail_trigger(dev[0], "GET_ALLOC_FAIL")
749 def test_wpas_mesh_reconnect(dev, apdev):
750 """Secure mesh network plink counting during reconnection"""
751 check_mesh_support(dev[0])
753 _test_wpas_mesh_reconnect(dev)
755 dev[0].request("SET max_peer_links 99")
757 def _test_wpas_mesh_reconnect(dev):
758 dev[0].request("SET max_peer_links 2")
759 dev[0].request("SET sae_groups ")
760 id = add_mesh_secure_net(dev[0])
761 dev[0].set_network(id, "beacon_int", "100")
762 dev[0].mesh_group_add(id)
763 dev[1].request("SET sae_groups ")
764 id = add_mesh_secure_net(dev[1])
765 dev[1].mesh_group_add(id)
766 check_mesh_group_added(dev[0])
767 check_mesh_group_added(dev[1])
768 check_mesh_peer_connected(dev[0])
769 check_mesh_peer_connected(dev[1])
772 # Drop incoming management frames to avoid handling link close
773 dev[0].request("SET ext_mgmt_frame_handling 1")
774 dev[1].mesh_group_remove()
775 check_mesh_group_removed(dev[1])
776 dev[1].request("FLUSH")
777 dev[0].request("SET ext_mgmt_frame_handling 0")
778 id = add_mesh_secure_net(dev[1])
779 dev[1].mesh_group_add(id)
780 check_mesh_group_added(dev[1])
781 check_mesh_peer_connected(dev[1])
782 dev[0].dump_monitor()
783 dev[1].dump_monitor()
785 def test_wpas_mesh_gate_forwarding(dev, apdev, p):
786 """Mesh forwards traffic to unknown sta to mesh gates"""
787 addr0 = dev[0].own_addr()
788 addr1 = dev[1].own_addr()
789 addr2 = dev[2].own_addr()
790 external_sta = '02:11:22:33:44:55'
792 # start 3 node connected mesh
793 check_mesh_support(dev[0])
795 add_open_mesh_network(dev[i])
796 check_mesh_group_added(dev[i])
798 check_mesh_peer_connected(dev[i])
800 hwsim_utils.test_connectivity(dev[0], dev[1])
801 hwsim_utils.test_connectivity(dev[1], dev[2])
802 hwsim_utils.test_connectivity(dev[0], dev[2])
804 # dev0 and dev1 are mesh gates
805 subprocess.call(['iw', 'dev', dev[0].ifname, 'set', 'mesh_param',
806 'mesh_gate_announcements=1'])
807 subprocess.call(['iw', 'dev', dev[1].ifname, 'set', 'mesh_param',
808 'mesh_gate_announcements=1'])
810 # wait for gate announcement frames
813 # data frame from dev2 -> external sta should be sent to both gates
814 dev[2].request("DATA_TEST_CONFIG 1")
815 dev[2].request("DATA_TEST_TX {} {} 0".format(external_sta, addr2))
816 dev[2].request("DATA_TEST_CONFIG 0")
818 capfile = os.path.join(p['logdir'], "hwsim0.pcapng")
819 filt = "wlan.sa==%s && wlan_mgt.fixed.mesh_addr5==%s" % (addr2,
822 da = run_tshark(capfile, filt, [ "wlan.da" ])
823 if addr0 in da and addr1 in da:
824 logger.debug("Frames seen in tshark iteration %d" % i)
829 raise Exception("Frame to gate %s not observed" % addr0)
831 raise Exception("Frame to gate %s not observed" % addr1)
833 def test_wpas_mesh_pmksa_caching(dev, apdev):
834 """Secure mesh network and PMKSA caching"""
835 check_mesh_support(dev[0], secure=True)
836 dev[0].request("SET sae_groups ")
837 id = add_mesh_secure_net(dev[0])
838 dev[0].mesh_group_add(id)
840 dev[1].request("SET sae_groups ")
841 id = add_mesh_secure_net(dev[1])
842 dev[1].mesh_group_add(id)
844 # Check for mesh joined
845 check_mesh_group_added(dev[0])
846 check_mesh_group_added(dev[1])
848 # Check for peer connected
849 check_mesh_peer_connected(dev[0])
850 check_mesh_peer_connected(dev[1])
852 addr0 = dev[0].own_addr()
853 addr1 = dev[1].own_addr()
854 pmksa0 = dev[0].get_pmksa(addr1)
855 pmksa1 = dev[1].get_pmksa(addr0)
856 if pmksa0 is None or pmksa1 is None:
857 raise Exception("No PMKSA cache entry created")
858 if pmksa0['pmkid'] != pmksa1['pmkid']:
859 raise Exception("PMKID mismatch in PMKSA cache entries")
861 if "OK" not in dev[0].request("MESH_PEER_REMOVE " + addr1):
862 raise Exception("Failed to remove peer")
863 pmksa0b = dev[0].get_pmksa(addr1)
865 raise Exception("PMKSA cache entry not maintained")
868 if "FAIL" not in dev[0].request("MESH_PEER_ADD " + addr1):
869 raise Exception("MESH_PEER_ADD unexpectedly succeeded in no_auto_peer=0 case")
871 def test_wpas_mesh_pmksa_caching2(dev, apdev):
872 """Secure mesh network and PMKSA caching with no_auto_peer=1"""
873 check_mesh_support(dev[0], secure=True)
874 addr0 = dev[0].own_addr()
875 addr1 = dev[1].own_addr()
876 dev[0].request("SET sae_groups ")
877 id = add_mesh_secure_net(dev[0])
878 dev[0].set_network(id, "no_auto_peer", "1")
879 dev[0].mesh_group_add(id)
881 dev[1].request("SET sae_groups ")
882 id = add_mesh_secure_net(dev[1])
883 dev[1].set_network(id, "no_auto_peer", "1")
884 dev[1].mesh_group_add(id)
886 # Check for mesh joined
887 check_mesh_group_added(dev[0])
888 check_mesh_group_added(dev[1])
890 # Check for peer connected
891 ev = dev[0].wait_event(["will not initiate new peer link"], timeout=10)
893 raise Exception("Missing no-initiate message")
894 if "OK" not in dev[0].request("MESH_PEER_ADD " + addr1):
895 raise Exception("MESH_PEER_ADD failed")
896 check_mesh_peer_connected(dev[0])
897 check_mesh_peer_connected(dev[1])
899 pmksa0 = dev[0].get_pmksa(addr1)
900 pmksa1 = dev[1].get_pmksa(addr0)
901 if pmksa0 is None or pmksa1 is None:
902 raise Exception("No PMKSA cache entry created")
903 if pmksa0['pmkid'] != pmksa1['pmkid']:
904 raise Exception("PMKID mismatch in PMKSA cache entries")
906 if "OK" not in dev[0].request("MESH_PEER_REMOVE " + addr1):
907 raise Exception("Failed to remove peer")
908 pmksa0b = dev[0].get_pmksa(addr1)
910 raise Exception("PMKSA cache entry not maintained")
912 ev = dev[0].wait_event(["will not initiate new peer link"], timeout=10)
914 raise Exception("Missing no-initiate message (2)")
915 if "OK" not in dev[0].request("MESH_PEER_ADD " + addr1):
916 raise Exception("MESH_PEER_ADD failed (2)")
917 check_mesh_peer_connected(dev[0])
918 check_mesh_peer_connected(dev[1])
920 pmksa0c = dev[0].get_pmksa(addr1)
921 pmksa1c = dev[1].get_pmksa(addr0)
922 if pmksa0c is None or pmksa1c is None:
923 raise Exception("No PMKSA cache entry created (2)")
924 if pmksa0c['pmkid'] != pmksa1c['pmkid']:
925 raise Exception("PMKID mismatch in PMKSA cache entries")
926 if pmksa0['pmkid'] != pmksa0c['pmkid']:
927 raise Exception("PMKID changed")
929 hwsim_utils.test_connectivity(dev[0], dev[1])
931 def test_wpas_mesh_pmksa_caching_no_match(dev, apdev):
932 """Secure mesh network and PMKSA caching with no PMKID match"""
933 check_mesh_support(dev[0], secure=True)
934 addr0 = dev[0].own_addr()
935 addr1 = dev[1].own_addr()
936 dev[0].request("SET sae_groups ")
937 id = add_mesh_secure_net(dev[0])
938 dev[0].set_network(id, "no_auto_peer", "1")
939 dev[0].mesh_group_add(id)
941 dev[1].request("SET sae_groups ")
942 id = add_mesh_secure_net(dev[1])
943 dev[1].set_network(id, "no_auto_peer", "1")
944 dev[1].mesh_group_add(id)
946 # Check for mesh joined
947 check_mesh_group_added(dev[0])
948 check_mesh_group_added(dev[1])
950 # Check for peer connected
951 ev = dev[0].wait_event(["will not initiate new peer link"], timeout=10)
953 raise Exception("Missing no-initiate message")
954 if "OK" not in dev[0].request("MESH_PEER_ADD " + addr1):
955 raise Exception("MESH_PEER_ADD failed")
956 check_mesh_peer_connected(dev[0])
957 check_mesh_peer_connected(dev[1])
959 pmksa0 = dev[0].get_pmksa(addr1)
960 pmksa1 = dev[1].get_pmksa(addr0)
961 if pmksa0 is None or pmksa1 is None:
962 raise Exception("No PMKSA cache entry created")
963 if pmksa0['pmkid'] != pmksa1['pmkid']:
964 raise Exception("PMKID mismatch in PMKSA cache entries")
966 if "OK" not in dev[0].request("MESH_PEER_REMOVE " + addr1):
967 raise Exception("Failed to remove peer")
969 if "OK" not in dev[1].request("PMKSA_FLUSH"):
970 raise Exception("Failed to flush PMKSA cache")
972 ev = dev[0].wait_event(["will not initiate new peer link"], timeout=10)
974 raise Exception("Missing no-initiate message (2)")
975 if "OK" not in dev[0].request("MESH_PEER_ADD " + addr1):
976 raise Exception("MESH_PEER_ADD failed (2)")
977 check_mesh_peer_connected(dev[0])
978 check_mesh_peer_connected(dev[1])
980 pmksa0c = dev[0].get_pmksa(addr1)
981 pmksa1c = dev[1].get_pmksa(addr0)
982 if pmksa0c is None or pmksa1c is None:
983 raise Exception("No PMKSA cache entry created (2)")
984 if pmksa0c['pmkid'] != pmksa1c['pmkid']:
985 raise Exception("PMKID mismatch in PMKSA cache entries")
986 if pmksa0['pmkid'] == pmksa0c['pmkid']:
987 raise Exception("PMKID did not change")
989 hwsim_utils.test_connectivity(dev[0], dev[1])
991 def test_mesh_oom(dev, apdev):
992 """Mesh network setup failing due to OOM"""
993 check_mesh_support(dev[0], secure=True)
994 dev[0].request("SET sae_groups ")
996 with alloc_fail(dev[0], 1, "mesh_config_create"):
997 add_open_mesh_network(dev[0])
998 ev = dev[0].wait_event(["Failed to init mesh"])
1000 raise Exception("Init failure not reported")
1002 for i in range(1, 65):
1003 with alloc_fail(dev[0], i, "wpa_supplicant_mesh_init"):
1004 add_open_mesh_network(dev[0])
1005 wait_fail_trigger(dev[0], "GET_ALLOC_FAIL")
1006 ev = dev[0].wait_event(["Failed to init mesh",
1007 "MESH-GROUP-STARTED"])
1009 raise Exception("Init failure not reported")
1011 def test_mesh_add_interface_oom(dev):
1012 """wpa_supplicant mesh with dynamic interface addition failing"""
1013 check_mesh_support(dev[0])
1014 for i in range(1, 3):
1017 with alloc_fail(dev[0], i, "wpas_mesh_add_interface"):
1018 mesh = dev[0].request("MESH_INTERFACE_ADD").strip()
1020 if mesh and mesh != "FAIL":
1021 dev[0].request("MESH_GROUP_REMOVE " + mesh)
1023 def test_mesh_scan_oom(dev):
1024 """wpa_supplicant mesh scan results and OOM"""
1025 check_mesh_support(dev[0])
1026 add_open_mesh_network(dev[0])
1027 check_mesh_group_added(dev[0])
1029 dev[1].scan(freq="2412")
1030 res = dev[1].request("SCAN_RESULTS")
1033 for r in res.splitlines():
1036 bssid = r.split('\t')[0]
1038 bss = dev[1].get_bss(bssid)
1040 raise Exception("Could not get BSS entry for mesh")
1042 for i in range(1, 3):
1043 with alloc_fail(dev[1], i, "mesh_attr_text"):
1044 bss = dev[1].get_bss(bssid)
1046 raise Exception("Unexpected BSS result during OOM")