test_nfc_p2p.py 30 KB

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