]>
git.ipfire.org Git - thirdparty/hostap.git/blob - tests/hwsim/test_ap_wps.py
2 # Copyright (c) 2013-2014, Jouni Malinen <j@w1.fi>
4 # This software may be distributed under the terms of the BSD license.
5 # See README for more details.
11 logger
= logging
.getLogger()
17 import xml
.etree
.ElementTree
as ET
22 from wpasupplicant
import WpaSupplicant
24 def test_ap_wps_init(dev
, apdev
):
25 """Initial AP configuration with first WPS Enrollee"""
27 hostapd
.add_ap(apdev
[0]['ifname'],
28 { "ssid": ssid
, "eap_server": "1", "wps_state": "1" })
29 hapd
= hostapd
.Hostapd(apdev
[0]['ifname'])
30 logger
.info("WPS provisioning step")
31 hapd
.request("WPS_PBC")
32 if "PBC Status: Active" not in hapd
.request("WPS_GET_STATUS"):
33 raise Exception("PBC status not shown correctly")
35 id = dev
[0].add_network()
36 dev
[0].set_network_quoted(id, "ssid", "home")
37 dev
[0].set_network_quoted(id, "psk", "12345678")
38 dev
[0].request("ENABLE_NETWORK %s no-connect" % id)
40 id = dev
[0].add_network()
41 dev
[0].set_network_quoted(id, "ssid", "home2")
42 dev
[0].set_network(id, "bssid", "00:11:22:33:44:55")
43 dev
[0].set_network(id, "key_mgmt", "NONE")
44 dev
[0].request("ENABLE_NETWORK %s no-connect" % id)
46 dev
[0].request("WPS_PBC")
47 dev
[0].wait_connected(timeout
=30)
48 status
= dev
[0].get_status()
49 if status
['wpa_state'] != 'COMPLETED' or status
['bssid'] != apdev
[0]['bssid']:
50 raise Exception("Not fully connected")
51 if status
['ssid'] != ssid
:
52 raise Exception("Unexpected SSID")
53 if status
['pairwise_cipher'] != 'CCMP':
54 raise Exception("Unexpected encryption configuration")
55 if status
['key_mgmt'] != 'WPA2-PSK':
56 raise Exception("Unexpected key_mgmt")
58 status
= hapd
.request("WPS_GET_STATUS")
59 if "PBC Status: Disabled" not in status
:
60 raise Exception("PBC status not shown correctly")
61 if "Last WPS result: Success" not in status
:
62 raise Exception("Last WPS result not shown correctly")
63 if "Peer Address: " + dev
[0].p2p_interface_addr() not in status
:
64 raise Exception("Peer address not shown correctly")
65 conf
= hapd
.request("GET_CONFIG")
66 if "wps_state=configured" not in conf
:
67 raise Exception("AP not in WPS configured state")
68 if "rsn_pairwise_cipher=CCMP TKIP" not in conf
:
69 raise Exception("Unexpected rsn_pairwise_cipher")
70 if "wpa_pairwise_cipher=CCMP TKIP" not in conf
:
71 raise Exception("Unexpected wpa_pairwise_cipher")
72 if "group_cipher=TKIP" not in conf
:
73 raise Exception("Unexpected group_cipher")
75 if len(dev
[0].list_networks()) != 3:
76 raise Exception("Unexpected number of network blocks")
78 def test_ap_wps_init_2ap_pbc(dev
, apdev
):
79 """Initial two-radio AP configuration with first WPS PBC Enrollee"""
81 params
= { "ssid": ssid
, "eap_server": "1", "wps_state": "1" }
82 hostapd
.add_ap(apdev
[0]['ifname'], params
)
83 hostapd
.add_ap(apdev
[1]['ifname'], params
)
84 hapd
= hostapd
.Hostapd(apdev
[0]['ifname'])
85 logger
.info("WPS provisioning step")
86 hapd
.request("WPS_PBC")
87 dev
[0].scan_for_bss(apdev
[0]['bssid'], freq
="2412", force_scan
=True)
88 dev
[0].scan_for_bss(apdev
[1]['bssid'], freq
="2412")
89 bss
= dev
[0].get_bss(apdev
[0]['bssid'])
90 if "[WPS-PBC]" not in bss
['flags']:
91 raise Exception("WPS-PBC flag missing from AP1")
92 bss
= dev
[0].get_bss(apdev
[1]['bssid'])
93 if "[WPS-PBC]" not in bss
['flags']:
94 raise Exception("WPS-PBC flag missing from AP2")
96 dev
[0].request("SET wps_cred_processing 2")
97 dev
[0].request("WPS_PBC")
98 ev
= dev
[0].wait_event(["WPS-CRED-RECEIVED"], timeout
=30)
99 dev
[0].request("SET wps_cred_processing 0")
101 raise Exception("WPS cred event not seen")
103 raise Exception("WPS attributes not included in the cred event")
104 dev
[0].wait_connected(timeout
=30)
106 dev
[1].scan_for_bss(apdev
[0]['bssid'], freq
="2412", force_scan
=True)
107 dev
[1].scan_for_bss(apdev
[1]['bssid'], freq
="2412")
108 bss
= dev
[1].get_bss(apdev
[0]['bssid'])
109 if "[WPS-PBC]" in bss
['flags']:
110 raise Exception("WPS-PBC flag not cleared from AP1")
111 bss
= dev
[1].get_bss(apdev
[1]['bssid'])
112 if "[WPS-PBC]" in bss
['flags']:
113 raise Exception("WPS-PBC flag not cleared from AP2")
115 def test_ap_wps_init_2ap_pin(dev
, apdev
):
116 """Initial two-radio AP configuration with first WPS PIN Enrollee"""
118 params
= { "ssid": ssid
, "eap_server": "1", "wps_state": "1" }
119 hostapd
.add_ap(apdev
[0]['ifname'], params
)
120 hostapd
.add_ap(apdev
[1]['ifname'], params
)
121 hapd
= hostapd
.Hostapd(apdev
[0]['ifname'])
122 logger
.info("WPS provisioning step")
123 pin
= dev
[0].wps_read_pin()
124 hapd
.request("WPS_PIN any " + pin
)
125 dev
[0].scan_for_bss(apdev
[0]['bssid'], freq
="2412", force_scan
=True)
126 dev
[0].scan_for_bss(apdev
[1]['bssid'], freq
="2412")
127 bss
= dev
[0].get_bss(apdev
[0]['bssid'])
128 if "[WPS-AUTH]" not in bss
['flags']:
129 raise Exception("WPS-AUTH flag missing from AP1")
130 bss
= dev
[0].get_bss(apdev
[1]['bssid'])
131 if "[WPS-AUTH]" not in bss
['flags']:
132 raise Exception("WPS-AUTH flag missing from AP2")
133 dev
[0].dump_monitor()
134 dev
[0].request("WPS_PIN any " + pin
)
135 dev
[0].wait_connected(timeout
=30)
137 dev
[1].scan_for_bss(apdev
[0]['bssid'], freq
="2412", force_scan
=True)
138 dev
[1].scan_for_bss(apdev
[1]['bssid'], freq
="2412")
139 bss
= dev
[1].get_bss(apdev
[0]['bssid'])
140 if "[WPS-AUTH]" in bss
['flags']:
141 raise Exception("WPS-AUTH flag not cleared from AP1")
142 bss
= dev
[1].get_bss(apdev
[1]['bssid'])
143 if "[WPS-AUTH]" in bss
['flags']:
144 raise Exception("WPS-AUTH flag not cleared from AP2")
146 def test_ap_wps_init_through_wps_config(dev
, apdev
):
147 """Initial AP configuration using wps_config command"""
148 ssid
= "test-wps-init-config"
149 hostapd
.add_ap(apdev
[0]['ifname'],
150 { "ssid": ssid
, "eap_server": "1", "wps_state": "1" })
151 hapd
= hostapd
.Hostapd(apdev
[0]['ifname'])
152 if "FAIL" in hapd
.request("WPS_CONFIG " + ssid
.encode("hex") + " WPA2PSK CCMP " + "12345678".encode("hex")):
153 raise Exception("WPS_CONFIG command failed")
154 ev
= hapd
.wait_event(["WPS-NEW-AP-SETTINGS"], timeout
=5)
156 raise Exception("Timeout on WPS-NEW-AP-SETTINGS events")
157 # It takes some time for the AP to update Beacon and Probe Response frames,
158 # so wait here before requesting the scan to be started to avoid adding
159 # extra five second wait to the test due to fetching obsolete scan results.
162 dev
[0].connect(ssid
, psk
="12345678", scan_freq
="2412", proto
="WPA2",
163 pairwise
="CCMP", group
="CCMP")
165 def test_ap_wps_conf(dev
, apdev
):
166 """WPS PBC provisioning with configured AP"""
167 ssid
= "test-wps-conf"
168 hostapd
.add_ap(apdev
[0]['ifname'],
169 { "ssid": ssid
, "eap_server": "1", "wps_state": "2",
170 "wpa_passphrase": "12345678", "wpa": "2",
171 "wpa_key_mgmt": "WPA-PSK", "rsn_pairwise": "CCMP"})
172 hapd
= hostapd
.Hostapd(apdev
[0]['ifname'])
173 logger
.info("WPS provisioning step")
174 hapd
.request("WPS_PBC")
175 dev
[0].scan_for_bss(apdev
[0]['bssid'], freq
="2412")
176 dev
[0].dump_monitor()
177 dev
[0].request("WPS_PBC " + apdev
[0]['bssid'])
178 dev
[0].wait_connected(timeout
=30)
179 status
= dev
[0].get_status()
180 if status
['wpa_state'] != 'COMPLETED':
181 raise Exception("Not fully connected")
182 if status
['bssid'] != apdev
[0]['bssid']:
183 raise Exception("Unexpected BSSID")
184 if status
['ssid'] != ssid
:
185 raise Exception("Unexpected SSID")
186 if status
['pairwise_cipher'] != 'CCMP' or status
['group_cipher'] != 'CCMP':
187 raise Exception("Unexpected encryption configuration")
188 if status
['key_mgmt'] != 'WPA2-PSK':
189 raise Exception("Unexpected key_mgmt")
191 sta
= hapd
.get_sta(dev
[0].p2p_interface_addr())
192 if 'wpsDeviceName' not in sta
or sta
['wpsDeviceName'] != "Device A":
193 raise Exception("Device name not available in STA command")
195 def test_ap_wps_conf_5ghz(dev
, apdev
):
196 """WPS PBC provisioning with configured AP on 5 GHz band"""
199 ssid
= "test-wps-conf"
200 params
= { "ssid": ssid
, "eap_server": "1", "wps_state": "2",
201 "wpa_passphrase": "12345678", "wpa": "2",
202 "wpa_key_mgmt": "WPA-PSK", "rsn_pairwise": "CCMP",
203 "country_code": "FI", "hw_mode": "a", "channel": "36" }
204 hapd
= hostapd
.add_ap(apdev
[0]['ifname'], params
)
205 logger
.info("WPS provisioning step")
206 hapd
.request("WPS_PBC")
207 dev
[0].scan_for_bss(apdev
[0]['bssid'], freq
="5180")
208 dev
[0].request("WPS_PBC " + apdev
[0]['bssid'])
209 dev
[0].wait_connected(timeout
=30)
211 sta
= hapd
.get_sta(dev
[0].p2p_interface_addr())
212 if 'wpsDeviceName' not in sta
or sta
['wpsDeviceName'] != "Device A":
213 raise Exception("Device name not available in STA command")
215 dev
[0].request("DISCONNECT")
217 hapd
.request("DISABLE")
218 subprocess
.call(['sudo', 'iw', 'reg', 'set', '00'])
219 dev
[0].flush_scan_cache()
221 def test_ap_wps_conf_chan14(dev
, apdev
):
222 """WPS PBC provisioning with configured AP on channel 14"""
225 ssid
= "test-wps-conf"
226 params
= { "ssid": ssid
, "eap_server": "1", "wps_state": "2",
227 "wpa_passphrase": "12345678", "wpa": "2",
228 "wpa_key_mgmt": "WPA-PSK", "rsn_pairwise": "CCMP",
229 "country_code": "JP", "hw_mode": "b", "channel": "14" }
230 hapd
= hostapd
.add_ap(apdev
[0]['ifname'], params
)
231 logger
.info("WPS provisioning step")
232 hapd
.request("WPS_PBC")
233 dev
[0].request("WPS_PBC")
234 dev
[0].wait_connected(timeout
=30)
236 sta
= hapd
.get_sta(dev
[0].p2p_interface_addr())
237 if 'wpsDeviceName' not in sta
or sta
['wpsDeviceName'] != "Device A":
238 raise Exception("Device name not available in STA command")
240 dev
[0].request("DISCONNECT")
242 hapd
.request("DISABLE")
243 subprocess
.call(['sudo', 'iw', 'reg', 'set', '00'])
244 dev
[0].flush_scan_cache()
246 def test_ap_wps_twice(dev
, apdev
):
247 """WPS provisioning with twice to change passphrase"""
248 ssid
= "test-wps-twice"
249 params
= { "ssid": ssid
, "eap_server": "1", "wps_state": "2",
250 "wpa_passphrase": "12345678", "wpa": "2",
251 "wpa_key_mgmt": "WPA-PSK", "rsn_pairwise": "CCMP" }
252 hostapd
.add_ap(apdev
[0]['ifname'], params
)
253 hapd
= hostapd
.Hostapd(apdev
[0]['ifname'])
254 logger
.info("WPS provisioning step")
255 hapd
.request("WPS_PBC")
256 dev
[0].scan_for_bss(apdev
[0]['bssid'], freq
="2412")
257 dev
[0].dump_monitor()
258 dev
[0].request("WPS_PBC " + apdev
[0]['bssid'])
259 dev
[0].wait_connected(timeout
=30)
260 dev
[0].request("DISCONNECT")
262 logger
.info("Restart AP with different passphrase and re-run WPS")
263 hapd_global
= hostapd
.HostapdGlobal()
264 hapd_global
.remove(apdev
[0]['ifname'])
265 params
['wpa_passphrase'] = 'another passphrase'
266 hostapd
.add_ap(apdev
[0]['ifname'], params
)
267 hapd
= hostapd
.Hostapd(apdev
[0]['ifname'])
268 logger
.info("WPS provisioning step")
269 hapd
.request("WPS_PBC")
270 dev
[0].dump_monitor()
271 dev
[0].request("WPS_PBC " + apdev
[0]['bssid'])
272 dev
[0].wait_connected(timeout
=30)
273 networks
= dev
[0].list_networks()
274 if len(networks
) > 1:
275 raise Exception("Unexpected duplicated network block present")
277 def test_ap_wps_incorrect_pin(dev
, apdev
):
278 """WPS PIN provisioning with incorrect PIN"""
279 ssid
= "test-wps-incorrect-pin"
280 hostapd
.add_ap(apdev
[0]['ifname'],
281 { "ssid": ssid
, "eap_server": "1", "wps_state": "2",
282 "wpa_passphrase": "12345678", "wpa": "2",
283 "wpa_key_mgmt": "WPA-PSK", "rsn_pairwise": "CCMP"})
284 hapd
= hostapd
.Hostapd(apdev
[0]['ifname'])
286 logger
.info("WPS provisioning attempt 1")
287 hapd
.request("WPS_PIN any 12345670")
288 dev
[0].scan_for_bss(apdev
[0]['bssid'], freq
="2412")
289 dev
[0].dump_monitor()
290 dev
[0].request("WPS_PIN %s 55554444" % apdev
[0]['bssid'])
291 ev
= dev
[0].wait_event(["WPS-FAIL"], timeout
=30)
293 raise Exception("WPS operation timed out")
294 if "config_error=18" not in ev
:
295 raise Exception("Incorrect config_error reported")
296 if "msg=8" not in ev
:
297 raise Exception("PIN error detected on incorrect message")
298 dev
[0].wait_disconnected(timeout
=10)
299 dev
[0].request("WPS_CANCEL")
300 # if a scan was in progress, wait for it to complete before trying WPS again
301 ev
= dev
[0].wait_event(["CTRL-EVENT-SCAN-RESULTS"], 5)
303 status
= hapd
.request("WPS_GET_STATUS")
304 if "Last WPS result: Failed" not in status
:
305 raise Exception("WPS failure result not shown correctly")
307 logger
.info("WPS provisioning attempt 2")
308 hapd
.request("WPS_PIN any 12345670")
309 dev
[0].dump_monitor()
310 dev
[0].request("WPS_PIN %s 12344444" % apdev
[0]['bssid'])
311 ev
= dev
[0].wait_event(["WPS-FAIL"], timeout
=30)
313 raise Exception("WPS operation timed out")
314 if "config_error=18" not in ev
:
315 raise Exception("Incorrect config_error reported")
316 if "msg=10" not in ev
:
317 raise Exception("PIN error detected on incorrect message")
318 dev
[0].wait_disconnected(timeout
=10)
320 def test_ap_wps_conf_pin(dev
, apdev
):
321 """WPS PIN provisioning with configured AP"""
322 ssid
= "test-wps-conf-pin"
323 hostapd
.add_ap(apdev
[0]['ifname'],
324 { "ssid": ssid
, "eap_server": "1", "wps_state": "2",
325 "wpa_passphrase": "12345678", "wpa": "2",
326 "wpa_key_mgmt": "WPA-PSK", "rsn_pairwise": "CCMP"})
327 hapd
= hostapd
.Hostapd(apdev
[0]['ifname'])
328 logger
.info("WPS provisioning step")
329 pin
= dev
[0].wps_read_pin()
330 hapd
.request("WPS_PIN any " + pin
)
331 dev
[0].scan_for_bss(apdev
[0]['bssid'], freq
="2412")
332 dev
[0].dump_monitor()
333 dev
[0].request("WPS_PIN %s %s" % (apdev
[0]['bssid'], pin
))
334 dev
[0].wait_connected(timeout
=30)
335 status
= dev
[0].get_status()
336 if status
['wpa_state'] != 'COMPLETED' or status
['bssid'] != apdev
[0]['bssid']:
337 raise Exception("Not fully connected")
338 if status
['ssid'] != ssid
:
339 raise Exception("Unexpected SSID")
340 if status
['pairwise_cipher'] != 'CCMP' or status
['group_cipher'] != 'CCMP':
341 raise Exception("Unexpected encryption configuration")
342 if status
['key_mgmt'] != 'WPA2-PSK':
343 raise Exception("Unexpected key_mgmt")
345 dev
[1].scan_for_bss(apdev
[0]['bssid'], freq
="2412", force_scan
=True)
346 bss
= dev
[1].get_bss(apdev
[0]['bssid'])
347 if "[WPS-AUTH]" in bss
['flags']:
348 raise Exception("WPS-AUTH flag not cleared")
349 logger
.info("Try to connect from another station using the same PIN")
350 pin
= dev
[1].request("WPS_PIN " + apdev
[0]['bssid'])
351 ev
= dev
[1].wait_event(["WPS-M2D","CTRL-EVENT-CONNECTED"], timeout
=30)
353 raise Exception("Operation timed out")
354 if "WPS-M2D" not in ev
:
355 raise Exception("Unexpected WPS operation started")
356 hapd
.request("WPS_PIN any " + pin
)
357 dev
[1].wait_connected(timeout
=30)
359 def test_ap_wps_conf_pin_v1(dev
, apdev
):
360 """WPS PIN provisioning with configured WPS v1.0 AP"""
361 ssid
= "test-wps-conf-pin-v1"
362 hostapd
.add_ap(apdev
[0]['ifname'],
363 { "ssid": ssid
, "eap_server": "1", "wps_state": "2",
364 "wpa_passphrase": "12345678", "wpa": "2",
365 "wpa_key_mgmt": "WPA-PSK", "rsn_pairwise": "CCMP"})
366 hapd
= hostapd
.Hostapd(apdev
[0]['ifname'])
367 logger
.info("WPS provisioning step")
368 pin
= dev
[0].wps_read_pin()
369 hapd
.request("SET wps_version_number 0x10")
370 hapd
.request("WPS_PIN any " + pin
)
372 for i
in range(0, 10):
373 dev
[0].scan(freq
="2412")
374 if "[WPS-PIN]" in dev
[0].request("SCAN_RESULTS"):
378 hapd
.request("SET wps_version_number 0x20")
379 raise Exception("WPS-PIN flag not seen in scan results")
380 dev
[0].dump_monitor()
381 dev
[0].request("WPS_PIN %s %s" % (apdev
[0]['bssid'], pin
))
382 dev
[0].wait_connected(timeout
=30)
383 hapd
.request("SET wps_version_number 0x20")
385 def test_ap_wps_conf_pin_2sta(dev
, apdev
):
386 """Two stations trying to use WPS PIN at the same time"""
387 ssid
= "test-wps-conf-pin2"
388 hostapd
.add_ap(apdev
[0]['ifname'],
389 { "ssid": ssid
, "eap_server": "1", "wps_state": "2",
390 "wpa_passphrase": "12345678", "wpa": "2",
391 "wpa_key_mgmt": "WPA-PSK", "rsn_pairwise": "CCMP"})
392 hapd
= hostapd
.Hostapd(apdev
[0]['ifname'])
393 logger
.info("WPS provisioning step")
396 hapd
.request("WPS_PIN " + dev
[0].get_status_field("uuid") + " " + pin
)
397 hapd
.request("WPS_PIN " + dev
[1].get_status_field("uuid") + " " + pin
)
398 dev
[0].dump_monitor()
399 dev
[1].dump_monitor()
400 dev
[0].scan_for_bss(apdev
[0]['bssid'], freq
="2412")
401 dev
[1].scan_for_bss(apdev
[0]['bssid'], freq
="2412")
402 dev
[0].request("WPS_PIN %s %s" % (apdev
[0]['bssid'], pin
))
403 dev
[1].request("WPS_PIN %s %s" % (apdev
[0]['bssid'], pin
))
404 dev
[0].wait_connected(timeout
=30)
405 dev
[1].wait_connected(timeout
=30)
407 def test_ap_wps_conf_pin_timeout(dev
, apdev
):
408 """WPS PIN provisioning with configured AP timing out PIN"""
409 ssid
= "test-wps-conf-pin"
410 hostapd
.add_ap(apdev
[0]['ifname'],
411 { "ssid": ssid
, "eap_server": "1", "wps_state": "2",
412 "wpa_passphrase": "12345678", "wpa": "2",
413 "wpa_key_mgmt": "WPA-PSK", "rsn_pairwise": "CCMP"})
414 hapd
= hostapd
.Hostapd(apdev
[0]['ifname'])
415 addr
= dev
[0].p2p_interface_addr()
416 pin
= dev
[0].wps_read_pin()
417 if "FAIL" not in hapd
.request("WPS_PIN "):
418 raise Exception("Unexpected success on invalid WPS_PIN")
419 hapd
.request("WPS_PIN any " + pin
+ " 1")
420 dev
[0].scan_for_bss(apdev
[0]['bssid'], freq
="2412")
422 dev
[0].request("WPS_PIN %s %s" % (apdev
[0]['bssid'], pin
))
423 ev
= hapd
.wait_event(["WPS-PIN-NEEDED"], timeout
=20)
425 raise Exception("WPS-PIN-NEEDED event timed out")
426 ev
= dev
[0].wait_event(["WPS-M2D"])
428 raise Exception("M2D not reported")
429 dev
[0].request("WPS_CANCEL")
431 hapd
.request("WPS_PIN any " + pin
+ " 20 " + addr
)
432 dev
[0].request("WPS_PIN %s %s" % (apdev
[0]['bssid'], pin
))
433 dev
[0].wait_connected(timeout
=30)
435 def test_ap_wps_reg_connect(dev
, apdev
):
436 """WPS registrar using AP PIN to connect"""
437 ssid
= "test-wps-reg-ap-pin"
439 hostapd
.add_ap(apdev
[0]['ifname'],
440 { "ssid": ssid
, "eap_server": "1", "wps_state": "2",
441 "wpa_passphrase": "12345678", "wpa": "2",
442 "wpa_key_mgmt": "WPA-PSK", "rsn_pairwise": "CCMP",
444 logger
.info("WPS provisioning step")
445 dev
[0].dump_monitor()
446 dev
[0].scan_for_bss(apdev
[0]['bssid'], freq
=2412)
447 dev
[0].wps_reg(apdev
[0]['bssid'], appin
)
448 status
= dev
[0].get_status()
449 if status
['wpa_state'] != 'COMPLETED' or status
['bssid'] != apdev
[0]['bssid']:
450 raise Exception("Not fully connected")
451 if status
['ssid'] != ssid
:
452 raise Exception("Unexpected SSID")
453 if status
['pairwise_cipher'] != 'CCMP' or status
['group_cipher'] != 'CCMP':
454 raise Exception("Unexpected encryption configuration")
455 if status
['key_mgmt'] != 'WPA2-PSK':
456 raise Exception("Unexpected key_mgmt")
458 def check_wps_reg_failure(dev
, ap
, appin
):
459 dev
.request("WPS_REG " + ap
['bssid'] + " " + appin
)
460 ev
= dev
.wait_event(["WPS-SUCCESS", "WPS-FAIL"], timeout
=15)
462 raise Exception("WPS operation timed out")
463 if "WPS-SUCCESS" in ev
:
464 raise Exception("WPS operation succeeded unexpectedly")
465 if "config_error=15" not in ev
:
466 raise Exception("WPS setup locked state was not reported correctly")
468 def test_ap_wps_random_ap_pin(dev
, apdev
):
469 """WPS registrar using random AP PIN"""
470 ssid
= "test-wps-reg-random-ap-pin"
471 ap_uuid
= "27ea801a-9e5c-4e73-bd82-f89cbcd10d7e"
472 hostapd
.add_ap(apdev
[0]['ifname'],
473 { "ssid": ssid
, "eap_server": "1", "wps_state": "2",
474 "wpa_passphrase": "12345678", "wpa": "2",
475 "wpa_key_mgmt": "WPA-PSK", "rsn_pairwise": "CCMP",
476 "device_name": "Wireless AP", "manufacturer": "Company",
477 "model_name": "WAP", "model_number": "123",
478 "serial_number": "12345", "device_type": "6-0050F204-1",
479 "os_version": "01020300",
480 "config_methods": "label push_button",
481 "uuid": ap_uuid
, "upnp_iface": "lo" })
482 hapd
= hostapd
.Hostapd(apdev
[0]['ifname'])
483 appin
= hapd
.request("WPS_AP_PIN random")
485 raise Exception("Could not generate random AP PIN")
486 if appin
not in hapd
.request("WPS_AP_PIN get"):
487 raise Exception("Could not fetch current AP PIN")
488 logger
.info("WPS provisioning step")
489 dev
[0].scan_for_bss(apdev
[0]['bssid'], freq
=2412)
490 dev
[0].wps_reg(apdev
[0]['bssid'], appin
)
492 hapd
.request("WPS_AP_PIN disable")
493 logger
.info("WPS provisioning step with AP PIN disabled")
494 dev
[1].scan_for_bss(apdev
[0]['bssid'], freq
=2412)
495 check_wps_reg_failure(dev
[1], apdev
[0], appin
)
497 logger
.info("WPS provisioning step with AP PIN reset")
499 hapd
.request("WPS_AP_PIN set " + appin
)
500 dev
[1].wps_reg(apdev
[0]['bssid'], appin
)
501 dev
[0].request("REMOVE_NETWORK all")
502 dev
[1].request("REMOVE_NETWORK all")
503 dev
[0].wait_disconnected(timeout
=10)
504 dev
[1].wait_disconnected(timeout
=10)
506 logger
.info("WPS provisioning step after AP PIN timeout")
507 hapd
.request("WPS_AP_PIN disable")
508 appin
= hapd
.request("WPS_AP_PIN random 1")
510 if "FAIL" not in hapd
.request("WPS_AP_PIN get"):
511 raise Exception("AP PIN unexpectedly still enabled")
512 check_wps_reg_failure(dev
[0], apdev
[0], appin
)
514 logger
.info("WPS provisioning step after AP PIN timeout(2)")
515 hapd
.request("WPS_AP_PIN disable")
517 hapd
.request("WPS_AP_PIN set " + appin
+ " 1")
519 if "FAIL" not in hapd
.request("WPS_AP_PIN get"):
520 raise Exception("AP PIN unexpectedly still enabled")
521 check_wps_reg_failure(dev
[1], apdev
[0], appin
)
523 def test_ap_wps_reg_config(dev
, apdev
):
524 """WPS registrar configuring an AP using AP PIN"""
525 ssid
= "test-wps-init-ap-pin"
527 hostapd
.add_ap(apdev
[0]['ifname'],
528 { "ssid": ssid
, "eap_server": "1", "wps_state": "2",
530 logger
.info("WPS configuration step")
531 dev
[0].scan_for_bss(apdev
[0]['bssid'], freq
=2412)
532 dev
[0].dump_monitor()
533 new_ssid
= "wps-new-ssid"
534 new_passphrase
= "1234567890"
535 dev
[0].wps_reg(apdev
[0]['bssid'], appin
, new_ssid
, "WPA2PSK", "CCMP",
537 status
= dev
[0].get_status()
538 if status
['wpa_state'] != 'COMPLETED' or status
['bssid'] != apdev
[0]['bssid']:
539 raise Exception("Not fully connected")
540 if status
['ssid'] != new_ssid
:
541 raise Exception("Unexpected SSID")
542 if status
['pairwise_cipher'] != 'CCMP' or status
['group_cipher'] != 'CCMP':
543 raise Exception("Unexpected encryption configuration")
544 if status
['key_mgmt'] != 'WPA2-PSK':
545 raise Exception("Unexpected key_mgmt")
547 logger
.info("Re-configure back to open")
548 dev
[0].request("REMOVE_NETWORK all")
549 dev
[0].flush_scan_cache()
550 dev
[0].dump_monitor()
551 dev
[0].wps_reg(apdev
[0]['bssid'], appin
, "wps-open", "OPEN", "NONE", "")
552 status
= dev
[0].get_status()
553 if status
['wpa_state'] != 'COMPLETED' or status
['bssid'] != apdev
[0]['bssid']:
554 raise Exception("Not fully connected")
555 if status
['ssid'] != "wps-open":
556 raise Exception("Unexpected SSID")
557 if status
['key_mgmt'] != 'NONE':
558 raise Exception("Unexpected key_mgmt")
560 def test_ap_wps_reg_config_ext_processing(dev
, apdev
):
561 """WPS registrar configuring an AP with external config processing"""
562 ssid
= "test-wps-init-ap-pin"
564 params
= { "ssid": ssid
, "eap_server": "1", "wps_state": "2",
565 "wps_cred_processing": "1", "ap_pin": appin
}
566 hapd
= hostapd
.add_ap(apdev
[0]['ifname'], params
)
567 dev
[0].scan_for_bss(apdev
[0]['bssid'], freq
=2412)
568 new_ssid
= "wps-new-ssid"
569 new_passphrase
= "1234567890"
570 dev
[0].wps_reg(apdev
[0]['bssid'], appin
, new_ssid
, "WPA2PSK", "CCMP",
571 new_passphrase
, no_wait
=True)
572 ev
= dev
[0].wait_event(["WPS-SUCCESS"], timeout
=15)
574 raise Exception("WPS registrar operation timed out")
575 ev
= hapd
.wait_event(["WPS-NEW-AP-SETTINGS"], timeout
=15)
577 raise Exception("WPS configuration timed out")
579 raise Exception("AP Settings missing from event")
580 hapd
.request("SET wps_cred_processing 0")
581 if "FAIL" in hapd
.request("WPS_CONFIG " + new_ssid
.encode("hex") + " WPA2PSK CCMP " + new_passphrase
.encode("hex")):
582 raise Exception("WPS_CONFIG command failed")
583 dev
[0].wait_connected(timeout
=15)
585 def test_ap_wps_reg_config_tkip(dev
, apdev
):
586 """WPS registrar configuring AP to use TKIP and AP upgrading to TKIP+CCMP"""
587 ssid
= "test-wps-init-ap"
589 hostapd
.add_ap(apdev
[0]['ifname'],
590 { "ssid": ssid
, "eap_server": "1", "wps_state": "1",
592 logger
.info("WPS configuration step")
593 dev
[0].request("SET wps_version_number 0x10")
594 dev
[0].scan_for_bss(apdev
[0]['bssid'], freq
=2412)
595 dev
[0].dump_monitor()
596 new_ssid
= "wps-new-ssid-with-tkip"
597 new_passphrase
= "1234567890"
598 dev
[0].wps_reg(apdev
[0]['bssid'], appin
, new_ssid
, "WPAPSK", "TKIP",
600 logger
.info("Re-connect to verify WPA2 mixed mode")
601 dev
[0].request("DISCONNECT")
603 dev
[0].set_network(id, "pairwise", "CCMP")
604 dev
[0].set_network(id, "proto", "RSN")
605 dev
[0].connect_network(id)
606 status
= dev
[0].get_status()
607 if status
['wpa_state'] != 'COMPLETED' or status
['bssid'] != apdev
[0]['bssid']:
608 raise Exception("Not fully connected: wpa_state={} bssid={}".format(status
['wpa_state'], status
['bssid']))
609 if status
['ssid'] != new_ssid
:
610 raise Exception("Unexpected SSID")
611 if status
['pairwise_cipher'] != 'CCMP' or status
['group_cipher'] != 'TKIP':
612 raise Exception("Unexpected encryption configuration")
613 if status
['key_mgmt'] != 'WPA2-PSK':
614 raise Exception("Unexpected key_mgmt")
616 def test_ap_wps_setup_locked(dev
, apdev
):
617 """WPS registrar locking up AP setup on AP PIN failures"""
618 ssid
= "test-wps-incorrect-ap-pin"
620 hostapd
.add_ap(apdev
[0]['ifname'],
621 { "ssid": ssid
, "eap_server": "1", "wps_state": "2",
622 "wpa_passphrase": "12345678", "wpa": "2",
623 "wpa_key_mgmt": "WPA-PSK", "rsn_pairwise": "CCMP",
625 new_ssid
= "wps-new-ssid-test"
626 new_passphrase
= "1234567890"
628 dev
[0].scan_for_bss(apdev
[0]['bssid'], freq
=2412)
629 ap_setup_locked
=False
630 for pin
in ["55554444", "1234", "12345678", "00000000", "11111111"]:
631 dev
[0].dump_monitor()
632 logger
.info("Try incorrect AP PIN - attempt " + pin
)
633 dev
[0].wps_reg(apdev
[0]['bssid'], pin
, new_ssid
, "WPA2PSK",
634 "CCMP", new_passphrase
, no_wait
=True)
635 ev
= dev
[0].wait_event(["WPS-FAIL", "CTRL-EVENT-CONNECTED"])
637 raise Exception("Timeout on receiving WPS operation failure event")
638 if "CTRL-EVENT-CONNECTED" in ev
:
639 raise Exception("Unexpected connection")
640 if "config_error=15" in ev
:
641 logger
.info("AP Setup Locked")
643 elif "config_error=18" not in ev
:
644 raise Exception("config_error=18 not reported")
645 dev
[0].wait_disconnected(timeout
=10)
647 if not ap_setup_locked
:
648 raise Exception("AP setup was not locked")
650 hapd
= hostapd
.Hostapd(apdev
[0]['ifname'])
651 status
= hapd
.request("WPS_GET_STATUS")
652 if "Last WPS result: Failed" not in status
:
653 raise Exception("WPS failure result not shown correctly")
654 if "Peer Address: " + dev
[0].p2p_interface_addr() not in status
:
655 raise Exception("Peer address not shown correctly")
658 dev
[0].dump_monitor()
659 logger
.info("WPS provisioning step")
660 pin
= dev
[0].wps_read_pin()
661 hapd
= hostapd
.Hostapd(apdev
[0]['ifname'])
662 hapd
.request("WPS_PIN any " + pin
)
663 dev
[0].request("WPS_PIN %s %s" % (apdev
[0]['bssid'], pin
))
664 ev
= dev
[0].wait_event(["WPS-SUCCESS"], timeout
=30)
666 raise Exception("WPS success was not reported")
667 dev
[0].wait_connected(timeout
=30)
669 appin
= hapd
.request("WPS_AP_PIN random")
671 raise Exception("Could not generate random AP PIN")
672 ev
= hapd
.wait_event(["WPS-AP-SETUP-UNLOCKED"], timeout
=10)
674 raise Exception("Failed to unlock AP PIN")
676 def test_ap_wps_setup_locked_timeout(dev
, apdev
):
677 """WPS re-enabling AP PIN after timeout"""
678 ssid
= "test-wps-incorrect-ap-pin"
680 hostapd
.add_ap(apdev
[0]['ifname'],
681 { "ssid": ssid
, "eap_server": "1", "wps_state": "2",
682 "wpa_passphrase": "12345678", "wpa": "2",
683 "wpa_key_mgmt": "WPA-PSK", "rsn_pairwise": "CCMP",
685 new_ssid
= "wps-new-ssid-test"
686 new_passphrase
= "1234567890"
688 dev
[0].scan_for_bss(apdev
[0]['bssid'], freq
=2412)
689 ap_setup_locked
=False
690 for pin
in ["55554444", "1234", "12345678", "00000000", "11111111"]:
691 dev
[0].dump_monitor()
692 logger
.info("Try incorrect AP PIN - attempt " + pin
)
693 dev
[0].wps_reg(apdev
[0]['bssid'], pin
, new_ssid
, "WPA2PSK",
694 "CCMP", new_passphrase
, no_wait
=True)
695 ev
= dev
[0].wait_event(["WPS-FAIL", "CTRL-EVENT-CONNECTED"], timeout
=15)
697 raise Exception("Timeout on receiving WPS operation failure event")
698 if "CTRL-EVENT-CONNECTED" in ev
:
699 raise Exception("Unexpected connection")
700 if "config_error=15" in ev
:
701 logger
.info("AP Setup Locked")
704 elif "config_error=18" not in ev
:
705 raise Exception("config_error=18 not reported")
706 dev
[0].wait_disconnected(timeout
=10)
708 if not ap_setup_locked
:
709 raise Exception("AP setup was not locked")
710 hapd
= hostapd
.Hostapd(apdev
[0]['ifname'])
711 ev
= hapd
.wait_event(["WPS-AP-SETUP-UNLOCKED"], timeout
=80)
713 raise Exception("AP PIN did not get unlocked on 60 second timeout")
715 def test_ap_wps_pbc_overlap_2ap(dev
, apdev
):
716 """WPS PBC session overlap with two active APs"""
717 hostapd
.add_ap(apdev
[0]['ifname'],
718 { "ssid": "wps1", "eap_server": "1", "wps_state": "2",
719 "wpa_passphrase": "12345678", "wpa": "2",
720 "wpa_key_mgmt": "WPA-PSK", "rsn_pairwise": "CCMP",
721 "wps_independent": "1"})
722 hostapd
.add_ap(apdev
[1]['ifname'],
723 { "ssid": "wps2", "eap_server": "1", "wps_state": "2",
724 "wpa_passphrase": "123456789", "wpa": "2",
725 "wpa_key_mgmt": "WPA-PSK", "rsn_pairwise": "CCMP",
726 "wps_independent": "1"})
727 hapd
= hostapd
.Hostapd(apdev
[0]['ifname'])
728 hapd
.request("WPS_PBC")
729 hapd2
= hostapd
.Hostapd(apdev
[1]['ifname'])
730 hapd2
.request("WPS_PBC")
731 logger
.info("WPS provisioning step")
732 dev
[0].scan_for_bss(apdev
[0]['bssid'], freq
="2412", force_scan
=True)
733 dev
[0].scan_for_bss(apdev
[1]['bssid'], freq
="2412")
734 dev
[0].request("WPS_PBC")
735 ev
= dev
[0].wait_event(["WPS-OVERLAP-DETECTED"], timeout
=15)
737 raise Exception("PBC session overlap not detected")
739 def test_ap_wps_pbc_overlap_2sta(dev
, apdev
):
740 """WPS PBC session overlap with two active STAs"""
741 ssid
= "test-wps-pbc-overlap"
742 hostapd
.add_ap(apdev
[0]['ifname'],
743 { "ssid": ssid
, "eap_server": "1", "wps_state": "2",
744 "wpa_passphrase": "12345678", "wpa": "2",
745 "wpa_key_mgmt": "WPA-PSK", "rsn_pairwise": "CCMP"})
746 hapd
= hostapd
.Hostapd(apdev
[0]['ifname'])
747 logger
.info("WPS provisioning step")
748 hapd
.request("WPS_PBC")
749 dev
[0].scan_for_bss(apdev
[0]['bssid'], freq
="2412")
750 dev
[0].dump_monitor()
751 dev
[1].scan_for_bss(apdev
[0]['bssid'], freq
="2412")
752 dev
[1].dump_monitor()
753 dev
[0].request("WPS_PBC " + apdev
[0]['bssid'])
754 dev
[1].request("WPS_PBC " + apdev
[0]['bssid'])
755 ev
= dev
[0].wait_event(["WPS-M2D"], timeout
=15)
757 raise Exception("PBC session overlap not detected (dev0)")
758 if "config_error=12" not in ev
:
759 raise Exception("PBC session overlap not correctly reported (dev0)")
760 ev
= dev
[1].wait_event(["WPS-M2D"], timeout
=15)
762 raise Exception("PBC session overlap not detected (dev1)")
763 if "config_error=12" not in ev
:
764 raise Exception("PBC session overlap not correctly reported (dev1)")
765 hapd
.request("WPS_CANCEL")
766 ret
= hapd
.request("WPS_PBC")
767 if "FAIL" not in ret
:
768 raise Exception("PBC mode allowed to be started while PBC overlap still active")
770 def test_ap_wps_cancel(dev
, apdev
):
771 """WPS AP cancelling enabled config method"""
772 ssid
= "test-wps-ap-cancel"
773 hostapd
.add_ap(apdev
[0]['ifname'],
774 { "ssid": ssid
, "eap_server": "1", "wps_state": "2",
775 "wpa_passphrase": "12345678", "wpa": "2",
776 "wpa_key_mgmt": "WPA-PSK", "rsn_pairwise": "CCMP" })
777 bssid
= apdev
[0]['bssid']
778 hapd
= hostapd
.Hostapd(apdev
[0]['ifname'])
780 logger
.info("Verify PBC enable/cancel")
781 hapd
.request("WPS_PBC")
782 dev
[0].scan(freq
="2412")
783 dev
[0].scan(freq
="2412")
784 bss
= dev
[0].get_bss(apdev
[0]['bssid'])
785 if "[WPS-PBC]" not in bss
['flags']:
786 raise Exception("WPS-PBC flag missing")
787 if "FAIL" in hapd
.request("WPS_CANCEL"):
788 raise Exception("WPS_CANCEL failed")
789 dev
[0].scan(freq
="2412")
790 dev
[0].scan(freq
="2412")
791 bss
= dev
[0].get_bss(apdev
[0]['bssid'])
792 if "[WPS-PBC]" in bss
['flags']:
793 raise Exception("WPS-PBC flag not cleared")
795 logger
.info("Verify PIN enable/cancel")
796 hapd
.request("WPS_PIN any 12345670")
797 dev
[0].scan(freq
="2412")
798 dev
[0].scan(freq
="2412")
799 bss
= dev
[0].get_bss(apdev
[0]['bssid'])
800 if "[WPS-AUTH]" not in bss
['flags']:
801 raise Exception("WPS-AUTH flag missing")
802 if "FAIL" in hapd
.request("WPS_CANCEL"):
803 raise Exception("WPS_CANCEL failed")
804 dev
[0].scan(freq
="2412")
805 dev
[0].scan(freq
="2412")
806 bss
= dev
[0].get_bss(apdev
[0]['bssid'])
807 if "[WPS-AUTH]" in bss
['flags']:
808 raise Exception("WPS-AUTH flag not cleared")
810 def test_ap_wps_er_add_enrollee(dev
, apdev
):
811 """WPS ER configuring AP and adding a new enrollee using PIN"""
813 _test_ap_wps_er_add_enrollee(dev
, apdev
)
815 dev
[0].request("WPS_ER_STOP")
817 def _test_ap_wps_er_add_enrollee(dev
, apdev
):
818 ssid
= "wps-er-add-enrollee"
820 ap_uuid
= "27ea801a-9e5c-4e73-bd82-f89cbcd10d7e"
821 hostapd
.add_ap(apdev
[0]['ifname'],
822 { "ssid": ssid
, "eap_server": "1", "wps_state": "1",
823 "device_name": "Wireless AP", "manufacturer": "Company",
824 "model_name": "WAP", "model_number": "123",
825 "serial_number": "12345", "device_type": "6-0050F204-1",
826 "os_version": "01020300",
827 "config_methods": "label push_button",
828 "ap_pin": ap_pin
, "uuid": ap_uuid
, "upnp_iface": "lo"})
829 logger
.info("WPS configuration step")
830 new_passphrase
= "1234567890"
831 dev
[0].dump_monitor()
832 dev
[0].scan_for_bss(apdev
[0]['bssid'], freq
=2412)
833 dev
[0].wps_reg(apdev
[0]['bssid'], ap_pin
, ssid
, "WPA2PSK", "CCMP",
835 status
= dev
[0].get_status()
836 if status
['wpa_state'] != 'COMPLETED' or status
['bssid'] != apdev
[0]['bssid']:
837 raise Exception("Not fully connected")
838 if status
['ssid'] != ssid
:
839 raise Exception("Unexpected SSID")
840 if status
['pairwise_cipher'] != 'CCMP' or status
['group_cipher'] != 'CCMP':
841 raise Exception("Unexpected encryption configuration")
842 if status
['key_mgmt'] != 'WPA2-PSK':
843 raise Exception("Unexpected key_mgmt")
845 logger
.info("Start ER")
846 dev
[0].request("WPS_ER_START ifname=lo")
847 ev
= dev
[0].wait_event(["WPS-ER-AP-ADD"], timeout
=15)
849 raise Exception("AP discovery timed out")
850 if ap_uuid
not in ev
:
851 raise Exception("Expected AP UUID not found")
853 logger
.info("Learn AP configuration through UPnP")
854 dev
[0].dump_monitor()
855 dev
[0].request("WPS_ER_LEARN " + ap_uuid
+ " " + ap_pin
)
856 ev
= dev
[0].wait_event(["WPS-ER-AP-SETTINGS"], timeout
=15)
858 raise Exception("AP learn timed out")
859 if ap_uuid
not in ev
:
860 raise Exception("Expected AP UUID not in settings")
861 if "ssid=" + ssid
not in ev
:
862 raise Exception("Expected SSID not in settings")
863 if "key=" + new_passphrase
not in ev
:
864 raise Exception("Expected passphrase not in settings")
865 ev
= dev
[0].wait_event(["WPS-FAIL"], timeout
=15)
867 raise Exception("WPS-FAIL after AP learn timed out")
870 logger
.info("Add Enrollee using ER")
871 pin
= dev
[1].wps_read_pin()
872 dev
[0].dump_monitor()
873 dev
[0].request("WPS_ER_PIN any " + pin
+ " " + dev
[1].p2p_interface_addr())
874 dev
[1].scan_for_bss(apdev
[0]['bssid'], freq
=2412)
875 dev
[1].dump_monitor()
876 dev
[1].request("WPS_PIN %s %s" % (apdev
[0]['bssid'], pin
))
877 ev
= dev
[1].wait_event(["WPS-SUCCESS"], timeout
=30)
879 raise Exception("Enrollee did not report success")
880 dev
[1].wait_connected(timeout
=15)
881 ev
= dev
[0].wait_event(["WPS-SUCCESS"], timeout
=15)
883 raise Exception("WPS ER did not report success")
884 hwsim_utils
.test_connectivity_sta(dev
[0], dev
[1])
886 logger
.info("Add a specific Enrollee using ER")
887 pin
= dev
[2].wps_read_pin()
888 addr2
= dev
[2].p2p_interface_addr()
889 dev
[0].dump_monitor()
890 dev
[2].scan_for_bss(apdev
[0]['bssid'], freq
=2412)
891 dev
[2].dump_monitor()
892 dev
[2].request("WPS_PIN %s %s" % (apdev
[0]['bssid'], pin
))
893 ev
= dev
[0].wait_event(["WPS-ER-ENROLLEE-ADD"], timeout
=10)
895 raise Exception("Enrollee not seen")
897 raise Exception("Unexpected Enrollee MAC address")
898 dev
[0].request("WPS_ER_PIN " + addr2
+ " " + pin
+ " " + addr2
)
899 dev
[2].wait_connected(timeout
=30)
900 ev
= dev
[0].wait_event(["WPS-SUCCESS"], timeout
=15)
902 raise Exception("WPS ER did not report success")
904 logger
.info("Verify registrar selection behavior")
905 dev
[0].request("WPS_ER_PIN any " + pin
+ " " + dev
[1].p2p_interface_addr())
906 dev
[1].request("DISCONNECT")
907 dev
[1].wait_disconnected(timeout
=10)
908 dev
[1].scan_for_bss(apdev
[0]['bssid'], freq
="2412")
909 dev
[1].scan(freq
="2412")
910 bss
= dev
[1].get_bss(apdev
[0]['bssid'])
911 if "[WPS-AUTH]" not in bss
['flags']:
912 # It is possible for scan to miss an update especially when running
913 # tests under load with multiple VMs, so allow another attempt.
914 dev
[1].scan(freq
="2412")
915 bss
= dev
[1].get_bss(apdev
[0]['bssid'])
916 if "[WPS-AUTH]" not in bss
['flags']:
917 raise Exception("WPS-AUTH flag missing")
919 logger
.info("Stop ER")
920 dev
[0].dump_monitor()
921 dev
[0].request("WPS_ER_STOP")
922 ev
= dev
[0].wait_event(["WPS-ER-AP-REMOVE"])
924 raise Exception("WPS ER unsubscription timed out")
925 # It takes some time for the UPnP UNSUBSCRIBE command to go through, so wait
926 # a bit before verifying that the scan results have changed.
929 for i
in range(0, 10):
930 dev
[1].request("BSS_FLUSH 0")
931 dev
[1].scan(freq
="2412", only_new
=True)
932 bss
= dev
[1].get_bss(apdev
[0]['bssid'])
933 if bss
and 'flags' in bss
and "[WPS-AUTH]" not in bss
['flags']:
935 logger
.debug("WPS-AUTH flag was still in place - wait a bit longer")
937 if "[WPS-AUTH]" in bss
['flags']:
938 raise Exception("WPS-AUTH flag not removed")
940 def test_ap_wps_er_add_enrollee_pbc(dev
, apdev
):
941 """WPS ER connected to AP and adding a new enrollee using PBC"""
943 _test_ap_wps_er_add_enrollee_pbc(dev
, apdev
)
945 dev
[0].request("WPS_ER_STOP")
947 def _test_ap_wps_er_add_enrollee_pbc(dev
, apdev
):
948 ssid
= "wps-er-add-enrollee-pbc"
950 ap_uuid
= "27ea801a-9e5c-4e73-bd82-f89cbcd10d7e"
951 hostapd
.add_ap(apdev
[0]['ifname'],
952 { "ssid": ssid
, "eap_server": "1", "wps_state": "2",
953 "wpa_passphrase": "12345678", "wpa": "2",
954 "wpa_key_mgmt": "WPA-PSK", "rsn_pairwise": "CCMP",
955 "device_name": "Wireless AP", "manufacturer": "Company",
956 "model_name": "WAP", "model_number": "123",
957 "serial_number": "12345", "device_type": "6-0050F204-1",
958 "os_version": "01020300",
959 "config_methods": "label push_button",
960 "ap_pin": ap_pin
, "uuid": ap_uuid
, "upnp_iface": "lo"})
961 logger
.info("Learn AP configuration")
962 dev
[0].scan_for_bss(apdev
[0]['bssid'], freq
=2412)
963 dev
[0].dump_monitor()
964 dev
[0].wps_reg(apdev
[0]['bssid'], ap_pin
)
965 status
= dev
[0].get_status()
966 if status
['wpa_state'] != 'COMPLETED' or status
['bssid'] != apdev
[0]['bssid']:
967 raise Exception("Not fully connected")
969 logger
.info("Start ER")
970 dev
[0].request("WPS_ER_START ifname=lo")
971 ev
= dev
[0].wait_event(["WPS-ER-AP-ADD"], timeout
=15)
973 raise Exception("AP discovery timed out")
974 if ap_uuid
not in ev
:
975 raise Exception("Expected AP UUID not found")
977 enrollee
= dev
[1].p2p_interface_addr()
979 if "FAIL-UNKNOWN-UUID" not in dev
[0].request("WPS_ER_PBC " + enrollee
):
980 raise Exception("Unknown UUID not reported")
982 logger
.info("Add Enrollee using ER and PBC")
983 dev
[0].dump_monitor()
984 dev
[1].dump_monitor()
985 dev
[1].request("WPS_PBC")
987 for i
in range(0, 2):
988 ev
= dev
[0].wait_event(["WPS-ER-ENROLLEE-ADD"], timeout
=15)
990 raise Exception("Enrollee discovery timed out")
994 raise Exception("Expected Enrollee not found")
995 if "FAIL-NO-AP-SETTINGS" not in dev
[0].request("WPS_ER_PBC " + enrollee
):
996 raise Exception("Unknown UUID not reported")
997 logger
.info("Use learned network configuration on ER")
998 dev
[0].request("WPS_ER_SET_CONFIG " + ap_uuid
+ " 0")
999 if "OK" not in dev
[0].request("WPS_ER_PBC " + enrollee
):
1000 raise Exception("WPS_ER_PBC failed")
1002 ev
= dev
[1].wait_event(["WPS-SUCCESS"], timeout
=15)
1004 raise Exception("Enrollee did not report success")
1005 dev
[1].wait_connected(timeout
=15)
1006 ev
= dev
[0].wait_event(["WPS-SUCCESS"], timeout
=15)
1008 raise Exception("WPS ER did not report success")
1009 hwsim_utils
.test_connectivity_sta(dev
[0], dev
[1])
1011 def test_ap_wps_er_pbc_overlap(dev
, apdev
):
1012 """WPS ER connected to AP and PBC session overlap"""
1014 _test_ap_wps_er_pbc_overlap(dev
, apdev
)
1016 dev
[0].request("WPS_ER_STOP")
1018 def _test_ap_wps_er_pbc_overlap(dev
, apdev
):
1019 ssid
= "wps-er-add-enrollee-pbc"
1021 ap_uuid
= "27ea801a-9e5c-4e73-bd82-f89cbcd10d7e"
1022 hostapd
.add_ap(apdev
[0]['ifname'],
1023 { "ssid": ssid
, "eap_server": "1", "wps_state": "2",
1024 "wpa_passphrase": "12345678", "wpa": "2",
1025 "wpa_key_mgmt": "WPA-PSK", "rsn_pairwise": "CCMP",
1026 "device_name": "Wireless AP", "manufacturer": "Company",
1027 "model_name": "WAP", "model_number": "123",
1028 "serial_number": "12345", "device_type": "6-0050F204-1",
1029 "os_version": "01020300",
1030 "config_methods": "label push_button",
1031 "ap_pin": ap_pin
, "uuid": ap_uuid
, "upnp_iface": "lo"})
1032 dev
[0].scan_for_bss(apdev
[0]['bssid'], freq
=2412)
1033 dev
[0].dump_monitor()
1034 dev
[0].wps_reg(apdev
[0]['bssid'], ap_pin
)
1036 dev
[0].dump_monitor()
1037 dev
[0].request("WPS_ER_START ifname=lo")
1039 ev
= dev
[0].wait_event(["WPS-ER-AP-ADD"], timeout
=15)
1041 raise Exception("AP discovery timed out")
1042 if ap_uuid
not in ev
:
1043 raise Exception("Expected AP UUID not found")
1045 # verify BSSID selection of the AP instead of UUID
1046 if "FAIL" in dev
[0].request("WPS_ER_SET_CONFIG " + apdev
[0]['bssid'] + " 0"):
1047 raise Exception("Could not select AP based on BSSID")
1049 dev
[1].scan_for_bss(apdev
[0]['bssid'], freq
="2412")
1050 dev
[2].scan_for_bss(apdev
[0]['bssid'], freq
="2412")
1051 dev
[1].request("WPS_PBC " + apdev
[0]['bssid'])
1052 dev
[2].request("WPS_PBC " + apdev
[0]['bssid'])
1053 ev
= dev
[1].wait_event(["CTRL-EVENT-SCAN-RESULTS"], timeout
=10)
1055 raise Exception("PBC scan failed")
1056 ev
= dev
[2].wait_event(["CTRL-EVENT-SCAN-RESULTS"], timeout
=10)
1058 raise Exception("PBC scan failed")
1059 for i
in range(0, 2):
1060 ev
= dev
[0].wait_event(["WPS-ER-ENROLLEE-ADD"], timeout
=15)
1062 raise Exception("Enrollee discovery timed out")
1063 if dev
[0].request("WPS_ER_PBC " + ap_uuid
) != "FAIL-PBC-OVERLAP\n":
1064 raise Exception("PBC overlap not reported")
1065 dev
[1].request("WPS_CANCEL")
1066 dev
[2].request("WPS_CANCEL")
1067 if dev
[0].request("WPS_ER_PBC foo") != "FAIL\n":
1068 raise Exception("Invalid WPS_ER_PBC accepted")
1070 def test_ap_wps_er_v10_add_enrollee_pin(dev
, apdev
):
1071 """WPS v1.0 ER connected to AP and adding a new enrollee using PIN"""
1073 _test_ap_wps_er_v10_add_enrollee_pin(dev
, apdev
)
1075 dev
[0].request("WPS_ER_STOP")
1077 def _test_ap_wps_er_v10_add_enrollee_pin(dev
, apdev
):
1078 ssid
= "wps-er-add-enrollee-pbc"
1080 ap_uuid
= "27ea801a-9e5c-4e73-bd82-f89cbcd10d7e"
1081 hostapd
.add_ap(apdev
[0]['ifname'],
1082 { "ssid": ssid
, "eap_server": "1", "wps_state": "2",
1083 "wpa_passphrase": "12345678", "wpa": "2",
1084 "wpa_key_mgmt": "WPA-PSK", "rsn_pairwise": "CCMP",
1085 "device_name": "Wireless AP", "manufacturer": "Company",
1086 "model_name": "WAP", "model_number": "123",
1087 "serial_number": "12345", "device_type": "6-0050F204-1",
1088 "os_version": "01020300",
1089 "config_methods": "label push_button",
1090 "ap_pin": ap_pin
, "uuid": ap_uuid
, "upnp_iface": "lo"})
1091 logger
.info("Learn AP configuration")
1092 dev
[0].request("SET wps_version_number 0x10")
1093 dev
[0].scan_for_bss(apdev
[0]['bssid'], freq
=2412)
1094 dev
[0].dump_monitor()
1095 dev
[0].wps_reg(apdev
[0]['bssid'], ap_pin
)
1096 status
= dev
[0].get_status()
1097 if status
['wpa_state'] != 'COMPLETED' or status
['bssid'] != apdev
[0]['bssid']:
1098 raise Exception("Not fully connected")
1100 logger
.info("Start ER")
1101 dev
[0].request("WPS_ER_START ifname=lo")
1102 ev
= dev
[0].wait_event(["WPS-ER-AP-ADD"], timeout
=15)
1104 raise Exception("AP discovery timed out")
1105 if ap_uuid
not in ev
:
1106 raise Exception("Expected AP UUID not found")
1108 logger
.info("Use learned network configuration on ER")
1109 dev
[0].request("WPS_ER_SET_CONFIG " + ap_uuid
+ " 0")
1111 logger
.info("Add Enrollee using ER and PIN")
1112 enrollee
= dev
[1].p2p_interface_addr()
1113 pin
= dev
[1].wps_read_pin()
1114 dev
[0].dump_monitor()
1115 dev
[0].request("WPS_ER_PIN any " + pin
+ " " + enrollee
)
1116 dev
[1].scan_for_bss(apdev
[0]['bssid'], freq
=2412)
1117 dev
[1].dump_monitor()
1118 dev
[1].request("WPS_PIN %s %s" % (apdev
[0]['bssid'], pin
))
1119 dev
[1].wait_connected(timeout
=30)
1120 ev
= dev
[0].wait_event(["WPS-SUCCESS"], timeout
=15)
1122 raise Exception("WPS ER did not report success")
1124 def test_ap_wps_er_config_ap(dev
, apdev
):
1125 """WPS ER configuring AP over UPnP"""
1127 _test_ap_wps_er_config_ap(dev
, apdev
)
1129 dev
[0].request("WPS_ER_STOP")
1131 def _test_ap_wps_er_config_ap(dev
, apdev
):
1132 ssid
= "wps-er-ap-config"
1134 ap_uuid
= "27ea801a-9e5c-4e73-bd82-f89cbcd10d7e"
1135 hostapd
.add_ap(apdev
[0]['ifname'],
1136 { "ssid": ssid
, "eap_server": "1", "wps_state": "2",
1137 "wpa_passphrase": "12345678", "wpa": "2",
1138 "wpa_key_mgmt": "WPA-PSK", "rsn_pairwise": "CCMP",
1139 "device_name": "Wireless AP", "manufacturer": "Company",
1140 "model_name": "WAP", "model_number": "123",
1141 "serial_number": "12345", "device_type": "6-0050F204-1",
1142 "os_version": "01020300",
1143 "config_methods": "label push_button",
1144 "ap_pin": ap_pin
, "uuid": ap_uuid
, "upnp_iface": "lo"})
1146 logger
.info("Connect ER to the AP")
1147 dev
[0].connect(ssid
, psk
="12345678", scan_freq
="2412")
1149 logger
.info("WPS configuration step")
1150 dev
[0].request("WPS_ER_START ifname=lo")
1151 ev
= dev
[0].wait_event(["WPS-ER-AP-ADD"], timeout
=15)
1153 raise Exception("AP discovery timed out")
1154 if ap_uuid
not in ev
:
1155 raise Exception("Expected AP UUID not found")
1156 new_passphrase
= "1234567890"
1157 dev
[0].request("WPS_ER_CONFIG " + apdev
[0]['bssid'] + " " + ap_pin
+ " " +
1158 ssid
.encode("hex") + " WPA2PSK CCMP " +
1159 new_passphrase
.encode("hex"))
1160 ev
= dev
[0].wait_event(["WPS-SUCCESS"])
1162 raise Exception("WPS ER configuration operation timed out")
1163 dev
[0].wait_disconnected(timeout
=10)
1164 dev
[0].connect(ssid
, psk
="1234567890", scan_freq
="2412")
1166 logger
.info("WPS ER restart")
1167 dev
[0].request("WPS_ER_START")
1168 ev
= dev
[0].wait_event(["WPS-ER-AP-ADD"], timeout
=15)
1170 raise Exception("AP discovery timed out on ER restart")
1171 if ap_uuid
not in ev
:
1172 raise Exception("Expected AP UUID not found on ER restart")
1173 if "OK" not in dev
[0].request("WPS_ER_STOP"):
1174 raise Exception("WPS_ER_STOP failed")
1175 if "OK" not in dev
[0].request("WPS_ER_STOP"):
1176 raise Exception("WPS_ER_STOP failed")
1178 def test_ap_wps_fragmentation(dev
, apdev
):
1179 """WPS with fragmentation in EAP-WSC and mixed mode WPA+WPA2"""
1180 ssid
= "test-wps-fragmentation"
1182 hostapd
.add_ap(apdev
[0]['ifname'],
1183 { "ssid": ssid
, "eap_server": "1", "wps_state": "2",
1184 "wpa_passphrase": "12345678", "wpa": "3",
1185 "wpa_key_mgmt": "WPA-PSK", "rsn_pairwise": "CCMP",
1186 "wpa_pairwise": "TKIP", "ap_pin": appin
,
1187 "fragment_size": "50" })
1188 hapd
= hostapd
.Hostapd(apdev
[0]['ifname'])
1189 logger
.info("WPS provisioning step (PBC)")
1190 hapd
.request("WPS_PBC")
1191 dev
[0].scan_for_bss(apdev
[0]['bssid'], freq
=2412)
1192 dev
[0].dump_monitor()
1193 dev
[0].request("SET wps_fragment_size 50")
1194 dev
[0].request("WPS_PBC " + apdev
[0]['bssid'])
1195 dev
[0].wait_connected(timeout
=30)
1196 status
= dev
[0].get_status()
1197 if status
['wpa_state'] != 'COMPLETED':
1198 raise Exception("Not fully connected")
1199 if status
['pairwise_cipher'] != 'CCMP' or status
['group_cipher'] != 'TKIP':
1200 raise Exception("Unexpected encryption configuration")
1201 if status
['key_mgmt'] != 'WPA2-PSK':
1202 raise Exception("Unexpected key_mgmt")
1204 logger
.info("WPS provisioning step (PIN)")
1205 pin
= dev
[1].wps_read_pin()
1206 hapd
.request("WPS_PIN any " + pin
)
1207 dev
[1].scan_for_bss(apdev
[0]['bssid'], freq
=2412)
1208 dev
[1].request("SET wps_fragment_size 50")
1209 dev
[1].request("WPS_PIN %s %s" % (apdev
[0]['bssid'], pin
))
1210 dev
[1].wait_connected(timeout
=30)
1211 status
= dev
[1].get_status()
1212 if status
['wpa_state'] != 'COMPLETED':
1213 raise Exception("Not fully connected")
1214 if status
['pairwise_cipher'] != 'CCMP' or status
['group_cipher'] != 'TKIP':
1215 raise Exception("Unexpected encryption configuration")
1216 if status
['key_mgmt'] != 'WPA2-PSK':
1217 raise Exception("Unexpected key_mgmt")
1219 logger
.info("WPS connection as registrar")
1220 dev
[2].scan_for_bss(apdev
[0]['bssid'], freq
=2412)
1221 dev
[2].request("SET wps_fragment_size 50")
1222 dev
[2].wps_reg(apdev
[0]['bssid'], appin
)
1223 status
= dev
[2].get_status()
1224 if status
['wpa_state'] != 'COMPLETED':
1225 raise Exception("Not fully connected")
1226 if status
['pairwise_cipher'] != 'CCMP' or status
['group_cipher'] != 'TKIP':
1227 raise Exception("Unexpected encryption configuration")
1228 if status
['key_mgmt'] != 'WPA2-PSK':
1229 raise Exception("Unexpected key_mgmt")
1231 def test_ap_wps_new_version_sta(dev
, apdev
):
1232 """WPS compatibility with new version number on the station"""
1233 ssid
= "test-wps-ver"
1234 hostapd
.add_ap(apdev
[0]['ifname'],
1235 { "ssid": ssid
, "eap_server": "1", "wps_state": "2",
1236 "wpa_passphrase": "12345678", "wpa": "2",
1237 "wpa_key_mgmt": "WPA-PSK", "rsn_pairwise": "CCMP" })
1238 hapd
= hostapd
.Hostapd(apdev
[0]['ifname'])
1239 logger
.info("WPS provisioning step")
1240 hapd
.request("WPS_PBC")
1241 dev
[0].scan_for_bss(apdev
[0]['bssid'], freq
="2412")
1242 dev
[0].dump_monitor()
1243 dev
[0].request("SET wps_version_number 0x43")
1244 dev
[0].request("SET wps_vendor_ext_m1 000137100100020001")
1245 dev
[0].request("WPS_PBC " + apdev
[0]['bssid'])
1246 dev
[0].wait_connected(timeout
=30)
1248 def test_ap_wps_new_version_ap(dev
, apdev
):
1249 """WPS compatibility with new version number on the AP"""
1250 ssid
= "test-wps-ver"
1251 hostapd
.add_ap(apdev
[0]['ifname'],
1252 { "ssid": ssid
, "eap_server": "1", "wps_state": "2",
1253 "wpa_passphrase": "12345678", "wpa": "2",
1254 "wpa_key_mgmt": "WPA-PSK", "rsn_pairwise": "CCMP" })
1255 hapd
= hostapd
.Hostapd(apdev
[0]['ifname'])
1256 logger
.info("WPS provisioning step")
1257 if "FAIL" in hapd
.request("SET wps_version_number 0x43"):
1258 raise Exception("Failed to enable test functionality")
1259 hapd
.request("WPS_PBC")
1260 dev
[0].scan_for_bss(apdev
[0]['bssid'], freq
="2412")
1261 dev
[0].dump_monitor()
1262 dev
[0].request("WPS_PBC " + apdev
[0]['bssid'])
1263 dev
[0].wait_connected(timeout
=30)
1264 hapd
.request("SET wps_version_number 0x20")
1266 def test_ap_wps_check_pin(dev
, apdev
):
1267 """Verify PIN checking through control interface"""
1268 hostapd
.add_ap(apdev
[0]['ifname'],
1269 { "ssid": "wps", "eap_server": "1", "wps_state": "2",
1270 "wpa_passphrase": "12345678", "wpa": "2",
1271 "wpa_key_mgmt": "WPA-PSK", "rsn_pairwise": "CCMP" })
1272 hapd
= hostapd
.Hostapd(apdev
[0]['ifname'])
1273 for t
in [ ("12345670", "12345670"),
1274 ("12345678", "FAIL-CHECKSUM"),
1276 ("123456789", "FAIL"),
1277 ("1234-5670", "12345670"),
1278 ("1234 5670", "12345670"),
1279 ("1-2.3:4 5670", "12345670") ]:
1280 res
= hapd
.request("WPS_CHECK_PIN " + t
[0]).rstrip('\n')
1281 res2
= dev
[0].request("WPS_CHECK_PIN " + t
[0]).rstrip('\n')
1283 raise Exception("Unexpected difference in WPS_CHECK_PIN responses")
1285 raise Exception("Incorrect WPS_CHECK_PIN response {} (expected {})".format(res
, t
[1]))
1287 if "FAIL" not in hapd
.request("WPS_CHECK_PIN 12345"):
1288 raise Exception("Unexpected WPS_CHECK_PIN success")
1289 if "FAIL" not in hapd
.request("WPS_CHECK_PIN 123456789"):
1290 raise Exception("Unexpected WPS_CHECK_PIN success")
1292 for i
in range(0, 10):
1293 pin
= dev
[0].request("WPS_PIN get")
1294 rpin
= dev
[0].request("WPS_CHECK_PIN " + pin
).rstrip('\n')
1296 raise Exception("Random PIN validation failed for " + pin
)
1298 def test_ap_wps_wep_config(dev
, apdev
):
1299 """WPS 2.0 AP rejecting WEP configuration"""
1300 ssid
= "test-wps-config"
1302 hostapd
.add_ap(apdev
[0]['ifname'],
1303 { "ssid": ssid
, "eap_server": "1", "wps_state": "2",
1305 hapd
= hostapd
.Hostapd(apdev
[0]['ifname'])
1306 dev
[0].scan_for_bss(apdev
[0]['bssid'], freq
=2412)
1307 dev
[0].wps_reg(apdev
[0]['bssid'], appin
, "wps-new-ssid-wep", "OPEN", "WEP",
1308 "hello", no_wait
=True)
1309 ev
= hapd
.wait_event(["WPS-FAIL"], timeout
=15)
1311 raise Exception("WPS-FAIL timed out")
1312 if "reason=2" not in ev
:
1313 raise Exception("Unexpected reason code in WPS-FAIL")
1314 status
= hapd
.request("WPS_GET_STATUS")
1315 if "Last WPS result: Failed" not in status
:
1316 raise Exception("WPS failure result not shown correctly")
1317 if "Failure Reason: WEP Prohibited" not in status
:
1318 raise Exception("Failure reason not reported correctly")
1319 if "Peer Address: " + dev
[0].p2p_interface_addr() not in status
:
1320 raise Exception("Peer address not shown correctly")
1322 def test_ap_wps_wep_enroll(dev
, apdev
):
1323 """WPS 2.0 STA rejecting WEP configuration"""
1324 ssid
= "test-wps-wep"
1325 hostapd
.add_ap(apdev
[0]['ifname'],
1326 { "ssid": ssid
, "eap_server": "1", "wps_state": "2",
1327 "skip_cred_build": "1", "extra_cred": "wps-wep-cred" })
1328 hapd
= hostapd
.Hostapd(apdev
[0]['ifname'])
1329 hapd
.request("WPS_PBC")
1330 dev
[0].scan_for_bss(apdev
[0]['bssid'], freq
=2412)
1331 dev
[0].request("WPS_PBC " + apdev
[0]['bssid'])
1332 ev
= dev
[0].wait_event(["WPS-FAIL"], timeout
=15)
1334 raise Exception("WPS-FAIL event timed out")
1335 if "msg=12" not in ev
or "reason=2 (WEP Prohibited)" not in ev
:
1336 raise Exception("Unexpected WPS-FAIL event: " + ev
)
1338 def test_ap_wps_ie_fragmentation(dev
, apdev
):
1339 """WPS AP using fragmented WPS IE"""
1340 ssid
= "test-wps-ie-fragmentation"
1341 params
= { "ssid": ssid
, "eap_server": "1", "wps_state": "2",
1342 "wpa_passphrase": "12345678", "wpa": "2",
1343 "wpa_key_mgmt": "WPA-PSK", "rsn_pairwise": "CCMP",
1344 "device_name": "1234567890abcdef1234567890abcdef",
1345 "manufacturer": "1234567890abcdef1234567890abcdef1234567890abcdef1234567890abcdef",
1346 "model_name": "1234567890abcdef1234567890abcdef",
1347 "model_number": "1234567890abcdef1234567890abcdef",
1348 "serial_number": "1234567890abcdef1234567890abcdef" }
1349 hostapd
.add_ap(apdev
[0]['ifname'], params
)
1350 hapd
= hostapd
.Hostapd(apdev
[0]['ifname'])
1351 hapd
.request("WPS_PBC")
1352 dev
[0].scan_for_bss(apdev
[0]['bssid'], freq
="2412")
1353 dev
[0].request("WPS_PBC " + apdev
[0]['bssid'])
1354 dev
[0].wait_connected(timeout
=30)
1355 bss
= dev
[0].get_bss(apdev
[0]['bssid'])
1356 if "wps_device_name" not in bss
or bss
['wps_device_name'] != "1234567890abcdef1234567890abcdef":
1357 logger
.info("Device Name not received correctly")
1359 # This can fail if Probe Response frame is missed and Beacon frame was
1360 # used to fill in the BSS entry. This can happen, e.g., during heavy
1361 # load every now and then and is not really an error, so try to
1362 # workaround by runnign another scan.
1363 dev
[0].scan(freq
="2412", only_new
=True)
1364 bss
= dev
[0].get_bss(apdev
[0]['bssid'])
1365 if not bss
or "wps_device_name" not in bss
or bss
['wps_device_name'] != "1234567890abcdef1234567890abcdef":
1367 raise Exception("Device Name not received correctly")
1368 if len(re
.findall("dd..0050f204", bss
['ie'])) != 2:
1369 raise Exception("Unexpected number of WPS IEs")
1371 def get_psk(pskfile
):
1373 with
open(pskfile
, "r") as f
:
1374 lines
= f
.read().splitlines()
1376 if l
== "# WPA PSKs":
1378 (addr
,psk
) = l
.split(' ')
1382 def test_ap_wps_per_station_psk(dev
, apdev
):
1383 """WPS PBC provisioning with per-station PSK"""
1384 addr0
= dev
[0].p2p_dev_addr()
1385 addr1
= dev
[1].p2p_dev_addr()
1386 addr2
= dev
[2].p2p_dev_addr()
1389 pskfile
= "/tmp/ap_wps_per_enrollee_psk.psk_file"
1396 with
open(pskfile
, "w") as f
:
1397 f
.write("# WPA PSKs\n")
1399 params
= { "ssid": ssid
, "eap_server": "1", "wps_state": "2",
1400 "wpa": "2", "wpa_key_mgmt": "WPA-PSK",
1401 "rsn_pairwise": "CCMP", "ap_pin": appin
,
1402 "wpa_psk_file": pskfile
}
1403 hapd
= hostapd
.add_ap(apdev
[0]['ifname'], params
)
1405 logger
.info("First enrollee")
1406 hapd
.request("WPS_PBC")
1407 dev
[0].scan_for_bss(apdev
[0]['bssid'], freq
=2412)
1408 dev
[0].request("WPS_PBC " + apdev
[0]['bssid'])
1409 dev
[0].wait_connected(timeout
=30)
1411 logger
.info("Second enrollee")
1412 hapd
.request("WPS_PBC")
1413 dev
[1].scan_for_bss(apdev
[0]['bssid'], freq
=2412)
1414 dev
[1].request("WPS_PBC " + apdev
[0]['bssid'])
1415 dev
[1].wait_connected(timeout
=30)
1417 logger
.info("External registrar")
1418 dev
[2].scan_for_bss(apdev
[0]['bssid'], freq
=2412)
1419 dev
[2].wps_reg(apdev
[0]['bssid'], appin
)
1421 logger
.info("Verifying PSK results")
1422 psks
= get_psk(pskfile
)
1423 if addr0
not in psks
:
1424 raise Exception("No PSK recorded for sta0")
1425 if addr1
not in psks
:
1426 raise Exception("No PSK recorded for sta1")
1427 if addr2
not in psks
:
1428 raise Exception("No PSK recorded for sta2")
1429 if psks
[addr0
] == psks
[addr1
]:
1430 raise Exception("Same PSK recorded for sta0 and sta1")
1431 if psks
[addr0
] == psks
[addr2
]:
1432 raise Exception("Same PSK recorded for sta0 and sta2")
1433 if psks
[addr1
] == psks
[addr2
]:
1434 raise Exception("Same PSK recorded for sta1 and sta2")
1436 dev
[0].request("REMOVE_NETWORK all")
1437 logger
.info("Second external registrar")
1438 dev
[0].scan_for_bss(apdev
[0]['bssid'], freq
=2412)
1439 dev
[0].wps_reg(apdev
[0]['bssid'], appin
)
1440 psks2
= get_psk(pskfile
)
1441 if addr0
not in psks2
:
1442 raise Exception("No PSK recorded for sta0(reg)")
1443 if psks
[addr0
] == psks2
[addr0
]:
1444 raise Exception("Same PSK recorded for sta0(enrollee) and sta0(reg)")
1448 def test_ap_wps_per_station_psk_failure(dev
, apdev
):
1449 """WPS PBC provisioning with per-station PSK (file not writable)"""
1450 addr0
= dev
[0].p2p_dev_addr()
1451 addr1
= dev
[1].p2p_dev_addr()
1452 addr2
= dev
[2].p2p_dev_addr()
1455 pskfile
= "/tmp/ap_wps_per_enrollee_psk.psk_file"
1462 with
open(pskfile
, "w") as f
:
1463 f
.write("# WPA PSKs\n")
1465 params
= { "ssid": ssid
, "eap_server": "1", "wps_state": "2",
1466 "wpa": "2", "wpa_key_mgmt": "WPA-PSK",
1467 "rsn_pairwise": "CCMP", "ap_pin": appin
,
1468 "wpa_psk_file": pskfile
}
1469 hapd
= hostapd
.add_ap(apdev
[0]['ifname'], params
)
1470 if "FAIL" in hapd
.request("SET wpa_psk_file /tmp/does/not/exists/ap_wps_per_enrollee_psk_failure.psk_file"):
1471 raise Exception("Failed to set wpa_psk_file")
1473 logger
.info("First enrollee")
1474 hapd
.request("WPS_PBC")
1475 dev
[0].scan_for_bss(apdev
[0]['bssid'], freq
=2412)
1476 dev
[0].request("WPS_PBC " + apdev
[0]['bssid'])
1477 dev
[0].wait_connected(timeout
=30)
1479 logger
.info("Second enrollee")
1480 hapd
.request("WPS_PBC")
1481 dev
[1].scan_for_bss(apdev
[0]['bssid'], freq
=2412)
1482 dev
[1].request("WPS_PBC " + apdev
[0]['bssid'])
1483 dev
[1].wait_connected(timeout
=30)
1485 logger
.info("External registrar")
1486 dev
[2].scan_for_bss(apdev
[0]['bssid'], freq
=2412)
1487 dev
[2].wps_reg(apdev
[0]['bssid'], appin
)
1489 logger
.info("Verifying PSK results")
1490 psks
= get_psk(pskfile
)
1492 raise Exception("PSK recorded unexpectedly")
1496 def test_ap_wps_pin_request_file(dev
, apdev
):
1497 """WPS PIN provisioning with configured AP"""
1499 pinfile
= "/tmp/ap_wps_pin_request_file.log"
1500 if os
.path
.exists(pinfile
):
1501 subprocess
.call(['sudo', 'rm', pinfile
])
1502 hostapd
.add_ap(apdev
[0]['ifname'],
1503 { "ssid": ssid
, "eap_server": "1", "wps_state": "2",
1504 "wps_pin_requests": pinfile
,
1505 "wpa_passphrase": "12345678", "wpa": "2",
1506 "wpa_key_mgmt": "WPA-PSK", "rsn_pairwise": "CCMP"})
1507 hapd
= hostapd
.Hostapd(apdev
[0]['ifname'])
1508 uuid
= dev
[0].get_status_field("uuid")
1509 pin
= dev
[0].wps_read_pin()
1511 dev
[0].scan_for_bss(apdev
[0]['bssid'], freq
="2412")
1512 dev
[0].request("WPS_PIN %s %s" % (apdev
[0]['bssid'], pin
))
1513 ev
= hapd
.wait_event(["WPS-PIN-NEEDED"], timeout
=15)
1515 raise Exception("PIN needed event not shown")
1517 raise Exception("UUID mismatch")
1518 dev
[0].request("WPS_CANCEL")
1520 with
open(pinfile
, "r") as f
:
1521 lines
= f
.readlines()
1527 raise Exception("PIN request entry not in the log file")
1529 subprocess
.call(['sudo', 'rm', pinfile
])
1531 def test_ap_wps_auto_setup_with_config_file(dev
, apdev
):
1532 """WPS auto-setup with configuration file"""
1533 conffile
= "/tmp/ap_wps_auto_setup_with_config_file.conf"
1534 ifname
= apdev
[0]['ifname']
1536 with
open(conffile
, "w") as f
:
1537 f
.write("driver=nl80211\n")
1538 f
.write("hw_mode=g\n")
1539 f
.write("channel=1\n")
1540 f
.write("ieee80211n=1\n")
1541 f
.write("interface=%s\n" % ifname
)
1542 f
.write("ctrl_interface=/var/run/hostapd\n")
1543 f
.write("ssid=wps\n")
1544 f
.write("eap_server=1\n")
1545 f
.write("wps_state=1\n")
1546 hostapd
.add_bss('phy3', ifname
, conffile
)
1547 hapd
= hostapd
.Hostapd(ifname
)
1548 hapd
.request("WPS_PBC")
1549 dev
[0].scan_for_bss(apdev
[0]['bssid'], freq
="2412")
1550 dev
[0].request("WPS_PBC " + apdev
[0]['bssid'])
1551 dev
[0].wait_connected(timeout
=30)
1552 with
open(conffile
, "r") as f
:
1553 lines
= f
.read().splitlines()
1557 [name
,value
] = l
.split('=', 1)
1559 except ValueError, e
:
1560 if "# WPS configuration" in l
:
1563 raise Exception("Unexpected configuration line: " + l
)
1564 if vals
['ieee80211n'] != '1' or vals
['wps_state'] != '2' or "WPA-PSK" not in vals
['wpa_key_mgmt']:
1565 raise Exception("Incorrect configuration: " + str(vals
))
1567 subprocess
.call(['sudo', 'rm', conffile
])
1569 def test_ap_wps_pbc_timeout(dev
, apdev
, params
):
1570 """wpa_supplicant PBC walk time [long]"""
1571 if not params
['long']:
1572 logger
.info("Skip test case with long duration due to --long not specified")
1575 hostapd
.add_ap(apdev
[0]['ifname'],
1576 { "ssid": ssid
, "eap_server": "1", "wps_state": "1" })
1577 hapd
= hostapd
.Hostapd(apdev
[0]['ifname'])
1578 logger
.info("Start WPS_PBC and wait for PBC walk time expiration")
1579 if "OK" not in dev
[0].request("WPS_PBC"):
1580 raise Exception("WPS_PBC failed")
1581 ev
= dev
[0].wait_event(["WPS-TIMEOUT"], timeout
=150)
1583 raise Exception("WPS-TIMEOUT not reported")
1585 def add_ssdp_ap(ifname
, ap_uuid
):
1588 hostapd
.add_ap(ifname
,
1589 { "ssid": ssid
, "eap_server": "1", "wps_state": "2",
1590 "wpa_passphrase": "12345678", "wpa": "2",
1591 "wpa_key_mgmt": "WPA-PSK", "rsn_pairwise": "CCMP",
1592 "device_name": "Wireless AP", "manufacturer": "Company",
1593 "model_name": "WAP", "model_number": "123",
1594 "serial_number": "12345", "device_type": "6-0050F204-1",
1595 "os_version": "01020300",
1596 "config_methods": "label push_button",
1597 "ap_pin": ap_pin
, "uuid": ap_uuid
, "upnp_iface": "lo",
1598 "friendly_name": "WPS Access Point",
1599 "manufacturer_url": "http://www.example.com/",
1600 "model_description": "Wireless Access Point",
1601 "model_url": "http://www.example.com/model/",
1602 "upc": "123456789012" })
1604 def ssdp_send(msg
, no_recv
=False):
1605 socket
.setdefaulttimeout(1)
1606 sock
= socket
.socket(socket
.AF_INET
, socket
.SOCK_DGRAM
, socket
.IPPROTO_UDP
)
1607 sock
.setsockopt(socket
.SOL_SOCKET
, socket
.SO_REUSEADDR
, 1)
1608 sock
.setsockopt(socket
.IPPROTO_IP
, socket
.IP_MULTICAST_TTL
, 2)
1609 sock
.bind(("127.0.0.1", 0))
1610 sock
.sendto(msg
, ("239.255.255.250", 1900))
1613 return sock
.recv(1000)
1615 def ssdp_send_msearch(st
):
1617 'M-SEARCH * HTTP/1.1',
1618 'HOST: 239.255.255.250:1900',
1620 'MAN: "ssdp:discover"',
1623 return ssdp_send(msg
)
1625 def test_ap_wps_ssdp_msearch(dev
, apdev
):
1626 """WPS AP and SSDP M-SEARCH messages"""
1627 ap_uuid
= "27ea801a-9e5c-4e73-bd82-f89cbcd10d7e"
1628 add_ssdp_ap(apdev
[0]['ifname'], ap_uuid
)
1631 'M-SEARCH * HTTP/1.1',
1632 'Host: 239.255.255.250:1900',
1634 'Man: "ssdp:discover"',
1635 'St: urn:schemas-wifialliance-org:device:WFADevice:1',
1640 'M-SEARCH * HTTP/1.1',
1641 'host:\t239.255.255.250:1900\t\t\t\t \t\t',
1643 'man: \t \t "ssdp:discover" ',
1644 'st: urn:schemas-wifialliance-org:device:WFADevice:1\t\t',
1648 ssdp_send_msearch("ssdp:all")
1649 ssdp_send_msearch("upnp:rootdevice")
1650 ssdp_send_msearch("uuid:" + ap_uuid
)
1651 ssdp_send_msearch("urn:schemas-wifialliance-org:service:WFAWLANConfig:1")
1652 ssdp_send_msearch("urn:schemas-wifialliance-org:device:WFADevice:1");
1655 'M-SEARCH * HTTP/1.1',
1656 'HOST:\t239.255.255.250:1900',
1657 'MAN: "ssdp:discover"',
1659 'ST: urn:schemas-wifialliance-org:device:WFADevice:1',
1661 ssdp_send(msg
, no_recv
=True)
1663 def test_ap_wps_ssdp_invalid_msearch(dev
, apdev
):
1664 """WPS AP and invalid SSDP M-SEARCH messages"""
1665 ap_uuid
= "27ea801a-9e5c-4e73-bd82-f89cbcd10d7e"
1666 add_ssdp_ap(apdev
[0]['ifname'], ap_uuid
)
1668 socket
.setdefaulttimeout(1)
1669 sock
= socket
.socket(socket
.AF_INET
, socket
.SOCK_DGRAM
, socket
.IPPROTO_UDP
)
1670 sock
.setsockopt(socket
.SOL_SOCKET
, socket
.SO_REUSEADDR
, 1)
1671 sock
.setsockopt(socket
.IPPROTO_IP
, socket
.IP_MULTICAST_TTL
, 2)
1672 sock
.bind(("127.0.0.1", 0))
1674 logger
.debug("Missing MX")
1676 'M-SEARCH * HTTP/1.1',
1677 'HOST: 239.255.255.250:1900',
1678 'MAN: "ssdp:discover"',
1679 'ST: urn:schemas-wifialliance-org:device:WFADevice:1',
1681 sock
.sendto(msg
, ("239.255.255.250", 1900))
1683 logger
.debug("Negative MX")
1685 'M-SEARCH * HTTP/1.1',
1686 'HOST: 239.255.255.250:1900',
1688 'MAN: "ssdp:discover"',
1689 'ST: urn:schemas-wifialliance-org:device:WFADevice:1',
1691 sock
.sendto(msg
, ("239.255.255.250", 1900))
1693 logger
.debug("Invalid MX")
1695 'M-SEARCH * HTTP/1.1',
1696 'HOST: 239.255.255.250:1900',
1698 'MAN: "ssdp:discover"',
1699 'ST: urn:schemas-wifialliance-org:device:WFADevice:1',
1701 sock
.sendto(msg
, ("239.255.255.250", 1900))
1703 logger
.debug("Missing MAN")
1705 'M-SEARCH * HTTP/1.1',
1706 'HOST: 239.255.255.250:1900',
1708 'ST: urn:schemas-wifialliance-org:device:WFADevice:1',
1710 sock
.sendto(msg
, ("239.255.255.250", 1900))
1712 logger
.debug("Invalid MAN")
1714 'M-SEARCH * HTTP/1.1',
1715 'HOST: 239.255.255.250:1900',
1718 'ST: urn:schemas-wifialliance-org:device:WFADevice:1',
1720 sock
.sendto(msg
, ("239.255.255.250", 1900))
1722 'M-SEARCH * HTTP/1.1',
1723 'HOST: 239.255.255.250:1900',
1725 'MAN; "ssdp:discover"',
1726 'ST: urn:schemas-wifialliance-org:device:WFADevice:1',
1728 sock
.sendto(msg
, ("239.255.255.250", 1900))
1730 logger
.debug("Missing HOST")
1732 'M-SEARCH * HTTP/1.1',
1733 'MAN: "ssdp:discover"',
1735 'ST: urn:schemas-wifialliance-org:device:WFADevice:1',
1737 sock
.sendto(msg
, ("239.255.255.250", 1900))
1739 logger
.debug("Missing ST")
1741 'M-SEARCH * HTTP/1.1',
1742 'HOST: 239.255.255.250:1900',
1743 'MAN: "ssdp:discover"',
1746 sock
.sendto(msg
, ("239.255.255.250", 1900))
1748 logger
.debug("Mismatching ST")
1750 'M-SEARCH * HTTP/1.1',
1751 'HOST: 239.255.255.250:1900',
1752 'MAN: "ssdp:discover"',
1754 'ST: uuid:16d5f8a9-4ee4-4f5e-81f9-cc6e2f47f42d',
1756 sock
.sendto(msg
, ("239.255.255.250", 1900))
1758 'M-SEARCH * HTTP/1.1',
1759 'HOST: 239.255.255.250:1900',
1760 'MAN: "ssdp:discover"',
1764 sock
.sendto(msg
, ("239.255.255.250", 1900))
1766 'M-SEARCH * HTTP/1.1',
1767 'HOST: 239.255.255.250:1900',
1768 'MAN: "ssdp:discover"',
1772 sock
.sendto(msg
, ("239.255.255.250", 1900))
1774 logger
.debug("Invalid ST")
1776 'M-SEARCH * HTTP/1.1',
1777 'HOST: 239.255.255.250:1900',
1778 'MAN: "ssdp:discover"',
1780 'ST; urn:schemas-wifialliance-org:device:WFADevice:1',
1782 sock
.sendto(msg
, ("239.255.255.250", 1900))
1784 logger
.debug("Invalid M-SEARCH")
1786 'M+SEARCH * HTTP/1.1',
1787 'HOST: 239.255.255.250:1900',
1788 'MAN: "ssdp:discover"',
1790 'ST: urn:schemas-wifialliance-org:device:WFADevice:1',
1792 sock
.sendto(msg
, ("239.255.255.250", 1900))
1794 'M-SEARCH-* HTTP/1.1',
1795 'HOST: 239.255.255.250:1900',
1796 'MAN: "ssdp:discover"',
1798 'ST: urn:schemas-wifialliance-org:device:WFADevice:1',
1800 sock
.sendto(msg
, ("239.255.255.250", 1900))
1802 logger
.debug("Invalid message format")
1803 sock
.sendto("NOTIFY * HTTP/1.1", ("239.255.255.250", 1900))
1805 'M-SEARCH * HTTP/1.1',
1806 'HOST: 239.255.255.250:1900',
1807 'MAN: "ssdp:discover"',
1809 'ST: urn:schemas-wifialliance-org:device:WFADevice:1',
1811 sock
.sendto(msg
, ("239.255.255.250", 1900))
1815 raise Exception("Unexpected M-SEARCH response: " + r
)
1816 except socket
.timeout
:
1819 logger
.debug("Valid M-SEARCH")
1821 'M-SEARCH * HTTP/1.1',
1822 'HOST: 239.255.255.250:1900',
1823 'MAN: "ssdp:discover"',
1825 'ST: urn:schemas-wifialliance-org:device:WFADevice:1',
1827 sock
.sendto(msg
, ("239.255.255.250", 1900))
1832 except socket
.timeout
:
1833 raise Exception("No SSDP response")
1835 def test_ap_wps_ssdp_burst(dev
, apdev
):
1836 """WPS AP and SSDP burst"""
1837 ap_uuid
= "27ea801a-9e5c-4e73-bd82-f89cbcd10d7e"
1838 add_ssdp_ap(apdev
[0]['ifname'], ap_uuid
)
1841 'M-SEARCH * HTTP/1.1',
1842 'HOST: 239.255.255.250:1900',
1843 'MAN: "ssdp:discover"',
1845 'ST: urn:schemas-wifialliance-org:device:WFADevice:1',
1847 socket
.setdefaulttimeout(1)
1848 sock
= socket
.socket(socket
.AF_INET
, socket
.SOCK_DGRAM
, socket
.IPPROTO_UDP
)
1849 sock
.setsockopt(socket
.SOL_SOCKET
, socket
.SO_REUSEADDR
, 1)
1850 sock
.setsockopt(socket
.IPPROTO_IP
, socket
.IP_MULTICAST_TTL
, 2)
1851 sock
.bind(("127.0.0.1", 0))
1852 for i
in range(0, 25):
1853 sock
.sendto(msg
, ("239.255.255.250", 1900))
1858 if not r
.startswith("HTTP/1.1 200 OK\r\n"):
1859 raise Exception("Unexpected message: " + r
)
1861 except socket
.timeout
:
1864 raise Exception("Too few SSDP responses")
1866 sock
= socket
.socket(socket
.AF_INET
, socket
.SOCK_DGRAM
, socket
.IPPROTO_UDP
)
1867 sock
.setsockopt(socket
.SOL_SOCKET
, socket
.SO_REUSEADDR
, 1)
1868 sock
.setsockopt(socket
.IPPROTO_IP
, socket
.IP_MULTICAST_TTL
, 2)
1869 sock
.bind(("127.0.0.1", 0))
1870 for i
in range(0, 25):
1871 sock
.sendto(msg
, ("239.255.255.250", 1900))
1877 except socket
.timeout
:
1878 raise Exception("No SSDP response")
1880 def ssdp_get_location(uuid
):
1881 res
= ssdp_send_msearch("uuid:" + uuid
)
1883 for l
in res
.splitlines():
1884 if l
.lower().startswith("location:"):
1885 location
= l
.split(':', 1)[1].strip()
1887 if location
is None:
1888 raise Exception("No UPnP location found")
1891 def upnp_get_urls(location
):
1892 conn
= urllib
.urlopen(location
)
1893 tree
= ET
.parse(conn
)
1894 root
= tree
.getroot()
1895 urn
= '{urn:schemas-upnp-org:device-1-0}'
1896 service
= root
.find("./" + urn
+ "device/" + urn
+ "serviceList/" + urn
+ "service")
1898 res
['scpd_url'] = urlparse
.urljoin(location
, service
.find(urn
+ 'SCPDURL').text
)
1899 res
['control_url'] = urlparse
.urljoin(location
, service
.find(urn
+ 'controlURL').text
)
1900 res
['event_sub_url'] = urlparse
.urljoin(location
, service
.find(urn
+ 'eventSubURL').text
)
1903 def upnp_soap_action(conn
, path
, action
, include_soap_action
=True, soap_action_override
=None):
1904 soapns
= 'http://schemas.xmlsoap.org/soap/envelope/'
1905 wpsns
= 'urn:schemas-wifialliance-org:service:WFAWLANConfig:1'
1906 ET
.register_namespace('soapenv', soapns
)
1907 ET
.register_namespace('wfa', wpsns
)
1909 attrib
['{%s}encodingStyle' % soapns
] = 'http://schemas.xmlsoap.org/soap/encoding/'
1910 root
= ET
.Element("{%s}Envelope" % soapns
, attrib
=attrib
)
1911 body
= ET
.SubElement(root
, "{%s}Body" % soapns
)
1912 act
= ET
.SubElement(body
, "{%s}%s" % (wpsns
, action
))
1913 tree
= ET
.ElementTree(root
)
1914 soap
= StringIO
.StringIO()
1915 tree
.write(soap
, xml_declaration
=True, encoding
='utf-8')
1917 headers
= { "Content-type": 'text/xml; charset="utf-8"' }
1918 if include_soap_action
:
1919 headers
["SOAPAction"] = '"urn:schemas-wifialliance-org:service:WFAWLANConfig:1#%s"' % action
1920 elif soap_action_override
:
1921 headers
["SOAPAction"] = soap_action_override
1922 conn
.request("POST", path
, soap
.getvalue(), headers
)
1923 return conn
.getresponse()
1925 def test_ap_wps_upnp(dev
, apdev
):
1926 """WPS AP and UPnP operations"""
1927 ap_uuid
= "27ea801a-9e5c-4e73-bd82-f89cbcd10d7e"
1928 add_ssdp_ap(apdev
[0]['ifname'], ap_uuid
)
1930 location
= ssdp_get_location(ap_uuid
)
1931 urls
= upnp_get_urls(location
)
1933 conn
= urllib
.urlopen(urls
['scpd_url'])
1936 conn
= urllib
.urlopen(urlparse
.urljoin(location
, "unknown.html"))
1937 if conn
.getcode() != 404:
1938 raise Exception("Unexpected HTTP response to GET unknown URL")
1940 url
= urlparse
.urlparse(location
)
1941 conn
= httplib
.HTTPConnection(url
.netloc
)
1942 #conn.set_debuglevel(1)
1943 headers
= { "Content-type": 'text/xml; charset="utf-8"',
1944 "SOAPAction": '"urn:schemas-wifialliance-org:service:WFAWLANConfig:1#GetDeviceInfo"' }
1945 conn
.request("POST", "hello", "\r\n\r\n", headers
)
1946 resp
= conn
.getresponse()
1947 if resp
.status
!= 404:
1948 raise Exception("Unexpected HTTP response: %s" % resp
.status
)
1950 conn
.request("UNKNOWN", "hello", "\r\n\r\n", headers
)
1951 resp
= conn
.getresponse()
1952 if resp
.status
!= 501:
1953 raise Exception("Unexpected HTTP response: %s" % resp
.status
)
1955 headers
= { "Content-type": 'text/xml; charset="utf-8"',
1956 "SOAPAction": '"urn:some-unknown-action#GetDeviceInfo"' }
1957 ctrlurl
= urlparse
.urlparse(urls
['control_url'])
1958 conn
.request("POST", ctrlurl
.path
, "\r\n\r\n", headers
)
1959 resp
= conn
.getresponse()
1960 if resp
.status
!= 401:
1961 raise Exception("Unexpected HTTP response: %s" % resp
.status
)
1963 logger
.debug("GetDeviceInfo without SOAPAction header")
1964 resp
= upnp_soap_action(conn
, ctrlurl
.path
, "GetDeviceInfo",
1965 include_soap_action
=False)
1966 if resp
.status
!= 401:
1967 raise Exception("Unexpected HTTP response: %s" % resp
.status
)
1969 logger
.debug("GetDeviceInfo with invalid SOAPAction header")
1971 "urn:schemas-wifialliance-org:service:WFAWLANConfig:1#GetDeviceInfo",
1972 '"urn:schemas-wifialliance-org:service:WFAWLANConfig:1"',
1973 '"urn:schemas-wifialliance-org:service:WFAWLANConfig:123#GetDevice']:
1974 resp
= upnp_soap_action(conn
, ctrlurl
.path
, "GetDeviceInfo",
1975 include_soap_action
=False,
1976 soap_action_override
=act
)
1977 if resp
.status
!= 401:
1978 raise Exception("Unexpected HTTP response: %s" % resp
.status
)
1980 resp
= upnp_soap_action(conn
, ctrlurl
.path
, "GetDeviceInfo")
1981 if resp
.status
!= 200:
1982 raise Exception("Unexpected HTTP response: %s" % resp
.status
)
1984 if "NewDeviceInfo" not in dev
:
1985 raise Exception("Unexpected GetDeviceInfo response")
1987 logger
.debug("PutMessage without required parameters")
1988 resp
= upnp_soap_action(conn
, ctrlurl
.path
, "PutMessage")
1989 if resp
.status
!= 600:
1990 raise Exception("Unexpected HTTP response: %s" % resp
.status
)
1992 logger
.debug("PutWLANResponse without required parameters")
1993 resp
= upnp_soap_action(conn
, ctrlurl
.path
, "PutWLANResponse")
1994 if resp
.status
!= 600:
1995 raise Exception("Unexpected HTTP response: %s" % resp
.status
)
1997 logger
.debug("SetSelectedRegistrar from unregistered ER")
1998 resp
= upnp_soap_action(conn
, ctrlurl
.path
, "SetSelectedRegistrar")
1999 if resp
.status
!= 501:
2000 raise Exception("Unexpected HTTP response: %s" % resp
.status
)
2002 logger
.debug("Unknown action")
2003 resp
= upnp_soap_action(conn
, ctrlurl
.path
, "Unknown")
2004 if resp
.status
!= 401:
2005 raise Exception("Unexpected HTTP response: %s" % resp
.status
)
2007 def test_ap_wps_upnp_subscribe(dev
, apdev
):
2008 """WPS AP and UPnP event subscription"""
2009 ap_uuid
= "27ea801a-9e5c-4e73-bd82-f89cbcd10d7e"
2010 add_ssdp_ap(apdev
[0]['ifname'], ap_uuid
)
2012 location
= ssdp_get_location(ap_uuid
)
2013 urls
= upnp_get_urls(location
)
2014 eventurl
= urlparse
.urlparse(urls
['event_sub_url'])
2016 url
= urlparse
.urlparse(location
)
2017 conn
= httplib
.HTTPConnection(url
.netloc
)
2018 #conn.set_debuglevel(1)
2019 headers
= { "callback": '<http://127.0.0.1:12345/event>',
2020 "timeout": "Second-1234" }
2021 conn
.request("SUBSCRIBE", "hello", "\r\n\r\n", headers
)
2022 resp
= conn
.getresponse()
2023 if resp
.status
!= 412:
2024 raise Exception("Unexpected HTTP response: %s" % resp
.status
)
2026 conn
.request("SUBSCRIBE", eventurl
.path
, "\r\n\r\n", headers
)
2027 resp
= conn
.getresponse()
2028 if resp
.status
!= 412:
2029 raise Exception("Unexpected HTTP response: %s" % resp
.status
)
2031 headers
= { "NT": "upnp:event",
2032 "timeout": "Second-1234" }
2033 conn
.request("SUBSCRIBE", eventurl
.path
, "\r\n\r\n", headers
)
2034 resp
= conn
.getresponse()
2035 if resp
.status
!= 412:
2036 raise Exception("Unexpected HTTP response: %s" % resp
.status
)
2038 headers
= { "callback": '<http://127.0.0.1:12345/event>',
2039 "NT": "upnp:foobar",
2040 "timeout": "Second-1234" }
2041 conn
.request("SUBSCRIBE", eventurl
.path
, "\r\n\r\n", headers
)
2042 resp
= conn
.getresponse()
2043 if resp
.status
!= 400:
2044 raise Exception("Unexpected HTTP response: %s" % resp
.status
)
2046 logger
.debug("Valid subscription")
2047 headers
= { "callback": '<http://127.0.0.1:12345/event>',
2049 "timeout": "Second-1234" }
2050 conn
.request("SUBSCRIBE", eventurl
.path
, "\r\n\r\n", headers
)
2051 resp
= conn
.getresponse()
2052 if resp
.status
!= 200:
2053 raise Exception("Unexpected HTTP response: %s" % resp
.status
)
2054 sid
= resp
.getheader("sid")
2055 logger
.debug("Subscription SID " + sid
)
2057 logger
.debug("Invalid re-subscription")
2058 headers
= { "NT": "upnp:event",
2059 "sid": "123456734567854",
2060 "timeout": "Second-1234" }
2061 conn
.request("SUBSCRIBE", eventurl
.path
, "\r\n\r\n", headers
)
2062 resp
= conn
.getresponse()
2063 if resp
.status
!= 400:
2064 raise Exception("Unexpected HTTP response: %s" % resp
.status
)
2066 logger
.debug("Invalid re-subscription")
2067 headers
= { "NT": "upnp:event",
2068 "sid": "uuid:123456734567854",
2069 "timeout": "Second-1234" }
2070 conn
.request("SUBSCRIBE", eventurl
.path
, "\r\n\r\n", headers
)
2071 resp
= conn
.getresponse()
2072 if resp
.status
!= 400:
2073 raise Exception("Unexpected HTTP response: %s" % resp
.status
)
2075 logger
.debug("Invalid re-subscription")
2076 headers
= { "callback": '<http://127.0.0.1:12345/event>',
2079 "timeout": "Second-1234" }
2080 conn
.request("SUBSCRIBE", eventurl
.path
, "\r\n\r\n", headers
)
2081 resp
= conn
.getresponse()
2082 if resp
.status
!= 400:
2083 raise Exception("Unexpected HTTP response: %s" % resp
.status
)
2085 logger
.debug("SID mismatch in re-subscription")
2086 headers
= { "NT": "upnp:event",
2087 "sid": "uuid:4c2bca79-1ff4-4e43-85d4-952a2b8a51fb",
2088 "timeout": "Second-1234" }
2089 conn
.request("SUBSCRIBE", eventurl
.path
, "\r\n\r\n", headers
)
2090 resp
= conn
.getresponse()
2091 if resp
.status
!= 412:
2092 raise Exception("Unexpected HTTP response: %s" % resp
.status
)
2094 logger
.debug("Valid re-subscription")
2095 headers
= { "NT": "upnp:event",
2097 "timeout": "Second-1234" }
2098 conn
.request("SUBSCRIBE", eventurl
.path
, "\r\n\r\n", headers
)
2099 resp
= conn
.getresponse()
2100 if resp
.status
!= 200:
2101 raise Exception("Unexpected HTTP response: %s" % resp
.status
)
2102 sid2
= resp
.getheader("sid")
2103 logger
.debug("Subscription SID " + sid2
)
2106 raise Exception("Unexpected SID change")
2108 logger
.debug("Valid re-subscription")
2109 headers
= { "NT": "upnp:event",
2110 "sid": "uuid: \t \t" + sid
.split(':')[1],
2111 "timeout": "Second-1234" }
2112 conn
.request("SUBSCRIBE", eventurl
.path
, "\r\n\r\n", headers
)
2113 resp
= conn
.getresponse()
2114 if resp
.status
!= 200:
2115 raise Exception("Unexpected HTTP response: %s" % resp
.status
)
2117 logger
.debug("Invalid unsubscription")
2118 headers
= { "sid": sid
}
2119 conn
.request("UNSUBSCRIBE", "/hello", "\r\n\r\n", headers
)
2120 resp
= conn
.getresponse()
2121 if resp
.status
!= 412:
2122 raise Exception("Unexpected HTTP response: %s" % resp
.status
)
2123 headers
= { "foo": "bar" }
2124 conn
.request("UNSUBSCRIBE", eventurl
.path
, "\r\n\r\n", headers
)
2125 resp
= conn
.getresponse()
2126 if resp
.status
!= 412:
2127 raise Exception("Unexpected HTTP response: %s" % resp
.status
)
2129 logger
.debug("Valid unsubscription")
2130 headers
= { "sid": sid
}
2131 conn
.request("UNSUBSCRIBE", eventurl
.path
, "\r\n\r\n", headers
)
2132 resp
= conn
.getresponse()
2133 if resp
.status
!= 200:
2134 raise Exception("Unexpected HTTP response: %s" % resp
.status
)
2136 logger
.debug("Unsubscription for not existing SID")
2137 headers
= { "sid": sid
}
2138 conn
.request("UNSUBSCRIBE", eventurl
.path
, "\r\n\r\n", headers
)
2139 resp
= conn
.getresponse()
2140 if resp
.status
!= 412:
2141 raise Exception("Unexpected HTTP response: %s" % resp
.status
)
2143 logger
.debug("Invalid unsubscription")
2144 headers
= { "sid": " \t \tfoo" }
2145 conn
.request("UNSUBSCRIBE", eventurl
.path
, "\r\n\r\n", headers
)
2146 resp
= conn
.getresponse()
2147 if resp
.status
!= 400:
2148 raise Exception("Unexpected HTTP response: %s" % resp
.status
)
2150 logger
.debug("Invalid unsubscription")
2151 headers
= { "sid": "uuid:\t \tfoo" }
2152 conn
.request("UNSUBSCRIBE", eventurl
.path
, "\r\n\r\n", headers
)
2153 resp
= conn
.getresponse()
2154 if resp
.status
!= 400:
2155 raise Exception("Unexpected HTTP response: %s" % resp
.status
)
2157 logger
.debug("Invalid unsubscription")
2158 headers
= { "NT": "upnp:event",
2160 conn
.request("UNSUBSCRIBE", eventurl
.path
, "\r\n\r\n", headers
)
2161 resp
= conn
.getresponse()
2162 if resp
.status
!= 400:
2163 raise Exception("Unexpected HTTP response: %s" % resp
.status
)
2164 headers
= { "callback": '<http://127.0.0.1:12345/event>',
2166 conn
.request("UNSUBSCRIBE", eventurl
.path
, "\r\n\r\n", headers
)
2167 resp
= conn
.getresponse()
2168 if resp
.status
!= 400:
2169 raise Exception("Unexpected HTTP response: %s" % resp
.status
)
2171 logger
.debug("Valid subscription with multiple callbacks")
2172 headers
= { "callback": '<http://127.0.0.1:12345/event> <http://127.0.0.1:12345/event>\t<http://127.0.0.1:12345/event><http://127.0.0.1:12345/event><http://127.0.0.1:12345/event><http://127.0.0.1:12345/event><http://127.0.0.1:12345/event><http://127.0.0.1:12345/event><http://127.0.0.1:12345/event><http://127.0.0.1:12345/event><http://127.0.0.1:12345/event><http://127.0.0.1:12345/event><http://127.0.0.1:12345/event><http://127.0.0.1:12345/event><http://127.0.0.1:12345/event><http://127.0.0.1:12345/event><http://127.0.0.1:12345/event><http://127.0.0.1:12345/event><http://127.0.0.1:12345/event><http://127.0.0.1:12345/event><http://127.0.0.1:12345/event><http://127.0.0.1:12345/event><http://127.0.0.1:12345/event><http://127.0.0.1:12345/event>',
2174 "timeout": "Second-1234" }
2175 conn
.request("SUBSCRIBE", eventurl
.path
, "\r\n\r\n", headers
)
2176 resp
= conn
.getresponse()
2177 if resp
.status
!= 200:
2178 raise Exception("Unexpected HTTP response: %s" % resp
.status
)
2179 sid
= resp
.getheader("sid")
2180 logger
.debug("Subscription SID " + sid
)
2182 def test_ap_wps_disabled(dev
, apdev
):
2183 """WPS operations while WPS is disabled"""
2184 ssid
= "test-wps-disabled"
2185 hostapd
.add_ap(apdev
[0]['ifname'], { "ssid": ssid
})
2186 hapd
= hostapd
.Hostapd(apdev
[0]['ifname'])
2187 if "FAIL" not in hapd
.request("WPS_PBC"):
2188 raise Exception("WPS_PBC succeeded unexpectedly")
2189 if "FAIL" not in hapd
.request("WPS_CANCEL"):
2190 raise Exception("WPS_CANCEL succeeded unexpectedly")
2192 def test_ap_wps_mixed_cred(dev
, apdev
):
2193 """WPS 2.0 STA merging mixed mode WPA/WPA2 credentials"""
2194 ssid
= "test-wps-wep"
2195 hostapd
.add_ap(apdev
[0]['ifname'],
2196 { "ssid": ssid
, "eap_server": "1", "wps_state": "2",
2197 "skip_cred_build": "1", "extra_cred": "wps-mixed-cred" })
2198 hapd
= hostapd
.Hostapd(apdev
[0]['ifname'])
2199 hapd
.request("WPS_PBC")
2200 dev
[0].scan_for_bss(apdev
[0]['bssid'], freq
="2412")
2201 dev
[0].request("WPS_PBC " + apdev
[0]['bssid'])
2202 ev
= dev
[0].wait_event(["WPS-SUCCESS"], timeout
=30)
2204 raise Exception("WPS-SUCCESS event timed out")
2205 nets
= dev
[0].list_networks()
2207 raise Exception("Unexpected number of network blocks")
2209 proto
= dev
[0].get_network(id, "proto")
2210 if proto
!= "WPA RSN":
2211 raise Exception("Unexpected merged proto field value: " + proto
)
2212 pairwise
= dev
[0].get_network(id, "pairwise")
2213 if pairwise
!= "CCMP TKIP" and pairwise
!= "CCMP GCMP TKIP":
2214 raise Exception("Unexpected merged pairwise field value: " + pairwise
)
2216 def test_ap_wps_while_connected(dev
, apdev
):
2217 """WPS PBC provisioning while connected to another AP"""
2218 ssid
= "test-wps-conf"
2219 hostapd
.add_ap(apdev
[0]['ifname'],
2220 { "ssid": ssid
, "eap_server": "1", "wps_state": "2",
2221 "wpa_passphrase": "12345678", "wpa": "2",
2222 "wpa_key_mgmt": "WPA-PSK", "rsn_pairwise": "CCMP"})
2223 hapd
= hostapd
.Hostapd(apdev
[0]['ifname'])
2225 hostapd
.add_ap(apdev
[1]['ifname'], { "ssid": "open" })
2226 dev
[0].connect("open", key_mgmt
="NONE", scan_freq
="2412")
2228 logger
.info("WPS provisioning step")
2229 hapd
.request("WPS_PBC")
2230 dev
[0].dump_monitor()
2231 dev
[0].request("WPS_PBC " + apdev
[0]['bssid'])
2232 dev
[0].wait_connected(timeout
=30)
2233 status
= dev
[0].get_status()
2234 if status
['bssid'] != apdev
[0]['bssid']:
2235 raise Exception("Unexpected BSSID")
2237 def test_ap_wps_while_connected_no_autoconnect(dev
, apdev
):
2238 """WPS PBC provisioning while connected to another AP and STA_AUTOCONNECT disabled"""
2239 ssid
= "test-wps-conf"
2240 hostapd
.add_ap(apdev
[0]['ifname'],
2241 { "ssid": ssid
, "eap_server": "1", "wps_state": "2",
2242 "wpa_passphrase": "12345678", "wpa": "2",
2243 "wpa_key_mgmt": "WPA-PSK", "rsn_pairwise": "CCMP"})
2244 hapd
= hostapd
.Hostapd(apdev
[0]['ifname'])
2246 hostapd
.add_ap(apdev
[1]['ifname'], { "ssid": "open" })
2249 dev
[0].request("STA_AUTOCONNECT 0")
2250 dev
[0].connect("open", key_mgmt
="NONE", scan_freq
="2412")
2252 logger
.info("WPS provisioning step")
2253 hapd
.request("WPS_PBC")
2254 dev
[0].dump_monitor()
2255 dev
[0].request("WPS_PBC " + apdev
[0]['bssid'])
2256 dev
[0].wait_connected(timeout
=30)
2257 status
= dev
[0].get_status()
2258 if status
['bssid'] != apdev
[0]['bssid']:
2259 raise Exception("Unexpected BSSID")
2261 dev
[0].request("STA_AUTOCONNECT 1")
2263 def test_ap_wps_from_event(dev
, apdev
):
2264 """WPS PBC event on AP to enable PBC"""
2265 ssid
= "test-wps-conf"
2266 hapd
= hostapd
.add_ap(apdev
[0]['ifname'],
2267 { "ssid": ssid
, "eap_server": "1", "wps_state": "2",
2268 "wpa_passphrase": "12345678", "wpa": "2",
2269 "wpa_key_mgmt": "WPA-PSK", "rsn_pairwise": "CCMP"})
2270 dev
[0].scan_for_bss(apdev
[0]['bssid'], freq
="2412")
2271 dev
[0].dump_monitor()
2273 dev
[0].request("WPS_PBC " + apdev
[0]['bssid'])
2275 ev
= hapd
.wait_event(['WPS-ENROLLEE-SEEN'], timeout
=15)
2277 raise Exception("No WPS-ENROLLEE-SEEN event on AP")
2278 vals
= ev
.split(' ')
2279 if vals
[1] != dev
[0].p2p_interface_addr():
2280 raise Exception("Unexpected enrollee address: " + vals
[1])
2282 raise Exception("Unexpected Device Password Id: " + vals
[5])
2283 hapd
.request("WPS_PBC")
2284 dev
[0].wait_connected(timeout
=30)
2286 def test_ap_wps_ap_scan_2(dev
, apdev
):
2287 """AP_SCAN 2 for WPS"""
2288 ssid
= "test-wps-conf"
2289 hapd
= hostapd
.add_ap(apdev
[0]['ifname'],
2290 { "ssid": ssid
, "eap_server": "1", "wps_state": "2",
2291 "wpa_passphrase": "12345678", "wpa": "2",
2292 "wpa_key_mgmt": "WPA-PSK", "rsn_pairwise": "CCMP"})
2293 hapd
.request("WPS_PBC")
2295 wpas
= WpaSupplicant(global_iface
='/tmp/wpas-wlan5')
2296 wpas
.interface_add("wlan5", drv_params
="force_connect_cmd=1")
2298 if "OK" not in wpas
.request("AP_SCAN 2"):
2299 raise Exception("Failed to set AP_SCAN 2")
2301 wpas
.scan_for_bss(apdev
[0]['bssid'], freq
="2412")
2302 wpas
.request("WPS_PBC " + apdev
[0]['bssid'])
2303 ev
= wpas
.wait_event(["WPS-SUCCESS"], timeout
=15)
2305 raise Exception("WPS-SUCCESS event timed out")
2306 wpas
.wait_connected(timeout
=30)
2307 wpas
.request("DISCONNECT")
2308 wpas
.request("BSS_FLUSH 0")
2310 wpas
.request("REASSOCIATE")
2311 wpas
.wait_connected(timeout
=30)