]> git.ipfire.org Git - thirdparty/hostap.git/blame - tests/hwsim/test_ap_params.py
tests: Fix ft_psk_key_lifetime_in_memory with new PTK derivation debug
[thirdparty/hostap.git] / tests / hwsim / test_ap_params.py
CommitLineData
e769364b
JM
1# Test various AP mode parameters
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
7import logging
8logger = logging.getLogger()
f6e1eb07 9import subprocess
e769364b
JM
10
11import hwsim_utils
12import hostapd
13
14def test_ap_fragmentation_rts_set_high(dev, apdev):
15 """WPA2-PSK AP with fragmentation and RTS thresholds larger than frame length"""
16 ssid = "test-wpa2-psk"
17 passphrase = 'qwertyuiop'
18 params = hostapd.wpa2_params(ssid=ssid, passphrase=passphrase)
19 params['rts_threshold'] = "1000"
20 params['fragm_threshold'] = "2000"
a8375c94 21 hapd = hostapd.add_ap(apdev[0]['ifname'], params)
e769364b 22 dev[0].connect(ssid, psk=passphrase, scan_freq="2412")
a8375c94 23 hwsim_utils.test_connectivity(dev[0], hapd)
e769364b
JM
24
25def test_ap_fragmentation_open(dev, apdev):
26 """Open AP with fragmentation threshold"""
27 ssid = "fragmentation"
28 params = {}
29 params['ssid'] = ssid
30 params['fragm_threshold'] = "1000"
a8375c94 31 hapd = hostapd.add_ap(apdev[0]['ifname'], params)
e769364b 32 dev[0].connect(ssid, key_mgmt="NONE", scan_freq="2412")
a8375c94 33 hwsim_utils.test_connectivity(dev[0], hapd)
e769364b
JM
34
35def test_ap_fragmentation_wpa2(dev, apdev):
36 """WPA2-PSK AP with fragmentation threshold"""
37 ssid = "test-wpa2-psk"
38 passphrase = 'qwertyuiop'
39 params = hostapd.wpa2_params(ssid=ssid, passphrase=passphrase)
40 params['fragm_threshold'] = "1000"
a8375c94 41 hapd = hostapd.add_ap(apdev[0]['ifname'], params)
e769364b 42 dev[0].connect(ssid, psk=passphrase, scan_freq="2412")
a8375c94 43 hwsim_utils.test_connectivity(dev[0], hapd)
52ec1aeb
JM
44
45def test_ap_vendor_elements(dev, apdev):
46 """WPA2-PSK AP with vendor elements added"""
47 bssid = apdev[0]['bssid']
48 ssid = "test-wpa2-psk"
49 passphrase = 'qwertyuiop'
50 params = hostapd.wpa2_params(ssid=ssid, passphrase=passphrase)
51 params['vendor_elements'] = "dd0411223301"
52 hostapd.add_ap(apdev[0]['ifname'], params)
53 dev[0].connect(ssid, psk=passphrase, scan_freq="2412")
54 bss = dev[0].get_bss(bssid)
55 if "dd0411223301" not in bss['ie']:
56 raise Exception("Vendor element not shown in scan results")
f6e1eb07
JM
57
58def test_ap_country(dev, apdev):
59 """WPA2-PSK AP setting country code and using 5 GHz band"""
60 try:
9d7fdac5 61 hapd = None
f6e1eb07
JM
62 bssid = apdev[0]['bssid']
63 ssid = "test-wpa2-psk"
64 passphrase = 'qwertyuiop'
65 params = hostapd.wpa2_params(ssid=ssid, passphrase=passphrase)
66 params['country_code'] = 'FI'
67 params['ieee80211d'] = '1'
68 params['hw_mode'] = 'a'
69 params['channel'] = '36'
a8375c94 70 hapd = hostapd.add_ap(apdev[0]['ifname'], params)
f6e1eb07 71 dev[0].connect(ssid, psk=passphrase, scan_freq="5180")
a8375c94 72 hwsim_utils.test_connectivity(dev[0], hapd)
f6e1eb07 73 finally:
9d7fdac5
JM
74 dev[0].request("DISCONNECT")
75 if hapd:
76 hapd.request("DISABLE")
f6e1eb07 77 subprocess.call(['sudo', 'iw', 'reg', 'set', '00'])
9d7fdac5 78 dev[0].flush_scan_cache()
656a3ef2
JM
79
80def test_ap_acl_accept(dev, apdev):
81 """MAC ACL accept list"""
82 ssid = "acl"
83 params = {}
84 params['ssid'] = ssid
85 params['accept_mac_file'] = "hostapd.macaddr"
86 hapd = hostapd.add_ap(apdev[0]['ifname'], params)
7e49399b 87 dev[0].scan_for_bss(apdev[0]['bssid'], freq="2412")
656a3ef2 88 dev[0].connect(ssid, key_mgmt="NONE", scan_freq="2412")
7e49399b 89 dev[1].scan_for_bss(apdev[0]['bssid'], freq="2412")
656a3ef2
JM
90 dev[1].connect(ssid, key_mgmt="NONE", scan_freq="2412")
91 dev[0].request("REMOVE_NETWORK all")
92 dev[1].request("REMOVE_NETWORK all")
93 hapd.request("SET macaddr_acl 1")
94 dev[1].dump_monitor()
95 dev[1].connect(ssid, key_mgmt="NONE", scan_freq="2412", wait_connect=False)
96 dev[0].connect(ssid, key_mgmt="NONE", scan_freq="2412")
97 ev = dev[1].wait_event(["CTRL-EVENT-CONNECTED"], timeout=1)
98 if ev is not None:
99 raise Exception("Unexpected association")
100
101def test_ap_acl_deny(dev, apdev):
102 """MAC ACL deny list"""
103 ssid = "acl"
104 params = {}
105 params['ssid'] = ssid
106 params['deny_mac_file'] = "hostapd.macaddr"
107 hapd = hostapd.add_ap(apdev[0]['ifname'], params)
7e49399b 108 dev[0].scan_for_bss(apdev[0]['bssid'], freq="2412")
656a3ef2 109 dev[0].connect(ssid, key_mgmt="NONE", scan_freq="2412", wait_connect=False)
7e49399b 110 dev[1].scan_for_bss(apdev[0]['bssid'], freq="2412")
656a3ef2
JM
111 dev[1].connect(ssid, key_mgmt="NONE", scan_freq="2412")
112 ev = dev[0].wait_event(["CTRL-EVENT-CONNECTED"], timeout=1)
113 if ev is not None:
114 raise Exception("Unexpected association")
8a9a3b34
JM
115
116def test_ap_wds_sta(dev, apdev):
117 """WPA2-PSK AP with STA using 4addr mode"""
118 ssid = "test-wpa2-psk"
119 passphrase = 'qwertyuiop'
120 params = hostapd.wpa2_params(ssid=ssid, passphrase=passphrase)
121 params['wds_sta'] = "1"
122 params['wds_bridge'] = "wds-br0"
1131a1c8 123 hapd = hostapd.add_ap(apdev[0]['ifname'], params)
8a9a3b34
JM
124
125 try:
126 subprocess.call(['sudo', 'brctl', 'addbr', 'wds-br0'])
127 subprocess.call(['sudo', 'brctl', 'setfd', 'wds-br0', '0'])
128 subprocess.call(['sudo', 'ip', 'link', 'set', 'dev', 'wds-br0', 'up'])
129 subprocess.call(['sudo', 'iw', dev[0].ifname, 'set', '4addr', 'on'])
130 dev[0].connect(ssid, psk=passphrase, scan_freq="2412")
1131a1c8
JM
131 hwsim_utils.test_connectivity_iface(dev[0], hapd, "wds-br0",
132 max_tries=15)
8a9a3b34
JM
133 finally:
134 subprocess.call(['sudo', 'iw', dev[0].ifname, 'set', '4addr', 'off'])
135 subprocess.call(['sudo', 'ip', 'link', 'set', 'dev', 'wds-br0', 'down'])
136 subprocess.call(['sudo', 'brctl', 'delbr', 'wds-br0'])
a424259a
JM
137
138def test_ap_inactivity_poll(dev, apdev):
139 """AP using inactivity poll"""
140 ssid = "test-wpa2-psk"
141 passphrase = 'qwertyuiop'
142 params = hostapd.wpa2_params(ssid=ssid, passphrase=passphrase)
143 params['ap_max_inactivity'] = "1"
144 hapd = hostapd.add_ap(apdev[0]['ifname'], params)
145 dev[0].connect(ssid, psk=passphrase, scan_freq="2412")
146 hapd.set("ext_mgmt_frame_handling", "1")
147 dev[0].request("DISCONNECT")
148 ev = hapd.wait_event(["MGMT-RX"], timeout=5)
149 if ev is None:
150 raise Exception("MGMT RX wait timed out for Deauth")
151 hapd.set("ext_mgmt_frame_handling", "0")
152 ev = hapd.wait_event(["AP-STA-DISCONNECTED"], timeout=30)
153 if ev is None:
154 raise Exception("STA disconnection on inactivity was not reported")
155
156def test_ap_inactivity_disconnect(dev, apdev):
157 """AP using inactivity disconnect"""
158 ssid = "test-wpa2-psk"
159 passphrase = 'qwertyuiop'
160 params = hostapd.wpa2_params(ssid=ssid, passphrase=passphrase)
161 params['ap_max_inactivity'] = "1"
162 params['skip_inactivity_poll'] = "1"
163 hapd = hostapd.add_ap(apdev[0]['ifname'], params)
164 dev[0].connect(ssid, psk=passphrase, scan_freq="2412")
165 hapd.set("ext_mgmt_frame_handling", "1")
166 dev[0].request("DISCONNECT")
167 ev = hapd.wait_event(["MGMT-RX"], timeout=5)
168 if ev is None:
169 raise Exception("MGMT RX wait timed out for Deauth")
170 hapd.set("ext_mgmt_frame_handling", "0")
171 ev = hapd.wait_event(["AP-STA-DISCONNECTED"], timeout=30)
172 if ev is None:
173 raise Exception("STA disconnection on inactivity was not reported")
a4e510fe
JM
174
175def test_ap_basic_rates(dev, apdev):
176 """Open AP with lots of basic rates"""
177 ssid = "basic rates"
178 params = {}
179 params['ssid'] = ssid
180 params['basic_rates'] = "10 20 55 110 60 90 120 180 240 360 480 540"
181 hostapd.add_ap(apdev[0]['ifname'], params)
182 dev[0].connect(ssid, key_mgmt="NONE", scan_freq="2412")
183
184def test_ap_short_preamble(dev, apdev):
185 """Open AP with short preamble"""
186 ssid = "short preamble"
187 params = {}
188 params['ssid'] = ssid
189 params['preamble'] = "1"
190 hostapd.add_ap(apdev[0]['ifname'], params)
191 dev[0].connect(ssid, key_mgmt="NONE", scan_freq="2412")
192
193def test_ap_spectrum_management_required(dev, apdev):
194 """Open AP with spectrum management required"""
195 ssid = "spectrum mgmt"
196 params = {}
197 params['ssid'] = ssid
198 params["country_code"] = "JP"
199 params["hw_mode"] = "a"
200 params["channel"] = "36"
201 params["ieee80211d"] = "1"
202 params["local_pwr_constraint"] = "3"
203 params['spectrum_mgmt_required'] = "1"
204 try:
9d7fdac5
JM
205 hapd = None
206 hapd = hostapd.add_ap(apdev[0]['ifname'], params)
a4e510fe
JM
207 dev[0].connect(ssid, key_mgmt="NONE", scan_freq="5180")
208 finally:
9d7fdac5
JM
209 dev[0].request("DISCONNECT")
210 if hapd:
211 hapd.request("DISABLE")
a4e510fe 212 subprocess.call(['sudo', 'iw', 'reg', 'set', '00'])
9d7fdac5 213 dev[0].flush_scan_cache()
11a4c910
JM
214
215def test_ap_max_listen_interval(dev, apdev):
216 """Open AP with maximum listen interval limit"""
217 ssid = "listen"
218 params = {}
219 params['ssid'] = ssid
220 params['max_listen_interval'] = "1"
221 hostapd.add_ap(apdev[0]['ifname'], params)
222 dev[0].connect(ssid, key_mgmt="NONE", scan_freq="2412", wait_connect=False)
223 ev = dev[0].wait_event(["CTRL-EVENT-ASSOC-REJECT"])
224 if ev is None:
225 raise Exception("Association rejection not reported")
226 if "status_code=51" not in ev:
227 raise Exception("Unexpected ASSOC-REJECT reason")
41be44af
JM
228
229def test_ap_max_num_sta(dev, apdev):
230 """Open AP with maximum STA count"""
231 ssid = "max"
232 params = {}
233 params['ssid'] = ssid
234 params['max_num_sta'] = "1"
235 hostapd.add_ap(apdev[0]['ifname'], params)
236 dev[1].connect(ssid, key_mgmt="NONE", scan_freq="2412")
237 dev[0].connect(ssid, key_mgmt="NONE", scan_freq="2412", wait_connect=False)
238 ev = dev[0].wait_event(["CTRL-EVENT-CONNECTED"], timeout=1)
239 if ev is not None:
240 raise Exception("Unexpected association")
6acecce1
JM
241
242def test_ap_tx_queue_params(dev, apdev):
243 """Open AP with TX queue params set"""
244 ssid = "tx"
245 params = {}
246 params['ssid'] = ssid
247 params['tx_queue_data2_aifs'] = "4"
248 params['tx_queue_data2_cwmin'] = "7"
249 params['tx_queue_data2_cwmax'] = "1023"
250 params['tx_queue_data2_burst'] = "4.2"
251 params['tx_queue_data1_aifs'] = "4"
252 params['tx_queue_data1_cwmin'] = "7"
253 params['tx_queue_data1_cwmax'] = "1023"
254 params['tx_queue_data1_burst'] = "2"
a8375c94 255 hapd = hostapd.add_ap(apdev[0]['ifname'], params)
6acecce1 256 dev[0].connect(ssid, key_mgmt="NONE", scan_freq="2412")
a8375c94 257 hwsim_utils.test_connectivity(dev[0], hapd)