]>
git.ipfire.org Git - thirdparty/hostap.git/blob - tests/hwsim/test_nfc_wps.py
2 # Copyright (c) 2013, Jouni Malinen <j@w1.fi>
4 # This software may be distributed under the terms of the BSD license.
5 # See README for more details.
10 logger
= logging
.getLogger()
15 def check_wpa2_connection(sta
, ap
, ssid
, mixed
=False):
16 status
= sta
.get_status()
17 if status
['wpa_state'] != 'COMPLETED':
18 raise Exception("Not fully connected")
19 if status
['bssid'] != ap
['bssid']:
20 raise Exception("Unexpected BSSID")
21 if status
['ssid'] != ssid
:
22 raise Exception("Unexpected SSID")
23 if status
['pairwise_cipher'] != 'CCMP':
24 raise Exception("Unexpected encryption configuration")
25 if status
['group_cipher'] != 'CCMP' and not mixed
:
26 raise Exception("Unexpected encryption configuration")
27 if status
['key_mgmt'] != 'WPA2-PSK':
28 raise Exception("Unexpected key_mgmt")
29 hwsim_utils
.test_connectivity(sta
.ifname
, ap
['ifname'])
31 def ap_wps_params(ssid
):
32 return { "ssid": ssid
, "eap_server": "1", "wps_state": "2",
33 "wpa_passphrase": "12345678", "wpa": "2",
34 "wpa_key_mgmt": "WPA-PSK", "rsn_pairwise": "CCMP"}
36 def test_nfc_wps_password_token_sta(dev
, apdev
):
37 """NFC tag with password token on the station/Enrollee"""
38 ssid
= "test-wps-nfc-pw-token-conf"
39 params
= ap_wps_params(ssid
)
40 hostapd
.add_ap(apdev
[0]['ifname'], params
)
41 hapd
= hostapd
.Hostapd(apdev
[0]['ifname'])
42 logger
.info("WPS provisioning step using password token from station")
43 pw
= dev
[0].request("WPS_NFC_TOKEN NDEF").rstrip()
45 raise Exception("Failed to generate password token")
46 res
= hapd
.request("WPS_NFC_TAG_READ " + pw
)
48 raise Exception("Failed to provide NFC tag contents to hostapd")
50 res
= dev
[0].request("WPS_NFC")
52 raise Exception("Failed to start Enrollee using NFC password token")
53 ev
= dev
[0].wait_event(["CTRL-EVENT-CONNECTED"], timeout
=30)
55 raise Exception("Association with the AP timed out")
56 check_wpa2_connection(dev
[0], apdev
[0], ssid
)
58 def test_nfc_wps_config_token(dev
, apdev
):
59 """NFC tag with configuration token from AP"""
60 ssid
= "test-wps-nfc-conf-token"
61 params
= ap_wps_params(ssid
)
62 hostapd
.add_ap(apdev
[0]['ifname'], params
)
63 hapd
= hostapd
.Hostapd(apdev
[0]['ifname'])
64 logger
.info("NFC configuration token from AP to station")
65 conf
= hapd
.request("WPS_NFC_CONFIG_TOKEN NDEF").rstrip()
67 raise Exception("Failed to generate configuration token")
69 res
= dev
[0].request("WPS_NFC_TAG_READ " + conf
)
71 raise Exception("Failed to provide NFC tag contents to wpa_supplicant")
72 ev
= dev
[0].wait_event(["CTRL-EVENT-CONNECTED"], timeout
=15)
74 raise Exception("Association with the AP timed out")
75 check_wpa2_connection(dev
[0], apdev
[0], ssid
)
77 def test_nfc_wps_config_token_init(dev
, apdev
):
78 """NFC tag with configuration token from AP with auto configuration"""
79 ssid
= "test-wps-nfc-conf-token-init"
80 hostapd
.add_ap(apdev
[0]['ifname'],
81 { "ssid": ssid
, "eap_server": "1", "wps_state": "1" })
82 hapd
= hostapd
.Hostapd(apdev
[0]['ifname'])
83 logger
.info("NFC configuration token from AP to station")
84 conf
= hapd
.request("WPS_NFC_CONFIG_TOKEN NDEF").rstrip()
86 raise Exception("Failed to generate configuration token")
88 res
= dev
[0].request("WPS_NFC_TAG_READ " + conf
)
90 raise Exception("Failed to provide NFC tag contents to wpa_supplicant")
91 ev
= dev
[0].wait_event(["CTRL-EVENT-CONNECTED"], timeout
=15)
93 raise Exception("Association with the AP timed out")
94 check_wpa2_connection(dev
[0], apdev
[0], ssid
, mixed
=True)
96 def test_nfc_wps_password_token_sta_init(dev
, apdev
):
97 """Initial AP configuration with first WPS NFC Enrollee"""
98 ssid
= "test-wps-nfc-pw-token-init"
99 hostapd
.add_ap(apdev
[0]['ifname'],
100 { "ssid": ssid
, "eap_server": "1", "wps_state": "1" })
101 hapd
= hostapd
.Hostapd(apdev
[0]['ifname'])
102 logger
.info("WPS provisioning step using password token from station")
103 pw
= dev
[0].request("WPS_NFC_TOKEN NDEF").rstrip()
105 raise Exception("Failed to generate password token")
106 res
= hapd
.request("WPS_NFC_TAG_READ " + pw
)
108 raise Exception("Failed to provide NFC tag contents to hostapd")
109 dev
[0].dump_monitor()
110 res
= dev
[0].request("WPS_NFC")
112 raise Exception("Failed to start Enrollee using NFC password token")
113 ev
= dev
[0].wait_event(["CTRL-EVENT-CONNECTED"], timeout
=30)
115 raise Exception("Association with the AP timed out")
116 check_wpa2_connection(dev
[0], apdev
[0], ssid
, mixed
=True)
118 def test_nfc_wps_password_token_ap(dev
, apdev
):
119 """WPS registrar configuring an AP using AP password token"""
120 ssid
= "test-wps-nfc-pw-token-init"
121 hostapd
.add_ap(apdev
[0]['ifname'],
122 { "ssid": ssid
, "eap_server": "1", "wps_state": "1" })
123 hapd
= hostapd
.Hostapd(apdev
[0]['ifname'])
124 logger
.info("WPS configuration step")
125 pw
= hapd
.request("WPS_NFC_TOKEN NDEF").rstrip()
127 raise Exception("Failed to generate password token")
128 res
= hapd
.request("WPS_NFC_TOKEN enable")
130 raise Exception("Failed to enable AP password token")
131 res
= dev
[0].request("WPS_NFC_TAG_READ " + pw
)
133 raise Exception("Failed to provide NFC tag contents to wpa_supplicant")
134 dev
[0].dump_monitor()
135 new_ssid
= "test-wps-nfc-pw-token-new-ssid"
136 new_passphrase
= "1234567890"
137 res
= dev
[0].request("WPS_REG " + apdev
[0]['bssid'] + " nfc-pw " + new_ssid
.encode("hex") + " WPA2PSK CCMP " + new_passphrase
.encode("hex"))
139 raise Exception("Failed to start Registrar using NFC password token")
140 ev
= dev
[0].wait_event(["CTRL-EVENT-CONNECTED"], timeout
=30)
142 raise Exception("Association with the AP timed out")
143 check_wpa2_connection(dev
[0], apdev
[0], new_ssid
, mixed
=True)
144 if "FAIL" in hapd
.request("WPS_NFC_TOKEN disable"):
145 raise Exception("Failed to disable AP password token")
146 if "FAIL" in hapd
.request("WPS_NFC_TOKEN WPS"):
147 raise Exception("Unexpected WPS_NFC_TOKEN WPS failure")
149 def test_nfc_wps_handover_init(dev
, apdev
):
150 """Connect to WPS AP with NFC connection handover and move to configured state"""
151 dev
[0].request("SET ignore_old_scan_res 1")
152 ssid
= "test-wps-nfc-handover-init"
153 hostapd
.add_ap(apdev
[0]['ifname'],
154 { "ssid": ssid
, "eap_server": "1", "wps_state": "1" })
155 hapd
= hostapd
.Hostapd(apdev
[0]['ifname'])
156 logger
.info("NFC connection handover")
157 req
= dev
[0].request("NFC_GET_HANDOVER_REQ NDEF WPS-CR").rstrip()
159 raise Exception("Failed to generate NFC connection handover request")
160 sel
= hapd
.request("NFC_GET_HANDOVER_SEL NDEF WPS-CR").rstrip()
162 raise Exception("Failed to generate NFC connection handover select")
163 res
= hapd
.request("NFC_REPORT_HANDOVER RESP WPS " + req
+ " " + sel
)
165 raise Exception("Failed to report NFC connection handover to to hostapd")
166 dev
[0].dump_monitor()
167 res
= dev
[0].request("NFC_REPORT_HANDOVER INIT WPS " + req
+ " " + sel
)
169 raise Exception("Failed to report NFC connection handover to to wpa_supplicant")
170 ev
= dev
[0].wait_event(["CTRL-EVENT-CONNECTED"], timeout
=15)
172 raise Exception("Association with the AP timed out")
173 check_wpa2_connection(dev
[0], apdev
[0], ssid
, mixed
=True)
175 def test_nfc_wps_handover_errors(dev
, apdev
):
176 """WPS AP NFC handover report error cases"""
177 ssid
= "test-wps-nfc-handover"
178 hostapd
.add_ap(apdev
[0]['ifname'],
179 { "ssid": ssid
, "eap_server": "1", "wps_state": "1" })
180 hapd
= hostapd
.Hostapd(apdev
[0]['ifname'])
181 sel
= hapd
.request("NFC_GET_HANDOVER_SEL NDEF WPS-CR").rstrip()
183 raise Exception("Failed to generate NFC connection handover select")
184 if "FAIL" not in hapd
.request("NFC_REPORT_HANDOVER "):
185 raise Exception("Unexpected handover report success")
186 if "FAIL" not in hapd
.request("NFC_REPORT_HANDOVER RESP"):
187 raise Exception("Unexpected handover report success")
188 if "FAIL" not in hapd
.request("NFC_REPORT_HANDOVER RESP WPS"):
189 raise Exception("Unexpected handover report success")
190 if "FAIL" not in hapd
.request("NFC_REPORT_HANDOVER RESP WPS 001122"):
191 raise Exception("Unexpected handover report success")
192 if "FAIL" not in hapd
.request("NFC_REPORT_HANDOVER RESP WPS 001122 00"):
193 raise Exception("Unexpected handover report success")
194 if "FAIL" not in hapd
.request("NFC_REPORT_HANDOVER RESP WPS 0 00"):
195 raise Exception("Unexpected handover report success")
196 if "FAIL" not in hapd
.request("NFC_REPORT_HANDOVER RESP WPS 001122 0"):
197 raise Exception("Unexpected handover report success")
198 if "FAIL" not in hapd
.request("NFC_REPORT_HANDOVER RESP WPS 00q122 001122"):
199 raise Exception("Unexpected handover report success")
200 if "FAIL" not in hapd
.request("NFC_REPORT_HANDOVER RESP WPS 001122 001q22"):
201 raise Exception("Unexpected handover report success")
202 if "FAIL" not in hapd
.request("NFC_REPORT_HANDOVER RESP FOO 001122 00"):
203 raise Exception("Unexpected handover report success")
205 def test_nfc_wps_handover(dev
, apdev
):
206 """Connect to WPS AP with NFC connection handover"""
207 ssid
= "test-wps-nfc-handover"
208 params
= ap_wps_params(ssid
)
209 hostapd
.add_ap(apdev
[0]['ifname'], params
)
210 hapd
= hostapd
.Hostapd(apdev
[0]['ifname'])
211 logger
.info("NFC connection handover")
212 req
= dev
[0].request("NFC_GET_HANDOVER_REQ NDEF WPS-CR").rstrip()
214 raise Exception("Failed to generate NFC connection handover request")
215 sel
= hapd
.request("NFC_GET_HANDOVER_SEL NDEF WPS-CR").rstrip()
217 raise Exception("Failed to generate NFC connection handover select")
218 res
= hapd
.request("NFC_REPORT_HANDOVER RESP WPS " + req
+ " " + sel
)
220 raise Exception("Failed to report NFC connection handover to to hostapd")
221 dev
[0].dump_monitor()
222 res
= dev
[0].request("NFC_REPORT_HANDOVER INIT WPS " + req
+ " " + sel
)
224 raise Exception("Failed to report NFC connection handover to to wpa_supplicant")
225 ev
= dev
[0].wait_event(["CTRL-EVENT-CONNECTED"], timeout
=30)
227 raise Exception("Association with the AP timed out")
228 check_wpa2_connection(dev
[0], apdev
[0], ssid
)
230 def test_nfc_wps_handover_5ghz(dev
, apdev
):
231 """Connect to WPS AP with NFC connection handover on 5 GHz band"""
233 ssid
= "test-wps-nfc-handover"
234 params
= ap_wps_params(ssid
)
235 params
["country_code"] = "FI"
236 params
["hw_mode"] = "a"
237 params
["channel"] = "36"
238 hapd
= hostapd
.add_ap(apdev
[0]['ifname'], params
)
239 logger
.info("NFC connection handover")
240 req
= dev
[0].request("NFC_GET_HANDOVER_REQ NDEF WPS-CR").rstrip()
242 raise Exception("Failed to generate NFC connection handover request")
243 sel
= hapd
.request("NFC_GET_HANDOVER_SEL NDEF WPS-CR").rstrip()
245 raise Exception("Failed to generate NFC connection handover select")
246 res
= hapd
.request("NFC_REPORT_HANDOVER RESP WPS " + req
+ " " + sel
)
248 raise Exception("Failed to report NFC connection handover to to hostapd")
249 dev
[0].dump_monitor()
250 res
= dev
[0].request("NFC_REPORT_HANDOVER INIT WPS " + req
+ " " + sel
)
252 raise Exception("Failed to report NFC connection handover to to wpa_supplicant")
253 ev
= dev
[0].wait_event(["CTRL-EVENT-CONNECTED"], timeout
=30)
255 raise Exception("Association with the AP timed out")
256 check_wpa2_connection(dev
[0], apdev
[0], ssid
)
258 subprocess
.call(['sudo', 'iw', 'reg', 'set', '00'])
260 def test_nfc_wps_handover_chan14(dev
, apdev
):
261 """Connect to WPS AP with NFC connection handover on channel 14"""
263 ssid
= "test-wps-nfc-handover"
264 params
= ap_wps_params(ssid
)
265 params
["country_code"] = "JP"
266 params
["hw_mode"] = "b"
267 params
["channel"] = "14"
268 hapd
= hostapd
.add_ap(apdev
[0]['ifname'], params
)
269 logger
.info("NFC connection handover")
270 req
= dev
[0].request("NFC_GET_HANDOVER_REQ NDEF WPS-CR").rstrip()
272 raise Exception("Failed to generate NFC connection handover request")
273 sel
= hapd
.request("NFC_GET_HANDOVER_SEL NDEF WPS-CR").rstrip()
275 raise Exception("Failed to generate NFC connection handover select")
276 res
= hapd
.request("NFC_REPORT_HANDOVER RESP WPS " + req
+ " " + sel
)
278 raise Exception("Failed to report NFC connection handover to to hostapd")
279 dev
[0].dump_monitor()
280 res
= dev
[0].request("NFC_REPORT_HANDOVER INIT WPS " + req
+ " " + sel
)
282 raise Exception("Failed to report NFC connection handover to to wpa_supplicant")
283 ev
= dev
[0].wait_event(["CTRL-EVENT-CONNECTED"], timeout
=30)
285 raise Exception("Association with the AP timed out")
286 check_wpa2_connection(dev
[0], apdev
[0], ssid
)
288 subprocess
.call(['sudo', 'iw', 'reg', 'set', '00'])
290 def test_nfc_wps_handover_with_pw_token_set(dev
, apdev
):
291 """Connect to WPS AP with NFC connection handover (wps_nfc_* set)"""
292 ssid
= "test-wps-nfc-handover2"
293 params
= ap_wps_params(ssid
)
294 hostapd
.add_ap(apdev
[0]['ifname'], params
)
295 hapd
= hostapd
.Hostapd(apdev
[0]['ifname'])
296 # enable a password token (which won't be used in this test case)
297 pw
= hapd
.request("WPS_NFC_TOKEN NDEF").rstrip()
299 raise Exception("Failed to generate password token")
300 res
= hapd
.request("WPS_NFC_TOKEN enable")
302 raise Exception("Failed to enable AP password token")
303 logger
.info("NFC connection handover")
304 req
= dev
[0].request("NFC_GET_HANDOVER_REQ NDEF WPS-CR").rstrip()
306 raise Exception("Failed to generate NFC connection handover request")
307 sel
= hapd
.request("NFC_GET_HANDOVER_SEL NDEF WPS-CR").rstrip()
309 raise Exception("Failed to generate NFC connection handover select")
310 res
= hapd
.request("NFC_REPORT_HANDOVER RESP WPS " + req
+ " " + sel
)
312 raise Exception("Failed to report NFC connection handover to to hostapd")
313 dev
[0].dump_monitor()
314 res
= dev
[0].request("NFC_REPORT_HANDOVER INIT WPS " + req
+ " " + sel
)
316 raise Exception("Failed to report NFC connection handover to to wpa_supplicant")
317 ev
= dev
[0].wait_event(["CTRL-EVENT-CONNECTED"], timeout
=15)
319 raise Exception("Association with the AP timed out")
320 check_wpa2_connection(dev
[0], apdev
[0], ssid
)
322 def test_nfc_wps_handover_pk_hash_mismatch_sta(dev
, apdev
):
323 """WPS NFC connection handover with invalid pkhash from station (negative)"""
324 ssid
= "wps-nfc-handover-pkhash-sta"
325 if "FAIL" in dev
[0].request("SET wps_corrupt_pkhash 1"):
326 raise Exception("Could not enable wps_corrupt_pkhash")
327 params
= ap_wps_params(ssid
)
328 hostapd
.add_ap(apdev
[0]['ifname'], params
)
329 hapd
= hostapd
.Hostapd(apdev
[0]['ifname'])
330 logger
.info("NFC connection handover")
331 req
= dev
[0].request("NFC_GET_HANDOVER_REQ NDEF WPS-CR").rstrip()
333 raise Exception("Failed to generate NFC connection handover request")
334 sel
= hapd
.request("NFC_GET_HANDOVER_SEL NDEF WPS-CR").rstrip()
336 raise Exception("Failed to generate NFC connection handover select")
337 res
= hapd
.request("NFC_REPORT_HANDOVER RESP WPS " + req
+ " " + sel
)
339 raise Exception("Failed to report NFC connection handover to to hostapd")
340 dev
[0].dump_monitor()
341 res
= dev
[0].request("NFC_REPORT_HANDOVER INIT WPS " + req
+ " " + sel
)
343 raise Exception("Failed to report NFC connection handover to to wpa_supplicant")
344 ev
= dev
[0].wait_event(["CTRL-EVENT-CONNECTED", "WPS-FAIL"], timeout
=15)
346 raise Exception("Timed out")
347 if "WPS-FAIL" not in ev
:
348 raise Exception("Public key hash mismatch not detected")
350 def test_nfc_wps_handover_pk_hash_mismatch_ap(dev
, apdev
):
351 """WPS NFC connection handover with invalid pkhash from AP (negative)"""
352 ssid
= "wps-nfc-handover-pkhash-ap"
353 params
= ap_wps_params(ssid
)
354 hostapd
.add_ap(apdev
[0]['ifname'], params
)
355 hapd
= hostapd
.Hostapd(apdev
[0]['ifname'])
356 if "FAIL" in hapd
.request("SET wps_corrupt_pkhash 1"):
357 raise Exception("Could not enable wps_corrupt_pkhash")
358 logger
.info("NFC connection handover")
359 req
= dev
[0].request("NFC_GET_HANDOVER_REQ NDEF WPS-CR").rstrip()
361 raise Exception("Failed to generate NFC connection handover request")
362 sel
= hapd
.request("NFC_GET_HANDOVER_SEL NDEF WPS-CR").rstrip()
364 raise Exception("Failed to generate NFC connection handover select")
365 res
= hapd
.request("NFC_REPORT_HANDOVER RESP WPS " + req
+ " " + sel
)
367 raise Exception("Failed to report NFC connection handover to to hostapd")
368 dev
[0].dump_monitor()
369 res
= dev
[0].request("NFC_REPORT_HANDOVER INIT WPS " + req
+ " " + sel
)
371 raise Exception("Failed to report NFC connection handover to to wpa_supplicant")
372 ev
= dev
[0].wait_event(["CTRL-EVENT-CONNECTED", "WPS-FAIL"], timeout
=15)
374 raise Exception("Timed out")
375 if "WPS-FAIL" not in ev
:
376 raise Exception("Public key hash mismatch not detected")
378 def start_ap_er(er
, ap
, ssid
):
380 ap_uuid
= "27ea801a-9e5c-4e73-bd82-f89cbcd10d7e"
381 hostapd
.add_ap(ap
['ifname'],
382 { "ssid": ssid
, "eap_server": "1", "wps_state": "2",
383 "wpa_passphrase": "12345678", "wpa": "2",
384 "wpa_key_mgmt": "WPA-PSK", "rsn_pairwise": "CCMP",
385 "device_name": "Wireless AP", "manufacturer": "Company",
386 "model_name": "WAP", "model_number": "123",
387 "serial_number": "12345", "device_type": "6-0050F204-1",
388 "os_version": "01020300",
389 "config_methods": "label push_button",
390 "ap_pin": ap_pin
, "uuid": ap_uuid
, "upnp_iface": "lo"})
391 logger
.info("Learn AP configuration")
393 er
.request("SET ignore_old_scan_res 1")
394 er
.wps_reg(ap
['bssid'], ap_pin
)
396 logger
.info("Start ER")
397 er
.request("WPS_ER_STOP")
399 er
.request("WPS_ER_START ifname=lo")
400 ev
= er
.wait_event(["WPS-ER-AP-ADD"], timeout
=15)
402 raise Exception("AP discovery timed out")
403 if ap_uuid
not in ev
:
404 raise Exception("Expected AP UUID not found")
406 logger
.info("Use learned network configuration on ER")
407 er
.request("WPS_ER_SET_CONFIG " + ap_uuid
+ " 0")
409 def test_nfc_wps_er_pw_token(dev
, apdev
):
410 """WPS NFC password token from Enrollee to ER"""
411 ssid
= "wps-nfc-er-pw-token"
412 start_ap_er(dev
[0], apdev
[0], ssid
)
413 logger
.info("WPS provisioning step using password token from station")
414 dev
[1].request("SET ignore_old_scan_res 1")
415 pw
= dev
[1].request("WPS_NFC_TOKEN NDEF").rstrip()
417 raise Exception("Failed to generate password token")
418 res
= dev
[0].request("WPS_NFC_TAG_READ " + pw
)
420 raise Exception("Failed to provide NFC tag contents to WPS ER")
421 dev
[0].dump_monitor()
422 res
= dev
[1].request("WPS_NFC")
424 raise Exception("Failed to start Enrollee using NFC password token")
425 ev
= dev
[0].wait_event(["WPS-SUCCESS"], timeout
=15)
427 raise Exception("WPS ER did not report success")
428 ev
= dev
[1].wait_event(["CTRL-EVENT-CONNECTED"], timeout
=15)
430 raise Exception("Association with the AP timed out")
431 check_wpa2_connection(dev
[1], apdev
[0], ssid
)
433 def test_nfc_wps_er_config_token(dev
, apdev
):
434 """WPS NFC configuration token from ER to Enrollee"""
435 ssid
= "wps-nfc-er-config-token"
436 start_ap_er(dev
[0], apdev
[0], ssid
)
437 logger
.info("WPS provisioning step using configuration token from ER")
438 conf
= dev
[0].request("WPS_ER_NFC_CONFIG_TOKEN NDEF " + apdev
[0]['bssid']).rstrip()
440 raise Exception("Failed to generate configugration token")
441 dev
[1].request("SET ignore_old_scan_res 1")
442 res
= dev
[1].request("WPS_NFC_TAG_READ " + conf
)
444 raise Exception("Failed to provide NFC tag contents to wpa_supplicant")
445 ev
= dev
[1].wait_event(["CTRL-EVENT-CONNECTED"], timeout
=15)
447 raise Exception("Association with the AP timed out")
448 check_wpa2_connection(dev
[1], apdev
[0], ssid
)
450 def test_nfc_wps_er_handover(dev
, apdev
):
451 """WPS NFC connection handover between Enrollee and ER"""
452 ssid
= "wps-nfc-er-handover"
453 start_ap_er(dev
[0], apdev
[0], ssid
)
454 logger
.info("WPS provisioning step using connection handover")
455 req
= dev
[1].request("NFC_GET_HANDOVER_REQ NDEF WPS-CR").rstrip()
457 raise Exception("Failed to generate NFC connection handover request")
458 sel
= dev
[0].request("NFC_GET_HANDOVER_SEL NDEF WPS-CR " + apdev
[0]['bssid']).rstrip()
460 raise Exception("Failed to generate NFC connection handover select")
461 res
= dev
[0].request("NFC_REPORT_HANDOVER RESP WPS " + req
+ " " + sel
)
463 raise Exception("Failed to report NFC connection handover to to hostapd")
464 dev
[1].dump_monitor()
465 res
= dev
[1].request("NFC_REPORT_HANDOVER INIT WPS " + req
+ " " + sel
)
467 raise Exception("Failed to report NFC connection handover to to wpa_supplicant")
468 ev
= dev
[1].wait_event(["CTRL-EVENT-CONNECTED"], timeout
=15)
470 raise Exception("Association with the AP timed out")
471 check_wpa2_connection(dev
[1], apdev
[0], ssid
)
473 def test_nfc_wps_er_handover_pk_hash_mismatch_sta(dev
, apdev
):
474 """WPS NFC connection handover with invalid pkhash from station to ER (negative)"""
475 ssid
= "wps-nfc-er-handover-pkhash-sta"
476 start_ap_er(dev
[0], apdev
[0], ssid
)
477 logger
.info("WPS provisioning step using connection handover")
478 if "FAIL" in dev
[1].request("SET wps_corrupt_pkhash 1"):
479 raise Exception("Could not enable wps_corrupt_pkhash")
480 dev
[1].request("SET ignore_old_scan_res 1")
481 req
= dev
[1].request("NFC_GET_HANDOVER_REQ NDEF WPS-CR").rstrip()
483 raise Exception("Failed to generate NFC connection handover request")
484 sel
= dev
[0].request("NFC_GET_HANDOVER_SEL NDEF WPS-CR " + apdev
[0]['bssid']).rstrip()
486 raise Exception("Failed to generate NFC connection handover select")
487 res
= dev
[0].request("NFC_REPORT_HANDOVER RESP WPS " + req
+ " " + sel
)
489 raise Exception("Failed to report NFC connection handover to to hostapd")
490 dev
[1].dump_monitor()
491 res
= dev
[1].request("NFC_REPORT_HANDOVER INIT WPS " + req
+ " " + sel
)
493 raise Exception("Failed to report NFC connection handover to to wpa_supplicant")
494 ev
= dev
[1].wait_event(["CTRL-EVENT-CONNECTED", "WPS-FAIL"], timeout
=15)
496 raise Exception("Timed out")
497 if "WPS-FAIL" not in ev
:
498 raise Exception("Public key hash mismatch not detected")
500 def test_nfc_wps_er_handover_pk_hash_mismatch_er(dev
, apdev
):
501 """WPS NFC connection handover with invalid pkhash from ER to station (negative)"""
502 ssid
= "wps-nfc-er-handover-pkhash-er"
503 start_ap_er(dev
[0], apdev
[0], ssid
)
504 logger
.info("WPS provisioning step using connection handover")
505 if "FAIL" in dev
[0].request("SET wps_corrupt_pkhash 1"):
506 raise Exception("Could not enable wps_corrupt_pkhash")
507 dev
[1].request("SET ignore_old_scan_res 1")
508 req
= dev
[1].request("NFC_GET_HANDOVER_REQ NDEF WPS-CR").rstrip()
510 raise Exception("Failed to generate NFC connection handover request")
511 sel
= dev
[0].request("NFC_GET_HANDOVER_SEL NDEF WPS-CR " + apdev
[0]['bssid']).rstrip()
513 raise Exception("Failed to generate NFC connection handover select")
514 res
= dev
[0].request("NFC_REPORT_HANDOVER RESP WPS " + req
+ " " + sel
)
516 raise Exception("Failed to report NFC connection handover to to hostapd")
517 dev
[1].dump_monitor()
518 res
= dev
[1].request("NFC_REPORT_HANDOVER INIT WPS " + req
+ " " + sel
)
520 raise Exception("Failed to report NFC connection handover to to wpa_supplicant")
521 ev
= dev
[1].wait_event(["CTRL-EVENT-CONNECTED", "WPS-FAIL"], timeout
=15)
523 raise Exception("Timed out")
524 if "WPS-FAIL" not in ev
:
525 raise Exception("Public key hash mismatch not detected")