]> git.ipfire.org Git - thirdparty/hostap.git/blob - tests/hwsim/test_wpas_ctrl.py
tests: Add RRM tests
[thirdparty/hostap.git] / tests / hwsim / test_wpas_ctrl.py
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
7 import logging
8 logger = logging.getLogger()
9 import os
10 import socket
11 import subprocess
12 import time
13
14 import hostapd
15 import hwsim_utils
16 from hwsim import HWSimRadio
17 from wpasupplicant import WpaSupplicant
18 from utils import alloc_fail, fail_test
19 from test_wpas_ap import wait_ap_ready
20
21 def test_wpas_ctrl_network(dev):
22 """wpa_supplicant ctrl_iface network set/get"""
23 id = dev[0].add_network()
24
25 if "FAIL" not in dev[0].request("SET_NETWORK " + str(id)):
26 raise Exception("Unexpected success for invalid SET_NETWORK")
27 if "FAIL" not in dev[0].request("SET_NETWORK " + str(id) + " name"):
28 raise Exception("Unexpected success for invalid SET_NETWORK")
29 if "FAIL" not in dev[0].request("SET_NETWORK " + str(id + 1) + " proto OPEN"):
30 raise Exception("Unexpected success for invalid network id")
31 if "FAIL" not in dev[0].request("GET_NETWORK " + str(id)):
32 raise Exception("Unexpected success for invalid GET_NETWORK")
33 if "FAIL" not in dev[0].request("GET_NETWORK " + str(id + 1) + " proto"):
34 raise Exception("Unexpected success for invalid network id")
35
36 if "OK" not in dev[0].request("SET_NETWORK " + str(id) + " proto \t WPA2 "):
37 raise Exception("Unexpected failure for SET_NETWORK proto")
38 res = dev[0].request("GET_NETWORK " + str(id) + " proto")
39 if res != "RSN":
40 raise Exception("Unexpected SET_NETWORK/GET_NETWORK conversion for proto: " + res)
41
42 if "OK" not in dev[0].request("SET_NETWORK " + str(id) + " key_mgmt \t WPA-PSK "):
43 raise Exception("Unexpected success for SET_NETWORK key_mgmt")
44 res = dev[0].request("GET_NETWORK " + str(id) + " key_mgmt")
45 if res != "WPA-PSK":
46 raise Exception("Unexpected SET_NETWORK/GET_NETWORK conversion for key_mgmt: " + res)
47
48 if "OK" not in dev[0].request("SET_NETWORK " + str(id) + " auth_alg \t OPEN "):
49 raise Exception("Unexpected failure for SET_NETWORK auth_alg")
50 res = dev[0].request("GET_NETWORK " + str(id) + " auth_alg")
51 if res != "OPEN":
52 raise Exception("Unexpected SET_NETWORK/GET_NETWORK conversion for auth_alg: " + res)
53
54 if "OK" not in dev[0].request("SET_NETWORK " + str(id) + " eap \t TLS "):
55 raise Exception("Unexpected failure for SET_NETWORK eap")
56 res = dev[0].request("GET_NETWORK " + str(id) + " eap")
57 if res != "TLS":
58 raise Exception("Unexpected SET_NETWORK/GET_NETWORK conversion for eap: " + res)
59
60 tests = ("bssid foo", "key_mgmt foo", "key_mgmt ", "group NONE")
61 for t in tests:
62 if "FAIL" not in dev[0].request("SET_NETWORK " + str(id) + " " + t):
63 raise Exception("Unexpected success for invalid SET_NETWORK: " + t)
64
65 tests = [("key_mgmt", "WPA-PSK WPA-EAP IEEE8021X NONE WPA-NONE FT-PSK FT-EAP WPA-PSK-SHA256 WPA-EAP-SHA256"),
66 ("pairwise", "CCMP-256 GCMP-256 CCMP GCMP TKIP"),
67 ("group", "CCMP-256 GCMP-256 CCMP GCMP TKIP"),
68 ("auth_alg", "OPEN SHARED LEAP"),
69 ("scan_freq", "1 2 3 4 5 6 7 8 9 10 11 12 13 14 15"),
70 ("freq_list", "2412 2417"),
71 ("scan_ssid", "1"),
72 ("bssid", "00:11:22:33:44:55"),
73 ("proto", "WPA RSN OSEN"),
74 ("eap", "TLS"),
75 ("go_p2p_dev_addr", "22:33:44:55:66:aa"),
76 ("p2p_client_list", "22:33:44:55:66:bb 02:11:22:33:44:55")]
77 if "SAE" not in dev[0].get_capability("auth_alg"):
78 tests.append(("key_mgmt", "WPS OSEN"))
79 else:
80 tests.append(("key_mgmt", "WPS SAE FT-SAE OSEN"))
81
82 dev[0].set_network_quoted(id, "ssid", "test")
83 for field, value in tests:
84 dev[0].set_network(id, field, value)
85 res = dev[0].get_network(id, field)
86 if res != value:
87 raise Exception("Unexpected response for '" + field + "': '" + res + "'")
88
89 try:
90 value = "WPA-EAP-SUITE-B WPA-EAP-SUITE-B-192"
91 dev[0].set_network(id, "key_mgmt", value)
92 res = dev[0].get_network(id, "key_mgmt")
93 if res != value:
94 raise Exception("Unexpected response for key_mgmt")
95 except Exception, e:
96 if str(e).startswith("Unexpected"):
97 raise
98 else:
99 pass
100
101 q_tests = (("identity", "hello"),
102 ("anonymous_identity", "foo@nowhere.com"))
103 for field, value in q_tests:
104 dev[0].set_network_quoted(id, field, value)
105 res = dev[0].get_network(id, field)
106 if res != '"' + value + '"':
107 raise Exception("Unexpected quoted response for '" + field + "': '" + res + "'")
108
109 get_tests = (("foo", None), ("ssid", '"test"'))
110 for field, value in get_tests:
111 res = dev[0].get_network(id, field)
112 if res != value:
113 raise Exception("Unexpected response for '" + field + "': '" + res + "'")
114
115 if dev[0].get_network(id, "password"):
116 raise Exception("Unexpected response for 'password'")
117 dev[0].set_network_quoted(id, "password", "foo")
118 if dev[0].get_network(id, "password") != '*':
119 raise Exception("Unexpected response for 'password' (expected *)")
120 dev[0].set_network(id, "password", "hash:12345678901234567890123456789012")
121 if dev[0].get_network(id, "password") != '*':
122 raise Exception("Unexpected response for 'password' (expected *)")
123 dev[0].set_network(id, "password", "NULL")
124 if dev[0].get_network(id, "password"):
125 raise Exception("Unexpected response for 'password'")
126 if "FAIL" not in dev[0].request("SET_NETWORK " + str(id) + " password hash:12"):
127 raise Exception("Unexpected success for invalid password hash")
128 if "FAIL" not in dev[0].request("SET_NETWORK " + str(id) + " password hash:123456789012345678x0123456789012"):
129 raise Exception("Unexpected success for invalid password hash")
130
131 dev[0].set_network(id, "identity", "414243")
132 if dev[0].get_network(id, "identity") != '"ABC"':
133 raise Exception("Unexpected identity hex->text response")
134
135 dev[0].set_network(id, "identity", 'P"abc\ndef"')
136 if dev[0].get_network(id, "identity") != "6162630a646566":
137 raise Exception("Unexpected identity printf->hex response")
138
139 if "FAIL" not in dev[0].request("SET_NETWORK " + str(id) + ' identity P"foo'):
140 raise Exception("Unexpected success for invalid identity string")
141
142 if "FAIL" not in dev[0].request("SET_NETWORK " + str(id) + ' identity 12x3'):
143 raise Exception("Unexpected success for invalid identity string")
144
145 for i in range(0, 4):
146 if "FAIL" in dev[0].request("SET_NETWORK " + str(id) + ' wep_key' + str(i) + ' aabbccddee'):
147 raise Exception("Unexpected wep_key set failure")
148 if dev[0].get_network(id, "wep_key" + str(i)) != '*':
149 raise Exception("Unexpected wep_key get failure")
150
151 if "FAIL" in dev[0].request("SET_NETWORK " + str(id) + ' psk_list P2P-00:11:22:33:44:55-0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef'):
152 raise Exception("Unexpected failure for psk_list string")
153
154 if "FAIL" not in dev[0].request("SET_NETWORK " + str(id) + ' psk_list 00:11:x2:33:44:55-0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef'):
155 raise Exception("Unexpected success for invalid psk_list string")
156
157 if "FAIL" not in dev[0].request("SET_NETWORK " + str(id) + ' psk_list P2P-00:11:x2:33:44:55-0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef'):
158 raise Exception("Unexpected success for invalid psk_list string")
159
160 if "FAIL" not in dev[0].request("SET_NETWORK " + str(id) + ' psk_list P2P-00:11:22:33:44:55+0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef'):
161 raise Exception("Unexpected success for invalid psk_list string")
162
163 if "FAIL" not in dev[0].request("SET_NETWORK " + str(id) + ' psk_list P2P-00:11:22:33:44:55-0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcde'):
164 raise Exception("Unexpected success for invalid psk_list string")
165
166 if "FAIL" not in dev[0].request("SET_NETWORK " + str(id) + ' psk_list P2P-00:11:22:33:44:55-0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdex'):
167 raise Exception("Unexpected success for invalid psk_list string")
168
169 if dev[0].get_network(id, "psk_list"):
170 raise Exception("Unexpected psk_list get response")
171
172 if dev[0].list_networks()[0]['ssid'] != "test":
173 raise Exception("Unexpected ssid in LIST_NETWORKS")
174 dev[0].set_network(id, "ssid", "NULL")
175 if dev[0].list_networks()[0]['ssid'] != "":
176 raise Exception("Unexpected ssid in LIST_NETWORKS after clearing it")
177
178 if "FAIL" not in dev[0].request('SET_NETWORK ' + str(id) + ' ssid "0123456789abcdef0123456789abcdef0"'):
179 raise Exception("Too long SSID accepted")
180 if "FAIL" not in dev[0].request('SET_NETWORK ' + str(id) + ' scan_ssid qwerty'):
181 raise Exception("Invalid integer accepted")
182 if "FAIL" not in dev[0].request('SET_NETWORK ' + str(id) + ' scan_ssid 2'):
183 raise Exception("Too large integer accepted")
184 if "FAIL" not in dev[0].request('SET_NETWORK ' + str(id) + ' psk 12345678'):
185 raise Exception("Invalid PSK accepted")
186 if "FAIL" not in dev[0].request('SET_NETWORK ' + str(id) + ' psk "1234567"'):
187 raise Exception("Too short PSK accepted")
188 if "FAIL" not in dev[0].request('SET_NETWORK ' + str(id) + ' psk "1234567890123456789012345678901234567890123456789012345678901234"'):
189 raise Exception("Too long PSK accepted")
190 dev[0].set_network_quoted(id, "psk", "123456768");
191 dev[0].set_network_quoted(id, "psk", "123456789012345678901234567890123456789012345678901234567890123");
192 if dev[0].get_network(id, "psk") != '*':
193 raise Exception("Unexpected psk read result");
194
195 if "FAIL" not in dev[0].request('SET_NETWORK ' + str(id) + ' eap UNKNOWN'):
196 raise Exception("Unknown EAP method accepted")
197
198 if "FAIL" not in dev[0].request('SET_NETWORK ' + str(id) + ' password "foo'):
199 raise Exception("Invalid password accepted")
200
201 if "FAIL" not in dev[0].request('SET_NETWORK ' + str(id) + ' wep_key0 "foo'):
202 raise Exception("Invalid WEP key accepted")
203 if "FAIL" not in dev[0].request('SET_NETWORK ' + str(id) + ' wep_key0 "12345678901234567"'):
204 raise Exception("Too long WEP key accepted")
205 # too short WEP key is ignored
206 dev[0].set_network_quoted(id, "wep_key0", "1234")
207 dev[0].set_network_quoted(id, "wep_key1", "12345")
208 dev[0].set_network_quoted(id, "wep_key2", "1234567890123")
209 dev[0].set_network_quoted(id, "wep_key3", "1234567890123456")
210
211 dev[0].set_network(id, "go_p2p_dev_addr", "any")
212 if dev[0].get_network(id, "go_p2p_dev_addr") is not None:
213 raise Exception("Unexpected go_p2p_dev_addr value")
214 if "FAIL" not in dev[0].request('SET_NETWORK ' + str(id) + ' go_p2p_dev_addr 00:11:22:33:44'):
215 raise Exception("Invalid go_p2p_dev_addr accepted")
216 if "FAIL" not in dev[0].request('SET_NETWORK ' + str(id) + ' p2p_client_list 00:11:22:33:44'):
217 raise Exception("Invalid p2p_client_list accepted")
218 if "FAIL" in dev[0].request('SET_NETWORK ' + str(id) + ' p2p_client_list 00:11:22:33:44:55 00:1'):
219 raise Exception("p2p_client_list truncation workaround failed")
220 if dev[0].get_network(id, "p2p_client_list") != "00:11:22:33:44:55":
221 raise Exception("p2p_client_list truncation workaround did not work")
222
223 if "FAIL" not in dev[0].request('SET_NETWORK ' + str(id) + ' auth_alg '):
224 raise Exception("Empty auth_alg accepted")
225 if "FAIL" not in dev[0].request('SET_NETWORK ' + str(id) + ' auth_alg FOO'):
226 raise Exception("Invalid auth_alg accepted")
227
228 if "FAIL" not in dev[0].request('SET_NETWORK ' + str(id) + ' proto '):
229 raise Exception("Empty proto accepted")
230 if "FAIL" not in dev[0].request('SET_NETWORK ' + str(id) + ' proto FOO'):
231 raise Exception("Invalid proto accepted")
232
233 if "FAIL" not in dev[0].request('SET_NETWORK ' + str(id) + ' pairwise '):
234 raise Exception("Empty pairwise accepted")
235 if "FAIL" not in dev[0].request('SET_NETWORK ' + str(id) + ' pairwise FOO'):
236 raise Exception("Invalid pairwise accepted")
237 if "FAIL" not in dev[0].request('SET_NETWORK ' + str(id) + ' pairwise WEP40'):
238 raise Exception("Invalid pairwise accepted")
239
240 if "OK" not in dev[0].request('BSSID ' + str(id) + ' 00:11:22:33:44:55'):
241 raise Exception("Unexpected BSSID failure")
242 if dev[0].request("GET_NETWORK 0 bssid") != '00:11:22:33:44:55':
243 raise Exception("BSSID command did not set network bssid")
244 if "OK" not in dev[0].request('BSSID ' + str(id) + ' 00:00:00:00:00:00'):
245 raise Exception("Unexpected BSSID failure")
246 if "FAIL" not in dev[0].request("GET_NETWORK 0 bssid"):
247 raise Exception("bssid claimed configured after clearing")
248 if "FAIL" not in dev[0].request('BSSID 123 00:11:22:33:44:55'):
249 raise Exception("Unexpected BSSID success")
250 if "FAIL" not in dev[0].request('BSSID ' + str(id) + ' 00:11:22:33:44'):
251 raise Exception("Unexpected BSSID success")
252 if "FAIL" not in dev[0].request('BSSID ' + str(id)):
253 raise Exception("Unexpected BSSID success")
254
255 tests = [ "02:11:22:33:44:55",
256 "02:11:22:33:44:55 02:ae:be:ce:53:77",
257 "02:11:22:33:44:55/ff:00:ff:00:ff:00",
258 "02:11:22:33:44:55/ff:00:ff:00:ff:00 f2:99:88:77:66:55",
259 "f2:99:88:77:66:55 02:11:22:33:44:55/ff:00:ff:00:ff:00",
260 "f2:99:88:77:66:55 02:11:22:33:44:55/ff:00:ff:00:ff:00 12:34:56:78:90:ab",
261 "02:11:22:33:44:55/ff:ff:ff:00:00:00 02:ae:be:ce:53:77/00:00:00:00:00:ff" ]
262 for val in tests:
263 dev[0].set_network(id, "bssid_blacklist", val)
264 res = dev[0].get_network(id, "bssid_blacklist")
265 if res != val:
266 raise Exception("Unexpected bssid_blacklist value: %s != %s" % (res, val))
267 dev[0].set_network(id, "bssid_whitelist", val)
268 res = dev[0].get_network(id, "bssid_whitelist")
269 if res != val:
270 raise Exception("Unexpected bssid_whitelist value: %s != %s" % (res, val))
271
272 tests = [ "foo",
273 "00:11:22:33:44:5",
274 "00:11:22:33:44:55q",
275 "00:11:22:33:44:55/",
276 "00:11:22:33:44:55/66:77:88:99:aa:b" ]
277 for val in tests:
278 if "FAIL" not in dev[0].request("SET_NETWORK %d bssid_blacklist %s" % (id, val)):
279 raise Exception("Invalid bssid_blacklist value accepted")
280
281 def test_wpas_ctrl_network_oom(dev):
282 """wpa_supplicant ctrl_iface network OOM in string parsing"""
283 id = dev[0].add_network()
284
285 tests = [ ('"foo"', 1, 'dup_binstr;wpa_config_set'),
286 ('P"foo"', 1, 'dup_binstr;wpa_config_set'),
287 ('P"foo"', 2, 'wpa_config_set'),
288 ('112233', 1, 'wpa_config_set') ]
289 for val,count,func in tests:
290 with alloc_fail(dev[0], count, func):
291 if "FAIL" not in dev[0].request("SET_NETWORK " + str(id) + ' ssid ' + val):
292 raise Exception("Unexpected success for SET_NETWORK during OOM")
293
294 def test_wpas_ctrl_many_networks(dev, apdev):
295 """wpa_supplicant ctrl_iface LIST_NETWORKS with huge number of networks"""
296 for i in range(1000):
297 id = dev[0].add_network()
298 res = dev[0].request("LIST_NETWORKS")
299 if str(id) in res:
300 raise Exception("Last added network was unexpectedly included")
301 res = dev[0].request("LIST_NETWORKS LAST_ID=%d" % (id - 2))
302 if str(id) not in res:
303 raise Exception("Last added network was not present when using LAST_ID")
304 # This command can take a very long time under valgrind testing on a low
305 # power CPU, so increase the command timeout significantly to avoid issues
306 # with the test case failing and following reset operation timing out.
307 dev[0].request("REMOVE_NETWORK all", timeout=60)
308
309 def test_wpas_ctrl_dup_network(dev, apdev):
310 """wpa_supplicant ctrl_iface DUP_NETWORK"""
311 ssid = "target"
312 passphrase = 'qwertyuiop'
313 params = hostapd.wpa2_params(ssid=ssid, passphrase=passphrase)
314 hostapd.add_ap(apdev[0], params)
315
316 src = dev[0].connect("another", psk=passphrase, scan_freq="2412",
317 only_add_network=True)
318 id = dev[0].add_network()
319 dev[0].set_network_quoted(id, "ssid", ssid)
320 for f in [ "key_mgmt", "psk", "scan_freq" ]:
321 res = dev[0].request("DUP_NETWORK {} {} {}".format(src, id, f))
322 if "OK" not in res:
323 raise Exception("DUP_NETWORK failed")
324 dev[0].connect_network(id)
325
326 if "FAIL" not in dev[0].request("DUP_NETWORK "):
327 raise Exception("Unexpected DUP_NETWORK success")
328 if "FAIL" not in dev[0].request("DUP_NETWORK %d " % id):
329 raise Exception("Unexpected DUP_NETWORK success")
330 if "FAIL" not in dev[0].request("DUP_NETWORK %d %d" % (id, id)):
331 raise Exception("Unexpected DUP_NETWORK success")
332 if "FAIL" not in dev[0].request("DUP_NETWORK 123456 1234567 "):
333 raise Exception("Unexpected DUP_NETWORK success")
334 if "FAIL" not in dev[0].request("DUP_NETWORK %d 123456 " % id):
335 raise Exception("Unexpected DUP_NETWORK success")
336 if "FAIL" not in dev[0].request("DUP_NETWORK %d %d foo" % (id, id)):
337 raise Exception("Unexpected DUP_NETWORK success")
338 dev[0].request("DISCONNECT")
339 if "OK" not in dev[0].request("DUP_NETWORK %d %d ssid" % (id, id)):
340 raise Exception("Unexpected DUP_NETWORK failure")
341
342 def test_wpas_ctrl_dup_network_global(dev, apdev):
343 """wpa_supplicant ctrl_iface DUP_NETWORK (global)"""
344 ssid = "target"
345 passphrase = 'qwertyuiop'
346 params = hostapd.wpa2_params(ssid=ssid, passphrase=passphrase)
347 hostapd.add_ap(apdev[0], params)
348
349 src = dev[0].connect("another", psk=passphrase, scan_freq="2412",
350 only_add_network=True)
351 id = dev[0].add_network()
352 dev[0].set_network_quoted(id, "ssid", ssid)
353 for f in [ "key_mgmt", "psk", "scan_freq" ]:
354 res = dev[0].global_request("DUP_NETWORK {} {} {} {} {}".format(dev[0].ifname, dev[0].ifname, src, id, f))
355 if "OK" not in res:
356 raise Exception("DUP_NETWORK failed")
357 dev[0].connect_network(id)
358
359 if "FAIL" not in dev[0].global_request("DUP_NETWORK "):
360 raise Exception("Unexpected DUP_NETWORK success")
361 if "FAIL" not in dev[0].global_request("DUP_NETWORK %s" % dev[0].ifname):
362 raise Exception("Unexpected DUP_NETWORK success")
363 if "FAIL" not in dev[0].global_request("DUP_NETWORK %s %s" % (dev[0].ifname, dev[0].ifname)):
364 raise Exception("Unexpected DUP_NETWORK success")
365 if "FAIL" not in dev[0].global_request("DUP_NETWORK %s %s %d" % (dev[0].ifname, dev[0].ifname, id)):
366 raise Exception("Unexpected DUP_NETWORK success")
367 if "FAIL" not in dev[0].global_request("DUP_NETWORK %s %s %d %d" % (dev[0].ifname, dev[0].ifname, id, id)):
368 raise Exception("Unexpected DUP_NETWORK success")
369 dev[0].request("DISCONNECT")
370 if "OK" not in dev[0].global_request("DUP_NETWORK %s %s %d %d ssid" % (dev[0].ifname, dev[0].ifname, id, id)):
371 raise Exception("Unexpected DUP_NETWORK failure")
372
373 def add_cred(dev):
374 id = dev.add_cred()
375 ev = dev.wait_event(["CRED-ADDED"])
376 if ev is None:
377 raise Exception("Missing CRED-ADDED event")
378 if " " + str(id) not in ev:
379 raise Exception("CRED-ADDED event without matching id")
380 return id
381
382 def set_cred(dev, id, field, value):
383 dev.set_cred(id, field, value)
384 ev = dev.wait_event(["CRED-MODIFIED"])
385 if ev is None:
386 raise Exception("Missing CRED-MODIFIED event")
387 if " " + str(id) + " " not in ev:
388 raise Exception("CRED-MODIFIED event without matching id")
389 if field not in ev:
390 raise Exception("CRED-MODIFIED event without matching field")
391
392 def set_cred_quoted(dev, id, field, value):
393 dev.set_cred_quoted(id, field, value)
394 ev = dev.wait_event(["CRED-MODIFIED"])
395 if ev is None:
396 raise Exception("Missing CRED-MODIFIED event")
397 if " " + str(id) + " " not in ev:
398 raise Exception("CRED-MODIFIED event without matching id")
399 if field not in ev:
400 raise Exception("CRED-MODIFIED event without matching field")
401
402 def remove_cred(dev, id):
403 dev.remove_cred(id)
404 ev = dev.wait_event(["CRED-REMOVED"])
405 if ev is None:
406 raise Exception("Missing CRED-REMOVED event")
407 if " " + str(id) not in ev:
408 raise Exception("CRED-REMOVED event without matching id")
409
410 def test_wpas_ctrl_cred(dev):
411 """wpa_supplicant ctrl_iface cred set"""
412 id1 = add_cred(dev[0])
413 if "FAIL" not in dev[0].request("SET_CRED " + str(id1 + 1) + " temporary 1"):
414 raise Exception("SET_CRED succeeded unexpectedly on unknown cred id")
415 if "FAIL" not in dev[0].request("SET_CRED " + str(id1)):
416 raise Exception("Invalid SET_CRED succeeded unexpectedly")
417 if "FAIL" not in dev[0].request("SET_CRED " + str(id1) + " temporary"):
418 raise Exception("Invalid SET_CRED succeeded unexpectedly")
419 if "FAIL" not in dev[0].request("GET_CRED " + str(id1 + 1) + " temporary"):
420 raise Exception("GET_CRED succeeded unexpectedly on unknown cred id")
421 if "FAIL" not in dev[0].request("GET_CRED " + str(id1)):
422 raise Exception("Invalid GET_CRED succeeded unexpectedly")
423 if "FAIL" not in dev[0].request("GET_CRED " + str(id1) + " foo"):
424 raise Exception("Invalid GET_CRED succeeded unexpectedly")
425 id = add_cred(dev[0])
426 id2 = add_cred(dev[0])
427 set_cred(dev[0], id, "temporary", "1")
428 set_cred(dev[0], id, "priority", "1")
429 set_cred(dev[0], id, "pcsc", "1")
430 set_cred(dev[0], id, "sim_num", "0")
431 set_cred_quoted(dev[0], id, "private_key_passwd", "test")
432 set_cred_quoted(dev[0], id, "domain_suffix_match", "test")
433 set_cred_quoted(dev[0], id, "phase1", "test")
434 set_cred_quoted(dev[0], id, "phase2", "test")
435
436 if "FAIL" not in dev[0].request("SET_CRED " + str(id) + " eap FOO"):
437 raise Exception("Unexpected success on unknown EAP method")
438
439 if "FAIL" not in dev[0].request("SET_CRED " + str(id) + " username 12xa"):
440 raise Exception("Unexpected success on invalid string")
441
442 for i in ("11", "1122", "112233445566778899aabbccddeeff00"):
443 if "FAIL" not in dev[0].request("SET_CRED " + str(id) + " roaming_consortium " + i):
444 raise Exception("Unexpected success on invalid roaming_consortium")
445
446 dev[0].set_cred(id, "excluded_ssid", "00112233445566778899aabbccddeeff00112233445566778899aabbccddeeff")
447 if "FAIL" not in dev[0].request("SET_CRED " + str(id) + " excluded_ssid 00112233445566778899aabbccddeeff00112233445566778899aabbccddeeff00"):
448 raise Exception("Unexpected success on invalid excluded_ssid")
449
450 if "FAIL" not in dev[0].request("SET_CRED " + str(id) + " foo 4142"):
451 raise Exception("Unexpected success on unknown field")
452
453 tests = ["sp_priority 256",
454 'roaming_partner "example.org"',
455 'roaming_partner "' + 200*'a' + '.example.org,"',
456 'roaming_partner "example.org,1"',
457 'roaming_partner "example.org,1,2"',
458 'roaming_partner "example.org,1,2,ABC"' ]
459 for t in tests:
460 if "FAIL" not in dev[0].request("SET_CRED " + str(id) + " " + t):
461 raise Exception("Unexpected success on invalid SET_CRED value: " + t)
462
463 id3 = add_cred(dev[0])
464 id4 = add_cred(dev[0])
465 if len(dev[0].request("LIST_CREDS").splitlines()) != 6:
466 raise Exception("Unexpected LIST_CREDS result(1)")
467
468 remove_cred(dev[0], id1)
469 remove_cred(dev[0], id3)
470 remove_cred(dev[0], id4)
471 remove_cred(dev[0], id2)
472 remove_cred(dev[0], id)
473 if "FAIL" not in dev[0].request("REMOVE_CRED 1"):
474 raise Exception("Unexpected success on invalid remove cred")
475 if len(dev[0].request("LIST_CREDS").splitlines()) != 1:
476 raise Exception("Unexpected LIST_CREDS result(2)")
477
478 id = add_cred(dev[0])
479 values = [ ("temporary", "1", False),
480 ("temporary", "0", False),
481 ("pcsc", "1", False),
482 ("realm", "example.com", True),
483 ("username", "user@example.com", True),
484 ("password", "foo", True, "*"),
485 ("ca_cert", "ca.pem", True),
486 ("client_cert", "user.pem", True),
487 ("private_key", "key.pem", True),
488 ("private_key_passwd", "foo", True, "*"),
489 ("imsi", "310026-000000000", True),
490 ("milenage", "foo", True, "*"),
491 ("domain_suffix_match", "example.com", True),
492 ("domain", "example.com", True),
493 ("domain", "example.org", True, "example.com\nexample.org"),
494 ("roaming_consortium", "0123456789", False),
495 ("required_roaming_consortium", "456789", False),
496 ("eap", "TTLS", False),
497 ("phase1", "foo=bar1", True),
498 ("phase2", "foo=bar2", True),
499 ("excluded_ssid", "test", True),
500 ("excluded_ssid", "foo", True, "test\nfoo"),
501 ("roaming_partner", "example.com,0,4,*", True),
502 ("roaming_partner", "example.org,1,2,US", True,
503 "example.com,0,4,*\nexample.org,1,2,US"),
504 ("update_identifier", "4", False),
505 ("provisioning_sp", "sp.example.com", True),
506 ("sp_priority", "7", False),
507 ("min_dl_bandwidth_home", "100", False),
508 ("min_ul_bandwidth_home", "101", False),
509 ("min_dl_bandwidth_roaming", "102", False),
510 ("min_ul_bandwidth_roaming", "103", False),
511 ("max_bss_load", "57", False),
512 ("req_conn_capab", "6:22,80,443", False),
513 ("req_conn_capab", "17:500", False, "6:22,80,443\n17:500"),
514 ("req_conn_capab", "50", False, "6:22,80,443\n17:500\n50"),
515 ("ocsp", "1", False) ]
516 for v in values:
517 if v[2]:
518 set_cred_quoted(dev[0], id, v[0], v[1])
519 else:
520 set_cred(dev[0], id, v[0], v[1])
521 val = dev[0].get_cred(id, v[0])
522 if len(v) == 4:
523 expect = v[3]
524 else:
525 expect = v[1]
526 if val != expect:
527 raise Exception("Unexpected GET_CRED value for {}: {} != {}".format(v[0], val, expect))
528 creds = dev[0].request("LIST_CREDS").splitlines()
529 if len(creds) != 2:
530 raise Exception("Unexpected LIST_CREDS result(3)")
531 if creds[1] != "0\texample.com\tuser@example.com\texample.com\t310026-000000000":
532 raise Exception("Unexpected LIST_CREDS value")
533 remove_cred(dev[0], id)
534 if len(dev[0].request("LIST_CREDS").splitlines()) != 1:
535 raise Exception("Unexpected LIST_CREDS result(4)")
536
537 id = add_cred(dev[0])
538 set_cred_quoted(dev[0], id, "domain", "foo.example.com")
539 id = add_cred(dev[0])
540 set_cred_quoted(dev[0], id, "domain", "bar.example.com")
541 id = add_cred(dev[0])
542 set_cred_quoted(dev[0], id, "domain", "foo.example.com")
543 if "OK" not in dev[0].request("REMOVE_CRED sp_fqdn=foo.example.com"):
544 raise Exception("REMOVE_CRED failed")
545 creds = dev[0].request("LIST_CREDS")
546 if "foo.example.com" in creds:
547 raise Exception("REMOVE_CRED sp_fqdn did not remove cred")
548 if "bar.example.com" not in creds:
549 raise Exception("REMOVE_CRED sp_fqdn removed incorrect cred")
550 dev[0].request("REMOVE_CRED all")
551
552 id = add_cred(dev[0])
553 set_cred_quoted(dev[0], id, "domain", "foo.example.com")
554 set_cred_quoted(dev[0], id, "provisioning_sp", "sp.foo.example.com")
555 id = add_cred(dev[0])
556 set_cred_quoted(dev[0], id, "domain", "bar.example.com")
557 set_cred_quoted(dev[0], id, "provisioning_sp", "sp.bar.example.com")
558 id = add_cred(dev[0])
559 set_cred_quoted(dev[0], id, "domain", "foo.example.com")
560 set_cred_quoted(dev[0], id, "provisioning_sp", "sp.foo.example.com")
561 if "OK" not in dev[0].request("REMOVE_CRED provisioning_sp=sp.foo.example.com"):
562 raise Exception("REMOVE_CRED failed")
563 creds = dev[0].request("LIST_CREDS")
564 if "foo.example.com" in creds:
565 raise Exception("REMOVE_CRED provisioning_sp did not remove cred")
566 if "bar.example.com" not in creds:
567 raise Exception("REMOVE_CRED provisioning_sp removed incorrect cred")
568 dev[0].request("REMOVE_CRED all")
569
570 # Test large number of creds and LIST_CREDS truncation
571 dev[0].dump_monitor()
572 for i in range(0, 100):
573 id = add_cred(dev[0])
574 set_cred_quoted(dev[0], id, "realm", "relatively.long.realm.test%d.example.com" % i)
575 dev[0].dump_monitor()
576 creds = dev[0].request("LIST_CREDS")
577 for i in range(0, 100):
578 dev[0].remove_cred(i)
579 dev[0].dump_monitor()
580 if len(creds) < 3900 or len(creds) > 4100:
581 raise Exception("Unexpected LIST_CREDS length: %d" % len(creds))
582 if "test10.example.com" not in creds:
583 raise Exception("Missing credential")
584 if len(creds.splitlines()) > 95:
585 raise Exception("Too many LIST_CREDS entries in the buffer")
586
587 def test_wpas_ctrl_pno(dev):
588 """wpa_supplicant ctrl_iface pno"""
589 if "FAIL" not in dev[0].request("SET pno 1"):
590 raise Exception("Unexpected success in enabling PNO without enabled network blocks")
591 id = dev[0].add_network()
592 dev[0].set_network_quoted(id, "ssid", "test")
593 dev[0].set_network(id, "key_mgmt", "NONE")
594 dev[0].request("ENABLE_NETWORK " + str(id) + " no-connect")
595 #mac80211_hwsim does not yet support PNO, so this fails
596 if "FAIL" not in dev[0].request("SET pno 1"):
597 raise Exception("Unexpected success in enabling PNO")
598 if "FAIL" not in dev[0].request("SET pno 1 freq=2000-3000,5180"):
599 raise Exception("Unexpected success in enabling PNO")
600 if "FAIL" not in dev[0].request("SET pno 1 freq=0-6000"):
601 raise Exception("Unexpected success in enabling PNO")
602 if "FAIL" in dev[0].request("SET pno 0"):
603 raise Exception("Unexpected failure in disabling PNO")
604
605 def test_wpas_ctrl_get(dev):
606 """wpa_supplicant ctrl_iface get"""
607 if "FAIL" in dev[0].request("GET version"):
608 raise Exception("Unexpected get failure for version")
609 if "FAIL" in dev[0].request("GET wifi_display"):
610 raise Exception("Unexpected get failure for wifi_display")
611 if "FAIL" not in dev[0].request("GET foo"):
612 raise Exception("Unexpected success on get command")
613
614 def test_wpas_ctrl_preauth(dev):
615 """wpa_supplicant ctrl_iface preauth"""
616 if "FAIL" not in dev[0].request("PREAUTH "):
617 raise Exception("Unexpected success on invalid PREAUTH")
618 if "FAIL" in dev[0].request("PREAUTH 00:11:22:33:44:55"):
619 raise Exception("Unexpected failure on PREAUTH")
620
621 def test_wpas_ctrl_stkstart(dev):
622 """wpa_supplicant ctrl_iface strkstart"""
623 if "FAIL" not in dev[0].request("STKSTART "):
624 raise Exception("Unexpected success on invalid STKSTART")
625 if "FAIL" not in dev[0].request("STKSTART 00:11:22:33:44:55"):
626 raise Exception("Unexpected success on STKSTART")
627
628 def test_wpas_ctrl_tdls_discover(dev):
629 """wpa_supplicant ctrl_iface tdls_discover"""
630 if "FAIL" not in dev[0].request("TDLS_DISCOVER "):
631 raise Exception("Unexpected success on invalid TDLS_DISCOVER")
632 if "FAIL" not in dev[0].request("TDLS_DISCOVER 00:11:22:33:44:55"):
633 raise Exception("Unexpected success on TDLS_DISCOVER")
634
635 def test_wpas_ctrl_tdls_chan_switch(dev):
636 """wpa_supplicant ctrl_iface tdls_chan_switch error cases"""
637 for args in [ '', '00:11:22:33:44:55' ]:
638 if "FAIL" not in dev[0].request("TDLS_CANCEL_CHAN_SWITCH " + args):
639 raise Exception("Unexpected success on invalid TDLS_CANCEL_CHAN_SWITCH: " + args)
640
641 for args in [ '', 'foo ', '00:11:22:33:44:55 ', '00:11:22:33:44:55 q',
642 '00:11:22:33:44:55 81', '00:11:22:33:44:55 81 1234',
643 '00:11:22:33:44:55 81 1234 center_freq1=234 center_freq2=345 bandwidth=456 sec_channel_offset=567 ht vht' ]:
644 if "FAIL" not in dev[0].request("TDLS_CHAN_SWITCH " + args):
645 raise Exception("Unexpected success on invalid TDLS_CHAN_SWITCH: " + args)
646
647 def test_wpas_ctrl_addr(dev):
648 """wpa_supplicant ctrl_iface invalid address"""
649 if "FAIL" not in dev[0].request("TDLS_SETUP "):
650 raise Exception("Unexpected success on invalid TDLS_SETUP")
651 if "FAIL" not in dev[0].request("TDLS_TEARDOWN "):
652 raise Exception("Unexpected success on invalid TDLS_TEARDOWN")
653 if "FAIL" not in dev[0].request("FT_DS "):
654 raise Exception("Unexpected success on invalid FT_DS")
655 if "FAIL" not in dev[0].request("WPS_PBC 00:11:22:33:44"):
656 raise Exception("Unexpected success on invalid WPS_PBC")
657 if "FAIL" not in dev[0].request("WPS_PIN 00:11:22:33:44"):
658 raise Exception("Unexpected success on invalid WPS_PIN")
659 if "FAIL" not in dev[0].request("WPS_NFC 00:11:22:33:44"):
660 raise Exception("Unexpected success on invalid WPS_NFC")
661 if "FAIL" not in dev[0].request("WPS_REG 00:11:22:33:44 12345670"):
662 raise Exception("Unexpected success on invalid WPS_REG")
663 if "FAIL" not in dev[0].request("IBSS_RSN 00:11:22:33:44"):
664 raise Exception("Unexpected success on invalid IBSS_RSN")
665 if "FAIL" not in dev[0].request("BLACKLIST 00:11:22:33:44"):
666 raise Exception("Unexpected success on invalid BLACKLIST")
667
668 def test_wpas_ctrl_wps_errors(dev):
669 """wpa_supplicant ctrl_iface WPS error cases"""
670 if "FAIL" not in dev[0].request("WPS_REG 00:11:22:33:44:55"):
671 raise Exception("Unexpected success on invalid WPS_REG")
672 if "FAIL" not in dev[0].request("WPS_REG 00:11:22:33:44:55 12345670 2233"):
673 raise Exception("Unexpected success on invalid WPS_REG")
674 if "FAIL" not in dev[0].request("WPS_REG 00:11:22:33:44:55 12345670 2233 OPEN"):
675 raise Exception("Unexpected success on invalid WPS_REG")
676 if "FAIL" not in dev[0].request("WPS_REG 00:11:22:33:44:55 12345670 2233 OPEN NONE"):
677 raise Exception("Unexpected success on invalid WPS_REG")
678
679 if "FAIL" not in dev[0].request("WPS_AP_PIN random"):
680 raise Exception("Unexpected success on WPS_AP_PIN in non-AP mode")
681
682 if "FAIL" not in dev[0].request("WPS_ER_PIN any"):
683 raise Exception("Unexpected success on invalid WPS_ER_PIN")
684
685 if "FAIL" not in dev[0].request("WPS_ER_LEARN 00:11:22:33:44:55"):
686 raise Exception("Unexpected success on invalid WPS_ER_LEARN")
687
688 if "FAIL" not in dev[0].request("WPS_ER_SET_CONFIG 00:11:22:33:44:55"):
689 raise Exception("Unexpected success on invalid WPS_ER_SET_CONFIG")
690
691 if "FAIL" not in dev[0].request("WPS_ER_CONFIG 00:11:22:33:44:55"):
692 raise Exception("Unexpected success on invalid WPS_ER_CONFIG")
693 if "FAIL" not in dev[0].request("WPS_ER_CONFIG 00:11:22:33:44:55 12345670"):
694 raise Exception("Unexpected success on invalid WPS_ER_CONFIG")
695 if "FAIL" not in dev[0].request("WPS_ER_CONFIG 00:11:22:33:44:55 12345670 2233"):
696 raise Exception("Unexpected success on invalid WPS_ER_CONFIG")
697 if "FAIL" not in dev[0].request("WPS_ER_CONFIG 00:11:22:33:44:55 12345670 2233 OPEN"):
698 raise Exception("Unexpected success on invalid WPS_ER_CONFIG")
699 if "FAIL" not in dev[0].request("WPS_ER_CONFIG 00:11:22:33:44:55 12345670 2233 OPEN NONE"):
700 raise Exception("Unexpected success on invalid WPS_ER_CONFIG")
701
702 if "FAIL" not in dev[0].request("WPS_ER_NFC_CONFIG_TOKEN WPS"):
703 raise Exception("Unexpected success on invalid WPS_ER_NFC_CONFIG_TOKEN")
704 if "FAIL" not in dev[0].request("WPS_ER_NFC_CONFIG_TOKEN FOO 00:11:22:33:44:55"):
705 raise Exception("Unexpected success on invalid WPS_ER_NFC_CONFIG_TOKEN")
706 if "FAIL" not in dev[0].request("WPS_ER_NFC_CONFIG_TOKEN NDEF 00:11:22:33:44:55"):
707 raise Exception("Unexpected success on invalid WPS_ER_NFC_CONFIG_TOKEN")
708
709 if "FAIL" not in dev[0].request("WPS_NFC_CONFIG_TOKEN FOO"):
710 raise Exception("Unexpected success on invalid WPS_NFC_CONFIG_TOKEN")
711 if "FAIL" not in dev[0].request("WPS_NFC_CONFIG_TOKEN WPS FOO"):
712 raise Exception("Unexpected success on invalid WPS_NFC_CONFIG_TOKEN")
713 if "FAIL" not in dev[0].request("WPS_NFC_TOKEN FOO"):
714 raise Exception("Unexpected success on invalid WPS_NFC_TOKEN")
715
716 def test_wpas_ctrl_config_parser(dev):
717 """wpa_supplicant ctrl_iface SET config parser"""
718 if "FAIL" not in dev[0].request("SET pbc_in_m1 qwerty"):
719 raise Exception("Non-number accepted as integer")
720 if "FAIL" not in dev[0].request("SET eapol_version 0"):
721 raise Exception("Out-of-range value accepted")
722 if "FAIL" not in dev[0].request("SET eapol_version 10"):
723 raise Exception("Out-of-range value accepted")
724
725 if "FAIL" not in dev[0].request("SET serial_number 0123456789abcdef0123456789abcdef0"):
726 raise Exception("Too long string accepted")
727
728 def test_wpas_ctrl_mib(dev):
729 """wpa_supplicant ctrl_iface MIB"""
730 mib = dev[0].get_mib()
731 if "dot11RSNAOptionImplemented" not in mib:
732 raise Exception("Missing MIB entry")
733 if mib["dot11RSNAOptionImplemented"] != "TRUE":
734 raise Exception("Unexpected dot11RSNAOptionImplemented value")
735
736 def test_wpas_ctrl_set_wps_params(dev):
737 """wpa_supplicant ctrl_iface SET config_methods"""
738 try:
739 _test_wpas_ctrl_set_wps_params(dev)
740 finally:
741 dev[2].request("SET config_methods ")
742
743 def _test_wpas_ctrl_set_wps_params(dev):
744 ts = [ "config_methods label virtual_display virtual_push_button keypad",
745 "device_type 1-0050F204-1",
746 "os_version 01020300",
747 "uuid 12345678-9abc-def0-1234-56789abcdef0" ]
748 for t in ts:
749 if "OK" not in dev[2].request("SET " + t):
750 raise Exception("SET failed for: " + t)
751
752 ts = [ "uuid 12345678+9abc-def0-1234-56789abcdef0",
753 "uuid 12345678-qabc-def0-1234-56789abcdef0",
754 "uuid 12345678-9abc+def0-1234-56789abcdef0",
755 "uuid 12345678-9abc-qef0-1234-56789abcdef0",
756 "uuid 12345678-9abc-def0+1234-56789abcdef0",
757 "uuid 12345678-9abc-def0-q234-56789abcdef0",
758 "uuid 12345678-9abc-def0-1234+56789abcdef0",
759 "uuid 12345678-9abc-def0-1234-q6789abcdef0",
760 "uuid qwerty" ]
761 for t in ts:
762 if "FAIL" not in dev[2].request("SET " + t):
763 raise Exception("SET succeeded for: " + t)
764
765 def test_wpas_ctrl_level(dev):
766 """wpa_supplicant ctrl_iface LEVEL"""
767 try:
768 if "FAIL" not in dev[2].request("LEVEL 3"):
769 raise Exception("Unexpected LEVEL success")
770 if "OK" not in dev[2].mon.request("LEVEL 2"):
771 raise Exception("Unexpected LEVEL failure")
772 dev[2].request("SCAN freq=2412")
773 ev = dev[2].wait_event(["State:"], timeout=5)
774 if ev is None:
775 raise Exception("No debug message received")
776 dev[2].wait_event(["CTRL-EVENT-SCAN-RESULTS"], timeout=5)
777 finally:
778 dev[2].mon.request("LEVEL 3")
779
780 def test_wpas_ctrl_bssid_filter(dev, apdev):
781 """wpa_supplicant bssid_filter"""
782 try:
783 if "OK" not in dev[2].request("SET bssid_filter " + apdev[0]['bssid']):
784 raise Exception("Failed to set bssid_filter")
785 params = { "ssid": "test" }
786 hostapd.add_ap(apdev[0], params)
787 hostapd.add_ap(apdev[1], params)
788 dev[2].scan_for_bss(apdev[0]['bssid'], freq="2412")
789 dev[2].scan(freq="2412")
790 bss = dev[2].get_bss(apdev[0]['bssid'])
791 if bss is None or len(bss) == 0:
792 raise Exception("Missing BSS data")
793 bss = dev[2].get_bss(apdev[1]['bssid'])
794 if bss and len(bss) != 0:
795 raise Exception("Unexpected BSS data")
796 dev[2].request("SET bssid_filter ")
797 dev[2].scan(freq="2412")
798 bss = dev[2].get_bss(apdev[0]['bssid'])
799 if bss is None or len(bss) == 0:
800 raise Exception("Missing BSS data")
801 bss = dev[2].get_bss(apdev[1]['bssid'])
802 if bss is None or len(bss) == 0:
803 raise Exception("Missing BSS data(2)")
804 res = dev[2].request("SCAN_RESULTS").splitlines()
805 if "test" not in res[1] or "test" not in res[2]:
806 raise Exception("SSID missing from SCAN_RESULTS")
807 if apdev[0]['bssid'] not in res[1] and apdev[1]['bssid'] not in res[1]:
808 raise Exception("BSS1 missing from SCAN_RESULTS")
809 if apdev[0]['bssid'] not in res[2] and apdev[1]['bssid'] not in res[2]:
810 raise Exception("BSS1 missing from SCAN_RESULTS")
811
812 if "FAIL" not in dev[2].request("SET bssid_filter 00:11:22:33:44:55 00:11:22:33:44"):
813 raise Exception("Unexpected success for invalid SET bssid_filter")
814 finally:
815 dev[2].request("SET bssid_filter ")
816
817 def test_wpas_ctrl_disallow_aps(dev, apdev):
818 """wpa_supplicant ctrl_iface disallow_aps"""
819 params = { "ssid": "test" }
820 hostapd.add_ap(apdev[0], params)
821
822 if "FAIL" not in dev[0].request("SET disallow_aps bssid "):
823 raise Exception("Unexpected success on invalid disallow_aps")
824 if "FAIL" not in dev[0].request("SET disallow_aps bssid 00:11:22:33:44"):
825 raise Exception("Unexpected success on invalid disallow_aps")
826 if "FAIL" not in dev[0].request("SET disallow_aps ssid 0"):
827 raise Exception("Unexpected success on invalid disallow_aps")
828 if "FAIL" not in dev[0].request("SET disallow_aps ssid 4q"):
829 raise Exception("Unexpected success on invalid disallow_aps")
830 if "FAIL" not in dev[0].request("SET disallow_aps bssid 00:11:22:33:44:55 ssid 112233 ssid 123"):
831 raise Exception("Unexpected success on invalid disallow_aps")
832 if "FAIL" not in dev[0].request("SET disallow_aps ssid 000102030405060708090a0b0c0d0e0f000102030405060708090a0b0c0d0e0f00"):
833 raise Exception("Unexpected success on invalid disallow_aps")
834 if "FAIL" not in dev[0].request("SET disallow_aps foo 112233445566"):
835 raise Exception("Unexpected success on invalid disallow_aps")
836
837 dev[0].connect("test", key_mgmt="NONE", scan_freq="2412")
838 hostapd.add_ap(apdev[1], params)
839 dev[0].scan_for_bss(apdev[1]['bssid'], freq="2412")
840 dev[0].dump_monitor()
841 if "OK" not in dev[0].request("SET disallow_aps bssid 00:11:22:33:44:55 bssid 00:22:33:44:55:66"):
842 raise Exception("Failed to set disallow_aps")
843 if "OK" not in dev[0].request("SET disallow_aps bssid " + apdev[0]['bssid']):
844 raise Exception("Failed to set disallow_aps")
845 ev = dev[0].wait_connected(timeout=30, error="Reassociation timed out")
846 if apdev[1]['bssid'] not in ev:
847 raise Exception("Unexpected BSSID")
848
849 dev[0].dump_monitor()
850 if "OK" not in dev[0].request("SET disallow_aps ssid " + "test".encode("hex")):
851 raise Exception("Failed to set disallow_aps")
852 dev[0].wait_disconnected(timeout=5, error="Disconnection not seen")
853 ev = dev[0].wait_event(["CTRL-EVENT-CONNECTED"], timeout=1)
854 if ev is not None:
855 raise Exception("Unexpected reassociation")
856
857 dev[0].request("DISCONNECT")
858 dev[0].p2p_start_go(freq=2412)
859 if "OK" not in dev[0].request("SET disallow_aps "):
860 raise Exception("Failed to set disallow_aps")
861
862 def test_wpas_ctrl_blob(dev):
863 """wpa_supplicant ctrl_iface SET blob"""
864 if "FAIL" not in dev[0].request("SET blob foo"):
865 raise Exception("Unexpected SET success")
866 if "FAIL" not in dev[0].request("SET blob foo 0"):
867 raise Exception("Unexpected SET success")
868 if "FAIL" not in dev[0].request("SET blob foo 0q"):
869 raise Exception("Unexpected SET success")
870 if "OK" not in dev[0].request("SET blob foo 00"):
871 raise Exception("Unexpected SET failure")
872 if "OK" not in dev[0].request("SET blob foo 0011"):
873 raise Exception("Unexpected SET failure")
874
875 def test_wpas_ctrl_set_uapsd(dev):
876 """wpa_supplicant ctrl_iface SET uapsd"""
877 if "FAIL" not in dev[0].request("SET uapsd foo"):
878 raise Exception("Unexpected SET success")
879 if "FAIL" not in dev[0].request("SET uapsd 0,0,0"):
880 raise Exception("Unexpected SET success")
881 if "FAIL" not in dev[0].request("SET uapsd 0,0"):
882 raise Exception("Unexpected SET success")
883 if "FAIL" not in dev[0].request("SET uapsd 0"):
884 raise Exception("Unexpected SET success")
885 if "OK" not in dev[0].request("SET uapsd 1,1,1,1;1"):
886 raise Exception("Unexpected SET failure")
887 if "OK" not in dev[0].request("SET uapsd 0,0,0,0;0"):
888 raise Exception("Unexpected SET failure")
889 if "OK" not in dev[0].request("SET uapsd disable"):
890 raise Exception("Unexpected SET failure")
891
892 def test_wpas_ctrl_set(dev):
893 """wpa_supplicant ctrl_iface SET"""
894 vals = [ "foo",
895 "ampdu 0",
896 "radio_disable 0",
897 "ps 10",
898 "ps 1",
899 "dot11RSNAConfigPMKLifetime 0",
900 "dot11RSNAConfigPMKReauthThreshold 101",
901 "dot11RSNAConfigSATimeout 0",
902 "wps_version_number -1",
903 "wps_version_number 256",
904 "fst_group_id ",
905 "fst_llt 0"]
906 for val in vals:
907 if "FAIL" not in dev[0].request("SET " + val):
908 raise Exception("Unexpected SET success for " + val)
909
910 vals = [ "EAPOL::heldPeriod 60",
911 "EAPOL::authPeriod 30",
912 "EAPOL::startPeriod 30",
913 "EAPOL::maxStart 3",
914 "dot11RSNAConfigSATimeout 60",
915 "ps -1",
916 "ps 0",
917 "no_keep_alive 0",
918 "tdls_disabled 1",
919 "tdls_disabled 0" ]
920 for val in vals:
921 if "OK" not in dev[0].request("SET " + val):
922 raise Exception("Unexpected SET failure for " + val)
923
924 # This fails if wpa_supplicant is built with loadable EAP peer method
925 # support due to missing file and succeeds if no support for loadable
926 # methods is included, so don't check the return value for now.
927 dev[0].request("SET load_dynamic_eap /tmp/hwsim-eap-not-found.so")
928
929 def test_wpas_ctrl_get_capability(dev):
930 """wpa_supplicant ctrl_iface GET_CAPABILITY"""
931 if "FAIL" not in dev[0].request("GET_CAPABILITY 1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890"):
932 raise Exception("Unexpected success on invalid GET_CAPABILITY")
933 if "FAIL" not in dev[0].request("GET_CAPABILITY eap foo"):
934 raise Exception("Unexpected success on invalid GET_CAPABILITY")
935 if "AP" not in dev[0].request("GET_CAPABILITY modes strict"):
936 raise Exception("Unexpected GET_CAPABILITY response")
937 res = dev[0].get_capability("eap")
938 if "TTLS" not in res:
939 raise Exception("Unexpected GET_CAPABILITY eap response: " + str(res))
940
941 res = dev[0].get_capability("pairwise")
942 if "CCMP" not in res:
943 raise Exception("Unexpected GET_CAPABILITY pairwise response: " + str(res))
944
945 res = dev[0].get_capability("group")
946 if "CCMP" not in res:
947 raise Exception("Unexpected GET_CAPABILITY group response: " + str(res))
948
949 res = dev[0].get_capability("key_mgmt")
950 if "WPA-PSK" not in res or "WPA-EAP" not in res:
951 raise Exception("Unexpected GET_CAPABILITY key_mgmt response: " + str(res))
952
953 res = dev[0].get_capability("proto")
954 if "WPA" not in res or "RSN" not in res:
955 raise Exception("Unexpected GET_CAPABILITY proto response: " + str(res))
956
957 res = dev[0].get_capability("auth_alg")
958 if "OPEN" not in res or "SHARED" not in res:
959 raise Exception("Unexpected GET_CAPABILITY auth_alg response: " + str(res))
960
961 res = dev[0].get_capability("modes")
962 if "IBSS" not in res or "AP" not in res:
963 raise Exception("Unexpected GET_CAPABILITY modes response: " + str(res))
964
965 res = dev[0].get_capability("channels")
966 if "8" not in res or "36" not in res:
967 raise Exception("Unexpected GET_CAPABILITY channels response: " + str(res))
968
969 res = dev[0].get_capability("freq")
970 if "2457" not in res or "5180" not in res:
971 raise Exception("Unexpected GET_CAPABILITY freq response: " + str(res))
972
973 res = dev[0].get_capability("tdls")
974 if "EXTERNAL" not in res[0]:
975 raise Exception("Unexpected GET_CAPABILITY tdls response: " + str(res))
976
977 res = dev[0].get_capability("erp")
978 if res is None or "ERP" not in res[0]:
979 raise Exception("Unexpected GET_CAPABILITY erp response: " + str(res))
980
981 if dev[0].get_capability("foo") is not None:
982 raise Exception("Unexpected GET_CAPABILITY foo response: " + str(res))
983
984 def test_wpas_ctrl_nfc_report_handover(dev):
985 """wpa_supplicant ctrl_iface NFC_REPORT_HANDOVER"""
986 vals = [ "FOO",
987 "ROLE freq=12345",
988 "ROLE TYPE",
989 "ROLE TYPE REQ",
990 "ROLE TYPE REQ SEL",
991 "ROLE TYPE 0Q SEL",
992 "ROLE TYPE 00 SEL",
993 "ROLE TYPE 00 0Q",
994 "ROLE TYPE 00 00" ]
995 for v in vals:
996 if "FAIL" not in dev[0].request("NFC_REPORT_HANDOVER " + v):
997 raise Exception("Unexpected NFC_REPORT_HANDOVER success for " + v)
998
999 def test_wpas_ctrl_nfc_tag_read(dev):
1000 """wpa_supplicant ctrl_iface WPS_NFC_TAG_READ"""
1001 vals = [ "FOO", "0Q", "00", "000000", "10000001", "10000000", "00000000",
1002 "100e0000", "100e0001ff", "100e000411110000", "100e0004100e0001" ]
1003 for v in vals:
1004 if "FAIL" not in dev[0].request("WPS_NFC_TAG_READ " + v):
1005 raise Exception("Unexpected WPS_NFC_TAG_READ success for " + v)
1006
1007 def test_wpas_ctrl_nfc_get_handover(dev):
1008 """wpa_supplicant ctrl_iface NFC_GET_HANDOVER"""
1009 vals = [ "FOO", "FOO BAR", "WPS WPS", "WPS WPS-CR", "WPS FOO", "NDEF P2P" ]
1010 for v in vals:
1011 if "FAIL" not in dev[0].request("NFC_GET_HANDOVER_REQ " + v):
1012 raise Exception("Unexpected NFC_GET_HANDOVER_REQ success for " + v)
1013
1014 vals = [ "NDEF WPS", "NDEF P2P-CR", "WPS P2P-CR" ]
1015 for v in vals:
1016 if "FAIL" in dev[0].request("NFC_GET_HANDOVER_REQ " + v):
1017 raise Exception("Unexpected NFC_GET_HANDOVER_REQ failure for " + v)
1018
1019 vals = [ "FOO", "FOO BAR", "WPS WPS", "WPS WPS-CR", "WPS FOO", "NDEF P2P",
1020 "NDEF WPS", "NDEF WPS uuid" ]
1021 for v in vals:
1022 if "FAIL" not in dev[0].request("NFC_GET_HANDOVER_SEL " + v):
1023 raise Exception("Unexpected NFC_GET_HANDOVER_SEL success for " + v)
1024
1025 vals = [ "NDEF P2P-CR", "WPS P2P-CR", "NDEF P2P-CR-TAG",
1026 "WPS P2P-CR-TAG" ]
1027 for v in vals:
1028 if "FAIL" in dev[0].request("NFC_GET_HANDOVER_SEL " + v):
1029 raise Exception("Unexpected NFC_GET_HANDOVER_SEL failure for " + v)
1030
1031 def get_blacklist(dev):
1032 return dev.request("BLACKLIST").splitlines()
1033
1034 def test_wpas_ctrl_blacklist(dev):
1035 """wpa_supplicant ctrl_iface BLACKLIST"""
1036 if "OK" not in dev[0].request("BLACKLIST clear"):
1037 raise Exception("BLACKLIST clear failed")
1038 b = get_blacklist(dev[0])
1039 if len(b) != 0:
1040 raise Exception("Unexpected blacklist contents: " + str(b))
1041 if "OK" not in dev[0].request("BLACKLIST 00:11:22:33:44:55"):
1042 raise Exception("BLACKLIST add failed")
1043 b = get_blacklist(dev[0])
1044 if "00:11:22:33:44:55" not in b:
1045 raise Exception("Unexpected blacklist contents: " + str(b))
1046 if "OK" not in dev[0].request("BLACKLIST 00:11:22:33:44:56"):
1047 raise Exception("BLACKLIST add failed")
1048 b = get_blacklist(dev[0])
1049 if "00:11:22:33:44:55" not in b or "00:11:22:33:44:56" not in b:
1050 raise Exception("Unexpected blacklist contents: " + str(b))
1051 if "OK" not in dev[0].request("BLACKLIST 00:11:22:33:44:56"):
1052 raise Exception("BLACKLIST add failed")
1053 b = get_blacklist(dev[0])
1054 if "00:11:22:33:44:55" not in b or "00:11:22:33:44:56" not in b or len(b) != 2:
1055 raise Exception("Unexpected blacklist contents: " + str(b))
1056
1057 if "OK" not in dev[0].request("BLACKLIST clear"):
1058 raise Exception("BLACKLIST clear failed")
1059 if dev[0].request("BLACKLIST") != "":
1060 raise Exception("Unexpected blacklist contents")
1061
1062 def test_wpas_ctrl_blacklist_oom(dev):
1063 """wpa_supplicant ctrl_iface BLACKLIST and out-of-memory"""
1064 with alloc_fail(dev[0], 1, "wpa_blacklist_add"):
1065 if "FAIL" not in dev[0].request("BLACKLIST aa:bb:cc:dd:ee:ff"):
1066 raise Exception("Unexpected success with allocation failure")
1067
1068 def test_wpas_ctrl_log_level(dev):
1069 """wpa_supplicant ctrl_iface LOG_LEVEL"""
1070 level = dev[2].request("LOG_LEVEL")
1071 if "Current level: MSGDUMP" not in level:
1072 raise Exception("Unexpected debug level(1): " + level)
1073 if "Timestamp: 1" not in level:
1074 raise Exception("Unexpected timestamp(1): " + level)
1075
1076 if "OK" not in dev[2].request("LOG_LEVEL MSGDUMP 0"):
1077 raise Exception("LOG_LEVEL failed")
1078 level = dev[2].request("LOG_LEVEL")
1079 if "Current level: MSGDUMP" not in level:
1080 raise Exception("Unexpected debug level(2): " + level)
1081 if "Timestamp: 0" not in level:
1082 raise Exception("Unexpected timestamp(2): " + level)
1083
1084 if "OK" not in dev[2].request("LOG_LEVEL MSGDUMP 1"):
1085 raise Exception("LOG_LEVEL failed")
1086 level = dev[2].request("LOG_LEVEL")
1087 if "Current level: MSGDUMP" not in level:
1088 raise Exception("Unexpected debug level(3): " + level)
1089 if "Timestamp: 1" not in level:
1090 raise Exception("Unexpected timestamp(3): " + level)
1091
1092 if "FAIL" not in dev[2].request("LOG_LEVEL FOO"):
1093 raise Exception("Invalid LOG_LEVEL accepted")
1094
1095 for lev in [ "EXCESSIVE", "MSGDUMP", "DEBUG", "INFO", "WARNING", "ERROR" ]:
1096 if "OK" not in dev[2].request("LOG_LEVEL " + lev):
1097 raise Exception("LOG_LEVEL failed for " + lev)
1098 level = dev[2].request("LOG_LEVEL")
1099 if "Current level: " + lev not in level:
1100 raise Exception("Unexpected debug level: " + level)
1101
1102 if "OK" not in dev[2].request("LOG_LEVEL MSGDUMP 1"):
1103 raise Exception("LOG_LEVEL failed")
1104 level = dev[2].request("LOG_LEVEL")
1105 if "Current level: MSGDUMP" not in level:
1106 raise Exception("Unexpected debug level(3): " + level)
1107 if "Timestamp: 1" not in level:
1108 raise Exception("Unexpected timestamp(3): " + level)
1109
1110 def test_wpas_ctrl_enable_disable_network(dev, apdev):
1111 """wpa_supplicant ctrl_iface ENABLE/DISABLE_NETWORK"""
1112 params = { "ssid": "test" }
1113 hostapd.add_ap(apdev[0], params)
1114
1115 id = dev[0].connect("test", key_mgmt="NONE", scan_freq="2412",
1116 only_add_network=True)
1117 if "OK" not in dev[0].request("DISABLE_NETWORK " + str(id)):
1118 raise Exception("Failed to disable network")
1119 if "OK" not in dev[0].request("ENABLE_NETWORK " + str(id) + " no-connect"):
1120 raise Exception("Failed to enable network")
1121 if "OK" not in dev[0].request("DISABLE_NETWORK all"):
1122 raise Exception("Failed to disable networks")
1123 if "OK" not in dev[0].request("ENABLE_NETWORK " + str(id)):
1124 raise Exception("Failed to enable network")
1125 dev[0].wait_connected(timeout=10)
1126 if "OK" not in dev[0].request("DISABLE_NETWORK " + str(id)):
1127 raise Exception("Failed to disable network")
1128 dev[0].wait_disconnected(timeout=10)
1129 time.sleep(0.1)
1130
1131 if "OK" not in dev[0].request("ENABLE_NETWORK all"):
1132 raise Exception("Failed to enable network")
1133 dev[0].wait_connected(timeout=10)
1134 if "OK" not in dev[0].request("DISABLE_NETWORK all"):
1135 raise Exception("Failed to disable network")
1136 dev[0].wait_disconnected(timeout=10)
1137
1138 def test_wpas_ctrl_country(dev, apdev):
1139 """wpa_supplicant SET/GET country code"""
1140 try:
1141 # work around issues with possible pending regdom event from the end of
1142 # the previous test case
1143 time.sleep(0.2)
1144 dev[0].dump_monitor()
1145
1146 if "OK" not in dev[0].request("SET country FI"):
1147 raise Exception("Failed to set country code")
1148 if dev[0].request("GET country") != "FI":
1149 raise Exception("Country code set failed")
1150 ev = dev[0].wait_global_event(["CTRL-EVENT-REGDOM-CHANGE"], 10)
1151 if ev is None:
1152 raise Exception("regdom change event not seen")
1153 if "init=USER type=COUNTRY alpha2=FI" not in ev:
1154 raise Exception("Unexpected event contents: " + ev)
1155 dev[0].request("SET country 00")
1156 if dev[0].request("GET country") != "00":
1157 raise Exception("Country code set failed")
1158 ev = dev[0].wait_global_event(["CTRL-EVENT-REGDOM-CHANGE"], 10)
1159 if ev is None:
1160 raise Exception("regdom change event not seen")
1161 # init=CORE was previously used due to invalid db.txt data for 00. For
1162 # now, allow both it and the new init=USER after fixed db.txt.
1163 if "init=CORE type=WORLD" not in ev and "init=USER type=WORLD" not in ev:
1164 raise Exception("Unexpected event contents: " + ev)
1165 finally:
1166 subprocess.call(['iw', 'reg', 'set', '00'])
1167
1168 def test_wpas_ctrl_suspend_resume(dev):
1169 """wpa_supplicant SUSPEND/RESUME"""
1170 wpas = WpaSupplicant(global_iface='/tmp/wpas-wlan5')
1171 wpas.interface_add("wlan5")
1172 if "OK" not in wpas.global_request("SUSPEND"):
1173 raise Exception("SUSPEND failed")
1174 time.sleep(1)
1175 if "OK" not in wpas.global_request("RESUME"):
1176 raise Exception("RESUME failed")
1177 if "OK" not in wpas.request("SUSPEND"):
1178 raise Exception("Per-interface SUSPEND failed")
1179 if "OK" not in wpas.request("RESUME"):
1180 raise Exception("Per-interface RESUME failed")
1181 ev = wpas.wait_event(["CTRL-EVENT-SCAN-RESULTS"], timeout=10)
1182 if ev is None:
1183 raise Exception("Scan not completed")
1184
1185 def test_wpas_ctrl_global(dev):
1186 """wpa_supplicant global control interface"""
1187 wpas = WpaSupplicant(global_iface='/tmp/wpas-wlan5')
1188 wpas.interface_add("wlan5")
1189
1190 if "PONG" not in wpas.global_request("PING"):
1191 raise Exception("PING failed")
1192 if "wlan5" not in wpas.global_request("INTERFACES"):
1193 raise Exception("Interface not found")
1194 if "UNKNOWN COMMAND" not in wpas.global_request("FOO"):
1195 raise Exception("Unexpected response to unknown command")
1196 if "PONG" not in wpas.global_request("IFNAME=wlan5 PING"):
1197 raise Exception("Per-interface PING failed")
1198 if "FAIL-NO-IFNAME-MATCH" not in wpas.global_request("IFNAME=notfound PING"):
1199 raise Exception("Unknown interface not reported correctly")
1200 if "FAIL" not in wpas.global_request("SAVE_CONFIG"):
1201 raise Exception("SAVE_CONFIG succeeded unexpectedly")
1202 if "OK" not in wpas.global_request("SET wifi_display 0"):
1203 raise Exception("SET failed")
1204 if "wifi_display=0" not in wpas.global_request("STATUS"):
1205 raise Exception("wifi_display not disabled")
1206 if "OK" not in wpas.global_request("SET wifi_display 1"):
1207 raise Exception("SET failed")
1208 if "wifi_display=1" not in wpas.global_request("STATUS"):
1209 raise Exception("wifi_display not enabled")
1210 if "FAIL" not in wpas.global_request("SET foo 1"):
1211 raise Exception("SET succeeded unexpectedly")
1212
1213 if "p2p_state=IDLE" not in wpas.global_request("STATUS"):
1214 raise Exception("P2P was disabled")
1215 wpas.global_request("P2P_SET disabled 1")
1216 if "p2p_state=DISABLED" not in wpas.global_request("STATUS"):
1217 raise Exception("P2P was not disabled")
1218 wpas.global_request("P2P_SET disabled 0")
1219 if "p2p_state=IDLE" not in wpas.global_request("STATUS"):
1220 raise Exception("P2P was not enabled")
1221
1222 # driver_nl80211.c does not support interface list, so do not fail because
1223 # of that
1224 logger.debug(wpas.global_request("INTERFACE_LIST"))
1225
1226 if "FAIL" not in wpas.global_request("INTERFACE_ADD "):
1227 raise Exception("INTERFACE_ADD succeeded unexpectedly")
1228 if "FAIL" not in wpas.global_request("INTERFACE_ADD FOO"):
1229 raise Exception("INTERFACE_ADD succeeded unexpectedly")
1230 if "FAIL" not in wpas.global_request("INTERFACE_ADD FOO conf"):
1231 raise Exception("INTERFACE_ADD succeeded unexpectedly")
1232 if "FAIL" not in wpas.global_request("INTERFACE_ADD FOO conf driver"):
1233 raise Exception("INTERFACE_ADD succeeded unexpectedly")
1234 if "FAIL" not in wpas.global_request("INTERFACE_ADD FOO conf driver ctrliface"):
1235 raise Exception("INTERFACE_ADD succeeded unexpectedly")
1236 if "FAIL" not in wpas.global_request("INTERFACE_ADD FOO conf driver ctrliface driverparam"):
1237 raise Exception("INTERFACE_ADD succeeded unexpectedly")
1238 if "FAIL" not in wpas.global_request("INTERFACE_ADD FOO conf driver ctrliface driverparam bridge"):
1239 raise Exception("INTERFACE_ADD succeeded unexpectedly")
1240 if "FAIL" not in wpas.global_request("INTERFACE_ADD FOO conf driver ctrliface driverparam bridge foo"):
1241 raise Exception("INTERFACE_ADD succeeded unexpectedly")
1242 if "FAIL" not in wpas.global_request("INTERFACE_ADD FOO "):
1243 raise Exception("INTERFACE_ADD succeeded unexpectedly")
1244 if "FAIL" not in wpas.global_request("INTERFACE_ADD FOO conf driver ctrliface driverparam bridge create abcd"):
1245 raise Exception("INTERFACE_ADD succeeded unexpectedly")
1246
1247 def test_wpas_ctrl_roam(dev, apdev):
1248 """wpa_supplicant ctrl_iface ROAM error cases"""
1249 if "FAIL" not in dev[0].request("ROAM 00:11:22:33:44"):
1250 raise Exception("Unexpected success")
1251 if "FAIL" not in dev[0].request("ROAM 00:11:22:33:44:55"):
1252 raise Exception("Unexpected success")
1253 params = { "ssid": "test" }
1254 hostapd.add_ap(apdev[0], params)
1255 id = dev[0].connect("test", key_mgmt="NONE", scan_freq="2412")
1256 if "FAIL" not in dev[0].request("ROAM 00:11:22:33:44:55"):
1257 raise Exception("Unexpected success")
1258
1259 def test_wpas_ctrl_ipaddr(dev, apdev):
1260 """wpa_supplicant IP address in STATUS"""
1261 try:
1262 subprocess.call(['ip', 'addr', 'add', '10.174.65.207/32', 'dev',
1263 dev[0].ifname])
1264 ipaddr = dev[0].get_status_field('ip_address')
1265 if ipaddr != '10.174.65.207':
1266 raise Exception("IP address not in STATUS output")
1267 finally:
1268 subprocess.call(['ip', 'addr', 'del', '10.174.65.207/32', 'dev',
1269 dev[0].ifname])
1270
1271 def test_wpas_ctrl_rsp(dev, apdev):
1272 """wpa_supplicant ctrl_iface CTRL-RSP-"""
1273 if "FAIL" not in dev[0].request("CTRL-RSP-"):
1274 raise Exception("Request succeeded unexpectedly")
1275 if "FAIL" not in dev[0].request("CTRL-RSP-foo-"):
1276 raise Exception("Request succeeded unexpectedly")
1277 if "FAIL" not in dev[0].request("CTRL-RSP-foo-1234567"):
1278 raise Exception("Request succeeded unexpectedly")
1279 if "FAIL" not in dev[0].request("CTRL-RSP-foo-1234567:"):
1280 raise Exception("Request succeeded unexpectedly")
1281 id = dev[0].add_network()
1282 if "FAIL" not in dev[0].request("CTRL-RSP-foo-%d:" % id):
1283 raise Exception("Request succeeded unexpectedly")
1284 for req in [ "IDENTITY", "PASSWORD", "NEW_PASSWORD", "PIN", "OTP",
1285 "PASSPHRASE", "SIM" ]:
1286 if "OK" not in dev[0].request("CTRL-RSP-%s-%d:" % (req, id)):
1287 raise Exception("Request failed unexpectedly")
1288 if "OK" not in dev[0].request("CTRL-RSP-%s-%d:" % (req, id)):
1289 raise Exception("Request failed unexpectedly")
1290
1291 def test_wpas_ctrl_vendor(dev, apdev):
1292 """wpa_supplicant ctrl_iface VENDOR"""
1293 cmds = [ "foo",
1294 "1",
1295 "1 foo",
1296 "1 2foo",
1297 "1 2 qq" ]
1298 for cmd in cmds:
1299 if "FAIL" not in dev[0].request("VENDOR " + cmd):
1300 raise Exception("Invalid VENDOR command accepted: " + cmd)
1301
1302 def test_wpas_ctrl_mgmt_tx(dev, apdev):
1303 """wpa_supplicant ctrl_iface MGMT_TX"""
1304 cmds = [ "foo",
1305 "00:11:22:33:44:55 foo",
1306 "00:11:22:33:44:55 11:22:33:44:55:66",
1307 "00:11:22:33:44:55 11:22:33:44:55:66 freq=0 no_cck=0 wait_time=0 action=123",
1308 "00:11:22:33:44:55 11:22:33:44:55:66 action=12qq" ]
1309 for cmd in cmds:
1310 if "FAIL" not in dev[0].request("MGMT_TX " + cmd):
1311 raise Exception("Invalid MGMT_TX command accepted: " + cmd)
1312
1313 if "OK" not in dev[0].request("MGMT_TX_DONE"):
1314 raise Exception("MGMT_TX_DONE failed")
1315
1316 def test_wpas_ctrl_driver_event(dev, apdev):
1317 """wpa_supplicant ctrl_iface DRIVER_EVENT"""
1318 if "FAIL" not in dev[0].request("DRIVER_EVENT foo"):
1319 raise Exception("Invalid DRIVER_EVENT accepted")
1320
1321 def test_wpas_ctrl_eapol_rx(dev, apdev):
1322 """wpa_supplicant ctrl_iface EAPOL_RX"""
1323 cmds = [ "foo",
1324 "00:11:22:33:44:55 123",
1325 "00:11:22:33:44:55 12qq" ]
1326 for cmd in cmds:
1327 if "FAIL" not in dev[0].request("EAPOL_RX " + cmd):
1328 raise Exception("Invalid EAPOL_RX command accepted: " + cmd)
1329
1330 def test_wpas_ctrl_data_test(dev, apdev):
1331 """wpa_supplicant ctrl_iface DATA_TEST"""
1332 dev[0].request("DATA_TEST_CONFIG 0")
1333 if "FAIL" not in dev[0].request("DATA_TEST_TX 00:11:22:33:44:55 00:11:22:33:44:55 0"):
1334 raise Exception("DATA_TEST_TX accepted when not in test mode")
1335
1336 try:
1337 if "OK" not in dev[0].request("DATA_TEST_CONFIG 1"):
1338 raise Exception("DATA_TEST_CONFIG failed")
1339 if "OK" not in dev[0].request("DATA_TEST_CONFIG 1"):
1340 raise Exception("DATA_TEST_CONFIG failed")
1341 cmds = [ "foo",
1342 "00:11:22:33:44:55 foo",
1343 "00:11:22:33:44:55 00:11:22:33:44:55 -1",
1344 "00:11:22:33:44:55 00:11:22:33:44:55 256" ]
1345 for cmd in cmds:
1346 if "FAIL" not in dev[0].request("DATA_TEST_TX " + cmd):
1347 raise Exception("Invalid DATA_TEST_TX command accepted: " + cmd)
1348 if "OK" not in dev[0].request("DATA_TEST_TX 00:11:22:33:44:55 00:11:22:33:44:55 0"):
1349 raise Exception("DATA_TEST_TX failed")
1350 finally:
1351 dev[0].request("DATA_TEST_CONFIG 0")
1352
1353 cmds = [ "",
1354 "00",
1355 "00112233445566778899aabbccdde",
1356 "00112233445566778899aabbccdq" ]
1357 for cmd in cmds:
1358 if "FAIL" not in dev[0].request("DATA_TEST_FRAME " + cmd):
1359 raise Exception("Invalid DATA_TEST_FRAME command accepted: " + cmd)
1360
1361 if "OK" not in dev[0].request("DATA_TEST_FRAME 00112233445566778899aabbccddee"):
1362 raise Exception("DATA_TEST_FRAME failed")
1363
1364 def test_wpas_ctrl_vendor_elem(dev, apdev):
1365 """wpa_supplicant ctrl_iface VENDOR_ELEM"""
1366 if "OK" not in dev[0].request("VENDOR_ELEM_ADD 1 "):
1367 raise Exception("VENDOR_ELEM_ADD failed")
1368 cmds = [ "-1 ",
1369 "255 ",
1370 "1",
1371 "1 123",
1372 "1 12qq34" ]
1373 for cmd in cmds:
1374 if "FAIL" not in dev[0].request("VENDOR_ELEM_ADD " + cmd):
1375 raise Exception("Invalid VENDOR_ELEM_ADD command accepted: " + cmd)
1376
1377 cmds = [ "-1 ",
1378 "255 " ]
1379 for cmd in cmds:
1380 if "FAIL" not in dev[0].request("VENDOR_ELEM_GET " + cmd):
1381 raise Exception("Invalid VENDOR_ELEM_GET command accepted: " + cmd)
1382
1383 dev[0].request("VENDOR_ELEM_REMOVE 1 *")
1384 cmds = [ "-1 ",
1385 "255 ",
1386 "1",
1387 "1",
1388 "1 123",
1389 "1 12qq34",
1390 "1 12",
1391 "1 0000" ]
1392 for cmd in cmds:
1393 if "FAIL" not in dev[0].request("VENDOR_ELEM_REMOVE " + cmd):
1394 raise Exception("Invalid VENDOR_ELEM_REMOVE command accepted: " + cmd)
1395
1396 dev[0].request("VENDOR_ELEM_ADD 1 000100")
1397 if "OK" not in dev[0].request("VENDOR_ELEM_REMOVE 1 "):
1398 raise Exception("VENDOR_ELEM_REMOVE failed")
1399 cmds = [ "-1 ",
1400 "255 ",
1401 "1",
1402 "1 123",
1403 "1 12qq34",
1404 "1 12",
1405 "1 0000" ]
1406 for cmd in cmds:
1407 if "FAIL" not in dev[0].request("VENDOR_ELEM_REMOVE " + cmd):
1408 raise Exception("Invalid VENDOR_ELEM_REMOVE command accepted: " + cmd)
1409 if "OK" not in dev[0].request("VENDOR_ELEM_REMOVE 1 000100"):
1410 raise Exception("VENDOR_ELEM_REMOVE failed")
1411
1412 def test_wpas_ctrl_misc(dev, apdev):
1413 """wpa_supplicant ctrl_iface and miscellaneous commands"""
1414 if "OK" not in dev[0].request("RELOG"):
1415 raise Exception("RELOG failed")
1416 if dev[0].request("IFNAME") != dev[0].ifname:
1417 raise Exception("IFNAME returned unexpected response")
1418 if "FAIL" not in dev[0].request("REATTACH"):
1419 raise Exception("REATTACH accepted while disabled")
1420 if "OK" not in dev[2].request("RECONFIGURE"):
1421 raise Exception("RECONFIGURE failed")
1422 if "FAIL" in dev[0].request("INTERFACE_LIST"):
1423 raise Exception("INTERFACE_LIST failed")
1424 if "UNKNOWN COMMAND" not in dev[0].request("FOO"):
1425 raise Exception("Unknown command accepted")
1426
1427 if "FAIL" not in dev[0].global_request("INTERFACE_REMOVE foo"):
1428 raise Exception("Invalid INTERFACE_REMOVE accepted")
1429 if "FAIL" not in dev[0].global_request("SET foo"):
1430 raise Exception("Invalid global SET accepted")
1431
1432 def test_wpas_ctrl_dump(dev, apdev):
1433 """wpa_supplicant ctrl_iface and DUMP/GET global parameters"""
1434 vals = dev[0].get_config()
1435 logger.info("Config values from DUMP: " + str(vals))
1436 for field in vals:
1437 res = dev[0].request("GET " + field)
1438 if res == 'FAIL\n':
1439 res = "null"
1440 if res != vals[field]:
1441 print "'{}' != '{}'".format(res, vals[field])
1442 raise Exception("Mismatch in config field " + field)
1443 if "beacon_int" not in vals:
1444 raise Exception("Missing config field")
1445
1446 def test_wpas_ctrl_interface_add(dev, apdev):
1447 """wpa_supplicant INTERFACE_ADD/REMOVE with vif creation/removal"""
1448 hapd = hostapd.add_ap(apdev[0], { "ssid": "open" })
1449 dev[0].connect("open", key_mgmt="NONE", scan_freq="2412")
1450 hwsim_utils.test_connectivity(dev[0], hapd)
1451
1452 ifname = "test-" + dev[0].ifname
1453 dev[0].interface_add(ifname, create=True)
1454 wpas = WpaSupplicant(ifname=ifname)
1455 wpas.connect("open", key_mgmt="NONE", scan_freq="2412")
1456 hwsim_utils.test_connectivity(wpas, hapd)
1457 hwsim_utils.test_connectivity(dev[0], hapd)
1458 dev[0].global_request("INTERFACE_REMOVE " + ifname)
1459 hwsim_utils.test_connectivity(dev[0], hapd)
1460
1461 def test_wpas_ctrl_interface_add_sta(dev, apdev):
1462 """wpa_supplicant INTERFACE_ADD/REMOVE with STA vif creation/removal"""
1463 hapd = hostapd.add_ap(apdev[0], { "ssid": "open" })
1464 ifname = "test-" + dev[0].ifname
1465 dev[0].interface_add(ifname, create=True, if_type='sta')
1466 wpas = WpaSupplicant(ifname=ifname)
1467 wpas.connect("open", key_mgmt="NONE", scan_freq="2412")
1468 wpas.request("DISCONNECT")
1469 wpas.wait_disconnected()
1470 dev[0].global_request("INTERFACE_REMOVE " + ifname)
1471
1472 def test_wpas_ctrl_interface_add_ap(dev, apdev):
1473 """wpa_supplicant INTERFACE_ADD/REMOVE AP interface"""
1474 with HWSimRadio() as (radio, iface):
1475 wpas0 = WpaSupplicant(global_iface='/tmp/wpas-wlan5')
1476 wpas0.interface_add(iface)
1477
1478 ifname = "test-wpas-ap"
1479 wpas0.interface_add(ifname, create=True, if_type='ap')
1480 wpas = WpaSupplicant(ifname=ifname)
1481
1482 id = wpas.add_network()
1483 wpas.set_network(id, "mode", "2")
1484 wpas.set_network_quoted(id, "ssid", "wpas-ap-open")
1485 wpas.set_network(id, "key_mgmt", "NONE")
1486 wpas.set_network(id, "frequency", "2412")
1487 wpas.set_network(id, "scan_freq", "2412")
1488 wpas.select_network(id)
1489 wait_ap_ready(wpas)
1490
1491 dev[1].connect("wpas-ap-open", key_mgmt="NONE", scan_freq="2412")
1492 dev[2].connect("wpas-ap-open", key_mgmt="NONE", scan_freq="2412")
1493
1494 hwsim_utils.test_connectivity(wpas, dev[1])
1495 hwsim_utils.test_connectivity(dev[1], dev[2])
1496
1497 dev[1].request("DISCONNECT")
1498 dev[2].request("DISCONNECT")
1499 dev[1].wait_disconnected()
1500 dev[2].wait_disconnected()
1501 wpas0.global_request("INTERFACE_REMOVE " + ifname)
1502
1503 def test_wpas_ctrl_interface_add_many(dev, apdev):
1504 """wpa_supplicant INTERFACE_ADD/REMOVE with vif creation/removal (many)"""
1505 try:
1506 _test_wpas_ctrl_interface_add_many(dev, apdev)
1507 finally:
1508 for i in range(10):
1509 ifname = "test%d-" % i + dev[0].ifname
1510 dev[0].global_request("INTERFACE_REMOVE " + ifname)
1511
1512 def _test_wpas_ctrl_interface_add_many(dev, apdev):
1513 hapd = hostapd.add_ap(apdev[0], { "ssid": "open" })
1514 dev[0].connect("open", key_mgmt="NONE", scan_freq="2412")
1515 hwsim_utils.test_connectivity(dev[0], hapd)
1516 dev[0].dump_monitor()
1517
1518 l = []
1519 for i in range(10):
1520 ifname = "test%d-" % i + dev[0].ifname
1521 dev[0].interface_add(ifname, create=True)
1522 wpas = WpaSupplicant(ifname=ifname)
1523 wpas.connect("open", key_mgmt="NONE", scan_freq="2412")
1524 wpas.dump_monitor()
1525 l.append(wpas)
1526 dev[0].dump_monitor()
1527 for wpas in l:
1528 wpas.dump_monitor()
1529 hwsim_utils.test_connectivity(wpas, hapd)
1530 wpas.dump_monitor()
1531 dev[0].dump_monitor()
1532
1533 def test_wpas_ctrl_interface_add2(dev, apdev):
1534 """wpa_supplicant INTERFACE_ADD/REMOVE with vif without creation/removal"""
1535 ifname = "test-ext-" + dev[0].ifname
1536 try:
1537 _test_wpas_ctrl_interface_add2(dev, apdev, ifname)
1538 finally:
1539 subprocess.call(['iw', 'dev', ifname, 'del'])
1540
1541 def _test_wpas_ctrl_interface_add2(dev, apdev, ifname):
1542 hapd = hostapd.add_ap(apdev[0], { "ssid": "open" })
1543 dev[0].connect("open", key_mgmt="NONE", scan_freq="2412")
1544 hwsim_utils.test_connectivity(dev[0], hapd)
1545
1546 subprocess.call(['iw', 'dev', dev[0].ifname, 'interface', 'add', ifname,
1547 'type', 'station'])
1548 subprocess.call(['ip', 'link', 'set', 'dev', ifname, 'address',
1549 '02:01:00:00:02:01'])
1550 dev[0].interface_add(ifname, set_ifname=False, all_params=True)
1551 wpas = WpaSupplicant(ifname=ifname)
1552 wpas.connect("open", key_mgmt="NONE", scan_freq="2412")
1553 hwsim_utils.test_connectivity(wpas, hapd)
1554 hwsim_utils.test_connectivity(dev[0], hapd)
1555 del wpas
1556 dev[0].global_request("INTERFACE_REMOVE " + ifname)
1557 hwsim_utils.test_connectivity(dev[0], hapd)
1558
1559 def test_wpas_ctrl_wait(dev, apdev, test_params):
1560 """wpa_supplicant control interface wait for client"""
1561 logfile = os.path.join(test_params['logdir'], 'wpas_ctrl_wait.log-wpas')
1562 pidfile = os.path.join(test_params['logdir'], 'wpas_ctrl_wait.pid-wpas')
1563 conffile = os.path.join(test_params['logdir'], 'wpas_ctrl_wait.conf')
1564 with open(conffile, 'w') as f:
1565 f.write("ctrl_interface=DIR=/var/run/wpa_supplicant\n")
1566
1567 prg = os.path.join(test_params['logdir'],
1568 'alt-wpa_supplicant/wpa_supplicant/wpa_supplicant')
1569 if not os.path.exists(prg):
1570 prg = '../../wpa_supplicant/wpa_supplicant'
1571 arg = [ prg ]
1572 cmd = subprocess.Popen(arg, stdout=subprocess.PIPE)
1573 out = cmd.communicate()[0]
1574 cmd.wait()
1575 tracing = "Linux tracing" in out
1576
1577 with HWSimRadio() as (radio, iface):
1578 arg = [ prg, '-BdddW', '-P', pidfile, '-f', logfile,
1579 '-Dnl80211', '-c', conffile, '-i', iface ]
1580 if tracing:
1581 arg += [ '-T' ]
1582 logger.info("Start wpa_supplicant: " + str(arg))
1583 subprocess.call(arg)
1584 wpas = WpaSupplicant(ifname=iface)
1585 if "PONG" not in wpas.request("PING"):
1586 raise Exception("Could not PING wpa_supplicant")
1587 if not os.path.exists(pidfile):
1588 raise Exception("PID file not created")
1589 if "OK" not in wpas.request("TERMINATE"):
1590 raise Exception("Could not TERMINATE")
1591 ev = wpas.wait_event([ "CTRL-EVENT-TERMINATING" ], timeout=2)
1592 if ev is None:
1593 raise Exception("No termination event received")
1594 for i in range(20):
1595 if not os.path.exists(pidfile):
1596 break
1597 time.sleep(0.1)
1598 if os.path.exists(pidfile):
1599 raise Exception("PID file not removed")
1600
1601 def test_wpas_ctrl_oom(dev):
1602 """Various wpa_supplicant ctrl_iface OOM cases"""
1603 try:
1604 _test_wpas_ctrl_oom(dev)
1605 finally:
1606 dev[0].request("VENDOR_ELEM_REMOVE 1 *")
1607 dev[0].request("VENDOR_ELEM_REMOVE 2 *")
1608 dev[0].request("SET bssid_filter ")
1609
1610 def _test_wpas_ctrl_oom(dev):
1611 dev[0].request('VENDOR_ELEM_ADD 2 000100')
1612 tests = [ ('DRIVER_EVENT AVOID_FREQUENCIES 2412', 'FAIL',
1613 1, 'freq_range_list_parse'),
1614 ('P2P_SET disallow_freq 2412', 'FAIL',
1615 1, 'freq_range_list_parse'),
1616 ('SCAN freq=2412', 'FAIL',
1617 1, 'freq_range_list_parse'),
1618 ('INTERWORKING_SELECT freq=2412', 'FAIL',
1619 1, 'freq_range_list_parse'),
1620 ('SCAN ssid 112233', 'FAIL',
1621 1, 'wpas_ctrl_scan'),
1622 ('MGMT_TX 00:00:00:00:00:00 00:00:00:00:00:00 action=00', 'FAIL',
1623 1, 'wpas_ctrl_iface_mgmt_tx'),
1624 ('EAPOL_RX 00:00:00:00:00:00 00', 'FAIL',
1625 1, 'wpas_ctrl_iface_eapol_rx'),
1626 ('DATA_TEST_FRAME 00112233445566778899aabbccddee', 'FAIL',
1627 1, 'wpas_ctrl_iface_data_test_frame'),
1628 ('DATA_TEST_FRAME 00112233445566778899aabbccddee', 'FAIL',
1629 1, 'l2_packet_init;wpas_ctrl_iface_data_test_frame'),
1630 ('VENDOR_ELEM_ADD 1 000100', 'FAIL',
1631 1, 'wpas_ctrl_vendor_elem_add'),
1632 ('VENDOR_ELEM_ADD 2 000100', 'FAIL',
1633 2, 'wpas_ctrl_vendor_elem_add'),
1634 ('VENDOR_ELEM_REMOVE 2 000100', 'FAIL',
1635 1, 'wpas_ctrl_vendor_elem_remove'),
1636 ('SET bssid_filter 00:11:22:33:44:55', 'FAIL',
1637 1, 'set_bssid_filter'),
1638 ('SET disallow_aps bssid 00:11:22:33:44:55', 'FAIL',
1639 1, 'set_disallow_aps'),
1640 ('SET disallow_aps ssid 11', 'FAIL',
1641 1, 'set_disallow_aps'),
1642 ('SET blob foo 0011', 'FAIL',
1643 1, 'wpas_ctrl_set_blob'),
1644 ('SET blob foo 0011', 'FAIL',
1645 2, 'wpas_ctrl_set_blob'),
1646 ('SET blob foo 0011', 'FAIL',
1647 3, 'wpas_ctrl_set_blob'),
1648 ('WPS_NFC_TAG_READ 00', 'FAIL',
1649 1, 'wpa_supplicant_ctrl_iface_wps_nfc_tag_read'),
1650 ('WPS_NFC_TOKEN NDEF', 'FAIL',
1651 1, 'wpa_supplicant_ctrl_iface_wps_nfc_token'),
1652 ('WPS_NFC_TOKEN NDEF', 'FAIL',
1653 2, 'wpa_supplicant_ctrl_iface_wps_nfc_token'),
1654 ('WPS_NFC_TOKEN NDEF', 'FAIL',
1655 3, 'wpa_supplicant_ctrl_iface_wps_nfc_token'),
1656 ('WPS_NFC_TOKEN NDEF', 'FAIL',
1657 4, 'wpa_supplicant_ctrl_iface_wps_nfc_token'),
1658 ('NFC_REPORT_HANDOVER ROLE TYPE 00 00', 'FAIL',
1659 1, 'wpas_ctrl_nfc_report_handover'),
1660 ('NFC_REPORT_HANDOVER ROLE TYPE 00 00', 'FAIL',
1661 2, 'wpas_ctrl_nfc_report_handover'),
1662 ('NFC_GET_HANDOVER_REQ NDEF WPS-CR', 'FAIL',
1663 1, 'wps_build_nfc_handover_req'),
1664 ('NFC_GET_HANDOVER_REQ NDEF WPS-CR', 'FAIL',
1665 1, 'ndef_build_record'),
1666 ('NFC_GET_HANDOVER_REQ NDEF P2P-CR', None,
1667 1, 'wpas_p2p_nfc_handover'),
1668 ('NFC_GET_HANDOVER_REQ NDEF P2P-CR', None,
1669 1, 'wps_build_nfc_handover_req_p2p'),
1670 ('NFC_GET_HANDOVER_REQ NDEF P2P-CR', 'FAIL',
1671 1, 'ndef_build_record'),
1672 ('NFC_GET_HANDOVER_SEL NDEF P2P-CR-TAG', None,
1673 1, 'wpas_ctrl_nfc_get_handover_sel_p2p'),
1674 ('NFC_GET_HANDOVER_SEL NDEF P2P-CR', None,
1675 1, 'wpas_ctrl_nfc_get_handover_sel_p2p'),
1676 ('P2P_ASP_PROVISION_RESP 00:11:22:33:44:55 id=1', 'FAIL',
1677 1, 'p2p_parse_asp_provision_cmd'),
1678 ('P2P_SERV_DISC_REQ 00:11:22:33:44:55 02000001', 'FAIL',
1679 1, 'p2p_ctrl_serv_disc_req'),
1680 ('P2P_SERV_DISC_RESP 2412 00:11:22:33:44:55 1 00', 'FAIL',
1681 1, 'p2p_ctrl_serv_disc_resp'),
1682 ('P2P_SERVICE_ADD bonjour 0b5f6166706f766572746370c00c000c01 074578616d706c65c027',
1683 'FAIL',
1684 1, 'p2p_ctrl_service_add_bonjour'),
1685 ('P2P_SERVICE_ADD bonjour 0b5f6166706f766572746370c00c000c01 074578616d706c65c027',
1686 'FAIL',
1687 2, 'p2p_ctrl_service_add_bonjour'),
1688 ('P2P_SERVICE_ADD bonjour 0b5f6166706f766572746370c00c000c01 074578616d706c65c027',
1689 'FAIL',
1690 3, 'p2p_ctrl_service_add_bonjour'),
1691 ('P2P_SERVICE_DEL bonjour 0b5f6166706f766572746370c00c000c01',
1692 'FAIL',
1693 1, 'p2p_ctrl_service_del_bonjour'),
1694 ('GAS_REQUEST 00:11:22:33:44:55 00', 'FAIL',
1695 1, 'gas_request'),
1696 ('GAS_REQUEST 00:11:22:33:44:55 00 11', 'FAIL',
1697 2, 'gas_request'),
1698 ('HS20_GET_NAI_HOME_REALM_LIST 00:11:22:33:44:55 realm=example.com',
1699 'FAIL',
1700 1, 'hs20_nai_home_realm_list'),
1701 ('HS20_GET_NAI_HOME_REALM_LIST 00:11:22:33:44:55 00',
1702 'FAIL',
1703 1, 'hs20_get_nai_home_realm_list'),
1704 ('WNM_SLEEP enter tfs_req=11', 'FAIL',
1705 1, 'wpas_ctrl_iface_wnm_sleep'),
1706 ('WNM_SLEEP enter tfs_req=11', 'FAIL',
1707 2, 'wpas_ctrl_iface_wnm_sleep'),
1708 ('WNM_SLEEP enter tfs_req=11', 'FAIL',
1709 3, 'wpas_ctrl_iface_wnm_sleep'),
1710 ('WNM_SLEEP enter tfs_req=11', 'FAIL',
1711 4, 'wpas_ctrl_iface_wnm_sleep'),
1712 ('WNM_SLEEP enter tfs_req=11', 'FAIL',
1713 5, 'wpas_ctrl_iface_wnm_sleep'),
1714 ('WNM_SLEEP enter', 'FAIL',
1715 3, 'wpas_ctrl_iface_wnm_sleep'),
1716 ('VENDOR 1 1 00', 'FAIL',
1717 1, 'wpa_supplicant_vendor_cmd'),
1718 ('VENDOR 1 1 00', 'FAIL',
1719 2, 'wpa_supplicant_vendor_cmd'),
1720 ('RADIO_WORK add test', 'FAIL',
1721 1, 'wpas_ctrl_radio_work_add'),
1722 ('RADIO_WORK add test', 'FAIL',
1723 2, 'wpas_ctrl_radio_work_add'),
1724 ('AUTOSCAN periodic:1', 'FAIL',
1725 1, 'wpa_supplicant_ctrl_iface_autoscan'),
1726 ('PING', None,
1727 1, 'wpa_supplicant_ctrl_iface_process') ]
1728 tls = dev[0].request("GET tls_library")
1729 if not tls.startswith("internal"):
1730 tests.append(('NFC_GET_HANDOVER_SEL NDEF P2P-CR-TAG', 'FAIL',
1731 4, 'wpas_ctrl_nfc_get_handover_sel_p2p'))
1732 for cmd,exp,count,func in tests:
1733 with alloc_fail(dev[0], count, func):
1734 res = dev[0].request(cmd)
1735 if exp and exp not in res:
1736 raise Exception("Unexpected success for '%s' during OOM (%d:%s)" % (cmd, count, func))
1737
1738 tests = [ ('FOO', None,
1739 1, 'wpa_supplicant_global_ctrl_iface_process'),
1740 ('IFNAME=notfound PING', 'FAIL\n',
1741 1, 'wpas_global_ctrl_iface_ifname') ]
1742 for cmd,exp,count,func in tests:
1743 with alloc_fail(dev[0], count, func):
1744 res = dev[0].global_request(cmd)
1745 if exp and exp not in res:
1746 raise Exception("Unexpected success for '%s' during OOM" % cmd)
1747
1748 def test_wpas_ctrl_error(dev):
1749 """Various wpa_supplicant ctrl_iface error cases"""
1750 tests = [ ('WPS_NFC_TOKEN NDEF', 'FAIL',
1751 1, 'wpa_supplicant_ctrl_iface_wps_nfc_token'),
1752 ('WPS_NFC_TOKEN NDEF', 'FAIL',
1753 2, 'wpa_supplicant_ctrl_iface_wps_nfc_token'),
1754 ('NFC_GET_HANDOVER_REQ NDEF P2P-CR', None,
1755 1, 'wpas_p2p_nfc_handover'),
1756 ('NFC_GET_HANDOVER_REQ NDEF P2P-CR', None,
1757 1, 'wps_build_nfc_handover_req_p2p') ]
1758 for cmd,exp,count,func in tests:
1759 with fail_test(dev[0], count, func):
1760 res = dev[0].request(cmd)
1761 if exp and exp not in res:
1762 raise Exception("Unexpected success for '%s' during failure testing (%d:%s)" % (cmd, count, func))
1763
1764 def test_wpas_ctrl_socket_full(dev, apdev, test_params):
1765 """wpa_supplicant control socket and full send buffer"""
1766 if not dev[0].ping():
1767 raise Exception("Could not ping wpa_supplicant at the beginning of the test")
1768 dev[0].get_status()
1769
1770 counter = 0
1771
1772 s = socket.socket(socket.AF_UNIX, socket.SOCK_DGRAM)
1773 local = "/tmp/wpa_ctrl_test_%d-%d" % (os.getpid(), counter)
1774 counter += 1
1775 s.bind(local)
1776 s.connect("/var/run/wpa_supplicant/wlan0")
1777 for i in range(20):
1778 logger.debug("Command %d" % i)
1779 try:
1780 s.send("MIB")
1781 except Exception, e:
1782 logger.info("Could not send command %d: %s" % (i, str(e)))
1783 break
1784 # Close without receiving response
1785 time.sleep(0.01)
1786
1787 if not dev[0].ping():
1788 raise Exception("Could not ping wpa_supplicant in the middle of the test")
1789 dev[0].get_status()
1790
1791 s2 = socket.socket(socket.AF_UNIX, socket.SOCK_DGRAM)
1792 local2 = "/tmp/wpa_ctrl_test_%d-%d" % (os.getpid(), counter)
1793 counter += 1
1794 s2.bind(local2)
1795 s2.connect("/var/run/wpa_supplicant/wlan0")
1796 for i in range(10):
1797 logger.debug("Command %d [2]" % i)
1798 try:
1799 s2.send("MIB")
1800 except Exception, e:
1801 logger.info("Could not send command %d [2]: %s" % (i, str(e)))
1802 break
1803 # Close without receiving response
1804 time.sleep(0.01)
1805
1806 s.close()
1807 os.unlink(local)
1808
1809 for i in range(10):
1810 logger.debug("Command %d [3]" % i)
1811 try:
1812 s2.send("MIB")
1813 except Exception, e:
1814 logger.info("Could not send command %d [3]: %s" % (i, str(e)))
1815 break
1816 # Close without receiving response
1817 time.sleep(0.01)
1818
1819 s2.close()
1820 os.unlink(local2)
1821
1822 if not dev[0].ping():
1823 raise Exception("Could not ping wpa_supplicant in the middle of the test [2]")
1824 dev[0].get_status()
1825
1826 s = socket.socket(socket.AF_UNIX, socket.SOCK_DGRAM)
1827 local = "/tmp/wpa_ctrl_test_%d-%d" % (os.getpid(), counter)
1828 counter += 1
1829 s.bind(local)
1830 s.connect("/var/run/wpa_supplicant/wlan0")
1831 s.send("ATTACH")
1832 res = s.recv(100)
1833 if "OK" not in res:
1834 raise Exception("Could not attach a test socket")
1835
1836 for i in range(5):
1837 dev[0].scan(freq=2412)
1838
1839 s.close()
1840 os.unlink(local)
1841
1842 for i in range(5):
1843 dev[0].scan(freq=2412)
1844
1845 if not dev[0].ping():
1846 raise Exception("Could not ping wpa_supplicant at the end of the test")
1847 dev[0].get_status()
1848
1849 def test_wpas_ctrl_event_burst(dev, apdev):
1850 """wpa_supplicant control socket and event burst"""
1851 if "OK" not in dev[0].request("EVENT_TEST 1000"):
1852 raise Exception("Could not request event messages")
1853
1854 total_i = 0
1855 total_g = 0
1856 for i in range(100):
1857 (i,g) = dev[0].dump_monitor()
1858 total_i += i
1859 total_g += g
1860 logger.info("Received i=%d g=%d" % (i, g))
1861 if total_i >= 1000 and total_g >= 1000:
1862 break
1863 time.sleep(0.05)
1864
1865 if total_i < 1000:
1866 raise Exception("Some per-interface events not seen: %d" % total_i)
1867 if total_g < 1000:
1868 raise Exception("Some global events not seen: %d" % total_g)
1869
1870 if not dev[0].ping():
1871 raise Exception("Could not ping wpa_supplicant at the end of the test")
1872
1873 def test_wpas_ctrl_sched_scan_plans(dev, apdev):
1874 """wpa_supplicant sched_scan_plans parsing"""
1875 dev[0].request("SET sched_scan_plans foo")
1876 dev[0].request("SET sched_scan_plans 10:100 20:200 30")
1877 dev[0].request("SET sched_scan_plans ")
1878
1879 def test_wpas_ctrl_signal_monitor(dev, apdev):
1880 """wpa_supplicant SIGNAL_MONITOR command"""
1881 hapd = hostapd.add_ap(apdev[0], { "ssid": "open" })
1882 dev[0].connect("open", key_mgmt="NONE", scan_freq="2412")
1883 dev[1].connect("open", key_mgmt="NONE", scan_freq="2412",
1884 bgscan="simple:1:-45:2")
1885 dev[2].connect("open", key_mgmt="NONE", scan_freq="2412")
1886
1887 tests = [ " THRESHOLD=-45", " THRESHOLD=-44 HYSTERESIS=5", "" ]
1888 try:
1889 if "FAIL" in dev[2].request("SIGNAL_MONITOR THRESHOLD=-1 HYSTERESIS=5"):
1890 raise Exception("SIGNAL_MONITOR command failed")
1891 for t in tests:
1892 if "OK" not in dev[0].request("SIGNAL_MONITOR" + t):
1893 raise Exception("SIGNAL_MONITOR command failed: " + t)
1894 if "FAIL" not in dev[1].request("SIGNAL_MONITOR THRESHOLD=-44 HYSTERESIS=5"):
1895 raise Exception("SIGNAL_MONITOR command accepted while using bgscan")
1896 ev = dev[2].wait_event(["CTRL-EVENT-SIGNAL-CHANGE"], timeout=10)
1897 if ev is None:
1898 raise Exception("No signal change event seen")
1899 if "above=0" not in ev:
1900 raise Exception("Unexpected signal change event contents: " + ev)
1901 finally:
1902 dev[0].request("SIGNAL_MONITOR")
1903 dev[1].request("SIGNAL_MONITOR")
1904 dev[2].request("SIGNAL_MONITOR")
1905
1906 dev[0].request("REMOVE_NETWORK all")
1907 dev[1].request("REMOVE_NETWORK all")
1908 dev[1].wait_disconnected()