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