Updated through tag hostap_2_5 from git://w1.fi/hostap.git
[mech_eap.git] / libeap / 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 import hostapd
8 import hwsim_utils
9
10 def test_wep_open_auth(dev, apdev):
11     """WEP Open System authentication"""
12     hapd = hostapd.add_ap(apdev[0]['ifname'],
13                           { "ssid": "wep-open",
14                             "wep_key0": '"hello"' })
15     dev[0].flush_scan_cache()
16     dev[0].connect("wep-open", key_mgmt="NONE", wep_key0='"hello"',
17                    scan_freq="2412")
18     hwsim_utils.test_connectivity(dev[0], hapd)
19     if "[WEP]" not in dev[0].request("SCAN_RESULTS"):
20         raise Exception("WEP flag not indicated in scan results")
21
22     bss = dev[0].get_bss(apdev[0]['bssid'])
23     if 'flags' not in bss:
24         raise Exception("Could not get BSS flags from BSS table")
25     if "[WEP]" not in bss['flags']:
26         raise Exception("Unexpected BSS flags: " + bss['flags'])
27
28 def test_wep_shared_key_auth(dev, apdev):
29     """WEP Shared Key authentication"""
30     hapd = hostapd.add_ap(apdev[0]['ifname'],
31                           { "ssid": "wep-shared-key",
32                             "wep_key0": '"hello12345678"',
33                             "auth_algs": "2" })
34     dev[0].connect("wep-shared-key", key_mgmt="NONE", auth_alg="SHARED",
35                    wep_key0='"hello12345678"',
36                    scan_freq="2412")
37     hwsim_utils.test_connectivity(dev[0], hapd)
38     dev[1].connect("wep-shared-key", key_mgmt="NONE", auth_alg="OPEN SHARED",
39                    wep_key0='"hello12345678"',
40                    scan_freq="2412")
41
42 def test_wep_shared_key_auth_not_allowed(dev, apdev):
43     """WEP Shared Key authentication not allowed"""
44     hostapd.add_ap(apdev[0]['ifname'],
45                    { "ssid": "wep-shared-key",
46                      "wep_key0": '"hello12345678"',
47                      "auth_algs": "1" })
48     dev[0].connect("wep-shared-key", key_mgmt="NONE", auth_alg="SHARED",
49                    wep_key0='"hello12345678"',
50                    scan_freq="2412", wait_connect=False)
51     ev = dev[0].wait_event(["CTRL-EVENT-CONNECTED"], timeout=1)
52     if ev is not None:
53         raise Exception("Unexpected association")
54
55 def test_wep_shared_key_auth_multi_key(dev, apdev):
56     """WEP Shared Key authentication with multiple keys"""
57     hapd = hostapd.add_ap(apdev[0]['ifname'],
58                           { "ssid": "wep-shared-key",
59                             "wep_key0": '"hello12345678"',
60                             "wep_key1": '"other12345678"',
61                             "auth_algs": "2" })
62     dev[0].connect("wep-shared-key", key_mgmt="NONE", auth_alg="SHARED",
63                    wep_key0='"hello12345678"',
64                    scan_freq="2412")
65     dev[1].connect("wep-shared-key", key_mgmt="NONE", auth_alg="SHARED",
66                    wep_key0='"hello12345678"',
67                    wep_key1='"other12345678"',
68                    wep_tx_keyidx="1",
69                    scan_freq="2412")
70     id = dev[2].connect("wep-shared-key", key_mgmt="NONE", auth_alg="SHARED",
71                         wep_key0='"hello12345678"',
72                         wep_key1='"other12345678"',
73                         wep_tx_keyidx="0",
74                         scan_freq="2412")
75     hwsim_utils.test_connectivity(dev[0], hapd)
76     hwsim_utils.test_connectivity(dev[1], hapd)
77     hwsim_utils.test_connectivity(dev[2], hapd)
78
79     dev[2].set_network(id, "wep_tx_keyidx", "1")
80     dev[2].request("REASSOCIATE")
81     dev[2].wait_connected(timeout=10, error="Reassociation timed out")
82     hwsim_utils.test_connectivity(dev[2], hapd)