test_ap_open.py 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  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 hostapd
  10. import hwsim_utils
  11. def test_ap_open(dev, apdev):
  12. """AP with open mode (no security) configuration"""
  13. hapd = hostapd.add_ap(apdev[0]['ifname'], { "ssid": "open" })
  14. dev[0].connect("open", key_mgmt="NONE", scan_freq="2412")
  15. hwsim_utils.test_connectivity(dev[0].ifname, apdev[0]['ifname'])
  16. ev = hapd.wait_event([ "AP-STA-CONNECTED" ], timeout=5)
  17. if ev is None:
  18. raise Exception("No connection event received from hostapd")
  19. dev[0].request("DISCONNECT")
  20. ev = hapd.wait_event([ "AP-STA-DISCONNECTED" ], timeout=5)
  21. if ev is None:
  22. raise Exception("No disconnection event received from hostapd")
  23. def test_ap_open_packet_loss(dev, apdev):
  24. """AP with open mode configuration and large packet loss"""
  25. params = { "ssid": "open",
  26. "ignore_probe_probability": "0.5",
  27. "ignore_auth_probability": "0.5",
  28. "ignore_assoc_probability": "0.5",
  29. "ignore_reassoc_probability": "0.5" }
  30. hapd = hostapd.add_ap(apdev[0]['ifname'], params)
  31. for i in range(0, 3):
  32. dev[i].connect("open", key_mgmt="NONE", scan_freq="2412",
  33. wait_connect=False)
  34. for i in range(0, 3):
  35. ev = dev[i].wait_event(["CTRL-EVENT-CONNECTED"], timeout=20)
  36. if ev is None:
  37. raise Exception("Association with the AP timed out")
  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. ev = dev[0].wait_event(["CTRL-EVENT-DISCONNECTED"], timeout=5)
  57. if ev is None:
  58. raise Exception("Timeout on disconnection")
  59. ev = dev[0].wait_event(["CTRL-EVENT-CONNECTED"], timeout=2)
  60. if ev is None:
  61. raise Exception("Timeout on reconnection")
  62. def test_ap_open_assoc_timeout(dev, apdev):
  63. """AP timing out association"""
  64. ssid = "test"
  65. hapd = hostapd.add_ap(apdev[0]['ifname'], { "ssid": "open" })
  66. dev[0].scan(freq="2412")
  67. hapd.set("ext_mgmt_frame_handling", "1")
  68. dev[0].connect("open", key_mgmt="NONE", scan_freq="2412",
  69. wait_connect=False)
  70. for i in range(0, 10):
  71. req = hapd.mgmt_rx()
  72. if req is None:
  73. raise Exception("MGMT RX wait timed out")
  74. if req['subtype'] == 11:
  75. break
  76. req = None
  77. if not req:
  78. raise Exception("Authentication frame not received")
  79. resp = {}
  80. resp['fc'] = req['fc']
  81. resp['da'] = req['sa']
  82. resp['sa'] = req['da']
  83. resp['bssid'] = req['bssid']
  84. resp['payload'] = struct.pack('<HHH', 0, 2, 0)
  85. hapd.mgmt_tx(resp)
  86. assoc = 0
  87. for i in range(0, 10):
  88. req = hapd.mgmt_rx()
  89. if req is None:
  90. raise Exception("MGMT RX wait timed out")
  91. if req['subtype'] == 0:
  92. assoc += 1
  93. if assoc == 3:
  94. break
  95. if assoc != 3:
  96. raise Exception("Association Request frames not received: assoc=%d" % assoc)
  97. hapd.set("ext_mgmt_frame_handling", "0")
  98. ev = dev[0].wait_event(["CTRL-EVENT-CONNECTED"], timeout=15)
  99. if ev is None:
  100. raise Exception("Timeout on connection")
  101. def test_ap_open_id_str(dev, apdev):
  102. """AP with open mode and id_str"""
  103. hapd = hostapd.add_ap(apdev[0]['ifname'], { "ssid": "open" })
  104. dev[0].connect("open", key_mgmt="NONE", scan_freq="2412", id_str="foo",
  105. wait_connect=False)
  106. ev = dev[0].wait_event(["CTRL-EVENT-CONNECTED"])
  107. if ev is None:
  108. raise Exception("Association with the AP timed out")
  109. if "id_str=foo" not in ev:
  110. raise Exception("CTRL-EVENT-CONNECT did not have matching id_str: " + ev)
  111. if dev[0].get_status_field("id_str") != "foo":
  112. raise Exception("id_str mismatch")