test_ibss.py 3.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  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. logger.info(dev.ifname + " waiting for IBSS start/join to complete")
  17. ev = dev.wait_event(["CTRL-EVENT-CONNECTED"], timeout=20)
  18. if ev is None:
  19. raise Exception("Connection to the IBSS timed out")
  20. def wait_4way_handshake(dev1, dev2):
  21. logger.info(dev1.ifname + " waiting for 4-way handshake completion with " + dev2.ifname + " " + dev2.p2p_interface_addr())
  22. ev = dev1.wait_event(["IBSS-RSN-COMPLETED " + dev2.p2p_interface_addr()],
  23. timeout=20)
  24. if ev is None:
  25. raise Exception("4-way handshake in IBSS timed out")
  26. def wait_4way_handshake2(dev1, dev2, dev3):
  27. logger.info(dev1.ifname + " waiting for 4-way handshake completion with " + dev2.ifname + " " + dev2.p2p_interface_addr() + " and " + dev3.p2p_interface_addr())
  28. ev = dev1.wait_event(["IBSS-RSN-COMPLETED " + dev2.p2p_interface_addr(),
  29. "IBSS-RSN-COMPLETED " + dev3.p2p_interface_addr()],
  30. timeout=20)
  31. if ev is None:
  32. raise Exception("4-way handshake in IBSS timed out")
  33. ev = dev1.wait_event(["IBSS-RSN-COMPLETED " + dev2.p2p_interface_addr(),
  34. "IBSS-RSN-COMPLETED " + dev3.p2p_interface_addr()],
  35. timeout=20)
  36. if ev is None:
  37. raise Exception("4-way handshake in IBSS timed out")
  38. def add_ibss(dev, ssid, psk=None, proto=None, key_mgmt=None, pairwise=None, group=None):
  39. id = dev.add_network()
  40. dev.set_network(id, "mode", "1")
  41. dev.set_network(id, "frequency", "2412")
  42. dev.set_network_quoted(id, "ssid", ssid)
  43. if psk:
  44. dev.set_network_quoted(id, "psk", psk)
  45. if proto:
  46. dev.set_network(id, "proto", proto)
  47. if key_mgmt:
  48. dev.set_network(id, "key_mgmt", key_mgmt)
  49. if pairwise:
  50. dev.set_network(id, "pairwise", pairwise)
  51. if group:
  52. dev.set_network(id, "group", group)
  53. return id
  54. def add_ibss_rsn(dev, ssid):
  55. return add_ibss(dev, ssid, "12345678", "RSN", "WPA-PSK", "CCMP", "CCMP")
  56. def test_ibss_rsn(dev):
  57. """IBSS RSN"""
  58. ssid="ibss-rsn"
  59. logger.info("Start IBSS on the first STA")
  60. id = add_ibss_rsn(dev[0], ssid)
  61. connect_ibss_cmd(dev[0], id)
  62. wait_ibss_connection(dev[0])
  63. logger.info("Join two STAs to the IBSS")
  64. id = add_ibss_rsn(dev[1], ssid)
  65. connect_ibss_cmd(dev[1], id)
  66. wait_ibss_connection(dev[1])
  67. wait_4way_handshake(dev[0], dev[1])
  68. wait_4way_handshake(dev[1], dev[0])
  69. id = add_ibss_rsn(dev[2], ssid)
  70. connect_ibss_cmd(dev[2], id)
  71. wait_ibss_connection(dev[2])
  72. wait_4way_handshake(dev[0], dev[2])
  73. wait_4way_handshake2(dev[2], dev[0], dev[1])
  74. # Allow some time for all peers to complete key setup
  75. time.sleep(3)
  76. hwsim_utils.test_connectivity(dev[0].ifname, dev[1].ifname)
  77. hwsim_utils.test_connectivity(dev[0].ifname, dev[2].ifname)
  78. hwsim_utils.test_connectivity(dev[1].ifname, dev[2].ifname)