test_p2p_grpform.py 34 KB

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