test_p2p_grpform.py 45 KB

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