test_p2p_autogo.py 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211
  1. #!/usr/bin/python
  2. #
  3. # P2P autonomous GO test cases
  4. # Copyright (c) 2013, Jouni Malinen <j@w1.fi>
  5. #
  6. # This software may be distributed under the terms of the BSD license.
  7. # See README for more details.
  8. import time
  9. import subprocess
  10. import logging
  11. logger = logging.getLogger()
  12. import hwsim_utils
  13. import utils
  14. from wlantest import Wlantest
  15. def autogo(go, freq=None):
  16. logger.info("Start autonomous GO " + go.ifname)
  17. res = go.p2p_start_go(freq=freq)
  18. logger.debug("res: " + str(res))
  19. return res
  20. def connect_cli(go, client):
  21. logger.info("Try to connect the client to the GO")
  22. pin = client.wps_read_pin()
  23. go.p2p_go_authorize_client(pin)
  24. res = client.p2p_connect_group(go.p2p_dev_addr(), pin, timeout=60)
  25. logger.info("Client connected")
  26. hwsim_utils.test_connectivity_p2p(go, client)
  27. return res
  28. def test_autogo(dev):
  29. """P2P autonomous GO and client joining group"""
  30. res = autogo(dev[0])
  31. if "p2p-wlan" in res['ifname']:
  32. raise Exception("Unexpected group interface name on GO")
  33. res = connect_cli(dev[0], dev[1])
  34. if "p2p-wlan" in res['ifname']:
  35. raise Exception("Unexpected group interface name on client")
  36. dev[0].remove_group()
  37. dev[1].wait_go_ending_session()
  38. def test_autogo2(dev):
  39. """P2P autonomous GO with a separate group interface and client joining group"""
  40. dev[0].request("SET p2p_no_group_iface 0")
  41. res = autogo(dev[0])
  42. if "p2p-wlan" not in res['ifname']:
  43. raise Exception("Unexpected group interface name on GO")
  44. if res['ifname'] not in utils.get_ifnames():
  45. raise Exception("Could not find group interface netdev")
  46. connect_cli(dev[0], dev[1])
  47. dev[0].remove_group()
  48. dev[1].wait_go_ending_session()
  49. if res['ifname'] in utils.get_ifnames():
  50. raise Exception("Group interface netdev was not removed")
  51. def test_autogo3(dev):
  52. """P2P autonomous GO and client with a separate group interface joining group"""
  53. dev[1].request("SET p2p_no_group_iface 0")
  54. autogo(dev[0])
  55. res = connect_cli(dev[0], dev[1])
  56. if "p2p-wlan" not in res['ifname']:
  57. raise Exception("Unexpected group interface name on client")
  58. if res['ifname'] not in utils.get_ifnames():
  59. raise Exception("Could not find group interface netdev")
  60. dev[0].remove_group()
  61. dev[1].wait_go_ending_session()
  62. dev[1].ping()
  63. if res['ifname'] in utils.get_ifnames():
  64. raise Exception("Group interface netdev was not removed")
  65. def test_autogo4(dev):
  66. """P2P autonomous GO and client joining group (both with a separate group interface)"""
  67. dev[0].request("SET p2p_no_group_iface 0")
  68. dev[1].request("SET p2p_no_group_iface 0")
  69. res1 = autogo(dev[0])
  70. res2 = connect_cli(dev[0], dev[1])
  71. if "p2p-wlan" not in res1['ifname']:
  72. raise Exception("Unexpected group interface name on GO")
  73. if "p2p-wlan" not in res2['ifname']:
  74. raise Exception("Unexpected group interface name on client")
  75. ifnames = utils.get_ifnames()
  76. if res1['ifname'] not in ifnames:
  77. raise Exception("Could not find GO group interface netdev")
  78. if res2['ifname'] not in ifnames:
  79. raise Exception("Could not find client group interface netdev")
  80. dev[0].remove_group()
  81. dev[1].wait_go_ending_session()
  82. dev[1].ping()
  83. ifnames = utils.get_ifnames()
  84. if res1['ifname'] in ifnames:
  85. raise Exception("GO group interface netdev was not removed")
  86. if res2['ifname'] in ifnames:
  87. raise Exception("Client group interface netdev was not removed")
  88. def test_autogo_2cli(dev):
  89. """P2P autonomous GO and two clients joining group"""
  90. autogo(dev[0])
  91. connect_cli(dev[0], dev[1])
  92. connect_cli(dev[0], dev[2])
  93. hwsim_utils.test_connectivity_p2p(dev[1], dev[2])
  94. dev[0].global_request("P2P_REMOVE_CLIENT " + dev[1].p2p_dev_addr())
  95. dev[1].wait_go_ending_session()
  96. dev[0].remove_group()
  97. dev[2].wait_go_ending_session()
  98. def test_autogo_tdls(dev):
  99. """P2P autonomous GO and two clients using TDLS"""
  100. wt = Wlantest()
  101. go = dev[0]
  102. logger.info("Start autonomous GO with fixed parameters " + go.ifname)
  103. id = go.add_network()
  104. go.set_network_quoted(id, "ssid", "DIRECT-tdls")
  105. go.set_network_quoted(id, "psk", "12345678")
  106. go.set_network(id, "mode", "3")
  107. go.set_network(id, "disabled", "2")
  108. res = go.p2p_start_go(persistent=id)
  109. logger.debug("res: " + str(res))
  110. wt.flush()
  111. wt.add_passphrase("12345678")
  112. connect_cli(go, dev[1])
  113. connect_cli(go, dev[2])
  114. hwsim_utils.test_connectivity_p2p(dev[1], dev[2])
  115. bssid = dev[0].p2p_interface_addr()
  116. addr1 = dev[1].p2p_interface_addr()
  117. addr2 = dev[2].p2p_interface_addr()
  118. dev[1].tdls_setup(addr2)
  119. time.sleep(1)
  120. hwsim_utils.test_connectivity_p2p(dev[1], dev[2])
  121. conf = wt.get_tdls_counter("setup_conf_ok", bssid, addr1, addr2);
  122. if conf == 0:
  123. raise Exception("No TDLS Setup Confirm (success) seen")
  124. dl = wt.get_tdls_counter("valid_direct_link", bssid, addr1, addr2);
  125. if dl == 0:
  126. raise Exception("No valid frames through direct link")
  127. wt.tdls_clear(bssid, addr1, addr2);
  128. dev[1].tdls_teardown(addr2)
  129. time.sleep(1)
  130. teardown = wt.get_tdls_counter("teardown", bssid, addr1, addr2);
  131. if teardown == 0:
  132. raise Exception("No TDLS Setup Teardown seen")
  133. wt.tdls_clear(bssid, addr1, addr2);
  134. hwsim_utils.test_connectivity_p2p(dev[1], dev[2])
  135. ap_path = wt.get_tdls_counter("valid_ap_path", bssid, addr1, addr2);
  136. if ap_path == 0:
  137. raise Exception("No valid frames via AP path")
  138. direct_link = wt.get_tdls_counter("valid_direct_link", bssid, addr1, addr2);
  139. if direct_link > 0:
  140. raise Exception("Unexpected frames through direct link")
  141. idirect_link = wt.get_tdls_counter("invalid_direct_link", bssid, addr1,
  142. addr2);
  143. if idirect_link > 0:
  144. raise Exception("Unexpected frames through direct link (invalid)")
  145. dev[2].remove_group()
  146. dev[1].remove_group()
  147. dev[0].remove_group()
  148. def test_autogo_legacy(dev):
  149. """P2P autonomous GO and legacy clients"""
  150. res = autogo(dev[0])
  151. logger.info("Connect P2P client")
  152. connect_cli(dev[0], dev[1])
  153. logger.info("Connect legacy WPS client")
  154. pin = dev[2].wps_read_pin()
  155. dev[0].p2p_go_authorize_client(pin)
  156. dev[2].request("SET ignore_old_scan_res 1")
  157. dev[2].request("P2P_SET disabled 1")
  158. dev[2].dump_monitor()
  159. dev[2].request("WPS_PIN any " + pin)
  160. ev = dev[2].wait_event(["CTRL-EVENT-CONNECTED"], timeout=30)
  161. if ev is None:
  162. raise Exception("Association with the GO timed out")
  163. status = dev[2].get_status()
  164. if status['wpa_state'] != 'COMPLETED':
  165. raise Exception("Not fully connected")
  166. hwsim_utils.test_connectivity_p2p_sta(dev[1], dev[2])
  167. dev[2].request("DISCONNECT")
  168. logger.info("Connect legacy non-WPS client")
  169. dev[2].request("FLUSH")
  170. dev[2].request("P2P_SET disabled 1")
  171. dev[2].connect(ssid=res['ssid'], psk=res['passphrase'], proto='RSN',
  172. key_mgmt='WPA-PSK', pairwise='CCMP', group='CCMP',
  173. scan_freq=res['freq'])
  174. hwsim_utils.test_connectivity_p2p_sta(dev[1], dev[2])
  175. dev[2].request("DISCONNECT")
  176. dev[0].remove_group()
  177. dev[1].wait_go_ending_session()
  178. def test_autogo_chan_switch(dev):
  179. """P2P autonomous GO switching channels"""
  180. autogo(dev[0], freq=2417)
  181. connect_cli(dev[0], dev[1])
  182. res = dev[0].request("CHAN_SWITCH 5 2422")
  183. if "FAIL" in res:
  184. # for now, skip test since mac80211_hwsim support is not yet widely
  185. # deployed
  186. return 'skip'
  187. ev = dev[0].wait_event(["AP-CSA-FINISHED"], timeout=10)
  188. if ev is None:
  189. raise Exception("CSA finished event timed out")
  190. if "freq=2422" not in ev:
  191. raise Exception("Unexpected cahnnel in CSA finished event")
  192. dev[0].dump_monitor()
  193. dev[1].dump_monitor()
  194. time.sleep(0.1)
  195. hwsim_utils.test_connectivity_p2p(dev[0], dev[1])