1 # wpa_supplicant control interface
2 # Copyright (c) 2014, Qualcomm Atheros, Inc.
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 alloc_fail
16 def test_wpas_ctrl_network(dev):
17 """wpa_supplicant ctrl_iface network set/get"""
18 id = dev[0].add_network()
20 if "FAIL" not in dev[0].request("SET_NETWORK " + str(id)):
21 raise Exception("Unexpected success for invalid SET_NETWORK")
22 if "FAIL" not in dev[0].request("SET_NETWORK " + str(id) + " name"):
23 raise Exception("Unexpected success for invalid SET_NETWORK")
24 if "FAIL" not in dev[0].request("SET_NETWORK " + str(id + 1) + " proto OPEN"):
25 raise Exception("Unexpected success for invalid network id")
26 if "FAIL" not in dev[0].request("GET_NETWORK " + str(id)):
27 raise Exception("Unexpected success for invalid GET_NETWORK")
28 if "FAIL" not in dev[0].request("GET_NETWORK " + str(id + 1) + " proto"):
29 raise Exception("Unexpected success for invalid network id")
31 tests = (("key_mgmt", "WPA-PSK WPA-EAP IEEE8021X NONE WPA-NONE FT-PSK FT-EAP WPA-PSK-SHA256 WPA-EAP-SHA256"),
32 ("pairwise", "CCMP-256 GCMP-256 CCMP GCMP TKIP"),
33 ("group", "CCMP-256 GCMP-256 CCMP GCMP TKIP WEP104 WEP40"),
34 ("auth_alg", "OPEN SHARED LEAP"),
35 ("scan_freq", "1 2 3 4 5 6 7 8 9 10 11 12 13 14 15"),
36 ("freq_list", "2412 2417"),
38 ("bssid", "00:11:22:33:44:55"),
39 ("proto", "WPA RSN OSEN"),
41 ("go_p2p_dev_addr", "22:33:44:55:66:aa"),
42 ("p2p_client_list", "22:33:44:55:66:bb 02:11:22:33:44:55"))
44 dev[0].set_network_quoted(id, "ssid", "test")
45 for field, value in tests:
46 dev[0].set_network(id, field, value)
47 res = dev[0].get_network(id, field)
49 raise Exception("Unexpected response for '" + field + "': '" + res + "'")
51 q_tests = (("identity", "hello"),
52 ("anonymous_identity", "foo@nowhere.com"))
53 for field, value in q_tests:
54 dev[0].set_network_quoted(id, field, value)
55 res = dev[0].get_network(id, field)
56 if res != '"' + value + '"':
57 raise Exception("Unexpected quoted response for '" + field + "': '" + res + "'")
59 get_tests = (("foo", None), ("ssid", '"test"'))
60 for field, value in get_tests:
61 res = dev[0].get_network(id, field)
63 raise Exception("Unexpected response for '" + field + "': '" + res + "'")
65 if dev[0].get_network(id, "password"):
66 raise Exception("Unexpected response for 'password'")
67 dev[0].set_network_quoted(id, "password", "foo")
68 if dev[0].get_network(id, "password") != '*':
69 raise Exception("Unexpected response for 'password' (expected *)")
70 dev[0].set_network(id, "password", "hash:12345678901234567890123456789012")
71 if dev[0].get_network(id, "password") != '*':
72 raise Exception("Unexpected response for 'password' (expected *)")
73 dev[0].set_network(id, "password", "NULL")
74 if dev[0].get_network(id, "password"):
75 raise Exception("Unexpected response for 'password'")
76 if "FAIL" not in dev[0].request("SET_NETWORK " + str(id) + " password hash:12"):
77 raise Exception("Unexpected success for invalid password hash")
78 if "FAIL" not in dev[0].request("SET_NETWORK " + str(id) + " password hash:123456789012345678x0123456789012"):
79 raise Exception("Unexpected success for invalid password hash")
81 dev[0].set_network(id, "identity", "414243")
82 if dev[0].get_network(id, "identity") != '"ABC"':
83 raise Exception("Unexpected identity hex->text response")
85 dev[0].set_network(id, "identity", 'P"abc\ndef"')
86 if dev[0].get_network(id, "identity") != "6162630a646566":
87 raise Exception("Unexpected identity printf->hex response")
89 if "FAIL" not in dev[0].request("SET_NETWORK " + str(id) + ' identity P"foo'):
90 raise Exception("Unexpected success for invalid identity string")
92 if "FAIL" not in dev[0].request("SET_NETWORK " + str(id) + ' identity 12x3'):
93 raise Exception("Unexpected success for invalid identity string")
96 if "FAIL" in dev[0].request("SET_NETWORK " + str(id) + ' wep_key' + str(i) + ' aabbccddee'):
97 raise Exception("Unexpected wep_key set failure")
98 if dev[0].get_network(id, "wep_key" + str(i)) != '*':
99 raise Exception("Unexpected wep_key get failure")
101 if "FAIL" in dev[0].request("SET_NETWORK " + str(id) + ' psk_list P2P-00:11:22:33:44:55-0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef'):
102 raise Exception("Unexpected failure for psk_list string")
104 if "FAIL" not in dev[0].request("SET_NETWORK " + str(id) + ' psk_list 00:11:x2:33:44:55-0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef'):
105 raise Exception("Unexpected success for invalid psk_list string")
107 if "FAIL" not in dev[0].request("SET_NETWORK " + str(id) + ' psk_list P2P-00:11:x2:33:44:55-0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef'):
108 raise Exception("Unexpected success for invalid psk_list string")
110 if "FAIL" not in dev[0].request("SET_NETWORK " + str(id) + ' psk_list P2P-00:11:22:33:44:55+0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef'):
111 raise Exception("Unexpected success for invalid psk_list string")
113 if "FAIL" not in dev[0].request("SET_NETWORK " + str(id) + ' psk_list P2P-00:11:22:33:44:55-0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcde'):
114 raise Exception("Unexpected success for invalid psk_list string")
116 if "FAIL" not in dev[0].request("SET_NETWORK " + str(id) + ' psk_list P2P-00:11:22:33:44:55-0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdex'):
117 raise Exception("Unexpected success for invalid psk_list string")
119 if dev[0].get_network(id, "psk_list"):
120 raise Exception("Unexpected psk_list get response")
122 if dev[0].list_networks()[0]['ssid'] != "test":
123 raise Exception("Unexpected ssid in LIST_NETWORKS")
124 dev[0].set_network(id, "ssid", "NULL")
125 if dev[0].list_networks()[0]['ssid'] != "":
126 raise Exception("Unexpected ssid in LIST_NETWORKS after clearing it")
128 if "FAIL" not in dev[0].request('SET_NETWORK ' + str(id) + ' ssid "0123456789abcdef0123456789abcdef0"'):
129 raise Exception("Too long SSID accepted")
130 if "FAIL" not in dev[0].request('SET_NETWORK ' + str(id) + ' scan_ssid qwerty'):
131 raise Exception("Invalid integer accepted")
132 if "FAIL" not in dev[0].request('SET_NETWORK ' + str(id) + ' scan_ssid 2'):
133 raise Exception("Too large integer accepted")
134 if "FAIL" not in dev[0].request('SET_NETWORK ' + str(id) + ' psk 12345678'):
135 raise Exception("Invalid PSK accepted")
136 if "FAIL" not in dev[0].request('SET_NETWORK ' + str(id) + ' psk "1234567"'):
137 raise Exception("Too short PSK accepted")
138 if "FAIL" not in dev[0].request('SET_NETWORK ' + str(id) + ' psk "1234567890123456789012345678901234567890123456789012345678901234"'):
139 raise Exception("Too long PSK accepted")
140 dev[0].set_network_quoted(id, "psk", "123456768");
141 dev[0].set_network_quoted(id, "psk", "123456789012345678901234567890123456789012345678901234567890123");
142 if dev[0].get_network(id, "psk") != '*':
143 raise Exception("Unexpected psk read result");
145 if "FAIL" not in dev[0].request('SET_NETWORK ' + str(id) + ' eap UNKNOWN'):
146 raise Exception("Unknown EAP method accepted")
148 if "FAIL" not in dev[0].request('SET_NETWORK ' + str(id) + ' password "foo'):
149 raise Exception("Invalid password accepted")
151 if "FAIL" not in dev[0].request('SET_NETWORK ' + str(id) + ' wep_key0 "foo'):
152 raise Exception("Invalid WEP key accepted")
153 if "FAIL" not in dev[0].request('SET_NETWORK ' + str(id) + ' wep_key0 "12345678901234567"'):
154 raise Exception("Too long WEP key accepted")
155 # too short WEP key is ignored
156 dev[0].set_network_quoted(id, "wep_key0", "1234")
157 dev[0].set_network_quoted(id, "wep_key1", "12345")
158 dev[0].set_network_quoted(id, "wep_key2", "1234567890123")
159 dev[0].set_network_quoted(id, "wep_key3", "1234567890123456")
161 dev[0].set_network(id, "go_p2p_dev_addr", "any")
162 if dev[0].get_network(id, "go_p2p_dev_addr") is not None:
163 raise Exception("Unexpected go_p2p_dev_addr value")
164 if "FAIL" not in dev[0].request('SET_NETWORK ' + str(id) + ' go_p2p_dev_addr 00:11:22:33:44'):
165 raise Exception("Invalid go_p2p_dev_addr accepted")
166 if "FAIL" not in dev[0].request('SET_NETWORK ' + str(id) + ' p2p_client_list 00:11:22:33:44'):
167 raise Exception("Invalid p2p_client_list accepted")
168 if "FAIL" in dev[0].request('SET_NETWORK ' + str(id) + ' p2p_client_list 00:11:22:33:44:55 00:1'):
169 raise Exception("p2p_client_list truncation workaround failed")
170 if dev[0].get_network(id, "p2p_client_list") != "00:11:22:33:44:55":
171 raise Exception("p2p_client_list truncation workaround did not work")
173 if "FAIL" not in dev[0].request('SET_NETWORK ' + str(id) + ' auth_alg '):
174 raise Exception("Empty auth_alg accepted")
175 if "FAIL" not in dev[0].request('SET_NETWORK ' + str(id) + ' auth_alg FOO'):
176 raise Exception("Invalid auth_alg accepted")
178 if "FAIL" not in dev[0].request('SET_NETWORK ' + str(id) + ' proto '):
179 raise Exception("Empty proto accepted")
180 if "FAIL" not in dev[0].request('SET_NETWORK ' + str(id) + ' proto FOO'):
181 raise Exception("Invalid proto accepted")
183 if "FAIL" not in dev[0].request('SET_NETWORK ' + str(id) + ' pairwise '):
184 raise Exception("Empty pairwise accepted")
185 if "FAIL" not in dev[0].request('SET_NETWORK ' + str(id) + ' pairwise FOO'):
186 raise Exception("Invalid pairwise accepted")
187 if "FAIL" not in dev[0].request('SET_NETWORK ' + str(id) + ' pairwise WEP40'):
188 raise Exception("Invalid pairwise accepted")
190 if "OK" not in dev[0].request('BSSID ' + str(id) + ' 00:11:22:33:44:55'):
191 raise Exception("Unexpected BSSID failure")
192 if dev[0].request("GET_NETWORK 0 bssid") != '00:11:22:33:44:55':
193 raise Exception("BSSID command did not set network bssid")
194 if "OK" not in dev[0].request('BSSID ' + str(id) + ' 00:00:00:00:00:00'):
195 raise Exception("Unexpected BSSID failure")
196 if "FAIL" not in dev[0].request("GET_NETWORK 0 bssid"):
197 raise Exception("bssid claimed configured after clearing")
198 if "FAIL" not in dev[0].request('BSSID 123 00:11:22:33:44:55'):
199 raise Exception("Unexpected BSSID success")
200 if "FAIL" not in dev[0].request('BSSID ' + str(id) + ' 00:11:22:33:44'):
201 raise Exception("Unexpected BSSID success")
202 if "FAIL" not in dev[0].request('BSSID ' + str(id)):
203 raise Exception("Unexpected BSSID success")
205 tests = [ "02:11:22:33:44:55",
206 "02:11:22:33:44:55 02:ae:be:ce:53:77",
207 "02:11:22:33:44:55/ff:00:ff:00:ff:00",
208 "02:11:22:33:44:55/ff:00:ff:00:ff:00 f2:99:88:77:66:55",
209 "f2:99:88:77:66:55 02:11:22:33:44:55/ff:00:ff:00:ff:00",
210 "f2:99:88:77:66:55 02:11:22:33:44:55/ff:00:ff:00:ff:00 12:34:56:78:90:ab",
211 "02:11:22:33:44:55/ff:ff:ff:00:00:00 02:ae:be:ce:53:77/00:00:00:00:00:ff" ]
213 dev[0].set_network(id, "bssid_blacklist", val)
214 res = dev[0].get_network(id, "bssid_blacklist")
216 raise Exception("Unexpected bssid_blacklist value: %s != %s" % (res, val))
217 dev[0].set_network(id, "bssid_whitelist", val)
218 res = dev[0].get_network(id, "bssid_whitelist")
220 raise Exception("Unexpected bssid_whitelist value: %s != %s" % (res, val))
224 "00:11:22:33:44:55q",
225 "00:11:22:33:44:55/",
226 "00:11:22:33:44:55/66:77:88:99:aa:b" ]
228 if "FAIL" not in dev[0].request("SET_NETWORK %d bssid_blacklist %s" % (id, val)):
229 raise Exception("Invalid bssid_blacklist value accepted")
231 def test_wpas_ctrl_many_networks(dev, apdev):
232 """wpa_supplicant ctrl_iface LIST_NETWORKS with huge number of networks"""
233 for i in range(1000):
234 id = dev[0].add_network()
235 res = dev[0].request("LIST_NETWORKS")
237 raise Exception("Last added network was unexpectedly included")
238 res = dev[0].request("LIST_NETWORKS LAST_ID=%d" % (id - 2))
239 if str(id) not in res:
240 raise Exception("Last added network was not present when using LAST_ID")
241 # This command can take a very long time under valgrind testing on a low
242 # power CPU, so increase the command timeout significantly to avoid issues
243 # with the test case failing and following reset operation timing out.
244 dev[0].request("REMOVE_NETWORK all", timeout=60)
246 def test_wpas_ctrl_dup_network(dev, apdev):
247 """wpa_supplicant ctrl_iface DUP_NETWORK"""
249 passphrase = 'qwertyuiop'
250 params = hostapd.wpa2_params(ssid=ssid, passphrase=passphrase)
251 hostapd.add_ap(apdev[0]['ifname'], params)
253 src = dev[0].connect("another", psk=passphrase, scan_freq="2412",
254 only_add_network=True)
255 id = dev[0].add_network()
256 dev[0].set_network_quoted(id, "ssid", ssid)
257 for f in [ "key_mgmt", "psk", "scan_freq" ]:
258 res = dev[0].request("DUP_NETWORK {} {} {}".format(src, id, f))
260 raise Exception("DUP_NETWORK failed")
261 dev[0].connect_network(id)
263 if "FAIL" not in dev[0].request("DUP_NETWORK "):
264 raise Exception("Unexpected DUP_NETWORK success")
265 if "FAIL" not in dev[0].request("DUP_NETWORK %d " % id):
266 raise Exception("Unexpected DUP_NETWORK success")
267 if "FAIL" not in dev[0].request("DUP_NETWORK %d %d" % (id, id)):
268 raise Exception("Unexpected DUP_NETWORK success")
269 if "FAIL" not in dev[0].request("DUP_NETWORK 123456 1234567 "):
270 raise Exception("Unexpected DUP_NETWORK success")
271 if "FAIL" not in dev[0].request("DUP_NETWORK %d 123456 " % id):
272 raise Exception("Unexpected DUP_NETWORK success")
273 if "FAIL" not in dev[0].request("DUP_NETWORK %d %d foo" % (id, id)):
274 raise Exception("Unexpected DUP_NETWORK success")
275 dev[0].request("DISCONNECT")
276 if "OK" not in dev[0].request("DUP_NETWORK %d %d ssid" % (id, id)):
277 raise Exception("Unexpected DUP_NETWORK failure")
281 ev = dev.wait_event(["CRED-ADDED"])
283 raise Exception("Missing CRED-ADDED event")
284 if " " + str(id) not in ev:
285 raise Exception("CRED-ADDED event without matching id")
288 def set_cred(dev, id, field, value):
289 dev.set_cred(id, field, value)
290 ev = dev.wait_event(["CRED-MODIFIED"])
292 raise Exception("Missing CRED-MODIFIED event")
293 if " " + str(id) + " " not in ev:
294 raise Exception("CRED-MODIFIED event without matching id")
296 raise Exception("CRED-MODIFIED event without matching field")
298 def set_cred_quoted(dev, id, field, value):
299 dev.set_cred_quoted(id, field, value)
300 ev = dev.wait_event(["CRED-MODIFIED"])
302 raise Exception("Missing CRED-MODIFIED event")
303 if " " + str(id) + " " not in ev:
304 raise Exception("CRED-MODIFIED event without matching id")
306 raise Exception("CRED-MODIFIED event without matching field")
308 def remove_cred(dev, id):
310 ev = dev.wait_event(["CRED-REMOVED"])
312 raise Exception("Missing CRED-REMOVED event")
313 if " " + str(id) not in ev:
314 raise Exception("CRED-REMOVED event without matching id")
316 def test_wpas_ctrl_cred(dev):
317 """wpa_supplicant ctrl_iface cred set"""
318 id1 = add_cred(dev[0])
319 if "FAIL" not in dev[0].request("SET_CRED " + str(id1 + 1) + " temporary 1"):
320 raise Exception("SET_CRED succeeded unexpectedly on unknown cred id")
321 if "FAIL" not in dev[0].request("SET_CRED " + str(id1)):
322 raise Exception("Invalid SET_CRED succeeded unexpectedly")
323 if "FAIL" not in dev[0].request("SET_CRED " + str(id1) + " temporary"):
324 raise Exception("Invalid SET_CRED succeeded unexpectedly")
325 if "FAIL" not in dev[0].request("GET_CRED " + str(id1 + 1) + " temporary"):
326 raise Exception("GET_CRED succeeded unexpectedly on unknown cred id")
327 if "FAIL" not in dev[0].request("GET_CRED " + str(id1)):
328 raise Exception("Invalid GET_CRED succeeded unexpectedly")
329 if "FAIL" not in dev[0].request("GET_CRED " + str(id1) + " foo"):
330 raise Exception("Invalid GET_CRED succeeded unexpectedly")
331 id = add_cred(dev[0])
332 id2 = add_cred(dev[0])
333 set_cred(dev[0], id, "temporary", "1")
334 set_cred(dev[0], id, "priority", "1")
335 set_cred(dev[0], id, "pcsc", "1")
336 set_cred_quoted(dev[0], id, "private_key_passwd", "test")
337 set_cred_quoted(dev[0], id, "domain_suffix_match", "test")
338 set_cred_quoted(dev[0], id, "phase1", "test")
339 set_cred_quoted(dev[0], id, "phase2", "test")
341 if "FAIL" not in dev[0].request("SET_CRED " + str(id) + " eap FOO"):
342 raise Exception("Unexpected success on unknown EAP method")
344 if "FAIL" not in dev[0].request("SET_CRED " + str(id) + " username 12xa"):
345 raise Exception("Unexpected success on invalid string")
347 for i in ("11", "1122", "112233445566778899aabbccddeeff00"):
348 if "FAIL" not in dev[0].request("SET_CRED " + str(id) + " roaming_consortium " + i):
349 raise Exception("Unexpected success on invalid roaming_consortium")
351 dev[0].set_cred(id, "excluded_ssid", "00112233445566778899aabbccddeeff00112233445566778899aabbccddeeff")
352 if "FAIL" not in dev[0].request("SET_CRED " + str(id) + " excluded_ssid 00112233445566778899aabbccddeeff00112233445566778899aabbccddeeff00"):
353 raise Exception("Unexpected success on invalid excluded_ssid")
355 if "FAIL" not in dev[0].request("SET_CRED " + str(id) + " foo 4142"):
356 raise Exception("Unexpected success on unknown field")
358 id3 = add_cred(dev[0])
359 id4 = add_cred(dev[0])
360 if len(dev[0].request("LIST_CREDS").splitlines()) != 6:
361 raise Exception("Unexpected LIST_CREDS result(1)")
363 remove_cred(dev[0], id1)
364 remove_cred(dev[0], id3)
365 remove_cred(dev[0], id4)
366 remove_cred(dev[0], id2)
367 remove_cred(dev[0], id)
368 if "FAIL" not in dev[0].request("REMOVE_CRED 1"):
369 raise Exception("Unexpected success on invalid remove cred")
370 if len(dev[0].request("LIST_CREDS").splitlines()) != 1:
371 raise Exception("Unexpected LIST_CREDS result(2)")
373 id = add_cred(dev[0])
374 values = [ ("temporary", "1", False),
375 ("temporary", "0", False),
376 ("pcsc", "1", False),
377 ("realm", "example.com", True),
378 ("username", "user@example.com", True),
379 ("password", "foo", True, "*"),
380 ("ca_cert", "ca.pem", True),
381 ("client_cert", "user.pem", True),
382 ("private_key", "key.pem", True),
383 ("private_key_passwd", "foo", True, "*"),
384 ("imsi", "310026-000000000", True),
385 ("milenage", "foo", True, "*"),
386 ("domain_suffix_match", "example.com", True),
387 ("domain", "example.com", True),
388 ("domain", "example.org", True, "example.com\nexample.org"),
389 ("roaming_consortium", "0123456789", False),
390 ("required_roaming_consortium", "456789", False),
391 ("eap", "TTLS", False),
392 ("phase1", "foo=bar1", True),
393 ("phase2", "foo=bar2", True),
394 ("excluded_ssid", "test", True),
395 ("excluded_ssid", "foo", True, "test\nfoo"),
396 ("roaming_partner", "example.com,0,4,*", True),
397 ("roaming_partner", "example.org,1,2,US", True,
398 "example.com,0,4,*\nexample.org,1,2,US"),
399 ("update_identifier", "4", False),
400 ("provisioning_sp", "sp.example.com", True),
401 ("sp_priority", "7", False),
402 ("min_dl_bandwidth_home", "100", False),
403 ("min_ul_bandwidth_home", "101", False),
404 ("min_dl_bandwidth_roaming", "102", False),
405 ("min_ul_bandwidth_roaming", "103", False),
406 ("max_bss_load", "57", False),
407 ("req_conn_capab", "6:22,80,443", False),
408 ("req_conn_capab", "17:500", False, "6:22,80,443\n17:500"),
409 ("req_conn_capab", "50", False, "6:22,80,443\n17:500\n50"),
410 ("ocsp", "1", False) ]
413 set_cred_quoted(dev[0], id, v[0], v[1])
415 set_cred(dev[0], id, v[0], v[1])
416 val = dev[0].get_cred(id, v[0])
422 raise Exception("Unexpected GET_CRED value for {}: {} != {}".format(v[0], val, expect))
423 creds = dev[0].request("LIST_CREDS").splitlines()
425 raise Exception("Unexpected LIST_CREDS result(3)")
426 if creds[1] != "0\texample.com\tuser@example.com\texample.com\t310026-000000000":
427 raise Exception("Unexpected LIST_CREDS value")
428 remove_cred(dev[0], id)
429 if len(dev[0].request("LIST_CREDS").splitlines()) != 1:
430 raise Exception("Unexpected LIST_CREDS result(4)")
432 id = add_cred(dev[0])
433 set_cred_quoted(dev[0], id, "domain", "foo.example.com")
434 id = add_cred(dev[0])
435 set_cred_quoted(dev[0], id, "domain", "bar.example.com")
436 id = add_cred(dev[0])
437 set_cred_quoted(dev[0], id, "domain", "foo.example.com")
438 if "OK" not in dev[0].request("REMOVE_CRED sp_fqdn=foo.example.com"):
439 raise Exception("REMOVE_CRED failed")
440 creds = dev[0].request("LIST_CREDS")
441 if "foo.example.com" in creds:
442 raise Exception("REMOVE_CRED sp_fqdn did not remove cred")
443 if "bar.example.com" not in creds:
444 raise Exception("REMOVE_CRED sp_fqdn removed incorrect cred")
445 dev[0].request("REMOVE_CRED all")
447 id = add_cred(dev[0])
448 set_cred_quoted(dev[0], id, "domain", "foo.example.com")
449 set_cred_quoted(dev[0], id, "provisioning_sp", "sp.foo.example.com")
450 id = add_cred(dev[0])
451 set_cred_quoted(dev[0], id, "domain", "bar.example.com")
452 set_cred_quoted(dev[0], id, "provisioning_sp", "sp.bar.example.com")
453 id = add_cred(dev[0])
454 set_cred_quoted(dev[0], id, "domain", "foo.example.com")
455 set_cred_quoted(dev[0], id, "provisioning_sp", "sp.foo.example.com")
456 if "OK" not in dev[0].request("REMOVE_CRED provisioning_sp=sp.foo.example.com"):
457 raise Exception("REMOVE_CRED failed")
458 creds = dev[0].request("LIST_CREDS")
459 if "foo.example.com" in creds:
460 raise Exception("REMOVE_CRED provisioning_sp did not remove cred")
461 if "bar.example.com" not in creds:
462 raise Exception("REMOVE_CRED provisioning_sp removed incorrect cred")
463 dev[0].request("REMOVE_CRED all")
465 # Test large number of creds and LIST_CREDS truncation
466 dev[0].dump_monitor()
467 for i in range(0, 100):
468 id = add_cred(dev[0])
469 set_cred_quoted(dev[0], id, "realm", "relatively.long.realm.test%d.example.com" % i)
470 dev[0].dump_monitor()
471 creds = dev[0].request("LIST_CREDS")
472 for i in range(0, 100):
473 dev[0].remove_cred(i)
474 dev[0].dump_monitor()
475 if len(creds) < 3900 or len(creds) > 4100:
476 raise Exception("Unexpected LIST_CREDS length: %d" % len(creds))
477 if "test10.example.com" not in creds:
478 raise Exception("Missing credential")
479 if len(creds.splitlines()) > 95:
480 raise Exception("Too many LIST_CREDS entries in the buffer")
482 def test_wpas_ctrl_pno(dev):
483 """wpa_supplicant ctrl_iface pno"""
484 if "FAIL" not in dev[0].request("SET pno 1"):
485 raise Exception("Unexpected success in enabling PNO without enabled network blocks")
486 id = dev[0].add_network()
487 dev[0].set_network_quoted(id, "ssid", "test")
488 dev[0].set_network(id, "key_mgmt", "NONE")
489 dev[0].request("ENABLE_NETWORK " + str(id) + " no-connect")
490 #mac80211_hwsim does not yet support PNO, so this fails
491 if "FAIL" not in dev[0].request("SET pno 1"):
492 raise Exception("Unexpected success in enabling PNO")
493 if "FAIL" not in dev[0].request("SET pno 1 freq=2000-3000,5180"):
494 raise Exception("Unexpected success in enabling PNO")
495 if "FAIL" not in dev[0].request("SET pno 1 freq=0-6000"):
496 raise Exception("Unexpected success in enabling PNO")
497 if "FAIL" in dev[0].request("SET pno 0"):
498 raise Exception("Unexpected failure in disabling PNO")
500 def test_wpas_ctrl_get(dev):
501 """wpa_supplicant ctrl_iface get"""
502 if "FAIL" in dev[0].request("GET version"):
503 raise Exception("Unexpected get failure for version")
504 if "FAIL" in dev[0].request("GET wifi_display"):
505 raise Exception("Unexpected get failure for wifi_display")
506 if "FAIL" not in dev[0].request("GET foo"):
507 raise Exception("Unexpected success on get command")
509 def test_wpas_ctrl_preauth(dev):
510 """wpa_supplicant ctrl_iface preauth"""
511 if "FAIL" not in dev[0].request("PREAUTH "):
512 raise Exception("Unexpected success on invalid PREAUTH")
513 if "FAIL" in dev[0].request("PREAUTH 00:11:22:33:44:55"):
514 raise Exception("Unexpected failure on PREAUTH")
516 def test_wpas_ctrl_stkstart(dev):
517 """wpa_supplicant ctrl_iface strkstart"""
518 if "FAIL" not in dev[0].request("STKSTART "):
519 raise Exception("Unexpected success on invalid STKSTART")
520 if "FAIL" not in dev[0].request("STKSTART 00:11:22:33:44:55"):
521 raise Exception("Unexpected success on STKSTART")
523 def test_wpas_ctrl_tdls_discover(dev):
524 """wpa_supplicant ctrl_iface tdls_discover"""
525 if "FAIL" not in dev[0].request("TDLS_DISCOVER "):
526 raise Exception("Unexpected success on invalid TDLS_DISCOVER")
527 if "FAIL" not in dev[0].request("TDLS_DISCOVER 00:11:22:33:44:55"):
528 raise Exception("Unexpected success on TDLS_DISCOVER")
530 def test_wpas_ctrl_tdls_chan_switch(dev):
531 """wpa_supplicant ctrl_iface tdls_chan_switch error cases"""
532 for args in [ '', '00:11:22:33:44:55' ]:
533 if "FAIL" not in dev[0].request("TDLS_CANCEL_CHAN_SWITCH " + args):
534 raise Exception("Unexpected success on invalid TDLS_CANCEL_CHAN_SWITCH: " + args)
536 for args in [ '', 'foo ', '00:11:22:33:44:55 ', '00:11:22:33:44:55 q',
537 '00:11:22:33:44:55 81', '00:11:22:33:44:55 81 1234',
538 '00:11:22:33:44:55 81 1234 center_freq1=234 center_freq2=345 bandwidth=456 sec_channel_offset=567 ht vht' ]:
539 if "FAIL" not in dev[0].request("TDLS_CHAN_SWITCH " + args):
540 raise Exception("Unexpected success on invalid TDLS_CHAN_SWITCH: " + args)
542 def test_wpas_ctrl_addr(dev):
543 """wpa_supplicant ctrl_iface invalid address"""
544 if "FAIL" not in dev[0].request("TDLS_SETUP "):
545 raise Exception("Unexpected success on invalid TDLS_SETUP")
546 if "FAIL" not in dev[0].request("TDLS_TEARDOWN "):
547 raise Exception("Unexpected success on invalid TDLS_TEARDOWN")
548 if "FAIL" not in dev[0].request("FT_DS "):
549 raise Exception("Unexpected success on invalid FT_DS")
550 if "FAIL" not in dev[0].request("WPS_PBC 00:11:22:33:44"):
551 raise Exception("Unexpected success on invalid WPS_PBC")
552 if "FAIL" not in dev[0].request("WPS_PIN 00:11:22:33:44"):
553 raise Exception("Unexpected success on invalid WPS_PIN")
554 if "FAIL" not in dev[0].request("WPS_NFC 00:11:22:33:44"):
555 raise Exception("Unexpected success on invalid WPS_NFC")
556 if "FAIL" not in dev[0].request("WPS_REG 00:11:22:33:44 12345670"):
557 raise Exception("Unexpected success on invalid WPS_REG")
558 if "FAIL" not in dev[0].request("IBSS_RSN 00:11:22:33:44"):
559 raise Exception("Unexpected success on invalid IBSS_RSN")
560 if "FAIL" not in dev[0].request("BLACKLIST 00:11:22:33:44"):
561 raise Exception("Unexpected success on invalid BLACKLIST")
563 def test_wpas_ctrl_wps_errors(dev):
564 """wpa_supplicant ctrl_iface WPS error cases"""
565 if "FAIL" not in dev[0].request("WPS_REG 00:11:22:33:44:55"):
566 raise Exception("Unexpected success on invalid WPS_REG")
567 if "FAIL" not in dev[0].request("WPS_REG 00:11:22:33:44:55 12345670 2233"):
568 raise Exception("Unexpected success on invalid WPS_REG")
569 if "FAIL" not in dev[0].request("WPS_REG 00:11:22:33:44:55 12345670 2233 OPEN"):
570 raise Exception("Unexpected success on invalid WPS_REG")
571 if "FAIL" not in dev[0].request("WPS_REG 00:11:22:33:44:55 12345670 2233 OPEN NONE"):
572 raise Exception("Unexpected success on invalid WPS_REG")
574 if "FAIL" not in dev[0].request("WPS_AP_PIN random"):
575 raise Exception("Unexpected success on WPS_AP_PIN in non-AP mode")
577 if "FAIL" not in dev[0].request("WPS_ER_PIN any"):
578 raise Exception("Unexpected success on invalid WPS_ER_PIN")
580 if "FAIL" not in dev[0].request("WPS_ER_LEARN 00:11:22:33:44:55"):
581 raise Exception("Unexpected success on invalid WPS_ER_LEARN")
583 if "FAIL" not in dev[0].request("WPS_ER_SET_CONFIG 00:11:22:33:44:55"):
584 raise Exception("Unexpected success on invalid WPS_ER_SET_CONFIG")
586 if "FAIL" not in dev[0].request("WPS_ER_CONFIG 00:11:22:33:44:55"):
587 raise Exception("Unexpected success on invalid WPS_ER_CONFIG")
588 if "FAIL" not in dev[0].request("WPS_ER_CONFIG 00:11:22:33:44:55 12345670"):
589 raise Exception("Unexpected success on invalid WPS_ER_CONFIG")
590 if "FAIL" not in dev[0].request("WPS_ER_CONFIG 00:11:22:33:44:55 12345670 2233"):
591 raise Exception("Unexpected success on invalid WPS_ER_CONFIG")
592 if "FAIL" not in dev[0].request("WPS_ER_CONFIG 00:11:22:33:44:55 12345670 2233 OPEN"):
593 raise Exception("Unexpected success on invalid WPS_ER_CONFIG")
594 if "FAIL" not in dev[0].request("WPS_ER_CONFIG 00:11:22:33:44:55 12345670 2233 OPEN NONE"):
595 raise Exception("Unexpected success on invalid WPS_ER_CONFIG")
597 if "FAIL" not in dev[0].request("WPS_ER_NFC_CONFIG_TOKEN WPS"):
598 raise Exception("Unexpected success on invalid WPS_ER_NFC_CONFIG_TOKEN")
599 if "FAIL" not in dev[0].request("WPS_ER_NFC_CONFIG_TOKEN FOO 00:11:22:33:44:55"):
600 raise Exception("Unexpected success on invalid WPS_ER_NFC_CONFIG_TOKEN")
601 if "FAIL" not in dev[0].request("WPS_ER_NFC_CONFIG_TOKEN NDEF 00:11:22:33:44:55"):
602 raise Exception("Unexpected success on invalid WPS_ER_NFC_CONFIG_TOKEN")
604 if "FAIL" not in dev[0].request("WPS_NFC_CONFIG_TOKEN FOO"):
605 raise Exception("Unexpected success on invalid WPS_NFC_CONFIG_TOKEN")
606 if "FAIL" not in dev[0].request("WPS_NFC_CONFIG_TOKEN WPS FOO"):
607 raise Exception("Unexpected success on invalid WPS_NFC_CONFIG_TOKEN")
608 if "FAIL" not in dev[0].request("WPS_NFC_TOKEN FOO"):
609 raise Exception("Unexpected success on invalid WPS_NFC_TOKEN")
611 def test_wpas_ctrl_config_parser(dev):
612 """wpa_supplicant ctrl_iface SET config parser"""
613 if "FAIL" not in dev[0].request("SET pbc_in_m1 qwerty"):
614 raise Exception("Non-number accepted as integer")
615 if "FAIL" not in dev[0].request("SET eapol_version 0"):
616 raise Exception("Out-of-range value accepted")
617 if "FAIL" not in dev[0].request("SET eapol_version 10"):
618 raise Exception("Out-of-range value accepted")
620 if "FAIL" not in dev[0].request("SET serial_number 0123456789abcdef0123456789abcdef0"):
621 raise Exception("Too long string accepted")
623 def test_wpas_ctrl_mib(dev):
624 """wpa_supplicant ctrl_iface MIB"""
625 mib = dev[0].get_mib()
626 if "dot11RSNAOptionImplemented" not in mib:
627 raise Exception("Missing MIB entry")
628 if mib["dot11RSNAOptionImplemented"] != "TRUE":
629 raise Exception("Unexpected dot11RSNAOptionImplemented value")
631 def test_wpas_ctrl_set_wps_params(dev):
632 """wpa_supplicant ctrl_iface SET config_methods"""
633 ts = [ "config_methods label virtual_display virtual_push_button keypad",
634 "device_type 1-0050F204-1",
635 "os_version 01020300",
636 "uuid 12345678-9abc-def0-1234-56789abcdef0" ]
638 if "OK" not in dev[2].request("SET " + t):
639 raise Exception("SET failed for: " + t)
641 def test_wpas_ctrl_level(dev):
642 """wpa_supplicant ctrl_iface LEVEL"""
644 if "FAIL" not in dev[2].request("LEVEL 3"):
645 raise Exception("Unexpected LEVEL success")
646 if "OK" not in dev[2].mon.request("LEVEL 2"):
647 raise Exception("Unexpected LEVEL failure")
648 dev[2].request("SCAN freq=2412")
649 ev = dev[2].wait_event(["State:"], timeout=5)
651 raise Exception("No debug message received")
652 dev[2].wait_event(["CTRL-EVENT-SCAN-RESULTS"], timeout=5)
654 dev[2].mon.request("LEVEL 3")
656 def test_wpas_ctrl_bssid_filter(dev, apdev):
657 """wpa_supplicant bssid_filter"""
659 if "OK" not in dev[2].request("SET bssid_filter " + apdev[0]['bssid']):
660 raise Exception("Failed to set bssid_filter")
661 params = { "ssid": "test" }
662 hostapd.add_ap(apdev[0]['ifname'], params)
663 hostapd.add_ap(apdev[1]['ifname'], params)
664 dev[2].scan_for_bss(apdev[0]['bssid'], freq="2412")
665 dev[2].scan(freq="2412")
666 bss = dev[2].get_bss(apdev[0]['bssid'])
667 if bss is None or len(bss) == 0:
668 raise Exception("Missing BSS data")
669 bss = dev[2].get_bss(apdev[1]['bssid'])
670 if bss and len(bss) != 0:
671 raise Exception("Unexpected BSS data")
672 dev[2].request("SET bssid_filter ")
673 dev[2].scan(freq="2412")
674 bss = dev[2].get_bss(apdev[0]['bssid'])
675 if bss is None or len(bss) == 0:
676 raise Exception("Missing BSS data")
677 bss = dev[2].get_bss(apdev[1]['bssid'])
678 if bss is None or len(bss) == 0:
679 raise Exception("Missing BSS data(2)")
680 res = dev[2].request("SCAN_RESULTS").splitlines()
681 if "test" not in res[1] or "test" not in res[2]:
682 raise Exception("SSID missing from SCAN_RESULTS")
683 if apdev[0]['bssid'] not in res[1] and apdev[1]['bssid'] not in res[1]:
684 raise Exception("BSS1 missing from SCAN_RESULTS")
685 if apdev[0]['bssid'] not in res[2] and apdev[1]['bssid'] not in res[2]:
686 raise Exception("BSS1 missing from SCAN_RESULTS")
688 if "FAIL" not in dev[2].request("SET bssid_filter 00:11:22:33:44:55 00:11:22:33:44"):
689 raise Exception("Unexpected success for invalid SET bssid_filter")
691 dev[2].request("SET bssid_filter ")
693 def test_wpas_ctrl_disallow_aps(dev, apdev):
694 """wpa_supplicant ctrl_iface disallow_aps"""
695 params = { "ssid": "test" }
696 hostapd.add_ap(apdev[0]['ifname'], params)
698 if "FAIL" not in dev[0].request("SET disallow_aps bssid "):
699 raise Exception("Unexpected success on invalid disallow_aps")
700 if "FAIL" not in dev[0].request("SET disallow_aps bssid 00:11:22:33:44"):
701 raise Exception("Unexpected success on invalid disallow_aps")
702 if "FAIL" not in dev[0].request("SET disallow_aps ssid 0"):
703 raise Exception("Unexpected success on invalid disallow_aps")
704 if "FAIL" not in dev[0].request("SET disallow_aps ssid 4q"):
705 raise Exception("Unexpected success on invalid disallow_aps")
706 if "FAIL" not in dev[0].request("SET disallow_aps bssid 00:11:22:33:44:55 ssid 112233 ssid 123"):
707 raise Exception("Unexpected success on invalid disallow_aps")
708 if "FAIL" not in dev[0].request("SET disallow_aps ssid 000102030405060708090a0b0c0d0e0f000102030405060708090a0b0c0d0e0f00"):
709 raise Exception("Unexpected success on invalid disallow_aps")
710 if "FAIL" not in dev[0].request("SET disallow_aps foo 112233445566"):
711 raise Exception("Unexpected success on invalid disallow_aps")
713 dev[0].connect("test", key_mgmt="NONE", scan_freq="2412")
714 hostapd.add_ap(apdev[1]['ifname'], params)
715 dev[0].scan_for_bss(apdev[1]['bssid'], freq="2412")
716 dev[0].dump_monitor()
717 if "OK" not in dev[0].request("SET disallow_aps bssid 00:11:22:33:44:55 bssid 00:22:33:44:55:66"):
718 raise Exception("Failed to set disallow_aps")
719 if "OK" not in dev[0].request("SET disallow_aps bssid " + apdev[0]['bssid']):
720 raise Exception("Failed to set disallow_aps")
721 ev = dev[0].wait_connected(timeout=30, error="Reassociation timed out")
722 if apdev[1]['bssid'] not in ev:
723 raise Exception("Unexpected BSSID")
725 dev[0].dump_monitor()
726 if "OK" not in dev[0].request("SET disallow_aps ssid " + "test".encode("hex")):
727 raise Exception("Failed to set disallow_aps")
728 dev[0].wait_disconnected(timeout=5, error="Disconnection not seen")
729 ev = dev[0].wait_event(["CTRL-EVENT-CONNECTED"], timeout=1)
731 raise Exception("Unexpected reassociation")
733 dev[0].request("DISCONNECT")
734 dev[0].p2p_start_go(freq=2412)
735 if "OK" not in dev[0].request("SET disallow_aps "):
736 raise Exception("Failed to set disallow_aps")
738 def test_wpas_ctrl_blob(dev):
739 """wpa_supplicant ctrl_iface SET blob"""
740 if "FAIL" not in dev[0].request("SET blob foo"):
741 raise Exception("Unexpected SET success")
742 if "FAIL" not in dev[0].request("SET blob foo 0"):
743 raise Exception("Unexpected SET success")
744 if "FAIL" not in dev[0].request("SET blob foo 0q"):
745 raise Exception("Unexpected SET success")
746 if "OK" not in dev[0].request("SET blob foo 00"):
747 raise Exception("Unexpected SET failure")
748 if "OK" not in dev[0].request("SET blob foo 0011"):
749 raise Exception("Unexpected SET failure")
751 def test_wpas_ctrl_set_uapsd(dev):
752 """wpa_supplicant ctrl_iface SET uapsd"""
753 if "FAIL" not in dev[0].request("SET uapsd foo"):
754 raise Exception("Unexpected SET success")
755 if "FAIL" not in dev[0].request("SET uapsd 0,0,0"):
756 raise Exception("Unexpected SET success")
757 if "FAIL" not in dev[0].request("SET uapsd 0,0"):
758 raise Exception("Unexpected SET success")
759 if "FAIL" not in dev[0].request("SET uapsd 0"):
760 raise Exception("Unexpected SET success")
761 if "OK" not in dev[0].request("SET uapsd 1,1,1,1;1"):
762 raise Exception("Unexpected SET failure")
763 if "OK" not in dev[0].request("SET uapsd 0,0,0,0;0"):
764 raise Exception("Unexpected SET failure")
765 if "OK" not in dev[0].request("SET uapsd disable"):
766 raise Exception("Unexpected SET failure")
768 def test_wpas_ctrl_set(dev):
769 """wpa_supplicant ctrl_iface SET"""
775 "dot11RSNAConfigPMKLifetime 0",
776 "dot11RSNAConfigPMKReauthThreshold 101",
777 "dot11RSNAConfigSATimeout 0",
778 "wps_version_number -1",
779 "wps_version_number 256" ]
781 if "FAIL" not in dev[0].request("SET " + val):
782 raise Exception("Unexpected SET success for " + val)
784 vals = [ "EAPOL::heldPeriod 60",
785 "EAPOL::authPeriod 30",
786 "EAPOL::startPeriod 30",
788 "dot11RSNAConfigSATimeout 60",
795 if "OK" not in dev[0].request("SET " + val):
796 raise Exception("Unexpected SET failure for " + val)
798 def test_wpas_ctrl_get_capability(dev):
799 """wpa_supplicant ctrl_iface GET_CAPABILITY"""
800 if "FAIL" not in dev[0].request("GET_CAPABILITY 1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890"):
801 raise Exception("Unexpected success on invalid GET_CAPABILITY")
802 if "FAIL" not in dev[0].request("GET_CAPABILITY eap foo"):
803 raise Exception("Unexpected success on invalid GET_CAPABILITY")
804 if "AP" not in dev[0].request("GET_CAPABILITY modes strict"):
805 raise Exception("Unexpected GET_CAPABILITY response")
806 res = dev[0].get_capability("eap")
807 if "TTLS" not in res:
808 raise Exception("Unexpected GET_CAPABILITY eap response: " + str(res))
810 res = dev[0].get_capability("pairwise")
811 if "CCMP" not in res:
812 raise Exception("Unexpected GET_CAPABILITY pairwise response: " + str(res))
814 res = dev[0].get_capability("group")
815 if "CCMP" not in res:
816 raise Exception("Unexpected GET_CAPABILITY group response: " + str(res))
818 res = dev[0].get_capability("key_mgmt")
819 if "WPA-PSK" not in res or "WPA-EAP" not in res:
820 raise Exception("Unexpected GET_CAPABILITY key_mgmt response: " + str(res))
822 res = dev[0].get_capability("proto")
823 if "WPA" not in res or "RSN" not in res:
824 raise Exception("Unexpected GET_CAPABILITY proto response: " + str(res))
826 res = dev[0].get_capability("auth_alg")
827 if "OPEN" not in res or "SHARED" not in res:
828 raise Exception("Unexpected GET_CAPABILITY auth_alg response: " + str(res))
830 res = dev[0].get_capability("modes")
831 if "IBSS" not in res or "AP" not in res:
832 raise Exception("Unexpected GET_CAPABILITY modes response: " + str(res))
834 res = dev[0].get_capability("channels")
835 if "8" not in res or "36" not in res:
836 raise Exception("Unexpected GET_CAPABILITY channels response: " + str(res))
838 res = dev[0].get_capability("freq")
839 if "2457" not in res or "5180" not in res:
840 raise Exception("Unexpected GET_CAPABILITY freq response: " + str(res))
842 res = dev[0].get_capability("tdls")
843 if "EXTERNAL" not in res[0]:
844 raise Exception("Unexpected GET_CAPABILITY tdls response: " + str(res))
846 res = dev[0].get_capability("erp")
847 if res is None or "ERP" not in res[0]:
848 raise Exception("Unexpected GET_CAPABILITY erp response: " + str(res))
850 if dev[0].get_capability("foo") is not None:
851 raise Exception("Unexpected GET_CAPABILITY foo response: " + str(res))
853 def test_wpas_ctrl_nfc_report_handover(dev):
854 """wpa_supplicant ctrl_iface NFC_REPORT_HANDOVER"""
865 if "FAIL" not in dev[0].request("NFC_REPORT_HANDOVER " + v):
866 raise Exception("Unexpected NFC_REPORT_HANDOVER success for " + v)
868 def test_wpas_ctrl_nfc_tag_read(dev):
869 """wpa_supplicant ctrl_iface WPS_NFC_TAG_READ"""
870 vals = [ "FOO", "0Q", "00", "000000", "10000001", "10000000", "00000000",
871 "100e0000", "100e0001ff", "100e000411110000", "100e0004100e0001" ]
873 if "FAIL" not in dev[0].request("WPS_NFC_TAG_READ " + v):
874 raise Exception("Unexpected WPS_NFC_TAG_READ success for " + v)
876 def test_wpas_ctrl_nfc_get_handover(dev):
877 """wpa_supplicant ctrl_iface NFC_GET_HANDOVER"""
878 vals = [ "FOO", "FOO BAR", "WPS WPS", "WPS WPS-CR", "WPS FOO", "NDEF P2P" ]
880 if "FAIL" not in dev[0].request("NFC_GET_HANDOVER_REQ " + v):
881 raise Exception("Unexpected NFC_GET_HANDOVER_REQ success for " + v)
883 vals = [ "NDEF WPS", "NDEF P2P-CR", "WPS P2P-CR" ]
885 if "FAIL" in dev[0].request("NFC_GET_HANDOVER_REQ " + v):
886 raise Exception("Unexpected NFC_GET_HANDOVER_REQ failure for " + v)
888 vals = [ "FOO", "FOO BAR", "WPS WPS", "WPS WPS-CR", "WPS FOO", "NDEF P2P",
889 "NDEF WPS", "NDEF WPS uuid" ]
891 if "FAIL" not in dev[0].request("NFC_GET_HANDOVER_SEL " + v):
892 raise Exception("Unexpected NFC_GET_HANDOVER_SEL success for " + v)
894 vals = [ "NDEF P2P-CR", "WPS P2P-CR", "NDEF P2P-CR-TAG",
897 if "FAIL" in dev[0].request("NFC_GET_HANDOVER_SEL " + v):
898 raise Exception("Unexpected NFC_GET_HANDOVER_SEL failure for " + v)
900 def get_blacklist(dev):
901 return dev.request("BLACKLIST").splitlines()
903 def test_wpas_ctrl_blacklist(dev):
904 """wpa_supplicant ctrl_iface BLACKLIST"""
905 if "OK" not in dev[0].request("BLACKLIST clear"):
906 raise Exception("BLACKLIST clear failed")
907 b = get_blacklist(dev[0])
909 raise Exception("Unexpected blacklist contents: " + str(b))
910 if "OK" not in dev[0].request("BLACKLIST 00:11:22:33:44:55"):
911 raise Exception("BLACKLIST add failed")
912 b = get_blacklist(dev[0])
913 if "00:11:22:33:44:55" not in b:
914 raise Exception("Unexpected blacklist contents: " + str(b))
915 if "OK" not in dev[0].request("BLACKLIST 00:11:22:33:44:56"):
916 raise Exception("BLACKLIST add failed")
917 b = get_blacklist(dev[0])
918 if "00:11:22:33:44:55" not in b or "00:11:22:33:44:56" not in b:
919 raise Exception("Unexpected blacklist contents: " + str(b))
920 if "OK" not in dev[0].request("BLACKLIST 00:11:22:33:44:56"):
921 raise Exception("BLACKLIST add failed")
922 b = get_blacklist(dev[0])
923 if "00:11:22:33:44:55" not in b or "00:11:22:33:44:56" not in b or len(b) != 2:
924 raise Exception("Unexpected blacklist contents: " + str(b))
926 if "OK" not in dev[0].request("BLACKLIST clear"):
927 raise Exception("BLACKLIST clear failed")
928 if dev[0].request("BLACKLIST") != "":
929 raise Exception("Unexpected blacklist contents")
931 def test_wpas_ctrl_blacklist_oom(dev):
932 """wpa_supplicant ctrl_iface BLACKLIST and out-of-memory"""
933 with alloc_fail(dev[0], 1, "wpa_blacklist_add"):
934 if "FAIL" not in dev[0].request("BLACKLIST aa:bb:cc:dd:ee:ff"):
935 raise Exception("Unexpected success with allocation failure")
937 def test_wpas_ctrl_log_level(dev):
938 """wpa_supplicant ctrl_iface LOG_LEVEL"""
939 level = dev[2].request("LOG_LEVEL")
940 if "Current level: MSGDUMP" not in level:
941 raise Exception("Unexpected debug level(1): " + level)
942 if "Timestamp: 1" not in level:
943 raise Exception("Unexpected timestamp(1): " + level)
945 if "OK" not in dev[2].request("LOG_LEVEL MSGDUMP 0"):
946 raise Exception("LOG_LEVEL failed")
947 level = dev[2].request("LOG_LEVEL")
948 if "Current level: MSGDUMP" not in level:
949 raise Exception("Unexpected debug level(2): " + level)
950 if "Timestamp: 0" not in level:
951 raise Exception("Unexpected timestamp(2): " + level)
953 if "OK" not in dev[2].request("LOG_LEVEL MSGDUMP 1"):
954 raise Exception("LOG_LEVEL failed")
955 level = dev[2].request("LOG_LEVEL")
956 if "Current level: MSGDUMP" not in level:
957 raise Exception("Unexpected debug level(3): " + level)
958 if "Timestamp: 1" not in level:
959 raise Exception("Unexpected timestamp(3): " + level)
961 if "FAIL" not in dev[2].request("LOG_LEVEL FOO"):
962 raise Exception("Invalid LOG_LEVEL accepted")
964 for lev in [ "EXCESSIVE", "MSGDUMP", "DEBUG", "INFO", "WARNING", "ERROR" ]:
965 if "OK" not in dev[2].request("LOG_LEVEL " + lev):
966 raise Exception("LOG_LEVEL failed for " + lev)
967 level = dev[2].request("LOG_LEVEL")
968 if "Current level: " + lev not in level:
969 raise Exception("Unexpected debug level: " + level)
971 if "OK" not in dev[2].request("LOG_LEVEL MSGDUMP 1"):
972 raise Exception("LOG_LEVEL failed")
973 level = dev[2].request("LOG_LEVEL")
974 if "Current level: MSGDUMP" not in level:
975 raise Exception("Unexpected debug level(3): " + level)
976 if "Timestamp: 1" not in level:
977 raise Exception("Unexpected timestamp(3): " + level)
979 def test_wpas_ctrl_enable_disable_network(dev, apdev):
980 """wpa_supplicant ctrl_iface ENABLE/DISABLE_NETWORK"""
981 params = { "ssid": "test" }
982 hostapd.add_ap(apdev[0]['ifname'], params)
984 id = dev[0].connect("test", key_mgmt="NONE", scan_freq="2412",
985 only_add_network=True)
986 if "OK" not in dev[0].request("DISABLE_NETWORK " + str(id)):
987 raise Exception("Failed to disable network")
988 if "OK" not in dev[0].request("ENABLE_NETWORK " + str(id) + " no-connect"):
989 raise Exception("Failed to enable network")
990 if "OK" not in dev[0].request("DISABLE_NETWORK all"):
991 raise Exception("Failed to disable networks")
992 if "OK" not in dev[0].request("ENABLE_NETWORK " + str(id)):
993 raise Exception("Failed to enable network")
994 dev[0].wait_connected(timeout=10)
995 if "OK" not in dev[0].request("DISABLE_NETWORK " + str(id)):
996 raise Exception("Failed to disable network")
997 dev[0].wait_disconnected(timeout=10)
1000 if "OK" not in dev[0].request("ENABLE_NETWORK all"):
1001 raise Exception("Failed to enable network")
1002 dev[0].wait_connected(timeout=10)
1003 if "OK" not in dev[0].request("DISABLE_NETWORK all"):
1004 raise Exception("Failed to disable network")
1005 dev[0].wait_disconnected(timeout=10)
1007 def test_wpas_ctrl_country(dev, apdev):
1008 """wpa_supplicant SET/GET country code"""
1010 # work around issues with possible pending regdom event from the end of
1011 # the previous test case
1013 dev[0].dump_monitor()
1015 if "OK" not in dev[0].request("SET country FI"):
1016 raise Exception("Failed to set country code")
1017 if dev[0].request("GET country") != "FI":
1018 raise Exception("Country code set failed")
1019 ev = dev[0].wait_event(["CTRL-EVENT-REGDOM-CHANGE"])
1021 raise Exception("regdom change event not seen")
1022 if "init=USER type=COUNTRY alpha2=FI" not in ev:
1023 raise Exception("Unexpected event contents: " + ev)
1024 dev[0].request("SET country 00")
1025 if dev[0].request("GET country") != "00":
1026 raise Exception("Country code set failed")
1027 ev = dev[0].wait_event(["CTRL-EVENT-REGDOM-CHANGE"])
1029 raise Exception("regdom change event not seen")
1030 if "init=CORE type=WORLD" not in ev:
1031 raise Exception("Unexpected event contents: " + ev)
1033 subprocess.call(['iw', 'reg', 'set', '00'])
1035 def test_wpas_ctrl_suspend_resume(dev):
1036 """wpa_supplicant SUSPEND/RESUME"""
1037 wpas = WpaSupplicant(global_iface='/tmp/wpas-wlan5')
1038 wpas.interface_add("wlan5")
1039 if "OK" not in wpas.global_request("SUSPEND"):
1040 raise Exception("SUSPEND failed")
1042 if "OK" not in wpas.global_request("RESUME"):
1043 raise Exception("RESUME failed")
1044 if "OK" not in wpas.request("SUSPEND"):
1045 raise Exception("Per-interface SUSPEND failed")
1046 if "OK" not in wpas.request("RESUME"):
1047 raise Exception("Per-interface RESUME failed")
1048 ev = wpas.wait_event(["CTRL-EVENT-SCAN-RESULTS"], timeout=10)
1050 raise Exception("Scan not completed")
1052 def test_wpas_ctrl_global(dev):
1053 """wpa_supplicant global control interface"""
1054 wpas = WpaSupplicant(global_iface='/tmp/wpas-wlan5')
1055 wpas.interface_add("wlan5")
1057 if "PONG" not in wpas.global_request("PING"):
1058 raise Exception("PING failed")
1059 if "wlan5" not in wpas.global_request("INTERFACES"):
1060 raise Exception("Interface not found")
1061 if "UNKNOWN COMMAND" not in wpas.global_request("FOO"):
1062 raise Exception("Unexpected response to unknown command")
1063 if "PONG" not in wpas.global_request("IFNAME=wlan5 PING"):
1064 raise Exception("Per-interface PING failed")
1065 if "FAIL-NO-IFNAME-MATCH" not in wpas.global_request("IFNAME=notfound PING"):
1066 raise Exception("Unknown interface not reported correctly")
1067 if "FAIL" not in wpas.global_request("SAVE_CONFIG"):
1068 raise Exception("SAVE_CONFIG succeeded unexpectedly")
1069 if "OK" not in wpas.global_request("SET wifi_display 0"):
1070 raise Exception("SET failed")
1071 if "wifi_display=0" not in wpas.global_request("STATUS"):
1072 raise Exception("wifi_display not disabled")
1073 if "OK" not in wpas.global_request("SET wifi_display 1"):
1074 raise Exception("SET failed")
1075 if "wifi_display=1" not in wpas.global_request("STATUS"):
1076 raise Exception("wifi_display not enabled")
1077 if "FAIL" not in wpas.global_request("SET foo 1"):
1078 raise Exception("SET succeeded unexpectedly")
1080 if "p2p_state=IDLE" not in wpas.global_request("STATUS"):
1081 raise Exception("P2P was disabled")
1082 wpas.global_request("P2P_SET disabled 1")
1083 if "p2p_state=DISABLED" not in wpas.global_request("STATUS"):
1084 raise Exception("P2P was not disabled")
1085 wpas.global_request("P2P_SET disabled 0")
1086 if "p2p_state=IDLE" not in wpas.global_request("STATUS"):
1087 raise Exception("P2P was not enabled")
1089 # driver_nl80211.c does not support interface list, so do not fail because
1091 logger.debug(wpas.global_request("INTERFACE_LIST"))
1093 if "FAIL" not in wpas.global_request("INTERFACE_ADD "):
1094 raise Exception("INTERFACE_ADD succeeded unexpectedly")
1095 if "FAIL" not in wpas.global_request("INTERFACE_ADD FOO"):
1096 raise Exception("INTERFACE_ADD succeeded unexpectedly")
1097 if "FAIL" not in wpas.global_request("INTERFACE_ADD FOO conf"):
1098 raise Exception("INTERFACE_ADD succeeded unexpectedly")
1099 if "FAIL" not in wpas.global_request("INTERFACE_ADD FOO conf driver"):
1100 raise Exception("INTERFACE_ADD succeeded unexpectedly")
1101 if "FAIL" not in wpas.global_request("INTERFACE_ADD FOO conf driver ctrliface"):
1102 raise Exception("INTERFACE_ADD succeeded unexpectedly")
1103 if "FAIL" not in wpas.global_request("INTERFACE_ADD FOO conf driver ctrliface driverparam"):
1104 raise Exception("INTERFACE_ADD succeeded unexpectedly")
1105 if "FAIL" not in wpas.global_request("INTERFACE_ADD FOO conf driver ctrliface driverparam bridge"):
1106 raise Exception("INTERFACE_ADD succeeded unexpectedly")
1107 if "FAIL" not in wpas.global_request("INTERFACE_ADD FOO conf driver ctrliface driverparam bridge foo"):
1108 raise Exception("INTERFACE_ADD succeeded unexpectedly")
1109 if "FAIL" not in wpas.global_request("INTERFACE_ADD FOO "):
1110 raise Exception("INTERFACE_ADD succeeded unexpectedly")
1112 def test_wpas_ctrl_roam(dev, apdev):
1113 """wpa_supplicant ctrl_iface ROAM error cases"""
1114 if "FAIL" not in dev[0].request("ROAM 00:11:22:33:44"):
1115 raise Exception("Unexpected success")
1116 if "FAIL" not in dev[0].request("ROAM 00:11:22:33:44:55"):
1117 raise Exception("Unexpected success")
1118 params = { "ssid": "test" }
1119 hostapd.add_ap(apdev[0]['ifname'], params)
1120 id = dev[0].connect("test", key_mgmt="NONE", scan_freq="2412")
1121 if "FAIL" not in dev[0].request("ROAM 00:11:22:33:44:55"):
1122 raise Exception("Unexpected success")
1124 def test_wpas_ctrl_ipaddr(dev, apdev):
1125 """wpa_supplicant IP address in STATUS"""
1127 subprocess.call(['ip', 'addr', 'add', '10.174.65.207/32', 'dev',
1129 ipaddr = dev[0].get_status_field('ip_address')
1130 if ipaddr != '10.174.65.207':
1131 raise Exception("IP address not in STATUS output")
1133 subprocess.call(['ip', 'addr', 'del', '10.174.65.207/32', 'dev',
1136 def test_wpas_ctrl_neighbor_rep_req(dev, apdev):
1137 """wpa_supplicant ctrl_iface NEIGHBOR_REP_REQUEST"""
1138 params = { "ssid": "test" }
1139 hostapd.add_ap(apdev[0]['ifname'], params)
1140 params = { "ssid": "test2", "radio_measurements": "1" }
1141 hostapd.add_ap(apdev[1]['ifname'], params)
1143 dev[0].connect("test", key_mgmt="NONE", scan_freq="2412")
1144 if "FAIL" not in dev[0].request("NEIGHBOR_REP_REQUEST"):
1145 raise Exception("Request succeeded unexpectedly")
1146 if "FAIL" not in dev[0].request("NEIGHBOR_REP_REQUEST ssid=abcdef"):
1147 raise Exception("Request succeeded unexpectedly")
1148 dev[0].request("DISCONNECT")
1150 rrm = int(dev[0].get_driver_status_field("capa.rrm_flags"), 16)
1151 if rrm & 0x5 != 0x5:
1152 logger.info("Driver does not support required RRM capabilities - skip rest of the test case")
1155 dev[0].connect("test2", key_mgmt="NONE", scan_freq="2412")
1157 # These requests are expected to get sent properly, but since hostapd does
1158 # not yet support processing of the request, these are expected to fail.
1160 if "OK" not in dev[0].request("NEIGHBOR_REP_REQUEST"):
1161 raise Exception("Request failed")
1162 ev = dev[0].wait_event([ "RRM-NEIGHBOR-REP-RECEIVED",
1163 "RRM-NEIGHBOR-REP-REQUEST-FAILED" ], timeout=10)
1165 raise Exception("RRM report result not indicated")
1166 logger.info("RRM result: " + ev)
1168 if "OK" not in dev[0].request("NEIGHBOR_REP_REQUEST ssid=abcdef"):
1169 raise Exception("Request failed")
1170 ev = dev[0].wait_event([ "RRM-NEIGHBOR-REP-RECEIVED",
1171 "RRM-NEIGHBOR-REP-REQUEST-FAILED" ], timeout=10)
1173 raise Exception("RRM report result not indicated")
1174 logger.info("RRM result: " + ev)
1176 def test_wpas_ctrl_rsp(dev, apdev):
1177 """wpa_supplicant ctrl_iface CTRL-RSP-"""
1178 if "FAIL" not in dev[0].request("CTRL-RSP-"):
1179 raise Exception("Request succeeded unexpectedly")
1180 if "FAIL" not in dev[0].request("CTRL-RSP-foo-"):
1181 raise Exception("Request succeeded unexpectedly")
1182 if "FAIL" not in dev[0].request("CTRL-RSP-foo-1234567"):
1183 raise Exception("Request succeeded unexpectedly")
1184 if "FAIL" not in dev[0].request("CTRL-RSP-foo-1234567:"):
1185 raise Exception("Request succeeded unexpectedly")
1186 id = dev[0].add_network()
1187 if "FAIL" not in dev[0].request("CTRL-RSP-foo-%d:" % id):
1188 raise Exception("Request succeeded unexpectedly")
1189 for req in [ "IDENTITY", "PASSWORD", "NEW_PASSWORD", "PIN", "OTP",
1190 "PASSPHRASE", "SIM" ]:
1191 if "OK" not in dev[0].request("CTRL-RSP-%s-%d:" % (req, id)):
1192 raise Exception("Request failed unexpectedly")
1193 if "OK" not in dev[0].request("CTRL-RSP-%s-%d:" % (req, id)):
1194 raise Exception("Request failed unexpectedly")
1196 def test_wpas_ctrl_vendor(dev, apdev):
1197 """wpa_supplicant ctrl_iface VENDOR"""
1204 if "FAIL" not in dev[0].request("VENDOR " + cmd):
1205 raise Exception("Invalid VENDOR command accepted: " + cmd)
1207 def test_wpas_ctrl_mgmt_tx(dev, apdev):
1208 """wpa_supplicant ctrl_iface MGMT_TX"""
1210 "00:11:22:33:44:55 foo",
1211 "00:11:22:33:44:55 11:22:33:44:55:66",
1212 "00:11:22:33:44:55 11:22:33:44:55:66 freq=0 no_cck=0 wait_time=0 action=123",
1213 "00:11:22:33:44:55 11:22:33:44:55:66 action=12qq" ]
1215 if "FAIL" not in dev[0].request("MGMT_TX " + cmd):
1216 raise Exception("Invalid MGMT_TX command accepted: " + cmd)
1218 if "OK" not in dev[0].request("MGMT_TX_DONE"):
1219 raise Exception("MGMT_TX_DONE failed")
1221 def test_wpas_ctrl_driver_event(dev, apdev):
1222 """wpa_supplicant ctrl_iface DRIVER_EVENT"""
1223 if "FAIL" not in dev[0].request("DRIVER_EVENT foo"):
1224 raise Exception("Invalid DRIVER_EVENT accepted")
1226 def test_wpas_ctrl_eapol_rx(dev, apdev):
1227 """wpa_supplicant ctrl_iface EAPOL_RX"""
1229 "00:11:22:33:44:55 123",
1230 "00:11:22:33:44:55 12qq" ]
1232 if "FAIL" not in dev[0].request("EAPOL_RX " + cmd):
1233 raise Exception("Invalid EAPOL_RX command accepted: " + cmd)
1235 def test_wpas_ctrl_data_test(dev, apdev):
1236 """wpa_supplicant ctrl_iface DATA_TEST"""
1237 dev[0].request("DATA_TEST_CONFIG 0")
1238 if "FAIL" not in dev[0].request("DATA_TEST_TX 00:11:22:33:44:55 00:11:22:33:44:55 0"):
1239 raise Exception("DATA_TEST_TX accepted when not in test mode")
1242 if "OK" not in dev[0].request("DATA_TEST_CONFIG 1"):
1243 raise Exception("DATA_TEST_CONFIG failed")
1244 if "OK" not in dev[0].request("DATA_TEST_CONFIG 1"):
1245 raise Exception("DATA_TEST_CONFIG failed")
1247 "00:11:22:33:44:55 foo",
1248 "00:11:22:33:44:55 00:11:22:33:44:55 -1",
1249 "00:11:22:33:44:55 00:11:22:33:44:55 256" ]
1251 if "FAIL" not in dev[0].request("DATA_TEST_TX " + cmd):
1252 raise Exception("Invalid DATA_TEST_TX command accepted: " + cmd)
1253 if "OK" not in dev[0].request("DATA_TEST_TX 00:11:22:33:44:55 00:11:22:33:44:55 0"):
1254 raise Exception("DATA_TEST_TX failed")
1256 dev[0].request("DATA_TEST_CONFIG 0")
1260 "00112233445566778899aabbccdde",
1261 "00112233445566778899aabbccdq" ]
1263 if "FAIL" not in dev[0].request("DATA_TEST_FRAME " + cmd):
1264 raise Exception("Invalid DATA_TEST_FRAME command accepted: " + cmd)
1266 if "OK" not in dev[0].request("DATA_TEST_FRAME 00112233445566778899aabbccddee"):
1267 raise Exception("DATA_TEST_FRAME failed")
1269 def test_wpas_ctrl_vendor_elem(dev, apdev):
1270 """wpa_supplicant ctrl_iface VENDOR_ELEM"""
1271 if "OK" not in dev[0].request("VENDOR_ELEM_ADD 1 "):
1272 raise Exception("VENDOR_ELEM_ADD failed")
1279 if "FAIL" not in dev[0].request("VENDOR_ELEM_ADD " + cmd):
1280 raise Exception("Invalid VENDOR_ELEM_ADD command accepted: " + cmd)
1285 if "FAIL" not in dev[0].request("VENDOR_ELEM_GET " + cmd):
1286 raise Exception("Invalid VENDOR_ELEM_GET command accepted: " + cmd)
1288 dev[0].request("VENDOR_ELEM_REMOVE 1 *")
1298 if "FAIL" not in dev[0].request("VENDOR_ELEM_REMOVE " + cmd):
1299 raise Exception("Invalid VENDOR_ELEM_REMOVE command accepted: " + cmd)
1301 dev[0].request("VENDOR_ELEM_ADD 1 000100")
1302 if "OK" not in dev[0].request("VENDOR_ELEM_REMOVE 1 "):
1303 raise Exception("VENDOR_ELEM_REMOVE failed")
1312 if "FAIL" not in dev[0].request("VENDOR_ELEM_REMOVE " + cmd):
1313 raise Exception("Invalid VENDOR_ELEM_REMOVE command accepted: " + cmd)
1314 if "OK" not in dev[0].request("VENDOR_ELEM_REMOVE 1 000100"):
1315 raise Exception("VENDOR_ELEM_REMOVE failed")
1317 def test_wpas_ctrl_misc(dev, apdev):
1318 """wpa_supplicant ctrl_iface and miscellaneous commands"""
1319 if "OK" not in dev[0].request("RELOG"):
1320 raise Exception("RELOG failed")
1321 if dev[0].request("IFNAME") != dev[0].ifname:
1322 raise Exception("IFNAME returned unexpected response")
1323 if "FAIL" not in dev[0].request("REATTACH"):
1324 raise Exception("REATTACH accepted while disabled")
1325 if "OK" not in dev[2].request("RECONFIGURE"):
1326 raise Exception("RECONFIGURE failed")
1327 if "FAIL" in dev[0].request("INTERFACE_LIST"):
1328 raise Exception("INTERFACE_LIST failed")
1329 if "UNKNOWN COMMAND" not in dev[0].request("FOO"):
1330 raise Exception("Unknown command accepted")
1332 if "FAIL" not in dev[0].global_request("INTERFACE_REMOVE foo"):
1333 raise Exception("Invalid INTERFACE_REMOVE accepted")
1334 if "FAIL" not in dev[0].global_request("SET foo"):
1335 raise Exception("Invalid global SET accepted")