test_ap_acs.py 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. #!/usr/bin/python
  2. #
  3. # Test cases for automatic channel selection with hostapd
  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()
  10. import hostapd
  11. def wait_acs(hapd):
  12. ev = hapd.wait_event(["ACS-STARTED", "ACS-COMPLETED", "ACS-FAILED",
  13. "AP-ENABLED"], timeout=5)
  14. if not ev:
  15. raise Exception("ACS start timed out")
  16. if "ACS-STARTED" not in ev:
  17. raise Exception("Unexpected ACS event")
  18. state = hapd.get_status_field("state")
  19. if state != "ACS":
  20. raise Exception("Unexpected interface state")
  21. ev = hapd.wait_event(["ACS-COMPLETED", "ACS-FAILED", "AP-ENABLED"],
  22. timeout=20)
  23. if not ev:
  24. raise Exception("ACS timed out")
  25. if "ACS-COMPLETED" not in ev:
  26. raise Exception("Unexpected ACS event")
  27. ev = hapd.wait_event(["AP-ENABLED"], timeout=5)
  28. if not ev:
  29. raise Exception("AP setup timed out")
  30. state = hapd.get_status_field("state")
  31. if state != "ENABLED":
  32. raise Exception("Unexpected interface state")
  33. def test_ap_acs(dev, apdev):
  34. """Automatic channel selection"""
  35. params = hostapd.wpa2_params(ssid="test-acs", passphrase="12345678")
  36. params['channel'] = '0'
  37. hapd = hostapd.add_ap(apdev[0]['ifname'], params)
  38. wait_acs(hapd)
  39. freq = hapd.get_status_field("freq")
  40. if int(freq) < 2400:
  41. raise Exception("Unexpected frequency")
  42. dev[0].connect("test-acs", psk="12345678", scan_freq=freq)
  43. def test_ap_multi_bss_acs(dev, apdev):
  44. """hostapd start with a multi-BSS configuration file using ACS"""
  45. ifname = apdev[0]['ifname']
  46. hostapd.add_iface(ifname, 'multi-bss-acs.conf')
  47. hapd = hostapd.Hostapd(ifname)
  48. hapd.enable()
  49. wait_acs(hapd)
  50. freq = hapd.get_status_field("freq")
  51. if int(freq) < 2400:
  52. raise Exception("Unexpected frequency")
  53. dev[0].connect("bss-1", key_mgmt="NONE", scan_freq=freq)
  54. dev[1].connect("bss-2", psk="12345678", scan_freq=freq)
  55. dev[2].connect("bss-3", psk="qwertyuiop", scan_freq=freq)