test_ap_csa.py 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  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, **kwargs):
  13. params = { "ssid": "ap-csa",
  14. "channel": "1" }
  15. params.update(kwargs)
  16. ap = hostapd.add_ap(apdev[0]['ifname'], params)
  17. dev.connect("ap-csa", key_mgmt="NONE")
  18. return ap
  19. def switch_channel(ap, count, freq):
  20. ap.request("CHAN_SWITCH " + str(count) + " " + str(freq))
  21. ev = ap.wait_event(["AP-CSA-FINISHED"], timeout=10)
  22. if ev is None:
  23. raise Exception("CSA finished event timed out")
  24. if "freq=" + str(freq) not in ev:
  25. raise Exception("Unexpected channel in CSA finished event")
  26. time.sleep(0.1)
  27. # This function checks whether the provided dev, which may be either
  28. # WpaSupplicant or Hostapd supports CSA.
  29. def csa_supported(dev):
  30. res = dev.get_driver_status()
  31. if (int(res['capa.flags'], 0) & 0x80000000) == 0:
  32. raise HwsimSkip("CSA not supported")
  33. def test_ap_csa_1_switch(dev, apdev):
  34. """AP Channel Switch, one switch"""
  35. csa_supported(dev[0])
  36. ap = connect(dev[0], apdev)
  37. hwsim_utils.test_connectivity(dev[0], ap)
  38. switch_channel(ap, 10, 2462)
  39. hwsim_utils.test_connectivity(dev[0], ap)
  40. def test_ap_csa_2_switches(dev, apdev):
  41. """AP Channel Switch, two switches"""
  42. csa_supported(dev[0])
  43. ap = connect(dev[0], apdev)
  44. hwsim_utils.test_connectivity(dev[0], ap)
  45. switch_channel(ap, 10, 2462)
  46. hwsim_utils.test_connectivity(dev[0], ap)
  47. switch_channel(ap, 10, 2412)
  48. hwsim_utils.test_connectivity(dev[0], ap)
  49. def test_ap_csa_1_switch_count_0(dev, apdev):
  50. """AP Channel Switch, one switch with count 0"""
  51. csa_supported(dev[0])
  52. ap = connect(dev[0], apdev)
  53. hwsim_utils.test_connectivity(dev[0], ap)
  54. switch_channel(ap, 0, 2462)
  55. # this does not result in CSA currently, so do not bother checking
  56. # connectivity
  57. def test_ap_csa_2_switches_count_0(dev, apdev):
  58. """AP Channel Switch, two switches with count 0"""
  59. csa_supported(dev[0])
  60. ap = connect(dev[0], apdev)
  61. hwsim_utils.test_connectivity(dev[0], ap)
  62. switch_channel(ap, 0, 2462)
  63. # this does not result in CSA currently, so do not bother checking
  64. # connectivity
  65. switch_channel(ap, 0, 2412)
  66. # this does not result in CSA currently, so do not bother checking
  67. # connectivity
  68. def test_ap_csa_1_switch_count_1(dev, apdev):
  69. """AP Channel Switch, one switch with count 1"""
  70. csa_supported(dev[0])
  71. ap = connect(dev[0], apdev)
  72. hwsim_utils.test_connectivity(dev[0], ap)
  73. switch_channel(ap, 1, 2462)
  74. # this does not result in CSA currently, so do not bother checking
  75. # connectivity
  76. def test_ap_csa_2_switches_count_1(dev, apdev):
  77. """AP Channel Switch, two switches with count 1"""
  78. csa_supported(dev[0])
  79. ap = connect(dev[0], apdev)
  80. hwsim_utils.test_connectivity(dev[0], ap)
  81. switch_channel(ap, 1, 2462)
  82. # this does not result in CSA currently, so do not bother checking
  83. # connectivity
  84. switch_channel(ap, 1, 2412)
  85. # this does not result in CSA currently, so do not bother checking
  86. # connectivity
  87. def test_ap_csa_1_switch_count_2(dev, apdev):
  88. """AP Channel Switch, one switch with count 2"""
  89. csa_supported(dev[0])
  90. ap = connect(dev[0], apdev)
  91. hwsim_utils.test_connectivity(dev[0], ap)
  92. switch_channel(ap, 2, 2462)
  93. hwsim_utils.test_connectivity(dev[0], ap)
  94. def test_ap_csa_ecsa_only(dev, apdev):
  95. """AP Channel Switch, one switch with only ECSA IE"""
  96. csa_supported(dev[0])
  97. ap = connect(dev[0], apdev, ecsa_ie_only="1")
  98. hwsim_utils.test_connectivity(dev[0], ap)
  99. switch_channel(ap, 10, 2462)
  100. hwsim_utils.test_connectivity(dev[0], ap)