]>
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-2014, 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()
14 from wpasupplicant
import WpaSupplicant
15 from test_rfkill
import get_rfkill_id
17 def get_wext_interface():
18 if not os
.path
.exists("/proc/net/wireless"):
19 logger
.info("WEXT support not included in the kernel")
22 wpas
= WpaSupplicant(global_iface
='/tmp/wpas-wlan5')
24 wpas
.interface_add("wlan5", driver
="wext")
26 logger
.info("WEXT driver support not included in wpa_supplicant")
30 def test_wext_open(dev
, apdev
):
31 """WEXT driver interface with open network"""
32 wpas
= get_wext_interface()
36 params
= { "ssid": "wext-open" }
37 hapd
= hostapd
.add_ap(apdev
[0]['ifname'], params
)
39 wpas
.connect("wext-open", key_mgmt
="NONE")
40 hwsim_utils
.test_connectivity(wpas
, hapd
)
42 def test_wext_wpa2_psk(dev
, apdev
):
43 """WEXT driver interface with WPA2-PSK"""
44 wpas
= get_wext_interface()
48 params
= hostapd
.wpa2_params(ssid
="wext-wpa2-psk", passphrase
="12345678")
49 hapd
= hostapd
.add_ap(apdev
[0]['ifname'], params
)
51 wpas
.connect("wext-wpa2-psk", psk
="12345678")
52 hwsim_utils
.test_connectivity(wpas
, hapd
)
53 if "RSSI=" not in wpas
.request("SIGNAL_POLL"):
54 raise Exception("Missing RSSI from SIGNAL_POLL")
57 hapd
.request("DEAUTHENTICATE " + wpas
.p2p_interface_addr())
58 wpas
.wait_disconnected(timeout
=15)
60 def test_wext_wpa_psk(dev
, apdev
):
61 """WEXT driver interface with WPA-PSK"""
62 wpas
= get_wext_interface()
66 params
= hostapd
.wpa_params(ssid
="wext-wpa-psk", passphrase
="12345678")
67 hapd
= hostapd
.add_ap(apdev
[0]['ifname'], params
)
68 testfile
= "/sys/kernel/debug/ieee80211/%s/netdev:%s/tkip_mic_test" % (hapd
.get_driver_status_field("phyname"), apdev
[0]['ifname'])
69 if not os
.path
.exists(testfile
):
72 wpas
.connect("wext-wpa-psk", psk
="12345678")
73 hwsim_utils
.test_connectivity(wpas
, hapd
)
75 with
open(testfile
, "w") as f
:
76 f
.write(wpas
.p2p_interface_addr())
77 ev
= wpas
.wait_event(["CTRL-EVENT-DISCONNECTED"], timeout
=1)
79 raise Exception("Unexpected disconnection on first Michael MIC failure")
81 with
open(testfile
, "w") as f
:
82 f
.write("ff:ff:ff:ff:ff:ff")
83 ev
= wpas
.wait_disconnected(timeout
=10,
84 error
="No disconnection after two Michael MIC failures")
85 if "reason=14 locally_generated=1" not in ev
:
86 raise Exception("Unexpected disconnection reason: " + ev
)
88 def test_wext_pmksa_cache(dev
, apdev
):
89 """PMKSA caching with WEXT"""
90 wpas
= get_wext_interface()
94 params
= hostapd
.wpa2_eap_params(ssid
="test-pmksa-cache")
95 hostapd
.add_ap(apdev
[0]['ifname'], params
)
96 bssid
= apdev
[0]['bssid']
97 wpas
.connect("test-pmksa-cache", proto
="RSN", key_mgmt
="WPA-EAP",
98 eap
="GPSK", identity
="gpsk user",
99 password
="abcdefghijklmnop0123456789abcdef",
101 pmksa
= wpas
.get_pmksa(bssid
)
103 raise Exception("No PMKSA cache entry created")
104 if pmksa
['opportunistic'] != '0':
105 raise Exception("Unexpected opportunistic PMKSA cache entry")
107 hostapd
.add_ap(apdev
[1]['ifname'], params
)
108 bssid2
= apdev
[1]['bssid']
111 logger
.info("Roam to AP2")
112 # It can take some time for the second AP to become ready to reply to Probe
113 # Request frames especially under heavy CPU load, so allow couple of rounds
114 # of scanning to avoid reporting errors incorrectly just because of scans
115 # not having seen the target AP.
118 if wpas
.get_bss(bssid2
) is not None:
120 logger
.info("Scan again to find target AP")
121 wpas
.request("ROAM " + bssid2
)
122 ev
= wpas
.wait_event(["CTRL-EVENT-EAP-SUCCESS"], timeout
=10)
124 raise Exception("EAP success timed out")
125 wpas
.wait_connected(timeout
=10, error
="Roaming timed out")
126 pmksa2
= wpas
.get_pmksa(bssid2
)
128 raise Exception("No PMKSA cache entry found")
129 if pmksa2
['opportunistic'] != '0':
130 raise Exception("Unexpected opportunistic PMKSA cache entry")
133 logger
.info("Roam back to AP1")
135 wpas
.request("ROAM " + bssid
)
136 ev
= wpas
.wait_event(["CTRL-EVENT-EAP-STARTED",
137 "CTRL-EVENT-CONNECTED"], timeout
=15)
139 raise Exception("Roaming with the AP timed out")
140 if "CTRL-EVENT-EAP-STARTED" in ev
:
141 raise Exception("Unexpected EAP exchange")
142 pmksa1b
= wpas
.get_pmksa(bssid
)
144 raise Exception("No PMKSA cache entry found")
145 if pmksa
['pmkid'] != pmksa1b
['pmkid']:
146 raise Exception("Unexpected PMKID change for AP1")
149 if "FAIL" in wpas
.request("PMKSA_FLUSH"):
150 raise Exception("PMKSA_FLUSH failed")
151 if wpas
.get_pmksa(bssid
) is not None or wpas
.get_pmksa(bssid2
) is not None:
152 raise Exception("PMKSA_FLUSH did not remove PMKSA entries")
153 wpas
.wait_disconnected(timeout
=5)
154 wpas
.wait_connected(timeout
=15, error
="Reconnection timed out")
156 def test_wext_wep_open_auth(dev
, apdev
):
157 """WEP Open System authentication"""
158 wpas
= get_wext_interface()
162 hapd
= hostapd
.add_ap(apdev
[0]['ifname'],
163 { "ssid": "wep-open",
164 "wep_key0": '"hello"' })
165 wpas
.connect("wep-open", key_mgmt
="NONE", wep_key0
='"hello"',
167 hwsim_utils
.test_connectivity(wpas
, hapd
)
168 if "[WEP]" not in wpas
.request("SCAN_RESULTS"):
169 raise Exception("WEP flag not indicated in scan results")
171 def test_wext_wep_shared_key_auth(dev
, apdev
):
172 """WEP Shared Key authentication"""
173 wpas
= get_wext_interface()
177 hapd
= hostapd
.add_ap(apdev
[0]['ifname'],
178 { "ssid": "wep-shared-key",
179 "wep_key0": '"hello12345678"',
181 wpas
.connect("wep-shared-key", key_mgmt
="NONE", auth_alg
="SHARED",
182 wep_key0
='"hello12345678"', scan_freq
="2412")
183 hwsim_utils
.test_connectivity(wpas
, hapd
)
184 wpas
.request("REMOVE_NETWORK all")
185 wpas
.wait_disconnected(timeout
=5)
186 wpas
.connect("wep-shared-key", key_mgmt
="NONE", auth_alg
="OPEN SHARED",
187 wep_key0
='"hello12345678"', scan_freq
="2412")
189 def test_wext_pmf(dev
, apdev
):
190 """WEXT driver interface with WPA2-PSK and PMF"""
191 wpas
= get_wext_interface()
195 params
= hostapd
.wpa2_params(ssid
="wext-wpa2-psk", passphrase
="12345678")
196 params
["wpa_key_mgmt"] = "WPA-PSK-SHA256";
197 params
["ieee80211w"] = "2";
198 hapd
= hostapd
.add_ap(apdev
[0]['ifname'], params
)
200 wpas
.connect("wext-wpa2-psk", psk
="12345678", ieee80211w
="1",
201 key_mgmt
="WPA-PSK WPA-PSK-SHA256", proto
="WPA2",
203 hwsim_utils
.test_connectivity(wpas
, hapd
)
205 addr
= wpas
.p2p_interface_addr()
206 hapd
.request("DEAUTHENTICATE " + addr
)
207 wpas
.wait_disconnected(timeout
=5)
209 def test_wext_scan_hidden(dev
, apdev
):
210 """WEXT with hidden SSID"""
211 wpas
= get_wext_interface()
215 hostapd
.add_ap(apdev
[0]['ifname'], { "ssid": "test-scan",
216 "ignore_broadcast_ssid": "1" })
217 hostapd
.add_ap(apdev
[1]['ifname'], { "ssid": "test-scan2",
218 "ignore_broadcast_ssid": "1" })
220 id1
= wpas
.connect("test-scan", key_mgmt
="NONE", scan_ssid
="1",
221 only_add_network
=True)
223 wpas
.request("SCAN scan_id=%d" % id1
)
225 ev
= wpas
.wait_event(["CTRL-EVENT-SCAN-RESULTS"], timeout
=15)
227 raise Exception("Scan did not complete")
229 if "test-scan" not in wpas
.request("SCAN_RESULTS"):
230 raise Exception("Did not find hidden SSID in scan")
232 id = wpas
.connect("test-scan2", key_mgmt
="NONE", scan_ssid
="1",
233 only_add_network
=True)
234 wpas
.connect_network(id, timeout
=30)
236 def test_wext_rfkill(dev
, apdev
):
237 """WEXT and rfkill block/unblock"""
238 wpas
= WpaSupplicant(global_iface
='/tmp/wpas-wlan5')
239 wpas
.interface_add("wlan5")
240 id = get_rfkill_id(wpas
)
243 wpas
.interface_remove("wlan5")
245 wpas
= get_wext_interface()
249 hapd
= hostapd
.add_ap(apdev
[0]['ifname'], { "ssid": "open" })
250 wpas
.connect("open", key_mgmt
="NONE", scan_freq
="2412")
252 logger
.info("rfkill block")
253 subprocess
.call(['rfkill', 'block', id])
254 wpas
.wait_disconnected(timeout
=10,
255 error
="Missing disconnection event on rfkill block")
257 logger
.info("rfkill unblock")
258 subprocess
.call(['rfkill', 'unblock', id])
259 wpas
.wait_connected(timeout
=20,
260 error
="Missing connection event on rfkill unblock")
261 hwsim_utils
.test_connectivity(wpas
, hapd
)
263 subprocess
.call(['rfkill', 'unblock', id])