test_nfc_p2p.py 37 KB

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