]> git.ipfire.org Git - thirdparty/hostap.git/blob - tests/hwsim/test_ap_params.py
tests: Pass full apdev to add_ap() function (1)
[thirdparty/hostap.git] / tests / hwsim / test_ap_params.py
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
7 import logging
8 logger = logging.getLogger()
9 import os
10 import subprocess
11
12 import hwsim_utils
13 import hostapd
14 from tshark import run_tshark
15 from utils import alloc_fail
16
17 def test_ap_fragmentation_rts_set_high(dev, apdev):
18 """WPA2-PSK AP with fragmentation and RTS thresholds larger than frame length"""
19 ssid = "test-wpa2-psk"
20 passphrase = 'qwertyuiop'
21 params = hostapd.wpa2_params(ssid=ssid, passphrase=passphrase)
22 params['rts_threshold'] = "1000"
23 params['fragm_threshold'] = "2000"
24 hapd = hostapd.add_ap(apdev[0], params)
25 dev[0].connect(ssid, psk=passphrase, scan_freq="2412")
26 hwsim_utils.test_connectivity(dev[0], hapd)
27
28 def test_ap_fragmentation_open(dev, apdev):
29 """Open AP with fragmentation threshold"""
30 ssid = "fragmentation"
31 params = {}
32 params['ssid'] = ssid
33 params['fragm_threshold'] = "1000"
34 hapd = hostapd.add_ap(apdev[0], params)
35 dev[0].connect(ssid, key_mgmt="NONE", scan_freq="2412")
36 hwsim_utils.test_connectivity(dev[0], hapd)
37
38 def test_ap_fragmentation_wpa2(dev, apdev):
39 """WPA2-PSK AP with fragmentation threshold"""
40 ssid = "test-wpa2-psk"
41 passphrase = 'qwertyuiop'
42 params = hostapd.wpa2_params(ssid=ssid, passphrase=passphrase)
43 params['fragm_threshold'] = "1000"
44 hapd = hostapd.add_ap(apdev[0], params)
45 dev[0].connect(ssid, psk=passphrase, scan_freq="2412")
46 hwsim_utils.test_connectivity(dev[0], hapd)
47
48 def test_ap_vendor_elements(dev, apdev):
49 """WPA2-PSK AP with vendor elements added"""
50 bssid = apdev[0]['bssid']
51 ssid = "test-wpa2-psk"
52 passphrase = 'qwertyuiop'
53 params = hostapd.wpa2_params(ssid=ssid, passphrase=passphrase)
54 params['vendor_elements'] = "dd0411223301"
55 hapd = hostapd.add_ap(apdev[0], params)
56 dev[0].connect(ssid, psk=passphrase, scan_freq="2412")
57 bss = dev[0].get_bss(bssid)
58 if "dd0411223301" not in bss['ie']:
59 raise Exception("Vendor element not shown in scan results")
60
61 hapd.set('vendor_elements', 'dd051122330203dd0400137400dd04001374ff')
62 if "OK" not in hapd.request("UPDATE_BEACON"):
63 raise Exception("UPDATE_BEACON failed")
64 dev[1].scan_for_bss(apdev[0]['bssid'], freq="2412")
65 bss = dev[1].get_bss(bssid)
66 if "dd0411223301" in bss['ie']:
67 raise Exception("Old vendor element still in scan results")
68 if "dd051122330203" not in bss['ie']:
69 raise Exception("New vendor element not shown in scan results")
70
71 def test_ap_element_parse(dev, apdev):
72 """Information element parsing - extra coverage"""
73 bssid = apdev[0]['bssid']
74 ssid = "test-wpa2-psk"
75 params = { 'ssid': ssid,
76 'vendor_elements': "380501020304059e009e009e009e009e009e00" }
77 hapd = hostapd.add_ap(apdev[0], params)
78 dev[0].scan_for_bss(apdev[0]['bssid'], freq="2412")
79 bss = dev[0].get_bss(bssid)
80 if "38050102030405" not in bss['ie']:
81 raise Exception("Timeout element not shown in scan results")
82
83 def test_ap_element_parse_oom(dev, apdev):
84 """Information element parsing OOM"""
85 bssid = apdev[0]['bssid']
86 ssid = "test-wpa2-psk"
87 params = { 'ssid': ssid,
88 'vendor_elements': "dd0d506f9a0a00000600411c440028" }
89 hapd = hostapd.add_ap(apdev[0], params)
90 dev[0].scan_for_bss(apdev[0]['bssid'], freq="2412")
91 with alloc_fail(dev[0], 1, "wpabuf_alloc;ieee802_11_vendor_ie_concat"):
92 bss = dev[0].get_bss(bssid)
93 logger.info(str(bss))
94
95 def test_ap_country(dev, apdev):
96 """WPA2-PSK AP setting country code and using 5 GHz band"""
97 try:
98 hapd = None
99 bssid = apdev[0]['bssid']
100 ssid = "test-wpa2-psk"
101 passphrase = 'qwertyuiop'
102 params = hostapd.wpa2_params(ssid=ssid, passphrase=passphrase)
103 params['country_code'] = 'FI'
104 params['ieee80211d'] = '1'
105 params['hw_mode'] = 'a'
106 params['channel'] = '36'
107 hapd = hostapd.add_ap(apdev[0], params)
108 dev[0].connect(ssid, psk=passphrase, scan_freq="5180")
109 hwsim_utils.test_connectivity(dev[0], hapd)
110 finally:
111 dev[0].request("DISCONNECT")
112 if hapd:
113 hapd.request("DISABLE")
114 subprocess.call(['iw', 'reg', 'set', '00'])
115 dev[0].flush_scan_cache()
116
117 def test_ap_acl_accept(dev, apdev):
118 """MAC ACL accept list"""
119 ssid = "acl"
120 params = {}
121 params['ssid'] = ssid
122 params['accept_mac_file'] = "hostapd.macaddr"
123 hapd = hostapd.add_ap(apdev[0], params)
124 dev[0].scan_for_bss(apdev[0]['bssid'], freq="2412")
125 dev[0].connect(ssid, key_mgmt="NONE", scan_freq="2412")
126 dev[1].scan_for_bss(apdev[0]['bssid'], freq="2412")
127 dev[1].connect(ssid, key_mgmt="NONE", scan_freq="2412")
128 dev[0].request("REMOVE_NETWORK all")
129 dev[1].request("REMOVE_NETWORK all")
130 hapd.request("SET macaddr_acl 1")
131 dev[1].dump_monitor()
132 dev[1].connect(ssid, key_mgmt="NONE", scan_freq="2412", wait_connect=False)
133 dev[0].connect(ssid, key_mgmt="NONE", scan_freq="2412")
134 ev = dev[1].wait_event(["CTRL-EVENT-CONNECTED"], timeout=1)
135 if ev is not None:
136 raise Exception("Unexpected association")
137
138 def test_ap_acl_deny(dev, apdev):
139 """MAC ACL deny list"""
140 ssid = "acl"
141 params = {}
142 params['ssid'] = ssid
143 params['deny_mac_file'] = "hostapd.macaddr"
144 hapd = hostapd.add_ap(apdev[0], params)
145 dev[0].scan_for_bss(apdev[0]['bssid'], freq="2412")
146 dev[0].connect(ssid, key_mgmt="NONE", scan_freq="2412", wait_connect=False)
147 dev[1].scan_for_bss(apdev[0]['bssid'], freq="2412")
148 dev[1].connect(ssid, key_mgmt="NONE", scan_freq="2412")
149 ev = dev[0].wait_event(["CTRL-EVENT-CONNECTED"], timeout=1)
150 if ev is not None:
151 raise Exception("Unexpected association")
152
153 def test_ap_wds_sta(dev, apdev):
154 """WPA2-PSK AP with STA using 4addr mode"""
155 ssid = "test-wpa2-psk"
156 passphrase = 'qwertyuiop'
157 params = hostapd.wpa2_params(ssid=ssid, passphrase=passphrase)
158 params['wds_sta'] = "1"
159 params['wds_bridge'] = "wds-br0"
160 hapd = hostapd.add_ap(apdev[0], params)
161
162 try:
163 subprocess.call(['brctl', 'addbr', 'wds-br0'])
164 subprocess.call(['brctl', 'setfd', 'wds-br0', '0'])
165 subprocess.call(['ip', 'link', 'set', 'dev', 'wds-br0', 'up'])
166 subprocess.call(['iw', dev[0].ifname, 'set', '4addr', 'on'])
167 dev[0].connect(ssid, psk=passphrase, scan_freq="2412")
168 hwsim_utils.test_connectivity_iface(dev[0], hapd, "wds-br0",
169 max_tries=15)
170 finally:
171 subprocess.call(['iw', dev[0].ifname, 'set', '4addr', 'off'])
172 subprocess.call(['ip', 'link', 'set', 'dev', 'wds-br0', 'down'])
173 subprocess.call(['brctl', 'delbr', 'wds-br0'])
174
175 def test_ap_inactivity_poll(dev, apdev):
176 """AP using inactivity poll"""
177 ssid = "test-wpa2-psk"
178 passphrase = 'qwertyuiop'
179 params = hostapd.wpa2_params(ssid=ssid, passphrase=passphrase)
180 params['ap_max_inactivity'] = "1"
181 hapd = hostapd.add_ap(apdev[0], params)
182 dev[0].connect(ssid, psk=passphrase, scan_freq="2412")
183 hapd.set("ext_mgmt_frame_handling", "1")
184 dev[0].request("DISCONNECT")
185 ev = hapd.wait_event(["MGMT-RX"], timeout=5)
186 if ev is None:
187 raise Exception("MGMT RX wait timed out for Deauth")
188 hapd.set("ext_mgmt_frame_handling", "0")
189 ev = hapd.wait_event(["AP-STA-DISCONNECTED"], timeout=30)
190 if ev is None:
191 raise Exception("STA disconnection on inactivity was not reported")
192
193 def test_ap_inactivity_disconnect(dev, apdev):
194 """AP using inactivity disconnect"""
195 ssid = "test-wpa2-psk"
196 passphrase = 'qwertyuiop'
197 params = hostapd.wpa2_params(ssid=ssid, passphrase=passphrase)
198 params['ap_max_inactivity'] = "1"
199 params['skip_inactivity_poll'] = "1"
200 hapd = hostapd.add_ap(apdev[0], params)
201 dev[0].connect(ssid, psk=passphrase, scan_freq="2412")
202 hapd.set("ext_mgmt_frame_handling", "1")
203 dev[0].request("DISCONNECT")
204 ev = hapd.wait_event(["MGMT-RX"], timeout=5)
205 if ev is None:
206 raise Exception("MGMT RX wait timed out for Deauth")
207 hapd.set("ext_mgmt_frame_handling", "0")
208 ev = hapd.wait_event(["AP-STA-DISCONNECTED"], timeout=30)
209 if ev is None:
210 raise Exception("STA disconnection on inactivity was not reported")
211
212 def test_ap_basic_rates(dev, apdev):
213 """Open AP with lots of basic rates"""
214 ssid = "basic rates"
215 params = {}
216 params['ssid'] = ssid
217 params['basic_rates'] = "10 20 55 110 60 90 120 180 240 360 480 540"
218 hostapd.add_ap(apdev[0], params)
219 dev[0].connect(ssid, key_mgmt="NONE", scan_freq="2412")
220
221 def test_ap_short_preamble(dev, apdev):
222 """Open AP with short preamble"""
223 ssid = "short preamble"
224 params = {}
225 params['ssid'] = ssid
226 params['preamble'] = "1"
227 hostapd.add_ap(apdev[0], params)
228 dev[0].connect(ssid, key_mgmt="NONE", scan_freq="2412")
229
230 def test_ap_spectrum_management_required(dev, apdev):
231 """Open AP with spectrum management required"""
232 ssid = "spectrum mgmt"
233 params = {}
234 params['ssid'] = ssid
235 params["country_code"] = "JP"
236 params["hw_mode"] = "a"
237 params["channel"] = "36"
238 params["ieee80211d"] = "1"
239 params["local_pwr_constraint"] = "3"
240 params['spectrum_mgmt_required'] = "1"
241 try:
242 hapd = None
243 hapd = hostapd.add_ap(apdev[0], params)
244 dev[0].connect(ssid, key_mgmt="NONE", scan_freq="5180")
245 finally:
246 dev[0].request("DISCONNECT")
247 if hapd:
248 hapd.request("DISABLE")
249 subprocess.call(['iw', 'reg', 'set', '00'])
250 dev[0].flush_scan_cache()
251
252 def test_ap_max_listen_interval(dev, apdev):
253 """Open AP with maximum listen interval limit"""
254 ssid = "listen"
255 params = {}
256 params['ssid'] = ssid
257 params['max_listen_interval'] = "1"
258 hostapd.add_ap(apdev[0], params)
259 dev[0].connect(ssid, key_mgmt="NONE", scan_freq="2412", wait_connect=False)
260 ev = dev[0].wait_event(["CTRL-EVENT-ASSOC-REJECT"])
261 if ev is None:
262 raise Exception("Association rejection not reported")
263 if "status_code=51" not in ev:
264 raise Exception("Unexpected ASSOC-REJECT reason")
265
266 def test_ap_max_num_sta(dev, apdev):
267 """Open AP with maximum STA count"""
268 ssid = "max"
269 params = {}
270 params['ssid'] = ssid
271 params['max_num_sta'] = "1"
272 hostapd.add_ap(apdev[0], params)
273 dev[1].connect(ssid, key_mgmt="NONE", scan_freq="2412")
274 dev[0].connect(ssid, key_mgmt="NONE", scan_freq="2412", wait_connect=False)
275 ev = dev[0].wait_event(["CTRL-EVENT-CONNECTED"], timeout=1)
276 if ev is not None:
277 raise Exception("Unexpected association")
278
279 def test_ap_max_num_sta_no_probe_resp(dev, apdev, params):
280 """Maximum STA count and limit on Probe Response frames"""
281 logdir = params['logdir']
282 dev[0].flush_scan_cache()
283 ssid = "max"
284 params = {}
285 params['ssid'] = ssid
286 params['beacon_int'] = "2000"
287 params['max_num_sta'] = "1"
288 params['no_probe_resp_if_max_sta'] = "1"
289 hostapd.add_ap(apdev[0], params)
290 dev[1].connect(ssid, key_mgmt="NONE", scan_freq="2412")
291 dev[0].scan(freq=2412, type="ONLY")
292 dev[0].scan(freq=2412, type="ONLY")
293 seen = dev[0].get_bss(apdev[0]['bssid']) != None
294 dev[1].scan(freq=2412, type="ONLY")
295 if seen:
296 out = run_tshark(os.path.join(logdir, "hwsim0.pcapng"),
297 "wlan.fc.type_subtype == 5", ["wlan.da" ])
298 if out:
299 if dev[0].own_addr() not in out:
300 # Discovery happened through Beacon frame reception. That's not
301 # an error case.
302 seen = False
303 if dev[1].own_addr() not in out:
304 raise Exception("No Probe Response frames to dev[1] seen")
305 if seen:
306 raise Exception("AP found unexpectedly")
307
308 def test_ap_tx_queue_params(dev, apdev):
309 """Open AP with TX queue params set"""
310 ssid = "tx"
311 params = {}
312 params['ssid'] = ssid
313 params['tx_queue_data2_aifs'] = "4"
314 params['tx_queue_data2_cwmin'] = "7"
315 params['tx_queue_data2_cwmax'] = "1023"
316 params['tx_queue_data2_burst'] = "4.2"
317 params['tx_queue_data1_aifs'] = "4"
318 params['tx_queue_data1_cwmin'] = "7"
319 params['tx_queue_data1_cwmax'] = "1023"
320 params['tx_queue_data1_burst'] = "2"
321 hapd = hostapd.add_ap(apdev[0], params)
322 dev[0].connect(ssid, key_mgmt="NONE", scan_freq="2412")
323 hwsim_utils.test_connectivity(dev[0], hapd)