test_ap_config.py 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  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()
  108. def test_ap_config_invalid_value(dev, apdev, params):
  109. """Ignoring invalid hostapd configuration parameter updates"""
  110. hapd = hostapd.add_ap(apdev[0], { "ssid": "test" }, no_enable=True)
  111. not_exist = "/tmp/hostapd-test/does-not-exist"
  112. tests = [ ("driver", "foobar"),
  113. ("ssid2", "Q"),
  114. ("macaddr_acl", "255"),
  115. ("accept_mac_file", not_exist),
  116. ("deny_mac_file", not_exist),
  117. ("eapol_version", "255"),
  118. ("eap_user_file", not_exist),
  119. ("wep_key_len_broadcast", "-1"),
  120. ("wep_key_len_unicast", "-1"),
  121. ("wep_rekey_period", "-1"),
  122. ("eap_rekey_period", "-1"),
  123. ("radius_client_addr", "foo"),
  124. ("acs_chan_bias", "-1:0.8"),
  125. ("acs_chan_bias", "1"),
  126. ("acs_chan_bias", "1:p"),
  127. ("acs_chan_bias", "1:-0.8"),
  128. ("acs_chan_bias", "1:0.8p"),
  129. ("dtim_period", "0"),
  130. ("bss_load_update_period", "-1"),
  131. ("send_probe_response", "255"),
  132. ("beacon_rate", "ht:-1"),
  133. ("beacon_rate", "ht:32"),
  134. ("beacon_rate", "vht:-1"),
  135. ("beacon_rate", "vht:10"),
  136. ("beacon_rate", "9"),
  137. ("beacon_rate", "10001"),
  138. ("vlan_file", not_exist),
  139. ("bss", ""),
  140. ("bssid", "foo"),
  141. ("extra_cred", not_exist),
  142. ("anqp_elem", "265"),
  143. ("anqp_elem", "265"),
  144. ("anqp_elem", "265:1"),
  145. ("anqp_elem", "265:1q"),
  146. ("fst_priority", ""),
  147. ("fils_cache_id", "q"),
  148. ("unknown-item", "foo") ]
  149. for field, val in tests:
  150. if "FAIL" not in hapd.request("SET %s %s" % (field, val)):
  151. raise Exception("Invalid %s accepted" % field)
  152. hapd.enable()
  153. dev[0].connect("test", key_mgmt="NONE", scan_freq="2412")