]>
Commit | Line | Data |
---|---|---|
c2f70afa | 1 | # Deprecated WEXT driver interface in wpa_supplicant |
81e787b7 | 2 | # Copyright (c) 2013-2015, Jouni Malinen <j@w1.fi> |
c2f70afa JM |
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 os | |
10 | ||
11 | import hostapd | |
12 | import hwsim_utils | |
13 | from wpasupplicant import WpaSupplicant | |
a1eabc74 | 14 | from utils import HwsimSkip, skip_with_fips |
9c8779da | 15 | from test_rfkill import get_rfkill |
c2f70afa | 16 | |
ee27f673 | 17 | def get_wext_interface(): |
c2f70afa | 18 | if not os.path.exists("/proc/net/wireless"): |
81e787b7 | 19 | raise HwsimSkip("WEXT support not included in the kernel") |
c2f70afa JM |
20 | |
21 | wpas = WpaSupplicant(global_iface='/tmp/wpas-wlan5') | |
22 | try: | |
23 | wpas.interface_add("wlan5", driver="wext") | |
bab493b9 | 24 | except Exception as e: |
a66d2248 | 25 | wpas.close_ctrl() |
81e787b7 | 26 | raise HwsimSkip("WEXT driver support not included in wpa_supplicant") |
ee27f673 JM |
27 | return wpas |
28 | ||
29 | def test_wext_open(dev, apdev): | |
30 | """WEXT driver interface with open network""" | |
31 | wpas = get_wext_interface() | |
c2f70afa | 32 | |
ee27f673 | 33 | params = { "ssid": "wext-open" } |
8b8a1864 | 34 | hapd = hostapd.add_ap(apdev[0], params) |
ee27f673 | 35 | |
c2f70afa | 36 | wpas.connect("wext-open", key_mgmt="NONE") |
a8375c94 | 37 | hwsim_utils.test_connectivity(wpas, hapd) |
c2f70afa JM |
38 | |
39 | def test_wext_wpa2_psk(dev, apdev): | |
40 | """WEXT driver interface with WPA2-PSK""" | |
ee27f673 | 41 | wpas = get_wext_interface() |
c2f70afa JM |
42 | |
43 | params = hostapd.wpa2_params(ssid="wext-wpa2-psk", passphrase="12345678") | |
8b8a1864 | 44 | hapd = hostapd.add_ap(apdev[0], params) |
c2f70afa | 45 | |
ee27f673 JM |
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") | |
50 | ||
51 | wpas.dump_monitor() | |
52 | hapd.request("DEAUTHENTICATE " + wpas.p2p_interface_addr()) | |
5f35a5e2 | 53 | wpas.wait_disconnected(timeout=15) |
ee27f673 JM |
54 | |
55 | def test_wext_wpa_psk(dev, apdev): | |
56 | """WEXT driver interface with WPA-PSK""" | |
a1eabc74 | 57 | skip_with_fips(dev[0]) |
ee27f673 | 58 | wpas = get_wext_interface() |
c2f70afa | 59 | |
ee27f673 | 60 | params = hostapd.wpa_params(ssid="wext-wpa-psk", passphrase="12345678") |
8b8a1864 | 61 | hapd = hostapd.add_ap(apdev[0], params) |
ee27f673 JM |
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): | |
a66d2248 | 64 | wpas.close_ctrl() |
81e787b7 | 65 | raise HwsimSkip("tkip_mic_test not supported in mac80211") |
ee27f673 JM |
66 | |
67 | wpas.connect("wext-wpa-psk", psk="12345678") | |
68 | hwsim_utils.test_connectivity(wpas, hapd) | |
69 | ||
70 | with open(testfile, "w") as f: | |
71 | f.write(wpas.p2p_interface_addr()) | |
72 | ev = wpas.wait_event(["CTRL-EVENT-DISCONNECTED"], timeout=1) | |
73 | if ev is not None: | |
74 | raise Exception("Unexpected disconnection on first Michael MIC failure") | |
75 | ||
76 | with open(testfile, "w") as f: | |
77 | f.write("ff:ff:ff:ff:ff:ff") | |
5f35a5e2 JM |
78 | ev = wpas.wait_disconnected(timeout=10, |
79 | error="No disconnection after two Michael MIC failures") | |
ee27f673 JM |
80 | if "reason=14 locally_generated=1" not in ev: |
81 | raise Exception("Unexpected disconnection reason: " + ev) | |
82 | ||
83 | def test_wext_pmksa_cache(dev, apdev): | |
84 | """PMKSA caching with WEXT""" | |
85 | wpas = get_wext_interface() | |
ee27f673 JM |
86 | |
87 | params = hostapd.wpa2_eap_params(ssid="test-pmksa-cache") | |
8b8a1864 | 88 | hostapd.add_ap(apdev[0], params) |
ee27f673 JM |
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", | |
93 | scan_freq="2412") | |
94 | pmksa = wpas.get_pmksa(bssid) | |
95 | if pmksa is None: | |
96 | raise Exception("No PMKSA cache entry created") | |
97 | if pmksa['opportunistic'] != '0': | |
98 | raise Exception("Unexpected opportunistic PMKSA cache entry") | |
99 | ||
8b8a1864 | 100 | hostapd.add_ap(apdev[1], params) |
ee27f673 JM |
101 | bssid2 = apdev[1]['bssid'] |
102 | ||
103 | wpas.dump_monitor() | |
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. | |
109 | for i in range(3): | |
110 | wpas.scan() | |
111 | if wpas.get_bss(bssid2) is not None: | |
112 | break | |
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) | |
116 | if ev is None: | |
117 | raise Exception("EAP success timed out") | |
5f35a5e2 | 118 | wpas.wait_connected(timeout=10, error="Roaming timed out") |
ee27f673 JM |
119 | pmksa2 = wpas.get_pmksa(bssid2) |
120 | if pmksa2 is None: | |
121 | raise Exception("No PMKSA cache entry found") | |
122 | if pmksa2['opportunistic'] != '0': | |
123 | raise Exception("Unexpected opportunistic PMKSA cache entry") | |
124 | ||
125 | wpas.dump_monitor() | |
126 | logger.info("Roam back to AP1") | |
127 | wpas.scan() | |
128 | wpas.request("ROAM " + bssid) | |
129 | ev = wpas.wait_event(["CTRL-EVENT-EAP-STARTED", | |
130 | "CTRL-EVENT-CONNECTED"], timeout=15) | |
131 | if ev is None: | |
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) | |
136 | if pmksa1b is None: | |
137 | raise Exception("No PMKSA cache entry found") | |
138 | if pmksa['pmkid'] != pmksa1b['pmkid']: | |
139 | raise Exception("Unexpected PMKID change for AP1") | |
140 | ||
141 | wpas.dump_monitor() | |
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") | |
5f35a5e2 JM |
146 | wpas.wait_disconnected(timeout=5) |
147 | wpas.wait_connected(timeout=15, error="Reconnection timed out") | |
ee27f673 JM |
148 | |
149 | def test_wext_wep_open_auth(dev, apdev): | |
150 | """WEP Open System authentication""" | |
151 | wpas = get_wext_interface() | |
ee27f673 | 152 | |
8b8a1864 | 153 | hapd = hostapd.add_ap(apdev[0], |
ee27f673 JM |
154 | { "ssid": "wep-open", |
155 | "wep_key0": '"hello"' }) | |
156 | wpas.connect("wep-open", key_mgmt="NONE", wep_key0='"hello"', | |
157 | scan_freq="2412") | |
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") | |
161 | ||
162 | def test_wext_wep_shared_key_auth(dev, apdev): | |
163 | """WEP Shared Key authentication""" | |
164 | wpas = get_wext_interface() | |
ee27f673 | 165 | |
8b8a1864 | 166 | hapd = hostapd.add_ap(apdev[0], |
ee27f673 JM |
167 | { "ssid": "wep-shared-key", |
168 | "wep_key0": '"hello12345678"', | |
169 | "auth_algs": "2" }) | |
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") | |
5f35a5e2 | 174 | wpas.wait_disconnected(timeout=5) |
ee27f673 JM |
175 | wpas.connect("wep-shared-key", key_mgmt="NONE", auth_alg="OPEN SHARED", |
176 | wep_key0='"hello12345678"', scan_freq="2412") | |
177 | ||
178 | def test_wext_pmf(dev, apdev): | |
179 | """WEXT driver interface with WPA2-PSK and PMF""" | |
180 | wpas = get_wext_interface() | |
ee27f673 JM |
181 | |
182 | params = hostapd.wpa2_params(ssid="wext-wpa2-psk", passphrase="12345678") | |
bc6e3288 JM |
183 | params["wpa_key_mgmt"] = "WPA-PSK-SHA256" |
184 | params["ieee80211w"] = "2" | |
8b8a1864 | 185 | hapd = hostapd.add_ap(apdev[0], params) |
ee27f673 JM |
186 | |
187 | wpas.connect("wext-wpa2-psk", psk="12345678", ieee80211w="1", | |
188 | key_mgmt="WPA-PSK WPA-PSK-SHA256", proto="WPA2", | |
189 | scan_freq="2412") | |
a8375c94 | 190 | hwsim_utils.test_connectivity(wpas, hapd) |
ee27f673 JM |
191 | |
192 | addr = wpas.p2p_interface_addr() | |
193 | hapd.request("DEAUTHENTICATE " + addr) | |
5f35a5e2 | 194 | wpas.wait_disconnected(timeout=5) |
ee27f673 JM |
195 | |
196 | def test_wext_scan_hidden(dev, apdev): | |
197 | """WEXT with hidden SSID""" | |
198 | wpas = get_wext_interface() | |
ee27f673 | 199 | |
8b8a1864 JD |
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" }) | |
ee27f673 JM |
204 | |
205 | id1 = wpas.connect("test-scan", key_mgmt="NONE", scan_ssid="1", | |
206 | only_add_network=True) | |
207 | ||
208 | wpas.request("SCAN scan_id=%d" % id1) | |
209 | ||
210 | ev = wpas.wait_event(["CTRL-EVENT-SCAN-RESULTS"], timeout=15) | |
211 | if ev is None: | |
212 | raise Exception("Scan did not complete") | |
213 | ||
214 | if "test-scan" not in wpas.request("SCAN_RESULTS"): | |
215 | raise Exception("Did not find hidden SSID in scan") | |
216 | ||
217 | id = wpas.connect("test-scan2", key_mgmt="NONE", scan_ssid="1", | |
218 | only_add_network=True) | |
219 | wpas.connect_network(id, timeout=30) | |
1264b683 JM |
220 | wpas.request("DISCONNECT") |
221 | hapd2.disable() | |
222 | hapd.disable() | |
223 | wpas.interface_remove("wlan5") | |
224 | wpas.interface_add("wlan5") | |
225 | wpas.flush_scan_cache(freq=2412) | |
226 | wpas.flush_scan_cache() | |
ee27f673 JM |
227 | |
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") | |
9c8779da | 232 | rfk = get_rfkill(wpas) |
ee27f673 JM |
233 | wpas.interface_remove("wlan5") |
234 | ||
235 | wpas = get_wext_interface() | |
ee27f673 | 236 | |
8b8a1864 | 237 | hapd = hostapd.add_ap(apdev[0], { "ssid": "open" }) |
ee27f673 JM |
238 | wpas.connect("open", key_mgmt="NONE", scan_freq="2412") |
239 | try: | |
240 | logger.info("rfkill block") | |
9c8779da | 241 | rfk.block() |
5f35a5e2 JM |
242 | wpas.wait_disconnected(timeout=10, |
243 | error="Missing disconnection event on rfkill block") | |
ee27f673 JM |
244 | |
245 | logger.info("rfkill unblock") | |
9c8779da | 246 | rfk.unblock() |
5f35a5e2 JM |
247 | wpas.wait_connected(timeout=20, |
248 | error="Missing connection event on rfkill unblock") | |
ee27f673 JM |
249 | hwsim_utils.test_connectivity(wpas, hapd) |
250 | finally: | |
9c8779da | 251 | rfk.unblock() |