test_nfc_p2p.py 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607
  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_go(dev):
  278. """NFC static handover to form a new P2P group (NFC Tag device becomes GO)"""
  279. set_ip_addr_info(dev[1])
  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. res = dev[1].request("P2P_SET nfc_tag 1").rstrip()
  289. if "FAIL" in res:
  290. raise Exception("Failed to enable NFC Tag for P2P static handover")
  291. sel = dev[1].request("NFC_GET_HANDOVER_SEL NDEF P2P-CR-TAG").rstrip()
  292. if "FAIL" in sel:
  293. raise Exception("Failed to generate NFC connection handover select")
  294. res = dev[1].request("P2P_LISTEN")
  295. if "FAIL" in res:
  296. raise Exception("Failed to start Listen mode")
  297. dev[1].dump_monitor()
  298. dev[0].dump_monitor()
  299. dev[0].request("SET p2p_go_intent 3")
  300. res = dev[0].request("WPS_NFC_TAG_READ " + sel)
  301. if "FAIL" in res:
  302. raise Exception("Failed to provide NFC tag contents to wpa_supplicant")
  303. ev = dev[0].wait_event(grpform_events, timeout=15)
  304. if ev is None:
  305. raise Exception("Group formation timed out")
  306. res0 = dev[0].group_form_result(ev)
  307. ev = dev[1].wait_event(grpform_events, timeout=1)
  308. if ev is None:
  309. raise Exception("Group formation timed out")
  310. res1 = dev[1].group_form_result(ev)
  311. logger.info("Group formed")
  312. if res0['role'] != 'client' or res1['role'] != 'GO':
  313. raise Exception("Unexpected roles negotiated")
  314. hwsim_utils.test_connectivity_p2p(dev[0], dev[1])
  315. check_ip_addr(res0)
  316. def test_nfc_p2p_static_handover_join_tagdev_go(dev):
  317. """NFC static handover to join a P2P group (NFC Tag device is the GO)"""
  318. logger.info("Start autonomous GO")
  319. set_ip_addr_info(dev[0])
  320. dev[0].p2p_start_go()
  321. logger.info("Write NFC Tag on the GO")
  322. pw = dev[0].request("WPS_NFC_TOKEN NDEF").rstrip()
  323. if "FAIL" in pw:
  324. raise Exception("Failed to generate password token")
  325. res = dev[0].request("P2P_SET nfc_tag 1").rstrip()
  326. if "FAIL" in res:
  327. raise Exception("Failed to enable NFC Tag for P2P static handover")
  328. sel = dev[0].request("NFC_GET_HANDOVER_SEL NDEF P2P-CR-TAG").rstrip()
  329. if "FAIL" in sel:
  330. raise Exception("Failed to generate NFC connection handover select")
  331. logger.info("Read NFC Tag on a P2P Device to join a group")
  332. res = dev[1].request("WPS_NFC_TAG_READ " + sel)
  333. if "FAIL" in res:
  334. raise Exception("Failed to provide NFC tag contents to wpa_supplicant")
  335. ev = dev[1].wait_event(grpform_events, timeout=30)
  336. if ev is None:
  337. raise Exception("Joining the group timed out")
  338. res = dev[1].group_form_result(ev)
  339. hwsim_utils.test_connectivity_p2p(dev[0], dev[1])
  340. check_ip_addr(res)
  341. logger.info("Read NFC Tag on another P2P Device to join a group")
  342. res = dev[2].request("WPS_NFC_TAG_READ " + sel)
  343. if "FAIL" in res:
  344. raise Exception("Failed to provide NFC tag contents to wpa_supplicant")
  345. ev = dev[2].wait_event(grpform_events, timeout=30)
  346. if ev is None:
  347. raise Exception("Joining the group timed out")
  348. res = dev[2].group_form_result(ev)
  349. hwsim_utils.test_connectivity_p2p(dev[0], dev[2])
  350. check_ip_addr(res)
  351. def test_nfc_p2p_static_handover_join_tagdev_client(dev):
  352. """NFC static handover to join a P2P group (NFC Tag device is the P2P Client)"""
  353. set_ip_addr_info(dev[0])
  354. logger.info("Start autonomous GO")
  355. dev[0].p2p_start_go()
  356. dev[1].request("SET ignore_old_scan_res 1")
  357. dev[2].request("SET ignore_old_scan_res 1")
  358. logger.info("Write NFC Tag on the P2P Client")
  359. res = dev[1].request("P2P_LISTEN")
  360. if "FAIL" in res:
  361. raise Exception("Failed to start Listen mode")
  362. pw = dev[1].request("WPS_NFC_TOKEN NDEF").rstrip()
  363. if "FAIL" in pw:
  364. raise Exception("Failed to generate password token")
  365. res = dev[1].request("P2P_SET nfc_tag 1").rstrip()
  366. if "FAIL" in res:
  367. raise Exception("Failed to enable NFC Tag for P2P static handover")
  368. sel = dev[1].request("NFC_GET_HANDOVER_SEL NDEF P2P-CR-TAG").rstrip()
  369. if "FAIL" in sel:
  370. raise Exception("Failed to generate NFC connection handover select")
  371. logger.info("Read NFC Tag on the GO to trigger invitation")
  372. res = dev[0].request("WPS_NFC_TAG_READ " + sel)
  373. if "FAIL" in res:
  374. raise Exception("Failed to provide NFC tag contents to wpa_supplicant")
  375. ev = dev[1].wait_event(grpform_events, timeout=30)
  376. if ev is None:
  377. raise Exception("Joining the group timed out")
  378. res = dev[1].group_form_result(ev)
  379. hwsim_utils.test_connectivity_p2p(dev[0], dev[1])
  380. check_ip_addr(res)
  381. logger.info("Write NFC Tag on another P2P Client")
  382. res = dev[2].request("P2P_LISTEN")
  383. if "FAIL" in res:
  384. raise Exception("Failed to start Listen mode")
  385. pw = dev[2].request("WPS_NFC_TOKEN NDEF").rstrip()
  386. if "FAIL" in pw:
  387. raise Exception("Failed to generate password token")
  388. res = dev[2].request("P2P_SET nfc_tag 1").rstrip()
  389. if "FAIL" in res:
  390. raise Exception("Failed to enable NFC Tag for P2P static handover")
  391. sel = dev[2].request("NFC_GET_HANDOVER_SEL NDEF P2P-CR-TAG").rstrip()
  392. if "FAIL" in sel:
  393. raise Exception("Failed to generate NFC connection handover select")
  394. logger.info("Read NFC Tag on the GO to trigger invitation")
  395. res = dev[0].request("WPS_NFC_TAG_READ " + sel)
  396. if "FAIL" in res:
  397. raise Exception("Failed to provide NFC tag contents to wpa_supplicant")
  398. ev = dev[2].wait_event(grpform_events, timeout=30)
  399. if ev is None:
  400. raise Exception("Joining the group timed out")
  401. res = dev[2].group_form_result(ev)
  402. hwsim_utils.test_connectivity_p2p(dev[0], dev[2])
  403. check_ip_addr(res)
  404. def test_nfc_p2p_go_legacy_config_token(dev):
  405. logger.info("Start autonomous GOs")
  406. dev[0].p2p_start_go()
  407. logger.info("Connect legacy WPS STA with configuration token")
  408. conf = dev[0].request("WPS_NFC_CONFIG_TOKEN NDEF").rstrip()
  409. if "FAIL" in conf:
  410. raise Exception("Failed to generate configuration token")
  411. dev[1].dump_monitor()
  412. res = dev[1].request("WPS_NFC_TAG_READ " + conf)
  413. if "FAIL" in res:
  414. raise Exception("Failed to provide NFC tag contents to wpa_supplicant")
  415. ev = dev[1].wait_event(["CTRL-EVENT-CONNECTED"], timeout=15)
  416. if ev is None:
  417. raise Exception("Joining the group timed out")
  418. hwsim_utils.test_connectivity_p2p(dev[0], dev[1])
  419. dev[1].request("DISCONNECT")
  420. dev[0].remove_group()
  421. def test_nfc_p2p_go_legacy_handover(dev):
  422. logger.info("Start autonomous GOs")
  423. dev[0].p2p_start_go()
  424. logger.info("Connect legacy WPS STA with connection handover")
  425. req = dev[1].request("NFC_GET_HANDOVER_REQ NDEF WPS-CR").rstrip()
  426. if "FAIL" in req:
  427. raise Exception("Failed to generate NFC connection handover request")
  428. sel = dev[0].request("NFC_GET_HANDOVER_SEL NDEF WPS-CR").rstrip()
  429. if "FAIL" in sel:
  430. raise Exception("Failed to generate NFC connection handover select")
  431. res = dev[0].request("NFC_REPORT_HANDOVER RESP WPS " + req + " " + sel)
  432. if "FAIL" in res:
  433. raise Exception("Failed to report NFC connection handover to wpa_supplicant (GO)")
  434. dev[1].dump_monitor()
  435. res = dev[1].request("NFC_REPORT_HANDOVER INIT WPS " + req + " " + sel)
  436. if "FAIL" in res:
  437. raise Exception("Failed to report NFC connection handover to wpa_supplicant (legacy STA)")
  438. ev = dev[1].wait_event(["CTRL-EVENT-CONNECTED"], timeout=15)
  439. if ev is None:
  440. raise Exception("Joining the group timed out")
  441. hwsim_utils.test_connectivity_p2p(dev[0], dev[1])
  442. dev[1].request("DISCONNECT")
  443. dev[0].remove_group()
  444. def test_nfc_p2p_ip_addr_assignment(dev):
  445. """NFC connection handover and legacy station IP address assignment"""
  446. set_ip_addr_info(dev[1])
  447. dev[0].request("SET p2p_go_intent 3")
  448. logger.info("Perform NFC connection handover")
  449. req = dev[0].request("NFC_GET_HANDOVER_REQ NDEF P2P-CR").rstrip()
  450. if "FAIL" in req:
  451. raise Exception("Failed to generate NFC connection handover request")
  452. sel = dev[1].request("NFC_GET_HANDOVER_SEL NDEF P2P-CR").rstrip()
  453. if "FAIL" in sel:
  454. raise Exception("Failed to generate NFC connection handover select")
  455. dev[0].dump_monitor()
  456. dev[1].dump_monitor()
  457. res = dev[1].request("NFC_REPORT_HANDOVER RESP P2P " + req + " " + sel)
  458. if "FAIL" in res:
  459. raise Exception("Failed to report NFC connection handover to wpa_supplicant(resp)")
  460. res = dev[0].request("NFC_REPORT_HANDOVER INIT P2P " + req + " " + sel)
  461. if "FAIL" in res:
  462. raise Exception("Failed to report NFC connection handover to wpa_supplicant(init)")
  463. ev = dev[0].wait_event(["P2P-GROUP-STARTED",
  464. "P2P-GO-NEG-FAILURE",
  465. "P2P-GROUP-FORMATION-FAILURE",
  466. "WPS-PIN-NEEDED"], timeout=15)
  467. if ev is None:
  468. raise Exception("Group formation timed out")
  469. res0 = dev[0].group_form_result(ev)
  470. ev = dev[1].wait_event(["P2P-GROUP-STARTED",
  471. "P2P-GO-NEG-FAILURE",
  472. "P2P-GROUP-FORMATION-FAILURE",
  473. "WPS-PIN-NEEDED"], timeout=1)
  474. if ev is None:
  475. raise Exception("Group formation timed out")
  476. res1 = dev[1].group_form_result(ev)
  477. logger.info("Group formed")
  478. if res0['role'] != 'client' or res1['role'] != 'GO':
  479. raise Exception("Unexpected roles negotiated")
  480. hwsim_utils.test_connectivity_p2p(dev[0], dev[1])
  481. check_ip_addr(res0)
  482. logger.info("Connect legacy P2P client that does not use new IP address assignment")
  483. res = dev[2].request("P2P_SET disable_ip_addr_req 1")
  484. if "FAIL" in res:
  485. raise Exception("Failed to disable IP address assignment request")
  486. pin = dev[2].wps_read_pin()
  487. dev[1].p2p_go_authorize_client(pin)
  488. res = dev[2].p2p_connect_group(dev[1].p2p_dev_addr(), pin, timeout=60)
  489. logger.info("Client connected")
  490. hwsim_utils.test_connectivity_p2p(dev[1], dev[2])
  491. if 'ip_addr' in res:
  492. raise Exception("Unexpected IP address assignment")
  493. def test_nfc_p2p_ip_addr_assignment2(dev):
  494. """NFC connection handover and IP address assignment for two clients"""
  495. set_ip_addr_info(dev[1])
  496. dev[0].request("SET p2p_go_intent 3")
  497. logger.info("Perform NFC connection handover")
  498. req = dev[0].request("NFC_GET_HANDOVER_REQ NDEF P2P-CR").rstrip()
  499. if "FAIL" in req:
  500. raise Exception("Failed to generate NFC connection handover request")
  501. sel = dev[1].request("NFC_GET_HANDOVER_SEL NDEF P2P-CR").rstrip()
  502. if "FAIL" in sel:
  503. raise Exception("Failed to generate NFC connection handover select")
  504. dev[0].dump_monitor()
  505. dev[1].dump_monitor()
  506. res = dev[1].request("NFC_REPORT_HANDOVER RESP P2P " + req + " " + sel)
  507. if "FAIL" in res:
  508. raise Exception("Failed to report NFC connection handover to wpa_supplicant(resp)")
  509. res = dev[0].request("NFC_REPORT_HANDOVER INIT P2P " + req + " " + sel)
  510. if "FAIL" in res:
  511. raise Exception("Failed to report NFC connection handover to wpa_supplicant(init)")
  512. ev = dev[0].wait_event(["P2P-GROUP-STARTED",
  513. "P2P-GO-NEG-FAILURE",
  514. "P2P-GROUP-FORMATION-FAILURE",
  515. "WPS-PIN-NEEDED"], timeout=15)
  516. if ev is None:
  517. raise Exception("Group formation timed out")
  518. res0 = dev[0].group_form_result(ev)
  519. ev = dev[1].wait_event(["P2P-GROUP-STARTED",
  520. "P2P-GO-NEG-FAILURE",
  521. "P2P-GROUP-FORMATION-FAILURE",
  522. "WPS-PIN-NEEDED"], timeout=1)
  523. if ev is None:
  524. raise Exception("Group formation timed out")
  525. res1 = dev[1].group_form_result(ev)
  526. logger.info("Group formed")
  527. if res0['role'] != 'client' or res1['role'] != 'GO':
  528. raise Exception("Unexpected roles negotiated")
  529. hwsim_utils.test_connectivity_p2p(dev[0], dev[1])
  530. check_ip_addr(res0)
  531. print "Client 1 IP address: " + res0['ip_addr']
  532. logger.info("Connect a P2P client")
  533. pin = dev[2].wps_read_pin()
  534. dev[1].p2p_go_authorize_client(pin)
  535. res = dev[2].p2p_connect_group(dev[1].p2p_dev_addr(), pin, timeout=60)
  536. logger.info("Client connected")
  537. hwsim_utils.test_connectivity_p2p(dev[1], dev[2])
  538. check_ip_addr(res)
  539. print "Client 2 IP address: " + res['ip_addr']
  540. if res['ip_addr'] == res0['ip_addr']:
  541. raise Exception("Same IP address assigned to both clients")