]>
Commit | Line | Data |
---|---|---|
ca5b81a5 JM |
1 | # wpa_supplicant control interface |
2 | # Copyright (c) 2014, Qualcomm Atheros, Inc. | |
3 | # | |
4 | # This software may be distributed under the terms of the BSD license. | |
5 | # See README for more details. | |
6 | ||
d21939a6 JM |
7 | import logging |
8 | logger = logging.getLogger() | |
c9075f62 | 9 | import subprocess |
e4ac747c JM |
10 | import time |
11 | ||
9f52e97d | 12 | import hostapd |
d21939a6 | 13 | from wpasupplicant import WpaSupplicant |
9f52e97d | 14 | |
ca5b81a5 JM |
15 | def test_wpas_ctrl_network(dev): |
16 | """wpa_supplicant ctrl_iface network set/get""" | |
17 | id = dev[0].add_network() | |
18 | ||
733c8acf JM |
19 | if "FAIL" not in dev[0].request("SET_NETWORK " + str(id)): |
20 | raise Exception("Unexpected success for invalid SET_NETWORK") | |
21 | if "FAIL" not in dev[0].request("SET_NETWORK " + str(id) + " name"): | |
22 | raise Exception("Unexpected success for invalid SET_NETWORK") | |
23 | if "FAIL" not in dev[0].request("SET_NETWORK " + str(id + 1) + " proto OPEN"): | |
24 | raise Exception("Unexpected success for invalid network id") | |
25 | if "FAIL" not in dev[0].request("GET_NETWORK " + str(id)): | |
26 | raise Exception("Unexpected success for invalid GET_NETWORK") | |
27 | if "FAIL" not in dev[0].request("GET_NETWORK " + str(id + 1) + " proto"): | |
28 | raise Exception("Unexpected success for invalid network id") | |
29 | ||
ca5b81a5 JM |
30 | tests = (("key_mgmt", "WPA-PSK WPA-EAP IEEE8021X NONE WPA-NONE FT-PSK FT-EAP WPA-PSK-SHA256 WPA-EAP-SHA256"), |
31 | ("pairwise", "CCMP-256 GCMP-256 CCMP GCMP TKIP"), | |
32 | ("group", "CCMP-256 GCMP-256 CCMP GCMP TKIP WEP104 WEP40"), | |
33 | ("auth_alg", "OPEN SHARED LEAP"), | |
34 | ("scan_freq", "1 2 3 4 5 6 7 8 9 10 11 12 13 14 15"), | |
35 | ("freq_list", "2412 2417"), | |
0fc743f2 JM |
36 | ("scan_ssid", "1"), |
37 | ("bssid", "00:11:22:33:44:55"), | |
38 | ("proto", "WPA RSN OSEN"), | |
ca5b81a5 JM |
39 | ("eap", "TLS"), |
40 | ("go_p2p_dev_addr", "22:33:44:55:66:aa"), | |
41 | ("p2p_client_list", "22:33:44:55:66:bb 02:11:22:33:44:55")) | |
42 | ||
43 | dev[0].set_network_quoted(id, "ssid", "test") | |
44 | for field, value in tests: | |
45 | dev[0].set_network(id, field, value) | |
46 | res = dev[0].get_network(id, field) | |
47 | if res != value: | |
48 | raise Exception("Unexpected response for '" + field + "': '" + res + "'") | |
49 | ||
50 | q_tests = (("identity", "hello"), | |
51 | ("anonymous_identity", "foo@nowhere.com")) | |
52 | for field, value in q_tests: | |
53 | dev[0].set_network_quoted(id, field, value) | |
54 | res = dev[0].get_network(id, field) | |
55 | if res != '"' + value + '"': | |
56 | raise Exception("Unexpected quoted response for '" + field + "': '" + res + "'") | |
57 | ||
58 | get_tests = (("foo", None), ("ssid", '"test"')) | |
59 | for field, value in get_tests: | |
60 | res = dev[0].get_network(id, field) | |
61 | if res != value: | |
62 | raise Exception("Unexpected response for '" + field + "': '" + res + "'") | |
63 | ||
64 | if dev[0].get_network(id, "password"): | |
65 | raise Exception("Unexpected response for 'password'") | |
66 | dev[0].set_network_quoted(id, "password", "foo") | |
67 | if dev[0].get_network(id, "password") != '*': | |
68 | raise Exception("Unexpected response for 'password' (expected *)") | |
69 | dev[0].set_network(id, "password", "hash:12345678901234567890123456789012") | |
70 | if dev[0].get_network(id, "password") != '*': | |
71 | raise Exception("Unexpected response for 'password' (expected *)") | |
72 | dev[0].set_network(id, "password", "NULL") | |
73 | if dev[0].get_network(id, "password"): | |
74 | raise Exception("Unexpected response for 'password'") | |
75 | if "FAIL" not in dev[0].request("SET_NETWORK " + str(id) + " password hash:12"): | |
76 | raise Exception("Unexpected success for invalid password hash") | |
77 | if "FAIL" not in dev[0].request("SET_NETWORK " + str(id) + " password hash:123456789012345678x0123456789012"): | |
78 | raise Exception("Unexpected success for invalid password hash") | |
79 | ||
80 | dev[0].set_network(id, "identity", "414243") | |
81 | if dev[0].get_network(id, "identity") != '"ABC"': | |
82 | raise Exception("Unexpected identity hex->text response") | |
83 | ||
84 | dev[0].set_network(id, "identity", 'P"abc\ndef"') | |
85 | if dev[0].get_network(id, "identity") != "6162630a646566": | |
86 | raise Exception("Unexpected identity printf->hex response") | |
87 | ||
88 | if "FAIL" not in dev[0].request("SET_NETWORK " + str(id) + ' identity P"foo'): | |
89 | raise Exception("Unexpected success for invalid identity string") | |
90 | ||
91 | if "FAIL" not in dev[0].request("SET_NETWORK " + str(id) + ' identity 12x3'): | |
92 | raise Exception("Unexpected success for invalid identity string") | |
93 | ||
94 | for i in range(0, 4): | |
95 | if "FAIL" in dev[0].request("SET_NETWORK " + str(id) + ' wep_key' + str(i) + ' aabbccddee'): | |
96 | raise Exception("Unexpected wep_key set failure") | |
97 | if dev[0].get_network(id, "wep_key" + str(i)) != '*': | |
98 | raise Exception("Unexpected wep_key get failure") | |
99 | ||
100 | if "FAIL" in dev[0].request("SET_NETWORK " + str(id) + ' psk_list P2P-00:11:22:33:44:55-0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef'): | |
101 | raise Exception("Unexpected failure for psk_list string") | |
102 | ||
103 | if "FAIL" not in dev[0].request("SET_NETWORK " + str(id) + ' psk_list 00:11:x2:33:44:55-0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef'): | |
104 | raise Exception("Unexpected success for invalid psk_list string") | |
105 | ||
106 | if "FAIL" not in dev[0].request("SET_NETWORK " + str(id) + ' psk_list P2P-00:11:x2:33:44:55-0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef'): | |
107 | raise Exception("Unexpected success for invalid psk_list string") | |
108 | ||
109 | if "FAIL" not in dev[0].request("SET_NETWORK " + str(id) + ' psk_list P2P-00:11:22:33:44:55+0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef'): | |
110 | raise Exception("Unexpected success for invalid psk_list string") | |
111 | ||
112 | if "FAIL" not in dev[0].request("SET_NETWORK " + str(id) + ' psk_list P2P-00:11:22:33:44:55-0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcde'): | |
113 | raise Exception("Unexpected success for invalid psk_list string") | |
114 | ||
115 | if "FAIL" not in dev[0].request("SET_NETWORK " + str(id) + ' psk_list P2P-00:11:22:33:44:55-0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdex'): | |
116 | raise Exception("Unexpected success for invalid psk_list string") | |
117 | ||
118 | if dev[0].get_network(id, "psk_list"): | |
119 | raise Exception("Unexpected psk_list get response") | |
120 | ||
0fc743f2 JM |
121 | if dev[0].list_networks()[0]['ssid'] != "test": |
122 | raise Exception("Unexpected ssid in LIST_NETWORKS") | |
123 | dev[0].set_network(id, "ssid", "NULL") | |
124 | if dev[0].list_networks()[0]['ssid'] != "": | |
125 | raise Exception("Unexpected ssid in LIST_NETWORKS after clearing it") | |
126 | ||
127 | if "FAIL" not in dev[0].request('SET_NETWORK ' + str(id) + ' ssid "0123456789abcdef0123456789abcdef0"'): | |
128 | raise Exception("Too long SSID accepted") | |
129 | if "FAIL" not in dev[0].request('SET_NETWORK ' + str(id) + ' scan_ssid qwerty'): | |
130 | raise Exception("Invalid integer accepted") | |
131 | if "FAIL" not in dev[0].request('SET_NETWORK ' + str(id) + ' scan_ssid 2'): | |
132 | raise Exception("Too large integer accepted") | |
133 | if "FAIL" not in dev[0].request('SET_NETWORK ' + str(id) + ' psk 12345678'): | |
134 | raise Exception("Invalid PSK accepted") | |
135 | if "FAIL" not in dev[0].request('SET_NETWORK ' + str(id) + ' psk "1234567"'): | |
136 | raise Exception("Too short PSK accepted") | |
137 | if "FAIL" not in dev[0].request('SET_NETWORK ' + str(id) + ' psk "1234567890123456789012345678901234567890123456789012345678901234"'): | |
138 | raise Exception("Too long PSK accepted") | |
139 | dev[0].set_network_quoted(id, "psk", "123456768"); | |
140 | dev[0].set_network_quoted(id, "psk", "123456789012345678901234567890123456789012345678901234567890123"); | |
141 | if dev[0].get_network(id, "psk") != '*': | |
142 | raise Exception("Unexpected psk read result"); | |
143 | ||
144 | if "FAIL" not in dev[0].request('SET_NETWORK ' + str(id) + ' eap UNKNOWN'): | |
145 | raise Exception("Unknown EAP method accepted") | |
146 | ||
147 | if "FAIL" not in dev[0].request('SET_NETWORK ' + str(id) + ' password "foo'): | |
148 | raise Exception("Invalid password accepted") | |
149 | ||
150 | if "FAIL" not in dev[0].request('SET_NETWORK ' + str(id) + ' wep_key0 "foo'): | |
151 | raise Exception("Invalid WEP key accepted") | |
152 | if "FAIL" not in dev[0].request('SET_NETWORK ' + str(id) + ' wep_key0 "12345678901234567"'): | |
153 | raise Exception("Too long WEP key accepted") | |
154 | # too short WEP key is ignored | |
155 | dev[0].set_network_quoted(id, "wep_key0", "1234") | |
156 | dev[0].set_network_quoted(id, "wep_key1", "12345") | |
157 | dev[0].set_network_quoted(id, "wep_key2", "1234567890123") | |
158 | dev[0].set_network_quoted(id, "wep_key3", "1234567890123456") | |
159 | ||
160 | dev[0].set_network(id, "go_p2p_dev_addr", "any") | |
161 | if dev[0].get_network(id, "go_p2p_dev_addr") is not None: | |
162 | raise Exception("Unexpected go_p2p_dev_addr value") | |
163 | if "FAIL" not in dev[0].request('SET_NETWORK ' + str(id) + ' go_p2p_dev_addr 00:11:22:33:44'): | |
164 | raise Exception("Invalid go_p2p_dev_addr accepted") | |
165 | if "FAIL" not in dev[0].request('SET_NETWORK ' + str(id) + ' p2p_client_list 00:11:22:33:44'): | |
166 | raise Exception("Invalid p2p_client_list accepted") | |
167 | if "FAIL" in dev[0].request('SET_NETWORK ' + str(id) + ' p2p_client_list 00:11:22:33:44:55 00:1'): | |
168 | raise Exception("p2p_client_list truncation workaround failed") | |
169 | if dev[0].get_network(id, "p2p_client_list") != "00:11:22:33:44:55": | |
170 | raise Exception("p2p_client_list truncation workaround did not work") | |
171 | ||
172 | if "FAIL" not in dev[0].request('SET_NETWORK ' + str(id) + ' auth_alg '): | |
173 | raise Exception("Empty auth_alg accepted") | |
174 | if "FAIL" not in dev[0].request('SET_NETWORK ' + str(id) + ' auth_alg FOO'): | |
175 | raise Exception("Invalid auth_alg accepted") | |
176 | ||
177 | if "FAIL" not in dev[0].request('SET_NETWORK ' + str(id) + ' proto '): | |
178 | raise Exception("Empty proto accepted") | |
179 | if "FAIL" not in dev[0].request('SET_NETWORK ' + str(id) + ' proto FOO'): | |
180 | raise Exception("Invalid proto accepted") | |
181 | ||
182 | if "FAIL" not in dev[0].request('SET_NETWORK ' + str(id) + ' pairwise '): | |
183 | raise Exception("Empty pairwise accepted") | |
184 | if "FAIL" not in dev[0].request('SET_NETWORK ' + str(id) + ' pairwise FOO'): | |
185 | raise Exception("Invalid pairwise accepted") | |
186 | if "FAIL" not in dev[0].request('SET_NETWORK ' + str(id) + ' pairwise WEP40'): | |
187 | raise Exception("Invalid pairwise accepted") | |
188 | ||
23fbf45c JM |
189 | if "OK" not in dev[0].request('BSSID ' + str(id) + ' 00:11:22:33:44:55'): |
190 | raise Exception("Unexpected BSSID failure") | |
191 | if dev[0].request("GET_NETWORK 0 bssid") != '00:11:22:33:44:55': | |
192 | raise Exception("BSSID command did not set network bssid") | |
193 | if "OK" not in dev[0].request('BSSID ' + str(id) + ' 00:00:00:00:00:00'): | |
194 | raise Exception("Unexpected BSSID failure") | |
195 | if "FAIL" not in dev[0].request("GET_NETWORK 0 bssid"): | |
196 | raise Exception("bssid claimed configured after clearing") | |
197 | if "FAIL" not in dev[0].request('BSSID 123 00:11:22:33:44:55'): | |
198 | raise Exception("Unexpected BSSID success") | |
199 | if "FAIL" not in dev[0].request('BSSID ' + str(id) + ' 00:11:22:33:44'): | |
200 | raise Exception("Unexpected BSSID success") | |
201 | ||
aa45859e JM |
202 | def add_cred(dev): |
203 | id = dev.add_cred() | |
204 | ev = dev.wait_event(["CRED-ADDED"]) | |
205 | if ev is None: | |
206 | raise Exception("Missing CRED-ADDED event") | |
207 | if " " + str(id) not in ev: | |
208 | raise Exception("CRED-ADDED event without matching id") | |
209 | return id | |
210 | ||
211 | def set_cred(dev, id, field, value): | |
212 | dev.set_cred(id, field, value) | |
213 | ev = dev.wait_event(["CRED-MODIFIED"]) | |
214 | if ev is None: | |
215 | raise Exception("Missing CRED-MODIFIED event") | |
216 | if " " + str(id) + " " not in ev: | |
217 | raise Exception("CRED-MODIFIED event without matching id") | |
218 | if field not in ev: | |
219 | raise Exception("CRED-MODIFIED event without matching field") | |
220 | ||
221 | def set_cred_quoted(dev, id, field, value): | |
222 | dev.set_cred_quoted(id, field, value) | |
223 | ev = dev.wait_event(["CRED-MODIFIED"]) | |
224 | if ev is None: | |
225 | raise Exception("Missing CRED-MODIFIED event") | |
226 | if " " + str(id) + " " not in ev: | |
227 | raise Exception("CRED-MODIFIED event without matching id") | |
228 | if field not in ev: | |
229 | raise Exception("CRED-MODIFIED event without matching field") | |
230 | ||
231 | def remove_cred(dev, id): | |
232 | dev.remove_cred(id) | |
233 | ev = dev.wait_event(["CRED-REMOVED"]) | |
234 | if ev is None: | |
235 | raise Exception("Missing CRED-REMOVED event") | |
236 | if " " + str(id) not in ev: | |
237 | raise Exception("CRED-REMOVED event without matching id") | |
238 | ||
ca5b81a5 JM |
239 | def test_wpas_ctrl_cred(dev): |
240 | """wpa_supplicant ctrl_iface cred set""" | |
aa45859e JM |
241 | id1 = add_cred(dev[0]) |
242 | id = add_cred(dev[0]) | |
243 | id2 = add_cred(dev[0]) | |
244 | set_cred(dev[0], id, "temporary", "1") | |
245 | set_cred(dev[0], id, "priority", "1") | |
246 | set_cred(dev[0], id, "pcsc", "1") | |
247 | set_cred_quoted(dev[0], id, "private_key_passwd", "test") | |
248 | set_cred_quoted(dev[0], id, "domain_suffix_match", "test") | |
249 | set_cred_quoted(dev[0], id, "phase1", "test") | |
250 | set_cred_quoted(dev[0], id, "phase2", "test") | |
ca5b81a5 JM |
251 | |
252 | if "FAIL" not in dev[0].request("SET_CRED " + str(id) + " eap FOO"): | |
253 | raise Exception("Unexpected success on unknown EAP method") | |
254 | ||
255 | if "FAIL" not in dev[0].request("SET_CRED " + str(id) + " username 12xa"): | |
256 | raise Exception("Unexpected success on invalid string") | |
257 | ||
258 | for i in ("11", "1122", "112233445566778899aabbccddeeff00"): | |
259 | if "FAIL" not in dev[0].request("SET_CRED " + str(id) + " roaming_consortium " + i): | |
260 | raise Exception("Unexpected success on invalid roaming_consortium") | |
261 | ||
262 | dev[0].set_cred(id, "excluded_ssid", "00112233445566778899aabbccddeeff00112233445566778899aabbccddeeff") | |
263 | if "FAIL" not in dev[0].request("SET_CRED " + str(id) + " excluded_ssid 00112233445566778899aabbccddeeff00112233445566778899aabbccddeeff00"): | |
264 | raise Exception("Unexpected success on invalid excluded_ssid") | |
265 | ||
266 | if "FAIL" not in dev[0].request("SET_CRED " + str(id) + " foo 4142"): | |
267 | raise Exception("Unexpected success on unknown field") | |
268 | ||
aa45859e JM |
269 | id3 = add_cred(dev[0]) |
270 | id4 = add_cred(dev[0]) | |
c7a4bf82 JM |
271 | if len(dev[0].request("LIST_CREDS").splitlines()) != 6: |
272 | raise Exception("Unexpected LIST_CREDS result(1)") | |
ca5b81a5 | 273 | |
aa45859e JM |
274 | remove_cred(dev[0], id1) |
275 | remove_cred(dev[0], id3) | |
276 | remove_cred(dev[0], id4) | |
277 | remove_cred(dev[0], id2) | |
278 | remove_cred(dev[0], id) | |
ca5b81a5 JM |
279 | if "FAIL" not in dev[0].request("REMOVE_CRED 1"): |
280 | raise Exception("Unexpected success on invalid remove cred") | |
c7a4bf82 JM |
281 | if len(dev[0].request("LIST_CREDS").splitlines()) != 1: |
282 | raise Exception("Unexpected LIST_CREDS result(2)") | |
ca5b81a5 | 283 | |
aa45859e JM |
284 | id = add_cred(dev[0]) |
285 | values = [ ("temporary", "1", False), | |
286 | ("temporary", "0", False), | |
287 | ("pcsc", "1", False), | |
288 | ("realm", "example.com", True), | |
289 | ("username", "user@example.com", True), | |
290 | ("password", "foo", True, "*"), | |
291 | ("ca_cert", "ca.pem", True), | |
292 | ("client_cert", "user.pem", True), | |
293 | ("private_key", "key.pem", True), | |
294 | ("private_key_passwd", "foo", True, "*"), | |
295 | ("imsi", "310026-000000000", True), | |
296 | ("milenage", "foo", True, "*"), | |
297 | ("domain_suffix_match", "example.com", True), | |
298 | ("domain", "example.com", True), | |
299 | ("domain", "example.org", True, "example.com\nexample.org"), | |
300 | ("roaming_consortium", "0123456789", False), | |
301 | ("required_roaming_consortium", "456789", False), | |
302 | ("eap", "TTLS", False), | |
303 | ("phase1", "foo=bar1", True), | |
304 | ("phase2", "foo=bar2", True), | |
305 | ("excluded_ssid", "test", True), | |
306 | ("excluded_ssid", "foo", True, "test\nfoo"), | |
307 | ("roaming_partner", "example.com,0,4,*", True), | |
308 | ("roaming_partner", "example.org,1,2,US", True, | |
309 | "example.com,0,4,*\nexample.org,1,2,US"), | |
310 | ("update_identifier", "4", False), | |
311 | ("provisioning_sp", "sp.example.com", True), | |
312 | ("sp_priority", "7", False), | |
313 | ("min_dl_bandwidth_home", "100", False), | |
314 | ("min_ul_bandwidth_home", "101", False), | |
315 | ("min_dl_bandwidth_roaming", "102", False), | |
316 | ("min_ul_bandwidth_roaming", "103", False), | |
317 | ("max_bss_load", "57", False), | |
318 | ("req_conn_capab", "6:22,80,443", False), | |
319 | ("req_conn_capab", "17:500", False, "6:22,80,443\n17:500"), | |
320 | ("req_conn_capab", "50", False, "6:22,80,443\n17:500\n50"), | |
321 | ("ocsp", "1", False) ] | |
322 | for v in values: | |
323 | if v[2]: | |
324 | set_cred_quoted(dev[0], id, v[0], v[1]) | |
325 | else: | |
326 | set_cred(dev[0], id, v[0], v[1]) | |
327 | val = dev[0].get_cred(id, v[0]) | |
328 | if len(v) == 4: | |
329 | expect = v[3] | |
330 | else: | |
331 | expect = v[1] | |
332 | if val != expect: | |
333 | raise Exception("Unexpected GET_CRED value for {}: {} != {}".format(v[0], val, expect)) | |
c7a4bf82 JM |
334 | creds = dev[0].request("LIST_CREDS").splitlines() |
335 | if len(creds) != 2: | |
336 | raise Exception("Unexpected LIST_CREDS result(3)") | |
337 | if creds[1] != "0\texample.com\tuser@example.com\texample.com\t310026-000000000": | |
338 | raise Exception("Unexpected LIST_CREDS value") | |
aa45859e | 339 | remove_cred(dev[0], id) |
c7a4bf82 JM |
340 | if len(dev[0].request("LIST_CREDS").splitlines()) != 1: |
341 | raise Exception("Unexpected LIST_CREDS result(4)") | |
aa45859e | 342 | |
ca5b81a5 JM |
343 | def test_wpas_ctrl_pno(dev): |
344 | """wpa_supplicant ctrl_iface pno""" | |
345 | if "FAIL" not in dev[0].request("SET pno 1"): | |
346 | raise Exception("Unexpected success in enabling PNO without enabled network blocks") | |
347 | id = dev[0].add_network() | |
348 | dev[0].set_network_quoted(id, "ssid", "test") | |
349 | dev[0].set_network(id, "key_mgmt", "NONE") | |
350 | dev[0].request("ENABLE_NETWORK " + str(id) + " no-connect") | |
351 | #mac80211_hwsim does not yet support PNO, so this fails | |
352 | if "FAIL" not in dev[0].request("SET pno 1"): | |
353 | raise Exception("Unexpected success in enabling PNO") | |
fa9e07ec JM |
354 | if "FAIL" not in dev[0].request("SET pno 1 freq=2000-3000,5180"): |
355 | raise Exception("Unexpected success in enabling PNO") | |
356 | if "FAIL" not in dev[0].request("SET pno 1 freq=0-6000"): | |
357 | raise Exception("Unexpected success in enabling PNO") | |
ca5b81a5 JM |
358 | if "FAIL" in dev[0].request("SET pno 0"): |
359 | raise Exception("Unexpected failure in disabling PNO") | |
360 | ||
361 | def test_wpas_ctrl_get(dev): | |
362 | """wpa_supplicant ctrl_iface get""" | |
363 | if "FAIL" in dev[0].request("GET version"): | |
364 | raise Exception("Unexpected get failure for version") | |
365 | if "FAIL" in dev[0].request("GET wifi_display"): | |
366 | raise Exception("Unexpected get failure for wifi_display") | |
367 | if "FAIL" not in dev[0].request("GET foo"): | |
368 | raise Exception("Unexpected success on get command") | |
369 | ||
370 | def test_wpas_ctrl_preauth(dev): | |
371 | """wpa_supplicant ctrl_iface preauth""" | |
372 | if "FAIL" not in dev[0].request("PREAUTH "): | |
373 | raise Exception("Unexpected success on invalid PREAUTH") | |
374 | if "FAIL" in dev[0].request("PREAUTH 00:11:22:33:44:55"): | |
375 | raise Exception("Unexpected failure on PREAUTH") | |
376 | ||
377 | def test_wpas_ctrl_stkstart(dev): | |
378 | """wpa_supplicant ctrl_iface strkstart""" | |
379 | if "FAIL" not in dev[0].request("STKSTART "): | |
380 | raise Exception("Unexpected success on invalid STKSTART") | |
381 | if "FAIL" not in dev[0].request("STKSTART 00:11:22:33:44:55"): | |
382 | raise Exception("Unexpected success on STKSTART") | |
383 | ||
384 | def test_wpas_ctrl_tdls_discover(dev): | |
385 | """wpa_supplicant ctrl_iface tdls_discover""" | |
386 | if "FAIL" not in dev[0].request("TDLS_DISCOVER "): | |
387 | raise Exception("Unexpected success on invalid TDLS_DISCOVER") | |
388 | if "FAIL" not in dev[0].request("TDLS_DISCOVER 00:11:22:33:44:55"): | |
389 | raise Exception("Unexpected success on TDLS_DISCOVER") | |
2ded0539 | 390 | |
2f35bc64 JM |
391 | def test_wpas_ctrl_addr(dev): |
392 | """wpa_supplicant ctrl_iface invalid address""" | |
393 | if "FAIL" not in dev[0].request("TDLS_SETUP "): | |
394 | raise Exception("Unexpected success on invalid TDLS_SETUP") | |
395 | if "FAIL" not in dev[0].request("TDLS_TEARDOWN "): | |
396 | raise Exception("Unexpected success on invalid TDLS_TEARDOWN") | |
397 | if "FAIL" not in dev[0].request("FT_DS "): | |
398 | raise Exception("Unexpected success on invalid FT_DS") | |
399 | if "FAIL" not in dev[0].request("WPS_PBC 00:11:22:33:44"): | |
400 | raise Exception("Unexpected success on invalid WPS_PBC") | |
401 | if "FAIL" not in dev[0].request("WPS_PIN 00:11:22:33:44"): | |
402 | raise Exception("Unexpected success on invalid WPS_PIN") | |
403 | if "FAIL" not in dev[0].request("WPS_NFC 00:11:22:33:44"): | |
404 | raise Exception("Unexpected success on invalid WPS_NFC") | |
20fd210a | 405 | if "FAIL" not in dev[0].request("WPS_REG 00:11:22:33:44 12345670"): |
2f35bc64 JM |
406 | raise Exception("Unexpected success on invalid WPS_REG") |
407 | if "FAIL" not in dev[0].request("IBSS_RSN 00:11:22:33:44"): | |
408 | raise Exception("Unexpected success on invalid IBSS_RSN") | |
5f0e5932 JM |
409 | if "FAIL" not in dev[0].request("BLACKLIST 00:11:22:33:44"): |
410 | raise Exception("Unexpected success on invalid BLACKLIST") | |
2f35bc64 | 411 | |
20fd210a JM |
412 | def test_wpas_ctrl_wps_errors(dev): |
413 | """wpa_supplicant ctrl_iface WPS error cases""" | |
414 | if "FAIL" not in dev[0].request("WPS_REG 00:11:22:33:44:55"): | |
415 | raise Exception("Unexpected success on invalid WPS_REG") | |
416 | if "FAIL" not in dev[0].request("WPS_REG 00:11:22:33:44:55 12345670 2233"): | |
417 | raise Exception("Unexpected success on invalid WPS_REG") | |
418 | if "FAIL" not in dev[0].request("WPS_REG 00:11:22:33:44:55 12345670 2233 OPEN"): | |
419 | raise Exception("Unexpected success on invalid WPS_REG") | |
420 | if "FAIL" not in dev[0].request("WPS_REG 00:11:22:33:44:55 12345670 2233 OPEN NONE"): | |
421 | raise Exception("Unexpected success on invalid WPS_REG") | |
422 | ||
423 | if "FAIL" not in dev[0].request("WPS_AP_PIN random"): | |
424 | raise Exception("Unexpected success on WPS_AP_PIN in non-AP mode") | |
425 | ||
426 | if "FAIL" not in dev[0].request("WPS_ER_PIN any"): | |
427 | raise Exception("Unexpected success on invalid WPS_ER_PIN") | |
428 | ||
429 | if "FAIL" not in dev[0].request("WPS_ER_LEARN 00:11:22:33:44:55"): | |
430 | raise Exception("Unexpected success on invalid WPS_ER_LEARN") | |
431 | ||
432 | if "FAIL" not in dev[0].request("WPS_ER_SET_CONFIG 00:11:22:33:44:55"): | |
433 | raise Exception("Unexpected success on invalid WPS_ER_SET_CONFIG") | |
434 | ||
435 | if "FAIL" not in dev[0].request("WPS_ER_CONFIG 00:11:22:33:44:55"): | |
436 | raise Exception("Unexpected success on invalid WPS_ER_CONFIG") | |
437 | if "FAIL" not in dev[0].request("WPS_ER_CONFIG 00:11:22:33:44:55 12345670"): | |
438 | raise Exception("Unexpected success on invalid WPS_ER_CONFIG") | |
439 | if "FAIL" not in dev[0].request("WPS_ER_CONFIG 00:11:22:33:44:55 12345670 2233"): | |
440 | raise Exception("Unexpected success on invalid WPS_ER_CONFIG") | |
441 | if "FAIL" not in dev[0].request("WPS_ER_CONFIG 00:11:22:33:44:55 12345670 2233 OPEN"): | |
442 | raise Exception("Unexpected success on invalid WPS_ER_CONFIG") | |
443 | if "FAIL" not in dev[0].request("WPS_ER_CONFIG 00:11:22:33:44:55 12345670 2233 OPEN NONE"): | |
444 | raise Exception("Unexpected success on invalid WPS_ER_CONFIG") | |
445 | ||
446 | if "FAIL" not in dev[0].request("WPS_ER_NFC_CONFIG_TOKEN WPS"): | |
447 | raise Exception("Unexpected success on invalid WPS_ER_NFC_CONFIG_TOKEN") | |
448 | if "FAIL" not in dev[0].request("WPS_ER_NFC_CONFIG_TOKEN FOO 00:11:22:33:44:55"): | |
449 | raise Exception("Unexpected success on invalid WPS_ER_NFC_CONFIG_TOKEN") | |
450 | if "FAIL" not in dev[0].request("WPS_ER_NFC_CONFIG_TOKEN NDEF 00:11:22:33:44:55"): | |
451 | raise Exception("Unexpected success on invalid WPS_ER_NFC_CONFIG_TOKEN") | |
452 | ||
2ded0539 JM |
453 | def test_wpas_ctrl_config_parser(dev): |
454 | """wpa_supplicant ctrl_iface SET config parser""" | |
455 | if "FAIL" not in dev[0].request("SET pbc_in_m1 qwerty"): | |
456 | raise Exception("Non-number accepted as integer") | |
457 | if "FAIL" not in dev[0].request("SET eapol_version 0"): | |
458 | raise Exception("Out-of-range value accepted") | |
459 | if "FAIL" not in dev[0].request("SET eapol_version 10"): | |
460 | raise Exception("Out-of-range value accepted") | |
461 | ||
462 | if "FAIL" not in dev[0].request("SET serial_number 0123456789abcdef0123456789abcdef0"): | |
463 | raise Exception("Too long string accepted") | |
44bb9106 JM |
464 | |
465 | def test_wpas_ctrl_mib(dev): | |
466 | """wpa_supplicant ctrl_iface MIB""" | |
467 | mib = dev[0].get_mib() | |
468 | if "dot11RSNAOptionImplemented" not in mib: | |
469 | raise Exception("Missing MIB entry") | |
470 | if mib["dot11RSNAOptionImplemented"] != "TRUE": | |
471 | raise Exception("Unexpected dot11RSNAOptionImplemented value") | |
fb8d53e0 JM |
472 | |
473 | def test_wpas_ctrl_set_wps_params(dev): | |
474 | """wpa_supplicant ctrl_iface SET config_methods""" | |
475 | ts = [ "config_methods label virtual_display virtual_push_button keypad", | |
476 | "device_type 1-0050F204-1", | |
477 | "os_version 01020300", | |
478 | "uuid 12345678-9abc-def0-1234-56789abcdef0" ] | |
479 | for t in ts: | |
480 | if "OK" not in dev[2].request("SET " + t): | |
481 | raise Exception("SET failed for: " + t) | |
a408873c JM |
482 | |
483 | def test_wpas_ctrl_level(dev): | |
484 | """wpa_supplicant ctrl_iface LEVEL""" | |
485 | try: | |
486 | if "FAIL" not in dev[2].request("LEVEL 3"): | |
487 | raise Exception("Unexpected LEVEL success") | |
488 | if "OK" not in dev[2].mon.request("LEVEL 2"): | |
489 | raise Exception("Unexpected LEVEL failure") | |
490 | dev[2].request("SCAN freq=2412") | |
491 | ev = dev[2].wait_event(["State:"], timeout=5) | |
492 | if ev is None: | |
493 | raise Exception("No debug message received") | |
494 | dev[2].wait_event(["CTRL-EVENT-SCAN-RESULTS"], timeout=5) | |
495 | finally: | |
496 | dev[2].mon.request("LEVEL 3") | |
9f52e97d JM |
497 | |
498 | def test_wpas_ctrl_bssid_filter(dev, apdev): | |
499 | """wpa_supplicant bssid_filter""" | |
500 | try: | |
501 | if "OK" not in dev[2].request("SET bssid_filter " + apdev[0]['bssid']): | |
502 | raise Exception("Failed to set bssid_filter") | |
503 | params = { "ssid": "test" } | |
504 | hostapd.add_ap(apdev[0]['ifname'], params) | |
505 | hostapd.add_ap(apdev[1]['ifname'], params) | |
506 | dev[2].scan(freq="2412") | |
507 | bss = dev[2].get_bss(apdev[0]['bssid']) | |
508 | if len(bss) == 0: | |
509 | raise Exception("Missing BSS data") | |
510 | bss = dev[2].get_bss(apdev[1]['bssid']) | |
511 | if len(bss) != 0: | |
512 | raise Exception("Unexpected BSS data") | |
513 | dev[2].request("SET bssid_filter ") | |
514 | dev[2].scan(freq="2412") | |
515 | bss = dev[2].get_bss(apdev[0]['bssid']) | |
516 | if len(bss) == 0: | |
517 | raise Exception("Missing BSS data") | |
518 | bss = dev[2].get_bss(apdev[1]['bssid']) | |
519 | if len(bss) == 0: | |
520 | raise Exception("Missing BSS data(2)") | |
939f5b26 JM |
521 | res = dev[2].request("SCAN_RESULTS").splitlines() |
522 | if "test" not in res[1] or "test" not in res[2]: | |
523 | raise Exception("SSID missing from SCAN_RESULTS") | |
524 | if apdev[0]['bssid'] not in res[1] and apdev[1]['bssid'] not in res[1]: | |
525 | raise Exception("BSS1 missing from SCAN_RESULTS") | |
526 | if apdev[0]['bssid'] not in res[2] and apdev[1]['bssid'] not in res[2]: | |
527 | raise Exception("BSS1 missing from SCAN_RESULTS") | |
4f23926c JM |
528 | |
529 | if "FAIL" not in dev[2].request("SET bssid_filter 00:11:22:33:44:55 00:11:22:33:44"): | |
530 | raise Exception("Unexpected success for invalid SET bssid_filter") | |
9f52e97d JM |
531 | finally: |
532 | dev[2].request("SET bssid_filter ") | |
14692fa4 JM |
533 | |
534 | def test_wpas_ctrl_disallow_aps(dev, apdev): | |
535 | """wpa_supplicant ctrl_iface disallow_aps""" | |
536 | params = { "ssid": "test" } | |
537 | hostapd.add_ap(apdev[0]['ifname'], params) | |
538 | ||
539 | if "FAIL" not in dev[0].request("SET disallow_aps bssid "): | |
540 | raise Exception("Unexpected success on invalid disallow_aps") | |
541 | if "FAIL" not in dev[0].request("SET disallow_aps bssid 00:11:22:33:44"): | |
542 | raise Exception("Unexpected success on invalid disallow_aps") | |
543 | if "FAIL" not in dev[0].request("SET disallow_aps ssid 0"): | |
544 | raise Exception("Unexpected success on invalid disallow_aps") | |
545 | if "FAIL" not in dev[0].request("SET disallow_aps ssid 4q"): | |
546 | raise Exception("Unexpected success on invalid disallow_aps") | |
4f23926c JM |
547 | if "FAIL" not in dev[0].request("SET disallow_aps bssid 00:11:22:33:44:55 ssid 112233 ssid 123"): |
548 | raise Exception("Unexpected success on invalid disallow_aps") | |
14692fa4 JM |
549 | if "FAIL" not in dev[0].request("SET disallow_aps ssid 000102030405060708090a0b0c0d0e0f000102030405060708090a0b0c0d0e0f00"): |
550 | raise Exception("Unexpected success on invalid disallow_aps") | |
551 | if "FAIL" not in dev[0].request("SET disallow_aps foo 112233445566"): | |
552 | raise Exception("Unexpected success on invalid disallow_aps") | |
553 | ||
554 | dev[0].connect("test", key_mgmt="NONE", scan_freq="2412") | |
555 | hostapd.add_ap(apdev[1]['ifname'], params) | |
556 | dev[0].dump_monitor() | |
4f23926c JM |
557 | if "OK" not in dev[0].request("SET disallow_aps bssid 00:11:22:33:44:55 bssid 00:22:33:44:55:66"): |
558 | raise Exception("Failed to set disallow_aps") | |
14692fa4 JM |
559 | if "OK" not in dev[0].request("SET disallow_aps bssid " + apdev[0]['bssid']): |
560 | raise Exception("Failed to set disallow_aps") | |
561 | ev = dev[0].wait_event(["CTRL-EVENT-CONNECTED"], timeout=15) | |
562 | if ev is None: | |
563 | raise Exception("Reassociation timed out") | |
564 | if apdev[1]['bssid'] not in ev: | |
565 | raise Exception("Unexpected BSSID") | |
566 | ||
567 | dev[0].dump_monitor() | |
568 | if "OK" not in dev[0].request("SET disallow_aps ssid " + "test".encode("hex")): | |
569 | raise Exception("Failed to set disallow_aps") | |
570 | ev = dev[0].wait_event(["CTRL-EVENT-DISCONNECTED"], timeout=5) | |
571 | if ev is None: | |
572 | raise Exception("Disconnection not seen") | |
573 | ev = dev[0].wait_event(["CTRL-EVENT-CONNECTED"], timeout=1) | |
574 | if ev is not None: | |
575 | raise Exception("Unexpected reassociation") | |
4993179d JM |
576 | |
577 | def test_wpas_ctrl_blob(dev): | |
578 | """wpa_supplicant ctrl_iface SET blob""" | |
579 | if "FAIL" not in dev[0].request("SET blob foo"): | |
580 | raise Exception("Unexpected SET success") | |
581 | if "FAIL" not in dev[0].request("SET blob foo 0"): | |
582 | raise Exception("Unexpected SET success") | |
583 | if "FAIL" not in dev[0].request("SET blob foo 0q"): | |
584 | raise Exception("Unexpected SET success") | |
585 | if "OK" not in dev[0].request("SET blob foo 00"): | |
586 | raise Exception("Unexpected SET failure") | |
587 | if "OK" not in dev[0].request("SET blob foo 0011"): | |
588 | raise Exception("Unexpected SET failure") | |
07407c0a JM |
589 | |
590 | def test_wpas_ctrl_set_uapsd(dev): | |
591 | """wpa_supplicant ctrl_iface SET uapsd""" | |
592 | if "FAIL" not in dev[0].request("SET uapsd foo"): | |
593 | raise Exception("Unexpected SET success") | |
594 | if "FAIL" not in dev[0].request("SET uapsd 0,0,0"): | |
595 | raise Exception("Unexpected SET success") | |
596 | if "FAIL" not in dev[0].request("SET uapsd 0,0"): | |
597 | raise Exception("Unexpected SET success") | |
598 | if "FAIL" not in dev[0].request("SET uapsd 0"): | |
599 | raise Exception("Unexpected SET success") | |
4f23926c JM |
600 | if "OK" not in dev[0].request("SET uapsd 1,1,1,1;1"): |
601 | raise Exception("Unexpected SET failure") | |
07407c0a JM |
602 | if "OK" not in dev[0].request("SET uapsd 0,0,0,0;0"): |
603 | raise Exception("Unexpected SET failure") | |
604 | if "OK" not in dev[0].request("SET uapsd disable"): | |
605 | raise Exception("Unexpected SET failure") | |
4ea378cd | 606 | |
4f23926c JM |
607 | def test_wpas_ctrl_set(dev): |
608 | """wpa_supplicant ctrl_iface SET""" | |
609 | vals = [ "foo", | |
610 | "dot11RSNAConfigPMKLifetime 0", | |
611 | "dot11RSNAConfigPMKReauthThreshold 101", | |
612 | "dot11RSNAConfigSATimeout 0", | |
613 | "wps_version_number -1", | |
614 | "wps_version_number 256" ] | |
615 | for val in vals: | |
616 | if "FAIL" not in dev[0].request("SET " + val): | |
617 | raise Exception("Unexpected SET success for " + val) | |
618 | ||
619 | vals = [ "EAPOL::heldPeriod 60", | |
620 | "EAPOL::authPeriod 30", | |
621 | "EAPOL::startPeriod 30", | |
622 | "EAPOL::maxStart 3", | |
623 | "dot11RSNAConfigSATimeout 60", | |
624 | "tdls_disabled 1", | |
625 | "tdls_disabled 0" ] | |
626 | for val in vals: | |
627 | if "OK" not in dev[0].request("SET " + val): | |
628 | raise Exception("Unexpected SET failure for " + val) | |
629 | ||
4ea378cd JM |
630 | def test_wpas_ctrl_get_capability(dev): |
631 | """wpa_supplicant ctrl_iface GET_CAPABILITY""" | |
632 | res = dev[0].get_capability("eap") | |
633 | if "TTLS" not in res: | |
634 | raise Exception("Unexpected GET_CAPABILITY eap response: " + str(res)) | |
635 | ||
636 | res = dev[0].get_capability("pairwise") | |
637 | if "CCMP" not in res: | |
638 | raise Exception("Unexpected GET_CAPABILITY pairwise response: " + str(res)) | |
639 | ||
640 | res = dev[0].get_capability("group") | |
641 | if "CCMP" not in res: | |
642 | raise Exception("Unexpected GET_CAPABILITY group response: " + str(res)) | |
643 | ||
644 | res = dev[0].get_capability("key_mgmt") | |
645 | if "WPA-PSK" not in res or "WPA-EAP" not in res: | |
646 | raise Exception("Unexpected GET_CAPABILITY key_mgmt response: " + str(res)) | |
647 | ||
648 | res = dev[0].get_capability("proto") | |
649 | if "WPA" not in res or "RSN" not in res: | |
650 | raise Exception("Unexpected GET_CAPABILITY proto response: " + str(res)) | |
651 | ||
652 | res = dev[0].get_capability("auth_alg") | |
653 | if "OPEN" not in res or "SHARED" not in res: | |
654 | raise Exception("Unexpected GET_CAPABILITY auth_alg response: " + str(res)) | |
655 | ||
656 | res = dev[0].get_capability("modes") | |
657 | if "IBSS" not in res or "AP" not in res: | |
658 | raise Exception("Unexpected GET_CAPABILITY modes response: " + str(res)) | |
659 | ||
660 | res = dev[0].get_capability("channels") | |
661 | if "8" not in res or "36" not in res: | |
662 | raise Exception("Unexpected GET_CAPABILITY channels response: " + str(res)) | |
663 | ||
664 | res = dev[0].get_capability("freq") | |
665 | if "2457" not in res or "5180" not in res: | |
666 | raise Exception("Unexpected GET_CAPABILITY freq response: " + str(res)) | |
667 | ||
668 | res = dev[0].get_capability("tdls") | |
669 | if "EXTERNAL" not in res[0]: | |
670 | raise Exception("Unexpected GET_CAPABILITY tdls response: " + str(res)) | |
671 | ||
672 | if dev[0].get_capability("foo") is not None: | |
673 | raise Exception("Unexpected GET_CAPABILITY foo response: " + str(res)) | |
d6e88ee9 JM |
674 | |
675 | def test_wpas_ctrl_nfc_report_handover(dev): | |
676 | """wpa_supplicant ctrl_iface NFC_REPORT_HANDOVER""" | |
677 | vals = [ "FOO", | |
678 | "ROLE freq=12345", | |
679 | "ROLE TYPE", | |
680 | "ROLE TYPE REQ", | |
681 | "ROLE TYPE REQ SEL", | |
682 | "ROLE TYPE 0Q SEL", | |
683 | "ROLE TYPE 00 SEL", | |
684 | "ROLE TYPE 00 0Q", | |
685 | "ROLE TYPE 00 00" ] | |
686 | for v in vals: | |
687 | if "FAIL" not in dev[0].request("NFC_REPORT_HANDOVER " + v): | |
688 | raise Exception("Unexpected NFC_REPORT_HANDOVER success for " + v) | |
2eaf55c2 | 689 | |
ad38f1f0 JM |
690 | def test_wpas_ctrl_nfc_tag_read(dev): |
691 | """wpa_supplicant ctrl_iface WPS_NFC_TAG_READ""" | |
692 | vals = [ "FOO", "0Q", "00", "000000", "10000001", "10000000", "00000000", | |
693 | "100e0000", "100e0001ff", "100e000411110000", "100e0004100e0001" ] | |
694 | for v in vals: | |
695 | if "FAIL" not in dev[0].request("WPS_NFC_TAG_READ " + v): | |
696 | raise Exception("Unexpected WPS_NFC_TAG_READ success for " + v) | |
697 | ||
aed1c056 JM |
698 | def test_wpas_ctrl_nfc_get_handover(dev): |
699 | """wpa_supplicant ctrl_iface NFC_GET_HANDOVER""" | |
700 | vals = [ "FOO", "FOO BAR", "WPS WPS", "WPS WPS-CR", "WPS FOO", "NDEF P2P" ] | |
701 | for v in vals: | |
702 | if "FAIL" not in dev[0].request("NFC_GET_HANDOVER_REQ " + v): | |
703 | raise Exception("Unexpected NFC_GET_HANDOVER_REQ success for " + v) | |
704 | ||
705 | vals = [ "NDEF WPS", "NDEF P2P-CR", "WPS P2P-CR" ] | |
706 | for v in vals: | |
707 | if "FAIL" in dev[0].request("NFC_GET_HANDOVER_REQ " + v): | |
708 | raise Exception("Unexpected NFC_GET_HANDOVER_REQ failure for " + v) | |
709 | ||
710 | vals = [ "FOO", "FOO BAR", "WPS WPS", "WPS WPS-CR", "WPS FOO", "NDEF P2P", | |
711 | "NDEF WPS", "NDEF WPS uuid" ] | |
712 | for v in vals: | |
713 | if "FAIL" not in dev[0].request("NFC_GET_HANDOVER_SEL " + v): | |
714 | raise Exception("Unexpected NFC_GET_HANDOVER_SEL success for " + v) | |
715 | ||
716 | vals = [ "NDEF P2P-CR", "WPS P2P-CR", "NDEF P2P-CR-TAG", | |
717 | "WPS P2P-CR-TAG" ] | |
718 | for v in vals: | |
719 | if "FAIL" in dev[0].request("NFC_GET_HANDOVER_SEL " + v): | |
720 | raise Exception("Unexpected NFC_GET_HANDOVER_SEL failure for " + v) | |
721 | ||
2eaf55c2 JM |
722 | def get_blacklist(dev): |
723 | return dev.request("BLACKLIST").splitlines() | |
724 | ||
725 | def test_wpas_ctrl_blacklist(dev): | |
726 | """wpa_supplicant ctrl_iface BLACKLIST""" | |
727 | if "OK" not in dev[0].request("BLACKLIST clear"): | |
728 | raise Exception("BLACKLIST clear failed") | |
729 | b = get_blacklist(dev[0]) | |
730 | if len(b) != 0: | |
731 | raise Exception("Unexpected blacklist contents: " + str(b)) | |
732 | if "OK" not in dev[0].request("BLACKLIST 00:11:22:33:44:55"): | |
733 | raise Exception("BLACKLIST add failed") | |
734 | b = get_blacklist(dev[0]) | |
735 | if "00:11:22:33:44:55" not in b: | |
736 | raise Exception("Unexpected blacklist contents: " + str(b)) | |
737 | if "OK" not in dev[0].request("BLACKLIST 00:11:22:33:44:56"): | |
738 | raise Exception("BLACKLIST add failed") | |
739 | b = get_blacklist(dev[0]) | |
740 | if "00:11:22:33:44:55" not in b or "00:11:22:33:44:56" not in b: | |
741 | raise Exception("Unexpected blacklist contents: " + str(b)) | |
742 | if "OK" not in dev[0].request("BLACKLIST 00:11:22:33:44:56"): | |
743 | raise Exception("BLACKLIST add failed") | |
744 | b = get_blacklist(dev[0]) | |
745 | if "00:11:22:33:44:55" not in b or "00:11:22:33:44:56" not in b or len(b) != 2: | |
746 | raise Exception("Unexpected blacklist contents: " + str(b)) | |
747 | ||
748 | if "OK" not in dev[0].request("BLACKLIST clear"): | |
749 | raise Exception("BLACKLIST clear failed") | |
750 | if dev[0].request("BLACKLIST") != "": | |
751 | raise Exception("Unexpected blacklist contents") | |
82146a86 JM |
752 | |
753 | def test_wpas_ctrl_log_level(dev): | |
754 | """wpa_supplicant ctrl_iface LOG_LEVEL""" | |
755 | level = dev[2].request("LOG_LEVEL") | |
756 | if "Current level: MSGDUMP" not in level: | |
757 | raise Exception("Unexpected debug level(1): " + level) | |
758 | if "Timestamp: 1" not in level: | |
759 | raise Exception("Unexpected timestamp(1): " + level) | |
760 | ||
761 | if "OK" not in dev[2].request("LOG_LEVEL MSGDUMP 0"): | |
762 | raise Exception("LOG_LEVEL failed") | |
763 | level = dev[2].request("LOG_LEVEL") | |
764 | if "Current level: MSGDUMP" not in level: | |
765 | raise Exception("Unexpected debug level(2): " + level) | |
766 | if "Timestamp: 0" not in level: | |
767 | raise Exception("Unexpected timestamp(2): " + level) | |
768 | ||
769 | if "OK" not in dev[2].request("LOG_LEVEL MSGDUMP 1"): | |
770 | raise Exception("LOG_LEVEL failed") | |
771 | level = dev[2].request("LOG_LEVEL") | |
772 | if "Current level: MSGDUMP" not in level: | |
773 | raise Exception("Unexpected debug level(3): " + level) | |
774 | if "Timestamp: 1" not in level: | |
775 | raise Exception("Unexpected timestamp(3): " + level) | |
776 | ||
777 | if "FAIL" not in dev[2].request("LOG_LEVEL FOO"): | |
778 | raise Exception("Invalid LOG_LEVEL accepted") | |
779 | ||
780 | for lev in [ "EXCESSIVE", "MSGDUMP", "DEBUG", "INFO", "WARNING", "ERROR" ]: | |
781 | if "OK" not in dev[2].request("LOG_LEVEL " + lev): | |
782 | raise Exception("LOG_LEVEL failed for " + lev) | |
783 | level = dev[2].request("LOG_LEVEL") | |
784 | if "Current level: " + lev not in level: | |
785 | raise Exception("Unexpected debug level: " + level) | |
786 | ||
787 | if "OK" not in dev[2].request("LOG_LEVEL MSGDUMP 1"): | |
788 | raise Exception("LOG_LEVEL failed") | |
789 | level = dev[2].request("LOG_LEVEL") | |
790 | if "Current level: MSGDUMP" not in level: | |
791 | raise Exception("Unexpected debug level(3): " + level) | |
792 | if "Timestamp: 1" not in level: | |
793 | raise Exception("Unexpected timestamp(3): " + level) | |
e4ac747c JM |
794 | |
795 | def test_wpas_ctrl_enable_disable_network(dev, apdev): | |
796 | """wpa_supplicant ctrl_iface ENABLE/DISABLE_NETWORK""" | |
797 | params = { "ssid": "test" } | |
798 | hostapd.add_ap(apdev[0]['ifname'], params) | |
799 | ||
800 | id = dev[0].connect("test", key_mgmt="NONE", scan_freq="2412", | |
801 | only_add_network=True) | |
802 | if "OK" not in dev[0].request("DISABLE_NETWORK " + str(id)): | |
803 | raise Exception("Failed to disable network") | |
804 | if "OK" not in dev[0].request("ENABLE_NETWORK " + str(id) + " no-connect"): | |
805 | raise Exception("Failed to enable network") | |
806 | if "OK" not in dev[0].request("DISABLE_NETWORK all"): | |
807 | raise Exception("Failed to disable networks") | |
808 | if "OK" not in dev[0].request("ENABLE_NETWORK " + str(id)): | |
809 | raise Exception("Failed to enable network") | |
810 | ev = dev[0].wait_event(["CTRL-EVENT-CONNECTED"], timeout=10) | |
811 | if ev is None: | |
812 | raise Exception("Association with the AP timed out") | |
813 | if "OK" not in dev[0].request("DISABLE_NETWORK " + str(id)): | |
814 | raise Exception("Failed to disable network") | |
815 | ev = dev[0].wait_event(["CTRL-EVENT-DISCONNECTED"], timeout=10) | |
816 | if ev is None: | |
817 | raise Exception("Disconnection with the AP timed out") | |
818 | time.sleep(0.1) | |
819 | ||
820 | if "OK" not in dev[0].request("ENABLE_NETWORK all"): | |
821 | raise Exception("Failed to enable network") | |
822 | ev = dev[0].wait_event(["CTRL-EVENT-CONNECTED"], timeout=10) | |
823 | if ev is None: | |
824 | raise Exception("Association with the AP timed out") | |
825 | if "OK" not in dev[0].request("DISABLE_NETWORK all"): | |
826 | raise Exception("Failed to disable network") | |
827 | ev = dev[0].wait_event(["CTRL-EVENT-DISCONNECTED"], timeout=10) | |
828 | if ev is None: | |
829 | raise Exception("Disconnection with the AP timed out") | |
c9075f62 JM |
830 | |
831 | def test_wpas_ctrl_country(dev, apdev): | |
832 | """wpa_supplicant SET/GET country code""" | |
833 | try: | |
2b46e698 JM |
834 | # work around issues with possible pending regdom event from the end of |
835 | # the previous test case | |
836 | time.sleep(0.2) | |
837 | dev[0].dump_monitor() | |
838 | ||
c9075f62 JM |
839 | if "OK" not in dev[0].request("SET country FI"): |
840 | raise Exception("Failed to set country code") | |
841 | if dev[0].request("GET country") != "FI": | |
842 | raise Exception("Country code set failed") | |
843 | ev = dev[0].wait_event(["CTRL-EVENT-REGDOM-CHANGE"]) | |
844 | if ev is None: | |
845 | raise Exception("regdom change event not seen") | |
846 | if "init=USER type=COUNTRY alpha2=FI" not in ev: | |
847 | raise Exception("Unexpected event contents: " + ev) | |
848 | dev[0].request("SET country 00") | |
849 | if dev[0].request("GET country") != "00": | |
850 | raise Exception("Country code set failed") | |
851 | ev = dev[0].wait_event(["CTRL-EVENT-REGDOM-CHANGE"]) | |
852 | if ev is None: | |
853 | raise Exception("regdom change event not seen") | |
854 | if "init=DRIVER type=WORLD" not in ev: | |
855 | raise Exception("Unexpected event contents: " + ev) | |
856 | finally: | |
857 | subprocess.call(['sudo', 'iw', 'reg', 'set', '00']) | |
d21939a6 JM |
858 | |
859 | def test_wpas_ctrl_suspend_resume(dev): | |
860 | """wpa_supplicant SUSPEND/RESUME""" | |
861 | wpas = WpaSupplicant(global_iface='/tmp/wpas-wlan5') | |
862 | wpas.interface_add("wlan5") | |
863 | if "OK" not in wpas.global_request("SUSPEND"): | |
864 | raise Exception("SUSPEND failed") | |
865 | time.sleep(1) | |
866 | if "OK" not in wpas.global_request("RESUME"): | |
867 | raise Exception("RESUME failed") | |
868 | if "OK" not in wpas.request("SUSPEND"): | |
869 | raise Exception("Per-interface SUSPEND failed") | |
870 | if "OK" not in wpas.request("RESUME"): | |
871 | raise Exception("Per-interface RESUME failed") | |
872 | ev = wpas.wait_event(["CTRL-EVENT-SCAN-RESULTS"], timeout=10) | |
873 | if ev is None: | |
874 | raise Exception("Scan not completed") | |
875 | ||
876 | def test_wpas_ctrl_global(dev): | |
877 | """wpa_supplicant global control interface""" | |
878 | wpas = WpaSupplicant(global_iface='/tmp/wpas-wlan5') | |
879 | wpas.interface_add("wlan5") | |
880 | ||
881 | if "PONG" not in wpas.global_request("PING"): | |
882 | raise Exception("PING failed") | |
883 | if "wlan5" not in wpas.global_request("INTERFACES"): | |
884 | raise Exception("Interface not found") | |
885 | if "UNKNOWN COMMAND" not in wpas.global_request("FOO"): | |
886 | raise Exception("Unexpected response to unknown command") | |
887 | if "PONG" not in wpas.global_request("IFNAME=wlan5 PING"): | |
888 | raise Exception("Per-interface PING failed") | |
889 | if "FAIL-NO-IFNAME-MATCH" not in wpas.global_request("IFNAME=notfound PING"): | |
890 | raise Exception("Unknown interface not reported correctly") | |
891 | if "FAIL" not in wpas.global_request("SAVE_CONFIG"): | |
892 | raise Exception("SAVE_CONFIG succeeded unexpectedly") | |
893 | if "OK" not in wpas.global_request("SET wifi_display 0"): | |
894 | raise Exception("SET failed") | |
895 | if "wifi_display=0" not in wpas.global_request("STATUS"): | |
896 | raise Exception("wifi_display not disabled") | |
897 | if "OK" not in wpas.global_request("SET wifi_display 1"): | |
898 | raise Exception("SET failed") | |
899 | if "wifi_display=1" not in wpas.global_request("STATUS"): | |
900 | raise Exception("wifi_display not enabled") | |
901 | if "FAIL" not in wpas.global_request("SET foo 1"): | |
902 | raise Exception("SET succeeded unexpectedly") | |
903 | ||
904 | if "p2p_state=IDLE" not in wpas.global_request("STATUS"): | |
905 | raise Exception("P2P was disabled") | |
906 | wpas.request("P2P_SET disabled 1") | |
907 | if "p2p_state=DISABLED" not in wpas.global_request("STATUS"): | |
908 | raise Exception("P2P was not disabled") | |
909 | wpas.request("P2P_SET disabled 0") | |
910 | if "p2p_state=IDLE" not in wpas.global_request("STATUS"): | |
911 | raise Exception("P2P was not enabled") | |
912 | ||
913 | # driver_nl80211.c does not support interface list, so do not fail because | |
914 | # of that | |
915 | logger.debug(wpas.global_request("INTERFACE_LIST")) | |
916 | ||
917 | if "FAIL" not in wpas.global_request("INTERFACE_ADD "): | |
918 | raise Exception("INTERFACE_ADD succeeded unexpectedly") | |
919 | if "FAIL" not in wpas.global_request("INTERFACE_ADD FOO"): | |
920 | raise Exception("INTERFACE_ADD succeeded unexpectedly") | |
2a354dc0 JM |
921 | if "FAIL" not in wpas.global_request("INTERFACE_ADD FOO conf"): |
922 | raise Exception("INTERFACE_ADD succeeded unexpectedly") | |
923 | if "FAIL" not in wpas.global_request("INTERFACE_ADD FOO conf driver"): | |
924 | raise Exception("INTERFACE_ADD succeeded unexpectedly") | |
925 | if "FAIL" not in wpas.global_request("INTERFACE_ADD FOO conf driver ctrliface"): | |
926 | raise Exception("INTERFACE_ADD succeeded unexpectedly") | |
927 | if "FAIL" not in wpas.global_request("INTERFACE_ADD FOO conf driver ctrliface driverparam"): | |
928 | raise Exception("INTERFACE_ADD succeeded unexpectedly") | |
d21939a6 JM |
929 | if "FAIL" not in wpas.global_request("INTERFACE_ADD FOO conf driver ctrliface driverparam bridge"): |
930 | raise Exception("INTERFACE_ADD succeeded unexpectedly") | |
2a354dc0 JM |
931 | if "FAIL" not in wpas.global_request("INTERFACE_ADD FOO conf driver ctrliface driverparam bridge foo"): |
932 | raise Exception("INTERFACE_ADD succeeded unexpectedly") | |
d21939a6 JM |
933 | if "FAIL" not in wpas.global_request("INTERFACE_ADD FOO "): |
934 | raise Exception("INTERFACE_ADD succeeded unexpectedly") |