test_ap_roam.py 5.8 KB

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