test_p2p_grpform.py 47 KB

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