test_ibss.py 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. #!/usr/bin/python
  2. #
  3. # IBSS 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 logging
  9. logger = logging.getLogger(__name__)
  10. import time
  11. import hwsim_utils
  12. def connect_ibss_cmd(dev, id):
  13. dev.dump_monitor()
  14. dev.select_network(id)
  15. def wait_ibss_connection(dev):
  16. ev = dev.wait_event(["CTRL-EVENT-CONNECTED"], timeout=20)
  17. if ev is None:
  18. raise Exception("Connection to the IBSS timed out")
  19. dev.dump_monitor()
  20. def add_ibss(dev, ssid, psk=None, proto=None, key_mgmt=None, pairwise=None, group=None):
  21. id = dev.add_network()
  22. dev.set_network(id, "mode", "1")
  23. dev.set_network(id, "frequency", "2412")
  24. dev.set_network_quoted(id, "ssid", ssid)
  25. if psk:
  26. dev.set_network_quoted(id, "psk", psk)
  27. if proto:
  28. dev.set_network(id, "proto", proto)
  29. if key_mgmt:
  30. dev.set_network(id, "key_mgmt", key_mgmt)
  31. if pairwise:
  32. dev.set_network(id, "pairwise", pairwise)
  33. if group:
  34. dev.set_network(id, "group", group)
  35. return id
  36. def add_ibss_rsn(dev, ssid):
  37. return add_ibss(dev, ssid, "12345678", "RSN", "WPA-PSK", "CCMP", "CCMP")
  38. def test_ibss_rsn(dev):
  39. """IBSS RSN"""
  40. ssid="ibss-rsn"
  41. logger.info("Start IBSS on the first STA")
  42. id = add_ibss_rsn(dev[0], ssid)
  43. connect_ibss_cmd(dev[0], id)
  44. wait_ibss_connection(dev[0])
  45. logger.info("Join two STAs to the IBSS")
  46. id = add_ibss_rsn(dev[1], ssid)
  47. connect_ibss_cmd(dev[1], id)
  48. id = add_ibss_rsn(dev[2], ssid)
  49. connect_ibss_cmd(dev[2], id)
  50. wait_ibss_connection(dev[1])
  51. wait_ibss_connection(dev[2])
  52. # Allow some time for all peers to complete key setup
  53. time.sleep(3)
  54. hwsim_utils.test_connectivity(dev[0].ifname, dev[1].ifname)
  55. hwsim_utils.test_connectivity(dev[0].ifname, dev[2].ifname)
  56. time.sleep(2)
  57. hwsim_utils.test_connectivity(dev[1].ifname, dev[2].ifname)