test_p2p_grpform.py 48 KB

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