test_ap_config.py 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. # hostapd configuration tests
  2. # Copyright (c) 2014, 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 os
  7. import signal
  8. import time
  9. from remotehost import remote_compatible
  10. import hostapd
  11. @remote_compatible
  12. def test_ap_config_errors(dev, apdev):
  13. """Various hostapd configuration errors"""
  14. # IEEE 802.11d without country code
  15. params = { "ssid": "foo", "ieee80211d": "1" }
  16. hapd = hostapd.add_ap(apdev[0], params, no_enable=True)
  17. if "FAIL" not in hapd.request("ENABLE"):
  18. raise Exception("Unexpected ENABLE success (ieee80211d without country_code)")
  19. hostapd.remove_bss(apdev[0])
  20. # IEEE 802.11h without IEEE 802.11d
  21. params = { "ssid": "foo", "ieee80211h": "1" }
  22. hapd = hostapd.add_ap(apdev[0], params, no_enable=True)
  23. if "FAIL" not in hapd.request("ENABLE"):
  24. raise Exception("Unexpected ENABLE success (ieee80211h without ieee80211d")
  25. hostapd.remove_bss(apdev[0])
  26. # Power Constraint without IEEE 802.11d
  27. params = { "ssid": "foo", "local_pwr_constraint": "1" }
  28. hapd = hostapd.add_ap(apdev[0], params, no_enable=True)
  29. if "FAIL" not in hapd.request("ENABLE"):
  30. raise Exception("Unexpected ENABLE success (local_pwr_constraint without ieee80211d)")
  31. hostapd.remove_bss(apdev[0])
  32. # Spectrum management without Power Constraint
  33. params = { "ssid": "foo", "spectrum_mgmt_required": "1" }
  34. hapd = hostapd.add_ap(apdev[0], params, no_enable=True)
  35. if "FAIL" not in hapd.request("ENABLE"):
  36. raise Exception("Unexpected ENABLE success (spectrum_mgmt_required without local_pwr_constraint)")
  37. hostapd.remove_bss(apdev[0])
  38. # IEEE 802.1X without authentication server
  39. params = { "ssid": "foo", "ieee8021x": "1" }
  40. hapd = hostapd.add_ap(apdev[0], params, no_enable=True)
  41. if "FAIL" not in hapd.request("ENABLE"):
  42. raise Exception("Unexpected ENABLE success (ieee8021x)")
  43. hostapd.remove_bss(apdev[0])
  44. # RADIUS-PSK without macaddr_acl=2
  45. params = hostapd.wpa2_params(ssid="foo", passphrase="12345678")
  46. params["wpa_psk_radius"] = "1"
  47. hapd = hostapd.add_ap(apdev[0], params, no_enable=True)
  48. if "FAIL" not in hapd.request("ENABLE"):
  49. raise Exception("Unexpected ENABLE success (wpa_psk_radius)")
  50. hostapd.remove_bss(apdev[0])
  51. # FT without NAS-Identifier
  52. params = { "wpa": "2",
  53. "wpa_key_mgmt": "FT-PSK",
  54. "rsn_pairwise": "CCMP",
  55. "wpa_passphrase": "12345678" }
  56. hapd = hostapd.add_ap(apdev[0], params, no_enable=True)
  57. if "FAIL" not in hapd.request("ENABLE"):
  58. raise Exception("Unexpected ENABLE success (FT without nas_identifier)")
  59. hostapd.remove_bss(apdev[0])
  60. # Hotspot 2.0 without WPA2/CCMP
  61. params = hostapd.wpa2_params(ssid="foo")
  62. params['wpa_key_mgmt'] = "WPA-EAP"
  63. params['ieee8021x'] = "1"
  64. params['auth_server_addr'] = "127.0.0.1"
  65. params['auth_server_port'] = "1812"
  66. params['auth_server_shared_secret'] = "radius"
  67. params['interworking'] = "1"
  68. params['hs20'] = "1"
  69. params['wpa'] = "1"
  70. hapd = hostapd.add_ap(apdev[0], params, no_enable=True)
  71. if "FAIL" not in hapd.request("ENABLE"):
  72. raise Exception("Unexpected ENABLE success (HS 2.0 without WPA2/CCMP)")
  73. hostapd.remove_bss(apdev[0])
  74. def test_ap_config_reload(dev, apdev, params):
  75. """hostapd configuration reload"""
  76. hapd = hostapd.add_ap(apdev[0], { "ssid": "foo" })
  77. hapd.set("ssid", "foobar")
  78. with open(os.path.join(params['logdir'], 'hostapd-test.pid'), "r") as f:
  79. pid = int(f.read())
  80. os.kill(pid, signal.SIGHUP)
  81. time.sleep(0.1)
  82. dev[0].connect("foobar", key_mgmt="NONE", scan_freq="2412")
  83. hapd.set("ssid", "foo")
  84. os.kill(pid, signal.SIGHUP)
  85. dev[0].wait_disconnected()
  86. dev[0].request("DISCONNECT")
  87. def test_ap_config_reload_file(dev, apdev, params):
  88. """hostapd configuration reload from file"""
  89. hapd = hostapd.add_iface(apdev[0], "bss-1.conf")
  90. hapd.enable()
  91. hapd.set("ssid", "foobar")
  92. with open(os.path.join(params['logdir'], 'hostapd-test.pid'), "r") as f:
  93. pid = int(f.read())
  94. os.kill(pid, signal.SIGHUP)
  95. time.sleep(0.1)
  96. dev[0].connect("foobar", key_mgmt="NONE", scan_freq="2412")
  97. hapd.set("ssid", "foo")
  98. os.kill(pid, signal.SIGHUP)
  99. dev[0].wait_disconnected()
  100. dev[0].request("DISCONNECT")
  101. def test_ap_config_reload_before_enable(dev, apdev, params):
  102. """hostapd configuration reload before enable"""
  103. hapd = hostapd.add_iface(apdev[0], "bss-1.conf")
  104. with open(os.path.join(params['logdir'], 'hostapd-test.pid'), "r") as f:
  105. pid = int(f.read())
  106. os.kill(pid, signal.SIGHUP)
  107. hapd.ping()