test_p2p_persistent.py 29 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673
  1. # P2P persistent group test cases
  2. # Copyright (c) 2013-2014, Jouni Malinen <j@w1.fi>
  3. #
  4. # This software may be distributed under the terms of the BSD license.
  5. # See README for more details.
  6. from remotehost import remote_compatible
  7. import logging
  8. logger = logging.getLogger()
  9. import re
  10. import time
  11. import hwsim_utils
  12. from p2p_utils import *
  13. @remote_compatible
  14. def test_persistent_group(dev):
  15. """P2P persistent group formation and re-invocation"""
  16. form(dev[0], dev[1])
  17. invite_from_cli(dev[0], dev[1])
  18. invite_from_go(dev[0], dev[1])
  19. logger.info("Remove group on the client and try to invite from GO")
  20. id = None
  21. for n in dev[0].list_networks(p2p=True):
  22. if "[P2P-PERSISTENT]" in n['flags']:
  23. id = n['id']
  24. break
  25. if id is None:
  26. raise Exception("Could not find persistent group entry")
  27. clients = dev[0].global_request("GET_NETWORK " + id + " p2p_client_list").rstrip()
  28. if dev[1].p2p_dev_addr() not in clients:
  29. raise Exception("Peer missing from client list")
  30. if "FAIL" not in dev[1].request("SELECT_NETWORK " + str(id)):
  31. raise Exception("SELECT_NETWORK succeeded unexpectedly")
  32. if "FAIL" not in dev[1].request("SELECT_NETWORK 1234567"):
  33. raise Exception("SELECT_NETWORK succeeded unexpectedly(2)")
  34. if "FAIL" not in dev[1].request("ENABLE_NETWORK " + str(id)):
  35. raise Exception("ENABLE_NETWORK succeeded unexpectedly")
  36. if "FAIL" not in dev[1].request("ENABLE_NETWORK 1234567"):
  37. raise Exception("ENABLE_NETWORK succeeded unexpectedly(2)")
  38. if "FAIL" not in dev[1].request("DISABLE_NETWORK " + str(id)):
  39. raise Exception("DISABLE_NETWORK succeeded unexpectedly")
  40. if "FAIL" not in dev[1].request("DISABLE_NETWORK 1234567"):
  41. raise Exception("DISABLE_NETWORK succeeded unexpectedly(2)")
  42. if "FAIL" not in dev[1].request("REMOVE_NETWORK 1234567"):
  43. raise Exception("REMOVE_NETWORK succeeded unexpectedly")
  44. dev[1].global_request("REMOVE_NETWORK all")
  45. if len(dev[1].list_networks(p2p=True)) > 0:
  46. raise Exception("Unexpected network block remaining")
  47. invite(dev[0], dev[1])
  48. ev = dev[0].wait_global_event(["P2P-INVITATION-RESULT"], timeout=10)
  49. if ev is None:
  50. raise Exception("No invitation result seen")
  51. if "status=8" not in ev:
  52. raise Exception("Unexpected invitation result: " + ev)
  53. clients = dev[0].request("GET_NETWORK " + id + " p2p_client_list").rstrip()
  54. if dev[1].p2p_dev_addr() in clients:
  55. raise Exception("Peer was still in client list")
  56. @remote_compatible
  57. def test_persistent_group2(dev):
  58. """P2P persistent group formation with reverse roles"""
  59. form(dev[0], dev[1], reverse_init=True)
  60. invite_from_cli(dev[0], dev[1])
  61. invite_from_go(dev[0], dev[1])
  62. @remote_compatible
  63. def test_persistent_group3(dev):
  64. """P2P persistent group formation and re-invocation with empty BSS table"""
  65. form(dev[0], dev[1])
  66. dev[1].request("BSS_FLUSH 0")
  67. invite_from_cli(dev[0], dev[1])
  68. dev[1].request("BSS_FLUSH 0")
  69. invite_from_go(dev[0], dev[1])
  70. def test_persistent_group_per_sta_psk(dev):
  71. """P2P persistent group formation and re-invocation using per-client PSK"""
  72. addr0 = dev[0].p2p_dev_addr()
  73. addr1 = dev[1].p2p_dev_addr()
  74. addr2 = dev[2].p2p_dev_addr()
  75. dev[0].global_request("P2P_SET per_sta_psk 1")
  76. logger.info("Form a persistent group")
  77. [i_res, r_res] = go_neg_pin_authorized_persistent(i_dev=dev[0], i_intent=15,
  78. r_dev=dev[1], r_intent=0)
  79. if not i_res['persistent'] or not r_res['persistent']:
  80. raise Exception("Formed group was not persistent")
  81. logger.info("Join another client to the group")
  82. pin = dev[2].wps_read_pin()
  83. dev[0].p2p_go_authorize_client(pin)
  84. social = int(i_res['freq']) in [ 2412, 2437, 2462 ]
  85. c_res = dev[2].p2p_connect_group(addr0, pin, timeout=60, social=social,
  86. freq=i_res['freq'])
  87. if not c_res['persistent']:
  88. raise Exception("Joining client did not recognize persistent group")
  89. if r_res['psk'] == c_res['psk']:
  90. raise Exception("Same PSK assigned for both clients")
  91. hwsim_utils.test_connectivity_p2p(dev[1], dev[2])
  92. logger.info("Remove persistent group and re-start it manually")
  93. dev[0].remove_group()
  94. dev[1].wait_go_ending_session()
  95. dev[2].wait_go_ending_session()
  96. dev[0].dump_monitor()
  97. dev[1].dump_monitor()
  98. dev[2].dump_monitor()
  99. for i in range(0, 3):
  100. networks = dev[i].list_networks(p2p=True)
  101. if len(networks) != 1:
  102. raise Exception("Unexpected number of networks")
  103. if "[P2P-PERSISTENT]" not in networks[0]['flags']:
  104. raise Exception("Not the persistent group data")
  105. if i > 0:
  106. # speed up testing by avoiding use of the old BSS entry since the
  107. # GO may have changed channels
  108. dev[i].request("BSS_FLUSH 0")
  109. dev[i].scan(freq="2412", only_new=True)
  110. if "OK" not in dev[i].global_request("P2P_GROUP_ADD persistent=" + networks[0]['id'] + " freq=2412"):
  111. raise Exception("Could not re-start persistent group")
  112. ev = dev[i].wait_global_event(["P2P-GROUP-STARTED"], timeout=30)
  113. if ev is None:
  114. raise Exception("Timeout on group restart")
  115. dev[i].group_form_result(ev)
  116. logger.info("Leave persistent group and rejoin it")
  117. dev[2].remove_group()
  118. ev = dev[2].wait_global_event(["P2P-GROUP-REMOVED"], timeout=3)
  119. if ev is None:
  120. raise Exception("Group removal event timed out")
  121. if not dev[2].discover_peer(addr0, social=True):
  122. raise Exception("Peer " + peer + " not found")
  123. dev[2].dump_monitor()
  124. peer = dev[2].get_peer(addr0)
  125. dev[2].global_request("P2P_GROUP_ADD persistent=" + peer['persistent'] + " freq=2412")
  126. ev = dev[2].wait_global_event(["P2P-GROUP-STARTED"], timeout=30)
  127. if ev is None:
  128. raise Exception("Timeout on group restart (on client)")
  129. cli_res = dev[2].group_form_result(ev)
  130. if not cli_res['persistent']:
  131. raise Exception("Persistent group not restarted as persistent (cli)")
  132. hwsim_utils.test_connectivity_p2p(dev[1], dev[2])
  133. logger.info("Remove one of the clients from the group without removing persistent group information for the client")
  134. dev[0].global_request("P2P_REMOVE_CLIENT iface=" + dev[2].p2p_interface_addr())
  135. dev[2].wait_go_ending_session()
  136. logger.info("Try to reconnect after having been removed from group (but persistent group info still present)")
  137. if not dev[2].discover_peer(addr0, social=True):
  138. raise Exception("Peer " + peer + " not found")
  139. dev[2].dump_monitor()
  140. peer = dev[2].get_peer(addr0)
  141. dev[2].global_request("P2P_GROUP_ADD persistent=" + peer['persistent'] + " freq=2412")
  142. ev = dev[2].wait_global_event(["P2P-GROUP-STARTED","WPA: 4-Way Handshake failed"], timeout=30)
  143. if ev is None:
  144. raise Exception("Timeout on group restart (on client)")
  145. if "P2P-GROUP-STARTED" not in ev:
  146. raise Exception("Connection failed")
  147. logger.info("Remove one of the clients from the group")
  148. dev[0].global_request("P2P_REMOVE_CLIENT " + addr2)
  149. dev[2].wait_go_ending_session()
  150. logger.info("Try to reconnect after having been removed from group")
  151. if not dev[2].discover_peer(addr0, social=True):
  152. raise Exception("Peer " + peer + " not found")
  153. dev[2].dump_monitor()
  154. peer = dev[2].get_peer(addr0)
  155. dev[2].global_request("P2P_GROUP_ADD persistent=" + peer['persistent'] + " freq=2412")
  156. ev = dev[2].wait_global_event(["P2P-GROUP-STARTED","WPA: 4-Way Handshake failed"], timeout=30)
  157. if ev is None:
  158. raise Exception("Timeout on group restart (on client)")
  159. if "P2P-GROUP-STARTED" in ev:
  160. raise Exception("Client managed to connect after being removed")
  161. logger.info("Remove the remaining client from the group")
  162. dev[0].global_request("P2P_REMOVE_CLIENT " + addr1)
  163. dev[1].wait_go_ending_session()
  164. logger.info("Terminate persistent group")
  165. dev[0].remove_group()
  166. dev[0].dump_monitor()
  167. logger.info("Try to re-invoke persistent group from client")
  168. dev[0].global_request("SET persistent_reconnect 1")
  169. dev[0].p2p_listen()
  170. if not dev[1].discover_peer(addr0, social=True):
  171. raise Exception("Peer " + peer + " not found")
  172. dev[1].dump_monitor()
  173. peer = dev[1].get_peer(addr0)
  174. dev[1].global_request("P2P_INVITE persistent=" + peer['persistent'] + " peer=" + addr0)
  175. ev = dev[0].wait_global_event(["P2P-GROUP-STARTED"], timeout=30)
  176. dev[0].group_form_result(ev)
  177. ev = dev[1].wait_global_event(["P2P-GROUP-STARTED","WPA: 4-Way Handshake failed"], timeout=30)
  178. if ev is None:
  179. raise Exception("Timeout on group restart (on client)")
  180. if "P2P-GROUP-STARTED" in ev:
  181. raise Exception("Client managed to re-invoke after being removed")
  182. dev[0].dump_monitor()
  183. logger.info("Terminate persistent group")
  184. dev[0].remove_group()
  185. dev[0].dump_monitor()
  186. def test_persistent_group_invite_removed_client(dev):
  187. """P2P persistent group client removal and re-invitation"""
  188. addr0 = dev[0].p2p_dev_addr()
  189. addr1 = dev[1].p2p_dev_addr()
  190. dev[0].request("P2P_SET per_sta_psk 1")
  191. logger.info("Form a persistent group")
  192. [i_res, r_res] = go_neg_pin_authorized_persistent(i_dev=dev[0], i_intent=15,
  193. r_dev=dev[1], r_intent=0)
  194. if not i_res['persistent'] or not r_res['persistent']:
  195. raise Exception("Formed group was not persistent")
  196. logger.info("Remove client from the group")
  197. dev[0].global_request("P2P_REMOVE_CLIENT " + addr1)
  198. dev[1].wait_go_ending_session()
  199. logger.info("Re-invite the removed client to join the group")
  200. dev[1].p2p_listen()
  201. if not dev[0].discover_peer(addr1, social=True):
  202. raise Exception("Peer " + peer + " not found")
  203. dev[0].global_request("P2P_INVITE group=" + dev[0].group_ifname + " peer=" + addr1)
  204. ev = dev[1].wait_global_event(["P2P-INVITATION-RECEIVED"], timeout=10)
  205. if ev is None:
  206. raise Exception("Timeout on invitation")
  207. if "sa=" + addr0 + " persistent=" not in ev:
  208. raise Exception("Unexpected invitation event")
  209. [event,addr,persistent] = ev.split(' ', 2)
  210. dev[1].global_request("P2P_GROUP_ADD " + persistent)
  211. ev = dev[1].wait_global_event(["P2P-PERSISTENT-PSK-FAIL"], timeout=30)
  212. if ev is None:
  213. raise Exception("Did not receive PSK failure report")
  214. [tmp,id] = ev.split('=', 1)
  215. ev = dev[1].wait_global_event(["P2P-GROUP-REMOVED"], timeout=10)
  216. if ev is None:
  217. raise Exception("Group removal event timed out")
  218. if "reason=PSK_FAILURE" not in ev:
  219. raise Exception("Unexpected group removal reason")
  220. dev[1].global_request("REMOVE_NETWORK " + id)
  221. logger.info("Re-invite after client removed persistent group info")
  222. dev[1].p2p_listen()
  223. if not dev[0].discover_peer(addr1, social=True):
  224. raise Exception("Peer " + peer + " not found")
  225. dev[0].global_request("P2P_INVITE group=" + dev[0].group_ifname + " peer=" + addr1)
  226. ev = dev[1].wait_global_event(["P2P-INVITATION-RECEIVED"], timeout=10)
  227. if ev is None:
  228. raise Exception("Timeout on invitation")
  229. if " persistent=" in ev:
  230. raise Exception("Unexpected invitation event")
  231. pin = dev[1].wps_read_pin()
  232. dev[0].p2p_go_authorize_client(pin)
  233. c_res = dev[1].p2p_connect_group(addr0, pin, timeout=60, social=True,
  234. freq=i_res['freq'])
  235. if not c_res['persistent']:
  236. raise Exception("Joining client did not recognize persistent group")
  237. if r_res['psk'] == c_res['psk']:
  238. raise Exception("Same PSK assigned on both times")
  239. hwsim_utils.test_connectivity_p2p(dev[0], dev[1])
  240. terminate_group(dev[0], dev[1])
  241. @remote_compatible
  242. def test_persistent_group_channel(dev):
  243. """P2P persistent group re-invocation with channel selection"""
  244. form(dev[0], dev[1], test_data=False)
  245. logger.info("Re-invoke persistent group from client with forced channel")
  246. invite(dev[1], dev[0], "freq=2427")
  247. [go_res, cli_res] = check_result(dev[0], dev[1])
  248. if go_res['freq'] != "2427":
  249. raise Exception("Persistent group client forced channel not followed")
  250. terminate_group(dev[0], dev[1])
  251. logger.info("Re-invoke persistent group from GO with forced channel")
  252. invite(dev[0], dev[1], "freq=2432")
  253. [go_res, cli_res] = check_result(dev[0], dev[1])
  254. if go_res['freq'] != "2432":
  255. raise Exception("Persistent group GO channel preference not followed")
  256. terminate_group(dev[0], dev[1])
  257. logger.info("Re-invoke persistent group from client with channel preference")
  258. invite(dev[1], dev[0], "pref=2417")
  259. [go_res, cli_res] = check_result(dev[0], dev[1])
  260. if go_res['freq'] != "2417":
  261. raise Exception("Persistent group client channel preference not followed")
  262. terminate_group(dev[0], dev[1])
  263. @remote_compatible
  264. def test_persistent_group_and_role_change(dev):
  265. """P2P persistent group, auto GO in another role, and re-invocation"""
  266. form(dev[0], dev[1])
  267. logger.info("Start and stop autonomous GO on previous P2P client device")
  268. dev[1].p2p_start_go()
  269. dev[1].remove_group()
  270. dev[1].dump_monitor()
  271. logger.info("Re-invoke the persistent group")
  272. invite_from_go(dev[0], dev[1])
  273. def test_persistent_go_client_list(dev):
  274. """P2P GO and list of clients in persistent group"""
  275. addr0 = dev[0].p2p_dev_addr()
  276. addr1 = dev[1].p2p_dev_addr()
  277. addr2 = dev[2].p2p_dev_addr()
  278. res = dev[0].p2p_start_go(persistent=True)
  279. id = None
  280. for n in dev[0].list_networks(p2p=True):
  281. if "[P2P-PERSISTENT]" in n['flags']:
  282. id = n['id']
  283. break
  284. if id is None:
  285. raise Exception("Could not find persistent group entry")
  286. connect_cli(dev[0], dev[1], social=True, freq=res['freq'])
  287. clients = dev[0].global_request("GET_NETWORK " + id + " p2p_client_list").rstrip()
  288. if clients != addr1:
  289. raise Exception("Unexpected p2p_client_list entry(2): " + clients)
  290. connect_cli(dev[0], dev[2], social=True, freq=res['freq'])
  291. clients = dev[0].global_request("GET_NETWORK " + id + " p2p_client_list").rstrip()
  292. if clients != addr2 + " " + addr1:
  293. raise Exception("Unexpected p2p_client_list entry(3): " + clients)
  294. peer = dev[1].get_peer(res['go_dev_addr'])
  295. dev[1].remove_group()
  296. dev[1].global_request("P2P_GROUP_ADD persistent=" + peer['persistent'])
  297. ev = dev[1].wait_global_event(["P2P-GROUP-STARTED"], timeout=30)
  298. if ev is None:
  299. raise Exception("Timeout on group restart (on client)")
  300. dev[1].group_form_result(ev)
  301. clients = dev[0].global_request("GET_NETWORK " + id + " p2p_client_list").rstrip()
  302. if clients != addr1 + " " + addr2:
  303. raise Exception("Unexpected p2p_client_list entry(4): " + clients)
  304. dev[2].remove_group()
  305. dev[1].remove_group()
  306. dev[0].remove_group()
  307. clients = dev[0].global_request("GET_NETWORK " + id + " p2p_client_list").rstrip()
  308. if clients != addr1 + " " + addr2:
  309. raise Exception("Unexpected p2p_client_list entry(5): " + clients)
  310. dev[1].p2p_listen()
  311. dev[2].p2p_listen()
  312. dev[0].request("P2P_FLUSH")
  313. dev[0].discover_peer(addr1, social=True)
  314. peer = dev[0].get_peer(addr1)
  315. if 'persistent' not in peer or peer['persistent'] != id:
  316. raise Exception("Persistent group client not recognized(1)")
  317. dev[0].discover_peer(addr2, social=True)
  318. peer = dev[0].get_peer(addr2)
  319. if 'persistent' not in peer or peer['persistent'] != id:
  320. raise Exception("Persistent group client not recognized(2)")
  321. @remote_compatible
  322. def test_persistent_group_in_grpform(dev):
  323. """P2P persistent group parameters re-used in group formation"""
  324. addr0 = dev[0].p2p_dev_addr()
  325. addr1 = dev[1].p2p_dev_addr()
  326. form(dev[0], dev[1])
  327. dev[1].p2p_listen()
  328. if not dev[0].discover_peer(addr1, social=True):
  329. raise Exception("Could not discover peer")
  330. peer = dev[0].get_peer(addr1)
  331. if "persistent" not in peer:
  332. raise Exception("Could not map peer to a persistent group")
  333. pin = dev[1].wps_read_pin()
  334. dev[1].p2p_go_neg_auth(addr0, pin, "display", go_intent=0)
  335. i_res = dev[0].p2p_go_neg_init(addr1, pin, "enter", timeout=20,
  336. go_intent=15,
  337. persistent_id=peer['persistent'])
  338. r_res = dev[1].p2p_go_neg_auth_result()
  339. logger.debug("i_res: " + str(i_res))
  340. logger.debug("r_res: " + str(r_res))
  341. @remote_compatible
  342. def test_persistent_group_without_persistent_reconnect(dev):
  343. """P2P persistent group re-invocation without persistent reconnect"""
  344. form(dev[0], dev[1])
  345. dev[0].dump_monitor()
  346. dev[1].dump_monitor()
  347. logger.info("Re-invoke persistent group from client")
  348. invite(dev[1], dev[0], persistent_reconnect=False)
  349. ev = dev[0].wait_global_event(["P2P-INVITATION-RECEIVED"], timeout=15)
  350. if ev is None:
  351. raise Exception("No invitation request reported")
  352. if "persistent=" not in ev:
  353. raise Exception("Invalid invitation type reported: " + ev)
  354. ev2 = dev[1].wait_global_event(["P2P-INVITATION-RESULT"], timeout=15)
  355. if ev2 is None:
  356. raise Exception("No invitation response reported")
  357. if "status=1" not in ev2:
  358. raise Exception("Unexpected status: " + ev2)
  359. dev[1].p2p_listen()
  360. exp = r'<.>(P2P-INVITATION-RECEIVED) sa=([0-9a-f:]*) persistent=([0-9]*) freq=([0-9]*)'
  361. s = re.split(exp, ev)
  362. if len(s) < 5:
  363. raise Exception("Could not parse invitation event")
  364. sa = s[2]
  365. id = s[3]
  366. freq = s[4]
  367. logger.info("Invalid P2P_INVITE test coverage")
  368. if "FAIL" not in dev[0].global_request("P2P_INVITE persistent=" + id + " peer=" + sa + " freq=0"):
  369. raise Exception("Invalid P2P_INVITE accepted")
  370. if "FAIL" not in dev[0].global_request("P2P_INVITE persistent=" + id + " peer=" + sa + " pref=0"):
  371. raise Exception("Invalid P2P_INVITE accepted")
  372. logger.info("Re-initiate invitation based on upper layer acceptance")
  373. if "OK" not in dev[0].global_request("P2P_INVITE persistent=" + id + " peer=" + sa + " freq=" + freq):
  374. raise Exception("Invitation command failed")
  375. [go_res, cli_res] = check_result(dev[0], dev[1])
  376. if go_res['freq'] != freq:
  377. raise Exception("Unexpected channel on GO: {} MHz, expected {} MHz".format(go_res['freq'], freq))
  378. if cli_res['freq'] != freq:
  379. raise Exception("Unexpected channel on CLI: {} MHz, expected {} MHz".format(cli_res['freq'], freq))
  380. terminate_group(dev[0], dev[1])
  381. dev[0].dump_monitor()
  382. dev[1].dump_monitor()
  383. logger.info("Re-invoke persistent group from GO")
  384. invite(dev[0], dev[1], persistent_reconnect=False)
  385. ev = dev[1].wait_global_event(["P2P-INVITATION-RECEIVED"], timeout=15)
  386. if ev is None:
  387. raise Exception("No invitation request reported")
  388. if "persistent=" not in ev:
  389. raise Exception("Invalid invitation type reported: " + ev)
  390. ev2 = dev[0].wait_global_event(["P2P-INVITATION-RESULT"], timeout=15)
  391. if ev2 is None:
  392. raise Exception("No invitation response reported")
  393. if "status=1" not in ev2:
  394. raise Exception("Unexpected status: " + ev2)
  395. dev[0].p2p_listen()
  396. exp = r'<.>(P2P-INVITATION-RECEIVED) sa=([0-9a-f:]*) persistent=([0-9]*)'
  397. s = re.split(exp, ev)
  398. if len(s) < 4:
  399. raise Exception("Could not parse invitation event")
  400. sa = s[2]
  401. id = s[3]
  402. logger.info("Re-initiate invitation based on upper layer acceptance")
  403. if "OK" not in dev[1].global_request("P2P_INVITE persistent=" + id + " peer=" + sa + " freq=" + freq):
  404. raise Exception("Invitation command failed")
  405. [go_res, cli_res] = check_result(dev[0], dev[1])
  406. terminate_group(dev[0], dev[1])
  407. @remote_compatible
  408. def test_persistent_group_already_running(dev):
  409. """P2P persistent group formation and invitation while GO already running"""
  410. form(dev[0], dev[1])
  411. peer = dev[1].get_peer(dev[0].p2p_dev_addr())
  412. listen_freq = peer['listen_freq']
  413. dev[0].dump_monitor()
  414. dev[1].dump_monitor()
  415. networks = dev[0].list_networks(p2p=True)
  416. if len(networks) != 1:
  417. raise Exception("Unexpected number of networks")
  418. if "[P2P-PERSISTENT]" not in networks[0]['flags']:
  419. raise Exception("Not the persistent group data")
  420. if "OK" not in dev[0].global_request("P2P_GROUP_ADD persistent=" + networks[0]['id'] + " freq=" + listen_freq):
  421. raise Exception("Could not state GO")
  422. invite_from_cli(dev[0], dev[1])
  423. @remote_compatible
  424. def test_persistent_group_add_cli_chan(dev):
  425. """P2P persistent group formation and re-invocation with p2p_add_cli_chan=1"""
  426. try:
  427. dev[0].request("SET p2p_add_cli_chan 1")
  428. dev[1].request("SET p2p_add_cli_chan 1")
  429. form(dev[0], dev[1])
  430. dev[1].request("BSS_FLUSH 0")
  431. dev[1].scan(freq="2412", only_new=True)
  432. dev[1].scan(freq="2437", only_new=True)
  433. dev[1].scan(freq="2462", only_new=True)
  434. dev[1].request("BSS_FLUSH 0")
  435. invite_from_cli(dev[0], dev[1])
  436. invite_from_go(dev[0], dev[1])
  437. finally:
  438. dev[0].request("SET p2p_add_cli_chan 0")
  439. dev[1].request("SET p2p_add_cli_chan 0")
  440. @remote_compatible
  441. def test_persistent_invalid_group_add(dev):
  442. """Invalid P2P_GROUP_ADD command"""
  443. id = dev[0].add_network()
  444. if "FAIL" not in dev[0].global_request("P2P_GROUP_ADD persistent=12345"):
  445. raise Exception("Invalid P2P_GROUP_ADD accepted")
  446. if "FAIL" not in dev[0].global_request("P2P_GROUP_ADD persistent=%d" % id):
  447. raise Exception("Invalid P2P_GROUP_ADD accepted")
  448. if "FAIL" not in dev[0].global_request("P2P_GROUP_ADD foo"):
  449. raise Exception("Invalid P2P_GROUP_ADD accepted")
  450. def test_persistent_group_missed_inv_resp(dev):
  451. """P2P persistent group re-invocation with invitation response getting lost"""
  452. form(dev[0], dev[1])
  453. addr = dev[1].p2p_dev_addr()
  454. dev[1].global_request("SET persistent_reconnect 1")
  455. dev[1].p2p_listen()
  456. if not dev[0].discover_peer(addr, social=True):
  457. raise Exception("Peer " + addr + " not found")
  458. dev[0].dump_monitor()
  459. peer = dev[0].get_peer(addr)
  460. # Drop the first Invitation Response frame
  461. if "FAIL" in dev[0].request("SET ext_mgmt_frame_handling 1"):
  462. raise Exception("Failed to enable external management frame handling")
  463. cmd = "P2P_INVITE persistent=" + peer['persistent'] + " peer=" + addr
  464. dev[0].global_request(cmd)
  465. rx_msg = dev[0].mgmt_rx()
  466. if rx_msg is None:
  467. raise Exception("MGMT-RX timeout (no Invitation Response)")
  468. time.sleep(2)
  469. # Allow following Invitation Response frame to go through
  470. if "FAIL" in dev[0].request("SET ext_mgmt_frame_handling 0"):
  471. raise Exception("Failed to disable external management frame handling")
  472. time.sleep(1)
  473. # Force the P2P Client side to be on its Listen channel for retry
  474. dev[1].p2p_listen()
  475. ev = dev[0].wait_global_event(["P2P-INVITATION-RESULT"], timeout=15)
  476. if ev is None:
  477. raise Exception("Invitation result timed out")
  478. # Allow P2P Client side to continue connection-to-GO attempts
  479. dev[1].p2p_stop_find()
  480. # Verify that group re-invocation goes through
  481. ev = dev[1].wait_global_event([ "P2P-GROUP-STARTED",
  482. "P2P-GROUP-FORMATION-FAILURE" ],
  483. timeout=20)
  484. if ev is None:
  485. raise Exception("Group start event timed out")
  486. if "P2P-GROUP-STARTED" not in ev:
  487. raise Exception("Group re-invocation failed")
  488. dev[0].group_form_result(ev)
  489. ev = dev[0].wait_global_event([ "P2P-GROUP-STARTED" ], timeout=5)
  490. if ev is None:
  491. raise Exception("Group start event timed out on GO")
  492. dev[0].group_form_result(ev)
  493. terminate_group(dev[0], dev[1])
  494. @remote_compatible
  495. def test_persistent_group_profile_add(dev):
  496. """Create a P2P persistent group with ADD_NETWORK"""
  497. passphrase="passphrase here"
  498. id = dev[0].p2pdev_add_network()
  499. dev[0].p2pdev_set_network_quoted(id, "ssid", "DIRECT-ab")
  500. dev[0].p2pdev_set_network_quoted(id, "psk", passphrase)
  501. dev[0].p2pdev_set_network(id, "mode", "3")
  502. dev[0].p2pdev_set_network(id, "disabled", "2")
  503. dev[0].p2p_start_go(persistent=id, freq=2412)
  504. pin = dev[1].wps_read_pin()
  505. dev[0].p2p_go_authorize_client(pin)
  506. res = dev[1].p2p_connect_group(dev[0].p2p_dev_addr(), pin, timeout=60,
  507. social=True, freq=2412)
  508. if res['result'] != 'success':
  509. raise Exception("Joining the group did not succeed")
  510. dev[0].remove_group()
  511. dev[1].wait_go_ending_session()
  512. @remote_compatible
  513. def test_persistent_group_cancel_on_cli(dev):
  514. """P2P persistent group formation, re-invocation, and cancel"""
  515. dev[0].global_request("SET p2p_no_group_iface 0")
  516. dev[1].global_request("SET p2p_no_group_iface 0")
  517. form(dev[0], dev[1])
  518. invite_from_go(dev[0], dev[1], terminate=False)
  519. if "FAIL" not in dev[1].global_request("P2P_CANCEL"):
  520. raise Exception("P2P_CANCEL succeeded unexpectedly on CLI")
  521. if "FAIL" not in dev[0].global_request("P2P_CANCEL"):
  522. raise Exception("P2P_CANCEL succeeded unexpectedly on GO")
  523. terminate_group(dev[0], dev[1])
  524. invite_from_cli(dev[0], dev[1], terminate=False)
  525. if "FAIL" not in dev[1].global_request("P2P_CANCEL"):
  526. raise Exception("P2P_CANCEL succeeded unexpectedly on CLI")
  527. if "FAIL" not in dev[0].global_request("P2P_CANCEL"):
  528. raise Exception("P2P_CANCEL succeeded unexpectedly on GO")
  529. terminate_group(dev[0], dev[1])
  530. @remote_compatible
  531. def test_persistent_group_cancel_on_cli2(dev):
  532. """P2P persistent group formation, re-invocation, and cancel (2)"""
  533. form(dev[0], dev[1])
  534. invite_from_go(dev[0], dev[1], terminate=False)
  535. if "FAIL" not in dev[1].global_request("P2P_CANCEL"):
  536. raise Exception("P2P_CANCEL succeeded unexpectedly on CLI")
  537. if "FAIL" not in dev[0].global_request("P2P_CANCEL"):
  538. raise Exception("P2P_CANCEL succeeded unexpectedly on GO")
  539. terminate_group(dev[0], dev[1])
  540. invite_from_cli(dev[0], dev[1], terminate=False)
  541. if "FAIL" not in dev[1].global_request("P2P_CANCEL"):
  542. raise Exception("P2P_CANCEL succeeded unexpectedly on CLI")
  543. if "FAIL" not in dev[0].global_request("P2P_CANCEL"):
  544. raise Exception("P2P_CANCEL succeeded unexpectedly on GO")
  545. terminate_group(dev[0], dev[1])
  546. @remote_compatible
  547. def test_persistent_group_peer_dropped(dev):
  548. """P2P persistent group formation and re-invocation with peer having dropped group"""
  549. form(dev[0], dev[1], reverse_init=True)
  550. invite_from_cli(dev[0], dev[1])
  551. logger.info("Remove group on the GO and try to invite from the client")
  552. dev[0].global_request("REMOVE_NETWORK all")
  553. invite(dev[1], dev[0])
  554. ev = dev[1].wait_global_event(["P2P-INVITATION-RESULT"], timeout=10)
  555. if ev is None:
  556. raise Exception("No invitation result seen")
  557. if "status=8" not in ev:
  558. raise Exception("Unexpected invitation result: " + ev)
  559. networks = dev[1].list_networks(p2p=True)
  560. if len(networks) > 0:
  561. raise Exception("Unexpected network block on client")
  562. logger.info("Verify that a new group can be formed")
  563. form(dev[0], dev[1], reverse_init=True)
  564. @remote_compatible
  565. def test_persistent_group_peer_dropped2(dev):
  566. """P2P persistent group formation and re-invocation with peer having dropped group (2)"""
  567. form(dev[0], dev[1])
  568. invite_from_go(dev[0], dev[1])
  569. logger.info("Remove group on the client and try to invite from the GO")
  570. dev[1].global_request("REMOVE_NETWORK all")
  571. invite(dev[0], dev[1])
  572. ev = dev[0].wait_global_event(["P2P-INVITATION-RESULT"], timeout=10)
  573. if ev is None:
  574. raise Exception("No invitation result seen")
  575. if "status=8" not in ev:
  576. raise Exception("Unexpected invitation result: " + ev)
  577. networks = dev[1].list_networks(p2p=True)
  578. if len(networks) > 0:
  579. raise Exception("Unexpected network block on client")
  580. logger.info("Verify that a new group can be formed")
  581. form(dev[0], dev[1])
  582. def test_persistent_group_peer_dropped3(dev):
  583. """P2P persistent group formation and re-invocation with peer having dropped group (3)"""
  584. form(dev[0], dev[1], reverse_init=True)
  585. invite_from_cli(dev[0], dev[1])
  586. logger.info("Remove group on the GO and try to invite from the client")
  587. dev[0].global_request("REMOVE_NETWORK all")
  588. invite(dev[1], dev[0], use_listen=False)
  589. ev = dev[1].wait_global_event(["P2P-INVITATION-RESULT"], timeout=10)
  590. if ev is None:
  591. raise Exception("No invitation result seen")
  592. if "status=8" not in ev:
  593. raise Exception("Unexpected invitation result: " + ev)
  594. networks = dev[1].list_networks(p2p=True)
  595. if len(networks) > 0:
  596. raise Exception("Unexpected network block on client")
  597. time.sleep(0.2)
  598. logger.info("Verify that a new group can be formed")
  599. form(dev[0], dev[1], reverse_init=True, r_listen=False)