tests: MBO cellular data capability update
[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 import time
13
14 from tshark import run_tshark
15
16 def test_mbo_assoc_disallow(dev, apdev, params):
17     hapd1 = hostapd.add_ap(apdev[0]['ifname'], { "ssid": "MBO", "mbo": "1" })
18     hapd2 = hostapd.add_ap(apdev[1]['ifname'], { "ssid": "MBO", "mbo": "1" })
19
20     logger.debug("Set mbo_assoc_disallow with invalid value")
21     if "FAIL" not in hapd1.request("SET mbo_assoc_disallow 2"):
22         raise Exception("Set mbo_assoc_disallow for AP1 succeeded unexpectedly with value 2")
23
24     logger.debug("Disallow associations to AP1 and allow association to AP2")
25     if "OK" not in hapd1.request("SET mbo_assoc_disallow 1"):
26         raise Exception("Failed to set mbo_assoc_disallow for AP1")
27     if "OK" not in hapd2.request("SET mbo_assoc_disallow 0"):
28         raise Exception("Failed to set mbo_assoc_disallow for AP2")
29
30     dev[0].connect("MBO", key_mgmt="NONE", scan_freq="2412")
31
32     out = run_tshark(os.path.join(params['logdir'], "hwsim0.pcapng"),
33                      "wlan.fc.type == 0 && wlan.fc.type_subtype == 0x00",
34                      wait=False)
35     if "Destination address: " + hapd1.own_addr() in out:
36         raise Exception("Association request sent to disallowed AP")
37
38     timestamp = run_tshark(os.path.join(params['logdir'], "hwsim0.pcapng"),
39                            "wlan.fc.type_subtype == 0x00",
40                            display=['frame.time'], wait=False)
41
42     logger.debug("Allow associations to AP1 and disallow assications to AP2")
43     if "OK" not in hapd1.request("SET mbo_assoc_disallow 0"):
44         raise Exception("Failed to set mbo_assoc_disallow for AP1")
45     if "OK" not in hapd2.request("SET mbo_assoc_disallow 1"):
46         raise Exception("Failed to set mbo_assoc_disallow for AP2")
47
48     dev[0].request("DISCONNECT")
49     dev[0].wait_disconnected()
50
51     # Force new scan, so the assoc_disallowed indication is updated */
52     dev[0].request("FLUSH")
53
54     dev[0].connect("MBO", key_mgmt="NONE", scan_freq="2412")
55
56     filter = 'wlan.fc.type == 0 && wlan.fc.type_subtype == 0x00 && frame.time > "' + timestamp.rstrip() + '"'
57     out = run_tshark(os.path.join(params['logdir'], "hwsim0.pcapng"),
58                      filter, wait=False)
59     if "Destination address: " + hapd2.own_addr() in out:
60         raise Exception("Association request sent to disallowed AP 2")
61
62 def test_mbo_cell_capa_update(dev, apdev):
63     """MBO cellular data capability update"""
64     ssid = "test-wnm-mbo"
65     params = { 'ssid': ssid, 'mbo': '1' }
66     hapd = hostapd.add_ap(apdev[0]['ifname'], params)
67     bssid = apdev[0]['bssid']
68     if "OK" not in dev[0].request("SET mbo_cell_capa 1"):
69         raise Exception("Failed to set STA as cellular data capable")
70
71     dev[0].connect(ssid, key_mgmt="NONE", scan_freq="2412")
72
73     addr = dev[0].own_addr()
74     sta = hapd.get_sta(addr)
75     if 'mbo_cell_capa' not in sta or sta['mbo_cell_capa'] != '1':
76         raise Exception("mbo_cell_capa missing after association")
77
78     if "OK" not in dev[0].request("SET mbo_cell_capa 3"):
79         raise Exception("Failed to set STA as cellular data not-capable")
80
81     time.sleep(0.2)
82     sta = hapd.get_sta(addr)
83     if 'mbo_cell_capa' not in sta:
84         raise Exception("mbo_cell_capa missing after update")
85     if sta['mbo_cell_capa'] != '3':
86         raise Exception("mbo_cell_capa not updated properly")