test_ap_csa.py 3.6 KB

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