fst_test_common.py 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. # FST tests related definitions
  2. # Copyright (c) 2015, Qualcomm Atheros, Inc.
  3. #
  4. # This software may be distributed under the terms of the BSD license.
  5. # See README for more details.
  6. import subprocess
  7. import logging
  8. import hostapd
  9. logger = logging.getLogger()
  10. fst_test_def_group='fstg0'
  11. fst_test_def_freq_g='2412' # Channel 1
  12. fst_test_def_freq_a='5180' # Channel 36
  13. fst_test_def_chan_g='1'
  14. fst_test_def_chan_a='36'
  15. fst_test_def_prio_low='100'
  16. fst_test_def_prio_high='110'
  17. fst_test_def_llt='100'
  18. fst_test_def_reg_domain='00'
  19. class HapdRegCtrl:
  20. def __init__(self):
  21. self.refcnt = 0
  22. self.ifname = None
  23. self.changed = False
  24. def __del__(self):
  25. if self.refcnt != 0 and self.changed == True:
  26. self.restore_reg_domain()
  27. def start(self):
  28. if self.ifname != None:
  29. hapd = hostapd.Hostapd(self.ifname)
  30. self.changed = self.wait_hapd_reg_change(hapd)
  31. def stop(self):
  32. if self.changed == True:
  33. self.restore_reg_domain()
  34. self.changed = False
  35. def add_ap(self, ifname, chan):
  36. if self.changed == False and self.channel_may_require_reg_change(chan):
  37. self.ifname = ifname
  38. @staticmethod
  39. def channel_may_require_reg_change(chan):
  40. if int(chan) > 14:
  41. return True
  42. return False
  43. @staticmethod
  44. def wait_hapd_reg_change(hapd):
  45. state = hapd.get_status_field("state")
  46. if state != "COUNTRY_UPDATE":
  47. state = hapd.get_status_field("state")
  48. if state != "ENABLED":
  49. raise Exception("Unexpected interface state - expected COUNTRY_UPDATE")
  50. else:
  51. logger.debug("fst hostapd: regulatory domain already set")
  52. return True
  53. logger.debug("fst hostapd: waiting for regulatory domain to be set...")
  54. ev = hapd.wait_event(["AP-ENABLED"], timeout=10)
  55. if not ev:
  56. raise Exception("AP setup timed out")
  57. logger.debug("fst hostapd: regulatory domain set")
  58. state = hapd.get_status_field("state")
  59. if state != "ENABLED":
  60. raise Exception("Unexpected interface state - expected ENABLED")
  61. logger.debug("fst hostapd: regulatory domain ready")
  62. return True
  63. @staticmethod
  64. def restore_reg_domain():
  65. logger.debug("fst hostapd: waiting for regulatory domain to be restored...")
  66. res = subprocess.call(['iw', 'reg', 'set', fst_test_def_reg_domain])
  67. if res != 0:
  68. raise Exception("Cannot restore regulatory domain")
  69. logger.debug("fst hostapd: regulatory domain ready")