test_p2p_grpform.py 46 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079
  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. try:
  334. dev[1].request("SET p2p_no_go_freq 100-200,300,4000-6000")
  335. [i_res, r_res] = go_neg_pin_authorized(i_dev=dev[0], i_intent=0,
  336. r_dev=dev[1], r_intent=15,
  337. test_data=False)
  338. check_grpform_results(i_res, r_res)
  339. if int(i_res['freq']) > 4000:
  340. raise Exception("Unexpected channel - did not follow no-GO freq")
  341. remove_group(dev[0], dev[1])
  342. finally:
  343. dev[1].request("SET p2p_no_go_freq ")
  344. def test_grpform_no_go_freq_conflict(dev):
  345. """P2P group formation fails due to no-GO range forced by client"""
  346. try:
  347. dev[1].request("SET p2p_no_go_freq 2000-3000")
  348. go_neg_pin_authorized(i_dev=dev[0], i_intent=0, i_freq=2422,
  349. r_dev=dev[1], r_intent=15,
  350. expect_failure=True, i_go_neg_status=7)
  351. finally:
  352. dev[1].request("SET p2p_no_go_freq ")
  353. def test_grpform_no_5ghz_world_roaming(dev):
  354. """P2P group formation with world roaming regulatory"""
  355. [i_res, r_res] = go_neg_pin_authorized(i_dev=dev[0], i_intent=0,
  356. r_dev=dev[1], r_intent=15,
  357. test_data=False)
  358. check_grpform_results(i_res, r_res)
  359. if int(i_res['freq']) > 4000:
  360. raise Exception("Unexpected channel - did not follow world roaming rules")
  361. remove_group(dev[0], dev[1])
  362. def test_grpform_no_5ghz_add_cli(dev):
  363. """P2P group formation with passive scan 5 GHz and p2p_add_cli_chan=1"""
  364. dev[0].request("SET p2p_add_cli_chan 1")
  365. dev[1].request("SET p2p_add_cli_chan 1")
  366. [i_res, r_res] = go_neg_pin_authorized(i_dev=dev[0], i_intent=0,
  367. r_dev=dev[1], r_intent=14,
  368. test_data=False)
  369. check_grpform_results(i_res, r_res)
  370. if int(i_res['freq']) > 4000:
  371. raise Exception("Unexpected channel - did not follow world roaming rules")
  372. remove_group(dev[0], dev[1])
  373. def test_grpform_no_5ghz_add_cli2(dev):
  374. """P2P group formation with passive scan 5 GHz and p2p_add_cli_chan=1 (reverse)"""
  375. dev[0].request("SET p2p_add_cli_chan 1")
  376. dev[1].request("SET p2p_add_cli_chan 1")
  377. [i_res, r_res] = go_neg_pin_authorized(i_dev=dev[0], i_intent=14,
  378. r_dev=dev[1], r_intent=0,
  379. test_data=False)
  380. check_grpform_results(i_res, r_res)
  381. if int(i_res['freq']) > 4000:
  382. raise Exception("Unexpected channel - did not follow world roaming rules")
  383. remove_group(dev[0], dev[1])
  384. def test_grpform_no_5ghz_add_cli3(dev):
  385. """P2P group formation with passive scan 5 GHz and p2p_add_cli_chan=1 (intent 15)"""
  386. dev[0].request("SET p2p_add_cli_chan 1")
  387. dev[1].request("SET p2p_add_cli_chan 1")
  388. [i_res, r_res] = go_neg_pin_authorized(i_dev=dev[0], i_intent=0,
  389. r_dev=dev[1], r_intent=15,
  390. test_data=False)
  391. check_grpform_results(i_res, r_res)
  392. if int(i_res['freq']) > 4000:
  393. raise Exception("Unexpected channel - did not follow world roaming rules")
  394. remove_group(dev[0], dev[1])
  395. def test_grpform_no_5ghz_add_cli4(dev):
  396. """P2P group formation with passive scan 5 GHz and p2p_add_cli_chan=1 (reverse; intent 15)"""
  397. dev[0].request("SET p2p_add_cli_chan 1")
  398. dev[1].request("SET p2p_add_cli_chan 1")
  399. [i_res, r_res] = go_neg_pin_authorized(i_dev=dev[0], i_intent=15,
  400. r_dev=dev[1], r_intent=0,
  401. test_data=False)
  402. check_grpform_results(i_res, r_res)
  403. if int(i_res['freq']) > 4000:
  404. raise Exception("Unexpected channel - did not follow world roaming rules")
  405. remove_group(dev[0], dev[1])
  406. def test_grpform_incorrect_pin(dev):
  407. """P2P GO Negotiation with incorrect PIN"""
  408. dev[1].p2p_listen()
  409. addr1 = dev[1].p2p_dev_addr()
  410. if not dev[0].discover_peer(addr1):
  411. raise Exception("Peer not found")
  412. res = dev[1].global_request("P2P_CONNECT " + dev[0].p2p_dev_addr() + " pin auth go_intent=0")
  413. if "FAIL" in res:
  414. raise Exception("P2P_CONNECT failed to generate PIN")
  415. logger.info("PIN from P2P_CONNECT: " + res)
  416. dev[0].global_request("P2P_CONNECT " + addr1 + " 00000000 enter go_intent=15")
  417. ev = dev[0].wait_global_event(["P2P-GO-NEG-SUCCESS"], timeout=15)
  418. if ev is None:
  419. raise Exception("GO Negotiation did not complete successfully(0)")
  420. ev = dev[1].wait_global_event(["P2P-GO-NEG-SUCCESS"], timeout=15)
  421. if ev is None:
  422. raise Exception("GO Negotiation did not complete successfully(1)")
  423. ev = dev[1].wait_global_event(["WPS-FAIL"], timeout=15)
  424. if ev is None:
  425. raise Exception("WPS failure not reported(1)")
  426. if "msg=8 config_error=18" not in ev:
  427. raise Exception("Unexpected WPS failure(1): " + ev)
  428. ev = dev[0].wait_global_event(["WPS-FAIL"], timeout=15)
  429. if ev is None:
  430. raise Exception("WPS failure not reported")
  431. if "msg=8 config_error=18" not in ev:
  432. raise Exception("Unexpected WPS failure: " + ev)
  433. ev = dev[1].wait_global_event(["P2P-GROUP-FORMATION-FAILURE"], timeout=10)
  434. if ev is None:
  435. raise Exception("Group formation failure timed out")
  436. ev = dev[0].wait_global_event(["P2P-GROUP-FORMATION-FAILURE"], timeout=5)
  437. if ev is None:
  438. raise Exception("Group formation failure timed out")
  439. def test_grpform_reject(dev):
  440. """User rejecting group formation attempt by a P2P peer"""
  441. addr0 = dev[0].p2p_dev_addr()
  442. dev[0].p2p_listen()
  443. dev[1].p2p_go_neg_init(addr0, None, "pbc")
  444. ev = dev[0].wait_global_event(["P2P-GO-NEG-REQUEST"], timeout=15)
  445. if ev is None:
  446. raise Exception("GO Negotiation timed out")
  447. if "OK" in dev[0].global_request("P2P_REJECT foo"):
  448. raise Exception("Invalid P2P_REJECT accepted")
  449. if "FAIL" in dev[0].global_request("P2P_REJECT " + ev.split(' ')[1]):
  450. raise Exception("P2P_REJECT failed")
  451. dev[1].request("P2P_STOP_FIND")
  452. dev[1].p2p_go_neg_init(addr0, None, "pbc")
  453. ev = dev[1].wait_global_event(["GO-NEG-FAILURE"], timeout=10)
  454. if ev is None:
  455. raise Exception("Rejection not reported")
  456. if "status=11" not in ev:
  457. raise Exception("Unexpected status code in rejection")
  458. def test_grpform_pd_no_probe_resp(dev):
  459. """GO Negotiation after PD, but no Probe Response"""
  460. addr0 = dev[0].p2p_dev_addr()
  461. addr1 = dev[1].p2p_dev_addr()
  462. dev[0].p2p_listen()
  463. if not dev[1].discover_peer(addr0):
  464. raise Exception("Peer not found")
  465. dev[1].p2p_stop_find()
  466. dev[0].p2p_stop_find()
  467. peer = dev[0].get_peer(addr1)
  468. if peer['listen_freq'] == '0':
  469. raise Exception("Peer listen frequency not learned from Probe Request")
  470. time.sleep(0.3)
  471. dev[0].request("P2P_FLUSH")
  472. dev[0].p2p_listen()
  473. dev[1].global_request("P2P_PROV_DISC " + addr0 + " display")
  474. ev = dev[0].wait_global_event(["P2P-PROV-DISC-SHOW-PIN"], timeout=5)
  475. if ev is None:
  476. raise Exception("PD Request timed out")
  477. ev = dev[1].wait_global_event(["P2P-PROV-DISC-ENTER-PIN"], timeout=5)
  478. if ev is None:
  479. raise Exception("PD Response timed out")
  480. peer = dev[0].get_peer(addr1)
  481. if peer['listen_freq'] != '0':
  482. raise Exception("Peer listen frequency learned unexpectedly from PD Request")
  483. pin = dev[0].wps_read_pin()
  484. if "FAIL" in dev[1].global_request("P2P_CONNECT " + addr0 + " " + pin + " enter"):
  485. raise Exception("P2P_CONNECT on initiator failed")
  486. ev = dev[0].wait_global_event(["P2P-GO-NEG-REQUEST"], timeout=5)
  487. if ev is None:
  488. raise Exception("GO Negotiation start timed out")
  489. peer = dev[0].get_peer(addr1)
  490. if peer['listen_freq'] == '0':
  491. raise Exception("Peer listen frequency not learned from PD followed by GO Neg Req")
  492. if "FAIL" in dev[0].global_request("P2P_CONNECT " + addr1 + " " + pin + " display"):
  493. raise Exception("P2P_CONNECT on responder failed")
  494. ev = dev[0].wait_global_event(["P2P-GROUP-STARTED"], timeout=15)
  495. if ev is None:
  496. raise Exception("Group formation timed out")
  497. ev = dev[1].wait_global_event(["P2P-GROUP-STARTED"], timeout=15)
  498. if ev is None:
  499. raise Exception("Group formation timed out")
  500. def test_go_neg_two_peers(dev):
  501. """P2P GO Negotiation rejected due to already started negotiation with another peer"""
  502. addr0 = dev[0].p2p_dev_addr()
  503. addr1 = dev[1].p2p_dev_addr()
  504. addr2 = dev[2].p2p_dev_addr()
  505. dev[1].p2p_listen()
  506. dev[2].p2p_listen()
  507. if not dev[0].discover_peer(addr1):
  508. raise Exception("Could not discover peer")
  509. if not dev[0].discover_peer(addr2):
  510. raise Exception("Could not discover peer")
  511. if "OK" not in dev[0].request("P2P_CONNECT " + addr2 + " pbc auth"):
  512. raise Exception("Failed to authorize GO Neg")
  513. dev[0].p2p_listen()
  514. if not dev[2].discover_peer(addr0):
  515. raise Exception("Could not discover peer")
  516. if "OK" not in dev[0].request("P2P_CONNECT " + addr1 + " pbc"):
  517. raise Exception("Failed to initiate GO Neg")
  518. ev = dev[1].wait_global_event(["P2P-GO-NEG-REQUEST"], timeout=5)
  519. if ev is None:
  520. raise Exception("timeout on GO Neg RX event")
  521. dev[2].request("P2P_CONNECT " + addr0 + " pbc")
  522. ev = dev[2].wait_global_event(["GO-NEG-FAILURE"], timeout=10)
  523. if ev is None:
  524. raise Exception("Rejection not reported")
  525. if "status=5" not in ev:
  526. raise Exception("Unexpected status code in rejection: " + ev)
  527. def clear_pbc_overlap(dev, ifname):
  528. hapd_global = hostapd.HostapdGlobal()
  529. hapd_global.remove(ifname)
  530. dev[0].request("P2P_CANCEL")
  531. dev[1].request("P2P_CANCEL")
  532. dev[0].p2p_stop_find()
  533. dev[1].p2p_stop_find()
  534. dev[0].dump_monitor()
  535. dev[1].dump_monitor()
  536. time.sleep(0.1)
  537. dev[0].flush_scan_cache()
  538. dev[1].flush_scan_cache()
  539. time.sleep(0.1)
  540. def test_grpform_pbc_overlap(dev, apdev):
  541. """P2P group formation during PBC overlap"""
  542. params = { "ssid": "wps", "eap_server": "1", "wps_state": "1" }
  543. hapd = hostapd.add_ap(apdev[0]['ifname'], params)
  544. hapd.request("WPS_PBC")
  545. time.sleep(0.1)
  546. # Since P2P Client scan case is now optimzied to use a specific SSID, the
  547. # WPS AP will not reply to that and the scan after GO Negotiation can quite
  548. # likely miss the AP due to dwell time being short enoguh to miss the Beacon
  549. # frame. This has made the test case somewhat pointless, but keep it here
  550. # for now with an additional scan to confirm that PBC detection works if
  551. # there is a BSS entry for a overlapping AP.
  552. for i in range(0, 5):
  553. dev[0].scan(freq="2412")
  554. if dev[0].get_bss(apdev[0]['bssid']) is not None:
  555. break
  556. addr0 = dev[0].p2p_dev_addr()
  557. addr1 = dev[1].p2p_dev_addr()
  558. dev[0].p2p_listen()
  559. if not dev[1].discover_peer(addr0):
  560. raise Exception("Could not discover peer")
  561. dev[1].p2p_listen()
  562. if not dev[0].discover_peer(addr1):
  563. raise Exception("Could not discover peer")
  564. dev[0].p2p_listen()
  565. if "OK" not in dev[0].global_request("P2P_CONNECT " + addr1 + " pbc auth go_intent=0"):
  566. raise Exception("Failed to authorize GO Neg")
  567. if "OK" not in dev[1].global_request("P2P_CONNECT " + addr0 + " pbc go_intent=15 freq=2412"):
  568. raise Exception("Failed to initiate GO Neg")
  569. ev = dev[0].wait_global_event(["WPS-OVERLAP-DETECTED"], timeout=15)
  570. if ev is None:
  571. raise Exception("PBC overlap not reported")
  572. clear_pbc_overlap(dev, apdev[0]['ifname'])
  573. def test_grpform_pbc_overlap_group_iface(dev, apdev):
  574. """P2P group formation during PBC overlap using group interfaces"""
  575. # Note: Need to include P2P IE from the AP to get the P2P interface BSS
  576. # update use this information.
  577. params = { "ssid": "wps", "eap_server": "1", "wps_state": "1",
  578. "beacon_int": "15", 'manage_p2p': '1' }
  579. hapd = hostapd.add_ap(apdev[0]['ifname'], params)
  580. hapd.request("WPS_PBC")
  581. dev[0].request("SET p2p_no_group_iface 0")
  582. dev[1].request("SET p2p_no_group_iface 0")
  583. addr0 = dev[0].p2p_dev_addr()
  584. addr1 = dev[1].p2p_dev_addr()
  585. dev[0].p2p_listen()
  586. if not dev[1].discover_peer(addr0):
  587. raise Exception("Could not discover peer")
  588. dev[1].p2p_listen()
  589. if not dev[0].discover_peer(addr1):
  590. raise Exception("Could not discover peer")
  591. dev[0].p2p_stop_find()
  592. dev[0].scan(freq="2412")
  593. dev[0].p2p_listen()
  594. if "OK" not in dev[0].global_request("P2P_CONNECT " + addr1 + " pbc auth go_intent=0"):
  595. raise Exception("Failed to authorize GO Neg")
  596. if "OK" not in dev[1].global_request("P2P_CONNECT " + addr0 + " pbc go_intent=15 freq=2412"):
  597. raise Exception("Failed to initiate GO Neg")
  598. ev = dev[0].wait_global_event(["WPS-OVERLAP-DETECTED",
  599. "P2P-GROUP-FORMATION-SUCCESS"], timeout=15)
  600. if ev is None or "WPS-OVERLAP-DETECTED" not in ev:
  601. # Do not report this as failure since the P2P group formation case
  602. # using a separate group interface has limited chances of "seeing" the
  603. # overlapping AP due to a per-SSID scan and no prior scan operations on
  604. # the group interface.
  605. logger.info("PBC overlap not reported")
  606. clear_pbc_overlap(dev, apdev[0]['ifname'])
  607. def test_grpform_goneg_fail_with_group_iface(dev):
  608. """P2P group formation fails while using group interface"""
  609. dev[0].request("SET p2p_no_group_iface 0")
  610. dev[1].p2p_listen()
  611. peer = dev[1].p2p_dev_addr()
  612. if not dev[0].discover_peer(peer):
  613. raise Exception("Peer " + peer + " not found")
  614. if "OK" not in dev[1].request("P2P_REJECT " + dev[0].p2p_dev_addr()):
  615. raise Exception("P2P_REJECT failed")
  616. if "OK" not in dev[0].request("P2P_CONNECT " + peer + " pbc"):
  617. raise Exception("P2P_CONNECT failed")
  618. ev = dev[0].wait_global_event(["P2P-GO-NEG-FAILURE"], timeout=10)
  619. if ev is None:
  620. raise Exception("GO Negotiation failure timed out")
  621. def test_grpform_cred_ready_timeout(dev, apdev, params):
  622. """P2P GO Negotiation wait for credentials to become ready [long]"""
  623. if not params['long']:
  624. raise HwsimSkip("Skip test case with long duration due to --long not specified")
  625. dev[1].p2p_listen()
  626. addr1 = dev[1].p2p_dev_addr()
  627. if not dev[0].discover_peer(addr1):
  628. raise Exception("Peer " + addr1 + " not found")
  629. if not dev[2].discover_peer(addr1):
  630. raise Exception("Peer " + addr1 + " not found(2)")
  631. start = os.times()[4]
  632. cmd = "P2P_CONNECT " + addr1 + " 12345670 display"
  633. if "OK" not in dev[0].global_request(cmd):
  634. raise Exception("Failed to initiate GO Neg")
  635. if "OK" not in dev[2].global_request(cmd):
  636. raise Exception("Failed to initiate GO Neg(2)")
  637. # First, check with p2p_find
  638. ev = dev[2].wait_global_event(["P2P-GO-NEG-FAILURE"], timeout=30)
  639. if ev is not None:
  640. raise Exception("Too early GO Negotiation timeout reported(2)")
  641. dev[2].dump_monitor()
  642. logger.info("Starting p2p_find to change state")
  643. dev[2].p2p_find()
  644. ev = dev[2].wait_global_event(["P2P-GO-NEG-FAILURE"], timeout=100)
  645. if ev is None:
  646. raise Exception("GO Negotiation failure timed out(2)")
  647. dev[2].dump_monitor()
  648. end = os.times()[4]
  649. logger.info("GO Negotiation wait time: {} seconds(2)".format(end - start))
  650. if end - start < 120:
  651. raise Exception("Too short GO Negotiation wait time(2): {}".format(end - start))
  652. wpas = WpaSupplicant(global_iface='/tmp/wpas-wlan5')
  653. wpas.interface_add("wlan5")
  654. wpas.p2p_listen()
  655. ev = dev[2].wait_global_event(["P2P-DEVICE-FOUND"], timeout=10)
  656. if ev is None:
  657. raise Exception("Did not discover new device after GO Negotiation failure")
  658. if wpas.p2p_dev_addr() not in ev:
  659. raise Exception("Unexpected device found: " + ev)
  660. dev[2].p2p_stop_find()
  661. wpas.p2p_stop_find()
  662. # Finally, verify without p2p_find
  663. ev = dev[0].wait_global_event(["P2P-GO-NEG-FAILURE"], timeout=120)
  664. if ev is None:
  665. raise Exception("GO Negotiation failure timed out")
  666. end = os.times()[4]
  667. logger.info("GO Negotiation wait time: {} seconds".format(end - start))
  668. if end - start < 120:
  669. raise Exception("Too short GO Negotiation wait time: {}".format(end - start))
  670. def test_grpform_no_wsc_done(dev):
  671. """P2P group formation with WSC-Done not sent"""
  672. addr0 = dev[0].p2p_dev_addr()
  673. addr1 = dev[1].p2p_dev_addr()
  674. for i in range(0, 2):
  675. dev[0].request("SET ext_eapol_frame_io 1")
  676. dev[1].request("SET ext_eapol_frame_io 1")
  677. dev[0].p2p_listen()
  678. dev[1].p2p_go_neg_auth(addr0, "12345670", "display", 0)
  679. dev[1].p2p_listen()
  680. dev[0].p2p_go_neg_init(addr1, "12345670", "enter", timeout=20,
  681. go_intent=15, wait_group=False)
  682. mode = None
  683. while True:
  684. ev = dev[0].wait_event(["EAPOL-TX"], timeout=15)
  685. if ev is None:
  686. raise Exception("Timeout on EAPOL-TX from GO")
  687. if not mode:
  688. mode = dev[0].get_status_field("mode")
  689. res = dev[1].request("EAPOL_RX " + addr0 + " " + ev.split(' ')[2])
  690. if "OK" not in res:
  691. raise Exception("EAPOL_RX failed")
  692. ev = dev[1].wait_event(["EAPOL-TX"], timeout=15)
  693. if ev is None:
  694. raise Exception("Timeout on EAPOL-TX from P2P Client")
  695. msg = ev.split(' ')[2]
  696. if msg[46:56] == "102200010f":
  697. logger.info("Drop WSC_Done")
  698. dev[0].request("SET ext_eapol_frame_io 0")
  699. dev[1].request("SET ext_eapol_frame_io 0")
  700. # Fake EAP-Failure to complete session on the client
  701. id = msg[10:12]
  702. dev[1].request("EAPOL_RX " + addr0 + " 0300000404" + id + "0004")
  703. break
  704. res = dev[0].request("EAPOL_RX " + addr1 + " " + msg)
  705. if "OK" not in res:
  706. raise Exception("EAPOL_RX failed")
  707. ev = dev[0].wait_global_event(["P2P-GROUP-STARTED"], timeout=15)
  708. if ev is None:
  709. raise Exception("Group formation timed out on GO")
  710. ev = dev[1].wait_global_event(["P2P-GROUP-STARTED"], timeout=15)
  711. if ev is None:
  712. raise Exception("Group formation timed out on P2P Client")
  713. dev[0].remove_group()
  714. dev[1].wait_go_ending_session()
  715. if mode != "P2P GO - group formation":
  716. raise Exception("Unexpected mode on GO during group formation: " + mode)
  717. def test_grpform_wait_peer(dev):
  718. """P2P group formation wait for peer to become ready"""
  719. addr0 = dev[0].p2p_dev_addr()
  720. addr1 = dev[1].p2p_dev_addr()
  721. dev[1].p2p_listen()
  722. if not dev[0].discover_peer(addr1):
  723. raise Exception("Peer " + addr1 + " not found")
  724. dev[0].request("SET extra_roc_dur 500")
  725. if "OK" not in dev[0].request("P2P_CONNECT " + addr1 + " 12345670 display go_intent=15"):
  726. raise Exception("Failed to initiate GO Neg")
  727. time.sleep(3)
  728. dev[1].request("P2P_CONNECT " + addr0 + " 12345670 enter go_intent=0")
  729. ev = dev[0].wait_global_event(["P2P-GROUP-STARTED"], timeout=15)
  730. if ev is None:
  731. raise Exception("Group formation timed out")
  732. dev[0].group_form_result(ev)
  733. dev[0].request("SET extra_roc_dur 0")
  734. ev = dev[1].wait_global_event(["P2P-GROUP-STARTED"], timeout=15)
  735. if ev is None:
  736. raise Exception("Group formation timed out")
  737. dev[0].remove_group()
  738. def test_invalid_p2p_connect_command(dev):
  739. """P2P_CONNECT error cases"""
  740. id = dev[0].add_network()
  741. for cmd in [ "foo",
  742. "00:11:22:33:44:55",
  743. "00:11:22:33:44:55 pbc persistent=123",
  744. "00:11:22:33:44:55 pbc persistent=%d" % id,
  745. "00:11:22:33:44:55 pbc go_intent=-1",
  746. "00:11:22:33:44:55 pbc go_intent=16",
  747. "00:11:22:33:44:55 pin",
  748. "00:11:22:33:44:55 pbc freq=0" ]:
  749. if "FAIL" not in dev[0].request("P2P_CONNECT " + cmd):
  750. raise Exception("Invalid P2P_CONNECT command accepted: " + cmd)
  751. if "FAIL-INVALID-PIN" not in dev[0].request("P2P_CONNECT 00:11:22:33:44:55 1234567"):
  752. raise Exception("Invalid PIN was not rejected")
  753. if "FAIL-INVALID-PIN" not in dev[0].request("P2P_CONNECT 00:11:22:33:44:55 12345678a"):
  754. raise Exception("Invalid PIN was not rejected")
  755. if "FAIL-CHANNEL-UNSUPPORTED" not in dev[0].request("P2P_CONNECT 00:11:22:33:44:55 pin freq=3000"):
  756. raise Exception("Unsupported channel not reported")
  757. def test_p2p_unauthorize(dev):
  758. """P2P_UNAUTHORIZE to unauthorize a peer"""
  759. if "FAIL" not in dev[0].request("P2P_UNAUTHORIZE foo"):
  760. raise Exception("Invalid P2P_UNAUTHORIZE accepted")
  761. if "FAIL" not in dev[0].request("P2P_UNAUTHORIZE 00:11:22:33:44:55"):
  762. raise Exception("P2P_UNAUTHORIZE for unknown peer accepted")
  763. addr0 = dev[0].p2p_dev_addr()
  764. addr1 = dev[1].p2p_dev_addr()
  765. dev[1].p2p_listen()
  766. pin = dev[0].wps_read_pin()
  767. dev[0].p2p_go_neg_auth(addr1, pin, "display")
  768. dev[0].p2p_listen()
  769. if "OK" not in dev[0].request("P2P_UNAUTHORIZE " + addr1):
  770. raise Exception("P2P_UNAUTHORIZE failed")
  771. dev[1].p2p_go_neg_init(addr0, pin, "keypad", timeout=0)
  772. ev = dev[0].wait_global_event(["P2P-GO-NEG-REQUEST"], timeout=10)
  773. if ev is None:
  774. raise Exception("No GO Negotiation Request RX reported")
  775. def test_grpform_pbc_multiple(dev):
  776. """P2P group formation using PBC multiple times in a row"""
  777. try:
  778. dev[1].request("SET passive_scan 1")
  779. for i in range(5):
  780. [i_res, r_res] = go_neg_pbc_authorized(i_dev=dev[0], i_intent=15,
  781. r_dev=dev[1], r_intent=0)
  782. remove_group(dev[0], dev[1])
  783. finally:
  784. dev[1].request("SET passive_scan 0")
  785. dev[1].flush_scan_cache()
  786. def test_grpform_not_ready(dev):
  787. """Not ready for GO Negotiation (listen)"""
  788. addr0 = dev[0].p2p_dev_addr()
  789. addr2 = dev[2].p2p_dev_addr()
  790. dev[0].p2p_listen()
  791. if not dev[1].discover_peer(addr0):
  792. raise Exception("Could not discover peer")
  793. dev[1].global_request("P2P_CONNECT " + addr0 + " pbc")
  794. ev = dev[0].wait_global_event(["P2P-GO-NEG-REQUEST"], timeout=5)
  795. if ev is None:
  796. raise Exception("No P2P-GO-NEG-REQUEST event")
  797. dev[0].dump_monitor()
  798. time.sleep(5)
  799. if not dev[2].discover_peer(addr0):
  800. raise Exception("Could not discover peer(2)")
  801. for i in range(3):
  802. dev[i].p2p_stop_find()
  803. def test_grpform_not_ready2(dev):
  804. """Not ready for GO Negotiation (search)"""
  805. addr0 = dev[0].p2p_dev_addr()
  806. addr2 = dev[2].p2p_dev_addr()
  807. dev[0].p2p_find(social=True)
  808. if not dev[1].discover_peer(addr0):
  809. raise Exception("Could not discover peer")
  810. dev[1].global_request("P2P_CONNECT " + addr0 + " pbc")
  811. ev = dev[0].wait_global_event(["P2P-GO-NEG-REQUEST"], timeout=5)
  812. if ev is None:
  813. raise Exception("No P2P-GO-NEG-REQUEST event")
  814. dev[0].dump_monitor()
  815. time.sleep(1)
  816. dev[2].p2p_listen()
  817. ev = dev[0].wait_global_event(["P2P-DEVICE-FOUND"], timeout=10)
  818. if ev is None:
  819. raise Exception("Peer not discovered after GO Neg Resp(status=1) TX")
  820. if addr2 not in ev:
  821. raise Exception("Unexpected peer discovered: " + ev)
  822. for i in range(3):
  823. dev[i].p2p_stop_find()
  824. def test_grpform_and_scan(dev):
  825. """GO Negotiation and scan operations"""
  826. addr0 = dev[0].p2p_dev_addr()
  827. addr1 = dev[1].p2p_dev_addr()
  828. dev[1].p2p_listen()
  829. if not dev[0].discover_peer(addr1):
  830. raise Exception("Could not discover peer")
  831. dev[0].p2p_stop_find()
  832. dev[1].p2p_stop_find()
  833. if "OK" not in dev[0].request("SCAN TYPE=ONLY freq=2412-2472"):
  834. raise Exception("Could not start scan")
  835. ev = dev[0].wait_event(["CTRL-EVENT-SCAN-STARTED"], timeout=5)
  836. if ev is None:
  837. raise Exception("Scan did not start")
  838. time.sleep(0.1)
  839. # Request PD while the previously started scan is still in progress
  840. if "OK" not in dev[0].request("P2P_PROV_DISC %s pbc" % addr1):
  841. raise Exception("Could not request PD")
  842. ev = dev[0].wait_event(["CTRL-EVENT-SCAN-RESULTS"], timeout=10)
  843. if ev is None:
  844. raise Exception("Scan did not complete")
  845. time.sleep(0.3)
  846. dev[1].p2p_listen()
  847. ev = dev[0].wait_global_event(["P2P-PROV-DISC-PBC-RESP"], timeout=5)
  848. if ev is None:
  849. raise Exception("PD Response not received")
  850. if "OK" not in dev[0].request("SCAN TYPE=ONLY freq=2412-2472"):
  851. raise Exception("Could not start scan")
  852. ev = dev[0].wait_event(["CTRL-EVENT-SCAN-STARTED"], timeout=5)
  853. if ev is None:
  854. raise Exception("Scan did not start")
  855. time.sleep(0.1)
  856. # Request GO Neg while the previously started scan is still in progress
  857. if "OK" not in dev[0].request("P2P_CONNECT %s pbc" % addr1):
  858. raise Exception("Could not request GO Negotiation")
  859. ev = dev[0].wait_event(["CTRL-EVENT-SCAN-RESULTS"], timeout=10)
  860. if ev is None:
  861. raise Exception("Scan did not complete")
  862. ev = dev[1].wait_global_event(["P2P-GO-NEG-REQUEST"], timeout=10)
  863. if ev is None:
  864. raise Exception("GO Neg Req RX not reported")
  865. dev[1].p2p_stop_find()
  866. if "OK" not in dev[1].request("SCAN TYPE=ONLY freq=2412-2472"):
  867. raise Exception("Could not start scan")
  868. ev = dev[1].wait_event(["CTRL-EVENT-SCAN-STARTED"], timeout=5)
  869. if ev is None:
  870. raise Exception("Scan did not start")
  871. time.sleep(0.1)
  872. dev[1].global_request("P2P_CONNECT " + addr0 + " pbc")
  873. ev = dev[1].wait_event(["CTRL-EVENT-SCAN-RESULTS"], timeout=10)
  874. if ev is None:
  875. raise Exception("Scan did not complete")
  876. ev0 = dev[0].wait_global_event(["P2P-GROUP-STARTED"], timeout=15)
  877. if ev0 is None:
  878. raise Exception("Group formation timed out on dev0")
  879. dev[0].group_form_result(ev0)
  880. ev1 = dev[1].wait_global_event(["P2P-GROUP-STARTED"], timeout=15)
  881. if ev1 is None:
  882. raise Exception("Group formation timed out on dev1")
  883. dev[1].group_form_result(ev1)
  884. dev[0].dump_monitor()
  885. dev[1].dump_monitor()
  886. remove_group(dev[0], dev[1])
  887. dev[0].dump_monitor()
  888. dev[1].dump_monitor()
  889. def test_grpform_go_neg_dup_on_restart(dev):
  890. """Duplicated GO Negotiation Request after GO Neg restart"""
  891. if dev[0].p2p_dev_addr() > dev[1].p2p_dev_addr():
  892. higher = dev[0]
  893. lower = dev[1]
  894. else:
  895. higher = dev[1]
  896. lower = dev[0]
  897. addr_low = lower.p2p_dev_addr()
  898. addr_high = higher.p2p_dev_addr()
  899. higher.p2p_listen()
  900. if not lower.discover_peer(addr_high):
  901. raise Exception("Could not discover peer")
  902. lower.p2p_stop_find()
  903. if "OK" not in lower.request("P2P_CONNECT %s pbc" % addr_high):
  904. raise Exception("Could not request GO Negotiation")
  905. ev = higher.wait_global_event(["P2P-GO-NEG-REQUEST"], timeout=10)
  906. if ev is None:
  907. raise Exception("GO Neg Req RX not reported")
  908. # Wait for GO Negotiation Response (Status=1) to go through
  909. time.sleep(0.2)
  910. if "FAIL" in lower.request("SET ext_mgmt_frame_handling 1"):
  911. raise Exception("Failed to enable external management frame handling")
  912. higher.p2p_stop_find()
  913. higher.global_request("P2P_CONNECT " + addr_low + " pbc")
  914. # Wait for the GO Negotiation Request frame of the restarted GO Negotiation
  915. rx_msg = lower.mgmt_rx()
  916. if rx_msg is None:
  917. raise Exception("MGMT-RX timeout")
  918. p2p = parse_p2p_public_action(rx_msg['payload'])
  919. if p2p is None:
  920. raise Exception("Not a P2P Public Action frame")
  921. if p2p['subtype'] != 0:
  922. raise Exception("Unexpected P2P Public Action subtype %d" % p2p['subtype'])
  923. # Send duplicate GO Negotiation Request from the prior instance of GO
  924. # Negotiation
  925. lower.p2p_stop_find()
  926. peer = higher.get_peer(addr_low)
  927. msg = p2p_hdr(addr_high, addr_low, type=P2P_GO_NEG_REQ, dialog_token=123)
  928. attrs = p2p_attr_capability(dev_capab=0x25, group_capab=0x08)
  929. attrs += p2p_attr_go_intent(go_intent=7, tie_breaker=1)
  930. attrs += p2p_attr_config_timeout()
  931. attrs += p2p_attr_listen_channel(chan=(int(peer['listen_freq']) - 2407) / 5)
  932. attrs += p2p_attr_intended_interface_addr(lower.p2p_dev_addr())
  933. attrs += p2p_attr_channel_list()
  934. attrs += p2p_attr_device_info(addr_low, config_methods=0x80, name="Device A")
  935. attrs += p2p_attr_operating_channel()
  936. wsc_attrs = struct.pack(">HHH", 0x1012, 2, 4)
  937. msg['payload'] += ie_p2p(attrs) + ie_wsc(wsc_attrs)
  938. 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'])))
  939. # Wait for the GO Negotiation Response frame which would have been sent in
  940. # this case previously, but not anymore after the check for
  941. # dev->go_neg_req_sent and dev->flags & P2P_DEV_PEER_WAITING_RESPONSE.
  942. rx_msg = lower.mgmt_rx(timeout=0.2)
  943. if rx_msg is not None:
  944. raise Exception("Unexpected management frame")
  945. if "FAIL" in lower.request("SET ext_mgmt_frame_handling 0"):
  946. raise Exception("Failed to disable external management frame handling")
  947. lower.p2p_listen()
  948. ev = lower.wait_global_event(["P2P-GO-NEG-SUCCESS"], timeout=10)
  949. if ev is None:
  950. raise Exception("GO Negotiation did not succeed on dev0")
  951. ev = higher.wait_global_event(["P2P-GO-NEG-SUCCESS"], timeout=10)
  952. if ev is None:
  953. raise Exception("GO Negotiation did not succeed on dev1")
  954. ev0 = lower.wait_global_event(["P2P-GROUP-STARTED"], timeout=15)
  955. if ev0 is None:
  956. raise Exception("Group formation timed out on dev0")
  957. lower.group_form_result(ev0)
  958. ev1 = higher.wait_global_event(["P2P-GROUP-STARTED"], timeout=15)
  959. if ev1 is None:
  960. raise Exception("Group formation timed out on dev1")
  961. higher.group_form_result(ev1)
  962. lower.dump_monitor()
  963. higher.dump_monitor()
  964. remove_group(lower, higher)
  965. lower.dump_monitor()
  966. higher.dump_monitor()