Updated to hostap_2_6
[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 logging
8 logger = logging.getLogger()
9 import subprocess
10
11 from remotehost import remote_compatible
12 import hostapd
13 import hwsim_utils
14
15 @remote_compatible
16 def test_wep_open_auth(dev, apdev):
17     """WEP Open System authentication"""
18     hapd = hostapd.add_ap(apdev[0],
19                           { "ssid": "wep-open",
20                             "wep_key0": '"hello"' })
21     dev[0].flush_scan_cache()
22     dev[0].connect("wep-open", key_mgmt="NONE", wep_key0='"hello"',
23                    scan_freq="2412")
24     hwsim_utils.test_connectivity(dev[0], hapd)
25     if "[WEP]" not in dev[0].request("SCAN_RESULTS"):
26         raise Exception("WEP flag not indicated in scan results")
27
28     bss = dev[0].get_bss(apdev[0]['bssid'])
29     if 'flags' not in bss:
30         raise Exception("Could not get BSS flags from BSS table")
31     if "[WEP]" not in bss['flags']:
32         raise Exception("Unexpected BSS flags: " + bss['flags'])
33
34 @remote_compatible
35 def test_wep_shared_key_auth(dev, apdev):
36     """WEP Shared Key authentication"""
37     hapd = hostapd.add_ap(apdev[0],
38                           { "ssid": "wep-shared-key",
39                             "wep_key0": '"hello12345678"',
40                             "auth_algs": "2" })
41     dev[0].connect("wep-shared-key", key_mgmt="NONE", auth_alg="SHARED",
42                    wep_key0='"hello12345678"',
43                    scan_freq="2412")
44     hwsim_utils.test_connectivity(dev[0], hapd)
45     dev[1].connect("wep-shared-key", key_mgmt="NONE", auth_alg="OPEN SHARED",
46                    wep_key0='"hello12345678"',
47                    scan_freq="2412")
48
49 @remote_compatible
50 def test_wep_shared_key_auth_not_allowed(dev, apdev):
51     """WEP Shared Key authentication not allowed"""
52     hostapd.add_ap(apdev[0],
53                    { "ssid": "wep-shared-key",
54                      "wep_key0": '"hello12345678"',
55                      "auth_algs": "1" })
56     dev[0].connect("wep-shared-key", key_mgmt="NONE", auth_alg="SHARED",
57                    wep_key0='"hello12345678"',
58                    scan_freq="2412", wait_connect=False)
59     ev = dev[0].wait_event(["CTRL-EVENT-CONNECTED"], timeout=1)
60     if ev is not None:
61         raise Exception("Unexpected association")
62
63 def test_wep_shared_key_auth_multi_key(dev, apdev):
64     """WEP Shared Key authentication with multiple keys"""
65     hapd = hostapd.add_ap(apdev[0],
66                           { "ssid": "wep-shared-key",
67                             "wep_key0": '"hello12345678"',
68                             "wep_key1": '"other12345678"',
69                             "auth_algs": "2" })
70     dev[0].connect("wep-shared-key", key_mgmt="NONE", auth_alg="SHARED",
71                    wep_key0='"hello12345678"',
72                    scan_freq="2412")
73     dev[1].connect("wep-shared-key", key_mgmt="NONE", auth_alg="SHARED",
74                    wep_key0='"hello12345678"',
75                    wep_key1='"other12345678"',
76                    wep_tx_keyidx="1",
77                    scan_freq="2412")
78     id = dev[2].connect("wep-shared-key", key_mgmt="NONE", auth_alg="SHARED",
79                         wep_key0='"hello12345678"',
80                         wep_key1='"other12345678"',
81                         wep_tx_keyidx="0",
82                         scan_freq="2412")
83     hwsim_utils.test_connectivity(dev[0], hapd)
84     hwsim_utils.test_connectivity(dev[1], hapd)
85     hwsim_utils.test_connectivity(dev[2], hapd)
86
87     dev[2].set_network(id, "wep_tx_keyidx", "1")
88     dev[2].request("REASSOCIATE")
89     dev[2].wait_connected(timeout=10, error="Reassociation timed out")
90     hwsim_utils.test_connectivity(dev[2], hapd)
91
92 def test_wep_ht_vht(dev, apdev):
93     """WEP and HT/VHT"""
94     dev[0].flush_scan_cache()
95     try:
96         hapd = None
97         params = { "ssid": "test-vht40-wep",
98                    "country_code": "SE",
99                    "hw_mode": "a",
100                    "channel": "36",
101                    "ieee80211n": "1",
102                    "ieee80211ac": "1",
103                    "ht_capab": "[HT40+]",
104                    "vht_capab": "",
105                    "vht_oper_chwidth": "0",
106                    "vht_oper_centr_freq_seg0_idx": "0",
107                    "wep_key0": '"hello"' }
108         hapd = hostapd.add_ap(apdev[0], params)
109         dev[0].connect("test-vht40-wep", scan_freq="5180", key_mgmt="NONE",
110                        wep_key0='"hello"')
111         hwsim_utils.test_connectivity(dev[0], hapd)
112         status = hapd.get_status()
113         logger.info("hostapd STATUS: " + str(status))
114         if status["ieee80211n"] != "0":
115             raise Exception("Unexpected STATUS ieee80211n value")
116         if status["ieee80211ac"] != "0":
117             raise Exception("Unexpected STATUS ieee80211ac value")
118         if status["secondary_channel"] != "0":
119             raise Exception("Unexpected STATUS secondary_channel value")
120     finally:
121         dev[0].request("DISCONNECT")
122         if hapd:
123             hapd.request("DISABLE")
124         subprocess.call(['iw', 'reg', 'set', '00'])
125         dev[0].flush_scan_cache()