tests: MBO association disallowed indication
[mech_eap.git] / tests / hwsim / test_mbo.py
1 # MBO tests
2 # Copyright (c) 2016, Intel Deutschland GmbH
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
10 import hostapd
11 import os
12
13 from tshark import run_tshark
14
15 def test_mbo_assoc_disallow(dev, apdev, params):
16     hapd1 = hostapd.add_ap(apdev[0]['ifname'], { "ssid": "MBO", "mbo": "1" })
17     hapd2 = hostapd.add_ap(apdev[1]['ifname'], { "ssid": "MBO", "mbo": "1" })
18
19     logger.debug("Set mbo_assoc_disallow with invalid value")
20     if "FAIL" not in hapd1.request("SET mbo_assoc_disallow 2"):
21         raise Exception("Set mbo_assoc_disallow for AP1 succeeded unexpectedly with value 2")
22
23     logger.debug("Disallow associations to AP1 and allow association to AP2")
24     if "OK" not in hapd1.request("SET mbo_assoc_disallow 1"):
25         raise Exception("Failed to set mbo_assoc_disallow for AP1")
26     if "OK" not in hapd2.request("SET mbo_assoc_disallow 0"):
27         raise Exception("Failed to set mbo_assoc_disallow for AP2")
28
29     dev[0].connect("MBO", key_mgmt="NONE", scan_freq="2412")
30
31     out = run_tshark(os.path.join(params['logdir'], "hwsim0.pcapng"),
32                      "wlan.fc.type == 0 && wlan.fc.type_subtype == 0x00",
33                      wait=False)
34     if "Destination address: " + hapd1.own_addr() in out:
35         raise Exception("Association request sent to disallowed AP")
36
37     timestamp = run_tshark(os.path.join(params['logdir'], "hwsim0.pcapng"),
38                            "wlan.fc.type_subtype == 0x00",
39                            display=['frame.time'], wait=False)
40
41     logger.debug("Allow associations to AP1 and disallow assications to AP2")
42     if "OK" not in hapd1.request("SET mbo_assoc_disallow 0"):
43         raise Exception("Failed to set mbo_assoc_disallow for AP1")
44     if "OK" not in hapd2.request("SET mbo_assoc_disallow 1"):
45         raise Exception("Failed to set mbo_assoc_disallow for AP2")
46
47     dev[0].request("DISCONNECT")
48     dev[0].wait_disconnected()
49
50     # Force new scan, so the assoc_disallowed indication is updated */
51     dev[0].request("FLUSH")
52
53     dev[0].connect("MBO", key_mgmt="NONE", scan_freq="2412")
54
55     filter = 'wlan.fc.type == 0 && wlan.fc.type_subtype == 0x00 && frame.time > "' + timestamp.rstrip() + '"'
56     out = run_tshark(os.path.join(params['logdir'], "hwsim0.pcapng"),
57                      filter, wait=False)
58     if "Destination address: " + hapd2.own_addr() in out:
59         raise Exception("Association request sent to disallowed AP 2")