]>
git.ipfire.org Git - thirdparty/hostap.git/blob - tests/hwsim/test_wpas_ctrl.py
1 # wpa_supplicant control interface
2 # Copyright (c) 2014, Qualcomm Atheros, Inc.
4 # This software may be distributed under the terms of the BSD license.
5 # See README for more details.
8 logger
= logging
. getLogger ()
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
21 def test_wpas_ctrl_network ( dev
):
22 """wpa_supplicant ctrl_iface network set/get"""
23 id = dev
[ 0 ]. add_network ()
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" )
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" )
40 raise Exception ( "Unexpected SET_NETWORK/GET_NETWORK conversion for proto: " + res
)
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" )
46 raise Exception ( "Unexpected SET_NETWORK/GET_NETWORK conversion for key_mgmt: " + res
)
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" )
52 raise Exception ( "Unexpected SET_NETWORK/GET_NETWORK conversion for auth_alg: " + res
)
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" )
58 raise Exception ( "Unexpected SET_NETWORK/GET_NETWORK conversion for eap: " + res
)
60 tests
= ( "bssid foo" , "key_mgmt foo" , "key_mgmt " , "group NONE" )
62 if "FAIL" not in dev
[ 0 ]. request ( "SET_NETWORK " + str ( id ) + " " + t
):
63 raise Exception ( "Unexpected success for invalid SET_NETWORK: " + t
)
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" ),
72 ( "bssid" , "00:11:22:33:44:55" ),
73 ( "proto" , "WPA RSN OSEN" ),
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" ))
80 tests
. append (( "key_mgmt" , "WPS SAE FT-SAE OSEN" ))
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
)
87 raise Exception ( "Unexpected response for '" + field
+ "': '" + res
+ "'" )
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" )
94 raise Exception ( "Unexpected response for key_mgmt" )
96 if str ( e
). startswith ( "Unexpected" ):
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
+ "'" )
109 get_tests
= (( "foo" , None ), ( "ssid" , '"test"' ))
110 for field
, value
in get_tests
:
111 res
= dev
[ 0 ]. get_network ( id , field
)
113 raise Exception ( "Unexpected response for '" + field
+ "': '" + res
+ "'" )
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" )
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" )
135 dev
[ 0 ]. set_network ( id , "identity" , 'P"abc \n def"' )
136 if dev
[ 0 ]. get_network ( id , "identity" ) != "6162630a646566" :
137 raise Exception ( "Unexpected identity printf->hex response" )
139 if "FAIL" not in dev
[ 0 ]. request ( "SET_NETWORK " + str ( id ) + ' identity P"foo' ):
140 raise Exception ( "Unexpected success for invalid identity string" )
142 if "FAIL" not in dev
[ 0 ]. request ( "SET_NETWORK " + str ( id ) + ' identity 12x3' ):
143 raise Exception ( "Unexpected success for invalid identity string" )
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" )
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" )
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" )
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" )
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" )
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" )
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" )
169 if dev
[ 0 ]. get_network ( id , "psk_list" ):
170 raise Exception ( "Unexpected psk_list get response" )
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" )
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" );
195 if "FAIL" not in dev
[ 0 ]. request ( 'SET_NETWORK ' + str ( id ) + ' eap UNKNOWN' ):
196 raise Exception ( "Unknown EAP method accepted" )
198 if "FAIL" not in dev
[ 0 ]. request ( 'SET_NETWORK ' + str ( id ) + ' password "foo' ):
199 raise Exception ( "Invalid password accepted" )
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" )
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" )
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" )
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" )
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" )
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" )
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" ]
263 dev
[ 0 ]. set_network ( id , "bssid_blacklist" , val
)
264 res
= dev
[ 0 ]. get_network ( id , "bssid_blacklist" )
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" )
270 raise Exception ( "Unexpected bssid_whitelist value: %s != %s " % ( res
, val
))
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" ]
278 if "FAIL" not in dev
[ 0 ]. request ( "SET_NETWORK %d bssid_blacklist %s " % ( id , val
)):
279 raise Exception ( "Invalid bssid_blacklist value accepted" )
281 def test_wpas_ctrl_network_oom ( dev
):
282 """wpa_supplicant ctrl_iface network OOM in string parsing"""
283 id = dev
[ 0 ]. add_network ()
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" )
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" )
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 )
309 def test_wpas_ctrl_dup_network ( dev
, apdev
):
310 """wpa_supplicant ctrl_iface DUP_NETWORK"""
312 passphrase
= 'qwertyuiop'
313 params
= hostapd
. wpa2_params ( ssid
= ssid
, passphrase
= passphrase
)
314 hostapd
. add_ap ( apdev
[ 0 ], params
)
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
))
323 raise Exception ( "DUP_NETWORK failed" )
324 dev
[ 0 ]. connect_network ( id )
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" )
342 def test_wpas_ctrl_dup_network_global ( dev
, apdev
):
343 """wpa_supplicant ctrl_iface DUP_NETWORK (global)"""
345 passphrase
= 'qwertyuiop'
346 params
= hostapd
. wpa2_params ( ssid
= ssid
, passphrase
= passphrase
)
347 hostapd
. add_ap ( apdev
[ 0 ], params
)
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
))
356 raise Exception ( "DUP_NETWORK failed" )
357 dev
[ 0 ]. connect_network ( id )
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" )
375 ev
= dev
. wait_event ([ "CRED-ADDED" ])
377 raise Exception ( "Missing CRED-ADDED event" )
378 if " " + str ( id ) not in ev
:
379 raise Exception ( "CRED-ADDED event without matching id" )
382 def set_cred ( dev
, id , field
, value
):
383 dev
. set_cred ( id , field
, value
)
384 ev
= dev
. wait_event ([ "CRED-MODIFIED" ])
386 raise Exception ( "Missing CRED-MODIFIED event" )
387 if " " + str ( id ) + " " not in ev
:
388 raise Exception ( "CRED-MODIFIED event without matching id" )
390 raise Exception ( "CRED-MODIFIED event without matching field" )
392 def set_cred_quoted ( dev
, id , field
, value
):
393 dev
. set_cred_quoted ( id , field
, value
)
394 ev
= dev
. wait_event ([ "CRED-MODIFIED" ])
396 raise Exception ( "Missing CRED-MODIFIED event" )
397 if " " + str ( id ) + " " not in ev
:
398 raise Exception ( "CRED-MODIFIED event without matching id" )
400 raise Exception ( "CRED-MODIFIED event without matching field" )
402 def remove_cred ( dev
, id ):
404 ev
= dev
. wait_event ([ "CRED-REMOVED" ])
406 raise Exception ( "Missing CRED-REMOVED event" )
407 if " " + str ( id ) not in ev
:
408 raise Exception ( "CRED-REMOVED event without matching id" )
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" )
436 if "FAIL" not in dev
[ 0 ]. request ( "SET_CRED " + str ( id ) + " eap FOO" ):
437 raise Exception ( "Unexpected success on unknown EAP method" )
439 if "FAIL" not in dev
[ 0 ]. request ( "SET_CRED " + str ( id ) + " username 12xa" ):
440 raise Exception ( "Unexpected success on invalid string" )
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" )
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" )
450 if "FAIL" not in dev
[ 0 ]. request ( "SET_CRED " + str ( id ) + " foo 4142" ):
451 raise Exception ( "Unexpected success on unknown field" )
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"' ]
460 if "FAIL" not in dev
[ 0 ]. request ( "SET_CRED " + str ( id ) + " " + t
):
461 raise Exception ( "Unexpected success on invalid SET_CRED value: " + t
)
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)" )
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)" )
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 \n example.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 \n foo" ),
501 ( "roaming_partner" , "example.com,0,4,*" , True ),
502 ( "roaming_partner" , "example.org,1,2,US" , True ,
503 "example.com,0,4,* \n example.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 \n 17:500" ),
514 ( "req_conn_capab" , "50" , False , "6:22,80,443 \n 17:500 \n 50" ),
515 ( "ocsp" , "1" , False ) ]
518 set_cred_quoted ( dev
[ 0 ], id , v
[ 0 ], v
[ 1 ])
520 set_cred ( dev
[ 0 ], id , v
[ 0 ], v
[ 1 ])
521 val
= dev
[ 0 ]. get_cred ( id , v
[ 0 ])
527 raise Exception ( "Unexpected GET_CRED value for {}: {} != {}" . format ( v
[ 0 ], val
, expect
))
528 creds
= dev
[ 0 ]. request ( "LIST_CREDS" ). splitlines ()
530 raise Exception ( "Unexpected LIST_CREDS result(3)" )
531 if creds
[ 1 ] != "0 \t example.com \t user@example.com \t example.com \t 310026-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)" )
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" )
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" )
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" )
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" )
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" )
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" )
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" )
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" )
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
)
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
)
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" )
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" )
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" )
682 if "FAIL" not in dev
[ 0 ]. request ( "WPS_ER_PIN any" ):
683 raise Exception ( "Unexpected success on invalid WPS_ER_PIN" )
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" )
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" )
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" )
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" )
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" )
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" )
725 if "FAIL" not in dev
[ 0 ]. request ( "SET serial_number 0123456789abcdef0123456789abcdef0" ):
726 raise Exception ( "Too long string accepted" )
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" )
736 def test_wpas_ctrl_set_wps_params ( dev
):
737 """wpa_supplicant ctrl_iface SET config_methods"""
739 _test_wpas_ctrl_set_wps_params ( dev
)
741 dev
[ 2 ]. request ( "SET config_methods " )
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" ]
749 if "OK" not in dev
[ 2 ]. request ( "SET " + t
):
750 raise Exception ( "SET failed for: " + t
)
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" ,
762 if "FAIL" not in dev
[ 2 ]. request ( "SET " + t
):
763 raise Exception ( "SET succeeded for: " + t
)
765 def test_wpas_ctrl_level ( dev
):
766 """wpa_supplicant ctrl_iface LEVEL"""
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 )
775 raise Exception ( "No debug message received" )
776 dev
[ 2 ]. wait_event ([ "CTRL-EVENT-SCAN-RESULTS" ], timeout
= 5 )
778 dev
[ 2 ]. mon
. request ( "LEVEL 3" )
780 def test_wpas_ctrl_bssid_filter ( dev
, apdev
):
781 """wpa_supplicant bssid_filter"""
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" )
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" )
815 dev
[ 2 ]. request ( "SET bssid_filter " )
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
)
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" )
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" )
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 )
855 raise Exception ( "Unexpected reassociation" )
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" )
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" )
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" )
892 def test_wpas_ctrl_set ( dev
):
893 """wpa_supplicant ctrl_iface SET"""
899 "dot11RSNAConfigPMKLifetime 0" ,
900 "dot11RSNAConfigPMKReauthThreshold 101" ,
901 "dot11RSNAConfigSATimeout 0" ,
902 "wps_version_number -1" ,
903 "wps_version_number 256" ,
907 if "FAIL" not in dev
[ 0 ]. request ( "SET " + val
):
908 raise Exception ( "Unexpected SET success for " + val
)
910 vals
= [ "EAPOL::heldPeriod 60" ,
911 "EAPOL::authPeriod 30" ,
912 "EAPOL::startPeriod 30" ,
914 "dot11RSNAConfigSATimeout 60" ,
921 if "OK" not in dev
[ 0 ]. request ( "SET " + val
):
922 raise Exception ( "Unexpected SET failure for " + val
)
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" )
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
))
941 res
= dev
[ 0 ]. get_capability ( "pairwise" )
942 if "CCMP" not in res
:
943 raise Exception ( "Unexpected GET_CAPABILITY pairwise response: " + str ( res
))
945 res
= dev
[ 0 ]. get_capability ( "group" )
946 if "CCMP" not in res
:
947 raise Exception ( "Unexpected GET_CAPABILITY group response: " + str ( res
))
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
))
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
))
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
))
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
))
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
))
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
))
973 res
= dev
[ 0 ]. get_capability ( "tdls" )
974 if "EXTERNAL" not in res
[ 0 ]:
975 raise Exception ( "Unexpected GET_CAPABILITY tdls response: " + str ( res
))
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
))
981 if dev
[ 0 ]. get_capability ( "foo" ) is not None :
982 raise Exception ( "Unexpected GET_CAPABILITY foo response: " + str ( res
))
984 def test_wpas_ctrl_nfc_report_handover ( dev
):
985 """wpa_supplicant ctrl_iface NFC_REPORT_HANDOVER"""
996 if "FAIL" not in dev
[ 0 ]. request ( "NFC_REPORT_HANDOVER " + v
):
997 raise Exception ( "Unexpected NFC_REPORT_HANDOVER success for " + v
)
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" ]
1004 if "FAIL" not in dev
[ 0 ]. request ( "WPS_NFC_TAG_READ " + v
):
1005 raise Exception ( "Unexpected WPS_NFC_TAG_READ success for " + v
)
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" ]
1011 if "FAIL" not in dev
[ 0 ]. request ( "NFC_GET_HANDOVER_REQ " + v
):
1012 raise Exception ( "Unexpected NFC_GET_HANDOVER_REQ success for " + v
)
1014 vals
= [ "NDEF WPS" , "NDEF P2P-CR" , "WPS P2P-CR" ]
1016 if "FAIL" in dev
[ 0 ]. request ( "NFC_GET_HANDOVER_REQ " + v
):
1017 raise Exception ( "Unexpected NFC_GET_HANDOVER_REQ failure for " + v
)
1019 vals
= [ "FOO" , "FOO BAR" , "WPS WPS" , "WPS WPS-CR" , "WPS FOO" , "NDEF P2P" ,
1020 "NDEF WPS" , "NDEF WPS uuid" ]
1022 if "FAIL" not in dev
[ 0 ]. request ( "NFC_GET_HANDOVER_SEL " + v
):
1023 raise Exception ( "Unexpected NFC_GET_HANDOVER_SEL success for " + v
)
1025 vals
= [ "NDEF P2P-CR" , "WPS P2P-CR" , "NDEF P2P-CR-TAG" ,
1028 if "FAIL" in dev
[ 0 ]. request ( "NFC_GET_HANDOVER_SEL " + v
):
1029 raise Exception ( "Unexpected NFC_GET_HANDOVER_SEL failure for " + v
)
1031 def get_blacklist ( dev
):
1032 return dev
. request ( "BLACKLIST" ). splitlines ()
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 ])
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
))
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" )
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" )
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
)
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
)
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
)
1092 if "FAIL" not in dev
[ 2 ]. request ( "LOG_LEVEL FOO" ):
1093 raise Exception ( "Invalid LOG_LEVEL accepted" )
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
)
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
)
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
)
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 )
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 )
1138 def test_wpas_ctrl_country ( dev
, apdev
):
1139 """wpa_supplicant SET/GET country code"""
1141 # work around issues with possible pending regdom event from the end of
1142 # the previous test case
1144 dev
[ 0 ]. dump_monitor ()
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 )
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 )
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
)
1166 subprocess
. call ([ 'iw' , 'reg' , 'set' , '00' ])
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" )
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 )
1183 raise Exception ( "Scan not completed" )
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" )
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" )
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" )
1222 # driver_nl80211.c does not support interface list, so do not fail because
1224 logger
. debug ( wpas
. global_request ( "INTERFACE_LIST" ))
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" )
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" )
1259 def test_wpas_ctrl_ipaddr ( dev
, apdev
):
1260 """wpa_supplicant IP address in STATUS"""
1262 subprocess
. call ([ 'ip' , 'addr' , 'add' , '10.174.65.207/32' , 'dev' ,
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" )
1268 subprocess
. call ([ 'ip' , 'addr' , 'del' , '10.174.65.207/32' , 'dev' ,
1271 def test_wpas_ctrl_neighbor_rep_req ( dev
, apdev
):
1272 """wpa_supplicant ctrl_iface NEIGHBOR_REP_REQUEST"""
1273 params
= { "ssid" : "test" }
1274 hostapd
. add_ap ( apdev
[ 0 ], params
)
1275 params
= { "ssid" : "test2" , "radio_measurements" : "1" }
1276 hostapd
. add_ap ( apdev
[ 1 ], params
)
1278 dev
[ 0 ]. connect ( "test" , key_mgmt
= "NONE" , scan_freq
= "2412" )
1279 if "FAIL" not in dev
[ 0 ]. request ( "NEIGHBOR_REP_REQUEST" ):
1280 raise Exception ( "Request succeeded unexpectedly" )
1281 if "FAIL" not in dev
[ 0 ]. request ( "NEIGHBOR_REP_REQUEST ssid=abcdef" ):
1282 raise Exception ( "Request succeeded unexpectedly" )
1283 dev
[ 0 ]. request ( "DISCONNECT" )
1285 rrm
= int ( dev
[ 0 ]. get_driver_status_field ( "capa.rrm_flags" ), 16 )
1286 if rrm
& 0x5 != 0x5 :
1287 logger
. info ( "Driver does not support required RRM capabilities - skip rest of the test case" )
1290 dev
[ 0 ]. connect ( "test2" , key_mgmt
= "NONE" , scan_freq
= "2412" )
1292 # These requests are expected to get sent properly, but since hostapd does
1293 # not yet support processing of the request, these are expected to fail.
1295 if "OK" not in dev
[ 0 ]. request ( "NEIGHBOR_REP_REQUEST" ):
1296 raise Exception ( "Request failed" )
1297 ev
= dev
[ 0 ]. wait_event ([ "RRM-NEIGHBOR-REP-RECEIVED" ,
1298 "RRM-NEIGHBOR-REP-REQUEST-FAILED" ], timeout
= 10 )
1300 raise Exception ( "RRM report result not indicated" )
1301 logger
. info ( "RRM result: " + ev
)
1303 if "OK" not in dev
[ 0 ]. request ( "NEIGHBOR_REP_REQUEST ssid=abcdef" ):
1304 raise Exception ( "Request failed" )
1305 ev
= dev
[ 0 ]. wait_event ([ "RRM-NEIGHBOR-REP-RECEIVED" ,
1306 "RRM-NEIGHBOR-REP-REQUEST-FAILED" ], timeout
= 10 )
1308 raise Exception ( "RRM report result not indicated" )
1309 logger
. info ( "RRM result: " + ev
)
1311 def test_wpas_ctrl_rsp ( dev
, apdev
):
1312 """wpa_supplicant ctrl_iface CTRL-RSP-"""
1313 if "FAIL" not in dev
[ 0 ]. request ( "CTRL-RSP-" ):
1314 raise Exception ( "Request succeeded unexpectedly" )
1315 if "FAIL" not in dev
[ 0 ]. request ( "CTRL-RSP-foo-" ):
1316 raise Exception ( "Request succeeded unexpectedly" )
1317 if "FAIL" not in dev
[ 0 ]. request ( "CTRL-RSP-foo-1234567" ):
1318 raise Exception ( "Request succeeded unexpectedly" )
1319 if "FAIL" not in dev
[ 0 ]. request ( "CTRL-RSP-foo-1234567:" ):
1320 raise Exception ( "Request succeeded unexpectedly" )
1321 id = dev
[ 0 ]. add_network ()
1322 if "FAIL" not in dev
[ 0 ]. request ( "CTRL-RSP-foo- %d :" % id ):
1323 raise Exception ( "Request succeeded unexpectedly" )
1324 for req
in [ "IDENTITY" , "PASSWORD" , "NEW_PASSWORD" , "PIN" , "OTP" ,
1325 "PASSPHRASE" , "SIM" ]:
1326 if "OK" not in dev
[ 0 ]. request ( "CTRL-RSP- %s-%d :" % ( req
, id )):
1327 raise Exception ( "Request failed unexpectedly" )
1328 if "OK" not in dev
[ 0 ]. request ( "CTRL-RSP- %s-%d :" % ( req
, id )):
1329 raise Exception ( "Request failed unexpectedly" )
1331 def test_wpas_ctrl_vendor ( dev
, apdev
):
1332 """wpa_supplicant ctrl_iface VENDOR"""
1339 if "FAIL" not in dev
[ 0 ]. request ( "VENDOR " + cmd
):
1340 raise Exception ( "Invalid VENDOR command accepted: " + cmd
)
1342 def test_wpas_ctrl_mgmt_tx ( dev
, apdev
):
1343 """wpa_supplicant ctrl_iface MGMT_TX"""
1345 "00:11:22:33:44:55 foo" ,
1346 "00:11:22:33:44:55 11:22:33:44:55:66" ,
1347 "00:11:22:33:44:55 11:22:33:44:55:66 freq=0 no_cck=0 wait_time=0 action=123" ,
1348 "00:11:22:33:44:55 11:22:33:44:55:66 action=12qq" ]
1350 if "FAIL" not in dev
[ 0 ]. request ( "MGMT_TX " + cmd
):
1351 raise Exception ( "Invalid MGMT_TX command accepted: " + cmd
)
1353 if "OK" not in dev
[ 0 ]. request ( "MGMT_TX_DONE" ):
1354 raise Exception ( "MGMT_TX_DONE failed" )
1356 def test_wpas_ctrl_driver_event ( dev
, apdev
):
1357 """wpa_supplicant ctrl_iface DRIVER_EVENT"""
1358 if "FAIL" not in dev
[ 0 ]. request ( "DRIVER_EVENT foo" ):
1359 raise Exception ( "Invalid DRIVER_EVENT accepted" )
1361 def test_wpas_ctrl_eapol_rx ( dev
, apdev
):
1362 """wpa_supplicant ctrl_iface EAPOL_RX"""
1364 "00:11:22:33:44:55 123" ,
1365 "00:11:22:33:44:55 12qq" ]
1367 if "FAIL" not in dev
[ 0 ]. request ( "EAPOL_RX " + cmd
):
1368 raise Exception ( "Invalid EAPOL_RX command accepted: " + cmd
)
1370 def test_wpas_ctrl_data_test ( dev
, apdev
):
1371 """wpa_supplicant ctrl_iface DATA_TEST"""
1372 dev
[ 0 ]. request ( "DATA_TEST_CONFIG 0" )
1373 if "FAIL" not in dev
[ 0 ]. request ( "DATA_TEST_TX 00:11:22:33:44:55 00:11:22:33:44:55 0" ):
1374 raise Exception ( "DATA_TEST_TX accepted when not in test mode" )
1377 if "OK" not in dev
[ 0 ]. request ( "DATA_TEST_CONFIG 1" ):
1378 raise Exception ( "DATA_TEST_CONFIG failed" )
1379 if "OK" not in dev
[ 0 ]. request ( "DATA_TEST_CONFIG 1" ):
1380 raise Exception ( "DATA_TEST_CONFIG failed" )
1382 "00:11:22:33:44:55 foo" ,
1383 "00:11:22:33:44:55 00:11:22:33:44:55 -1" ,
1384 "00:11:22:33:44:55 00:11:22:33:44:55 256" ]
1386 if "FAIL" not in dev
[ 0 ]. request ( "DATA_TEST_TX " + cmd
):
1387 raise Exception ( "Invalid DATA_TEST_TX command accepted: " + cmd
)
1388 if "OK" not in dev
[ 0 ]. request ( "DATA_TEST_TX 00:11:22:33:44:55 00:11:22:33:44:55 0" ):
1389 raise Exception ( "DATA_TEST_TX failed" )
1391 dev
[ 0 ]. request ( "DATA_TEST_CONFIG 0" )
1395 "00112233445566778899aabbccdde" ,
1396 "00112233445566778899aabbccdq" ]
1398 if "FAIL" not in dev
[ 0 ]. request ( "DATA_TEST_FRAME " + cmd
):
1399 raise Exception ( "Invalid DATA_TEST_FRAME command accepted: " + cmd
)
1401 if "OK" not in dev
[ 0 ]. request ( "DATA_TEST_FRAME 00112233445566778899aabbccddee" ):
1402 raise Exception ( "DATA_TEST_FRAME failed" )
1404 def test_wpas_ctrl_vendor_elem ( dev
, apdev
):
1405 """wpa_supplicant ctrl_iface VENDOR_ELEM"""
1406 if "OK" not in dev
[ 0 ]. request ( "VENDOR_ELEM_ADD 1 " ):
1407 raise Exception ( "VENDOR_ELEM_ADD failed" )
1414 if "FAIL" not in dev
[ 0 ]. request ( "VENDOR_ELEM_ADD " + cmd
):
1415 raise Exception ( "Invalid VENDOR_ELEM_ADD command accepted: " + cmd
)
1420 if "FAIL" not in dev
[ 0 ]. request ( "VENDOR_ELEM_GET " + cmd
):
1421 raise Exception ( "Invalid VENDOR_ELEM_GET command accepted: " + cmd
)
1423 dev
[ 0 ]. request ( "VENDOR_ELEM_REMOVE 1 *" )
1433 if "FAIL" not in dev
[ 0 ]. request ( "VENDOR_ELEM_REMOVE " + cmd
):
1434 raise Exception ( "Invalid VENDOR_ELEM_REMOVE command accepted: " + cmd
)
1436 dev
[ 0 ]. request ( "VENDOR_ELEM_ADD 1 000100" )
1437 if "OK" not in dev
[ 0 ]. request ( "VENDOR_ELEM_REMOVE 1 " ):
1438 raise Exception ( "VENDOR_ELEM_REMOVE failed" )
1447 if "FAIL" not in dev
[ 0 ]. request ( "VENDOR_ELEM_REMOVE " + cmd
):
1448 raise Exception ( "Invalid VENDOR_ELEM_REMOVE command accepted: " + cmd
)
1449 if "OK" not in dev
[ 0 ]. request ( "VENDOR_ELEM_REMOVE 1 000100" ):
1450 raise Exception ( "VENDOR_ELEM_REMOVE failed" )
1452 def test_wpas_ctrl_misc ( dev
, apdev
):
1453 """wpa_supplicant ctrl_iface and miscellaneous commands"""
1454 if "OK" not in dev
[ 0 ]. request ( "RELOG" ):
1455 raise Exception ( "RELOG failed" )
1456 if dev
[ 0 ]. request ( "IFNAME" ) != dev
[ 0 ]. ifname
:
1457 raise Exception ( "IFNAME returned unexpected response" )
1458 if "FAIL" not in dev
[ 0 ]. request ( "REATTACH" ):
1459 raise Exception ( "REATTACH accepted while disabled" )
1460 if "OK" not in dev
[ 2 ]. request ( "RECONFIGURE" ):
1461 raise Exception ( "RECONFIGURE failed" )
1462 if "FAIL" in dev
[ 0 ]. request ( "INTERFACE_LIST" ):
1463 raise Exception ( "INTERFACE_LIST failed" )
1464 if "UNKNOWN COMMAND" not in dev
[ 0 ]. request ( "FOO" ):
1465 raise Exception ( "Unknown command accepted" )
1467 if "FAIL" not in dev
[ 0 ]. global_request ( "INTERFACE_REMOVE foo" ):
1468 raise Exception ( "Invalid INTERFACE_REMOVE accepted" )
1469 if "FAIL" not in dev
[ 0 ]. global_request ( "SET foo" ):
1470 raise Exception ( "Invalid global SET accepted" )
1472 def test_wpas_ctrl_dump ( dev
, apdev
):
1473 """wpa_supplicant ctrl_iface and DUMP/GET global parameters"""
1474 vals
= dev
[ 0 ]. get_config ()
1475 logger
. info ( "Config values from DUMP: " + str ( vals
))
1477 res
= dev
[ 0 ]. request ( "GET " + field
)
1480 if res
!= vals
[ field
]:
1481 print "'{}' != '{}'" . format ( res
, vals
[ field
])
1482 raise Exception ( "Mismatch in config field " + field
)
1483 if "beacon_int" not in vals
:
1484 raise Exception ( "Missing config field" )
1486 def test_wpas_ctrl_interface_add ( dev
, apdev
):
1487 """wpa_supplicant INTERFACE_ADD/REMOVE with vif creation/removal"""
1488 hapd
= hostapd
. add_ap ( apdev
[ 0 ], { "ssid" : "open" })
1489 dev
[ 0 ]. connect ( "open" , key_mgmt
= "NONE" , scan_freq
= "2412" )
1490 hwsim_utils
. test_connectivity ( dev
[ 0 ], hapd
)
1492 ifname
= "test-" + dev
[ 0 ]. ifname
1493 dev
[ 0 ]. interface_add ( ifname
, create
= True )
1494 wpas
= WpaSupplicant ( ifname
= ifname
)
1495 wpas
. connect ( "open" , key_mgmt
= "NONE" , scan_freq
= "2412" )
1496 hwsim_utils
. test_connectivity ( wpas
, hapd
)
1497 hwsim_utils
. test_connectivity ( dev
[ 0 ], hapd
)
1498 dev
[ 0 ]. global_request ( "INTERFACE_REMOVE " + ifname
)
1499 hwsim_utils
. test_connectivity ( dev
[ 0 ], hapd
)
1501 def test_wpas_ctrl_interface_add_sta ( dev
, apdev
):
1502 """wpa_supplicant INTERFACE_ADD/REMOVE with STA vif creation/removal"""
1503 hapd
= hostapd
. add_ap ( apdev
[ 0 ], { "ssid" : "open" })
1504 ifname
= "test-" + dev
[ 0 ]. ifname
1505 dev
[ 0 ]. interface_add ( ifname
, create
= True , if_type
= 'sta' )
1506 wpas
= WpaSupplicant ( ifname
= ifname
)
1507 wpas
. connect ( "open" , key_mgmt
= "NONE" , scan_freq
= "2412" )
1508 wpas
. request ( "DISCONNECT" )
1509 wpas
. wait_disconnected ()
1510 dev
[ 0 ]. global_request ( "INTERFACE_REMOVE " + ifname
)
1512 def test_wpas_ctrl_interface_add_ap ( dev
, apdev
):
1513 """wpa_supplicant INTERFACE_ADD/REMOVE AP interface"""
1514 with
HWSimRadio () as ( radio
, iface
):
1515 wpas0
= WpaSupplicant ( global_iface
= '/tmp/wpas-wlan5' )
1516 wpas0
. interface_add ( iface
)
1518 ifname
= "test-wpas-ap"
1519 wpas0
. interface_add ( ifname
, create
= True , if_type
= 'ap' )
1520 wpas
= WpaSupplicant ( ifname
= ifname
)
1522 id = wpas
. add_network ()
1523 wpas
. set_network ( id , "mode" , "2" )
1524 wpas
. set_network_quoted ( id , "ssid" , "wpas-ap-open" )
1525 wpas
. set_network ( id , "key_mgmt" , "NONE" )
1526 wpas
. set_network ( id , "frequency" , "2412" )
1527 wpas
. set_network ( id , "scan_freq" , "2412" )
1528 wpas
. select_network ( id )
1531 dev
[ 1 ]. connect ( "wpas-ap-open" , key_mgmt
= "NONE" , scan_freq
= "2412" )
1532 dev
[ 2 ]. connect ( "wpas-ap-open" , key_mgmt
= "NONE" , scan_freq
= "2412" )
1534 hwsim_utils
. test_connectivity ( wpas
, dev
[ 1 ])
1535 hwsim_utils
. test_connectivity ( dev
[ 1 ], dev
[ 2 ])
1537 dev
[ 1 ]. request ( "DISCONNECT" )
1538 dev
[ 2 ]. request ( "DISCONNECT" )
1539 dev
[ 1 ]. wait_disconnected ()
1540 dev
[ 2 ]. wait_disconnected ()
1541 wpas0
. global_request ( "INTERFACE_REMOVE " + ifname
)
1543 def test_wpas_ctrl_interface_add_many ( dev
, apdev
):
1544 """wpa_supplicant INTERFACE_ADD/REMOVE with vif creation/removal (many)"""
1546 _test_wpas_ctrl_interface_add_many ( dev
, apdev
)
1549 ifname
= "test %d- " % i
+ dev
[ 0 ]. ifname
1550 dev
[ 0 ]. global_request ( "INTERFACE_REMOVE " + ifname
)
1552 def _test_wpas_ctrl_interface_add_many ( dev
, apdev
):
1553 hapd
= hostapd
. add_ap ( apdev
[ 0 ], { "ssid" : "open" })
1554 dev
[ 0 ]. connect ( "open" , key_mgmt
= "NONE" , scan_freq
= "2412" )
1555 hwsim_utils
. test_connectivity ( dev
[ 0 ], hapd
)
1556 dev
[ 0 ]. dump_monitor ()
1560 ifname
= "test %d- " % i
+ dev
[ 0 ]. ifname
1561 dev
[ 0 ]. interface_add ( ifname
, create
= True )
1562 wpas
= WpaSupplicant ( ifname
= ifname
)
1563 wpas
. connect ( "open" , key_mgmt
= "NONE" , scan_freq
= "2412" )
1566 dev
[ 0 ]. dump_monitor ()
1569 hwsim_utils
. test_connectivity ( wpas
, hapd
)
1571 dev
[ 0 ]. dump_monitor ()
1573 def test_wpas_ctrl_interface_add2 ( dev
, apdev
):
1574 """wpa_supplicant INTERFACE_ADD/REMOVE with vif without creation/removal"""
1575 ifname
= "test-ext-" + dev
[ 0 ]. ifname
1577 _test_wpas_ctrl_interface_add2 ( dev
, apdev
, ifname
)
1579 subprocess
. call ([ 'iw' , 'dev' , ifname
, 'del' ])
1581 def _test_wpas_ctrl_interface_add2 ( dev
, apdev
, ifname
):
1582 hapd
= hostapd
. add_ap ( apdev
[ 0 ], { "ssid" : "open" })
1583 dev
[ 0 ]. connect ( "open" , key_mgmt
= "NONE" , scan_freq
= "2412" )
1584 hwsim_utils
. test_connectivity ( dev
[ 0 ], hapd
)
1586 subprocess
. call ([ 'iw' , 'dev' , dev
[ 0 ]. ifname
, 'interface' , 'add' , ifname
,
1588 subprocess
. call ([ 'ip' , 'link' , 'set' , 'dev' , ifname
, 'address' ,
1589 '02:01:00:00:02:01' ])
1590 dev
[ 0 ]. interface_add ( ifname
, set_ifname
= False , all_params
= True )
1591 wpas
= WpaSupplicant ( ifname
= ifname
)
1592 wpas
. connect ( "open" , key_mgmt
= "NONE" , scan_freq
= "2412" )
1593 hwsim_utils
. test_connectivity ( wpas
, hapd
)
1594 hwsim_utils
. test_connectivity ( dev
[ 0 ], hapd
)
1596 dev
[ 0 ]. global_request ( "INTERFACE_REMOVE " + ifname
)
1597 hwsim_utils
. test_connectivity ( dev
[ 0 ], hapd
)
1599 def test_wpas_ctrl_wait ( dev
, apdev
, test_params
):
1600 """wpa_supplicant control interface wait for client"""
1601 logfile
= os
. path
. join ( test_params
[ 'logdir' ], 'wpas_ctrl_wait.log-wpas' )
1602 pidfile
= os
. path
. join ( test_params
[ 'logdir' ], 'wpas_ctrl_wait.pid-wpas' )
1603 conffile
= os
. path
. join ( test_params
[ 'logdir' ], 'wpas_ctrl_wait.conf' )
1604 with
open ( conffile
, 'w' ) as f
:
1605 f
. write ( "ctrl_interface=DIR=/var/run/wpa_supplicant \n " )
1607 prg
= os
. path
. join ( test_params
[ 'logdir' ],
1608 'alt-wpa_supplicant/wpa_supplicant/wpa_supplicant' )
1609 if not os
. path
. exists ( prg
):
1610 prg
= '../../wpa_supplicant/wpa_supplicant'
1612 cmd
= subprocess
. Popen ( arg
, stdout
= subprocess
. PIPE
)
1613 out
= cmd
. communicate ()[ 0 ]
1615 tracing
= "Linux tracing" in out
1617 with
HWSimRadio () as ( radio
, iface
):
1618 arg
= [ prg
, '-BdddW' , '-P' , pidfile
, '-f' , logfile
,
1619 '-Dnl80211' , '-c' , conffile
, '-i' , iface
]
1622 logger
. info ( "Start wpa_supplicant: " + str ( arg
))
1623 subprocess
. call ( arg
)
1624 wpas
= WpaSupplicant ( ifname
= iface
)
1625 if "PONG" not in wpas
. request ( "PING" ):
1626 raise Exception ( "Could not PING wpa_supplicant" )
1627 if not os
. path
. exists ( pidfile
):
1628 raise Exception ( "PID file not created" )
1629 if "OK" not in wpas
. request ( "TERMINATE" ):
1630 raise Exception ( "Could not TERMINATE" )
1631 ev
= wpas
. wait_event ([ "CTRL-EVENT-TERMINATING" ], timeout
= 2 )
1633 raise Exception ( "No termination event received" )
1635 if not os
. path
. exists ( pidfile
):
1638 if os
. path
. exists ( pidfile
):
1639 raise Exception ( "PID file not removed" )
1641 def test_wpas_ctrl_oom ( dev
):
1642 """Various wpa_supplicant ctrl_iface OOM cases"""
1644 _test_wpas_ctrl_oom ( dev
)
1646 dev
[ 0 ]. request ( "VENDOR_ELEM_REMOVE 1 *" )
1647 dev
[ 0 ]. request ( "VENDOR_ELEM_REMOVE 2 *" )
1648 dev
[ 0 ]. request ( "SET bssid_filter " )
1650 def _test_wpas_ctrl_oom ( dev
):
1651 dev
[ 0 ]. request ( 'VENDOR_ELEM_ADD 2 000100' )
1652 tests
= [ ( 'DRIVER_EVENT AVOID_FREQUENCIES 2412' , 'FAIL' ,
1653 1 , 'freq_range_list_parse' ),
1654 ( 'P2P_SET disallow_freq 2412' , 'FAIL' ,
1655 1 , 'freq_range_list_parse' ),
1656 ( 'SCAN freq=2412' , 'FAIL' ,
1657 1 , 'freq_range_list_parse' ),
1658 ( 'INTERWORKING_SELECT freq=2412' , 'FAIL' ,
1659 1 , 'freq_range_list_parse' ),
1660 ( 'SCAN ssid 112233' , 'FAIL' ,
1661 1 , 'wpas_ctrl_scan' ),
1662 ( 'MGMT_TX 00:00:00:00:00:00 00:00:00:00:00:00 action=00' , 'FAIL' ,
1663 1 , 'wpas_ctrl_iface_mgmt_tx' ),
1664 ( 'EAPOL_RX 00:00:00:00:00:00 00' , 'FAIL' ,
1665 1 , 'wpas_ctrl_iface_eapol_rx' ),
1666 ( 'DATA_TEST_FRAME 00112233445566778899aabbccddee' , 'FAIL' ,
1667 1 , 'wpas_ctrl_iface_data_test_frame' ),
1668 ( 'DATA_TEST_FRAME 00112233445566778899aabbccddee' , 'FAIL' ,
1669 1 , 'l2_packet_init;wpas_ctrl_iface_data_test_frame' ),
1670 ( 'VENDOR_ELEM_ADD 1 000100' , 'FAIL' ,
1671 1 , 'wpas_ctrl_vendor_elem_add' ),
1672 ( 'VENDOR_ELEM_ADD 2 000100' , 'FAIL' ,
1673 2 , 'wpas_ctrl_vendor_elem_add' ),
1674 ( 'VENDOR_ELEM_REMOVE 2 000100' , 'FAIL' ,
1675 1 , 'wpas_ctrl_vendor_elem_remove' ),
1676 ( 'SET bssid_filter 00:11:22:33:44:55' , 'FAIL' ,
1677 1 , 'set_bssid_filter' ),
1678 ( 'SET disallow_aps bssid 00:11:22:33:44:55' , 'FAIL' ,
1679 1 , 'set_disallow_aps' ),
1680 ( 'SET disallow_aps ssid 11' , 'FAIL' ,
1681 1 , 'set_disallow_aps' ),
1682 ( 'SET blob foo 0011' , 'FAIL' ,
1683 1 , 'wpas_ctrl_set_blob' ),
1684 ( 'SET blob foo 0011' , 'FAIL' ,
1685 2 , 'wpas_ctrl_set_blob' ),
1686 ( 'SET blob foo 0011' , 'FAIL' ,
1687 3 , 'wpas_ctrl_set_blob' ),
1688 ( 'WPS_NFC_TAG_READ 00' , 'FAIL' ,
1689 1 , 'wpa_supplicant_ctrl_iface_wps_nfc_tag_read' ),
1690 ( 'WPS_NFC_TOKEN NDEF' , 'FAIL' ,
1691 1 , 'wpa_supplicant_ctrl_iface_wps_nfc_token' ),
1692 ( 'WPS_NFC_TOKEN NDEF' , 'FAIL' ,
1693 2 , 'wpa_supplicant_ctrl_iface_wps_nfc_token' ),
1694 ( 'WPS_NFC_TOKEN NDEF' , 'FAIL' ,
1695 3 , 'wpa_supplicant_ctrl_iface_wps_nfc_token' ),
1696 ( 'WPS_NFC_TOKEN NDEF' , 'FAIL' ,
1697 4 , 'wpa_supplicant_ctrl_iface_wps_nfc_token' ),
1698 ( 'NFC_REPORT_HANDOVER ROLE TYPE 00 00' , 'FAIL' ,
1699 1 , 'wpas_ctrl_nfc_report_handover' ),
1700 ( 'NFC_REPORT_HANDOVER ROLE TYPE 00 00' , 'FAIL' ,
1701 2 , 'wpas_ctrl_nfc_report_handover' ),
1702 ( 'NFC_GET_HANDOVER_REQ NDEF WPS-CR' , 'FAIL' ,
1703 1 , 'wps_build_nfc_handover_req' ),
1704 ( 'NFC_GET_HANDOVER_REQ NDEF WPS-CR' , 'FAIL' ,
1705 1 , 'ndef_build_record' ),
1706 ( 'NFC_GET_HANDOVER_REQ NDEF P2P-CR' , None ,
1707 1 , 'wpas_p2p_nfc_handover' ),
1708 ( 'NFC_GET_HANDOVER_REQ NDEF P2P-CR' , None ,
1709 1 , 'wps_build_nfc_handover_req_p2p' ),
1710 ( 'NFC_GET_HANDOVER_REQ NDEF P2P-CR' , 'FAIL' ,
1711 1 , 'ndef_build_record' ),
1712 ( 'NFC_GET_HANDOVER_SEL NDEF P2P-CR-TAG' , None ,
1713 1 , 'wpas_ctrl_nfc_get_handover_sel_p2p' ),
1714 ( 'NFC_GET_HANDOVER_SEL NDEF P2P-CR' , None ,
1715 1 , 'wpas_ctrl_nfc_get_handover_sel_p2p' ),
1716 ( 'P2P_ASP_PROVISION_RESP 00:11:22:33:44:55 id=1' , 'FAIL' ,
1717 1 , 'p2p_parse_asp_provision_cmd' ),
1718 ( 'P2P_SERV_DISC_REQ 00:11:22:33:44:55 02000001' , 'FAIL' ,
1719 1 , 'p2p_ctrl_serv_disc_req' ),
1720 ( 'P2P_SERV_DISC_RESP 2412 00:11:22:33:44:55 1 00' , 'FAIL' ,
1721 1 , 'p2p_ctrl_serv_disc_resp' ),
1722 ( 'P2P_SERVICE_ADD bonjour 0b5f6166706f766572746370c00c000c01 074578616d706c65c027' ,
1724 1 , 'p2p_ctrl_service_add_bonjour' ),
1725 ( 'P2P_SERVICE_ADD bonjour 0b5f6166706f766572746370c00c000c01 074578616d706c65c027' ,
1727 2 , 'p2p_ctrl_service_add_bonjour' ),
1728 ( 'P2P_SERVICE_ADD bonjour 0b5f6166706f766572746370c00c000c01 074578616d706c65c027' ,
1730 3 , 'p2p_ctrl_service_add_bonjour' ),
1731 ( 'P2P_SERVICE_DEL bonjour 0b5f6166706f766572746370c00c000c01' ,
1733 1 , 'p2p_ctrl_service_del_bonjour' ),
1734 ( 'GAS_REQUEST 00:11:22:33:44:55 00' , 'FAIL' ,
1736 ( 'GAS_REQUEST 00:11:22:33:44:55 00 11' , 'FAIL' ,
1738 ( 'HS20_GET_NAI_HOME_REALM_LIST 00:11:22:33:44:55 realm=example.com' ,
1740 1 , 'hs20_nai_home_realm_list' ),
1741 ( 'HS20_GET_NAI_HOME_REALM_LIST 00:11:22:33:44:55 00' ,
1743 1 , 'hs20_get_nai_home_realm_list' ),
1744 ( 'WNM_SLEEP enter tfs_req=11' , 'FAIL' ,
1745 1 , 'wpas_ctrl_iface_wnm_sleep' ),
1746 ( 'WNM_SLEEP enter tfs_req=11' , 'FAIL' ,
1747 2 , 'wpas_ctrl_iface_wnm_sleep' ),
1748 ( 'WNM_SLEEP enter tfs_req=11' , 'FAIL' ,
1749 3 , 'wpas_ctrl_iface_wnm_sleep' ),
1750 ( 'WNM_SLEEP enter tfs_req=11' , 'FAIL' ,
1751 4 , 'wpas_ctrl_iface_wnm_sleep' ),
1752 ( 'WNM_SLEEP enter tfs_req=11' , 'FAIL' ,
1753 5 , 'wpas_ctrl_iface_wnm_sleep' ),
1754 ( 'WNM_SLEEP enter' , 'FAIL' ,
1755 3 , 'wpas_ctrl_iface_wnm_sleep' ),
1756 ( 'VENDOR 1 1 00' , 'FAIL' ,
1757 1 , 'wpa_supplicant_vendor_cmd' ),
1758 ( 'VENDOR 1 1 00' , 'FAIL' ,
1759 2 , 'wpa_supplicant_vendor_cmd' ),
1760 ( 'RADIO_WORK add test' , 'FAIL' ,
1761 1 , 'wpas_ctrl_radio_work_add' ),
1762 ( 'RADIO_WORK add test' , 'FAIL' ,
1763 2 , 'wpas_ctrl_radio_work_add' ),
1764 ( 'AUTOSCAN periodic:1' , 'FAIL' ,
1765 1 , 'wpa_supplicant_ctrl_iface_autoscan' ),
1767 1 , 'wpa_supplicant_ctrl_iface_process' ) ]
1768 tls
= dev
[ 0 ]. request ( "GET tls_library" )
1769 if not tls
. startswith ( "internal" ):
1770 tests
. append (( 'NFC_GET_HANDOVER_SEL NDEF P2P-CR-TAG' , 'FAIL' ,
1771 4 , 'wpas_ctrl_nfc_get_handover_sel_p2p' ))
1772 for cmd
, exp
, count
, func
in tests
:
1773 with
alloc_fail ( dev
[ 0 ], count
, func
):
1774 res
= dev
[ 0 ]. request ( cmd
)
1775 if exp
and exp
not in res
:
1776 raise Exception ( "Unexpected success for ' %s ' during OOM ( %d : %s )" % ( cmd
, count
, func
))
1778 tests
= [ ( 'FOO' , None ,
1779 1 , 'wpa_supplicant_global_ctrl_iface_process' ),
1780 ( 'IFNAME=notfound PING' , 'FAIL \n ' ,
1781 1 , 'wpas_global_ctrl_iface_ifname' ) ]
1782 for cmd
, exp
, count
, func
in tests
:
1783 with
alloc_fail ( dev
[ 0 ], count
, func
):
1784 res
= dev
[ 0 ]. global_request ( cmd
)
1785 if exp
and exp
not in res
:
1786 raise Exception ( "Unexpected success for ' %s ' during OOM" % cmd
)
1788 def test_wpas_ctrl_error ( dev
):
1789 """Various wpa_supplicant ctrl_iface error cases"""
1790 tests
= [ ( 'WPS_NFC_TOKEN NDEF' , 'FAIL' ,
1791 1 , 'wpa_supplicant_ctrl_iface_wps_nfc_token' ),
1792 ( 'WPS_NFC_TOKEN NDEF' , 'FAIL' ,
1793 2 , 'wpa_supplicant_ctrl_iface_wps_nfc_token' ),
1794 ( 'NFC_GET_HANDOVER_REQ NDEF P2P-CR' , None ,
1795 1 , 'wpas_p2p_nfc_handover' ),
1796 ( 'NFC_GET_HANDOVER_REQ NDEF P2P-CR' , None ,
1797 1 , 'wps_build_nfc_handover_req_p2p' ) ]
1798 for cmd
, exp
, count
, func
in tests
:
1799 with
fail_test ( dev
[ 0 ], count
, func
):
1800 res
= dev
[ 0 ]. request ( cmd
)
1801 if exp
and exp
not in res
:
1802 raise Exception ( "Unexpected success for ' %s ' during failure testing ( %d : %s )" % ( cmd
, count
, func
))
1804 def test_wpas_ctrl_socket_full ( dev
, apdev
, test_params
):
1805 """wpa_supplicant control socket and full send buffer"""
1806 if not dev
[ 0 ]. ping ():
1807 raise Exception ( "Could not ping wpa_supplicant at the beginning of the test" )
1812 s
= socket
. socket ( socket
. AF_UNIX
, socket
. SOCK_DGRAM
)
1813 local
= "/tmp/wpa_ctrl_test_ %d-%d " % ( os
. getpid (), counter
)
1816 s
. connect ( "/var/run/wpa_supplicant/wlan0" )
1818 logger
. debug ( "Command %d " % i
)
1821 except Exception , e
:
1822 logger
. info ( "Could not send command %d : %s " % ( i
, str ( e
)))
1824 # Close without receiving response
1827 if not dev
[ 0 ]. ping ():
1828 raise Exception ( "Could not ping wpa_supplicant in the middle of the test" )
1831 s2
= socket
. socket ( socket
. AF_UNIX
, socket
. SOCK_DGRAM
)
1832 local2
= "/tmp/wpa_ctrl_test_ %d-%d " % ( os
. getpid (), counter
)
1835 s2
. connect ( "/var/run/wpa_supplicant/wlan0" )
1837 logger
. debug ( "Command %d [2]" % i
)
1840 except Exception , e
:
1841 logger
. info ( "Could not send command %d [2]: %s " % ( i
, str ( e
)))
1843 # Close without receiving response
1850 logger
. debug ( "Command %d [3]" % i
)
1853 except Exception , e
:
1854 logger
. info ( "Could not send command %d [3]: %s " % ( i
, str ( e
)))
1856 # Close without receiving response
1862 if not dev
[ 0 ]. ping ():
1863 raise Exception ( "Could not ping wpa_supplicant in the middle of the test [2]" )
1866 s
= socket
. socket ( socket
. AF_UNIX
, socket
. SOCK_DGRAM
)
1867 local
= "/tmp/wpa_ctrl_test_ %d-%d " % ( os
. getpid (), counter
)
1870 s
. connect ( "/var/run/wpa_supplicant/wlan0" )
1874 raise Exception ( "Could not attach a test socket" )
1877 dev
[ 0 ]. scan ( freq
= 2412 )
1883 dev
[ 0 ]. scan ( freq
= 2412 )
1885 if not dev
[ 0 ]. ping ():
1886 raise Exception ( "Could not ping wpa_supplicant at the end of the test" )
1889 def test_wpas_ctrl_event_burst ( dev
, apdev
):
1890 """wpa_supplicant control socket and event burst"""
1891 if "OK" not in dev
[ 0 ]. request ( "EVENT_TEST 1000" ):
1892 raise Exception ( "Could not request event messages" )
1896 for i
in range ( 100 ):
1897 ( i
, g
) = dev
[ 0 ]. dump_monitor ()
1900 logger
. info ( "Received i= %d g= %d " % ( i
, g
))
1901 if total_i
>= 1000 and total_g
>= 1000 :
1906 raise Exception ( "Some per-interface events not seen: %d " % total_i
)
1908 raise Exception ( "Some global events not seen: %d " % total_g
)
1910 if not dev
[ 0 ]. ping ():
1911 raise Exception ( "Could not ping wpa_supplicant at the end of the test" )
1913 def test_wpas_ctrl_sched_scan_plans ( dev
, apdev
):
1914 """wpa_supplicant sched_scan_plans parsing"""
1915 dev
[ 0 ]. request ( "SET sched_scan_plans foo" )
1916 dev
[ 0 ]. request ( "SET sched_scan_plans 10:100 20:200 30" )
1917 dev
[ 0 ]. request ( "SET sched_scan_plans " )
1919 def test_wpas_ctrl_signal_monitor ( dev
, apdev
):
1920 """wpa_supplicant SIGNAL_MONITOR command"""
1921 hapd
= hostapd
. add_ap ( apdev
[ 0 ], { "ssid" : "open" })
1922 dev
[ 0 ]. connect ( "open" , key_mgmt
= "NONE" , scan_freq
= "2412" )
1923 dev
[ 1 ]. connect ( "open" , key_mgmt
= "NONE" , scan_freq
= "2412" ,
1924 bgscan
= "simple:1:-45:2" )
1925 dev
[ 2 ]. connect ( "open" , key_mgmt
= "NONE" , scan_freq
= "2412" )
1927 tests
= [ " THRESHOLD=-45" , " THRESHOLD=-44 HYSTERESIS=5" , "" ]
1929 if "FAIL" in dev
[ 2 ]. request ( "SIGNAL_MONITOR THRESHOLD=-1 HYSTERESIS=5" ):
1930 raise Exception ( "SIGNAL_MONITOR command failed" )
1932 if "OK" not in dev
[ 0 ]. request ( "SIGNAL_MONITOR" + t
):
1933 raise Exception ( "SIGNAL_MONITOR command failed: " + t
)
1934 if "FAIL" not in dev
[ 1 ]. request ( "SIGNAL_MONITOR THRESHOLD=-44 HYSTERESIS=5" ):
1935 raise Exception ( "SIGNAL_MONITOR command accepted while using bgscan" )
1936 ev
= dev
[ 2 ]. wait_event ([ "CTRL-EVENT-SIGNAL-CHANGE" ], timeout
= 10 )
1938 raise Exception ( "No signal change event seen" )
1939 if "above=0" not in ev
:
1940 raise Exception ( "Unexpected signal change event contents: " + ev
)
1942 dev
[ 0 ]. request ( "SIGNAL_MONITOR" )
1943 dev
[ 1 ]. request ( "SIGNAL_MONITOR" )
1944 dev
[ 2 ]. request ( "SIGNAL_MONITOR" )
1946 dev
[ 0 ]. request ( "REMOVE_NETWORK all" )
1947 dev
[ 1 ]. request ( "REMOVE_NETWORK all" )
1948 dev
[ 1 ]. wait_disconnected ()