]>
git.ipfire.org Git - thirdparty/hostap.git/blob - tests/hwsim/test_wext.py
1 # Deprecated WEXT driver interface in wpa_supplicant
2 # Copyright (c) 2013-2015, Jouni Malinen <j@w1.fi>
4 # This software may be distributed under the terms of the BSD license.
5 # See README for more details.
8 logger
= logging
.getLogger()
13 from wpasupplicant
import WpaSupplicant
14 from utils
import HwsimSkip
, skip_with_fips
15 from test_rfkill
import get_rfkill
17 def get_wext_interface():
18 if not os
.path
.exists("/proc/net/wireless"):
19 raise HwsimSkip("WEXT support not included in the kernel")
21 wpas
= WpaSupplicant(global_iface
='/tmp/wpas-wlan5')
23 wpas
.interface_add("wlan5", driver
="wext")
24 except Exception as e
:
26 raise HwsimSkip("WEXT driver support not included in wpa_supplicant")
29 def test_wext_open(dev
, apdev
):
30 """WEXT driver interface with open network"""
31 wpas
= get_wext_interface()
33 params
= {"ssid": "wext-open"}
34 hapd
= hostapd
.add_ap(apdev
[0], params
)
36 wpas
.connect("wext-open", key_mgmt
="NONE")
37 hwsim_utils
.test_connectivity(wpas
, hapd
)
39 def test_wext_wpa2_psk(dev
, apdev
):
40 """WEXT driver interface with WPA2-PSK"""
41 wpas
= get_wext_interface()
43 params
= hostapd
.wpa2_params(ssid
="wext-wpa2-psk", passphrase
="12345678")
44 hapd
= hostapd
.add_ap(apdev
[0], params
)
46 wpas
.connect("wext-wpa2-psk", psk
="12345678")
47 hwsim_utils
.test_connectivity(wpas
, hapd
)
48 if "RSSI=" not in wpas
.request("SIGNAL_POLL"):
49 raise Exception("Missing RSSI from SIGNAL_POLL")
52 hapd
.request("DEAUTHENTICATE " + wpas
.p2p_interface_addr())
53 wpas
.wait_disconnected(timeout
=15)
55 def test_wext_wpa_psk(dev
, apdev
):
56 """WEXT driver interface with WPA-PSK"""
57 skip_with_fips(dev
[0])
58 wpas
= get_wext_interface()
60 params
= hostapd
.wpa_params(ssid
="wext-wpa-psk", passphrase
="12345678")
61 hapd
= hostapd
.add_ap(apdev
[0], params
)
62 testfile
= "/sys/kernel/debug/ieee80211/%s/netdev:%s/tkip_mic_test" % (hapd
.get_driver_status_field("phyname"), apdev
[0]['ifname'])
63 if not os
.path
.exists(testfile
):
65 raise HwsimSkip("tkip_mic_test not supported in mac80211")
67 wpas
.connect("wext-wpa-psk", psk
="12345678")
68 hwsim_utils
.test_connectivity(wpas
, hapd
)
70 with
open(testfile
, "w") as f
:
71 f
.write(wpas
.p2p_interface_addr())
72 ev
= wpas
.wait_event(["CTRL-EVENT-DISCONNECTED"], timeout
=1)
74 raise Exception("Unexpected disconnection on first Michael MIC failure")
76 with
open(testfile
, "w") as f
:
77 f
.write("ff:ff:ff:ff:ff:ff")
78 ev
= wpas
.wait_disconnected(timeout
=10,
79 error
="No disconnection after two Michael MIC failures")
80 if "reason=14 locally_generated=1" not in ev
:
81 raise Exception("Unexpected disconnection reason: " + ev
)
83 def test_wext_pmksa_cache(dev
, apdev
):
84 """PMKSA caching with WEXT"""
85 wpas
= get_wext_interface()
87 params
= hostapd
.wpa2_eap_params(ssid
="test-pmksa-cache")
88 hostapd
.add_ap(apdev
[0], params
)
89 bssid
= apdev
[0]['bssid']
90 wpas
.connect("test-pmksa-cache", proto
="RSN", key_mgmt
="WPA-EAP",
91 eap
="GPSK", identity
="gpsk user",
92 password
="abcdefghijklmnop0123456789abcdef",
94 pmksa
= wpas
.get_pmksa(bssid
)
96 raise Exception("No PMKSA cache entry created")
97 if pmksa
['opportunistic'] != '0':
98 raise Exception("Unexpected opportunistic PMKSA cache entry")
100 hostapd
.add_ap(apdev
[1], params
)
101 bssid2
= apdev
[1]['bssid']
104 logger
.info("Roam to AP2")
105 # It can take some time for the second AP to become ready to reply to Probe
106 # Request frames especially under heavy CPU load, so allow couple of rounds
107 # of scanning to avoid reporting errors incorrectly just because of scans
108 # not having seen the target AP.
111 if wpas
.get_bss(bssid2
) is not None:
113 logger
.info("Scan again to find target AP")
114 wpas
.request("ROAM " + bssid2
)
115 ev
= wpas
.wait_event(["CTRL-EVENT-EAP-SUCCESS"], timeout
=10)
117 raise Exception("EAP success timed out")
118 wpas
.wait_connected(timeout
=10, error
="Roaming timed out")
119 pmksa2
= wpas
.get_pmksa(bssid2
)
121 raise Exception("No PMKSA cache entry found")
122 if pmksa2
['opportunistic'] != '0':
123 raise Exception("Unexpected opportunistic PMKSA cache entry")
126 logger
.info("Roam back to AP1")
128 wpas
.request("ROAM " + bssid
)
129 ev
= wpas
.wait_event(["CTRL-EVENT-EAP-STARTED",
130 "CTRL-EVENT-CONNECTED"], timeout
=15)
132 raise Exception("Roaming with the AP timed out")
133 if "CTRL-EVENT-EAP-STARTED" in ev
:
134 raise Exception("Unexpected EAP exchange")
135 pmksa1b
= wpas
.get_pmksa(bssid
)
137 raise Exception("No PMKSA cache entry found")
138 if pmksa
['pmkid'] != pmksa1b
['pmkid']:
139 raise Exception("Unexpected PMKID change for AP1")
142 if "FAIL" in wpas
.request("PMKSA_FLUSH"):
143 raise Exception("PMKSA_FLUSH failed")
144 if wpas
.get_pmksa(bssid
) is not None or wpas
.get_pmksa(bssid2
) is not None:
145 raise Exception("PMKSA_FLUSH did not remove PMKSA entries")
146 wpas
.wait_disconnected(timeout
=5)
147 wpas
.wait_connected(timeout
=15, error
="Reconnection timed out")
149 def test_wext_wep_open_auth(dev
, apdev
):
150 """WEP Open System authentication"""
151 wpas
= get_wext_interface()
153 hapd
= hostapd
.add_ap(apdev
[0],
155 "wep_key0": '"hello"'})
156 wpas
.connect("wep-open", key_mgmt
="NONE", wep_key0
='"hello"',
158 hwsim_utils
.test_connectivity(wpas
, hapd
)
159 if "[WEP]" not in wpas
.request("SCAN_RESULTS"):
160 raise Exception("WEP flag not indicated in scan results")
162 def test_wext_wep_shared_key_auth(dev
, apdev
):
163 """WEP Shared Key authentication"""
164 wpas
= get_wext_interface()
166 hapd
= hostapd
.add_ap(apdev
[0],
167 {"ssid": "wep-shared-key",
168 "wep_key0": '"hello12345678"',
170 wpas
.connect("wep-shared-key", key_mgmt
="NONE", auth_alg
="SHARED",
171 wep_key0
='"hello12345678"', scan_freq
="2412")
172 hwsim_utils
.test_connectivity(wpas
, hapd
)
173 wpas
.request("REMOVE_NETWORK all")
174 wpas
.wait_disconnected(timeout
=5)
175 wpas
.connect("wep-shared-key", key_mgmt
="NONE", auth_alg
="OPEN SHARED",
176 wep_key0
='"hello12345678"', scan_freq
="2412")
178 def test_wext_pmf(dev
, apdev
):
179 """WEXT driver interface with WPA2-PSK and PMF"""
180 wpas
= get_wext_interface()
182 params
= hostapd
.wpa2_params(ssid
="wext-wpa2-psk", passphrase
="12345678")
183 params
["wpa_key_mgmt"] = "WPA-PSK-SHA256"
184 params
["ieee80211w"] = "2"
185 hapd
= hostapd
.add_ap(apdev
[0], params
)
187 wpas
.connect("wext-wpa2-psk", psk
="12345678", ieee80211w
="1",
188 key_mgmt
="WPA-PSK WPA-PSK-SHA256", proto
="WPA2",
190 hwsim_utils
.test_connectivity(wpas
, hapd
)
192 addr
= wpas
.p2p_interface_addr()
193 hapd
.request("DEAUTHENTICATE " + addr
)
194 wpas
.wait_disconnected(timeout
=5)
196 def test_wext_scan_hidden(dev
, apdev
):
197 """WEXT with hidden SSID"""
198 wpas
= get_wext_interface()
200 hapd
= hostapd
.add_ap(apdev
[0], {"ssid": "test-scan",
201 "ignore_broadcast_ssid": "1"})
202 hapd2
= hostapd
.add_ap(apdev
[1], {"ssid": "test-scan2",
203 "ignore_broadcast_ssid": "1"})
205 id1
= wpas
.connect("test-scan", key_mgmt
="NONE", scan_ssid
="1",
206 only_add_network
=True)
208 wpas
.request("SCAN scan_id=%d" % id1
)
210 ev
= wpas
.wait_event(["CTRL-EVENT-SCAN-RESULTS"], timeout
=15)
212 raise Exception("Scan did not complete")
214 if "test-scan" not in wpas
.request("SCAN_RESULTS"):
215 raise Exception("Did not find hidden SSID in scan")
217 id = wpas
.connect("test-scan2", key_mgmt
="NONE", scan_ssid
="1",
218 only_add_network
=True)
219 wpas
.connect_network(id, timeout
=30)
220 wpas
.request("DISCONNECT")
223 wpas
.interface_remove("wlan5")
224 wpas
.interface_add("wlan5")
225 wpas
.flush_scan_cache(freq
=2412)
226 wpas
.flush_scan_cache()
228 def test_wext_rfkill(dev
, apdev
):
229 """WEXT and rfkill block/unblock"""
230 wpas
= WpaSupplicant(global_iface
='/tmp/wpas-wlan5')
231 wpas
.interface_add("wlan5")
232 rfk
= get_rfkill(wpas
)
233 wpas
.interface_remove("wlan5")
235 wpas
= get_wext_interface()
237 hapd
= hostapd
.add_ap(apdev
[0], {"ssid": "open"})
238 wpas
.connect("open", key_mgmt
="NONE", scan_freq
="2412")
240 logger
.info("rfkill block")
242 wpas
.wait_disconnected(timeout
=10,
243 error
="Missing disconnection event on rfkill block")
245 logger
.info("rfkill unblock")
247 wpas
.wait_connected(timeout
=20,
248 error
="Missing connection event on rfkill unblock")
249 hwsim_utils
.test_connectivity(wpas
, hapd
)