]> git.ipfire.org Git - thirdparty/hostap.git/blame - tests/hwsim/test_nfc_p2p.py
tests: Add wait_connected() and wait_disconnected() helpers
[thirdparty/hostap.git] / tests / hwsim / test_nfc_p2p.py
CommitLineData
c9dc5623
JM
1# P2P+NFC tests
2# Copyright (c) 2013, Qualcomm Atheros, Inc.
3#
4# This software may be distributed under the terms of the BSD license.
5# See README for more details.
6
7import time
8import subprocess
9import logging
10logger = logging.getLogger(__name__)
11
12import hwsim_utils
13
14grpform_events = ["P2P-GROUP-STARTED",
15 "P2P-GO-NEG-FAILURE",
16 "P2P-GROUP-FORMATION-FAILURE",
17 "WPS-PIN-NEEDED",
18 "WPS-M2D",
19 "WPS-FAIL"]
20
21def set_ip_addr_info(dev):
22 dev.request("SET ip_addr_go 192.168.42.1")
23 dev.request("SET ip_addr_mask 255.255.255.0")
24 dev.request("SET ip_addr_start 192.168.42.100")
25 dev.request("SET ip_addr_end 192.168.42.199")
26
27def check_ip_addr(res):
28 if 'ip_addr' not in res:
29 raise Exception("Did not receive IP address from GO")
30 if '192.168.42.' not in res['ip_addr']:
31 raise Exception("Unexpected IP address received from GO")
32 if 'ip_mask' not in res:
33 raise Exception("Did not receive IP address mask from GO")
34 if '255.255.255.' not in res['ip_mask']:
35 raise Exception("Unexpected IP address mask received from GO")
36 if 'go_ip_addr' not in res:
37 raise Exception("Did not receive GO IP address from GO")
38 if '192.168.42.' not in res['go_ip_addr']:
39 raise Exception("Unexpected GO IP address received from GO")
40
41def test_nfc_p2p_go_neg(dev):
42 """NFC connection handover to form a new P2P group (initiator becomes GO)"""
43 set_ip_addr_info(dev[0])
44 dev[0].request("SET p2p_go_intent 10")
45 logger.info("Perform NFC connection handover")
46 req = dev[0].request("NFC_GET_HANDOVER_REQ NDEF P2P-CR").rstrip()
47 if "FAIL" in req:
48 raise Exception("Failed to generate NFC connection handover request")
49 sel = dev[1].request("NFC_GET_HANDOVER_SEL NDEF P2P-CR").rstrip()
50 if "FAIL" in sel:
51 raise Exception("Failed to generate NFC connection handover select")
52 dev[0].dump_monitor()
53 dev[1].dump_monitor()
54 res = dev[1].request("NFC_REPORT_HANDOVER RESP P2P " + req + " " + sel)
55 if "FAIL" in res:
56 raise Exception("Failed to report NFC connection handover to wpa_supplicant(resp)")
57 res = dev[0].request("NFC_REPORT_HANDOVER INIT P2P " + req + " " + sel)
58 if "FAIL" in res:
59 raise Exception("Failed to report NFC connection handover to wpa_supplicant(init)")
60
61 ev = dev[0].wait_event(["P2P-GROUP-STARTED",
62 "P2P-GO-NEG-FAILURE",
63 "P2P-GROUP-FORMATION-FAILURE",
64 "WPS-PIN-NEEDED"], timeout=15)
65 if ev is None:
66 raise Exception("Group formation timed out")
67 res0 = dev[0].group_form_result(ev)
68
69 ev = dev[1].wait_event(["P2P-GROUP-STARTED",
70 "P2P-GO-NEG-FAILURE",
71 "P2P-GROUP-FORMATION-FAILURE",
72 "WPS-PIN-NEEDED"], timeout=1)
73 if ev is None:
74 raise Exception("Group formation timed out")
75 res1 = dev[1].group_form_result(ev)
76 logger.info("Group formed")
77
78 if res1['role'] != 'client' or res0['role'] != 'GO':
79 raise Exception("Unexpected roles negotiated")
80 hwsim_utils.test_connectivity_p2p(dev[0], dev[1])
81 check_ip_addr(res1)
82
83def test_nfc_p2p_go_neg_reverse(dev):
84 """NFC connection handover to form a new P2P group (responder becomes GO)"""
85 set_ip_addr_info(dev[1])
86 dev[0].request("SET p2p_go_intent 3")
87 logger.info("Perform NFC connection handover")
88 req = dev[0].request("NFC_GET_HANDOVER_REQ NDEF P2P-CR").rstrip()
89 if "FAIL" in req:
90 raise Exception("Failed to generate NFC connection handover request")
91 sel = dev[1].request("NFC_GET_HANDOVER_SEL NDEF P2P-CR").rstrip()
92 if "FAIL" in sel:
93 raise Exception("Failed to generate NFC connection handover select")
94 dev[0].dump_monitor()
95 dev[1].dump_monitor()
96 res = dev[1].request("NFC_REPORT_HANDOVER RESP P2P " + req + " " + sel)
97 if "FAIL" in res:
98 raise Exception("Failed to report NFC connection handover to wpa_supplicant(resp)")
99 res = dev[0].request("NFC_REPORT_HANDOVER INIT P2P " + req + " " + sel)
100 if "FAIL" in res:
101 raise Exception("Failed to report NFC connection handover to wpa_supplicant(init)")
102
103 ev = dev[0].wait_event(["P2P-GROUP-STARTED",
104 "P2P-GO-NEG-FAILURE",
105 "P2P-GROUP-FORMATION-FAILURE",
106 "WPS-PIN-NEEDED"], timeout=15)
107 if ev is None:
108 raise Exception("Group formation timed out")
109 res0 = dev[0].group_form_result(ev)
110
111 ev = dev[1].wait_event(["P2P-GROUP-STARTED",
112 "P2P-GO-NEG-FAILURE",
113 "P2P-GROUP-FORMATION-FAILURE",
114 "WPS-PIN-NEEDED"], timeout=1)
115 if ev is None:
116 raise Exception("Group formation timed out")
117 res1 = dev[1].group_form_result(ev)
118 logger.info("Group formed")
119
120 if res0['role'] != 'client' or res1['role'] != 'GO':
121 raise Exception("Unexpected roles negotiated")
122 hwsim_utils.test_connectivity_p2p(dev[0], dev[1])
123 check_ip_addr(res0)
124
125def test_nfc_p2p_initiator_go(dev):
126 """NFC connection handover with initiator already GO"""
127 set_ip_addr_info(dev[0])
128 logger.info("Start autonomous GO")
129 dev[0].p2p_start_go()
130 logger.info("Perform NFC connection handover")
131 req = dev[0].request("NFC_GET_HANDOVER_REQ NDEF P2P-CR").rstrip()
132 if "FAIL" in req:
133 raise Exception("Failed to generate NFC connection handover request")
134 sel = dev[1].request("NFC_GET_HANDOVER_SEL NDEF P2P-CR").rstrip()
135 if "FAIL" in sel:
136 raise Exception("Failed to generate NFC connection handover select")
137 dev[0].dump_monitor()
138 dev[1].dump_monitor()
139 res = dev[1].request("NFC_REPORT_HANDOVER RESP P2P " + req + " " + sel)
140 if "FAIL" in res:
141 raise Exception("Failed to report NFC connection handover to wpa_supplicant(resp)")
142 res = dev[0].request("NFC_REPORT_HANDOVER INIT P2P " + req + " " + sel)
143 if "FAIL" in res:
144 raise Exception("Failed to report NFC connection handover to wpa_supplicant(init)")
145
146 ev = dev[1].wait_event(["P2P-GROUP-STARTED"], timeout=15)
147 if ev is None:
148 raise Exception("Connection to the group timed out")
149 res1 = dev[1].group_form_result(ev)
150 if res1['result'] != 'success':
151 raise Exception("Unexpected connection failure")
152 hwsim_utils.test_connectivity_p2p(dev[0], dev[1])
153 check_ip_addr(res1)
154
155def test_nfc_p2p_responder_go(dev):
156 """NFC connection handover with responder already GO"""
157 set_ip_addr_info(dev[1])
158 logger.info("Start autonomous GO")
159 dev[1].p2p_start_go()
160 logger.info("Perform NFC connection handover")
161 req = dev[0].request("NFC_GET_HANDOVER_REQ NDEF P2P-CR").rstrip()
162 if "FAIL" in req:
163 raise Exception("Failed to generate NFC connection handover request")
164 sel = dev[1].request("NFC_GET_HANDOVER_SEL NDEF P2P-CR").rstrip()
165 if "FAIL" in sel:
166 raise Exception("Failed to generate NFC connection handover select")
167 dev[0].dump_monitor()
168 dev[1].dump_monitor()
169 res = dev[1].request("NFC_REPORT_HANDOVER RESP P2P " + req + " " + sel)
170 if "FAIL" in res:
171 raise Exception("Failed to report NFC connection handover to wpa_supplicant(resp)")
172 res = dev[0].request("NFC_REPORT_HANDOVER INIT P2P " + req + " " + sel)
173 if "FAIL" in res:
174 raise Exception("Failed to report NFC connection handover to wpa_supplicant(init)")
175
176 ev = dev[0].wait_event(["P2P-GROUP-STARTED"], timeout=15)
177 if ev is None:
178 raise Exception("Connection to the group timed out")
179 res0 = dev[0].group_form_result(ev)
180 if res0['result'] != 'success':
181 raise Exception("Unexpected connection failure")
182 hwsim_utils.test_connectivity_p2p(dev[0], dev[1])
183 check_ip_addr(res0)
184
185def test_nfc_p2p_both_go(dev):
186 """NFC connection handover with both devices already GOs"""
187 set_ip_addr_info(dev[0])
188 set_ip_addr_info(dev[1])
189 logger.info("Start autonomous GOs")
190 dev[0].p2p_start_go()
191 dev[1].p2p_start_go()
192 logger.info("Perform NFC connection handover")
193 req = dev[0].request("NFC_GET_HANDOVER_REQ NDEF P2P-CR").rstrip()
194 if "FAIL" in req:
195 raise Exception("Failed to generate NFC connection handover request")
196 sel = dev[1].request("NFC_GET_HANDOVER_SEL NDEF P2P-CR").rstrip()
197 if "FAIL" in sel:
198 raise Exception("Failed to generate NFC connection handover select")
199 dev[0].dump_monitor()
200 dev[1].dump_monitor()
201 res = dev[1].request("NFC_REPORT_HANDOVER RESP P2P " + req + " " + sel)
202 if "FAIL" in res:
203 raise Exception("Failed to report NFC connection handover to wpa_supplicant(resp)")
204 res = dev[0].request("NFC_REPORT_HANDOVER INIT P2P " + req + " " + sel)
205 if "FAIL" in res:
206 raise Exception("Failed to report NFC connection handover to wpa_supplicant(init)")
207
208 ev = dev[0].wait_event(["P2P-NFC-BOTH-GO"], timeout=15)
209 if ev is None:
210 raise Exception("Time out waiting for P2P-NFC-BOTH-GO (dev0)")
211 ev = dev[1].wait_event(["P2P-NFC-BOTH-GO"], timeout=1)
212 if ev is None:
213 raise Exception("Time out waiting for P2P-NFC-BOTH-GO (dev1)")
214 dev[0].remove_group()
215 dev[1].remove_group()
216
217def test_nfc_p2p_client(dev):
218 """NFC connection handover when one device is P2P client"""
219 logger.info("Start autonomous GOs")
220 dev[0].p2p_start_go()
221 logger.info("Connect one device as a P2P client")
222 pin = dev[1].wps_read_pin()
223 dev[0].p2p_go_authorize_client(pin)
224 dev[1].p2p_connect_group(dev[0].p2p_dev_addr(), pin, timeout=60)
225 logger.info("Client connected")
226 hwsim_utils.test_connectivity_p2p(dev[0], dev[1])
227
228 logger.info("NFC connection handover between P2P client and P2P device")
229 req = dev[1].request("NFC_GET_HANDOVER_REQ NDEF P2P-CR").rstrip()
230 if "FAIL" in req:
231 raise Exception("Failed to generate NFC connection handover request")
232 sel = dev[2].request("NFC_GET_HANDOVER_SEL NDEF P2P-CR").rstrip()
233 if "FAIL" in sel:
234 raise Exception("Failed to generate NFC connection handover select")
235 dev[1].dump_monitor()
236 dev[2].dump_monitor()
237 res = dev[2].request("NFC_REPORT_HANDOVER RESP P2P " + req + " " + sel)
238 if "FAIL" in res:
239 raise Exception("Failed to report NFC connection handover to wpa_supplicant(resp)")
240 res = dev[1].request("NFC_REPORT_HANDOVER INIT P2P " + req + " " + sel)
241 if "FAIL" in res:
242 raise Exception("Failed to report NFC connection handover to wpa_supplicant(init)")
243
244 ev = dev[1].wait_event(["P2P-NFC-WHILE-CLIENT"], timeout=15)
245 if ev is None:
246 raise Exception("Time out waiting for P2P-NFC-WHILE-CLIENT")
247 ev = dev[2].wait_event(["P2P-NFC-PEER-CLIENT"], timeout=1)
248 if ev is None:
249 raise Exception("Time out waiting for P2P-NFC-PEER-CLIENT")
250
251 logger.info("Connect to group based on upper layer trigger")
252 pin = dev[2].wps_read_pin()
253 dev[0].p2p_go_authorize_client(pin)
254 dev[2].p2p_connect_group(dev[0].p2p_dev_addr(), pin, timeout=60)
255 logger.info("Client connected")
256 hwsim_utils.test_connectivity_p2p(dev[0], dev[1])
257 hwsim_utils.test_connectivity_p2p(dev[1], dev[2])
258 dev[2].remove_group()
259 dev[1].remove_group()
260 dev[0].remove_group()
261
262def test_nfc_p2p_static_handover_tagdev_client(dev):
263 """NFC static handover to form a new P2P group (NFC Tag device becomes P2P Client)"""
264
265 set_ip_addr_info(dev[0])
266
267 logger.info("Perform NFC connection handover")
268
269 res = dev[1].request("SET p2p_listen_reg_class 81")
270 res2 = dev[1].request("SET p2p_listen_channel 6")
271 if "FAIL" in res or "FAIL" in res2:
272 raise Exception("Could not set Listen channel")
273 pw = dev[1].request("WPS_NFC_TOKEN NDEF").rstrip()
274 if "FAIL" in pw:
275 raise Exception("Failed to generate password token")
276 res = dev[1].request("P2P_SET nfc_tag 1").rstrip()
277 if "FAIL" in res:
278 raise Exception("Failed to enable NFC Tag for P2P static handover")
279 sel = dev[1].request("NFC_GET_HANDOVER_SEL NDEF P2P-CR-TAG").rstrip()
280 if "FAIL" in sel:
281 raise Exception("Failed to generate NFC connection handover select")
282 res = dev[1].request("P2P_LISTEN")
283 if "FAIL" in res:
284 raise Exception("Failed to start Listen mode")
285 dev[1].dump_monitor()
286
e7388bd9
JM
287 dev[0].dump_monitor()
288 dev[0].request("SET p2p_go_intent 10")
289 res = dev[0].request("WPS_NFC_TAG_READ " + sel)
290 if "FAIL" in res:
291 raise Exception("Failed to provide NFC tag contents to wpa_supplicant")
292
293 ev = dev[0].wait_event(grpform_events, timeout=15)
294 if ev is None:
295 raise Exception("Group formation timed out")
296 res0 = dev[0].group_form_result(ev)
297
298 ev = dev[1].wait_event(grpform_events, timeout=1)
299 if ev is None:
300 raise Exception("Group formation timed out")
301 res1 = dev[1].group_form_result(ev)
302 logger.info("Group formed")
303
304 if res1['role'] != 'client' or res0['role'] != 'GO':
305 raise Exception("Unexpected roles negotiated")
306 hwsim_utils.test_connectivity_p2p(dev[0], dev[1])
307 check_ip_addr(res1)
308
309def test_nfc_p2p_static_handover_tagdev_client_group_iface(dev):
310 """NFC static handover to form a new P2P group (NFC Tag device becomes P2P Client with group iface)"""
311
312 set_ip_addr_info(dev[0])
313
314 logger.info("Perform NFC connection handover")
315
316 res = dev[1].request("SET p2p_listen_reg_class 81")
317 res2 = dev[1].request("SET p2p_listen_channel 6")
318 if "FAIL" in res or "FAIL" in res2:
319 raise Exception("Could not set Listen channel")
320 pw = dev[1].request("WPS_NFC_TOKEN NDEF").rstrip()
321 if "FAIL" in pw:
322 raise Exception("Failed to generate password token")
323 dev[1].request("SET p2p_no_group_iface 0")
324 res = dev[1].request("P2P_SET nfc_tag 1").rstrip()
325 if "FAIL" in res:
326 raise Exception("Failed to enable NFC Tag for P2P static handover")
327 sel = dev[1].request("NFC_GET_HANDOVER_SEL NDEF P2P-CR-TAG").rstrip()
328 if "FAIL" in sel:
329 raise Exception("Failed to generate NFC connection handover select")
330 res = dev[1].request("P2P_LISTEN")
331 if "FAIL" in res:
332 raise Exception("Failed to start Listen mode")
333 dev[1].dump_monitor()
334
c9dc5623
JM
335 dev[0].dump_monitor()
336 dev[0].request("SET p2p_go_intent 10")
337 res = dev[0].request("WPS_NFC_TAG_READ " + sel)
338 if "FAIL" in res:
339 raise Exception("Failed to provide NFC tag contents to wpa_supplicant")
340
341 ev = dev[0].wait_event(grpform_events, timeout=15)
342 if ev is None:
343 raise Exception("Group formation timed out")
344 res0 = dev[0].group_form_result(ev)
345
346 ev = dev[1].wait_event(grpform_events, timeout=1)
347 if ev is None:
348 raise Exception("Group formation timed out")
349 res1 = dev[1].group_form_result(ev)
350 logger.info("Group formed")
351
352 if res1['role'] != 'client' or res0['role'] != 'GO':
353 raise Exception("Unexpected roles negotiated")
354 hwsim_utils.test_connectivity_p2p(dev[0], dev[1])
355 check_ip_addr(res1)
356
357def test_nfc_p2p_static_handover_tagdev_go(dev):
358 """NFC static handover to form a new P2P group (NFC Tag device becomes GO)"""
359
360 set_ip_addr_info(dev[1])
361
362 logger.info("Perform NFC connection handover")
363
364 res = dev[1].request("SET p2p_listen_reg_class 81")
365 res2 = dev[1].request("SET p2p_listen_channel 6")
366 if "FAIL" in res or "FAIL" in res2:
367 raise Exception("Could not set Listen channel")
368 pw = dev[1].request("WPS_NFC_TOKEN NDEF").rstrip()
369 if "FAIL" in pw:
370 raise Exception("Failed to generate password token")
371 res = dev[1].request("P2P_SET nfc_tag 1").rstrip()
372 if "FAIL" in res:
373 raise Exception("Failed to enable NFC Tag for P2P static handover")
374 sel = dev[1].request("NFC_GET_HANDOVER_SEL NDEF P2P-CR-TAG").rstrip()
375 if "FAIL" in sel:
376 raise Exception("Failed to generate NFC connection handover select")
377 res = dev[1].request("P2P_LISTEN")
378 if "FAIL" in res:
379 raise Exception("Failed to start Listen mode")
380 dev[1].dump_monitor()
381
382 dev[0].dump_monitor()
383 dev[0].request("SET p2p_go_intent 3")
384 res = dev[0].request("WPS_NFC_TAG_READ " + sel)
385 if "FAIL" in res:
386 raise Exception("Failed to provide NFC tag contents to wpa_supplicant")
387
388 ev = dev[0].wait_event(grpform_events, timeout=15)
389 if ev is None:
390 raise Exception("Group formation timed out")
391 res0 = dev[0].group_form_result(ev)
392
393 ev = dev[1].wait_event(grpform_events, timeout=1)
394 if ev is None:
395 raise Exception("Group formation timed out")
396 res1 = dev[1].group_form_result(ev)
397 logger.info("Group formed")
0867979c
JM
398
399 if res0['role'] != 'client' or res1['role'] != 'GO':
400 raise Exception("Unexpected roles negotiated")
401 hwsim_utils.test_connectivity_p2p(dev[0], dev[1])
402 check_ip_addr(res0)
403
404def test_nfc_p2p_static_handover_tagdev_go_forced_freq(dev):
405 """NFC static handover to form a new P2P group on forced channel (NFC Tag device becomes GO)"""
406
407 set_ip_addr_info(dev[1])
408
409 logger.info("Perform NFC connection handover")
410
411 res = dev[1].request("SET p2p_listen_reg_class 81")
412 res2 = dev[1].request("SET p2p_listen_channel 6")
413 if "FAIL" in res or "FAIL" in res2:
414 raise Exception("Could not set Listen channel")
415 pw = dev[1].request("WPS_NFC_TOKEN NDEF").rstrip()
416 if "FAIL" in pw:
417 raise Exception("Failed to generate password token")
418 res = dev[1].request("P2P_SET nfc_tag 1").rstrip()
419 if "FAIL" in res:
420 raise Exception("Failed to enable NFC Tag for P2P static handover")
421 sel = dev[1].request("NFC_GET_HANDOVER_SEL NDEF P2P-CR-TAG").rstrip()
422 if "FAIL" in sel:
423 raise Exception("Failed to generate NFC connection handover select")
424 res = dev[1].request("P2P_LISTEN")
425 if "FAIL" in res:
426 raise Exception("Failed to start Listen mode")
427 dev[1].dump_monitor()
428
429 dev[0].dump_monitor()
430 dev[0].request("SET p2p_go_intent 3")
431 res = dev[0].request("WPS_NFC_TAG_READ " + sel + " freq=2442")
432 if "FAIL" in res:
433 raise Exception("Failed to provide NFC tag contents to wpa_supplicant")
434
435 ev = dev[0].wait_event(grpform_events, timeout=15)
436 if ev is None:
437 raise Exception("Group formation timed out")
438 res0 = dev[0].group_form_result(ev)
439
440 ev = dev[1].wait_event(grpform_events, timeout=1)
441 if ev is None:
442 raise Exception("Group formation timed out")
443 res1 = dev[1].group_form_result(ev)
444 logger.info("Group formed")
c9dc5623
JM
445
446 if res0['role'] != 'client' or res1['role'] != 'GO':
447 raise Exception("Unexpected roles negotiated")
448 hwsim_utils.test_connectivity_p2p(dev[0], dev[1])
449 check_ip_addr(res0)
450
c8373f10
JM
451def test_nfc_p2p_static_handover_join_tagdev_go(dev):
452 """NFC static handover to join a P2P group (NFC Tag device is the GO)"""
453
454 logger.info("Start autonomous GO")
455 set_ip_addr_info(dev[0])
456 dev[0].p2p_start_go()
457
458 logger.info("Write NFC Tag on the GO")
459 pw = dev[0].request("WPS_NFC_TOKEN NDEF").rstrip()
460 if "FAIL" in pw:
461 raise Exception("Failed to generate password token")
462 res = dev[0].request("P2P_SET nfc_tag 1").rstrip()
463 if "FAIL" in res:
464 raise Exception("Failed to enable NFC Tag for P2P static handover")
465 sel = dev[0].request("NFC_GET_HANDOVER_SEL NDEF P2P-CR-TAG").rstrip()
466 if "FAIL" in sel:
467 raise Exception("Failed to generate NFC connection handover select")
468
469 logger.info("Read NFC Tag on a P2P Device to join a group")
470 res = dev[1].request("WPS_NFC_TAG_READ " + sel)
471 if "FAIL" in res:
472 raise Exception("Failed to provide NFC tag contents to wpa_supplicant")
473
474 ev = dev[1].wait_event(grpform_events, timeout=30)
475 if ev is None:
476 raise Exception("Joining the group timed out")
477 res = dev[1].group_form_result(ev)
478 hwsim_utils.test_connectivity_p2p(dev[0], dev[1])
479 check_ip_addr(res)
480
481 logger.info("Read NFC Tag on another P2P Device to join a group")
482 res = dev[2].request("WPS_NFC_TAG_READ " + sel)
483 if "FAIL" in res:
484 raise Exception("Failed to provide NFC tag contents to wpa_supplicant")
485
486 ev = dev[2].wait_event(grpform_events, timeout=30)
487 if ev is None:
488 raise Exception("Joining the group timed out")
489 res = dev[2].group_form_result(ev)
490 hwsim_utils.test_connectivity_p2p(dev[0], dev[2])
491 check_ip_addr(res)
492
493def test_nfc_p2p_static_handover_join_tagdev_client(dev):
494 """NFC static handover to join a P2P group (NFC Tag device is the P2P Client)"""
495 set_ip_addr_info(dev[0])
496 logger.info("Start autonomous GO")
497 dev[0].p2p_start_go()
498
499 dev[1].request("SET ignore_old_scan_res 1")
500 dev[2].request("SET ignore_old_scan_res 1")
501
502 logger.info("Write NFC Tag on the P2P Client")
503 res = dev[1].request("P2P_LISTEN")
504 if "FAIL" in res:
505 raise Exception("Failed to start Listen mode")
506 pw = dev[1].request("WPS_NFC_TOKEN NDEF").rstrip()
507 if "FAIL" in pw:
508 raise Exception("Failed to generate password token")
509 res = dev[1].request("P2P_SET nfc_tag 1").rstrip()
510 if "FAIL" in res:
511 raise Exception("Failed to enable NFC Tag for P2P static handover")
512 sel = dev[1].request("NFC_GET_HANDOVER_SEL NDEF P2P-CR-TAG").rstrip()
513 if "FAIL" in sel:
514 raise Exception("Failed to generate NFC connection handover select")
515
516 logger.info("Read NFC Tag on the GO to trigger invitation")
517 res = dev[0].request("WPS_NFC_TAG_READ " + sel)
518 if "FAIL" in res:
519 raise Exception("Failed to provide NFC tag contents to wpa_supplicant")
520
521 ev = dev[1].wait_event(grpform_events, timeout=30)
522 if ev is None:
523 raise Exception("Joining the group timed out")
524 res = dev[1].group_form_result(ev)
525 hwsim_utils.test_connectivity_p2p(dev[0], dev[1])
526 check_ip_addr(res)
527
528 logger.info("Write NFC Tag on another P2P Client")
529 res = dev[2].request("P2P_LISTEN")
530 if "FAIL" in res:
531 raise Exception("Failed to start Listen mode")
532 pw = dev[2].request("WPS_NFC_TOKEN NDEF").rstrip()
533 if "FAIL" in pw:
534 raise Exception("Failed to generate password token")
535 res = dev[2].request("P2P_SET nfc_tag 1").rstrip()
536 if "FAIL" in res:
537 raise Exception("Failed to enable NFC Tag for P2P static handover")
538 sel = dev[2].request("NFC_GET_HANDOVER_SEL NDEF P2P-CR-TAG").rstrip()
539 if "FAIL" in sel:
540 raise Exception("Failed to generate NFC connection handover select")
541
542 logger.info("Read NFC Tag on the GO to trigger invitation")
543 res = dev[0].request("WPS_NFC_TAG_READ " + sel)
544 if "FAIL" in res:
545 raise Exception("Failed to provide NFC tag contents to wpa_supplicant")
546
547 ev = dev[2].wait_event(grpform_events, timeout=30)
548 if ev is None:
549 raise Exception("Joining the group timed out")
550 res = dev[2].group_form_result(ev)
551 hwsim_utils.test_connectivity_p2p(dev[0], dev[2])
552 check_ip_addr(res)
553
c9dc5623 554def test_nfc_p2p_go_legacy_config_token(dev):
14637401 555 """NFC config token from P2P GO to legacy WPS STA"""
c9dc5623
JM
556 logger.info("Start autonomous GOs")
557 dev[0].p2p_start_go()
558 logger.info("Connect legacy WPS STA with configuration token")
559 conf = dev[0].request("WPS_NFC_CONFIG_TOKEN NDEF").rstrip()
560 if "FAIL" in conf:
561 raise Exception("Failed to generate configuration token")
562 dev[1].dump_monitor()
563 res = dev[1].request("WPS_NFC_TAG_READ " + conf)
564 if "FAIL" in res:
565 raise Exception("Failed to provide NFC tag contents to wpa_supplicant")
5f35a5e2 566 dev[1].wait_connected(timeout=15, error="Joining the group timed out")
c9dc5623
JM
567 hwsim_utils.test_connectivity_p2p(dev[0], dev[1])
568 dev[1].request("DISCONNECT")
569 dev[0].remove_group()
570
571def test_nfc_p2p_go_legacy_handover(dev):
14637401 572 """NFC token from legacy WPS STA to P2P GO"""
c9dc5623
JM
573 logger.info("Start autonomous GOs")
574 dev[0].p2p_start_go()
575 logger.info("Connect legacy WPS STA with connection handover")
576 req = dev[1].request("NFC_GET_HANDOVER_REQ NDEF WPS-CR").rstrip()
577 if "FAIL" in req:
578 raise Exception("Failed to generate NFC connection handover request")
579 sel = dev[0].request("NFC_GET_HANDOVER_SEL NDEF WPS-CR").rstrip()
580 if "FAIL" in sel:
581 raise Exception("Failed to generate NFC connection handover select")
582 res = dev[0].request("NFC_REPORT_HANDOVER RESP WPS " + req + " " + sel)
583 if "FAIL" in res:
584 raise Exception("Failed to report NFC connection handover to wpa_supplicant (GO)")
585 dev[1].dump_monitor()
586 res = dev[1].request("NFC_REPORT_HANDOVER INIT WPS " + req + " " + sel)
587 if "FAIL" in res:
588 raise Exception("Failed to report NFC connection handover to wpa_supplicant (legacy STA)")
5f35a5e2 589 dev[1].wait_connected(timeout=15, error="Joining the group timed out")
c9dc5623
JM
590 hwsim_utils.test_connectivity_p2p(dev[0], dev[1])
591 dev[1].request("DISCONNECT")
592 dev[0].remove_group()
593
594def test_nfc_p2p_ip_addr_assignment(dev):
595 """NFC connection handover and legacy station IP address assignment"""
596 set_ip_addr_info(dev[1])
597 dev[0].request("SET p2p_go_intent 3")
598 logger.info("Perform NFC connection handover")
599 req = dev[0].request("NFC_GET_HANDOVER_REQ NDEF P2P-CR").rstrip()
600 if "FAIL" in req:
601 raise Exception("Failed to generate NFC connection handover request")
602 sel = dev[1].request("NFC_GET_HANDOVER_SEL NDEF P2P-CR").rstrip()
603 if "FAIL" in sel:
604 raise Exception("Failed to generate NFC connection handover select")
605 dev[0].dump_monitor()
606 dev[1].dump_monitor()
607 res = dev[1].request("NFC_REPORT_HANDOVER RESP P2P " + req + " " + sel)
608 if "FAIL" in res:
609 raise Exception("Failed to report NFC connection handover to wpa_supplicant(resp)")
610 res = dev[0].request("NFC_REPORT_HANDOVER INIT P2P " + req + " " + sel)
611 if "FAIL" in res:
612 raise Exception("Failed to report NFC connection handover to wpa_supplicant(init)")
613
614 ev = dev[0].wait_event(["P2P-GROUP-STARTED",
615 "P2P-GO-NEG-FAILURE",
616 "P2P-GROUP-FORMATION-FAILURE",
617 "WPS-PIN-NEEDED"], timeout=15)
618 if ev is None:
619 raise Exception("Group formation timed out")
620 res0 = dev[0].group_form_result(ev)
621
622 ev = dev[1].wait_event(["P2P-GROUP-STARTED",
623 "P2P-GO-NEG-FAILURE",
624 "P2P-GROUP-FORMATION-FAILURE",
625 "WPS-PIN-NEEDED"], timeout=1)
626 if ev is None:
627 raise Exception("Group formation timed out")
628 res1 = dev[1].group_form_result(ev)
629 logger.info("Group formed")
630
631 if res0['role'] != 'client' or res1['role'] != 'GO':
632 raise Exception("Unexpected roles negotiated")
633 hwsim_utils.test_connectivity_p2p(dev[0], dev[1])
634 check_ip_addr(res0)
635
636 logger.info("Connect legacy P2P client that does not use new IP address assignment")
637 res = dev[2].request("P2P_SET disable_ip_addr_req 1")
638 if "FAIL" in res:
639 raise Exception("Failed to disable IP address assignment request")
640 pin = dev[2].wps_read_pin()
641 dev[1].p2p_go_authorize_client(pin)
642 res = dev[2].p2p_connect_group(dev[1].p2p_dev_addr(), pin, timeout=60)
643 logger.info("Client connected")
644 hwsim_utils.test_connectivity_p2p(dev[1], dev[2])
645 if 'ip_addr' in res:
646 raise Exception("Unexpected IP address assignment")
647
648def test_nfc_p2p_ip_addr_assignment2(dev):
649 """NFC connection handover and IP address assignment for two clients"""
650 set_ip_addr_info(dev[1])
651 dev[0].request("SET p2p_go_intent 3")
652 logger.info("Perform NFC connection handover")
653 req = dev[0].request("NFC_GET_HANDOVER_REQ NDEF P2P-CR").rstrip()
654 if "FAIL" in req:
655 raise Exception("Failed to generate NFC connection handover request")
656 sel = dev[1].request("NFC_GET_HANDOVER_SEL NDEF P2P-CR").rstrip()
657 if "FAIL" in sel:
658 raise Exception("Failed to generate NFC connection handover select")
659 dev[0].dump_monitor()
660 dev[1].dump_monitor()
661 res = dev[1].request("NFC_REPORT_HANDOVER RESP P2P " + req + " " + sel)
662 if "FAIL" in res:
663 raise Exception("Failed to report NFC connection handover to wpa_supplicant(resp)")
664 res = dev[0].request("NFC_REPORT_HANDOVER INIT P2P " + req + " " + sel)
665 if "FAIL" in res:
666 raise Exception("Failed to report NFC connection handover to wpa_supplicant(init)")
667
668 ev = dev[0].wait_event(["P2P-GROUP-STARTED",
669 "P2P-GO-NEG-FAILURE",
670 "P2P-GROUP-FORMATION-FAILURE",
671 "WPS-PIN-NEEDED"], timeout=15)
672 if ev is None:
673 raise Exception("Group formation timed out")
674 res0 = dev[0].group_form_result(ev)
675
676 ev = dev[1].wait_event(["P2P-GROUP-STARTED",
677 "P2P-GO-NEG-FAILURE",
678 "P2P-GROUP-FORMATION-FAILURE",
679 "WPS-PIN-NEEDED"], timeout=1)
680 if ev is None:
681 raise Exception("Group formation timed out")
682 res1 = dev[1].group_form_result(ev)
683 logger.info("Group formed")
684
685 if res0['role'] != 'client' or res1['role'] != 'GO':
686 raise Exception("Unexpected roles negotiated")
687 hwsim_utils.test_connectivity_p2p(dev[0], dev[1])
688 check_ip_addr(res0)
689 print "Client 1 IP address: " + res0['ip_addr']
690
691 logger.info("Connect a P2P client")
692 pin = dev[2].wps_read_pin()
693 dev[1].p2p_go_authorize_client(pin)
694 res = dev[2].p2p_connect_group(dev[1].p2p_dev_addr(), pin, timeout=60)
695 logger.info("Client connected")
696 hwsim_utils.test_connectivity_p2p(dev[1], dev[2])
697 check_ip_addr(res)
698 print "Client 2 IP address: " + res['ip_addr']
699 if res['ip_addr'] == res0['ip_addr']:
700 raise Exception("Same IP address assigned to both clients")
b45364b6
JM
701
702def test_nfc_p2p_tag_enable_disable(dev):
703 """NFC tag enable/disable for P2P"""
704 if "FAIL" in dev[0].request("WPS_NFC_TOKEN NDEF").rstrip():
705 raise Exception("Failed to generate password token")
706 if "OK" not in dev[0].request("P2P_SET nfc_tag 1"):
707 raise Exception("Failed to enable NFC Tag for P2P static handover")
708 if "OK" not in dev[0].request("P2P_SET nfc_tag 0"):
709 raise Exception("Failed to disable NFC Tag for P2P static handover")
710
711 dev[0].request("SET p2p_no_group_iface 0")
712 if "OK" not in dev[0].request("P2P_SET nfc_tag 1"):
713 raise Exception("Failed to enable NFC Tag for P2P static handover")
714 if "OK" not in dev[0].request("P2P_SET nfc_tag 0"):
715 raise Exception("Failed to disable NFC Tag for P2P static handover")
716 if "OK" not in dev[0].request("P2P_SET nfc_tag 1"):
717 raise Exception("Failed to enable NFC Tag for P2P static handover")
718 if "OK" not in dev[0].request("P2P_SET nfc_tag 0"):
719 raise Exception("Failed to disable NFC Tag for P2P static handover")