test_ap_roam.py 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  1. # Roaming tests
  2. # Copyright (c) 2013, 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 time
  7. import subprocess
  8. import logging
  9. logger = logging.getLogger()
  10. import hwsim_utils
  11. import hostapd
  12. def test_ap_roam_open(dev, apdev):
  13. """Roam between two open APs"""
  14. hapd0 = hostapd.add_ap(apdev[0], { "ssid": "test-open" })
  15. dev[0].connect("test-open", key_mgmt="NONE")
  16. hwsim_utils.test_connectivity(dev[0], hapd0)
  17. hapd1 = hostapd.add_ap(apdev[1], { "ssid": "test-open" })
  18. dev[0].scan(type="ONLY")
  19. dev[0].roam(apdev[1]['bssid'])
  20. hwsim_utils.test_connectivity(dev[0], hapd1)
  21. dev[0].roam(apdev[0]['bssid'])
  22. hwsim_utils.test_connectivity(dev[0], hapd0)
  23. def test_ap_roam_open_failed(dev, apdev):
  24. """Roam failure due to rejected authentication"""
  25. hapd0 = hostapd.add_ap(apdev[0], { "ssid": "test-open" })
  26. dev[0].connect("test-open", key_mgmt="NONE", scan_freq="2412")
  27. hwsim_utils.test_connectivity(dev[0], hapd0)
  28. params = { "ssid": "test-open", "max_num_sta" : "0" }
  29. hapd1 = hostapd.add_ap(apdev[1], params)
  30. bssid = hapd1.own_addr()
  31. dev[0].scan_for_bss(bssid, freq=2412)
  32. dev[0].dump_monitor()
  33. if "OK" not in dev[0].request("ROAM " + bssid):
  34. raise Exception("ROAM failed")
  35. ev = dev[0].wait_event(["CTRL-EVENT-AUTH-REJECT"], 1)
  36. if not ev:
  37. raise Exception("CTRL-EVENT-AUTH-REJECT was not seen")
  38. dev[0].wait_connected(timeout=5)
  39. hwsim_utils.test_connectivity(dev[0], hapd0)
  40. def test_ap_roam_wpa2_psk(dev, apdev):
  41. """Roam between two WPA2-PSK APs"""
  42. params = hostapd.wpa2_params(ssid="test-wpa2-psk", passphrase="12345678")
  43. hapd0 = hostapd.add_ap(apdev[0], params)
  44. dev[0].connect("test-wpa2-psk", psk="12345678")
  45. hwsim_utils.test_connectivity(dev[0], hapd0)
  46. hapd1 = hostapd.add_ap(apdev[1], params)
  47. dev[0].scan(type="ONLY")
  48. dev[0].roam(apdev[1]['bssid'])
  49. hwsim_utils.test_connectivity(dev[0], hapd1)
  50. dev[0].roam(apdev[0]['bssid'])
  51. hwsim_utils.test_connectivity(dev[0], hapd0)
  52. def test_ap_roam_wpa2_psk_failed(dev, apdev, params):
  53. """Roam failure with WPA2-PSK AP due to wrong passphrase"""
  54. params = hostapd.wpa2_params(ssid="test-wpa2-psk", passphrase="12345678")
  55. hapd0 = hostapd.add_ap(apdev[0], params)
  56. id = dev[0].connect("test-wpa2-psk", psk="12345678", scan_freq="2412")
  57. hwsim_utils.test_connectivity(dev[0], hapd0)
  58. params['wpa_passphrase'] = "22345678"
  59. hapd1 = hostapd.add_ap(apdev[1], params)
  60. bssid = hapd1.own_addr()
  61. dev[0].scan_for_bss(bssid, freq=2412)
  62. dev[0].dump_monitor()
  63. if "OK" not in dev[0].request("ROAM " + bssid):
  64. raise Exception("ROAM failed")
  65. ev = dev[0].wait_event(["CTRL-EVENT-SSID-TEMP-DISABLED",
  66. "CTRL-EVENT-CONNECTED"], 5)
  67. if "CTRL-EVENT-CONNECTED" in ev:
  68. raise Exception("Got unexpected CTRL-EVENT-CONNECTED")
  69. if "CTRL-EVENT-SSID-TEMP-DISABLED" not in ev:
  70. raise Exception("CTRL-EVENT-SSID-TEMP-DISABLED not seen")
  71. if "OK" not in dev[0].request("SELECT_NETWORK id=" + str(id)):
  72. raise Exception("SELECT_NETWORK failed")
  73. ev = dev[0].wait_event(["CTRL-EVENT-SSID-REENABLED"], 3)
  74. if not ev:
  75. raise Exception("CTRL-EVENT-SSID-REENABLED not seen");
  76. dev[0].wait_connected(timeout=5)
  77. hwsim_utils.test_connectivity(dev[0], hapd0)
  78. def test_ap_reassociation_to_same_bss(dev, apdev):
  79. """Reassociate to the same BSS"""
  80. hapd = hostapd.add_ap(apdev[0], { "ssid": "test-open" })
  81. dev[0].connect("test-open", key_mgmt="NONE")
  82. dev[0].request("REASSOCIATE")
  83. dev[0].wait_connected(timeout=10, error="Reassociation timed out")
  84. hwsim_utils.test_connectivity(dev[0], hapd)
  85. dev[0].request("REATTACH")
  86. dev[0].wait_connected(timeout=10, error="Reattach timed out")
  87. hwsim_utils.test_connectivity(dev[0], hapd)
  88. # Wait for previous scan results to expire to trigger new scan
  89. time.sleep(5)
  90. dev[0].request("REATTACH")
  91. dev[0].wait_connected(timeout=10, error="Reattach timed out")
  92. hwsim_utils.test_connectivity(dev[0], hapd)
  93. def test_ap_roam_set_bssid(dev, apdev):
  94. """Roam control"""
  95. hostapd.add_ap(apdev[0], { "ssid": "test-open" })
  96. hostapd.add_ap(apdev[1], { "ssid": "test-open" })
  97. id = dev[0].connect("test-open", key_mgmt="NONE", bssid=apdev[1]['bssid'],
  98. scan_freq="2412")
  99. if dev[0].get_status_field('bssid') != apdev[1]['bssid']:
  100. raise Exception("Unexpected BSS")
  101. # for now, these are just verifying that the code path to indicate
  102. # within-ESS roaming changes can be executed; the actual results of those
  103. # operations are not currently verified (that would require a test driver
  104. # that does BSS selection)
  105. dev[0].set_network(id, "bssid", "")
  106. dev[0].set_network(id, "bssid", apdev[0]['bssid'])
  107. dev[0].set_network(id, "bssid", apdev[1]['bssid'])
  108. def test_ap_roam_wpa2_psk_race(dev, apdev):
  109. """Roam between two WPA2-PSK APs and try to hit a disconnection race"""
  110. params = hostapd.wpa2_params(ssid="test-wpa2-psk", passphrase="12345678")
  111. hapd0 = hostapd.add_ap(apdev[0], params)
  112. dev[0].connect("test-wpa2-psk", psk="12345678", scan_freq="2412")
  113. hwsim_utils.test_connectivity(dev[0], hapd0)
  114. params['channel'] = '2'
  115. hapd1 = hostapd.add_ap(apdev[1], params)
  116. dev[0].scan_for_bss(apdev[1]['bssid'], freq=2417)
  117. dev[0].roam(apdev[1]['bssid'])
  118. hwsim_utils.test_connectivity(dev[0], hapd1)
  119. dev[0].roam(apdev[0]['bssid'])
  120. hwsim_utils.test_connectivity(dev[0], hapd0)
  121. # Wait at least two seconds to trigger the previous issue with the
  122. # disconnection callback.
  123. for i in range(3):
  124. time.sleep(0.8)
  125. hwsim_utils.test_connectivity(dev[0], hapd0)