]>
git.ipfire.org Git - thirdparty/hostap.git/blob - tests/hwsim/test_wpas_mesh.py
1 # wpa_supplicant mesh mode tests
2 # Copyright (c) 2014, cozybit Inc.
4 # This software may be distributed under the terms of the BSD license.
5 # See README for more details.
8 logger
= logging
.getLogger()
18 from wpasupplicant
import WpaSupplicant
19 from utils
import HwsimSkip
, alloc_fail
, fail_test
, wait_fail_trigger
20 from tshark
import run_tshark
, run_tshark_json
21 from test_ap_ht
import set_world_reg
22 from test_sae
import radiotap_build
, start_monitor
, stop_monitor
, \
23 build_sae_commit
, sae_rx_commit_token_req
24 from hwsim_utils
import set_group_map
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")
32 def check_mesh_scan(dev
, params
, other_started
=False, beacon_int
=0):
35 id = dev
.request("SCAN " + params
)
37 raise Exception("Failed to start scan")
41 ev
= dev
.wait_event(["CTRL-EVENT-SCAN-STARTED"])
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")
47 ev
= dev
.wait_event(["CTRL-EVENT-SCAN-RESULTS"])
49 raise Exception("Other scan did not complete")
50 if "id=" + str(id) in ev
:
52 "Own scan id unexpectedly included in completed event")
54 ev
= dev
.wait_event(["CTRL-EVENT-SCAN-STARTED"])
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")
60 ev
= dev
.wait_event(["CTRL-EVENT-SCAN-RESULTS"])
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")
66 res
= dev
.request("SCAN_RESULTS")
68 if res
.find("[MESH]") < 0:
69 raise Exception("Scan did not contain a MESH network")
71 bssid
= res
.splitlines()[1].split(' ')[0]
72 bss
= dev
.get_bss(bssid
)
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")
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")
85 def check_mesh_group_added(dev
):
86 ev
= dev
.wait_event(["MESH-GROUP-STARTED"])
88 raise Exception("Test exception: Couldn't join mesh")
91 def check_mesh_group_removed(dev
):
92 ev
= dev
.wait_event(["MESH-GROUP-REMOVED"])
94 raise Exception("Test exception: Couldn't leave mesh")
97 def check_mesh_peer_connected(dev
, timeout
=10):
98 ev
= dev
.wait_event(["MESH-PEER-CONNECTED"], timeout
=timeout
)
100 raise Exception("Test exception: Remote peer did not connect.")
103 def check_mesh_peer_disconnected(dev
):
104 ev
= dev
.wait_event(["MESH-PEER-DISCONNECTED"])
106 raise Exception("Test exception: Peer disconnect event not detected.")
108 def check_mesh_joined2(dev
):
109 check_mesh_group_added(dev
[0])
110 check_mesh_group_added(dev
[1])
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])
116 hwsim_utils
.test_connectivity(dev
[0], dev
[1])
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
)
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)
129 def add_open_mesh_network(dev
, freq
="2412", start
=True, beacon_int
=0,
130 basic_rates
=None, chwidth
=-1, disable_vht
=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")
137 dev
.set_network(id, "frequency", freq
)
139 dev
.set_network(id, "max_oper_chwidth", str(chwidth
))
141 dev
.set_network(id, "beacon_int", str(beacon_int
))
143 dev
.set_network(id, "mesh_basic_rates", basic_rates
)
145 dev
.set_network(id, "disable_vht", "1")
147 dev
.set_network(id, "disable_ht40", "1")
149 dev
.mesh_group_add(id)
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])
157 # Check for MESH-GROUP-STARTED event
158 check_mesh_group_added(dev
[0])
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()
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
)
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
)
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])
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)
198 check_mesh_joined2(dev
)
200 # Check for Mesh scan
201 check_mesh_scan(dev
[0], "use_id=1 freq=2412", beacon_int
=175)
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")
209 check_mesh_joined_connected(dev
, connectivity
=True)
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
)
218 mode
= dev
[0].get_status_field("mode")
220 raise Exception("Unexpected mode: " + mode
)
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)
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)
234 check_mesh_joined_connected(dev
, connectivity
=True, timeout0
=30)
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)
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)
247 check_mesh_joined2(dev
)
249 ev
= dev
[0].wait_event(["will not initiate new peer link"], timeout
=10)
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])
262 def test_mesh_open_rssi_threshold(dev
, apdev
):
263 """Open mesh network with RSSI threshold"""
264 check_mesh_support(dev
[0])
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)
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])
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])
280 dev
[0].mesh_group_remove()
281 check_mesh_group_removed(dev
[0])
283 if mesh_rssi_threshold
!= expected
:
284 raise Exception("mesh_rssi_threshold should be " + str(expected
) +
285 ": " + str(mesh_rssi_threshold
))
287 def add_mesh_secure_net(dev
, psk
=True, pmf
=False, pairwise
=None, group
=None,
288 sae_password
=False, sae_password_id
=None, ocv
=False):
289 id = dev
.add_network()
290 dev
.set_network(id, "mode", "5")
291 dev
.set_network_quoted(id, "ssid", "wpas-mesh-sec")
292 dev
.set_network(id, "key_mgmt", "SAE")
293 dev
.set_network(id, "frequency", "2412")
295 dev
.set_network_quoted(id, "sae_password", "thisismypassphrase!")
297 dev
.set_network_quoted(id, "sae_password_id", sae_password_id
)
299 dev
.set_network_quoted(id, "psk", "thisismypassphrase!")
301 dev
.set_network(id, "ieee80211w", "2")
303 dev
.set_network(id, "pairwise", pairwise
)
305 dev
.set_network(id, "group", group
)
308 dev
.set_network(id, "ocv", "1")
309 except Exception as e
:
310 if "SET_NETWORK failed" in str(e
):
311 raise HwsimSkip("OCV not supported")
315 def test_wpas_mesh_secure(dev
, apdev
):
316 """wpa_supplicant secure MESH network connectivity"""
317 check_mesh_support(dev
[0], secure
=True)
318 dev
[0].request("SET sae_groups ")
319 id = add_mesh_secure_net(dev
[0])
320 dev
[0].mesh_group_add(id)
322 dev
[1].request("SET sae_groups ")
323 id = add_mesh_secure_net(dev
[1])
324 dev
[1].mesh_group_add(id)
326 check_mesh_joined_connected(dev
, connectivity
=True)
328 state
= dev
[0].get_status_field("wpa_state")
329 if state
!= "COMPLETED":
330 raise Exception("Unexpected wpa_state on dev0: " + state
)
331 state
= dev
[1].get_status_field("wpa_state")
332 if state
!= "COMPLETED":
333 raise Exception("Unexpected wpa_state on dev1: " + state
)
335 def test_wpas_mesh_secure_sae_password(dev
, apdev
):
336 """wpa_supplicant secure mesh using sae_password"""
337 check_mesh_support(dev
[0], secure
=True)
338 dev
[0].request("SET sae_groups ")
339 id = add_mesh_secure_net(dev
[0], psk
=False, sae_password
=True)
340 dev
[0].mesh_group_add(id)
342 dev
[1].request("SET sae_groups ")
343 id = add_mesh_secure_net(dev
[1])
344 dev
[1].mesh_group_add(id)
346 check_mesh_joined_connected(dev
, connectivity
=True)
348 def test_wpas_mesh_secure_sae_password_id(dev
, apdev
):
349 """Secure mesh using sae_password and password identifier"""
350 check_mesh_support(dev
[0], secure
=True)
351 dev
[0].request("SET sae_groups ")
352 id = add_mesh_secure_net(dev
[0], psk
=False, sae_password
=True,
353 sae_password_id
="pw id")
354 dev
[0].mesh_group_add(id)
356 dev
[1].request("SET sae_groups ")
357 id = add_mesh_secure_net(dev
[1], sae_password
=True,
358 sae_password_id
="pw id")
359 dev
[1].mesh_group_add(id)
361 check_mesh_joined_connected(dev
, connectivity
=True)
363 def test_wpas_mesh_secure_sae_password_id_mismatch(dev
, apdev
):
364 """Secure mesh using sae_password and password identifier mismatch"""
365 check_mesh_support(dev
[0], secure
=True)
366 dev
[0].request("SET sae_groups ")
367 id = add_mesh_secure_net(dev
[0], psk
=False, sae_password
=True,
368 sae_password_id
="pw id")
369 dev
[0].mesh_group_add(id)
371 dev
[1].request("SET sae_groups ")
372 id = add_mesh_secure_net(dev
[1], sae_password
=True,
373 sae_password_id
="wrong")
374 dev
[1].mesh_group_add(id)
376 check_mesh_joined2(dev
)
378 ev
= dev
[0].wait_event(["CTRL-EVENT-SAE-UNKNOWN-PASSWORD-IDENTIFIER"],
381 raise Exception("Unknown Password Identifier not noticed")
383 def test_mesh_secure_pmf(dev
, apdev
):
384 """Secure mesh network connectivity with PMF enabled"""
385 check_mesh_support(dev
[0], secure
=True)
386 dev
[0].request("SET sae_groups ")
387 id = add_mesh_secure_net(dev
[0], pmf
=True)
388 dev
[0].mesh_group_add(id)
390 dev
[1].request("SET sae_groups ")
391 id = add_mesh_secure_net(dev
[1], pmf
=True)
392 dev
[1].mesh_group_add(id)
394 check_mesh_joined_connected(dev
, connectivity
=True)
396 def test_mesh_secure_ocv(dev
, apdev
):
397 """Secure mesh network connectivity with OCV enabled"""
398 check_mesh_support(dev
[0], secure
=True)
399 dev
[0].request("SET sae_groups ")
400 id = add_mesh_secure_net(dev
[0], pmf
=True, ocv
=True)
401 dev
[0].mesh_group_add(id)
402 dev
[1].request("SET sae_groups ")
403 id = add_mesh_secure_net(dev
[1], pmf
=True, ocv
=True)
404 dev
[1].mesh_group_add(id)
406 check_mesh_joined_connected(dev
, connectivity
=True)
408 def test_mesh_secure_ocv_compat(dev
, apdev
):
409 """Secure mesh network where only one peer has OCV enabled"""
410 check_mesh_support(dev
[0], secure
=True)
411 dev
[0].request("SET sae_groups ")
412 id = add_mesh_secure_net(dev
[0], pmf
=True, ocv
=True)
413 dev
[0].mesh_group_add(id)
414 dev
[1].request("SET sae_groups ")
415 id = add_mesh_secure_net(dev
[1], pmf
=True, ocv
=False)
416 dev
[1].mesh_group_add(id)
418 check_mesh_joined_connected(dev
, connectivity
=True)
420 def set_reg(dev
, country
):
421 subprocess
.call(['iw', 'reg', 'set', country
])
424 ev
= dev
[i
].wait_event(["CTRL-EVENT-REGDOM-CHANGE"], timeout
=5)
426 raise Exception("No regdom change event")
427 if "alpha2=" + country
in ev
:
430 def clear_reg_setting(dev
):
431 dev
[0].request("MESH_GROUP_REMOVE " + dev
[0].ifname
)
432 dev
[1].request("MESH_GROUP_REMOVE " + dev
[1].ifname
)
433 subprocess
.call(['iw', 'reg', 'set', '00'])
434 dev
[0].flush_scan_cache()
435 dev
[1].flush_scan_cache()
437 def test_mesh_secure_ocv_mix_legacy(dev
, apdev
):
438 """Mesh network with a VHT STA and a legacy STA under OCV"""
440 run_mesh_secure_ocv_mix_legacy(dev
, apdev
)
442 clear_reg_setting(dev
)
444 def run_mesh_secure_ocv_mix_legacy(dev
, apdev
):
445 check_mesh_support(dev
[0], secure
=True)
448 dev
[0].request("SET sae_groups ")
449 id = add_mesh_secure_net(dev
[0], pmf
=True, ocv
=True)
450 dev
[0].set_network(id, "frequency", "5200")
451 dev
[0].set_network(id, "max_oper_chwidth", "2")
452 dev
[0].mesh_group_add(id)
454 dev
[1].request("SET sae_groups ")
455 id = add_mesh_secure_net(dev
[1], pmf
=True, ocv
=True)
456 dev
[1].set_network(id, "frequency", "5200")
457 dev
[1].set_network(id, "disable_vht", "1")
458 dev
[1].set_network(id, "disable_ht40", "1")
459 dev
[1].mesh_group_add(id)
461 check_mesh_joined_connected(dev
, connectivity
=True)
463 def test_mesh_secure_ocv_mix_ht(dev
, apdev
):
464 """Mesh network with a VHT STA and a HT STA under OCV"""
466 run_mesh_secure_ocv_mix_ht(dev
, apdev
)
468 clear_reg_setting(dev
)
470 def run_mesh_secure_ocv_mix_ht(dev
, apdev
):
471 check_mesh_support(dev
[0], secure
=True)
474 dev
[0].request("SET sae_groups ")
475 id = add_mesh_secure_net(dev
[0], pmf
=True, ocv
=True)
476 dev
[0].set_network(id, "frequency", "5200")
477 dev
[0].set_network(id, "max_oper_chwidth", "2")
478 dev
[0].mesh_group_add(id)
480 dev
[1].request("SET sae_groups ")
481 id = add_mesh_secure_net(dev
[1], pmf
=True, ocv
=True)
482 dev
[1].set_network(id, "frequency", "5200")
483 dev
[1].set_network(id, "disable_vht", "1")
484 dev
[1].mesh_group_add(id)
486 check_mesh_joined_connected(dev
, connectivity
=True)
488 def run_mesh_secure(dev
, cipher
):
489 if cipher
not in dev
[0].get_capability("pairwise"):
490 raise HwsimSkip("Cipher %s not supported" % cipher
)
491 check_mesh_support(dev
[0], secure
=True)
492 dev
[0].request("SET sae_groups ")
493 id = add_mesh_secure_net(dev
[0], pairwise
=cipher
, group
=cipher
)
494 dev
[0].mesh_group_add(id)
496 dev
[1].request("SET sae_groups ")
497 id = add_mesh_secure_net(dev
[1], pairwise
=cipher
, group
=cipher
)
498 dev
[1].mesh_group_add(id)
500 check_mesh_joined_connected(dev
, connectivity
=True)
502 def test_mesh_secure_ccmp(dev
, apdev
):
503 """Secure mesh with CCMP"""
504 run_mesh_secure(dev
, "CCMP")
506 def test_mesh_secure_gcmp(dev
, apdev
):
507 """Secure mesh with GCMP"""
508 run_mesh_secure(dev
, "GCMP")
510 def test_mesh_secure_gcmp_256(dev
, apdev
):
511 """Secure mesh with GCMP-256"""
512 run_mesh_secure(dev
, "GCMP-256")
514 def test_mesh_secure_ccmp_256(dev
, apdev
):
515 """Secure mesh with CCMP-256"""
516 run_mesh_secure(dev
, "CCMP-256")
518 def test_mesh_secure_invalid_pairwise_cipher(dev
, apdev
):
519 """Secure mesh and invalid group cipher"""
520 check_mesh_support(dev
[0], secure
=True)
521 dev
[0].request("SET sae_groups ")
522 id = add_mesh_secure_net(dev
[0], pairwise
="TKIP", group
="CCMP")
523 if dev
[0].mesh_group_add(id) != None:
524 raise Exception("Unexpected group add success")
525 ev
= dev
[0].wait_event(["mesh: Invalid pairwise cipher"], timeout
=1)
527 raise Exception("Invalid pairwise cipher not reported")
529 def test_mesh_secure_invalid_group_cipher(dev
, apdev
):
530 """Secure mesh and invalid group cipher"""
531 check_mesh_support(dev
[0], secure
=True)
532 dev
[0].request("SET sae_groups ")
533 id = add_mesh_secure_net(dev
[0], pairwise
="CCMP", group
="TKIP")
534 if dev
[0].mesh_group_add(id) != None:
535 raise Exception("Unexpected group add success")
536 ev
= dev
[0].wait_event(["mesh: Invalid group cipher"], timeout
=1)
538 raise Exception("Invalid group cipher not reported")
540 def test_wpas_mesh_secure_sae_group_mismatch(dev
, apdev
):
541 """wpa_supplicant secure MESH and SAE group mismatch"""
542 check_mesh_support(dev
[0], secure
=True)
543 addr0
= dev
[0].p2p_interface_addr()
544 addr1
= dev
[1].p2p_interface_addr()
545 addr2
= dev
[2].p2p_interface_addr()
547 dev
[0].request("SET sae_groups 19 25")
548 id = add_mesh_secure_net(dev
[0])
549 dev
[0].mesh_group_add(id)
551 dev
[1].request("SET sae_groups 19")
552 id = add_mesh_secure_net(dev
[1])
553 dev
[1].mesh_group_add(id)
555 dev
[2].request("SET sae_groups 26")
556 id = add_mesh_secure_net(dev
[2])
557 dev
[2].mesh_group_add(id)
559 check_mesh_group_added(dev
[0])
560 check_mesh_group_added(dev
[1])
561 check_mesh_group_added(dev
[2])
563 ev
= dev
[0].wait_event(["MESH-PEER-CONNECTED"])
565 raise Exception("Remote peer did not connect")
567 raise Exception("Unexpected peer connected: " + ev
)
569 ev
= dev
[1].wait_event(["MESH-PEER-CONNECTED"])
571 raise Exception("Remote peer did not connect")
573 raise Exception("Unexpected peer connected: " + ev
)
575 ev
= dev
[2].wait_event(["MESH-PEER-CONNECTED"], timeout
=1)
577 raise Exception("Unexpected peer connection at dev[2]: " + ev
)
579 ev
= dev
[0].wait_event(["MESH-PEER-CONNECTED"], timeout
=0.1)
581 raise Exception("Unexpected peer connection: " + ev
)
583 ev
= dev
[1].wait_event(["MESH-PEER-CONNECTED"], timeout
=0.1)
585 raise Exception("Unexpected peer connection: " + ev
)
587 dev
[0].request("SET sae_groups ")
588 dev
[1].request("SET sae_groups ")
589 dev
[2].request("SET sae_groups ")
591 def test_wpas_mesh_secure_sae_group_negotiation(dev
, apdev
):
592 """wpa_supplicant secure MESH and SAE group negotiation"""
593 check_mesh_support(dev
[0], secure
=True)
594 addr0
= dev
[0].own_addr()
595 addr1
= dev
[1].own_addr()
597 #dev[0].request("SET sae_groups 21 20 25 26")
598 dev
[0].request("SET sae_groups 26")
599 id = add_mesh_secure_net(dev
[0])
600 dev
[0].mesh_group_add(id)
602 dev
[1].request("SET sae_groups 19 26")
603 id = add_mesh_secure_net(dev
[1])
604 dev
[1].mesh_group_add(id)
606 check_mesh_joined_connected(dev
)
608 dev
[0].request("SET sae_groups ")
609 dev
[1].request("SET sae_groups ")
611 def test_wpas_mesh_secure_sae_missing_password(dev
, apdev
):
612 """wpa_supplicant secure MESH and missing SAE password"""
613 check_mesh_support(dev
[0], secure
=True)
614 id = add_mesh_secure_net(dev
[0], psk
=False)
615 dev
[0].set_network(id, "psk", "8f20b381f9b84371d61b5080ad85cac3c61ab3ca9525be5b2d0f4da3d979187a")
616 dev
[0].mesh_group_add(id)
617 ev
= dev
[0].wait_event(["MESH-GROUP-STARTED", "Could not join mesh"],
620 raise Exception("Timeout on mesh start event")
621 if "MESH-GROUP-STARTED" in ev
:
622 raise Exception("Unexpected mesh group start")
623 ev
= dev
[0].wait_event(["MESH-GROUP-STARTED"], timeout
=0.1)
625 raise Exception("Unexpected mesh group start")
627 def test_wpas_mesh_secure_no_auto(dev
, apdev
):
628 """wpa_supplicant secure MESH network connectivity"""
629 check_mesh_support(dev
[0], secure
=True)
630 dev
[0].request("SET sae_groups 19")
631 id = add_mesh_secure_net(dev
[0])
632 dev
[0].mesh_group_add(id)
634 dev
[1].request("SET sae_groups 19")
635 id = add_mesh_secure_net(dev
[1])
636 dev
[1].set_network(id, "no_auto_peer", "1")
637 dev
[1].mesh_group_add(id)
639 check_mesh_joined_connected(dev
, connectivity
=True)
641 dev
[0].request("SET sae_groups ")
642 dev
[1].request("SET sae_groups ")
644 def test_wpas_mesh_secure_dropped_frame(dev
, apdev
):
645 """Secure mesh network connectivity when the first plink Open is dropped"""
646 check_mesh_support(dev
[0], secure
=True)
648 dev
[0].request("SET ext_mgmt_frame_handling 1")
649 dev
[0].request("SET sae_groups ")
650 id = add_mesh_secure_net(dev
[0])
651 dev
[0].mesh_group_add(id)
653 dev
[1].request("SET sae_groups ")
654 id = add_mesh_secure_net(dev
[1])
655 dev
[1].mesh_group_add(id)
657 check_mesh_joined2(dev
)
659 # Drop the first Action frame (plink Open) to test unexpected order of
660 # Confirm/Open messages.
665 raise Exception("Did not see Action frames")
666 rx_msg
= dev
[0].mgmt_rx()
668 raise Exception("MGMT-RX timeout")
669 if rx_msg
['subtype'] == 13:
670 logger
.info("Drop the first Action frame")
672 if "OK" not in dev
[0].request("MGMT_RX_PROCESS freq={} datarate={} ssi_signal={} frame={}".format(
673 rx_msg
['freq'], rx_msg
['datarate'], rx_msg
['ssi_signal'], binascii
.hexlify(rx_msg
['frame']).decode())):
674 raise Exception("MGMT_RX_PROCESS failed")
676 dev
[0].request("SET ext_mgmt_frame_handling 0")
678 check_mesh_connected2(dev
, connectivity
=True)
680 def test_mesh_secure_fail(dev
, apdev
):
681 """Secure mesh network connectivity failure"""
682 check_mesh_support(dev
[0], secure
=True)
683 dev
[0].request("SET sae_groups ")
684 id = add_mesh_secure_net(dev
[0], pmf
=True)
685 dev
[0].mesh_group_add(id)
687 dev
[1].request("SET sae_groups ")
688 id = add_mesh_secure_net(dev
[1], pmf
=True)
690 with
fail_test(dev
[0], 1, "wpa_driver_nl80211_sta_add;mesh_mpm_auth_peer"):
691 dev
[1].mesh_group_add(id)
693 check_mesh_joined_connected(dev
)
695 def test_wpas_mesh_ctrl(dev
):
696 """wpa_supplicant ctrl_iface mesh command error cases"""
697 check_mesh_support(dev
[0])
698 if "FAIL" not in dev
[0].request("MESH_GROUP_ADD 123"):
699 raise Exception("Unexpected MESH_GROUP_ADD success")
700 id = dev
[0].add_network()
701 if "FAIL" not in dev
[0].request("MESH_GROUP_ADD %d" % id):
702 raise Exception("Unexpected MESH_GROUP_ADD success")
703 dev
[0].set_network(id, "mode", "5")
704 dev
[0].set_network(id, "key_mgmt", "WPA-PSK")
705 if "FAIL" not in dev
[0].request("MESH_GROUP_ADD %d" % id):
706 raise Exception("Unexpected MESH_GROUP_ADD success")
708 if "FAIL" not in dev
[0].request("MESH_GROUP_REMOVE foo"):
709 raise Exception("Unexpected MESH_GROUP_REMOVE success")
711 def test_wpas_mesh_dynamic_interface(dev
):
712 """wpa_supplicant mesh with dynamic interface"""
713 check_mesh_support(dev
[0])
717 mesh0
= dev
[0].request("MESH_INTERFACE_ADD ifname=mesh0")
719 raise Exception("MESH_INTERFACE_ADD failed")
720 mesh1
= dev
[1].request("MESH_INTERFACE_ADD")
722 raise Exception("MESH_INTERFACE_ADD failed")
724 wpas0
= WpaSupplicant(ifname
=mesh0
)
725 wpas1
= WpaSupplicant(ifname
=mesh1
)
726 logger
.info(mesh0
+ " address " + wpas0
.get_status_field("address"))
727 logger
.info(mesh1
+ " address " + wpas1
.get_status_field("address"))
729 add_open_mesh_network(wpas0
)
730 add_open_mesh_network(wpas1
)
731 check_mesh_joined_connected([wpas0
, wpas1
], connectivity
=True)
733 # Must not allow MESH_GROUP_REMOVE on dynamic interface
734 if "FAIL" not in wpas0
.request("MESH_GROUP_REMOVE " + mesh0
):
735 raise Exception("Invalid MESH_GROUP_REMOVE accepted")
736 if "FAIL" not in wpas1
.request("MESH_GROUP_REMOVE " + mesh1
):
737 raise Exception("Invalid MESH_GROUP_REMOVE accepted")
739 # Must not allow MESH_GROUP_REMOVE on another radio interface
740 if "FAIL" not in wpas0
.request("MESH_GROUP_REMOVE " + mesh1
):
741 raise Exception("Invalid MESH_GROUP_REMOVE accepted")
742 if "FAIL" not in wpas1
.request("MESH_GROUP_REMOVE " + mesh0
):
743 raise Exception("Invalid MESH_GROUP_REMOVE accepted")
745 wpas0
.remove_ifname()
746 wpas1
.remove_ifname()
748 if "OK" not in dev
[0].request("MESH_GROUP_REMOVE " + mesh0
):
749 raise Exception("MESH_GROUP_REMOVE failed")
750 if "OK" not in dev
[1].request("MESH_GROUP_REMOVE " + mesh1
):
751 raise Exception("MESH_GROUP_REMOVE failed")
753 if "FAIL" not in dev
[0].request("MESH_GROUP_REMOVE " + mesh0
):
754 raise Exception("Invalid MESH_GROUP_REMOVE accepted")
755 if "FAIL" not in dev
[1].request("MESH_GROUP_REMOVE " + mesh1
):
756 raise Exception("Invalid MESH_GROUP_REMOVE accepted")
758 logger
.info("Make sure another dynamic group can be added")
759 mesh0
= dev
[0].request("MESH_INTERFACE_ADD ifname=mesh0")
761 raise Exception("MESH_INTERFACE_ADD failed")
762 mesh1
= dev
[1].request("MESH_INTERFACE_ADD")
764 raise Exception("MESH_INTERFACE_ADD failed")
766 wpas0
= WpaSupplicant(ifname
=mesh0
)
767 wpas1
= WpaSupplicant(ifname
=mesh1
)
768 logger
.info(mesh0
+ " address " + wpas0
.get_status_field("address"))
769 logger
.info(mesh1
+ " address " + wpas1
.get_status_field("address"))
771 add_open_mesh_network(wpas0
)
772 add_open_mesh_network(wpas1
)
773 check_mesh_joined_connected([wpas0
, wpas1
], connectivity
=True)
776 dev
[0].request("MESH_GROUP_REMOVE " + mesh0
)
778 dev
[1].request("MESH_GROUP_REMOVE " + mesh1
)
780 def test_wpas_mesh_dynamic_interface_remove(dev
):
781 """wpa_supplicant mesh with dynamic interface and removal"""
782 wpas
= WpaSupplicant(global_iface
='/tmp/wpas-wlan5')
783 wpas
.interface_add("wlan5")
784 check_mesh_support(wpas
)
785 mesh5
= wpas
.request("MESH_INTERFACE_ADD ifname=mesh5")
787 raise Exception("MESH_INTERFACE_ADD failed")
789 wpas5
= WpaSupplicant(ifname
=mesh5
)
790 logger
.info(mesh5
+ " address " + wpas5
.get_status_field("address"))
791 add_open_mesh_network(wpas5
)
792 add_open_mesh_network(dev
[0])
793 check_mesh_joined_connected([wpas5
, dev
[0]], connectivity
=True)
795 # Remove the main interface while mesh interface is in use
796 wpas
.interface_remove("wlan5")
798 def test_wpas_mesh_max_peering(dev
, apdev
, params
):
799 """Mesh max peering limit"""
800 check_mesh_support(dev
[0])
802 dev
[0].request("SET max_peer_links 1")
804 # first, connect dev[0] and dev[1]
805 add_open_mesh_network(dev
[0])
806 add_open_mesh_network(dev
[1])
808 ev
= dev
[i
].wait_event(["MESH-PEER-CONNECTED"])
810 raise Exception("dev%d did not connect with any peer" % i
)
812 # add dev[2] which will try to connect with both dev[0] and dev[1],
813 # but can complete connection only with dev[1]
814 add_open_mesh_network(dev
[2])
815 for i
in range(1, 3):
816 ev
= dev
[i
].wait_event(["MESH-PEER-CONNECTED"])
818 raise Exception("dev%d did not connect the second peer" % i
)
820 ev
= dev
[0].wait_event(["MESH-PEER-CONNECTED"], timeout
=1)
822 raise Exception("dev0 connection beyond max peering limit")
824 ev
= dev
[2].wait_event(["MESH-PEER-CONNECTED"], timeout
=0.1)
826 raise Exception("dev2 reported unexpected peering: " + ev
)
829 dev
[i
].mesh_group_remove()
830 check_mesh_group_removed(dev
[i
])
832 dev
[0].request("SET max_peer_links 99")
834 addr0
= dev
[0].own_addr()
835 addr1
= dev
[1].own_addr()
836 addr2
= dev
[2].own_addr()
838 capfile
= os
.path
.join(params
['logdir'], "hwsim0.pcapng")
839 filt
= "wlan.fc.type_subtype == 8"
840 out
= run_tshark(capfile
, filt
, ["wlan.sa", "wlan.mesh.config.cap"])
841 pkts
= out
.splitlines()
846 addr
, cap
= pkt
.split('\t')
862 logger
.info("one: " + str(one
))
863 logger
.info("zero: " + str(zero
))
865 # It looks like tshark parser was broken at some point for
866 # wlan.mesh.config.cap which is now (tshark 2.6.3) pointing to incorrect
867 # field (same as wlan.mesh.config.ps_protocol). This used to work with
870 # For now, assume the capability field ends up being the last octet of
874 addrs
= [addr0
, addr1
, addr2
]
877 out
= run_tshark_json(capfile
, filt
+ " && wlan.sa == " + addr
)
878 pkts
= json
.loads(out
)
880 frame
= pkt
["_source"]["layers"]["frame_raw"][0]
881 cap
= int(frame
[-2:], 16)
886 logger
.info("one: " + str(one
))
887 logger
.info("zero: " + str(zero
))
889 raise Exception("Accepting Additional Mesh Peerings not cleared")
891 raise Exception("Accepting Additional Mesh Peerings was not set in the first Beacon frame")
892 if zero
[1] > 0 or zero
[2] > 0 or one
[1] == 0 or one
[2] == 0:
893 raise Exception("Unexpected value in Accepting Additional Mesh Peerings from other STAs")
895 def test_wpas_mesh_open_5ghz(dev
, apdev
):
896 """wpa_supplicant open MESH network on 5 GHz band"""
898 _test_wpas_mesh_open_5ghz(dev
, apdev
)
900 dev
[0].request("MESH_GROUP_REMOVE " + dev
[0].ifname
)
901 dev
[1].request("MESH_GROUP_REMOVE " + dev
[1].ifname
)
902 subprocess
.call(['iw', 'reg', 'set', '00'])
903 dev
[0].flush_scan_cache()
904 dev
[1].flush_scan_cache()
906 def _test_wpas_mesh_open_5ghz(dev
, apdev
):
907 check_mesh_support(dev
[0])
908 subprocess
.call(['iw', 'reg', 'set', 'US'])
911 ev
= dev
[i
].wait_event(["CTRL-EVENT-REGDOM-CHANGE"], timeout
=5)
913 raise Exception("No regdom change event")
914 if "alpha2=US" in ev
:
916 add_open_mesh_network(dev
[i
], freq
="5180")
918 check_mesh_joined_connected(dev
, connectivity
=True)
920 dev
[0].mesh_group_remove()
921 dev
[1].mesh_group_remove()
922 check_mesh_group_removed(dev
[0])
923 check_mesh_group_removed(dev
[1])
924 dev
[0].dump_monitor()
925 dev
[1].dump_monitor()
927 def test_wpas_mesh_open_5ghz_coex(dev
, apdev
):
928 """Mesh network on 5 GHz band and 20/40 coex change"""
930 _test_wpas_mesh_open_5ghz_coex(dev
, apdev
)
932 dev
[0].request("MESH_GROUP_REMOVE " + dev
[0].ifname
)
933 dev
[1].request("MESH_GROUP_REMOVE " + dev
[1].ifname
)
934 set_world_reg(apdev0
=apdev
[0], dev0
=dev
[0])
935 dev
[0].flush_scan_cache()
936 dev
[1].flush_scan_cache()
938 def _test_wpas_mesh_open_5ghz_coex(dev
, apdev
):
939 check_mesh_support(dev
[0])
940 subprocess
.call(['iw', 'reg', 'set', 'US'])
942 # Start a 20 MHz BSS on channel 40 that would be the secondary channel of
943 # HT40+ mesh on channel 36.
944 params
= {"ssid": "test-ht40",
947 "country_code": "US"}
948 hapd
= hostapd
.add_ap(apdev
[0], params
)
949 bssid
= hapd
.own_addr()
953 ev
= dev
[i
].wait_event(["CTRL-EVENT-REGDOM-CHANGE"], timeout
=5)
955 raise Exception("No regdom change event")
956 if "alpha2=US" in ev
:
958 dev
[i
].scan_for_bss(bssid
, freq
=5200)
959 add_open_mesh_network(dev
[i
], freq
="5180")
961 check_mesh_joined_connected(dev
)
963 freq
= dev
[0].get_status_field("freq")
965 raise Exception("Unexpected STATUS freq=" + freq
)
966 sig
= dev
[0].request("SIGNAL_POLL").splitlines()
967 if "FREQUENCY=5200" not in sig
:
968 raise Exception("Unexpected SIGNAL_POLL output: " + str(sig
))
971 dev
[0].mesh_group_remove()
972 dev
[1].mesh_group_remove()
973 check_mesh_group_removed(dev
[0])
974 check_mesh_group_removed(dev
[1])
975 dev
[0].dump_monitor()
976 dev
[1].dump_monitor()
978 def test_wpas_mesh_open_ht40(dev
, apdev
):
979 """Mesh and HT40 support difference"""
981 _test_wpas_mesh_open_ht40(dev
, apdev
)
983 dev
[0].request("MESH_GROUP_REMOVE " + dev
[0].ifname
)
984 dev
[1].request("MESH_GROUP_REMOVE " + dev
[1].ifname
)
985 dev
[2].request("MESH_GROUP_REMOVE " + dev
[2].ifname
)
986 subprocess
.call(['iw', 'reg', 'set', '00'])
987 dev
[0].flush_scan_cache()
988 dev
[1].flush_scan_cache()
989 dev
[2].flush_scan_cache()
991 def _test_wpas_mesh_open_ht40(dev
, apdev
):
992 check_mesh_support(dev
[0])
993 subprocess
.call(['iw', 'reg', 'set', 'US'])
996 ev
= dev
[i
].wait_event(["CTRL-EVENT-REGDOM-CHANGE"], timeout
=5)
998 raise Exception("No regdom change event")
999 if "alpha2=US" in ev
:
1001 add_open_mesh_network(dev
[i
], freq
="5180", disable_vht
=True,
1002 disable_ht40
=(i
== 2))
1004 check_mesh_group_added(dev
[0])
1005 check_mesh_group_added(dev
[1])
1006 check_mesh_group_added(dev
[2])
1008 check_mesh_peer_connected(dev
[0])
1009 check_mesh_peer_connected(dev
[1])
1010 check_mesh_peer_connected(dev
[2])
1012 hwsim_utils
.test_connectivity(dev
[0], dev
[1])
1013 hwsim_utils
.test_connectivity(dev
[0], dev
[2])
1014 hwsim_utils
.test_connectivity(dev
[1], dev
[2])
1016 dev
[0].mesh_group_remove()
1017 dev
[1].mesh_group_remove()
1018 dev
[2].mesh_group_remove()
1019 check_mesh_group_removed(dev
[0])
1020 check_mesh_group_removed(dev
[1])
1021 check_mesh_group_removed(dev
[2])
1022 dev
[0].dump_monitor()
1023 dev
[1].dump_monitor()
1024 dev
[2].dump_monitor()
1026 def test_wpas_mesh_open_vht40(dev
, apdev
):
1027 """wpa_supplicant open MESH network on VHT 40 MHz channel"""
1029 _test_wpas_mesh_open_vht40(dev
, apdev
)
1031 dev
[0].request("MESH_GROUP_REMOVE " + dev
[0].ifname
)
1032 dev
[1].request("MESH_GROUP_REMOVE " + dev
[1].ifname
)
1033 subprocess
.call(['iw', 'reg', 'set', '00'])
1034 dev
[0].flush_scan_cache()
1035 dev
[1].flush_scan_cache()
1037 def _test_wpas_mesh_open_vht40(dev
, apdev
):
1038 check_mesh_support(dev
[0])
1039 subprocess
.call(['iw', 'reg', 'set', 'US'])
1042 ev
= dev
[i
].wait_event(["CTRL-EVENT-REGDOM-CHANGE"], timeout
=5)
1044 raise Exception("No regdom change event")
1045 if "alpha2=US" in ev
:
1047 add_open_mesh_network(dev
[i
], freq
="5180", chwidth
=0)
1049 check_mesh_joined_connected(dev
, connectivity
=True)
1051 sig
= dev
[0].request("SIGNAL_POLL").splitlines()
1052 if "WIDTH=40 MHz" not in sig
:
1053 raise Exception("Unexpected SIGNAL_POLL value(2): " + str(sig
))
1054 if "CENTER_FRQ1=5190" not in sig
:
1055 raise Exception("Unexpected SIGNAL_POLL value(3): " + str(sig
))
1057 sig
= dev
[1].request("SIGNAL_POLL").splitlines()
1058 if "WIDTH=40 MHz" not in sig
:
1059 raise Exception("Unexpected SIGNAL_POLL value(2b): " + str(sig
))
1060 if "CENTER_FRQ1=5190" not in sig
:
1061 raise Exception("Unexpected SIGNAL_POLL value(3b): " + str(sig
))
1063 dev
[0].mesh_group_remove()
1064 dev
[1].mesh_group_remove()
1065 check_mesh_group_removed(dev
[0])
1066 check_mesh_group_removed(dev
[1])
1067 dev
[0].dump_monitor()
1068 dev
[1].dump_monitor()
1070 def test_wpas_mesh_open_vht20(dev
, apdev
):
1071 """wpa_supplicant open MESH network on VHT 20 MHz channel"""
1073 _test_wpas_mesh_open_vht20(dev
, apdev
)
1075 dev
[0].request("MESH_GROUP_REMOVE " + dev
[0].ifname
)
1076 dev
[1].request("MESH_GROUP_REMOVE " + dev
[1].ifname
)
1077 subprocess
.call(['iw', 'reg', 'set', '00'])
1078 dev
[0].flush_scan_cache()
1079 dev
[1].flush_scan_cache()
1081 def _test_wpas_mesh_open_vht20(dev
, apdev
):
1082 check_mesh_support(dev
[0])
1083 subprocess
.call(['iw', 'reg', 'set', 'US'])
1086 ev
= dev
[i
].wait_event(["CTRL-EVENT-REGDOM-CHANGE"], timeout
=5)
1088 raise Exception("No regdom change event")
1089 if "alpha2=US" in ev
:
1091 add_open_mesh_network(dev
[i
], freq
="5180", chwidth
=0, disable_ht40
=True)
1093 check_mesh_joined_connected(dev
, connectivity
=True)
1095 sig
= dev
[0].request("SIGNAL_POLL").splitlines()
1096 if "WIDTH=20 MHz" not in sig
:
1097 raise Exception("Unexpected SIGNAL_POLL value(2): " + str(sig
))
1098 if "CENTER_FRQ1=5180" not in sig
:
1099 raise Exception("Unexpected SIGNAL_POLL value(3): " + str(sig
))
1101 sig
= dev
[1].request("SIGNAL_POLL").splitlines()
1102 if "WIDTH=20 MHz" not in sig
:
1103 raise Exception("Unexpected SIGNAL_POLL value(2b): " + str(sig
))
1104 if "CENTER_FRQ1=5180" not in sig
:
1105 raise Exception("Unexpected SIGNAL_POLL value(3b): " + str(sig
))
1107 dev
[0].mesh_group_remove()
1108 dev
[1].mesh_group_remove()
1109 check_mesh_group_removed(dev
[0])
1110 check_mesh_group_removed(dev
[1])
1111 dev
[0].dump_monitor()
1112 dev
[1].dump_monitor()
1114 def test_wpas_mesh_open_vht_80p80(dev
, apdev
):
1115 """wpa_supplicant open MESH network on VHT 80+80 MHz channel"""
1117 _test_wpas_mesh_open_vht_80p80(dev
, apdev
)
1119 dev
[0].request("MESH_GROUP_REMOVE " + dev
[0].ifname
)
1120 dev
[1].request("MESH_GROUP_REMOVE " + dev
[1].ifname
)
1121 subprocess
.call(['iw', 'reg', 'set', '00'])
1122 dev
[0].flush_scan_cache()
1123 dev
[1].flush_scan_cache()
1125 def _test_wpas_mesh_open_vht_80p80(dev
, apdev
):
1126 check_mesh_support(dev
[0])
1127 subprocess
.call(['iw', 'reg', 'set', 'US'])
1130 ev
= dev
[i
].wait_event(["CTRL-EVENT-REGDOM-CHANGE"], timeout
=5)
1132 raise Exception("No regdom change event")
1133 if "alpha2=US" in ev
:
1135 add_open_mesh_network(dev
[i
], freq
="5180", chwidth
=3)
1137 check_mesh_joined_connected(dev
, connectivity
=True)
1139 sig
= dev
[0].request("SIGNAL_POLL").splitlines()
1140 if "WIDTH=80+80 MHz" not in sig
:
1141 raise Exception("Unexpected SIGNAL_POLL value(2): " + str(sig
))
1142 if "CENTER_FRQ1=5210" not in sig
:
1143 raise Exception("Unexpected SIGNAL_POLL value(3): " + str(sig
))
1144 if "CENTER_FRQ2=5775" not in sig
:
1145 raise Exception("Unexpected SIGNAL_POLL value(4): " + str(sig
))
1147 sig
= dev
[1].request("SIGNAL_POLL").splitlines()
1148 if "WIDTH=80+80 MHz" not in sig
:
1149 raise Exception("Unexpected SIGNAL_POLL value(2b): " + str(sig
))
1150 if "CENTER_FRQ1=5210" not in sig
:
1151 raise Exception("Unexpected SIGNAL_POLL value(3b): " + str(sig
))
1152 if "CENTER_FRQ2=5775" not in sig
:
1153 raise Exception("Unexpected SIGNAL_POLL value(4b): " + str(sig
))
1155 dev
[0].mesh_group_remove()
1156 dev
[1].mesh_group_remove()
1157 check_mesh_group_removed(dev
[0])
1158 check_mesh_group_removed(dev
[1])
1159 dev
[0].dump_monitor()
1160 dev
[1].dump_monitor()
1162 def test_mesh_open_vht_160(dev
, apdev
):
1163 """Open mesh network on VHT 160 MHz channel"""
1165 _test_mesh_open_vht_160(dev
, apdev
)
1167 dev
[0].request("MESH_GROUP_REMOVE " + dev
[0].ifname
)
1168 dev
[1].request("MESH_GROUP_REMOVE " + dev
[1].ifname
)
1169 subprocess
.call(['iw', 'reg', 'set', '00'])
1170 dev
[0].flush_scan_cache()
1171 dev
[1].flush_scan_cache()
1173 def _test_mesh_open_vht_160(dev
, apdev
):
1174 check_mesh_support(dev
[0])
1175 subprocess
.call(['iw', 'reg', 'set', 'ZA'])
1178 ev
= dev
[i
].wait_event(["CTRL-EVENT-REGDOM-CHANGE"], timeout
=5)
1180 raise Exception("No regdom change event")
1181 if "alpha2=ZA" in ev
:
1184 cmd
= subprocess
.Popen(["iw", "reg", "get"], stdout
=subprocess
.PIPE
)
1185 reg
= cmd
.stdout
.read()
1187 for entry
in reg
.splitlines():
1188 entry
= entry
.decode()
1189 if "@ 160)" in entry
and "DFS" not in entry
:
1193 raise HwsimSkip("160 MHz channel without DFS not supported in regulatory information")
1195 add_open_mesh_network(dev
[i
], freq
="5520", chwidth
=2)
1197 check_mesh_joined_connected(dev
, connectivity
=True)
1198 dev
[0].dump_monitor()
1199 dev
[1].dump_monitor()
1201 sig
= dev
[0].request("SIGNAL_POLL").splitlines()
1202 if "WIDTH=160 MHz" not in sig
:
1203 raise Exception("Unexpected SIGNAL_POLL value(2): " + str(sig
))
1204 if "FREQUENCY=5520" not in sig
:
1205 raise Exception("Unexpected SIGNAL_POLL value(3): " + str(sig
))
1207 sig
= dev
[1].request("SIGNAL_POLL").splitlines()
1208 if "WIDTH=160 MHz" not in sig
:
1209 raise Exception("Unexpected SIGNAL_POLL value(2b): " + str(sig
))
1210 if "FREQUENCY=5520" not in sig
:
1211 raise Exception("Unexpected SIGNAL_POLL value(3b): " + str(sig
))
1213 dev
[0].mesh_group_remove()
1214 dev
[1].mesh_group_remove()
1215 check_mesh_group_removed(dev
[0])
1216 check_mesh_group_removed(dev
[1])
1217 dev
[0].dump_monitor()
1218 dev
[1].dump_monitor()
1220 def test_wpas_mesh_password_mismatch(dev
, apdev
):
1221 """Mesh network and one device with mismatching password"""
1222 check_mesh_support(dev
[0], secure
=True)
1223 dev
[0].request("SET sae_groups ")
1224 id = add_mesh_secure_net(dev
[0])
1225 dev
[0].mesh_group_add(id)
1227 dev
[1].request("SET sae_groups ")
1228 id = add_mesh_secure_net(dev
[1])
1229 dev
[1].mesh_group_add(id)
1231 dev
[2].request("SET sae_groups ")
1232 id = add_mesh_secure_net(dev
[2])
1233 dev
[2].set_network_quoted(id, "psk", "wrong password")
1234 dev
[2].mesh_group_add(id)
1236 # The two peers with matching password need to be able to connect
1237 check_mesh_joined_connected(dev
)
1239 ev
= dev
[2].wait_event(["MESH-SAE-AUTH-FAILURE"], timeout
=20)
1241 raise Exception("dev2 did not report auth failure (1)")
1242 ev
= dev
[2].wait_event(["MESH-SAE-AUTH-FAILURE"], timeout
=20)
1244 raise Exception("dev2 did not report auth failure (2)")
1245 dev
[2].dump_monitor()
1248 ev
= dev
[0].wait_event(["MESH-SAE-AUTH-FAILURE"], timeout
=5)
1250 logger
.info("dev0 did not report auth failure")
1252 if "addr=" + dev
[2].own_addr() not in ev
:
1253 raise Exception("Unexpected peer address in dev0 event: " + ev
)
1255 dev
[0].dump_monitor()
1257 ev
= dev
[1].wait_event(["MESH-SAE-AUTH-FAILURE"], timeout
=5)
1259 logger
.info("dev1 did not report auth failure")
1261 if "addr=" + dev
[2].own_addr() not in ev
:
1262 raise Exception("Unexpected peer address in dev1 event: " + ev
)
1264 dev
[1].dump_monitor()
1266 hwsim_utils
.test_connectivity(dev
[0], dev
[1])
1270 hwsim_utils
.test_connectivity(dev
[i
], dev
[2], timeout
=1)
1271 raise Exception("Data connectivity test passed unexpectedly")
1272 except Exception as e
:
1273 if "data delivery failed" not in str(e
):
1277 raise Exception("Neither dev0 nor dev1 reported auth failure")
1279 def test_wpas_mesh_password_mismatch_retry(dev
, apdev
, params
):
1280 """Mesh password mismatch and retry [long]"""
1281 if not params
['long']:
1282 raise HwsimSkip("Skip test case with long duration due to --long not specified")
1283 check_mesh_support(dev
[0], secure
=True)
1284 dev
[0].request("SET sae_groups ")
1285 id = add_mesh_secure_net(dev
[0])
1286 dev
[0].mesh_group_add(id)
1288 dev
[1].request("SET sae_groups ")
1289 id = add_mesh_secure_net(dev
[1])
1290 dev
[1].set_network_quoted(id, "psk", "wrong password")
1291 dev
[1].mesh_group_add(id)
1293 check_mesh_joined2(dev
)
1296 ev
= dev
[0].wait_event(["MESH-SAE-AUTH-FAILURE"], timeout
=20)
1298 raise Exception("dev0 did not report auth failure (%d)" % i
)
1299 ev
= dev
[1].wait_event(["MESH-SAE-AUTH-FAILURE"], timeout
=20)
1301 raise Exception("dev1 did not report auth failure (%d)" % i
)
1303 ev
= dev
[0].wait_event(["MESH-SAE-AUTH-BLOCKED"], timeout
=10)
1305 raise Exception("dev0 did not report auth blocked")
1306 ev
= dev
[1].wait_event(["MESH-SAE-AUTH-BLOCKED"], timeout
=10)
1308 raise Exception("dev1 did not report auth blocked")
1310 def test_mesh_wpa_auth_init_oom(dev
, apdev
):
1311 """Secure mesh network setup failing due to wpa_init() OOM"""
1312 check_mesh_support(dev
[0], secure
=True)
1313 dev
[0].request("SET sae_groups ")
1314 with
alloc_fail(dev
[0], 1, "wpa_init"):
1315 id = add_mesh_secure_net(dev
[0])
1316 dev
[0].mesh_group_add(id)
1317 ev
= dev
[0].wait_event(["MESH-GROUP-STARTED"], timeout
=0.2)
1319 raise Exception("Unexpected mesh group start during OOM")
1321 def test_mesh_wpa_init_fail(dev
, apdev
):
1322 """Secure mesh network setup local failure"""
1323 check_mesh_support(dev
[0], secure
=True)
1324 check_mesh_support(dev
[1], secure
=True)
1325 check_mesh_support(dev
[2], secure
=True)
1326 dev
[0].request("SET sae_groups ")
1328 with
fail_test(dev
[0], 1, "os_get_random;=__mesh_rsn_auth_init"):
1329 id = add_mesh_secure_net(dev
[0])
1330 dev
[0].mesh_group_add(id)
1331 wait_fail_trigger(dev
[0], "GET_FAIL")
1333 dev
[0].dump_monitor()
1334 with
alloc_fail(dev
[0], 1, "mesh_rsn_auth_init"):
1335 id = add_mesh_secure_net(dev
[0])
1336 dev
[0].mesh_group_add(id)
1337 wait_fail_trigger(dev
[0], "GET_ALLOC_FAIL")
1339 dev
[0].dump_monitor()
1340 with
fail_test(dev
[0], 1, "os_get_random;mesh_rsn_init_ampe_sta"):
1341 id = add_mesh_secure_net(dev
[0])
1342 dev
[0].mesh_group_add(id)
1343 dev
[1].request("SET sae_groups ")
1344 id = add_mesh_secure_net(dev
[1])
1345 dev
[1].mesh_group_add(id)
1346 wait_fail_trigger(dev
[0], "GET_FAIL")
1348 with
fail_test(dev
[0], 2, "=omac1_aes_vector;aes_siv_encrypt"):
1349 id = add_mesh_secure_net(dev
[2])
1350 dev
[0].mesh_group_add(id)
1351 dev
[2].request("SET sae_groups ")
1352 id = add_mesh_secure_net(dev
[2])
1353 dev
[2].mesh_group_add(id)
1354 wait_fail_trigger(dev
[0], "GET_FAIL")
1356 def test_wpas_mesh_reconnect(dev
, apdev
):
1357 """Secure mesh network plink counting during reconnection"""
1358 check_mesh_support(dev
[0])
1360 _test_wpas_mesh_reconnect(dev
)
1362 dev
[0].request("SET max_peer_links 99")
1364 def _test_wpas_mesh_reconnect(dev
):
1365 dev
[0].request("SET max_peer_links 2")
1366 dev
[0].request("SET sae_groups ")
1367 id = add_mesh_secure_net(dev
[0])
1368 dev
[0].set_network(id, "beacon_int", "100")
1369 dev
[0].mesh_group_add(id)
1370 dev
[1].request("SET sae_groups ")
1371 id = add_mesh_secure_net(dev
[1])
1372 dev
[1].mesh_group_add(id)
1373 check_mesh_joined_connected(dev
)
1376 # Drop incoming management frames to avoid handling link close
1377 dev
[0].request("SET ext_mgmt_frame_handling 1")
1378 dev
[1].mesh_group_remove()
1379 check_mesh_group_removed(dev
[1])
1380 dev
[1].request("FLUSH")
1381 dev
[0].request("SET ext_mgmt_frame_handling 0")
1382 id = add_mesh_secure_net(dev
[1])
1383 dev
[1].mesh_group_add(id)
1384 check_mesh_group_added(dev
[1])
1385 check_mesh_peer_connected(dev
[1])
1386 dev
[0].dump_monitor()
1387 dev
[1].dump_monitor()
1389 def test_wpas_mesh_gate_forwarding(dev
, apdev
, p
):
1390 """Mesh forwards traffic to unknown sta to mesh gates"""
1391 addr0
= dev
[0].own_addr()
1392 addr1
= dev
[1].own_addr()
1393 addr2
= dev
[2].own_addr()
1394 external_sta
= '02:11:22:33:44:55'
1396 # start 3 node connected mesh
1397 check_mesh_support(dev
[0])
1399 add_open_mesh_network(dev
[i
])
1400 check_mesh_group_added(dev
[i
])
1402 check_mesh_peer_connected(dev
[i
])
1404 hwsim_utils
.test_connectivity(dev
[0], dev
[1])
1405 hwsim_utils
.test_connectivity(dev
[1], dev
[2])
1406 hwsim_utils
.test_connectivity(dev
[0], dev
[2])
1408 # dev0 and dev1 are mesh gates
1409 subprocess
.call(['iw', 'dev', dev
[0].ifname
, 'set', 'mesh_param',
1410 'mesh_gate_announcements=1'])
1411 subprocess
.call(['iw', 'dev', dev
[1].ifname
, 'set', 'mesh_param',
1412 'mesh_gate_announcements=1'])
1414 # wait for gate announcement frames
1417 # data frame from dev2 -> external sta should be sent to both gates
1418 dev
[2].request("DATA_TEST_CONFIG 1")
1419 dev
[2].request("DATA_TEST_TX {} {} 0".format(external_sta
, addr2
))
1420 dev
[2].request("DATA_TEST_CONFIG 0")
1422 capfile
= os
.path
.join(p
['logdir'], "hwsim0.pcapng")
1423 filt
= "wlan.sa==%s && wlan_mgt.fixed.mesh_addr5==%s" % (addr2
,
1426 da
= run_tshark(capfile
, filt
, ["wlan.da"])
1427 if addr0
in da
and addr1
in da
:
1428 logger
.debug("Frames seen in tshark iteration %d" % i
)
1433 raise Exception("Frame to gate %s not observed" % addr0
)
1435 raise Exception("Frame to gate %s not observed" % addr1
)
1437 def test_wpas_mesh_pmksa_caching(dev
, apdev
):
1438 """Secure mesh network and PMKSA caching"""
1439 check_mesh_support(dev
[0], secure
=True)
1440 dev
[0].request("SET sae_groups ")
1441 id = add_mesh_secure_net(dev
[0])
1442 dev
[0].mesh_group_add(id)
1444 dev
[1].request("SET sae_groups ")
1445 id = add_mesh_secure_net(dev
[1])
1446 dev
[1].mesh_group_add(id)
1448 check_mesh_joined_connected(dev
)
1450 addr0
= dev
[0].own_addr()
1451 addr1
= dev
[1].own_addr()
1452 pmksa0
= dev
[0].get_pmksa(addr1
)
1453 pmksa1
= dev
[1].get_pmksa(addr0
)
1454 if pmksa0
is None or pmksa1
is None:
1455 raise Exception("No PMKSA cache entry created")
1456 if pmksa0
['pmkid'] != pmksa1
['pmkid']:
1457 raise Exception("PMKID mismatch in PMKSA cache entries")
1459 if "OK" not in dev
[0].request("MESH_PEER_REMOVE " + addr1
):
1460 raise Exception("Failed to remove peer")
1461 pmksa0b
= dev
[0].get_pmksa(addr1
)
1463 raise Exception("PMKSA cache entry not maintained")
1466 if "FAIL" not in dev
[0].request("MESH_PEER_ADD " + addr1
):
1467 raise Exception("MESH_PEER_ADD unexpectedly succeeded in no_auto_peer=0 case")
1469 def test_wpas_mesh_pmksa_caching2(dev
, apdev
):
1470 """Secure mesh network and PMKSA caching with no_auto_peer=1"""
1471 check_mesh_support(dev
[0], secure
=True)
1472 addr0
= dev
[0].own_addr()
1473 addr1
= dev
[1].own_addr()
1474 dev
[0].request("SET sae_groups ")
1475 id = add_mesh_secure_net(dev
[0])
1476 dev
[0].set_network(id, "no_auto_peer", "1")
1477 dev
[0].mesh_group_add(id)
1479 dev
[1].request("SET sae_groups ")
1480 id = add_mesh_secure_net(dev
[1])
1481 dev
[1].set_network(id, "no_auto_peer", "1")
1482 dev
[1].mesh_group_add(id)
1484 check_mesh_joined2(dev
)
1486 # Check for peer connected
1487 ev
= dev
[0].wait_event(["will not initiate new peer link"], timeout
=10)
1489 raise Exception("Missing no-initiate message")
1490 if "OK" not in dev
[0].request("MESH_PEER_ADD " + addr1
):
1491 raise Exception("MESH_PEER_ADD failed")
1492 check_mesh_connected2(dev
)
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")
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
)
1505 raise Exception("PMKSA cache entry not maintained")
1507 ev
= dev
[0].wait_event(["will not initiate new peer link"], timeout
=10)
1509 raise Exception("Missing no-initiate message (2)")
1510 if "OK" not in dev
[0].request("MESH_PEER_ADD " + addr1
):
1511 raise Exception("MESH_PEER_ADD failed (2)")
1512 check_mesh_connected2(dev
)
1514 pmksa0c
= dev
[0].get_pmksa(addr1
)
1515 pmksa1c
= dev
[1].get_pmksa(addr0
)
1516 if pmksa0c
is None or pmksa1c
is None:
1517 raise Exception("No PMKSA cache entry created (2)")
1518 if pmksa0c
['pmkid'] != pmksa1c
['pmkid']:
1519 raise Exception("PMKID mismatch in PMKSA cache entries")
1520 if pmksa0
['pmkid'] != pmksa0c
['pmkid']:
1521 raise Exception("PMKID changed")
1523 hwsim_utils
.test_connectivity(dev
[0], dev
[1])
1525 def test_wpas_mesh_pmksa_caching_no_match(dev
, apdev
):
1526 """Secure mesh network and PMKSA caching with no PMKID match"""
1527 check_mesh_support(dev
[0], secure
=True)
1528 addr0
= dev
[0].own_addr()
1529 addr1
= dev
[1].own_addr()
1530 dev
[0].request("SET sae_groups ")
1531 id = add_mesh_secure_net(dev
[0])
1532 dev
[0].set_network(id, "no_auto_peer", "1")
1533 dev
[0].mesh_group_add(id)
1535 dev
[1].request("SET sae_groups ")
1536 id = add_mesh_secure_net(dev
[1])
1537 dev
[1].set_network(id, "no_auto_peer", "1")
1538 dev
[1].mesh_group_add(id)
1540 check_mesh_joined2(dev
)
1542 # Check for peer connected
1543 ev
= dev
[0].wait_event(["will not initiate new peer link"], timeout
=10)
1545 raise Exception("Missing no-initiate message")
1546 if "OK" not in dev
[0].request("MESH_PEER_ADD " + addr1
):
1547 raise Exception("MESH_PEER_ADD failed")
1548 check_mesh_connected2(dev
)
1550 pmksa0
= dev
[0].get_pmksa(addr1
)
1551 pmksa1
= dev
[1].get_pmksa(addr0
)
1552 if pmksa0
is None or pmksa1
is None:
1553 raise Exception("No PMKSA cache entry created")
1554 if pmksa0
['pmkid'] != pmksa1
['pmkid']:
1555 raise Exception("PMKID mismatch in PMKSA cache entries")
1557 if "OK" not in dev
[0].request("MESH_PEER_REMOVE " + addr1
):
1558 raise Exception("Failed to remove peer")
1560 if "OK" not in dev
[1].request("PMKSA_FLUSH"):
1561 raise Exception("Failed to flush PMKSA cache")
1563 ev
= dev
[0].wait_event(["will not initiate new peer link"], timeout
=10)
1565 raise Exception("Missing no-initiate message (2)")
1566 if "OK" not in dev
[0].request("MESH_PEER_ADD " + addr1
):
1567 raise Exception("MESH_PEER_ADD failed (2)")
1568 check_mesh_connected2(dev
)
1570 pmksa0c
= dev
[0].get_pmksa(addr1
)
1571 pmksa1c
= dev
[1].get_pmksa(addr0
)
1572 if pmksa0c
is None or pmksa1c
is None:
1573 raise Exception("No PMKSA cache entry created (2)")
1574 if pmksa0c
['pmkid'] != pmksa1c
['pmkid']:
1575 raise Exception("PMKID mismatch in PMKSA cache entries")
1576 if pmksa0
['pmkid'] == pmksa0c
['pmkid']:
1577 raise Exception("PMKID did not change")
1579 hwsim_utils
.test_connectivity(dev
[0], dev
[1])
1581 def test_mesh_pmksa_caching_oom(dev
, apdev
):
1582 """Secure mesh network and PMKSA caching failing due to OOM"""
1583 check_mesh_support(dev
[0], secure
=True)
1584 addr0
= dev
[0].own_addr()
1585 addr1
= dev
[1].own_addr()
1586 dev
[0].request("SET sae_groups ")
1587 id = add_mesh_secure_net(dev
[0])
1588 dev
[0].set_network(id, "no_auto_peer", "1")
1589 dev
[0].mesh_group_add(id)
1591 dev
[1].request("SET sae_groups ")
1592 id = add_mesh_secure_net(dev
[1])
1593 dev
[1].set_network(id, "no_auto_peer", "1")
1594 dev
[1].mesh_group_add(id)
1596 check_mesh_joined2(dev
)
1598 # Check for peer connected
1599 ev
= dev
[0].wait_event(["will not initiate new peer link"], timeout
=10)
1601 raise Exception("Missing no-initiate message")
1602 if "OK" not in dev
[0].request("MESH_PEER_ADD " + addr1
):
1603 raise Exception("MESH_PEER_ADD failed")
1604 check_mesh_connected2(dev
)
1606 if "OK" not in dev
[0].request("MESH_PEER_REMOVE " + addr1
):
1607 raise Exception("Failed to remove peer")
1608 pmksa0b
= dev
[0].get_pmksa(addr1
)
1610 raise Exception("PMKSA cache entry not maintained")
1612 ev
= dev
[0].wait_event(["will not initiate new peer link"], timeout
=10)
1614 raise Exception("Missing no-initiate message (2)")
1616 with
alloc_fail(dev
[0], 1, "wpa_auth_sta_init;mesh_rsn_auth_sae_sta"):
1617 if "OK" not in dev
[0].request("MESH_PEER_ADD " + addr1
):
1618 raise Exception("MESH_PEER_ADD failed (2)")
1619 wait_fail_trigger(dev
[0], "GET_ALLOC_FAIL")
1621 def test_wpas_mesh_pmksa_caching_ext(dev
, apdev
):
1622 """Secure mesh network and PMKSA caching and external storage"""
1623 check_mesh_support(dev
[0], secure
=True)
1624 dev
[0].request("SET sae_groups ")
1625 id = add_mesh_secure_net(dev
[0])
1626 dev
[0].mesh_group_add(id)
1628 dev
[1].request("SET sae_groups ")
1629 id = add_mesh_secure_net(dev
[1])
1630 dev
[1].mesh_group_add(id)
1632 check_mesh_joined_connected(dev
)
1633 dev
[0].dump_monitor()
1634 dev
[1].dump_monitor()
1636 addr0
= dev
[0].own_addr()
1637 addr1
= dev
[1].own_addr()
1638 pmksa0
= dev
[0].get_pmksa(addr1
)
1639 pmksa1
= dev
[1].get_pmksa(addr0
)
1640 if pmksa0
is None or pmksa1
is None:
1641 raise Exception("No PMKSA cache entry created")
1642 if pmksa0
['pmkid'] != pmksa1
['pmkid']:
1643 raise Exception("PMKID mismatch in PMKSA cache entries")
1645 res1
= dev
[1].request("MESH_PMKSA_GET any")
1646 res2
= dev
[1].request("MESH_PMKSA_GET " + addr0
)
1647 logger
.info("MESH_PMKSA_GET: " + res1
)
1648 if "UNKNOWN COMMAND" in res1
:
1649 raise HwsimSkip("MESH_PMKSA_GET not supported in the build")
1650 logger
.info("MESH_PMKSA_GET: " + res2
)
1651 if pmksa0
['pmkid'] not in res1
:
1652 raise Exception("PMKID not included in PMKSA entry")
1654 raise Exception("Unexpected difference in MESH_PMKSA_GET output")
1656 dev
[1].mesh_group_remove()
1657 check_mesh_group_removed(dev
[1])
1658 dev
[0].dump_monitor()
1659 dev
[1].dump_monitor()
1660 res
= dev
[1].get_pmksa(addr0
)
1662 raise Exception("Unexpected PMKSA cache entry remaining")
1664 if "OK" not in dev
[1].request("MESH_PMKSA_ADD " + res2
):
1665 raise Exception("MESH_PMKSA_ADD failed")
1666 dev
[1].mesh_group_add(id)
1667 check_mesh_group_added(dev
[1])
1668 check_mesh_peer_connected(dev
[1])
1669 dev
[0].dump_monitor()
1670 dev
[1].dump_monitor()
1671 pmksa1b
= dev
[1].get_pmksa(addr0
)
1673 raise Exception("No PMKSA cache entry created after external storage restore")
1674 if pmksa1
['pmkid'] != pmksa1b
['pmkid']:
1675 raise Exception("PMKID mismatch in PMKSA cache entries after external storage restore")
1677 hwsim_utils
.test_connectivity(dev
[0], dev
[1])
1679 res
= dev
[1].request("MESH_PMKSA_GET foo")
1680 if "FAIL" not in res
:
1681 raise Exception("Invalid MESH_PMKSA_GET accepted")
1683 dev
[1].mesh_group_remove()
1684 check_mesh_group_removed(dev
[1])
1685 dev
[0].dump_monitor()
1686 dev
[1].dump_monitor()
1687 dev
[1].request("REMOVE_NETWORK all")
1688 res
= dev
[1].request("MESH_PMKSA_GET any")
1689 if "FAIL" not in res
:
1690 raise Exception("MESH_PMKSA_GET accepted when not in mesh")
1693 "02:02:02:02:02:02",
1694 "02:02:02:02:02:02 q",
1695 "02:02:02:02:02:02 c3d51a7ccfca0c6d5287291a7169d79b",
1696 "02:02:02:02:02:02 c3d51a7ccfca0c6d5287291a7169d79b q",
1697 "02:02:02:02:02:02 c3d51a7ccfca0c6d5287291a7169d79b 1bed4fa22ece7997ca1bdc8b829019fe63acac91cba3405522c24c91f7cfb49f",
1698 "02:02:02:02:02:02 c3d51a7ccfca0c6d5287291a7169d79b 1bed4fa22ece7997ca1bdc8b829019fe63acac91cba3405522c24c91f7cfb49f q"]
1700 if "FAIL" not in dev
[1].request("MESH_PMKSA_ADD " + t
):
1701 raise Exception("Invalid MESH_PMKSA_ADD accepted")
1703 def test_mesh_oom(dev
, apdev
):
1704 """Mesh network setup failing due to OOM"""
1705 check_mesh_support(dev
[0], secure
=True)
1706 dev
[0].request("SET sae_groups ")
1708 with
alloc_fail(dev
[0], 1, "mesh_config_create"):
1709 add_open_mesh_network(dev
[0])
1710 ev
= dev
[0].wait_event(["Failed to init mesh"])
1712 raise Exception("Init failure not reported")
1714 with
alloc_fail(dev
[0], 2, "=wpa_supplicant_mesh_init"):
1715 add_open_mesh_network(dev
[0], basic_rates
="60 120 240")
1716 ev
= dev
[0].wait_event(["Failed to init mesh"])
1718 raise Exception("Init failure not reported")
1720 for i
in range(1, 66):
1721 dev
[0].dump_monitor()
1722 logger
.info("Test instance %d" % i
)
1724 with
alloc_fail(dev
[0], i
, "wpa_supplicant_mesh_init"):
1725 add_open_mesh_network(dev
[0])
1726 wait_fail_trigger(dev
[0], "GET_ALLOC_FAIL")
1727 ev
= dev
[0].wait_event(["Failed to init mesh",
1728 "MESH-GROUP-STARTED"])
1730 raise Exception("Init failure not reported")
1731 except Exception as e
:
1734 logger
.info("Ignore no-oom for i=%d" % i
)
1736 with
alloc_fail(dev
[0], 2, "=wpa_supplicant_mesh_init"):
1737 id = add_mesh_secure_net(dev
[0])
1738 dev
[0].mesh_group_add(id)
1739 ev
= dev
[0].wait_event(["Failed to init mesh"])
1741 raise Exception("Init failure not reported")
1743 def test_mesh_add_interface_oom(dev
):
1744 """wpa_supplicant mesh with dynamic interface addition failing"""
1745 check_mesh_support(dev
[0])
1746 for i
in range(1, 3):
1749 with
alloc_fail(dev
[0], i
, "wpas_mesh_add_interface"):
1750 mesh
= dev
[0].request("MESH_INTERFACE_ADD").strip()
1752 if mesh
and mesh
!= "FAIL":
1753 dev
[0].request("MESH_GROUP_REMOVE " + mesh
)
1755 def test_mesh_scan_oom(dev
):
1756 """wpa_supplicant mesh scan results and OOM"""
1757 check_mesh_support(dev
[0])
1758 add_open_mesh_network(dev
[0])
1759 check_mesh_group_added(dev
[0])
1761 dev
[1].scan(freq
="2412")
1762 res
= dev
[1].request("SCAN_RESULTS")
1765 for r
in res
.splitlines():
1768 bssid
= r
.split('\t')[0]
1770 bss
= dev
[1].get_bss(bssid
)
1772 raise Exception("Could not get BSS entry for mesh")
1774 for i
in range(1, 3):
1775 with
alloc_fail(dev
[1], i
, "mesh_attr_text"):
1776 bss
= dev
[1].get_bss(bssid
)
1777 if bss
and "mesh_id" in bss
:
1778 raise Exception("Unexpected BSS result during OOM")
1780 def test_mesh_drv_fail(dev
, apdev
):
1781 """Mesh network setup failing due to driver command failure"""
1782 check_mesh_support(dev
[0], secure
=True)
1783 dev
[0].request("SET sae_groups ")
1785 with
fail_test(dev
[0], 1, "nl80211_join_mesh"):
1786 add_open_mesh_network(dev
[0])
1787 ev
= dev
[0].wait_event(["mesh join error"])
1789 raise Exception("Join failure not reported")
1791 dev
[0].dump_monitor()
1792 with
fail_test(dev
[0], 1, "wpa_driver_nl80211_if_add"):
1793 if "FAIL" not in dev
[0].request("MESH_INTERFACE_ADD").strip():
1794 raise Exception("Interface added unexpectedly")
1796 dev
[0].dump_monitor()
1797 with
fail_test(dev
[0], 1, "wpa_driver_nl80211_init_mesh"):
1798 add_open_mesh_network(dev
[0])
1799 ev
= dev
[0].wait_event(["Could not join mesh"])
1801 raise Exception("Join failure not reported")
1803 def test_mesh_sae_groups_invalid(dev
, apdev
):
1804 """Mesh with invalid SAE group configuration"""
1805 check_mesh_support(dev
[0], secure
=True)
1807 dev
[0].request("SET sae_groups 26")
1808 id = add_mesh_secure_net(dev
[0])
1809 dev
[0].mesh_group_add(id)
1811 dev
[1].request("SET sae_groups 123 122 121")
1812 id = add_mesh_secure_net(dev
[1])
1813 dev
[1].mesh_group_add(id)
1815 check_mesh_joined2(dev
)
1817 ev
= dev
[0].wait_event(["new peer notification"], timeout
=10)
1819 raise Exception("dev[0] did not see peer")
1820 ev
= dev
[1].wait_event(["new peer notification"], timeout
=10)
1822 raise Exception("dev[1] did not see peer")
1824 ev
= dev
[0].wait_event(["MESH-PEER-CONNECTED"], timeout
=0.1)
1826 raise Exception("Unexpected connection(0)")
1828 ev
= dev
[1].wait_event(["MESH-PEER-CONNECTED"], timeout
=0.01)
1830 raise Exception("Unexpected connection(1)")
1832 # Additional coverage in mesh_rsn_sae_group() with non-zero
1833 # wpa_s->mesh_rsn->sae_group_index.
1834 dev
[0].dump_monitor()
1835 dev
[1].dump_monitor()
1836 dev
[2].request("SET sae_groups ")
1837 id = add_mesh_secure_net(dev
[2])
1838 dev
[2].mesh_group_add(id)
1839 check_mesh_group_added(dev
[2])
1840 check_mesh_peer_connected(dev
[0])
1841 check_mesh_peer_connected(dev
[2])
1842 ev
= dev
[1].wait_event(["new peer notification"], timeout
=10)
1844 raise Exception("dev[1] did not see peer(2)")
1845 dev
[0].dump_monitor()
1846 dev
[1].dump_monitor()
1847 dev
[2].dump_monitor()
1849 dev
[0].request("SET sae_groups ")
1850 dev
[1].request("SET sae_groups ")
1851 dev
[2].request("SET sae_groups ")
1853 def test_mesh_sae_failure(dev
, apdev
):
1854 """Mesh and local SAE failures"""
1855 check_mesh_support(dev
[0], secure
=True)
1857 dev
[0].request("SET sae_groups ")
1858 dev
[1].request("SET sae_groups ")
1860 funcs
= [(1, "=mesh_rsn_auth_sae_sta", True),
1861 (1, "mesh_rsn_build_sae_commit;mesh_rsn_auth_sae_sta", False),
1862 (1, "auth_sae_init_committed;mesh_rsn_auth_sae_sta", True),
1863 (1, "=mesh_rsn_protect_frame", True),
1864 (2, "=mesh_rsn_protect_frame", True),
1865 (1, "aes_siv_encrypt;mesh_rsn_protect_frame", True),
1866 (1, "=mesh_rsn_process_ampe", True),
1867 (1, "aes_siv_decrypt;mesh_rsn_process_ampe", True)]
1868 for count
, func
, success
in funcs
:
1869 id = add_mesh_secure_net(dev
[0])
1870 dev
[0].mesh_group_add(id)
1872 with
alloc_fail(dev
[1], count
, func
):
1873 id = add_mesh_secure_net(dev
[1])
1874 dev
[1].mesh_group_add(id)
1875 check_mesh_joined2(dev
)
1877 # retry is expected to work
1878 check_mesh_connected2(dev
)
1880 wait_fail_trigger(dev
[1], "GET_ALLOC_FAIL")
1881 dev
[0].mesh_group_remove()
1882 dev
[1].mesh_group_remove()
1883 check_mesh_group_removed(dev
[0])
1884 check_mesh_group_removed(dev
[1])
1886 def test_mesh_failure(dev
, apdev
):
1887 """Mesh and local failures"""
1888 check_mesh_support(dev
[0])
1890 funcs
= [(1, "ap_sta_add;mesh_mpm_add_peer", True),
1891 (1, "wpabuf_alloc;mesh_mpm_send_plink_action", True)]
1892 for count
, func
, success
in funcs
:
1893 add_open_mesh_network(dev
[0])
1895 with
alloc_fail(dev
[1], count
, func
):
1896 add_open_mesh_network(dev
[1])
1897 check_mesh_joined2(dev
)
1899 # retry is expected to work
1900 check_mesh_connected2(dev
)
1902 wait_fail_trigger(dev
[1], "GET_ALLOC_FAIL")
1903 dev
[0].mesh_group_remove()
1904 dev
[1].mesh_group_remove()
1905 check_mesh_group_removed(dev
[0])
1906 check_mesh_group_removed(dev
[1])
1908 funcs
= [(1, "mesh_mpm_init_link", True)]
1909 for count
, func
, success
in funcs
:
1910 add_open_mesh_network(dev
[0])
1912 with
fail_test(dev
[1], count
, func
):
1913 add_open_mesh_network(dev
[1])
1914 check_mesh_joined2(dev
)
1916 # retry is expected to work
1917 check_mesh_connected2(dev
)
1919 wait_fail_trigger(dev
[1], "GET_FAIL")
1920 dev
[0].mesh_group_remove()
1921 dev
[1].mesh_group_remove()
1922 check_mesh_group_removed(dev
[0])
1923 check_mesh_group_removed(dev
[1])
1925 def test_mesh_invalid_frequency(dev
, apdev
):
1926 """Mesh and invalid frequency configuration"""
1927 check_mesh_support(dev
[0])
1928 add_open_mesh_network(dev
[0], freq
=None)
1929 ev
= dev
[0].wait_event(["MESH-GROUP-STARTED",
1930 "Could not join mesh"])
1931 if ev
is None or "Could not join mesh" not in ev
:
1932 raise Exception("Mesh join failure not reported")
1933 dev
[0].request("REMOVE_NETWORK all")
1935 add_open_mesh_network(dev
[0], freq
="2413")
1936 ev
= dev
[0].wait_event(["MESH-GROUP-STARTED",
1937 "Could not join mesh"])
1938 if ev
is None or "Could not join mesh" not in ev
:
1939 raise Exception("Mesh join failure not reported")
1941 def test_mesh_default_beacon_int(dev
, apdev
):
1942 """Mesh and default beacon interval"""
1943 check_mesh_support(dev
[0])
1945 dev
[0].request("SET beacon_int 200")
1946 add_open_mesh_network(dev
[0])
1947 check_mesh_group_added(dev
[0])
1949 dev
[0].request("SET beacon_int 0")
1951 def test_mesh_scan_parse_error(dev
, apdev
):
1952 """Mesh scan element parse error"""
1953 check_mesh_support(dev
[0])
1954 params
= {"ssid": "open",
1955 "beacon_int": "2000"}
1956 hapd
= hostapd
.add_ap(apdev
[0], params
)
1957 bssid
= apdev
[0]['bssid']
1958 hapd
.set('vendor_elements', 'dd0201')
1960 dev
[0].scan(freq
=2412)
1961 if bssid
in dev
[0].request("SCAN_RESULTS"):
1963 # This will fail in IE parsing due to the truncated IE in the Probe
1965 bss
= dev
[0].request("BSS " + bssid
)
1967 def test_mesh_missing_mic(dev
, apdev
):
1968 """Secure mesh network and missing MIC"""
1969 check_mesh_support(dev
[0], secure
=True)
1971 dev
[0].request("SET ext_mgmt_frame_handling 1")
1972 dev
[0].request("SET sae_groups ")
1973 id = add_mesh_secure_net(dev
[0])
1974 dev
[0].mesh_group_add(id)
1976 dev
[1].request("SET sae_groups ")
1977 id = add_mesh_secure_net(dev
[1])
1978 dev
[1].mesh_group_add(id)
1980 check_mesh_joined2(dev
)
1987 raise Exception("Did not see Action frames")
1988 rx_msg
= dev
[0].mgmt_rx()
1990 ev
= dev
[1].wait_event(["MESH-PEER-CONNECTED"], timeout
=0.01)
1993 raise Exception("MGMT-RX timeout")
1994 if rx_msg
['subtype'] == 13:
1995 payload
= rx_msg
['payload']
1996 frame
= rx_msg
['frame']
1997 (categ
, action
) = struct
.unpack('BB', payload
[0:2])
1998 if categ
== 15 and action
== 1 and remove_mic
:
2000 pos
= frame
.find(b
'\x8c\x10')
2002 raise Exception("Could not find MIC element")
2003 logger
.info("Found MIC at %d" % pos
)
2005 rx_msg
['frame'] = frame
[0:pos
]
2007 if "OK" not in dev
[0].request("MGMT_RX_PROCESS freq={} datarate={} ssi_signal={} frame={}".format(
2008 rx_msg
['freq'], rx_msg
['datarate'], rx_msg
['ssi_signal'], binascii
.hexlify(rx_msg
['frame']).decode())):
2009 raise Exception("MGMT_RX_PROCESS failed")
2010 ev
= dev
[1].wait_event(["MESH-PEER-CONNECTED"], timeout
=0.01)
2014 def test_mesh_pmkid_mismatch(dev
, apdev
):
2015 """Secure mesh network and PMKID mismatch"""
2016 check_mesh_support(dev
[0], secure
=True)
2017 addr0
= dev
[0].own_addr()
2018 addr1
= dev
[1].own_addr()
2019 dev
[0].request("SET sae_groups ")
2020 id = add_mesh_secure_net(dev
[0])
2021 dev
[0].set_network(id, "no_auto_peer", "1")
2022 dev
[0].mesh_group_add(id)
2024 dev
[1].request("SET sae_groups ")
2025 id = add_mesh_secure_net(dev
[1])
2026 dev
[1].set_network(id, "no_auto_peer", "1")
2027 dev
[1].mesh_group_add(id)
2029 check_mesh_joined2(dev
)
2031 # Check for peer connected
2032 ev
= dev
[0].wait_event(["will not initiate new peer link"], timeout
=10)
2034 raise Exception("Missing no-initiate message")
2035 if "OK" not in dev
[0].request("MESH_PEER_ADD " + addr1
):
2036 raise Exception("MESH_PEER_ADD failed")
2037 check_mesh_connected2(dev
)
2039 if "OK" not in dev
[0].request("MESH_PEER_REMOVE " + addr1
):
2040 raise Exception("Failed to remove peer")
2042 ev
= dev
[0].wait_event(["will not initiate new peer link"], timeout
=10)
2044 raise Exception("Missing no-initiate message (2)")
2045 dev
[0].dump_monitor()
2046 dev
[1].dump_monitor()
2047 dev
[0].request("SET ext_mgmt_frame_handling 1")
2048 if "OK" not in dev
[0].request("MESH_PEER_ADD " + addr1
):
2049 raise Exception("MESH_PEER_ADD failed (2)")
2056 raise Exception("Did not see Action frames")
2057 rx_msg
= dev
[0].mgmt_rx()
2059 ev
= dev
[1].wait_event(["MESH-PEER-CONNECTED"], timeout
=0.1)
2062 raise Exception("MGMT-RX timeout")
2063 if rx_msg
['subtype'] == 13:
2064 payload
= rx_msg
['payload']
2065 frame
= rx_msg
['frame']
2066 (categ
, action
) = struct
.unpack('BB', payload
[0:2])
2067 if categ
== 15 and action
== 1 and break_pmkid
:
2069 pos
= frame
.find(b
'\x75\x14')
2071 raise Exception("Could not find Mesh Peering Management element")
2072 logger
.info("Found Mesh Peering Management element at %d" % pos
)
2073 # Break PMKID to hit "Mesh RSN: Invalid PMKID (Chosen PMK did
2074 # not match calculated PMKID)"
2075 rx_msg
['frame'] = frame
[0:pos
+ 6] + b
'\x00\x00\x00\x00' + frame
[pos
+ 10:]
2077 if "OK" not in dev
[0].request("MGMT_RX_PROCESS freq={} datarate={} ssi_signal={} frame={}".format(
2078 rx_msg
['freq'], rx_msg
['datarate'], rx_msg
['ssi_signal'], binascii
.hexlify(rx_msg
['frame']).decode())):
2079 raise Exception("MGMT_RX_PROCESS failed")
2080 ev
= dev
[1].wait_event(["MESH-PEER-CONNECTED"], timeout
=0.01)
2084 def test_mesh_peering_proto(dev
, apdev
):
2085 """Mesh peering management protocol testing"""
2086 check_mesh_support(dev
[0])
2088 dev
[0].request("SET ext_mgmt_frame_handling 1")
2089 add_open_mesh_network(dev
[0], beacon_int
=160)
2090 add_open_mesh_network(dev
[1], beacon_int
=160)
2097 raise Exception("Did not see Action frames")
2098 rx_msg
= dev
[0].mgmt_rx()
2100 ev
= dev
[1].wait_event(["MESH-PEER-CONNECTED"], timeout
=0.01)
2103 raise Exception("MGMT-RX timeout")
2104 if rx_msg
['subtype'] == 13:
2105 payload
= rx_msg
['payload']
2106 frame
= rx_msg
['frame']
2107 (categ
, action
) = struct
.unpack('BB', payload
[0:2])
2108 if categ
== 15 and action
== 1 and test
== 1:
2110 pos
= frame
.find(b
'\x75\x04')
2112 raise Exception("Could not find Mesh Peering Management element")
2113 logger
.info("Found Mesh Peering Management element at %d" % pos
)
2114 # Remove the element to hit
2115 # "MPM: No Mesh Peering Management element"
2116 rx_msg
['frame'] = frame
[0:pos
]
2118 elif categ
== 15 and action
== 1 and test
== 2:
2120 pos
= frame
.find(b
'\x72\x0e')
2122 raise Exception("Could not find Mesh ID element")
2123 logger
.info("Found Mesh ID element at %d" % pos
)
2124 # Remove the element to hit
2125 # "MPM: No Mesh ID or Mesh Configuration element"
2126 rx_msg
['frame'] = frame
[0:pos
] + frame
[pos
+ 16:]
2128 elif categ
== 15 and action
== 1 and test
== 3:
2130 pos
= frame
.find(b
'\x72\x0e')
2132 raise Exception("Could not find Mesh ID element")
2133 logger
.info("Found Mesh ID element at %d" % pos
)
2134 # Replace Mesh ID to hit "MPM: Mesh ID or Mesh Configuration
2135 # element do not match local MBSS"
2136 rx_msg
['frame'] = frame
[0:pos
] + b
'\x72\x0etest-test-test' + frame
[pos
+ 16:]
2138 elif categ
== 15 and action
== 1 and test
== 4:
2141 # "MPM: Ignore too short action frame 1 ie_len 0"
2142 rx_msg
['frame'] = frame
[0:26]
2144 elif categ
== 15 and action
== 1 and test
== 5:
2146 # Truncate IEs to hit
2147 # "MPM: Failed to parse PLINK IEs"
2148 rx_msg
['frame'] = frame
[0:30]
2150 elif categ
== 15 and action
== 1 and test
== 6:
2152 pos
= frame
.find(b
'\x75\x04')
2154 raise Exception("Could not find Mesh Peering Management element")
2155 logger
.info("Found Mesh Peering Management element at %d" % pos
)
2156 # Truncate the element to hit
2157 # "MPM: Invalid peer mgmt ie" and
2158 # "MPM: Mesh parsing rejected frame"
2159 rx_msg
['frame'] = frame
[0:pos
] + b
'\x75\x00\x00\x00' + frame
[pos
+ 6:]
2161 if "OK" not in dev
[0].request("MGMT_RX_PROCESS freq={} datarate={} ssi_signal={} frame={}".format(
2162 rx_msg
['freq'], rx_msg
['datarate'], rx_msg
['ssi_signal'], binascii
.hexlify(rx_msg
['frame']).decode())):
2163 raise Exception("MGMT_RX_PROCESS failed")
2164 ev
= dev
[1].wait_event(["MESH-PEER-CONNECTED"], timeout
=0.01)
2169 raise Exception("Not all test frames completed")
2171 def test_mesh_mpm_init_proto(dev
, apdev
):
2172 """Mesh peering management protocol testing for peer addition"""
2173 check_mesh_support(dev
[0])
2174 add_open_mesh_network(dev
[0])
2175 check_mesh_group_added(dev
[0])
2176 dev
[0].dump_monitor()
2178 dev
[0].request("SET ext_mgmt_frame_handling 1")
2180 addr
= "020000000100"
2181 hdr
= "d000ac00020000000000" + addr
+ addr
+ "1000"
2183 supp_rates
= "010802040b168c129824"
2184 ext_supp_rates
= "3204b048606c"
2185 mesh_id
= "720e777061732d6d6573682d6f70656e"
2186 mesh_conf
= "710701010001000009"
2187 mpm
= "75040000079d"
2188 ht_capab
= "2d1a7c001bffff000000000000000000000100000000000000000000"
2189 ht_oper
= "3d160b000000000000000000000000000000000000000000"
2191 dev
[0].request("NOTE no supported rates")
2192 frame
= hdr
+ fixed
+ ext_supp_rates
+ mesh_id
+ mesh_conf
+ mpm
+ ht_capab
+ ht_oper
2193 if "OK" not in dev
[0].request("MGMT_RX_PROCESS freq=2412 datarate=0 ssi_signal=-30 frame=%s" % frame
):
2194 raise Exception("MGMT_RX_PROCESS failed")
2196 dev
[0].request("NOTE Invalid supported rates element length 33+0")
2197 long_supp_rates
= "012100112233445566778899aabbccddeeff00112233445566778899aabbccddeeff00"
2198 frame
= hdr
+ fixed
+ long_supp_rates
+ mesh_id
+ mesh_conf
+ mpm
+ ht_capab
+ ht_oper
2199 if "OK" not in dev
[0].request("MGMT_RX_PROCESS freq=2412 datarate=0 ssi_signal=-30 frame=%s" % frame
):
2200 raise Exception("MGMT_RX_PROCESS failed")
2202 dev
[0].request("NOTE Too short mesh config")
2203 short_mesh_conf
= "710401010001"
2204 frame
= hdr
+ fixed
+ supp_rates
+ mesh_id
+ short_mesh_conf
+ mpm
+ ht_capab
+ ht_oper
2205 if "OK" not in dev
[0].request("MGMT_RX_PROCESS freq=2412 datarate=0 ssi_signal=-30 frame=%s" % frame
):
2206 raise Exception("MGMT_RX_PROCESS failed")
2208 dev
[0].request("NOTE Add STA failure")
2209 frame
= hdr
+ fixed
+ supp_rates
+ ext_supp_rates
+ mesh_id
+ mesh_conf
+ mpm
+ ht_capab
+ ht_oper
2210 with
fail_test(dev
[0], 1, "wpa_driver_nl80211_sta_add"):
2211 if "OK" not in dev
[0].request("MGMT_RX_PROCESS freq=2412 datarate=0 ssi_signal=-30 frame=%s" % frame
):
2212 raise Exception("MGMT_RX_PROCESS failed")
2214 dev
[0].request("NOTE Send Action failure")
2215 with
fail_test(dev
[0], 1, "driver_nl80211_send_action"):
2216 if "OK" not in dev
[0].request("MGMT_RX_PROCESS freq=2412 datarate=0 ssi_signal=-30 frame=%s" % frame
):
2217 raise Exception("MGMT_RX_PROCESS failed")
2219 dev
[0].request("NOTE Set STA failure")
2220 addr
= "020000000101"
2221 hdr
= "d000ac00020000000000" + addr
+ addr
+ "1000"
2222 frame
= hdr
+ fixed
+ supp_rates
+ ext_supp_rates
+ mesh_id
+ mesh_conf
+ mpm
+ ht_capab
+ ht_oper
2223 with
fail_test(dev
[0], 2, "wpa_driver_nl80211_sta_add"):
2224 if "OK" not in dev
[0].request("MGMT_RX_PROCESS freq=2412 datarate=0 ssi_signal=-30 frame=%s" % frame
):
2225 raise Exception("MGMT_RX_PROCESS failed")
2227 dev
[0].request("NOTE ap_sta_add OOM")
2228 addr
= "020000000102"
2229 hdr
= "d000ac00020000000000" + addr
+ addr
+ "1000"
2230 frame
= hdr
+ fixed
+ supp_rates
+ ext_supp_rates
+ mesh_id
+ mesh_conf
+ mpm
+ ht_capab
+ ht_oper
2231 with
alloc_fail(dev
[0], 1, "ap_sta_add"):
2232 if "OK" not in dev
[0].request("MGMT_RX_PROCESS freq=2412 datarate=0 ssi_signal=-30 frame=%s" % frame
):
2233 raise Exception("MGMT_RX_PROCESS failed")
2235 dev
[0].request("NOTE hostapd_get_aid() failure")
2236 addr
= "020000000103"
2237 hdr
= "d000ac00020000000000" + addr
+ addr
+ "1000"
2238 frame
= hdr
+ fixed
+ supp_rates
+ ext_supp_rates
+ mesh_id
+ mesh_conf
+ mpm
+ ht_capab
+ ht_oper
2239 with
fail_test(dev
[0], 1, "hostapd_get_aid"):
2240 if "OK" not in dev
[0].request("MGMT_RX_PROCESS freq=2412 datarate=0 ssi_signal=-30 frame=%s" % frame
):
2241 raise Exception("MGMT_RX_PROCESS failed")
2243 if "OK" not in dev
[0].request("MESH_PEER_REMOVE 02:00:00:00:01:00"):
2244 raise Exception("Failed to remove peer")
2245 if "FAIL" not in dev
[0].request("MESH_PEER_REMOVE 02:00:00:00:01:02"):
2246 raise Exception("Unexpected MESH_PEER_REMOVE success")
2247 if "FAIL" not in dev
[1].request("MESH_PEER_REMOVE 02:00:00:00:01:02"):
2248 raise Exception("Unexpected MESH_PEER_REMOVE success(2)")
2249 if "FAIL" not in dev
[1].request("MESH_PEER_ADD 02:00:00:00:01:02"):
2250 raise Exception("Unexpected MESH_PEER_ADD success")
2252 def test_mesh_holding(dev
, apdev
):
2253 """Mesh MPM FSM and HOLDING state event OPN_ACPT"""
2254 check_mesh_support(dev
[0])
2255 add_open_mesh_network(dev
[0])
2256 add_open_mesh_network(dev
[1])
2257 check_mesh_joined_connected(dev
)
2259 addr0
= dev
[0].own_addr()
2260 addr1
= dev
[1].own_addr()
2262 dev
[0].request("SET ext_mgmt_frame_handling 1")
2263 if "OK" not in dev
[0].request("MESH_PEER_REMOVE " + addr1
):
2264 raise Exception("Failed to remove peer")
2266 rx_msg
= dev
[0].mgmt_rx()
2268 raise Exception("MGMT-RX timeout")
2269 if rx_msg
['subtype'] != 13:
2270 raise Exception("Unexpected management frame")
2271 payload
= rx_msg
['payload']
2272 (categ
, action
) = struct
.unpack('BB', payload
[0:2])
2273 if categ
!= 0x0f or action
!= 0x03:
2274 raise Exception("Did not see Mesh Peering Close")
2276 peer_lid
= binascii
.hexlify(payload
[-6:-4]).decode()
2277 my_lid
= binascii
.hexlify(payload
[-4:-2]).decode()
2279 # Drop Mesh Peering Close and instead, process an unexpected Mesh Peering
2280 # Open to trigger transmission of another Mesh Peering Close in the HOLDING
2281 # state based on an OPN_ACPT event.
2283 dst
= addr0
.replace(':', '')
2284 src
= addr1
.replace(':', '')
2285 hdr
= "d000ac00" + dst
+ src
+ src
+ "1000"
2287 supp_rates
= "010802040b168c129824"
2288 ext_supp_rates
= "3204b048606c"
2289 mesh_id
= "720e777061732d6d6573682d6f70656e"
2290 mesh_conf
= "710701010001000009"
2291 mpm
= "7504" + my_lid
+ peer_lid
2292 ht_capab
= "2d1a7c001bffff000000000000000000000100000000000000000000"
2293 ht_oper
= "3d160b000000000000000000000000000000000000000000"
2295 frame
= hdr
+ fixed
+ supp_rates
+ ext_supp_rates
+ mesh_id
+ mesh_conf
+ mpm
+ ht_capab
+ ht_oper
2296 if "OK" not in dev
[0].request("MGMT_RX_PROCESS freq=2412 datarate=0 ssi_signal=-30 frame=%s" % frame
):
2297 raise Exception("MGMT_RX_PROCESS failed")
2300 def test_mesh_cnf_rcvd_event_cls_acpt(dev
, apdev
):
2301 """Mesh peering management protocol testing - CLS_ACPT event in CNF_RCVD"""
2302 check_mesh_support(dev
[0])
2303 add_open_mesh_network(dev
[0])
2304 check_mesh_group_added(dev
[0])
2305 dev
[0].dump_monitor()
2307 dev
[0].request("SET ext_mgmt_frame_handling 1")
2308 add_open_mesh_network(dev
[1])
2309 check_mesh_group_added(dev
[1])
2311 addr0
= dev
[0].own_addr()
2312 addr1
= dev
[1].own_addr()
2314 rx_msg
= dev
[0].mgmt_rx()
2315 # Drop Mesh Peering Open
2317 rx_msg
= dev
[0].mgmt_rx()
2318 # Allow Mesh Peering Confirm to go through
2319 if "OK" not in dev
[0].request("MGMT_RX_PROCESS freq={} datarate={} ssi_signal={} frame={}".format(
2320 rx_msg
['freq'], rx_msg
['datarate'], rx_msg
['ssi_signal'], binascii
.hexlify(rx_msg
['frame']).decode())):
2321 raise Exception("MGMT_RX_PROCESS failed")
2323 payload
= rx_msg
['payload']
2324 peer_lid
= binascii
.hexlify(payload
[51:53]).decode()
2325 my_lid
= binascii
.hexlify(payload
[53:55]).decode()
2327 dst
= addr0
.replace(':', '')
2328 src
= addr1
.replace(':', '')
2329 hdr
= "d000ac00" + dst
+ src
+ src
+ "1000"
2331 mesh_id
= "720e777061732d6d6573682d6f70656e"
2332 mpm
= "75080000" + peer_lid
+ my_lid
+ "3700"
2333 frame
= hdr
+ fixed
+ mesh_id
+ mpm
2335 # Inject Mesh Peering Close to hit "state CNF_RCVD event CLS_ACPT" to
2336 # HOLDING transition.
2337 if "OK" not in dev
[0].request("MGMT_RX_PROCESS freq=2412 datarate=0 ssi_signal=-30 frame=" + frame
):
2338 raise Exception("MGMT_RX_PROCESS failed")
2340 def test_mesh_opn_snt_event_cls_acpt(dev
, apdev
):
2341 """Mesh peering management protocol testing - CLS_ACPT event in OPN_SNT"""
2342 check_mesh_support(dev
[0])
2343 add_open_mesh_network(dev
[0])
2344 check_mesh_group_added(dev
[0])
2345 dev
[0].dump_monitor()
2347 dev
[0].request("SET ext_mgmt_frame_handling 1")
2348 add_open_mesh_network(dev
[1])
2349 check_mesh_group_added(dev
[1])
2351 addr0
= dev
[0].own_addr()
2352 addr1
= dev
[1].own_addr()
2354 rx_msg
= dev
[0].mgmt_rx()
2355 # Drop Mesh Peering Open
2357 rx_msg
= dev
[0].mgmt_rx()
2358 # Drop Mesh Peering Confirm
2360 payload
= rx_msg
['payload']
2362 my_lid
= binascii
.hexlify(payload
[53:55]).decode()
2364 dst
= addr0
.replace(':', '')
2365 src
= addr1
.replace(':', '')
2366 hdr
= "d000ac00" + dst
+ src
+ src
+ "1000"
2368 mesh_id
= "720e777061732d6d6573682d6f70656e"
2369 mpm
= "75080000" + peer_lid
+ my_lid
+ "3700"
2370 frame
= hdr
+ fixed
+ mesh_id
+ mpm
2372 # Inject Mesh Peering Close to hit "state OPN_SNTevent CLS_ACPT" to
2373 # HOLDING transition.
2374 if "OK" not in dev
[0].request("MGMT_RX_PROCESS freq=2412 datarate=0 ssi_signal=-30 frame=" + frame
):
2375 raise Exception("MGMT_RX_PROCESS failed")
2377 def test_mesh_select_network(dev
):
2378 """Mesh network and SELECT_NETWORK"""
2379 check_mesh_support(dev
[0])
2380 id0
= add_open_mesh_network(dev
[0], start
=False)
2381 id1
= add_open_mesh_network(dev
[1], start
=False)
2382 dev
[0].select_network(id0
)
2383 dev
[1].select_network(id1
)
2384 check_mesh_joined_connected(dev
, connectivity
=True)
2386 def test_mesh_forwarding(dev
):
2387 """Mesh with two stations that can't reach each other directly"""
2389 set_group_map(dev
[0], 1)
2390 set_group_map(dev
[1], 3)
2391 set_group_map(dev
[2], 2)
2392 check_mesh_support(dev
[0])
2394 add_open_mesh_network(dev
[i
])
2395 check_mesh_group_added(dev
[i
])
2397 check_mesh_peer_connected(dev
[i
])
2399 hwsim_utils
.test_connectivity(dev
[0], dev
[1])
2400 hwsim_utils
.test_connectivity(dev
[1], dev
[2])
2401 hwsim_utils
.test_connectivity(dev
[0], dev
[2])
2404 set_group_map(dev
[0], 1)
2405 set_group_map(dev
[1], 1)
2406 set_group_map(dev
[2], 1)
2408 def test_mesh_forwarding_secure(dev
):
2409 """Mesh with two stations that can't reach each other directly (RSN)"""
2410 check_mesh_support(dev
[0], secure
=True)
2412 set_group_map(dev
[0], 1)
2413 set_group_map(dev
[1], 3)
2414 set_group_map(dev
[2], 2)
2416 dev
[i
].request("SET sae_groups ")
2417 id = add_mesh_secure_net(dev
[i
])
2418 dev
[i
].mesh_group_add(id)
2419 check_mesh_group_added(dev
[i
])
2421 check_mesh_peer_connected(dev
[i
])
2423 hwsim_utils
.test_connectivity(dev
[0], dev
[1])
2424 hwsim_utils
.test_connectivity(dev
[1], dev
[2])
2425 hwsim_utils
.test_connectivity(dev
[0], dev
[2])
2428 set_group_map(dev
[0], 1)
2429 set_group_map(dev
[1], 1)
2430 set_group_map(dev
[2], 1)
2432 def test_mesh_sae_anti_clogging(dev
, apdev
):
2433 """Mesh using SAE and anti-clogging"""
2435 run_mesh_sae_anti_clogging(dev
, apdev
)
2437 stop_monitor(apdev
[1]["ifname"])
2439 def run_mesh_sae_anti_clogging(dev
, apdev
):
2440 check_mesh_support(dev
[0], secure
=True)
2441 check_mesh_support(dev
[1], secure
=True)
2442 check_mesh_support(dev
[2], secure
=True)
2444 sock
= start_monitor(apdev
[1]["ifname"])
2445 radiotap
= radiotap_build()
2447 dev
[0].request("SET sae_groups 21")
2448 id = add_mesh_secure_net(dev
[0])
2449 dev
[0].mesh_group_add(id)
2450 check_mesh_group_added(dev
[0])
2452 # This flood of SAE authentication frames is from not yet known mesh STAs,
2453 # so the messages get dropped.
2454 addr0
= binascii
.unhexlify(dev
[0].own_addr().replace(':', ''))
2456 addr
= binascii
.unhexlify("f2%010x" % i
)
2457 frame
= build_sae_commit(addr0
, addr
)
2458 sock
.send(radiotap
+ frame
)
2460 dev
[1].request("SET sae_groups 21")
2461 id = add_mesh_secure_net(dev
[1])
2462 dev
[1].mesh_group_add(id)
2463 check_mesh_group_added(dev
[1])
2464 check_mesh_connected2(dev
)
2466 # Inject Beacon frames to make the sources of the second flood known to the
2468 bcn1
= binascii
.unhexlify("80000000" + "ffffffffffff")
2469 bcn2
= binascii
.unhexlify("0000dd20c44015840500e80310000000010882848b968c1298240301010504000200003204b048606c30140100000fac040100000fac040100000fac0800002d1afe131bffff0000000000000000000001000000000000000000003d16010000000000ffff0000000000000000000000000000720d777061732d6d6573682d736563710701010001010009")
2471 addr
= binascii
.unhexlify("f4%010x" % i
)
2472 frame
= bcn1
+ addr
+ addr
+ bcn2
2473 sock
.send(radiotap
+ frame
)
2475 # This flood of SAE authentication frames is from known mesh STAs, so the
2476 # target will need to process these.
2478 addr
= binascii
.unhexlify("f4%010x" % i
)
2479 frame
= build_sae_commit(addr0
, addr
)
2480 sock
.send(radiotap
+ frame
)
2482 dev
[2].request("SET sae_groups 21")
2483 id = add_mesh_secure_net(dev
[2])
2484 dev
[2].mesh_group_add(id)
2485 check_mesh_group_added(dev
[2])
2486 check_mesh_peer_connected(dev
[2])
2487 check_mesh_peer_connected(dev
[0])
2489 def test_mesh_link_probe(dev
, apdev
, params
):
2490 """Mesh link probing"""
2491 addr0
= dev
[0].own_addr()
2492 addr1
= dev
[1].own_addr()
2493 addr2
= dev
[2].own_addr()
2495 check_mesh_support(dev
[0])
2497 add_open_mesh_network(dev
[i
])
2498 check_mesh_group_added(dev
[i
])
2500 check_mesh_peer_connected(dev
[i
])
2502 dev
[0].request("MESH_LINK_PROBE " + addr1
)
2503 dev
[0].request("MESH_LINK_PROBE " + addr2
+ " payload=aabbccdd")
2504 dev
[1].request("MESH_LINK_PROBE " + addr0
+ " payload=bbccddee")
2505 dev
[1].request("MESH_LINK_PROBE " + addr2
+ " payload=ccddeeff")
2506 dev
[2].request("MESH_LINK_PROBE " + addr0
+ " payload=aaaa")
2507 dev
[2].request("MESH_LINK_PROBE " + addr1
+ " payload=000102030405060708090a0b0c0d0e0f")
2509 capfile
= os
.path
.join(params
['logdir'], "hwsim0.pcapng")
2510 filt
= "wlan.fc == 0x8803"
2512 out
= run_tshark(capfile
, filt
, ["wlan.sa", "wlan.da"])
2513 if len(out
.splitlines()) >= 6:
2516 for i
in [addr0
, addr1
, addr2
]:
2517 for j
in [addr0
, addr1
, addr2
]:
2520 if i
+ "\t" + j
not in out
:
2521 raise Exception("Did not see probe %s --> %s" % (i
, j
))