test_nfc_p2p.py 25 KB

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