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