test_scan.py 3.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. #!/usr/bin/python
  2. #
  3. # Scanning tests
  4. # Copyright (c) 2013, Jouni Malinen <j@w1.fi>
  5. #
  6. # This software may be distributed under the terms of the BSD license.
  7. # See README for more details.
  8. import time
  9. import logging
  10. logger = logging.getLogger()
  11. import hostapd
  12. def check_scan(dev, params):
  13. dev.dump_monitor()
  14. id = dev.request("SCAN " + params)
  15. if "FAIL" in id:
  16. raise Exception("Failed to start scan")
  17. id = int(id)
  18. ev = dev.wait_event(["CTRL-EVENT-SCAN-STARTED"])
  19. if ev is None:
  20. raise Exception("Scan did not start")
  21. if "id=" + str(id) not in ev:
  22. raise Exception("Scan id not included in start event")
  23. ev = dev.wait_event(["CTRL-EVENT-SCAN-RESULTS"])
  24. if ev is None:
  25. raise Exception("Scan did not complete")
  26. if "id=" + str(id) not in ev:
  27. raise Exception("Scan id not included in completed event")
  28. def test_scan(dev, apdev):
  29. """Control interface behavior on scan parameters"""
  30. hostapd.add_ap(apdev[0]['ifname'], { "ssid": "test-scan" })
  31. bssid = apdev[0]['bssid']
  32. logger.info("Full scan")
  33. check_scan(dev[0], "use_id=1")
  34. logger.info("Limited channel scan")
  35. check_scan(dev[0], "freq=2412-2462,5180 use_id=1")
  36. if int(dev[0].get_bss(bssid)['age']) > 1:
  37. raise Exception("Unexpectedly old BSS entry")
  38. # wait long enough to allow next scans to be verified not to find the AP
  39. time.sleep(2)
  40. logger.info("Passive single-channel scan")
  41. check_scan(dev[0], "freq=2457 passive=1 use_id=1")
  42. logger.info("Active single-channel scan")
  43. check_scan(dev[0], "freq=2452 passive=0 use_id=1")
  44. if int(dev[0].get_bss(bssid)['age']) < 2:
  45. raise Exception("Unexpectedly updated BSS entry")
  46. logger.info("Active single-channel scan on AP's operating channel")
  47. check_scan(dev[0], "freq=2412 passive=0 use_id=1")
  48. if int(dev[0].get_bss(bssid)['age']) > 1:
  49. raise Exception("Unexpectedly old BSS entry")
  50. def test_scan_only(dev, apdev):
  51. """Control interface behavior on scan parameters with type=only"""
  52. hostapd.add_ap(apdev[0]['ifname'], { "ssid": "test-scan" })
  53. bssid = apdev[0]['bssid']
  54. logger.info("Full scan")
  55. check_scan(dev[0], "type=only use_id=1")
  56. logger.info("Limited channel scan")
  57. check_scan(dev[0], "type=only freq=2412-2462,5180 use_id=1")
  58. if int(dev[0].get_bss(bssid)['age']) > 1:
  59. raise Exception("Unexpectedly old BSS entry")
  60. # wait long enough to allow next scans to be verified not to find the AP
  61. time.sleep(2)
  62. logger.info("Passive single-channel scan")
  63. check_scan(dev[0], "type=only freq=2457 passive=1 use_id=1")
  64. logger.info("Active single-channel scan")
  65. check_scan(dev[0], "type=only freq=2452 passive=0 use_id=1")
  66. if int(dev[0].get_bss(bssid)['age']) < 2:
  67. raise Exception("Unexpectedly updated BSS entry")
  68. logger.info("Active single-channel scan on AP's operating channel")
  69. check_scan(dev[0], "type=only freq=2412 passive=0 use_id=1")
  70. if int(dev[0].get_bss(bssid)['age']) > 1:
  71. raise Exception("Unexpectedly old BSS entry")