test_p2p_concurrency.py 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287
  1. # P2P concurrency test cases
  2. # Copyright (c) 2013-2015, 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 subprocess
  10. import time
  11. import hwsim_utils
  12. import hostapd
  13. from p2p_utils import *
  14. from test_ap_ht import clear_scan_cache
  15. from utils import HwsimSkip
  16. @remote_compatible
  17. def test_concurrent_autogo(dev, apdev):
  18. """Concurrent P2P autonomous GO"""
  19. logger.info("Connect to an infrastructure AP")
  20. dev[0].request("P2P_SET cross_connect 0")
  21. hapd = hostapd.add_ap(apdev[0], { "ssid": "test-open" })
  22. dev[0].connect("test-open", key_mgmt="NONE", scan_freq="2412")
  23. hwsim_utils.test_connectivity(dev[0], hapd)
  24. logger.info("Start a P2P group while associated to an AP")
  25. dev[0].global_request("SET p2p_no_group_iface 0")
  26. dev[0].p2p_start_go()
  27. pin = dev[1].wps_read_pin()
  28. dev[0].p2p_go_authorize_client(pin)
  29. dev[1].p2p_connect_group(dev[0].p2p_dev_addr(), pin, timeout=60,
  30. social=True)
  31. hwsim_utils.test_connectivity_p2p(dev[0], dev[1])
  32. dev[0].remove_group()
  33. dev[1].wait_go_ending_session()
  34. logger.info("Confirm AP connection after P2P group removal")
  35. hwsim_utils.test_connectivity(dev[0], hapd)
  36. def test_concurrent_autogo_5ghz_ht40(dev, apdev):
  37. """Concurrent P2P autonomous GO on 5 GHz and HT40 co-ex"""
  38. clear_scan_cache(apdev[1])
  39. try:
  40. hapd = None
  41. hapd2 = None
  42. params = { "ssid": "ht40",
  43. "hw_mode": "a",
  44. "channel": "153",
  45. "country_code": "US",
  46. "ht_capab": "[HT40-]" }
  47. hapd2 = hostapd.add_ap(apdev[1], params)
  48. params = { "ssid": "test-open-5",
  49. "hw_mode": "a",
  50. "channel": "149",
  51. "country_code": "US" }
  52. hapd = hostapd.add_ap(apdev[0], params)
  53. dev[0].request("P2P_SET cross_connect 0")
  54. dev[0].scan_for_bss(apdev[0]['bssid'], freq=5745)
  55. dev[0].scan_for_bss(apdev[1]['bssid'], freq=5765)
  56. dev[0].connect("test-open-5", key_mgmt="NONE", scan_freq="5745")
  57. dev[0].global_request("SET p2p_no_group_iface 0")
  58. if "OK" not in dev[0].global_request("P2P_GROUP_ADD ht40"):
  59. raise Exception("P2P_GROUP_ADD failed")
  60. ev = dev[0].wait_global_event(["P2P-GROUP-STARTED"], timeout=5)
  61. if ev is None:
  62. raise Exception("GO start up timed out")
  63. dev[0].group_form_result(ev)
  64. pin = dev[1].wps_read_pin()
  65. dev[0].p2p_go_authorize_client(pin)
  66. dev[1].p2p_find(freq=5745)
  67. addr0 = dev[0].p2p_dev_addr()
  68. count = 0
  69. while count < 10:
  70. time.sleep(0.25)
  71. count += 1
  72. if dev[1].peer_known(addr0):
  73. break
  74. dev[1].p2p_connect_group(addr0, pin, timeout=60)
  75. dev[0].remove_group()
  76. dev[1].wait_go_ending_session()
  77. finally:
  78. dev[0].request("REMOVE_NETWORK all")
  79. if hapd:
  80. hapd.request("DISABLE")
  81. if hapd2:
  82. hapd2.request("DISABLE")
  83. subprocess.call(['iw', 'reg', 'set', '00'])
  84. dev[0].flush_scan_cache()
  85. dev[1].flush_scan_cache()
  86. def test_concurrent_autogo_crossconnect(dev, apdev):
  87. """Concurrent P2P autonomous GO"""
  88. dev[0].global_request("P2P_SET cross_connect 1")
  89. hapd = hostapd.add_ap(apdev[0], { "ssid": "test-open" })
  90. dev[0].connect("test-open", key_mgmt="NONE", scan_freq="2412")
  91. dev[0].global_request("SET p2p_no_group_iface 0")
  92. dev[0].p2p_start_go(no_event_clear=True)
  93. ev = dev[0].wait_global_event("P2P-CROSS-CONNECT-ENABLE", timeout=10)
  94. if ev is None:
  95. raise Exception("Timeout on cross connection enabled event")
  96. if dev[0].group_ifname + " " + dev[0].ifname not in ev:
  97. raise Exception("Unexpected interfaces: " + ev)
  98. dev[0].dump_monitor()
  99. dev[0].global_request("P2P_SET cross_connect 0")
  100. ev = dev[0].wait_global_event("P2P-CROSS-CONNECT-DISABLE", timeout=10)
  101. if ev is None:
  102. raise Exception("Timeout on cross connection disabled event")
  103. if dev[0].group_ifname + " " + dev[0].ifname not in ev:
  104. raise Exception("Unexpected interfaces: " + ev)
  105. dev[0].remove_group()
  106. dev[0].global_request("P2P_SET cross_connect 1")
  107. dev[0].p2p_start_go(no_event_clear=True)
  108. ev = dev[0].wait_global_event("P2P-CROSS-CONNECT-ENABLE", timeout=10)
  109. if ev is None:
  110. raise Exception("Timeout on cross connection enabled event")
  111. if dev[0].group_ifname + " " + dev[0].ifname not in ev:
  112. raise Exception("Unexpected interfaces: " + ev)
  113. dev[0].dump_monitor()
  114. dev[0].remove_group()
  115. ev = dev[0].wait_global_event("P2P-CROSS-CONNECT-DISABLE", timeout=10)
  116. if ev is None:
  117. raise Exception("Timeout on cross connection disabled event")
  118. dev[0].global_request("P2P_SET cross_connect 0")
  119. @remote_compatible
  120. def test_concurrent_p2pcli(dev, apdev):
  121. """Concurrent P2P client join"""
  122. logger.info("Connect to an infrastructure AP")
  123. hapd = hostapd.add_ap(apdev[0], { "ssid": "test-open" })
  124. dev[0].connect("test-open", key_mgmt="NONE", scan_freq="2412")
  125. hwsim_utils.test_connectivity(dev[0], hapd)
  126. logger.info("Join a P2P group while associated to an AP")
  127. dev[0].global_request("SET p2p_no_group_iface 0")
  128. dev[1].p2p_start_go(freq=2412)
  129. pin = dev[0].wps_read_pin()
  130. dev[1].p2p_go_authorize_client(pin)
  131. dev[0].p2p_connect_group(dev[1].p2p_dev_addr(), pin, timeout=60,
  132. social=True)
  133. hwsim_utils.test_connectivity_p2p(dev[0], dev[1])
  134. dev[1].remove_group()
  135. dev[0].wait_go_ending_session()
  136. logger.info("Confirm AP connection after P2P group removal")
  137. hwsim_utils.test_connectivity(dev[0], hapd)
  138. @remote_compatible
  139. def test_concurrent_grpform_go(dev, apdev):
  140. """Concurrent P2P group formation to become GO"""
  141. logger.info("Connect to an infrastructure AP")
  142. hapd = hostapd.add_ap(apdev[0], { "ssid": "test-open" })
  143. dev[0].connect("test-open", key_mgmt="NONE", scan_freq="2412")
  144. hwsim_utils.test_connectivity(dev[0], hapd)
  145. logger.info("Form a P2P group while associated to an AP")
  146. dev[0].global_request("SET p2p_no_group_iface 0")
  147. [i_res, r_res] = go_neg_pin_authorized(i_dev=dev[0], i_intent=15,
  148. r_dev=dev[1], r_intent=0)
  149. check_grpform_results(i_res, r_res)
  150. remove_group(dev[0], dev[1])
  151. logger.info("Confirm AP connection after P2P group removal")
  152. hwsim_utils.test_connectivity(dev[0], hapd)
  153. @remote_compatible
  154. def test_concurrent_grpform_cli(dev, apdev):
  155. """Concurrent P2P group formation to become P2P Client"""
  156. logger.info("Connect to an infrastructure AP")
  157. hapd = hostapd.add_ap(apdev[0], { "ssid": "test-open" })
  158. dev[0].connect("test-open", key_mgmt="NONE", scan_freq="2412")
  159. hwsim_utils.test_connectivity(dev[0], hapd)
  160. logger.info("Form a P2P group while associated to an AP")
  161. dev[0].global_request("SET p2p_no_group_iface 0")
  162. [i_res, r_res] = go_neg_pin_authorized(i_dev=dev[0], i_intent=0,
  163. r_dev=dev[1], r_intent=15)
  164. check_grpform_results(i_res, r_res)
  165. remove_group(dev[0], dev[1])
  166. logger.info("Confirm AP connection after P2P group removal")
  167. hwsim_utils.test_connectivity(dev[0], hapd)
  168. @remote_compatible
  169. def test_concurrent_grpform_while_connecting(dev, apdev):
  170. """Concurrent P2P group formation while connecting to an AP"""
  171. logger.info("Start connection to an infrastructure AP")
  172. hapd = hostapd.add_ap(apdev[0], { "ssid": "test-open" })
  173. dev[0].connect("test-open", key_mgmt="NONE", wait_connect=False)
  174. logger.info("Form a P2P group while connecting to an AP")
  175. dev[0].global_request("SET p2p_no_group_iface 0")
  176. [i_res, r_res] = go_neg_pin_authorized(i_dev=dev[0], i_freq=2412,
  177. r_dev=dev[1], r_freq=2412)
  178. check_grpform_results(i_res, r_res)
  179. remove_group(dev[0], dev[1])
  180. logger.info("Confirm AP connection after P2P group removal")
  181. hwsim_utils.test_connectivity(dev[0], hapd)
  182. @remote_compatible
  183. def test_concurrent_grpform_while_connecting2(dev, apdev):
  184. """Concurrent P2P group formation while connecting to an AP (2)"""
  185. logger.info("Start connection to an infrastructure AP")
  186. hapd = hostapd.add_ap(apdev[0], { "ssid": "test-open" })
  187. dev[0].connect("test-open", key_mgmt="NONE", wait_connect=False)
  188. dev[1].flush_scan_cache()
  189. logger.info("Form a P2P group while connecting to an AP")
  190. dev[0].global_request("SET p2p_no_group_iface 0")
  191. [i_res, r_res] = go_neg_pbc(i_dev=dev[0], i_intent=15, i_freq=2412,
  192. r_dev=dev[1], r_intent=0, r_freq=2412)
  193. check_grpform_results(i_res, r_res)
  194. remove_group(dev[0], dev[1])
  195. logger.info("Confirm AP connection after P2P group removal")
  196. dev[0].wait_completed()
  197. hwsim_utils.test_connectivity(dev[0], hapd)
  198. @remote_compatible
  199. def test_concurrent_grpform_while_connecting3(dev, apdev):
  200. """Concurrent P2P group formation while connecting to an AP (3)"""
  201. logger.info("Start connection to an infrastructure AP")
  202. hapd = hostapd.add_ap(apdev[0], { "ssid": "test-open" })
  203. dev[0].connect("test-open", key_mgmt="NONE", wait_connect=False)
  204. logger.info("Form a P2P group while connecting to an AP")
  205. dev[0].global_request("SET p2p_no_group_iface 0")
  206. [i_res, r_res] = go_neg_pbc(i_dev=dev[1], i_intent=15, i_freq=2412,
  207. r_dev=dev[0], r_intent=0, r_freq=2412)
  208. check_grpform_results(i_res, r_res)
  209. remove_group(dev[0], dev[1])
  210. logger.info("Confirm AP connection after P2P group removal")
  211. dev[0].wait_completed()
  212. hwsim_utils.test_connectivity(dev[0], hapd)
  213. @remote_compatible
  214. def test_concurrent_persistent_group(dev, apdev):
  215. """Concurrent P2P persistent group"""
  216. logger.info("Connect to an infrastructure AP")
  217. hostapd.add_ap(apdev[0], { "ssid": "test-open", "channel": "2" })
  218. dev[0].global_request("SET p2p_no_group_iface 0")
  219. dev[0].connect("test-open", key_mgmt="NONE", scan_freq="2417")
  220. logger.info("Run persistent group test while associated to an AP")
  221. form(dev[0], dev[1])
  222. [go_res, cli_res] = invite_from_cli(dev[0], dev[1])
  223. if go_res['freq'] != '2417':
  224. raise Exception("Unexpected channel selected: " + go_res['freq'])
  225. [go_res, cli_res] = invite_from_go(dev[0], dev[1])
  226. if go_res['freq'] != '2417':
  227. raise Exception("Unexpected channel selected: " + go_res['freq'])
  228. def test_concurrent_invitation_channel_mismatch(dev, apdev):
  229. """P2P persistent group invitation and channel mismatch"""
  230. if dev[0].get_mcc() > 1:
  231. raise HwsimSkip("Skip due to MCC being enabled")
  232. form(dev[0], dev[1])
  233. dev[0].dump_monitor()
  234. dev[1].dump_monitor()
  235. logger.info("Connect to an infrastructure AP")
  236. hostapd.add_ap(apdev[0], { "ssid": "test-open", "channel": "2" })
  237. dev[0].global_request("SET p2p_no_group_iface 0")
  238. dev[0].connect("test-open", key_mgmt="NONE", scan_freq="2417")
  239. invite(dev[1], dev[0], extra="freq=2412")
  240. ev = dev[1].wait_global_event(["P2P-INVITATION-RESULT"], timeout=15)
  241. if ev is None:
  242. raise Exception("P2P invitation result not received")
  243. if "status=7" not in ev:
  244. raise Exception("Unexpected P2P invitation result: " + ev)