]> git.ipfire.org Git - thirdparty/hostap.git/blob - tests/hwsim/test_wpas_mesh.py
7f9cd83960dcf6eeee5b8dc3e1b6e49f38873124
[thirdparty/hostap.git] / tests / hwsim / test_wpas_mesh.py
1 #!/usr/bin/python
2 #
3 # wpa_supplicant mesh mode tests
4 # Copyright (c) 2014, cozybit Inc.
5 #
6 # This software may be distributed under the terms of the BSD license.
7 # See README for more details.
8
9 import logging
10 logger = logging.getLogger()
11 import os
12 import subprocess
13 import time
14
15 import hwsim_utils
16 from wpasupplicant import WpaSupplicant
17 from utils import HwsimSkip, alloc_fail
18 from tshark import run_tshark
19
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")
25
26 def check_mesh_scan(dev, params, other_started=False, beacon_int=0):
27 if not other_started:
28 dev.dump_monitor()
29 id = dev.request("SCAN " + params)
30 if "FAIL" in id:
31 raise Exception("Failed to start scan")
32 id = int(id)
33
34 if other_started:
35 ev = dev.wait_event(["CTRL-EVENT-SCAN-STARTED"])
36 if ev is None:
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")
40
41 ev = dev.wait_event(["CTRL-EVENT-SCAN-RESULTS"])
42 if ev is None:
43 raise Exception("Other scan did not complete")
44 if "id=" + str(id) in ev:
45 raise Exception(
46 "Own scan id unexpectedly included in completed event")
47
48 ev = dev.wait_event(["CTRL-EVENT-SCAN-STARTED"])
49 if ev is None:
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")
53
54 ev = dev.wait_event(["CTRL-EVENT-SCAN-RESULTS"])
55 if ev is None:
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")
59
60 res = dev.request("SCAN_RESULTS")
61
62 if res.find("[MESH]") < 0:
63 raise Exception("Scan did not contain a MESH network")
64
65 bssid = res.splitlines()[1].split(' ')[0]
66 bss = dev.get_bss(bssid)
67 if bss is None:
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")
71 if beacon_int:
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'])
76
77 def check_mesh_group_added(dev):
78 ev = dev.wait_event(["MESH-GROUP-STARTED"])
79 if ev is None:
80 raise Exception("Test exception: Couldn't join mesh")
81
82
83 def check_mesh_group_removed(dev):
84 ev = dev.wait_event(["MESH-GROUP-REMOVED"])
85 if ev is None:
86 raise Exception("Test exception: Couldn't leave mesh")
87
88
89 def check_mesh_peer_connected(dev, timeout=10):
90 ev = dev.wait_event(["MESH-PEER-CONNECTED"], timeout=timeout)
91 if ev is None:
92 raise Exception("Test exception: Remote peer did not connect.")
93
94
95 def check_mesh_peer_disconnected(dev):
96 ev = dev.wait_event(["MESH-PEER-DISCONNECTED"])
97 if ev is None:
98 raise Exception("Test exception: Peer disconnect event not detected.")
99
100
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)
107
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)
115 if chwidth > 0:
116 dev.set_network(id, "max_oper_chwidth", str(chwidth))
117 if beacon_int:
118 dev.set_network(id, "beacon_int", str(beacon_int))
119 if basic_rates:
120 dev.set_network(id, "mesh_basic_rates", basic_rates)
121 if start:
122 dev.mesh_group_add(id)
123 return id
124
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])
129
130 # Check for MESH-GROUP-STARTED event
131 check_mesh_group_added(dev[0])
132
133
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()
144
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)
150
151 # Check for mesh joined
152 check_mesh_group_added(dev[0])
153 check_mesh_group_added(dev[1])
154
155 # Check for peer connected
156 check_mesh_peer_connected(dev[0])
157 check_mesh_peer_connected(dev[1])
158
159
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])
165
166 # Check for mesh joined
167 check_mesh_group_added(dev[0])
168 check_mesh_group_added(dev[1])
169
170 # Check for peer connected
171 check_mesh_peer_connected(dev[0])
172 check_mesh_peer_connected(dev[1])
173
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])
178
179
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)
185
186 # Check for mesh joined
187 check_mesh_group_added(dev[0])
188 check_mesh_group_added(dev[1])
189
190 # Check for Mesh scan
191 check_mesh_scan(dev[0], "use_id=1", beacon_int=175)
192
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")
198
199 # Check for mesh joined
200 check_mesh_group_added(dev[0])
201 check_mesh_group_added(dev[1])
202
203 # Check for peer connected
204 check_mesh_peer_connected(dev[0])
205 check_mesh_peer_connected(dev[1])
206
207 # Test connectivity 0->1 and 1->0
208 hwsim_utils.test_connectivity(dev[0], dev[1])
209
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)
217
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)
221
222 # Check for mesh joined
223 check_mesh_group_added(dev[0])
224 check_mesh_group_added(dev[1])
225
226 # Check for peer connected
227 check_mesh_peer_connected(dev[0], timeout=30)
228 check_mesh_peer_connected(dev[1])
229
230 # Test connectivity 0->1 and 1->0
231 hwsim_utils.test_connectivity(dev[0], dev[1])
232
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")
239 if psk:
240 dev.set_network_quoted(id, "psk", "thisismypassphrase!")
241 return id
242
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)
249
250 dev[1].request("SET sae_groups ")
251 id = add_mesh_secure_net(dev[1])
252 dev[1].mesh_group_add(id)
253
254 # Check for mesh joined
255 check_mesh_group_added(dev[0])
256 check_mesh_group_added(dev[1])
257
258 # Check for peer connected
259 check_mesh_peer_connected(dev[0])
260 check_mesh_peer_connected(dev[1])
261
262 # Test connectivity 0->1 and 1->0
263 hwsim_utils.test_connectivity(dev[0], dev[1])
264
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()
271
272 dev[0].request("SET sae_groups 19 25")
273 id = add_mesh_secure_net(dev[0])
274 dev[0].mesh_group_add(id)
275
276 dev[1].request("SET sae_groups 19")
277 id = add_mesh_secure_net(dev[1])
278 dev[1].mesh_group_add(id)
279
280 dev[2].request("SET sae_groups 26")
281 id = add_mesh_secure_net(dev[2])
282 dev[2].mesh_group_add(id)
283
284 check_mesh_group_added(dev[0])
285 check_mesh_group_added(dev[1])
286 check_mesh_group_added(dev[2])
287
288 ev = dev[0].wait_event(["MESH-PEER-CONNECTED"])
289 if ev is None:
290 raise Exception("Remote peer did not connect")
291 if addr1 not in ev:
292 raise Exception("Unexpected peer connected: " + ev)
293
294 ev = dev[1].wait_event(["MESH-PEER-CONNECTED"])
295 if ev is None:
296 raise Exception("Remote peer did not connect")
297 if addr0 not in ev:
298 raise Exception("Unexpected peer connected: " + ev)
299
300 ev = dev[2].wait_event(["MESH-PEER-CONNECTED"], timeout=1)
301 if ev is not None:
302 raise Exception("Unexpected peer connection at dev[2]: " + ev)
303
304 ev = dev[0].wait_event(["MESH-PEER-CONNECTED"], timeout=0.1)
305 if ev is not None:
306 raise Exception("Unexpected peer connection: " + ev)
307
308 ev = dev[1].wait_event(["MESH-PEER-CONNECTED"], timeout=0.1)
309 if ev is not None:
310 raise Exception("Unexpected peer connection: " + ev)
311
312 dev[0].request("SET sae_groups ")
313 dev[1].request("SET sae_groups ")
314 dev[2].request("SET sae_groups ")
315
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"],
323 timeout=5)
324 if ev is None:
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)
329 if ev is not None:
330 raise Exception("Unexpected mesh group start")
331
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)
338
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)
343
344 # Check for mesh joined
345 check_mesh_group_added(dev[0])
346 check_mesh_group_added(dev[1])
347
348 # Check for peer connected
349 check_mesh_peer_connected(dev[0], timeout=30)
350 check_mesh_peer_connected(dev[1])
351
352 # Test connectivity 0->1 and 1->0
353 hwsim_utils.test_connectivity(dev[0], dev[1])
354
355 dev[0].request("SET sae_groups ")
356 dev[1].request("SET sae_groups ")
357
358 def test_wpas_mesh_ctrl(dev):
359 """wpa_supplicant ctrl_iface mesh command error cases"""
360 check_mesh_support(dev[0])
361 if "FAIL" not in dev[0].request("MESH_GROUP_ADD 123"):
362 raise Exception("Unexpected MESH_GROUP_ADD success")
363 id = dev[0].add_network()
364 if "FAIL" not in dev[0].request("MESH_GROUP_ADD %d" % id):
365 raise Exception("Unexpected MESH_GROUP_ADD success")
366 dev[0].set_network(id, "mode", "5")
367 dev[0].set_network(id, "key_mgmt", "WPA-PSK")
368 if "FAIL" not in dev[0].request("MESH_GROUP_ADD %d" % id):
369 raise Exception("Unexpected MESH_GROUP_ADD success")
370
371 if "FAIL" not in dev[0].request("MESH_GROUP_REMOVE foo"):
372 raise Exception("Unexpected MESH_GROUP_REMOVE success")
373
374 def test_wpas_mesh_dynamic_interface(dev):
375 """wpa_supplicant mesh with dynamic interface"""
376 check_mesh_support(dev[0])
377 mesh0 = None
378 mesh1 = None
379 try:
380 mesh0 = dev[0].request("MESH_INTERFACE_ADD ifname=mesh0")
381 if "FAIL" in mesh0:
382 raise Exception("MESH_INTERFACE_ADD failed")
383 mesh1 = dev[1].request("MESH_INTERFACE_ADD")
384 if "FAIL" in mesh1:
385 raise Exception("MESH_INTERFACE_ADD failed")
386
387 wpas0 = WpaSupplicant(ifname=mesh0)
388 wpas1 = WpaSupplicant(ifname=mesh1)
389 logger.info(mesh0 + " address " + wpas0.get_status_field("address"))
390 logger.info(mesh1 + " address " + wpas1.get_status_field("address"))
391
392 add_open_mesh_network(wpas0)
393 add_open_mesh_network(wpas1)
394 check_mesh_group_added(wpas0)
395 check_mesh_group_added(wpas1)
396 check_mesh_peer_connected(wpas0)
397 check_mesh_peer_connected(wpas1)
398 hwsim_utils.test_connectivity(wpas0, wpas1)
399
400 # Must not allow MESH_GROUP_REMOVE on dynamic interface
401 if "FAIL" not in wpas0.request("MESH_GROUP_REMOVE " + mesh0):
402 raise Exception("Invalid MESH_GROUP_REMOVE accepted")
403 if "FAIL" not in wpas1.request("MESH_GROUP_REMOVE " + mesh1):
404 raise Exception("Invalid MESH_GROUP_REMOVE accepted")
405
406 # Must not allow MESH_GROUP_REMOVE on another radio interface
407 if "FAIL" not in wpas0.request("MESH_GROUP_REMOVE " + mesh1):
408 raise Exception("Invalid MESH_GROUP_REMOVE accepted")
409 if "FAIL" not in wpas1.request("MESH_GROUP_REMOVE " + mesh0):
410 raise Exception("Invalid MESH_GROUP_REMOVE accepted")
411
412 wpas0.remove_ifname()
413 wpas1.remove_ifname()
414
415 if "OK" not in dev[0].request("MESH_GROUP_REMOVE " + mesh0):
416 raise Exception("MESH_GROUP_REMOVE failed")
417 if "OK" not in dev[1].request("MESH_GROUP_REMOVE " + mesh1):
418 raise Exception("MESH_GROUP_REMOVE failed")
419
420 if "FAIL" not in dev[0].request("MESH_GROUP_REMOVE " + mesh0):
421 raise Exception("Invalid MESH_GROUP_REMOVE accepted")
422 if "FAIL" not in dev[1].request("MESH_GROUP_REMOVE " + mesh1):
423 raise Exception("Invalid MESH_GROUP_REMOVE accepted")
424
425 logger.info("Make sure another dynamic group can be added")
426 mesh0 = dev[0].request("MESH_INTERFACE_ADD ifname=mesh0")
427 if "FAIL" in mesh0:
428 raise Exception("MESH_INTERFACE_ADD failed")
429 mesh1 = dev[1].request("MESH_INTERFACE_ADD")
430 if "FAIL" in mesh1:
431 raise Exception("MESH_INTERFACE_ADD failed")
432
433 wpas0 = WpaSupplicant(ifname=mesh0)
434 wpas1 = WpaSupplicant(ifname=mesh1)
435 logger.info(mesh0 + " address " + wpas0.get_status_field("address"))
436 logger.info(mesh1 + " address " + wpas1.get_status_field("address"))
437
438 add_open_mesh_network(wpas0)
439 add_open_mesh_network(wpas1)
440 check_mesh_group_added(wpas0)
441 check_mesh_group_added(wpas1)
442 check_mesh_peer_connected(wpas0)
443 check_mesh_peer_connected(wpas1)
444 hwsim_utils.test_connectivity(wpas0, wpas1)
445 finally:
446 if mesh0:
447 dev[0].request("MESH_GROUP_REMOVE " + mesh0)
448 if mesh1:
449 dev[1].request("MESH_GROUP_REMOVE " + mesh1)
450
451 def test_wpas_mesh_max_peering(dev, apdev):
452 """Mesh max peering limit"""
453 check_mesh_support(dev[0])
454 try:
455 dev[0].request("SET max_peer_links 1")
456
457 # first, connect dev[0] and dev[1]
458 add_open_mesh_network(dev[0])
459 add_open_mesh_network(dev[1])
460 for i in range(2):
461 ev = dev[i].wait_event(["MESH-PEER-CONNECTED"])
462 if ev is None:
463 raise Exception("dev%d did not connect with any peer" % i)
464
465 # add dev[2] which will try to connect with both dev[0] and dev[1],
466 # but can complete connection only with dev[1]
467 add_open_mesh_network(dev[2])
468 for i in range(1, 3):
469 ev = dev[i].wait_event(["MESH-PEER-CONNECTED"])
470 if ev is None:
471 raise Exception("dev%d did not connect the second peer" % i)
472
473 ev = dev[0].wait_event(["MESH-PEER-CONNECTED"], timeout=1)
474 if ev is not None:
475 raise Exception("dev0 connection beyond max peering limit")
476
477 ev = dev[2].wait_event(["MESH-PEER-CONNECTED"], timeout=0.1)
478 if ev is not None:
479 raise Exception("dev2 reported unexpected peering: " + ev)
480
481 for i in range(3):
482 dev[i].mesh_group_remove()
483 check_mesh_group_removed(dev[i])
484 finally:
485 dev[0].request("SET max_peer_links 99")
486
487 def test_wpas_mesh_open_5ghz(dev, apdev):
488 """wpa_supplicant open MESH network on 5 GHz band"""
489 try:
490 _test_wpas_mesh_open_5ghz(dev, apdev)
491 finally:
492 subprocess.call(['iw', 'reg', 'set', '00'])
493 dev[0].flush_scan_cache()
494 dev[1].flush_scan_cache()
495
496 def _test_wpas_mesh_open_5ghz(dev, apdev):
497 check_mesh_support(dev[0])
498 subprocess.call(['iw', 'reg', 'set', 'US'])
499 for i in range(2):
500 for j in range(5):
501 ev = dev[i].wait_event(["CTRL-EVENT-REGDOM-CHANGE"], timeout=5)
502 if ev is None:
503 raise Exception("No regdom change event")
504 if "alpha2=US" in ev:
505 break
506 add_open_mesh_network(dev[i], freq="5180")
507
508 # Check for mesh joined
509 check_mesh_group_added(dev[0])
510 check_mesh_group_added(dev[1])
511
512 # Check for peer connected
513 check_mesh_peer_connected(dev[0])
514 check_mesh_peer_connected(dev[1])
515
516 # Test connectivity 0->1 and 1->0
517 hwsim_utils.test_connectivity(dev[0], dev[1])
518
519 def test_wpas_mesh_open_vht_80p80(dev, apdev):
520 """wpa_supplicant open MESH network on VHT 80+80 MHz channel"""
521 try:
522 _test_wpas_mesh_open_vht_80p80(dev, apdev)
523 finally:
524 subprocess.call(['iw', 'reg', 'set', '00'])
525 dev[0].flush_scan_cache()
526 dev[1].flush_scan_cache()
527
528 def _test_wpas_mesh_open_vht_80p80(dev, apdev):
529 check_mesh_support(dev[0])
530 subprocess.call(['iw', 'reg', 'set', 'US'])
531 for i in range(2):
532 for j in range(5):
533 ev = dev[i].wait_event(["CTRL-EVENT-REGDOM-CHANGE"], timeout=5)
534 if ev is None:
535 raise Exception("No regdom change event")
536 if "alpha2=US" in ev:
537 break
538 add_open_mesh_network(dev[i], freq="5180", chwidth=3)
539
540 # Check for mesh joined
541 check_mesh_group_added(dev[0])
542 check_mesh_group_added(dev[1])
543
544 # Check for peer connected
545 check_mesh_peer_connected(dev[0])
546 check_mesh_peer_connected(dev[1])
547
548 # Test connectivity 0->1 and 1->0
549 hwsim_utils.test_connectivity(dev[0], dev[1])
550
551 sig = dev[0].request("SIGNAL_POLL").splitlines()
552 if "WIDTH=80+80 MHz" not in sig:
553 raise Exception("Unexpected SIGNAL_POLL value(2): " + str(sig))
554 if "CENTER_FRQ1=5210" not in sig:
555 raise Exception("Unexpected SIGNAL_POLL value(3): " + str(sig))
556 if "CENTER_FRQ2=5775" not in sig:
557 raise Exception("Unexpected SIGNAL_POLL value(4): " + str(sig))
558
559 sig = dev[1].request("SIGNAL_POLL").splitlines()
560 if "WIDTH=80+80 MHz" not in sig:
561 raise Exception("Unexpected SIGNAL_POLL value(2b): " + str(sig))
562 if "CENTER_FRQ1=5210" not in sig:
563 raise Exception("Unexpected SIGNAL_POLL value(3b): " + str(sig))
564 if "CENTER_FRQ2=5775" not in sig:
565 raise Exception("Unexpected SIGNAL_POLL value(4b): " + str(sig))
566
567 def test_wpas_mesh_password_mismatch(dev, apdev):
568 """Mesh network and one device with mismatching password"""
569 check_mesh_support(dev[0], secure=True)
570 dev[0].request("SET sae_groups ")
571 id = add_mesh_secure_net(dev[0])
572 dev[0].mesh_group_add(id)
573
574 dev[1].request("SET sae_groups ")
575 id = add_mesh_secure_net(dev[1])
576 dev[1].mesh_group_add(id)
577
578 dev[2].request("SET sae_groups ")
579 id = add_mesh_secure_net(dev[2])
580 dev[2].set_network_quoted(id, "psk", "wrong password")
581 dev[2].mesh_group_add(id)
582
583 # The two peers with matching password need to be able to connect
584 check_mesh_group_added(dev[0])
585 check_mesh_group_added(dev[1])
586 check_mesh_peer_connected(dev[0])
587 check_mesh_peer_connected(dev[1])
588
589 ev = dev[2].wait_event(["MESH-SAE-AUTH-FAILURE"], timeout=20)
590 if ev is None:
591 raise Exception("dev2 did not report auth failure (1)")
592 ev = dev[2].wait_event(["MESH-SAE-AUTH-FAILURE"], timeout=20)
593 if ev is None:
594 raise Exception("dev2 did not report auth failure (2)")
595
596 count = 0
597 ev = dev[0].wait_event(["MESH-SAE-AUTH-FAILURE"], timeout=1)
598 if ev is None:
599 logger.info("dev0 did not report auth failure")
600 else:
601 if "addr=" + dev[2].own_addr() not in ev:
602 raise Exception("Unexpected peer address in dev0 event: " + ev)
603 count += 1
604
605 ev = dev[1].wait_event(["MESH-SAE-AUTH-FAILURE"], timeout=1)
606 if ev is None:
607 logger.info("dev1 did not report auth failure")
608 else:
609 if "addr=" + dev[2].own_addr() not in ev:
610 raise Exception("Unexpected peer address in dev1 event: " + ev)
611 count += 1
612
613 hwsim_utils.test_connectivity(dev[0], dev[1])
614
615 for i in range(2):
616 try:
617 hwsim_utils.test_connectivity(dev[i], dev[2], timeout=1)
618 raise Exception("Data connectivity test passed unexpectedly")
619 except Exception, e:
620 if "data delivery failed" not in str(e):
621 raise
622
623 if count == 0:
624 raise Exception("Neither dev0 nor dev1 reported auth failure")
625
626 def test_wpas_mesh_password_mismatch_retry(dev, apdev, params):
627 """Mesh password mismatch and retry [long]"""
628 if not params['long']:
629 raise HwsimSkip("Skip test case with long duration due to --long not specified")
630 check_mesh_support(dev[0], secure=True)
631 dev[0].request("SET sae_groups ")
632 id = add_mesh_secure_net(dev[0])
633 dev[0].mesh_group_add(id)
634
635 dev[1].request("SET sae_groups ")
636 id = add_mesh_secure_net(dev[1])
637 dev[1].set_network_quoted(id, "psk", "wrong password")
638 dev[1].mesh_group_add(id)
639
640 # Check for mesh joined
641 check_mesh_group_added(dev[0])
642 check_mesh_group_added(dev[1])
643
644 for i in range(4):
645 ev = dev[0].wait_event(["MESH-SAE-AUTH-FAILURE"], timeout=20)
646 if ev is None:
647 raise Exception("dev0 did not report auth failure (%d)" % i)
648 ev = dev[1].wait_event(["MESH-SAE-AUTH-FAILURE"], timeout=20)
649 if ev is None:
650 raise Exception("dev1 did not report auth failure (%d)" % i)
651
652 ev = dev[0].wait_event(["MESH-SAE-AUTH-BLOCKED"], timeout=10)
653 if ev is None:
654 raise Exception("dev0 did not report auth blocked")
655 ev = dev[1].wait_event(["MESH-SAE-AUTH-BLOCKED"], timeout=10)
656 if ev is None:
657 raise Exception("dev1 did not report auth blocked")
658
659 def test_mesh_wpa_auth_init_oom(dev, apdev):
660 """Secure mesh network setup failing due to wpa_init() OOM"""
661 check_mesh_support(dev[0], secure=True)
662 dev[0].request("SET sae_groups ")
663 with alloc_fail(dev[0], 1, "wpa_init"):
664 id = add_mesh_secure_net(dev[0])
665 dev[0].mesh_group_add(id)
666 ev = dev[0].wait_event(["MESH-GROUP-STARTED"], timeout=0.2)
667 if ev is not None:
668 raise Exception("Unexpected mesh group start during OOM")
669
670 def test_wpas_mesh_reconnect(dev, apdev):
671 """Secure mesh network plink counting during reconnection"""
672 check_mesh_support(dev[0])
673 try:
674 _test_wpas_mesh_reconnect(dev)
675 finally:
676 dev[0].request("SET max_peer_links 99")
677
678 def _test_wpas_mesh_reconnect(dev):
679 dev[0].request("SET max_peer_links 2")
680 dev[0].request("SET sae_groups ")
681 id = add_mesh_secure_net(dev[0])
682 dev[0].set_network(id, "beacon_int", "100")
683 dev[0].mesh_group_add(id)
684 dev[1].request("SET sae_groups ")
685 id = add_mesh_secure_net(dev[1])
686 dev[1].mesh_group_add(id)
687 check_mesh_group_added(dev[0])
688 check_mesh_group_added(dev[1])
689 check_mesh_peer_connected(dev[0])
690 check_mesh_peer_connected(dev[1])
691
692 for i in range(3):
693 # Drop incoming management frames to avoid handling link close
694 dev[0].request("SET ext_mgmt_frame_handling 1")
695 dev[1].mesh_group_remove()
696 check_mesh_group_removed(dev[1])
697 dev[1].request("FLUSH")
698 dev[0].request("SET ext_mgmt_frame_handling 0")
699 id = add_mesh_secure_net(dev[1])
700 dev[1].mesh_group_add(id)
701 check_mesh_group_added(dev[1])
702 check_mesh_peer_connected(dev[1])
703 dev[0].dump_monitor()
704 dev[1].dump_monitor()
705
706 def test_wpas_mesh_gate_forwarding(dev, apdev, p):
707 """Mesh forwards traffic to unknown sta to mesh gates"""
708 addr0 = dev[0].own_addr()
709 addr1 = dev[1].own_addr()
710 addr2 = dev[2].own_addr()
711 external_sta = '02:11:22:33:44:55'
712
713 # start 3 node connected mesh
714 check_mesh_support(dev[0])
715 for i in range(3):
716 add_open_mesh_network(dev[i])
717 check_mesh_group_added(dev[i])
718 for i in range(3):
719 check_mesh_peer_connected(dev[i])
720
721 hwsim_utils.test_connectivity(dev[0], dev[1])
722 hwsim_utils.test_connectivity(dev[1], dev[2])
723 hwsim_utils.test_connectivity(dev[0], dev[2])
724
725 # dev0 and dev1 are mesh gates
726 subprocess.call(['iw', 'dev', dev[0].ifname, 'set', 'mesh_param',
727 'mesh_gate_announcements=1'])
728 subprocess.call(['iw', 'dev', dev[1].ifname, 'set', 'mesh_param',
729 'mesh_gate_announcements=1'])
730
731 # wait for gate announcement frames
732 time.sleep(1)
733
734 # data frame from dev2 -> external sta should be sent to both gates
735 dev[2].request("DATA_TEST_CONFIG 1")
736 dev[2].request("DATA_TEST_TX {} {} 0".format(external_sta, addr2))
737 dev[2].request("DATA_TEST_CONFIG 0")
738
739 capfile = os.path.join(p['logdir'], "hwsim0.pcapng")
740 filt = "wlan.sa==%s && wlan_mgt.fixed.mesh_addr5==%s" % (addr2,
741 external_sta)
742 for i in range(15):
743 da = run_tshark(capfile, filt, [ "wlan.da" ])
744 if addr0 in da and addr1 in da:
745 logger.debug("Frames seen in tshark iteration %d" % i)
746 break
747 time.sleep(0.3)
748
749 if addr0 not in da:
750 raise Exception("Frame to gate %s not observed" % addr0)
751 if addr1 not in da:
752 raise Exception("Frame to gate %s not observed" % addr1)