test_p2p_grpform.py 29 KB

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