Updated through tag hostap_2_5 from git://w1.fi/hostap.git
[mech_eap.git] / libeap / tests / hwsim / test_ap_csa.py
1 # AP CSA tests
2 # Copyright (c) 2013, Luciano Coelho <luciano.coelho@intel.com>
3 #
4 # This software may be distributed under the terms of the BSD license.
5 # See README for more details.
6
7 import time
8 import logging
9 logger = logging.getLogger()
10
11 import hwsim_utils
12 import hostapd
13 from utils import HwsimSkip
14
15 def connect(dev, apdev):
16     params = { "ssid": "ap-csa",
17                "channel": "1" }
18     ap = hostapd.add_ap(apdev[0]['ifname'], params)
19     dev.connect("ap-csa", key_mgmt="NONE")
20     return ap
21
22 def switch_channel(ap, count, freq):
23     ap.request("CHAN_SWITCH " + str(count) + " " + str(freq))
24     ev = ap.wait_event(["AP-CSA-FINISHED"], timeout=10)
25     if ev is None:
26         raise Exception("CSA finished event timed out")
27     if "freq=" + str(freq) not in ev:
28         raise Exception("Unexpected channel in CSA finished event")
29     time.sleep(0.1)
30
31 # This function checks whether the provided dev, which may be either
32 # WpaSupplicant or Hostapd supports CSA.
33 def csa_supported(dev):
34     res = dev.get_driver_status()
35     if (int(res['capa.flags'], 0) & 0x80000000) == 0:
36         raise HwsimSkip("CSA not supported")
37
38 def test_ap_csa_1_switch(dev, apdev):
39     """AP Channel Switch, one switch"""
40     csa_supported(dev[0])
41     ap = connect(dev[0], apdev)
42
43     hwsim_utils.test_connectivity(dev[0], ap)
44     switch_channel(ap, 10, 2462)
45     hwsim_utils.test_connectivity(dev[0], ap)
46
47 def test_ap_csa_2_switches(dev, apdev):
48     """AP Channel Switch, two switches"""
49     csa_supported(dev[0])
50     ap = connect(dev[0], apdev)
51
52     hwsim_utils.test_connectivity(dev[0], ap)
53     switch_channel(ap, 10, 2462)
54     hwsim_utils.test_connectivity(dev[0], ap)
55     switch_channel(ap, 10, 2412)
56     hwsim_utils.test_connectivity(dev[0], ap)
57
58 def test_ap_csa_1_switch_count_0(dev, apdev):
59     """AP Channel Switch, one switch with count 0"""
60     csa_supported(dev[0])
61     ap = connect(dev[0], apdev)
62
63     hwsim_utils.test_connectivity(dev[0], ap)
64     switch_channel(ap, 0, 2462)
65     # this does not result in CSA currently, so do not bother checking
66     # connectivity
67
68 def test_ap_csa_2_switches_count_0(dev, apdev):
69     """AP Channel Switch, two switches with count 0"""
70     csa_supported(dev[0])
71     ap = connect(dev[0], apdev)
72
73     hwsim_utils.test_connectivity(dev[0], ap)
74     switch_channel(ap, 0, 2462)
75     # this does not result in CSA currently, so do not bother checking
76     # connectivity
77     switch_channel(ap, 0, 2412)
78     # this does not result in CSA currently, so do not bother checking
79     # connectivity
80
81 def test_ap_csa_1_switch_count_1(dev, apdev):
82     """AP Channel Switch, one switch with count 1"""
83     csa_supported(dev[0])
84     ap = connect(dev[0], apdev)
85
86     hwsim_utils.test_connectivity(dev[0], ap)
87     switch_channel(ap, 1, 2462)
88     # this does not result in CSA currently, so do not bother checking
89     # connectivity
90
91 def test_ap_csa_2_switches_count_1(dev, apdev):
92     """AP Channel Switch, two switches with count 1"""
93     csa_supported(dev[0])
94     ap = connect(dev[0], apdev)
95
96     hwsim_utils.test_connectivity(dev[0], ap)
97     switch_channel(ap, 1, 2462)
98     # this does not result in CSA currently, so do not bother checking
99     # connectivity
100     switch_channel(ap, 1, 2412)
101     # this does not result in CSA currently, so do not bother checking
102     # connectivity
103
104 def test_ap_csa_1_switch_count_2(dev, apdev):
105     """AP Channel Switch, one switch with count 2"""
106     csa_supported(dev[0])
107     ap = connect(dev[0], apdev)
108
109     hwsim_utils.test_connectivity(dev[0], ap)
110     switch_channel(ap, 2, 2462)
111     hwsim_utils.test_connectivity(dev[0], ap)