test_ap_acs.py 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. # Test cases for automatic channel selection with hostapd
  2. # Copyright (c) 2013, Jouni Malinen <j@w1.fi>
  3. #
  4. # This software may be distributed under the terms of the BSD license.
  5. # See README for more details.
  6. import logging
  7. logger = logging.getLogger()
  8. import hostapd
  9. def wait_acs(hapd):
  10. ev = hapd.wait_event(["ACS-STARTED", "ACS-COMPLETED", "ACS-FAILED",
  11. "AP-ENABLED"], timeout=5)
  12. if not ev:
  13. raise Exception("ACS start timed out")
  14. if "ACS-STARTED" not in ev:
  15. raise Exception("Unexpected ACS event")
  16. state = hapd.get_status_field("state")
  17. if state != "ACS":
  18. raise Exception("Unexpected interface state")
  19. ev = hapd.wait_event(["ACS-COMPLETED", "ACS-FAILED", "AP-ENABLED"],
  20. timeout=20)
  21. if not ev:
  22. raise Exception("ACS timed out")
  23. if "ACS-COMPLETED" not in ev:
  24. raise Exception("Unexpected ACS event")
  25. ev = hapd.wait_event(["AP-ENABLED"], timeout=5)
  26. if not ev:
  27. raise Exception("AP setup timed out")
  28. state = hapd.get_status_field("state")
  29. if state != "ENABLED":
  30. raise Exception("Unexpected interface state")
  31. def test_ap_acs(dev, apdev):
  32. """Automatic channel selection"""
  33. params = hostapd.wpa2_params(ssid="test-acs", passphrase="12345678")
  34. params['channel'] = '0'
  35. hapd = hostapd.add_ap(apdev[0]['ifname'], params, wait_enabled=False)
  36. wait_acs(hapd)
  37. freq = hapd.get_status_field("freq")
  38. if int(freq) < 2400:
  39. raise Exception("Unexpected frequency")
  40. dev[0].connect("test-acs", psk="12345678", scan_freq=freq)
  41. def test_ap_multi_bss_acs(dev, apdev):
  42. """hostapd start with a multi-BSS configuration file using ACS"""
  43. ifname = apdev[0]['ifname']
  44. hostapd.add_iface(ifname, 'multi-bss-acs.conf')
  45. hapd = hostapd.Hostapd(ifname)
  46. hapd.enable()
  47. wait_acs(hapd)
  48. freq = hapd.get_status_field("freq")
  49. if int(freq) < 2400:
  50. raise Exception("Unexpected frequency")
  51. dev[0].connect("bss-1", key_mgmt="NONE", scan_freq=freq)
  52. dev[1].connect("bss-2", psk="12345678", scan_freq=freq)
  53. dev[2].connect("bss-3", psk="qwertyuiop", scan_freq=freq)