test_p2p_grpform.py 47 KB

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