test_ap_csa.py 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. # AP CSA tests
  2. # Copyright (c) 2013, Luciano Coelho <luciano.coelho@intel.com>
  3. #
  4. # This software may be distributed under the terms of the BSD license.
  5. # See README for more details.
  6. import time
  7. import logging
  8. logger = logging.getLogger()
  9. import hwsim_utils
  10. import hostapd
  11. from utils import HwsimSkip
  12. def connect(dev, apdev):
  13. params = { "ssid": "ap-csa",
  14. "channel": "1" }
  15. ap = hostapd.add_ap(apdev[0]['ifname'], params)
  16. dev.connect("ap-csa", key_mgmt="NONE")
  17. return ap
  18. def switch_channel(ap, count, freq):
  19. ap.request("CHAN_SWITCH " + str(count) + " " + str(freq))
  20. ev = ap.wait_event(["AP-CSA-FINISHED"], timeout=10)
  21. if ev is None:
  22. raise Exception("CSA finished event timed out")
  23. if "freq=" + str(freq) not in ev:
  24. raise Exception("Unexpected channel in CSA finished event")
  25. time.sleep(0.1)
  26. # This function checks whether the provided dev, which may be either
  27. # WpaSupplicant or Hostapd supports CSA.
  28. def csa_supported(dev):
  29. res = dev.get_driver_status()
  30. if (int(res['capa.flags'], 0) & 0x80000000) == 0:
  31. raise HwsimSkip("CSA not supported")
  32. def test_ap_csa_1_switch(dev, apdev):
  33. """AP Channel Switch, one switch"""
  34. csa_supported(dev[0])
  35. ap = connect(dev[0], apdev)
  36. hwsim_utils.test_connectivity(dev[0], ap)
  37. switch_channel(ap, 10, 2462)
  38. hwsim_utils.test_connectivity(dev[0], ap)
  39. def test_ap_csa_2_switches(dev, apdev):
  40. """AP Channel Switch, two switches"""
  41. csa_supported(dev[0])
  42. ap = connect(dev[0], apdev)
  43. hwsim_utils.test_connectivity(dev[0], ap)
  44. switch_channel(ap, 10, 2462)
  45. hwsim_utils.test_connectivity(dev[0], ap)
  46. switch_channel(ap, 10, 2412)
  47. hwsim_utils.test_connectivity(dev[0], ap)
  48. def test_ap_csa_1_switch_count_0(dev, apdev):
  49. """AP Channel Switch, one switch with count 0"""
  50. csa_supported(dev[0])
  51. ap = connect(dev[0], apdev)
  52. hwsim_utils.test_connectivity(dev[0], ap)
  53. switch_channel(ap, 0, 2462)
  54. # this does not result in CSA currently, so do not bother checking
  55. # connectivity
  56. def test_ap_csa_2_switches_count_0(dev, apdev):
  57. """AP Channel Switch, two switches with count 0"""
  58. csa_supported(dev[0])
  59. ap = connect(dev[0], apdev)
  60. hwsim_utils.test_connectivity(dev[0], ap)
  61. switch_channel(ap, 0, 2462)
  62. # this does not result in CSA currently, so do not bother checking
  63. # connectivity
  64. switch_channel(ap, 0, 2412)
  65. # this does not result in CSA currently, so do not bother checking
  66. # connectivity
  67. def test_ap_csa_1_switch_count_1(dev, apdev):
  68. """AP Channel Switch, one switch with count 1"""
  69. csa_supported(dev[0])
  70. ap = connect(dev[0], apdev)
  71. hwsim_utils.test_connectivity(dev[0], ap)
  72. switch_channel(ap, 1, 2462)
  73. # this does not result in CSA currently, so do not bother checking
  74. # connectivity
  75. def test_ap_csa_2_switches_count_1(dev, apdev):
  76. """AP Channel Switch, two switches with count 1"""
  77. csa_supported(dev[0])
  78. ap = connect(dev[0], apdev)
  79. hwsim_utils.test_connectivity(dev[0], ap)
  80. switch_channel(ap, 1, 2462)
  81. # this does not result in CSA currently, so do not bother checking
  82. # connectivity
  83. switch_channel(ap, 1, 2412)
  84. # this does not result in CSA currently, so do not bother checking
  85. # connectivity
  86. def test_ap_csa_1_switch_count_2(dev, apdev):
  87. """AP Channel Switch, one switch with count 2"""
  88. csa_supported(dev[0])
  89. ap = connect(dev[0], apdev)
  90. hwsim_utils.test_connectivity(dev[0], ap)
  91. switch_channel(ap, 2, 2462)
  92. hwsim_utils.test_connectivity(dev[0], ap)