test_nfc_p2p.py 36 KB

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