]> git.ipfire.org Git - thirdparty/hostap.git/blame - tests/hwsim/test_ap_params.py
tests: Pass wpas/hapd instance to test_connectivity()
[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:
61 bssid = apdev[0]['bssid']
62 ssid = "test-wpa2-psk"
63 passphrase = 'qwertyuiop'
64 params = hostapd.wpa2_params(ssid=ssid, passphrase=passphrase)
65 params['country_code'] = 'FI'
66 params['ieee80211d'] = '1'
67 params['hw_mode'] = 'a'
68 params['channel'] = '36'
a8375c94 69 hapd = hostapd.add_ap(apdev[0]['ifname'], params)
f6e1eb07 70 dev[0].connect(ssid, psk=passphrase, scan_freq="5180")
a8375c94 71 hwsim_utils.test_connectivity(dev[0], hapd)
f6e1eb07
JM
72 finally:
73 subprocess.call(['sudo', 'iw', 'reg', 'set', '00'])
656a3ef2
JM
74
75def test_ap_acl_accept(dev, apdev):
76 """MAC ACL accept list"""
77 ssid = "acl"
78 params = {}
79 params['ssid'] = ssid
80 params['accept_mac_file'] = "hostapd.macaddr"
81 hapd = hostapd.add_ap(apdev[0]['ifname'], params)
7e49399b 82 dev[0].scan_for_bss(apdev[0]['bssid'], freq="2412")
656a3ef2 83 dev[0].connect(ssid, key_mgmt="NONE", scan_freq="2412")
7e49399b 84 dev[1].scan_for_bss(apdev[0]['bssid'], freq="2412")
656a3ef2
JM
85 dev[1].connect(ssid, key_mgmt="NONE", scan_freq="2412")
86 dev[0].request("REMOVE_NETWORK all")
87 dev[1].request("REMOVE_NETWORK all")
88 hapd.request("SET macaddr_acl 1")
89 dev[1].dump_monitor()
90 dev[1].connect(ssid, key_mgmt="NONE", scan_freq="2412", wait_connect=False)
91 dev[0].connect(ssid, key_mgmt="NONE", scan_freq="2412")
92 ev = dev[1].wait_event(["CTRL-EVENT-CONNECTED"], timeout=1)
93 if ev is not None:
94 raise Exception("Unexpected association")
95
96def test_ap_acl_deny(dev, apdev):
97 """MAC ACL deny list"""
98 ssid = "acl"
99 params = {}
100 params['ssid'] = ssid
101 params['deny_mac_file'] = "hostapd.macaddr"
102 hapd = hostapd.add_ap(apdev[0]['ifname'], params)
7e49399b 103 dev[0].scan_for_bss(apdev[0]['bssid'], freq="2412")
656a3ef2 104 dev[0].connect(ssid, key_mgmt="NONE", scan_freq="2412", wait_connect=False)
7e49399b 105 dev[1].scan_for_bss(apdev[0]['bssid'], freq="2412")
656a3ef2
JM
106 dev[1].connect(ssid, key_mgmt="NONE", scan_freq="2412")
107 ev = dev[0].wait_event(["CTRL-EVENT-CONNECTED"], timeout=1)
108 if ev is not None:
109 raise Exception("Unexpected association")
8a9a3b34
JM
110
111def test_ap_wds_sta(dev, apdev):
112 """WPA2-PSK AP with STA using 4addr mode"""
113 ssid = "test-wpa2-psk"
114 passphrase = 'qwertyuiop'
115 params = hostapd.wpa2_params(ssid=ssid, passphrase=passphrase)
116 params['wds_sta'] = "1"
117 params['wds_bridge'] = "wds-br0"
118 hostapd.add_ap(apdev[0]['ifname'], params)
119
120 try:
121 subprocess.call(['sudo', 'brctl', 'addbr', 'wds-br0'])
122 subprocess.call(['sudo', 'brctl', 'setfd', 'wds-br0', '0'])
123 subprocess.call(['sudo', 'ip', 'link', 'set', 'dev', 'wds-br0', 'up'])
124 subprocess.call(['sudo', 'iw', dev[0].ifname, 'set', '4addr', 'on'])
125 dev[0].connect(ssid, psk=passphrase, scan_freq="2412")
a8375c94 126 hwsim_utils.test_connectivity_iface(dev[0], "wds-br0", max_tries=15)
8a9a3b34
JM
127 finally:
128 subprocess.call(['sudo', 'iw', dev[0].ifname, 'set', '4addr', 'off'])
129 subprocess.call(['sudo', 'ip', 'link', 'set', 'dev', 'wds-br0', 'down'])
130 subprocess.call(['sudo', 'brctl', 'delbr', 'wds-br0'])
a424259a
JM
131
132def test_ap_inactivity_poll(dev, apdev):
133 """AP using inactivity poll"""
134 ssid = "test-wpa2-psk"
135 passphrase = 'qwertyuiop'
136 params = hostapd.wpa2_params(ssid=ssid, passphrase=passphrase)
137 params['ap_max_inactivity'] = "1"
138 hapd = hostapd.add_ap(apdev[0]['ifname'], params)
139 dev[0].connect(ssid, psk=passphrase, scan_freq="2412")
140 hapd.set("ext_mgmt_frame_handling", "1")
141 dev[0].request("DISCONNECT")
142 ev = hapd.wait_event(["MGMT-RX"], timeout=5)
143 if ev is None:
144 raise Exception("MGMT RX wait timed out for Deauth")
145 hapd.set("ext_mgmt_frame_handling", "0")
146 ev = hapd.wait_event(["AP-STA-DISCONNECTED"], timeout=30)
147 if ev is None:
148 raise Exception("STA disconnection on inactivity was not reported")
149
150def test_ap_inactivity_disconnect(dev, apdev):
151 """AP using inactivity disconnect"""
152 ssid = "test-wpa2-psk"
153 passphrase = 'qwertyuiop'
154 params = hostapd.wpa2_params(ssid=ssid, passphrase=passphrase)
155 params['ap_max_inactivity'] = "1"
156 params['skip_inactivity_poll'] = "1"
157 hapd = hostapd.add_ap(apdev[0]['ifname'], params)
158 dev[0].connect(ssid, psk=passphrase, scan_freq="2412")
159 hapd.set("ext_mgmt_frame_handling", "1")
160 dev[0].request("DISCONNECT")
161 ev = hapd.wait_event(["MGMT-RX"], timeout=5)
162 if ev is None:
163 raise Exception("MGMT RX wait timed out for Deauth")
164 hapd.set("ext_mgmt_frame_handling", "0")
165 ev = hapd.wait_event(["AP-STA-DISCONNECTED"], timeout=30)
166 if ev is None:
167 raise Exception("STA disconnection on inactivity was not reported")
a4e510fe
JM
168
169def test_ap_basic_rates(dev, apdev):
170 """Open AP with lots of basic rates"""
171 ssid = "basic rates"
172 params = {}
173 params['ssid'] = ssid
174 params['basic_rates'] = "10 20 55 110 60 90 120 180 240 360 480 540"
175 hostapd.add_ap(apdev[0]['ifname'], params)
176 dev[0].connect(ssid, key_mgmt="NONE", scan_freq="2412")
177
178def test_ap_short_preamble(dev, apdev):
179 """Open AP with short preamble"""
180 ssid = "short preamble"
181 params = {}
182 params['ssid'] = ssid
183 params['preamble'] = "1"
184 hostapd.add_ap(apdev[0]['ifname'], params)
185 dev[0].connect(ssid, key_mgmt="NONE", scan_freq="2412")
186
187def test_ap_spectrum_management_required(dev, apdev):
188 """Open AP with spectrum management required"""
189 ssid = "spectrum mgmt"
190 params = {}
191 params['ssid'] = ssid
192 params["country_code"] = "JP"
193 params["hw_mode"] = "a"
194 params["channel"] = "36"
195 params["ieee80211d"] = "1"
196 params["local_pwr_constraint"] = "3"
197 params['spectrum_mgmt_required'] = "1"
198 try:
199 hostapd.add_ap(apdev[0]['ifname'], params)
200 dev[0].connect(ssid, key_mgmt="NONE", scan_freq="5180")
201 finally:
202 subprocess.call(['sudo', 'iw', 'reg', 'set', '00'])
11a4c910
JM
203
204def test_ap_max_listen_interval(dev, apdev):
205 """Open AP with maximum listen interval limit"""
206 ssid = "listen"
207 params = {}
208 params['ssid'] = ssid
209 params['max_listen_interval'] = "1"
210 hostapd.add_ap(apdev[0]['ifname'], params)
211 dev[0].connect(ssid, key_mgmt="NONE", scan_freq="2412", wait_connect=False)
212 ev = dev[0].wait_event(["CTRL-EVENT-ASSOC-REJECT"])
213 if ev is None:
214 raise Exception("Association rejection not reported")
215 if "status_code=51" not in ev:
216 raise Exception("Unexpected ASSOC-REJECT reason")
41be44af
JM
217
218def test_ap_max_num_sta(dev, apdev):
219 """Open AP with maximum STA count"""
220 ssid = "max"
221 params = {}
222 params['ssid'] = ssid
223 params['max_num_sta'] = "1"
224 hostapd.add_ap(apdev[0]['ifname'], params)
225 dev[1].connect(ssid, key_mgmt="NONE", scan_freq="2412")
226 dev[0].connect(ssid, key_mgmt="NONE", scan_freq="2412", wait_connect=False)
227 ev = dev[0].wait_event(["CTRL-EVENT-CONNECTED"], timeout=1)
228 if ev is not None:
229 raise Exception("Unexpected association")
6acecce1
JM
230
231def test_ap_tx_queue_params(dev, apdev):
232 """Open AP with TX queue params set"""
233 ssid = "tx"
234 params = {}
235 params['ssid'] = ssid
236 params['tx_queue_data2_aifs'] = "4"
237 params['tx_queue_data2_cwmin'] = "7"
238 params['tx_queue_data2_cwmax'] = "1023"
239 params['tx_queue_data2_burst'] = "4.2"
240 params['tx_queue_data1_aifs'] = "4"
241 params['tx_queue_data1_cwmin'] = "7"
242 params['tx_queue_data1_cwmax'] = "1023"
243 params['tx_queue_data1_burst'] = "2"
a8375c94 244 hapd = hostapd.add_ap(apdev[0]['ifname'], params)
6acecce1 245 dev[0].connect(ssid, key_mgmt="NONE", scan_freq="2412")
a8375c94 246 hwsim_utils.test_connectivity(dev[0], hapd)