]> git.ipfire.org Git - thirdparty/hostap.git/blob - tests/hwsim/test_nfc_p2p.py
tests: Make HS 2.0 test cases more robust
[thirdparty/hostap.git] / tests / hwsim / test_nfc_p2p.py
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
7 import time
8 import subprocess
9 import logging
10 logger = logging.getLogger(__name__)
11
12 import hwsim_utils
13
14 grpform_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
21 def 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
27 def 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
41 def 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
83 def 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
125 def 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
155 def 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
185 def 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
217 def 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
262 def 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
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
309 def 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
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
357 def 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")
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
404 def 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")
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
451 def 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
493 def 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
554 def test_nfc_p2p_go_legacy_config_token(dev):
555 logger.info("Start autonomous GOs")
556 dev[0].p2p_start_go()
557 logger.info("Connect legacy WPS STA with configuration token")
558 conf = dev[0].request("WPS_NFC_CONFIG_TOKEN NDEF").rstrip()
559 if "FAIL" in conf:
560 raise Exception("Failed to generate configuration token")
561 dev[1].dump_monitor()
562 res = dev[1].request("WPS_NFC_TAG_READ " + conf)
563 if "FAIL" in res:
564 raise Exception("Failed to provide NFC tag contents to wpa_supplicant")
565 ev = dev[1].wait_event(["CTRL-EVENT-CONNECTED"], timeout=15)
566 if ev is None:
567 raise Exception("Joining the group timed out")
568 hwsim_utils.test_connectivity_p2p(dev[0], dev[1])
569 dev[1].request("DISCONNECT")
570 dev[0].remove_group()
571
572 def test_nfc_p2p_go_legacy_handover(dev):
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)")
589 ev = dev[1].wait_event(["CTRL-EVENT-CONNECTED"], timeout=15)
590 if ev is None:
591 raise Exception("Joining the group timed out")
592 hwsim_utils.test_connectivity_p2p(dev[0], dev[1])
593 dev[1].request("DISCONNECT")
594 dev[0].remove_group()
595
596 def test_nfc_p2p_ip_addr_assignment(dev):
597 """NFC connection handover and legacy station IP address assignment"""
598 set_ip_addr_info(dev[1])
599 dev[0].request("SET p2p_go_intent 3")
600 logger.info("Perform NFC connection handover")
601 req = dev[0].request("NFC_GET_HANDOVER_REQ NDEF P2P-CR").rstrip()
602 if "FAIL" in req:
603 raise Exception("Failed to generate NFC connection handover request")
604 sel = dev[1].request("NFC_GET_HANDOVER_SEL NDEF P2P-CR").rstrip()
605 if "FAIL" in sel:
606 raise Exception("Failed to generate NFC connection handover select")
607 dev[0].dump_monitor()
608 dev[1].dump_monitor()
609 res = dev[1].request("NFC_REPORT_HANDOVER RESP P2P " + req + " " + sel)
610 if "FAIL" in res:
611 raise Exception("Failed to report NFC connection handover to wpa_supplicant(resp)")
612 res = dev[0].request("NFC_REPORT_HANDOVER INIT P2P " + req + " " + sel)
613 if "FAIL" in res:
614 raise Exception("Failed to report NFC connection handover to wpa_supplicant(init)")
615
616 ev = dev[0].wait_event(["P2P-GROUP-STARTED",
617 "P2P-GO-NEG-FAILURE",
618 "P2P-GROUP-FORMATION-FAILURE",
619 "WPS-PIN-NEEDED"], timeout=15)
620 if ev is None:
621 raise Exception("Group formation timed out")
622 res0 = dev[0].group_form_result(ev)
623
624 ev = dev[1].wait_event(["P2P-GROUP-STARTED",
625 "P2P-GO-NEG-FAILURE",
626 "P2P-GROUP-FORMATION-FAILURE",
627 "WPS-PIN-NEEDED"], timeout=1)
628 if ev is None:
629 raise Exception("Group formation timed out")
630 res1 = dev[1].group_form_result(ev)
631 logger.info("Group formed")
632
633 if res0['role'] != 'client' or res1['role'] != 'GO':
634 raise Exception("Unexpected roles negotiated")
635 hwsim_utils.test_connectivity_p2p(dev[0], dev[1])
636 check_ip_addr(res0)
637
638 logger.info("Connect legacy P2P client that does not use new IP address assignment")
639 res = dev[2].request("P2P_SET disable_ip_addr_req 1")
640 if "FAIL" in res:
641 raise Exception("Failed to disable IP address assignment request")
642 pin = dev[2].wps_read_pin()
643 dev[1].p2p_go_authorize_client(pin)
644 res = dev[2].p2p_connect_group(dev[1].p2p_dev_addr(), pin, timeout=60)
645 logger.info("Client connected")
646 hwsim_utils.test_connectivity_p2p(dev[1], dev[2])
647 if 'ip_addr' in res:
648 raise Exception("Unexpected IP address assignment")
649
650 def test_nfc_p2p_ip_addr_assignment2(dev):
651 """NFC connection handover and IP address assignment for two clients"""
652 set_ip_addr_info(dev[1])
653 dev[0].request("SET p2p_go_intent 3")
654 logger.info("Perform NFC connection handover")
655 req = dev[0].request("NFC_GET_HANDOVER_REQ NDEF P2P-CR").rstrip()
656 if "FAIL" in req:
657 raise Exception("Failed to generate NFC connection handover request")
658 sel = dev[1].request("NFC_GET_HANDOVER_SEL NDEF P2P-CR").rstrip()
659 if "FAIL" in sel:
660 raise Exception("Failed to generate NFC connection handover select")
661 dev[0].dump_monitor()
662 dev[1].dump_monitor()
663 res = dev[1].request("NFC_REPORT_HANDOVER RESP P2P " + req + " " + sel)
664 if "FAIL" in res:
665 raise Exception("Failed to report NFC connection handover to wpa_supplicant(resp)")
666 res = dev[0].request("NFC_REPORT_HANDOVER INIT P2P " + req + " " + sel)
667 if "FAIL" in res:
668 raise Exception("Failed to report NFC connection handover to wpa_supplicant(init)")
669
670 ev = dev[0].wait_event(["P2P-GROUP-STARTED",
671 "P2P-GO-NEG-FAILURE",
672 "P2P-GROUP-FORMATION-FAILURE",
673 "WPS-PIN-NEEDED"], timeout=15)
674 if ev is None:
675 raise Exception("Group formation timed out")
676 res0 = dev[0].group_form_result(ev)
677
678 ev = dev[1].wait_event(["P2P-GROUP-STARTED",
679 "P2P-GO-NEG-FAILURE",
680 "P2P-GROUP-FORMATION-FAILURE",
681 "WPS-PIN-NEEDED"], timeout=1)
682 if ev is None:
683 raise Exception("Group formation timed out")
684 res1 = dev[1].group_form_result(ev)
685 logger.info("Group formed")
686
687 if res0['role'] != 'client' or res1['role'] != 'GO':
688 raise Exception("Unexpected roles negotiated")
689 hwsim_utils.test_connectivity_p2p(dev[0], dev[1])
690 check_ip_addr(res0)
691 print "Client 1 IP address: " + res0['ip_addr']
692
693 logger.info("Connect a P2P client")
694 pin = dev[2].wps_read_pin()
695 dev[1].p2p_go_authorize_client(pin)
696 res = dev[2].p2p_connect_group(dev[1].p2p_dev_addr(), pin, timeout=60)
697 logger.info("Client connected")
698 hwsim_utils.test_connectivity_p2p(dev[1], dev[2])
699 check_ip_addr(res)
700 print "Client 2 IP address: " + res['ip_addr']
701 if res['ip_addr'] == res0['ip_addr']:
702 raise Exception("Same IP address assigned to both clients")
703
704 def test_nfc_p2p_tag_enable_disable(dev):
705 """NFC tag enable/disable for P2P"""
706 if "FAIL" in dev[0].request("WPS_NFC_TOKEN NDEF").rstrip():
707 raise Exception("Failed to generate password token")
708 if "OK" not in dev[0].request("P2P_SET nfc_tag 1"):
709 raise Exception("Failed to enable NFC Tag for P2P static handover")
710 if "OK" not in dev[0].request("P2P_SET nfc_tag 0"):
711 raise Exception("Failed to disable NFC Tag for P2P static handover")
712
713 dev[0].request("SET p2p_no_group_iface 0")
714 if "OK" not in dev[0].request("P2P_SET nfc_tag 1"):
715 raise Exception("Failed to enable NFC Tag for P2P static handover")
716 if "OK" not in dev[0].request("P2P_SET nfc_tag 0"):
717 raise Exception("Failed to disable NFC Tag for P2P static handover")
718 if "OK" not in dev[0].request("P2P_SET nfc_tag 1"):
719 raise Exception("Failed to enable NFC Tag for P2P static handover")
720 if "OK" not in dev[0].request("P2P_SET nfc_tag 0"):
721 raise Exception("Failed to disable NFC Tag for P2P static handover")