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