test_p2p_grpform.py 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493
  1. # P2P group formation test cases
  2. # Copyright (c) 2013-2014, Jouni Malinen <j@w1.fi>
  3. #
  4. # This software may be distributed under the terms of the BSD license.
  5. # See README for more details.
  6. import logging
  7. logger = logging.getLogger()
  8. import time
  9. import threading
  10. import Queue
  11. import hwsim_utils
  12. import utils
  13. def check_grpform_results(i_res, r_res):
  14. if i_res['result'] != 'success' or r_res['result'] != 'success':
  15. raise Exception("Failed group formation")
  16. if i_res['ssid'] != r_res['ssid']:
  17. raise Exception("SSID mismatch")
  18. if i_res['freq'] != r_res['freq']:
  19. raise Exception("freq mismatch")
  20. if 'go_neg_freq' in r_res and i_res['go_neg_freq'] != r_res['go_neg_freq']:
  21. raise Exception("go_neg_freq mismatch")
  22. if i_res['freq'] != i_res['go_neg_freq']:
  23. raise Exception("freq/go_neg_freq mismatch")
  24. if i_res['role'] != i_res['go_neg_role']:
  25. raise Exception("role/go_neg_role mismatch")
  26. if 'go_neg_role' in r_res and r_res['role'] != r_res['go_neg_role']:
  27. raise Exception("role/go_neg_role mismatch")
  28. if i_res['go_dev_addr'] != r_res['go_dev_addr']:
  29. raise Exception("GO Device Address mismatch")
  30. def go_neg_init(i_dev, r_dev, pin, i_method, i_intent, res):
  31. logger.debug("Initiate GO Negotiation from i_dev")
  32. try:
  33. i_res = i_dev.p2p_go_neg_init(r_dev.p2p_dev_addr(), pin, i_method, timeout=20, go_intent=i_intent)
  34. logger.debug("i_res: " + str(i_res))
  35. except Exception, e:
  36. i_res = None
  37. logger.info("go_neg_init thread caught an exception from p2p_go_neg_init: " + str(e))
  38. res.put(i_res)
  39. def go_neg_pin(i_dev, r_dev, i_intent=None, r_intent=None, i_method='enter', r_method='display'):
  40. r_dev.p2p_listen()
  41. i_dev.p2p_listen()
  42. pin = r_dev.wps_read_pin()
  43. logger.info("Start GO negotiation " + i_dev.ifname + " -> " + r_dev.ifname)
  44. r_dev.dump_monitor()
  45. res = Queue.Queue()
  46. t = threading.Thread(target=go_neg_init, args=(i_dev, r_dev, pin, i_method, i_intent, res))
  47. t.start()
  48. logger.debug("Wait for GO Negotiation Request on r_dev")
  49. ev = r_dev.wait_global_event(["P2P-GO-NEG-REQUEST"], timeout=15)
  50. if ev is None:
  51. raise Exception("GO Negotiation timed out")
  52. r_dev.dump_monitor()
  53. logger.debug("Re-initiate GO Negotiation from r_dev")
  54. r_res = r_dev.p2p_go_neg_init(i_dev.p2p_dev_addr(), pin, r_method, go_intent=r_intent, timeout=20)
  55. logger.debug("r_res: " + str(r_res))
  56. r_dev.dump_monitor()
  57. t.join()
  58. i_res = res.get()
  59. if i_res is None:
  60. raise Exception("go_neg_init thread failed")
  61. logger.debug("i_res: " + str(i_res))
  62. logger.info("Group formed")
  63. hwsim_utils.test_connectivity_p2p(r_dev, i_dev)
  64. i_dev.dump_monitor()
  65. return [i_res, r_res]
  66. def go_neg_pin_authorized(i_dev, r_dev, i_intent=None, r_intent=None, expect_failure=False, i_go_neg_status=None, i_method='enter', r_method='display', test_data=True, i_freq=None, r_freq=None):
  67. r_dev.p2p_listen()
  68. i_dev.p2p_listen()
  69. pin = r_dev.wps_read_pin()
  70. logger.info("Start GO negotiation " + i_dev.ifname + " -> " + r_dev.ifname)
  71. r_dev.p2p_go_neg_auth(i_dev.p2p_dev_addr(), pin, r_method, go_intent=r_intent, freq=r_freq)
  72. i_res = i_dev.p2p_go_neg_init(r_dev.p2p_dev_addr(), pin, i_method, timeout=20, go_intent=i_intent, expect_failure=expect_failure, freq=i_freq)
  73. r_res = r_dev.p2p_go_neg_auth_result(expect_failure=expect_failure)
  74. logger.debug("i_res: " + str(i_res))
  75. logger.debug("r_res: " + str(r_res))
  76. r_dev.dump_monitor()
  77. i_dev.dump_monitor()
  78. if i_go_neg_status:
  79. if i_res['result'] != 'go-neg-failed':
  80. raise Exception("Expected GO Negotiation failure not reported")
  81. if i_res['status'] != i_go_neg_status:
  82. raise Exception("Expected GO Negotiation status not seen")
  83. if expect_failure:
  84. return
  85. logger.info("Group formed")
  86. if test_data:
  87. hwsim_utils.test_connectivity_p2p(r_dev, i_dev)
  88. return [i_res, r_res]
  89. def go_neg_init_pbc(i_dev, r_dev, i_intent, res, freq, provdisc):
  90. logger.debug("Initiate GO Negotiation from i_dev")
  91. try:
  92. i_res = i_dev.p2p_go_neg_init(r_dev.p2p_dev_addr(), None, "pbc",
  93. timeout=20, go_intent=i_intent, freq=freq,
  94. provdisc=provdisc)
  95. logger.debug("i_res: " + str(i_res))
  96. except Exception, e:
  97. i_res = None
  98. logger.info("go_neg_init_pbc thread caught an exception from p2p_go_neg_init: " + str(e))
  99. res.put(i_res)
  100. def go_neg_pbc(i_dev, r_dev, i_intent=None, r_intent=None, i_freq=None, r_freq=None, provdisc=False, r_listen=False):
  101. if r_listen:
  102. r_dev.p2p_listen()
  103. else:
  104. r_dev.p2p_find(social=True)
  105. i_dev.p2p_find(social=True)
  106. logger.info("Start GO negotiation " + i_dev.ifname + " -> " + r_dev.ifname)
  107. r_dev.dump_monitor()
  108. res = Queue.Queue()
  109. t = threading.Thread(target=go_neg_init_pbc, args=(i_dev, r_dev, i_intent, res, i_freq, provdisc))
  110. t.start()
  111. logger.debug("Wait for GO Negotiation Request on r_dev")
  112. ev = r_dev.wait_global_event(["P2P-GO-NEG-REQUEST"], timeout=15)
  113. if ev is None:
  114. raise Exception("GO Negotiation timed out")
  115. r_dev.dump_monitor()
  116. logger.debug("Re-initiate GO Negotiation from r_dev")
  117. r_res = r_dev.p2p_go_neg_init(i_dev.p2p_dev_addr(), None, "pbc",
  118. go_intent=r_intent, timeout=20, freq=r_freq)
  119. logger.debug("r_res: " + str(r_res))
  120. r_dev.dump_monitor()
  121. t.join()
  122. i_res = res.get()
  123. if i_res is None:
  124. raise Exception("go_neg_init_pbc thread failed")
  125. logger.debug("i_res: " + str(i_res))
  126. logger.info("Group formed")
  127. hwsim_utils.test_connectivity_p2p(r_dev, i_dev)
  128. i_dev.dump_monitor()
  129. return [i_res, r_res]
  130. def remove_group(dev1, dev2):
  131. dev1.remove_group()
  132. try:
  133. dev2.remove_group()
  134. except:
  135. pass
  136. def test_grpform(dev):
  137. """P2P group formation using PIN and authorized connection (init -> GO)"""
  138. [i_res, r_res] = go_neg_pin_authorized(i_dev=dev[0], i_intent=15,
  139. r_dev=dev[1], r_intent=0)
  140. check_grpform_results(i_res, r_res)
  141. remove_group(dev[0], dev[1])
  142. def test_grpform_a(dev):
  143. """P2P group formation using PIN and authorized connection (init -> GO) (init: group iface)"""
  144. dev[0].request("SET p2p_no_group_iface 0")
  145. [i_res, r_res] = go_neg_pin_authorized(i_dev=dev[0], i_intent=15,
  146. r_dev=dev[1], r_intent=0)
  147. if "p2p-wlan" not in i_res['ifname']:
  148. raise Exception("Unexpected group interface name")
  149. check_grpform_results(i_res, r_res)
  150. remove_group(dev[0], dev[1])
  151. if i_res['ifname'] in utils.get_ifnames():
  152. raise Exception("Group interface netdev was not removed")
  153. def test_grpform_b(dev):
  154. """P2P group formation using PIN and authorized connection (init -> GO) (resp: group iface)"""
  155. dev[1].request("SET p2p_no_group_iface 0")
  156. [i_res, r_res] = go_neg_pin_authorized(i_dev=dev[0], i_intent=15,
  157. r_dev=dev[1], r_intent=0)
  158. if "p2p-wlan" not in r_res['ifname']:
  159. raise Exception("Unexpected group interface name")
  160. check_grpform_results(i_res, r_res)
  161. remove_group(dev[0], dev[1])
  162. if r_res['ifname'] in utils.get_ifnames():
  163. raise Exception("Group interface netdev was not removed")
  164. def test_grpform_c(dev):
  165. """P2P group formation using PIN and authorized connection (init -> GO) (group iface)"""
  166. dev[0].request("SET p2p_no_group_iface 0")
  167. dev[1].request("SET p2p_no_group_iface 0")
  168. [i_res, r_res] = go_neg_pin_authorized(i_dev=dev[0], i_intent=15,
  169. r_dev=dev[1], r_intent=0)
  170. if "p2p-wlan" not in i_res['ifname']:
  171. raise Exception("Unexpected group interface name")
  172. if "p2p-wlan" not in r_res['ifname']:
  173. raise Exception("Unexpected group interface name")
  174. check_grpform_results(i_res, r_res)
  175. remove_group(dev[0], dev[1])
  176. if i_res['ifname'] in utils.get_ifnames():
  177. raise Exception("Group interface netdev was not removed")
  178. if r_res['ifname'] in utils.get_ifnames():
  179. raise Exception("Group interface netdev was not removed")
  180. def test_grpform2(dev):
  181. """P2P group formation using PIN and authorized connection (resp -> GO)"""
  182. go_neg_pin_authorized(i_dev=dev[0], i_intent=0, r_dev=dev[1], r_intent=15)
  183. remove_group(dev[0], dev[1])
  184. def test_grpform2_c(dev):
  185. """P2P group formation using PIN and authorized connection (resp -> GO) (group iface)"""
  186. dev[0].request("SET p2p_no_group_iface 0")
  187. dev[1].request("SET p2p_no_group_iface 0")
  188. [i_res, r_res] = go_neg_pin_authorized(i_dev=dev[0], i_intent=0, r_dev=dev[1], r_intent=15)
  189. remove_group(dev[0], dev[1])
  190. if i_res['ifname'] in utils.get_ifnames():
  191. raise Exception("Group interface netdev was not removed")
  192. if r_res['ifname'] in utils.get_ifnames():
  193. raise Exception("Group interface netdev was not removed")
  194. def test_grpform3(dev):
  195. """P2P group formation using PIN and re-init GO Negotiation"""
  196. go_neg_pin(i_dev=dev[0], i_intent=15, r_dev=dev[1], r_intent=0)
  197. remove_group(dev[0], dev[1])
  198. def test_grpform3_c(dev):
  199. """P2P group formation using PIN and re-init GO Negotiation (group iface)"""
  200. dev[0].request("SET p2p_no_group_iface 0")
  201. dev[1].request("SET p2p_no_group_iface 0")
  202. [i_res, r_res] = go_neg_pin(i_dev=dev[0], i_intent=15, r_dev=dev[1], r_intent=0)
  203. remove_group(dev[0], dev[1])
  204. if i_res['ifname'] in utils.get_ifnames():
  205. raise Exception("Group interface netdev was not removed")
  206. if r_res['ifname'] in utils.get_ifnames():
  207. raise Exception("Group interface netdev was not removed")
  208. def test_grpform_pbc(dev):
  209. """P2P group formation using PBC and re-init GO Negotiation"""
  210. [i_res, r_res] = go_neg_pbc(i_dev=dev[0], i_intent=15, r_dev=dev[1], r_intent=0)
  211. check_grpform_results(i_res, r_res)
  212. if i_res['role'] != 'GO' or r_res['role'] != 'client':
  213. raise Exception("Unexpected device roles")
  214. remove_group(dev[0], dev[1])
  215. def test_grpform_pd(dev):
  216. """P2P group formation with PD-before-GO-Neg workaround"""
  217. [i_res, r_res] = go_neg_pbc(i_dev=dev[0], provdisc=True, r_dev=dev[1], r_listen=True)
  218. check_grpform_results(i_res, r_res)
  219. remove_group(dev[0], dev[1])
  220. def test_both_go_intent_15(dev):
  221. """P2P GO Negotiation with both devices using GO intent 15"""
  222. go_neg_pin_authorized(i_dev=dev[0], i_intent=15, r_dev=dev[1], r_intent=15, expect_failure=True, i_go_neg_status=9)
  223. def test_both_go_neg_display(dev):
  224. """P2P GO Negotiation with both devices trying to display PIN"""
  225. go_neg_pin_authorized(i_dev=dev[0], r_dev=dev[1], expect_failure=True, i_go_neg_status=10, i_method='display', r_method='display')
  226. def test_both_go_neg_enter(dev):
  227. """P2P GO Negotiation with both devices trying to enter PIN"""
  228. go_neg_pin_authorized(i_dev=dev[0], r_dev=dev[1], expect_failure=True, i_go_neg_status=10, i_method='enter', r_method='enter')
  229. def test_grpform_per_sta_psk(dev):
  230. """P2P group formation with per-STA PSKs"""
  231. dev[0].request("P2P_SET per_sta_psk 1")
  232. [i_res, r_res] = go_neg_pin_authorized(i_dev=dev[0], i_intent=15, r_dev=dev[1], r_intent=0)
  233. check_grpform_results(i_res, r_res)
  234. pin = dev[2].wps_read_pin()
  235. dev[0].p2p_go_authorize_client(pin)
  236. c_res = dev[2].p2p_connect_group(dev[0].p2p_dev_addr(), pin, timeout=60)
  237. check_grpform_results(i_res, c_res)
  238. if r_res['psk'] == c_res['psk']:
  239. raise Exception("Same PSK assigned for both clients")
  240. hwsim_utils.test_connectivity_p2p(dev[1], dev[2])
  241. dev[0].remove_group()
  242. dev[1].wait_go_ending_session()
  243. dev[2].wait_go_ending_session()
  244. def test_grpform_per_sta_psk_wps(dev):
  245. """P2P group formation with per-STA PSKs with non-P2P WPS STA"""
  246. dev[0].request("P2P_SET per_sta_psk 1")
  247. [i_res, r_res] = go_neg_pin_authorized(i_dev=dev[0], i_intent=15, r_dev=dev[1], r_intent=0)
  248. check_grpform_results(i_res, r_res)
  249. dev[0].p2p_go_authorize_client_pbc()
  250. dev[2].request("WPS_PBC")
  251. ev = dev[2].wait_event(["CTRL-EVENT-CONNECTED"], timeout=30)
  252. if ev is None:
  253. raise Exception("Association with the GO timed out")
  254. hwsim_utils.test_connectivity_p2p_sta(dev[1], dev[2])
  255. dev[0].remove_group()
  256. dev[2].request("DISCONNECT")
  257. dev[1].wait_go_ending_session()
  258. def test_grpform_force_chan_go(dev):
  259. """P2P group formation forced channel selection by GO"""
  260. [i_res, r_res] = go_neg_pin_authorized(i_dev=dev[0], i_intent=15,
  261. i_freq=2432,
  262. r_dev=dev[1], r_intent=0,
  263. test_data=False)
  264. check_grpform_results(i_res, r_res)
  265. if i_res['freq'] != "2432":
  266. raise Exception("Unexpected channel - did not follow GO's forced channel")
  267. remove_group(dev[0], dev[1])
  268. def test_grpform_force_chan_cli(dev):
  269. """P2P group formation forced channel selection by client"""
  270. [i_res, r_res] = go_neg_pin_authorized(i_dev=dev[0], i_intent=0,
  271. i_freq=2417,
  272. r_dev=dev[1], r_intent=15,
  273. test_data=False)
  274. check_grpform_results(i_res, r_res)
  275. if i_res['freq'] != "2417":
  276. raise Exception("Unexpected channel - did not follow GO's forced channel")
  277. remove_group(dev[0], dev[1])
  278. def test_grpform_force_chan_conflict(dev):
  279. """P2P group formation fails due to forced channel mismatch"""
  280. go_neg_pin_authorized(i_dev=dev[0], i_intent=0, i_freq=2422,
  281. r_dev=dev[1], r_intent=15, r_freq=2427,
  282. expect_failure=True, i_go_neg_status=7)
  283. def test_grpform_pref_chan_go(dev):
  284. """P2P group formation preferred channel selection by GO"""
  285. dev[0].request("SET p2p_pref_chan 81:7")
  286. [i_res, r_res] = go_neg_pin_authorized(i_dev=dev[0], i_intent=15,
  287. r_dev=dev[1], r_intent=0,
  288. test_data=False)
  289. check_grpform_results(i_res, r_res)
  290. if i_res['freq'] != "2442":
  291. raise Exception("Unexpected channel - did not follow GO's p2p_pref_chan")
  292. remove_group(dev[0], dev[1])
  293. def test_grpform_pref_chan_go_overridden(dev):
  294. """P2P group formation preferred channel selection by GO overridden by client"""
  295. dev[1].request("SET p2p_pref_chan 81:7")
  296. [i_res, r_res] = go_neg_pin_authorized(i_dev=dev[0], i_intent=0,
  297. i_freq=2422,
  298. r_dev=dev[1], r_intent=15,
  299. test_data=False)
  300. check_grpform_results(i_res, r_res)
  301. if i_res['freq'] != "2422":
  302. raise Exception("Unexpected channel - did not follow client's forced channel")
  303. remove_group(dev[0], dev[1])
  304. def test_grpform_no_go_freq_forcing_chan(dev):
  305. """P2P group formation with no-GO freq forcing channel"""
  306. dev[1].request("SET p2p_no_go_freq 100-200,300,4000-6000")
  307. [i_res, r_res] = go_neg_pin_authorized(i_dev=dev[0], i_intent=0,
  308. r_dev=dev[1], r_intent=15,
  309. test_data=False)
  310. check_grpform_results(i_res, r_res)
  311. if int(i_res['freq']) > 4000:
  312. raise Exception("Unexpected channel - did not follow no-GO freq")
  313. remove_group(dev[0], dev[1])
  314. def test_grpform_no_go_freq_conflict(dev):
  315. """P2P group formation fails due to no-GO range forced by client"""
  316. dev[1].request("SET p2p_no_go_freq 2000-3000")
  317. go_neg_pin_authorized(i_dev=dev[0], i_intent=0, i_freq=2422,
  318. r_dev=dev[1], r_intent=15,
  319. expect_failure=True, i_go_neg_status=7)
  320. def test_grpform_no_5ghz_world_roaming(dev):
  321. """P2P group formation with world roaming regulatory"""
  322. [i_res, r_res] = go_neg_pin_authorized(i_dev=dev[0], i_intent=0,
  323. r_dev=dev[1], r_intent=15,
  324. test_data=False)
  325. check_grpform_results(i_res, r_res)
  326. if int(i_res['freq']) > 4000:
  327. raise Exception("Unexpected channel - did not follow world roaming rules")
  328. remove_group(dev[0], dev[1])
  329. def test_grpform_no_5ghz_add_cli(dev):
  330. """P2P group formation with passive scan 5 GHz and p2p_add_cli_chan=1"""
  331. dev[0].request("SET p2p_add_cli_chan 1")
  332. dev[1].request("SET p2p_add_cli_chan 1")
  333. [i_res, r_res] = go_neg_pin_authorized(i_dev=dev[0], i_intent=0,
  334. r_dev=dev[1], r_intent=14,
  335. test_data=False)
  336. check_grpform_results(i_res, r_res)
  337. if int(i_res['freq']) > 4000:
  338. raise Exception("Unexpected channel - did not follow world roaming rules")
  339. remove_group(dev[0], dev[1])
  340. def test_grpform_no_5ghz_add_cli2(dev):
  341. """P2P group formation with passive scan 5 GHz and p2p_add_cli_chan=1 (reverse)"""
  342. dev[0].request("SET p2p_add_cli_chan 1")
  343. dev[1].request("SET p2p_add_cli_chan 1")
  344. [i_res, r_res] = go_neg_pin_authorized(i_dev=dev[0], i_intent=14,
  345. r_dev=dev[1], r_intent=0,
  346. test_data=False)
  347. check_grpform_results(i_res, r_res)
  348. if int(i_res['freq']) > 4000:
  349. raise Exception("Unexpected channel - did not follow world roaming rules")
  350. remove_group(dev[0], dev[1])
  351. def test_grpform_no_5ghz_add_cli3(dev):
  352. """P2P group formation with passive scan 5 GHz and p2p_add_cli_chan=1 (intent 15)"""
  353. dev[0].request("SET p2p_add_cli_chan 1")
  354. dev[1].request("SET p2p_add_cli_chan 1")
  355. [i_res, r_res] = go_neg_pin_authorized(i_dev=dev[0], i_intent=0,
  356. r_dev=dev[1], r_intent=15,
  357. test_data=False)
  358. check_grpform_results(i_res, r_res)
  359. if int(i_res['freq']) > 4000:
  360. raise Exception("Unexpected channel - did not follow world roaming rules")
  361. remove_group(dev[0], dev[1])
  362. def test_grpform_no_5ghz_add_cli4(dev):
  363. """P2P group formation with passive scan 5 GHz and p2p_add_cli_chan=1 (reverse; intent 15)"""
  364. dev[0].request("SET p2p_add_cli_chan 1")
  365. dev[1].request("SET p2p_add_cli_chan 1")
  366. [i_res, r_res] = go_neg_pin_authorized(i_dev=dev[0], i_intent=15,
  367. r_dev=dev[1], r_intent=0,
  368. test_data=False)
  369. check_grpform_results(i_res, r_res)
  370. if int(i_res['freq']) > 4000:
  371. raise Exception("Unexpected channel - did not follow world roaming rules")
  372. remove_group(dev[0], dev[1])
  373. def test_grpform_incorrect_pin(dev):
  374. """P2P GO Negotiation with incorrect PIN"""
  375. dev[1].p2p_listen()
  376. pin = dev[1].wps_read_pin()
  377. addr1 = dev[1].p2p_dev_addr()
  378. if not dev[0].discover_peer(addr1):
  379. raise Exception("Peer not found")
  380. dev[1].p2p_go_neg_auth(dev[0].p2p_dev_addr(), pin, 'display', go_intent=0)
  381. dev[0].request("P2P_CONNECT " + addr1 + " 00000000 enter go_intent=15")
  382. ev = dev[1].wait_event(["P2P-GROUP-FORMATION-FAILURE"], timeout=10)
  383. if ev is None:
  384. raise Exception("Group formation failure timed out")
  385. ev = dev[0].wait_event(["P2P-GROUP-FORMATION-FAILURE"], timeout=5)
  386. if ev is None:
  387. raise Exception("Group formation failure timed out")
  388. def test_grpform_reject(dev):
  389. """User rejecting group formation attempt by a P2P peer"""
  390. addr0 = dev[0].p2p_dev_addr()
  391. dev[0].p2p_listen()
  392. dev[1].p2p_go_neg_init(addr0, None, "pbc")
  393. ev = dev[0].wait_global_event(["P2P-GO-NEG-REQUEST"], timeout=15)
  394. if ev is None:
  395. raise Exception("GO Negotiation timed out")
  396. if "FAIL" in dev[0].global_request("P2P_REJECT " + ev.split(' ')[1]):
  397. raise Exception("P2P_REJECT failed")
  398. dev[1].request("P2P_STOP_FIND")
  399. dev[1].p2p_go_neg_init(addr0, None, "pbc")
  400. ev = dev[1].wait_global_event(["GO-NEG-FAILURE"], timeout=10)
  401. if ev is None:
  402. raise Exception("Rejection not reported")
  403. if "status=11" not in ev:
  404. raise Exception("Unexpected status code in rejection")
  405. def test_grpform_pd_no_probe_resp(dev):
  406. """GO Negotiation after PD, but no Probe Response"""
  407. addr0 = dev[0].p2p_dev_addr()
  408. addr1 = dev[1].p2p_dev_addr()
  409. dev[0].p2p_listen()
  410. if not dev[1].discover_peer(addr0):
  411. raise Exception("Peer not found")
  412. dev[1].p2p_stop_find()
  413. dev[0].p2p_stop_find()
  414. peer = dev[0].get_peer(addr1)
  415. if peer['listen_freq'] == '0':
  416. raise Exception("Peer listen frequency not learned from Probe Request")
  417. time.sleep(0.3)
  418. dev[0].request("P2P_FLUSH")
  419. dev[0].p2p_listen()
  420. dev[1].global_request("P2P_PROV_DISC " + addr0 + " display")
  421. ev = dev[0].wait_global_event(["P2P-PROV-DISC-SHOW-PIN"], timeout=5)
  422. if ev is None:
  423. raise Exception("PD Request timed out")
  424. ev = dev[1].wait_global_event(["P2P-PROV-DISC-ENTER-PIN"], timeout=5)
  425. if ev is None:
  426. raise Exception("PD Response timed out")
  427. peer = dev[0].get_peer(addr1)
  428. if peer['listen_freq'] != '0':
  429. raise Exception("Peer listen frequency learned unexpectedly from PD Request")
  430. pin = dev[0].wps_read_pin()
  431. if "FAIL" in dev[1].request("P2P_CONNECT " + addr0 + " " + pin + " enter"):
  432. raise Exception("P2P_CONNECT on initiator failed")
  433. ev = dev[0].wait_global_event(["P2P-GO-NEG-REQUEST"], timeout=5)
  434. if ev is None:
  435. raise Exception("GO Negotiation start timed out")
  436. peer = dev[0].get_peer(addr1)
  437. if peer['listen_freq'] == '0':
  438. raise Exception("Peer listen frequency not learned from PD followed by GO Neg Req")
  439. if "FAIL" in dev[0].request("P2P_CONNECT " + addr1 + " " + pin + " display"):
  440. raise Exception("P2P_CONNECT on responder failed")
  441. ev = dev[0].wait_global_event(["P2P-GROUP-STARTED"], timeout=15)
  442. if ev is None:
  443. raise Exception("Group formation timed out")
  444. ev = dev[1].wait_global_event(["P2P-GROUP-STARTED"], timeout=15)
  445. if ev is None:
  446. raise Exception("Group formation timed out")