test_nfc_p2p.py 35 KB

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