test_p2p_grpform.py 48 KB

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