]> git.ipfire.org Git - thirdparty/hostap.git/blob - tests/hwsim/test_wep.py
HE: MCS size is always a minimum of 4 bytes
[thirdparty/hostap.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 import logging
8 logger = logging.getLogger()
9 import subprocess
10
11 from remotehost import remote_compatible
12 import hostapd
13 import hwsim_utils
14 from utils import clear_regdom
15
16 @remote_compatible
17 def test_wep_open_auth(dev, apdev):
18 """WEP Open System authentication"""
19 hapd = hostapd.add_ap(apdev[0],
20 {"ssid": "wep-open",
21 "wep_key0": '"hello"'})
22 dev[0].flush_scan_cache()
23 dev[0].connect("wep-open", key_mgmt="NONE", wep_key0='"hello"',
24 scan_freq="2412")
25 hwsim_utils.test_connectivity(dev[0], hapd)
26 if "[WEP]" not in dev[0].request("SCAN_RESULTS"):
27 raise Exception("WEP flag not indicated in scan results")
28
29 bss = dev[0].get_bss(apdev[0]['bssid'])
30 if 'flags' not in bss:
31 raise Exception("Could not get BSS flags from BSS table")
32 if "[WEP]" not in bss['flags']:
33 raise Exception("Unexpected BSS flags: " + bss['flags'])
34
35 @remote_compatible
36 def test_wep_shared_key_auth(dev, apdev):
37 """WEP Shared Key authentication"""
38 hapd = hostapd.add_ap(apdev[0],
39 {"ssid": "wep-shared-key",
40 "wep_key0": '"hello12345678"',
41 "auth_algs": "2"})
42 dev[0].connect("wep-shared-key", key_mgmt="NONE", auth_alg="SHARED",
43 wep_key0='"hello12345678"',
44 scan_freq="2412")
45 hwsim_utils.test_connectivity(dev[0], hapd)
46 dev[1].connect("wep-shared-key", key_mgmt="NONE", auth_alg="OPEN SHARED",
47 wep_key0='"hello12345678"',
48 scan_freq="2412")
49
50 @remote_compatible
51 def test_wep_shared_key_auth_not_allowed(dev, apdev):
52 """WEP Shared Key authentication not allowed"""
53 hostapd.add_ap(apdev[0],
54 {"ssid": "wep-shared-key",
55 "wep_key0": '"hello12345678"',
56 "auth_algs": "1"})
57 dev[0].connect("wep-shared-key", key_mgmt="NONE", auth_alg="SHARED",
58 wep_key0='"hello12345678"',
59 scan_freq="2412", wait_connect=False)
60 ev = dev[0].wait_event(["CTRL-EVENT-CONNECTED"], timeout=1)
61 if ev is not None:
62 raise Exception("Unexpected association")
63
64 def test_wep_shared_key_auth_multi_key(dev, apdev):
65 """WEP Shared Key authentication with multiple keys"""
66 hapd = hostapd.add_ap(apdev[0],
67 {"ssid": "wep-shared-key",
68 "wep_key0": '"hello12345678"',
69 "wep_key1": '"other12345678"',
70 "auth_algs": "2"})
71 dev[0].connect("wep-shared-key", key_mgmt="NONE", auth_alg="SHARED",
72 wep_key0='"hello12345678"',
73 scan_freq="2412")
74 dev[1].connect("wep-shared-key", key_mgmt="NONE", auth_alg="SHARED",
75 wep_key0='"hello12345678"',
76 wep_key1='"other12345678"',
77 wep_tx_keyidx="1",
78 scan_freq="2412")
79 id = dev[2].connect("wep-shared-key", key_mgmt="NONE", auth_alg="SHARED",
80 wep_key0='"hello12345678"',
81 wep_key1='"other12345678"',
82 wep_tx_keyidx="0",
83 scan_freq="2412")
84 hwsim_utils.test_connectivity(dev[0], hapd)
85 hwsim_utils.test_connectivity(dev[1], hapd)
86 hwsim_utils.test_connectivity(dev[2], hapd)
87
88 dev[2].set_network(id, "wep_tx_keyidx", "1")
89 dev[2].request("REASSOCIATE")
90 dev[2].wait_connected(timeout=10, error="Reassociation timed out")
91 hwsim_utils.test_connectivity(dev[2], hapd)
92
93 def test_wep_ht_vht(dev, apdev):
94 """WEP and HT/VHT"""
95 dev[0].flush_scan_cache()
96 try:
97 hapd = None
98 params = {"ssid": "test-vht40-wep",
99 "country_code": "SE",
100 "hw_mode": "a",
101 "channel": "36",
102 "ieee80211n": "1",
103 "ieee80211ac": "1",
104 "ht_capab": "[HT40+]",
105 "vht_capab": "",
106 "vht_oper_chwidth": "0",
107 "vht_oper_centr_freq_seg0_idx": "0",
108 "wep_key0": '"hello"'}
109 hapd = hostapd.add_ap(apdev[0], params)
110 dev[0].connect("test-vht40-wep", scan_freq="5180", key_mgmt="NONE",
111 wep_key0='"hello"')
112 hwsim_utils.test_connectivity(dev[0], hapd)
113 status = hapd.get_status()
114 logger.info("hostapd STATUS: " + str(status))
115 if status["ieee80211n"] != "0":
116 raise Exception("Unexpected STATUS ieee80211n value")
117 if status["ieee80211ac"] != "0":
118 raise Exception("Unexpected STATUS ieee80211ac value")
119 if status["secondary_channel"] != "0":
120 raise Exception("Unexpected STATUS secondary_channel value")
121 finally:
122 dev[0].request("DISCONNECT")
123 clear_regdom(hapd, dev)
124
125 def test_wep_ifdown(dev, apdev):
126 """AP with WEP and external ifconfig down"""
127 hapd = hostapd.add_ap(apdev[0],
128 {"ssid": "wep-open",
129 "wep_key0": '"hello"'})
130 dev[0].flush_scan_cache()
131 id = dev[0].connect("wep-open", key_mgmt="NONE", wep_key0='"hello"',
132 scan_freq="2412")
133 hwsim_utils.test_connectivity(dev[0], hapd)
134 dev[0].request("DISCONNECT")
135 dev[0].wait_disconnected()
136
137 hapd.cmd_execute(['ip', 'link', 'set', 'dev', apdev[0]['ifname'], 'down'])
138 ev = hapd.wait_event(["INTERFACE-DISABLED"], timeout=10)
139 if ev is None:
140 raise Exception("No INTERFACE-DISABLED event")
141 hapd.cmd_execute(['ip', 'link', 'set', 'dev', apdev[0]['ifname'], 'up'])
142 ev = hapd.wait_event(["INTERFACE-ENABLED"], timeout=10)
143 if ev is None:
144 raise Exception("No INTERFACE-ENABLED event")
145 dev[0].select_network(id, freq=2412)
146 dev[0].wait_connected()
147 hwsim_utils.test_connectivity(dev[0], hapd)