test_p2p_concurrency.py 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186
  1. # P2P concurrency test cases
  2. # Copyright (c) 2013, 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 logging
  7. logger = logging.getLogger()
  8. import time
  9. import hwsim_utils
  10. import hostapd
  11. from test_p2p_grpform import go_neg_pin_authorized
  12. from test_p2p_grpform import go_neg_pbc
  13. from test_p2p_grpform import check_grpform_results
  14. from test_p2p_grpform import remove_group
  15. from test_p2p_persistent import form
  16. from test_p2p_persistent import invite_from_cli
  17. from test_p2p_persistent import invite_from_go
  18. from test_p2p_persistent import invite
  19. def test_concurrent_autogo(dev, apdev):
  20. """Concurrent P2P autonomous GO"""
  21. logger.info("Connect to an infrastructure AP")
  22. hostapd.add_ap(apdev[0]['ifname'], { "ssid": "test-open" })
  23. dev[0].connect("test-open", key_mgmt="NONE", scan_freq="2412")
  24. hwsim_utils.test_connectivity(dev[0].ifname, apdev[0]['ifname'])
  25. logger.info("Start a P2P group while associated to an AP")
  26. dev[0].request("SET p2p_no_group_iface 0")
  27. dev[0].p2p_start_go()
  28. pin = dev[1].wps_read_pin()
  29. dev[0].p2p_go_authorize_client(pin)
  30. dev[1].p2p_connect_group(dev[0].p2p_dev_addr(), pin, timeout=60,
  31. social=True)
  32. hwsim_utils.test_connectivity_p2p(dev[0], dev[1])
  33. dev[0].remove_group()
  34. dev[1].wait_go_ending_session()
  35. logger.info("Confirm AP connection after P2P group removal")
  36. hwsim_utils.test_connectivity(dev[0].ifname, apdev[0]['ifname'])
  37. def test_concurrent_p2pcli(dev, apdev):
  38. """Concurrent P2P client join"""
  39. logger.info("Connect to an infrastructure AP")
  40. hostapd.add_ap(apdev[0]['ifname'], { "ssid": "test-open" })
  41. dev[0].connect("test-open", key_mgmt="NONE", scan_freq="2412")
  42. hwsim_utils.test_connectivity(dev[0].ifname, apdev[0]['ifname'])
  43. logger.info("Join a P2P group while associated to an AP")
  44. dev[0].request("SET p2p_no_group_iface 0")
  45. dev[1].p2p_start_go(freq=2412)
  46. pin = dev[0].wps_read_pin()
  47. dev[1].p2p_go_authorize_client(pin)
  48. dev[0].p2p_connect_group(dev[1].p2p_dev_addr(), pin, timeout=60,
  49. social=True)
  50. hwsim_utils.test_connectivity_p2p(dev[0], dev[1])
  51. dev[1].remove_group()
  52. dev[0].wait_go_ending_session()
  53. logger.info("Confirm AP connection after P2P group removal")
  54. hwsim_utils.test_connectivity(dev[0].ifname, apdev[0]['ifname'])
  55. def test_concurrent_grpform_go(dev, apdev):
  56. """Concurrent P2P group formation to become GO"""
  57. logger.info("Connect to an infrastructure AP")
  58. hostapd.add_ap(apdev[0]['ifname'], { "ssid": "test-open" })
  59. dev[0].connect("test-open", key_mgmt="NONE", scan_freq="2412")
  60. hwsim_utils.test_connectivity(dev[0].ifname, apdev[0]['ifname'])
  61. logger.info("Form a P2P group while associated to an AP")
  62. dev[0].request("SET p2p_no_group_iface 0")
  63. [i_res, r_res] = go_neg_pin_authorized(i_dev=dev[0], i_intent=15,
  64. r_dev=dev[1], r_intent=0)
  65. check_grpform_results(i_res, r_res)
  66. remove_group(dev[0], dev[1])
  67. logger.info("Confirm AP connection after P2P group removal")
  68. hwsim_utils.test_connectivity(dev[0].ifname, apdev[0]['ifname'])
  69. def test_concurrent_grpform_cli(dev, apdev):
  70. """Concurrent P2P group formation to become P2P Client"""
  71. logger.info("Connect to an infrastructure AP")
  72. hostapd.add_ap(apdev[0]['ifname'], { "ssid": "test-open" })
  73. dev[0].connect("test-open", key_mgmt="NONE", scan_freq="2412")
  74. hwsim_utils.test_connectivity(dev[0].ifname, apdev[0]['ifname'])
  75. logger.info("Form a P2P group while associated to an AP")
  76. dev[0].request("SET p2p_no_group_iface 0")
  77. [i_res, r_res] = go_neg_pin_authorized(i_dev=dev[0], i_intent=0,
  78. r_dev=dev[1], r_intent=15)
  79. check_grpform_results(i_res, r_res)
  80. remove_group(dev[0], dev[1])
  81. logger.info("Confirm AP connection after P2P group removal")
  82. hwsim_utils.test_connectivity(dev[0].ifname, apdev[0]['ifname'])
  83. def test_concurrent_grpform_while_connecting(dev, apdev):
  84. """Concurrent P2P group formation while connecting to an AP"""
  85. logger.info("Start connection to an infrastructure AP")
  86. hostapd.add_ap(apdev[0]['ifname'], { "ssid": "test-open" })
  87. dev[0].connect("test-open", key_mgmt="NONE", wait_connect=False)
  88. logger.info("Form a P2P group while connecting to an AP")
  89. dev[0].request("SET p2p_no_group_iface 0")
  90. [i_res, r_res] = go_neg_pin_authorized(i_dev=dev[0], i_freq=2412,
  91. r_dev=dev[1], r_freq=2412)
  92. check_grpform_results(i_res, r_res)
  93. remove_group(dev[0], dev[1])
  94. logger.info("Confirm AP connection after P2P group removal")
  95. hwsim_utils.test_connectivity(dev[0].ifname, apdev[0]['ifname'])
  96. def test_concurrent_grpform_while_connecting2(dev, apdev):
  97. """Concurrent P2P group formation while connecting to an AP (2)"""
  98. logger.info("Start connection to an infrastructure AP")
  99. hostapd.add_ap(apdev[0]['ifname'], { "ssid": "test-open" })
  100. dev[0].connect("test-open", key_mgmt="NONE", wait_connect=False)
  101. dev[1].request("BSS_FLUSH 0")
  102. dev[1].scan(freq="2412", only_new=True)
  103. logger.info("Form a P2P group while connecting to an AP")
  104. dev[0].request("SET p2p_no_group_iface 0")
  105. [i_res, r_res] = go_neg_pbc(i_dev=dev[0], i_intent=15, i_freq=2412,
  106. r_dev=dev[1], r_intent=0, r_freq=2412)
  107. check_grpform_results(i_res, r_res)
  108. remove_group(dev[0], dev[1])
  109. logger.info("Confirm AP connection after P2P group removal")
  110. dev[0].wait_completed()
  111. hwsim_utils.test_connectivity(dev[0].ifname, apdev[0]['ifname'])
  112. def test_concurrent_grpform_while_connecting3(dev, apdev):
  113. """Concurrent P2P group formation while connecting to an AP (3)"""
  114. logger.info("Start connection to an infrastructure AP")
  115. hostapd.add_ap(apdev[0]['ifname'], { "ssid": "test-open" })
  116. dev[0].connect("test-open", key_mgmt="NONE", wait_connect=False)
  117. logger.info("Form a P2P group while connecting to an AP")
  118. dev[0].request("SET p2p_no_group_iface 0")
  119. [i_res, r_res] = go_neg_pbc(i_dev=dev[1], i_intent=15, i_freq=2412,
  120. r_dev=dev[0], r_intent=0, r_freq=2412)
  121. check_grpform_results(i_res, r_res)
  122. remove_group(dev[0], dev[1])
  123. logger.info("Confirm AP connection after P2P group removal")
  124. dev[0].wait_completed()
  125. hwsim_utils.test_connectivity(dev[0].ifname, apdev[0]['ifname'])
  126. def test_concurrent_persistent_group(dev, apdev):
  127. """Concurrent P2P persistent group"""
  128. logger.info("Connect to an infrastructure AP")
  129. hostapd.add_ap(apdev[0]['ifname'], { "ssid": "test-open", "channel": "2" })
  130. dev[0].request("SET p2p_no_group_iface 0")
  131. dev[0].connect("test-open", key_mgmt="NONE", scan_freq="2417")
  132. logger.info("Run persistent group test while associated to an AP")
  133. form(dev[0], dev[1])
  134. [go_res, cli_res] = invite_from_cli(dev[0], dev[1])
  135. if go_res['freq'] != '2417':
  136. raise Exception("Unexpected channel selected: " + go_res['freq'])
  137. [go_res, cli_res] = invite_from_go(dev[0], dev[1])
  138. if go_res['freq'] != '2417':
  139. raise Exception("Unexpected channel selected: " + go_res['freq'])
  140. def test_concurrent_invitation_channel_mismatch(dev, apdev):
  141. """P2P persistent group invitation and channel mismatch"""
  142. form(dev[0], dev[1])
  143. dev[0].dump_monitor()
  144. dev[1].dump_monitor()
  145. logger.info("Connect to an infrastructure AP")
  146. hostapd.add_ap(apdev[0]['ifname'], { "ssid": "test-open", "channel": "2" })
  147. dev[0].request("SET p2p_no_group_iface 0")
  148. dev[0].connect("test-open", key_mgmt="NONE", scan_freq="2417")
  149. invite(dev[1], dev[0], extra="freq=2412")
  150. ev = dev[1].wait_global_event(["P2P-INVITATION-RESULT"], timeout=15)
  151. if ev is None:
  152. raise Exception("P2P invitation result not received")
  153. if "status=7" not in ev:
  154. raise Exception("Unexpected P2P invitation result: " + ev)