test_ap_open.py 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  1. # Open mode AP tests
  2. # Copyright (c) 2014, 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 logging
  7. logger = logging.getLogger()
  8. import struct
  9. import subprocess
  10. import time
  11. import hostapd
  12. import hwsim_utils
  13. def test_ap_open(dev, apdev):
  14. """AP with open mode (no security) configuration"""
  15. hapd = hostapd.add_ap(apdev[0]['ifname'], { "ssid": "open" })
  16. dev[0].connect("open", key_mgmt="NONE", scan_freq="2412")
  17. ev = hapd.wait_event([ "AP-STA-CONNECTED" ], timeout=5)
  18. if ev is None:
  19. raise Exception("No connection event received from hostapd")
  20. hwsim_utils.test_connectivity(dev[0], hapd)
  21. dev[0].request("DISCONNECT")
  22. ev = hapd.wait_event([ "AP-STA-DISCONNECTED" ], timeout=5)
  23. if ev is None:
  24. raise Exception("No disconnection event received from hostapd")
  25. def test_ap_open_packet_loss(dev, apdev):
  26. """AP with open mode configuration and large packet loss"""
  27. params = { "ssid": "open",
  28. "ignore_probe_probability": "0.5",
  29. "ignore_auth_probability": "0.5",
  30. "ignore_assoc_probability": "0.5",
  31. "ignore_reassoc_probability": "0.5" }
  32. hapd = hostapd.add_ap(apdev[0]['ifname'], params)
  33. for i in range(0, 3):
  34. dev[i].connect("open", key_mgmt="NONE", scan_freq="2412",
  35. wait_connect=False)
  36. for i in range(0, 3):
  37. dev[i].wait_connected(timeout=20)
  38. def test_ap_open_unknown_action(dev, apdev):
  39. """AP with open mode configuration and unknown Action frame"""
  40. hapd = hostapd.add_ap(apdev[0]['ifname'], { "ssid": "open" })
  41. dev[0].connect("open", key_mgmt="NONE", scan_freq="2412")
  42. bssid = apdev[0]['bssid']
  43. cmd = "MGMT_TX {} {} freq=2412 action=765432".format(bssid, bssid)
  44. if "FAIL" in dev[0].request(cmd):
  45. raise Exception("Could not send test Action frame")
  46. ev = dev[0].wait_event(["MGMT-TX-STATUS"], timeout=10)
  47. if ev is None:
  48. raise Exception("Timeout on MGMT-TX-STATUS")
  49. if "result=SUCCESS" not in ev:
  50. raise Exception("AP did not ack Action frame")
  51. def test_ap_open_reconnect_on_inactivity_disconnect(dev, apdev):
  52. """Reconnect to open mode AP after inactivity related disconnection"""
  53. hapd = hostapd.add_ap(apdev[0]['ifname'], { "ssid": "open" })
  54. dev[0].connect("open", key_mgmt="NONE", scan_freq="2412")
  55. hapd.request("DEAUTHENTICATE " + dev[0].p2p_interface_addr() + " reason=4")
  56. dev[0].wait_disconnected(timeout=5)
  57. dev[0].wait_connected(timeout=2, error="Timeout on reconnection")
  58. def test_ap_open_assoc_timeout(dev, apdev):
  59. """AP timing out association"""
  60. ssid = "test"
  61. hapd = hostapd.add_ap(apdev[0]['ifname'], { "ssid": "open" })
  62. dev[0].scan(freq="2412")
  63. hapd.set("ext_mgmt_frame_handling", "1")
  64. dev[0].connect("open", key_mgmt="NONE", scan_freq="2412",
  65. wait_connect=False)
  66. for i in range(0, 10):
  67. req = hapd.mgmt_rx()
  68. if req is None:
  69. raise Exception("MGMT RX wait timed out")
  70. if req['subtype'] == 11:
  71. break
  72. req = None
  73. if not req:
  74. raise Exception("Authentication frame not received")
  75. resp = {}
  76. resp['fc'] = req['fc']
  77. resp['da'] = req['sa']
  78. resp['sa'] = req['da']
  79. resp['bssid'] = req['bssid']
  80. resp['payload'] = struct.pack('<HHH', 0, 2, 0)
  81. hapd.mgmt_tx(resp)
  82. assoc = 0
  83. for i in range(0, 10):
  84. req = hapd.mgmt_rx()
  85. if req is None:
  86. raise Exception("MGMT RX wait timed out")
  87. if req['subtype'] == 0:
  88. assoc += 1
  89. if assoc == 3:
  90. break
  91. if assoc != 3:
  92. raise Exception("Association Request frames not received: assoc=%d" % assoc)
  93. hapd.set("ext_mgmt_frame_handling", "0")
  94. dev[0].wait_connected(timeout=15)
  95. def test_ap_open_id_str(dev, apdev):
  96. """AP with open mode and id_str"""
  97. hapd = hostapd.add_ap(apdev[0]['ifname'], { "ssid": "open" })
  98. dev[0].connect("open", key_mgmt="NONE", scan_freq="2412", id_str="foo",
  99. wait_connect=False)
  100. ev = dev[0].wait_connected(timeout=10)
  101. if "id_str=foo" not in ev:
  102. raise Exception("CTRL-EVENT-CONNECT did not have matching id_str: " + ev)
  103. if dev[0].get_status_field("id_str") != "foo":
  104. raise Exception("id_str mismatch")
  105. def test_ap_open_select_any(dev, apdev):
  106. """AP with open mode and select any network"""
  107. hapd = hostapd.add_ap(apdev[0]['ifname'], { "ssid": "open" })
  108. id = dev[0].connect("unknown", key_mgmt="NONE", scan_freq="2412",
  109. only_add_network=True)
  110. dev[0].connect("open", key_mgmt="NONE", scan_freq="2412",
  111. only_add_network=True)
  112. dev[0].select_network(id)
  113. ev = dev[0].wait_event(["CTRL-EVENT-CONNECTED"], timeout=1)
  114. if ev is not None:
  115. raise Exception("Unexpected connection")
  116. dev[0].select_network("any")
  117. dev[0].wait_connected(timeout=10)
  118. def test_ap_open_unexpected_assoc_event(dev, apdev):
  119. """AP with open mode and unexpected association event"""
  120. hapd = hostapd.add_ap(apdev[0]['ifname'], { "ssid": "open" })
  121. dev[0].connect("open", key_mgmt="NONE", scan_freq="2412")
  122. dev[0].request("DISCONNECT")
  123. dev[0].wait_disconnected(timeout=15)
  124. dev[0].dump_monitor()
  125. # This will be accepted due to matching network
  126. subprocess.call(['iw', 'dev', dev[0].ifname, 'connect', 'open', "2412",
  127. apdev[0]['bssid']])
  128. dev[0].wait_connected(timeout=15)
  129. dev[0].dump_monitor()
  130. dev[0].request("REMOVE_NETWORK all")
  131. dev[0].wait_disconnected(timeout=5)
  132. dev[0].dump_monitor()
  133. # This will result in disconnection due to no matching network
  134. subprocess.call(['iw', 'dev', dev[0].ifname, 'connect', 'open', "2412",
  135. apdev[0]['bssid']])
  136. dev[0].wait_disconnected(timeout=15)
  137. def test_ap_bss_load(dev, apdev):
  138. """AP with open mode (no security) configuration"""
  139. hapd = hostapd.add_ap(apdev[0]['ifname'],
  140. { "ssid": "open",
  141. "bss_load_update_period": "10" })
  142. dev[0].connect("open", key_mgmt="NONE", scan_freq="2412")
  143. # this does not really get much useful output with mac80211_hwsim currently,
  144. # but run through the channel survey update couple of times
  145. for i in range(0, 10):
  146. hwsim_utils.test_connectivity(dev[0], hapd)
  147. hwsim_utils.test_connectivity(dev[0], hapd)
  148. hwsim_utils.test_connectivity(dev[0], hapd)
  149. time.sleep(0.15)