test_ap_csa.py 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  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. from remotehost import remote_compatible
  7. import time
  8. import logging
  9. logger = logging.getLogger()
  10. import hwsim_utils
  11. import hostapd
  12. from utils import HwsimSkip
  13. def connect(dev, apdev, **kwargs):
  14. params = { "ssid": "ap-csa",
  15. "channel": "1" }
  16. params.update(kwargs)
  17. ap = hostapd.add_ap(apdev[0], params)
  18. dev.connect("ap-csa", key_mgmt="NONE", scan_freq="2412")
  19. return ap
  20. def switch_channel(ap, count, freq):
  21. ap.request("CHAN_SWITCH " + str(count) + " " + str(freq))
  22. ev = ap.wait_event(["AP-CSA-FINISHED"], timeout=10)
  23. if ev is None:
  24. raise Exception("CSA finished event timed out")
  25. if "freq=" + str(freq) not in ev:
  26. raise Exception("Unexpected channel in CSA finished event")
  27. def wait_channel_switch(dev, freq):
  28. ev = dev.wait_event(["CTRL-EVENT-CHANNEL-SWITCH"], timeout=5)
  29. if ev is None:
  30. raise Exception("Channel switch not reported")
  31. if "freq=%d" % freq not in ev:
  32. raise Exception("Unexpected frequency: " + ev)
  33. # This function checks whether the provided dev, which may be either
  34. # WpaSupplicant or Hostapd supports CSA.
  35. def csa_supported(dev):
  36. res = dev.get_driver_status()
  37. if (int(res['capa.flags'], 0) & 0x80000000) == 0:
  38. raise HwsimSkip("CSA not supported")
  39. @remote_compatible
  40. def test_ap_csa_1_switch(dev, apdev):
  41. """AP Channel Switch, one switch"""
  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. wait_channel_switch(dev[0], 2462)
  47. hwsim_utils.test_connectivity(dev[0], ap)
  48. @remote_compatible
  49. def test_ap_csa_2_switches(dev, apdev):
  50. """AP Channel Switch, two switches"""
  51. csa_supported(dev[0])
  52. ap = connect(dev[0], apdev)
  53. hwsim_utils.test_connectivity(dev[0], ap)
  54. switch_channel(ap, 10, 2462)
  55. wait_channel_switch(dev[0], 2462)
  56. hwsim_utils.test_connectivity(dev[0], ap)
  57. switch_channel(ap, 10, 2412)
  58. wait_channel_switch(dev[0], 2412)
  59. hwsim_utils.test_connectivity(dev[0], ap)
  60. @remote_compatible
  61. def test_ap_csa_1_switch_count_0(dev, apdev):
  62. """AP Channel Switch, one switch with count 0"""
  63. csa_supported(dev[0])
  64. ap = connect(dev[0], apdev)
  65. hwsim_utils.test_connectivity(dev[0], ap)
  66. switch_channel(ap, 0, 2462)
  67. # this does not result in CSA currently, so do not bother checking
  68. # connectivity
  69. @remote_compatible
  70. def test_ap_csa_2_switches_count_0(dev, apdev):
  71. """AP Channel Switch, two switches with count 0"""
  72. csa_supported(dev[0])
  73. ap = connect(dev[0], apdev)
  74. hwsim_utils.test_connectivity(dev[0], ap)
  75. switch_channel(ap, 0, 2462)
  76. # this does not result in CSA currently, so do not bother checking
  77. # connectivity
  78. switch_channel(ap, 0, 2412)
  79. # this does not result in CSA currently, so do not bother checking
  80. # connectivity
  81. @remote_compatible
  82. def test_ap_csa_1_switch_count_1(dev, apdev):
  83. """AP Channel Switch, one switch with count 1"""
  84. csa_supported(dev[0])
  85. ap = connect(dev[0], apdev)
  86. hwsim_utils.test_connectivity(dev[0], ap)
  87. switch_channel(ap, 1, 2462)
  88. # this does not result in CSA currently, so do not bother checking
  89. # connectivity
  90. @remote_compatible
  91. def test_ap_csa_2_switches_count_1(dev, apdev):
  92. """AP Channel Switch, two switches with count 1"""
  93. csa_supported(dev[0])
  94. ap = connect(dev[0], apdev)
  95. hwsim_utils.test_connectivity(dev[0], ap)
  96. switch_channel(ap, 1, 2462)
  97. # this does not result in CSA currently, so do not bother checking
  98. # connectivity
  99. switch_channel(ap, 1, 2412)
  100. # this does not result in CSA currently, so do not bother checking
  101. # connectivity
  102. @remote_compatible
  103. def test_ap_csa_1_switch_count_2(dev, apdev):
  104. """AP Channel Switch, one switch with count 2"""
  105. csa_supported(dev[0])
  106. ap = connect(dev[0], apdev)
  107. hwsim_utils.test_connectivity(dev[0], ap)
  108. switch_channel(ap, 2, 2462)
  109. wait_channel_switch(dev[0], 2462)
  110. hwsim_utils.test_connectivity(dev[0], ap)
  111. @remote_compatible
  112. def test_ap_csa_ecsa_only(dev, apdev):
  113. """AP Channel Switch, one switch with only ECSA IE"""
  114. csa_supported(dev[0])
  115. ap = connect(dev[0], apdev, ecsa_ie_only="1")
  116. hwsim_utils.test_connectivity(dev[0], ap)
  117. switch_channel(ap, 10, 2462)
  118. wait_channel_switch(dev[0], 2462)
  119. hwsim_utils.test_connectivity(dev[0], ap)
  120. @remote_compatible
  121. def test_ap_csa_invalid(dev, apdev):
  122. """AP Channel Switch - invalid channel"""
  123. csa_supported(dev[0])
  124. ap = connect(dev[0], apdev)
  125. vals = [ 2461, 4900, 4901, 5181, 5746, 5699, 5895, 5899 ]
  126. for val in vals:
  127. if "FAIL" not in ap.request("CHAN_SWITCH 1 %d" % val):
  128. raise Exception("Invalid channel accepted: %d" % val)