test_ap_track.py 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. # Test cases for hostapd tracking unconnected stations
  2. # Copyright (c) 2015, Jouni Malinen <j@w1.fi>
  3. #
  4. # This software may be distributed under the terms of the BSD license.
  5. # See README for more details.
  6. import logging
  7. logger = logging.getLogger()
  8. import subprocess
  9. import time
  10. import hostapd
  11. from wpasupplicant import WpaSupplicant
  12. def test_ap_track_sta(dev, apdev):
  13. """Dualband AP tracking unconnected stations"""
  14. try:
  15. _test_ap_track_sta(dev, apdev)
  16. finally:
  17. subprocess.call(['iw', 'reg', 'set', '00'])
  18. def _test_ap_track_sta(dev, apdev):
  19. params = { "ssid": "track",
  20. "country_code": "US",
  21. "hw_mode": "g",
  22. "channel": "6",
  23. "track_sta_max_num": "2" }
  24. hapd = hostapd.add_ap(apdev[0]['ifname'], params)
  25. bssid = apdev[0]['bssid']
  26. params = { "ssid": "track",
  27. "country_code": "US",
  28. "hw_mode": "a",
  29. "channel": "40",
  30. "track_sta_max_num": "100",
  31. "track_sta_max_age": "1" }
  32. hapd2 = hostapd.add_ap(apdev[1]['ifname'], params)
  33. bssid2 = apdev[1]['bssid']
  34. for i in range(2):
  35. dev[0].scan_for_bss(bssid, freq=2437, force_scan=True)
  36. dev[0].scan_for_bss(bssid2, freq=5200, force_scan=True)
  37. dev[1].scan_for_bss(bssid, freq=2437, force_scan=True)
  38. dev[2].scan_for_bss(bssid2, freq=5200, force_scan=True)
  39. addr0 = dev[0].own_addr()
  40. addr1 = dev[1].own_addr()
  41. addr2 = dev[2].own_addr()
  42. track = hapd.request("TRACK_STA_LIST")
  43. if addr0 not in track or addr1 not in track:
  44. raise Exception("Station missing from 2.4 GHz tracking")
  45. if addr2 in track:
  46. raise Exception("Unexpected station included in 2.4 GHz tracking")
  47. track = hapd2.request("TRACK_STA_LIST")
  48. if addr0 not in track or addr2 not in track:
  49. raise Exception("Station missing from 5 GHz tracking")
  50. if addr1 in track:
  51. raise Exception("Unexpected station included in 5 GHz tracking")
  52. # Test expiration
  53. time.sleep(1.1)
  54. track = hapd.request("TRACK_STA_LIST")
  55. if addr0 not in track or addr1 not in track:
  56. raise Exception("Station missing from 2.4 GHz tracking (expiration)")
  57. track = hapd2.request("TRACK_STA_LIST")
  58. if addr0 in track or addr2 in track:
  59. raise Exception("Station not expired from 5 GHz tracking")
  60. # Test maximum list length
  61. dev[0].scan_for_bss(bssid, freq=2437, force_scan=True)
  62. dev[1].scan_for_bss(bssid, freq=2437, force_scan=True)
  63. dev[2].scan_for_bss(bssid, freq=2437, force_scan=True)
  64. track = hapd.request("TRACK_STA_LIST")
  65. if len(track.splitlines()) != 2:
  66. raise Exception("Unexpected number of entries: %d" % len(track.splitlines()))
  67. if addr1 not in track or addr2 not in track:
  68. raise Exception("Station missing from 2.4 GHz tracking (max limit)")