]> git.ipfire.org Git - thirdparty/hostap.git/blob - tests/hwsim/test_ap_wps.py
tests: WPS ER configuring AP over UPnP
[thirdparty/hostap.git] / tests / hwsim / test_ap_wps.py
1 #!/usr/bin/python
2 #
3 # WPS tests
4 # Copyright (c) 2013, Jouni Malinen <j@w1.fi>
5 #
6 # This software may be distributed under the terms of the BSD license.
7 # See README for more details.
8
9 import time
10 import subprocess
11 import logging
12 logger = logging.getLogger()
13
14 import hwsim_utils
15 import hostapd
16
17 def test_ap_wps_init(dev, apdev):
18 """Initial AP configuration with first WPS Enrollee"""
19 ssid = "test-wps"
20 hostapd.add_ap(apdev[0]['ifname'],
21 { "ssid": ssid, "eap_server": "1", "wps_state": "1" })
22 hapd = hostapd.Hostapd(apdev[0]['ifname'])
23 logger.info("WPS provisioning step")
24 hapd.request("WPS_PBC")
25 dev[0].request("SET ignore_old_scan_res 1")
26 dev[0].dump_monitor()
27 dev[0].request("WPS_PBC")
28 ev = dev[0].wait_event(["CTRL-EVENT-CONNECTED"], timeout=30)
29 if ev is None:
30 raise Exception("Association with the AP timed out")
31 status = dev[0].get_status()
32 if status['wpa_state'] != 'COMPLETED' or status['bssid'] != apdev[0]['bssid']:
33 raise Exception("Not fully connected")
34 if status['ssid'] != ssid:
35 raise Exception("Unexpected SSID")
36 if status['pairwise_cipher'] != 'CCMP':
37 raise Exception("Unexpected encryption configuration")
38 if status['key_mgmt'] != 'WPA2-PSK':
39 raise Exception("Unexpected key_mgmt")
40
41 def test_ap_wps_conf(dev, apdev):
42 """WPS PBC provisioning with configured AP"""
43 ssid = "test-wps-conf"
44 hostapd.add_ap(apdev[0]['ifname'],
45 { "ssid": ssid, "eap_server": "1", "wps_state": "2",
46 "wpa_passphrase": "12345678", "wpa": "2",
47 "wpa_key_mgmt": "WPA-PSK", "rsn_pairwise": "CCMP"})
48 hapd = hostapd.Hostapd(apdev[0]['ifname'])
49 logger.info("WPS provisioning step")
50 hapd.request("WPS_PBC")
51 dev[0].dump_monitor()
52 dev[0].request("WPS_PBC")
53 ev = dev[0].wait_event(["CTRL-EVENT-CONNECTED"], timeout=30)
54 if ev is None:
55 raise Exception("Association with the AP timed out")
56 status = dev[0].get_status()
57 if status['wpa_state'] != 'COMPLETED':
58 raise Exception("Not fully connected")
59 if status['bssid'] != apdev[0]['bssid']:
60 raise Exception("Unexpected BSSID")
61 if status['ssid'] != ssid:
62 raise Exception("Unexpected SSID")
63 if status['pairwise_cipher'] != 'CCMP' or status['group_cipher'] != 'CCMP':
64 raise Exception("Unexpected encryption configuration")
65 if status['key_mgmt'] != 'WPA2-PSK':
66 raise Exception("Unexpected key_mgmt")
67
68 def test_ap_wps_twice(dev, apdev):
69 """WPS provisioning with twice to change passphrase"""
70 ssid = "test-wps-twice"
71 params = { "ssid": ssid, "eap_server": "1", "wps_state": "2",
72 "wpa_passphrase": "12345678", "wpa": "2",
73 "wpa_key_mgmt": "WPA-PSK", "rsn_pairwise": "CCMP" }
74 hostapd.add_ap(apdev[0]['ifname'], params)
75 hapd = hostapd.Hostapd(apdev[0]['ifname'])
76 logger.info("WPS provisioning step")
77 hapd.request("WPS_PBC")
78 dev[0].request("SET ignore_old_scan_res 1")
79 dev[0].dump_monitor()
80 dev[0].request("WPS_PBC")
81 ev = dev[0].wait_event(["CTRL-EVENT-CONNECTED"], timeout=30)
82 if ev is None:
83 raise Exception("Association with the AP timed out")
84 dev[0].request("DISCONNECT")
85
86 logger.info("Restart AP with different passphrase and re-run WPS")
87 hapd_global = hostapd.HostapdGlobal()
88 hapd_global.remove(apdev[0]['ifname'])
89 params['wpa_passphrase'] = 'another passphrase'
90 hostapd.add_ap(apdev[0]['ifname'], params)
91 hapd = hostapd.Hostapd(apdev[0]['ifname'])
92 logger.info("WPS provisioning step")
93 hapd.request("WPS_PBC")
94 dev[0].dump_monitor()
95 dev[0].request("WPS_PBC")
96 ev = dev[0].wait_event(["CTRL-EVENT-CONNECTED"], timeout=30)
97 if ev is None:
98 raise Exception("Association with the AP timed out")
99 networks = dev[0].list_networks()
100 if len(networks) > 1:
101 raise Exception("Unexpected duplicated network block present")
102
103 def test_ap_wps_incorrect_pin(dev, apdev):
104 """WPS PIN provisioning with incorrect PIN"""
105 ssid = "test-wps-incorrect-pin"
106 hostapd.add_ap(apdev[0]['ifname'],
107 { "ssid": ssid, "eap_server": "1", "wps_state": "2",
108 "wpa_passphrase": "12345678", "wpa": "2",
109 "wpa_key_mgmt": "WPA-PSK", "rsn_pairwise": "CCMP"})
110 hapd = hostapd.Hostapd(apdev[0]['ifname'])
111
112 logger.info("WPS provisioning attempt 1")
113 hapd.request("WPS_PIN any 12345670")
114 dev[0].request("SET ignore_old_scan_res 1")
115 dev[0].dump_monitor()
116 dev[0].request("WPS_PIN any 55554444")
117 ev = dev[0].wait_event(["WPS-FAIL"], timeout=30)
118 if ev is None:
119 raise Exception("WPS operation timed out")
120 if "config_error=18" not in ev:
121 raise Exception("Incorrect config_error reported")
122 if "msg=8" not in ev:
123 raise Exception("PIN error detected on incorrect message")
124 ev = dev[0].wait_event(["CTRL-EVENT-DISCONNECTED"])
125 if ev is None:
126 raise Exception("Timeout on disconnection event")
127 dev[0].request("WPS_CANCEL")
128 # if a scan was in progress, wait for it to complete before trying WPS again
129 ev = dev[0].wait_event(["CTRL-EVENT-SCAN-RESULTS"], 5)
130
131 logger.info("WPS provisioning attempt 2")
132 hapd.request("WPS_PIN any 12345670")
133 dev[0].dump_monitor()
134 dev[0].request("WPS_PIN any 12344444")
135 ev = dev[0].wait_event(["WPS-FAIL"], timeout=30)
136 if ev is None:
137 raise Exception("WPS operation timed out")
138 if "config_error=18" not in ev:
139 raise Exception("Incorrect config_error reported")
140 if "msg=10" not in ev:
141 raise Exception("PIN error detected on incorrect message")
142 ev = dev[0].wait_event(["CTRL-EVENT-DISCONNECTED"])
143 if ev is None:
144 raise Exception("Timeout on disconnection event")
145
146 def test_ap_wps_conf_pin(dev, apdev):
147 """WPS PIN provisioning with configured AP"""
148 ssid = "test-wps-conf-pin"
149 hostapd.add_ap(apdev[0]['ifname'],
150 { "ssid": ssid, "eap_server": "1", "wps_state": "2",
151 "wpa_passphrase": "12345678", "wpa": "2",
152 "wpa_key_mgmt": "WPA-PSK", "rsn_pairwise": "CCMP"})
153 hapd = hostapd.Hostapd(apdev[0]['ifname'])
154 logger.info("WPS provisioning step")
155 pin = dev[0].wps_read_pin()
156 hapd.request("WPS_PIN any " + pin)
157 dev[0].request("SET ignore_old_scan_res 1")
158 dev[0].dump_monitor()
159 dev[0].request("WPS_PIN any " + pin)
160 ev = dev[0].wait_event(["CTRL-EVENT-CONNECTED"], timeout=30)
161 if ev is None:
162 raise Exception("Association with the AP timed out")
163 status = dev[0].get_status()
164 if status['wpa_state'] != 'COMPLETED' or status['bssid'] != apdev[0]['bssid']:
165 raise Exception("Not fully connected")
166 if status['ssid'] != ssid:
167 raise Exception("Unexpected SSID")
168 if status['pairwise_cipher'] != 'CCMP' or status['group_cipher'] != 'CCMP':
169 raise Exception("Unexpected encryption configuration")
170 if status['key_mgmt'] != 'WPA2-PSK':
171 raise Exception("Unexpected key_mgmt")
172
173 def test_ap_wps_reg_connect(dev, apdev):
174 """WPS registrar using AP PIN to connect"""
175 ssid = "test-wps-reg-ap-pin"
176 appin = "12345670"
177 hostapd.add_ap(apdev[0]['ifname'],
178 { "ssid": ssid, "eap_server": "1", "wps_state": "2",
179 "wpa_passphrase": "12345678", "wpa": "2",
180 "wpa_key_mgmt": "WPA-PSK", "rsn_pairwise": "CCMP",
181 "ap_pin": appin})
182 logger.info("WPS provisioning step")
183 dev[0].request("SET ignore_old_scan_res 1")
184 dev[0].dump_monitor()
185 dev[0].wps_reg(apdev[0]['bssid'], appin)
186 status = dev[0].get_status()
187 if status['wpa_state'] != 'COMPLETED' or status['bssid'] != apdev[0]['bssid']:
188 raise Exception("Not fully connected")
189 if status['ssid'] != ssid:
190 raise Exception("Unexpected SSID")
191 if status['pairwise_cipher'] != 'CCMP' or status['group_cipher'] != 'CCMP':
192 raise Exception("Unexpected encryption configuration")
193 if status['key_mgmt'] != 'WPA2-PSK':
194 raise Exception("Unexpected key_mgmt")
195
196 def test_ap_wps_reg_config(dev, apdev):
197 """WPS registrar configuring and AP using AP PIN"""
198 ssid = "test-wps-init-ap-pin"
199 appin = "12345670"
200 hostapd.add_ap(apdev[0]['ifname'],
201 { "ssid": ssid, "eap_server": "1", "wps_state": "2",
202 "ap_pin": appin})
203 logger.info("WPS configuration step")
204 dev[0].request("SET ignore_old_scan_res 1")
205 dev[0].dump_monitor()
206 new_ssid = "wps-new-ssid"
207 new_passphrase = "1234567890"
208 dev[0].wps_reg(apdev[0]['bssid'], appin, new_ssid, "WPA2PSK", "CCMP",
209 new_passphrase)
210 status = dev[0].get_status()
211 if status['wpa_state'] != 'COMPLETED' or status['bssid'] != apdev[0]['bssid']:
212 raise Exception("Not fully connected")
213 if status['ssid'] != new_ssid:
214 raise Exception("Unexpected SSID")
215 if status['pairwise_cipher'] != 'CCMP' or status['group_cipher'] != 'CCMP':
216 raise Exception("Unexpected encryption configuration")
217 if status['key_mgmt'] != 'WPA2-PSK':
218 raise Exception("Unexpected key_mgmt")
219
220 def test_ap_wps_reg_config_tkip(dev, apdev):
221 """WPS registrar configuring AP to use TKIP and AP upgrading to TKIP+CCMP"""
222 ssid = "test-wps-init-ap"
223 appin = "12345670"
224 hostapd.add_ap(apdev[0]['ifname'],
225 { "ssid": ssid, "eap_server": "1", "wps_state": "1",
226 "ap_pin": appin})
227 logger.info("WPS configuration step")
228 dev[0].request("SET ignore_old_scan_res 1")
229 dev[0].request("SET wps_version_number 0x10")
230 dev[0].dump_monitor()
231 new_ssid = "wps-new-ssid-with-tkip"
232 new_passphrase = "1234567890"
233 dev[0].wps_reg(apdev[0]['bssid'], appin, new_ssid, "WPAPSK", "TKIP",
234 new_passphrase)
235 logger.info("Re-connect to verify WPA2 mixed mode")
236 dev[0].request("DISCONNECT")
237 id = 0
238 dev[0].set_network(id, "pairwise", "CCMP")
239 dev[0].set_network(id, "proto", "RSN")
240 dev[0].connect_network(id)
241 status = dev[0].get_status()
242 if status['wpa_state'] != 'COMPLETED' or status['bssid'] != apdev[0]['bssid']:
243 raise Exception("Not fully connected")
244 if status['ssid'] != new_ssid:
245 raise Exception("Unexpected SSID")
246 if status['pairwise_cipher'] != 'CCMP' or status['group_cipher'] != 'TKIP':
247 raise Exception("Unexpected encryption configuration")
248 if status['key_mgmt'] != 'WPA2-PSK':
249 raise Exception("Unexpected key_mgmt")
250
251 def test_ap_wps_setup_locked(dev, apdev):
252 """WPS registrar locking up AP setup on AP PIN failures"""
253 ssid = "test-wps-incorrect-ap-pin"
254 appin = "12345670"
255 hostapd.add_ap(apdev[0]['ifname'],
256 { "ssid": ssid, "eap_server": "1", "wps_state": "2",
257 "wpa_passphrase": "12345678", "wpa": "2",
258 "wpa_key_mgmt": "WPA-PSK", "rsn_pairwise": "CCMP",
259 "ap_pin": appin})
260 dev[0].request("SET ignore_old_scan_res 1")
261 new_ssid = "wps-new-ssid-test"
262 new_passphrase = "1234567890"
263
264 ap_setup_locked=False
265 for pin in ["55554444", "1234", "12345678", "00000000", "11111111"]:
266 dev[0].dump_monitor()
267 logger.info("Try incorrect AP PIN - attempt " + pin)
268 dev[0].wps_reg(apdev[0]['bssid'], pin, new_ssid, "WPA2PSK",
269 "CCMP", new_passphrase, no_wait=True)
270 ev = dev[0].wait_event(["WPS-FAIL", "CTRL-EVENT-CONNECTED"])
271 if ev is None:
272 raise Exception("Timeout on receiving WPS operation failure event")
273 if "CTRL-EVENT-CONNECTED" in ev:
274 raise Exception("Unexpected connection")
275 if "config_error=15" in ev:
276 logger.info("AP Setup Locked")
277 ap_setup_locked=True
278 elif "config_error=18" not in ev:
279 raise Exception("config_error=18 not reported")
280 ev = dev[0].wait_event(["CTRL-EVENT-DISCONNECTED"])
281 if ev is None:
282 raise Exception("Timeout on disconnection event")
283 time.sleep(0.1)
284 if not ap_setup_locked:
285 raise Exception("AP setup was not locked")
286
287 time.sleep(0.5)
288 dev[0].dump_monitor()
289 logger.info("WPS provisioning step")
290 pin = dev[0].wps_read_pin()
291 hapd = hostapd.Hostapd(apdev[0]['ifname'])
292 hapd.request("WPS_PIN any " + pin)
293 dev[0].request("WPS_PIN any " + pin)
294 ev = dev[0].wait_event(["WPS-SUCCESS"], timeout=30)
295 if ev is None:
296 raise Exception("WPS success was not reported")
297 ev = dev[0].wait_event(["CTRL-EVENT-CONNECTED"], timeout=30)
298 if ev is None:
299 raise Exception("Association with the AP timed out")
300
301 def test_ap_wps_pbc_overlap_2ap(dev, apdev):
302 """WPS PBC session overlap with two active APs"""
303 hostapd.add_ap(apdev[0]['ifname'],
304 { "ssid": "wps1", "eap_server": "1", "wps_state": "2",
305 "wpa_passphrase": "12345678", "wpa": "2",
306 "wpa_key_mgmt": "WPA-PSK", "rsn_pairwise": "CCMP",
307 "wps_independent": "1"})
308 hostapd.add_ap(apdev[1]['ifname'],
309 { "ssid": "wps2", "eap_server": "1", "wps_state": "2",
310 "wpa_passphrase": "123456789", "wpa": "2",
311 "wpa_key_mgmt": "WPA-PSK", "rsn_pairwise": "CCMP",
312 "wps_independent": "1"})
313 hapd = hostapd.Hostapd(apdev[0]['ifname'])
314 hapd.request("WPS_PBC")
315 hapd2 = hostapd.Hostapd(apdev[1]['ifname'])
316 hapd2.request("WPS_PBC")
317 logger.info("WPS provisioning step")
318 dev[0].dump_monitor()
319 dev[0].request("WPS_PBC")
320 ev = dev[0].wait_event(["WPS-OVERLAP-DETECTED"], timeout=15)
321 if ev is None:
322 raise Exception("PBC session overlap not detected")
323
324 def test_ap_wps_pbc_overlap_2sta(dev, apdev):
325 """WPS PBC session overlap with two active STAs"""
326 ssid = "test-wps-pbc-overlap"
327 hostapd.add_ap(apdev[0]['ifname'],
328 { "ssid": ssid, "eap_server": "1", "wps_state": "2",
329 "wpa_passphrase": "12345678", "wpa": "2",
330 "wpa_key_mgmt": "WPA-PSK", "rsn_pairwise": "CCMP"})
331 hapd = hostapd.Hostapd(apdev[0]['ifname'])
332 logger.info("WPS provisioning step")
333 hapd.request("WPS_PBC")
334 dev[0].request("SET ignore_old_scan_res 1")
335 dev[1].request("SET ignore_old_scan_res 1")
336 dev[0].dump_monitor()
337 dev[1].dump_monitor()
338 dev[0].request("WPS_PBC")
339 dev[1].request("WPS_PBC")
340 ev = dev[0].wait_event(["WPS-M2D"], timeout=15)
341 if ev is None:
342 raise Exception("PBC session overlap not detected (dev0)")
343 if "config_error=12" not in ev:
344 raise Exception("PBC session overlap not correctly reported (dev0)")
345 ev = dev[1].wait_event(["WPS-M2D"], timeout=15)
346 if ev is None:
347 raise Exception("PBC session overlap not detected (dev1)")
348 if "config_error=12" not in ev:
349 raise Exception("PBC session overlap not correctly reported (dev1)")
350
351 def test_ap_wps_er_add_enrollee(dev, apdev):
352 """WPS ER configuring AP and adding a new enrollee using PIN"""
353 ssid = "wps-er-add-enrollee"
354 ap_pin = "12345670"
355 ap_uuid = "27ea801a-9e5c-4e73-bd82-f89cbcd10d7e"
356 hostapd.add_ap(apdev[0]['ifname'],
357 { "ssid": ssid, "eap_server": "1", "wps_state": "1",
358 "device_name": "Wireless AP", "manufacturer": "Company",
359 "model_name": "WAP", "model_number": "123",
360 "serial_number": "12345", "device_type": "6-0050F204-1",
361 "os_version": "01020300",
362 "config_methods": "label push_button",
363 "ap_pin": ap_pin, "uuid": ap_uuid, "upnp_iface": "lo"})
364 logger.info("WPS configuration step")
365 new_passphrase = "1234567890"
366 dev[0].dump_monitor()
367 dev[0].request("SET ignore_old_scan_res 1")
368 dev[0].wps_reg(apdev[0]['bssid'], ap_pin, ssid, "WPA2PSK", "CCMP",
369 new_passphrase)
370 status = dev[0].get_status()
371 if status['wpa_state'] != 'COMPLETED' or status['bssid'] != apdev[0]['bssid']:
372 raise Exception("Not fully connected")
373 if status['ssid'] != ssid:
374 raise Exception("Unexpected SSID")
375 if status['pairwise_cipher'] != 'CCMP' or status['group_cipher'] != 'CCMP':
376 raise Exception("Unexpected encryption configuration")
377 if status['key_mgmt'] != 'WPA2-PSK':
378 raise Exception("Unexpected key_mgmt")
379
380 logger.info("Start ER")
381 dev[0].request("WPS_ER_START ifname=lo")
382 ev = dev[0].wait_event(["WPS-ER-AP-ADD"], timeout=15)
383 if ev is None:
384 raise Exception("AP discovery timed out")
385 if ap_uuid not in ev:
386 raise Exception("Expected AP UUID not found")
387
388 logger.info("Learn AP configuration through UPnP")
389 dev[0].dump_monitor()
390 dev[0].request("WPS_ER_LEARN " + ap_uuid + " " + ap_pin)
391 ev = dev[0].wait_event(["WPS-ER-AP-SETTINGS"], timeout=15)
392 if ev is None:
393 raise Exception("AP learn timed out")
394 if ap_uuid not in ev:
395 raise Exception("Expected AP UUID not in settings")
396 if "ssid=" + ssid not in ev:
397 raise Exception("Expected SSID not in settings")
398 if "key=" + new_passphrase not in ev:
399 raise Exception("Expected passphrase not in settings")
400
401 logger.info("Add Enrollee using ER")
402 pin = dev[1].wps_read_pin()
403 dev[0].dump_monitor()
404 dev[0].request("WPS_ER_PIN any " + pin + " " + dev[1].p2p_interface_addr())
405 dev[1].request("SET ignore_old_scan_res 1")
406 dev[1].dump_monitor()
407 dev[1].request("WPS_PIN any " + pin)
408 ev = dev[1].wait_event(["WPS-SUCCESS"], timeout=30)
409 if ev is None:
410 raise Exception("Enrollee did not report success")
411 ev = dev[1].wait_event(["CTRL-EVENT-CONNECTED"], timeout=15)
412 if ev is None:
413 raise Exception("Association with the AP timed out")
414 ev = dev[0].wait_event(["WPS-SUCCESS"], timeout=15)
415 if ev is None:
416 raise Exception("WPS ER did not report success")
417 hwsim_utils.test_connectivity_sta(dev[0], dev[1])
418
419 logger.info("Verify registrar selection behavior")
420 dev[0].request("WPS_ER_PIN any " + pin + " " + dev[1].p2p_interface_addr())
421 dev[1].request("DISCONNECT")
422 dev[1].wait_event(["CTRL-EVENT-DISCONNECTED"])
423 dev[1].scan(freq="2412")
424 bss = dev[1].get_bss(apdev[0]['bssid'])
425 if "[WPS-AUTH]" not in bss['flags']:
426 raise Exception("WPS-AUTH flag missing")
427
428 logger.info("Stop ER")
429 dev[0].dump_monitor()
430 dev[0].request("WPS_ER_STOP")
431 ev = dev[0].wait_event(["WPS-ER-AP-REMOVE"])
432 if ev is None:
433 raise Exception("WPS ER unsubscription timed out")
434
435 dev[1].scan(freq="2412")
436 bss = dev[1].get_bss(apdev[0]['bssid'])
437 if "[WPS-AUTH]" in bss['flags']:
438 raise Exception("WPS-AUTH flag not removed")
439
440 def test_ap_wps_er_add_enrollee_pbc(dev, apdev):
441 """WPS ER connected to AP and adding a new enrollee using PBC"""
442 ssid = "wps-er-add-enrollee-pbc"
443 ap_pin = "12345670"
444 ap_uuid = "27ea801a-9e5c-4e73-bd82-f89cbcd10d7e"
445 hostapd.add_ap(apdev[0]['ifname'],
446 { "ssid": ssid, "eap_server": "1", "wps_state": "2",
447 "wpa_passphrase": "12345678", "wpa": "2",
448 "wpa_key_mgmt": "WPA-PSK", "rsn_pairwise": "CCMP",
449 "device_name": "Wireless AP", "manufacturer": "Company",
450 "model_name": "WAP", "model_number": "123",
451 "serial_number": "12345", "device_type": "6-0050F204-1",
452 "os_version": "01020300",
453 "config_methods": "label push_button",
454 "ap_pin": ap_pin, "uuid": ap_uuid, "upnp_iface": "lo"})
455 logger.info("Learn AP configuration")
456 dev[0].dump_monitor()
457 dev[0].request("SET ignore_old_scan_res 1")
458 dev[0].wps_reg(apdev[0]['bssid'], ap_pin)
459 status = dev[0].get_status()
460 if status['wpa_state'] != 'COMPLETED' or status['bssid'] != apdev[0]['bssid']:
461 raise Exception("Not fully connected")
462
463 logger.info("Start ER")
464 dev[0].request("WPS_ER_START ifname=lo")
465 ev = dev[0].wait_event(["WPS-ER-AP-ADD"], timeout=15)
466 if ev is None:
467 raise Exception("AP discovery timed out")
468 if ap_uuid not in ev:
469 raise Exception("Expected AP UUID not found")
470
471 logger.info("Use learned network configuration on ER")
472 dev[0].request("WPS_ER_SET_CONFIG " + ap_uuid + " 0")
473
474 logger.info("Add Enrollee using ER and PBC")
475 dev[0].dump_monitor()
476 enrollee = dev[1].p2p_interface_addr()
477 dev[1].request("SET ignore_old_scan_res 1")
478 dev[1].dump_monitor()
479 dev[1].request("WPS_PBC")
480
481 ev = dev[0].wait_event(["WPS-ER-ENROLLEE-ADD"], timeout=15)
482 if ev is None:
483 raise Exception("Enrollee discovery timed out")
484 if enrollee not in ev:
485 raise Exception("Expected Enrollee not found")
486 dev[0].request("WPS_ER_PBC " + enrollee)
487
488 ev = dev[1].wait_event(["WPS-SUCCESS"], timeout=15)
489 if ev is None:
490 raise Exception("Enrollee did not report success")
491 ev = dev[1].wait_event(["CTRL-EVENT-CONNECTED"], timeout=15)
492 if ev is None:
493 raise Exception("Association with the AP timed out")
494 ev = dev[0].wait_event(["WPS-SUCCESS"], timeout=15)
495 if ev is None:
496 raise Exception("WPS ER did not report success")
497 hwsim_utils.test_connectivity_sta(dev[0], dev[1])
498
499 # verify BSSID selection of the AP instead of UUID
500 if "FAIL" in dev[0].request("WPS_ER_SET_CONFIG " + apdev[0]['bssid'] + " 0"):
501 raise Exception("Could not select AP based on BSSID")
502
503 def test_ap_wps_er_config_ap(dev, apdev):
504 """WPS ER configuring AP over UPnP"""
505 ssid = "wps-er-ap-config"
506 ap_pin = "12345670"
507 ap_uuid = "27ea801a-9e5c-4e73-bd82-f89cbcd10d7e"
508 hostapd.add_ap(apdev[0]['ifname'],
509 { "ssid": ssid, "eap_server": "1", "wps_state": "2",
510 "wpa_passphrase": "12345678", "wpa": "2",
511 "wpa_key_mgmt": "WPA-PSK", "rsn_pairwise": "CCMP",
512 "device_name": "Wireless AP", "manufacturer": "Company",
513 "model_name": "WAP", "model_number": "123",
514 "serial_number": "12345", "device_type": "6-0050F204-1",
515 "os_version": "01020300",
516 "config_methods": "label push_button",
517 "ap_pin": ap_pin, "uuid": ap_uuid, "upnp_iface": "lo"})
518
519 logger.info("Connect ER to the AP")
520 dev[0].connect(ssid, psk="12345678", scan_freq="2412")
521
522 logger.info("WPS configuration step")
523 dev[0].request("WPS_ER_START ifname=lo")
524 ev = dev[0].wait_event(["WPS-ER-AP-ADD"], timeout=15)
525 if ev is None:
526 raise Exception("AP discovery timed out")
527 if ap_uuid not in ev:
528 raise Exception("Expected AP UUID not found")
529 new_passphrase = "1234567890"
530 dev[0].request("WPS_ER_CONFIG " + apdev[0]['bssid'] + " " + ap_pin + " " +
531 ssid.encode("hex") + " WPA2PSK CCMP " +
532 new_passphrase.encode("hex"))
533 ev = dev[0].wait_event(["WPS-SUCCESS"])
534 if ev is None:
535 raise Exception("WPS ER configuration operation timed out")
536 dev[1].wait_event(["CTRL-EVENT-DISCONNECTED"])
537 dev[0].connect(ssid, psk="1234567890", scan_freq="2412")
538
539 def test_ap_wps_fragmentation(dev, apdev):
540 """WPS with fragmentation in EAP-WSC and mixed mode WPA+WPA2"""
541 ssid = "test-wps-fragmentation"
542 hostapd.add_ap(apdev[0]['ifname'],
543 { "ssid": ssid, "eap_server": "1", "wps_state": "2",
544 "wpa_passphrase": "12345678", "wpa": "3",
545 "wpa_key_mgmt": "WPA-PSK", "rsn_pairwise": "CCMP",
546 "wpa_pairwise": "TKIP",
547 "fragment_size": "50" })
548 hapd = hostapd.Hostapd(apdev[0]['ifname'])
549 logger.info("WPS provisioning step")
550 hapd.request("WPS_PBC")
551 dev[0].request("SET ignore_old_scan_res 1")
552 dev[0].dump_monitor()
553 dev[0].request("SET wps_fragment_size 50")
554 dev[0].request("WPS_PBC")
555 ev = dev[0].wait_event(["CTRL-EVENT-CONNECTED"], timeout=30)
556 if ev is None:
557 raise Exception("Association with the AP timed out")
558 status = dev[0].get_status()
559 if status['wpa_state'] != 'COMPLETED':
560 raise Exception("Not fully connected")
561 if status['pairwise_cipher'] != 'CCMP' or status['group_cipher'] != 'TKIP':
562 raise Exception("Unexpected encryption configuration")
563 if status['key_mgmt'] != 'WPA2-PSK':
564 raise Exception("Unexpected key_mgmt")
565
566 def test_ap_wps_new_version_sta(dev, apdev):
567 """WPS compatibility with new version number on the station"""
568 ssid = "test-wps-ver"
569 hostapd.add_ap(apdev[0]['ifname'],
570 { "ssid": ssid, "eap_server": "1", "wps_state": "2",
571 "wpa_passphrase": "12345678", "wpa": "2",
572 "wpa_key_mgmt": "WPA-PSK", "rsn_pairwise": "CCMP" })
573 hapd = hostapd.Hostapd(apdev[0]['ifname'])
574 logger.info("WPS provisioning step")
575 hapd.request("WPS_PBC")
576 dev[0].request("SET ignore_old_scan_res 1")
577 dev[0].dump_monitor()
578 dev[0].request("SET wps_version_number 0x43")
579 dev[0].request("WPS_PBC")
580 ev = dev[0].wait_event(["CTRL-EVENT-CONNECTED"], timeout=30)
581 if ev is None:
582 raise Exception("Association with the AP timed out")
583
584 def test_ap_wps_new_version_ap(dev, apdev):
585 """WPS compatibility with new version number on the AP"""
586 ssid = "test-wps-ver"
587 hostapd.add_ap(apdev[0]['ifname'],
588 { "ssid": ssid, "eap_server": "1", "wps_state": "2",
589 "wpa_passphrase": "12345678", "wpa": "2",
590 "wpa_key_mgmt": "WPA-PSK", "rsn_pairwise": "CCMP" })
591 hapd = hostapd.Hostapd(apdev[0]['ifname'])
592 logger.info("WPS provisioning step")
593 if "FAIL" in hapd.request("SET wps_version_number 0x43"):
594 raise Exception("Failed to enable test functionality")
595 hapd.request("WPS_PBC")
596 dev[0].request("SET ignore_old_scan_res 1")
597 dev[0].dump_monitor()
598 dev[0].request("WPS_PBC")
599 ev = dev[0].wait_event(["CTRL-EVENT-CONNECTED"], timeout=30)
600 hapd.request("SET wps_version_number 0x20")
601 if ev is None:
602 raise Exception("Association with the AP timed out")