test_p2p_grpform.py 41 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930
  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 os
  12. import hostapd
  13. import hwsim_utils
  14. import utils
  15. from utils import HwsimSkip
  16. from wpasupplicant import WpaSupplicant
  17. def check_grpform_results(i_res, r_res):
  18. if i_res['result'] != 'success' or r_res['result'] != 'success':
  19. raise Exception("Failed group formation")
  20. if i_res['ssid'] != r_res['ssid']:
  21. raise Exception("SSID mismatch")
  22. if i_res['freq'] != r_res['freq']:
  23. raise Exception("freq mismatch")
  24. if 'go_neg_freq' in r_res and i_res['go_neg_freq'] != r_res['go_neg_freq']:
  25. raise Exception("go_neg_freq mismatch")
  26. if i_res['freq'] != i_res['go_neg_freq']:
  27. raise Exception("freq/go_neg_freq mismatch")
  28. if i_res['role'] != i_res['go_neg_role']:
  29. raise Exception("role/go_neg_role mismatch")
  30. if 'go_neg_role' in r_res and r_res['role'] != r_res['go_neg_role']:
  31. raise Exception("role/go_neg_role mismatch")
  32. if i_res['go_dev_addr'] != r_res['go_dev_addr']:
  33. raise Exception("GO Device Address mismatch")
  34. def go_neg_init(i_dev, r_dev, pin, i_method, i_intent, res):
  35. logger.debug("Initiate GO Negotiation from i_dev")
  36. try:
  37. i_res = i_dev.p2p_go_neg_init(r_dev.p2p_dev_addr(), pin, i_method, timeout=20, go_intent=i_intent)
  38. logger.debug("i_res: " + str(i_res))
  39. except Exception, e:
  40. i_res = None
  41. logger.info("go_neg_init thread caught an exception from p2p_go_neg_init: " + str(e))
  42. res.put(i_res)
  43. def go_neg_pin(i_dev, r_dev, i_intent=None, r_intent=None, i_method='enter', r_method='display'):
  44. r_dev.p2p_listen()
  45. i_dev.p2p_listen()
  46. pin = r_dev.wps_read_pin()
  47. logger.info("Start GO negotiation " + i_dev.ifname + " -> " + r_dev.ifname)
  48. r_dev.dump_monitor()
  49. res = Queue.Queue()
  50. t = threading.Thread(target=go_neg_init, args=(i_dev, r_dev, pin, i_method, i_intent, res))
  51. t.start()
  52. logger.debug("Wait for GO Negotiation Request on r_dev")
  53. ev = r_dev.wait_global_event(["P2P-GO-NEG-REQUEST"], timeout=15)
  54. if ev is None:
  55. raise Exception("GO Negotiation timed out")
  56. r_dev.dump_monitor()
  57. logger.debug("Re-initiate GO Negotiation from r_dev")
  58. r_res = r_dev.p2p_go_neg_init(i_dev.p2p_dev_addr(), pin, r_method, go_intent=r_intent, timeout=20)
  59. logger.debug("r_res: " + str(r_res))
  60. r_dev.dump_monitor()
  61. t.join()
  62. i_res = res.get()
  63. if i_res is None:
  64. raise Exception("go_neg_init thread failed")
  65. logger.debug("i_res: " + str(i_res))
  66. logger.info("Group formed")
  67. hwsim_utils.test_connectivity_p2p(r_dev, i_dev)
  68. i_dev.dump_monitor()
  69. return [i_res, r_res]
  70. 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):
  71. i_dev.p2p_listen()
  72. pin = r_dev.wps_read_pin()
  73. logger.info("Start GO negotiation " + i_dev.ifname + " -> " + r_dev.ifname)
  74. r_dev.p2p_go_neg_auth(i_dev.p2p_dev_addr(), pin, r_method, go_intent=r_intent, freq=r_freq)
  75. r_dev.p2p_listen()
  76. 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)
  77. r_res = r_dev.p2p_go_neg_auth_result(expect_failure=expect_failure)
  78. logger.debug("i_res: " + str(i_res))
  79. logger.debug("r_res: " + str(r_res))
  80. r_dev.dump_monitor()
  81. i_dev.dump_monitor()
  82. if i_go_neg_status:
  83. if i_res['result'] != 'go-neg-failed':
  84. raise Exception("Expected GO Negotiation failure not reported")
  85. if i_res['status'] != i_go_neg_status:
  86. raise Exception("Expected GO Negotiation status not seen")
  87. if expect_failure:
  88. return
  89. logger.info("Group formed")
  90. if test_data:
  91. hwsim_utils.test_connectivity_p2p(r_dev, i_dev)
  92. return [i_res, r_res]
  93. def go_neg_init_pbc(i_dev, r_dev, i_intent, res, freq, provdisc):
  94. logger.debug("Initiate GO Negotiation from i_dev")
  95. try:
  96. i_res = i_dev.p2p_go_neg_init(r_dev.p2p_dev_addr(), None, "pbc",
  97. timeout=20, go_intent=i_intent, freq=freq,
  98. provdisc=provdisc)
  99. logger.debug("i_res: " + str(i_res))
  100. except Exception, e:
  101. i_res = None
  102. logger.info("go_neg_init_pbc thread caught an exception from p2p_go_neg_init: " + str(e))
  103. res.put(i_res)
  104. 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):
  105. if r_listen:
  106. r_dev.p2p_listen()
  107. else:
  108. r_dev.p2p_find(social=True)
  109. i_dev.p2p_find(social=True)
  110. logger.info("Start GO negotiation " + i_dev.ifname + " -> " + r_dev.ifname)
  111. r_dev.dump_monitor()
  112. res = Queue.Queue()
  113. t = threading.Thread(target=go_neg_init_pbc, args=(i_dev, r_dev, i_intent, res, i_freq, provdisc))
  114. t.start()
  115. logger.debug("Wait for GO Negotiation Request on r_dev")
  116. ev = r_dev.wait_global_event(["P2P-GO-NEG-REQUEST"], timeout=15)
  117. if ev is None:
  118. raise Exception("GO Negotiation timed out")
  119. r_dev.dump_monitor()
  120. # Allow some time for the GO Neg Resp to go out before initializing new
  121. # GO Negotiation.
  122. time.sleep(0.2)
  123. logger.debug("Re-initiate GO Negotiation from r_dev")
  124. r_res = r_dev.p2p_go_neg_init(i_dev.p2p_dev_addr(), None, "pbc",
  125. go_intent=r_intent, timeout=20, freq=r_freq)
  126. logger.debug("r_res: " + str(r_res))
  127. r_dev.dump_monitor()
  128. t.join()
  129. i_res = res.get()
  130. if i_res is None:
  131. raise Exception("go_neg_init_pbc thread failed")
  132. logger.debug("i_res: " + str(i_res))
  133. logger.info("Group formed")
  134. hwsim_utils.test_connectivity_p2p(r_dev, i_dev)
  135. i_dev.dump_monitor()
  136. return [i_res, r_res]
  137. def go_neg_pbc_authorized(i_dev, r_dev, i_intent=None, r_intent=None,
  138. expect_failure=False, i_freq=None, r_freq=None):
  139. i_dev.p2p_listen()
  140. logger.info("Start GO negotiation " + i_dev.ifname + " -> " + r_dev.ifname)
  141. r_dev.p2p_go_neg_auth(i_dev.p2p_dev_addr(), None, "pbc",
  142. go_intent=r_intent, freq=r_freq)
  143. r_dev.p2p_listen()
  144. i_res = i_dev.p2p_go_neg_init(r_dev.p2p_dev_addr(), None, "pbc", timeout=20,
  145. go_intent=i_intent,
  146. expect_failure=expect_failure, freq=i_freq)
  147. r_res = r_dev.p2p_go_neg_auth_result(expect_failure=expect_failure)
  148. logger.debug("i_res: " + str(i_res))
  149. logger.debug("r_res: " + str(r_res))
  150. r_dev.dump_monitor()
  151. i_dev.dump_monitor()
  152. if expect_failure:
  153. return
  154. logger.info("Group formed")
  155. return [i_res, r_res]
  156. def remove_group(dev1, dev2):
  157. dev1.remove_group()
  158. try:
  159. dev2.remove_group()
  160. except:
  161. pass
  162. def test_grpform(dev):
  163. """P2P group formation using PIN and authorized connection (init -> GO)"""
  164. try:
  165. dev[0].request("SET p2p_group_idle 2")
  166. [i_res, r_res] = go_neg_pin_authorized(i_dev=dev[0], i_intent=15,
  167. r_dev=dev[1], r_intent=0)
  168. check_grpform_results(i_res, r_res)
  169. dev[1].remove_group()
  170. ev = dev[0].wait_global_event(["P2P-GROUP-REMOVED"], timeout=10)
  171. if ev is None:
  172. raise Exception("GO did not remove group on idle timeout")
  173. if "GO reason=IDLE" not in ev:
  174. raise Exception("Unexpected group removal event: " + ev)
  175. finally:
  176. dev[0].request("SET p2p_group_idle 0")
  177. def test_grpform_a(dev):
  178. """P2P group formation using PIN and authorized connection (init -> GO) (init: group iface)"""
  179. dev[0].request("SET p2p_no_group_iface 0")
  180. [i_res, r_res] = go_neg_pin_authorized(i_dev=dev[0], i_intent=15,
  181. r_dev=dev[1], r_intent=0)
  182. if "p2p-wlan" not in i_res['ifname']:
  183. raise Exception("Unexpected group interface name")
  184. check_grpform_results(i_res, r_res)
  185. remove_group(dev[0], dev[1])
  186. if i_res['ifname'] in utils.get_ifnames():
  187. raise Exception("Group interface netdev was not removed")
  188. def test_grpform_b(dev):
  189. """P2P group formation using PIN and authorized connection (init -> GO) (resp: group iface)"""
  190. dev[1].request("SET p2p_no_group_iface 0")
  191. [i_res, r_res] = go_neg_pin_authorized(i_dev=dev[0], i_intent=15,
  192. r_dev=dev[1], r_intent=0)
  193. if "p2p-wlan" not in r_res['ifname']:
  194. raise Exception("Unexpected group interface name")
  195. check_grpform_results(i_res, r_res)
  196. remove_group(dev[0], dev[1])
  197. if r_res['ifname'] in utils.get_ifnames():
  198. raise Exception("Group interface netdev was not removed")
  199. def test_grpform_c(dev):
  200. """P2P group formation using PIN and authorized connection (init -> GO) (group iface)"""
  201. dev[0].request("SET p2p_no_group_iface 0")
  202. dev[1].request("SET p2p_no_group_iface 0")
  203. [i_res, r_res] = go_neg_pin_authorized(i_dev=dev[0], i_intent=15,
  204. r_dev=dev[1], r_intent=0)
  205. if "p2p-wlan" not in i_res['ifname']:
  206. raise Exception("Unexpected group interface name")
  207. if "p2p-wlan" not in r_res['ifname']:
  208. raise Exception("Unexpected group interface name")
  209. check_grpform_results(i_res, r_res)
  210. remove_group(dev[0], dev[1])
  211. if i_res['ifname'] in utils.get_ifnames():
  212. raise Exception("Group interface netdev was not removed")
  213. if r_res['ifname'] in utils.get_ifnames():
  214. raise Exception("Group interface netdev was not removed")
  215. def test_grpform2(dev):
  216. """P2P group formation using PIN and authorized connection (resp -> GO)"""
  217. go_neg_pin_authorized(i_dev=dev[0], i_intent=0, r_dev=dev[1], r_intent=15)
  218. remove_group(dev[0], dev[1])
  219. def test_grpform2_c(dev):
  220. """P2P group formation using PIN and authorized connection (resp -> GO) (group iface)"""
  221. dev[0].request("SET p2p_no_group_iface 0")
  222. dev[1].request("SET p2p_no_group_iface 0")
  223. [i_res, r_res] = go_neg_pin_authorized(i_dev=dev[0], i_intent=0, r_dev=dev[1], r_intent=15)
  224. remove_group(dev[0], dev[1])
  225. if i_res['ifname'] in utils.get_ifnames():
  226. raise Exception("Group interface netdev was not removed")
  227. if r_res['ifname'] in utils.get_ifnames():
  228. raise Exception("Group interface netdev was not removed")
  229. def test_grpform3(dev):
  230. """P2P group formation using PIN and re-init GO Negotiation"""
  231. go_neg_pin(i_dev=dev[0], i_intent=15, r_dev=dev[1], r_intent=0)
  232. remove_group(dev[0], dev[1])
  233. def test_grpform3_c(dev):
  234. """P2P group formation using PIN and re-init GO Negotiation (group iface)"""
  235. dev[0].request("SET p2p_no_group_iface 0")
  236. dev[1].request("SET p2p_no_group_iface 0")
  237. [i_res, r_res] = go_neg_pin(i_dev=dev[0], i_intent=15, r_dev=dev[1], r_intent=0)
  238. remove_group(dev[0], dev[1])
  239. if i_res['ifname'] in utils.get_ifnames():
  240. raise Exception("Group interface netdev was not removed")
  241. if r_res['ifname'] in utils.get_ifnames():
  242. raise Exception("Group interface netdev was not removed")
  243. def test_grpform_pbc(dev):
  244. """P2P group formation using PBC and re-init GO Negotiation"""
  245. [i_res, r_res] = go_neg_pbc(i_dev=dev[0], i_intent=15, r_dev=dev[1], r_intent=0)
  246. check_grpform_results(i_res, r_res)
  247. if i_res['role'] != 'GO' or r_res['role'] != 'client':
  248. raise Exception("Unexpected device roles")
  249. remove_group(dev[0], dev[1])
  250. def test_grpform_pd(dev):
  251. """P2P group formation with PD-before-GO-Neg workaround"""
  252. [i_res, r_res] = go_neg_pbc(i_dev=dev[0], provdisc=True, r_dev=dev[1], r_listen=True)
  253. check_grpform_results(i_res, r_res)
  254. remove_group(dev[0], dev[1])
  255. def test_grpform_ext_listen(dev):
  256. """P2P group formation with extended listen timing enabled"""
  257. try:
  258. if "FAIL" not in dev[0].global_request("P2P_EXT_LISTEN 100"):
  259. raise Exception("Invalid P2P_EXT_LISTEN accepted")
  260. if "OK" not in dev[0].global_request("P2P_EXT_LISTEN 100 50000"):
  261. raise Exception("Failed to set extended listen timing")
  262. if "OK" not in dev[1].global_request("P2P_EXT_LISTEN 200 40000"):
  263. raise Exception("Failed to set extended listen timing")
  264. [i_res, r_res] = go_neg_pbc(i_dev=dev[0], provdisc=True, r_dev=dev[1], r_listen=True)
  265. check_grpform_results(i_res, r_res)
  266. peer1 = dev[0].get_peer(dev[1].p2p_dev_addr())
  267. if peer1['ext_listen_interval'] != "40000":
  268. raise Exception("Extended listen interval not discovered correctly")
  269. if peer1['ext_listen_period'] != "200":
  270. raise Exception("Extended listen period not discovered correctly")
  271. peer0 = dev[1].get_peer(dev[0].p2p_dev_addr())
  272. if peer0['ext_listen_interval'] != "50000":
  273. raise Exception("Extended listen interval not discovered correctly")
  274. if peer0['ext_listen_period'] != "100":
  275. raise Exception("Extended listen period not discovered correctly")
  276. remove_group(dev[0], dev[1])
  277. finally:
  278. if "OK" not in dev[0].global_request("P2P_EXT_LISTEN"):
  279. raise Exception("Failed to clear extended listen timing")
  280. if "OK" not in dev[1].global_request("P2P_EXT_LISTEN"):
  281. raise Exception("Failed to clear extended listen timing")
  282. def test_both_go_intent_15(dev):
  283. """P2P GO Negotiation with both devices using GO intent 15"""
  284. 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)
  285. def test_both_go_neg_display(dev):
  286. """P2P GO Negotiation with both devices trying to display PIN"""
  287. 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')
  288. def test_both_go_neg_enter(dev):
  289. """P2P GO Negotiation with both devices trying to enter PIN"""
  290. 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')
  291. def test_go_neg_pbc_vs_pin(dev):
  292. """P2P GO Negotiation with one device using PBC and the other PIN"""
  293. addr0 = dev[0].p2p_dev_addr()
  294. addr1 = dev[1].p2p_dev_addr()
  295. dev[1].p2p_listen()
  296. if not dev[0].discover_peer(addr1):
  297. raise Exception("Could not discover peer")
  298. dev[0].p2p_listen()
  299. if "OK" not in dev[0].request("P2P_CONNECT " + addr1 + " pbc auth"):
  300. raise Exception("Failed to authorize GO Neg")
  301. if not dev[1].discover_peer(addr0):
  302. raise Exception("Could not discover peer")
  303. if "OK" not in dev[1].request("P2P_CONNECT " + addr0 + " 12345670 display"):
  304. raise Exception("Failed to initiate GO Neg")
  305. ev = dev[1].wait_global_event(["P2P-GO-NEG-FAILURE"], timeout=10)
  306. if ev is None:
  307. raise Exception("GO Negotiation failure timed out")
  308. if "status=10" not in ev:
  309. raise Exception("Unexpected failure reason: " + ev)
  310. def test_go_neg_pin_vs_pbc(dev):
  311. """P2P GO Negotiation with one device using PIN and the other PBC"""
  312. addr0 = dev[0].p2p_dev_addr()
  313. addr1 = dev[1].p2p_dev_addr()
  314. dev[1].p2p_listen()
  315. if not dev[0].discover_peer(addr1):
  316. raise Exception("Could not discover peer")
  317. dev[0].p2p_listen()
  318. if "OK" not in dev[0].request("P2P_CONNECT " + addr1 + " 12345670 display auth"):
  319. raise Exception("Failed to authorize GO Neg")
  320. if not dev[1].discover_peer(addr0):
  321. raise Exception("Could not discover peer")
  322. if "OK" not in dev[1].request("P2P_CONNECT " + addr0 + " pbc"):
  323. raise Exception("Failed to initiate GO Neg")
  324. ev = dev[1].wait_global_event(["P2P-GO-NEG-FAILURE"], timeout=10)
  325. if ev is None:
  326. raise Exception("GO Negotiation failure timed out")
  327. if "status=10" not in ev:
  328. raise Exception("Unexpected failure reason: " + ev)
  329. def test_grpform_per_sta_psk(dev):
  330. """P2P group formation with per-STA PSKs"""
  331. dev[0].request("P2P_SET per_sta_psk 1")
  332. [i_res, r_res] = go_neg_pin_authorized(i_dev=dev[0], i_intent=15, r_dev=dev[1], r_intent=0)
  333. check_grpform_results(i_res, r_res)
  334. pin = dev[2].wps_read_pin()
  335. dev[0].p2p_go_authorize_client(pin)
  336. c_res = dev[2].p2p_connect_group(dev[0].p2p_dev_addr(), pin, timeout=60)
  337. check_grpform_results(i_res, c_res)
  338. if r_res['psk'] == c_res['psk']:
  339. raise Exception("Same PSK assigned for both clients")
  340. hwsim_utils.test_connectivity_p2p(dev[1], dev[2])
  341. dev[0].remove_group()
  342. dev[1].wait_go_ending_session()
  343. dev[2].wait_go_ending_session()
  344. def test_grpform_per_sta_psk_wps(dev):
  345. """P2P group formation with per-STA PSKs with non-P2P WPS STA"""
  346. dev[0].request("P2P_SET per_sta_psk 1")
  347. [i_res, r_res] = go_neg_pin_authorized(i_dev=dev[0], i_intent=15, r_dev=dev[1], r_intent=0)
  348. check_grpform_results(i_res, r_res)
  349. dev[0].p2p_go_authorize_client_pbc()
  350. dev[2].request("WPS_PBC")
  351. dev[2].wait_connected(timeout=30)
  352. hwsim_utils.test_connectivity_p2p_sta(dev[1], dev[2])
  353. dev[0].remove_group()
  354. dev[2].request("DISCONNECT")
  355. dev[1].wait_go_ending_session()
  356. def test_grpform_force_chan_go(dev):
  357. """P2P group formation forced channel selection by GO"""
  358. [i_res, r_res] = go_neg_pin_authorized(i_dev=dev[0], i_intent=15,
  359. i_freq=2432,
  360. r_dev=dev[1], r_intent=0,
  361. test_data=False)
  362. check_grpform_results(i_res, r_res)
  363. if i_res['freq'] != "2432":
  364. raise Exception("Unexpected channel - did not follow GO's forced channel")
  365. remove_group(dev[0], dev[1])
  366. def test_grpform_force_chan_cli(dev):
  367. """P2P group formation forced channel selection by client"""
  368. [i_res, r_res] = go_neg_pin_authorized(i_dev=dev[0], i_intent=0,
  369. i_freq=2417,
  370. r_dev=dev[1], r_intent=15,
  371. test_data=False)
  372. check_grpform_results(i_res, r_res)
  373. if i_res['freq'] != "2417":
  374. raise Exception("Unexpected channel - did not follow GO's forced channel")
  375. remove_group(dev[0], dev[1])
  376. def test_grpform_force_chan_conflict(dev):
  377. """P2P group formation fails due to forced channel mismatch"""
  378. go_neg_pin_authorized(i_dev=dev[0], i_intent=0, i_freq=2422,
  379. r_dev=dev[1], r_intent=15, r_freq=2427,
  380. expect_failure=True, i_go_neg_status=7)
  381. def test_grpform_pref_chan_go(dev):
  382. """P2P group formation preferred channel selection by GO"""
  383. dev[0].request("SET p2p_pref_chan 81:7")
  384. [i_res, r_res] = go_neg_pin_authorized(i_dev=dev[0], i_intent=15,
  385. r_dev=dev[1], r_intent=0,
  386. test_data=False)
  387. check_grpform_results(i_res, r_res)
  388. if i_res['freq'] != "2442":
  389. raise Exception("Unexpected channel - did not follow GO's p2p_pref_chan")
  390. remove_group(dev[0], dev[1])
  391. def test_grpform_pref_chan_go_overridden(dev):
  392. """P2P group formation preferred channel selection by GO overridden by client"""
  393. dev[1].request("SET p2p_pref_chan 81:7")
  394. [i_res, r_res] = go_neg_pin_authorized(i_dev=dev[0], i_intent=0,
  395. i_freq=2422,
  396. r_dev=dev[1], r_intent=15,
  397. test_data=False)
  398. check_grpform_results(i_res, r_res)
  399. if i_res['freq'] != "2422":
  400. raise Exception("Unexpected channel - did not follow client's forced channel")
  401. remove_group(dev[0], dev[1])
  402. def test_grpform_no_go_freq_forcing_chan(dev):
  403. """P2P group formation with no-GO freq forcing channel"""
  404. dev[1].request("SET p2p_no_go_freq 100-200,300,4000-6000")
  405. [i_res, r_res] = go_neg_pin_authorized(i_dev=dev[0], i_intent=0,
  406. r_dev=dev[1], r_intent=15,
  407. test_data=False)
  408. check_grpform_results(i_res, r_res)
  409. if int(i_res['freq']) > 4000:
  410. raise Exception("Unexpected channel - did not follow no-GO freq")
  411. remove_group(dev[0], dev[1])
  412. def test_grpform_no_go_freq_conflict(dev):
  413. """P2P group formation fails due to no-GO range forced by client"""
  414. dev[1].request("SET p2p_no_go_freq 2000-3000")
  415. go_neg_pin_authorized(i_dev=dev[0], i_intent=0, i_freq=2422,
  416. r_dev=dev[1], r_intent=15,
  417. expect_failure=True, i_go_neg_status=7)
  418. def test_grpform_no_5ghz_world_roaming(dev):
  419. """P2P group formation with world roaming regulatory"""
  420. [i_res, r_res] = go_neg_pin_authorized(i_dev=dev[0], i_intent=0,
  421. r_dev=dev[1], r_intent=15,
  422. test_data=False)
  423. check_grpform_results(i_res, r_res)
  424. if int(i_res['freq']) > 4000:
  425. raise Exception("Unexpected channel - did not follow world roaming rules")
  426. remove_group(dev[0], dev[1])
  427. def test_grpform_no_5ghz_add_cli(dev):
  428. """P2P group formation with passive scan 5 GHz and p2p_add_cli_chan=1"""
  429. dev[0].request("SET p2p_add_cli_chan 1")
  430. dev[1].request("SET p2p_add_cli_chan 1")
  431. [i_res, r_res] = go_neg_pin_authorized(i_dev=dev[0], i_intent=0,
  432. r_dev=dev[1], r_intent=14,
  433. test_data=False)
  434. check_grpform_results(i_res, r_res)
  435. if int(i_res['freq']) > 4000:
  436. raise Exception("Unexpected channel - did not follow world roaming rules")
  437. remove_group(dev[0], dev[1])
  438. def test_grpform_no_5ghz_add_cli2(dev):
  439. """P2P group formation with passive scan 5 GHz and p2p_add_cli_chan=1 (reverse)"""
  440. dev[0].request("SET p2p_add_cli_chan 1")
  441. dev[1].request("SET p2p_add_cli_chan 1")
  442. [i_res, r_res] = go_neg_pin_authorized(i_dev=dev[0], i_intent=14,
  443. r_dev=dev[1], r_intent=0,
  444. test_data=False)
  445. check_grpform_results(i_res, r_res)
  446. if int(i_res['freq']) > 4000:
  447. raise Exception("Unexpected channel - did not follow world roaming rules")
  448. remove_group(dev[0], dev[1])
  449. def test_grpform_no_5ghz_add_cli3(dev):
  450. """P2P group formation with passive scan 5 GHz and p2p_add_cli_chan=1 (intent 15)"""
  451. dev[0].request("SET p2p_add_cli_chan 1")
  452. dev[1].request("SET p2p_add_cli_chan 1")
  453. [i_res, r_res] = go_neg_pin_authorized(i_dev=dev[0], i_intent=0,
  454. r_dev=dev[1], r_intent=15,
  455. test_data=False)
  456. check_grpform_results(i_res, r_res)
  457. if int(i_res['freq']) > 4000:
  458. raise Exception("Unexpected channel - did not follow world roaming rules")
  459. remove_group(dev[0], dev[1])
  460. def test_grpform_no_5ghz_add_cli4(dev):
  461. """P2P group formation with passive scan 5 GHz and p2p_add_cli_chan=1 (reverse; intent 15)"""
  462. dev[0].request("SET p2p_add_cli_chan 1")
  463. dev[1].request("SET p2p_add_cli_chan 1")
  464. [i_res, r_res] = go_neg_pin_authorized(i_dev=dev[0], i_intent=15,
  465. r_dev=dev[1], r_intent=0,
  466. test_data=False)
  467. check_grpform_results(i_res, r_res)
  468. if int(i_res['freq']) > 4000:
  469. raise Exception("Unexpected channel - did not follow world roaming rules")
  470. remove_group(dev[0], dev[1])
  471. def test_grpform_incorrect_pin(dev):
  472. """P2P GO Negotiation with incorrect PIN"""
  473. dev[1].p2p_listen()
  474. addr1 = dev[1].p2p_dev_addr()
  475. if not dev[0].discover_peer(addr1):
  476. raise Exception("Peer not found")
  477. res = dev[1].request("P2P_CONNECT " + dev[0].p2p_dev_addr() + " pin auth go_intent=0")
  478. if "FAIL" in res:
  479. raise Exception("P2P_CONNECT failed to generate PIN")
  480. logger.info("PIN from P2P_CONNECT: " + res)
  481. dev[0].request("P2P_CONNECT " + addr1 + " 00000000 enter go_intent=15")
  482. ev = dev[0].wait_global_event(["P2P-GO-NEG-SUCCESS"], timeout=15)
  483. if ev is None:
  484. raise Exception("GO Negotiation did not complete successfully(0)")
  485. ev = dev[1].wait_global_event(["P2P-GO-NEG-SUCCESS"], timeout=15)
  486. if ev is None:
  487. raise Exception("GO Negotiation did not complete successfully(1)")
  488. ev = dev[1].wait_event(["WPS-FAIL"], timeout=15)
  489. if ev is None:
  490. raise Exception("WPS failure not reported(1)")
  491. if "msg=8 config_error=18" not in ev:
  492. raise Exception("Unexpected WPS failure(1): " + ev)
  493. ev = dev[0].wait_event(["WPS-FAIL"], timeout=15)
  494. if ev is None:
  495. raise Exception("WPS failure not reported")
  496. if "msg=8 config_error=18" not in ev:
  497. raise Exception("Unexpected WPS failure: " + ev)
  498. ev = dev[1].wait_event(["P2P-GROUP-FORMATION-FAILURE"], timeout=10)
  499. if ev is None:
  500. raise Exception("Group formation failure timed out")
  501. ev = dev[0].wait_event(["P2P-GROUP-FORMATION-FAILURE"], timeout=5)
  502. if ev is None:
  503. raise Exception("Group formation failure timed out")
  504. def test_grpform_reject(dev):
  505. """User rejecting group formation attempt by a P2P peer"""
  506. addr0 = dev[0].p2p_dev_addr()
  507. dev[0].p2p_listen()
  508. dev[1].p2p_go_neg_init(addr0, None, "pbc")
  509. ev = dev[0].wait_global_event(["P2P-GO-NEG-REQUEST"], timeout=15)
  510. if ev is None:
  511. raise Exception("GO Negotiation timed out")
  512. if "OK" in dev[0].global_request("P2P_REJECT foo"):
  513. raise Exception("Invalid P2P_REJECT accepted")
  514. if "FAIL" in dev[0].global_request("P2P_REJECT " + ev.split(' ')[1]):
  515. raise Exception("P2P_REJECT failed")
  516. dev[1].request("P2P_STOP_FIND")
  517. dev[1].p2p_go_neg_init(addr0, None, "pbc")
  518. ev = dev[1].wait_global_event(["GO-NEG-FAILURE"], timeout=10)
  519. if ev is None:
  520. raise Exception("Rejection not reported")
  521. if "status=11" not in ev:
  522. raise Exception("Unexpected status code in rejection")
  523. def test_grpform_pd_no_probe_resp(dev):
  524. """GO Negotiation after PD, but no Probe Response"""
  525. addr0 = dev[0].p2p_dev_addr()
  526. addr1 = dev[1].p2p_dev_addr()
  527. dev[0].p2p_listen()
  528. if not dev[1].discover_peer(addr0):
  529. raise Exception("Peer not found")
  530. dev[1].p2p_stop_find()
  531. dev[0].p2p_stop_find()
  532. peer = dev[0].get_peer(addr1)
  533. if peer['listen_freq'] == '0':
  534. raise Exception("Peer listen frequency not learned from Probe Request")
  535. time.sleep(0.3)
  536. dev[0].request("P2P_FLUSH")
  537. dev[0].p2p_listen()
  538. dev[1].global_request("P2P_PROV_DISC " + addr0 + " display")
  539. ev = dev[0].wait_global_event(["P2P-PROV-DISC-SHOW-PIN"], timeout=5)
  540. if ev is None:
  541. raise Exception("PD Request timed out")
  542. ev = dev[1].wait_global_event(["P2P-PROV-DISC-ENTER-PIN"], timeout=5)
  543. if ev is None:
  544. raise Exception("PD Response timed out")
  545. peer = dev[0].get_peer(addr1)
  546. if peer['listen_freq'] != '0':
  547. raise Exception("Peer listen frequency learned unexpectedly from PD Request")
  548. pin = dev[0].wps_read_pin()
  549. if "FAIL" in dev[1].request("P2P_CONNECT " + addr0 + " " + pin + " enter"):
  550. raise Exception("P2P_CONNECT on initiator failed")
  551. ev = dev[0].wait_global_event(["P2P-GO-NEG-REQUEST"], timeout=5)
  552. if ev is None:
  553. raise Exception("GO Negotiation start timed out")
  554. peer = dev[0].get_peer(addr1)
  555. if peer['listen_freq'] == '0':
  556. raise Exception("Peer listen frequency not learned from PD followed by GO Neg Req")
  557. if "FAIL" in dev[0].request("P2P_CONNECT " + addr1 + " " + pin + " display"):
  558. raise Exception("P2P_CONNECT on responder failed")
  559. ev = dev[0].wait_global_event(["P2P-GROUP-STARTED"], timeout=15)
  560. if ev is None:
  561. raise Exception("Group formation timed out")
  562. ev = dev[1].wait_global_event(["P2P-GROUP-STARTED"], timeout=15)
  563. if ev is None:
  564. raise Exception("Group formation timed out")
  565. def test_go_neg_two_peers(dev):
  566. """P2P GO Negotiation rejected due to already started negotiation with another peer"""
  567. addr0 = dev[0].p2p_dev_addr()
  568. addr1 = dev[1].p2p_dev_addr()
  569. addr2 = dev[2].p2p_dev_addr()
  570. dev[1].p2p_listen()
  571. dev[2].p2p_listen()
  572. if not dev[0].discover_peer(addr1):
  573. raise Exception("Could not discover peer")
  574. if not dev[0].discover_peer(addr2):
  575. raise Exception("Could not discover peer")
  576. if "OK" not in dev[0].request("P2P_CONNECT " + addr2 + " pbc auth"):
  577. raise Exception("Failed to authorize GO Neg")
  578. dev[0].p2p_listen()
  579. if not dev[2].discover_peer(addr0):
  580. raise Exception("Could not discover peer")
  581. if "OK" not in dev[0].request("P2P_CONNECT " + addr1 + " pbc"):
  582. raise Exception("Failed to initiate GO Neg")
  583. ev = dev[1].wait_global_event(["P2P-GO-NEG-REQUEST"], timeout=5)
  584. if ev is None:
  585. raise Exception("timeout on GO Neg RX event")
  586. dev[2].request("P2P_CONNECT " + addr0 + " pbc")
  587. ev = dev[2].wait_global_event(["GO-NEG-FAILURE"], timeout=10)
  588. if ev is None:
  589. raise Exception("Rejection not reported")
  590. if "status=5" not in ev:
  591. raise Exception("Unexpected status code in rejection: " + ev)
  592. def clear_pbc_overlap(dev, ifname):
  593. hapd_global = hostapd.HostapdGlobal()
  594. hapd_global.remove(ifname)
  595. dev[0].request("P2P_CANCEL")
  596. dev[1].request("P2P_CANCEL")
  597. dev[0].p2p_stop_find()
  598. dev[1].p2p_stop_find()
  599. dev[0].dump_monitor()
  600. dev[1].dump_monitor()
  601. time.sleep(0.1)
  602. dev[0].flush_scan_cache()
  603. dev[1].flush_scan_cache()
  604. time.sleep(0.1)
  605. def test_grpform_pbc_overlap(dev, apdev):
  606. """P2P group formation during PBC overlap"""
  607. params = { "ssid": "wps", "eap_server": "1", "wps_state": "1" }
  608. hapd = hostapd.add_ap(apdev[0]['ifname'], params)
  609. hapd.request("WPS_PBC")
  610. time.sleep(0.1)
  611. # Since P2P Client scan case is now optimzied to use a specific SSID, the
  612. # WPS AP will not reply to that and the scan after GO Negotiation can quite
  613. # likely miss the AP due to dwell time being short enoguh to miss the Beacon
  614. # frame. This has made the test case somewhat pointless, but keep it here
  615. # for now with an additional scan to confirm that PBC detection works if
  616. # there is a BSS entry for a overlapping AP.
  617. for i in range(0, 5):
  618. dev[0].scan(freq="2412")
  619. if dev[0].get_bss(apdev[0]['bssid']) is not None:
  620. break
  621. addr0 = dev[0].p2p_dev_addr()
  622. addr1 = dev[1].p2p_dev_addr()
  623. dev[0].p2p_listen()
  624. if not dev[1].discover_peer(addr0):
  625. raise Exception("Could not discover peer")
  626. dev[1].p2p_listen()
  627. if not dev[0].discover_peer(addr1):
  628. raise Exception("Could not discover peer")
  629. dev[0].p2p_listen()
  630. if "OK" not in dev[0].request("P2P_CONNECT " + addr1 + " pbc auth go_intent=0"):
  631. raise Exception("Failed to authorize GO Neg")
  632. if "OK" not in dev[1].request("P2P_CONNECT " + addr0 + " pbc go_intent=15 freq=2412"):
  633. raise Exception("Failed to initiate GO Neg")
  634. ev = dev[0].wait_global_event(["WPS-OVERLAP-DETECTED"], timeout=15)
  635. if ev is None:
  636. raise Exception("PBC overlap not reported")
  637. clear_pbc_overlap(dev, apdev[0]['ifname'])
  638. def test_grpform_pbc_overlap_group_iface(dev, apdev):
  639. """P2P group formation during PBC overlap using group interfaces"""
  640. # Note: Need to include P2P IE from the AP to get the P2P interface BSS
  641. # update use this information.
  642. params = { "ssid": "wps", "eap_server": "1", "wps_state": "1",
  643. "beacon_int": "15", 'manage_p2p': '1' }
  644. hapd = hostapd.add_ap(apdev[0]['ifname'], params)
  645. hapd.request("WPS_PBC")
  646. dev[0].request("SET p2p_no_group_iface 0")
  647. dev[1].request("SET p2p_no_group_iface 0")
  648. addr0 = dev[0].p2p_dev_addr()
  649. addr1 = dev[1].p2p_dev_addr()
  650. dev[0].p2p_listen()
  651. if not dev[1].discover_peer(addr0):
  652. raise Exception("Could not discover peer")
  653. dev[1].p2p_listen()
  654. if not dev[0].discover_peer(addr1):
  655. raise Exception("Could not discover peer")
  656. dev[0].p2p_stop_find()
  657. dev[0].scan(freq="2412")
  658. dev[0].p2p_listen()
  659. if "OK" not in dev[0].request("P2P_CONNECT " + addr1 + " pbc auth go_intent=0"):
  660. raise Exception("Failed to authorize GO Neg")
  661. if "OK" not in dev[1].request("P2P_CONNECT " + addr0 + " pbc go_intent=15 freq=2412"):
  662. raise Exception("Failed to initiate GO Neg")
  663. ev = dev[0].wait_global_event(["WPS-OVERLAP-DETECTED",
  664. "P2P-GROUP-FORMATION-SUCCESS"], timeout=15)
  665. if ev is None or "WPS-OVERLAP-DETECTED" not in ev:
  666. # Do not report this as failure since the P2P group formation case
  667. # using a separate group interface has limited chances of "seeing" the
  668. # overlapping AP due to a per-SSID scan and no prior scan operations on
  669. # the group interface.
  670. logger.info("PBC overlap not reported")
  671. clear_pbc_overlap(dev, apdev[0]['ifname'])
  672. def test_grpform_goneg_fail_with_group_iface(dev):
  673. """P2P group formation fails while using group interface"""
  674. dev[0].request("SET p2p_no_group_iface 0")
  675. dev[1].p2p_listen()
  676. peer = dev[1].p2p_dev_addr()
  677. if not dev[0].discover_peer(peer):
  678. raise Exception("Peer " + peer + " not found")
  679. if "OK" not in dev[1].request("P2P_REJECT " + dev[0].p2p_dev_addr()):
  680. raise Exception("P2P_REJECT failed")
  681. if "OK" not in dev[0].request("P2P_CONNECT " + peer + " pbc"):
  682. raise Exception("P2P_CONNECT failed")
  683. ev = dev[0].wait_global_event(["P2P-GO-NEG-FAILURE"], timeout=10)
  684. if ev is None:
  685. raise Exception("GO Negotiation failure timed out")
  686. def test_grpform_cred_ready_timeout(dev, apdev, params):
  687. """P2P GO Negotiation wait for credentials to become ready [long]"""
  688. if not params['long']:
  689. raise HwsimSkip("Skip test case with long duration due to --long not specified")
  690. dev[1].p2p_listen()
  691. addr1 = dev[1].p2p_dev_addr()
  692. if not dev[0].discover_peer(addr1):
  693. raise Exception("Peer " + addr1 + " not found")
  694. if not dev[2].discover_peer(addr1):
  695. raise Exception("Peer " + addr1 + " not found(2)")
  696. start = os.times()[4]
  697. cmd = "P2P_CONNECT " + addr1 + " 12345670 display"
  698. if "OK" not in dev[0].global_request(cmd):
  699. raise Exception("Failed to initiate GO Neg")
  700. if "OK" not in dev[2].global_request(cmd):
  701. raise Exception("Failed to initiate GO Neg(2)")
  702. # First, check with p2p_find
  703. ev = dev[2].wait_global_event(["P2P-GO-NEG-FAILURE"], timeout=30)
  704. if ev is not None:
  705. raise Exception("Too early GO Negotiation timeout reported(2)")
  706. dev[2].dump_monitor()
  707. logger.info("Starting p2p_find to change state")
  708. dev[2].p2p_find()
  709. ev = dev[2].wait_global_event(["P2P-GO-NEG-FAILURE"], timeout=100)
  710. if ev is None:
  711. raise Exception("GO Negotiation failure timed out(2)")
  712. dev[2].dump_monitor()
  713. end = os.times()[4]
  714. logger.info("GO Negotiation wait time: {} seconds(2)".format(end - start))
  715. if end - start < 120:
  716. raise Exception("Too short GO Negotiation wait time(2): {}".format(end - start))
  717. wpas = WpaSupplicant(global_iface='/tmp/wpas-wlan5')
  718. wpas.interface_add("wlan5")
  719. wpas.p2p_listen()
  720. ev = dev[2].wait_global_event(["P2P-DEVICE-FOUND"], timeout=10)
  721. if ev is None:
  722. raise Exception("Did not discover new device after GO Negotiation failure")
  723. if wpas.p2p_dev_addr() not in ev:
  724. raise Exception("Unexpected device found: " + ev)
  725. dev[2].p2p_stop_find()
  726. wpas.p2p_stop_find()
  727. # Finally, verify without p2p_find
  728. ev = dev[0].wait_global_event(["P2P-GO-NEG-FAILURE"], timeout=120)
  729. if ev is None:
  730. raise Exception("GO Negotiation failure timed out")
  731. end = os.times()[4]
  732. logger.info("GO Negotiation wait time: {} seconds".format(end - start))
  733. if end - start < 120:
  734. raise Exception("Too short GO Negotiation wait time: {}".format(end - start))
  735. def test_grpform_no_wsc_done(dev):
  736. """P2P group formation with WSC-Done not sent"""
  737. addr0 = dev[0].p2p_dev_addr()
  738. addr1 = dev[1].p2p_dev_addr()
  739. for i in range(0, 2):
  740. dev[0].request("SET ext_eapol_frame_io 1")
  741. dev[1].request("SET ext_eapol_frame_io 1")
  742. dev[0].p2p_listen()
  743. dev[1].p2p_go_neg_auth(addr0, "12345670", "display", 0)
  744. dev[1].p2p_listen()
  745. dev[0].p2p_go_neg_init(addr1, "12345670", "enter", timeout=20,
  746. go_intent=15, wait_group=False)
  747. mode = None
  748. while True:
  749. ev = dev[0].wait_event(["EAPOL-TX"], timeout=15)
  750. if ev is None:
  751. raise Exception("Timeout on EAPOL-TX from GO")
  752. if not mode:
  753. mode = dev[0].get_status_field("mode")
  754. res = dev[1].request("EAPOL_RX " + addr0 + " " + ev.split(' ')[2])
  755. if "OK" not in res:
  756. raise Exception("EAPOL_RX failed")
  757. ev = dev[1].wait_event(["EAPOL-TX"], timeout=15)
  758. if ev is None:
  759. raise Exception("Timeout on EAPOL-TX from P2P Client")
  760. msg = ev.split(' ')[2]
  761. if msg[46:56] == "102200010f":
  762. logger.info("Drop WSC_Done")
  763. dev[0].request("SET ext_eapol_frame_io 0")
  764. dev[1].request("SET ext_eapol_frame_io 0")
  765. # Fake EAP-Failure to complete session on the client
  766. id = msg[10:12]
  767. dev[1].request("EAPOL_RX " + addr0 + " 0300000404" + id + "0004")
  768. break
  769. res = dev[0].request("EAPOL_RX " + addr1 + " " + msg)
  770. if "OK" not in res:
  771. raise Exception("EAPOL_RX failed")
  772. ev = dev[0].wait_global_event(["P2P-GROUP-STARTED"], timeout=15)
  773. if ev is None:
  774. raise Exception("Group formation timed out on GO")
  775. ev = dev[1].wait_global_event(["P2P-GROUP-STARTED"], timeout=15)
  776. if ev is None:
  777. raise Exception("Group formation timed out on P2P Client")
  778. dev[0].remove_group()
  779. if mode != "P2P GO - group formation":
  780. raise Exception("Unexpected mode on GO during group formation: " + mode)
  781. def test_grpform_wait_peer(dev):
  782. """P2P group formation wait for peer to become ready"""
  783. addr0 = dev[0].p2p_dev_addr()
  784. addr1 = dev[1].p2p_dev_addr()
  785. dev[1].p2p_listen()
  786. if not dev[0].discover_peer(addr1):
  787. raise Exception("Peer " + addr1 + " not found")
  788. dev[0].request("SET extra_roc_dur 500")
  789. if "OK" not in dev[0].request("P2P_CONNECT " + addr1 + " 12345670 display go_intent=15"):
  790. raise Exception("Failed to initiate GO Neg")
  791. time.sleep(3)
  792. dev[1].request("P2P_CONNECT " + addr0 + " 12345670 enter go_intent=0")
  793. ev = dev[0].wait_global_event(["P2P-GROUP-STARTED"], timeout=15)
  794. if ev is None:
  795. raise Exception("Group formation timed out")
  796. dev[0].request("SET extra_roc_dur 0")
  797. ev = dev[1].wait_global_event(["P2P-GROUP-STARTED"], timeout=15)
  798. if ev is None:
  799. raise Exception("Group formation timed out")
  800. dev[0].remove_group()
  801. def test_invalid_p2p_connect_command(dev):
  802. """P2P_CONNECT error cases"""
  803. id = dev[0].add_network()
  804. for cmd in [ "foo",
  805. "00:11:22:33:44:55",
  806. "00:11:22:33:44:55 pbc persistent=123",
  807. "00:11:22:33:44:55 pbc persistent=%d" % id,
  808. "00:11:22:33:44:55 pbc go_intent=-1",
  809. "00:11:22:33:44:55 pbc go_intent=16",
  810. "00:11:22:33:44:55 pin",
  811. "00:11:22:33:44:55 pbc freq=0" ]:
  812. if "FAIL" not in dev[0].request("P2P_CONNECT " + cmd):
  813. raise Exception("Invalid P2P_CONNECT command accepted: " + cmd)
  814. if "FAIL-INVALID-PIN" not in dev[0].request("P2P_CONNECT 00:11:22:33:44:55 1234567"):
  815. raise Exception("Invalid PIN was not rejected")
  816. if "FAIL-CHANNEL-UNSUPPORTED" not in dev[0].request("P2P_CONNECT 00:11:22:33:44:55 pin freq=3000"):
  817. raise Exception("Unsupported channel not reported")
  818. def test_p2p_unauthorize(dev):
  819. """P2P_UNAUTHORIZE to unauthorize a peer"""
  820. if "FAIL" not in dev[0].request("P2P_UNAUTHORIZE foo"):
  821. raise Exception("Invalid P2P_UNAUTHORIZE accepted")
  822. if "FAIL" not in dev[0].request("P2P_UNAUTHORIZE 00:11:22:33:44:55"):
  823. raise Exception("P2P_UNAUTHORIZE for unknown peer accepted")
  824. addr0 = dev[0].p2p_dev_addr()
  825. addr1 = dev[1].p2p_dev_addr()
  826. dev[1].p2p_listen()
  827. pin = dev[0].wps_read_pin()
  828. dev[0].p2p_go_neg_auth(addr1, pin, "display")
  829. dev[0].p2p_listen()
  830. if "OK" not in dev[0].request("P2P_UNAUTHORIZE " + addr1):
  831. raise Exception("P2P_UNAUTHORIZE failed")
  832. dev[1].p2p_go_neg_init(addr0, pin, "keypad", timeout=0)
  833. ev = dev[0].wait_global_event(["P2P-GO-NEG-REQUEST"], timeout=10)
  834. if ev is None:
  835. raise Exception("No GO Negotiation Request RX reported")
  836. def test_grpform_pbc_multiple(dev):
  837. """P2P group formation using PBC multiple times in a row"""
  838. try:
  839. dev[1].request("SET passive_scan 1")
  840. for i in range(5):
  841. [i_res, r_res] = go_neg_pbc_authorized(i_dev=dev[0], i_intent=15,
  842. r_dev=dev[1], r_intent=0)
  843. remove_group(dev[0], dev[1])
  844. finally:
  845. dev[1].request("SET passive_scan 0")
  846. dev[1].flush_scan_cache()