test_p2p_grpform.py 46 KB

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