test_p2p_grpform.py 45 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035
  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].global_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].global_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].global_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].global_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].global_request("SET p2p_no_group_iface 0")
  202. dev[1].global_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].global_request("SET p2p_no_group_iface 0")
  222. dev[1].global_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].global_request("SET p2p_no_group_iface 0")
  236. dev[1].global_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. addr0 = dev[0].p2p_dev_addr()
  258. try:
  259. if "FAIL" not in dev[0].global_request("P2P_EXT_LISTEN 100"):
  260. raise Exception("Invalid P2P_EXT_LISTEN accepted")
  261. if "OK" not in dev[0].global_request("P2P_EXT_LISTEN 300 1000"):
  262. raise Exception("Failed to set extended listen timing")
  263. if "OK" not in dev[1].global_request("P2P_EXT_LISTEN 200 40000"):
  264. raise Exception("Failed to set extended listen timing")
  265. [i_res, r_res] = go_neg_pbc(i_dev=dev[0], provdisc=True, r_dev=dev[1],
  266. r_listen=True, i_freq="2417", r_freq="2417",
  267. i_intent=1, r_intent=15)
  268. check_grpform_results(i_res, r_res)
  269. peer1 = dev[0].get_peer(dev[1].p2p_dev_addr())
  270. if peer1['ext_listen_interval'] != "40000":
  271. raise Exception("Extended listen interval not discovered correctly")
  272. if peer1['ext_listen_period'] != "200":
  273. raise Exception("Extended listen period not discovered correctly")
  274. peer0 = dev[1].get_peer(dev[0].p2p_dev_addr())
  275. if peer0['ext_listen_interval'] != "1000":
  276. raise Exception("Extended listen interval not discovered correctly")
  277. if peer0['ext_listen_period'] != "300":
  278. raise Exception("Extended listen period not discovered correctly")
  279. if not dev[2].discover_peer(addr0):
  280. raise Exception("Could not discover peer during ext listen")
  281. remove_group(dev[0], dev[1])
  282. finally:
  283. if "OK" not in dev[0].global_request("P2P_EXT_LISTEN"):
  284. raise Exception("Failed to clear extended listen timing")
  285. if "OK" not in dev[1].global_request("P2P_EXT_LISTEN"):
  286. raise Exception("Failed to clear extended listen timing")
  287. def test_grpform_ext_listen_oper(dev):
  288. """P2P extended listen timing operations"""
  289. try:
  290. _test_grpform_ext_listen_oper(dev)
  291. finally:
  292. dev[0].global_request("P2P_EXT_LISTEN")
  293. def _test_grpform_ext_listen_oper(dev):
  294. addr0 = dev[0].p2p_dev_addr()
  295. dev[0].global_request("SET p2p_no_group_iface 0")
  296. wpas = WpaSupplicant(global_iface='/tmp/wpas-wlan5')
  297. wpas.interface_add("wlan5")
  298. addr1 = wpas.p2p_dev_addr()
  299. wpas.request("P2P_SET listen_channel 1")
  300. wpas.global_request("SET p2p_no_group_iface 0")
  301. wpas.request("P2P_LISTEN")
  302. if not dev[0].discover_peer(addr1):
  303. raise Exception("Could not discover peer")
  304. dev[0].request("P2P_LISTEN")
  305. if not wpas.discover_peer(addr0):
  306. raise Exception("Could not discover peer (2)")
  307. dev[0].global_request("P2P_EXT_LISTEN 300 500")
  308. dev[0].global_request("P2P_CONNECT " + addr1 + " 12345670 display auth go_intent=0 freq=2417")
  309. wpas.global_request("P2P_CONNECT " + addr0 + " 12345670 enter go_intent=15 freq=2417")
  310. ev = dev[0].wait_global_event(["P2P-GO-NEG-SUCCESS"], timeout=15)
  311. if ev is None:
  312. raise Exception("GO Negotiation failed")
  313. ifaces = wpas.request("INTERFACES").splitlines()
  314. iface = ifaces[0] if "p2p-wlan" in ifaces[0] else ifaces[1]
  315. wpas.group_ifname = iface
  316. if "OK" not in wpas.group_request("STOP_AP"):
  317. raise Exception("STOP_AP failed")
  318. wpas.group_request("SET ext_mgmt_frame_handling 1")
  319. dev[1].p2p_find(social=True)
  320. time.sleep(1)
  321. if dev[1].peer_known(addr0):
  322. raise Exception("Unexpected peer discovery")
  323. ifaces = dev[0].request("INTERFACES").splitlines()
  324. iface = ifaces[0] if "p2p-wlan" in ifaces[0] else ifaces[1]
  325. if "OK" not in dev[0].global_request("P2P_GROUP_REMOVE " + iface):
  326. raise Exception("Failed to request group removal")
  327. wpas.remove_group()
  328. count = 0
  329. timeout = 15
  330. found = False
  331. while count < timeout * 4:
  332. time.sleep(0.25)
  333. count = count + 1
  334. if dev[1].peer_known(addr0):
  335. found = True
  336. break
  337. dev[1].p2p_stop_find()
  338. if not found:
  339. raise Exception("Could not discover peer that was supposed to use extended listen")
  340. def test_both_go_intent_15(dev):
  341. """P2P GO Negotiation with both devices using GO intent 15"""
  342. 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)
  343. def test_both_go_neg_display(dev):
  344. """P2P GO Negotiation with both devices trying to display PIN"""
  345. 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')
  346. def test_both_go_neg_enter(dev):
  347. """P2P GO Negotiation with both devices trying to enter PIN"""
  348. 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')
  349. def test_go_neg_pbc_vs_pin(dev):
  350. """P2P GO Negotiation with one device using PBC and the other PIN"""
  351. addr0 = dev[0].p2p_dev_addr()
  352. addr1 = dev[1].p2p_dev_addr()
  353. dev[1].p2p_listen()
  354. if not dev[0].discover_peer(addr1):
  355. raise Exception("Could not discover peer")
  356. dev[0].p2p_listen()
  357. if "OK" not in dev[0].request("P2P_CONNECT " + addr1 + " pbc auth"):
  358. raise Exception("Failed to authorize GO Neg")
  359. if not dev[1].discover_peer(addr0):
  360. raise Exception("Could not discover peer")
  361. if "OK" not in dev[1].request("P2P_CONNECT " + addr0 + " 12345670 display"):
  362. raise Exception("Failed to initiate GO Neg")
  363. ev = dev[1].wait_global_event(["P2P-GO-NEG-FAILURE"], timeout=10)
  364. if ev is None:
  365. raise Exception("GO Negotiation failure timed out")
  366. if "status=10" not in ev:
  367. raise Exception("Unexpected failure reason: " + ev)
  368. def test_go_neg_pin_vs_pbc(dev):
  369. """P2P GO Negotiation with one device using PIN and the other PBC"""
  370. addr0 = dev[0].p2p_dev_addr()
  371. addr1 = dev[1].p2p_dev_addr()
  372. dev[1].p2p_listen()
  373. if not dev[0].discover_peer(addr1):
  374. raise Exception("Could not discover peer")
  375. dev[0].p2p_listen()
  376. if "OK" not in dev[0].request("P2P_CONNECT " + addr1 + " 12345670 display auth"):
  377. raise Exception("Failed to authorize GO Neg")
  378. if not dev[1].discover_peer(addr0):
  379. raise Exception("Could not discover peer")
  380. if "OK" not in dev[1].request("P2P_CONNECT " + addr0 + " pbc"):
  381. raise Exception("Failed to initiate GO Neg")
  382. ev = dev[1].wait_global_event(["P2P-GO-NEG-FAILURE"], timeout=10)
  383. if ev is None:
  384. raise Exception("GO Negotiation failure timed out")
  385. if "status=10" not in ev:
  386. raise Exception("Unexpected failure reason: " + ev)
  387. def test_grpform_per_sta_psk(dev):
  388. """P2P group formation with per-STA PSKs"""
  389. dev[0].global_request("P2P_SET per_sta_psk 1")
  390. [i_res, r_res] = go_neg_pin_authorized(i_dev=dev[0], i_intent=15, r_dev=dev[1], r_intent=0)
  391. check_grpform_results(i_res, r_res)
  392. pin = dev[2].wps_read_pin()
  393. dev[0].p2p_go_authorize_client(pin)
  394. c_res = dev[2].p2p_connect_group(dev[0].p2p_dev_addr(), pin, timeout=60)
  395. check_grpform_results(i_res, c_res)
  396. if r_res['psk'] == c_res['psk']:
  397. raise Exception("Same PSK assigned for both clients")
  398. hwsim_utils.test_connectivity_p2p(dev[1], dev[2])
  399. dev[0].remove_group()
  400. dev[1].wait_go_ending_session()
  401. dev[2].wait_go_ending_session()
  402. def test_grpform_per_sta_psk_wps(dev):
  403. """P2P group formation with per-STA PSKs with non-P2P WPS STA"""
  404. dev[0].global_request("P2P_SET per_sta_psk 1")
  405. [i_res, r_res] = go_neg_pin_authorized(i_dev=dev[0], i_intent=15, r_dev=dev[1], r_intent=0)
  406. check_grpform_results(i_res, r_res)
  407. dev[0].p2p_go_authorize_client_pbc()
  408. dev[2].request("WPS_PBC")
  409. dev[2].wait_connected(timeout=30)
  410. hwsim_utils.test_connectivity_p2p_sta(dev[1], dev[2])
  411. dev[0].remove_group()
  412. dev[2].request("DISCONNECT")
  413. dev[1].wait_go_ending_session()
  414. def test_grpform_force_chan_go(dev):
  415. """P2P group formation forced channel selection by GO"""
  416. [i_res, r_res] = go_neg_pin_authorized(i_dev=dev[0], i_intent=15,
  417. i_freq=2432,
  418. r_dev=dev[1], r_intent=0,
  419. test_data=False)
  420. check_grpform_results(i_res, r_res)
  421. if i_res['freq'] != "2432":
  422. raise Exception("Unexpected channel - did not follow GO's forced channel")
  423. remove_group(dev[0], dev[1])
  424. def test_grpform_force_chan_cli(dev):
  425. """P2P group formation forced channel selection by client"""
  426. [i_res, r_res] = go_neg_pin_authorized(i_dev=dev[0], i_intent=0,
  427. i_freq=2417,
  428. r_dev=dev[1], r_intent=15,
  429. test_data=False)
  430. check_grpform_results(i_res, r_res)
  431. if i_res['freq'] != "2417":
  432. raise Exception("Unexpected channel - did not follow GO's forced channel")
  433. remove_group(dev[0], dev[1])
  434. def test_grpform_force_chan_conflict(dev):
  435. """P2P group formation fails due to forced channel mismatch"""
  436. go_neg_pin_authorized(i_dev=dev[0], i_intent=0, i_freq=2422,
  437. r_dev=dev[1], r_intent=15, r_freq=2427,
  438. expect_failure=True, i_go_neg_status=7)
  439. def test_grpform_pref_chan_go(dev):
  440. """P2P group formation preferred channel selection by GO"""
  441. dev[0].request("SET p2p_pref_chan 81:7")
  442. [i_res, r_res] = go_neg_pin_authorized(i_dev=dev[0], i_intent=15,
  443. r_dev=dev[1], r_intent=0,
  444. test_data=False)
  445. check_grpform_results(i_res, r_res)
  446. if i_res['freq'] != "2442":
  447. raise Exception("Unexpected channel - did not follow GO's p2p_pref_chan")
  448. remove_group(dev[0], dev[1])
  449. def test_grpform_pref_chan_go_overridden(dev):
  450. """P2P group formation preferred channel selection by GO overridden by client"""
  451. dev[1].request("SET p2p_pref_chan 81:7")
  452. [i_res, r_res] = go_neg_pin_authorized(i_dev=dev[0], i_intent=0,
  453. i_freq=2422,
  454. r_dev=dev[1], r_intent=15,
  455. test_data=False)
  456. check_grpform_results(i_res, r_res)
  457. if i_res['freq'] != "2422":
  458. raise Exception("Unexpected channel - did not follow client's forced channel")
  459. remove_group(dev[0], dev[1])
  460. def test_grpform_no_go_freq_forcing_chan(dev):
  461. """P2P group formation with no-GO freq forcing channel"""
  462. dev[1].request("SET p2p_no_go_freq 100-200,300,4000-6000")
  463. [i_res, r_res] = go_neg_pin_authorized(i_dev=dev[0], i_intent=0,
  464. r_dev=dev[1], r_intent=15,
  465. test_data=False)
  466. check_grpform_results(i_res, r_res)
  467. if int(i_res['freq']) > 4000:
  468. raise Exception("Unexpected channel - did not follow no-GO freq")
  469. remove_group(dev[0], dev[1])
  470. def test_grpform_no_go_freq_conflict(dev):
  471. """P2P group formation fails due to no-GO range forced by client"""
  472. dev[1].request("SET p2p_no_go_freq 2000-3000")
  473. go_neg_pin_authorized(i_dev=dev[0], i_intent=0, i_freq=2422,
  474. r_dev=dev[1], r_intent=15,
  475. expect_failure=True, i_go_neg_status=7)
  476. def test_grpform_no_5ghz_world_roaming(dev):
  477. """P2P group formation with world roaming regulatory"""
  478. [i_res, r_res] = go_neg_pin_authorized(i_dev=dev[0], i_intent=0,
  479. r_dev=dev[1], r_intent=15,
  480. test_data=False)
  481. check_grpform_results(i_res, r_res)
  482. if int(i_res['freq']) > 4000:
  483. raise Exception("Unexpected channel - did not follow world roaming rules")
  484. remove_group(dev[0], dev[1])
  485. def test_grpform_no_5ghz_add_cli(dev):
  486. """P2P group formation with passive scan 5 GHz and p2p_add_cli_chan=1"""
  487. dev[0].request("SET p2p_add_cli_chan 1")
  488. dev[1].request("SET p2p_add_cli_chan 1")
  489. [i_res, r_res] = go_neg_pin_authorized(i_dev=dev[0], i_intent=0,
  490. r_dev=dev[1], r_intent=14,
  491. test_data=False)
  492. check_grpform_results(i_res, r_res)
  493. if int(i_res['freq']) > 4000:
  494. raise Exception("Unexpected channel - did not follow world roaming rules")
  495. remove_group(dev[0], dev[1])
  496. def test_grpform_no_5ghz_add_cli2(dev):
  497. """P2P group formation with passive scan 5 GHz and p2p_add_cli_chan=1 (reverse)"""
  498. dev[0].request("SET p2p_add_cli_chan 1")
  499. dev[1].request("SET p2p_add_cli_chan 1")
  500. [i_res, r_res] = go_neg_pin_authorized(i_dev=dev[0], i_intent=14,
  501. r_dev=dev[1], r_intent=0,
  502. test_data=False)
  503. check_grpform_results(i_res, r_res)
  504. if int(i_res['freq']) > 4000:
  505. raise Exception("Unexpected channel - did not follow world roaming rules")
  506. remove_group(dev[0], dev[1])
  507. def test_grpform_no_5ghz_add_cli3(dev):
  508. """P2P group formation with passive scan 5 GHz and p2p_add_cli_chan=1 (intent 15)"""
  509. dev[0].request("SET p2p_add_cli_chan 1")
  510. dev[1].request("SET p2p_add_cli_chan 1")
  511. [i_res, r_res] = go_neg_pin_authorized(i_dev=dev[0], i_intent=0,
  512. r_dev=dev[1], r_intent=15,
  513. test_data=False)
  514. check_grpform_results(i_res, r_res)
  515. if int(i_res['freq']) > 4000:
  516. raise Exception("Unexpected channel - did not follow world roaming rules")
  517. remove_group(dev[0], dev[1])
  518. def test_grpform_no_5ghz_add_cli4(dev):
  519. """P2P group formation with passive scan 5 GHz and p2p_add_cli_chan=1 (reverse; intent 15)"""
  520. dev[0].request("SET p2p_add_cli_chan 1")
  521. dev[1].request("SET p2p_add_cli_chan 1")
  522. [i_res, r_res] = go_neg_pin_authorized(i_dev=dev[0], i_intent=15,
  523. r_dev=dev[1], r_intent=0,
  524. test_data=False)
  525. check_grpform_results(i_res, r_res)
  526. if int(i_res['freq']) > 4000:
  527. raise Exception("Unexpected channel - did not follow world roaming rules")
  528. remove_group(dev[0], dev[1])
  529. def test_grpform_incorrect_pin(dev):
  530. """P2P GO Negotiation with incorrect PIN"""
  531. dev[1].p2p_listen()
  532. addr1 = dev[1].p2p_dev_addr()
  533. if not dev[0].discover_peer(addr1):
  534. raise Exception("Peer not found")
  535. res = dev[1].global_request("P2P_CONNECT " + dev[0].p2p_dev_addr() + " pin auth go_intent=0")
  536. if "FAIL" in res:
  537. raise Exception("P2P_CONNECT failed to generate PIN")
  538. logger.info("PIN from P2P_CONNECT: " + res)
  539. dev[0].global_request("P2P_CONNECT " + addr1 + " 00000000 enter go_intent=15")
  540. ev = dev[0].wait_global_event(["P2P-GO-NEG-SUCCESS"], timeout=15)
  541. if ev is None:
  542. raise Exception("GO Negotiation did not complete successfully(0)")
  543. ev = dev[1].wait_global_event(["P2P-GO-NEG-SUCCESS"], timeout=15)
  544. if ev is None:
  545. raise Exception("GO Negotiation did not complete successfully(1)")
  546. ev = dev[1].wait_global_event(["WPS-FAIL"], timeout=15)
  547. if ev is None:
  548. raise Exception("WPS failure not reported(1)")
  549. if "msg=8 config_error=18" not in ev:
  550. raise Exception("Unexpected WPS failure(1): " + ev)
  551. ev = dev[0].wait_global_event(["WPS-FAIL"], timeout=15)
  552. if ev is None:
  553. raise Exception("WPS failure not reported")
  554. if "msg=8 config_error=18" not in ev:
  555. raise Exception("Unexpected WPS failure: " + ev)
  556. ev = dev[1].wait_global_event(["P2P-GROUP-FORMATION-FAILURE"], timeout=10)
  557. if ev is None:
  558. raise Exception("Group formation failure timed out")
  559. ev = dev[0].wait_global_event(["P2P-GROUP-FORMATION-FAILURE"], timeout=5)
  560. if ev is None:
  561. raise Exception("Group formation failure timed out")
  562. def test_grpform_reject(dev):
  563. """User rejecting group formation attempt by a P2P peer"""
  564. addr0 = dev[0].p2p_dev_addr()
  565. dev[0].p2p_listen()
  566. dev[1].p2p_go_neg_init(addr0, None, "pbc")
  567. ev = dev[0].wait_global_event(["P2P-GO-NEG-REQUEST"], timeout=15)
  568. if ev is None:
  569. raise Exception("GO Negotiation timed out")
  570. if "OK" in dev[0].global_request("P2P_REJECT foo"):
  571. raise Exception("Invalid P2P_REJECT accepted")
  572. if "FAIL" in dev[0].global_request("P2P_REJECT " + ev.split(' ')[1]):
  573. raise Exception("P2P_REJECT failed")
  574. dev[1].request("P2P_STOP_FIND")
  575. dev[1].p2p_go_neg_init(addr0, None, "pbc")
  576. ev = dev[1].wait_global_event(["GO-NEG-FAILURE"], timeout=10)
  577. if ev is None:
  578. raise Exception("Rejection not reported")
  579. if "status=11" not in ev:
  580. raise Exception("Unexpected status code in rejection")
  581. def test_grpform_pd_no_probe_resp(dev):
  582. """GO Negotiation after PD, but no Probe Response"""
  583. addr0 = dev[0].p2p_dev_addr()
  584. addr1 = dev[1].p2p_dev_addr()
  585. dev[0].p2p_listen()
  586. if not dev[1].discover_peer(addr0):
  587. raise Exception("Peer not found")
  588. dev[1].p2p_stop_find()
  589. dev[0].p2p_stop_find()
  590. peer = dev[0].get_peer(addr1)
  591. if peer['listen_freq'] == '0':
  592. raise Exception("Peer listen frequency not learned from Probe Request")
  593. time.sleep(0.3)
  594. dev[0].request("P2P_FLUSH")
  595. dev[0].p2p_listen()
  596. dev[1].global_request("P2P_PROV_DISC " + addr0 + " display")
  597. ev = dev[0].wait_global_event(["P2P-PROV-DISC-SHOW-PIN"], timeout=5)
  598. if ev is None:
  599. raise Exception("PD Request timed out")
  600. ev = dev[1].wait_global_event(["P2P-PROV-DISC-ENTER-PIN"], timeout=5)
  601. if ev is None:
  602. raise Exception("PD Response timed out")
  603. peer = dev[0].get_peer(addr1)
  604. if peer['listen_freq'] != '0':
  605. raise Exception("Peer listen frequency learned unexpectedly from PD Request")
  606. pin = dev[0].wps_read_pin()
  607. if "FAIL" in dev[1].global_request("P2P_CONNECT " + addr0 + " " + pin + " enter"):
  608. raise Exception("P2P_CONNECT on initiator failed")
  609. ev = dev[0].wait_global_event(["P2P-GO-NEG-REQUEST"], timeout=5)
  610. if ev is None:
  611. raise Exception("GO Negotiation start timed out")
  612. peer = dev[0].get_peer(addr1)
  613. if peer['listen_freq'] == '0':
  614. raise Exception("Peer listen frequency not learned from PD followed by GO Neg Req")
  615. if "FAIL" in dev[0].global_request("P2P_CONNECT " + addr1 + " " + pin + " display"):
  616. raise Exception("P2P_CONNECT on responder failed")
  617. ev = dev[0].wait_global_event(["P2P-GROUP-STARTED"], timeout=15)
  618. if ev is None:
  619. raise Exception("Group formation timed out")
  620. ev = dev[1].wait_global_event(["P2P-GROUP-STARTED"], timeout=15)
  621. if ev is None:
  622. raise Exception("Group formation timed out")
  623. def test_go_neg_two_peers(dev):
  624. """P2P GO Negotiation rejected due to already started negotiation with another peer"""
  625. addr0 = dev[0].p2p_dev_addr()
  626. addr1 = dev[1].p2p_dev_addr()
  627. addr2 = dev[2].p2p_dev_addr()
  628. dev[1].p2p_listen()
  629. dev[2].p2p_listen()
  630. if not dev[0].discover_peer(addr1):
  631. raise Exception("Could not discover peer")
  632. if not dev[0].discover_peer(addr2):
  633. raise Exception("Could not discover peer")
  634. if "OK" not in dev[0].request("P2P_CONNECT " + addr2 + " pbc auth"):
  635. raise Exception("Failed to authorize GO Neg")
  636. dev[0].p2p_listen()
  637. if not dev[2].discover_peer(addr0):
  638. raise Exception("Could not discover peer")
  639. if "OK" not in dev[0].request("P2P_CONNECT " + addr1 + " pbc"):
  640. raise Exception("Failed to initiate GO Neg")
  641. ev = dev[1].wait_global_event(["P2P-GO-NEG-REQUEST"], timeout=5)
  642. if ev is None:
  643. raise Exception("timeout on GO Neg RX event")
  644. dev[2].request("P2P_CONNECT " + addr0 + " pbc")
  645. ev = dev[2].wait_global_event(["GO-NEG-FAILURE"], timeout=10)
  646. if ev is None:
  647. raise Exception("Rejection not reported")
  648. if "status=5" not in ev:
  649. raise Exception("Unexpected status code in rejection: " + ev)
  650. def clear_pbc_overlap(dev, ifname):
  651. hapd_global = hostapd.HostapdGlobal()
  652. hapd_global.remove(ifname)
  653. dev[0].request("P2P_CANCEL")
  654. dev[1].request("P2P_CANCEL")
  655. dev[0].p2p_stop_find()
  656. dev[1].p2p_stop_find()
  657. dev[0].dump_monitor()
  658. dev[1].dump_monitor()
  659. time.sleep(0.1)
  660. dev[0].flush_scan_cache()
  661. dev[1].flush_scan_cache()
  662. time.sleep(0.1)
  663. def test_grpform_pbc_overlap(dev, apdev):
  664. """P2P group formation during PBC overlap"""
  665. params = { "ssid": "wps", "eap_server": "1", "wps_state": "1" }
  666. hapd = hostapd.add_ap(apdev[0]['ifname'], params)
  667. hapd.request("WPS_PBC")
  668. time.sleep(0.1)
  669. # Since P2P Client scan case is now optimzied to use a specific SSID, the
  670. # WPS AP will not reply to that and the scan after GO Negotiation can quite
  671. # likely miss the AP due to dwell time being short enoguh to miss the Beacon
  672. # frame. This has made the test case somewhat pointless, but keep it here
  673. # for now with an additional scan to confirm that PBC detection works if
  674. # there is a BSS entry for a overlapping AP.
  675. for i in range(0, 5):
  676. dev[0].scan(freq="2412")
  677. if dev[0].get_bss(apdev[0]['bssid']) is not None:
  678. break
  679. addr0 = dev[0].p2p_dev_addr()
  680. addr1 = dev[1].p2p_dev_addr()
  681. dev[0].p2p_listen()
  682. if not dev[1].discover_peer(addr0):
  683. raise Exception("Could not discover peer")
  684. dev[1].p2p_listen()
  685. if not dev[0].discover_peer(addr1):
  686. raise Exception("Could not discover peer")
  687. dev[0].p2p_listen()
  688. if "OK" not in dev[0].global_request("P2P_CONNECT " + addr1 + " pbc auth go_intent=0"):
  689. raise Exception("Failed to authorize GO Neg")
  690. if "OK" not in dev[1].global_request("P2P_CONNECT " + addr0 + " pbc go_intent=15 freq=2412"):
  691. raise Exception("Failed to initiate GO Neg")
  692. ev = dev[0].wait_global_event(["WPS-OVERLAP-DETECTED"], timeout=15)
  693. if ev is None:
  694. raise Exception("PBC overlap not reported")
  695. clear_pbc_overlap(dev, apdev[0]['ifname'])
  696. def test_grpform_pbc_overlap_group_iface(dev, apdev):
  697. """P2P group formation during PBC overlap using group interfaces"""
  698. # Note: Need to include P2P IE from the AP to get the P2P interface BSS
  699. # update use this information.
  700. params = { "ssid": "wps", "eap_server": "1", "wps_state": "1",
  701. "beacon_int": "15", 'manage_p2p': '1' }
  702. hapd = hostapd.add_ap(apdev[0]['ifname'], params)
  703. hapd.request("WPS_PBC")
  704. dev[0].request("SET p2p_no_group_iface 0")
  705. dev[1].request("SET p2p_no_group_iface 0")
  706. addr0 = dev[0].p2p_dev_addr()
  707. addr1 = dev[1].p2p_dev_addr()
  708. dev[0].p2p_listen()
  709. if not dev[1].discover_peer(addr0):
  710. raise Exception("Could not discover peer")
  711. dev[1].p2p_listen()
  712. if not dev[0].discover_peer(addr1):
  713. raise Exception("Could not discover peer")
  714. dev[0].p2p_stop_find()
  715. dev[0].scan(freq="2412")
  716. dev[0].p2p_listen()
  717. if "OK" not in dev[0].global_request("P2P_CONNECT " + addr1 + " pbc auth go_intent=0"):
  718. raise Exception("Failed to authorize GO Neg")
  719. if "OK" not in dev[1].global_request("P2P_CONNECT " + addr0 + " pbc go_intent=15 freq=2412"):
  720. raise Exception("Failed to initiate GO Neg")
  721. ev = dev[0].wait_global_event(["WPS-OVERLAP-DETECTED",
  722. "P2P-GROUP-FORMATION-SUCCESS"], timeout=15)
  723. if ev is None or "WPS-OVERLAP-DETECTED" not in ev:
  724. # Do not report this as failure since the P2P group formation case
  725. # using a separate group interface has limited chances of "seeing" the
  726. # overlapping AP due to a per-SSID scan and no prior scan operations on
  727. # the group interface.
  728. logger.info("PBC overlap not reported")
  729. clear_pbc_overlap(dev, apdev[0]['ifname'])
  730. def test_grpform_goneg_fail_with_group_iface(dev):
  731. """P2P group formation fails while using group interface"""
  732. dev[0].request("SET p2p_no_group_iface 0")
  733. dev[1].p2p_listen()
  734. peer = dev[1].p2p_dev_addr()
  735. if not dev[0].discover_peer(peer):
  736. raise Exception("Peer " + peer + " not found")
  737. if "OK" not in dev[1].request("P2P_REJECT " + dev[0].p2p_dev_addr()):
  738. raise Exception("P2P_REJECT failed")
  739. if "OK" not in dev[0].request("P2P_CONNECT " + peer + " pbc"):
  740. raise Exception("P2P_CONNECT failed")
  741. ev = dev[0].wait_global_event(["P2P-GO-NEG-FAILURE"], timeout=10)
  742. if ev is None:
  743. raise Exception("GO Negotiation failure timed out")
  744. def test_grpform_cred_ready_timeout(dev, apdev, params):
  745. """P2P GO Negotiation wait for credentials to become ready [long]"""
  746. if not params['long']:
  747. raise HwsimSkip("Skip test case with long duration due to --long not specified")
  748. dev[1].p2p_listen()
  749. addr1 = dev[1].p2p_dev_addr()
  750. if not dev[0].discover_peer(addr1):
  751. raise Exception("Peer " + addr1 + " not found")
  752. if not dev[2].discover_peer(addr1):
  753. raise Exception("Peer " + addr1 + " not found(2)")
  754. start = os.times()[4]
  755. cmd = "P2P_CONNECT " + addr1 + " 12345670 display"
  756. if "OK" not in dev[0].global_request(cmd):
  757. raise Exception("Failed to initiate GO Neg")
  758. if "OK" not in dev[2].global_request(cmd):
  759. raise Exception("Failed to initiate GO Neg(2)")
  760. # First, check with p2p_find
  761. ev = dev[2].wait_global_event(["P2P-GO-NEG-FAILURE"], timeout=30)
  762. if ev is not None:
  763. raise Exception("Too early GO Negotiation timeout reported(2)")
  764. dev[2].dump_monitor()
  765. logger.info("Starting p2p_find to change state")
  766. dev[2].p2p_find()
  767. ev = dev[2].wait_global_event(["P2P-GO-NEG-FAILURE"], timeout=100)
  768. if ev is None:
  769. raise Exception("GO Negotiation failure timed out(2)")
  770. dev[2].dump_monitor()
  771. end = os.times()[4]
  772. logger.info("GO Negotiation wait time: {} seconds(2)".format(end - start))
  773. if end - start < 120:
  774. raise Exception("Too short GO Negotiation wait time(2): {}".format(end - start))
  775. wpas = WpaSupplicant(global_iface='/tmp/wpas-wlan5')
  776. wpas.interface_add("wlan5")
  777. wpas.p2p_listen()
  778. ev = dev[2].wait_global_event(["P2P-DEVICE-FOUND"], timeout=10)
  779. if ev is None:
  780. raise Exception("Did not discover new device after GO Negotiation failure")
  781. if wpas.p2p_dev_addr() not in ev:
  782. raise Exception("Unexpected device found: " + ev)
  783. dev[2].p2p_stop_find()
  784. wpas.p2p_stop_find()
  785. # Finally, verify without p2p_find
  786. ev = dev[0].wait_global_event(["P2P-GO-NEG-FAILURE"], timeout=120)
  787. if ev is None:
  788. raise Exception("GO Negotiation failure timed out")
  789. end = os.times()[4]
  790. logger.info("GO Negotiation wait time: {} seconds".format(end - start))
  791. if end - start < 120:
  792. raise Exception("Too short GO Negotiation wait time: {}".format(end - start))
  793. def test_grpform_no_wsc_done(dev):
  794. """P2P group formation with WSC-Done not sent"""
  795. addr0 = dev[0].p2p_dev_addr()
  796. addr1 = dev[1].p2p_dev_addr()
  797. for i in range(0, 2):
  798. dev[0].request("SET ext_eapol_frame_io 1")
  799. dev[1].request("SET ext_eapol_frame_io 1")
  800. dev[0].p2p_listen()
  801. dev[1].p2p_go_neg_auth(addr0, "12345670", "display", 0)
  802. dev[1].p2p_listen()
  803. dev[0].p2p_go_neg_init(addr1, "12345670", "enter", timeout=20,
  804. go_intent=15, wait_group=False)
  805. mode = None
  806. while True:
  807. ev = dev[0].wait_event(["EAPOL-TX"], timeout=15)
  808. if ev is None:
  809. raise Exception("Timeout on EAPOL-TX from GO")
  810. if not mode:
  811. mode = dev[0].get_status_field("mode")
  812. res = dev[1].request("EAPOL_RX " + addr0 + " " + ev.split(' ')[2])
  813. if "OK" not in res:
  814. raise Exception("EAPOL_RX failed")
  815. ev = dev[1].wait_event(["EAPOL-TX"], timeout=15)
  816. if ev is None:
  817. raise Exception("Timeout on EAPOL-TX from P2P Client")
  818. msg = ev.split(' ')[2]
  819. if msg[46:56] == "102200010f":
  820. logger.info("Drop WSC_Done")
  821. dev[0].request("SET ext_eapol_frame_io 0")
  822. dev[1].request("SET ext_eapol_frame_io 0")
  823. # Fake EAP-Failure to complete session on the client
  824. id = msg[10:12]
  825. dev[1].request("EAPOL_RX " + addr0 + " 0300000404" + id + "0004")
  826. break
  827. res = dev[0].request("EAPOL_RX " + addr1 + " " + msg)
  828. if "OK" not in res:
  829. raise Exception("EAPOL_RX failed")
  830. ev = dev[0].wait_global_event(["P2P-GROUP-STARTED"], timeout=15)
  831. if ev is None:
  832. raise Exception("Group formation timed out on GO")
  833. ev = dev[1].wait_global_event(["P2P-GROUP-STARTED"], timeout=15)
  834. if ev is None:
  835. raise Exception("Group formation timed out on P2P Client")
  836. dev[0].remove_group()
  837. dev[1].wait_go_ending_session()
  838. if mode != "P2P GO - group formation":
  839. raise Exception("Unexpected mode on GO during group formation: " + mode)
  840. def test_grpform_wait_peer(dev):
  841. """P2P group formation wait for peer to become ready"""
  842. addr0 = dev[0].p2p_dev_addr()
  843. addr1 = dev[1].p2p_dev_addr()
  844. dev[1].p2p_listen()
  845. if not dev[0].discover_peer(addr1):
  846. raise Exception("Peer " + addr1 + " not found")
  847. dev[0].request("SET extra_roc_dur 500")
  848. if "OK" not in dev[0].request("P2P_CONNECT " + addr1 + " 12345670 display go_intent=15"):
  849. raise Exception("Failed to initiate GO Neg")
  850. time.sleep(3)
  851. dev[1].request("P2P_CONNECT " + addr0 + " 12345670 enter go_intent=0")
  852. ev = dev[0].wait_global_event(["P2P-GROUP-STARTED"], timeout=15)
  853. if ev is None:
  854. raise Exception("Group formation timed out")
  855. dev[0].group_form_result(ev)
  856. dev[0].request("SET extra_roc_dur 0")
  857. ev = dev[1].wait_global_event(["P2P-GROUP-STARTED"], timeout=15)
  858. if ev is None:
  859. raise Exception("Group formation timed out")
  860. dev[0].remove_group()
  861. def test_invalid_p2p_connect_command(dev):
  862. """P2P_CONNECT error cases"""
  863. id = dev[0].add_network()
  864. for cmd in [ "foo",
  865. "00:11:22:33:44:55",
  866. "00:11:22:33:44:55 pbc persistent=123",
  867. "00:11:22:33:44:55 pbc persistent=%d" % id,
  868. "00:11:22:33:44:55 pbc go_intent=-1",
  869. "00:11:22:33:44:55 pbc go_intent=16",
  870. "00:11:22:33:44:55 pin",
  871. "00:11:22:33:44:55 pbc freq=0" ]:
  872. if "FAIL" not in dev[0].request("P2P_CONNECT " + cmd):
  873. raise Exception("Invalid P2P_CONNECT command accepted: " + cmd)
  874. if "FAIL-INVALID-PIN" not in dev[0].request("P2P_CONNECT 00:11:22:33:44:55 1234567"):
  875. raise Exception("Invalid PIN was not rejected")
  876. if "FAIL-CHANNEL-UNSUPPORTED" not in dev[0].request("P2P_CONNECT 00:11:22:33:44:55 pin freq=3000"):
  877. raise Exception("Unsupported channel not reported")
  878. def test_p2p_unauthorize(dev):
  879. """P2P_UNAUTHORIZE to unauthorize a peer"""
  880. if "FAIL" not in dev[0].request("P2P_UNAUTHORIZE foo"):
  881. raise Exception("Invalid P2P_UNAUTHORIZE accepted")
  882. if "FAIL" not in dev[0].request("P2P_UNAUTHORIZE 00:11:22:33:44:55"):
  883. raise Exception("P2P_UNAUTHORIZE for unknown peer accepted")
  884. addr0 = dev[0].p2p_dev_addr()
  885. addr1 = dev[1].p2p_dev_addr()
  886. dev[1].p2p_listen()
  887. pin = dev[0].wps_read_pin()
  888. dev[0].p2p_go_neg_auth(addr1, pin, "display")
  889. dev[0].p2p_listen()
  890. if "OK" not in dev[0].request("P2P_UNAUTHORIZE " + addr1):
  891. raise Exception("P2P_UNAUTHORIZE failed")
  892. dev[1].p2p_go_neg_init(addr0, pin, "keypad", timeout=0)
  893. ev = dev[0].wait_global_event(["P2P-GO-NEG-REQUEST"], timeout=10)
  894. if ev is None:
  895. raise Exception("No GO Negotiation Request RX reported")
  896. def test_grpform_pbc_multiple(dev):
  897. """P2P group formation using PBC multiple times in a row"""
  898. try:
  899. dev[1].request("SET passive_scan 1")
  900. for i in range(5):
  901. [i_res, r_res] = go_neg_pbc_authorized(i_dev=dev[0], i_intent=15,
  902. r_dev=dev[1], r_intent=0)
  903. remove_group(dev[0], dev[1])
  904. finally:
  905. dev[1].request("SET passive_scan 0")
  906. dev[1].flush_scan_cache()
  907. def test_grpform_not_ready(dev):
  908. """Not ready for GO Negotiation (listen)"""
  909. addr0 = dev[0].p2p_dev_addr()
  910. addr2 = dev[2].p2p_dev_addr()
  911. dev[0].p2p_listen()
  912. if not dev[1].discover_peer(addr0):
  913. raise Exception("Could not discover peer")
  914. dev[1].global_request("P2P_CONNECT " + addr0 + " pbc")
  915. ev = dev[0].wait_global_event(["P2P-GO-NEG-REQUEST"], timeout=5)
  916. if ev is None:
  917. raise Exception("No P2P-GO-NEG-REQUEST event")
  918. dev[0].dump_monitor()
  919. time.sleep(5)
  920. if not dev[2].discover_peer(addr0):
  921. raise Exception("Could not discover peer(2)")
  922. for i in range(3):
  923. dev[i].p2p_stop_find()
  924. def test_grpform_not_ready2(dev):
  925. """Not ready for GO Negotiation (search)"""
  926. addr0 = dev[0].p2p_dev_addr()
  927. addr2 = dev[2].p2p_dev_addr()
  928. dev[0].p2p_find(social=True)
  929. if not dev[1].discover_peer(addr0):
  930. raise Exception("Could not discover peer")
  931. dev[1].global_request("P2P_CONNECT " + addr0 + " pbc")
  932. ev = dev[0].wait_global_event(["P2P-GO-NEG-REQUEST"], timeout=5)
  933. if ev is None:
  934. raise Exception("No P2P-GO-NEG-REQUEST event")
  935. dev[0].dump_monitor()
  936. time.sleep(1)
  937. dev[2].p2p_listen()
  938. ev = dev[0].wait_global_event(["P2P-DEVICE-FOUND"], timeout=10)
  939. if ev is None:
  940. raise Exception("Peer not discovered after GO Neg Resp(status=1) TX")
  941. if addr2 not in ev:
  942. raise Exception("Unexpected peer discovered: " + ev)
  943. for i in range(3):
  944. dev[i].p2p_stop_find()