test_p2p_autogo.py 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  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(__name__)
  12. import hwsim_utils
  13. from wlantest import Wlantest
  14. def autogo(go):
  15. logger.info("Start autonomous GO " + go.ifname)
  16. res = go.p2p_start_go()
  17. logger.debug("res: " + str(res))
  18. def connect_cli(go, client):
  19. logger.info("Try to connect the client to the GO")
  20. pin = client.wps_read_pin()
  21. go.p2p_go_authorize_client(pin)
  22. client.p2p_connect_group(go.p2p_dev_addr(), pin, timeout=60)
  23. logger.info("Client connected")
  24. hwsim_utils.test_connectivity_p2p(go, client)
  25. def test_autogo(dev):
  26. """P2P autonomous GO and client joining group"""
  27. autogo(dev[0])
  28. connect_cli(dev[0], dev[1])
  29. dev[0].remove_group()
  30. ev = dev[1].wait_event(["P2P-GROUP-REMOVED"], timeout=2)
  31. if ev is None:
  32. raise Exception("Group removal event timed out")
  33. if "reason=GO_ENDING_SESSION" not in ev:
  34. raise Exception("Unexpected group removal reason")
  35. def test_autogo_2cli(dev):
  36. """P2P autonomous GO and two clients joining group"""
  37. autogo(dev[0])
  38. connect_cli(dev[0], dev[1])
  39. connect_cli(dev[0], dev[2])
  40. hwsim_utils.test_connectivity_p2p(dev[1], dev[2])
  41. dev[2].remove_group()
  42. dev[1].remove_group()
  43. dev[0].remove_group()
  44. def test_autogo_tdls(dev):
  45. """P2P autonomous GO and two clients using TDLS"""
  46. wt = Wlantest()
  47. go = dev[0]
  48. logger.info("Start autonomous GO with fixed parameters " + go.ifname)
  49. id = go.add_network()
  50. go.set_network_quoted(id, "ssid", "DIRECT-tdls")
  51. go.set_network_quoted(id, "psk", "12345678")
  52. go.set_network(id, "mode", "3")
  53. go.set_network(id, "disabled", "2")
  54. res = go.p2p_start_go(persistent=id)
  55. logger.debug("res: " + str(res))
  56. wt.flush()
  57. wt.add_passphrase("12345678")
  58. connect_cli(go, dev[1])
  59. connect_cli(go, dev[2])
  60. hwsim_utils.test_connectivity_p2p(dev[1], dev[2])
  61. bssid = dev[0].p2p_interface_addr()
  62. addr1 = dev[1].p2p_interface_addr()
  63. addr2 = dev[2].p2p_interface_addr()
  64. dev[1].tdls_setup(addr2)
  65. time.sleep(1)
  66. hwsim_utils.test_connectivity_p2p(dev[1], dev[2])
  67. conf = wt.get_tdls_counter("setup_conf_ok", bssid, addr1, addr2);
  68. if conf == 0:
  69. raise Exception("No TDLS Setup Confirm (success) seen")
  70. dl = wt.get_tdls_counter("valid_direct_link", bssid, addr1, addr2);
  71. if dl == 0:
  72. raise Exception("No valid frames through direct link")
  73. wt.tdls_clear(bssid, addr1, addr2);
  74. dev[1].tdls_teardown(addr2)
  75. time.sleep(1)
  76. teardown = wt.get_tdls_counter("teardown", bssid, addr1, addr2);
  77. if teardown == 0:
  78. raise Exception("No TDLS Setup Teardown seen")
  79. wt.tdls_clear(bssid, addr1, addr2);
  80. hwsim_utils.test_connectivity_p2p(dev[1], dev[2])
  81. ap_path = wt.get_tdls_counter("valid_ap_path", bssid, addr1, addr2);
  82. if ap_path == 0:
  83. raise Exception("No valid frames via AP path")
  84. direct_link = wt.get_tdls_counter("valid_direct_link", bssid, addr1, addr2);
  85. if direct_link > 0:
  86. raise Exception("Unexpected frames through direct link")
  87. idirect_link = wt.get_tdls_counter("invalid_direct_link", bssid, addr1,
  88. addr2);
  89. if idirect_link > 0:
  90. raise Exception("Unexpected frames through direct link (invalid)")
  91. dev[2].remove_group()
  92. dev[1].remove_group()
  93. dev[0].remove_group()