tests: Hotspot 2.0 multi-cred and same sp_priority
[mech_eap.git] / tests / hwsim / test_wep.py
1 # WEP tests
2 # Copyright (c) 2014, Jouni Malinen <j@w1.fi>
3 #
4 # This software may be distributed under the terms of the BSD license.
5 # See README for more details.
6
7 from remotehost import remote_compatible
8 import hostapd
9 import hwsim_utils
10
11 @remote_compatible
12 def test_wep_open_auth(dev, apdev):
13     """WEP Open System authentication"""
14     hapd = hostapd.add_ap(apdev[0],
15                           { "ssid": "wep-open",
16                             "wep_key0": '"hello"' })
17     dev[0].flush_scan_cache()
18     dev[0].connect("wep-open", key_mgmt="NONE", wep_key0='"hello"',
19                    scan_freq="2412")
20     hwsim_utils.test_connectivity(dev[0], hapd)
21     if "[WEP]" not in dev[0].request("SCAN_RESULTS"):
22         raise Exception("WEP flag not indicated in scan results")
23
24     bss = dev[0].get_bss(apdev[0]['bssid'])
25     if 'flags' not in bss:
26         raise Exception("Could not get BSS flags from BSS table")
27     if "[WEP]" not in bss['flags']:
28         raise Exception("Unexpected BSS flags: " + bss['flags'])
29
30 @remote_compatible
31 def test_wep_shared_key_auth(dev, apdev):
32     """WEP Shared Key authentication"""
33     hapd = hostapd.add_ap(apdev[0],
34                           { "ssid": "wep-shared-key",
35                             "wep_key0": '"hello12345678"',
36                             "auth_algs": "2" })
37     dev[0].connect("wep-shared-key", key_mgmt="NONE", auth_alg="SHARED",
38                    wep_key0='"hello12345678"',
39                    scan_freq="2412")
40     hwsim_utils.test_connectivity(dev[0], hapd)
41     dev[1].connect("wep-shared-key", key_mgmt="NONE", auth_alg="OPEN SHARED",
42                    wep_key0='"hello12345678"',
43                    scan_freq="2412")
44
45 @remote_compatible
46 def test_wep_shared_key_auth_not_allowed(dev, apdev):
47     """WEP Shared Key authentication not allowed"""
48     hostapd.add_ap(apdev[0],
49                    { "ssid": "wep-shared-key",
50                      "wep_key0": '"hello12345678"',
51                      "auth_algs": "1" })
52     dev[0].connect("wep-shared-key", key_mgmt="NONE", auth_alg="SHARED",
53                    wep_key0='"hello12345678"',
54                    scan_freq="2412", wait_connect=False)
55     ev = dev[0].wait_event(["CTRL-EVENT-CONNECTED"], timeout=1)
56     if ev is not None:
57         raise Exception("Unexpected association")
58
59 def test_wep_shared_key_auth_multi_key(dev, apdev):
60     """WEP Shared Key authentication with multiple keys"""
61     hapd = hostapd.add_ap(apdev[0],
62                           { "ssid": "wep-shared-key",
63                             "wep_key0": '"hello12345678"',
64                             "wep_key1": '"other12345678"',
65                             "auth_algs": "2" })
66     dev[0].connect("wep-shared-key", key_mgmt="NONE", auth_alg="SHARED",
67                    wep_key0='"hello12345678"',
68                    scan_freq="2412")
69     dev[1].connect("wep-shared-key", key_mgmt="NONE", auth_alg="SHARED",
70                    wep_key0='"hello12345678"',
71                    wep_key1='"other12345678"',
72                    wep_tx_keyidx="1",
73                    scan_freq="2412")
74     id = dev[2].connect("wep-shared-key", key_mgmt="NONE", auth_alg="SHARED",
75                         wep_key0='"hello12345678"',
76                         wep_key1='"other12345678"',
77                         wep_tx_keyidx="0",
78                         scan_freq="2412")
79     hwsim_utils.test_connectivity(dev[0], hapd)
80     hwsim_utils.test_connectivity(dev[1], hapd)
81     hwsim_utils.test_connectivity(dev[2], hapd)
82
83     dev[2].set_network(id, "wep_tx_keyidx", "1")
84     dev[2].request("REASSOCIATE")
85     dev[2].wait_connected(timeout=10, error="Reassociation timed out")
86     hwsim_utils.test_connectivity(dev[2], hapd)