]> git.ipfire.org Git - thirdparty/hostap.git/blob - tests/hwsim/test_wpas_mesh.py
tests: Fix wlan.mesh.config.cap workaround for test_wpas_mesh_max_peering
[thirdparty/hostap.git] / tests / hwsim / test_wpas_mesh.py
1 # wpa_supplicant mesh mode tests
2 # Copyright (c) 2014, cozybit Inc.
3 #
4 # This software may be distributed under the terms of the BSD license.
5 # See README for more details.
6
7 import logging
8 logger = logging.getLogger()
9 import os
10 import struct
11 import subprocess
12 import time
13 import json
14 import binascii
15
16 import hwsim_utils
17 import hostapd
18 from wpasupplicant import WpaSupplicant
19 from utils import HwsimSkip, alloc_fail, fail_test, wait_fail_trigger
20 from tshark import run_tshark, run_tshark_json
21 from test_ap_ht import set_world_reg
22 from test_sae import radiotap_build, start_monitor, stop_monitor, \
23 build_sae_commit, sae_rx_commit_token_req
24 from hwsim_utils import set_group_map
25
26 def check_mesh_support(dev, secure=False):
27 if "MESH" not in dev.get_capability("modes"):
28 raise HwsimSkip("Driver does not support mesh")
29 if secure and "SAE" not in dev.get_capability("auth_alg"):
30 raise HwsimSkip("SAE not supported")
31
32 def check_mesh_scan(dev, params, other_started=False, beacon_int=0):
33 if not other_started:
34 dev.dump_monitor()
35 id = dev.request("SCAN " + params)
36 if "FAIL" in id:
37 raise Exception("Failed to start scan")
38 id = int(id)
39
40 if other_started:
41 ev = dev.wait_event(["CTRL-EVENT-SCAN-STARTED"])
42 if ev is None:
43 raise Exception("Other scan did not start")
44 if "id=" + str(id) in ev:
45 raise Exception("Own scan id unexpectedly included in start event")
46
47 ev = dev.wait_event(["CTRL-EVENT-SCAN-RESULTS"])
48 if ev is None:
49 raise Exception("Other scan did not complete")
50 if "id=" + str(id) in ev:
51 raise Exception(
52 "Own scan id unexpectedly included in completed event")
53
54 ev = dev.wait_event(["CTRL-EVENT-SCAN-STARTED"])
55 if ev is None:
56 raise Exception("Scan did not start")
57 if "id=" + str(id) not in ev:
58 raise Exception("Scan id not included in start event")
59
60 ev = dev.wait_event(["CTRL-EVENT-SCAN-RESULTS"])
61 if ev is None:
62 raise Exception("Scan did not complete")
63 if "id=" + str(id) not in ev:
64 raise Exception("Scan id not included in completed event")
65
66 res = dev.request("SCAN_RESULTS")
67
68 if res.find("[MESH]") < 0:
69 raise Exception("Scan did not contain a MESH network")
70
71 bssid = res.splitlines()[1].split(' ')[0]
72 bss = dev.get_bss(bssid)
73 if bss is None:
74 raise Exception("Could not get BSS entry for mesh")
75 if 'mesh_capability' not in bss:
76 raise Exception("mesh_capability missing from BSS entry")
77 if beacon_int:
78 if 'beacon_int' not in bss:
79 raise Exception("beacon_int missing from BSS entry")
80 if str(beacon_int) != bss['beacon_int']:
81 raise Exception("Unexpected beacon_int in BSS entry: " + bss['beacon_int'])
82 if '[MESH]' not in bss['flags']:
83 raise Exception("BSS output did not include MESH flag")
84
85 def check_mesh_group_added(dev):
86 ev = dev.wait_event(["MESH-GROUP-STARTED"])
87 if ev is None:
88 raise Exception("Test exception: Couldn't join mesh")
89
90
91 def check_mesh_group_removed(dev):
92 ev = dev.wait_event(["MESH-GROUP-REMOVED"])
93 if ev is None:
94 raise Exception("Test exception: Couldn't leave mesh")
95
96
97 def check_mesh_peer_connected(dev, timeout=10):
98 ev = dev.wait_event(["MESH-PEER-CONNECTED"], timeout=timeout)
99 if ev is None:
100 raise Exception("Test exception: Remote peer did not connect.")
101
102
103 def check_mesh_peer_disconnected(dev):
104 ev = dev.wait_event(["MESH-PEER-DISCONNECTED"])
105 if ev is None:
106 raise Exception("Test exception: Peer disconnect event not detected.")
107
108 def check_mesh_joined2(dev):
109 check_mesh_group_added(dev[0])
110 check_mesh_group_added(dev[1])
111
112 def check_mesh_connected2(dev, timeout0=10, connectivity=False):
113 check_mesh_peer_connected(dev[0], timeout=timeout0)
114 check_mesh_peer_connected(dev[1])
115 if connectivity:
116 hwsim_utils.test_connectivity(dev[0], dev[1])
117
118 def check_mesh_joined_connected(dev, connectivity=False, timeout0=10):
119 check_mesh_joined2(dev)
120 check_mesh_connected2(dev, timeout0=timeout0, connectivity=connectivity)
121
122 def test_wpas_add_set_remove_support(dev):
123 """wpa_supplicant MESH add/set/remove network support"""
124 check_mesh_support(dev[0])
125 id = dev[0].add_network()
126 dev[0].set_network(id, "mode", "5")
127 dev[0].remove_network(id)
128
129 def add_open_mesh_network(dev, freq="2412", start=True, beacon_int=0,
130 basic_rates=None, chwidth=-1, disable_vht=False,
131 disable_ht40=False):
132 id = dev.add_network()
133 dev.set_network(id, "mode", "5")
134 dev.set_network_quoted(id, "ssid", "wpas-mesh-open")
135 dev.set_network(id, "key_mgmt", "NONE")
136 if freq:
137 dev.set_network(id, "frequency", freq)
138 if chwidth > -1:
139 dev.set_network(id, "max_oper_chwidth", str(chwidth))
140 if beacon_int:
141 dev.set_network(id, "beacon_int", str(beacon_int))
142 if basic_rates:
143 dev.set_network(id, "mesh_basic_rates", basic_rates)
144 if disable_vht:
145 dev.set_network(id, "disable_vht", "1")
146 if disable_ht40:
147 dev.set_network(id, "disable_ht40", "1")
148 if start:
149 dev.mesh_group_add(id)
150 return id
151
152 def test_wpas_mesh_group_added(dev):
153 """wpa_supplicant MESH group add"""
154 check_mesh_support(dev[0])
155 add_open_mesh_network(dev[0])
156
157 # Check for MESH-GROUP-STARTED event
158 check_mesh_group_added(dev[0])
159
160
161 def test_wpas_mesh_group_remove(dev):
162 """wpa_supplicant MESH group remove"""
163 check_mesh_support(dev[0])
164 add_open_mesh_network(dev[0])
165 # Check for MESH-GROUP-STARTED event
166 check_mesh_group_added(dev[0])
167 dev[0].mesh_group_remove()
168 # Check for MESH-GROUP-REMOVED event
169 check_mesh_group_removed(dev[0])
170 dev[0].mesh_group_remove()
171
172 def test_wpas_mesh_peer_connected(dev):
173 """wpa_supplicant MESH peer connected"""
174 check_mesh_support(dev[0])
175 add_open_mesh_network(dev[0], beacon_int=160)
176 add_open_mesh_network(dev[1], beacon_int=160)
177 check_mesh_joined_connected(dev)
178
179 def test_wpas_mesh_peer_disconnected(dev):
180 """wpa_supplicant MESH peer disconnected"""
181 check_mesh_support(dev[0])
182 add_open_mesh_network(dev[0])
183 add_open_mesh_network(dev[1])
184 check_mesh_joined_connected(dev)
185
186 # Remove group on dev 1
187 dev[1].mesh_group_remove()
188 # Device 0 should get a disconnection event
189 check_mesh_peer_disconnected(dev[0])
190
191
192 def test_wpas_mesh_mode_scan(dev):
193 """wpa_supplicant MESH scan support"""
194 check_mesh_support(dev[0])
195 add_open_mesh_network(dev[0])
196 add_open_mesh_network(dev[1], beacon_int=175)
197
198 check_mesh_joined2(dev)
199
200 # Check for Mesh scan
201 check_mesh_scan(dev[0], "use_id=1 freq=2412", beacon_int=175)
202
203 def test_wpas_mesh_open(dev, apdev):
204 """wpa_supplicant open MESH network connectivity"""
205 check_mesh_support(dev[0])
206 add_open_mesh_network(dev[0], freq="2462", basic_rates="60 120 240")
207 add_open_mesh_network(dev[1], freq="2462", basic_rates="60 120 240")
208
209 check_mesh_joined_connected(dev, connectivity=True)
210
211 state = dev[0].get_status_field("wpa_state")
212 if state != "COMPLETED":
213 raise Exception("Unexpected wpa_state on dev0: " + state)
214 state = dev[1].get_status_field("wpa_state")
215 if state != "COMPLETED":
216 raise Exception("Unexpected wpa_state on dev1: " + state)
217
218 mode = dev[0].get_status_field("mode")
219 if mode != "mesh":
220 raise Exception("Unexpected mode: " + mode)
221
222 def test_wpas_mesh_open_no_auto(dev, apdev):
223 """wpa_supplicant open MESH network connectivity"""
224 check_mesh_support(dev[0])
225 id = add_open_mesh_network(dev[0], start=False)
226 dev[0].set_network(id, "dot11MeshMaxRetries", "16")
227 dev[0].set_network(id, "dot11MeshRetryTimeout", "255")
228 dev[0].mesh_group_add(id)
229
230 id = add_open_mesh_network(dev[1], start=False)
231 dev[1].set_network(id, "no_auto_peer", "1")
232 dev[1].mesh_group_add(id)
233
234 check_mesh_joined_connected(dev, connectivity=True, timeout0=30)
235
236 def test_mesh_open_no_auto2(dev, apdev):
237 """Open mesh network connectivity, no_auto on both peers"""
238 check_mesh_support(dev[0])
239 id = add_open_mesh_network(dev[0], start=False)
240 dev[0].set_network(id, "no_auto_peer", "1")
241 dev[0].mesh_group_add(id)
242
243 id = add_open_mesh_network(dev[1], start=False)
244 dev[1].set_network(id, "no_auto_peer", "1")
245 dev[1].mesh_group_add(id)
246
247 check_mesh_joined2(dev)
248
249 ev = dev[0].wait_event(["will not initiate new peer link"], timeout=10)
250 if ev is None:
251 raise Exception("Missing no-initiate message")
252 addr1 = dev[1].own_addr()
253 if "OK" not in dev[0].request("MESH_PEER_ADD " + addr1):
254 raise Exception("MESH_PEER_ADD failed")
255 if "FAIL" not in dev[0].request("MESH_PEER_ADD ff:ff:ff:ff:ff:ff"):
256 raise Exception("MESH_PEER_ADD with unknown STA succeeded")
257 check_mesh_connected2(dev, timeout0=30)
258 if "FAIL" not in dev[0].request("MESH_PEER_ADD " + addr1):
259 raise Exception("MESH_PEER_ADD succeeded for connected STA")
260 hwsim_utils.test_connectivity(dev[0], dev[1])
261
262 def test_mesh_open_rssi_threshold(dev, apdev):
263 """Open mesh network with RSSI threshold"""
264 check_mesh_support(dev[0])
265
266 _test_mesh_open_rssi_threshold(dev, apdev, -255, -255)
267 _test_mesh_open_rssi_threshold(dev, apdev, 0, 0)
268 _test_mesh_open_rssi_threshold(dev, apdev, 1, 0)
269
270 def _test_mesh_open_rssi_threshold(dev, apdev, value, expected):
271 id = add_open_mesh_network(dev[0], start=False)
272 dev[0].set_network(id, "mesh_rssi_threshold", str(value))
273 dev[0].mesh_group_add(id)
274 check_mesh_group_added(dev[0])
275
276 cmd = subprocess.Popen(["iw", "dev", dev[0].ifname, "get", "mesh_param",
277 "mesh_rssi_threshold"], stdout=subprocess.PIPE)
278 mesh_rssi_threshold = int(cmd.stdout.read().decode().split(" ")[0])
279
280 dev[0].mesh_group_remove()
281 check_mesh_group_removed(dev[0])
282
283 if mesh_rssi_threshold != expected:
284 raise Exception("mesh_rssi_threshold should be " + str(expected) +
285 ": " + str(mesh_rssi_threshold))
286
287 def add_mesh_secure_net(dev, psk=True, pmf=False, pairwise=None, group=None,
288 sae_password=False, sae_password_id=None, ocv=False):
289 id = dev.add_network()
290 dev.set_network(id, "mode", "5")
291 dev.set_network_quoted(id, "ssid", "wpas-mesh-sec")
292 dev.set_network(id, "key_mgmt", "SAE")
293 dev.set_network(id, "frequency", "2412")
294 if sae_password:
295 dev.set_network_quoted(id, "sae_password", "thisismypassphrase!")
296 if sae_password_id:
297 dev.set_network_quoted(id, "sae_password_id", sae_password_id)
298 if psk:
299 dev.set_network_quoted(id, "psk", "thisismypassphrase!")
300 if pmf:
301 dev.set_network(id, "ieee80211w", "2")
302 if pairwise:
303 dev.set_network(id, "pairwise", pairwise)
304 if group:
305 dev.set_network(id, "group", group)
306 if ocv:
307 try:
308 dev.set_network(id, "ocv", "1")
309 except Exception as e:
310 if "SET_NETWORK failed" in str(e):
311 raise HwsimSkip("OCV not supported")
312 raise
313 return id
314
315 def test_wpas_mesh_secure(dev, apdev):
316 """wpa_supplicant secure MESH network connectivity"""
317 check_mesh_support(dev[0], secure=True)
318 dev[0].request("SET sae_groups ")
319 id = add_mesh_secure_net(dev[0])
320 dev[0].mesh_group_add(id)
321
322 dev[1].request("SET sae_groups ")
323 id = add_mesh_secure_net(dev[1])
324 dev[1].mesh_group_add(id)
325
326 check_mesh_joined_connected(dev, connectivity=True)
327
328 state = dev[0].get_status_field("wpa_state")
329 if state != "COMPLETED":
330 raise Exception("Unexpected wpa_state on dev0: " + state)
331 state = dev[1].get_status_field("wpa_state")
332 if state != "COMPLETED":
333 raise Exception("Unexpected wpa_state on dev1: " + state)
334
335 def test_wpas_mesh_secure_sae_password(dev, apdev):
336 """wpa_supplicant secure mesh using sae_password"""
337 check_mesh_support(dev[0], secure=True)
338 dev[0].request("SET sae_groups ")
339 id = add_mesh_secure_net(dev[0], psk=False, sae_password=True)
340 dev[0].mesh_group_add(id)
341
342 dev[1].request("SET sae_groups ")
343 id = add_mesh_secure_net(dev[1])
344 dev[1].mesh_group_add(id)
345
346 check_mesh_joined_connected(dev, connectivity=True)
347
348 def test_wpas_mesh_secure_sae_password_id(dev, apdev):
349 """Secure mesh using sae_password and password identifier"""
350 check_mesh_support(dev[0], secure=True)
351 dev[0].request("SET sae_groups ")
352 id = add_mesh_secure_net(dev[0], psk=False, sae_password=True,
353 sae_password_id="pw id")
354 dev[0].mesh_group_add(id)
355
356 dev[1].request("SET sae_groups ")
357 id = add_mesh_secure_net(dev[1], sae_password=True,
358 sae_password_id="pw id")
359 dev[1].mesh_group_add(id)
360
361 check_mesh_joined_connected(dev, connectivity=True)
362
363 def test_wpas_mesh_secure_sae_password_id_mismatch(dev, apdev):
364 """Secure mesh using sae_password and password identifier mismatch"""
365 check_mesh_support(dev[0], secure=True)
366 dev[0].request("SET sae_groups ")
367 id = add_mesh_secure_net(dev[0], psk=False, sae_password=True,
368 sae_password_id="pw id")
369 dev[0].mesh_group_add(id)
370
371 dev[1].request("SET sae_groups ")
372 id = add_mesh_secure_net(dev[1], sae_password=True,
373 sae_password_id="wrong")
374 dev[1].mesh_group_add(id)
375
376 check_mesh_joined2(dev)
377
378 ev = dev[0].wait_event(["CTRL-EVENT-SAE-UNKNOWN-PASSWORD-IDENTIFIER"],
379 timeout=10)
380 if ev is None:
381 raise Exception("Unknown Password Identifier not noticed")
382
383 def test_mesh_secure_pmf(dev, apdev):
384 """Secure mesh network connectivity with PMF enabled"""
385 check_mesh_support(dev[0], secure=True)
386 dev[0].request("SET sae_groups ")
387 id = add_mesh_secure_net(dev[0], pmf=True)
388 dev[0].mesh_group_add(id)
389
390 dev[1].request("SET sae_groups ")
391 id = add_mesh_secure_net(dev[1], pmf=True)
392 dev[1].mesh_group_add(id)
393
394 check_mesh_joined_connected(dev, connectivity=True)
395
396 def test_mesh_secure_ocv(dev, apdev):
397 """Secure mesh network connectivity with OCV enabled"""
398 check_mesh_support(dev[0], secure=True)
399 dev[0].request("SET sae_groups ")
400 id = add_mesh_secure_net(dev[0], pmf=True, ocv=True)
401 dev[0].mesh_group_add(id)
402 dev[1].request("SET sae_groups ")
403 id = add_mesh_secure_net(dev[1], pmf=True, ocv=True)
404 dev[1].mesh_group_add(id)
405
406 check_mesh_joined_connected(dev, connectivity=True)
407
408 def test_mesh_secure_ocv_compat(dev, apdev):
409 """Secure mesh network where only one peer has OCV enabled"""
410 check_mesh_support(dev[0], secure=True)
411 dev[0].request("SET sae_groups ")
412 id = add_mesh_secure_net(dev[0], pmf=True, ocv=True)
413 dev[0].mesh_group_add(id)
414 dev[1].request("SET sae_groups ")
415 id = add_mesh_secure_net(dev[1], pmf=True, ocv=False)
416 dev[1].mesh_group_add(id)
417
418 check_mesh_joined_connected(dev, connectivity=True)
419
420 def set_reg(dev, country):
421 subprocess.call(['iw', 'reg', 'set', country])
422 for i in range(2):
423 for j in range(5):
424 ev = dev[i].wait_event(["CTRL-EVENT-REGDOM-CHANGE"], timeout=5)
425 if ev is None:
426 raise Exception("No regdom change event")
427 if "alpha2=" + country in ev:
428 break
429
430 def clear_reg_setting(dev):
431 dev[0].request("MESH_GROUP_REMOVE " + dev[0].ifname)
432 dev[1].request("MESH_GROUP_REMOVE " + dev[1].ifname)
433 subprocess.call(['iw', 'reg', 'set', '00'])
434 dev[0].flush_scan_cache()
435 dev[1].flush_scan_cache()
436
437 def test_mesh_secure_ocv_mix_legacy(dev, apdev):
438 """Mesh network with a VHT STA and a legacy STA under OCV"""
439 try:
440 run_mesh_secure_ocv_mix_legacy(dev, apdev)
441 finally:
442 clear_reg_setting(dev)
443
444 def run_mesh_secure_ocv_mix_legacy(dev, apdev):
445 check_mesh_support(dev[0], secure=True)
446 set_reg(dev, 'AZ')
447
448 dev[0].request("SET sae_groups ")
449 id = add_mesh_secure_net(dev[0], pmf=True, ocv=True)
450 dev[0].set_network(id, "frequency", "5200")
451 dev[0].set_network(id, "max_oper_chwidth", "2")
452 dev[0].mesh_group_add(id)
453
454 dev[1].request("SET sae_groups ")
455 id = add_mesh_secure_net(dev[1], pmf=True, ocv=True)
456 dev[1].set_network(id, "frequency", "5200")
457 dev[1].set_network(id, "disable_vht", "1")
458 dev[1].set_network(id, "disable_ht40", "1")
459 dev[1].mesh_group_add(id)
460
461 check_mesh_joined_connected(dev, connectivity=True)
462
463 def test_mesh_secure_ocv_mix_ht(dev, apdev):
464 """Mesh network with a VHT STA and a HT STA under OCV"""
465 try:
466 run_mesh_secure_ocv_mix_ht(dev, apdev)
467 finally:
468 clear_reg_setting(dev)
469
470 def run_mesh_secure_ocv_mix_ht(dev, apdev):
471 check_mesh_support(dev[0], secure=True)
472 set_reg(dev, 'AZ')
473
474 dev[0].request("SET sae_groups ")
475 id = add_mesh_secure_net(dev[0], pmf=True, ocv=True)
476 dev[0].set_network(id, "frequency", "5200")
477 dev[0].set_network(id, "max_oper_chwidth", "2")
478 dev[0].mesh_group_add(id)
479
480 dev[1].request("SET sae_groups ")
481 id = add_mesh_secure_net(dev[1], pmf=True, ocv=True)
482 dev[1].set_network(id, "frequency", "5200")
483 dev[1].set_network(id, "disable_vht", "1")
484 dev[1].mesh_group_add(id)
485
486 check_mesh_joined_connected(dev, connectivity=True)
487
488 def run_mesh_secure(dev, cipher):
489 if cipher not in dev[0].get_capability("pairwise"):
490 raise HwsimSkip("Cipher %s not supported" % cipher)
491 check_mesh_support(dev[0], secure=True)
492 dev[0].request("SET sae_groups ")
493 id = add_mesh_secure_net(dev[0], pairwise=cipher, group=cipher)
494 dev[0].mesh_group_add(id)
495
496 dev[1].request("SET sae_groups ")
497 id = add_mesh_secure_net(dev[1], pairwise=cipher, group=cipher)
498 dev[1].mesh_group_add(id)
499
500 check_mesh_joined_connected(dev, connectivity=True)
501
502 def test_mesh_secure_ccmp(dev, apdev):
503 """Secure mesh with CCMP"""
504 run_mesh_secure(dev, "CCMP")
505
506 def test_mesh_secure_gcmp(dev, apdev):
507 """Secure mesh with GCMP"""
508 run_mesh_secure(dev, "GCMP")
509
510 def test_mesh_secure_gcmp_256(dev, apdev):
511 """Secure mesh with GCMP-256"""
512 run_mesh_secure(dev, "GCMP-256")
513
514 def test_mesh_secure_ccmp_256(dev, apdev):
515 """Secure mesh with CCMP-256"""
516 run_mesh_secure(dev, "CCMP-256")
517
518 def test_mesh_secure_invalid_pairwise_cipher(dev, apdev):
519 """Secure mesh and invalid group cipher"""
520 check_mesh_support(dev[0], secure=True)
521 dev[0].request("SET sae_groups ")
522 id = add_mesh_secure_net(dev[0], pairwise="TKIP", group="CCMP")
523 if dev[0].mesh_group_add(id) != None:
524 raise Exception("Unexpected group add success")
525 ev = dev[0].wait_event(["mesh: Invalid pairwise cipher"], timeout=1)
526 if ev is None:
527 raise Exception("Invalid pairwise cipher not reported")
528
529 def test_mesh_secure_invalid_group_cipher(dev, apdev):
530 """Secure mesh and invalid group cipher"""
531 check_mesh_support(dev[0], secure=True)
532 dev[0].request("SET sae_groups ")
533 id = add_mesh_secure_net(dev[0], pairwise="CCMP", group="TKIP")
534 if dev[0].mesh_group_add(id) != None:
535 raise Exception("Unexpected group add success")
536 ev = dev[0].wait_event(["mesh: Invalid group cipher"], timeout=1)
537 if ev is None:
538 raise Exception("Invalid group cipher not reported")
539
540 def test_wpas_mesh_secure_sae_group_mismatch(dev, apdev):
541 """wpa_supplicant secure MESH and SAE group mismatch"""
542 check_mesh_support(dev[0], secure=True)
543 addr0 = dev[0].p2p_interface_addr()
544 addr1 = dev[1].p2p_interface_addr()
545 addr2 = dev[2].p2p_interface_addr()
546
547 dev[0].request("SET sae_groups 19 25")
548 id = add_mesh_secure_net(dev[0])
549 dev[0].mesh_group_add(id)
550
551 dev[1].request("SET sae_groups 19")
552 id = add_mesh_secure_net(dev[1])
553 dev[1].mesh_group_add(id)
554
555 dev[2].request("SET sae_groups 26")
556 id = add_mesh_secure_net(dev[2])
557 dev[2].mesh_group_add(id)
558
559 check_mesh_group_added(dev[0])
560 check_mesh_group_added(dev[1])
561 check_mesh_group_added(dev[2])
562
563 ev = dev[0].wait_event(["MESH-PEER-CONNECTED"])
564 if ev is None:
565 raise Exception("Remote peer did not connect")
566 if addr1 not in ev:
567 raise Exception("Unexpected peer connected: " + ev)
568
569 ev = dev[1].wait_event(["MESH-PEER-CONNECTED"])
570 if ev is None:
571 raise Exception("Remote peer did not connect")
572 if addr0 not in ev:
573 raise Exception("Unexpected peer connected: " + ev)
574
575 ev = dev[2].wait_event(["MESH-PEER-CONNECTED"], timeout=1)
576 if ev is not None:
577 raise Exception("Unexpected peer connection at dev[2]: " + ev)
578
579 ev = dev[0].wait_event(["MESH-PEER-CONNECTED"], timeout=0.1)
580 if ev is not None:
581 raise Exception("Unexpected peer connection: " + ev)
582
583 ev = dev[1].wait_event(["MESH-PEER-CONNECTED"], timeout=0.1)
584 if ev is not None:
585 raise Exception("Unexpected peer connection: " + ev)
586
587 dev[0].request("SET sae_groups ")
588 dev[1].request("SET sae_groups ")
589 dev[2].request("SET sae_groups ")
590
591 def test_wpas_mesh_secure_sae_group_negotiation(dev, apdev):
592 """wpa_supplicant secure MESH and SAE group negotiation"""
593 check_mesh_support(dev[0], secure=True)
594 addr0 = dev[0].own_addr()
595 addr1 = dev[1].own_addr()
596
597 #dev[0].request("SET sae_groups 21 20 25 26")
598 dev[0].request("SET sae_groups 26")
599 id = add_mesh_secure_net(dev[0])
600 dev[0].mesh_group_add(id)
601
602 dev[1].request("SET sae_groups 19 26")
603 id = add_mesh_secure_net(dev[1])
604 dev[1].mesh_group_add(id)
605
606 check_mesh_joined_connected(dev)
607
608 dev[0].request("SET sae_groups ")
609 dev[1].request("SET sae_groups ")
610
611 def test_wpas_mesh_secure_sae_missing_password(dev, apdev):
612 """wpa_supplicant secure MESH and missing SAE password"""
613 check_mesh_support(dev[0], secure=True)
614 id = add_mesh_secure_net(dev[0], psk=False)
615 dev[0].set_network(id, "psk", "8f20b381f9b84371d61b5080ad85cac3c61ab3ca9525be5b2d0f4da3d979187a")
616 dev[0].mesh_group_add(id)
617 ev = dev[0].wait_event(["MESH-GROUP-STARTED", "Could not join mesh"],
618 timeout=5)
619 if ev is None:
620 raise Exception("Timeout on mesh start event")
621 if "MESH-GROUP-STARTED" in ev:
622 raise Exception("Unexpected mesh group start")
623 ev = dev[0].wait_event(["MESH-GROUP-STARTED"], timeout=0.1)
624 if ev is not None:
625 raise Exception("Unexpected mesh group start")
626
627 def test_wpas_mesh_secure_no_auto(dev, apdev):
628 """wpa_supplicant secure MESH network connectivity"""
629 check_mesh_support(dev[0], secure=True)
630 dev[0].request("SET sae_groups 19")
631 id = add_mesh_secure_net(dev[0])
632 dev[0].mesh_group_add(id)
633
634 dev[1].request("SET sae_groups 19")
635 id = add_mesh_secure_net(dev[1])
636 dev[1].set_network(id, "no_auto_peer", "1")
637 dev[1].mesh_group_add(id)
638
639 check_mesh_joined_connected(dev, connectivity=True)
640
641 dev[0].request("SET sae_groups ")
642 dev[1].request("SET sae_groups ")
643
644 def test_wpas_mesh_secure_dropped_frame(dev, apdev):
645 """Secure mesh network connectivity when the first plink Open is dropped"""
646 check_mesh_support(dev[0], secure=True)
647
648 dev[0].request("SET ext_mgmt_frame_handling 1")
649 dev[0].request("SET sae_groups ")
650 id = add_mesh_secure_net(dev[0])
651 dev[0].mesh_group_add(id)
652
653 dev[1].request("SET sae_groups ")
654 id = add_mesh_secure_net(dev[1])
655 dev[1].mesh_group_add(id)
656
657 check_mesh_joined2(dev)
658
659 # Drop the first Action frame (plink Open) to test unexpected order of
660 # Confirm/Open messages.
661 count = 0
662 while True:
663 count += 1
664 if count > 10:
665 raise Exception("Did not see Action frames")
666 rx_msg = dev[0].mgmt_rx()
667 if rx_msg is None:
668 raise Exception("MGMT-RX timeout")
669 if rx_msg['subtype'] == 13:
670 logger.info("Drop the first Action frame")
671 break
672 if "OK" not in dev[0].request("MGMT_RX_PROCESS freq={} datarate={} ssi_signal={} frame={}".format(
673 rx_msg['freq'], rx_msg['datarate'], rx_msg['ssi_signal'], binascii.hexlify(rx_msg['frame']).decode())):
674 raise Exception("MGMT_RX_PROCESS failed")
675
676 dev[0].request("SET ext_mgmt_frame_handling 0")
677
678 check_mesh_connected2(dev, connectivity=True)
679
680 def test_mesh_secure_fail(dev, apdev):
681 """Secure mesh network connectivity failure"""
682 check_mesh_support(dev[0], secure=True)
683 dev[0].request("SET sae_groups ")
684 id = add_mesh_secure_net(dev[0], pmf=True)
685 dev[0].mesh_group_add(id)
686
687 dev[1].request("SET sae_groups ")
688 id = add_mesh_secure_net(dev[1], pmf=True)
689
690 with fail_test(dev[0], 1, "wpa_driver_nl80211_sta_add;mesh_mpm_auth_peer"):
691 dev[1].mesh_group_add(id)
692
693 check_mesh_joined_connected(dev)
694
695 def test_wpas_mesh_ctrl(dev):
696 """wpa_supplicant ctrl_iface mesh command error cases"""
697 check_mesh_support(dev[0])
698 if "FAIL" not in dev[0].request("MESH_GROUP_ADD 123"):
699 raise Exception("Unexpected MESH_GROUP_ADD success")
700 id = dev[0].add_network()
701 if "FAIL" not in dev[0].request("MESH_GROUP_ADD %d" % id):
702 raise Exception("Unexpected MESH_GROUP_ADD success")
703 dev[0].set_network(id, "mode", "5")
704 dev[0].set_network(id, "key_mgmt", "WPA-PSK")
705 if "FAIL" not in dev[0].request("MESH_GROUP_ADD %d" % id):
706 raise Exception("Unexpected MESH_GROUP_ADD success")
707
708 if "FAIL" not in dev[0].request("MESH_GROUP_REMOVE foo"):
709 raise Exception("Unexpected MESH_GROUP_REMOVE success")
710
711 def test_wpas_mesh_dynamic_interface(dev):
712 """wpa_supplicant mesh with dynamic interface"""
713 check_mesh_support(dev[0])
714 mesh0 = None
715 mesh1 = None
716 try:
717 mesh0 = dev[0].request("MESH_INTERFACE_ADD ifname=mesh0")
718 if "FAIL" in mesh0:
719 raise Exception("MESH_INTERFACE_ADD failed")
720 mesh1 = dev[1].request("MESH_INTERFACE_ADD")
721 if "FAIL" in mesh1:
722 raise Exception("MESH_INTERFACE_ADD failed")
723
724 wpas0 = WpaSupplicant(ifname=mesh0)
725 wpas1 = WpaSupplicant(ifname=mesh1)
726 logger.info(mesh0 + " address " + wpas0.get_status_field("address"))
727 logger.info(mesh1 + " address " + wpas1.get_status_field("address"))
728
729 add_open_mesh_network(wpas0)
730 add_open_mesh_network(wpas1)
731 check_mesh_joined_connected([wpas0, wpas1], connectivity=True)
732
733 # Must not allow MESH_GROUP_REMOVE on dynamic interface
734 if "FAIL" not in wpas0.request("MESH_GROUP_REMOVE " + mesh0):
735 raise Exception("Invalid MESH_GROUP_REMOVE accepted")
736 if "FAIL" not in wpas1.request("MESH_GROUP_REMOVE " + mesh1):
737 raise Exception("Invalid MESH_GROUP_REMOVE accepted")
738
739 # Must not allow MESH_GROUP_REMOVE on another radio interface
740 if "FAIL" not in wpas0.request("MESH_GROUP_REMOVE " + mesh1):
741 raise Exception("Invalid MESH_GROUP_REMOVE accepted")
742 if "FAIL" not in wpas1.request("MESH_GROUP_REMOVE " + mesh0):
743 raise Exception("Invalid MESH_GROUP_REMOVE accepted")
744
745 wpas0.remove_ifname()
746 wpas1.remove_ifname()
747
748 if "OK" not in dev[0].request("MESH_GROUP_REMOVE " + mesh0):
749 raise Exception("MESH_GROUP_REMOVE failed")
750 if "OK" not in dev[1].request("MESH_GROUP_REMOVE " + mesh1):
751 raise Exception("MESH_GROUP_REMOVE failed")
752
753 if "FAIL" not in dev[0].request("MESH_GROUP_REMOVE " + mesh0):
754 raise Exception("Invalid MESH_GROUP_REMOVE accepted")
755 if "FAIL" not in dev[1].request("MESH_GROUP_REMOVE " + mesh1):
756 raise Exception("Invalid MESH_GROUP_REMOVE accepted")
757
758 logger.info("Make sure another dynamic group can be added")
759 mesh0 = dev[0].request("MESH_INTERFACE_ADD ifname=mesh0")
760 if "FAIL" in mesh0:
761 raise Exception("MESH_INTERFACE_ADD failed")
762 mesh1 = dev[1].request("MESH_INTERFACE_ADD")
763 if "FAIL" in mesh1:
764 raise Exception("MESH_INTERFACE_ADD failed")
765
766 wpas0 = WpaSupplicant(ifname=mesh0)
767 wpas1 = WpaSupplicant(ifname=mesh1)
768 logger.info(mesh0 + " address " + wpas0.get_status_field("address"))
769 logger.info(mesh1 + " address " + wpas1.get_status_field("address"))
770
771 add_open_mesh_network(wpas0)
772 add_open_mesh_network(wpas1)
773 check_mesh_joined_connected([wpas0, wpas1], connectivity=True)
774 finally:
775 if mesh0:
776 dev[0].request("MESH_GROUP_REMOVE " + mesh0)
777 if mesh1:
778 dev[1].request("MESH_GROUP_REMOVE " + mesh1)
779
780 def test_wpas_mesh_dynamic_interface_remove(dev):
781 """wpa_supplicant mesh with dynamic interface and removal"""
782 wpas = WpaSupplicant(global_iface='/tmp/wpas-wlan5')
783 wpas.interface_add("wlan5")
784 check_mesh_support(wpas)
785 mesh5 = wpas.request("MESH_INTERFACE_ADD ifname=mesh5")
786 if "FAIL" in mesh5:
787 raise Exception("MESH_INTERFACE_ADD failed")
788
789 wpas5 = WpaSupplicant(ifname=mesh5)
790 logger.info(mesh5 + " address " + wpas5.get_status_field("address"))
791 add_open_mesh_network(wpas5)
792 add_open_mesh_network(dev[0])
793 check_mesh_joined_connected([wpas5, dev[0]], connectivity=True)
794
795 # Remove the main interface while mesh interface is in use
796 wpas.interface_remove("wlan5")
797
798 def test_wpas_mesh_max_peering(dev, apdev, params):
799 """Mesh max peering limit"""
800 check_mesh_support(dev[0])
801 try:
802 dev[0].request("SET max_peer_links 1")
803
804 # first, connect dev[0] and dev[1]
805 add_open_mesh_network(dev[0])
806 add_open_mesh_network(dev[1])
807 for i in range(2):
808 ev = dev[i].wait_event(["MESH-PEER-CONNECTED"])
809 if ev is None:
810 raise Exception("dev%d did not connect with any peer" % i)
811
812 # add dev[2] which will try to connect with both dev[0] and dev[1],
813 # but can complete connection only with dev[1]
814 add_open_mesh_network(dev[2])
815 for i in range(1, 3):
816 ev = dev[i].wait_event(["MESH-PEER-CONNECTED"])
817 if ev is None:
818 raise Exception("dev%d did not connect the second peer" % i)
819
820 ev = dev[0].wait_event(["MESH-PEER-CONNECTED"], timeout=1)
821 if ev is not None:
822 raise Exception("dev0 connection beyond max peering limit")
823
824 ev = dev[2].wait_event(["MESH-PEER-CONNECTED"], timeout=0.1)
825 if ev is not None:
826 raise Exception("dev2 reported unexpected peering: " + ev)
827
828 for i in range(3):
829 dev[i].mesh_group_remove()
830 check_mesh_group_removed(dev[i])
831 finally:
832 dev[0].request("SET max_peer_links 99")
833
834 addr0 = dev[0].own_addr()
835 addr1 = dev[1].own_addr()
836 addr2 = dev[2].own_addr()
837
838 capfile = os.path.join(params['logdir'], "hwsim0.pcapng")
839 filt = "wlan.fc.type_subtype == 8"
840 out = run_tshark(capfile, filt, ["wlan.sa", "wlan.mesh.config.cap"])
841 pkts = out.splitlines()
842 one = [0, 0, 0]
843 zero = [0, 0, 0]
844 all_cap_one = True
845 for pkt in pkts:
846 addr, cap = pkt.split('\t')
847 cap = int(cap, 16)
848 if cap != 1:
849 all_cap_one = False
850 if addr == addr0:
851 idx = 0
852 elif addr == addr1:
853 idx = 1
854 elif addr == addr2:
855 idx = 2
856 else:
857 continue
858 if cap & 0x01:
859 one[idx] += 1
860 else:
861 zero[idx] += 1
862 logger.info("one: " + str(one))
863 logger.info("zero: " + str(zero))
864 if all_cap_one:
865 # It looks like tshark parser was broken at some point for
866 # wlan.mesh.config.cap which is now (tshark 2.6.3) pointing to incorrect
867 # field (same as wlan.mesh.config.ps_protocol). This used to work with
868 # tshark 2.2.6.
869 #
870 # For now, assume the capability field ends up being the last octet of
871 # the frame.
872 one = [0, 0, 0]
873 zero = [0, 0, 0]
874 addrs = [addr0, addr1, addr2]
875 for idx in range(3):
876 addr = addrs[idx]
877 out = run_tshark_json(capfile, filt + " && wlan.sa == " + addr)
878 pkts = json.loads(out)
879 for pkt in pkts:
880 wlan = pkt["_source"]["layers"]["wlan"]
881 if "wlan.tagged.all" not in wlan:
882 continue
883
884 tagged = wlan["wlan.tagged.all"]
885 if "wlan.tag" not in tagged:
886 continue
887
888 wlan_tag = tagged["wlan.tag"]
889 if "wlan.mesh.config.ps_protocol_raw" not in wlan_tag:
890 continue
891
892 frame = pkt["_source"]["layers"]["frame_raw"][0]
893 cap_offset = wlan_tag["wlan.mesh.config.ps_protocol_raw"][1] + 6
894 cap = int(frame[(cap_offset * 2):(cap_offset * 2 + 2)], 16)
895 if cap & 0x01:
896 one[idx] += 1
897 else:
898 zero[idx] += 1
899 logger.info("one: " + str(one))
900 logger.info("zero: " + str(zero))
901 if zero[0] == 0:
902 raise Exception("Accepting Additional Mesh Peerings not cleared")
903 if one[0] == 0:
904 raise Exception("Accepting Additional Mesh Peerings was not set in the first Beacon frame")
905 if zero[1] > 0 or zero[2] > 0 or one[1] == 0 or one[2] == 0:
906 raise Exception("Unexpected value in Accepting Additional Mesh Peerings from other STAs")
907
908 def test_wpas_mesh_open_5ghz(dev, apdev):
909 """wpa_supplicant open MESH network on 5 GHz band"""
910 try:
911 _test_wpas_mesh_open_5ghz(dev, apdev)
912 finally:
913 dev[0].request("MESH_GROUP_REMOVE " + dev[0].ifname)
914 dev[1].request("MESH_GROUP_REMOVE " + dev[1].ifname)
915 subprocess.call(['iw', 'reg', 'set', '00'])
916 dev[0].flush_scan_cache()
917 dev[1].flush_scan_cache()
918
919 def _test_wpas_mesh_open_5ghz(dev, apdev):
920 check_mesh_support(dev[0])
921 subprocess.call(['iw', 'reg', 'set', 'US'])
922 for i in range(2):
923 for j in range(5):
924 ev = dev[i].wait_event(["CTRL-EVENT-REGDOM-CHANGE"], timeout=5)
925 if ev is None:
926 raise Exception("No regdom change event")
927 if "alpha2=US" in ev:
928 break
929 add_open_mesh_network(dev[i], freq="5180")
930
931 check_mesh_joined_connected(dev, connectivity=True)
932
933 dev[0].mesh_group_remove()
934 dev[1].mesh_group_remove()
935 check_mesh_group_removed(dev[0])
936 check_mesh_group_removed(dev[1])
937 dev[0].dump_monitor()
938 dev[1].dump_monitor()
939
940 def test_wpas_mesh_open_5ghz_coex(dev, apdev):
941 """Mesh network on 5 GHz band and 20/40 coex change"""
942 try:
943 _test_wpas_mesh_open_5ghz_coex(dev, apdev)
944 finally:
945 dev[0].request("MESH_GROUP_REMOVE " + dev[0].ifname)
946 dev[1].request("MESH_GROUP_REMOVE " + dev[1].ifname)
947 set_world_reg(apdev0=apdev[0], dev0=dev[0])
948 dev[0].flush_scan_cache()
949 dev[1].flush_scan_cache()
950
951 def _test_wpas_mesh_open_5ghz_coex(dev, apdev):
952 check_mesh_support(dev[0])
953 subprocess.call(['iw', 'reg', 'set', 'US'])
954
955 # Start a 20 MHz BSS on channel 40 that would be the secondary channel of
956 # HT40+ mesh on channel 36.
957 params = {"ssid": "test-ht40",
958 "hw_mode": "a",
959 "channel": "40",
960 "country_code": "US"}
961 hapd = hostapd.add_ap(apdev[0], params)
962 bssid = hapd.own_addr()
963
964 for i in range(2):
965 for j in range(5):
966 ev = dev[i].wait_event(["CTRL-EVENT-REGDOM-CHANGE"], timeout=5)
967 if ev is None:
968 raise Exception("No regdom change event")
969 if "alpha2=US" in ev:
970 break
971 dev[i].scan_for_bss(bssid, freq=5200)
972 add_open_mesh_network(dev[i], freq="5180")
973
974 check_mesh_joined_connected(dev)
975
976 freq = dev[0].get_status_field("freq")
977 if freq != "5200":
978 raise Exception("Unexpected STATUS freq=" + freq)
979 sig = dev[0].request("SIGNAL_POLL").splitlines()
980 if "FREQUENCY=5200" not in sig:
981 raise Exception("Unexpected SIGNAL_POLL output: " + str(sig))
982
983 hapd.disable()
984 dev[0].mesh_group_remove()
985 dev[1].mesh_group_remove()
986 check_mesh_group_removed(dev[0])
987 check_mesh_group_removed(dev[1])
988 dev[0].dump_monitor()
989 dev[1].dump_monitor()
990
991 def test_wpas_mesh_open_ht40(dev, apdev):
992 """Mesh and HT40 support difference"""
993 try:
994 _test_wpas_mesh_open_ht40(dev, apdev)
995 finally:
996 dev[0].request("MESH_GROUP_REMOVE " + dev[0].ifname)
997 dev[1].request("MESH_GROUP_REMOVE " + dev[1].ifname)
998 dev[2].request("MESH_GROUP_REMOVE " + dev[2].ifname)
999 subprocess.call(['iw', 'reg', 'set', '00'])
1000 dev[0].flush_scan_cache()
1001 dev[1].flush_scan_cache()
1002 dev[2].flush_scan_cache()
1003
1004 def _test_wpas_mesh_open_ht40(dev, apdev):
1005 check_mesh_support(dev[0])
1006 subprocess.call(['iw', 'reg', 'set', 'US'])
1007 for i in range(3):
1008 for j in range(5):
1009 ev = dev[i].wait_event(["CTRL-EVENT-REGDOM-CHANGE"], timeout=5)
1010 if ev is None:
1011 raise Exception("No regdom change event")
1012 if "alpha2=US" in ev:
1013 break
1014 add_open_mesh_network(dev[i], freq="5180", disable_vht=True,
1015 disable_ht40=(i == 2))
1016
1017 check_mesh_group_added(dev[0])
1018 check_mesh_group_added(dev[1])
1019 check_mesh_group_added(dev[2])
1020
1021 check_mesh_peer_connected(dev[0])
1022 check_mesh_peer_connected(dev[1])
1023 check_mesh_peer_connected(dev[2])
1024
1025 hwsim_utils.test_connectivity(dev[0], dev[1])
1026 hwsim_utils.test_connectivity(dev[0], dev[2])
1027 hwsim_utils.test_connectivity(dev[1], dev[2])
1028
1029 dev[0].mesh_group_remove()
1030 dev[1].mesh_group_remove()
1031 dev[2].mesh_group_remove()
1032 check_mesh_group_removed(dev[0])
1033 check_mesh_group_removed(dev[1])
1034 check_mesh_group_removed(dev[2])
1035 dev[0].dump_monitor()
1036 dev[1].dump_monitor()
1037 dev[2].dump_monitor()
1038
1039 def test_wpas_mesh_open_vht40(dev, apdev):
1040 """wpa_supplicant open MESH network on VHT 40 MHz channel"""
1041 try:
1042 _test_wpas_mesh_open_vht40(dev, apdev)
1043 finally:
1044 dev[0].request("MESH_GROUP_REMOVE " + dev[0].ifname)
1045 dev[1].request("MESH_GROUP_REMOVE " + dev[1].ifname)
1046 subprocess.call(['iw', 'reg', 'set', '00'])
1047 dev[0].flush_scan_cache()
1048 dev[1].flush_scan_cache()
1049
1050 def _test_wpas_mesh_open_vht40(dev, apdev):
1051 check_mesh_support(dev[0])
1052 subprocess.call(['iw', 'reg', 'set', 'US'])
1053 for i in range(2):
1054 for j in range(5):
1055 ev = dev[i].wait_event(["CTRL-EVENT-REGDOM-CHANGE"], timeout=5)
1056 if ev is None:
1057 raise Exception("No regdom change event")
1058 if "alpha2=US" in ev:
1059 break
1060 add_open_mesh_network(dev[i], freq="5180", chwidth=0)
1061
1062 check_mesh_joined_connected(dev, connectivity=True)
1063
1064 sig = dev[0].request("SIGNAL_POLL").splitlines()
1065 if "WIDTH=40 MHz" not in sig:
1066 raise Exception("Unexpected SIGNAL_POLL value(2): " + str(sig))
1067 if "CENTER_FRQ1=5190" not in sig:
1068 raise Exception("Unexpected SIGNAL_POLL value(3): " + str(sig))
1069
1070 sig = dev[1].request("SIGNAL_POLL").splitlines()
1071 if "WIDTH=40 MHz" not in sig:
1072 raise Exception("Unexpected SIGNAL_POLL value(2b): " + str(sig))
1073 if "CENTER_FRQ1=5190" not in sig:
1074 raise Exception("Unexpected SIGNAL_POLL value(3b): " + str(sig))
1075
1076 dev[0].mesh_group_remove()
1077 dev[1].mesh_group_remove()
1078 check_mesh_group_removed(dev[0])
1079 check_mesh_group_removed(dev[1])
1080 dev[0].dump_monitor()
1081 dev[1].dump_monitor()
1082
1083 def test_wpas_mesh_open_vht20(dev, apdev):
1084 """wpa_supplicant open MESH network on VHT 20 MHz channel"""
1085 try:
1086 _test_wpas_mesh_open_vht20(dev, apdev)
1087 finally:
1088 dev[0].request("MESH_GROUP_REMOVE " + dev[0].ifname)
1089 dev[1].request("MESH_GROUP_REMOVE " + dev[1].ifname)
1090 subprocess.call(['iw', 'reg', 'set', '00'])
1091 dev[0].flush_scan_cache()
1092 dev[1].flush_scan_cache()
1093
1094 def _test_wpas_mesh_open_vht20(dev, apdev):
1095 check_mesh_support(dev[0])
1096 subprocess.call(['iw', 'reg', 'set', 'US'])
1097 for i in range(2):
1098 for j in range(5):
1099 ev = dev[i].wait_event(["CTRL-EVENT-REGDOM-CHANGE"], timeout=5)
1100 if ev is None:
1101 raise Exception("No regdom change event")
1102 if "alpha2=US" in ev:
1103 break
1104 add_open_mesh_network(dev[i], freq="5180", chwidth=0, disable_ht40=True)
1105
1106 check_mesh_joined_connected(dev, connectivity=True)
1107
1108 sig = dev[0].request("SIGNAL_POLL").splitlines()
1109 if "WIDTH=20 MHz" not in sig:
1110 raise Exception("Unexpected SIGNAL_POLL value(2): " + str(sig))
1111 if "CENTER_FRQ1=5180" not in sig:
1112 raise Exception("Unexpected SIGNAL_POLL value(3): " + str(sig))
1113
1114 sig = dev[1].request("SIGNAL_POLL").splitlines()
1115 if "WIDTH=20 MHz" not in sig:
1116 raise Exception("Unexpected SIGNAL_POLL value(2b): " + str(sig))
1117 if "CENTER_FRQ1=5180" not in sig:
1118 raise Exception("Unexpected SIGNAL_POLL value(3b): " + str(sig))
1119
1120 dev[0].mesh_group_remove()
1121 dev[1].mesh_group_remove()
1122 check_mesh_group_removed(dev[0])
1123 check_mesh_group_removed(dev[1])
1124 dev[0].dump_monitor()
1125 dev[1].dump_monitor()
1126
1127 def test_wpas_mesh_open_vht_80p80(dev, apdev):
1128 """wpa_supplicant open MESH network on VHT 80+80 MHz channel"""
1129 try:
1130 _test_wpas_mesh_open_vht_80p80(dev, apdev)
1131 finally:
1132 dev[0].request("MESH_GROUP_REMOVE " + dev[0].ifname)
1133 dev[1].request("MESH_GROUP_REMOVE " + dev[1].ifname)
1134 subprocess.call(['iw', 'reg', 'set', '00'])
1135 dev[0].flush_scan_cache()
1136 dev[1].flush_scan_cache()
1137
1138 def _test_wpas_mesh_open_vht_80p80(dev, apdev):
1139 check_mesh_support(dev[0])
1140 subprocess.call(['iw', 'reg', 'set', 'US'])
1141 for i in range(2):
1142 for j in range(5):
1143 ev = dev[i].wait_event(["CTRL-EVENT-REGDOM-CHANGE"], timeout=5)
1144 if ev is None:
1145 raise Exception("No regdom change event")
1146 if "alpha2=US" in ev:
1147 break
1148 add_open_mesh_network(dev[i], freq="5180", chwidth=3)
1149
1150 check_mesh_joined_connected(dev, connectivity=True)
1151
1152 sig = dev[0].request("SIGNAL_POLL").splitlines()
1153 if "WIDTH=80+80 MHz" not in sig:
1154 raise Exception("Unexpected SIGNAL_POLL value(2): " + str(sig))
1155 if "CENTER_FRQ1=5210" not in sig:
1156 raise Exception("Unexpected SIGNAL_POLL value(3): " + str(sig))
1157 if "CENTER_FRQ2=5775" not in sig:
1158 raise Exception("Unexpected SIGNAL_POLL value(4): " + str(sig))
1159
1160 sig = dev[1].request("SIGNAL_POLL").splitlines()
1161 if "WIDTH=80+80 MHz" not in sig:
1162 raise Exception("Unexpected SIGNAL_POLL value(2b): " + str(sig))
1163 if "CENTER_FRQ1=5210" not in sig:
1164 raise Exception("Unexpected SIGNAL_POLL value(3b): " + str(sig))
1165 if "CENTER_FRQ2=5775" not in sig:
1166 raise Exception("Unexpected SIGNAL_POLL value(4b): " + str(sig))
1167
1168 dev[0].mesh_group_remove()
1169 dev[1].mesh_group_remove()
1170 check_mesh_group_removed(dev[0])
1171 check_mesh_group_removed(dev[1])
1172 dev[0].dump_monitor()
1173 dev[1].dump_monitor()
1174
1175 def test_mesh_open_vht_160(dev, apdev):
1176 """Open mesh network on VHT 160 MHz channel"""
1177 try:
1178 _test_mesh_open_vht_160(dev, apdev)
1179 finally:
1180 dev[0].request("MESH_GROUP_REMOVE " + dev[0].ifname)
1181 dev[1].request("MESH_GROUP_REMOVE " + dev[1].ifname)
1182 subprocess.call(['iw', 'reg', 'set', '00'])
1183 dev[0].flush_scan_cache()
1184 dev[1].flush_scan_cache()
1185
1186 def _test_mesh_open_vht_160(dev, apdev):
1187 check_mesh_support(dev[0])
1188 subprocess.call(['iw', 'reg', 'set', 'ZA'])
1189 for i in range(2):
1190 for j in range(5):
1191 ev = dev[i].wait_event(["CTRL-EVENT-REGDOM-CHANGE"], timeout=5)
1192 if ev is None:
1193 raise Exception("No regdom change event")
1194 if "alpha2=ZA" in ev:
1195 break
1196
1197 cmd = subprocess.Popen(["iw", "reg", "get"], stdout=subprocess.PIPE)
1198 reg = cmd.stdout.read()
1199 found = False
1200 for entry in reg.splitlines():
1201 entry = entry.decode()
1202 if "@ 160)" in entry and "DFS" not in entry:
1203 found = True
1204 break
1205 if not found:
1206 raise HwsimSkip("160 MHz channel without DFS not supported in regulatory information")
1207
1208 add_open_mesh_network(dev[i], freq="5520", chwidth=2)
1209
1210 check_mesh_joined_connected(dev, connectivity=True)
1211 dev[0].dump_monitor()
1212 dev[1].dump_monitor()
1213
1214 sig = dev[0].request("SIGNAL_POLL").splitlines()
1215 if "WIDTH=160 MHz" not in sig:
1216 raise Exception("Unexpected SIGNAL_POLL value(2): " + str(sig))
1217 if "FREQUENCY=5520" not in sig:
1218 raise Exception("Unexpected SIGNAL_POLL value(3): " + str(sig))
1219
1220 sig = dev[1].request("SIGNAL_POLL").splitlines()
1221 if "WIDTH=160 MHz" not in sig:
1222 raise Exception("Unexpected SIGNAL_POLL value(2b): " + str(sig))
1223 if "FREQUENCY=5520" not in sig:
1224 raise Exception("Unexpected SIGNAL_POLL value(3b): " + str(sig))
1225
1226 dev[0].mesh_group_remove()
1227 dev[1].mesh_group_remove()
1228 check_mesh_group_removed(dev[0])
1229 check_mesh_group_removed(dev[1])
1230 dev[0].dump_monitor()
1231 dev[1].dump_monitor()
1232
1233 def test_wpas_mesh_password_mismatch(dev, apdev):
1234 """Mesh network and one device with mismatching password"""
1235 check_mesh_support(dev[0], secure=True)
1236 dev[0].request("SET sae_groups ")
1237 id = add_mesh_secure_net(dev[0])
1238 dev[0].mesh_group_add(id)
1239
1240 dev[1].request("SET sae_groups ")
1241 id = add_mesh_secure_net(dev[1])
1242 dev[1].mesh_group_add(id)
1243
1244 dev[2].request("SET sae_groups ")
1245 id = add_mesh_secure_net(dev[2])
1246 dev[2].set_network_quoted(id, "psk", "wrong password")
1247 dev[2].mesh_group_add(id)
1248
1249 # The two peers with matching password need to be able to connect
1250 check_mesh_joined_connected(dev)
1251
1252 ev = dev[2].wait_event(["MESH-SAE-AUTH-FAILURE"], timeout=20)
1253 if ev is None:
1254 raise Exception("dev2 did not report auth failure (1)")
1255 ev = dev[2].wait_event(["MESH-SAE-AUTH-FAILURE"], timeout=20)
1256 if ev is None:
1257 raise Exception("dev2 did not report auth failure (2)")
1258 dev[2].dump_monitor()
1259
1260 count = 0
1261 ev = dev[0].wait_event(["MESH-SAE-AUTH-FAILURE"], timeout=5)
1262 if ev is None:
1263 logger.info("dev0 did not report auth failure")
1264 else:
1265 if "addr=" + dev[2].own_addr() not in ev:
1266 raise Exception("Unexpected peer address in dev0 event: " + ev)
1267 count += 1
1268 dev[0].dump_monitor()
1269
1270 ev = dev[1].wait_event(["MESH-SAE-AUTH-FAILURE"], timeout=5)
1271 if ev is None:
1272 logger.info("dev1 did not report auth failure")
1273 else:
1274 if "addr=" + dev[2].own_addr() not in ev:
1275 raise Exception("Unexpected peer address in dev1 event: " + ev)
1276 count += 1
1277 dev[1].dump_monitor()
1278
1279 hwsim_utils.test_connectivity(dev[0], dev[1])
1280
1281 for i in range(2):
1282 try:
1283 hwsim_utils.test_connectivity(dev[i], dev[2], timeout=1)
1284 raise Exception("Data connectivity test passed unexpectedly")
1285 except Exception as e:
1286 if "data delivery failed" not in str(e):
1287 raise
1288
1289 if count == 0:
1290 raise Exception("Neither dev0 nor dev1 reported auth failure")
1291
1292 def test_wpas_mesh_password_mismatch_retry(dev, apdev, params):
1293 """Mesh password mismatch and retry [long]"""
1294 if not params['long']:
1295 raise HwsimSkip("Skip test case with long duration due to --long not specified")
1296 check_mesh_support(dev[0], secure=True)
1297 dev[0].request("SET sae_groups ")
1298 id = add_mesh_secure_net(dev[0])
1299 dev[0].mesh_group_add(id)
1300
1301 dev[1].request("SET sae_groups ")
1302 id = add_mesh_secure_net(dev[1])
1303 dev[1].set_network_quoted(id, "psk", "wrong password")
1304 dev[1].mesh_group_add(id)
1305
1306 check_mesh_joined2(dev)
1307
1308 for i in range(4):
1309 ev = dev[0].wait_event(["MESH-SAE-AUTH-FAILURE"], timeout=20)
1310 if ev is None:
1311 raise Exception("dev0 did not report auth failure (%d)" % i)
1312 ev = dev[1].wait_event(["MESH-SAE-AUTH-FAILURE"], timeout=20)
1313 if ev is None:
1314 raise Exception("dev1 did not report auth failure (%d)" % i)
1315
1316 ev = dev[0].wait_event(["MESH-SAE-AUTH-BLOCKED"], timeout=10)
1317 if ev is None:
1318 raise Exception("dev0 did not report auth blocked")
1319 ev = dev[1].wait_event(["MESH-SAE-AUTH-BLOCKED"], timeout=10)
1320 if ev is None:
1321 raise Exception("dev1 did not report auth blocked")
1322
1323 def test_mesh_wpa_auth_init_oom(dev, apdev):
1324 """Secure mesh network setup failing due to wpa_init() OOM"""
1325 check_mesh_support(dev[0], secure=True)
1326 dev[0].request("SET sae_groups ")
1327 with alloc_fail(dev[0], 1, "wpa_init"):
1328 id = add_mesh_secure_net(dev[0])
1329 dev[0].mesh_group_add(id)
1330 ev = dev[0].wait_event(["MESH-GROUP-STARTED"], timeout=0.2)
1331 if ev is not None:
1332 raise Exception("Unexpected mesh group start during OOM")
1333
1334 def test_mesh_wpa_init_fail(dev, apdev):
1335 """Secure mesh network setup local failure"""
1336 check_mesh_support(dev[0], secure=True)
1337 check_mesh_support(dev[1], secure=True)
1338 check_mesh_support(dev[2], secure=True)
1339 dev[0].request("SET sae_groups ")
1340
1341 with fail_test(dev[0], 1, "os_get_random;=__mesh_rsn_auth_init"):
1342 id = add_mesh_secure_net(dev[0])
1343 dev[0].mesh_group_add(id)
1344 wait_fail_trigger(dev[0], "GET_FAIL")
1345
1346 dev[0].dump_monitor()
1347 with alloc_fail(dev[0], 1, "mesh_rsn_auth_init"):
1348 id = add_mesh_secure_net(dev[0])
1349 dev[0].mesh_group_add(id)
1350 wait_fail_trigger(dev[0], "GET_ALLOC_FAIL")
1351
1352 dev[0].dump_monitor()
1353 with fail_test(dev[0], 1, "os_get_random;mesh_rsn_init_ampe_sta"):
1354 id = add_mesh_secure_net(dev[0])
1355 dev[0].mesh_group_add(id)
1356 dev[1].request("SET sae_groups ")
1357 id = add_mesh_secure_net(dev[1])
1358 dev[1].mesh_group_add(id)
1359 wait_fail_trigger(dev[0], "GET_FAIL")
1360
1361 with fail_test(dev[0], 2, "=omac1_aes_vector;aes_siv_encrypt"):
1362 id = add_mesh_secure_net(dev[2])
1363 dev[0].mesh_group_add(id)
1364 dev[2].request("SET sae_groups ")
1365 id = add_mesh_secure_net(dev[2])
1366 dev[2].mesh_group_add(id)
1367 wait_fail_trigger(dev[0], "GET_FAIL")
1368
1369 def test_wpas_mesh_reconnect(dev, apdev):
1370 """Secure mesh network plink counting during reconnection"""
1371 check_mesh_support(dev[0])
1372 try:
1373 _test_wpas_mesh_reconnect(dev)
1374 finally:
1375 dev[0].request("SET max_peer_links 99")
1376
1377 def _test_wpas_mesh_reconnect(dev):
1378 dev[0].request("SET max_peer_links 2")
1379 dev[0].request("SET sae_groups ")
1380 id = add_mesh_secure_net(dev[0])
1381 dev[0].set_network(id, "beacon_int", "100")
1382 dev[0].mesh_group_add(id)
1383 dev[1].request("SET sae_groups ")
1384 id = add_mesh_secure_net(dev[1])
1385 dev[1].mesh_group_add(id)
1386 check_mesh_joined_connected(dev)
1387
1388 for i in range(3):
1389 # Drop incoming management frames to avoid handling link close
1390 dev[0].request("SET ext_mgmt_frame_handling 1")
1391 dev[1].mesh_group_remove()
1392 check_mesh_group_removed(dev[1])
1393 dev[1].request("FLUSH")
1394 dev[0].request("SET ext_mgmt_frame_handling 0")
1395 id = add_mesh_secure_net(dev[1])
1396 dev[1].mesh_group_add(id)
1397 check_mesh_group_added(dev[1])
1398 check_mesh_peer_connected(dev[1])
1399 dev[0].dump_monitor()
1400 dev[1].dump_monitor()
1401
1402 def test_wpas_mesh_gate_forwarding(dev, apdev, p):
1403 """Mesh forwards traffic to unknown sta to mesh gates"""
1404 addr0 = dev[0].own_addr()
1405 addr1 = dev[1].own_addr()
1406 addr2 = dev[2].own_addr()
1407 external_sta = '02:11:22:33:44:55'
1408
1409 # start 3 node connected mesh
1410 check_mesh_support(dev[0])
1411 for i in range(3):
1412 add_open_mesh_network(dev[i])
1413 check_mesh_group_added(dev[i])
1414 for i in range(3):
1415 check_mesh_peer_connected(dev[i])
1416
1417 hwsim_utils.test_connectivity(dev[0], dev[1])
1418 hwsim_utils.test_connectivity(dev[1], dev[2])
1419 hwsim_utils.test_connectivity(dev[0], dev[2])
1420
1421 # dev0 and dev1 are mesh gates
1422 subprocess.call(['iw', 'dev', dev[0].ifname, 'set', 'mesh_param',
1423 'mesh_gate_announcements=1'])
1424 subprocess.call(['iw', 'dev', dev[1].ifname, 'set', 'mesh_param',
1425 'mesh_gate_announcements=1'])
1426
1427 # wait for gate announcement frames
1428 time.sleep(1)
1429
1430 # data frame from dev2 -> external sta should be sent to both gates
1431 dev[2].request("DATA_TEST_CONFIG 1")
1432 dev[2].request("DATA_TEST_TX {} {} 0".format(external_sta, addr2))
1433 dev[2].request("DATA_TEST_CONFIG 0")
1434
1435 capfile = os.path.join(p['logdir'], "hwsim0.pcapng")
1436 filt = "wlan.sa==%s && wlan_mgt.fixed.mesh_addr5==%s" % (addr2,
1437 external_sta)
1438 for i in range(15):
1439 da = run_tshark(capfile, filt, ["wlan.da"])
1440 if addr0 in da and addr1 in da:
1441 logger.debug("Frames seen in tshark iteration %d" % i)
1442 break
1443 time.sleep(0.3)
1444
1445 if addr0 not in da:
1446 raise Exception("Frame to gate %s not observed" % addr0)
1447 if addr1 not in da:
1448 raise Exception("Frame to gate %s not observed" % addr1)
1449
1450 def test_wpas_mesh_pmksa_caching(dev, apdev):
1451 """Secure mesh network and PMKSA caching"""
1452 check_mesh_support(dev[0], secure=True)
1453 dev[0].request("SET sae_groups ")
1454 id = add_mesh_secure_net(dev[0])
1455 dev[0].mesh_group_add(id)
1456
1457 dev[1].request("SET sae_groups ")
1458 id = add_mesh_secure_net(dev[1])
1459 dev[1].mesh_group_add(id)
1460
1461 check_mesh_joined_connected(dev)
1462
1463 addr0 = dev[0].own_addr()
1464 addr1 = dev[1].own_addr()
1465 pmksa0 = dev[0].get_pmksa(addr1)
1466 pmksa1 = dev[1].get_pmksa(addr0)
1467 if pmksa0 is None or pmksa1 is None:
1468 raise Exception("No PMKSA cache entry created")
1469 if pmksa0['pmkid'] != pmksa1['pmkid']:
1470 raise Exception("PMKID mismatch in PMKSA cache entries")
1471
1472 if "OK" not in dev[0].request("MESH_PEER_REMOVE " + addr1):
1473 raise Exception("Failed to remove peer")
1474 pmksa0b = dev[0].get_pmksa(addr1)
1475 if pmksa0b is None:
1476 raise Exception("PMKSA cache entry not maintained")
1477 time.sleep(0.1)
1478
1479 if "FAIL" not in dev[0].request("MESH_PEER_ADD " + addr1):
1480 raise Exception("MESH_PEER_ADD unexpectedly succeeded in no_auto_peer=0 case")
1481
1482 def test_wpas_mesh_pmksa_caching2(dev, apdev):
1483 """Secure mesh network and PMKSA caching with no_auto_peer=1"""
1484 check_mesh_support(dev[0], secure=True)
1485 addr0 = dev[0].own_addr()
1486 addr1 = dev[1].own_addr()
1487 dev[0].request("SET sae_groups ")
1488 id = add_mesh_secure_net(dev[0])
1489 dev[0].set_network(id, "no_auto_peer", "1")
1490 dev[0].mesh_group_add(id)
1491
1492 dev[1].request("SET sae_groups ")
1493 id = add_mesh_secure_net(dev[1])
1494 dev[1].set_network(id, "no_auto_peer", "1")
1495 dev[1].mesh_group_add(id)
1496
1497 check_mesh_joined2(dev)
1498
1499 # Check for peer connected
1500 ev = dev[0].wait_event(["will not initiate new peer link"], timeout=10)
1501 if ev is None:
1502 raise Exception("Missing no-initiate message")
1503 if "OK" not in dev[0].request("MESH_PEER_ADD " + addr1):
1504 raise Exception("MESH_PEER_ADD failed")
1505 check_mesh_connected2(dev)
1506
1507 pmksa0 = dev[0].get_pmksa(addr1)
1508 pmksa1 = dev[1].get_pmksa(addr0)
1509 if pmksa0 is None or pmksa1 is None:
1510 raise Exception("No PMKSA cache entry created")
1511 if pmksa0['pmkid'] != pmksa1['pmkid']:
1512 raise Exception("PMKID mismatch in PMKSA cache entries")
1513
1514 if "OK" not in dev[0].request("MESH_PEER_REMOVE " + addr1):
1515 raise Exception("Failed to remove peer")
1516 pmksa0b = dev[0].get_pmksa(addr1)
1517 if pmksa0b is None:
1518 raise Exception("PMKSA cache entry not maintained")
1519
1520 ev = dev[0].wait_event(["will not initiate new peer link"], timeout=10)
1521 if ev is None:
1522 raise Exception("Missing no-initiate message (2)")
1523 if "OK" not in dev[0].request("MESH_PEER_ADD " + addr1):
1524 raise Exception("MESH_PEER_ADD failed (2)")
1525 check_mesh_connected2(dev)
1526
1527 pmksa0c = dev[0].get_pmksa(addr1)
1528 pmksa1c = dev[1].get_pmksa(addr0)
1529 if pmksa0c is None or pmksa1c is None:
1530 raise Exception("No PMKSA cache entry created (2)")
1531 if pmksa0c['pmkid'] != pmksa1c['pmkid']:
1532 raise Exception("PMKID mismatch in PMKSA cache entries")
1533 if pmksa0['pmkid'] != pmksa0c['pmkid']:
1534 raise Exception("PMKID changed")
1535
1536 hwsim_utils.test_connectivity(dev[0], dev[1])
1537
1538 def test_wpas_mesh_pmksa_caching_no_match(dev, apdev):
1539 """Secure mesh network and PMKSA caching with no PMKID match"""
1540 check_mesh_support(dev[0], secure=True)
1541 addr0 = dev[0].own_addr()
1542 addr1 = dev[1].own_addr()
1543 dev[0].request("SET sae_groups ")
1544 id = add_mesh_secure_net(dev[0])
1545 dev[0].set_network(id, "no_auto_peer", "1")
1546 dev[0].mesh_group_add(id)
1547
1548 dev[1].request("SET sae_groups ")
1549 id = add_mesh_secure_net(dev[1])
1550 dev[1].set_network(id, "no_auto_peer", "1")
1551 dev[1].mesh_group_add(id)
1552
1553 check_mesh_joined2(dev)
1554
1555 # Check for peer connected
1556 ev = dev[0].wait_event(["will not initiate new peer link"], timeout=10)
1557 if ev is None:
1558 raise Exception("Missing no-initiate message")
1559 if "OK" not in dev[0].request("MESH_PEER_ADD " + addr1):
1560 raise Exception("MESH_PEER_ADD failed")
1561 check_mesh_connected2(dev)
1562
1563 pmksa0 = dev[0].get_pmksa(addr1)
1564 pmksa1 = dev[1].get_pmksa(addr0)
1565 if pmksa0 is None or pmksa1 is None:
1566 raise Exception("No PMKSA cache entry created")
1567 if pmksa0['pmkid'] != pmksa1['pmkid']:
1568 raise Exception("PMKID mismatch in PMKSA cache entries")
1569
1570 if "OK" not in dev[0].request("MESH_PEER_REMOVE " + addr1):
1571 raise Exception("Failed to remove peer")
1572
1573 if "OK" not in dev[1].request("PMKSA_FLUSH"):
1574 raise Exception("Failed to flush PMKSA cache")
1575
1576 ev = dev[0].wait_event(["will not initiate new peer link"], timeout=10)
1577 if ev is None:
1578 raise Exception("Missing no-initiate message (2)")
1579 if "OK" not in dev[0].request("MESH_PEER_ADD " + addr1):
1580 raise Exception("MESH_PEER_ADD failed (2)")
1581 check_mesh_connected2(dev)
1582
1583 pmksa0c = dev[0].get_pmksa(addr1)
1584 pmksa1c = dev[1].get_pmksa(addr0)
1585 if pmksa0c is None or pmksa1c is None:
1586 raise Exception("No PMKSA cache entry created (2)")
1587 if pmksa0c['pmkid'] != pmksa1c['pmkid']:
1588 raise Exception("PMKID mismatch in PMKSA cache entries")
1589 if pmksa0['pmkid'] == pmksa0c['pmkid']:
1590 raise Exception("PMKID did not change")
1591
1592 hwsim_utils.test_connectivity(dev[0], dev[1])
1593
1594 def test_mesh_pmksa_caching_oom(dev, apdev):
1595 """Secure mesh network and PMKSA caching failing due to OOM"""
1596 check_mesh_support(dev[0], secure=True)
1597 addr0 = dev[0].own_addr()
1598 addr1 = dev[1].own_addr()
1599 dev[0].request("SET sae_groups ")
1600 id = add_mesh_secure_net(dev[0])
1601 dev[0].set_network(id, "no_auto_peer", "1")
1602 dev[0].mesh_group_add(id)
1603
1604 dev[1].request("SET sae_groups ")
1605 id = add_mesh_secure_net(dev[1])
1606 dev[1].set_network(id, "no_auto_peer", "1")
1607 dev[1].mesh_group_add(id)
1608
1609 check_mesh_joined2(dev)
1610
1611 # Check for peer connected
1612 ev = dev[0].wait_event(["will not initiate new peer link"], timeout=10)
1613 if ev is None:
1614 raise Exception("Missing no-initiate message")
1615 if "OK" not in dev[0].request("MESH_PEER_ADD " + addr1):
1616 raise Exception("MESH_PEER_ADD failed")
1617 check_mesh_connected2(dev)
1618
1619 if "OK" not in dev[0].request("MESH_PEER_REMOVE " + addr1):
1620 raise Exception("Failed to remove peer")
1621 pmksa0b = dev[0].get_pmksa(addr1)
1622 if pmksa0b is None:
1623 raise Exception("PMKSA cache entry not maintained")
1624
1625 ev = dev[0].wait_event(["will not initiate new peer link"], timeout=10)
1626 if ev is None:
1627 raise Exception("Missing no-initiate message (2)")
1628
1629 with alloc_fail(dev[0], 1, "wpa_auth_sta_init;mesh_rsn_auth_sae_sta"):
1630 if "OK" not in dev[0].request("MESH_PEER_ADD " + addr1):
1631 raise Exception("MESH_PEER_ADD failed (2)")
1632 wait_fail_trigger(dev[0], "GET_ALLOC_FAIL")
1633
1634 def test_wpas_mesh_pmksa_caching_ext(dev, apdev):
1635 """Secure mesh network and PMKSA caching and external storage"""
1636 check_mesh_support(dev[0], secure=True)
1637 dev[0].request("SET sae_groups ")
1638 id = add_mesh_secure_net(dev[0])
1639 dev[0].mesh_group_add(id)
1640
1641 dev[1].request("SET sae_groups ")
1642 id = add_mesh_secure_net(dev[1])
1643 dev[1].mesh_group_add(id)
1644
1645 check_mesh_joined_connected(dev)
1646 dev[0].dump_monitor()
1647 dev[1].dump_monitor()
1648
1649 addr0 = dev[0].own_addr()
1650 addr1 = dev[1].own_addr()
1651 pmksa0 = dev[0].get_pmksa(addr1)
1652 pmksa1 = dev[1].get_pmksa(addr0)
1653 if pmksa0 is None or pmksa1 is None:
1654 raise Exception("No PMKSA cache entry created")
1655 if pmksa0['pmkid'] != pmksa1['pmkid']:
1656 raise Exception("PMKID mismatch in PMKSA cache entries")
1657
1658 res1 = dev[1].request("MESH_PMKSA_GET any")
1659 res2 = dev[1].request("MESH_PMKSA_GET " + addr0)
1660 logger.info("MESH_PMKSA_GET: " + res1)
1661 if "UNKNOWN COMMAND" in res1:
1662 raise HwsimSkip("MESH_PMKSA_GET not supported in the build")
1663 logger.info("MESH_PMKSA_GET: " + res2)
1664 if pmksa0['pmkid'] not in res1:
1665 raise Exception("PMKID not included in PMKSA entry")
1666 if res1 != res2:
1667 raise Exception("Unexpected difference in MESH_PMKSA_GET output")
1668
1669 dev[1].mesh_group_remove()
1670 check_mesh_group_removed(dev[1])
1671 dev[0].dump_monitor()
1672 dev[1].dump_monitor()
1673 res = dev[1].get_pmksa(addr0)
1674 if res is not None:
1675 raise Exception("Unexpected PMKSA cache entry remaining")
1676
1677 if "OK" not in dev[1].request("MESH_PMKSA_ADD " + res2):
1678 raise Exception("MESH_PMKSA_ADD failed")
1679 dev[1].mesh_group_add(id)
1680 check_mesh_group_added(dev[1])
1681 check_mesh_peer_connected(dev[1])
1682 dev[0].dump_monitor()
1683 dev[1].dump_monitor()
1684 pmksa1b = dev[1].get_pmksa(addr0)
1685 if pmksa1b is None:
1686 raise Exception("No PMKSA cache entry created after external storage restore")
1687 if pmksa1['pmkid'] != pmksa1b['pmkid']:
1688 raise Exception("PMKID mismatch in PMKSA cache entries after external storage restore")
1689
1690 hwsim_utils.test_connectivity(dev[0], dev[1])
1691
1692 res = dev[1].request("MESH_PMKSA_GET foo")
1693 if "FAIL" not in res:
1694 raise Exception("Invalid MESH_PMKSA_GET accepted")
1695
1696 dev[1].mesh_group_remove()
1697 check_mesh_group_removed(dev[1])
1698 dev[0].dump_monitor()
1699 dev[1].dump_monitor()
1700 dev[1].request("REMOVE_NETWORK all")
1701 res = dev[1].request("MESH_PMKSA_GET any")
1702 if "FAIL" not in res:
1703 raise Exception("MESH_PMKSA_GET accepted when not in mesh")
1704
1705 tests = ["foo",
1706 "02:02:02:02:02:02",
1707 "02:02:02:02:02:02 q",
1708 "02:02:02:02:02:02 c3d51a7ccfca0c6d5287291a7169d79b",
1709 "02:02:02:02:02:02 c3d51a7ccfca0c6d5287291a7169d79b q",
1710 "02:02:02:02:02:02 c3d51a7ccfca0c6d5287291a7169d79b 1bed4fa22ece7997ca1bdc8b829019fe63acac91cba3405522c24c91f7cfb49f",
1711 "02:02:02:02:02:02 c3d51a7ccfca0c6d5287291a7169d79b 1bed4fa22ece7997ca1bdc8b829019fe63acac91cba3405522c24c91f7cfb49f q"]
1712 for t in tests:
1713 if "FAIL" not in dev[1].request("MESH_PMKSA_ADD " + t):
1714 raise Exception("Invalid MESH_PMKSA_ADD accepted")
1715
1716 def test_mesh_oom(dev, apdev):
1717 """Mesh network setup failing due to OOM"""
1718 check_mesh_support(dev[0], secure=True)
1719 dev[0].request("SET sae_groups ")
1720
1721 with alloc_fail(dev[0], 1, "mesh_config_create"):
1722 add_open_mesh_network(dev[0])
1723 ev = dev[0].wait_event(["Failed to init mesh"])
1724 if ev is None:
1725 raise Exception("Init failure not reported")
1726
1727 with alloc_fail(dev[0], 2, "=wpa_supplicant_mesh_init"):
1728 add_open_mesh_network(dev[0], basic_rates="60 120 240")
1729 ev = dev[0].wait_event(["Failed to init mesh"])
1730 if ev is None:
1731 raise Exception("Init failure not reported")
1732
1733 for i in range(1, 66):
1734 dev[0].dump_monitor()
1735 logger.info("Test instance %d" % i)
1736 try:
1737 with alloc_fail(dev[0], i, "wpa_supplicant_mesh_init"):
1738 add_open_mesh_network(dev[0])
1739 wait_fail_trigger(dev[0], "GET_ALLOC_FAIL")
1740 ev = dev[0].wait_event(["Failed to init mesh",
1741 "MESH-GROUP-STARTED"])
1742 if ev is None:
1743 raise Exception("Init failure not reported")
1744 except Exception as e:
1745 if i < 15:
1746 raise
1747 logger.info("Ignore no-oom for i=%d" % i)
1748
1749 with alloc_fail(dev[0], 2, "=wpa_supplicant_mesh_init"):
1750 id = add_mesh_secure_net(dev[0])
1751 dev[0].mesh_group_add(id)
1752 ev = dev[0].wait_event(["Failed to init mesh"])
1753 if ev is None:
1754 raise Exception("Init failure not reported")
1755
1756 def test_mesh_add_interface_oom(dev):
1757 """wpa_supplicant mesh with dynamic interface addition failing"""
1758 check_mesh_support(dev[0])
1759 for i in range(1, 3):
1760 mesh = None
1761 try:
1762 with alloc_fail(dev[0], i, "wpas_mesh_add_interface"):
1763 mesh = dev[0].request("MESH_INTERFACE_ADD").strip()
1764 finally:
1765 if mesh and mesh != "FAIL":
1766 dev[0].request("MESH_GROUP_REMOVE " + mesh)
1767
1768 def test_mesh_scan_oom(dev):
1769 """wpa_supplicant mesh scan results and OOM"""
1770 check_mesh_support(dev[0])
1771 add_open_mesh_network(dev[0])
1772 check_mesh_group_added(dev[0])
1773 for i in range(5):
1774 dev[1].scan(freq="2412")
1775 res = dev[1].request("SCAN_RESULTS")
1776 if "[MESH]" in res:
1777 break
1778 for r in res.splitlines():
1779 if "[MESH]" in r:
1780 break
1781 bssid = r.split('\t')[0]
1782
1783 bss = dev[1].get_bss(bssid)
1784 if bss is None:
1785 raise Exception("Could not get BSS entry for mesh")
1786
1787 for i in range(1, 3):
1788 with alloc_fail(dev[1], i, "mesh_attr_text"):
1789 bss = dev[1].get_bss(bssid)
1790 if bss and "mesh_id" in bss:
1791 raise Exception("Unexpected BSS result during OOM")
1792
1793 def test_mesh_drv_fail(dev, apdev):
1794 """Mesh network setup failing due to driver command failure"""
1795 check_mesh_support(dev[0], secure=True)
1796 dev[0].request("SET sae_groups ")
1797
1798 with fail_test(dev[0], 1, "nl80211_join_mesh"):
1799 add_open_mesh_network(dev[0])
1800 ev = dev[0].wait_event(["mesh join error"])
1801 if ev is None:
1802 raise Exception("Join failure not reported")
1803
1804 dev[0].dump_monitor()
1805 with fail_test(dev[0], 1, "wpa_driver_nl80211_if_add"):
1806 if "FAIL" not in dev[0].request("MESH_INTERFACE_ADD").strip():
1807 raise Exception("Interface added unexpectedly")
1808
1809 dev[0].dump_monitor()
1810 with fail_test(dev[0], 1, "wpa_driver_nl80211_init_mesh"):
1811 add_open_mesh_network(dev[0])
1812 ev = dev[0].wait_event(["Could not join mesh"])
1813 if ev is None:
1814 raise Exception("Join failure not reported")
1815
1816 def test_mesh_sae_groups_invalid(dev, apdev):
1817 """Mesh with invalid SAE group configuration"""
1818 check_mesh_support(dev[0], secure=True)
1819
1820 dev[0].request("SET sae_groups 26")
1821 id = add_mesh_secure_net(dev[0])
1822 dev[0].mesh_group_add(id)
1823
1824 dev[1].request("SET sae_groups 123 122 121")
1825 id = add_mesh_secure_net(dev[1])
1826 dev[1].mesh_group_add(id)
1827
1828 check_mesh_joined2(dev)
1829
1830 ev = dev[0].wait_event(["new peer notification"], timeout=10)
1831 if ev is None:
1832 raise Exception("dev[0] did not see peer")
1833 ev = dev[1].wait_event(["new peer notification"], timeout=10)
1834 if ev is None:
1835 raise Exception("dev[1] did not see peer")
1836
1837 ev = dev[0].wait_event(["MESH-PEER-CONNECTED"], timeout=0.1)
1838 if ev is not None:
1839 raise Exception("Unexpected connection(0)")
1840
1841 ev = dev[1].wait_event(["MESH-PEER-CONNECTED"], timeout=0.01)
1842 if ev is not None:
1843 raise Exception("Unexpected connection(1)")
1844
1845 # Additional coverage in mesh_rsn_sae_group() with non-zero
1846 # wpa_s->mesh_rsn->sae_group_index.
1847 dev[0].dump_monitor()
1848 dev[1].dump_monitor()
1849 dev[2].request("SET sae_groups ")
1850 id = add_mesh_secure_net(dev[2])
1851 dev[2].mesh_group_add(id)
1852 check_mesh_group_added(dev[2])
1853 check_mesh_peer_connected(dev[0])
1854 check_mesh_peer_connected(dev[2])
1855 ev = dev[1].wait_event(["new peer notification"], timeout=10)
1856 if ev is None:
1857 raise Exception("dev[1] did not see peer(2)")
1858 dev[0].dump_monitor()
1859 dev[1].dump_monitor()
1860 dev[2].dump_monitor()
1861
1862 dev[0].request("SET sae_groups ")
1863 dev[1].request("SET sae_groups ")
1864 dev[2].request("SET sae_groups ")
1865
1866 def test_mesh_sae_failure(dev, apdev):
1867 """Mesh and local SAE failures"""
1868 check_mesh_support(dev[0], secure=True)
1869
1870 dev[0].request("SET sae_groups ")
1871 dev[1].request("SET sae_groups ")
1872
1873 funcs = [(1, "=mesh_rsn_auth_sae_sta", True),
1874 (1, "mesh_rsn_build_sae_commit;mesh_rsn_auth_sae_sta", False),
1875 (1, "auth_sae_init_committed;mesh_rsn_auth_sae_sta", True),
1876 (1, "=mesh_rsn_protect_frame", True),
1877 (2, "=mesh_rsn_protect_frame", True),
1878 (1, "aes_siv_encrypt;mesh_rsn_protect_frame", True),
1879 (1, "=mesh_rsn_process_ampe", True),
1880 (1, "aes_siv_decrypt;mesh_rsn_process_ampe", True)]
1881 for count, func, success in funcs:
1882 id = add_mesh_secure_net(dev[0])
1883 dev[0].mesh_group_add(id)
1884
1885 with alloc_fail(dev[1], count, func):
1886 id = add_mesh_secure_net(dev[1])
1887 dev[1].mesh_group_add(id)
1888 check_mesh_joined2(dev)
1889 if success:
1890 # retry is expected to work
1891 check_mesh_connected2(dev)
1892 else:
1893 wait_fail_trigger(dev[1], "GET_ALLOC_FAIL")
1894 dev[0].mesh_group_remove()
1895 dev[1].mesh_group_remove()
1896 check_mesh_group_removed(dev[0])
1897 check_mesh_group_removed(dev[1])
1898
1899 def test_mesh_failure(dev, apdev):
1900 """Mesh and local failures"""
1901 check_mesh_support(dev[0])
1902
1903 funcs = [(1, "ap_sta_add;mesh_mpm_add_peer", True),
1904 (1, "wpabuf_alloc;mesh_mpm_send_plink_action", True)]
1905 for count, func, success in funcs:
1906 add_open_mesh_network(dev[0])
1907
1908 with alloc_fail(dev[1], count, func):
1909 add_open_mesh_network(dev[1])
1910 check_mesh_joined2(dev)
1911 if success:
1912 # retry is expected to work
1913 check_mesh_connected2(dev)
1914 else:
1915 wait_fail_trigger(dev[1], "GET_ALLOC_FAIL")
1916 dev[0].mesh_group_remove()
1917 dev[1].mesh_group_remove()
1918 check_mesh_group_removed(dev[0])
1919 check_mesh_group_removed(dev[1])
1920
1921 funcs = [(1, "mesh_mpm_init_link", True)]
1922 for count, func, success in funcs:
1923 add_open_mesh_network(dev[0])
1924
1925 with fail_test(dev[1], count, func):
1926 add_open_mesh_network(dev[1])
1927 check_mesh_joined2(dev)
1928 if success:
1929 # retry is expected to work
1930 check_mesh_connected2(dev)
1931 else:
1932 wait_fail_trigger(dev[1], "GET_FAIL")
1933 dev[0].mesh_group_remove()
1934 dev[1].mesh_group_remove()
1935 check_mesh_group_removed(dev[0])
1936 check_mesh_group_removed(dev[1])
1937
1938 def test_mesh_invalid_frequency(dev, apdev):
1939 """Mesh and invalid frequency configuration"""
1940 check_mesh_support(dev[0])
1941 add_open_mesh_network(dev[0], freq=None)
1942 ev = dev[0].wait_event(["MESH-GROUP-STARTED",
1943 "Could not join mesh"])
1944 if ev is None or "Could not join mesh" not in ev:
1945 raise Exception("Mesh join failure not reported")
1946 dev[0].request("REMOVE_NETWORK all")
1947
1948 add_open_mesh_network(dev[0], freq="2413")
1949 ev = dev[0].wait_event(["MESH-GROUP-STARTED",
1950 "Could not join mesh"])
1951 if ev is None or "Could not join mesh" not in ev:
1952 raise Exception("Mesh join failure not reported")
1953
1954 def test_mesh_default_beacon_int(dev, apdev):
1955 """Mesh and default beacon interval"""
1956 check_mesh_support(dev[0])
1957 try:
1958 dev[0].request("SET beacon_int 200")
1959 add_open_mesh_network(dev[0])
1960 check_mesh_group_added(dev[0])
1961 finally:
1962 dev[0].request("SET beacon_int 0")
1963
1964 def test_mesh_scan_parse_error(dev, apdev):
1965 """Mesh scan element parse error"""
1966 check_mesh_support(dev[0])
1967 params = {"ssid": "open",
1968 "beacon_int": "2000"}
1969 hapd = hostapd.add_ap(apdev[0], params)
1970 bssid = apdev[0]['bssid']
1971 hapd.set('vendor_elements', 'dd0201')
1972 for i in range(10):
1973 dev[0].scan(freq=2412)
1974 if bssid in dev[0].request("SCAN_RESULTS"):
1975 break
1976 # This will fail in IE parsing due to the truncated IE in the Probe
1977 # Response frame.
1978 bss = dev[0].request("BSS " + bssid)
1979
1980 def test_mesh_missing_mic(dev, apdev):
1981 """Secure mesh network and missing MIC"""
1982 check_mesh_support(dev[0], secure=True)
1983
1984 dev[0].request("SET ext_mgmt_frame_handling 1")
1985 dev[0].request("SET sae_groups ")
1986 id = add_mesh_secure_net(dev[0])
1987 dev[0].mesh_group_add(id)
1988
1989 dev[1].request("SET sae_groups ")
1990 id = add_mesh_secure_net(dev[1])
1991 dev[1].mesh_group_add(id)
1992
1993 check_mesh_joined2(dev)
1994
1995 count = 0
1996 remove_mic = True
1997 while True:
1998 count += 1
1999 if count > 15:
2000 raise Exception("Did not see Action frames")
2001 rx_msg = dev[0].mgmt_rx()
2002 if rx_msg is None:
2003 ev = dev[1].wait_event(["MESH-PEER-CONNECTED"], timeout=0.01)
2004 if ev:
2005 break
2006 raise Exception("MGMT-RX timeout")
2007 if rx_msg['subtype'] == 13:
2008 payload = rx_msg['payload']
2009 frame = rx_msg['frame']
2010 (categ, action) = struct.unpack('BB', payload[0:2])
2011 if categ == 15 and action == 1 and remove_mic:
2012 # Mesh Peering Open
2013 pos = frame.find(b'\x8c\x10')
2014 if not pos:
2015 raise Exception("Could not find MIC element")
2016 logger.info("Found MIC at %d" % pos)
2017 # Remove MIC
2018 rx_msg['frame'] = frame[0:pos]
2019 remove_mic = False
2020 if "OK" not in dev[0].request("MGMT_RX_PROCESS freq={} datarate={} ssi_signal={} frame={}".format(
2021 rx_msg['freq'], rx_msg['datarate'], rx_msg['ssi_signal'], binascii.hexlify(rx_msg['frame']).decode())):
2022 raise Exception("MGMT_RX_PROCESS failed")
2023 ev = dev[1].wait_event(["MESH-PEER-CONNECTED"], timeout=0.01)
2024 if ev:
2025 break
2026
2027 def test_mesh_pmkid_mismatch(dev, apdev):
2028 """Secure mesh network and PMKID mismatch"""
2029 check_mesh_support(dev[0], secure=True)
2030 addr0 = dev[0].own_addr()
2031 addr1 = dev[1].own_addr()
2032 dev[0].request("SET sae_groups ")
2033 id = add_mesh_secure_net(dev[0])
2034 dev[0].set_network(id, "no_auto_peer", "1")
2035 dev[0].mesh_group_add(id)
2036
2037 dev[1].request("SET sae_groups ")
2038 id = add_mesh_secure_net(dev[1])
2039 dev[1].set_network(id, "no_auto_peer", "1")
2040 dev[1].mesh_group_add(id)
2041
2042 check_mesh_joined2(dev)
2043
2044 # Check for peer connected
2045 ev = dev[0].wait_event(["will not initiate new peer link"], timeout=10)
2046 if ev is None:
2047 raise Exception("Missing no-initiate message")
2048 if "OK" not in dev[0].request("MESH_PEER_ADD " + addr1):
2049 raise Exception("MESH_PEER_ADD failed")
2050 check_mesh_connected2(dev)
2051
2052 if "OK" not in dev[0].request("MESH_PEER_REMOVE " + addr1):
2053 raise Exception("Failed to remove peer")
2054
2055 ev = dev[0].wait_event(["will not initiate new peer link"], timeout=10)
2056 if ev is None:
2057 raise Exception("Missing no-initiate message (2)")
2058 dev[0].dump_monitor()
2059 dev[1].dump_monitor()
2060 dev[0].request("SET ext_mgmt_frame_handling 1")
2061 if "OK" not in dev[0].request("MESH_PEER_ADD " + addr1):
2062 raise Exception("MESH_PEER_ADD failed (2)")
2063
2064 count = 0
2065 break_pmkid = True
2066 while True:
2067 count += 1
2068 if count > 50:
2069 raise Exception("Did not see Action frames")
2070 rx_msg = dev[0].mgmt_rx()
2071 if rx_msg is None:
2072 ev = dev[1].wait_event(["MESH-PEER-CONNECTED"], timeout=0.1)
2073 if ev:
2074 break
2075 raise Exception("MGMT-RX timeout")
2076 if rx_msg['subtype'] == 13:
2077 payload = rx_msg['payload']
2078 frame = rx_msg['frame']
2079 (categ, action) = struct.unpack('BB', payload[0:2])
2080 if categ == 15 and action == 1 and break_pmkid:
2081 # Mesh Peering Open
2082 pos = frame.find(b'\x75\x14')
2083 if not pos:
2084 raise Exception("Could not find Mesh Peering Management element")
2085 logger.info("Found Mesh Peering Management element at %d" % pos)
2086 # Break PMKID to hit "Mesh RSN: Invalid PMKID (Chosen PMK did
2087 # not match calculated PMKID)"
2088 rx_msg['frame'] = frame[0:pos + 6] + b'\x00\x00\x00\x00' + frame[pos + 10:]
2089 break_pmkid = False
2090 if "OK" not in dev[0].request("MGMT_RX_PROCESS freq={} datarate={} ssi_signal={} frame={}".format(
2091 rx_msg['freq'], rx_msg['datarate'], rx_msg['ssi_signal'], binascii.hexlify(rx_msg['frame']).decode())):
2092 raise Exception("MGMT_RX_PROCESS failed")
2093 ev = dev[1].wait_event(["MESH-PEER-CONNECTED"], timeout=0.01)
2094 if ev:
2095 break
2096
2097 def test_mesh_peering_proto(dev, apdev):
2098 """Mesh peering management protocol testing"""
2099 check_mesh_support(dev[0])
2100
2101 dev[0].request("SET ext_mgmt_frame_handling 1")
2102 add_open_mesh_network(dev[0], beacon_int=160)
2103 add_open_mesh_network(dev[1], beacon_int=160)
2104
2105 count = 0
2106 test = 1
2107 while True:
2108 count += 1
2109 if count > 50:
2110 raise Exception("Did not see Action frames")
2111 rx_msg = dev[0].mgmt_rx()
2112 if rx_msg is None:
2113 ev = dev[1].wait_event(["MESH-PEER-CONNECTED"], timeout=0.01)
2114 if ev:
2115 break
2116 raise Exception("MGMT-RX timeout")
2117 if rx_msg['subtype'] == 13:
2118 payload = rx_msg['payload']
2119 frame = rx_msg['frame']
2120 (categ, action) = struct.unpack('BB', payload[0:2])
2121 if categ == 15 and action == 1 and test == 1:
2122 # Mesh Peering Open
2123 pos = frame.find(b'\x75\x04')
2124 if not pos:
2125 raise Exception("Could not find Mesh Peering Management element")
2126 logger.info("Found Mesh Peering Management element at %d" % pos)
2127 # Remove the element to hit
2128 # "MPM: No Mesh Peering Management element"
2129 rx_msg['frame'] = frame[0:pos]
2130 test += 1
2131 elif categ == 15 and action == 1 and test == 2:
2132 # Mesh Peering Open
2133 pos = frame.find(b'\x72\x0e')
2134 if not pos:
2135 raise Exception("Could not find Mesh ID element")
2136 logger.info("Found Mesh ID element at %d" % pos)
2137 # Remove the element to hit
2138 # "MPM: No Mesh ID or Mesh Configuration element"
2139 rx_msg['frame'] = frame[0:pos] + frame[pos + 16:]
2140 test += 1
2141 elif categ == 15 and action == 1 and test == 3:
2142 # Mesh Peering Open
2143 pos = frame.find(b'\x72\x0e')
2144 if not pos:
2145 raise Exception("Could not find Mesh ID element")
2146 logger.info("Found Mesh ID element at %d" % pos)
2147 # Replace Mesh ID to hit "MPM: Mesh ID or Mesh Configuration
2148 # element do not match local MBSS"
2149 rx_msg['frame'] = frame[0:pos] + b'\x72\x0etest-test-test' + frame[pos + 16:]
2150 test += 1
2151 elif categ == 15 and action == 1 and test == 4:
2152 # Mesh Peering Open
2153 # Remove IEs to hit
2154 # "MPM: Ignore too short action frame 1 ie_len 0"
2155 rx_msg['frame'] = frame[0:26]
2156 test += 1
2157 elif categ == 15 and action == 1 and test == 5:
2158 # Mesh Peering Open
2159 # Truncate IEs to hit
2160 # "MPM: Failed to parse PLINK IEs"
2161 rx_msg['frame'] = frame[0:30]
2162 test += 1
2163 elif categ == 15 and action == 1 and test == 6:
2164 # Mesh Peering Open
2165 pos = frame.find(b'\x75\x04')
2166 if not pos:
2167 raise Exception("Could not find Mesh Peering Management element")
2168 logger.info("Found Mesh Peering Management element at %d" % pos)
2169 # Truncate the element to hit
2170 # "MPM: Invalid peer mgmt ie" and
2171 # "MPM: Mesh parsing rejected frame"
2172 rx_msg['frame'] = frame[0:pos] + b'\x75\x00\x00\x00' + frame[pos + 6:]
2173 test += 1
2174 if "OK" not in dev[0].request("MGMT_RX_PROCESS freq={} datarate={} ssi_signal={} frame={}".format(
2175 rx_msg['freq'], rx_msg['datarate'], rx_msg['ssi_signal'], binascii.hexlify(rx_msg['frame']).decode())):
2176 raise Exception("MGMT_RX_PROCESS failed")
2177 ev = dev[1].wait_event(["MESH-PEER-CONNECTED"], timeout=0.01)
2178 if ev:
2179 break
2180
2181 if test != 7:
2182 raise Exception("Not all test frames completed")
2183
2184 def test_mesh_mpm_init_proto(dev, apdev):
2185 """Mesh peering management protocol testing for peer addition"""
2186 check_mesh_support(dev[0])
2187 add_open_mesh_network(dev[0])
2188 check_mesh_group_added(dev[0])
2189 dev[0].dump_monitor()
2190
2191 dev[0].request("SET ext_mgmt_frame_handling 1")
2192
2193 addr = "020000000100"
2194 hdr = "d000ac00020000000000" + addr + addr + "1000"
2195 fixed = "0f010000"
2196 supp_rates = "010802040b168c129824"
2197 ext_supp_rates = "3204b048606c"
2198 mesh_id = "720e777061732d6d6573682d6f70656e"
2199 mesh_conf = "710701010001000009"
2200 mpm = "75040000079d"
2201 ht_capab = "2d1a7c001bffff000000000000000000000100000000000000000000"
2202 ht_oper = "3d160b000000000000000000000000000000000000000000"
2203
2204 dev[0].request("NOTE no supported rates")
2205 frame = hdr + fixed + ext_supp_rates + mesh_id + mesh_conf + mpm + ht_capab + ht_oper
2206 if "OK" not in dev[0].request("MGMT_RX_PROCESS freq=2412 datarate=0 ssi_signal=-30 frame=%s" % frame):
2207 raise Exception("MGMT_RX_PROCESS failed")
2208
2209 dev[0].request("NOTE Invalid supported rates element length 33+0")
2210 long_supp_rates = "012100112233445566778899aabbccddeeff00112233445566778899aabbccddeeff00"
2211 frame = hdr + fixed + long_supp_rates + mesh_id + mesh_conf + mpm + ht_capab + ht_oper
2212 if "OK" not in dev[0].request("MGMT_RX_PROCESS freq=2412 datarate=0 ssi_signal=-30 frame=%s" % frame):
2213 raise Exception("MGMT_RX_PROCESS failed")
2214
2215 dev[0].request("NOTE Too short mesh config")
2216 short_mesh_conf = "710401010001"
2217 frame = hdr + fixed + supp_rates + mesh_id + short_mesh_conf + mpm + ht_capab + ht_oper
2218 if "OK" not in dev[0].request("MGMT_RX_PROCESS freq=2412 datarate=0 ssi_signal=-30 frame=%s" % frame):
2219 raise Exception("MGMT_RX_PROCESS failed")
2220
2221 dev[0].request("NOTE Add STA failure")
2222 frame = hdr + fixed + supp_rates + ext_supp_rates + mesh_id + mesh_conf + mpm + ht_capab + ht_oper
2223 with fail_test(dev[0], 1, "wpa_driver_nl80211_sta_add"):
2224 if "OK" not in dev[0].request("MGMT_RX_PROCESS freq=2412 datarate=0 ssi_signal=-30 frame=%s" % frame):
2225 raise Exception("MGMT_RX_PROCESS failed")
2226
2227 dev[0].request("NOTE Send Action failure")
2228 with fail_test(dev[0], 1, "driver_nl80211_send_action"):
2229 if "OK" not in dev[0].request("MGMT_RX_PROCESS freq=2412 datarate=0 ssi_signal=-30 frame=%s" % frame):
2230 raise Exception("MGMT_RX_PROCESS failed")
2231
2232 dev[0].request("NOTE Set STA failure")
2233 addr = "020000000101"
2234 hdr = "d000ac00020000000000" + addr + addr + "1000"
2235 frame = hdr + fixed + supp_rates + ext_supp_rates + mesh_id + mesh_conf + mpm + ht_capab + ht_oper
2236 with fail_test(dev[0], 2, "wpa_driver_nl80211_sta_add"):
2237 if "OK" not in dev[0].request("MGMT_RX_PROCESS freq=2412 datarate=0 ssi_signal=-30 frame=%s" % frame):
2238 raise Exception("MGMT_RX_PROCESS failed")
2239
2240 dev[0].request("NOTE ap_sta_add OOM")
2241 addr = "020000000102"
2242 hdr = "d000ac00020000000000" + addr + addr + "1000"
2243 frame = hdr + fixed + supp_rates + ext_supp_rates + mesh_id + mesh_conf + mpm + ht_capab + ht_oper
2244 with alloc_fail(dev[0], 1, "ap_sta_add"):
2245 if "OK" not in dev[0].request("MGMT_RX_PROCESS freq=2412 datarate=0 ssi_signal=-30 frame=%s" % frame):
2246 raise Exception("MGMT_RX_PROCESS failed")
2247
2248 dev[0].request("NOTE hostapd_get_aid() failure")
2249 addr = "020000000103"
2250 hdr = "d000ac00020000000000" + addr + addr + "1000"
2251 frame = hdr + fixed + supp_rates + ext_supp_rates + mesh_id + mesh_conf + mpm + ht_capab + ht_oper
2252 with fail_test(dev[0], 1, "hostapd_get_aid"):
2253 if "OK" not in dev[0].request("MGMT_RX_PROCESS freq=2412 datarate=0 ssi_signal=-30 frame=%s" % frame):
2254 raise Exception("MGMT_RX_PROCESS failed")
2255
2256 if "OK" not in dev[0].request("MESH_PEER_REMOVE 02:00:00:00:01:00"):
2257 raise Exception("Failed to remove peer")
2258 if "FAIL" not in dev[0].request("MESH_PEER_REMOVE 02:00:00:00:01:02"):
2259 raise Exception("Unexpected MESH_PEER_REMOVE success")
2260 if "FAIL" not in dev[1].request("MESH_PEER_REMOVE 02:00:00:00:01:02"):
2261 raise Exception("Unexpected MESH_PEER_REMOVE success(2)")
2262 if "FAIL" not in dev[1].request("MESH_PEER_ADD 02:00:00:00:01:02"):
2263 raise Exception("Unexpected MESH_PEER_ADD success")
2264
2265 def test_mesh_holding(dev, apdev):
2266 """Mesh MPM FSM and HOLDING state event OPN_ACPT"""
2267 check_mesh_support(dev[0])
2268 add_open_mesh_network(dev[0])
2269 add_open_mesh_network(dev[1])
2270 check_mesh_joined_connected(dev)
2271
2272 addr0 = dev[0].own_addr()
2273 addr1 = dev[1].own_addr()
2274
2275 dev[0].request("SET ext_mgmt_frame_handling 1")
2276 if "OK" not in dev[0].request("MESH_PEER_REMOVE " + addr1):
2277 raise Exception("Failed to remove peer")
2278
2279 rx_msg = dev[0].mgmt_rx()
2280 if rx_msg is None:
2281 raise Exception("MGMT-RX timeout")
2282 if rx_msg['subtype'] != 13:
2283 raise Exception("Unexpected management frame")
2284 payload = rx_msg['payload']
2285 (categ, action) = struct.unpack('BB', payload[0:2])
2286 if categ != 0x0f or action != 0x03:
2287 raise Exception("Did not see Mesh Peering Close")
2288
2289 peer_lid = binascii.hexlify(payload[-6:-4]).decode()
2290 my_lid = binascii.hexlify(payload[-4:-2]).decode()
2291
2292 # Drop Mesh Peering Close and instead, process an unexpected Mesh Peering
2293 # Open to trigger transmission of another Mesh Peering Close in the HOLDING
2294 # state based on an OPN_ACPT event.
2295
2296 dst = addr0.replace(':', '')
2297 src = addr1.replace(':', '')
2298 hdr = "d000ac00" + dst + src + src + "1000"
2299 fixed = "0f010000"
2300 supp_rates = "010802040b168c129824"
2301 ext_supp_rates = "3204b048606c"
2302 mesh_id = "720e777061732d6d6573682d6f70656e"
2303 mesh_conf = "710701010001000009"
2304 mpm = "7504" + my_lid + peer_lid
2305 ht_capab = "2d1a7c001bffff000000000000000000000100000000000000000000"
2306 ht_oper = "3d160b000000000000000000000000000000000000000000"
2307
2308 frame = hdr + fixed + supp_rates + ext_supp_rates + mesh_id + mesh_conf + mpm + ht_capab + ht_oper
2309 if "OK" not in dev[0].request("MGMT_RX_PROCESS freq=2412 datarate=0 ssi_signal=-30 frame=%s" % frame):
2310 raise Exception("MGMT_RX_PROCESS failed")
2311 time.sleep(0.1)
2312
2313 def test_mesh_cnf_rcvd_event_cls_acpt(dev, apdev):
2314 """Mesh peering management protocol testing - CLS_ACPT event in CNF_RCVD"""
2315 check_mesh_support(dev[0])
2316 add_open_mesh_network(dev[0])
2317 check_mesh_group_added(dev[0])
2318 dev[0].dump_monitor()
2319
2320 dev[0].request("SET ext_mgmt_frame_handling 1")
2321 add_open_mesh_network(dev[1])
2322 check_mesh_group_added(dev[1])
2323
2324 addr0 = dev[0].own_addr()
2325 addr1 = dev[1].own_addr()
2326
2327 rx_msg = dev[0].mgmt_rx()
2328 # Drop Mesh Peering Open
2329
2330 rx_msg = dev[0].mgmt_rx()
2331 # Allow Mesh Peering Confirm to go through
2332 if "OK" not in dev[0].request("MGMT_RX_PROCESS freq={} datarate={} ssi_signal={} frame={}".format(
2333 rx_msg['freq'], rx_msg['datarate'], rx_msg['ssi_signal'], binascii.hexlify(rx_msg['frame']).decode())):
2334 raise Exception("MGMT_RX_PROCESS failed")
2335
2336 payload = rx_msg['payload']
2337 peer_lid = binascii.hexlify(payload[51:53]).decode()
2338 my_lid = binascii.hexlify(payload[53:55]).decode()
2339
2340 dst = addr0.replace(':', '')
2341 src = addr1.replace(':', '')
2342 hdr = "d000ac00" + dst + src + src + "1000"
2343 fixed = "0f03"
2344 mesh_id = "720e777061732d6d6573682d6f70656e"
2345 mpm = "75080000" + peer_lid + my_lid + "3700"
2346 frame = hdr + fixed + mesh_id + mpm
2347
2348 # Inject Mesh Peering Close to hit "state CNF_RCVD event CLS_ACPT" to
2349 # HOLDING transition.
2350 if "OK" not in dev[0].request("MGMT_RX_PROCESS freq=2412 datarate=0 ssi_signal=-30 frame=" + frame):
2351 raise Exception("MGMT_RX_PROCESS failed")
2352
2353 def test_mesh_opn_snt_event_cls_acpt(dev, apdev):
2354 """Mesh peering management protocol testing - CLS_ACPT event in OPN_SNT"""
2355 check_mesh_support(dev[0])
2356 add_open_mesh_network(dev[0])
2357 check_mesh_group_added(dev[0])
2358 dev[0].dump_monitor()
2359
2360 dev[0].request("SET ext_mgmt_frame_handling 1")
2361 add_open_mesh_network(dev[1])
2362 check_mesh_group_added(dev[1])
2363
2364 addr0 = dev[0].own_addr()
2365 addr1 = dev[1].own_addr()
2366
2367 rx_msg = dev[0].mgmt_rx()
2368 # Drop Mesh Peering Open
2369
2370 rx_msg = dev[0].mgmt_rx()
2371 # Drop Mesh Peering Confirm
2372
2373 payload = rx_msg['payload']
2374 peer_lid = "0000"
2375 my_lid = binascii.hexlify(payload[53:55]).decode()
2376
2377 dst = addr0.replace(':', '')
2378 src = addr1.replace(':', '')
2379 hdr = "d000ac00" + dst + src + src + "1000"
2380 fixed = "0f03"
2381 mesh_id = "720e777061732d6d6573682d6f70656e"
2382 mpm = "75080000" + peer_lid + my_lid + "3700"
2383 frame = hdr + fixed + mesh_id + mpm
2384
2385 # Inject Mesh Peering Close to hit "state OPN_SNTevent CLS_ACPT" to
2386 # HOLDING transition.
2387 if "OK" not in dev[0].request("MGMT_RX_PROCESS freq=2412 datarate=0 ssi_signal=-30 frame=" + frame):
2388 raise Exception("MGMT_RX_PROCESS failed")
2389
2390 def test_mesh_select_network(dev):
2391 """Mesh network and SELECT_NETWORK"""
2392 check_mesh_support(dev[0])
2393 id0 = add_open_mesh_network(dev[0], start=False)
2394 id1 = add_open_mesh_network(dev[1], start=False)
2395 dev[0].select_network(id0)
2396 dev[1].select_network(id1)
2397 check_mesh_joined_connected(dev, connectivity=True)
2398
2399 def test_mesh_forwarding(dev):
2400 """Mesh with two stations that can't reach each other directly"""
2401 try:
2402 set_group_map(dev[0], 1)
2403 set_group_map(dev[1], 3)
2404 set_group_map(dev[2], 2)
2405 check_mesh_support(dev[0])
2406 for i in range(3):
2407 add_open_mesh_network(dev[i])
2408 check_mesh_group_added(dev[i])
2409 for i in range(3):
2410 check_mesh_peer_connected(dev[i])
2411
2412 hwsim_utils.test_connectivity(dev[0], dev[1])
2413 hwsim_utils.test_connectivity(dev[1], dev[2])
2414 hwsim_utils.test_connectivity(dev[0], dev[2])
2415 finally:
2416 # reset groups
2417 set_group_map(dev[0], 1)
2418 set_group_map(dev[1], 1)
2419 set_group_map(dev[2], 1)
2420
2421 def test_mesh_forwarding_secure(dev):
2422 """Mesh with two stations that can't reach each other directly (RSN)"""
2423 check_mesh_support(dev[0], secure=True)
2424 try:
2425 set_group_map(dev[0], 1)
2426 set_group_map(dev[1], 3)
2427 set_group_map(dev[2], 2)
2428 for i in range(3):
2429 dev[i].request("SET sae_groups ")
2430 id = add_mesh_secure_net(dev[i])
2431 dev[i].mesh_group_add(id)
2432 check_mesh_group_added(dev[i])
2433 for i in range(3):
2434 check_mesh_peer_connected(dev[i])
2435
2436 hwsim_utils.test_connectivity(dev[0], dev[1])
2437 hwsim_utils.test_connectivity(dev[1], dev[2])
2438 hwsim_utils.test_connectivity(dev[0], dev[2])
2439 finally:
2440 # reset groups
2441 set_group_map(dev[0], 1)
2442 set_group_map(dev[1], 1)
2443 set_group_map(dev[2], 1)
2444
2445 def test_mesh_sae_anti_clogging(dev, apdev):
2446 """Mesh using SAE and anti-clogging"""
2447 try:
2448 run_mesh_sae_anti_clogging(dev, apdev)
2449 finally:
2450 stop_monitor(apdev[1]["ifname"])
2451
2452 def run_mesh_sae_anti_clogging(dev, apdev):
2453 check_mesh_support(dev[0], secure=True)
2454 check_mesh_support(dev[1], secure=True)
2455 check_mesh_support(dev[2], secure=True)
2456
2457 sock = start_monitor(apdev[1]["ifname"])
2458 radiotap = radiotap_build()
2459
2460 dev[0].request("SET sae_groups 21")
2461 id = add_mesh_secure_net(dev[0])
2462 dev[0].mesh_group_add(id)
2463 check_mesh_group_added(dev[0])
2464
2465 # This flood of SAE authentication frames is from not yet known mesh STAs,
2466 # so the messages get dropped.
2467 addr0 = binascii.unhexlify(dev[0].own_addr().replace(':', ''))
2468 for i in range(16):
2469 addr = binascii.unhexlify("f2%010x" % i)
2470 frame = build_sae_commit(addr0, addr)
2471 sock.send(radiotap + frame)
2472
2473 dev[1].request("SET sae_groups 21")
2474 id = add_mesh_secure_net(dev[1])
2475 dev[1].mesh_group_add(id)
2476 check_mesh_group_added(dev[1])
2477 check_mesh_connected2(dev)
2478
2479 # Inject Beacon frames to make the sources of the second flood known to the
2480 # target.
2481 bcn1 = binascii.unhexlify("80000000" + "ffffffffffff")
2482 bcn2 = binascii.unhexlify("0000dd20c44015840500e80310000000010882848b968c1298240301010504000200003204b048606c30140100000fac040100000fac040100000fac0800002d1afe131bffff0000000000000000000001000000000000000000003d16010000000000ffff0000000000000000000000000000720d777061732d6d6573682d736563710701010001010009")
2483 for i in range(16):
2484 addr = binascii.unhexlify("f4%010x" % i)
2485 frame = bcn1 + addr + addr + bcn2
2486 sock.send(radiotap + frame)
2487
2488 # This flood of SAE authentication frames is from known mesh STAs, so the
2489 # target will need to process these.
2490 for i in range(16):
2491 addr = binascii.unhexlify("f4%010x" % i)
2492 frame = build_sae_commit(addr0, addr)
2493 sock.send(radiotap + frame)
2494
2495 dev[2].request("SET sae_groups 21")
2496 id = add_mesh_secure_net(dev[2])
2497 dev[2].mesh_group_add(id)
2498 check_mesh_group_added(dev[2])
2499 check_mesh_peer_connected(dev[2])
2500 check_mesh_peer_connected(dev[0])
2501
2502 def test_mesh_link_probe(dev, apdev, params):
2503 """Mesh link probing"""
2504 addr0 = dev[0].own_addr()
2505 addr1 = dev[1].own_addr()
2506 addr2 = dev[2].own_addr()
2507
2508 check_mesh_support(dev[0])
2509 for i in range(3):
2510 add_open_mesh_network(dev[i])
2511 check_mesh_group_added(dev[i])
2512 for i in range(3):
2513 check_mesh_peer_connected(dev[i])
2514
2515 res = dev[0].request("MESH_LINK_PROBE " + addr1)
2516 if "FAIL" in res:
2517 raise HwsimSkip("MESH_LINK_PROBE kernel side support missing")
2518 dev[0].request("MESH_LINK_PROBE " + addr2 + " payload=aabbccdd")
2519 dev[1].request("MESH_LINK_PROBE " + addr0 + " payload=bbccddee")
2520 dev[1].request("MESH_LINK_PROBE " + addr2 + " payload=ccddeeff")
2521 dev[2].request("MESH_LINK_PROBE " + addr0 + " payload=aaaa")
2522 dev[2].request("MESH_LINK_PROBE " + addr1 + " payload=000102030405060708090a0b0c0d0e0f")
2523
2524 capfile = os.path.join(params['logdir'], "hwsim0.pcapng")
2525 filt = "wlan.fc == 0x8803"
2526 for i in range(10):
2527 out = run_tshark(capfile, filt, ["wlan.sa", "wlan.da"])
2528 if len(out.splitlines()) >= 6:
2529 break
2530 time.sleep(0.5)
2531 for i in [addr0, addr1, addr2]:
2532 for j in [addr0, addr1, addr2]:
2533 if i == j:
2534 continue
2535 if i + "\t" + j not in out:
2536 raise Exception("Did not see probe %s --> %s" % (i, j))