]>
git.ipfire.org Git - thirdparty/hostap.git/blob - tests/hwsim/test_ap_params.py
1 # Test various AP mode parameters
2 # Copyright (c) 2014, Qualcomm Atheros, Inc.
4 # This software may be distributed under the terms of the BSD license.
5 # See README for more details.
8 logger
= logging
.getLogger()
14 from tshark
import run_tshark
15 from utils
import alloc_fail
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
)
28 def test_ap_fragmentation_open(dev
, apdev
):
29 """Open AP with fragmentation threshold"""
30 ssid
= "fragmentation"
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
)
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
)
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")
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")
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")
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
)
95 def test_ap_country(dev
, apdev
):
96 """WPA2-PSK AP setting country code and using 5 GHz band"""
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
)
111 dev
[0].request("DISCONNECT")
113 hapd
.request("DISABLE")
114 subprocess
.call(['iw', 'reg', 'set', '00'])
115 dev
[0].flush_scan_cache()
117 def test_ap_acl_accept(dev
, apdev
):
118 """MAC ACL accept list"""
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)
136 raise Exception("Unexpected association")
138 def test_ap_acl_deny(dev
, apdev
):
139 """MAC ACL deny list"""
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)
151 raise Exception("Unexpected association")
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
)
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",
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'])
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)
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)
191 raise Exception("STA disconnection on inactivity was not reported")
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)
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)
210 raise Exception("STA disconnection on inactivity was not reported")
212 def test_ap_basic_rates(dev
, apdev
):
213 """Open AP with lots of basic rates"""
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")
221 def test_ap_short_preamble(dev
, apdev
):
222 """Open AP with short preamble"""
223 ssid
= "short preamble"
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")
230 def test_ap_spectrum_management_required(dev
, apdev
):
231 """Open AP with spectrum management required"""
232 ssid
= "spectrum mgmt"
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"
243 hapd
= hostapd
.add_ap(apdev
[0], params
)
244 dev
[0].connect(ssid
, key_mgmt
="NONE", scan_freq
="5180")
246 dev
[0].request("DISCONNECT")
248 hapd
.request("DISABLE")
249 subprocess
.call(['iw', 'reg', 'set', '00'])
250 dev
[0].flush_scan_cache()
252 def test_ap_max_listen_interval(dev
, apdev
):
253 """Open AP with maximum listen interval limit"""
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"])
262 raise Exception("Association rejection not reported")
263 if "status_code=51" not in ev
:
264 raise Exception("Unexpected ASSOC-REJECT reason")
266 def test_ap_max_num_sta(dev
, apdev
):
267 """Open AP with maximum STA count"""
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)
277 raise Exception("Unexpected association")
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()
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")
296 out
= run_tshark(os
.path
.join(logdir
, "hwsim0.pcapng"),
297 "wlan.fc.type_subtype == 5", ["wlan.da" ])
299 if dev
[0].own_addr() not in out
:
300 # Discovery happened through Beacon frame reception. That's not
303 if dev
[1].own_addr() not in out
:
304 raise Exception("No Probe Response frames to dev[1] seen")
306 raise Exception("AP found unexpectedly")
308 def test_ap_tx_queue_params(dev
, apdev
):
309 """Open AP with TX queue params set"""
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
)