test_p2p_grpform.py 49 KB

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