]>
git.ipfire.org Git - thirdparty/hostap.git/blob - tests/hwsim/test_ap_wps.py
4 # Copyright (c) 2013, Jouni Malinen <j@w1.fi>
6 # This software may be distributed under the terms of the BSD license.
7 # See README for more details.
12 logger
= logging
.getLogger()
17 def test_ap_wps_init(dev
, apdev
):
18 """Initial AP configuration with first WPS Enrollee"""
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")
27 dev
[0].request("WPS_PBC")
28 ev
= dev
[0].wait_event(["CTRL-EVENT-CONNECTED"], timeout
=30)
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")
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")
52 dev
[0].request("WPS_PBC")
53 ev
= dev
[0].wait_event(["CTRL-EVENT-CONNECTED"], timeout
=30)
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")
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")
80 dev
[0].request("WPS_PBC")
81 ev
= dev
[0].wait_event(["CTRL-EVENT-CONNECTED"], timeout
=30)
83 raise Exception("Association with the AP timed out")
84 dev
[0].request("DISCONNECT")
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")
95 dev
[0].request("WPS_PBC")
96 ev
= dev
[0].wait_event(["CTRL-EVENT-CONNECTED"], timeout
=30)
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")
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'])
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)
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"])
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)
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)
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"])
144 raise Exception("Timeout on disconnection event")
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)
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")
173 def test_ap_wps_reg_connect(dev
, apdev
):
174 """WPS registrar using AP PIN to connect"""
175 ssid
= "test-wps-reg-ap-pin"
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",
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")
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"
200 hostapd
.add_ap(apdev
[0]['ifname'],
201 { "ssid": ssid
, "eap_server": "1", "wps_state": "2",
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",
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")
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"
224 hostapd
.add_ap(apdev
[0]['ifname'],
225 { "ssid": ssid
, "eap_server": "1", "wps_state": "1",
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",
235 logger
.info("Re-connect to verify WPA2 mixed mode")
236 dev
[0].request("DISCONNECT")
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")
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"
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",
260 dev
[0].request("SET ignore_old_scan_res 1")
261 new_ssid
= "wps-new-ssid-test"
262 new_passphrase
= "1234567890"
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"])
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")
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"])
282 raise Exception("Timeout on disconnection event")
284 if not ap_setup_locked
:
285 raise Exception("AP setup was not locked")
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)
296 raise Exception("WPS success was not reported")
297 ev
= dev
[0].wait_event(["CTRL-EVENT-CONNECTED"], timeout
=30)
299 raise Exception("Association with the AP timed out")
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)
322 raise Exception("PBC session overlap not detected")
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)
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)
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)")
351 def test_ap_wps_cancel(dev
, apdev
):
352 """WPS AP cancelling enabled config method"""
353 ssid
= "test-wps-ap-cancel"
354 hostapd
.add_ap(apdev
[0]['ifname'],
355 { "ssid": ssid
, "eap_server": "1", "wps_state": "2",
356 "wpa_passphrase": "12345678", "wpa": "2",
357 "wpa_key_mgmt": "WPA-PSK", "rsn_pairwise": "CCMP" })
358 bssid
= apdev
[0]['bssid']
359 hapd
= hostapd
.Hostapd(apdev
[0]['ifname'])
361 logger
.info("Verify PBC enable/cancel")
362 hapd
.request("WPS_PBC")
363 dev
[0].request("SET ignore_old_scan_res 1")
364 dev
[0].scan(freq
="2412")
365 bss
= dev
[0].get_bss(apdev
[0]['bssid'])
366 if "[WPS-PBC]" not in bss
['flags']:
367 raise Exception("WPS-PBC flag missing")
368 if "FAIL" in hapd
.request("WPS_CANCEL"):
369 raise Exception("WPS_CANCEL failed")
370 dev
[0].scan(freq
="2412")
371 bss
= dev
[0].get_bss(apdev
[0]['bssid'])
372 if "[WPS-PBC]" in bss
['flags']:
373 raise Exception("WPS-PBC flag not cleared")
375 logger
.info("Verify PIN enable/cancel")
376 hapd
.request("WPS_PIN any 12345670")
377 dev
[0].scan(freq
="2412")
378 bss
= dev
[0].get_bss(apdev
[0]['bssid'])
379 if "[WPS-AUTH]" not in bss
['flags']:
380 raise Exception("WPS-AUTH flag missing")
381 if "FAIL" in hapd
.request("WPS_CANCEL"):
382 raise Exception("WPS_CANCEL failed")
383 dev
[0].scan(freq
="2412")
384 bss
= dev
[0].get_bss(apdev
[0]['bssid'])
385 if "[WPS-AUTH]" in bss
['flags']:
386 raise Exception("WPS-AUTH flag not cleared")
388 def test_ap_wps_er_add_enrollee(dev
, apdev
):
389 """WPS ER configuring AP and adding a new enrollee using PIN"""
390 ssid
= "wps-er-add-enrollee"
392 ap_uuid
= "27ea801a-9e5c-4e73-bd82-f89cbcd10d7e"
393 hostapd
.add_ap(apdev
[0]['ifname'],
394 { "ssid": ssid
, "eap_server": "1", "wps_state": "1",
395 "device_name": "Wireless AP", "manufacturer": "Company",
396 "model_name": "WAP", "model_number": "123",
397 "serial_number": "12345", "device_type": "6-0050F204-1",
398 "os_version": "01020300",
399 "config_methods": "label push_button",
400 "ap_pin": ap_pin
, "uuid": ap_uuid
, "upnp_iface": "lo"})
401 logger
.info("WPS configuration step")
402 new_passphrase
= "1234567890"
403 dev
[0].dump_monitor()
404 dev
[0].request("SET ignore_old_scan_res 1")
405 dev
[0].wps_reg(apdev
[0]['bssid'], ap_pin
, ssid
, "WPA2PSK", "CCMP",
407 status
= dev
[0].get_status()
408 if status
['wpa_state'] != 'COMPLETED' or status
['bssid'] != apdev
[0]['bssid']:
409 raise Exception("Not fully connected")
410 if status
['ssid'] != ssid
:
411 raise Exception("Unexpected SSID")
412 if status
['pairwise_cipher'] != 'CCMP' or status
['group_cipher'] != 'CCMP':
413 raise Exception("Unexpected encryption configuration")
414 if status
['key_mgmt'] != 'WPA2-PSK':
415 raise Exception("Unexpected key_mgmt")
417 logger
.info("Start ER")
418 dev
[0].request("WPS_ER_START ifname=lo")
419 ev
= dev
[0].wait_event(["WPS-ER-AP-ADD"], timeout
=15)
421 raise Exception("AP discovery timed out")
422 if ap_uuid
not in ev
:
423 raise Exception("Expected AP UUID not found")
425 logger
.info("Learn AP configuration through UPnP")
426 dev
[0].dump_monitor()
427 dev
[0].request("WPS_ER_LEARN " + ap_uuid
+ " " + ap_pin
)
428 ev
= dev
[0].wait_event(["WPS-ER-AP-SETTINGS"], timeout
=15)
430 raise Exception("AP learn timed out")
431 if ap_uuid
not in ev
:
432 raise Exception("Expected AP UUID not in settings")
433 if "ssid=" + ssid
not in ev
:
434 raise Exception("Expected SSID not in settings")
435 if "key=" + new_passphrase
not in ev
:
436 raise Exception("Expected passphrase not in settings")
438 logger
.info("Add Enrollee using ER")
439 pin
= dev
[1].wps_read_pin()
440 dev
[0].dump_monitor()
441 dev
[0].request("WPS_ER_PIN any " + pin
+ " " + dev
[1].p2p_interface_addr())
442 dev
[1].request("SET ignore_old_scan_res 1")
443 dev
[1].dump_monitor()
444 dev
[1].request("WPS_PIN any " + pin
)
445 ev
= dev
[1].wait_event(["WPS-SUCCESS"], timeout
=30)
447 raise Exception("Enrollee did not report success")
448 ev
= dev
[1].wait_event(["CTRL-EVENT-CONNECTED"], timeout
=15)
450 raise Exception("Association with the AP timed out")
451 ev
= dev
[0].wait_event(["WPS-SUCCESS"], timeout
=15)
453 raise Exception("WPS ER did not report success")
454 hwsim_utils
.test_connectivity_sta(dev
[0], dev
[1])
456 logger
.info("Verify registrar selection behavior")
457 dev
[0].request("WPS_ER_PIN any " + pin
+ " " + dev
[1].p2p_interface_addr())
458 dev
[1].request("DISCONNECT")
459 dev
[1].wait_event(["CTRL-EVENT-DISCONNECTED"])
460 dev
[1].scan(freq
="2412")
461 bss
= dev
[1].get_bss(apdev
[0]['bssid'])
462 if "[WPS-AUTH]" not in bss
['flags']:
463 raise Exception("WPS-AUTH flag missing")
465 logger
.info("Stop ER")
466 dev
[0].dump_monitor()
467 dev
[0].request("WPS_ER_STOP")
468 ev
= dev
[0].wait_event(["WPS-ER-AP-REMOVE"])
470 raise Exception("WPS ER unsubscription timed out")
472 dev
[1].scan(freq
="2412")
473 bss
= dev
[1].get_bss(apdev
[0]['bssid'])
474 if "[WPS-AUTH]" in bss
['flags']:
475 raise Exception("WPS-AUTH flag not removed")
477 def test_ap_wps_er_add_enrollee_pbc(dev
, apdev
):
478 """WPS ER connected to AP and adding a new enrollee using PBC"""
479 ssid
= "wps-er-add-enrollee-pbc"
481 ap_uuid
= "27ea801a-9e5c-4e73-bd82-f89cbcd10d7e"
482 hostapd
.add_ap(apdev
[0]['ifname'],
483 { "ssid": ssid
, "eap_server": "1", "wps_state": "2",
484 "wpa_passphrase": "12345678", "wpa": "2",
485 "wpa_key_mgmt": "WPA-PSK", "rsn_pairwise": "CCMP",
486 "device_name": "Wireless AP", "manufacturer": "Company",
487 "model_name": "WAP", "model_number": "123",
488 "serial_number": "12345", "device_type": "6-0050F204-1",
489 "os_version": "01020300",
490 "config_methods": "label push_button",
491 "ap_pin": ap_pin
, "uuid": ap_uuid
, "upnp_iface": "lo"})
492 logger
.info("Learn AP configuration")
493 dev
[0].dump_monitor()
494 dev
[0].request("SET ignore_old_scan_res 1")
495 dev
[0].wps_reg(apdev
[0]['bssid'], ap_pin
)
496 status
= dev
[0].get_status()
497 if status
['wpa_state'] != 'COMPLETED' or status
['bssid'] != apdev
[0]['bssid']:
498 raise Exception("Not fully connected")
500 logger
.info("Start ER")
501 dev
[0].request("WPS_ER_START ifname=lo")
502 ev
= dev
[0].wait_event(["WPS-ER-AP-ADD"], timeout
=15)
504 raise Exception("AP discovery timed out")
505 if ap_uuid
not in ev
:
506 raise Exception("Expected AP UUID not found")
508 logger
.info("Use learned network configuration on ER")
509 dev
[0].request("WPS_ER_SET_CONFIG " + ap_uuid
+ " 0")
511 logger
.info("Add Enrollee using ER and PBC")
512 dev
[0].dump_monitor()
513 enrollee
= dev
[1].p2p_interface_addr()
514 dev
[1].request("SET ignore_old_scan_res 1")
515 dev
[1].dump_monitor()
516 dev
[1].request("WPS_PBC")
518 ev
= dev
[0].wait_event(["WPS-ER-ENROLLEE-ADD"], timeout
=15)
520 raise Exception("Enrollee discovery timed out")
521 if enrollee
not in ev
:
522 raise Exception("Expected Enrollee not found")
523 dev
[0].request("WPS_ER_PBC " + enrollee
)
525 ev
= dev
[1].wait_event(["WPS-SUCCESS"], timeout
=15)
527 raise Exception("Enrollee did not report success")
528 ev
= dev
[1].wait_event(["CTRL-EVENT-CONNECTED"], timeout
=15)
530 raise Exception("Association with the AP timed out")
531 ev
= dev
[0].wait_event(["WPS-SUCCESS"], timeout
=15)
533 raise Exception("WPS ER did not report success")
534 hwsim_utils
.test_connectivity_sta(dev
[0], dev
[1])
536 # verify BSSID selection of the AP instead of UUID
537 if "FAIL" in dev
[0].request("WPS_ER_SET_CONFIG " + apdev
[0]['bssid'] + " 0"):
538 raise Exception("Could not select AP based on BSSID")
540 def test_ap_wps_er_config_ap(dev
, apdev
):
541 """WPS ER configuring AP over UPnP"""
542 ssid
= "wps-er-ap-config"
544 ap_uuid
= "27ea801a-9e5c-4e73-bd82-f89cbcd10d7e"
545 hostapd
.add_ap(apdev
[0]['ifname'],
546 { "ssid": ssid
, "eap_server": "1", "wps_state": "2",
547 "wpa_passphrase": "12345678", "wpa": "2",
548 "wpa_key_mgmt": "WPA-PSK", "rsn_pairwise": "CCMP",
549 "device_name": "Wireless AP", "manufacturer": "Company",
550 "model_name": "WAP", "model_number": "123",
551 "serial_number": "12345", "device_type": "6-0050F204-1",
552 "os_version": "01020300",
553 "config_methods": "label push_button",
554 "ap_pin": ap_pin
, "uuid": ap_uuid
, "upnp_iface": "lo"})
556 logger
.info("Connect ER to the AP")
557 dev
[0].connect(ssid
, psk
="12345678", scan_freq
="2412")
559 logger
.info("WPS configuration step")
560 dev
[0].request("WPS_ER_START ifname=lo")
561 ev
= dev
[0].wait_event(["WPS-ER-AP-ADD"], timeout
=15)
563 raise Exception("AP discovery timed out")
564 if ap_uuid
not in ev
:
565 raise Exception("Expected AP UUID not found")
566 new_passphrase
= "1234567890"
567 dev
[0].request("WPS_ER_CONFIG " + apdev
[0]['bssid'] + " " + ap_pin
+ " " +
568 ssid
.encode("hex") + " WPA2PSK CCMP " +
569 new_passphrase
.encode("hex"))
570 ev
= dev
[0].wait_event(["WPS-SUCCESS"])
572 raise Exception("WPS ER configuration operation timed out")
573 dev
[1].wait_event(["CTRL-EVENT-DISCONNECTED"])
574 dev
[0].connect(ssid
, psk
="1234567890", scan_freq
="2412")
576 def test_ap_wps_fragmentation(dev
, apdev
):
577 """WPS with fragmentation in EAP-WSC and mixed mode WPA+WPA2"""
578 ssid
= "test-wps-fragmentation"
579 hostapd
.add_ap(apdev
[0]['ifname'],
580 { "ssid": ssid
, "eap_server": "1", "wps_state": "2",
581 "wpa_passphrase": "12345678", "wpa": "3",
582 "wpa_key_mgmt": "WPA-PSK", "rsn_pairwise": "CCMP",
583 "wpa_pairwise": "TKIP",
584 "fragment_size": "50" })
585 hapd
= hostapd
.Hostapd(apdev
[0]['ifname'])
586 logger
.info("WPS provisioning step")
587 hapd
.request("WPS_PBC")
588 dev
[0].request("SET ignore_old_scan_res 1")
589 dev
[0].dump_monitor()
590 dev
[0].request("SET wps_fragment_size 50")
591 dev
[0].request("WPS_PBC")
592 ev
= dev
[0].wait_event(["CTRL-EVENT-CONNECTED"], timeout
=30)
594 raise Exception("Association with the AP timed out")
595 status
= dev
[0].get_status()
596 if status
['wpa_state'] != 'COMPLETED':
597 raise Exception("Not fully connected")
598 if status
['pairwise_cipher'] != 'CCMP' or status
['group_cipher'] != 'TKIP':
599 raise Exception("Unexpected encryption configuration")
600 if status
['key_mgmt'] != 'WPA2-PSK':
601 raise Exception("Unexpected key_mgmt")
603 def test_ap_wps_new_version_sta(dev
, apdev
):
604 """WPS compatibility with new version number on the station"""
605 ssid
= "test-wps-ver"
606 hostapd
.add_ap(apdev
[0]['ifname'],
607 { "ssid": ssid
, "eap_server": "1", "wps_state": "2",
608 "wpa_passphrase": "12345678", "wpa": "2",
609 "wpa_key_mgmt": "WPA-PSK", "rsn_pairwise": "CCMP" })
610 hapd
= hostapd
.Hostapd(apdev
[0]['ifname'])
611 logger
.info("WPS provisioning step")
612 hapd
.request("WPS_PBC")
613 dev
[0].request("SET ignore_old_scan_res 1")
614 dev
[0].dump_monitor()
615 dev
[0].request("SET wps_version_number 0x43")
616 dev
[0].request("WPS_PBC")
617 ev
= dev
[0].wait_event(["CTRL-EVENT-CONNECTED"], timeout
=30)
619 raise Exception("Association with the AP timed out")
621 def test_ap_wps_new_version_ap(dev
, apdev
):
622 """WPS compatibility with new version number on the AP"""
623 ssid
= "test-wps-ver"
624 hostapd
.add_ap(apdev
[0]['ifname'],
625 { "ssid": ssid
, "eap_server": "1", "wps_state": "2",
626 "wpa_passphrase": "12345678", "wpa": "2",
627 "wpa_key_mgmt": "WPA-PSK", "rsn_pairwise": "CCMP" })
628 hapd
= hostapd
.Hostapd(apdev
[0]['ifname'])
629 logger
.info("WPS provisioning step")
630 if "FAIL" in hapd
.request("SET wps_version_number 0x43"):
631 raise Exception("Failed to enable test functionality")
632 hapd
.request("WPS_PBC")
633 dev
[0].request("SET ignore_old_scan_res 1")
634 dev
[0].dump_monitor()
635 dev
[0].request("WPS_PBC")
636 ev
= dev
[0].wait_event(["CTRL-EVENT-CONNECTED"], timeout
=30)
637 hapd
.request("SET wps_version_number 0x20")
639 raise Exception("Association with the AP timed out")